1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

avcodec/mpegvideo: Move fields only used by H.263 decoders to H263DecCtx

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-06-20 00:44:04 +02:00
parent f1c56c08ed
commit 7db6267b30
10 changed files with 86 additions and 80 deletions

View File

@@ -89,13 +89,13 @@ int ff_flv_decode_picture_header(H263DecContext *const h)
skip_bits1(&h->gb); /* deblocking flag */ skip_bits1(&h->gb); /* deblocking flag */
h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5); h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
h->c.h263_long_vectors = 0; h->h263_long_vectors = 0;
/* PEI */ /* PEI */
if (skip_1stop_8data_bits(&h->gb) < 0) if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
if (h->c.ehc_mode) if (h->ehc_mode)
h->c.avctx->sample_aspect_ratio= (AVRational){1,2}; h->c.avctx->sample_aspect_ratio= (AVRational){1,2};
if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) { if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {

View File

@@ -157,7 +157,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263")) if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263"))
if (avctx->extradata_size == 56 && avctx->extradata[0] == 1) if (avctx->extradata_size == 56 && avctx->extradata[0] == 1)
s->ehc_mode = 1; h->ehc_mode = 1;
/* for H.263, we allocate the images after having read the header */ /* for H.263, we allocate the images after having read the header */
if (avctx->codec->id != AV_CODEC_ID_H263 && if (avctx->codec->id != AV_CODEC_ID_H263 &&
@@ -279,7 +279,7 @@ static int decode_slice(H263DecContext *const h)
ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
h->c.mb_x, h->c.mb_y, ER_MB_END & part_mask); h->c.mb_x, h->c.mb_y, ER_MB_END & part_mask);
h->c.padding_bug_score--; h->padding_bug_score--;
if (++h->c.mb_x >= h->c.mb_width) { if (++h->c.mb_x >= h->c.mb_width) {
h->c.mb_x = 0; h->c.mb_x = 0;
@@ -324,7 +324,7 @@ static int decode_slice(H263DecContext *const h)
get_bits_left(&h->gb) >= 48 && get_bits_left(&h->gb) >= 48 &&
show_bits(&h->gb, 24) == 0x4010 && show_bits(&h->gb, 24) == 0x4010 &&
!h->c.data_partitioning) !h->c.data_partitioning)
h->c.padding_bug_score += 32; h->padding_bug_score += 32;
/* try to detect the padding bug */ /* try to detect the padding bug */
if (h->c.codec_id == AV_CODEC_ID_MPEG4 && if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
@@ -336,18 +336,18 @@ static int decode_slice(H263DecContext *const h)
const int bits_left = h->gb.size_in_bits - bits_count; const int bits_left = h->gb.size_in_bits - bits_count;
if (bits_left == 0) { if (bits_left == 0) {
h->c.padding_bug_score += 16; h->padding_bug_score += 16;
} else if (bits_left != 1) { } else if (bits_left != 1) {
int v = show_bits(&h->gb, 8); int v = show_bits(&h->gb, 8);
v |= 0x7F >> (7 - (bits_count & 7)); v |= 0x7F >> (7 - (bits_count & 7));
if (v == 0x7F && bits_left <= 8) if (v == 0x7F && bits_left <= 8)
h->c.padding_bug_score--; h->padding_bug_score--;
else if (v == 0x7F && ((get_bits_count(&h->gb) + 8) & 8) && else if (v == 0x7F && ((get_bits_count(&h->gb) + 8) & 8) &&
bits_left <= 16) bits_left <= 16)
h->c.padding_bug_score += 4; h->padding_bug_score += 4;
else else
h->c.padding_bug_score++; h->padding_bug_score++;
} }
} }
@@ -359,7 +359,7 @@ static int decode_slice(H263DecContext *const h)
show_bits(&h->gb, 8) == 0 && show_bits(&h->gb, 8) == 0 &&
!h->c.data_partitioning) { !h->c.data_partitioning) {
h->c.padding_bug_score += 32; h->padding_bug_score += 32;
} }
if (h->c.codec_id == AV_CODEC_ID_H263 && if (h->c.codec_id == AV_CODEC_ID_H263 &&
@@ -367,12 +367,12 @@ static int decode_slice(H263DecContext *const h)
get_bits_left(&h->gb) >= 64 && get_bits_left(&h->gb) >= 64 &&
AV_RB64(h->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) { AV_RB64(h->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
h->c.padding_bug_score += 32; h->padding_bug_score += 32;
} }
if (h->c.workaround_bugs & FF_BUG_AUTODETECT) { if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
if ( if (
(h->c.padding_bug_score > -2 && !h->c.data_partitioning)) (h->padding_bug_score > -2 && !h->c.data_partitioning))
h->c.workaround_bugs |= FF_BUG_NO_PADDING; h->c.workaround_bugs |= FF_BUG_NO_PADDING;
else else
h->c.workaround_bugs &= ~FF_BUG_NO_PADDING; h->c.workaround_bugs &= ~FF_BUG_NO_PADDING;
@@ -410,7 +410,7 @@ static int decode_slice(H263DecContext *const h)
av_log(h->c.avctx, AV_LOG_ERROR, av_log(h->c.avctx, AV_LOG_ERROR,
"slice end not reached but screenspace end (%d left %06X, score= %d)\n", "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
get_bits_left(&h->gb), show_bits(&h->gb, 24), h->c.padding_bug_score); get_bits_left(&h->gb), show_bits(&h->gb, 24), h->padding_bug_score);
ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, h->c.mb_x, h->c.mb_y, ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, h->c.mb_x, h->c.mb_y,
ER_MB_END & part_mask); ER_MB_END & part_mask);
@@ -432,10 +432,10 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
/* no supplementary picture */ /* no supplementary picture */
if (buf_size == 0) { if (buf_size == 0) {
/* special case for last picture */ /* special case for last picture */
if ((!h->c.low_delay || h->c.skipped_last_frame) && h->c.next_pic.ptr) { if ((!h->c.low_delay || h->skipped_last_frame) && h->c.next_pic.ptr) {
if ((ret = av_frame_ref(pict, h->c.next_pic.ptr->f)) < 0) if ((ret = av_frame_ref(pict, h->c.next_pic.ptr->f)) < 0)
return ret; return ret;
if (h->c.skipped_last_frame) { if (h->skipped_last_frame) {
/* If the stream ended with an NVOP, we output the last frame /* If the stream ended with an NVOP, we output the last frame
* in display order, but with the props from the last input * in display order, but with the props from the last input
* packet so that the stream's end time is correct. */ * packet so that the stream's end time is correct. */
@@ -549,7 +549,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
if ((ret = ff_mpv_frame_start(s, avctx)) < 0) if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
return ret; return ret;
if (!h->c.divx_packed) if (!h->divx_packed)
ff_thread_finish_setup(avctx); ff_thread_finish_setup(avctx);
if (avctx->hwaccel) { if (avctx->hwaccel) {

View File

@@ -50,6 +50,26 @@ typedef struct H263DecContext {
GetBitContext gb; GetBitContext gb;
int pb_frame; ///< PB-frame mode (0 = none, 1 = base, 2 = improved)
/* motion compensation */
int h263_long_vectors; ///< use horrible H.263v1 long vector mode
/* H.263 specific */
int ehc_mode;
/* H.263+ specific */
int custom_pcf;
/* MPEG-4 specific */
int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG-4
int skipped_last_frame;
int divx_packed; ///< divx specific, used to workaround (many) bugs in divx5
/* RV10 specific */
int rv10_version; ///< RV10 version: 0 or 3
int rv10_first_dc_coded[3];
int (*decode_mb)(struct H263DecContext *h); int (*decode_mb)(struct H263DecContext *h);
GetBitContext last_resync_gb; ///< used to search for the next resync marker GetBitContext last_resync_gb; ///< used to search for the next resync marker

View File

@@ -60,14 +60,14 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb); h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
h->c.h263_long_vectors = get_bits1(&h->gb); h->h263_long_vectors = get_bits1(&h->gb);
if (get_bits1(&h->gb) != 0) { if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n"); av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n");
return -1; /* SAC: off */ return -1; /* SAC: off */
} }
h->c.obmc = get_bits1(&h->gb); h->c.obmc = get_bits1(&h->gb);
h->c.pb_frame = get_bits1(&h->gb); h->pb_frame = get_bits1(&h->gb);
if (format < 6) { if (format < 6) {
h->c.width = ff_h263_format[format][0]; h->c.width = ff_h263_format[format][0];
@@ -86,7 +86,7 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
if (get_bits1(&h->gb)) if (get_bits1(&h->gb))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
if (get_bits1(&h->gb)) if (get_bits1(&h->gb))
h->c.pb_frame = 2; h->pb_frame = 2;
if (get_bits(&h->gb, 5)) if (get_bits(&h->gb, 5))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
if (get_bits(&h->gb, 5) != 1) if (get_bits(&h->gb, 5) != 1)
@@ -110,7 +110,7 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5); h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */ skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
if (h->c.pb_frame) { if (h->pb_frame) {
skip_bits(&h->gb, 3); //temporal reference for B-frame skip_bits(&h->gb, 3); //temporal reference for B-frame
skip_bits(&h->gb, 2); //dbquant skip_bits(&h->gb, 2); //dbquant
} }

View File

@@ -85,7 +85,7 @@ void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
h->gb.size_in_bits, 1-h->c.no_rounding, h->gb.size_in_bits, 1-h->c.no_rounding,
h->c.obmc ? " AP" : "", h->c.obmc ? " AP" : "",
h->c.umvplus ? " UMV" : "", h->c.umvplus ? " UMV" : "",
h->c.h263_long_vectors ? " LONG" : "", h->h263_long_vectors ? " LONG" : "",
h263_plus ? " +" : "", h263_plus ? " +" : "",
h->c.h263_aic ? " AIC" : "", h->c.h263_aic ? " AIC" : "",
h->c.alt_inter_vlc ? " AIV" : "", h->c.alt_inter_vlc ? " AIV" : "",
@@ -295,7 +295,7 @@ int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
val += pred; val += pred;
/* modulo decoding */ /* modulo decoding */
if (!h->c.h263_long_vectors) { if (!h->h263_long_vectors) {
val = sign_extend(val, 5 + f_code); val = sign_extend(val, 5 + f_code);
} else { } else {
/* horrible H.263 long vector mode */ /* horrible H.263 long vector mode */
@@ -545,10 +545,10 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64],
} else if (h->c.mb_intra) { } else if (h->c.mb_intra) {
/* DC coef */ /* DC coef */
if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) { if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) {
if (h->c.rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) { if (h->rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) {
int component = (n <= 3 ? 0 : n - 4 + 1); int component = (n <= 3 ? 0 : n - 4 + 1);
level = h->c.last_dc[component]; level = h->c.last_dc[component];
if (h->c.rv10_first_dc_coded[component]) { if (h->rv10_first_dc_coded[component]) {
int diff = ff_rv_decode_dc(h, n); int diff = ff_rv_decode_dc(h, n);
if (diff < 0) if (diff < 0)
return -1; return -1;
@@ -556,7 +556,7 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64],
level = level & 0xff; /* handle wrap round */ level = level & 0xff; /* handle wrap round */
h->c.last_dc[component] = level; h->c.last_dc[component] = level;
} else { } else {
h->c.rv10_first_dc_coded[component] = 1; h->rv10_first_dc_coded[component] = 1;
} }
} else { } else {
level = get_bits(&h->gb, 8); level = get_bits(&h->gb, 8);
@@ -816,8 +816,8 @@ int ff_h263_decode_mb(H263DecContext *const h)
if (h->c.mb_intra) if (h->c.mb_intra)
goto intra; goto intra;
if (h->c.pb_frame && get_bits1(&h->gb)) if (h->pb_frame && get_bits1(&h->gb))
pb_mv_count = h263_get_modb(&h->gb, h->c.pb_frame, &cbpb); pb_mv_count = h263_get_modb(&h->gb, h->pb_frame, &cbpb);
cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) { if (cbpy < 0) {
@@ -1029,8 +1029,8 @@ intra:
}else }else
h->c.ac_pred = 0; h->c.ac_pred = 0;
if (h->c.pb_frame && get_bits1(&h->gb)) if (h->pb_frame && get_bits1(&h->gb))
pb_mv_count = h263_get_modb(&h->gb, h->c.pb_frame, &cbpb); pb_mv_count = h263_get_modb(&h->gb, h->pb_frame, &cbpb);
cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1); cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if(cbpy<0){ if(cbpy<0){
av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",
@@ -1042,7 +1042,7 @@ intra:
h263_decode_dquant(h); h263_decode_dquant(h);
} }
pb_mv_count += !!h->c.pb_frame; pb_mv_count += !!h->pb_frame;
} }
while(pb_mv_count--){ while(pb_mv_count--){
@@ -1057,7 +1057,7 @@ intra:
cbp+=cbp; cbp+=cbp;
} }
if (h->c.pb_frame && h263_skip_b_part(h, cbpb) < 0) if (h->pb_frame && h263_skip_b_part(h, cbpb) < 0)
return -1; return -1;
if (h->c.obmc && !h->c.mb_intra) { if (h->c.obmc && !h->c.mb_intra) {
if (h->c.pict_type == AV_PICTURE_TYPE_P && if (h->c.pict_type == AV_PICTURE_TYPE_P &&
@@ -1146,7 +1146,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb); h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
h->c.h263_long_vectors = get_bits1(&h->gb); h->h263_long_vectors = get_bits1(&h->gb);
if (get_bits1(&h->gb) != 0) { if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n"); av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
@@ -1154,7 +1154,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
} }
h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */ h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
h->c.pb_frame = get_bits1(&h->gb); h->pb_frame = get_bits1(&h->gb);
h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5); h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */ skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
@@ -1174,7 +1174,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
/* OPPTYPE */ /* OPPTYPE */
format = get_bits(&h->gb, 3); format = get_bits(&h->gb, 3);
ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format); ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);
h->c.custom_pcf = get_bits1(&h->gb); h->custom_pcf = get_bits1(&h->gb);
h->c.umvplus = get_bits1(&h->gb); /* Unrestricted Motion Vector */ h->c.umvplus = get_bits1(&h->gb); /* Unrestricted Motion Vector */
if (get_bits1(&h->gb) != 0) { if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
@@ -1210,7 +1210,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
switch (h->c.pict_type) { switch (h->c.pict_type) {
case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break; case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break;
case 1: h->c.pict_type = AV_PICTURE_TYPE_P; break; case 1: h->c.pict_type = AV_PICTURE_TYPE_P; break;
case 2: h->c.pict_type = AV_PICTURE_TYPE_P; h->c.pb_frame = 3; break; case 2: h->c.pict_type = AV_PICTURE_TYPE_P; h->pb_frame = 3; break;
case 3: h->c.pict_type = AV_PICTURE_TYPE_B; break; case 3: h->c.pict_type = AV_PICTURE_TYPE_B; break;
case 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO case 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO
default: default:
@@ -1251,13 +1251,13 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
height = ff_h263_format[format][1]; height = ff_h263_format[format][1];
h->c.avctx->sample_aspect_ratio = (AVRational){12,11}; h->c.avctx->sample_aspect_ratio = (AVRational){12,11};
} }
h->c.avctx->sample_aspect_ratio.den <<= h->c.ehc_mode; h->c.avctx->sample_aspect_ratio.den <<= h->ehc_mode;
if ((width == 0) || (height == 0)) if ((width == 0) || (height == 0))
return -1; return -1;
h->c.width = width; h->c.width = width;
h->c.height = height; h->c.height = height;
if (h->c.custom_pcf) { if (h->custom_pcf) {
h->c.avctx->framerate.num = 1800000; h->c.avctx->framerate.num = 1800000;
h->c.avctx->framerate.den = 1000 + get_bits1(&h->gb); h->c.avctx->framerate.den = 1000 + get_bits1(&h->gb);
h->c.avctx->framerate.den *= get_bits(&h->gb, 7); h->c.avctx->framerate.den *= get_bits(&h->gb, 7);
@@ -1273,7 +1273,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
} }
} }
if (h->c.custom_pcf) if (h->custom_pcf)
skip_bits(&h->gb, 2); //extended Temporal reference skip_bits(&h->gb, 2); //extended Temporal reference
if (ufep) { if (ufep) {
@@ -1315,9 +1315,9 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
h->c.gob_index = H263_GOB_HEIGHT(h->c.height); h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
if (h->c.pb_frame) { if (h->pb_frame) {
skip_bits(&h->gb, 3); /* Temporal reference for B-pictures */ skip_bits(&h->gb, 3); /* Temporal reference for B-pictures */
if (h->c.custom_pcf) if (h->custom_pcf)
skip_bits(&h->gb, 2); //extended Temporal reference skip_bits(&h->gb, 2); //extended Temporal reference
skip_bits(&h->gb, 2); /* Quantization information for B-pictures */ skip_bits(&h->gb, 2); /* Quantization information for B-pictures */
} }

View File

@@ -3031,7 +3031,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
if (e >= 2) { if (e >= 2) {
ctx->divx_version = ver; ctx->divx_version = ver;
ctx->divx_build = build; ctx->divx_build = build;
h->c.divx_packed = e == 3 && last == 'p'; h->divx_packed = e == 3 && last == 'p';
} }
/* libavcodec detection */ /* libavcodec detection */
@@ -3132,7 +3132,7 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA2; h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA2;
if (ctx->xvid_build <= 3U) if (ctx->xvid_build <= 3U)
h->c.padding_bug_score = 256 * 256 * 256 * 64; h->padding_bug_score = 256 * 256 * 256 * 64;
if (ctx->xvid_build <= 1U) if (ctx->xvid_build <= 1U)
h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA; h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA;
@@ -3170,7 +3170,7 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
if (ctx->divx_version >= 0) if (ctx->divx_version >= 0)
h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE; h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
if (ctx->divx_version == 501 && ctx->divx_build == 20020416) if (ctx->divx_version == 501 && ctx->divx_build == 20020416)
h->c.padding_bug_score = 256 * 256 * 256 * 64; h->padding_bug_score = 256 * 256 * 256 * 64;
if (ctx->divx_version < 500U) if (ctx->divx_version < 500U)
h->c.workaround_bugs |= FF_BUG_EDGE; h->c.workaround_bugs |= FF_BUG_EDGE;
@@ -3199,7 +3199,7 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
av_log(h->c.avctx, AV_LOG_DEBUG, av_log(h->c.avctx, AV_LOG_DEBUG,
"bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n", "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
h->c.workaround_bugs, ctx->lavc_build, ctx->xvid_build, h->c.workaround_bugs, ctx->lavc_build, ctx->xvid_build,
ctx->divx_version, ctx->divx_build, h->c.divx_packed ? "p" : ""); ctx->divx_version, ctx->divx_build, h->divx_packed ? "p" : "");
if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 && if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 &&
avctx->idct_algo == FF_IDCT_AUTO && !h->c.studio_profile) { avctx->idct_algo == FF_IDCT_AUTO && !h->c.studio_profile) {
@@ -3313,7 +3313,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
if (get_bits1(gb) != 1) { if (get_bits1(gb) != 1) {
if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
av_log(h->c.avctx, AV_LOG_ERROR, "vop not coded\n"); av_log(h->c.avctx, AV_LOG_ERROR, "vop not coded\n");
h->c.skipped_last_frame = 1; h->skipped_last_frame = 1;
return FRAME_SKIPPED; return FRAME_SKIPPED;
} }
if (ctx->new_pred) if (ctx->new_pred)
@@ -3740,14 +3740,14 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h)
{ {
Mpeg4DecContext *const ctx = h263_to_mpeg4(h); Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
h->c.skipped_last_frame = 0; h->skipped_last_frame = 0;
if (ctx->bitstream_buffer) { if (ctx->bitstream_buffer) {
int buf_size = get_bits_left(&h->gb) / 8U; int buf_size = get_bits_left(&h->gb) / 8U;
int bitstream_buffer_size = ctx->bitstream_buffer->size; int bitstream_buffer_size = ctx->bitstream_buffer->size;
const uint8_t *buf = h->gb.buffer; const uint8_t *buf = h->gb.buffer;
if (h->c.divx_packed) { if (h->divx_packed) {
for (int i = 0; i < buf_size - 3; i++) { for (int i = 0; i < buf_size - 3; i++) {
if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) { if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) {
if (buf[i+3] == 0xB0) { if (buf[i+3] == 0xB0) {
@@ -3759,7 +3759,7 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h)
} }
} }
ctx->bitstream_buffer->size = 0; ctx->bitstream_buffer->size = 0;
if (bitstream_buffer_size && (h->c.divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder if (bitstream_buffer_size && (h->divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder
int ret = init_get_bits8(&h->gb, ctx->bitstream_buffer->data, int ret = init_get_bits8(&h->gb, ctx->bitstream_buffer->data,
bitstream_buffer_size); bitstream_buffer_size);
if (ret < 0) if (ret < 0)
@@ -3780,7 +3780,7 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
av_assert1(!ctx->bitstream_buffer || !ctx->bitstream_buffer->size); av_assert1(!ctx->bitstream_buffer || !ctx->bitstream_buffer->size);
/* divx 5.01+ bitstream reorder stuff */ /* divx 5.01+ bitstream reorder stuff */
if (h->c.divx_packed) { if (h->divx_packed) {
int current_pos = ctx->bitstream_buffer && h->gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->gb) >> 3); int current_pos = ctx->bitstream_buffer && h->gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->gb) >> 3);
int startcode_found = 0; int startcode_found = 0;
uint8_t *buf = pkt->data; uint8_t *buf = pkt->data;
@@ -3907,7 +3907,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
s->enhancement_type = s1->enhancement_type; s->enhancement_type = s1->enhancement_type;
s->scalability = s1->scalability; s->scalability = s1->scalability;
s->intra_dc_threshold = s1->intra_dc_threshold; s->intra_dc_threshold = s1->intra_dc_threshold;
s->h.c.divx_packed = s1->h.c.divx_packed; s->h.divx_packed = s1->h.divx_packed;
s->divx_version = s1->divx_version; s->divx_version = s1->divx_version;
s->divx_build = s1->divx_build; s->divx_build = s1->divx_build;
s->xvid_build = s1->xvid_build; s->xvid_build = s1->xvid_build;
@@ -3919,7 +3919,9 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
s->cplx_estimation_trash_p = s1->cplx_estimation_trash_p; s->cplx_estimation_trash_p = s1->cplx_estimation_trash_p;
s->cplx_estimation_trash_b = s1->cplx_estimation_trash_b; s->cplx_estimation_trash_b = s1->cplx_estimation_trash_b;
s->rgb = s1->rgb; s->rgb = s1->rgb;
s->h.c.skipped_last_frame = s1->h.c.skipped_last_frame;
s->h.skipped_last_frame = s1->h.skipped_last_frame;
s->h.padding_bug_score = s1->h.padding_bug_score; // FIXME: racy
memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift)); memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift));
memcpy(s->sprite_traj, s1->sprite_traj, sizeof(s1->sprite_traj)); memcpy(s->sprite_traj, s1->sprite_traj, sizeof(s1->sprite_traj));
@@ -3930,11 +3932,11 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
static int mpeg4_update_thread_context_for_user(AVCodecContext *dst, static int mpeg4_update_thread_context_for_user(AVCodecContext *dst,
const AVCodecContext *src) const AVCodecContext *src)
{ {
MpegEncContext *m = dst->priv_data; H263DecContext *const h = dst->priv_data;
const MpegEncContext *m1 = src->priv_data; const H263DecContext *const h1 = src->priv_data;
m->quarter_sample = m1->quarter_sample; h->c.quarter_sample = h1->c.quarter_sample;
m->divx_packed = m1->divx_packed; h->divx_packed = h1->divx_packed;
return 0; return 0;
} }
@@ -4054,10 +4056,10 @@ static av_cold int mpeg4_close(AVCodecContext *avctx)
return ff_mpv_decode_close(avctx); return ff_mpv_decode_close(avctx);
} }
#define OFFSET(x) offsetof(MpegEncContext, x) #define OFFSET(x) offsetof(H263DecContext, x)
#define FLAGS AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY #define FLAGS AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY
static const AVOption mpeg4_options[] = { static const AVOption mpeg4_options[] = {
{"quarter_sample", "1/4 subpel MC", OFFSET(quarter_sample), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS}, {"quarter_sample", "1/4 subpel MC", OFFSET(c.quarter_sample), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS},
{"divx_packed", "divx style packed b frames", OFFSET(divx_packed), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS}, {"divx_packed", "divx style packed b frames", OFFSET(divx_packed), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS},
{NULL} {NULL}
}; };

View File

@@ -86,7 +86,6 @@ typedef struct MpegEncContext {
int width, height;///< picture size. must be a multiple of 16 int width, height;///< picture size. must be a multiple of 16
enum OutputFormat out_format; ///< output format enum OutputFormat out_format; ///< output format
int h263_pred; ///< use MPEG-4/H.263 ac/dc predictions int h263_pred; ///< use MPEG-4/H.263 ac/dc predictions
int pb_frame; ///< PB-frame mode (0 = none, 1 = base, 2 = improved)
/* the following codec id fields are deprecated in favor of codec_id */ /* the following codec id fields are deprecated in favor of codec_id */
int h263_flv; ///< use flv H.263 header int h263_flv; ///< use flv H.263 header
@@ -138,7 +137,6 @@ typedef struct MpegEncContext {
*/ */
MPVWorkPicture cur_pic; MPVWorkPicture cur_pic;
int skipped_last_frame;
int last_dc[3]; ///< last DC values for MPEG-1 int last_dc[3]; ///< last DC values for MPEG-1
int16_t *dc_val_base; int16_t *dc_val_base;
const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table
@@ -163,9 +161,6 @@ typedef struct MpegEncContext {
int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ... int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
int droppable; int droppable;
/* motion compensation */
int h263_long_vectors; ///< use horrible H.263v1 long vector mode
BlockDSPContext bdsp; BlockDSPContext bdsp;
H264ChromaContext h264chroma; H264ChromaContext h264chroma;
HpelDSPContext hdsp; HpelDSPContext hdsp;
@@ -224,7 +219,6 @@ typedef struct MpegEncContext {
/* H.263 specific */ /* H.263 specific */
int gob_index; int gob_index;
int obmc; ///< overlapped block motion compensation int obmc; ///< overlapped block motion compensation
int ehc_mode;
/* H.263+ specific */ /* H.263+ specific */
int umvplus; ///< == H.263+ && unrestricted_mv int umvplus; ///< == H.263+ && unrestricted_mv
@@ -233,7 +227,6 @@ typedef struct MpegEncContext {
int alt_inter_vlc; ///< alternative inter vlc int alt_inter_vlc; ///< alternative inter vlc
int modified_quant; int modified_quant;
int loop_filter; int loop_filter;
int custom_pcf;
/* MPEG-4 specific */ /* MPEG-4 specific */
int studio_profile; int studio_profile;
@@ -250,14 +243,6 @@ typedef struct MpegEncContext {
int data_partitioning; ///< data partitioning flag from header int data_partitioning; ///< data partitioning flag from header
int partitioned_frame; ///< is current frame partitioned int partitioned_frame; ///< is current frame partitioned
int low_delay; ///< no reordering needed / has no B-frames int low_delay; ///< no reordering needed / has no B-frames
int padding_bug_score; ///< used to detect the VERY common padding bug in MPEG-4
/* divx specific, used to workaround (many) bugs in divx5 */
int divx_packed;
/* RV10 specific */
int rv10_version; ///< RV10 version: 0 or 3
int rv10_first_dc_coded[3];
/* MSMPEG4 specific */ /* MSMPEG4 specific */
int slice_height; ///< in macroblocks int slice_height; ///< in macroblocks

View File

@@ -108,7 +108,6 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
// Error/bug resilience // Error/bug resilience
s->workaround_bugs = s1->workaround_bugs; s->workaround_bugs = s1->workaround_bugs;
s->padding_bug_score = s1->padding_bug_score;
// MPEG-4 timing info // MPEG-4 timing info
memcpy(&s->last_time_base, &s1->last_time_base, memcpy(&s->last_time_base, &s1->last_time_base,

View File

@@ -73,7 +73,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx,
.quant_type = m->mpeg_quant, .quant_type = m->mpeg_quant,
.quarter_sample = s->quarter_sample, .quarter_sample = s->quarter_sample,
.short_video_header = avctx->codec->id == AV_CODEC_ID_H263, .short_video_header = avctx->codec->id == AV_CODEC_ID_H263,
.divx_flags = s->divx_packed ? 5 : 0, .divx_flags = m->h.divx_packed ? 5 : 0,
.vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I, .vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I,
.vop_coded = 1, .vop_coded = 1,

View File

@@ -127,7 +127,7 @@ static int rv10_decode_picture_header(H263DecContext *const h)
} }
if (h->c.pict_type == AV_PICTURE_TYPE_I) { if (h->c.pict_type == AV_PICTURE_TYPE_I) {
if (h->c.rv10_version == 3) { if (h->rv10_version == 3) {
/* specific MPEG like DC coding not used */ /* specific MPEG like DC coding not used */
h->c.last_dc[0] = get_bits(&h->gb, 8); h->c.last_dc[0] = get_bits(&h->gb, 8);
h->c.last_dc[1] = get_bits(&h->gb, 8); h->c.last_dc[1] = get_bits(&h->gb, 8);
@@ -369,7 +369,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
rv->orig_width = avctx->coded_width; rv->orig_width = avctx->coded_width;
rv->orig_height = avctx->coded_height; rv->orig_height = avctx->coded_height;
h->c.h263_long_vectors = avctx->extradata[3] & 1; h->h263_long_vectors = avctx->extradata[3] & 1;
rv->sub_id = AV_RB32A(avctx->extradata + 4); rv->sub_id = AV_RB32A(avctx->extradata + 4);
if (avctx->codec_id == AV_CODEC_ID_RV20) { if (avctx->codec_id == AV_CODEC_ID_RV20) {
h->c.modified_quant = 1; h->c.modified_quant = 1;
@@ -382,7 +382,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
switch (major_ver) { switch (major_ver) {
case 1: case 1:
h->c.rv10_version = micro_ver ? 3 : 1; h->rv10_version = micro_ver ? 3 : 1;
h->c.obmc = micro_ver == 2; h->c.obmc = micro_ver == 2;
break; break;
case 2: case 2:
@@ -475,9 +475,9 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
ff_set_qscale(&h->c, h->c.qscale); ff_set_qscale(&h->c, h->c.qscale);
h->c.rv10_first_dc_coded[0] = 0; h->rv10_first_dc_coded[0] = 0;
h->c.rv10_first_dc_coded[1] = 0; h->rv10_first_dc_coded[1] = 0;
h->c.rv10_first_dc_coded[2] = 0; h->rv10_first_dc_coded[2] = 0;
ff_init_block_index(&h->c); ff_init_block_index(&h->c);
/* decode each macroblock */ /* decode each macroblock */