X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmpeg4videoenc.c;h=741c5971fbf51231112dc73ba6fca10069a5c8d1;hb=657ccb5ac75ce34e62bd67f228d9bd36db72189e;hp=28d026b33265d0325de2596d1adfdfa1e2f9b3f8;hpb=101ada9abd92185d80e6011c7c6b96dc15b69292;p=ffmpeg diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c index 28d026b3326..741c5971fbf 100644 --- a/libavcodec/mpeg4videoenc.c +++ b/libavcodec/mpeg4videoenc.c @@ -3,20 +3,20 @@ * Copyright (c) 2000,2001 Fabrice Bellard * Copyright (c) 2002-2010 Michael Niedermayer * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -54,7 +54,7 @@ max run: 29/41 /** - * Returns the number of bits that encoding the 8x8 block in block would need. + * Return the number of bits that encoding the 8x8 block in block would need. * @param[in] block_last_index last index in scantable order that refers to a non zero element in block. */ static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){ @@ -82,7 +82,7 @@ static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int bloc /** - * Restores the ac coefficients in block that have been changed by decide_ac_pred(). + * Restore the ac coefficients in block that have been changed by decide_ac_pred(). * This function also restores s->block_last_index. * @param[in,out] block MB coefficients, these will be restored * @param[in] dir ac prediction direction for each 8x8 block @@ -113,7 +113,7 @@ static inline void restore_ac_coeffs(MpegEncContext * s, DCTELEM block[6][64], c } /** - * Returns the optimal value (0 or 1) for the ac_pred element for the given MB in mpeg4. + * Return the optimal value (0 or 1) for the ac_pred element for the given MB in mpeg4. * This function will also update s->block_last_index and s->ac_val. * @param[in,out] block MB coefficients, these will be updated if 1 is returned * @param[in] dir ac prediction direction for each 8x8 block @@ -124,7 +124,7 @@ static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], const { int score= 0; int i, n; - int8_t * const qscale_table= s->current_picture.qscale_table; + int8_t * const qscale_table = s->current_picture.f.qscale_table; memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6); @@ -201,11 +201,11 @@ static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], const */ void ff_clean_mpeg4_qscales(MpegEncContext *s){ int i; - int8_t * const qscale_table= s->current_picture.qscale_table; + int8_t * const qscale_table = s->current_picture.f.qscale_table; ff_clean_h263_qscales(s); - if(s->pict_type== FF_B_TYPE){ + if(s->pict_type== AV_PICTURE_TYPE_B){ int odd=0; /* ok, come on, this isn't funny anymore, there's more code for handling this mpeg4 mess than for the actual adaptive quantization */ @@ -296,10 +296,6 @@ static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb) { int i, last_non_zero; -#if 0 //variables for the outcommented version - int code, sign, last; -#endif - const RLTable *rl; uint32_t *bits_tab; uint8_t *len_tab; const int last_index = s->block_last_index[n]; @@ -309,20 +305,17 @@ static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n mpeg4_encode_dc(dc_pb, intra_dc, n); if(last_index<1) return; i = 1; - rl = &ff_mpeg4_rl_intra; bits_tab= uni_mpeg4_intra_rl_bits; len_tab = uni_mpeg4_intra_rl_len; } else { if(last_index<0) return; i = 0; - rl = &ff_h263_rl_inter; bits_tab= uni_mpeg4_inter_rl_bits; len_tab = uni_mpeg4_inter_rl_len; } /* AC coefs */ last_non_zero = i - 1; -#if 1 for (; i < last_index; i++) { int level = block[ scan_table[i] ]; if (level) { @@ -348,64 +341,6 @@ static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); } } -#else - for (; i <= last_index; i++) { - const int slevel = block[ scan_table[i] ]; - if (slevel) { - int level; - int run = i - last_non_zero - 1; - last = (i == last_index); - sign = 0; - level = slevel; - if (level < 0) { - sign = 1; - level = -level; - } - code = get_rl_index(rl, last, run, level); - put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - if (code == rl->n) { - int level1, run1; - level1 = level - rl->max_level[last][run]; - if (level1 < 1) - goto esc2; - code = get_rl_index(rl, last, run, level1); - if (code == rl->n) { - esc2: - put_bits(ac_pb, 1, 1); - if (level > MAX_LEVEL) - goto esc3; - run1 = run - rl->max_run[last][level] - 1; - if (run1 < 0) - goto esc3; - code = get_rl_index(rl, last, run1, level); - if (code == rl->n) { - esc3: - /* third escape */ - put_bits(ac_pb, 1, 1); - put_bits(ac_pb, 1, last); - put_bits(ac_pb, 6, run); - put_bits(ac_pb, 1, 1); - put_sbits(ac_pb, 12, slevel); - put_bits(ac_pb, 1, 1); - } else { - /* second escape */ - put_bits(ac_pb, 1, 0); - put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - put_bits(ac_pb, 1, sign); - } - } else { - /* first escape */ - put_bits(ac_pb, 1, 0); - put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - put_bits(ac_pb, 1, sign); - } - } else { - put_bits(ac_pb, 1, sign); - } - last_non_zero = i; - } - } -#endif } static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, @@ -497,14 +432,14 @@ void mpeg4_encode_mb(MpegEncContext * s, { int cbpc, cbpy, pred_x, pred_y; PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb; - PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=FF_B_TYPE ? &s->tex_pb : &s->pb; - PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=FF_I_TYPE ? &s->pb2 : &s->pb; + PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_B ? &s->tex_pb : &s->pb; + PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_I ? &s->pb2 : &s->pb; const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0; if (!s->mb_intra) { int i, cbp; - if(s->pict_type==FF_B_TYPE){ + if(s->pict_type==AV_PICTURE_TYPE_B){ static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */ int mb_type= mb_type_table[s->mv_dir]; @@ -522,7 +457,7 @@ void mpeg4_encode_mb(MpegEncContext * s, assert(mb_type>=0); /* nothing to do if this MB was skipped in the next P Frame */ - if(s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]){ //FIXME avoid DCT & ... + if (s->next_picture.f.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]) { //FIXME avoid DCT & ... s->skip_count++; s->mv[0][0][0]= s->mv[0][0][1]= @@ -637,7 +572,7 @@ void mpeg4_encode_mb(MpegEncContext * s, s->p_tex_bits+= get_bits_diff(s); } - }else{ /* s->pict_type==FF_B_TYPE */ + }else{ /* s->pict_type==AV_PICTURE_TYPE_B */ cbp= get_p_cbp(s, block, motion_x, motion_y); if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) { @@ -654,7 +589,7 @@ void mpeg4_encode_mb(MpegEncContext * s, if(y+16 > s->height) y= s->height-16; offset= x + y*s->linesize; - p_pic= s->new_picture.data[0] + offset; + p_pic = s->new_picture.f.data[0] + offset; s->mb_skipped=1; for(i=0; imax_b_frames; i++){ @@ -662,10 +597,11 @@ void mpeg4_encode_mb(MpegEncContext * s, int diff; Picture *pic= s->reordered_input_picture[i+1]; - if(pic==NULL || pic->pict_type!=FF_B_TYPE) break; + if (pic == NULL || pic->f.pict_type != AV_PICTURE_TYPE_B) + break; - b_pic= pic->data[0] + offset; - if(pic->type != FF_BUFFER_TYPE_SHARED) + b_pic = pic->f.data[0] + offset; + if (pic->f.type != FF_BUFFER_TYPE_SHARED) b_pic+= INPLACE_OFFSET; diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16); if(diff>s->qscale*70){ //FIXME check that 70 is optimal @@ -769,8 +705,8 @@ void mpeg4_encode_mb(MpegEncContext * s, /* motion vectors: 8x8 mode*/ h263_pred_motion(s, i, 0, &pred_x, &pred_y); - ff_h263_encode_motion_vector(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, - s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code); + ff_h263_encode_motion_vector(s, s->current_picture.f.motion_val[0][ s->block_index[i] ][0] - pred_x, + s->current_picture.f.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code); } } @@ -812,7 +748,7 @@ void mpeg4_encode_mb(MpegEncContext * s, } cbpc = cbp & 3; - if (s->pict_type == FF_I_TYPE) { + if (s->pict_type == AV_PICTURE_TYPE_I) { if(s->dquant) cbpc+=4; put_bits(&s->pb, ff_h263_intra_MCBPC_bits[cbpc], @@ -864,7 +800,7 @@ void ff_mpeg4_stuffing(PutBitContext * pbc) /* must be called before writing the header */ void ff_set_mpeg4_time(MpegEncContext * s){ - if(s->pict_type==FF_B_TYPE){ + if(s->pict_type==AV_PICTURE_TYPE_B){ ff_mpeg4_init_direct_mv(s); }else{ s->last_time_base= s->time_base; @@ -879,9 +815,9 @@ static void mpeg4_encode_gop_header(MpegEncContext * s){ put_bits(&s->pb, 16, 0); put_bits(&s->pb, 16, GOP_STARTCODE); - time= s->current_picture_ptr->pts; + time = s->current_picture_ptr->f.pts; if(s->reordered_input_picture[1]) - time= FFMIN(time, s->reordered_input_picture[1]->pts); + time = FFMIN(time, s->reordered_input_picture[1]->f.pts); time= time*s->avctx->time_base.num; seconds= time/s->avctx->time_base.den; @@ -1054,7 +990,7 @@ void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) int time_incr; int time_div, time_mod; - if(s->pict_type==FF_I_TYPE){ + if(s->pict_type==AV_PICTURE_TYPE_I){ if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){ if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) //HACK, the reference sw is buggy mpeg4_encode_visual_object_header(s); @@ -1065,7 +1001,7 @@ void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) mpeg4_encode_gop_header(s); } - s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; + s->partitioned_frame= s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_B; put_bits(&s->pb, 16, 0); /* vop header */ put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */ @@ -1085,22 +1021,22 @@ void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */ put_bits(&s->pb, 1, 1); /* marker */ put_bits(&s->pb, 1, 1); /* vop coded */ - if ( s->pict_type == FF_P_TYPE - || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { + if ( s->pict_type == AV_PICTURE_TYPE_P + || (s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE)) { put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ } put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */ if(!s->progressive_sequence){ - put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first); + put_bits(&s->pb, 1, s->current_picture_ptr->f.top_field_first); put_bits(&s->pb, 1, s->alternate_scan); } //FIXME sprite stuff put_bits(&s->pb, 5, s->qscale); - if (s->pict_type != FF_I_TYPE) + if (s->pict_type != AV_PICTURE_TYPE_I) put_bits(&s->pb, 3, s->f_code); /* fcode_for */ - if (s->pict_type == FF_B_TYPE) + if (s->pict_type == AV_PICTURE_TYPE_B) put_bits(&s->pb, 3, s->b_code); /* fcode_back */ } @@ -1305,7 +1241,7 @@ void ff_mpeg4_merge_partitions(MpegEncContext *s) const int tex_pb_len= put_bits_count(&s->tex_pb); const int bits= put_bits_count(&s->pb); - if(s->pict_type==FF_I_TYPE){ + if(s->pict_type==AV_PICTURE_TYPE_I){ put_bits(&s->pb, 19, DC_MARKER); s->misc_bits+=19 + pb2_len + bits - s->last_bits; s->i_tex_bits+= tex_pb_len; @@ -1338,15 +1274,15 @@ void ff_mpeg4_encode_video_packet_header(MpegEncContext *s) put_bits(&s->pb, 1, 0); /* no HEC */ } -AVCodec mpeg4_encoder = { +AVCodec ff_mpeg4_encoder = { "mpeg4", - CODEC_TYPE_VIDEO, + AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG4, sizeof(MpegEncContext), encode_init, MPV_encode_picture, MPV_encode_end, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, - .capabilities= CODEC_CAP_DELAY, + .capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), };