diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-04-28 23:18:35 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-06-12 12:03:00 +0200 |
commit | b2ac792367382bcc90fa39290161c937f934b01a (patch) | |
tree | 8b4f6fcbfbec1a3f600840f1ffdf2119702f1e46 | |
parent | 2f6768c761ebdd50e6c6fc5ade0ed19fd647842f (diff) | |
download | ffmpeg-b2ac792367382bcc90fa39290161c937f934b01a.tar.gz |
avcodec/mpegvideo: Use enum for msmpeg4_version
Improves readability.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r-- | libavcodec/h263dec.c | 34 | ||||
-rw-r--r-- | libavcodec/motion_est.c | 8 | ||||
-rw-r--r-- | libavcodec/mpegvideo.c | 6 | ||||
-rw-r--r-- | libavcodec/mpegvideo.h | 10 | ||||
-rw-r--r-- | libavcodec/mpegvideo_enc.c | 28 | ||||
-rw-r--r-- | libavcodec/mpv_reconstruct_mb_template.c | 2 | ||||
-rw-r--r-- | libavcodec/msmpeg4.c | 17 | ||||
-rw-r--r-- | libavcodec/msmpeg4dec.c | 68 | ||||
-rw-r--r-- | libavcodec/msmpeg4enc.c | 37 | ||||
-rw-r--r-- | libavcodec/vc1dec.c | 2 |
10 files changed, 114 insertions, 98 deletions
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index b9762be9c9..eee7978452 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -113,23 +113,23 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) break; case AV_CODEC_ID_MSMPEG4V1: s->h263_pred = 1; - s->msmpeg4_version = 1; + s->msmpeg4_version = MSMP4_V1; break; case AV_CODEC_ID_MSMPEG4V2: s->h263_pred = 1; - s->msmpeg4_version = 2; + s->msmpeg4_version = MSMP4_V2; break; case AV_CODEC_ID_MSMPEG4V3: s->h263_pred = 1; - s->msmpeg4_version = 3; + s->msmpeg4_version = MSMP4_V3; break; case AV_CODEC_ID_WMV1: s->h263_pred = 1; - s->msmpeg4_version = 4; + s->msmpeg4_version = MSMP4_WMV1; break; case AV_CODEC_ID_WMV2: s->h263_pred = 1; - s->msmpeg4_version = 5; + s->msmpeg4_version = MSMP4_WMV2; break; case AV_CODEC_ID_H263I: break; @@ -227,7 +227,7 @@ static int decode_slice(MpegEncContext *s) for (; s->mb_y < s->mb_height; s->mb_y++) { /* per-row end of slice checks */ - if (s->msmpeg4_version) { + if (s->msmpeg4_version != MSMP4_UNUSED) { if (s->resync_mb_y + s->slice_height == s->mb_y) { ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x - 1, s->mb_y, ER_MB_END); @@ -236,7 +236,7 @@ static int decode_slice(MpegEncContext *s) } } - if (s->msmpeg4_version == 1) { + if (s->msmpeg4_version == MSMP4_V1) { s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128; @@ -375,12 +375,12 @@ static int decode_slice(MpegEncContext *s) } // handle formats which don't have unique end markers - if (s->msmpeg4_version || (s->workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly + if (s->msmpeg4_version != MSMP4_UNUSED || (s->workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly int left = get_bits_left(&s->gb); int max_extra = 7; /* no markers in M$ crap */ - if (s->msmpeg4_version && s->pict_type == AV_PICTURE_TYPE_I) + if (s->msmpeg4_version != MSMP4_UNUSED && s->pict_type == AV_PICTURE_TYPE_I) max_extra += 17; /* buggy padding but the frame should still end approximately at @@ -474,10 +474,12 @@ retry: return ret; /* let's go :-) */ - if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) { + if (CONFIG_WMV2_DECODER && s->msmpeg4_version == MSMP4_WMV2) { ret = ff_wmv2_decode_picture_header(s); - } else if (CONFIG_MSMPEG4DEC && s->msmpeg4_version) { +#if CONFIG_MSMPEG4DEC + } else if (s->msmpeg4_version != MSMP4_UNUSED) { ret = ff_msmpeg4_decode_picture_header(s); +#endif } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) { ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0, 0); s->skipped_last_frame = (ret == FRAME_SKIPPED); @@ -583,13 +585,15 @@ retry: /* the second part of the wmv2 header contains the MB skip bits which * are stored in current_picture->mb_type which is not available before * ff_mpv_frame_start() */ - if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) { +#if CONFIG_WMV2_DECODER + if (s->msmpeg4_version == MSMP4_WMV2) { ret = ff_wmv2_decode_secondary_picture_header(s); if (ret < 0) return ret; if (ret == 1) goto frame_end; } +#endif /* decode each macroblock */ s->mb_x = 0; @@ -597,7 +601,7 @@ retry: slice_ret = decode_slice(s); while (s->mb_y < s->mb_height) { - if (s->msmpeg4_version) { + if (s->msmpeg4_version != MSMP4_UNUSED) { if (s->slice_height == 0 || s->mb_x != 0 || slice_ret < 0 || (s->mb_y % s->slice_height) != 0 || get_bits_left(&s->gb) < 0) break; @@ -609,14 +613,14 @@ retry: s->er.error_occurred = 1; } - if (s->msmpeg4_version < 4 && s->h263_pred) + if (s->msmpeg4_version < MSMP4_WMV1 && s->h263_pred) ff_mpeg4_clean_buffers(s); if (decode_slice(s) < 0) slice_ret = AVERROR_INVALIDDATA; } - if (s->msmpeg4_version && s->msmpeg4_version < 4 && + if (s->msmpeg4_version != MSMP4_UNUSED && s->msmpeg4_version < MSMP4_WMV1 && s->pict_type == AV_PICTURE_TYPE_I) if (!CONFIG_MSMPEG4DEC || ff_msmpeg4_decode_ext_header(s, buf_size) < 0) diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index fcef47a623..162472d693 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -1609,7 +1609,7 @@ int ff_get_best_fcode(MpegEncContext * s, const int16_t (*mv_table)[2], int type int best_fcode=-1; int best_score=-10000000; - if(s->msmpeg4_version) + if (s->msmpeg4_version != MSMP4_UNUSED) range= FFMIN(range, 16); else if(s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) range= FFMIN(range, 256); @@ -1660,9 +1660,9 @@ void ff_fix_long_p_mvs(MpegEncContext * s, int type) int y, range; av_assert0(s->pict_type==AV_PICTURE_TYPE_P); - range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code); + range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version != MSMP4_UNUSED) ? 8 : 16) << f_code); - av_assert0(range <= 16 || !s->msmpeg4_version); + av_assert0(range <= 16 || s->msmpeg4_version == MSMP4_UNUSED); av_assert0(range <=256 || !(s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)); if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range; @@ -1709,7 +1709,7 @@ void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_ int y, h_range, v_range; // RAL: 8 in MPEG-1, 16 in MPEG-4 - int range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code); + int range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version != MSMP4_UNUSED) ? 8 : 16) << f_code); if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range; diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index c5ed4701d0..4fe9350c40 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -381,7 +381,7 @@ static int init_duplicate_context(MpegEncContext *s) s->block = s->blocks[0]; if (s->out_format == FMT_H263) { - int mb_height = s->msmpeg4_version == 6 /* VC-1 like */ ? + int mb_height = s->msmpeg4_version == MSMP4_VC1 ? FFALIGN(s->mb_height, 2) : s->mb_height; int y_size = s->b8_stride * (2 * mb_height + 1); int c_size = s->mb_stride * (mb_height + 1); @@ -535,7 +535,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s) /* VC-1 can change from being progressive to interlaced on a per-frame * basis. We therefore allocate certain buffers so big that they work * in both instances. */ - mb_height = s->msmpeg4_version == 6 /* VC-1 like*/ ? + mb_height = s->msmpeg4_version == MSMP4_VC1 ? FFALIGN(s->mb_height, 2) : s->mb_height; s->mb_width = (s->width + 15) / 16; @@ -602,7 +602,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s) } } - if (s->msmpeg4_version >= 3) { + if (s->msmpeg4_version >= MSMP4_V3) { s->coded_block_base = av_mallocz(y_size); if (!s->coded_block_base) return AVERROR(ENOMEM); diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 5af74acf95..8351f806b4 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -418,7 +418,15 @@ typedef struct MpegEncContext { int slice_height; ///< in macroblocks int first_slice_line; ///< used in MPEG-4 too to handle resync markers int flipflop_rounding; - int msmpeg4_version; ///< 0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8 + enum { + MSMP4_UNUSED, + MSMP4_V1, + MSMP4_V2, + MSMP4_V3, + MSMP4_WMV1, + MSMP4_WMV2, + MSMP4_VC1, ///< for VC1 (image), WMV3 (image) and MSS2. + } msmpeg4_version; int per_mb_rl_table; int esc3_level_length; int esc3_run_length; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 6d1dbccf5f..64b6696c51 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -754,7 +754,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->out_format = FMT_H263; s->h263_pred = 1; s->unrestricted_mv = 1; - s->msmpeg4_version = 2; + s->msmpeg4_version = MSMP4_V2; avctx->delay = 0; s->low_delay = 1; break; @@ -762,7 +762,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->out_format = FMT_H263; s->h263_pred = 1; s->unrestricted_mv = 1; - s->msmpeg4_version = 3; + s->msmpeg4_version = MSMP4_V3; s->flipflop_rounding = 1; avctx->delay = 0; s->low_delay = 1; @@ -771,7 +771,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->out_format = FMT_H263; s->h263_pred = 1; s->unrestricted_mv = 1; - s->msmpeg4_version = 4; + s->msmpeg4_version = MSMP4_WMV1; s->flipflop_rounding = 1; avctx->delay = 0; s->low_delay = 1; @@ -780,7 +780,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->out_format = FMT_H263; s->h263_pred = 1; s->unrestricted_mv = 1; - s->msmpeg4_version = 5; + s->msmpeg4_version = MSMP4_WMV2; s->flipflop_rounding = 1; avctx->delay = 0; s->low_delay = 1; @@ -916,8 +916,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) if (CONFIG_H263_ENCODER && s->out_format == FMT_H263) { ff_h263_encode_init(s); - if (CONFIG_MSMPEG4ENC && s->msmpeg4_version) +#if CONFIG_MSMPEG4ENC + if (s->msmpeg4_version != MSMP4_UNUSED) ff_msmpeg4_encode_init(s); +#endif } /* init q matrix */ @@ -3456,9 +3458,12 @@ static int encode_thread(AVCodecContext *c, void *arg){ } } +#if CONFIG_MSMPEG4ENC //not beautiful here but we must write it before flushing so it has to be here - if (CONFIG_MSMPEG4ENC && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == AV_PICTURE_TYPE_I) + if (s->msmpeg4_version != MSMP4_UNUSED && s->msmpeg4_version < MSMP4_WMV1 && + s->pict_type == AV_PICTURE_TYPE_I) ff_msmpeg4_encode_ext_header(s); +#endif write_slice_end(s); @@ -3561,7 +3566,7 @@ static int encode_picture(MpegEncContext *s, const AVPacket *pkt) /* we need to initialize some time vars before we can encode B-frames */ // RAL: Condition added for MPEG1VIDEO - if (s->out_format == FMT_MPEG1 || (s->h263_pred && !s->msmpeg4_version)) + if (s->out_format == FMT_MPEG1 || (s->h263_pred && s->msmpeg4_version == MSMP4_UNUSED)) set_frame_distances(s); if(CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4) ff_set_mpeg4_time(s); @@ -3571,8 +3576,7 @@ static int encode_picture(MpegEncContext *s, const AVPacket *pkt) // s->lambda= s->cur_pic.ptr->quality; //FIXME qscale / ... stuff for ME rate distortion if(s->pict_type==AV_PICTURE_TYPE_I){ - if(s->msmpeg4_version >= 3) s->no_rounding=1; - else s->no_rounding=0; + s->no_rounding = s->msmpeg4_version >= MSMP4_V3; }else if(s->pict_type!=AV_PICTURE_TYPE_B){ if(s->flipflop_rounding || s->codec_id == AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_MPEG4) s->no_rounding ^= 1; @@ -3654,7 +3658,7 @@ static int encode_picture(MpegEncContext *s, const AVPacket *pkt) s->pict_type= AV_PICTURE_TYPE_I; for(i=0; i<s->mb_stride*s->mb_height; i++) s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; - if(s->msmpeg4_version >= 3) + if (s->msmpeg4_version >= MSMP4_V3) s->no_rounding=1; ff_dlog(s, "Scene change detected, encoding as I Frame %"PRId64" %"PRId64"\n", s->mb_var_sum, s->mc_mb_var_sum); @@ -3798,8 +3802,10 @@ static int encode_picture(MpegEncContext *s, const AVPacket *pkt) case FMT_H263: if (CONFIG_WMV2_ENCODER && s->codec_id == AV_CODEC_ID_WMV2) ff_wmv2_encode_picture_header(s); - else if (CONFIG_MSMPEG4ENC && s->msmpeg4_version) +#if CONFIG_MSMPEG4ENC + else if (s->msmpeg4_version != MSMP4_UNUSED) ff_msmpeg4_encode_picture_header(s); +#endif else if (CONFIG_MPEG4_ENCODER && s->h263_pred) { ret = ff_mpeg4_encode_picture_header(s); if (ret < 0) diff --git a/libavcodec/mpv_reconstruct_mb_template.c b/libavcodec/mpv_reconstruct_mb_template.c index 9aacf380a1..6ad353ddfd 100644 --- a/libavcodec/mpv_reconstruct_mb_template.c +++ b/libavcodec/mpv_reconstruct_mb_template.c @@ -173,7 +173,7 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], } /* add dct residue */ - if (!(IS_MPEG12(s) || s->msmpeg4_version || + if (!(IS_MPEG12(s) || s->msmpeg4_version != MSMP4_UNUSED || (s->codec_id == AV_CODEC_ID_MPEG4 && !s->mpeg_quant))) #endif /* !IS_ENCODER */ { diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c index f7ebb8ba89..50fd581a83 100644 --- a/libavcodec/msmpeg4.c +++ b/libavcodec/msmpeg4.c @@ -120,12 +120,12 @@ av_cold void ff_msmpeg4_common_init(MpegEncContext *s) static AVOnce init_static_once = AV_ONCE_INIT; switch(s->msmpeg4_version){ - case 1: - case 2: + case MSMP4_V1: + case MSMP4_V2: s->y_dc_scale_table= s->c_dc_scale_table= ff_mpeg1_dc_scale_table; break; - case 3: + case MSMP4_V3: if(s->workaround_bugs){ s->y_dc_scale_table= ff_old_ff_y_dc_scale_table; s->c_dc_scale_table= ff_wmv1_c_dc_scale_table; @@ -134,14 +134,14 @@ av_cold void ff_msmpeg4_common_init(MpegEncContext *s) s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; } break; - case 4: - case 5: + case MSMP4_WMV1: + case MSMP4_WMV2: s->y_dc_scale_table= ff_wmv1_y_dc_scale_table; s->c_dc_scale_table= ff_wmv1_c_dc_scale_table; break; } - if(s->msmpeg4_version>=4){ + if (s->msmpeg4_version >= MSMP4_WMV1) { ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_wmv1_scantable[1]); ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_wmv1_scantable[0]); ff_permute_scantable(s->permutated_intra_h_scantable, ff_wmv1_scantable[2], @@ -218,9 +218,8 @@ int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, b = dc_val[ - 1 - wrap]; c = dc_val[ - wrap]; - if(s->first_slice_line && (n&2)==0 && s->msmpeg4_version<4){ + if (s->first_slice_line && !(n & 2) && s->msmpeg4_version < MSMP4_WMV1) b=c=1024; - } /* XXX: the following solution consumes divisions, but it does not necessitate to modify mpegvideo.c. The problem comes from the @@ -259,7 +258,7 @@ int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, #endif /* XXX: WARNING: they did not choose the same test as MPEG-4. This is very important ! */ - if(s->msmpeg4_version>3){ + if (s->msmpeg4_version > MSMP4_V3) { if(s->inter_intra_pred){ uint8_t *dest; int wrap; diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c index 4143c46c15..209e1fe1b2 100644 --- a/libavcodec/msmpeg4dec.c +++ b/libavcodec/msmpeg4dec.c @@ -125,7 +125,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64]) } } - if(s->msmpeg4_version==2) + if (s->msmpeg4_version == MSMP4_V2) code = get_vlc2(&s->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1); else code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2); @@ -139,7 +139,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64]) cbp = code & 0x3; } else { s->mb_intra = 1; - if(s->msmpeg4_version==2) + if (s->msmpeg4_version == MSMP4_V2) cbp = get_vlc2(&s->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1); else cbp = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2); @@ -159,7 +159,8 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64]) } cbp|= cbpy<<2; - if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C; + if (s->msmpeg4_version == MSMP4_V1 || (cbp&3) != 3) + cbp ^= 0x3C; ff_h263_pred_motion(s, 0, 0, &mx, &my); mx= msmpeg4v2_decode_motion(s, mx, 1); @@ -172,7 +173,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64]) *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16; } else { int v; - if(s->msmpeg4_version==2){ + if (s->msmpeg4_version == MSMP4_V2) { s->ac_pred = get_bits1(&s->gb); v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); if (v < 0) { @@ -366,16 +367,16 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) ff_msmpeg4_common_init(s); - switch(s->msmpeg4_version){ - case 1: - case 2: + switch (s->msmpeg4_version) { + case MSMP4_V1: + case MSMP4_V2: s->decode_mb= msmpeg4v12_decode_mb; break; - case 3: - case 4: + case MSMP4_V3: + case MSMP4_WMV1: s->decode_mb= msmpeg4v34_decode_mb; break; - case 5: + case MSMP4_WMV2: break; } @@ -398,7 +399,7 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16)) return AVERROR_INVALIDDATA; - if(s->msmpeg4_version==1){ + if (s->msmpeg4_version == MSMP4_V1) { int start_code = get_bits_long(&s->gb, 32); if(start_code!=0x00000100){ av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n"); @@ -422,7 +423,7 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) if (s->pict_type == AV_PICTURE_TYPE_I) { code = get_bits(&s->gb, 5); - if(s->msmpeg4_version==1){ + if (s->msmpeg4_version == MSMP4_V1) { if(code==0 || code>s->mb_height){ av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code); return -1; @@ -440,20 +441,20 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) } switch(s->msmpeg4_version){ - case 1: - case 2: + case MSMP4_V1: + case MSMP4_V2: s->rl_chroma_table_index = 2; s->rl_table_index = 2; s->dc_table_index = 0; //not used break; - case 3: + case MSMP4_V3: s->rl_chroma_table_index = decode012(&s->gb); s->rl_table_index = decode012(&s->gb); s->dc_table_index = get_bits1(&s->gb); break; - case 4: + case MSMP4_WMV1: ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8); if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb); @@ -479,9 +480,9 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) s->slice_height); } else { switch(s->msmpeg4_version){ - case 1: - case 2: - if(s->msmpeg4_version==1) + case MSMP4_V1: + case MSMP4_V2: + if (s->msmpeg4_version == MSMP4_V1) s->use_skip_mb_code = 1; else s->use_skip_mb_code = get_bits1(&s->gb); @@ -490,7 +491,7 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) s->dc_table_index = 0; //not used s->mv_table_index = 0; break; - case 3: + case MSMP4_V3: s->use_skip_mb_code = get_bits1(&s->gb); s->rl_table_index = decode012(&s->gb); s->rl_chroma_table_index = s->rl_table_index; @@ -499,7 +500,7 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) s->mv_table_index = get_bits1(&s->gb); break; - case 4: + case MSMP4_WMV1: s->use_skip_mb_code = get_bits1(&s->gb); if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb); @@ -545,13 +546,13 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size) { int left= buf_size*8 - get_bits_count(&s->gb); - int length= s->msmpeg4_version>=3 ? 17 : 16; + int length = s->msmpeg4_version >= MSMP4_V3 ? 17 : 16; /* the alt_bitstream reader could read over the end so we need to check it */ if(left>=length && left<length+8) { skip_bits(&s->gb, 5); /* fps */ s->bit_rate= get_bits(&s->gb, 11)*1024; - if(s->msmpeg4_version>=3) + if (s->msmpeg4_version >= MSMP4_V3) s->flipflop_rounding= get_bits1(&s->gb); else s->flipflop_rounding= 0; @@ -559,7 +560,7 @@ int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size) else if(left<length+8) { s->flipflop_rounding= 0; - if(s->msmpeg4_version != 2) + if (s->msmpeg4_version != MSMP4_V2) av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left); } else @@ -574,7 +575,7 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) { int level, pred; - if(s->msmpeg4_version<=2){ + if (s->msmpeg4_version <= MSMP4_V2) { if (n < 4) { level = get_vlc2(&s->gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3); } else { @@ -600,7 +601,7 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) } } - if(s->msmpeg4_version==1){ + if (s->msmpeg4_version == MSMP4_V1) { int32_t *dc_val; pred = msmpeg4v1_pred_dc(s, n, &dc_val); level += pred; @@ -658,7 +659,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, } block[0] = level; - run_diff = s->msmpeg4_version >= 4; + run_diff = s->msmpeg4_version >= MSMP4_WMV1; i = 0; if (!coded) { goto not_coded; @@ -678,7 +679,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, i = -1; rl = &ff_rl_table[3 + s->rl_table_index]; - if(s->msmpeg4_version==2) + if (s->msmpeg4_version == MSMP4_V2) run_diff = 0; else run_diff = 1; @@ -700,12 +701,13 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, int cache; cache= GET_CACHE(re, &s->gb); /* escape */ - if (s->msmpeg4_version==1 || (cache&0x80000000)==0) { - if (s->msmpeg4_version==1 || (cache&0x40000000)==0) { + if (s->msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) { + if (s->msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) { /* third escape */ - if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2); + if (s->msmpeg4_version != MSMP4_V1) + LAST_SKIP_BITS(re, &s->gb, 2); UPDATE_CACHE(re, &s->gb); - if(s->msmpeg4_version<=3){ + if (s->msmpeg4_version <= MSMP4_V3) { last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6); level= SHOW_SBITS(re, &s->gb, 8); @@ -804,7 +806,7 @@ int ff_msmpeg4_decode_block(MpegEncContext * s, int16_t * block, i = 63; /* XXX: not optimal */ } } - if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize + if (s->msmpeg4_version >= MSMP4_WMV1 && i > 0) i=63; //FIXME/XXX optimize s->block_last_index[n] = i; return 0; diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c index 5e6bc231d4..642a0ff100 100644 --- a/libavcodec/msmpeg4enc.c +++ b/libavcodec/msmpeg4enc.c @@ -141,7 +141,7 @@ av_cold void ff_msmpeg4_encode_init(MpegEncContext *s) static AVOnce init_static_once = AV_ONCE_INIT; ff_msmpeg4_common_init(s); - if (s->msmpeg4_version >= 4) { + if (s->msmpeg4_version >= MSMP4_WMV1) { s->min_qcoeff = -255; s->max_qcoeff = 255; } @@ -226,7 +226,7 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s) put_bits(&s->pb, 2, s->pict_type - 1); put_bits(&s->pb, 5, s->qscale); - if(s->msmpeg4_version<=2){ + if (s->msmpeg4_version <= MSMP4_V2) { s->rl_table_index = 2; s->rl_chroma_table_index = 2; } @@ -235,7 +235,7 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s) s->mv_table_index = 1; /* only if P-frame */ s->use_skip_mb_code = 1; /* only if P-frame */ s->per_mb_rl_table = 0; - if(s->msmpeg4_version==4) + if (s->msmpeg4_version == MSMP4_WMV1) s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P); ff_dlog(s, "%d %"PRId64" %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height); @@ -244,13 +244,13 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s) s->slice_height= s->mb_height/1; put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height); - if(s->msmpeg4_version==4){ + if (s->msmpeg4_version == MSMP4_WMV1) { ff_msmpeg4_encode_ext_header(s); if(s->bit_rate>MBAC_BITRATE) put_bits(&s->pb, 1, s->per_mb_rl_table); } - if(s->msmpeg4_version>2){ + if (s->msmpeg4_version > MSMP4_V2) { if(!s->per_mb_rl_table){ ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index); ff_msmpeg4_code012(&s->pb, s->rl_table_index); @@ -261,10 +261,10 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s) } else { put_bits(&s->pb, 1, s->use_skip_mb_code); - if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE) + if (s->msmpeg4_version == MSMP4_WMV1 && s->bit_rate > MBAC_BITRATE) put_bits(&s->pb, 1, s->per_mb_rl_table); - if(s->msmpeg4_version>2){ + if (s->msmpeg4_version > MSMP4_V2) { if(!s->per_mb_rl_table) ff_msmpeg4_code012(&s->pb, s->rl_table_index); @@ -298,7 +298,7 @@ FF_ENABLE_DEPRECATION_WARNINGS put_bits(&s->pb, 11, FFMIN(s->bit_rate / 1024, 2047)); - if (s->msmpeg4_version >= 3) + if (s->msmpeg4_version >= MSMP4_V3) put_bits(&s->pb, 1, s->flipflop_rounding); else av_assert0(!s->flipflop_rounding); @@ -340,7 +340,7 @@ void ff_msmpeg4_encode_motion(MpegEncContext * s, void ff_msmpeg4_handle_slices(MpegEncContext *s){ if (s->mb_x == 0) { if (s->slice_height && (s->mb_y % s->slice_height) == 0) { - if(s->msmpeg4_version < 4){ + if (s->msmpeg4_version < MSMP4_WMV1) { ff_mpeg4_clean_buffers(s); } s->first_slice_line = 1; @@ -410,7 +410,7 @@ void ff_msmpeg4_encode_mb(MpegEncContext * s, if (s->use_skip_mb_code) put_bits(&s->pb, 1, 0); /* mb coded */ - if(s->msmpeg4_version<=2){ + if (s->msmpeg4_version <= MSMP4_V2) { put_bits(&s->pb, ff_v2_mb_type[cbp&3][1], ff_v2_mb_type[cbp&3][0]); @@ -452,7 +452,7 @@ void ff_msmpeg4_encode_mb(MpegEncContext * s, int val = (s->block_last_index[i] >= 1); cbp |= val << (5 - i); } - if(s->msmpeg4_version<=2){ + if (s->msmpeg4_version <= MSMP4_V2) { if (s->pict_type == AV_PICTURE_TYPE_I) { put_bits(&s->pb, ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]); @@ -524,7 +524,7 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr /* do the prediction */ level -= pred; - if(s->msmpeg4_version<=2){ + if (s->msmpeg4_version <= MSMP4_V2) { if (n < 4) { put_bits(&s->pb, ff_v2_dc_lum_table[level + 256][1], @@ -575,20 +575,17 @@ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n) } else { rl = &ff_rl_table[3 + s->rl_chroma_table_index]; } - run_diff = s->msmpeg4_version>=4; + run_diff = s->msmpeg4_version >= MSMP4_WMV1; scantable= s->intra_scantable.permutated; } else { i = 0; rl = &ff_rl_table[3 + s->rl_table_index]; - if(s->msmpeg4_version<=2) - run_diff = 0; - else - run_diff = 1; + run_diff = s->msmpeg4_version > MSMP4_V2; scantable= s->inter_scantable.permutated; } /* recalculate block_last_index for M$ wmv1 */ - if (s->msmpeg4_version >= 4 && s->block_last_index[n] > 0) { + if (s->msmpeg4_version >= MSMP4_WMV1 && s->block_last_index[n] > 0) { for(last_index=63; last_index>=0; last_index--){ if(block[scantable[last_index]]) break; } @@ -634,7 +631,7 @@ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n) if (run1 < 0) goto esc3; code = get_rl_index(rl, last, run1+1, level); - if (s->msmpeg4_version == 4 && code == rl->n) + if (s->msmpeg4_version == MSMP4_WMV1 && code == rl->n) goto esc3; code = get_rl_index(rl, last, run1, level); if (code == rl->n) { @@ -642,7 +639,7 @@ void ff_msmpeg4_encode_block(MpegEncContext * s, int16_t * block, int n) /* third escape */ put_bits(&s->pb, 1, 0); put_bits(&s->pb, 1, last); - if(s->msmpeg4_version>=4){ + if (s->msmpeg4_version >= MSMP4_WMV1) { if(s->esc3_level_length==0){ s->esc3_level_length=8; s->esc3_run_length= 6; diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 17da7ed7cd..4b31860c3f 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -610,7 +610,7 @@ av_cold void ff_vc1_init_common(VC1Context *v) s->out_format = FMT_H263; s->h263_pred = 1; - s->msmpeg4_version = 6; + s->msmpeg4_version = MSMP4_VC1; ff_vc1dsp_init(&v->vc1dsp); |