Revision 042ef4b7 libavcodec/h264.c

View differences:

libavcodec/h264.c
1598 1598
/**
1599 1599
 * gets the chroma qp.
1600 1600
 */
1601
static inline int get_chroma_qp(int chroma_qp_index_offset, int qscale){
1602

  
1603
    return chroma_qp[av_clip(qscale + chroma_qp_index_offset, 0, 51)];
1601
static inline int get_chroma_qp(H264Context *h, int qscale){
1602
    return h->pps.chroma_qp_table[qscale & 0xff];
1604 1603
}
1605 1604

  
1606 1605
//FIXME need to check that this does not overflow signed 32 bit for low qp, i am not sure, it's very close
......
3420 3419
            s->mb_y--;
3421 3420
            tprintf(h->s.avctx, "call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y);
3422 3421
            fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb
3423
            h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy]);
3422
            h->chroma_qp = get_chroma_qp(h, s->current_picture.qscale_table[mb_xy]);
3424 3423
            filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize);
3425 3424
            // bottom
3426 3425
            s->mb_y++;
3427 3426
            tprintf(h->s.avctx, "call mbaff filter_mb\n");
3428 3427
            fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb
3429
            h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy+s->mb_stride]);
3428
            h->chroma_qp = get_chroma_qp(h, s->current_picture.qscale_table[mb_xy+s->mb_stride]);
3430 3429
            filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
3431 3430
        } else {
3432 3431
            tprintf(h->s.avctx, "call filter_mb\n");
......
4448 4447
        return -1;
4449 4448
    }
4450 4449
    s->qscale= tmp;
4451
    h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale);
4450
    h->chroma_qp = get_chroma_qp(h, s->qscale);
4452 4451
    //FIXME qscale / qp ... stuff
4453 4452
    if(h->slice_type == SP_TYPE){
4454 4453
        get_bits1(&s->gb); /* sp_for_switch_flag */
......
4861 4860

  
4862 4861
        // In deblocking, the quantizer is 0
4863 4862
        s->current_picture.qscale_table[mb_xy]= 0;
4864
        h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 0);
4863
        h->chroma_qp = get_chroma_qp(h, 0);
4865 4864
        // All coeffs are present
4866 4865
        memset(h->non_zero_count[mb_xy], 16, 16);
4867 4866

  
......
5164 5163
            else            s->qscale-= 52;
5165 5164
        }
5166 5165

  
5167
        h->chroma_qp= chroma_qp= get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale);
5166
        h->chroma_qp= chroma_qp= get_chroma_qp(h, s->qscale);
5168 5167
        if(IS_INTRA16x16(mb_type)){
5169 5168
            if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){
5170 5169
                return -1; //FIXME continue if partitioned and other return -1 too
......
6014 6013
        h->chroma_pred_mode_table[mb_xy] = 0;
6015 6014
        // In deblocking, the quantizer is 0
6016 6015
        s->current_picture.qscale_table[mb_xy]= 0;
6017
        h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 0);
6016
        h->chroma_qp = get_chroma_qp(h, 0);
6018 6017
        // All coeffs are present
6019 6018
        memset(h->non_zero_count[mb_xy], 16, 16);
6020 6019
        s->current_picture.mb_type[mb_xy]= mb_type;
......
6290 6289
            if(s->qscale<0) s->qscale+= 52;
6291 6290
            else            s->qscale-= 52;
6292 6291
        }
6293
        h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale);
6292
        h->chroma_qp = get_chroma_qp(h, s->qscale);
