Mercurial > libavcodec.hg
comparison h264.c @ 5231:07a97575d0c4 libavcodec
Add support for streams with different chroma_qp_index_offset
for Cr and Cb
Patch by Andreas ªÓman % andreas A olebyn P nu %
Original thread:
Date: Jun 26, 2007 8:48 PM
subject: [FFmpeg-devel] Color corruption and seeking errors with H264 disc sources
author | gpoirier |
---|---|
date | Fri, 06 Jul 2007 14:21:37 +0000 |
parents | 65bffcc5571a |
children | 727a49c28c51 |
comparison
equal
deleted
inserted
replaced
5230:2a340aea762d | 5231:07a97575d0c4 |
---|---|
1596 #endif | 1596 #endif |
1597 | 1597 |
1598 /** | 1598 /** |
1599 * gets the chroma qp. | 1599 * gets the chroma qp. |
1600 */ | 1600 */ |
1601 static inline int get_chroma_qp(H264Context *h, int qscale){ | 1601 static inline int get_chroma_qp(H264Context *h, int t, int qscale){ |
1602 return h->pps.chroma_qp_table[qscale & 0xff]; | 1602 return h->pps.chroma_qp_table[t][qscale & 0xff]; |
1603 } | 1603 } |
1604 | 1604 |
1605 //FIXME need to check that this does not overflow signed 32 bit for low qp, i am not sure, it's very close | 1605 //FIXME need to check that this does not overflow signed 32 bit for low qp, i am not sure, it's very close |
1606 //FIXME check that gcc inlines this (and optimizes intra & separate_dc stuff away) | 1606 //FIXME check that gcc inlines this (and optimizes intra & separate_dc stuff away) |
1607 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int separate_dc){ | 1607 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int separate_dc){ |
3374 if(transform_bypass){ | 3374 if(transform_bypass){ |
3375 idct_add = idct_dc_add = s->dsp.add_pixels4; | 3375 idct_add = idct_dc_add = s->dsp.add_pixels4; |
3376 }else{ | 3376 }else{ |
3377 idct_add = s->dsp.h264_idct_add; | 3377 idct_add = s->dsp.h264_idct_add; |
3378 idct_dc_add = s->dsp.h264_idct_dc_add; | 3378 idct_dc_add = s->dsp.h264_idct_dc_add; |
3379 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp, h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp][0]); | 3379 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp[0], h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]); |
3380 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp][0]); | 3380 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp[1], h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]); |
3381 } | 3381 } |
3382 if(is_h264){ | 3382 if(is_h264){ |
3383 for(i=16; i<16+8; i++){ | 3383 for(i=16; i<16+8; i++){ |
3384 if(h->non_zero_count_cache[ scan8[i] ]) | 3384 if(h->non_zero_count_cache[ scan8[i] ]) |
3385 idct_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize); | 3385 idct_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize); |
3417 // deblock a pair | 3417 // deblock a pair |
3418 // top | 3418 // top |
3419 s->mb_y--; | 3419 s->mb_y--; |
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); | 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); |
3421 fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb | 3421 fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb |
3422 h->chroma_qp = get_chroma_qp(h, s->current_picture.qscale_table[mb_xy]); | 3422 h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy]); |
3423 h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy]); | |
3423 filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize); | 3424 filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize); |
3424 // bottom | 3425 // bottom |
3425 s->mb_y++; | 3426 s->mb_y++; |
3426 tprintf(h->s.avctx, "call mbaff filter_mb\n"); | 3427 tprintf(h->s.avctx, "call mbaff filter_mb\n"); |
3427 fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb | 3428 fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb |
3428 h->chroma_qp = get_chroma_qp(h, s->current_picture.qscale_table[mb_xy+s->mb_stride]); | 3429 h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy+s->mb_stride]); |
3430 h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy+s->mb_stride]); | |
3429 filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize); | 3431 filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize); |
3430 } else { | 3432 } else { |
3431 tprintf(h->s.avctx, "call filter_mb\n"); | 3433 tprintf(h->s.avctx, "call filter_mb\n"); |
3432 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, simple); | 3434 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, simple); |
3433 fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb | 3435 fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb |
4445 if(tmp>51){ | 4447 if(tmp>51){ |
4446 av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); | 4448 av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); |
4447 return -1; | 4449 return -1; |
4448 } | 4450 } |
4449 s->qscale= tmp; | 4451 s->qscale= tmp; |
4450 h->chroma_qp = get_chroma_qp(h, s->qscale); | 4452 h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); |
4453 h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); | |
4451 //FIXME qscale / qp ... stuff | 4454 //FIXME qscale / qp ... stuff |
4452 if(h->slice_type == SP_TYPE){ | 4455 if(h->slice_type == SP_TYPE){ |
4453 get_bits1(&s->gb); /* sp_for_switch_flag */ | 4456 get_bits1(&s->gb); /* sp_for_switch_flag */ |
4454 } | 4457 } |
4455 if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){ | 4458 if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){ |
4858 } | 4861 } |
4859 } | 4862 } |
4860 | 4863 |
4861 // In deblocking, the quantizer is 0 | 4864 // In deblocking, the quantizer is 0 |
4862 s->current_picture.qscale_table[mb_xy]= 0; | 4865 s->current_picture.qscale_table[mb_xy]= 0; |
4863 h->chroma_qp = get_chroma_qp(h, 0); | 4866 h->chroma_qp[0] = get_chroma_qp(h, 0, 0); |
4867 h->chroma_qp[1] = get_chroma_qp(h, 1, 0); | |
4864 // All coeffs are present | 4868 // All coeffs are present |
4865 memset(h->non_zero_count[mb_xy], 16, 16); | 4869 memset(h->non_zero_count[mb_xy], 16, 16); |
4866 | 4870 |
4867 s->current_picture.mb_type[mb_xy]= mb_type; | 4871 s->current_picture.mb_type[mb_xy]= mb_type; |
4868 return 0; | 4872 return 0; |
5132 } | 5136 } |
5133 s->current_picture.mb_type[mb_xy]= mb_type; | 5137 s->current_picture.mb_type[mb_xy]= mb_type; |
5134 | 5138 |
5135 if(cbp || IS_INTRA16x16(mb_type)){ | 5139 if(cbp || IS_INTRA16x16(mb_type)){ |
5136 int i8x8, i4x4, chroma_idx; | 5140 int i8x8, i4x4, chroma_idx; |
5137 int chroma_qp, dquant; | 5141 int dquant; |
5138 GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; | 5142 GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; |
5139 const uint8_t *scan, *scan8x8, *dc_scan; | 5143 const uint8_t *scan, *scan8x8, *dc_scan; |
5140 | 5144 |
5141 // fill_non_zero_count_cache(h); | 5145 // fill_non_zero_count_cache(h); |
5142 | 5146 |
5161 if(((unsigned)s->qscale) > 51){ | 5165 if(((unsigned)s->qscale) > 51){ |
5162 if(s->qscale<0) s->qscale+= 52; | 5166 if(s->qscale<0) s->qscale+= 52; |
5163 else s->qscale-= 52; | 5167 else s->qscale-= 52; |
5164 } | 5168 } |
5165 | 5169 |
5166 h->chroma_qp= chroma_qp= get_chroma_qp(h, s->qscale); | 5170 h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale); |
5171 h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale); | |
5167 if(IS_INTRA16x16(mb_type)){ | 5172 if(IS_INTRA16x16(mb_type)){ |
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){ | 5173 if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){ |
5169 return -1; //FIXME continue if partitioned and other return -1 too | 5174 return -1; //FIXME continue if partitioned and other return -1 too |
5170 } | 5175 } |
5171 | 5176 |
5219 } | 5224 } |
5220 } | 5225 } |
5221 | 5226 |
5222 if(cbp&0x20){ | 5227 if(cbp&0x20){ |
5223 for(chroma_idx=0; chroma_idx<2; chroma_idx++){ | 5228 for(chroma_idx=0; chroma_idx<2; chroma_idx++){ |
5224 const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][chroma_qp]; | 5229 const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]]; |
5225 for(i4x4=0; i4x4<4; i4x4++){ | 5230 for(i4x4=0; i4x4<4; i4x4++){ |
5226 const int index= 16 + 4*chroma_idx + i4x4; | 5231 const int index= 16 + 4*chroma_idx + i4x4; |
5227 if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){ | 5232 if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){ |
5228 return -1; | 5233 return -1; |
5229 } | 5234 } |
6011 // All blocks are present | 6016 // All blocks are present |
6012 h->cbp_table[mb_xy] = 0x1ef; | 6017 h->cbp_table[mb_xy] = 0x1ef; |
6013 h->chroma_pred_mode_table[mb_xy] = 0; | 6018 h->chroma_pred_mode_table[mb_xy] = 0; |
6014 // In deblocking, the quantizer is 0 | 6019 // In deblocking, the quantizer is 0 |
6015 s->current_picture.qscale_table[mb_xy]= 0; | 6020 s->current_picture.qscale_table[mb_xy]= 0; |
6016 h->chroma_qp = get_chroma_qp(h, 0); | 6021 h->chroma_qp[0] = get_chroma_qp(h, 0, 0); |
6022 h->chroma_qp[1] = get_chroma_qp(h, 1, 0); | |
6017 // All coeffs are present | 6023 // All coeffs are present |
6018 memset(h->non_zero_count[mb_xy], 16, 16); | 6024 memset(h->non_zero_count[mb_xy], 16, 16); |
6019 s->current_picture.mb_type[mb_xy]= mb_type; | 6025 s->current_picture.mb_type[mb_xy]= mb_type; |
6020 return 0; | 6026 return 0; |
6021 } | 6027 } |
6287 s->qscale += dqp; | 6293 s->qscale += dqp; |
6288 if(((unsigned)s->qscale) > 51){ | 6294 if(((unsigned)s->qscale) > 51){ |
6289 if(s->qscale<0) s->qscale+= 52; | 6295 if(s->qscale<0) s->qscale+= 52; |
6290 else s->qscale-= 52; | 6296 else s->qscale-= 52; |
6291 } | 6297 } |
6292 h->chroma_qp = get_chroma_qp(h, s->qscale); | 6298 h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); |
6299 h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); | |
6293 | 6300 |
6294 if( IS_INTRA16x16( mb_type ) ) { | 6301 if( IS_INTRA16x16( mb_type ) ) { |
6295 int i; | 6302 int i; |
6296 //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); | 6303 //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); |
6297 if( decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16) < 0) | 6304 if( decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16) < 0) |
6339 } | 6346 } |
6340 | 6347 |
6341 if( cbp&0x20 ) { | 6348 if( cbp&0x20 ) { |
6342 int c, i; | 6349 int c, i; |
6343 for( c = 0; c < 2; c++ ) { | 6350 for( c = 0; c < 2; c++ ) { |
6344 const uint32_t *qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp]; | 6351 const uint32_t *qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]]; |
6345 for( i = 0; i < 4; i++ ) { | 6352 for( i = 0; i < 4; i++ ) { |
6346 const int index = 16 + 4 * c + i; | 6353 const int index = 16 + 4 * c + i; |
6347 //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); | 6354 //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); |
6348 if( decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, qmul, 15) < 0) | 6355 if( decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, qmul, 15) < 0) |
6349 return -1; | 6356 return -1; |
6683 int mb_xy, mb_type; | 6690 int mb_xy, mb_type; |
6684 int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh; | 6691 int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh; |
6685 | 6692 |
6686 mb_xy = mb_x + mb_y*s->mb_stride; | 6693 mb_xy = mb_x + mb_y*s->mb_stride; |
6687 | 6694 |
6688 if(mb_x==0 || mb_y==0 || !s->dsp.h264_loop_filter_strength || | 6695 if(mb_x==0 || mb_y==0 || !s->dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff || |
6689 (h->deblocking_filter == 2 && (h->slice_table[mb_xy] != h->slice_table[h->top_mb_xy] || | 6696 (h->deblocking_filter == 2 && (h->slice_table[mb_xy] != h->slice_table[h->top_mb_xy] || |
6690 h->slice_table[mb_xy] != h->slice_table[mb_xy - 1]))) { | 6697 h->slice_table[mb_xy] != h->slice_table[mb_xy - 1]))) { |
6691 filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); | 6698 filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); |
6692 return; | 6699 return; |
6693 } | 6700 } |
6695 | 6702 |
6696 mb_type = s->current_picture.mb_type[mb_xy]; | 6703 mb_type = s->current_picture.mb_type[mb_xy]; |
6697 qp = s->current_picture.qscale_table[mb_xy]; | 6704 qp = s->current_picture.qscale_table[mb_xy]; |
6698 qp0 = s->current_picture.qscale_table[mb_xy-1]; | 6705 qp0 = s->current_picture.qscale_table[mb_xy-1]; |
6699 qp1 = s->current_picture.qscale_table[h->top_mb_xy]; | 6706 qp1 = s->current_picture.qscale_table[h->top_mb_xy]; |
6700 qpc = get_chroma_qp( h, qp ); | 6707 qpc = get_chroma_qp( h, 0, qp ); |
6701 qpc0 = get_chroma_qp( h, qp0 ); | 6708 qpc0 = get_chroma_qp( h, 0, qp0 ); |
6702 qpc1 = get_chroma_qp( h, qp1 ); | 6709 qpc1 = get_chroma_qp( h, 0, qp1 ); |
6703 qp0 = (qp + qp0 + 1) >> 1; | 6710 qp0 = (qp + qp0 + 1) >> 1; |
6704 qp1 = (qp + qp1 + 1) >> 1; | 6711 qp1 = (qp + qp1 + 1) >> 1; |
6705 qpc0 = (qpc + qpc0 + 1) >> 1; | 6712 qpc0 = (qpc + qpc0 + 1) >> 1; |
6706 qpc1 = (qpc + qpc1 + 1) >> 1; | 6713 qpc1 = (qpc + qpc1 + 1) >> 1; |
6707 qp_thresh = 15 - h->slice_alpha_c0_offset; | 6714 qp_thresh = 15 - h->slice_alpha_c0_offset; |
6803 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; | 6810 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; |
6804 | 6811 |
6805 //for sufficiently low qp, filtering wouldn't do anything | 6812 //for sufficiently low qp, filtering wouldn't do anything |
6806 //this is a conservative estimate: could also check beta_offset and more accurate chroma_qp | 6813 //this is a conservative estimate: could also check beta_offset and more accurate chroma_qp |
6807 if(!FRAME_MBAFF){ | 6814 if(!FRAME_MBAFF){ |
6808 int qp_thresh = 15 - h->slice_alpha_c0_offset - FFMAX(0, h->pps.chroma_qp_index_offset); | 6815 int qp_thresh = 15 - h->slice_alpha_c0_offset - FFMAX(0, FFMAX(h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1])); |
6809 int qp = s->current_picture.qscale_table[mb_xy]; | 6816 int qp = s->current_picture.qscale_table[mb_xy]; |
6810 if(qp <= qp_thresh | 6817 if(qp <= qp_thresh |
6811 && (mb_x == 0 || ((qp + s->current_picture.qscale_table[mb_xy-1] + 1)>>1) <= qp_thresh) | 6818 && (mb_x == 0 || ((qp + s->current_picture.qscale_table[mb_xy-1] + 1)>>1) <= qp_thresh) |
6812 && (mb_y == 0 || ((qp + s->current_picture.qscale_table[h->top_mb_xy] + 1)>>1) <= qp_thresh)){ | 6819 && (mb_y == 0 || ((qp + s->current_picture.qscale_table[h->top_mb_xy] + 1)>>1) <= qp_thresh)){ |
6813 return; | 6820 return; |
6826 */ | 6833 */ |
6827 const int pair_xy = mb_x + (mb_y&~1)*s->mb_stride; | 6834 const int pair_xy = mb_x + (mb_y&~1)*s->mb_stride; |
6828 const int left_mb_xy[2] = { pair_xy-1, pair_xy-1+s->mb_stride }; | 6835 const int left_mb_xy[2] = { pair_xy-1, pair_xy-1+s->mb_stride }; |
6829 int16_t bS[8]; | 6836 int16_t bS[8]; |
6830 int qp[2]; | 6837 int qp[2]; |
6831 int chroma_qp[2]; | 6838 int bqp[2]; |
6839 int rqp[2]; | |
6832 int mb_qp, mbn0_qp, mbn1_qp; | 6840 int mb_qp, mbn0_qp, mbn1_qp; |
6833 int i; | 6841 int i; |
6834 first_vertical_edge_done = 1; | 6842 first_vertical_edge_done = 1; |
6835 | 6843 |
6836 if( IS_INTRA(mb_type) ) | 6844 if( IS_INTRA(mb_type) ) |
6852 | 6860 |
6853 mb_qp = s->current_picture.qscale_table[mb_xy]; | 6861 mb_qp = s->current_picture.qscale_table[mb_xy]; |
6854 mbn0_qp = s->current_picture.qscale_table[left_mb_xy[0]]; | 6862 mbn0_qp = s->current_picture.qscale_table[left_mb_xy[0]]; |
6855 mbn1_qp = s->current_picture.qscale_table[left_mb_xy[1]]; | 6863 mbn1_qp = s->current_picture.qscale_table[left_mb_xy[1]]; |
6856 qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1; | 6864 qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1; |
6857 chroma_qp[0] = ( get_chroma_qp( h, mb_qp ) + | 6865 bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) + |
6858 get_chroma_qp( h, mbn0_qp ) + 1 ) >> 1; | 6866 get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1; |
6867 rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) + | |
6868 get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1; | |
6859 qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1; | 6869 qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1; |
6860 chroma_qp[1] = ( get_chroma_qp( h, mb_qp ) + | 6870 bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) + |
6861 get_chroma_qp( h, mbn1_qp ) + 1 ) >> 1; | 6871 get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1; |
6872 rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) + | |
6873 get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1; | |
6862 | 6874 |
6863 /* Filter edge */ | 6875 /* Filter edge */ |
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); | 6876 tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize); |
6865 { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | 6877 { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } |
6866 filter_mb_mbaff_edgev ( h, &img_y [0], linesize, bS, qp ); | 6878 filter_mb_mbaff_edgev ( h, &img_y [0], linesize, bS, qp ); |
6867 filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, chroma_qp ); | 6879 filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, bqp ); |
6868 filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, chroma_qp ); | 6880 filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, rqp ); |
6869 } | 6881 } |
6870 /* dir : 0 -> vertical edge, 1 -> horizontal edge */ | 6882 /* dir : 0 -> vertical edge, 1 -> horizontal edge */ |
6871 for( dir = 0; dir < 2; dir++ ) | 6883 for( dir = 0; dir < 2; dir++ ) |
6872 { | 6884 { |
6873 int edge; | 6885 int edge; |
6901 // | 6913 // |
6902 static const int nnz_idx[4] = {4,5,6,3}; | 6914 static const int nnz_idx[4] = {4,5,6,3}; |
6903 unsigned int tmp_linesize = 2 * linesize; | 6915 unsigned int tmp_linesize = 2 * linesize; |
6904 unsigned int tmp_uvlinesize = 2 * uvlinesize; | 6916 unsigned int tmp_uvlinesize = 2 * uvlinesize; |
6905 int mbn_xy = mb_xy - 2 * s->mb_stride; | 6917 int mbn_xy = mb_xy - 2 * s->mb_stride; |
6906 int qp, chroma_qp; | 6918 int qp; |
6907 int i, j; | 6919 int i, j; |
6908 int16_t bS[4]; | 6920 int16_t bS[4]; |
6909 | 6921 |
6910 for(j=0; j<2; j++, mbn_xy += s->mb_stride){ | 6922 for(j=0; j<2; j++, mbn_xy += s->mb_stride){ |
6911 if( IS_INTRA(mb_type) || | 6923 if( IS_INTRA(mb_type) || |
6925 // value in IPCM macroblocks. | 6937 // value in IPCM macroblocks. |
6926 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; | 6938 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; |
6927 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); | 6939 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); |
6928 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | 6940 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } |
6929 filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp ); | 6941 filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp ); |
6930 chroma_qp = ( h->chroma_qp + | 6942 filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, |
6931 get_chroma_qp( h, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; | 6943 ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); |
6932 filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp ); | 6944 filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, |
6933 filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp ); | 6945 ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); |
6934 } | 6946 } |
6935 | 6947 |
6936 start = 1; | 6948 start = 1; |
6937 } | 6949 } |
6938 | 6950 |
7025 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); | 7037 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); |
7026 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } | 7038 { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } |
7027 if( dir == 0 ) { | 7039 if( dir == 0 ) { |
7028 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); | 7040 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); |
7029 if( (edge&1) == 0 ) { | 7041 if( (edge&1) == 0 ) { |
7030 int chroma_qp = ( h->chroma_qp + | 7042 filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, |
7031 get_chroma_qp( h, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; | 7043 ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); |
7032 filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, chroma_qp ); | 7044 filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, |
7033 filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, chroma_qp ); | 7045 ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); |
7034 } | 7046 } |
7035 } else { | 7047 } else { |
7036 filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp ); | 7048 filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp ); |
7037 if( (edge&1) == 0 ) { | 7049 if( (edge&1) == 0 ) { |
7038 int chroma_qp = ( h->chroma_qp + | 7050 filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, |
7039 get_chroma_qp( h, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; | 7051 ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); |
7040 filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, chroma_qp ); | 7052 filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, |
7041 filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, chroma_qp ); | 7053 ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); |
7042 } | 7054 } |
7043 } | 7055 } |
7044 } | 7056 } |
7045 } | 7057 } |
7046 } | 7058 } |
7570 } | 7582 } |
7571 return 0; | 7583 return 0; |
7572 } | 7584 } |
7573 | 7585 |
7574 static void | 7586 static void |
7575 build_qp_table(PPS *pps, int index) | 7587 build_qp_table(PPS *pps, int t, int index) |
7576 { | 7588 { |
7577 int i; | 7589 int i; |
7578 for(i = 0; i < 255; i++) | 7590 for(i = 0; i < 255; i++) |
7579 pps->chroma_qp_table[i & 0xff] = chroma_qp[av_clip(i + index, 0, 51)]; | 7591 pps->chroma_qp_table[t][i & 0xff] = chroma_qp[av_clip(i + index, 0, 51)]; |
7580 pps->chroma_qp_index_offset = index; | |
7581 } | 7592 } |
7582 | 7593 |
7583 static inline int decode_picture_parameter_set(H264Context *h, int bit_length){ | 7594 static inline int decode_picture_parameter_set(H264Context *h, int bit_length){ |
7584 MpegEncContext * const s = &h->s; | 7595 MpegEncContext * const s = &h->s; |
7585 unsigned int tmp, pps_id= get_ue_golomb(&s->gb); | 7596 unsigned int tmp, pps_id= get_ue_golomb(&s->gb); |
7646 | 7657 |
7647 pps->weighted_pred= get_bits1(&s->gb); | 7658 pps->weighted_pred= get_bits1(&s->gb); |
7648 pps->weighted_bipred_idc= get_bits(&s->gb, 2); | 7659 pps->weighted_bipred_idc= get_bits(&s->gb, 2); |
7649 pps->init_qp= get_se_golomb(&s->gb) + 26; | 7660 pps->init_qp= get_se_golomb(&s->gb) + 26; |
7650 pps->init_qs= get_se_golomb(&s->gb) + 26; | 7661 pps->init_qs= get_se_golomb(&s->gb) + 26; |
7651 build_qp_table(pps, get_se_golomb(&s->gb)); | 7662 pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb); |
7652 pps->deblocking_filter_parameters_present= get_bits1(&s->gb); | 7663 pps->deblocking_filter_parameters_present= get_bits1(&s->gb); |
7653 pps->constrained_intra_pred= get_bits1(&s->gb); | 7664 pps->constrained_intra_pred= get_bits1(&s->gb); |
7654 pps->redundant_pic_cnt_present = get_bits1(&s->gb); | 7665 pps->redundant_pic_cnt_present = get_bits1(&s->gb); |
7655 | 7666 |
7656 pps->transform_8x8_mode= 0; | 7667 pps->transform_8x8_mode= 0; |
7659 memset(pps->scaling_matrix8, 16, 2*64*sizeof(uint8_t)); | 7670 memset(pps->scaling_matrix8, 16, 2*64*sizeof(uint8_t)); |
7660 | 7671 |
7661 if(get_bits_count(&s->gb) < bit_length){ | 7672 if(get_bits_count(&s->gb) < bit_length){ |
7662 pps->transform_8x8_mode= get_bits1(&s->gb); | 7673 pps->transform_8x8_mode= get_bits1(&s->gb); |
7663 decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); | 7674 decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); |
7664 get_se_golomb(&s->gb); //second_chroma_qp_index_offset | 7675 pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset |
7665 } | 7676 } else { |
7677 pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0]; | |
7678 } | |
7679 | |
7680 build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]); | |
7681 if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) { | |
7682 build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]); | |
7683 h->pps.chroma_qp_diff= 1; | |
7684 } else | |
7685 memcpy(pps->chroma_qp_table[1], pps->chroma_qp_table[0], 256); | |
7666 | 7686 |
7667 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | 7687 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ |
7668 av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d %s %s %s %s\n", | 7688 av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n", |
7669 pps_id, pps->sps_id, | 7689 pps_id, pps->sps_id, |
7670 pps->cabac ? "CABAC" : "CAVLC", | 7690 pps->cabac ? "CABAC" : "CAVLC", |
7671 pps->slice_group_count, | 7691 pps->slice_group_count, |
7672 pps->ref_count[0], pps->ref_count[1], | 7692 pps->ref_count[0], pps->ref_count[1], |
7673 pps->weighted_pred ? "weighted" : "", | 7693 pps->weighted_pred ? "weighted" : "", |
7674 pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset, | 7694 pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1], |
7675 pps->deblocking_filter_parameters_present ? "LPAR" : "", | 7695 pps->deblocking_filter_parameters_present ? "LPAR" : "", |
7676 pps->constrained_intra_pred ? "CONSTR" : "", | 7696 pps->constrained_intra_pred ? "CONSTR" : "", |
7677 pps->redundant_pic_cnt_present ? "REDU" : "", | 7697 pps->redundant_pic_cnt_present ? "REDU" : "", |
7678 pps->transform_8x8_mode ? "8x8DCT" : "" | 7698 pps->transform_8x8_mode ? "8x8DCT" : "" |
7679 ); | 7699 ); |