Revision d268bed2 libavcodec/h264_cabac.c

View differences:

libavcodec/h264_cabac.c
689 689
    MpegEncContext * const s = &h->s;
690 690
    int i;
691 691
    const int8_t (*tab)[2];
692
    const int slice_qp = av_clip(s->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51);
692 693

  
693 694
    if( h->slice_type_nos == FF_I_TYPE ) tab = cabac_context_init_I;
694 695
    else                                 tab = cabac_context_init_PB[h->cabac_init_idc];
695 696

  
696 697
    /* calculate pre-state */
697 698
    for( i= 0; i < 460; i++ ) {
698
        int pre = 2*(((tab[i][0] * s->qscale) >>4 ) + tab[i][1]) - 127;
699
        int pre = 2*(((tab[i][0] * slice_qp) >>4 ) + tab[i][1]) - 127;
699 700

  
700 701
        pre^= pre>>31;
701 702
        if(pre > 124)
......
1630 1631
        if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){
1631 1632
            int val = 1;
1632 1633
            int ctx= 2;
1634
            const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8);
1633 1635

  
1634 1636
            while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) {
1635 1637
                ctx= 3;
1636 1638
                val++;
1637
                if(val > 102){ //prevent infinite loop
1639
                if(val > 2*max_qp){ //prevent infinite loop
1638 1640
                    av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y);
1639 1641
                    return -1;
1640 1642
                }
......
1646 1648
                val= -((val + 1)>>1);
1647 1649
            h->last_qscale_diff = val;
1648 1650
            s->qscale += val;
1649
            if(((unsigned)s->qscale) > 51){
1650
                if(s->qscale<0) s->qscale+= 52;
1651
                else            s->qscale-= 52;
1651
            if(((unsigned)s->qscale) > max_qp){
1652
                if(s->qscale<0) s->qscale+= max_qp+1;
1653
                else            s->qscale-= max_qp+1;
1652 1654
            }
1653 1655
            h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);
1654 1656
            h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);

Also available in: Unified diff