6294 6293

  
6295 6294
        if( IS_INTRA16x16( mb_type ) ) {
6296 6295
            int i;
......
6698 6697
    qp = s->current_picture.qscale_table[mb_xy];
6699 6698
    qp0 = s->current_picture.qscale_table[mb_xy-1];
6700 6699
    qp1 = s->current_picture.qscale_table[h->top_mb_xy];
6701
    qpc = get_chroma_qp( h->pps.chroma_qp_index_offset, qp );
6702
    qpc0 = get_chroma_qp( h->pps.chroma_qp_index_offset, qp0 );
6703
    qpc1 = get_chroma_qp( h->pps.chroma_qp_index_offset, qp1 );
6700
    qpc = get_chroma_qp( h, qp );
6701
    qpc0 = get_chroma_qp( h, qp0 );
6702
    qpc1 = get_chroma_qp( h, qp1 );
6704 6703
    qp0 = (qp + qp0 + 1) >> 1;
6705 6704
    qp1 = (qp + qp1 + 1) >> 1;
6706 6705
    qpc0 = (qpc + qpc0 + 1) >> 1;
......
6855 6854
        mbn0_qp = s->current_picture.qscale_table[left_mb_xy[0]];
6856 6855
        mbn1_qp = s->current_picture.qscale_table[left_mb_xy[1]];
6857 6856
        qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1;
6858
        chroma_qp[0] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) +
6859
                         get_chroma_qp( h->pps.chroma_qp_index_offset, mbn0_qp ) + 1 ) >> 1;
6857
        chroma_qp[0] = ( get_chroma_qp( h, mb_qp ) +
6858
                         get_chroma_qp( h, mbn0_qp ) + 1 ) >> 1;
6860 6859
        qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;
6861
        chroma_qp[1] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) +
6862
                         get_chroma_qp( h->pps.chroma_qp_index_offset, mbn1_qp ) + 1 ) >> 1;
6860
        chroma_qp[1] = ( get_chroma_qp( h, mb_qp ) +
6861
                         get_chroma_qp( h, mbn1_qp ) + 1 ) >> 1;
6863 6862

  
6864 6863
        /* Filter edge */
6865 6864
        tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPc:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], chroma_qp[0], chroma_qp[1], linesize, uvlinesize);
......
6929 6928
                { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); }
6930 6929
                filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp );
6931 6930
                chroma_qp = ( h->chroma_qp +
6932
                              get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
6931
                              get_chroma_qp( h, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
6933 6932
                filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp );
6934 6933
                filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp );
6935 6934
            }
......
7029 7028
                filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp );
7030 7029
                if( (edge&1) == 0 ) {
7031 7030
                    int chroma_qp = ( h->chroma_qp +
7032
                                      get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
7031
                                      get_chroma_qp( h, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
7033 7032
                    filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, chroma_qp );
7034 7033
                    filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, chroma_qp );
7035 7034
                }
......
7037 7036
                filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp );
7038 7037
                if( (edge&1) == 0 ) {
7039 7038
                    int chroma_qp = ( h->chroma_qp +
7040
                                      get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
7039
                                      get_chroma_qp( h, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;
7041 7040
                    filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, chroma_qp );
7042 7041
                    filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, chroma_qp );
7043 7042
                }
......
7572 7571
    return 0;
7573 7572
}
7574 7573

  
7574
static void
7575
build_qp_table(PPS *pps, int index)
7576
{
7577
    int i;
7578
    for(i = 0; i < 255; i++)
7579
        pps->chroma_qp_table[i & 0xff] = chroma_qp[av_clip(i + index, 0, 51)];
7580
    pps->chroma_qp_index_offset = index;
7581
}
7582

  
7575 7583
static inline int decode_picture_parameter_set(H264Context *h, int bit_length){
7576 7584
    MpegEncContext * const s = &h->s;
7577 7585
    unsigned int tmp, pps_id= get_ue_golomb(&s->gb);
......
7640 7648
    pps->weighted_bipred_idc= get_bits(&s->gb, 2);
7641 7649
    pps->init_qp= get_se_golomb(&s->gb) + 26;
7642 7650
    pps->init_qs= get_se_golomb(&s->gb) + 26;
7643
    pps->chroma_qp_index_offset= get_se_golomb(&s->gb);
7651
    build_qp_table(pps, get_se_golomb(&s->gb));
7644 7652
    pps->deblocking_filter_parameters_present= get_bits1(&s->gb);
7645 7653
    pps->constrained_intra_pred= get_bits1(&s->gb);
7646 7654
    pps->redundant_pic_cnt_present = get_bits1(&s->gb);

Also available in: Unified diff