diff options
author | Anton Khirnov <anton@khirnov.net> | 2013-02-03 14:10:05 +0400 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2013-02-15 19:35:16 +0400 |
commit | 2c541554076cc8a72e7145d4da30389ca763f32f (patch) | |
tree | b404051a202e1ffffe4ecee2df1b89f9f92a70f5 /libavcodec/h264_cavlc.c | |
parent | 1d0feb5d1ac04d187b335f0e8d411c9f40b3a885 (diff) |
h264: deMpegEncContextize
Most of the changes are just trivial are just trivial replacements of
fields from MpegEncContext with equivalent fields in H264Context.
Everything in h264* other than h264.c are those trivial changes.
The nontrivial parts are:
1) extracting a simplified version of the frame management code from
mpegvideo.c. We don't need last/next_picture anymore, since h264 uses
its own more complex system already and those were set only to appease
the mpegvideo parts.
2) some tables that need to be allocated/freed in appropriate places.
3) hwaccels -- mostly trivial replacements.
for dxva, the draw_horiz_band() call is moved from
ff_dxva2_common_end_frame() to per-codec end_frame() callbacks,
because it's now different for h264 and MpegEncContext-based
decoders.
4) svq3 -- it does not use h264 complex reference system, so I just
added some very simplistic frame management instead and dropped the
use of ff_h264_frame_start(). Because of this I also had to move some
initialization code to svq3.
Additional fixes for chroma format and bit depth changes by
Janne Grunau <janne-libav@jannau.net>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavcodec/h264_cavlc.c')
-rw-r--r-- | libavcodec/h264_cavlc.c | 151 |
1 files changed, 74 insertions, 77 deletions
diff --git a/libavcodec/h264_cavlc.c b/libavcodec/h264_cavlc.c index be1cdf1ea2..9585b77830 100644 --- a/libavcodec/h264_cavlc.c +++ b/libavcodec/h264_cavlc.c @@ -292,7 +292,7 @@ static inline int pred_non_zero_count(H264Context *h, int n){ if(i<64) i= (i+1)>>1; - tprintf(h->s.avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); + tprintf(h->avctx, "pred_nnz L%X T%X n%d s%d P%X\n", left, top, n, scan8[n], i&31); return i&31; } @@ -443,7 +443,6 @@ static inline int get_level_prefix(GetBitContext *gb){ * @return <0 if an error occurred */ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff){ - MpegEncContext * const s = &h->s; static const int coeff_token_table_index[17]= {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3}; int level[16]; int zeros_left, coeff_token, total_coeff, i, trailing_ones, run_before; @@ -474,12 +473,12 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in if(total_coeff==0) return 0; if(total_coeff > (unsigned)max_coeff) { - av_log(h->s.avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", s->mb_x, s->mb_y, total_coeff); + av_log(h->avctx, AV_LOG_ERROR, "corrupted macroblock %d %d (total_coeff=%d)\n", h->mb_x, h->mb_y, total_coeff); return -1; } trailing_ones= coeff_token&3; - tprintf(h->s.avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff); + tprintf(h->avctx, "trailing:%d, total:%d\n", trailing_ones, total_coeff); assert(total_coeff<=16); i = show_bits(gb, 3); @@ -515,7 +514,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in level_code= 30 + get_bits(gb, prefix-3); //part if(prefix>=16){ if(prefix > 25+3){ - av_log(h->s.avctx, AV_LOG_ERROR, "Invalid level prefix\n"); + av_log(h->avctx, AV_LOG_ERROR, "Invalid level prefix\n"); return -1; } level_code += (1<<(prefix-3))-4096; @@ -611,8 +610,8 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in } if (zeros_left < 0) { - av_log(h->s.avctx, AV_LOG_ERROR, - "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, + "negative number of zero coeffs at %d %d\n", h->mb_x, h->mb_y); return AVERROR_INVALIDDATA; } @@ -627,8 +626,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, int16_t *block, in static av_always_inline int decode_luma_residual(H264Context *h, GetBitContext *gb, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p){ int i4x4, i8x8; - MpegEncContext * const s = &h->s; - int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1]; + int qscale = p == 0 ? h->qscale : h->chroma_qp[p-1]; if(IS_INTRA16x16(mb_type)){ AV_ZERO128(h->mb_luma_dc[p]+0); AV_ZERO128(h->mb_luma_dc[p]+8); @@ -693,7 +691,6 @@ static av_always_inline int decode_luma_residual(H264Context *h, GetBitContext * } int ff_h264_decode_mb_cavlc(H264Context *h){ - MpegEncContext * const s = &h->s; int mb_xy; int partition_count; unsigned int mb_type, cbp; @@ -701,32 +698,32 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2; const int pixel_shift = h->pixel_shift; - mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; + mb_xy = h->mb_xy = h->mb_x + h->mb_y*h->mb_stride; - tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); + tprintf(h->avctx, "pic:%d mb:%d/%d\n", h->frame_num, h->mb_x, h->mb_y); cbp = 0; /* avoid warning. FIXME: find a solution without slowing down the code */ if(h->slice_type_nos != AV_PICTURE_TYPE_I){ - if(s->mb_skip_run==-1) - s->mb_skip_run= get_ue_golomb(&s->gb); + if(h->mb_skip_run==-1) + h->mb_skip_run= get_ue_golomb(&h->gb); - if (s->mb_skip_run--) { - if(FRAME_MBAFF && (s->mb_y&1) == 0){ - if(s->mb_skip_run==0) - h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); + if (h->mb_skip_run--) { + if(FRAME_MBAFF && (h->mb_y&1) == 0){ + if(h->mb_skip_run==0) + h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&h->gb); } decode_mb_skip(h); return 0; } } if(FRAME_MBAFF){ - if( (s->mb_y&1) == 0 ) - h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&s->gb); + if( (h->mb_y&1) == 0 ) + h->mb_mbaff = h->mb_field_decoding_flag = get_bits1(&h->gb); } h->prev_mb_skipped= 0; - mb_type= get_ue_golomb(&s->gb); + mb_type= get_ue_golomb(&h->gb); if(h->slice_type_nos == AV_PICTURE_TYPE_B){ if(mb_type < 23){ partition_count= b_mb_type_info[mb_type].partition_count; @@ -749,7 +746,7 @@ int ff_h264_decode_mb_cavlc(H264Context *h){ mb_type--; decode_intra_mb: if(mb_type > 25){ - av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(h->slice_type), s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(h->slice_type), h->mb_x, h->mb_y); return -1; } partition_count=0; @@ -769,19 +766,19 @@ decode_intra_mb: h->sps.bit_depth_luma >> 3; // We assume these blocks are very rare so we do not optimize it. - align_get_bits(&s->gb); + align_get_bits(&h->gb); // The pixels are stored in the same order as levels in h->mb array. for(x=0; x < mb_size; x++){ - ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8); + ((uint8_t*)h->mb)[x]= get_bits(&h->gb, 8); } // In deblocking, the quantizer is 0 - s->current_picture.f.qscale_table[mb_xy] = 0; + h->cur_pic.f.qscale_table[mb_xy] = 0; // All coeffs are present memset(h->non_zero_count[mb_xy], 16, 48); - s->current_picture.f.mb_type[mb_xy] = mb_type; + h->cur_pic.f.mb_type[mb_xy] = mb_type; return 0; } @@ -795,7 +792,7 @@ decode_intra_mb: if(IS_INTRA4x4(mb_type)){ int i; int di = 1; - if(dct8x8_allowed && get_bits1(&s->gb)){ + if(dct8x8_allowed && get_bits1(&h->gb)){ mb_type |= MB_TYPE_8x8DCT; di = 4; } @@ -804,8 +801,8 @@ decode_intra_mb: for(i=0; i<16; i+=di){ int mode= pred_intra_mode(h, i); - if(!get_bits1(&s->gb)){ - const int rem_mode= get_bits(&s->gb, 3); + if(!get_bits1(&h->gb)){ + const int rem_mode= get_bits(&h->gb, 3); mode = rem_mode + (rem_mode >= mode); } @@ -823,7 +820,7 @@ decode_intra_mb: return -1; } if(decode_chroma){ - pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb), 1); + pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&h->gb), 1); if(pred_mode < 0) return -1; h->chroma_pred_mode= pred_mode; @@ -835,9 +832,9 @@ decode_intra_mb: if(h->slice_type_nos == AV_PICTURE_TYPE_B){ for(i=0; i<4; i++){ - h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); + h->sub_mb_type[i]= get_ue_golomb_31(&h->gb); if(h->sub_mb_type[i] >=13){ - av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "B sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], h->mb_x, h->mb_y); return -1; } sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; @@ -853,9 +850,9 @@ decode_intra_mb: }else{ assert(h->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ? for(i=0; i<4; i++){ - h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); + h->sub_mb_type[i]= get_ue_golomb_31(&h->gb); if(h->sub_mb_type[i] >=4){ - av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "P sub_mb_type %u out of range at %d %d\n", h->sub_mb_type[i], h->mb_x, h->mb_y); return -1; } sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; @@ -872,11 +869,11 @@ decode_intra_mb: if(ref_count == 1){ tmp= 0; }else if(ref_count == 2){ - tmp= get_bits1(&s->gb)^1; + tmp= get_bits1(&h->gb)^1; }else{ - tmp= get_ue_golomb_31(&s->gb); + tmp= get_ue_golomb_31(&h->gb); if(tmp>=ref_count){ - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); + av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", tmp); return -1; } } @@ -908,9 +905,9 @@ decode_intra_mb: const int index= 4*i + block_width*j; int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + mx += get_se_golomb(&h->gb); + my += get_se_golomb(&h->gb); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); if(IS_SUB_8X8(sub_mb_type)){ mv_cache[ 1 ][0]= @@ -948,11 +945,11 @@ decode_intra_mb: if (rc == 1) { val= 0; } else if (rc == 2) { - val= get_bits1(&s->gb)^1; + val= get_bits1(&h->gb)^1; }else{ - val= get_ue_golomb_31(&s->gb); + val= get_ue_golomb_31(&h->gb); if (val >= rc) { - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } @@ -962,9 +959,9 @@ decode_intra_mb: for(list=0; list<h->list_count; list++){ if(IS_DIR(mb_type, 0, list)){ pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + mx += get_se_golomb(&h->gb); + my += get_se_golomb(&h->gb); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); } @@ -979,11 +976,11 @@ decode_intra_mb: if (rc == 1) { val= 0; } else if (rc == 2) { - val= get_bits1(&s->gb)^1; + val= get_bits1(&h->gb)^1; }else{ - val= get_ue_golomb_31(&s->gb); + val= get_ue_golomb_31(&h->gb); if (val >= rc) { - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } @@ -997,9 +994,9 @@ decode_intra_mb: unsigned int val; if(IS_DIR(mb_type, i, list)){ pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + mx += get_se_golomb(&h->gb); + my += get_se_golomb(&h->gb); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); val= pack16to32(mx,my); }else @@ -1017,11 +1014,11 @@ decode_intra_mb: if (rc == 1) { val= 0; } else if (rc == 2) { - val= get_bits1(&s->gb)^1; + val= get_bits1(&h->gb)^1; }else{ - val= get_ue_golomb_31(&s->gb); + val= get_ue_golomb_31(&h->gb); if (val >= rc) { - av_log(h->s.avctx, AV_LOG_ERROR, "ref %u overflow\n", val); + av_log(h->avctx, AV_LOG_ERROR, "ref %u overflow\n", val); return -1; } } @@ -1035,9 +1032,9 @@ decode_intra_mb: unsigned int val; if(IS_DIR(mb_type, i, list)){ pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my); - mx += get_se_golomb(&s->gb); - my += get_se_golomb(&s->gb); - tprintf(s->avctx, "final mv:%d %d\n", mx, my); + mx += get_se_golomb(&h->gb); + my += get_se_golomb(&h->gb); + tprintf(h->avctx, "final mv:%d %d\n", mx, my); val= pack16to32(mx,my); }else @@ -1052,18 +1049,18 @@ decode_intra_mb: write_back_motion(h, mb_type); if(!IS_INTRA16x16(mb_type)){ - cbp= get_ue_golomb(&s->gb); + cbp= get_ue_golomb(&h->gb); if(decode_chroma){ if(cbp > 47){ - av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, h->mb_x, h->mb_y); return -1; } if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp]; else cbp= golomb_to_inter_cbp [cbp]; }else{ if(cbp > 15){ - av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); + av_log(h->avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, h->mb_x, h->mb_y); return -1; } if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; @@ -1072,11 +1069,11 @@ decode_intra_mb: } if(dct8x8_allowed && (cbp&15) && !IS_INTRA(mb_type)){ - mb_type |= MB_TYPE_8x8DCT*get_bits1(&s->gb); + mb_type |= MB_TYPE_8x8DCT*get_bits1(&h->gb); } h->cbp= h->cbp_table[mb_xy]= cbp; - s->current_picture.f.mb_type[mb_xy] = mb_type; + h->cur_pic.f.mb_type[mb_xy] = mb_type; if(cbp || IS_INTRA16x16(mb_type)){ int i4x4, i8x8, chroma_idx; @@ -1087,28 +1084,28 @@ decode_intra_mb: const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8); if(IS_INTERLACED(mb_type)){ - scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; - scan= s->qscale ? h->field_scan : h->field_scan_q0; + scan8x8= h->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; + scan= h->qscale ? h->field_scan : h->field_scan_q0; }else{ - scan8x8= s->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; - scan= s->qscale ? h->zigzag_scan : h->zigzag_scan_q0; + scan8x8= h->qscale ? h->zigzag_scan8x8_cavlc : h->zigzag_scan8x8_cavlc_q0; + scan= h->qscale ? h->zigzag_scan : h->zigzag_scan_q0; } - dquant= get_se_golomb(&s->gb); + dquant= get_se_golomb(&h->gb); - s->qscale += dquant; + h->qscale += dquant; - if(((unsigned)s->qscale) > max_qp){ - if(s->qscale<0) s->qscale+= max_qp+1; - else s->qscale-= max_qp+1; - if(((unsigned)s->qscale) > max_qp){ - av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); + if(((unsigned)h->qscale) > max_qp){ + if(h->qscale<0) h->qscale+= max_qp+1; + else h->qscale-= max_qp+1; + if(((unsigned)h->qscale) > max_qp){ + av_log(h->avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, h->mb_x, h->mb_y); return -1; } } - h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale); - h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale); + h->chroma_qp[0]= get_chroma_qp(h, 0, h->qscale); + h->chroma_qp[1]= get_chroma_qp(h, 1, h->qscale); if( (ret = decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ){ return -1; @@ -1176,7 +1173,7 @@ decode_intra_mb: fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); } - s->current_picture.f.qscale_table[mb_xy] = s->qscale; + h->cur_pic.f.qscale_table[mb_xy] = h->qscale; write_back_non_zero_count(h); return 0; |