* [FFmpeg-devel] [PATCH 01/48] avcodec/ituh263dec: Use correct logcontext
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 02/48] avcodec/rl: Avoid branch in index lookup Andreas Rheinhardt
` (46 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263dec.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index f1f96010b2..95cd8f0b13 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -1295,7 +1295,8 @@ int ff_h263_decode_picture_header(MpegEncContext *s)
s->qscale = get_bits(&s->gb, 5);
}
- if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0)
+ ret = av_image_check_size(s->width, s->height, 0, s->avctx);
+ if (ret < 0)
return ret;
if (!(s->avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 02/48] avcodec/rl: Avoid branch in index lookup
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 01/48] avcodec/ituh263dec: Use correct logcontext Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 03/48] avcodec/ituh263enc: Simplify creating LUT Andreas Rheinhardt
` (45 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This uses the same logic as the MPEG-1/2 and SpeedHQ encoders.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rl.h | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/libavcodec/rl.h b/libavcodec/rl.h
index c45d8659d1..2588de2440 100644
--- a/libavcodec/rl.h
+++ b/libavcodec/rl.h
@@ -100,13 +100,9 @@ do { \
static inline int get_rl_index(const RLTable *rl, int last, int run, int level)
{
- int index;
- index = rl->index_run[last][run];
- if (index >= rl->n)
- return rl->n;
if (level > rl->max_level[last][run])
return rl->n;
- return index + level - 1;
+ return rl->index_run[last][run] + level - 1;
}
#endif /* AVCODEC_RL_H */
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 03/48] avcodec/ituh263enc: Simplify creating LUT
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 01/48] avcodec/ituh263dec: Use correct logcontext Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 02/48] avcodec/rl: Avoid branch in index lookup Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 04/48] avcodec/ituh263dec: Only initialize ff_h263_rl_inter when needed Andreas Rheinhardt
` (44 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Only very few combinations (2x102) of 16384 correspond to
valid codes; so just initialize all codes via memset
and then set the few valid codes explicitly instead of initializing
everything in the same way.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263data.h | 4 +++
libavcodec/ituh263enc.c | 54 +++++++++++++++++------------------------
2 files changed, 26 insertions(+), 32 deletions(-)
diff --git a/libavcodec/h263data.h b/libavcodec/h263data.h
index 06554bdf0d..e733089e83 100644
--- a/libavcodec/h263data.h
+++ b/libavcodec/h263data.h
@@ -59,6 +59,10 @@ extern const uint16_t ff_inter_vlc[103][2];
extern const int8_t ff_inter_level[102];
extern const int8_t ff_inter_run[102];
+/* the following defines are valid for both ff_h263_rl_inter and ff_rl_intra_aic */
+#define H263_RL_NB_ELEMS 102 // does not include escape
+#define H263_RL_NON_LAST_CODES 58
+#define H263_ESCAPE_CODE_LENGTH 7
extern RLTable ff_h263_rl_inter;
extern RLTable ff_rl_intra_aic;
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 903bb45fce..4ec851cab9 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -99,41 +99,31 @@ static uint8_t uni_h263_inter_rl_len [64*64*2*2];
static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
{
+ const uint16_t (*table_vlc)[2] = rl->table_vlc;
+ const uint8_t *table_run = rl->table_run;
+ const uint8_t *table_level = rl->table_level;
+
av_assert0(MAX_LEVEL >= 64);
av_assert0(MAX_RUN >= 63);
- for (int slevel = -64; slevel < 64; slevel++) {
- if (slevel == 0) continue;
- for (int run = 0; run < 64; run++) {
- for (int last = 0; last <= 1; last++) {
- const int index = UNI_MPEG4_ENC_INDEX(last, run, slevel + 64);
- int level = slevel < 0 ? -slevel : slevel;
- int sign = slevel < 0 ? 1 : 0;
- int bits, len, code;
-
- len_tab[index] = 100;
-
- /* ESC0 */
- code = get_rl_index(rl, last, run, level);
- bits = rl->table_vlc[code][0];
- len = rl->table_vlc[code][1];
- bits = bits * 2 + sign;
- len++;
-
- if (code != rl->n && len < len_tab[index])
- len_tab[index] = len;
-
- /* ESC */
- bits = rl->table_vlc[rl->n][0];
- len = rl->table_vlc[rl->n][1];
- bits = bits * 2 + last; len++;
- bits = bits * 64 + run; len += 6;
- bits = bits * 256 + (level & 0xff); len += 8;
-
- if (len < len_tab[index])
- len_tab[index] = len;
- }
- }
+ // Note: The LUT only covers level values for which the escape value
+ // is eight bits (not 8 + 5 + 6)
+ memset(len_tab, H263_ESCAPE_CODE_LENGTH + 1 + 6 + 8,
+ sizeof(uni_h263_intra_aic_rl_len));
+
+ len_tab += 64; // simplifies addressing
+ for (int i = 0; i < H263_RL_NB_ELEMS; ++i) {
+ int run = table_run[i];
+ int level = table_level[i];
+ int last = i >= H263_RL_NON_LAST_CODES;
+ int len = table_vlc[i][1];
+
+ len_tab[UNI_MPEG4_ENC_INDEX(last, run, level)] =
+ len_tab[UNI_MPEG4_ENC_INDEX(last, run, -level)] = len + 1 /* sign */;
+ }
+ for (int run = 0; run < MAX_RUN; ++run) {
+ len_tab[UNI_MPEG4_ENC_INDEX(0, run, 0)] =
+ len_tab[UNI_MPEG4_ENC_INDEX(1, run, 0)] = 0; // is this necessary?
}
}
#endif
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 04/48] avcodec/ituh263dec: Only initialize ff_h263_rl_inter when needed
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (2 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 03/48] avcodec/ituh263enc: Simplify creating LUT Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 05/48] avcodec/mpegvideoenc: Allocate blocks as part of MPVEncContext Andreas Rheinhardt
` (43 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The H.263 decoder itself does not need max_run/max_level
of this RLTable, only the MPEG-4 decoder does.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/ituh263dec.c | 1 -
libavcodec/mpeg4videodec.c | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 95cd8f0b13..fa09ebb84b 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -123,7 +123,6 @@ static av_cold void h263_decode_init_vlc(void)
VLC_INIT_STATIC_TABLE(ff_h263_mv_vlc, H263_MV_VLC_BITS, 33,
&ff_mvtab[0][1], 2, 1,
&ff_mvtab[0][0], 2, 1, 0);
- ff_h263_init_rl_inter();
VLC_INIT_RL(ff_h263_rl_inter, 554);
INIT_FIRST_VLC_RL(ff_rl_intra_aic, 554);
VLC_INIT_STATIC_SPARSE_TABLE(h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 522242de40..2e3609b0d5 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3962,6 +3962,7 @@ static av_cold void mpeg4_init_static(void)
static uint8_t mpeg4_rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
ff_rl_init(&ff_mpeg4_rl_intra, mpeg4_rl_intra_table);
+ ff_h263_init_rl_inter();
INIT_FIRST_VLC_RL(ff_mpeg4_rl_intra, 554);
VLC_INIT_RL(ff_rvlc_rl_inter, 1072);
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 05/48] avcodec/mpegvideoenc: Allocate blocks as part of MPVEncContext
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (3 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 04/48] avcodec/ituh263dec: Only initialize ff_h263_rl_inter when needed Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 06/48] avcodec/mpegvideo: Add MPVContext typedef Andreas Rheinhardt
` (42 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This avoids mpegvideo.c having to deal with the fact that
the encoders use two sets of blocks and is in preparation
for not allocating blocks at all.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263enc.h | 2 +-
libavcodec/mpeg4videodec.c | 1 -
libavcodec/mpeg4videoenc.c | 2 +-
libavcodec/mpegvideo.c | 12 +++---
libavcodec/mpegvideo.h | 3 +-
libavcodec/mpegvideo_enc.c | 78 +++++++++++++++++++-------------------
libavcodec/mpegvideoenc.h | 5 +++
7 files changed, 54 insertions(+), 49 deletions(-)
diff --git a/libavcodec/h263enc.h b/libavcodec/h263enc.h
index 20e0c57326..5a6e7d500d 100644
--- a/libavcodec/h263enc.h
+++ b/libavcodec/h263enc.h
@@ -87,7 +87,7 @@ static inline int get_p_cbp(MPVEncContext *const s,
for (int i = 0; i < 6; i++) {
if (s->c.block_last_index[i] >= 0 && !((cbp >> (5 - i)) & 1)) {
s->c.block_last_index[i] = -1;
- s->c.bdsp.clear_block(s->c.block[i]);
+ s->c.bdsp.clear_block(s->block[i]);
}
}
} else {
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 2e3609b0d5..34f383bbbd 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3826,7 +3826,6 @@ static av_cold void clear_context(MpegEncContext *s)
memset(s->thread_context, 0, sizeof(s->thread_context));
s->block = NULL;
- s->blocks = NULL;
s->ac_val_base = NULL;
s->ac_val = NULL;
memset(&s->sc, 0, sizeof(s->sc));
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index a9d673707a..1aa35aa70a 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -433,7 +433,7 @@ static inline int get_b_cbp(MPVEncContext *const s, int16_t block[6][64],
for (i = 0; i < 6; i++) {
if (s->c.block_last_index[i] >= 0 && ((cbp >> (5 - i)) & 1) == 0) {
s->c.block_last_index[i] = -1;
- s->c.bdsp.clear_block(s->c.block[i]);
+ s->c.bdsp.clear_block(s->block[i]);
}
}
} else {
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index ff2703f487..3cbd686558 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -116,9 +116,11 @@ av_cold void ff_mpv_idct_init(MpegEncContext *s)
static av_cold int init_duplicate_context(MpegEncContext *s)
{
- if (!FF_ALLOCZ_TYPED_ARRAY(s->blocks, 1 + s->encoding))
- return AVERROR(ENOMEM);
- s->block = s->blocks[0];
+ if (!s->encoding) {
+ s->block = av_mallocz(12 * sizeof(*s->block));
+ if (!s->block)
+ return AVERROR(ENOMEM);
+ }
return 0;
}
@@ -158,8 +160,7 @@ static av_cold void free_duplicate_context(MpegEncContext *s)
s->sc.obmc_scratchpad = NULL;
s->sc.linesize = 0;
- av_freep(&s->blocks);
- s->block = NULL;
+ av_freep(&s->block);
}
static av_cold void free_duplicate_contexts(MpegEncContext *s)
@@ -175,7 +176,6 @@ int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
{
#define COPY(M) \
M(ScratchpadContext, sc) \
- M(void*, blocks) \
M(void*, block) \
M(int, start_mb_y) \
M(int, end_mb_y) \
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 55a490adc7..4ff5e8906d 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -309,8 +309,7 @@ typedef struct MpegEncContext {
int interlaced_dct;
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
- int16_t (*block)[64]; ///< points to one of the following blocks
- int16_t (*blocks)[12][64]; // for HQ mode we need to keep the best block
+ int16_t (*block)[64];
int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
#define SLICE_OK 0
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1f51f237fa..1ceb6296c4 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -538,6 +538,8 @@ static av_cold int init_slice_buffers(MPVMainEncContext *const m)
for (unsigned i = 0; i < nb_slices; ++i) {
MPVEncContext *const s2 = s->c.enc_contexts[i];
+ s2->block = s2->blocks[0];
+
if (dct_error) {
s2->dct_offset = s->dct_offset;
s2->dct_error_sum = (void*)dct_error;
@@ -2184,7 +2186,7 @@ static inline void dct_single_coeff_elimination(MPVEncContext *const s,
int score = 0;
int run = 0;
int i;
- int16_t *block = s->c.block[n];
+ int16_t *block = s->block[n];
const int last_index = s->c.block_last_index[n];
int skip_dc;
@@ -2399,27 +2401,27 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s,
}
}
- s->pdsp.get_pixels(s->c.block[0], ptr_y, wrap_y);
- s->pdsp.get_pixels(s->c.block[1], ptr_y + 8, wrap_y);
- s->pdsp.get_pixels(s->c.block[2], ptr_y + dct_offset, wrap_y);
- s->pdsp.get_pixels(s->c.block[3], ptr_y + dct_offset + 8, wrap_y);
+ s->pdsp.get_pixels(s->block[0], ptr_y, wrap_y);
+ s->pdsp.get_pixels(s->block[1], ptr_y + 8, wrap_y);
+ s->pdsp.get_pixels(s->block[2], ptr_y + dct_offset, wrap_y);
+ s->pdsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y);
if (s->c.avctx->flags & AV_CODEC_FLAG_GRAY) {
skip_dct[4] = 1;
skip_dct[5] = 1;
} else {
- s->pdsp.get_pixels(s->c.block[4], ptr_cb, wrap_c);
- s->pdsp.get_pixels(s->c.block[5], ptr_cr, wrap_c);
+ s->pdsp.get_pixels(s->block[4], ptr_cb, wrap_c);
+ s->pdsp.get_pixels(s->block[5], ptr_cr, wrap_c);
if (chroma_format == CHROMA_422) {
- s->pdsp.get_pixels(s->c.block[6], ptr_cb + uv_dct_offset, wrap_c);
- s->pdsp.get_pixels(s->c.block[7], ptr_cr + uv_dct_offset, wrap_c);
+ s->pdsp.get_pixels(s->block[6], ptr_cb + uv_dct_offset, wrap_c);
+ s->pdsp.get_pixels(s->block[7], ptr_cr + uv_dct_offset, wrap_c);
} else if (chroma_format == CHROMA_444) {
- s->pdsp.get_pixels(s->c.block[ 6], ptr_cb + 8, wrap_c);
- s->pdsp.get_pixels(s->c.block[ 7], ptr_cr + 8, wrap_c);
- s->pdsp.get_pixels(s->c.block[ 8], ptr_cb + uv_dct_offset, wrap_c);
- s->pdsp.get_pixels(s->c.block[ 9], ptr_cr + uv_dct_offset, wrap_c);
- s->pdsp.get_pixels(s->c.block[10], ptr_cb + uv_dct_offset + 8, wrap_c);
- s->pdsp.get_pixels(s->c.block[11], ptr_cr + uv_dct_offset + 8, wrap_c);
+ s->pdsp.get_pixels(s->block[ 6], ptr_cb + 8, wrap_c);
+ s->pdsp.get_pixels(s->block[ 7], ptr_cr + 8, wrap_c);
+ s->pdsp.get_pixels(s->block[ 8], ptr_cb + uv_dct_offset, wrap_c);
+ s->pdsp.get_pixels(s->block[ 9], ptr_cr + uv_dct_offset, wrap_c);
+ s->pdsp.get_pixels(s->block[10], ptr_cb + uv_dct_offset + 8, wrap_c);
+ s->pdsp.get_pixels(s->block[11], ptr_cr + uv_dct_offset + 8, wrap_c);
}
}
} else {
@@ -2483,23 +2485,23 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s,
}
}
- s->pdsp.diff_pixels(s->c.block[0], ptr_y, dest_y, wrap_y);
- s->pdsp.diff_pixels(s->c.block[1], ptr_y + 8, dest_y + 8, wrap_y);
- s->pdsp.diff_pixels(s->c.block[2], ptr_y + dct_offset,
+ s->pdsp.diff_pixels(s->block[0], ptr_y, dest_y, wrap_y);
+ s->pdsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y);
+ s->pdsp.diff_pixels(s->block[2], ptr_y + dct_offset,
dest_y + dct_offset, wrap_y);
- s->pdsp.diff_pixels(s->c.block[3], ptr_y + dct_offset + 8,
+ s->pdsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8,
dest_y + dct_offset + 8, wrap_y);
if (s->c.avctx->flags & AV_CODEC_FLAG_GRAY) {
skip_dct[4] = 1;
skip_dct[5] = 1;
} else {
- s->pdsp.diff_pixels(s->c.block[4], ptr_cb, dest_cb, wrap_c);
- s->pdsp.diff_pixels(s->c.block[5], ptr_cr, dest_cr, wrap_c);
+ s->pdsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c);
+ s->pdsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c);
if (!chroma_y_shift) { /* 422 */
- s->pdsp.diff_pixels(s->c.block[6], ptr_cb + uv_dct_offset,
+ s->pdsp.diff_pixels(s->block[6], ptr_cb + uv_dct_offset,
dest_cb + uv_dct_offset, wrap_c);
- s->pdsp.diff_pixels(s->c.block[7], ptr_cr + uv_dct_offset,
+ s->pdsp.diff_pixels(s->block[7], ptr_cr + uv_dct_offset,
dest_cr + uv_dct_offset, wrap_c);
}
}
@@ -2554,7 +2556,7 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s,
get_visual_weight(weight[7], ptr_cr + uv_dct_offset,
wrap_c);
}
- memcpy(orig[0], s->c.block[0], sizeof(int16_t) * 64 * mb_block_count);
+ memcpy(orig[0], s->block[0], sizeof(int16_t) * 64 * mb_block_count);
}
/* DCT & quantize */
@@ -2563,14 +2565,14 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s,
for (i = 0; i < mb_block_count; i++) {
if (!skip_dct[i]) {
int overflow;
- s->c.block_last_index[i] = s->dct_quantize(s, s->c.block[i], i, s->c.qscale, &overflow);
+ s->c.block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->c.qscale, &overflow);
// FIXME we could decide to change to quantizer instead of
// clipping
// JS: I don't think that would be a good idea it could lower
// quality instead of improve it. Just INTRADC clipping
// deserves changes in quantizer
if (overflow)
- clip_coeffs(s, s->c.block[i], s->c.block_last_index[i]);
+ clip_coeffs(s, s->block[i], s->c.block_last_index[i]);
} else
s->c.block_last_index[i] = -1;
}
@@ -2578,7 +2580,7 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s,
for (i = 0; i < mb_block_count; i++) {
if (!skip_dct[i]) {
s->c.block_last_index[i] =
- dct_quantize_refine(s, s->c.block[i], weight[i],
+ dct_quantize_refine(s, s->block[i], weight[i],
orig[i], i, s->c.qscale);
}
}
@@ -2602,12 +2604,12 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s,
if ((s->c.avctx->flags & AV_CODEC_FLAG_GRAY) && s->c.mb_intra) {
s->c.block_last_index[4] =
s->c.block_last_index[5] = 0;
- s->c.block[4][0] =
- s->c.block[5][0] = (1024 + s->c.c_dc_scale / 2) / s->c.c_dc_scale;
+ s->block[4][0] =
+ s->block[5][0] = (1024 + s->c.c_dc_scale / 2) / s->c.c_dc_scale;
if (!chroma_y_shift) { /* 422 / 444 */
for (i=6; i<12; i++) {
s->c.block_last_index[i] = 0;
- s->c.block[i][0] = s->c.block[4][0];
+ s->block[i][0] = s->block[4][0];
}
}
}
@@ -2618,7 +2620,7 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s,
int j;
if (s->c.block_last_index[i] > 0) {
for (j = 63; j > 0; j--) {
- if (s->c.block[i][s->c.intra_scantable.permutated[j]])
+ if (s->block[i][s->c.intra_scantable.permutated[j]])
break;
}
s->c.block_last_index[i] = j;
@@ -2626,7 +2628,7 @@ static av_always_inline void encode_mb_internal(MPVEncContext *const s,
}
}
- s->encode_mb(s, s->c.block, motion_x, motion_y);
+ s->encode_mb(s, s->block, motion_x, motion_y);
}
static void encode_mb(MPVEncContext *const s, int motion_x, int motion_y)
@@ -2649,11 +2651,11 @@ typedef struct MBBackup {
int qscale;
int block_last_index[8];
int interlaced_dct;
- int16_t (*block)[64];
} c;
int mv_bits, i_tex_bits, p_tex_bits, i_count, misc_bits, last_bits;
int dquant;
int esc3_level_length;
+ int16_t (*block)[64];
PutBitContext pb, pb2, tex_pb;
} MBBackup;
@@ -2713,7 +2715,7 @@ static inline void AFTER ## _context_after_encode(DST_TYPE *const d, \
d->pb2 = s->pb2; \
d->tex_pb = s->tex_pb; \
} \
- d->c.block = s->c.block; \
+ d->block = s->block; \
for (int i = 0; i < 8; i++) \
d->c.block_last_index[i] = s->c.block_last_index[i]; \
d->c.interlaced_dct = s->c.interlaced_dct; \
@@ -2734,7 +2736,7 @@ static void encode_mb_hq(MPVEncContext *const s, MBBackup *const backup, MBBacku
reset_context_before_encode(s, backup);
- s->c.block = s->c.blocks[*next_block];
+ s->block = s->blocks[*next_block];
s->pb = pb[*next_block];
if (s->c.data_partitioning) {
s->pb2 = pb2 [*next_block];
@@ -2758,7 +2760,7 @@ static void encode_mb_hq(MPVEncContext *const s, MBBackup *const backup, MBBacku
}
if (s->c.avctx->mb_decision == FF_MB_DECISION_RD) {
- mpv_reconstruct_mb(s, s->c.block);
+ mpv_reconstruct_mb(s, s->block);
score *= s->lambda2;
score += sse_mb(s) << FF_LAMBDA_SHIFT;
@@ -3446,7 +3448,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
}
if (s->c.avctx->mb_decision == FF_MB_DECISION_BITS)
- mpv_reconstruct_mb(s, s->c.block);
+ mpv_reconstruct_mb(s, s->block);
} else {
int motion_x = 0, motion_y = 0;
s->c.mv_type = MV_TYPE_16X16;
@@ -3569,7 +3571,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
s->c.out_format == FMT_H263 && s->c.pict_type != AV_PICTURE_TYPE_B)
ff_h263_update_mb(s);
- mpv_reconstruct_mb(s, s->c.block);
+ mpv_reconstruct_mb(s, s->block);
}
s->c.cur_pic.qscale_table[xy] = s->c.qscale;
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 5510b43f86..8ad2fe2e8a 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -31,6 +31,7 @@
#include <float.h>
#include "libavutil/avassert.h"
+#include "libavutil/mem_internal.h"
#include "libavutil/opt.h"
#include "fdctdsp.h"
#include "motion_est.h"
@@ -110,6 +111,8 @@ typedef struct MPVEncContext {
int coded_score[12];
+ int16_t (*block)[64]; ///< points into blocks below
+
/** precomputed matrix (combine qscale and DCT renorm) */
int (*q_intra_matrix)[64];
int (*q_chroma_intra_matrix)[64];
@@ -173,6 +176,8 @@ typedef struct MPVEncContext {
int (*sum_abs_dctelem)(const int16_t *block);
int intra_penalty;
+
+ DECLARE_ALIGNED_32(int16_t, blocks)[2][12][64]; // for HQ mode we need to keep the best block
} MPVEncContext;
typedef struct MPVMainEncContext {
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 06/48] avcodec/mpegvideo: Add MPVContext typedef
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (4 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 05/48] avcodec/mpegvideoenc: Allocate blocks as part of MPVEncContext Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 07/48] avcodec/mpegvideo_dec: Factor debugging dct coefficients out Andreas Rheinhardt
` (41 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
MpegEncContext is also used for decoding, so it is a misnomer.
This commit therefore adds MPVContext as typedef for it in order
to gradually switch the code to the new name (in line with
MPVEncContext).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 4ff5e8906d..fe3ae97f5d 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -332,6 +332,7 @@ typedef struct MpegEncContext {
ERContext er;
} MpegEncContext;
+typedef MpegEncContext MPVContext;
/**
* Set the given MpegEncContext to common defaults (same for encoding
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 07/48] avcodec/mpegvideo_dec: Factor debugging dct coefficients out
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (5 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 06/48] avcodec/mpegvideo: Add MPVContext typedef Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 08/48] avcodec/mpegvideo_dec: Reindent after the previous commit Andreas Rheinhardt
` (40 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This allows to hint to the compiler that the branch is likely
not taken by marking the factored out function as av_cold.
It is also in preparation for further commits.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_dec.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index f8551b93c8..c687f3a972 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -1064,6 +1064,19 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
}
}
+static av_cold void debug_dct_coeffs(MPVContext *s, const int16_t block[][64])
+{
+ /* print DCT coefficients */
+ av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
+ for (int i = 0; i < 6; i++) {
+ for (int j = 0; j < 64; j++) {
+ av_log(s->avctx, AV_LOG_DEBUG, "%5d",
+ block[i][s->idsp.idct_permutation[j]]);
+ }
+ av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ }
+}
+
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
{
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
@@ -1082,17 +1095,8 @@ void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
*mbskip_ptr = 0; /* not skipped */
}
- if (s->avctx->debug & FF_DEBUG_DCT_COEFF) {
- /* print DCT coefficients */
- av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 64; j++) {
- av_log(s->avctx, AV_LOG_DEBUG, "%5d",
- block[i][s->idsp.idct_permutation[j]]);
- }
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
- }
- }
+ if (s->avctx->debug & FF_DEBUG_DCT_COEFF)
+ debug_dct_coeffs(s, block);
av_assert2((s->out_format <= FMT_H261) == (s->out_format == FMT_H261 || s->out_format == FMT_MPEG1));
if (!s->avctx->lowres) {
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 08/48] avcodec/mpegvideo_dec: Reindent after the previous commit
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (6 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 07/48] avcodec/mpegvideo_dec: Factor debugging dct coefficients out Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 09/48] avcodec/mpeg_er: Don't use MpegEncContext.block Andreas Rheinhardt
` (39 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Also use dedicated variables for the accesses.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_dec.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index c687f3a972..903d435e8c 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -1066,15 +1066,18 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
static av_cold void debug_dct_coeffs(MPVContext *s, const int16_t block[][64])
{
- /* print DCT coefficients */
- av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 64; j++) {
- av_log(s->avctx, AV_LOG_DEBUG, "%5d",
- block[i][s->idsp.idct_permutation[j]]);
- }
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
- }
+ void *const logctx = s->avctx;
+ const uint8_t *const idct_permutation = s->idsp.idct_permutation;
+
+ /* print DCT coefficients */
+ av_log(logctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
+ for (int i = 0; i < 6; i++) {
+ for (int j = 0; j < 64; j++) {
+ av_log(logctx, AV_LOG_DEBUG, "%5d",
+ block[i][idct_permutation[j]]);
+ }
+ av_log(logctx, AV_LOG_DEBUG, "\n");
+ }
}
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 09/48] avcodec/mpeg_er: Don't use MpegEncContext.block
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (7 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 08/48] avcodec/mpegvideo_dec: Reindent after the previous commit Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 10/48] avcodec/mpegvideodec: Remove size expectation from ff_mpv_reconstruct_mb Andreas Rheinhardt
` (38 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It is unused (because unquantizing/the idct has been disabled)
apart from FF_DEBUG_DCT_COEFF debug code which makes no sense
when this function is called via error resilience. So pass a NULL
as block when calling ff_mpv_reconstruct_mb() from mpeg_er_decode_mb()
and disable the debug code in this scenario.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg_er.c | 4 ++--
libavcodec/mpegvideo_dec.c | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c
index 6ac3e7b3e7..951167a478 100644
--- a/libavcodec/mpeg_er.c
+++ b/libavcodec/mpeg_er.c
@@ -76,7 +76,7 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
s->mcsel = 0;
memcpy(s->mv, mv, sizeof(*mv));
- // The following disables the IDCT.
+ // The following disables unquantizing and the IDCT.
for (size_t i = 0; i < FF_ARRAY_ELEMS(s->block_last_index); i++)
s->block_last_index[i] = -1;
@@ -93,7 +93,7 @@ static void mpeg_er_decode_mb(void *opaque, int ref, int mv_dir, int mv_type,
if (ref)
av_log(s->avctx, AV_LOG_DEBUG,
"Interlaced error concealment is not fully implemented\n");
- ff_mpv_reconstruct_mb(s, s->block);
+ ff_mpv_reconstruct_mb(s, NULL);
}
av_cold int ff_mpeg_er_init(MpegEncContext *s)
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 903d435e8c..928464d6c1 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -1066,6 +1066,9 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
static av_cold void debug_dct_coeffs(MPVContext *s, const int16_t block[][64])
{
+ if (!block) // happens when called via error resilience
+ return;
+
void *const logctx = s->avctx;
const uint8_t *const idct_permutation = s->idsp.idct_permutation;
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 10/48] avcodec/mpegvideodec: Remove size expectation from ff_mpv_reconstruct_mb
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (8 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 09/48] avcodec/mpeg_er: Don't use MpegEncContext.block Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 11/48] avcodec/h261dec: Stop using MpegEncContext.gb Andreas Rheinhardt
` (37 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
In the common case of decoding 420 content, only six blocks are used
and it makes perfect sense for the caller to only have that many.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo_dec.c | 2 +-
libavcodec/mpegvideodec.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 928464d6c1..c4831bf85b 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -1083,7 +1083,7 @@ static av_cold void debug_dct_coeffs(MPVContext *s, const int16_t block[][64])
}
}
-void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
+void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64])
{
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
diff --git a/libavcodec/mpegvideodec.h b/libavcodec/mpegvideodec.h
index 8bc70b02c0..5b2a38d1c8 100644
--- a/libavcodec/mpegvideodec.h
+++ b/libavcodec/mpegvideodec.h
@@ -56,7 +56,7 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx);
* Ensure that the dummy frames are allocated according to pict_type if necessary.
*/
int ff_mpv_alloc_dummy_frames(MpegEncContext *s);
-void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]);
+void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64]);
void ff_mpv_frame_end(MpegEncContext *s);
int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f,
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 11/48] avcodec/h261dec: Stop using MpegEncContext.gb
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (9 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 10/48] avcodec/mpegvideodec: Remove size expectation from ff_mpv_reconstruct_mb Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 12/48] avcodec/h261dec: Don't use MpegEncContext.block Andreas Rheinhardt
` (36 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is in preparation for removing said field from MpegEncContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 80 +++++++++++++++++++++++---------------------
1 file changed, 41 insertions(+), 39 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 146f979a5e..50fc375c26 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -29,6 +29,7 @@
#include "avcodec.h"
#include "codec_internal.h"
#include "decode.h"
+#include "get_bits.h"
#include "mpeg_er.h"
#include "mpegutils.h"
#include "mpegvideo.h"
@@ -51,6 +52,8 @@ static VLCElem h261_cbp_vlc[512];
typedef struct H261DecContext {
MpegEncContext s;
+ GetBitContext gb;
+
H261Context common;
int current_mba;
@@ -129,18 +132,18 @@ static int h261_decode_gob_header(H261DecContext *h)
if (!h->gob_start_code_skipped) {
/* Check for GOB Start Code */
- val = show_bits(&s->gb, 15);
+ val = show_bits(&h->gb, 15);
if (val)
return -1;
/* We have a GBSC */
- skip_bits(&s->gb, 16);
+ skip_bits(&h->gb, 16);
}
h->gob_start_code_skipped = 0;
- h->gob_number = get_bits(&s->gb, 4); /* GN */
- s->qscale = get_bits(&s->gb, 5); /* GQUANT */
+ h->gob_number = get_bits(&h->gb, 4); /* GN */
+ s->qscale = get_bits(&h->gb, 5); /* GQUANT */
/* Check if gob_number is valid */
if (s->mb_height == 18) { // CIF
@@ -153,7 +156,7 @@ static int h261_decode_gob_header(H261DecContext *h)
}
/* GEI */
- if (skip_1stop_8data_bits(&s->gb) < 0)
+ if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA;
if (s->qscale == 0) {
@@ -257,7 +260,7 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
scan_table = s->intra_scantable.permutated;
if (s->mb_intra) {
/* DC coef */
- level = get_bits(&s->gb, 8);
+ level = get_bits(&h->gb, 8);
// 0 (00000000b) and -128 (10000000b) are FORBIDDEN
if ((level & 0x7F) == 0) {
av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
@@ -275,10 +278,10 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
// EOB Not possible for first level when cbp is available (that's why the table is different)
// 0 1 1s
// * * 0*
- int check = show_bits(&s->gb, 2);
+ int check = show_bits(&h->gb, 2);
i = 0;
if (check & 0x2) {
- skip_bits(&s->gb, 2);
+ skip_bits(&h->gb, 2);
block[0] = qmul + qadd;
block[0] *= (check & 0x1) ? -1 : 1;
i = 1;
@@ -291,14 +294,14 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
return 0;
}
{
- OPEN_READER(re, &s->gb);
+ OPEN_READER(re, &h->gb);
i--; // offset by -1 to allow direct indexing of scan_table
for (;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TCOEFF_VLC_BITS, 2, 0);
+ UPDATE_CACHE(re, &h->gb);
+ GET_RL_VLC(level, run, re, &h->gb, rl->rl_vlc[0], TCOEFF_VLC_BITS, 2, 0);
if (run == 66) {
if (level) {
- CLOSE_READER(re, &s->gb);
+ CLOSE_READER(re, &h->gb);
av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
s->mb_x, s->mb_y);
return -1;
@@ -307,25 +310,25 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
/* The remaining combinations of (run, level) are encoded with a
* 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
* level. */
- run = SHOW_UBITS(re, &s->gb, 6) + 1;
- SKIP_CACHE(re, &s->gb, 6);
- level = SHOW_SBITS(re, &s->gb, 8);
+ run = SHOW_UBITS(re, &h->gb, 6) + 1;
+ SKIP_CACHE(re, &h->gb, 6);
+ level = SHOW_SBITS(re, &h->gb, 8);
if (level > 0)
level = level * qmul + qadd;
else if (level < 0)
level = level * qmul - qadd;
- SKIP_COUNTER(re, &s->gb, 6 + 8);
+ SKIP_COUNTER(re, &h->gb, 6 + 8);
} else if (level == 0) {
break;
} else {
level = level * qmul + qadd;
- if (SHOW_UBITS(re, &s->gb, 1))
+ if (SHOW_UBITS(re, &h->gb, 1))
level = -level;
- SKIP_COUNTER(re, &s->gb, 1);
+ SKIP_COUNTER(re, &h->gb, 1);
}
i += run;
if (i >= 64) {
- CLOSE_READER(re, &s->gb);
+ CLOSE_READER(re, &h->gb);
av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
s->mb_x, s->mb_y);
return -1;
@@ -333,7 +336,7 @@ static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded
j = scan_table[i];
block[j] = level;
}
- CLOSE_READER(re, &s->gb);
+ CLOSE_READER(re, &h->gb);
}
s->block_last_index[n] = i;
return 0;
@@ -348,7 +351,7 @@ static int h261_decode_mb(H261DecContext *h)
cbp = 63;
// Read mba
do {
- h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc,
+ h->mba_diff = get_vlc2(&h->gb, h261_mba_vlc,
H261_MBA_VLC_BITS, 2);
/* Check for slice end */
@@ -360,7 +363,7 @@ static int h261_decode_mb(H261DecContext *h)
} while (h->mba_diff == MBA_STUFFING); // stuffing
if (h->mba_diff < 0) {
- if (get_bits_left(&s->gb) <= 7)
+ if (get_bits_left(&h->gb) <= 7)
return SLICE_END;
av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
@@ -379,7 +382,7 @@ static int h261_decode_mb(H261DecContext *h)
h261_init_dest(s);
// Read mtype
- com->mtype = get_vlc2(&s->gb, h261_mtype_vlc, H261_MTYPE_VLC_BITS, 2);
+ com->mtype = get_vlc2(&h->gb, h261_mtype_vlc, H261_MTYPE_VLC_BITS, 2);
if (com->mtype < 0) {
av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index\n");
return SLICE_ERROR;
@@ -387,7 +390,7 @@ static int h261_decode_mb(H261DecContext *h)
// Read mquant
if (IS_QUANT(com->mtype)) {
- s->qscale = get_bits(&s->gb, 5);
+ s->qscale = get_bits(&h->gb, 5);
if (!s->qscale)
s->qscale = 1;
}
@@ -410,8 +413,8 @@ static int h261_decode_mb(H261DecContext *h)
h->current_mv_y = 0;
}
- h->current_mv_x = decode_mv_component(&s->gb, h->current_mv_x);
- h->current_mv_y = decode_mv_component(&s->gb, h->current_mv_y);
+ h->current_mv_x = decode_mv_component(&h->gb, h->current_mv_x);
+ h->current_mv_y = decode_mv_component(&h->gb, h->current_mv_y);
} else {
h->current_mv_x = 0;
h->current_mv_y = 0;
@@ -419,7 +422,7 @@ static int h261_decode_mb(H261DecContext *h)
// Read cbp
if (HAS_CBP(com->mtype))
- cbp = get_vlc2(&s->gb, h261_cbp_vlc, H261_CBP_VLC_BITS, 1) + 1;
+ cbp = get_vlc2(&h->gb, h261_cbp_vlc, H261_CBP_VLC_BITS, 1) + 1;
if (s->mb_intra) {
s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
@@ -466,11 +469,10 @@ intra:
static int h261_decode_picture_header(H261DecContext *h, int *is_key)
{
MpegEncContext *const s = &h->s;
- int format, i;
uint32_t startcode = 0;
- for (i = get_bits_left(&s->gb); i > 24; i -= 1) {
- startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
+ for (int i = get_bits_left(&h->gb); i > 24; i -= 1) {
+ startcode = ((startcode << 1) | get_bits(&h->gb, 1)) & 0x000FFFFF;
if (startcode == 0x10)
break;
@@ -482,14 +484,14 @@ static int h261_decode_picture_header(H261DecContext *h, int *is_key)
}
/* temporal reference */
- skip_bits(&s->gb, 5); /* picture timestamp */
+ skip_bits(&h->gb, 5); /* picture timestamp */
/* PTYPE starts here */
- skip_bits1(&s->gb); /* split screen off */
- skip_bits1(&s->gb); /* camera off */
- *is_key = get_bits1(&s->gb); /* freeze picture release off */
+ skip_bits1(&h->gb); /* split screen off */
+ skip_bits1(&h->gb); /* camera off */
+ *is_key = get_bits1(&h->gb); /* freeze picture release off */
- format = get_bits1(&s->gb);
+ int format = get_bits1(&h->gb);
// only 2 formats possible
if (format == 0) { // QCIF
@@ -500,11 +502,11 @@ static int h261_decode_picture_header(H261DecContext *h, int *is_key)
s->height = 288;
}
- skip_bits1(&s->gb); /* still image mode off */
- skip_bits1(&s->gb); /* Reserved */
+ skip_bits1(&h->gb); /* still image mode off */
+ skip_bits1(&h->gb); /* Reserved */
/* PEI */
- if (skip_1stop_8data_bits(&s->gb) < 0)
+ if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA;
h->gob_number = 0;
@@ -552,7 +554,7 @@ static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict,
h->gob_start_code_skipped = 0;
- init_get_bits(&s->gb, buf, buf_size * 8);
+ init_get_bits(&h->gb, buf, buf_size * 8);
ret = h261_decode_picture_header(h, &is_key);
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 12/48] avcodec/h261dec: Don't use MpegEncContext.block
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (10 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 11/48] avcodec/h261dec: Stop using MpegEncContext.gb Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 13/48] avcodec/mpeg12dec: Put GetBitContext on the stack where advantageous Andreas Rheinhardt
` (35 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Instead put it into H261DecContext. This is in preparation
for removing MpegEncContext.block.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index 50fc375c26..e47bc00a71 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -25,6 +25,7 @@
* H.261 decoder.
*/
+#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"
#include "avcodec.h"
#include "codec_internal.h"
@@ -62,6 +63,8 @@ typedef struct H261DecContext {
int current_mv_y;
int gob_number;
int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
+
+ DECLARE_ALIGNED_32(int16_t, block)[6][64];
} H261DecContext;
static av_cold void h261_decode_init_static(void)
@@ -213,7 +216,7 @@ static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2)
s->cur_pic.motion_val[0][b_xy][1] = s->mv[0][0][1];
}
- ff_mpv_reconstruct_mb(s, s->block);
+ ff_mpv_reconstruct_mb(s, h->block);
}
return 0;
@@ -446,9 +449,9 @@ static int h261_decode_mb(H261DecContext *h)
intra:
/* decode each block */
if (s->mb_intra || HAS_CBP(com->mtype)) {
- s->bdsp.clear_blocks(s->block[0]);
+ s->bdsp.clear_blocks(h->block[0]);
for (i = 0; i < 6; i++) {
- if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0)
+ if (h261_decode_block(h, h->block[i], i, cbp & 32) < 0)
return SLICE_ERROR;
cbp += cbp;
}
@@ -457,7 +460,7 @@ intra:
s->block_last_index[i] = -1;
}
- ff_mpv_reconstruct_mb(s, s->block);
+ ff_mpv_reconstruct_mb(s, h->block);
return SLICE_OK;
}
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 13/48] avcodec/mpeg12dec: Put GetBitContext on the stack where advantageous
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (11 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 12/48] avcodec/h261dec: Don't use MpegEncContext.block Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 14/48] avcodec/mpeg12dec: Remove unused function parameter Andreas Rheinhardt
` (34 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is in preparation for no longer using MpegEncContext.gb.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 192 ++++++++++++++++++++++-------------------
1 file changed, 102 insertions(+), 90 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 5d2719d0f0..ec8b213206 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -44,6 +44,7 @@
#include "codec_internal.h"
#include "decode.h"
#include "error_resilience.h"
+#include "get_bits.h"
#include "hwaccel_internal.h"
#include "hwconfig.h"
#include "idctdsp.h"
@@ -969,23 +970,24 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf,
{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
+ GetBitContext gb0, *const gb = &gb0;
int ref, f_code, vbv_delay, ret;
- ret = init_get_bits8(&s->gb, buf, buf_size);
+ ret = init_get_bits8(gb, buf, buf_size);
if (ret < 0)
return ret;
- ref = get_bits(&s->gb, 10); /* temporal ref */
- s->pict_type = get_bits(&s->gb, 3);
+ ref = get_bits(gb, 10); /* temporal ref */
+ s->pict_type = get_bits(gb, 3);
if (s->pict_type == 0 || s->pict_type > 3)
return AVERROR_INVALIDDATA;
- vbv_delay = get_bits(&s->gb, 16);
+ vbv_delay = get_bits(gb, 16);
s1->vbv_delay = vbv_delay;
if (s->pict_type == AV_PICTURE_TYPE_P ||
s->pict_type == AV_PICTURE_TYPE_B) {
- s->full_pel[0] = get_bits1(&s->gb);
- f_code = get_bits(&s->gb, 3);
+ s->full_pel[0] = get_bits1(gb);
+ f_code = get_bits(gb, 3);
if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)))
return AVERROR_INVALIDDATA;
f_code += !f_code;
@@ -993,8 +995,8 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf,
s->mpeg_f_code[0][1] = f_code;
}
if (s->pict_type == AV_PICTURE_TYPE_B) {
- s->full_pel[1] = get_bits1(&s->gb);
- f_code = get_bits(&s->gb, 3);
+ s->full_pel[1] = get_bits1(gb);
+ f_code = get_bits(gb, 3);
if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)))
return AVERROR_INVALIDDATA;
f_code += !f_code;
@@ -1009,38 +1011,39 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf,
return 0;
}
-static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
+static void mpeg_decode_sequence_extension(Mpeg1Context *const s1,
+ GetBitContext *const gb)
{
MpegEncContext *s = &s1->mpeg_enc_ctx;
int horiz_size_ext, vert_size_ext;
int bit_rate_ext;
- skip_bits(&s->gb, 1); /* profile and level esc*/
- s->avctx->profile = get_bits(&s->gb, 3);
- s->avctx->level = get_bits(&s->gb, 4);
- s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
- s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
+ skip_bits(gb, 1); /* profile and level esc*/
+ s->avctx->profile = get_bits(gb, 3);
+ s->avctx->level = get_bits(gb, 4);
+ s->progressive_sequence = get_bits1(gb); /* progressive_sequence */
+ s->chroma_format = get_bits(gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
if (!s->chroma_format) {
s->chroma_format = CHROMA_420;
av_log(s->avctx, AV_LOG_WARNING, "Chroma format invalid\n");
}
- horiz_size_ext = get_bits(&s->gb, 2);
- vert_size_ext = get_bits(&s->gb, 2);
+ horiz_size_ext = get_bits(gb, 2);
+ vert_size_ext = get_bits(gb, 2);
s->width |= (horiz_size_ext << 12);
s->height |= (vert_size_ext << 12);
- bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */
+ bit_rate_ext = get_bits(gb, 12); /* XXX: handle it */
s1->bit_rate += (bit_rate_ext << 18) * 400LL;
- check_marker(s->avctx, &s->gb, "after bit rate extension");
- s->avctx->rc_buffer_size += get_bits(&s->gb, 8) * 1024 * 16 << 10;
+ check_marker(s->avctx, gb, "after bit rate extension");
+ s->avctx->rc_buffer_size += get_bits(gb, 8) * 1024 * 16 << 10;
- s->low_delay = get_bits1(&s->gb);
+ s->low_delay = get_bits1(gb);
if (s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
s->low_delay = 1;
- s1->frame_rate_ext.num = get_bits(&s->gb, 2) + 1;
- s1->frame_rate_ext.den = get_bits(&s->gb, 5) + 1;
+ s1->frame_rate_ext.num = get_bits(gb, 2) + 1;
+ s1->frame_rate_ext.den = get_bits(gb, 5) + 1;
ff_dlog(s->avctx, "sequence extension\n");
s->codec_id = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
@@ -1052,21 +1055,22 @@ static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
s->avctx->rc_buffer_size, s1->bit_rate);
}
-static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
+static void mpeg_decode_sequence_display_extension(Mpeg1Context *const s1,
+ GetBitContext *const gb)
{
MpegEncContext *s = &s1->mpeg_enc_ctx;
int color_description, w, h;
- skip_bits(&s->gb, 3); /* video format */
- color_description = get_bits1(&s->gb);
+ skip_bits(gb, 3); /* video format */
+ color_description = get_bits1(gb);
if (color_description) {
- s->avctx->color_primaries = get_bits(&s->gb, 8);
- s->avctx->color_trc = get_bits(&s->gb, 8);
- s->avctx->colorspace = get_bits(&s->gb, 8);
+ s->avctx->color_primaries = get_bits(gb, 8);
+ s->avctx->color_trc = get_bits(gb, 8);
+ s->avctx->colorspace = get_bits(gb, 8);
}
- w = get_bits(&s->gb, 14);
- skip_bits(&s->gb, 1); // marker
- h = get_bits(&s->gb, 14);
+ w = get_bits(gb, 14);
+ skip_bits(gb, 1); // marker
+ h = get_bits(gb, 14);
// remaining 3 bits are zero padding
s1->pan_scan.width = 16 * w;
@@ -1076,7 +1080,8 @@ static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h);
}
-static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
+static void mpeg_decode_picture_display_extension(Mpeg1Context *const s1,
+ GetBitContext *const gb)
{
MpegEncContext *s = &s1->mpeg_enc_ctx;
int i, nofco;
@@ -1096,10 +1101,10 @@ static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
}
}
for (i = 0; i < nofco; i++) {
- s1->pan_scan.position[i][0] = get_sbits(&s->gb, 16);
- skip_bits(&s->gb, 1); // marker
- s1->pan_scan.position[i][1] = get_sbits(&s->gb, 16);
- skip_bits(&s->gb, 1); // marker
+ s1->pan_scan.position[i][0] = get_sbits(gb, 16);
+ skip_bits(gb, 1); // marker
+ s1->pan_scan.position[i][1] = get_sbits(gb, 16);
+ skip_bits(gb, 1); // marker
}
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
@@ -1110,14 +1115,14 @@ static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]);
}
-static int load_matrix(MpegEncContext *s, uint16_t matrix0[64],
- uint16_t matrix1[64], int intra)
+static int load_matrix(MPVContext *const s, GetBitContext *const gb,
+ uint16_t matrix0[64], uint16_t matrix1[64], int intra)
{
int i;
for (i = 0; i < 64; i++) {
int j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
- int v = get_bits(&s->gb, 8);
+ int v = get_bits(gb, 8);
if (v == 0) {
av_log(s->avctx, AV_LOG_ERROR, "matrix damaged\n");
return AVERROR_INVALIDDATA;
@@ -1133,29 +1138,31 @@ static int load_matrix(MpegEncContext *s, uint16_t matrix0[64],
return 0;
}
-static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
+static void mpeg_decode_quant_matrix_extension(MPVContext *const s,
+ GetBitContext *const gb)
{
ff_dlog(s->avctx, "matrix extension\n");
- if (get_bits1(&s->gb))
- load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
- if (get_bits1(&s->gb))
- load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
- if (get_bits1(&s->gb))
- load_matrix(s, s->chroma_intra_matrix, NULL, 1);
- if (get_bits1(&s->gb))
- load_matrix(s, s->chroma_inter_matrix, NULL, 0);
+ if (get_bits1(gb))
+ load_matrix(s, gb, s->chroma_intra_matrix, s->intra_matrix, 1);
+ if (get_bits1(gb))
+ load_matrix(s, gb, s->chroma_inter_matrix, s->inter_matrix, 0);
+ if (get_bits1(gb))
+ load_matrix(s, gb, s->chroma_intra_matrix, NULL, 1);
+ if (get_bits1(gb))
+ load_matrix(s, gb, s->chroma_inter_matrix, NULL, 0);
}
-static int mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
+static int mpeg_decode_picture_coding_extension(Mpeg1Context *const s1,
+ GetBitContext *const gb)
{
MpegEncContext *s = &s1->mpeg_enc_ctx;
s->full_pel[0] = s->full_pel[1] = 0;
- s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
- s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
- s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
- s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
+ s->mpeg_f_code[0][0] = get_bits(gb, 4);
+ s->mpeg_f_code[0][1] = get_bits(gb, 4);
+ s->mpeg_f_code[1][0] = get_bits(gb, 4);
+ s->mpeg_f_code[1][1] = get_bits(gb, 4);
s->mpeg_f_code[0][0] += !s->mpeg_f_code[0][0];
s->mpeg_f_code[0][1] += !s->mpeg_f_code[0][1];
s->mpeg_f_code[1][0] += !s->mpeg_f_code[1][0];
@@ -1174,17 +1181,17 @@ static int mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
s->pict_type = AV_PICTURE_TYPE_B;
}
- s->intra_dc_precision = get_bits(&s->gb, 2);
- s->picture_structure = get_bits(&s->gb, 2);
- s->top_field_first = get_bits1(&s->gb);
- s->frame_pred_frame_dct = get_bits1(&s->gb);
- s->concealment_motion_vectors = get_bits1(&s->gb);
- s->q_scale_type = get_bits1(&s->gb);
- s->intra_vlc_format = get_bits1(&s->gb);
- s->alternate_scan = get_bits1(&s->gb);
- s->repeat_first_field = get_bits1(&s->gb);
- s->chroma_420_type = get_bits1(&s->gb);
- s->progressive_frame = get_bits1(&s->gb);
+ s->intra_dc_precision = get_bits(gb, 2);
+ s->picture_structure = get_bits(gb, 2);
+ s->top_field_first = get_bits1(gb);
+ s->frame_pred_frame_dct = get_bits1(gb);
+ s->concealment_motion_vectors = get_bits1(gb);
+ s->q_scale_type = get_bits1(gb);
+ s->intra_vlc_format = get_bits1(gb);
+ s->alternate_scan = get_bits1(gb);
+ s->repeat_first_field = get_bits1(gb);
+ s->chroma_420_type = get_bits1(gb);
+ s->progressive_frame = get_bits1(gb);
// We only initialize intra_scantable.permutated, as this is all we use.
ff_permute_scantable(s->intra_scantable.permutated,
@@ -1724,44 +1731,45 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
+ GetBitContext gb0, *const gb = &gb0;
int width, height;
int i, v, j;
- int ret = init_get_bits8(&s->gb, buf, buf_size);
+ int ret = init_get_bits8(gb, buf, buf_size);
if (ret < 0)
return ret;
- width = get_bits(&s->gb, 12);
- height = get_bits(&s->gb, 12);
+ width = get_bits(gb, 12);
+ height = get_bits(gb, 12);
if (width == 0 || height == 0) {
av_log(avctx, AV_LOG_WARNING,
"Invalid horizontal or vertical size value.\n");
if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
return AVERROR_INVALIDDATA;
}
- s1->aspect_ratio_info = get_bits(&s->gb, 4);
+ s1->aspect_ratio_info = get_bits(gb, 4);
if (s1->aspect_ratio_info == 0) {
av_log(avctx, AV_LOG_ERROR, "aspect ratio has forbidden 0 value\n");
if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
return AVERROR_INVALIDDATA;
}
- s1->frame_rate_index = get_bits(&s->gb, 4);
+ s1->frame_rate_index = get_bits(gb, 4);
if (s1->frame_rate_index == 0 || s1->frame_rate_index > 13) {
av_log(avctx, AV_LOG_WARNING,
"frame_rate_index %d is invalid\n", s1->frame_rate_index);
s1->frame_rate_index = 1;
}
- s1->bit_rate = get_bits(&s->gb, 18) * 400;
- if (check_marker(s->avctx, &s->gb, "in sequence header") == 0) {
+ s1->bit_rate = get_bits(gb, 18) * 400;
+ if (check_marker(s->avctx, gb, "in sequence header") == 0) {
return AVERROR_INVALIDDATA;
}
- s->avctx->rc_buffer_size = get_bits(&s->gb, 10) * 1024 * 16;
- skip_bits(&s->gb, 1);
+ s->avctx->rc_buffer_size = get_bits(gb, 10) * 1024 * 16;
+ skip_bits(gb, 1);
/* get matrix */
- if (get_bits1(&s->gb)) {
- load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
+ if (get_bits1(gb)) {
+ load_matrix(s, gb, s->chroma_intra_matrix, s->intra_matrix, 1);
} else {
for (i = 0; i < 64; i++) {
j = s->idsp.idct_permutation[i];
@@ -1770,8 +1778,8 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
s->chroma_intra_matrix[j] = v;
}
}
- if (get_bits1(&s->gb)) {
- load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
+ if (get_bits1(gb)) {
+ load_matrix(s, gb, s->chroma_inter_matrix, s->inter_matrix, 0);
} else {
for (i = 0; i < 64; i++) {
int j = s->idsp.idct_permutation[i];
@@ -1781,7 +1789,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
}
}
- if (show_bits(&s->gb, 23) != 0) {
+ if (show_bits(gb, 23) != 0) {
av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n");
return AVERROR_INVALIDDATA;
}
@@ -2158,20 +2166,21 @@ static int mpeg_decode_gop(AVCodecContext *avctx,
{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
+ GetBitContext gb0, *const gb = &gb0;
int broken_link;
int64_t tc;
- int ret = init_get_bits8(&s->gb, buf, buf_size);
+ int ret = init_get_bits8(gb, buf, buf_size);
if (ret < 0)
return ret;
- tc = s1->timecode_frame_start = get_bits(&s->gb, 25);
+ tc = s1->timecode_frame_start = get_bits(gb, 25);
- s1->closed_gop = get_bits1(&s->gb);
+ s1->closed_gop = get_bits1(gb);
/* broken_link indicates that after editing the
* reference frames of the first B-Frames after GOP I-Frame
* are missing (open gop) */
- broken_link = get_bits1(&s->gb);
+ broken_link = get_bits1(gb);
if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
char tcbuf[AV_TIMECODE_STR_SIZE];
@@ -2313,15 +2322,17 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
return AVERROR_INVALIDDATA;
}
break;
- case EXT_START_CODE:
- ret = init_get_bits8(&s2->gb, buf_ptr, input_size);
+ case EXT_START_CODE: {
+ GetBitContext gb0, *const gb = &gb0;
+
+ ret = init_get_bits8(gb, buf_ptr, input_size);
if (ret < 0)
return ret;
- switch (get_bits(&s2->gb, 4)) {
+ switch (get_bits(gb, 4)) {
case 0x1:
if (last_code == 0) {
- mpeg_decode_sequence_extension(s);
+ mpeg_decode_sequence_extension(s, gb);
} else {
av_log(avctx, AV_LOG_ERROR,
"ignoring seq ext after %X\n", last_code);
@@ -2330,17 +2341,17 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
}
break;
case 0x2:
- mpeg_decode_sequence_display_extension(s);
+ mpeg_decode_sequence_display_extension(s, gb);
break;
case 0x3:
- mpeg_decode_quant_matrix_extension(s2);
+ mpeg_decode_quant_matrix_extension(s2, gb);
break;
case 0x7:
- mpeg_decode_picture_display_extension(s);
+ mpeg_decode_picture_display_extension(s, gb);
break;
case 0x8:
if (last_code == PICTURE_START_CODE) {
- int ret = mpeg_decode_picture_coding_extension(s);
+ int ret = mpeg_decode_picture_coding_extension(s, gb);
if (ret < 0)
return ret;
} else {
@@ -2352,6 +2363,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
break;
}
break;
+ }
case USER_START_CODE:
mpeg_decode_user_data(avctx, buf_ptr, input_size);
break;
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 14/48] avcodec/mpeg12dec: Remove unused function parameter
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (12 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 13/48] avcodec/mpeg12dec: Put GetBitContext on the stack where advantageous Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 15/48] avcodec/rv34: Don't use MpegEncContext.gb Andreas Rheinhardt
` (33 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index ec8b213206..a056dd87cc 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -395,7 +395,7 @@ static inline int get_dmv(MpegEncContext *s)
#define MT_16X8 2
#define MT_DMV 3
-static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
+static int mpeg_decode_mb(MPVContext *const s)
{
int i, j, k, cbp, val, mb_type, motion_type;
const int mb_block_count = 4 + (1 << s->chroma_format);
@@ -1449,7 +1449,8 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
}
for (;;) {
- if ((ret = mpeg_decode_mb(s, s->block)) < 0)
+ ret = mpeg_decode_mb(s);
+ if (ret < 0)
return ret;
// Note motion_val is normally NULL unless we want to extract the MVs.
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 15/48] avcodec/rv34: Don't use MpegEncContext.gb
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (13 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 14/48] avcodec/mpeg12dec: Remove unused function parameter Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 16/48] avcodec/rv34: Don't use MpegEncContext.block Andreas Rheinhardt
` (32 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is in preparation for removing MpegEncContext.gb.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv30.c | 2 +-
libavcodec/rv34.c | 28 ++++++++++++++--------------
libavcodec/rv34.h | 2 ++
libavcodec/rv40.c | 2 +-
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/libavcodec/rv30.c b/libavcodec/rv30.c
index 351276995b..e0b5395fa6 100644
--- a/libavcodec/rv30.c
+++ b/libavcodec/rv30.c
@@ -116,7 +116,7 @@ static int rv30_decode_mb_info(RV34DecContext *r)
static const int rv30_p_types[6] = { RV34_MB_SKIP, RV34_MB_P_16x16, RV34_MB_P_8x8, -1, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 };
static const int rv30_b_types[6] = { RV34_MB_SKIP, RV34_MB_B_DIRECT, RV34_MB_B_FORWARD, RV34_MB_B_BACKWARD, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 };
MpegEncContext *s = &r->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &r->gb;
unsigned code = get_interleaved_ue_golomb(gb);
if (code > 11) {
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 5dcbe9a222..73fd16b3e2 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -363,7 +363,7 @@ static inline RV34VLC* choose_vlc_set(int quant, int mod, int type)
static int rv34_decode_intra_mb_header(RV34DecContext *r, int8_t *intra_types)
{
MpegEncContext *s = &r->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &r->gb;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int t;
@@ -398,7 +398,7 @@ static int rv34_decode_intra_mb_header(RV34DecContext *r, int8_t *intra_types)
static int rv34_decode_inter_mb_header(RV34DecContext *r, int8_t *intra_types)
{
MpegEncContext *s = &r->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &r->gb;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int i, t;
@@ -871,7 +871,7 @@ static const int num_mvs[RV34_MB_TYPES] = { 0, 0, 1, 4, 1, 1, 0, 0, 2, 2, 2, 1 }
static int rv34_decode_mv(RV34DecContext *r, int block_type)
{
MpegEncContext *s = &r->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &r->gb;
int i, j, k, l;
int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride;
int next_bt;
@@ -1031,7 +1031,7 @@ static inline void rv34_process_block(RV34DecContext *r,
{
MpegEncContext *s = &r->s;
int16_t *ptr = s->block[0];
- int has_ac = rv34_decode_block(ptr, &s->gb, r->cur_vlcs,
+ int has_ac = rv34_decode_block(ptr, &r->gb, r->cur_vlcs,
fc, sc, q_dc, q_ac, q_ac);
if(has_ac){
r->rdsp.rv34_idct_add(pdst, stride, ptr);
@@ -1045,7 +1045,7 @@ static void rv34_output_i16x16(RV34DecContext *r, int8_t *intra_types, int cbp)
{
LOCAL_ALIGNED_16(int16_t, block16, [16]);
MpegEncContext *s = &r->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &r->gb;
int q_dc = rv34_qscale_tab[ r->luma_dc_quant_i[s->qscale] ],
q_ac = rv34_qscale_tab[s->qscale];
uint8_t *dst = s->dest[0];
@@ -1213,7 +1213,7 @@ static int rv34_set_deblock_coef(RV34DecContext *r)
static int rv34_decode_inter_macroblock(RV34DecContext *r, int8_t *intra_types)
{
MpegEncContext *s = &r->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &r->gb;
uint8_t *dst = s->dest[0];
int16_t *ptr = s->block[0];
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
@@ -1367,8 +1367,8 @@ static int check_slice_end(RV34DecContext *r, MpegEncContext *s)
return 1;
if(r->s.mb_skip_run > 1)
return 0;
- bits = get_bits_left(&s->gb);
- if(bits <= 0 || (bits < 8 && !show_bits(&s->gb, bits)))
+ bits = get_bits_left(&r->gb);
+ if (bits <= 0 || (bits < 8 && !show_bits(&r->gb, bits)))
return 1;
return 0;
}
@@ -1424,11 +1424,11 @@ static int rv34_decoder_realloc(RV34DecContext *r)
static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int buf_size)
{
MpegEncContext *s = &r->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &r->gb;
int mb_pos, slice_type;
int res;
- init_get_bits(&r->s.gb, buf, buf_size*8);
+ init_get_bits(gb, buf, buf_size*8);
res = r->parse_slice_header(r, gb, &r->si);
if(res < 0){
av_log(s->avctx, AV_LOG_ERROR, "Incorrect or unknown slice header\n");
@@ -1651,8 +1651,8 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
return AVERROR_INVALIDDATA;
}
- init_get_bits(&s->gb, buf+offset, (buf_size-offset)*8);
- if(r->parse_slice_header(r, &r->s.gb, &si) < 0 || si.start){
+ init_get_bits(&r->gb, buf+offset, (buf_size-offset)*8);
+ if (r->parse_slice_header(r, &r->gb, &si) < 0 || si.start) {
av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n");
return AVERROR_INVALIDDATA;
}
@@ -1781,8 +1781,8 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n");
break;
}
- init_get_bits(&s->gb, buf+offset1, (buf_size-offset1)*8);
- if(r->parse_slice_header(r, &r->s.gb, &si) < 0){
+ init_get_bits(&r->gb, buf+offset1, (buf_size-offset1)*8);
+ if (r->parse_slice_header(r, &r->gb, &si) < 0) {
size = offset2 - offset;
}else
r->si.end = si.start;
diff --git a/libavcodec/rv34.h b/libavcodec/rv34.h
index 6fe1f8087d..485a034f9e 100644
--- a/libavcodec/rv34.h
+++ b/libavcodec/rv34.h
@@ -30,6 +30,7 @@
#include "libavutil/mem_internal.h"
#include "avcodec.h"
+#include "get_bits.h"
#include "mpegvideo.h"
#include "h264pred.h"
@@ -85,6 +86,7 @@ typedef struct SliceInfo{
/** decoder context */
typedef struct RV34DecContext{
MpegEncContext s;
+ GetBitContext gb;
RV34DSPContext rdsp;
int8_t *intra_types_hist;///< old block types, used for prediction
int8_t *intra_types; ///< block types
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index d28e02c2d1..79e99e9efd 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -226,7 +226,7 @@ static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t
static int rv40_decode_mb_info(RV34DecContext *r)
{
MpegEncContext *s = &r->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &r->gb;
int q, i;
int prev_type = 0;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 16/48] avcodec/rv34: Don't use MpegEncContext.block
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (14 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 15/48] avcodec/rv34: Don't use MpegEncContext.gb Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 17/48] avcodec/intrax8: Don't pretend to need more than one int16_t[64] Andreas Rheinhardt
` (31 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
These decoders only need a single 4x4 block; put it in RV34DecContext.
This is in preparation for removing MpegEncContext.block.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv34.c | 7 +++----
libavcodec/rv34.h | 1 +
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 73fd16b3e2..9f8a0f12b8 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1029,8 +1029,7 @@ static inline void rv34_process_block(RV34DecContext *r,
uint8_t *pdst, int stride,
int fc, int sc, int q_dc, int q_ac)
{
- MpegEncContext *s = &r->s;
- int16_t *ptr = s->block[0];
+ int16_t *const ptr = r->block;
int has_ac = rv34_decode_block(ptr, &r->gb, r->cur_vlcs,
fc, sc, q_dc, q_ac, q_ac);
if(has_ac){
@@ -1049,7 +1048,7 @@ static void rv34_output_i16x16(RV34DecContext *r, int8_t *intra_types, int cbp)
int q_dc = rv34_qscale_tab[ r->luma_dc_quant_i[s->qscale] ],
q_ac = rv34_qscale_tab[s->qscale];
uint8_t *dst = s->dest[0];
- int16_t *ptr = s->block[0];
+ int16_t *const ptr = r->block;
int i, j, itype, has_ac;
memset(block16, 0, 16 * sizeof(*block16));
@@ -1215,7 +1214,7 @@ static int rv34_decode_inter_macroblock(RV34DecContext *r, int8_t *intra_types)
MpegEncContext *s = &r->s;
GetBitContext *const gb = &r->gb;
uint8_t *dst = s->dest[0];
- int16_t *ptr = s->block[0];
+ int16_t *const ptr = r->block;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp, cbp2;
int q_dc, q_ac, has_ac;
diff --git a/libavcodec/rv34.h b/libavcodec/rv34.h
index 485a034f9e..5bed46ea4f 100644
--- a/libavcodec/rv34.h
+++ b/libavcodec/rv34.h
@@ -119,6 +119,7 @@ typedef struct RV34DecContext{
uint8_t *cbp_chroma; ///< CBP values for chroma subblocks
uint16_t *deblock_coefs; ///< deblock coefficients for each macroblock
+ DECLARE_ALIGNED_16(int16_t, block)[16];
/** 8x8 block available flags (for MV prediction) */
DECLARE_ALIGNED(8, uint32_t, avail_cache)[3*4];
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 17/48] avcodec/intrax8: Don't pretend to need more than one int16_t[64]
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (15 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 16/48] avcodec/rv34: Don't use MpegEncContext.block Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 18/48] avcodec/vc1: Stop using MpegEncContext.gb Andreas Rheinhardt
` (30 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Intrax8 needs only a single block.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/intrax8.c | 16 ++++++++--------
libavcodec/intrax8.h | 4 ++--
libavcodec/vc1dec.c | 2 +-
libavcodec/wmv2dec.c | 2 +-
4 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c
index 684f15d904..89b70e5902 100644
--- a/libavcodec/intrax8.c
+++ b/libavcodec/intrax8.c
@@ -437,7 +437,7 @@ static void x8_ac_compensation(IntraX8Context *const w, const int direction,
const int dc_level)
{
int t;
-#define B(x,y) w->block[0][w->idct_permutation[(x) + (y) * 8]]
+#define B(x,y) w->block[w->idct_permutation[(x) + (y) * 8]]
#define T(x) ((x) * dc_level + 0x8000) >> 16;
switch (direction) {
case 0:
@@ -530,7 +530,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
int sign;
av_assert2(w->orient < 12);
- w->bdsp.clear_block(w->block[0]);
+ w->bdsp.clear_block(w->block);
if (chroma)
dc_mode = 2;
@@ -591,7 +591,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
if (use_quant_matrix)
level = (level * quant_table[pos]) >> 8;
- w->block[0][scantable[pos]] = level;
+ w->block[scantable[pos]] = level;
} while (!final);
} else { // DC only
if (w->flat_dc && ((unsigned) (dc_level + 1)) < 3) { // [-1; 1]
@@ -613,9 +613,9 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
zeros_only = dc_level == 0;
}
if (!chroma)
- w->block[0][0] = dc_level * w->quant;
+ w->block[0] = dc_level * w->quant;
else
- w->block[0][0] = dc_level * w->quant_dc_chroma;
+ w->block[0] = dc_level * w->quant_dc_chroma;
// there is !zero_only check in the original, but dc_level check is enough
if ((unsigned int) (dc_level + 1) >= 3 && (w->edges & 3) != 3) {
@@ -624,7 +624,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
* -> 01'10' 10'10' 00'00' 00'01' 01'11' 11'00 => 0x6A017C */
direction = (0x6A017C >> (w->orient * 2)) & 3;
if (direction != 3) {
- x8_ac_compensation(w, direction, w->block[0][0]);
+ x8_ac_compensation(w, direction, w->block[0]);
}
}
@@ -639,7 +639,7 @@ static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma)
if (!zeros_only)
w->wdsp.idct_add(w->dest[chroma],
w->frame->linesize[!!chroma],
- w->block[0]);
+ w->block);
block_placed:
if (!chroma)
@@ -678,7 +678,7 @@ static void x8_init_block_index(IntraX8Context *w, AVFrame *frame)
av_cold int ff_intrax8_common_init(AVCodecContext *avctx,
IntraX8Context *w,
- int16_t (*block)[64],
+ int16_t block[64],
int mb_width, int mb_height)
{
static AVOnce init_static_once = AV_ONCE_INIT;
diff --git a/libavcodec/intrax8.h b/libavcodec/intrax8.h
index 38ad09c837..2ec90963a8 100644
--- a/libavcodec/intrax8.h
+++ b/libavcodec/intrax8.h
@@ -38,7 +38,7 @@ typedef struct IntraX8Context {
WMV2DSPContext wdsp;
uint8_t idct_permutation[64];
AVCodecContext *avctx;
- int16_t (*block)[64];
+ int16_t *block;
// set by the caller codec
IntraX8DSPContext dsp;
@@ -82,7 +82,7 @@ typedef struct IntraX8Context {
*/
int ff_intrax8_common_init(AVCodecContext *avctx,
IntraX8Context *w,
- int16_t (*block)[64],
+ int16_t block[64],
int mb_width, int mb_height);
/**
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 97174d10e3..8bcc7c60df 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -420,7 +420,7 @@ static av_cold int vc1_decode_init_alloc_tables(VC1Context *v)
return AVERROR(ENOMEM);
}
- ret = ff_intrax8_common_init(s->avctx, &v->x8, s->block,
+ ret = ff_intrax8_common_init(s->avctx, &v->x8, s->block[0],
s->mb_width, s->mb_height);
if (ret < 0)
return ret;
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 964d6a4c06..301c786633 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -581,7 +581,7 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx)
decode_ext_header(w);
- return ff_intrax8_common_init(avctx, &w->x8, s->block,
+ return ff_intrax8_common_init(avctx, &w->x8, s->block[0],
s->mb_width, s->mb_height);
}
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 18/48] avcodec/vc1: Stop using MpegEncContext.gb
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (16 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 17/48] avcodec/intrax8: Don't pretend to need more than one int16_t[64] Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 19/48] avcodec/vc1: Don't use MpegEncContext.block Andreas Rheinhardt
` (29 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Add a GetBitContext to VC1Context instead. This is in preparation
for removing MpegEncContext.gb.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/dxva2_vc1.c | 2 +-
libavcodec/mss2.c | 4 +-
libavcodec/vaapi_vc1.c | 2 +-
libavcodec/vc1.c | 14 +++----
libavcodec/vc1.h | 2 +
libavcodec/vc1_block.c | 92 +++++++++++++++++++++---------------------
libavcodec/vc1_pred.c | 12 +++---
libavcodec/vc1dec.c | 52 ++++++++++++------------
8 files changed, 91 insertions(+), 89 deletions(-)
diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
index 1f5db8156a..3400480f1f 100644
--- a/libavcodec/dxva2_vc1.c
+++ b/libavcodec/dxva2_vc1.c
@@ -177,7 +177,7 @@ void ff_dxva2_vc1_fill_slice(AVCodecContext *avctx, DXVA_SliceInfo *slice,
slice->dwSliceDataLocation = position;
slice->bStartCodeBitOffset = 0;
slice->bReservedBits = (s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type) ? v->bfraction_lut_index + 9 : 0;
- slice->wMBbitOffset = v->p_frame_skipped ? 0xffff : get_bits_count(&s->gb) + (avctx->codec_id == AV_CODEC_ID_VC1 ? 32 : 0);
+ slice->wMBbitOffset = v->p_frame_skipped ? 0xffff : get_bits_count(&v->gb) + (avctx->codec_id == AV_CODEC_ID_VC1 ? 32 : 0);
/* XXX We store the index of the first MB and it will be fixed later */
slice->wNumberMBsInSlice = (s->mb_y >> v->field_mode) * s->mb_width + s->mb_x;
slice->wQuantizerScaleCode = v->pq;
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 74a25b3e55..3758313fa8 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -387,12 +387,12 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
ff_mpeg_flush(avctx);
- if ((ret = init_get_bits8(&s->gb, buf, buf_size)) < 0)
+ if ((ret = init_get_bits8(&v->gb, buf, buf_size)) < 0)
return ret;
s->loop_filter = avctx->skip_loop_filter < AVDISCARD_ALL;
- if (ff_vc1_parse_frame_header(v, &s->gb) < 0) {
+ if (ff_vc1_parse_frame_header(v, &v->gb) < 0) {
av_log(v->s.avctx, AV_LOG_ERROR, "header error\n");
return AVERROR_INVALIDDATA;
}
diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index f2285c396b..7a955ac7f3 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -490,7 +490,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
.slice_data_size = size,
.slice_data_offset = 0,
.slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
- .macroblock_offset = get_bits_count(&s->gb),
+ .macroblock_offset = get_bits_count(&v->gb),
.slice_vertical_position = s->mb_y % mb_height,
};
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index 076127a1be..c136f14c82 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -94,7 +94,7 @@ static void decode_colskip(uint8_t* plane, int width, int height, int stride,
*/
static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
{
- GetBitContext *gb = &v->s.gb;
+ GetBitContext *const gb = &v->gb;
int imode, x, y, code, offset;
uint8_t invert, *planep = data;
@@ -161,7 +161,7 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
planep += stride * 3;
}
if (width & 1)
- decode_colskip(data, 1, height, stride, &v->s.gb);
+ decode_colskip(data, 1, height, stride, &v->gb);
} else { // 3x2
planep += (height & 1) * stride;
for (y = height & 1; y < height; y += 2) {
@@ -182,16 +182,16 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
}
x = width % 3;
if (x)
- decode_colskip(data, x, height, stride, &v->s.gb);
+ decode_colskip(data, x, height, stride, &v->gb);
if (height & 1)
- decode_rowskip(data + x, width - x, 1, stride, &v->s.gb);
+ decode_rowskip(data + x, width - x, 1, stride, &v->gb);
}
break;
case IMODE_ROWSKIP:
- decode_rowskip(data, width, height, stride, &v->s.gb);
+ decode_rowskip(data, width, height, stride, &v->gb);
break;
case IMODE_COLSKIP:
- decode_colskip(data, width, height, stride, &v->s.gb);
+ decode_colskip(data, width, height, stride, &v->gb);
break;
default:
break;
@@ -227,7 +227,7 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
*/
static int vop_dquant_decoding(VC1Context *v)
{
- GetBitContext *gb = &v->s.gb;
+ GetBitContext *const gb = &v->gb;
int pqdiff;
//variable size
diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h
index 992c073cdc..1be97aebfd 100644
--- a/libavcodec/vc1.h
+++ b/libavcodec/vc1.h
@@ -24,6 +24,7 @@
#define AVCODEC_VC1_H
#include "avcodec.h"
+#include "get_bits.h"
#include "h264chroma.h"
#include "mpegvideo.h"
#include "intrax8.h"
@@ -172,6 +173,7 @@ enum Imode {
*/
typedef struct VC1Context{
MpegEncContext s;
+ GetBitContext gb;
IntraX8Context x8;
H264ChromaContext h264chroma;
VC1DSPContext vc1dsp;
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index f73a9a8898..0e709f5f08 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -269,7 +269,7 @@ static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x,
{
int index, index1;
int extend_x, extend_y;
- GetBitContext *gb = &v->s.gb;
+ GetBitContext *const gb = &v->gb;
int bits, esc;
int val, sign;
@@ -515,7 +515,7 @@ static inline int vc1_coded_block_pred(MpegEncContext * s, int n,
static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
int *value, int codingset)
{
- GetBitContext *gb = &v->s.gb;
+ GetBitContext *const gb = &v->gb;
int index, run, level, lst, sign;
index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset], AC_VLC_BITS, 3);
@@ -582,7 +582,7 @@ static int vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip,
static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
int coded, int codingset)
{
- GetBitContext *gb = &v->s.gb;
+ GetBitContext *const gb = &v->gb;
MpegEncContext *s = &v->s;
int dc_pred_dir = 0; /* Direction of the DC prediction used */
int16_t *dc_val;
@@ -590,7 +590,7 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
int dcdiff, scale;
/* Get DC differential */
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
+ dcdiff = get_vlc2(gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
MSMP4_DC_VLC_BITS, 3);
if (dcdiff) {
const int m = (v->pq == 1 || v->pq == 2) ? 3 - v->pq : 0;
@@ -709,7 +709,7 @@ static int vc1_decode_i_block(VC1Context *v, int16_t block[64], int n,
static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
int coded, int codingset, int mquant)
{
- GetBitContext *gb = &v->s.gb;
+ GetBitContext *const gb = &v->gb;
MpegEncContext *s = &v->s;
int dc_pred_dir = 0; /* Direction of the DC prediction used */
int16_t *dc_val = NULL;
@@ -723,7 +723,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
int quant = FFABS(mquant);
/* Get DC differential */
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
+ dcdiff = get_vlc2(gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
MSMP4_DC_VLC_BITS, 3);
if (dcdiff) {
const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
@@ -889,7 +889,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, int16_t block[64], int n,
static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
int coded, int mquant, int codingset)
{
- GetBitContext *gb = &v->s.gb;
+ GetBitContext *const gb = &v->gb;
MpegEncContext *s = &v->s;
int dc_pred_dir = 0; /* Direction of the DC prediction used */
int16_t *dc_val = NULL;
@@ -911,7 +911,7 @@ static int vc1_decode_intra_block(VC1Context *v, int16_t block[64], int n,
s->y_dc_scale = ff_wmv3_dc_scale_table[quant];
/* Get DC differential */
- dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
+ dcdiff = get_vlc2(gb, ff_msmp4_dc_vlc[v->dc_table_index][n >= 4],
MSMP4_DC_VLC_BITS, 3);
if (dcdiff) {
const int m = (quant == 1 || quant == 2) ? 3 - quant : 0;
@@ -1084,7 +1084,7 @@ static int vc1_decode_p_block(VC1Context *v, int16_t block[64], int n,
int *ttmb_out)
{
MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &v->gb;
int i, j;
int subblkpat = 0;
int scale, off, idx, last, skip, value;
@@ -1253,7 +1253,7 @@ static const uint8_t size_table[6] = { 0, 2, 3, 4, 5, 8 };
static int vc1_decode_p_mb(VC1Context *v)
{
MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &v->gb;
int i, j;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp; /* cbp decoding stuff */
@@ -1300,7 +1300,7 @@ static int vc1_decode_p_mb(VC1Context *v)
} else if (mb_has_coeffs) {
if (s->mb_intra)
s->ac_pred = get_bits1(gb);
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
} else {
mquant = v->pq;
@@ -1367,7 +1367,7 @@ static int vc1_decode_p_mb(VC1Context *v)
int intra_count = 0, coded_inter = 0;
int is_intra[6], is_coded[6];
/* Get CBPCY */
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
for (i = 0; i < 6; i++) {
val = ((cbp >> (5 - i)) & 1);
s->dc_val[s->block_index[i]] = 0;
@@ -1490,7 +1490,7 @@ end:
static int vc1_decode_p_mb_intfr(VC1Context *v)
{
MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &v->gb;
int i;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp = 0; /* cbp decoding stuff */
@@ -1560,7 +1560,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = get_bits1(gb);
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
GET_MQUANT();
s->cur_pic.qscale_table[mb_pos] = mquant;
@@ -1591,7 +1591,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
} else { // inter MB
mb_has_coeffs = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][3];
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) {
v->twomvbp = get_vlc2(gb, v->twomvbp_vlc, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
} else {
@@ -1698,7 +1698,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v)
static int vc1_decode_p_mb_intfi(VC1Context *v)
{
MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &v->gb;
int i;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp = 0; /* cbp decoding stuff */
@@ -1731,7 +1731,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = idx_mbmode & 1;
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_ICBPCY_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(gb, v->cbpcy_vlc, VC1_ICBPCY_VLC_BITS, 2);
dst_idx = 0;
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
@@ -1779,7 +1779,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
mb_has_coeffs = idx_mbmode & 1;
}
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
if (cbp) {
GET_MQUANT();
}
@@ -1823,7 +1823,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v)
static int vc1_decode_b_mb(VC1Context *v)
{
MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &v->gb;
int i, j;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp = 0; /* cbp decoding stuff */
@@ -1890,7 +1890,7 @@ static int vc1_decode_b_mb(VC1Context *v)
return 0;
}
if (direct) {
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
s->mb_intra = 0;
s->cur_pic.qscale_table[mb_pos] = mquant;
@@ -1928,7 +1928,7 @@ static int vc1_decode_b_mb(VC1Context *v)
}
if (s->mb_intra)
s->ac_pred = get_bits1(gb);
- cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
GET_MQUANT();
s->cur_pic.qscale_table[mb_pos] = mquant;
if (!v->ttmbf && !s->mb_intra && mb_has_coeffs)
@@ -1984,7 +1984,7 @@ static int vc1_decode_b_mb(VC1Context *v)
static int vc1_decode_b_mb_intfi(VC1Context *v)
{
MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &v->gb;
int i, j;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp = 0; /* cbp decoding stuff */
@@ -2018,7 +2018,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = idx_mbmode & 1;
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_ICBPCY_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(gb, v->cbpcy_vlc, VC1_ICBPCY_VLC_BITS, 2);
dst_idx = 0;
for (i = 0; i < 6; i++) {
v->a_avail = v->c_avail = 0;
@@ -2114,7 +2114,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
mb_has_coeffs = idx_mbmode & 1;
}
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
if (cbp) {
GET_MQUANT();
}
@@ -2153,7 +2153,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
static int vc1_decode_b_mb_intfr(VC1Context *v)
{
MpegEncContext *s = &v->s;
- GetBitContext *gb = &s->gb;
+ GetBitContext *const gb = &v->gb;
int i, j;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
int cbp = 0; /* cbp decoding stuff */
@@ -2209,7 +2209,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
mb_has_coeffs = get_bits1(gb);
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
GET_MQUANT();
s->cur_pic.qscale_table[mb_pos] = mquant;
@@ -2305,7 +2305,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
if (!skipped) { // inter MB
mb_has_coeffs = ff_vc1_mbmode_intfrp[0][idx_mbmode][3];
if (mb_has_coeffs)
- cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
+ cbp = 1 + get_vlc2(gb, v->cbpcy_vlc, VC1_CBPCY_P_VLC_BITS, 2);
if (!direct) {
if (bmvtype == BMV_TYPE_INTERPOLATED && twomv) {
v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
@@ -2557,9 +2557,9 @@ static void vc1_decode_i_blocks(VC1Context *v)
}
// do actual MB decoding and displaying
- cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc,
+ cbp = get_vlc2(&v->gb, ff_msmp4_mb_i_vlc,
MSMP4_MB_INTRA_VLC_BITS, 2);
- v->s.ac_pred = get_bits1(&v->s.gb);
+ v->s.ac_pred = get_bits1(&v->gb);
for (k = 0; k < 6; k++) {
v->mb_type[s->block_index[k]] = 1;
@@ -2598,10 +2598,10 @@ static void vc1_decode_i_blocks(VC1Context *v)
if (v->s.loop_filter)
ff_vc1_i_loop_filter(v);
- if (get_bits_left(&s->gb) < 0) {
+ if (get_bits_left(&v->gb) < 0) {
ff_er_add_slice(&s->er, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR);
av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
- get_bits_count(&s->gb), s->gb.size_in_bits);
+ get_bits_count(&v->gb), v->gb.size_in_bits);
return;
}
@@ -2625,12 +2625,12 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
{
int k;
MpegEncContext *s = &v->s;
+ GetBitContext *const gb = &v->gb;
int cbp, val;
uint8_t *coded_val;
int mb_pos;
int mquant;
int mqdiff;
- GetBitContext *gb = &s->gb;
if (get_bits_left(gb) <= 1)
return AVERROR_INVALIDDATA;
@@ -2685,21 +2685,21 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
// do actual MB decoding and displaying
if (v->fieldtx_is_raw)
- v->fieldtx_plane[mb_pos] = get_bits1(&v->s.gb);
- if (get_bits_left(&v->s.gb) <= 1) {
+ v->fieldtx_plane[mb_pos] = get_bits1(gb);
+ if (get_bits_left(gb) <= 1) {
ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
return 0;
}
- cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc,
+ cbp = get_vlc2(gb, ff_msmp4_mb_i_vlc,
MSMP4_MB_INTRA_VLC_BITS, 2);
if (v->acpred_is_raw)
- v->s.ac_pred = get_bits1(&v->s.gb);
+ v->s.ac_pred = get_bits1(gb);
else
v->s.ac_pred = v->acpred_plane[mb_pos];
if (v->condover == CONDOVER_SELECT && v->overflg_is_raw)
- v->over_flags_plane[mb_pos] = get_bits1(&v->s.gb);
+ v->over_flags_plane[mb_pos] = get_bits1(gb);
GET_MQUANT();
@@ -2736,11 +2736,11 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
if (v->s.loop_filter)
ff_vc1_i_loop_filter(v);
- if (get_bits_left(&s->gb) < 0) {
+ if (get_bits_left(gb) < 0) {
// TODO: may need modification to handle slice coding
ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n",
- get_bits_count(&s->gb), s->gb.size_in_bits);
+ get_bits_count(gb), gb->size_in_bits);
return 0;
}
inc_blk_idx(v->topleft_blk_idx);
@@ -2797,7 +2797,7 @@ static void vc1_decode_p_blocks(VC1Context *v)
update_block_index(s);
if (v->fcm == ILACE_FIELD || (v->fcm == PROGRESSIVE && v->mv_type_is_raw) || v->skip_is_raw)
- if (get_bits_left(&v->s.gb) <= 1) {
+ if (get_bits_left(&v->gb) <= 1) {
ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
return;
}
@@ -2815,11 +2815,11 @@ static void vc1_decode_p_blocks(VC1Context *v)
if (apply_loop_filter)
ff_vc1_p_loop_filter(v);
}
- if (ret < 0 || get_bits_left(&s->gb) < 0 || get_bits_count(&s->gb) < 0) {
+ if (ret < 0 || get_bits_left(&v->gb) < 0 || get_bits_count(&v->gb) < 0) {
// TODO: may need modification to handle slice coding
ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
av_log(s->avctx, AV_LOG_ERROR, "Error or Bits overconsumption: %i > %i at %ix%i\n",
- get_bits_count(&s->gb), s->gb.size_in_bits, s->mb_x, s->mb_y);
+ get_bits_count(&v->gb), v->gb.size_in_bits, s->mb_x, s->mb_y);
return;
}
inc_blk_idx(v->topleft_blk_idx);
@@ -2882,7 +2882,7 @@ static void vc1_decode_b_blocks(VC1Context *v)
update_block_index(s);
if (v->fcm == ILACE_FIELD || v->skip_is_raw || v->dmb_is_raw)
- if (get_bits_left(&v->s.gb) <= 1) {
+ if (get_bits_left(&v->gb) <= 1) {
ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
return;
}
@@ -2900,11 +2900,11 @@ static void vc1_decode_b_blocks(VC1Context *v)
if (v->s.loop_filter)
ff_vc1_i_loop_filter(v);
}
- if (get_bits_left(&s->gb) < 0 || get_bits_count(&s->gb) < 0) {
+ if (get_bits_left(&v->gb) < 0 || get_bits_count(&v->gb) < 0) {
// TODO: may need modification to handle slice coding
ff_er_add_slice(&s->er, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR);
av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n",
- get_bits_count(&s->gb), s->gb.size_in_bits, s->mb_x, s->mb_y);
+ get_bits_count(&v->gb), v->gb.size_in_bits, s->mb_x, s->mb_y);
return;
}
}
@@ -2949,7 +2949,7 @@ void ff_vc1_decode_blocks(VC1Context *v)
v->esc3_level_length = 0;
if (v->x8_type) {
ff_intrax8_decode_picture(&v->x8, v->s.cur_pic.ptr,
- &v->s.gb, &v->s.mb_x, &v->s.mb_y,
+ &v->gb, &v->s.mb_x, &v->s.mb_y,
2 * v->pq + v->halfpq, v->pq * !v->pquantizer,
v->s.loop_filter, v->s.low_delay);
diff --git a/libavcodec/vc1_pred.c b/libavcodec/vc1_pred.c
index 202fa8cc3b..1ac8f6156b 100644
--- a/libavcodec/vc1_pred.c
+++ b/libavcodec/vc1_pred.c
@@ -420,7 +420,7 @@ void ff_vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
else
sum = FFABS(px - field_predA[0]) + FFABS(py - field_predA[1]);
if (sum > hybridmv_thresh) {
- if (get_bits1(&s->gb)) { // read HYBRIDPRED bit
+ if (get_bits1(&v->gb)) { // read HYBRIDPRED bit
px = field_predA[0];
py = field_predA[1];
} else {
@@ -433,7 +433,7 @@ void ff_vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y,
else
sum = FFABS(px - field_predC[0]) + FFABS(py - field_predC[1]);
if (sum > hybridmv_thresh) {
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&v->gb)) {
px = field_predA[0];
py = field_predA[1];
} else {
@@ -782,7 +782,7 @@ void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
else
sum = FFABS(px - A[0]) + FFABS(py - A[1]);
if (sum > 32) {
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&v->gb)) {
px = A[0];
py = A[1];
} else {
@@ -795,7 +795,7 @@ void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
else
sum = FFABS(px - C[0]) + FFABS(py - C[1]);
if (sum > 32) {
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&v->gb)) {
px = A[0];
py = A[1];
} else {
@@ -852,7 +852,7 @@ void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
else
sum = FFABS(px - A[0]) + FFABS(py - A[1]);
if (sum > 32) {
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&v->gb)) {
px = A[0];
py = A[1];
} else {
@@ -865,7 +865,7 @@ void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2],
else
sum = FFABS(px - C[0]) + FFABS(py - C[1]);
if (sum > 32) {
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&v->gb)) {
px = A[0];
py = A[1];
} else {
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 8bcc7c60df..9c942929b5 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -899,8 +899,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
}
case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
buf_size2 = v->vc1dsp.vc1_unescape_buffer(start + 4, size, buf2);
- init_get_bits(&s->gb, buf2, buf_size2 * 8);
- ff_vc1_decode_entry_point(avctx, v, &s->gb);
+ init_get_bits(&v->gb, buf2, buf_size2 * 8);
+ ff_vc1_decode_entry_point(avctx, v, &v->gb);
break;
case VC1_CODE_SLICE: {
int buf_size3;
@@ -964,16 +964,16 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
} else {
buf_size2 = v->vc1dsp.vc1_unescape_buffer(buf, buf_size, buf2);
}
- init_get_bits(&s->gb, buf2, buf_size2*8);
+ init_get_bits(&v->gb, buf2, buf_size2*8);
} else{
- ret = init_get_bits8(&s->gb, buf, buf_size);
+ ret = init_get_bits8(&v->gb, buf, buf_size);
if (ret < 0)
return ret;
}
if (v->res_sprite) {
- v->new_sprite = !get_bits1(&s->gb);
- v->two_sprites = get_bits1(&s->gb);
+ v->new_sprite = !get_bits1(&v->gb);
+ v->two_sprites = get_bits1(&v->gb);
/* res_sprite means a Windows Media Image stream, AV_CODEC_ID_*IMAGE means
we're using the sprite compositor. These are intentionally kept separate
so you can get the raw sprites by using the wmv3 decoder for WMVP or
@@ -1016,11 +1016,11 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
v->pic_header_flag = 0;
v->first_pic_header_flag = 1;
if (v->profile < PROFILE_ADVANCED) {
- if ((ret = ff_vc1_parse_frame_header(v, &s->gb)) < 0) {
+ if ((ret = ff_vc1_parse_frame_header(v, &v->gb)) < 0) {
goto err;
}
} else {
- if ((ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
+ if ((ret = ff_vc1_parse_frame_header_adv(v, &v->gb)) < 0) {
goto err;
}
}
@@ -1103,12 +1103,12 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
goto err;
for (i = 0 ; i < n_slices1 + 1; i++) {
- s->gb = slices[i].gb;
+ v->gb = slices[i].gb;
s->mb_y = slices[i].mby_start;
- v->pic_header_flag = get_bits1(&s->gb);
+ v->pic_header_flag = get_bits1(&v->gb);
if (v->pic_header_flag) {
- if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
+ if (ff_vc1_parse_frame_header_adv(v, &v->gb) < 0) {
av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
ret = AVERROR_INVALIDDATA;
if (avctx->err_recognition & AV_EF_EXPLODE)
@@ -1128,12 +1128,12 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
goto err;
// decode second field
- s->gb = slices[n_slices1 + 1].gb;
+ v->gb = slices[n_slices1 + 1].gb;
s->mb_y = slices[n_slices1 + 1].mby_start;
s->picture_structure = PICT_TOP_FIELD + v->tff;
v->second_field = 1;
v->pic_header_flag = 0;
- if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
+ if (ff_vc1_parse_frame_header_adv(v, &v->gb) < 0) {
av_log(avctx, AV_LOG_ERROR, "parsing header for second field failed");
ret = AVERROR_INVALIDDATA;
goto err;
@@ -1158,12 +1158,12 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
goto err;
for (i = n_slices1 + 2; i < n_slices; i++) {
- s->gb = slices[i].gb;
+ v->gb = slices[i].gb;
s->mb_y = slices[i].mby_start;
- v->pic_header_flag = get_bits1(&s->gb);
+ v->pic_header_flag = get_bits1(&v->gb);
if (v->pic_header_flag) {
- if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
+ if (ff_vc1_parse_frame_header_adv(v, &v->gb) < 0) {
av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
ret = AVERROR_INVALIDDATA;
if (avctx->err_recognition & AV_EF_EXPLODE)
@@ -1203,12 +1203,12 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
// and process the slices as additional slices afterwards
for (i = 0 ; i < n_slices; i++) {
- s->gb = slices[i].gb;
+ v->gb = slices[i].gb;
s->mb_y = slices[i].mby_start;
- v->pic_header_flag = get_bits1(&s->gb);
+ v->pic_header_flag = get_bits1(&v->gb);
if (v->pic_header_flag) {
- if (ff_vc1_parse_frame_header_adv(v, &s->gb) < 0) {
+ if (ff_vc1_parse_frame_header_adv(v, &v->gb) < 0) {
av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
ret = AVERROR_INVALIDDATA;
if (avctx->err_recognition & AV_EF_EXPLODE)
@@ -1263,16 +1263,16 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
if (i) {
v->pic_header_flag = 0;
if (v->field_mode && i == n_slices1 + 2) {
- if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
+ if ((header_ret = ff_vc1_parse_frame_header_adv(v, &v->gb)) < 0) {
av_log(v->s.avctx, AV_LOG_ERROR, "Field header damaged\n");
ret = AVERROR_INVALIDDATA;
if (avctx->err_recognition & AV_EF_EXPLODE)
goto err;
continue;
}
- } else if (get_bits1(&s->gb)) {
+ } else if (get_bits1(&v->gb)) {
v->pic_header_flag = 1;
- if ((header_ret = ff_vc1_parse_frame_header_adv(v, &s->gb)) < 0) {
+ if ((header_ret = ff_vc1_parse_frame_header_adv(v, &v->gb)) < 0) {
av_log(v->s.avctx, AV_LOG_ERROR, "Slice header damaged\n");
ret = AVERROR_INVALIDDATA;
if (avctx->err_recognition & AV_EF_EXPLODE)
@@ -1305,7 +1305,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
}
ff_vc1_decode_blocks(v);
if (i != n_slices) {
- s->gb = slices[i].gb;
+ v->gb = slices[i].gb;
}
}
if (v->field_mode) {
@@ -1321,8 +1321,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
}
}
ff_dlog(s->avctx, "Consumed %i/%i bits\n",
- get_bits_count(&s->gb), s->gb.size_in_bits);
-// if (get_bits_count(&s->gb) > buf_size * 8)
+ get_bits_count(&v->gb), v->gb.size_in_bits);
+// if (get_bits_count(&v->gb) > buf_size * 8)
// return -1;
if(s->er.error_occurred && s->pict_type == AV_PICTURE_TYPE_B) {
ret = AVERROR_INVALIDDATA;
@@ -1348,7 +1348,7 @@ image:
goto err;
}
#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER
- if ((ret = vc1_decode_sprites(v, &s->gb)) < 0)
+ if ((ret = vc1_decode_sprites(v, &v->gb)) < 0)
goto err;
#endif
if ((ret = av_frame_ref(pict, v->sprite_output_frame)) < 0)
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 19/48] avcodec/vc1: Don't use MpegEncContext.block
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (17 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 18/48] avcodec/vc1: Stop using MpegEncContext.gb Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 20/48] avcodec/mpeg12dec: Deduplicate variables Andreas Rheinhardt
` (28 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Instead add the necessary blocks directly to VC1Context
(only six are needed, not 12 as ff_mpv_common_init()
currently allocates).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/vc1.h | 4 ++++
libavcodec/vc1_block.c | 28 ++++++++++++++--------------
libavcodec/vc1dec.c | 2 +-
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h
index 1be97aebfd..5eee646e31 100644
--- a/libavcodec/vc1.h
+++ b/libavcodec/vc1.h
@@ -31,6 +31,8 @@
#include "vc1_common.h"
#include "vc1dsp.h"
+#include "libavutil/mem_internal.h"
+
#define AC_VLC_BITS 9
/** Sequence quantizer mode */
@@ -399,6 +401,8 @@ typedef struct VC1Context{
int parse_only; ///< Context is used within parser
int resync_marker; ///< could this stream contain resync markers
+
+ DECLARE_ALIGNED_32(int16_t, blocks)[6][64];
} VC1Context;
/**
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 0e709f5f08..165d875458 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -1950,22 +1950,22 @@ static int vc1_decode_b_mb(VC1Context *v)
if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[s->block_index[i] - 1];
- ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant,
+ ret = vc1_decode_intra_block(v, v->blocks[i], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
if (ret < 0)
return ret;
if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
continue;
- v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
+ v->vc1dsp.vc1_inv_trans_8x8(v->blocks[i]);
if (v->rangeredfrm)
for (j = 0; j < 64; j++)
- s->block[i][j] *= 2;
- s->idsp.put_signed_pixels_clamped(s->block[i],
+ v->blocks[i][j] *= 2;
+ s->idsp.put_signed_pixels_clamped(v->blocks[i],
s->dest[dst_idx] + off,
i & 4 ? s->uvlinesize
: s->linesize);
} else if (val) {
- int pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
+ int pat = vc1_decode_p_block(v, v->blocks[i], i, mquant, ttmb,
first_block, s->dest[dst_idx] + off,
(i & 4) ? s->uvlinesize : s->linesize,
CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), NULL);
@@ -2031,18 +2031,18 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[s->block_index[i] - 1];
- ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant,
+ ret = vc1_decode_intra_block(v, v->blocks[i], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
if (ret < 0)
return ret;
if (CONFIG_GRAY && (i > 3) && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
continue;
- v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
+ v->vc1dsp.vc1_inv_trans_8x8(v->blocks[i]);
if (v->rangeredfrm)
for (j = 0; j < 64; j++)
- s->block[i][j] <<= 1;
+ v->blocks[i][j] <<= 1;
off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
- s->idsp.put_signed_pixels_clamped(s->block[i],
+ s->idsp.put_signed_pixels_clamped(v->blocks[i],
s->dest[dst_idx] + off,
(i & 4) ? s->uvlinesize
: s->linesize);
@@ -2129,7 +2129,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v)
val = ((cbp >> (5 - i)) & 1);
off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize;
if (val) {
- pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
+ pat = vc1_decode_p_block(v, v->blocks[i], i, mquant, ttmb,
first_block, s->dest[dst_idx] + off,
(i & 4) ? s->uvlinesize : s->linesize,
CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
@@ -2227,13 +2227,13 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
if (i == 1 || i == 3 || s->mb_x)
v->c_avail = v->mb_type[s->block_index[i] - 1];
- ret = vc1_decode_intra_block(v, s->block[i], i, val, mquant,
+ ret = vc1_decode_intra_block(v, v->blocks[i], i, val, mquant,
(i & 4) ? v->codingset2 : v->codingset);
if (ret < 0)
return ret;
if (CONFIG_GRAY && i > 3 && (s->avctx->flags & AV_CODEC_FLAG_GRAY))
continue;
- v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
+ v->vc1dsp.vc1_inv_trans_8x8(v->blocks[i]);
if (i < 4) {
stride_y = s->linesize << fieldtx;
off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize;
@@ -2241,7 +2241,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
stride_y = s->uvlinesize;
off = 0;
}
- s->idsp.put_signed_pixels_clamped(s->block[i],
+ s->idsp.put_signed_pixels_clamped(v->blocks[i],
s->dest[dst_idx] + off,
stride_y);
}
@@ -2430,7 +2430,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v)
else
off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize));
if (val) {
- pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
+ pat = vc1_decode_p_block(v, v->blocks[i], i, mquant, ttmb,
first_block, s->dest[dst_idx] + off,
(i & 4) ? s->uvlinesize : (s->linesize << fieldtx),
CONFIG_GRAY && (i & 4) && (s->avctx->flags & AV_CODEC_FLAG_GRAY), &block_tt);
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 9c942929b5..de6d9ef7a9 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -420,7 +420,7 @@ static av_cold int vc1_decode_init_alloc_tables(VC1Context *v)
return AVERROR(ENOMEM);
}
- ret = ff_intrax8_common_init(s->avctx, &v->x8, s->block[0],
+ ret = ff_intrax8_common_init(s->avctx, &v->x8, v->blocks[0],
s->mb_width, s->mb_height);
if (ret < 0)
return ret;
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 20/48] avcodec/mpeg12dec: Deduplicate variables
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (18 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 19/48] avcodec/vc1: Don't use MpegEncContext.block Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 21/48] avcodec/mpegvideo: Move flipflop_rounding to {MSMPEG4Dec, MPVEnc}Context Andreas Rheinhardt
` (27 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This situation was created in merge commit
71d008ebe4f96974433eecfd3575bc82eb4b06a8.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index a056dd87cc..cba57369cd 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -2095,7 +2095,6 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx,
static void mpeg_decode_user_data(AVCodecContext *avctx,
const uint8_t *p, int buf_size)
{
- Mpeg1Context *s = avctx->priv_data;
const uint8_t *buf_end = p + buf_size;
Mpeg1Context *s1 = avctx->priv_data;
@@ -2111,7 +2110,7 @@ static void mpeg_decode_user_data(AVCodecContext *avctx,
int i;
for(i=0; i<20; i++)
if (!memcmp(p+i, "\0TMPGEXS\0", 9)){
- s->tmpgexs= 1;
+ s1->tmpgexs = 1;
}
}
/* we parse the DTG active format information */
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 21/48] avcodec/mpegvideo: Move flipflop_rounding to {MSMPEG4Dec, MPVEnc}Context
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (19 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 20/48] avcodec/mpeg12dec: Deduplicate variables Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 22/48] avcodec/mpegvideo: Move unrestricted_mv to MotionEstContext Andreas Rheinhardt
` (26 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Forgotten in 9964212545554d9ae1afaabd23a7f9a361997d01.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpegvideo.h | 1 -
libavcodec/mpegvideo_enc.c | 14 +++++++-------
libavcodec/mpegvideoenc.h | 1 +
libavcodec/msmpeg4dec.c | 8 ++++----
libavcodec/msmpeg4dec.h | 1 +
libavcodec/msmpeg4enc.c | 4 ++--
libavcodec/wmv2enc.c | 2 +-
7 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index fe3ae97f5d..a439c1878b 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -265,7 +265,6 @@ typedef struct MpegEncContext {
/* MSMPEG4 specific */
int slice_height; ///< in macroblocks
int first_slice_line; ///< used in MPEG-4 too to handle resync markers
- int flipflop_rounding;
enum {
MSMP4_UNUSED,
MSMP4_V1,
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 1ceb6296c4..8a38e54982 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -927,7 +927,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.modified_quant = s->c.h263_aic;
s->c.loop_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
s->c.unrestricted_mv = s->c.obmc || s->c.loop_filter || s->c.umvplus;
- s->c.flipflop_rounding = 1;
+ s->flipflop_rounding = 1;
/* /Fx */
/* These are just to be sure */
@@ -968,7 +968,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.out_format = FMT_H263;
s->c.h263_pred = 1;
s->c.unrestricted_mv = 1;
- s->c.flipflop_rounding = 1;
+ s->flipflop_rounding = 1;
s->c.low_delay = m->max_b_frames ? 0 : 1;
avctx->delay = s->c.low_delay ? 0 : (m->max_b_frames + 1);
break;
@@ -985,7 +985,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.h263_pred = 1;
s->c.unrestricted_mv = 1;
s->c.msmpeg4_version = MSMP4_V3;
- s->c.flipflop_rounding = 1;
+ s->flipflop_rounding = 1;
avctx->delay = 0;
s->c.low_delay = 1;
break;
@@ -994,7 +994,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.h263_pred = 1;
s->c.unrestricted_mv = 1;
s->c.msmpeg4_version = MSMP4_WMV1;
- s->c.flipflop_rounding = 1;
+ s->flipflop_rounding = 1;
avctx->delay = 0;
s->c.low_delay = 1;
break;
@@ -1003,7 +1003,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.h263_pred = 1;
s->c.unrestricted_mv = 1;
s->c.msmpeg4_version = MSMP4_WMV2;
- s->c.flipflop_rounding = 1;
+ s->flipflop_rounding = 1;
avctx->delay = 0;
s->c.low_delay = 1;
break;
@@ -2022,7 +2022,7 @@ vbv_retry:
s->c.mb_skipped = 0; // done in frame_start()
// done in encode_picture() so we must undo it
if (s->c.pict_type == AV_PICTURE_TYPE_P) {
- s->c.no_rounding ^= s->c.flipflop_rounding;
+ s->c.no_rounding ^= s->flipflop_rounding;
}
if (s->c.pict_type != AV_PICTURE_TYPE_B) {
s->c.time_base = s->c.last_time_base;
@@ -3734,7 +3734,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
if (s->c.pict_type == AV_PICTURE_TYPE_I) {
s->c.no_rounding = s->c.msmpeg4_version >= MSMP4_V3;
} else if (s->c.pict_type != AV_PICTURE_TYPE_B) {
- s->c.no_rounding ^= s->c.flipflop_rounding;
+ s->c.no_rounding ^= s->flipflop_rounding;
}
if (s->c.avctx->flags & AV_CODEC_FLAG_PASS2) {
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 8ad2fe2e8a..2a04abab26 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -155,6 +155,7 @@ typedef struct MPVEncContext {
PutBitContext pb2; ///< used for data partitioned VOPs
/* MSMPEG4 specific */
+ int flipflop_rounding; ///< also used for MPEG-4, H.263+
int esc3_level_length;
/* RTP specific */
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index df5ab5186e..55e51aff3c 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -544,7 +544,7 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
ms->per_mb_rl_table,
s->qscale);
- if(s->flipflop_rounding){
+ if (ms->flipflop_rounding) {
s->no_rounding ^= 1;
}else{
s->no_rounding = 0;
@@ -570,13 +570,13 @@ int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
skip_bits(&s->gb, 5); /* fps */
ms->bit_rate = get_bits(&s->gb, 11) * 1024;
if (s->msmpeg4_version >= MSMP4_V3)
- s->flipflop_rounding= get_bits1(&s->gb);
+ ms->flipflop_rounding = get_bits1(&s->gb);
else
- s->flipflop_rounding= 0;
+ ms->flipflop_rounding = 0;
}
else if(left<length+8)
{
- s->flipflop_rounding= 0;
+ ms->flipflop_rounding = 0;
if (s->msmpeg4_version != MSMP4_V2)
av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
}
diff --git a/libavcodec/msmpeg4dec.h b/libavcodec/msmpeg4dec.h
index b04331fd47..862c50b3f0 100644
--- a/libavcodec/msmpeg4dec.h
+++ b/libavcodec/msmpeg4dec.h
@@ -31,6 +31,7 @@
typedef struct MSMP4DecContext {
MpegEncContext m;
int bit_rate;
+ int flipflop_rounding;
int mv_table_index;
int rl_table_index;
int rl_chroma_table_index;
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 3449328b3c..bcb4af23e9 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -298,9 +298,9 @@ void ff_msmpeg4_encode_ext_header(MPVEncContext *const s)
put_bits(&s->pb, 11, FFMIN(m->bit_rate / 1024, 2047));
if (s->c.msmpeg4_version >= MSMP4_V3)
- put_bits(&s->pb, 1, s->c.flipflop_rounding);
+ put_bits(&s->pb, 1, s->flipflop_rounding);
else
- av_assert0(!s->c.flipflop_rounding);
+ av_assert0(!s->flipflop_rounding);
}
void ff_msmpeg4_encode_motion(MSMPEG4EncContext *const ms,
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index 592d1060d3..0eef5b7cfb 100644
--- a/libavcodec/wmv2enc.c
+++ b/libavcodec/wmv2enc.c
@@ -94,7 +94,7 @@ static int wmv2_encode_picture_header(MPVMainEncContext *const m)
w->abt_type = 0;
w->j_type = 0;
- av_assert0(s->c.flipflop_rounding);
+ av_assert0(s->flipflop_rounding);
if (s->c.pict_type == AV_PICTURE_TYPE_I) {
av_assert0(s->c.no_rounding == 1);
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 22/48] avcodec/mpegvideo: Move unrestricted_mv to MotionEstContext
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (20 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 21/48] avcodec/mpegvideo: Move flipflop_rounding to {MSMPEG4Dec, MPVEnc}Context Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 23/48] avcodec/mpeg4videodec: Avoid unnecessary indirections Andreas Rheinhardt
` (25 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/motion_est.c | 4 ++--
libavcodec/motion_est.h | 1 +
libavcodec/mpegvideo.h | 1 -
libavcodec/mpegvideo_enc.c | 18 +++++++++---------
libavcodec/rv20enc.c | 2 +-
libavcodec/snowenc.c | 2 +-
libavcodec/svq1enc.c | 2 +-
7 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c
index 333048d1c8..93be712cc0 100644
--- a/libavcodec/motion_est.c
+++ b/libavcodec/motion_est.c
@@ -551,7 +551,7 @@ static inline void get_limits(MPVEncContext *const s, int x, int y, int bframe)
if(c->avctx->me_range) c->range= c->avctx->me_range >> 1;
else c->range= 16;
*/
- if (s->c.unrestricted_mv) {
+ if (c->unrestricted_mv) {
c->xmin = - x - 16;
c->ymin = - y - 16;
c->xmax = - x + s->c.width;
@@ -600,7 +600,7 @@ static inline int h263_mv4_search(MPVEncContext *const s, int mx, int my, int sh
int same=1;
const int stride= c->stride;
const uint8_t *mv_penalty = c->current_mv_penalty;
- int safety_clipping = s->c.unrestricted_mv && (s->c.width&15) && (s->c.height&15);
+ int safety_clipping = c->unrestricted_mv && (s->c.width&15) && (s->c.height&15);
init_mv4_ref(c);
diff --git a/libavcodec/motion_est.h b/libavcodec/motion_est.h
index 89a2f41b75..7e57a3a79b 100644
--- a/libavcodec/motion_est.h
+++ b/libavcodec/motion_est.h
@@ -69,6 +69,7 @@ typedef struct MotionEstContext {
int mb_flags;
int pre_pass; ///< = 1 for the pre pass
int dia_size;
+ int unrestricted_mv; ///< mv can point outside of the coded picture
int xmin;
int xmax;
int ymin;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index a439c1878b..d95cebedd8 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -164,7 +164,6 @@ typedef struct MpegEncContext {
int droppable;
/* motion compensation */
- int unrestricted_mv; ///< mv can point outside of the coded picture
int h263_long_vectors; ///< use horrible H.263v1 long vector mode
BlockDSPContext bdsp;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 8a38e54982..afdc2fb787 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -926,7 +926,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.h263_aic = (avctx->flags & AV_CODEC_FLAG_AC_PRED) ? 1 : 0;
s->c.modified_quant = s->c.h263_aic;
s->c.loop_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
- s->c.unrestricted_mv = s->c.obmc || s->c.loop_filter || s->c.umvplus;
+ s->me.unrestricted_mv = s->c.obmc || s->c.loop_filter || s->c.umvplus;
s->flipflop_rounding = 1;
/* /Fx */
@@ -937,7 +937,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
case AV_CODEC_ID_FLV1:
s->c.out_format = FMT_H263;
s->c.h263_flv = 2; /* format = 1; 11-bit codes */
- s->c.unrestricted_mv = 1;
+ s->me.unrestricted_mv = 1;
s->rtp_mode = 0; /* don't allow GOB */
avctx->delay = 0;
s->c.low_delay = 1;
@@ -961,13 +961,13 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
// will be set later on a per-frame basis.
s->c.h263_aic = 1;
s->c.loop_filter = 1;
- s->c.unrestricted_mv = 0;
+ s->me.unrestricted_mv = 0;
break;
#endif
case AV_CODEC_ID_MPEG4:
s->c.out_format = FMT_H263;
s->c.h263_pred = 1;
- s->c.unrestricted_mv = 1;
+ s->me.unrestricted_mv = 1;
s->flipflop_rounding = 1;
s->c.low_delay = m->max_b_frames ? 0 : 1;
avctx->delay = s->c.low_delay ? 0 : (m->max_b_frames + 1);
@@ -975,7 +975,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
case AV_CODEC_ID_MSMPEG4V2:
s->c.out_format = FMT_H263;
s->c.h263_pred = 1;
- s->c.unrestricted_mv = 1;
+ s->me.unrestricted_mv = 1;
s->c.msmpeg4_version = MSMP4_V2;
avctx->delay = 0;
s->c.low_delay = 1;
@@ -983,7 +983,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
case AV_CODEC_ID_MSMPEG4V3:
s->c.out_format = FMT_H263;
s->c.h263_pred = 1;
- s->c.unrestricted_mv = 1;
+ s->me.unrestricted_mv = 1;
s->c.msmpeg4_version = MSMP4_V3;
s->flipflop_rounding = 1;
avctx->delay = 0;
@@ -992,7 +992,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
case AV_CODEC_ID_WMV1:
s->c.out_format = FMT_H263;
s->c.h263_pred = 1;
- s->c.unrestricted_mv = 1;
+ s->me.unrestricted_mv = 1;
s->c.msmpeg4_version = MSMP4_WMV1;
s->flipflop_rounding = 1;
avctx->delay = 0;
@@ -1001,7 +1001,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
case AV_CODEC_ID_WMV2:
s->c.out_format = FMT_H263;
s->c.h263_pred = 1;
- s->c.unrestricted_mv = 1;
+ s->me.unrestricted_mv = 1;
s->c.msmpeg4_version = MSMP4_WMV2;
s->flipflop_rounding = 1;
avctx->delay = 0;
@@ -1867,7 +1867,7 @@ static void frame_end(MPVMainEncContext *const m)
{
MPVEncContext *const s = &m->s;
- if (s->c.unrestricted_mv &&
+ if (s->me.unrestricted_mv &&
s->c.cur_pic.reference &&
!m->intra_only) {
int hshift = s->c.chroma_x_shift;
diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c
index 5c3850c12f..ef2228bb26 100644
--- a/libavcodec/rv20enc.c
+++ b/libavcodec/rv20enc.c
@@ -51,7 +51,7 @@ int ff_rv20_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb, 1, s->c.no_rounding);
av_assert1(s->f_code == 1);
- av_assert1(!s->c.unrestricted_mv);
+ av_assert1(!s->me.unrestricted_mv);
av_assert1(!s->c.alt_inter_vlc);
av_assert1(!s->c.umvplus);
av_assert1(s->c.modified_quant == 1);
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 661c6b3c07..68da7f55e7 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -1869,7 +1869,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
mpv->me.dia_size = avctx->dia_size;
mpv->c.quarter_sample = (s->avctx->flags & AV_CODEC_FLAG_QPEL)!=0;
mpv->c.out_format = FMT_H263;
- mpv->c.unrestricted_mv = 1;
+ mpv->me.unrestricted_mv = 1;
mpv->lambda = enc->lambda;
mpv->c.qscale = (mpv->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7);
diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
index 0816252c2f..ed3dca9025 100644
--- a/libavcodec/svq1enc.c
+++ b/libavcodec/svq1enc.c
@@ -333,7 +333,7 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane,
s2->pict_type = s->pict_type;
s->m.me.scene_change_score = 0;
// s2->out_format = FMT_H263;
- // s2->unrestricted_mv = 1;
+ // s->m.me.unrestricted_mv = 1;
s->m.lambda = s->quality;
s2->qscale = s->m.lambda * 139 +
FF_LAMBDA_SCALE * 64 >>
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 23/48] avcodec/mpeg4videodec: Avoid unnecessary indirections
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (21 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 22/48] avcodec/mpegvideo: Move unrestricted_mv to MotionEstContext Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 24/48] avcodec/{h263, mpeg4video}dec: Pass MPVContext*, not Mpeg4DecContext* Andreas Rheinhardt
` (24 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This basically reverts d4967c04e040b3b2f937cad88599af825147ec94.
Said commit was based on the false premise that it would
be an aliasing violation to upcast a pointer to structure
to a pointer to a bigger structure containing the original
structure as its first element, but this is just not true.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 34f383bbbd..c61fd23c48 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1647,12 +1647,10 @@ not_coded:
*/
static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64])
{
- Mpeg4DecContext *ctx = s->avctx->priv_data;
+ Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
int cbp, mb_type, use_intra_dc_vlc;
const int xy = s->mb_x + s->mb_y * s->mb_stride;
- av_assert2(s == (void*)ctx);
-
mb_type = s->cur_pic.mb_type[xy];
cbp = s->cbp_table[xy];
@@ -1737,13 +1735,12 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64])
static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
{
- Mpeg4DecContext *ctx = s->avctx->priv_data;
+ Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
const int xy = s->mb_x + s->mb_y * s->mb_stride;
int next;
- av_assert2(s == (void*)ctx);
av_assert2(s->h263_pred);
if (s->pict_type == AV_PICTURE_TYPE_P ||
@@ -2153,7 +2150,7 @@ static const uint8_t ac_state_tab[22][2] =
static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n)
{
- Mpeg4DecContext *ctx = s->avctx->priv_data;
+ Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0,
additional_code_len, sign, mismatch;
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 24/48] avcodec/{h263, mpeg4video}dec: Pass MPVContext*, not Mpeg4DecContext*
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (22 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 23/48] avcodec/mpeg4videodec: Avoid unnecessary indirections Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 25/48] avcodec/mpegvideo: Move dct_precision to Mpeg4DecContext Andreas Rheinhardt
` (23 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The code in h263dec.c is not supposed to know that the MPEG-4
decoder uses an Mpeg4DecContext as private context at all
(said context is only exposed in a header so that hardware
accelerations can access it and for the parser to use).
Passing an MPVContext* directly also allows to remove
the indirection via AVCodecContext.priv_data.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 4 ++--
libavcodec/ituh263dec.c | 4 ++--
libavcodec/mpeg4videodec.c | 12 ++++++------
libavcodec/mpeg4videodec.h | 6 +++---
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 52b17663db..7e454e3406 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -194,7 +194,7 @@ static int decode_slice(MpegEncContext *s)
ff_set_qscale(s, s->qscale);
if (s->studio_profile) {
- if ((ret = ff_mpeg4_decode_studio_slice_header(s->avctx->priv_data)) < 0)
+ if ((ret = ff_mpeg4_decode_studio_slice_header(s)) < 0)
return ret;
}
@@ -210,7 +210,7 @@ static int decode_slice(MpegEncContext *s)
const int qscale = s->qscale;
if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4)
- if ((ret = ff_mpeg4_decode_partitions(s->avctx->priv_data)) < 0)
+ if ((ret = ff_mpeg4_decode_partitions(s)) < 0)
return ret;
/* restore variables which were modified */
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index fa09ebb84b..f5001200fe 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -240,7 +240,7 @@ int ff_h263_resync(MpegEncContext *s){
if(show_bits(&s->gb, 16)==0){
pos= get_bits_count(&s->gb);
if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
- ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
+ ret = ff_mpeg4_decode_video_packet_header(s);
else
ret= h263_decode_gob_header(s);
if(ret>=0)
@@ -257,7 +257,7 @@ int ff_h263_resync(MpegEncContext *s){
pos= get_bits_count(&s->gb);
if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
- ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
+ ret = ff_mpeg4_decode_video_packet_header(s);
else
ret= h263_decode_gob_header(s);
if(ret>=0)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index c61fd23c48..91b1687884 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -700,9 +700,9 @@ static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) {
* Decode the next video packet.
* @return <0 if something went wrong
*/
-int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx)
+int ff_mpeg4_decode_video_packet_header(MPVContext *const s)
{
- MpegEncContext *s = &ctx->m;
+ Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
int mb_num_bits = av_log2(s->mb_num - 1) + 1;
int header_extension = 0, mb_num, len;
@@ -799,9 +799,9 @@ static void reset_studio_dc_predictors(MpegEncContext *s)
* Decode the next video packet.
* @return <0 if something went wrong
*/
-int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx)
+int ff_mpeg4_decode_studio_slice_header(MPVContext *const s)
{
- MpegEncContext *s = &ctx->m;
+ Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
GetBitContext *gb = &s->gb;
unsigned vlc_len;
uint16_t mb_num;
@@ -1307,9 +1307,9 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
* Decode the first and second partition.
* @return <0 if error (and sets error type in the error_status_table)
*/
-int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx)
+int ff_mpeg4_decode_partitions(MPVContext *const s)
{
- MpegEncContext *s = &ctx->m;
+ Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
int mb_num;
int ret;
const int part_a_error = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR;
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index ae8428fd2b..32ad081df3 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -116,9 +116,9 @@ void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb
void ff_mpeg4_mcsel_motion(MpegEncContext *s,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
uint8_t *const *ref_picture);
-int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx);
-int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext *ctx);
-int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx);
+int ff_mpeg4_decode_partitions(MPVContext *const s);
+int ff_mpeg4_decode_video_packet_header(MPVContext *const s);
+int ff_mpeg4_decode_studio_slice_header(MPVContext *const s);
void ff_mpeg4_workaround_bugs(AVCodecContext *avctx);
void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n,
int dir);
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 25/48] avcodec/mpegvideo: Move dct_precision to Mpeg4DecContext
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (23 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 24/48] avcodec/{h263, mpeg4video}dec: Pass MPVContext*, not Mpeg4DecContext* Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 26/48] avcodec/h263dec: Add H263DecContext Andreas Rheinhardt
` (22 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg4videodec.c | 25 ++++++++++++++-----------
libavcodec/mpeg4videodec.h | 1 +
libavcodec/mpegvideo.h | 1 -
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 91b1687884..677b372fee 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -787,12 +787,13 @@ int ff_mpeg4_decode_video_packet_header(MPVContext *const s)
return 0;
}
-static void reset_studio_dc_predictors(MpegEncContext *s)
+static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
{
+ MPVContext *const s = &ctx->m;
/* Reset DC Predictors */
s->last_dc[0] =
s->last_dc[1] =
- s->last_dc[2] = 1 << (s->avctx->bits_per_raw_sample + s->dct_precision + s->intra_dc_precision - 1);
+ s->last_dc[2] = 1 << (s->avctx->bits_per_raw_sample + ctx->dct_precision + s->intra_dc_precision - 1);
}
/**
@@ -827,7 +828,7 @@ int ff_mpeg4_decode_studio_slice_header(MPVContext *const s)
skip_bits(gb, 8); /* extra_information_slice */
}
- reset_studio_dc_predictors(s);
+ reset_studio_dc_predictors(ctx);
}
else {
return AVERROR_INVALIDDATA;
@@ -2160,7 +2161,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
uint32_t flc;
const int min = -1 * (1 << (s->avctx->bits_per_raw_sample + 6));
const int max = ((1 << (s->avctx->bits_per_raw_sample + 6)) - 1);
- int shift = 3 - s->dct_precision;
+ int shift = 3 - ctx->dct_precision;
mismatch = 1;
@@ -2196,7 +2197,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
if (ctx->mpeg_quant)
block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision);
else
- block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision) * (8 >> s->dct_precision);
+ block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision) * (8 >> ctx->dct_precision);
/* TODO: support mpeg_quant for AC coefficients */
block[0] = av_clip(block[0], min, max);
@@ -2246,7 +2247,7 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
if (idx > 63)
return AVERROR_INVALIDDATA;
j = scantable[idx++];
- additional_code_len = s->avctx->bits_per_raw_sample + s->dct_precision + 4;
+ additional_code_len = s->avctx->bits_per_raw_sample + ctx->dct_precision + 4;
flc = get_bits(&s->gb, additional_code_len);
if (flc >> (additional_code_len-1))
block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
@@ -2263,8 +2264,10 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
return 0;
}
-static int mpeg4_decode_dpcm_macroblock(MpegEncContext *s, int16_t macroblock[256], int n)
+static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
+ int16_t macroblock[256], int n)
{
+ MPVContext *const s = &ctx->m;
int i, j, w, h, idx = 0;
int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
dpcm_residual, left, top, topleft, min_left_top, max_left_top, p, p2, output;
@@ -2276,7 +2279,7 @@ static int mpeg4_decode_dpcm_macroblock(MpegEncContext *s, int16_t macroblock[25
av_log(s->avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
return AVERROR_INVALIDDATA;
}
- s->last_dc[n] = block_mean * (1 << (s->dct_precision + s->intra_dc_precision));
+ s->last_dc[n] = block_mean * (1 << (ctx->dct_precision + s->intra_dc_precision));
rice_parameter = get_bits(&s->gb, 4);
if (rice_parameter == 0) {
@@ -2373,7 +2376,7 @@ static int mpeg4_decode_studio_mb(MpegEncContext *s, int16_t block_[12][64])
check_marker(s->avctx, &s->gb, "DPCM block start");
ctx->dpcm_direction = get_bits1(&s->gb) ? -1 : 1;
for (i = 0; i < 3; i++) {
- if (mpeg4_decode_dpcm_macroblock(s, ctx->dpcm_macroblock[i], i) < 0)
+ if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0)
return AVERROR_INVALIDDATA;
}
}
@@ -3521,13 +3524,13 @@ static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
if (s->pict_type == AV_PICTURE_TYPE_I) {
if (get_bits1(gb))
- reset_studio_dc_predictors(s);
+ reset_studio_dc_predictors(ctx);
}
if (ctx->shape != BIN_ONLY_SHAPE) {
s->alternate_scan = get_bits1(gb);
s->frame_pred_frame_dct = get_bits1(gb);
- s->dct_precision = get_bits(gb, 2);
+ ctx->dct_precision = get_bits(gb, 2);
s->intra_dc_precision = get_bits(gb, 2);
s->q_scale_type = get_bits1(gb);
}
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 32ad081df3..9598429d08 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -105,6 +105,7 @@ typedef struct Mpeg4DecContext {
};
// 0 = DCT, 1 = DPCM top to bottom scan, -1 = DPCM bottom to top scan
int dpcm_direction;
+ int dct_precision;
} Mpeg4DecContext;
int ff_mpeg4_decode_picture_header(MpegEncContext *s);
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index d95cebedd8..81d2675f50 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -238,7 +238,6 @@ typedef struct MpegEncContext {
/* MPEG-4 specific */
int studio_profile;
- int dct_precision;
int last_time_base;
int time_base; ///< time in seconds of last I,P,S Frame
int64_t time; ///< time of current frame
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 26/48] avcodec/h263dec: Add H263DecContext
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (24 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 25/48] avcodec/mpegvideo: Move dct_precision to Mpeg4DecContext Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 27/48] avcodec/h263dec: Remove redundant block parameter from decode_mb Andreas Rheinhardt
` (21 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is in preparation for moving the fields only used
by H.263-based decoders from MPVContext to H263DecContext.
For now only the decode_mb function pointer has been moved
(to be able to switch said callback to use an H263DecContext*).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/flvdec.c | 60 +-
libavcodec/flvdec.h | 4 +-
libavcodec/h263dec.c | 408 ++++----
libavcodec/h263dec.h | 22 +-
libavcodec/intelh263dec.c | 110 +--
libavcodec/ituh263dec.c | 947 +++++++++---------
libavcodec/mpeg4video_parser.c | 4 +-
libavcodec/mpeg4videodec.c | 1703 ++++++++++++++++----------------
libavcodec/mpeg4videodec.h | 13 +-
libavcodec/mpegvideo.h | 1 -
libavcodec/msmpeg4dec.c | 505 +++++-----
libavcodec/msmpeg4dec.h | 11 +-
libavcodec/nvdec_mpeg4.c | 2 +-
libavcodec/rv10.c | 340 +++----
libavcodec/rv10dec.h | 4 +-
libavcodec/vaapi_mpeg4.c | 2 +-
libavcodec/vdpau_mpeg4.c | 2 +-
libavcodec/wmv2.h | 4 +-
libavcodec/wmv2dec.c | 321 +++---
libavcodec/wmv2dec.h | 5 +-
libavcodec/wmv2enc.c | 2 +-
21 files changed, 2250 insertions(+), 2220 deletions(-)
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index e8c1595639..a5d96584f1 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -26,31 +26,31 @@
#include "mpegvideo.h"
#include "mpegvideodec.h"
-int ff_flv_decode_picture_header(MpegEncContext *s)
+int ff_flv_decode_picture_header(H263DecContext *const h)
{
int format, width, height;
/* picture header */
- if (get_bits(&s->gb, 17) != 1) {
- av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
+ if (get_bits(&h->c.gb, 17) != 1) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
return AVERROR_INVALIDDATA;
}
- format = get_bits(&s->gb, 5);
+ format = get_bits(&h->c.gb, 5);
if (format != 0 && format != 1) {
- av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");
return AVERROR_INVALIDDATA;
}
- s->h263_flv = format + 1;
- s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
- format = get_bits(&s->gb, 3);
+ h->c.h263_flv = format + 1;
+ h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */
+ format = get_bits(&h->c.gb, 3);
switch (format) {
case 0:
- width = get_bits(&s->gb, 8);
- height = get_bits(&s->gb, 8);
+ width = get_bits(&h->c.gb, 8);
+ height = get_bits(&h->c.gb, 8);
break;
case 1:
- width = get_bits(&s->gb, 16);
- height = get_bits(&s->gb, 16);
+ width = get_bits(&h->c.gb, 16);
+ height = get_bits(&h->c.gb, 16);
break;
case 2:
width = 352;
@@ -76,32 +76,32 @@ int ff_flv_decode_picture_header(MpegEncContext *s)
width = height = 0;
break;
}
- if (av_image_check_size(width, height, 0, s->avctx))
+ if (av_image_check_size(width, height, 0, h->c.avctx))
return AVERROR(EINVAL);
- s->width = width;
- s->height = height;
+ h->c.width = width;
+ h->c.height = height;
- s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
- s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
- if (s->droppable)
- s->pict_type = AV_PICTURE_TYPE_P;
+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->c.gb, 2);
+ h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P;
+ if (h->c.droppable)
+ h->c.pict_type = AV_PICTURE_TYPE_P;
- skip_bits1(&s->gb); /* deblocking flag */
- s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
+ skip_bits1(&h->c.gb); /* deblocking flag */
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
- s->h263_long_vectors = 0;
+ h->c.h263_long_vectors = 0;
/* PEI */
- if (skip_1stop_8data_bits(&s->gb) < 0)
+ if (skip_1stop_8data_bits(&h->c.gb) < 0)
return AVERROR_INVALIDDATA;
- if (s->ehc_mode)
- s->avctx->sample_aspect_ratio= (AVRational){1,2};
+ if (h->c.ehc_mode)
+ h->c.avctx->sample_aspect_ratio= (AVRational){1,2};
- if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
- s->droppable ? 'D' : av_get_picture_type_char(s->pict_type),
- s->h263_flv - 1, s->qscale, s->picture_number);
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
+ av_log(h->c.avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
+ h->c.droppable ? 'D' : av_get_picture_type_char(h->c.pict_type),
+ h->c.h263_flv - 1, h->c.qscale, h->c.picture_number);
}
return 0;
@@ -112,7 +112,7 @@ const FFCodec ff_flv_decoder = {
CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_FLV1,
- .priv_data_size = sizeof(MpegEncContext),
+ .priv_data_size = sizeof(H263DecContext),
.init = ff_h263_decode_init,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
diff --git a/libavcodec/flvdec.h b/libavcodec/flvdec.h
index d5aff74a98..e0f6d299ca 100644
--- a/libavcodec/flvdec.h
+++ b/libavcodec/flvdec.h
@@ -21,8 +21,8 @@
#ifndef AVCODEC_FLVDEC_H
#define AVCODEC_FLVDEC_H
-#include "mpegvideo.h"
+struct H263DecContext;
-int ff_flv_decode_picture_header(MpegEncContext *s);
+int ff_flv_decode_picture_header(struct H263DecContext *const h);
#endif /* AVCODEC_FLVDEC_H */
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 7e454e3406..22bcf40681 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -90,7 +90,8 @@ static enum AVPixelFormat h263_get_format(AVCodecContext *avctx)
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
{
- MpegEncContext *s = avctx->priv_data;
+ H263DecContext *const h = avctx->priv_data;
+ MPVContext *const s = &h->c;
MPVUnquantDSPContext unquant_dsp_ctx;
int ret;
@@ -101,7 +102,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
if (ret < 0)
return ret;
- s->decode_mb = ff_h263_decode_mb;
+ h->decode_mb = ff_h263_decode_mb;
s->low_delay = 1;
s->y_dc_scale_table =
@@ -179,239 +180,239 @@ static void report_decode_progress(MpegEncContext *s)
ff_thread_progress_report(&s->cur_pic.ptr->progress, s->mb_y);
}
-static int decode_slice(MpegEncContext *s)
+static int decode_slice(H263DecContext *const h)
{
- const int part_mask = s->partitioned_frame
+ const int part_mask = h->c.partitioned_frame
? (ER_AC_END | ER_AC_ERROR) : 0x7F;
- const int mb_size = 16 >> s->avctx->lowres;
+ const int mb_size = 16 >> h->c.avctx->lowres;
int ret;
- s->last_resync_gb = s->gb;
- s->first_slice_line = 1;
- s->resync_mb_x = s->mb_x;
- s->resync_mb_y = s->mb_y;
+ h->c.last_resync_gb = h->c.gb;
+ h->c.first_slice_line = 1;
+ h->c.resync_mb_x = h->c.mb_x;
+ h->c.resync_mb_y = h->c.mb_y;
- ff_set_qscale(s, s->qscale);
+ ff_set_qscale(&h->c, h->c.qscale);
- if (s->studio_profile) {
- if ((ret = ff_mpeg4_decode_studio_slice_header(s)) < 0)
+ if (h->c.studio_profile) {
+ if ((ret = ff_mpeg4_decode_studio_slice_header(h)) < 0)
return ret;
}
- if (s->avctx->hwaccel) {
- const uint8_t *start = s->gb.buffer + get_bits_count(&s->gb) / 8;
- ret = FF_HW_CALL(s->avctx, decode_slice, start, s->gb.buffer_end - start);
+ if (h->c.avctx->hwaccel) {
+ const uint8_t *start = h->c.gb.buffer + get_bits_count(&h->c.gb) / 8;
+ ret = FF_HW_CALL(h->c.avctx, decode_slice, start, h->c.gb.buffer_end - start);
// ensure we exit decode loop
- s->mb_y = s->mb_height;
+ h->c.mb_y = h->c.mb_height;
return ret;
}
- if (s->partitioned_frame) {
- const int qscale = s->qscale;
+ if (h->c.partitioned_frame) {
+ const int qscale = h->c.qscale;
- if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4)
- if ((ret = ff_mpeg4_decode_partitions(s)) < 0)
+ if (CONFIG_MPEG4_DECODER && h->c.codec_id == AV_CODEC_ID_MPEG4)
+ if ((ret = ff_mpeg4_decode_partitions(h)) < 0)
return ret;
/* restore variables which were modified */
- s->first_slice_line = 1;
- s->mb_x = s->resync_mb_x;
- s->mb_y = s->resync_mb_y;
- ff_set_qscale(s, qscale);
+ h->c.first_slice_line = 1;
+ h->c.mb_x = h->c.resync_mb_x;
+ h->c.mb_y = h->c.resync_mb_y;
+ ff_set_qscale(&h->c, qscale);
}
- for (; s->mb_y < s->mb_height; s->mb_y++) {
+ for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) {
/* per-row end of slice checks */
- 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);
+ if (h->c.msmpeg4_version != MSMP4_UNUSED) {
+ if (h->c.resync_mb_y + h->c.slice_height == 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 - 1, h->c.mb_y, ER_MB_END);
return 0;
}
}
- if (s->msmpeg4_version == MSMP4_V1) {
- s->last_dc[0] =
- s->last_dc[1] =
- s->last_dc[2] = 128;
+ if (h->c.msmpeg4_version == MSMP4_V1) {
+ h->c.last_dc[0] =
+ h->c.last_dc[1] =
+ h->c.last_dc[2] = 128;
}
- ff_init_block_index(s);
- for (; s->mb_x < s->mb_width; s->mb_x++) {
+ ff_init_block_index(&h->c);
+ for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
int ret;
- ff_update_block_index(s, s->avctx->bits_per_raw_sample,
- s->avctx->lowres, s->chroma_x_shift);
+ ff_update_block_index(&h->c, h->c.avctx->bits_per_raw_sample,
+ h->c.avctx->lowres, h->c.chroma_x_shift);
- if (s->resync_mb_x == s->mb_x && s->resync_mb_y + 1 == s->mb_y)
- s->first_slice_line = 0;
+ if (h->c.resync_mb_x == h->c.mb_x && h->c.resync_mb_y + 1 == h->c.mb_y)
+ h->c.first_slice_line = 0;
/* DCT & quantize */
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- ff_dlog(s->avctx, "%d %06X\n",
- get_bits_count(&s->gb), show_bits(&s->gb, 24));
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ ff_dlog(h->c.avctx, "%d %06X\n",
+ get_bits_count(&h->c.gb), show_bits(&h->c.gb, 24));
- ff_tlog(NULL, "Decoding MB at %dx%d\n", s->mb_x, s->mb_y);
- ret = s->decode_mb(s, s->block);
+ ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y);
+ ret = h->decode_mb(h, h->c.block);
- if (s->h263_pred || s->h263_aic) {
- int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
- if (!s->mb_intra) {
- ff_h263_clean_intra_table_entries(s, mb_xy);
+ if (h->c.h263_pred || h->c.h263_aic) {
+ int mb_xy = h->c.mb_y * h->c.mb_stride + h->c.mb_x;
+ if (!h->c.mb_intra) {
+ ff_h263_clean_intra_table_entries(&h->c, mb_xy);
} else
- s->mbintra_table[mb_xy] = 1;
+ h->c.mbintra_table[mb_xy] = 1;
}
- if (s->pict_type != AV_PICTURE_TYPE_B)
- ff_h263_update_motion_val(s);
+ if (h->c.pict_type != AV_PICTURE_TYPE_B)
+ ff_h263_update_motion_val(&h->c);
if (ret < 0) {
- const int xy = s->mb_x + s->mb_y * s->mb_stride;
+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
if (ret == SLICE_END) {
- ff_mpv_reconstruct_mb(s, s->block);
- if (s->loop_filter)
- ff_h263_loop_filter(s);
+ ff_mpv_reconstruct_mb(&h->c, h->c.block);
+ if (h->c.loop_filter)
+ ff_h263_loop_filter(&h->c);
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x, s->mb_y, ER_MB_END & part_mask);
+ 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);
- s->padding_bug_score--;
+ h->c.padding_bug_score--;
- if (++s->mb_x >= s->mb_width) {
- s->mb_x = 0;
- report_decode_progress(s);
- ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
- s->mb_y++;
+ if (++h->c.mb_x >= h->c.mb_width) {
+ h->c.mb_x = 0;
+ report_decode_progress(&h->c);
+ ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
+ h->c.mb_y++;
}
return 0;
} else if (ret == SLICE_NOEND) {
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"Slice mismatch at MB: %d\n", xy);
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x + 1, s->mb_y,
+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
+ h->c.mb_x + 1, h->c.mb_y,
ER_MB_END & part_mask);
return AVERROR_INVALIDDATA;
}
- av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x, s->mb_y, ER_MB_ERROR & part_mask);
+ av_log(h->c.avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
+ 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_ERROR & part_mask);
- if ((s->avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&s->gb) > 0)
+ if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->c.gb) > 0)
continue;
return AVERROR_INVALIDDATA;
}
- ff_mpv_reconstruct_mb(s, s->block);
- if (s->loop_filter)
- ff_h263_loop_filter(s);
+ ff_mpv_reconstruct_mb(&h->c, h->c.block);
+ if (h->c.loop_filter)
+ ff_h263_loop_filter(&h->c);
}
- report_decode_progress(s);
- ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
+ report_decode_progress(&h->c);
+ ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
- s->mb_x = 0;
+ h->c.mb_x = 0;
}
- av_assert1(s->mb_x == 0 && s->mb_y == s->mb_height);
+ av_assert1(h->c.mb_x == 0 && h->c.mb_y == h->c.mb_height);
// Detect incorrect padding with wrong stuffing codes used by NEC N-02B
- if (s->codec_id == AV_CODEC_ID_MPEG4 &&
- (s->workaround_bugs & FF_BUG_AUTODETECT) &&
- get_bits_left(&s->gb) >= 48 &&
- show_bits(&s->gb, 24) == 0x4010 &&
- !s->data_partitioning)
- s->padding_bug_score += 32;
+ if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
+ (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
+ get_bits_left(&h->c.gb) >= 48 &&
+ show_bits(&h->c.gb, 24) == 0x4010 &&
+ !h->c.data_partitioning)
+ h->c.padding_bug_score += 32;
/* try to detect the padding bug */
- if (s->codec_id == AV_CODEC_ID_MPEG4 &&
- (s->workaround_bugs & FF_BUG_AUTODETECT) &&
- get_bits_left(&s->gb) >= 0 &&
- get_bits_left(&s->gb) < 137 &&
- !s->data_partitioning) {
- const int bits_count = get_bits_count(&s->gb);
- const int bits_left = s->gb.size_in_bits - bits_count;
+ if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
+ (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
+ get_bits_left(&h->c.gb) >= 0 &&
+ get_bits_left(&h->c.gb) < 137 &&
+ !h->c.data_partitioning) {
+ const int bits_count = get_bits_count(&h->c.gb);
+ const int bits_left = h->c.gb.size_in_bits - bits_count;
if (bits_left == 0) {
- s->padding_bug_score += 16;
+ h->c.padding_bug_score += 16;
} else if (bits_left != 1) {
- int v = show_bits(&s->gb, 8);
+ int v = show_bits(&h->c.gb, 8);
v |= 0x7F >> (7 - (bits_count & 7));
if (v == 0x7F && bits_left <= 8)
- s->padding_bug_score--;
- else if (v == 0x7F && ((get_bits_count(&s->gb) + 8) & 8) &&
+ h->c.padding_bug_score--;
+ else if (v == 0x7F && ((get_bits_count(&h->c.gb) + 8) & 8) &&
bits_left <= 16)
- s->padding_bug_score += 4;
+ h->c.padding_bug_score += 4;
else
- s->padding_bug_score++;
+ h->c.padding_bug_score++;
}
}
- if (s->codec_id == AV_CODEC_ID_H263 &&
- (s->workaround_bugs & FF_BUG_AUTODETECT) &&
- get_bits_left(&s->gb) >= 8 &&
- get_bits_left(&s->gb) < 300 &&
- s->pict_type == AV_PICTURE_TYPE_I &&
- show_bits(&s->gb, 8) == 0 &&
- !s->data_partitioning) {
+ if (h->c.codec_id == AV_CODEC_ID_H263 &&
+ (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
+ get_bits_left(&h->c.gb) >= 8 &&
+ get_bits_left(&h->c.gb) < 300 &&
+ h->c.pict_type == AV_PICTURE_TYPE_I &&
+ show_bits(&h->c.gb, 8) == 0 &&
+ !h->c.data_partitioning) {
- s->padding_bug_score += 32;
+ h->c.padding_bug_score += 32;
}
- if (s->codec_id == AV_CODEC_ID_H263 &&
- (s->workaround_bugs & FF_BUG_AUTODETECT) &&
- get_bits_left(&s->gb) >= 64 &&
- AV_RB64(s->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
+ if (h->c.codec_id == AV_CODEC_ID_H263 &&
+ (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
+ get_bits_left(&h->c.gb) >= 64 &&
+ AV_RB64(h->c.gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
- s->padding_bug_score += 32;
+ h->c.padding_bug_score += 32;
}
- if (s->workaround_bugs & FF_BUG_AUTODETECT) {
+ if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
if (
- (s->padding_bug_score > -2 && !s->data_partitioning))
- s->workaround_bugs |= FF_BUG_NO_PADDING;
+ (h->c.padding_bug_score > -2 && !h->c.data_partitioning))
+ h->c.workaround_bugs |= FF_BUG_NO_PADDING;
else
- s->workaround_bugs &= ~FF_BUG_NO_PADDING;
+ h->c.workaround_bugs &= ~FF_BUG_NO_PADDING;
}
// handle formats which don't have unique end markers
- 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);
+ if (h->c.msmpeg4_version != MSMP4_UNUSED || (h->c.workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
+ int left = get_bits_left(&h->c.gb);
int max_extra = 7;
/* no markers in M$ crap */
- if (s->msmpeg4_version != MSMP4_UNUSED && s->pict_type == AV_PICTURE_TYPE_I)
+ if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.pict_type == AV_PICTURE_TYPE_I)
max_extra += 17;
/* buggy padding but the frame should still end approximately at
* the bitstream end */
- if ((s->workaround_bugs & FF_BUG_NO_PADDING) &&
- (s->avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
+ if ((h->c.workaround_bugs & FF_BUG_NO_PADDING) &&
+ (h->c.avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
max_extra += 48;
- else if ((s->workaround_bugs & FF_BUG_NO_PADDING))
+ else if ((h->c.workaround_bugs & FF_BUG_NO_PADDING))
max_extra += 256 * 256 * 256 * 64;
if (left > max_extra)
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"discarding %d junk bits at end, next would be %X\n",
- left, show_bits(&s->gb, 24));
+ left, show_bits(&h->c.gb, 24));
else if (left < 0)
- av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
+ av_log(h->c.avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
else
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x - 1, s->mb_y, ER_MB_END);
+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
+ h->c.mb_x - 1, h->c.mb_y, ER_MB_END);
return 0;
}
- av_log(s->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",
- get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score);
+ get_bits_left(&h->c.gb), show_bits(&h->c.gb, 24), h->c.padding_bug_score);
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->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);
return AVERROR_INVALIDDATA;
@@ -420,9 +421,10 @@ static int decode_slice(MpegEncContext *s)
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
int *got_frame, AVPacket *avpkt)
{
+ H263DecContext *const h = avctx->priv_data;
+ MPVContext *const s = &h->c;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
- MpegEncContext *s = avctx->priv_data;
int ret;
int slice_ret = 0;
int bak_width, bak_height;
@@ -430,10 +432,10 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
/* no supplementary picture */
if (buf_size == 0) {
/* special case for last picture */
- if ((!s->low_delay || s->skipped_last_frame) && s->next_pic.ptr) {
- if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
+ if ((!h->c.low_delay || h->c.skipped_last_frame) && h->c.next_pic.ptr) {
+ if ((ret = av_frame_ref(pict, h->c.next_pic.ptr->f)) < 0)
return ret;
- if (s->skipped_last_frame) {
+ if (h->c.skipped_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
* packet so that the stream's end time is correct. */
@@ -442,7 +444,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
return ret;
}
- ff_mpv_unref_picture(&s->next_pic);
+ ff_mpv_unref_picture(&h->c.next_pic);
*got_frame = 1;
}
@@ -450,37 +452,37 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
return 0;
}
- // s->gb might be overridden in ff_mpeg4_decode_picture_header() below.
- ret = init_get_bits8(&s->gb, buf, buf_size);
+ // h->c.gb might be overridden in ff_mpeg4_decode_picture_header() below.
+ ret = init_get_bits8(&h->c.gb, buf, buf_size);
if (ret < 0)
return ret;
- bak_width = s->width;
- bak_height = s->height;
+ bak_width = h->c.width;
+ bak_height = h->c.height;
/* let's go :-) */
- if (CONFIG_WMV2_DECODER && s->msmpeg4_version == MSMP4_WMV2) {
- ret = ff_wmv2_decode_picture_header(s);
+ if (CONFIG_WMV2_DECODER && h->c.msmpeg4_version == MSMP4_WMV2) {
+ ret = ff_wmv2_decode_picture_header(h);
#if CONFIG_MSMPEG4DEC
- } else if (s->msmpeg4_version != MSMP4_UNUSED) {
- ret = ff_msmpeg4_decode_picture_header(s);
+ } else if (h->c.msmpeg4_version != MSMP4_UNUSED) {
+ ret = ff_msmpeg4_decode_picture_header(h);
#endif
} else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
- ret = ff_mpeg4_decode_picture_header(s);
- } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
- ret = ff_intel_h263_decode_picture_header(s);
- } else if (CONFIG_FLV_DECODER && s->h263_flv) {
- ret = ff_flv_decode_picture_header(s);
+ ret = ff_mpeg4_decode_picture_header(h);
+ } else if (CONFIG_H263I_DECODER && h->c.codec_id == AV_CODEC_ID_H263I) {
+ ret = ff_intel_h263_decode_picture_header(h);
+ } else if (CONFIG_FLV_DECODER && h->c.h263_flv) {
+ ret = ff_flv_decode_picture_header(h);
} else {
- ret = ff_h263_decode_picture_header(s);
+ ret = ff_h263_decode_picture_header(h);
}
if (ret < 0 || ret == FRAME_SKIPPED) {
- if ( s->width != bak_width
- || s->height != bak_height) {
- av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
- s->width = bak_width;
- s->height= bak_height;
+ if ( h->c.width != bak_width
+ || h->c.height != bak_height) {
+ av_log(h->c.avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
+ h->c.width = bak_width;
+ h->c.height= bak_height;
}
}
@@ -489,23 +491,23 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
/* skip if the header was thrashed */
if (ret < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "header damaged\n");
return ret;
}
- if (!s->context_initialized) {
+ if (!h->c.context_initialized) {
avctx->pix_fmt = h263_get_format(avctx);
if ((ret = ff_mpv_common_init(s)) < 0)
return ret;
}
- avctx->has_b_frames = !s->low_delay;
+ avctx->has_b_frames = !h->c.low_delay;
if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
- if (s->pict_type != AV_PICTURE_TYPE_B && s->mb_num/2 > get_bits_left(&s->gb))
+ if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->c.gb))
return AVERROR_INVALIDDATA;
ff_mpeg4_workaround_bugs(avctx);
- if (s->studio_profile != (s->idsp.idct == NULL))
+ if (h->c.studio_profile != (h->c.idsp.idct == NULL))
ff_mpv_idct_init(s);
}
@@ -513,13 +515,13 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
* and other parameters. So then we could init the picture.
* FIXME: By the way H.263 decoder is evolving it should have
* an H263EncContext */
- if (s->width != avctx->coded_width ||
- s->height != avctx->coded_height ||
- s->context_reinit) {
+ if (h->c.width != avctx->coded_width ||
+ h->c.height != avctx->coded_height ||
+ h->c.context_reinit) {
/* H.263 could change picture size any time */
- s->context_reinit = 0;
+ h->c.context_reinit = 0;
- ret = ff_set_dimensions(avctx, s->width, s->height);
+ ret = ff_set_dimensions(avctx, h->c.width, h->c.height);
if (ret < 0)
return ret;
@@ -536,25 +538,25 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
}
/* skip B-frames if we don't have reference frames */
- if (!s->last_pic.ptr &&
- (s->pict_type == AV_PICTURE_TYPE_B || s->droppable))
+ if (!h->c.last_pic.ptr &&
+ (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.droppable))
return buf_size;
if ((avctx->skip_frame >= AVDISCARD_NONREF &&
- s->pict_type == AV_PICTURE_TYPE_B) ||
+ h->c.pict_type == AV_PICTURE_TYPE_B) ||
(avctx->skip_frame >= AVDISCARD_NONKEY &&
- s->pict_type != AV_PICTURE_TYPE_I) ||
+ h->c.pict_type != AV_PICTURE_TYPE_I) ||
avctx->skip_frame >= AVDISCARD_ALL)
return buf_size;
if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
return ret;
- if (!s->divx_packed)
+ if (!h->c.divx_packed)
ff_thread_finish_setup(avctx);
if (avctx->hwaccel) {
ret = FF_HW_CALL(avctx, start_frame, NULL,
- s->gb.buffer, s->gb.buffer_end - s->gb.buffer);
+ h->c.gb.buffer, h->c.gb.buffer_end - h->c.gb.buffer);
if (ret < 0 )
return ret;
}
@@ -565,8 +567,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
* are stored in current_picture->mb_type which is not available before
* ff_mpv_frame_start() */
#if CONFIG_WMV2_DECODER
- if (s->msmpeg4_version == MSMP4_WMV2) {
- ret = ff_wmv2_decode_secondary_picture_header(s);
+ if (h->c.msmpeg4_version == MSMP4_WMV2) {
+ ret = ff_wmv2_decode_secondary_picture_header(h);
if (ret < 0)
return ret;
if (ret == 1)
@@ -575,39 +577,39 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
#endif
/* decode each macroblock */
- s->mb_x = 0;
- s->mb_y = 0;
-
- slice_ret = decode_slice(s);
- while (s->mb_y < s->mb_height) {
- 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)
+ h->c.mb_x = 0;
+ h->c.mb_y = 0;
+
+ slice_ret = decode_slice(h);
+ while (h->c.mb_y < h->c.mb_height) {
+ if (h->c.msmpeg4_version != MSMP4_UNUSED) {
+ if (h->c.slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 ||
+ (h->c.mb_y % h->c.slice_height) != 0 || get_bits_left(&h->c.gb) < 0)
break;
} else {
- int prev_x = s->mb_x, prev_y = s->mb_y;
- if (ff_h263_resync(s) < 0)
+ int prev_x = h->c.mb_x, prev_y = h->c.mb_y;
+ if (ff_h263_resync(h) < 0)
break;
- if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x)
- s->er.error_occurred = 1;
+ if (prev_y * h->c.mb_width + prev_x < h->c.mb_y * h->c.mb_width + h->c.mb_x)
+ h->c.er.error_occurred = 1;
}
- if (s->msmpeg4_version < MSMP4_WMV1 && s->h263_pred)
+ if (h->c.msmpeg4_version < MSMP4_WMV1 && h->c.h263_pred)
ff_mpeg4_clean_buffers(s);
- if (decode_slice(s) < 0)
+ if (decode_slice(h) < 0)
slice_ret = AVERROR_INVALIDDATA;
}
- if (s->msmpeg4_version != MSMP4_UNUSED && s->msmpeg4_version < MSMP4_WMV1 &&
- s->pict_type == AV_PICTURE_TYPE_I)
+ if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.msmpeg4_version < MSMP4_WMV1 &&
+ h->c.pict_type == AV_PICTURE_TYPE_I)
if (!CONFIG_MSMPEG4DEC ||
- ff_msmpeg4_decode_ext_header(s, buf_size) < 0)
- s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR;
+ ff_msmpeg4_decode_ext_header(h, buf_size) < 0)
+ h->c.er.error_status_table[h->c.mb_num - 1] = ER_MB_ERROR;
frame_end:
- if (!s->studio_profile)
- ff_er_frame_end(&s->er, NULL);
+ if (!h->c.studio_profile)
+ ff_er_frame_end(&h->c.er, NULL);
if (avctx->hwaccel) {
ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
@@ -620,22 +622,22 @@ frame_end:
if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
ff_mpeg4_frame_end(avctx, avpkt);
- av_assert1(s->pict_type == s->cur_pic.ptr->f->pict_type);
- if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
+ av_assert1(h->c.pict_type == h->c.cur_pic.ptr->f->pict_type);
+ if (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.low_delay) {
+ if ((ret = av_frame_ref(pict, h->c.cur_pic.ptr->f)) < 0)
return ret;
- ff_print_debug_info(s, s->cur_pic.ptr, pict);
- ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
- } else if (s->last_pic.ptr) {
- if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0)
+ ff_print_debug_info(s, h->c.cur_pic.ptr, pict);
+ ff_mpv_export_qp_table(s, pict, h->c.cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
+ } else if (h->c.last_pic.ptr) {
+ if ((ret = av_frame_ref(pict, h->c.last_pic.ptr->f)) < 0)
return ret;
- ff_print_debug_info(s, s->last_pic.ptr, pict);
- ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
+ ff_print_debug_info(s, h->c.last_pic.ptr, pict);
+ ff_mpv_export_qp_table(s, pict, h->c.last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
}
- if (s->last_pic.ptr || s->low_delay) {
+ if (h->c.last_pic.ptr || h->c.low_delay) {
if ( pict->format == AV_PIX_FMT_YUV420P
- && (s->codec_tag == AV_RL32("GEOV") || s->codec_tag == AV_RL32("GEOX"))) {
+ && (h->c.codec_tag == AV_RL32("GEOV") || h->c.codec_tag == AV_RL32("GEOX"))) {
for (int p = 0; p < 3; p++) {
int h = AV_CEIL_RSHIFT(pict->height, !!p);
@@ -673,7 +675,7 @@ const FFCodec ff_h263_decoder = {
CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_H263,
- .priv_data_size = sizeof(MpegEncContext),
+ .priv_data_size = sizeof(H263DecContext),
.init = ff_h263_decode_init,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
@@ -691,7 +693,7 @@ const FFCodec ff_h263p_decoder = {
CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_H263P,
- .priv_data_size = sizeof(MpegEncContext),
+ .priv_data_size = sizeof(H263DecContext),
.init = ff_h263_decode_init,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index c1306c7ec5..0600e0bcb0 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -43,24 +43,30 @@ extern VLCElem ff_h263_inter_MCBPC_vlc[];
extern VLCElem ff_h263_cbpy_vlc[];
extern VLCElem ff_h263_mv_vlc[];
-int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code);
+typedef struct H263DecContext {
+ MPVContext c;
+
+ int (*decode_mb)(struct H263DecContext *h, int16_t block[6][64]);
+} H263DecContext;
+
+int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code);
int ff_h263_decode_init(AVCodecContext *avctx);
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *frame,
int *got_frame, AVPacket *avpkt);
void ff_h263_decode_init_vlc(void);
-int ff_h263_decode_picture_header(MpegEncContext *s);
-int ff_h263_decode_gob_header(MpegEncContext *s);
-int ff_h263_decode_mba(MpegEncContext *s);
+int ff_h263_decode_picture_header(H263DecContext *const h);
+int ff_h263_decode_gob_header(H263DecContext *const h);
+int ff_h263_decode_mba(H263DecContext *const h);
/**
* Print picture info if FF_DEBUG_PICT_INFO is set.
*/
-void ff_h263_show_pict_info(MpegEncContext *s, int h263_plus);
+void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus);
-int ff_intel_h263_decode_picture_header(MpegEncContext *s);
-int ff_h263_decode_mb(MpegEncContext *s,
+int ff_intel_h263_decode_picture_header(H263DecContext *const h);
+int ff_h263_decode_mb(H263DecContext *const h,
int16_t block[6][64]);
-int ff_h263_resync(MpegEncContext *s);
+int ff_h263_resync(H263DecContext *const h);
#endif
diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c
index 02016e93bf..d7242f4922 100644
--- a/libavcodec/intelh263dec.c
+++ b/libavcodec/intelh263dec.c
@@ -26,102 +26,102 @@
#include "h263dec.h"
/* don't understand why they choose a different header ! */
-int ff_intel_h263_decode_picture_header(MpegEncContext *s)
+int ff_intel_h263_decode_picture_header(H263DecContext *const h)
{
int format;
- if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
+ if (get_bits_left(&h->c.gb) == 64) { /* special dummy frames */
return FRAME_SKIPPED;
}
/* picture header */
- if (get_bits(&s->gb, 22) != 0x20) {
- av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
+ if (get_bits(&h->c.gb, 22) != 0x20) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
return -1;
}
- s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
+ h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */
- if (check_marker(s->avctx, &s->gb, "after picture_number") != 1) {
+ if (check_marker(h->c.avctx, &h->c.gb, "after picture_number") != 1) {
return -1; /* marker */
}
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
return -1; /* H.263 id */
}
- skip_bits1(&s->gb); /* split screen off */
- skip_bits1(&s->gb); /* camera off */
- skip_bits1(&s->gb); /* freeze picture release off */
+ skip_bits1(&h->c.gb); /* split screen off */
+ skip_bits1(&h->c.gb); /* camera off */
+ skip_bits1(&h->c.gb); /* freeze picture release off */
- format = get_bits(&s->gb, 3);
+ format = get_bits(&h->c.gb, 3);
if (format == 0 || format == 6) {
- av_log(s->avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
return -1;
}
- s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb);
- s->h263_long_vectors = get_bits1(&s->gb);
+ h->c.h263_long_vectors = get_bits1(&h->c.gb);
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n");
return -1; /* SAC: off */
}
- s->obmc= get_bits1(&s->gb);
- s->pb_frame = get_bits1(&s->gb);
+ h->c.obmc = get_bits1(&h->c.gb);
+ h->c.pb_frame = get_bits1(&h->c.gb);
if (format < 6) {
- s->width = ff_h263_format[format][0];
- s->height = ff_h263_format[format][1];
- s->avctx->sample_aspect_ratio.num = 12;
- s->avctx->sample_aspect_ratio.den = 11;
+ h->c.width = ff_h263_format[format][0];
+ h->c.height = ff_h263_format[format][1];
+ h->c.avctx->sample_aspect_ratio.num = 12;
+ h->c.avctx->sample_aspect_ratio.den = 11;
} else {
- format = get_bits(&s->gb, 3);
+ format = get_bits(&h->c.gb, 3);
if(format == 0 || format == 7){
- av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
return -1;
}
- if(get_bits(&s->gb, 2))
- av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
- s->loop_filter = get_bits1(&s->gb) * !s->avctx->lowres;
- if(get_bits1(&s->gb))
- av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
- if(get_bits1(&s->gb))
- s->pb_frame = 2;
- if(get_bits(&s->gb, 5))
- av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
- if(get_bits(&s->gb, 5) != 1)
- av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
+ if (get_bits(&h->c.gb, 2))
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
+ h->c.loop_filter = get_bits1(&h->c.gb) * !h->c.avctx->lowres;
+ if (get_bits1(&h->c.gb))
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
+ if (get_bits1(&h->c.gb))
+ h->c.pb_frame = 2;
+ if (get_bits(&h->c.gb, 5))
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
+ if (get_bits(&h->c.gb, 5) != 1)
+ av_log(h->c.avctx, AV_LOG_ERROR, "Invalid marker\n");
}
if(format == 6){
- int ar = get_bits(&s->gb, 4);
- skip_bits(&s->gb, 9); // display width
- check_marker(s->avctx, &s->gb, "in dimensions");
- skip_bits(&s->gb, 9); // display height
- if(ar == 15){
- s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
- s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
+ int ar = get_bits(&h->c.gb, 4);
+ skip_bits(&h->c.gb, 9); // display width
+ check_marker(h->c.avctx, &h->c.gb, "in dimensions");
+ skip_bits(&h->c.gb, 9); // display height
+ if (ar == 15) {
+ h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8); // aspect ratio - width
+ h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8); // aspect ratio - height
} else {
- s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
+ h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
}
- if (s->avctx->sample_aspect_ratio.num == 0)
- av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
+ if (h->c.avctx->sample_aspect_ratio.num == 0)
+ av_log(h->c.avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
}
- s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
- skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
+ skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */
- if(s->pb_frame){
- skip_bits(&s->gb, 3); //temporal reference for B-frame
- skip_bits(&s->gb, 2); //dbquant
+ if (h->c.pb_frame) {
+ skip_bits(&h->c.gb, 3); //temporal reference for B-frame
+ skip_bits(&h->c.gb, 2); //dbquant
}
/* PEI */
- if (skip_1stop_8data_bits(&s->gb) < 0)
+ if (skip_1stop_8data_bits(&h->c.gb) < 0)
return AVERROR_INVALIDDATA;
- s->gob_index = H263_GOB_HEIGHT(s->height);
+ h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
- ff_h263_show_pict_info(s, 0);
+ ff_h263_show_pict_info(h, 0);
return 0;
}
@@ -131,7 +131,7 @@ const FFCodec ff_h263i_decoder = {
CODEC_LONG_NAME("Intel H.263"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_H263I,
- .priv_data_size = sizeof(MpegEncContext),
+ .priv_data_size = sizeof(H263DecContext),
.init = ff_h263_decode_init,
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.close = ff_mpv_decode_close,
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index f5001200fe..d37ebaeb0b 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -77,23 +77,22 @@ static const int16_t h263_mb_type_b_map[15]= {
MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT,
};
-void ff_h263_show_pict_info(MpegEncContext *s, int h263_plus)
+void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
{
- if(s->avctx->debug&FF_DEBUG_PICT_INFO){
- av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
- s->qscale, av_get_picture_type_char(s->pict_type),
- s->gb.size_in_bits, 1-s->no_rounding,
- s->obmc ? " AP" : "",
- s->umvplus ? " UMV" : "",
- s->h263_long_vectors ? " LONG" : "",
- h263_plus ? " +" : "",
- s->h263_aic ? " AIC" : "",
- s->alt_inter_vlc ? " AIV" : "",
- s->modified_quant ? " MQ" : "",
- s->loop_filter ? " LOOP" : "",
- s->h263_slice_structured ? " SS" : "",
- s->avctx->framerate.num, s->avctx->framerate.den
- );
+ if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {
+ av_log(h->c.avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
+ h->c.qscale, av_get_picture_type_char(h->c.pict_type),
+ h->c.gb.size_in_bits, 1-h->c.no_rounding,
+ h->c.obmc ? " AP" : "",
+ h->c.umvplus ? " UMV" : "",
+ h->c.h263_long_vectors ? " LONG" : "",
+ h263_plus ? " +" : "",
+ h->c.h263_aic ? " AIC" : "",
+ h->c.alt_inter_vlc ? " AIV" : "",
+ h->c.modified_quant ? " MQ" : "",
+ h->c.loop_filter ? " LOOP" : "",
+ h->c.h263_slice_structured ? " SS" : "",
+ h->c.avctx->framerate.num, h->c.avctx->framerate.den);
}
}
@@ -140,16 +139,16 @@ av_cold void ff_h263_decode_init_vlc(void)
ff_thread_once(&init_static_once, h263_decode_init_vlc);
}
-int ff_h263_decode_mba(MpegEncContext *s)
+int ff_h263_decode_mba(H263DecContext *const h)
{
int i, mb_pos;
for (i = 0; i < 6; i++)
- if (s->mb_num - 1 <= ff_mba_max[i])
+ if (h->c.mb_num - 1 <= ff_mba_max[i])
break;
- mb_pos = get_bits(&s->gb, ff_mba_length[i]);
- s->mb_x = mb_pos % s->mb_width;
- s->mb_y = mb_pos / s->mb_width;
+ mb_pos = get_bits(&h->c.gb, ff_mba_length[i]);
+ h->c.mb_x = mb_pos % h->c.mb_width;
+ h->c.mb_y = mb_pos / h->c.mb_width;
return mb_pos;
}
@@ -158,53 +157,53 @@ int ff_h263_decode_mba(MpegEncContext *s)
* Decode the group of blocks header or slice header.
* @return <0 if an error occurred
*/
-static int h263_decode_gob_header(MpegEncContext *s)
+static int h263_decode_gob_header(H263DecContext *const h)
{
unsigned int val, gob_number;
int left;
/* Check for GOB Start Code */
- val = show_bits(&s->gb, 16);
+ val = show_bits(&h->c.gb, 16);
if(val)
return -1;
/* We have a GBSC probably with GSTUFF */
- skip_bits(&s->gb, 16); /* Drop the zeros */
- left= get_bits_left(&s->gb);
+ skip_bits(&h->c.gb, 16); /* Drop the zeros */
+ left = get_bits_left(&h->c.gb);
left = FFMIN(left, 32);
//MN: we must check the bits left or we might end in an infinite loop (or segfault)
for(;left>13; left--){
- if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
+ if (get_bits1(&h->c.gb)) break; /* Seek the '1' bit */
}
if(left<=13)
return -1;
- if(s->h263_slice_structured){
- if(check_marker(s->avctx, &s->gb, "before MBA")==0)
+ if (h->c.h263_slice_structured) {
+ if (check_marker(h->c.avctx, &h->c.gb, "before MBA")==0)
return -1;
- ff_h263_decode_mba(s);
+ ff_h263_decode_mba(h);
- if(s->mb_num > 1583)
- if(check_marker(s->avctx, &s->gb, "after MBA")==0)
+ if (h->c.mb_num > 1583)
+ if (check_marker(h->c.avctx, &h->c.gb, "after MBA")==0)
return -1;
- s->qscale = get_bits(&s->gb, 5); /* SQUANT */
- if(check_marker(s->avctx, &s->gb, "after SQUANT")==0)
+ h->c.qscale = get_bits(&h->c.gb, 5); /* SQUANT */
+ if (check_marker(h->c.avctx, &h->c.gb, "after SQUANT")==0)
return -1;
- skip_bits(&s->gb, 2); /* GFID */
+ skip_bits(&h->c.gb, 2); /* GFID */
}else{
- gob_number = get_bits(&s->gb, 5); /* GN */
- s->mb_x= 0;
- s->mb_y= s->gob_index* gob_number;
- skip_bits(&s->gb, 2); /* GFID */
- s->qscale = get_bits(&s->gb, 5); /* GQUANT */
+ gob_number = get_bits(&h->c.gb, 5); /* GN */
+ h->c.mb_x = 0;
+ h->c.mb_y = h->c.gob_index* gob_number;
+ skip_bits(&h->c.gb, 2); /* GFID */
+ h->c.qscale = get_bits(&h->c.gb, 5); /* GQUANT */
}
- if(s->mb_y >= s->mb_height)
+ if (h->c.mb_y >= h->c.mb_height)
return -1;
- if(s->qscale==0)
+ if (h->c.qscale==0)
return -1;
return 0;
@@ -214,79 +213,80 @@ static int h263_decode_gob_header(MpegEncContext *s)
* Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
* @return bit position of the resync_marker, or <0 if none was found
*/
-int ff_h263_resync(MpegEncContext *s){
+int ff_h263_resync(H263DecContext *const h)
+{
int left, pos, ret;
/* In MPEG-4 studio mode look for a new slice startcode
* and decode slice header */
- if(s->codec_id==AV_CODEC_ID_MPEG4 && s->studio_profile) {
- align_get_bits(&s->gb);
+ if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) {
+ align_get_bits(&h->c.gb);
- while (get_bits_left(&s->gb) >= 32 && show_bits_long(&s->gb, 32) != SLICE_STARTCODE) {
- get_bits(&s->gb, 8);
+ while (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) != SLICE_STARTCODE) {
+ get_bits(&h->c.gb, 8);
}
- if (get_bits_left(&s->gb) >= 32 && show_bits_long(&s->gb, 32) == SLICE_STARTCODE)
- return get_bits_count(&s->gb);
+ if (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) == SLICE_STARTCODE)
+ return get_bits_count(&h->c.gb);
else
return -1;
}
- if(s->codec_id==AV_CODEC_ID_MPEG4){
- skip_bits1(&s->gb);
- align_get_bits(&s->gb);
+ if (h->c.codec_id==AV_CODEC_ID_MPEG4){
+ skip_bits1(&h->c.gb);
+ align_get_bits(&h->c.gb);
}
- if(show_bits(&s->gb, 16)==0){
- pos= get_bits_count(&s->gb);
- if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
- ret = ff_mpeg4_decode_video_packet_header(s);
+ if (show_bits(&h->c.gb, 16) ==0) {
+ pos = get_bits_count(&h->c.gb);
+ if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)
+ ret = ff_mpeg4_decode_video_packet_header(h);
else
- ret= h263_decode_gob_header(s);
+ ret = h263_decode_gob_header(h);
if(ret>=0)
return pos;
}
//OK, it's not where it is supposed to be ...
- s->gb= s->last_resync_gb;
- align_get_bits(&s->gb);
- left= get_bits_left(&s->gb);
+ h->c.gb = h->c.last_resync_gb;
+ align_get_bits(&h->c.gb);
+ left = get_bits_left(&h->c.gb);
for(;left>16+1+5+5; left-=8){
- if(show_bits(&s->gb, 16)==0){
- GetBitContext bak= s->gb;
+ if (show_bits(&h->c.gb, 16) == 0){
+ GetBitContext bak = h->c.gb;
- pos= get_bits_count(&s->gb);
- if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
- ret = ff_mpeg4_decode_video_packet_header(s);
+ pos = get_bits_count(&h->c.gb);
+ if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)
+ ret = ff_mpeg4_decode_video_packet_header(h);
else
- ret= h263_decode_gob_header(s);
+ ret = h263_decode_gob_header(h);
if(ret>=0)
return pos;
- s->gb= bak;
+ h->c.gb = bak;
}
- skip_bits(&s->gb, 8);
+ skip_bits(&h->c.gb, 8);
}
return -1;
}
-int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
+int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
{
int code, val, sign, shift;
- code = get_vlc2(&s->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
+ code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
if (code == 0)
return pred;
if (code < 0)
return 0xffff;
- sign = get_bits1(&s->gb);
+ sign = get_bits1(&h->c.gb);
shift = f_code - 1;
val = code;
if (shift) {
val = (val - 1) << shift;
- val |= get_bits(&s->gb, shift);
+ val |= get_bits(&h->c.gb, shift);
val++;
}
if (sign)
@@ -294,7 +294,7 @@ int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
val += pred;
/* modulo decoding */
- if (!s->h263_long_vectors) {
+ if (!h->c.h263_long_vectors) {
val = sign_extend(val, 5 + f_code);
} else {
/* horrible H.263 long vector mode */
@@ -309,21 +309,21 @@ int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
/* Decode RVLC of H.263+ UMV */
-static int h263p_decode_umotion(MpegEncContext * s, int pred)
+static int h263p_decode_umotion(H263DecContext *const h, int pred)
{
int code = 0, sign;
- if (get_bits1(&s->gb)) /* Motion difference = 0 */
+ if (get_bits1(&h->c.gb)) /* Motion difference = 0 */
return pred;
- code = 2 + get_bits1(&s->gb);
+ code = 2 + get_bits1(&h->c.gb);
- while (get_bits1(&s->gb))
+ while (get_bits1(&h->c.gb))
{
code <<= 1;
- code += get_bits1(&s->gb);
+ code += get_bits1(&h->c.gb);
if (code >= 32768) {
- avpriv_request_sample(s->avctx, "Huge DMV");
+ avpriv_request_sample(h->c.avctx, "Huge DMV");
return 0xffff;
}
}
@@ -331,7 +331,7 @@ static int h263p_decode_umotion(MpegEncContext * s, int pred)
code >>= 1;
code = (sign) ? (pred - code) : (pred + code);
- ff_tlog(s->avctx,"H.263+ UMV Motion = %d\n", code);
+ ff_tlog(h->c.avctx,"H.263+ UMV Motion = %d\n", code);
return code;
}
@@ -339,82 +339,79 @@ static int h263p_decode_umotion(MpegEncContext * s, int pred)
/**
* read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :)
*/
-static void preview_obmc(MpegEncContext *s){
- GetBitContext gb= s->gb;
+static void preview_obmc(H263DecContext *const h)
+{
+ GetBitContext gb = h->c.gb;
int cbpc, i, pred_x, pred_y, mx, my;
int16_t *mot_val;
- const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
- const int stride= s->b8_stride*2;
+ const int xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride;
+ const int stride = h->c.b8_stride * 2;
for(i=0; i<4; i++)
- s->block_index[i]+= 2;
+ h->c.block_index[i] += 2;
for(i=4; i<6; i++)
- s->block_index[i]+= 1;
- s->mb_x++;
+ h->c.block_index[i] += 1;
+ h->c.mb_x++;
- av_assert2(s->pict_type == AV_PICTURE_TYPE_P);
+ av_assert2(h->c.pict_type == AV_PICTURE_TYPE_P);
do{
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&h->c.gb)) {
/* skip mb */
- mot_val = s->cur_pic.motion_val[0][s->block_index[0]];
+ mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
mot_val[0 ]= mot_val[2 ]=
mot_val[0+stride]= mot_val[2+stride]= 0;
mot_val[1 ]= mot_val[3 ]=
mot_val[1+stride]= mot_val[3+stride]= 0;
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
goto end;
}
- cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
}while(cbpc == 20);
if(cbpc & 4){
- s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
}else{
- get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpc & 8) {
- if(s->modified_quant){
- if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
- else skip_bits(&s->gb, 5);
- }else
- skip_bits(&s->gb, 2);
+ skip_bits(&h->c.gb, h->c.modified_quant ? (get_bits1(&h->c.gb) ? 1 : 5) : 2);
}
if ((cbpc & 16) == 0) {
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
/* 16x16 motion prediction */
- mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- if (s->umvplus)
- mx = h263p_decode_umotion(s, pred_x);
+ mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
+ if (h->c.umvplus)
+ mx = h263p_decode_umotion(h, pred_x);
else
- mx = ff_h263_decode_motion(s, pred_x, 1);
+ mx = ff_h263_decode_motion(h, pred_x, 1);
- if (s->umvplus)
- my = h263p_decode_umotion(s, pred_y);
+ if (h->c.umvplus)
+ my = h263p_decode_umotion(h, pred_y);
else
- my = ff_h263_decode_motion(s, pred_y, 1);
+ my = ff_h263_decode_motion(h, pred_y, 1);
mot_val[0 ]= mot_val[2 ]=
mot_val[0+stride]= mot_val[2+stride]= mx;
mot_val[1 ]= mot_val[3 ]=
mot_val[1+stride]= mot_val[3+stride]= my;
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
for(i=0;i<4;i++) {
- mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
- if (s->umvplus)
- mx = h263p_decode_umotion(s, pred_x);
+ mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
+ if (h->c.umvplus)
+ mx = h263p_decode_umotion(h, pred_x);
else
- mx = ff_h263_decode_motion(s, pred_x, 1);
+ mx = ff_h263_decode_motion(h, pred_x, 1);
- if (s->umvplus)
- my = h263p_decode_umotion(s, pred_y);
+ if (h->c.umvplus)
+ my = h263p_decode_umotion(h, pred_y);
else
- my = ff_h263_decode_motion(s, pred_y, 1);
- if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
+ my = ff_h263_decode_motion(h, pred_y, 1);
+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
mot_val[0] = mx;
mot_val[1] = my;
}
@@ -423,26 +420,27 @@ static void preview_obmc(MpegEncContext *s){
end:
for(i=0; i<4; i++)
- s->block_index[i]-= 2;
+ h->c.block_index[i] -= 2;
for(i=4; i<6; i++)
- s->block_index[i]-= 1;
- s->mb_x--;
+ h->c.block_index[i] -= 1;
+ h->c.mb_x--;
- s->gb= gb;
+ h->c.gb = gb;
}
-static void h263_decode_dquant(MpegEncContext *s){
+static void h263_decode_dquant(H263DecContext *const h)
+{
static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
int qscale;
- if(s->modified_quant){
- if(get_bits1(&s->gb))
- qscale = ff_modified_quant_tab[get_bits1(&s->gb)][s->qscale];
+ if (h->c.modified_quant) {
+ if (get_bits1(&h->c.gb))
+ qscale = ff_modified_quant_tab[get_bits1(&h->c.gb)][h->c.qscale];
else
- qscale = get_bits(&s->gb, 5);
+ qscale = get_bits(&h->c.gb, 5);
}else
- qscale = s->qscale + quant_tab[get_bits(&s->gb, 2)];
- ff_set_qscale(s, qscale);
+ qscale = h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)];
+ ff_set_qscale(&h->c, qscale);
}
static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
@@ -523,52 +521,53 @@ static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
ac_val[8 + i] = block[s->idsp.idct_permutation[i]];
}
-static int h263_decode_block(MpegEncContext * s, int16_t * block,
+static int h263_decode_block(H263DecContext *const h, int16_t block[64],
int n, int coded)
{
int level, i, j, run;
const RLTable *rl = &ff_h263_rl_inter;
const uint8_t *scan_table;
- GetBitContext gb= s->gb;
+ GetBitContext gb = h->c.gb;
- scan_table = s->intra_scantable.permutated;
- if (s->h263_aic && s->mb_intra) {
+ scan_table = h->c.intra_scantable.permutated;
+ if (h->c.h263_aic && h->c.mb_intra) {
i = 0;
if (!coded)
goto not_coded;
rl = &ff_rl_intra_aic;
- if (s->ac_pred) {
- if (s->h263_aic_dir)
- scan_table = s->permutated_intra_v_scantable; /* left */
+ if (h->c.ac_pred) {
+ if (h->c.h263_aic_dir)
+ scan_table = h->c.permutated_intra_v_scantable; /* left */
else
- scan_table = s->permutated_intra_h_scantable; /* top */
+ scan_table = h->c.permutated_intra_h_scantable; /* top */
}
- } else if (s->mb_intra) {
+ } else if (h->c.mb_intra) {
/* DC coef */
- if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) {
- if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {
+ 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) {
int component = (n <= 3 ? 0 : n - 4 + 1);
- level = s->last_dc[component];
- if (s->rv10_first_dc_coded[component]) {
- int diff = ff_rv_decode_dc(s, n);
+ level = h->c.last_dc[component];
+ if (h->c.rv10_first_dc_coded[component]) {
+ int diff = ff_rv_decode_dc(h, n);
if (diff < 0)
return -1;
level += diff;
level = level & 0xff; /* handle wrap round */
- s->last_dc[component] = level;
+ h->c.last_dc[component] = level;
} else {
- s->rv10_first_dc_coded[component] = 1;
+ h->c.rv10_first_dc_coded[component] = 1;
}
} else {
- level = get_bits(&s->gb, 8);
+ level = get_bits(&h->c.gb, 8);
if (level == 255)
level = 128;
}
}else{
- level = get_bits(&s->gb, 8);
+ level = get_bits(&h->c.gb, 8);
if((level&0x7F) == 0){
- av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
- if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
+ level, h->c.mb_x, h->c.mb_y);
+ if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
return -1;
}
if (level == 255)
@@ -580,64 +579,65 @@ static int h263_decode_block(MpegEncContext * s, int16_t * block,
i = 0;
}
if (!coded) {
- s->block_last_index[n] = i - 1;
+ h->c.block_last_index[n] = i - 1;
return 0;
}
retry:
{
- OPEN_READER(re, &s->gb);
+ OPEN_READER(re, &h->c.gb);
i--; // offset by -1 to allow direct indexing of scan_table
for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+ UPDATE_CACHE(re, &h->c.gb);
+ GET_RL_VLC(level, run, re, &h->c.gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
if (run == 66) {
if (level){
- CLOSE_READER(re, &s->gb);
- av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
+ CLOSE_READER(re, &h->c.gb);
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
+ h->c.mb_x, h->c.mb_y);
return -1;
}
/* escape */
- if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
- int is11 = SHOW_UBITS(re, &s->gb, 1);
- SKIP_CACHE(re, &s->gb, 1);
- run = SHOW_UBITS(re, &s->gb, 7) + 1;
+ if (CONFIG_FLV_DECODER && h->c.h263_flv > 1) {
+ int is11 = SHOW_UBITS(re, &h->c.gb, 1);
+ SKIP_CACHE(re, &h->c.gb, 1);
+ run = SHOW_UBITS(re, &h->c.gb, 7) + 1;
if (is11) {
- SKIP_COUNTER(re, &s->gb, 1 + 7);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 11);
- SKIP_COUNTER(re, &s->gb, 11);
+ SKIP_COUNTER(re, &h->c.gb, 1 + 7);
+ UPDATE_CACHE(re, &h->c.gb);
+ level = SHOW_SBITS(re, &h->c.gb, 11);
+ SKIP_COUNTER(re, &h->c.gb, 11);
} else {
- SKIP_CACHE(re, &s->gb, 7);
- level = SHOW_SBITS(re, &s->gb, 7);
- SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);
+ SKIP_CACHE(re, &h->c.gb, 7);
+ level = SHOW_SBITS(re, &h->c.gb, 7);
+ SKIP_COUNTER(re, &h->c.gb, 1 + 7 + 7);
}
} else {
- run = SHOW_UBITS(re, &s->gb, 7) + 1;
- SKIP_CACHE(re, &s->gb, 7);
- level = (int8_t)SHOW_UBITS(re, &s->gb, 8);
- SKIP_COUNTER(re, &s->gb, 7 + 8);
+ run = SHOW_UBITS(re, &h->c.gb, 7) + 1;
+ SKIP_CACHE(re, &h->c.gb, 7);
+ level = (int8_t)SHOW_UBITS(re, &h->c.gb, 8);
+ SKIP_COUNTER(re, &h->c.gb, 7 + 8);
if(level == -128){
- UPDATE_CACHE(re, &s->gb);
- if (s->codec_id == AV_CODEC_ID_RV10) {
+ UPDATE_CACHE(re, &h->c.gb);
+ if (h->c.codec_id == AV_CODEC_ID_RV10) {
/* XXX: should patch encoder too */
- level = SHOW_SBITS(re, &s->gb, 12);
- SKIP_COUNTER(re, &s->gb, 12);
+ level = SHOW_SBITS(re, &h->c.gb, 12);
+ SKIP_COUNTER(re, &h->c.gb, 12);
}else{
- level = SHOW_UBITS(re, &s->gb, 5);
- SKIP_CACHE(re, &s->gb, 5);
- level |= SHOW_SBITS(re, &s->gb, 6) * (1<<5);
- SKIP_COUNTER(re, &s->gb, 5 + 6);
+ level = SHOW_UBITS(re, &h->c.gb, 5);
+ SKIP_CACHE(re, &h->c.gb, 5);
+ level |= SHOW_SBITS(re, &h->c.gb, 6) * (1<<5);
+ SKIP_COUNTER(re, &h->c.gb, 5 + 6);
}
}
}
} else {
- if (SHOW_UBITS(re, &s->gb, 1))
+ if (SHOW_UBITS(re, &h->c.gb, 1))
level = -level;
- SKIP_COUNTER(re, &s->gb, 1);
+ SKIP_COUNTER(re, &h->c.gb, 1);
}
i += run;
if (i >= 64){
- CLOSE_READER(re, &s->gb);
+ CLOSE_READER(re, &h->c.gb);
// redo update without last flag, revert -1 offset
i = i - run + ((run-1)&63) + 1;
if (i < 64) {
@@ -645,48 +645,49 @@ retry:
block[scan_table[i]] = level;
break;
}
- if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
+ if(h->c.alt_inter_vlc && rl == &ff_h263_rl_inter && !h->c.mb_intra){
//Looks like a hack but no, it's the way it is supposed to work ...
rl = &ff_rl_intra_aic;
i = 0;
- s->gb= gb;
- s->bdsp.clear_block(block);
+ h->c.gb = gb;
+ h->c.bdsp.clear_block(block);
goto retry;
}
- av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
+ av_log(h->c.avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n",
+ h->c.mb_x, h->c.mb_y, h->c.mb_intra);
return -1;
}
j = scan_table[i];
block[j] = level;
}
}
- if (s->mb_intra && s->h263_aic) {
+ if (h->c.mb_intra && h->c.h263_aic) {
not_coded:
- h263_pred_acdc(s, block, n);
+ h263_pred_acdc(&h->c, block, n);
}
- s->block_last_index[n] = i;
+ h->c.block_last_index[n] = i;
return 0;
}
-static int h263_skip_b_part(MpegEncContext *s, int cbp)
+static int h263_skip_b_part(H263DecContext *const h, int cbp)
{
LOCAL_ALIGNED_32(int16_t, dblock, [64]);
int i, mbi;
int bli[6];
- /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
+ /* we have to set h->c.mb_intra to zero to decode B-part of PB-frame correctly
* but real value should be restored in order to be used later (in OBMC condition)
*/
- mbi = s->mb_intra;
- memcpy(bli, s->block_last_index, sizeof(bli));
- s->mb_intra = 0;
+ mbi = h->c.mb_intra;
+ memcpy(bli, h->c.block_last_index, sizeof(bli));
+ h->c.mb_intra = 0;
for (i = 0; i < 6; i++) {
- if (h263_decode_block(s, dblock, i, cbp&32) < 0)
+ if (h263_decode_block(h, dblock, i, cbp&32) < 0)
return -1;
cbp+=cbp;
}
- s->mb_intra = mbi;
- memcpy(s->block_last_index, bli, sizeof(bli));
+ h->c.mb_intra = mbi;
+ memcpy(h->c.block_last_index, bli, sizeof(bli));
return 0;
}
@@ -775,119 +776,121 @@ static int set_direct_mv(MpegEncContext *s)
}
}
-int ff_h263_decode_mb(MpegEncContext *s,
- int16_t block[6][64])
+int ff_h263_decode_mb(H263DecContext *const h, int16_t block[6][64])
{
int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
int16_t *mot_val;
- const int xy= s->mb_x + s->mb_y * s->mb_stride;
+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
int cbpb = 0, pb_mv_count = 0;
- av_assert2(!s->h263_pred);
+ av_assert2(!h->c.h263_pred);
- if (s->pict_type == AV_PICTURE_TYPE_P) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_P) {
do{
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&h->c.gb)) {
/* skip mb */
- s->mb_intra = 0;
+ h->c.mb_intra = 0;
for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mb_skipped = !(s->obmc | s->loop_filter);
+ h->c.block_last_index[i] = -1;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ h->c.mv[0][0][0] = 0;
+ h->c.mv[0][0][1] = 0;
+ h->c.mb_skipped = !(h->c.obmc | h->c.loop_filter);
goto end;
}
- cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0){
- av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n",
+ h->c.mb_x, h->c.mb_y);
return SLICE_ERROR;
}
}while(cbpc == 20);
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
dquant = cbpc & 8;
- s->mb_intra = ((cbpc & 4) != 0);
- if (s->mb_intra) goto intra;
+ h->c.mb_intra = ((cbpc & 4) != 0);
+ if (h->c.mb_intra)
+ goto intra;
- if(s->pb_frame && get_bits1(&s->gb))
- pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ if(h->c.pb_frame && get_bits1(&h->c.gb))
+ pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb);
+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n",
+ h->c.mb_x, h->c.mb_y);
return SLICE_ERROR;
}
- if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
+ if (!h->c.alt_inter_vlc|| (cbpc & 3)!=3)
cbpy ^= 0xF;
cbp = (cbpc & 3) | (cbpy << 2);
if (dquant) {
- h263_decode_dquant(s);
+ h263_decode_dquant(h);
}
- s->mv_dir = MV_DIR_FORWARD;
+ h->c.mv_dir = MV_DIR_FORWARD;
if ((cbpc & 16) == 0) {
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
/* 16x16 motion prediction */
- s->mv_type = MV_TYPE_16X16;
- ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- if (s->umvplus)
- mx = h263p_decode_umotion(s, pred_x);
+ h->c.mv_type = MV_TYPE_16X16;
+ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
+ if (h->c.umvplus)
+ mx = h263p_decode_umotion(h, pred_x);
else
- mx = ff_h263_decode_motion(s, pred_x, 1);
+ mx = ff_h263_decode_motion(h, pred_x, 1);
if (mx >= 0xffff)
return SLICE_ERROR;
- if (s->umvplus)
- my = h263p_decode_umotion(s, pred_y);
+ if (h->c.umvplus)
+ my = h263p_decode_umotion(h, pred_y);
else
- my = ff_h263_decode_motion(s, pred_y, 1);
+ my = ff_h263_decode_motion(h, pred_y, 1);
if (my >= 0xffff)
return SLICE_ERROR;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
+ h->c.mv[0][0][0] = mx;
+ h->c.mv[0][0][1] = my;
- if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
- s->mv_type = MV_TYPE_8X8;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
+ h->c.mv_type = MV_TYPE_8X8;
for(i=0;i<4;i++) {
- mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
- if (s->umvplus)
- mx = h263p_decode_umotion(s, pred_x);
+ mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
+ if (h->c.umvplus)
+ mx = h263p_decode_umotion(h, pred_x);
else
- mx = ff_h263_decode_motion(s, pred_x, 1);
+ mx = ff_h263_decode_motion(h, pred_x, 1);
if (mx >= 0xffff)
return SLICE_ERROR;
- if (s->umvplus)
- my = h263p_decode_umotion(s, pred_y);
+ if (h->c.umvplus)
+ my = h263p_decode_umotion(h, pred_y);
else
- my = ff_h263_decode_motion(s, pred_y, 1);
+ my = ff_h263_decode_motion(h, pred_y, 1);
if (my >= 0xffff)
return SLICE_ERROR;
- s->mv[0][i][0] = mx;
- s->mv[0][i][1] = my;
- if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
+ h->c.mv[0][i][0] = mx;
+ h->c.mv[0][i][1] = my;
+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
mot_val[0] = mx;
mot_val[1] = my;
}
}
- } else if(s->pict_type==AV_PICTURE_TYPE_B) {
+ } else if (h->c.pict_type==AV_PICTURE_TYPE_B) {
int mb_type;
- const int stride= s->b8_stride;
- int16_t *mot_val0 = s->cur_pic.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
- int16_t *mot_val1 = s->cur_pic.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
-// const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
+ const int stride = h->c.b8_stride;
+ int16_t *mot_val0 = h->c.cur_pic.motion_val[0][2 * (h->c.mb_x + h->c.mb_y * stride)];
+ int16_t *mot_val1 = h->c.cur_pic.motion_val[1][2 * (h->c.mb_x + h->c.mb_y * stride)];
+// const int mv_xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride;
//FIXME ugly
mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
@@ -896,176 +899,181 @@ int ff_h263_decode_mb(MpegEncContext *s,
mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
do{
- mb_type = get_vlc2(&s->gb, h263_mbtype_b_vlc,
+ mb_type = get_vlc2(&h->c.gb, h263_mbtype_b_vlc,
H263_MBTYPE_B_VLC_BITS, 2);
if (mb_type < 0){
- av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n",
+ h->c.mb_x, h->c.mb_y);
return SLICE_ERROR;
}
}while(!mb_type);
- s->mb_intra = IS_INTRA(mb_type);
+ h->c.mb_intra = IS_INTRA(mb_type);
if(HAS_CBP(mb_type)){
- s->bdsp.clear_blocks(s->block[0]);
- cbpc = get_vlc2(&s->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
- if(s->mb_intra){
+ h->c.bdsp.clear_blocks(h->c.block[0]);
+ cbpc = get_vlc2(&h->c.gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
+ if (h->c.mb_intra) {
dquant = IS_QUANT(mb_type);
goto intra;
}
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0){
- av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n",
+ h->c.mb_x, h->c.mb_y);
return SLICE_ERROR;
}
- if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
+ if (!h->c.alt_inter_vlc || (cbpc & 3)!=3)
cbpy ^= 0xF;
cbp = (cbpc & 3) | (cbpy << 2);
}else
cbp=0;
- av_assert2(!s->mb_intra);
+ av_assert2(!h->c.mb_intra);
if(IS_QUANT(mb_type)){
- h263_decode_dquant(s);
+ h263_decode_dquant(h);
}
if(IS_DIRECT(mb_type)){
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- mb_type |= set_direct_mv(s);
+ h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
+ mb_type |= set_direct_mv(&h->c);
}else{
- s->mv_dir = 0;
- s->mv_type= MV_TYPE_16X16;
+ h->c.mv_dir = 0;
+ h->c.mv_type = MV_TYPE_16X16;
//FIXME UMV
if (HAS_FORWARD_MV(mb_type)) {
- int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- s->mv_dir = MV_DIR_FORWARD;
+ int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
+ h->c.mv_dir = MV_DIR_FORWARD;
- if (s->umvplus)
- mx = h263p_decode_umotion(s, pred_x);
+ if (h->c.umvplus)
+ mx = h263p_decode_umotion(h, pred_x);
else
- mx = ff_h263_decode_motion(s, pred_x, 1);
+ mx = ff_h263_decode_motion(h, pred_x, 1);
if (mx >= 0xffff)
return SLICE_ERROR;
- if (s->umvplus)
- my = h263p_decode_umotion(s, pred_y);
+ if (h->c.umvplus)
+ my = h263p_decode_umotion(h, pred_y);
else
- my = ff_h263_decode_motion(s, pred_y, 1);
+ my = ff_h263_decode_motion(h, pred_y, 1);
if (my >= 0xffff)
return SLICE_ERROR;
- if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
+ h->c.mv[0][0][0] = mx;
+ h->c.mv[0][0][1] = my;
mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
}
if (HAS_BACKWARD_MV(mb_type)) {
- int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &pred_x, &pred_y);
- s->mv_dir |= MV_DIR_BACKWARD;
+ int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 1, &pred_x, &pred_y);
+ h->c.mv_dir |= MV_DIR_BACKWARD;
- if (s->umvplus)
- mx = h263p_decode_umotion(s, pred_x);
+ if (h->c.umvplus)
+ mx = h263p_decode_umotion(h, pred_x);
else
- mx = ff_h263_decode_motion(s, pred_x, 1);
+ mx = ff_h263_decode_motion(h, pred_x, 1);
if (mx >= 0xffff)
return SLICE_ERROR;
- if (s->umvplus)
- my = h263p_decode_umotion(s, pred_y);
+ if (h->c.umvplus)
+ my = h263p_decode_umotion(h, pred_y);
else
- my = ff_h263_decode_motion(s, pred_y, 1);
+ my = ff_h263_decode_motion(h, pred_y, 1);
if (my >= 0xffff)
return SLICE_ERROR;
- if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
- s->mv[1][0][0] = mx;
- s->mv[1][0][1] = my;
+ h->c.mv[1][0][0] = mx;
+ h->c.mv[1][0][1] = my;
mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
}
}
- s->cur_pic.mb_type[xy] = mb_type;
+ h->c.cur_pic.mb_type[xy] = mb_type;
} else { /* I-Frame */
do{
- cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0){
- av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n",
+ h->c.mb_x, h->c.mb_y);
return SLICE_ERROR;
}
}while(cbpc == 8);
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
dquant = cbpc & 4;
- s->mb_intra = 1;
+ h->c.mb_intra = 1;
intra:
- s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
- if (s->h263_aic) {
- s->ac_pred = get_bits1(&s->gb);
- if(s->ac_pred){
- s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
+ if (h->c.h263_aic) {
+ h->c.ac_pred = get_bits1(&h->c.gb);
+ if (h->c.ac_pred) {
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
- s->h263_aic_dir = get_bits1(&s->gb);
+ h->c.h263_aic_dir = get_bits1(&h->c.gb);
}
}else
- s->ac_pred = 0;
+ h->c.ac_pred = 0;
- if(s->pb_frame && get_bits1(&s->gb))
- pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ if (h->c.pb_frame && get_bits1(&h->c.gb))
+ pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb);
+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if(cbpy<0){
- av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",
+ h->c.mb_x, h->c.mb_y);
return SLICE_ERROR;
}
cbp = (cbpc & 3) | (cbpy << 2);
if (dquant) {
- h263_decode_dquant(s);
+ h263_decode_dquant(h);
}
- pb_mv_count += !!s->pb_frame;
+ pb_mv_count += !!h->c.pb_frame;
}
while(pb_mv_count--){
- ff_h263_decode_motion(s, 0, 1);
- ff_h263_decode_motion(s, 0, 1);
+ ff_h263_decode_motion(h, 0, 1);
+ ff_h263_decode_motion(h, 0, 1);
}
/* decode each block */
for (i = 0; i < 6; i++) {
- if (h263_decode_block(s, block[i], i, cbp&32) < 0)
+ if (h263_decode_block(h, block[i], i, cbp&32) < 0)
return -1;
cbp+=cbp;
}
- if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0)
+ if (h->c.pb_frame && h263_skip_b_part(h, cbpb) < 0)
return -1;
- if(s->obmc && !s->mb_intra){
- if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
- preview_obmc(s);
+ if (h->c.obmc && !h->c.mb_intra) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_P &&
+ h->c.mb_x + 1 < h->c.mb_width && h->c.mb_num_left != 1)
+ preview_obmc(h);
}
end:
- if (get_bits_left(&s->gb) < 0)
+ if (get_bits_left(&h->c.gb) < 0)
return AVERROR_INVALIDDATA;
/* per-MB end of slice check */
{
- int v= show_bits(&s->gb, 16);
+ int v = show_bits(&h->c.gb, 16);
- if (get_bits_left(&s->gb) < 16) {
- v >>= 16 - get_bits_left(&s->gb);
+ if (get_bits_left(&h->c.gb) < 16) {
+ v >>= 16 - get_bits_left(&h->c.gb);
}
if(v==0)
@@ -1076,51 +1084,50 @@ end:
}
/* Most is hardcoded; should extend to handle all H.263 streams. */
-int ff_h263_decode_picture_header(MpegEncContext *s)
+int ff_h263_decode_picture_header(H263DecContext *const h)
{
- int format, width, height, i, ret;
- uint32_t startcode;
+ int width, height, i, ret;
int h263_plus;
- align_get_bits(&s->gb);
+ align_get_bits(&h->c.gb);
- if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_num == 0) {
- av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
+ if (show_bits(&h->c.gb, 2) == 2 && h->c.avctx->frame_num == 0) {
+ av_log(h->c.avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
}
- startcode= get_bits(&s->gb, 22-8);
+ uint32_t startcode = get_bits(&h->c.gb, 22-8);
- for(i= get_bits_left(&s->gb); i>24; i-=8) {
- startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
+ for (i = get_bits_left(&h->c.gb); i>24; i -= 8) {
+ startcode = ((startcode << 8) | get_bits(&h->c.gb, 8)) & 0x003FFFFF;
if(startcode == 0x20)
break;
}
if (startcode != 0x20) {
- av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
return -1;
}
/* temporal reference */
- i = get_bits(&s->gb, 8); /* picture timestamp */
+ i = get_bits(&h->c.gb, 8); /* picture timestamp */
- i -= (i - (s->picture_number & 0xFF) + 128) & ~0xFF;
+ i -= (i - (h->c.picture_number & 0xFF) + 128) & ~0xFF;
- s->picture_number= (s->picture_number&~0xFF) + i;
+ h->c.picture_number = (h->c.picture_number&~0xFF) + i;
/* PTYPE starts here */
- if (check_marker(s->avctx, &s->gb, "in PTYPE") != 1) {
+ if (check_marker(h->c.avctx, &h->c.gb, "in PTYPE") != 1) {
return -1;
}
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
return -1; /* H.263 id */
}
- skip_bits1(&s->gb); /* split screen off */
- skip_bits1(&s->gb); /* camera off */
- skip_bits1(&s->gb); /* freeze picture release off */
+ skip_bits1(&h->c.gb); /* split screen off */
+ skip_bits1(&h->c.gb); /* camera off */
+ skip_bits1(&h->c.gb); /* freeze picture release off */
- format = get_bits(&s->gb, 3);
+ int format = get_bits(&h->c.gb, 3);
/*
0 forbidden
1 sub-QCIF
@@ -1136,88 +1143,88 @@ int ff_h263_decode_picture_header(MpegEncContext *s)
if (!width)
return -1;
- s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb);
- s->h263_long_vectors = get_bits1(&s->gb);
+ h->c.h263_long_vectors = get_bits1(&h->c.gb);
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
return -1; /* SAC: off */
}
- s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
+ h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */
- s->pb_frame = get_bits1(&s->gb);
- s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
- skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
+ h->c.pb_frame = get_bits1(&h->c.gb);
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
+ skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */
- s->width = width;
- s->height = height;
- s->avctx->sample_aspect_ratio= (AVRational){12,11};
- s->avctx->framerate = (AVRational){ 30000, 1001 };
+ h->c.width = width;
+ h->c.height = height;
+ h->c.avctx->sample_aspect_ratio= (AVRational){12,11};
+ h->c.avctx->framerate = (AVRational){ 30000, 1001 };
} else {
int ufep;
/* H.263v2 */
h263_plus = 1;
- ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
+ ufep = get_bits(&h->c.gb, 3); /* Update Full Extended PTYPE */
/* ufep other than 0 and 1 are reserved */
if (ufep == 1) {
/* OPPTYPE */
- format = get_bits(&s->gb, 3);
- ff_dlog(s->avctx, "ufep=1, format: %d\n", format);
- s->custom_pcf= get_bits1(&s->gb);
- s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
+ format = get_bits(&h->c.gb, 3);
+ ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);
+ h->c.custom_pcf = get_bits1(&h->c.gb);
+ h->c.umvplus = get_bits1(&h->c.gb); /* Unrestricted Motion Vector */
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
}
- s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
- s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
- s->loop_filter= get_bits1(&s->gb);
- if(s->avctx->lowres)
- s->loop_filter = 0;
-
- s->h263_slice_structured= get_bits1(&s->gb);
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
+ h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */
+ h->c.h263_aic = get_bits1(&h->c.gb); /* Advanced Intra Coding (AIC) */
+ h->c.loop_filter = get_bits1(&h->c.gb);
+ if (h->c.avctx->lowres)
+ h->c.loop_filter = 0;
+
+ h->c.h263_slice_structured= get_bits1(&h->c.gb);
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
}
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
}
- s->alt_inter_vlc= get_bits1(&s->gb);
- s->modified_quant= get_bits1(&s->gb);
- if(s->modified_quant)
- s->chroma_qscale_table= ff_h263_chroma_qscale_table;
+ h->c.alt_inter_vlc = get_bits1(&h->c.gb);
+ h->c.modified_quant = get_bits1(&h->c.gb);
+ if (h->c.modified_quant)
+ h->c.chroma_qscale_table= ff_h263_chroma_qscale_table;
- skip_bits(&s->gb, 1); /* Prevent start code emulation */
+ skip_bits(&h->c.gb, 1); /* Prevent start code emulation */
- skip_bits(&s->gb, 3); /* Reserved */
+ skip_bits(&h->c.gb, 3); /* Reserved */
} else if (ufep != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
return -1;
}
/* MPPTYPE */
- s->pict_type = get_bits(&s->gb, 3);
- switch(s->pict_type){
- case 0: s->pict_type= AV_PICTURE_TYPE_I;break;
- case 1: s->pict_type= AV_PICTURE_TYPE_P;break;
- case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;
- case 3: s->pict_type= AV_PICTURE_TYPE_B;break;
- case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO
+ h->c.pict_type = get_bits(&h->c.gb, 3);
+ switch (h->c.pict_type) {
+ case 0: h->c.pict_type = AV_PICTURE_TYPE_I; 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 3: h->c.pict_type = AV_PICTURE_TYPE_B; break;
+ case 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO
default:
return -1;
}
- skip_bits(&s->gb, 2);
- s->no_rounding = get_bits1(&s->gb);
- skip_bits(&s->gb, 4);
+ skip_bits(&h->c.gb, 2);
+ h->c.no_rounding = get_bits1(&h->c.gb);
+ skip_bits(&h->c.gb, 4);
/* Get the picture dimensions */
if (ufep) {
if (format == 6) {
/* Custom Picture Format (CPFMT) */
- int aspect_ratio_info = get_bits(&s->gb, 4);
- ff_dlog(s->avctx, "aspect: %d\n", aspect_ratio_info);
+ int aspect_ratio_info = get_bits(&h->c.gb, 4);
+ ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info);
/* aspect ratios:
0 - forbidden
1 - 1:1
@@ -1227,153 +1234,151 @@ int ff_h263_decode_picture_header(MpegEncContext *s)
5 - 40:33 (525-type 16:9)
6-14 - reserved
*/
- width = (get_bits(&s->gb, 9) + 1) * 4;
- check_marker(s->avctx, &s->gb, "in dimensions");
- height = get_bits(&s->gb, 9) * 4;
- ff_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
+ width = (get_bits(&h->c.gb, 9) + 1) * 4;
+ check_marker(h->c.avctx, &h->c.gb, "in dimensions");
+ height = get_bits(&h->c.gb, 9) * 4;
+ ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
/* expected dimensions */
- s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
- s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);
+ h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8);
+ h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8);
}else{
- s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
+ h->c.avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
}
} else {
width = ff_h263_format[format][0];
height = ff_h263_format[format][1];
- s->avctx->sample_aspect_ratio= (AVRational){12,11};
+ h->c.avctx->sample_aspect_ratio = (AVRational){12,11};
}
- s->avctx->sample_aspect_ratio.den <<= s->ehc_mode;
+ h->c.avctx->sample_aspect_ratio.den <<= h->c.ehc_mode;
if ((width == 0) || (height == 0))
return -1;
- s->width = width;
- s->height = height;
-
- if(s->custom_pcf){
- int gcd;
- s->avctx->framerate.num = 1800000;
- s->avctx->framerate.den = 1000 + get_bits1(&s->gb);
- s->avctx->framerate.den *= get_bits(&s->gb, 7);
- if(s->avctx->framerate.den == 0){
- av_log(s->avctx, AV_LOG_ERROR, "zero framerate\n");
+ h->c.width = width;
+ h->c.height = height;
+
+ if (h->c.custom_pcf) {
+ h->c.avctx->framerate.num = 1800000;
+ h->c.avctx->framerate.den = 1000 + get_bits1(&h->c.gb);
+ h->c.avctx->framerate.den *= get_bits(&h->c.gb, 7);
+ if (h->c.avctx->framerate.den == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n");
return -1;
}
- gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num);
- s->avctx->framerate.den /= gcd;
- s->avctx->framerate.num /= gcd;
+ int gcd = av_gcd(h->c.avctx->framerate.den, h->c.avctx->framerate.num);
+ h->c.avctx->framerate.den /= gcd;
+ h->c.avctx->framerate.num /= gcd;
}else{
- s->avctx->framerate = (AVRational){ 30000, 1001 };
+ h->c.avctx->framerate = (AVRational){ 30000, 1001 };
}
}
- if(s->custom_pcf){
- skip_bits(&s->gb, 2); //extended Temporal reference
- }
+ if (h->c.custom_pcf)
+ skip_bits(&h->c.gb, 2); //extended Temporal reference
if (ufep) {
- if (s->umvplus) {
- if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
- skip_bits1(&s->gb);
+ if (h->c.umvplus) {
+ if(get_bits1(&h->c.gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
+ skip_bits1(&h->c.gb);
}
- if(s->h263_slice_structured){
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
+ if (h->c.h263_slice_structured) {
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
}
- if (get_bits1(&s->gb) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
+ if (get_bits1(&h->c.gb) != 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "unordered slices not supported\n");
}
}
- if (s->pict_type == AV_PICTURE_TYPE_B) {
- skip_bits(&s->gb, 4); //ELNUM
+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
+ skip_bits(&h->c.gb, 4); //ELNUM
if (ufep == 1) {
- skip_bits(&s->gb, 4); // RLNUM
+ skip_bits(&h->c.gb, 4); // RLNUM
}
}
}
- s->qscale = get_bits(&s->gb, 5);
+ h->c.qscale = get_bits(&h->c.gb, 5);
}
- ret = av_image_check_size(s->width, s->height, 0, s->avctx);
+ ret = av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx);
if (ret < 0)
return ret;
- if (!(s->avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
- if ((s->width * s->height / 256 / 8) > get_bits_left(&s->gb))
+ if (!(h->c.avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
+ if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->c.gb))
return AVERROR_INVALIDDATA;
}
- s->mb_width = (s->width + 15) / 16;
- s->mb_height = (s->height + 15) / 16;
- s->mb_num = s->mb_width * s->mb_height;
+ h->c.mb_width = (h->c.width + 15U) / 16;
+ h->c.mb_height = (h->c.height + 15U) / 16;
+ h->c.mb_num = h->c.mb_width * h->c.mb_height;
- s->gob_index = H263_GOB_HEIGHT(s->height);
+ h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
- if (s->pb_frame) {
- skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
- if (s->custom_pcf)
- skip_bits(&s->gb, 2); //extended Temporal reference
- skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
+ if (h->c.pb_frame) {
+ skip_bits(&h->c.gb, 3); /* Temporal reference for B-pictures */
+ if (h->c.custom_pcf)
+ skip_bits(&h->c.gb, 2); //extended Temporal reference
+ skip_bits(&h->c.gb, 2); /* Quantization information for B-pictures */
}
- if (s->pict_type!=AV_PICTURE_TYPE_B) {
- s->time = s->picture_number;
- s->pp_time = s->time - s->last_non_b_time;
- s->last_non_b_time = s->time;
+ if (h->c.pict_type!=AV_PICTURE_TYPE_B) {
+ h->c.time = h->c.picture_number;
+ h->c.pp_time = h->c.time - h->c.last_non_b_time;
+ h->c.last_non_b_time = h->c.time;
}else{
- s->time = s->picture_number;
- s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
- if (s->pp_time <=s->pb_time ||
- s->pp_time <= s->pp_time - s->pb_time ||
- s->pp_time <= 0){
- s->pp_time = 2;
- s->pb_time = 1;
+ h->c.time = h->c.picture_number;
+ h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
+ if (h->c.pp_time <= h->c.pb_time ||
+ h->c.pp_time <= h->c.pp_time - h->c.pb_time ||
+ h->c.pp_time <= 0) {
+ h->c.pp_time = 2;
+ h->c.pb_time = 1;
}
- ff_mpeg4_init_direct_mv(s);
+ ff_mpeg4_init_direct_mv(&h->c);
}
/* PEI */
- if (skip_1stop_8data_bits(&s->gb) < 0)
+ if (skip_1stop_8data_bits(&h->c.gb) < 0)
return AVERROR_INVALIDDATA;
- if(s->h263_slice_structured){
- if (check_marker(s->avctx, &s->gb, "SEPB1") != 1) {
+ if (h->c.h263_slice_structured) {
+ if (check_marker(h->c.avctx, &h->c.gb, "SEPB1") != 1) {
return -1;
}
- ff_h263_decode_mba(s);
+ ff_h263_decode_mba(h);
- if (check_marker(s->avctx, &s->gb, "SEPB2") != 1) {
+ if (check_marker(h->c.avctx, &h->c.gb, "SEPB2") != 1) {
return -1;
}
}
- if (s->pict_type == AV_PICTURE_TYPE_B)
- s->low_delay = 0;
+ if (h->c.pict_type == AV_PICTURE_TYPE_B)
+ h->c.low_delay = 0;
- if(s->h263_aic){
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_aic_dc_scale_table;
+ if (h->c.h263_aic) {
+ h->c.y_dc_scale_table =
+ h->c.c_dc_scale_table = ff_aic_dc_scale_table;
}else{
- s->y_dc_scale_table=
- s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
+ h->c.y_dc_scale_table =
+ h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table;
}
- ff_h263_show_pict_info(s, h263_plus);
+ ff_h263_show_pict_info(h, h263_plus);
- if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){
+ if (h->c.pict_type == AV_PICTURE_TYPE_I && h->c.codec_tag == AV_RL32("ZYGO") && get_bits_left(&h->c.gb) >= 85 + 13*3*16 + 50){
int i,j;
- for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb));
+ av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
for(i=0; i<13; i++){
for(j=0; j<3; j++){
- int v= get_bits(&s->gb, 8);
- v |= get_sbits(&s->gb, 8) * (1 << 8);
- av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
+ int v= get_bits(&h->c.gb, 8);
+ v |= get_sbits(&h->c.gb, 8) * (1 << 8);
+ av_log(h->c.avctx, AV_LOG_DEBUG, " %5d", v);
}
- av_log(s->avctx, AV_LOG_DEBUG, "\n");
+ av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
}
- for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
+ for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb));
}
return 0;
diff --git a/libavcodec/mpeg4video_parser.c b/libavcodec/mpeg4video_parser.c
index de92f1b1dc..a2a22234f2 100644
--- a/libavcodec/mpeg4video_parser.c
+++ b/libavcodec/mpeg4video_parser.c
@@ -84,7 +84,7 @@ static int mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx,
{
struct Mp4vParseContext *pc = s1->priv_data;
Mpeg4DecContext *dec_ctx = &pc->dec_ctx;
- MpegEncContext *s = &dec_ctx->m;
+ MPVContext *const s = &dec_ctx->h.c;
GetBitContext gb1, *gb = &gb1;
int ret;
@@ -124,7 +124,7 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s)
pc->first_picture = 1;
pc->dec_ctx.quant_precision = 5;
- pc->dec_ctx.m.slice_context_count = 1;
+ pc->dec_ctx.h.c.slice_context_count = 1;
pc->dec_ctx.showed_packed_warning = 1;
return 0;
}
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 677b372fee..e3503b1aca 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -81,6 +81,12 @@ static const int16_t mb_type_b_map[4] = {
MB_TYPE_FORWARD_MV | MB_TYPE_16x16,
};
+static inline Mpeg4DecContext *h263_to_mpeg4(H263DecContext *h)
+{
+ av_assert2(h->c.codec_id == AV_CODEC_ID_MPEG4 && h->c.avctx->priv_data == h);
+ return (Mpeg4DecContext*)h;
+}
+
static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
uint8_t *const *ref_picture)
@@ -319,55 +325,55 @@ void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb
* @param n block index (0-3 are luma, 4-5 are chroma)
* @param dir the ac prediction direction
*/
-void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
+void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, int dir)
{
int i;
int16_t *ac_val, *ac_val1;
- int8_t *const qscale_table = s->cur_pic.qscale_table;
+ int8_t *const qscale_table = h->c.cur_pic.qscale_table;
/* find prediction */
- ac_val = &s->ac_val[0][0] + s->block_index[n] * 16;
+ ac_val = &h->c.ac_val[0][0] + h->c.block_index[n] * 16;
ac_val1 = ac_val;
- if (s->ac_pred) {
+ if (h->c.ac_pred) {
if (dir == 0) {
- const int xy = s->mb_x - 1 + s->mb_y * s->mb_stride;
+ const int xy = h->c.mb_x - 1 + h->c.mb_y * h->c.mb_stride;
/* left prediction */
ac_val -= 16;
- if (s->mb_x == 0 || s->qscale == qscale_table[xy] ||
+ if (h->c.mb_x == 0 || h->c.qscale == qscale_table[xy] ||
n == 1 || n == 3) {
/* same qscale */
for (i = 1; i < 8; i++)
- block[s->idsp.idct_permutation[i << 3]] += ac_val[i];
+ block[h->c.idsp.idct_permutation[i << 3]] += ac_val[i];
} else {
/* different qscale, we must rescale */
for (i = 1; i < 8; i++)
- block[s->idsp.idct_permutation[i << 3]] += ROUNDED_DIV(ac_val[i] * qscale_table[xy], s->qscale);
+ block[h->c.idsp.idct_permutation[i << 3]] += ROUNDED_DIV(ac_val[i] * qscale_table[xy], h->c.qscale);
}
} else {
- const int xy = s->mb_x + s->mb_y * s->mb_stride - s->mb_stride;
+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride - h->c.mb_stride;
/* top prediction */
- ac_val -= 16 * s->block_wrap[n];
+ ac_val -= 16 * h->c.block_wrap[n];
- if (s->mb_y == 0 || s->qscale == qscale_table[xy] ||
+ if (h->c.mb_y == 0 || h->c.qscale == qscale_table[xy] ||
n == 2 || n == 3) {
/* same qscale */
for (i = 1; i < 8; i++)
- block[s->idsp.idct_permutation[i]] += ac_val[i + 8];
+ block[h->c.idsp.idct_permutation[i]] += ac_val[i + 8];
} else {
/* different qscale, we must rescale */
for (i = 1; i < 8; i++)
- block[s->idsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], s->qscale);
+ block[h->c.idsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], h->c.qscale);
}
}
}
/* left copy */
for (i = 1; i < 8; i++)
- ac_val1[i] = block[s->idsp.idct_permutation[i << 3]];
+ ac_val1[i] = block[h->c.idsp.idct_permutation[i << 3]];
/* top copy */
for (i = 1; i < 8; i++)
- ac_val1[8 + i] = block[s->idsp.idct_permutation[i]];
+ ac_val1[8 + i] = block[h->c.idsp.idct_permutation[i]];
}
/**
@@ -376,28 +382,28 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
*/
static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
{
- MpegEncContext *s = &ctx->m;
- int bits_count = get_bits_count(&s->gb);
- int v = show_bits(&s->gb, 16);
+ H263DecContext *const h = &ctx->h;
+ int bits_count = get_bits_count(&h->c.gb);
+ int v = show_bits(&h->c.gb, 16);
- if (s->workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)
+ if (h->c.workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)
return 0;
while (v <= 0xFF) {
- if (s->pict_type == AV_PICTURE_TYPE_B ||
- (v >> (8 - s->pict_type) != 1) || s->partitioned_frame)
+ if (h->c.pict_type == AV_PICTURE_TYPE_B ||
+ (v >> (8 - h->c.pict_type) != 1) || h->c.partitioned_frame)
break;
- skip_bits(&s->gb, 8 + s->pict_type);
- bits_count += 8 + s->pict_type;
- v = show_bits(&s->gb, 16);
+ skip_bits(&h->c.gb, 8 + h->c.pict_type);
+ bits_count += 8 + h->c.pict_type;
+ v = show_bits(&h->c.gb, 16);
}
- if (bits_count + 8 >= s->gb.size_in_bits) {
+ if (bits_count + 8 >= h->c.gb.size_in_bits) {
v >>= 8;
v |= 0x7F >> (7 - (bits_count & 7));
if (v == 0x7F)
- return s->mb_num;
+ return h->c.mb_num;
} else {
static const uint16_t mpeg4_resync_prefix[8] = {
0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000
@@ -405,23 +411,23 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
if (v == mpeg4_resync_prefix[bits_count & 7]) {
int len, mb_num;
- int mb_num_bits = av_log2(s->mb_num - 1) + 1;
- GetBitContext gb = s->gb;
+ int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;
+ GetBitContext gb = h->c.gb;
- skip_bits(&s->gb, 1);
- align_get_bits(&s->gb);
+ skip_bits(&h->c.gb, 1);
+ align_get_bits(&h->c.gb);
for (len = 0; len < 32; len++)
- if (get_bits1(&s->gb))
+ if (get_bits1(&h->c.gb))
break;
- mb_num = get_bits(&s->gb, mb_num_bits);
- if (!mb_num || mb_num > s->mb_num || get_bits_count(&s->gb)+6 > s->gb.size_in_bits)
+ mb_num = get_bits(&h->c.gb, mb_num_bits);
+ if (!mb_num || mb_num > h->c.mb_num || get_bits_count(&h->c.gb) + 6 > h->c.gb.size_in_bits)
mb_num= -1;
- s->gb = gb;
+ h->c.gb = gb;
- if (len >= ff_mpeg4_get_video_packet_prefix_length(s->pict_type, ctx->f_code, ctx->b_code))
+ if (len >= ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code))
return mb_num;
}
}
@@ -430,7 +436,7 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb)
{
- MpegEncContext *s = &ctx->m;
+ MpegEncContext *s = &ctx->h.c;
int a = 2 << ctx->sprite_warping_accuracy;
int rho = 3 - ctx->sprite_warping_accuracy;
int r = 16 / a;
@@ -685,13 +691,12 @@ overflow:
}
static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) {
- MpegEncContext *s = &ctx->m;
int len = FFMIN(ctx->time_increment_bits + 3, 15);
get_bits(gb, len);
if (get_bits1(gb))
get_bits(gb, len);
- check_marker(s->avctx, gb, "after new_pred");
+ check_marker(ctx->h.c.avctx, gb, "after new_pred");
return 0;
}
@@ -700,96 +705,96 @@ static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) {
* Decode the next video packet.
* @return <0 if something went wrong
*/
-int ff_mpeg4_decode_video_packet_header(MPVContext *const s)
+int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
{
- Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
- int mb_num_bits = av_log2(s->mb_num - 1) + 1;
+ int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;
int header_extension = 0, mb_num, len;
/* is there enough space left for a video packet + header */
- if (get_bits_count(&s->gb) > s->gb.size_in_bits - 20)
+ if (get_bits_count(&h->c.gb) > h->c.gb.size_in_bits - 20)
return AVERROR_INVALIDDATA;
for (len = 0; len < 32; len++)
- if (get_bits1(&s->gb))
+ if (get_bits1(&h->c.gb))
break;
- if (len != ff_mpeg4_get_video_packet_prefix_length(s->pict_type, ctx->f_code, ctx->b_code)) {
- av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n");
+ if (len != ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "marker does not match f_code\n");
return AVERROR_INVALIDDATA;
}
if (ctx->shape != RECT_SHAPE) {
- header_extension = get_bits1(&s->gb);
+ header_extension = get_bits1(&h->c.gb);
// FIXME more stuff here
}
- mb_num = get_bits(&s->gb, mb_num_bits);
- if (mb_num >= s->mb_num || !mb_num) {
- av_log(s->avctx, AV_LOG_ERROR,
- "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);
+ mb_num = get_bits(&h->c.gb, mb_num_bits);
+ if (mb_num >= h->c.mb_num || !mb_num) {
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "illegal mb_num in video packet (%d %d) \n", mb_num, h->c.mb_num);
return AVERROR_INVALIDDATA;
}
- s->mb_x = mb_num % s->mb_width;
- s->mb_y = mb_num / s->mb_width;
+ h->c.mb_x = mb_num % h->c.mb_width;
+ h->c.mb_y = mb_num / h->c.mb_width;
if (ctx->shape != BIN_ONLY_SHAPE) {
- int qscale = get_bits(&s->gb, ctx->quant_precision);
+ int qscale = get_bits(&h->c.gb, ctx->quant_precision);
if (qscale)
- s->chroma_qscale = s->qscale = qscale;
+ h->c.chroma_qscale = h->c.qscale = qscale;
}
if (ctx->shape == RECT_SHAPE)
- header_extension = get_bits1(&s->gb);
+ header_extension = get_bits1(&h->c.gb);
if (header_extension) {
- while (get_bits1(&s->gb) != 0)
+ while (get_bits1(&h->c.gb) != 0)
;
- check_marker(s->avctx, &s->gb, "before time_increment in video packed header");
- skip_bits(&s->gb, ctx->time_increment_bits); /* time_increment */
- check_marker(s->avctx, &s->gb, "before vop_coding_type in video packed header");
+ check_marker(h->c.avctx, &h->c.gb, "before time_increment in video packed header");
+ skip_bits(&h->c.gb, ctx->time_increment_bits); /* time_increment */
+ check_marker(h->c.avctx, &h->c.gb, "before vop_coding_type in video packed header");
- skip_bits(&s->gb, 2); /* vop coding type */
+ skip_bits(&h->c.gb, 2); /* vop coding type */
// FIXME not rect stuff here
if (ctx->shape != BIN_ONLY_SHAPE) {
- skip_bits(&s->gb, 3); /* intra dc vlc threshold */
+ skip_bits(&h->c.gb, 3); /* intra dc vlc threshold */
// FIXME don't just ignore everything
- if (s->pict_type == AV_PICTURE_TYPE_S &&
+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE) {
- if (mpeg4_decode_sprite_trajectory(ctx, &s->gb) < 0)
+ if (mpeg4_decode_sprite_trajectory(ctx, &h->c.gb) < 0)
return AVERROR_INVALIDDATA;
- av_log(s->avctx, AV_LOG_ERROR, "untested\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "untested\n");
}
// FIXME reduced res stuff here
- if (s->pict_type != AV_PICTURE_TYPE_I) {
- int f_code = get_bits(&s->gb, 3); /* fcode_for */
+ if (h->c.pict_type != AV_PICTURE_TYPE_I) {
+ int f_code = get_bits(&h->c.gb, 3); /* fcode_for */
if (f_code == 0)
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"Error, video packet header damaged (f_code=0)\n");
}
- if (s->pict_type == AV_PICTURE_TYPE_B) {
- int b_code = get_bits(&s->gb, 3);
+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
+ int b_code = get_bits(&h->c.gb, 3);
if (b_code == 0)
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"Error, video packet header damaged (b_code=0)\n");
}
}
}
if (ctx->new_pred)
- decode_new_pred(ctx, &s->gb);
+ decode_new_pred(ctx, &h->c.gb);
return 0;
}
static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
{
- MPVContext *const s = &ctx->m;
+ MPVContext *const s = &ctx->h.c;
/* Reset DC Predictors */
s->last_dc[0] =
s->last_dc[1] =
@@ -800,25 +805,25 @@ static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
* Decode the next video packet.
* @return <0 if something went wrong
*/
-int ff_mpeg4_decode_studio_slice_header(MPVContext *const s)
+int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
{
- Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
- GetBitContext *gb = &s->gb;
+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
+ GetBitContext *gb = &h->c.gb;
unsigned vlc_len;
uint16_t mb_num;
if (get_bits_left(gb) >= 32 && get_bits_long(gb, 32) == SLICE_STARTCODE) {
- vlc_len = av_log2(s->mb_width * s->mb_height) + 1;
+ vlc_len = av_log2(h->c.mb_width * h->c.mb_height) + 1;
mb_num = get_bits(gb, vlc_len);
- if (mb_num >= s->mb_num)
+ if (mb_num >= h->c.mb_num)
return AVERROR_INVALIDDATA;
- s->mb_x = mb_num % s->mb_width;
- s->mb_y = mb_num / s->mb_width;
+ h->c.mb_x = mb_num % h->c.mb_width;
+ h->c.mb_y = mb_num / h->c.mb_width;
if (ctx->shape != BIN_ONLY_SHAPE)
- s->qscale = mpeg_get_qscale(s);
+ h->c.qscale = mpeg_get_qscale(&h->c);
if (get_bits1(gb)) { /* slice_extension_flag */
skip_bits1(gb); /* intra_slice */
@@ -844,7 +849,7 @@ int ff_mpeg4_decode_studio_slice_header(MPVContext *const s)
*/
static inline int get_amv(Mpeg4DecContext *ctx, int n)
{
- MpegEncContext *s = &ctx->m;
+ MPVContext *const s = &ctx->h.c;
int x, y, mb_v, sum, dx, dy, shift;
int len = 1 << (ctx->f_code + 4);
const int a = ctx->sprite_warping_accuracy;
@@ -975,17 +980,17 @@ static inline int mpeg4_get_level_dc(MpegEncContext *s, int n, int pred, int lev
* @param dir_ptr the prediction direction will be stored here
* @return the quantized dc
*/
-static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
+static inline int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr)
{
int level, code, pred;
if (n < 4)
- code = get_vlc2(&s->gb, dc_lum, DC_VLC_BITS, 1);
+ code = get_vlc2(&h->c.gb, dc_lum, DC_VLC_BITS, 1);
else
- code = get_vlc2(&s->gb, dc_chrom, DC_VLC_BITS, 1);
+ code = get_vlc2(&h->c.gb, dc_chrom, DC_VLC_BITS, 1);
if (code < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
return AVERROR_INVALIDDATA;
}
@@ -994,29 +999,29 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
} else {
if (IS_3IV1) {
if (code == 1)
- level = 2 * get_bits1(&s->gb) - 1;
+ level = 2 * get_bits1(&h->c.gb) - 1;
else {
- if (get_bits1(&s->gb))
- level = get_bits(&s->gb, code - 1) + (1 << (code - 1));
+ if (get_bits1(&h->c.gb))
+ level = get_bits(&h->c.gb, code - 1) + (1 << (code - 1));
else
- level = -get_bits(&s->gb, code - 1) - (1 << (code - 1));
+ level = -get_bits(&h->c.gb, code - 1) - (1 << (code - 1));
}
} else {
- level = get_xbits(&s->gb, code);
+ level = get_xbits(&h->c.gb, code);
}
if (code > 8) {
- if (get_bits1(&s->gb) == 0) { /* marker */
- if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {
- av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n");
+ if (get_bits1(&h->c.gb) == 0) { /* marker */
+ if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "dc marker bit missing\n");
return AVERROR_INVALIDDATA;
}
}
}
}
- pred = mpeg4_pred_dc(s, n, dir_ptr);
- return mpeg4_get_level_dc(s, n, pred, level);
+ pred = mpeg4_pred_dc(&h->c, n, dir_ptr);
+ return mpeg4_get_level_dc(&h->c, n, pred, level);
}
/**
@@ -1025,85 +1030,85 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
*/
static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
{
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
int mb_num = 0;
static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
/* decode first partition */
- s->first_slice_line = 1;
- for (; s->mb_y < s->mb_height; s->mb_y++) {
- ff_init_block_index(s);
- for (; s->mb_x < s->mb_width; s->mb_x++) {
- const int xy = s->mb_x + s->mb_y * s->mb_stride;
+ h->c.first_slice_line = 1;
+ for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) {
+ ff_init_block_index(&h->c);
+ for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
int cbpc;
int dir = 0;
mb_num++;
- ff_update_block_index(s, 8, s->avctx->lowres, 1);
- if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1)
- s->first_slice_line = 0;
+ ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
+ if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1)
+ h->c.first_slice_line = 0;
- if (s->pict_type == AV_PICTURE_TYPE_I) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
int i;
do {
- if (show_bits(&s->gb, 19) == DC_MARKER)
+ if (show_bits(&h->c.gb, 19) == DC_MARKER)
return mb_num - 1;
- cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
} while (cbpc == 8);
- s->cbp_table[xy] = cbpc & 3;
- s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
- s->mb_intra = 1;
+ h->c.cbp_table[xy] = cbpc & 3;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
+ h->c.mb_intra = 1;
if (cbpc & 4)
- ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
- s->cur_pic.qscale_table[xy] = s->qscale;
+ h->c.cur_pic.qscale_table[xy] = h->c.qscale;
- s->mbintra_table[xy] = 1;
+ h->c.mbintra_table[xy] = 1;
for (i = 0; i < 6; i++) {
int dc_pred_dir;
- int dc = mpeg4_decode_dc(s, i, &dc_pred_dir);
+ int dc = mpeg4_decode_dc(h, i, &dc_pred_dir);
if (dc < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
return dc;
}
dir <<= 1;
if (dc_pred_dir)
dir |= 1;
}
- s->pred_dir_table[xy] = dir;
+ h->c.pred_dir_table[xy] = dir;
} else { /* P/S_TYPE */
int mx, my, pred_x, pred_y, bits;
- int16_t *const mot_val = s->cur_pic.motion_val[0][s->block_index[0]];
- const int stride = s->b8_stride * 2;
+ int16_t *const mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
+ const int stride = h->c.b8_stride * 2;
try_again:
- bits = show_bits(&s->gb, 17);
+ bits = show_bits(&h->c.gb, 17);
if (bits == MOTION_MARKER)
return mb_num - 1;
- skip_bits1(&s->gb);
+ skip_bits1(&h->c.gb);
if (bits & 0x10000) {
/* skip mb */
- if (s->pict_type == AV_PICTURE_TYPE_S &&
+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE) {
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
MB_TYPE_16x16 |
MB_TYPE_GMC |
MB_TYPE_FORWARD_MV;
mx = get_amv(ctx, 0);
my = get_amv(ctx, 1);
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
MB_TYPE_16x16 |
MB_TYPE_FORWARD_MV;
mx = my = 0;
@@ -1117,26 +1122,26 @@ try_again:
mot_val[1 + stride] =
mot_val[3 + stride] = my;
- ff_h263_clean_intra_table_entries(s, xy);
+ ff_h263_clean_intra_table_entries(&h->c, xy);
continue;
}
- cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
if (cbpc == 20)
goto try_again;
- s->cbp_table[xy] = cbpc & (8 + 3); // 8 is dquant
+ h->c.cbp_table[xy] = cbpc & (8 + 3); // 8 is dquant
- s->mb_intra = ((cbpc & 4) != 0);
+ h->c.mb_intra = ((cbpc & 4) != 0);
- if (s->mb_intra) {
- s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
- s->mbintra_table[xy] = 1;
+ if (h->c.mb_intra) {
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
+ h->c.mbintra_table[xy] = 1;
mot_val[0] =
mot_val[2] =
mot_val[0 + stride] =
@@ -1146,33 +1151,33 @@ try_again:
mot_val[1 + stride] =
mot_val[3 + stride] = 0;
} else {
- ff_h263_clean_intra_table_entries(s, xy);
+ ff_h263_clean_intra_table_entries(&h->c, xy);
- if (s->pict_type == AV_PICTURE_TYPE_S &&
+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE &&
(cbpc & 16) == 0)
- s->mcsel = get_bits1(&s->gb);
+ h->c.mcsel = get_bits1(&h->c.gb);
else
- s->mcsel = 0;
+ h->c.mcsel = 0;
if ((cbpc & 16) == 0) {
/* 16x16 motion prediction */
- ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- if (!s->mcsel) {
- mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
+ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
+ if (!h->c.mcsel) {
+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
if (mx >= 0xffff)
return AVERROR_INVALIDDATA;
- my = ff_h263_decode_motion(s, pred_y, ctx->f_code);
+ my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
if (my >= 0xffff)
return AVERROR_INVALIDDATA;
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 |
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 |
MB_TYPE_FORWARD_MV;
} else {
mx = get_amv(ctx, 0);
my = get_amv(ctx, 1);
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 |
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 |
MB_TYPE_GMC |
MB_TYPE_FORWARD_MV;
}
@@ -1187,15 +1192,15 @@ try_again:
mot_val[3 + stride] = my;
} else {
int i;
- s->cur_pic.mb_type[xy] = MB_TYPE_8x8 |
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 |
MB_TYPE_FORWARD_MV;
for (i = 0; i < 4; i++) {
- int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
- mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
+ int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
if (mx >= 0xffff)
return AVERROR_INVALIDDATA;
- my = ff_h263_decode_motion(s, pred_y, ctx->f_code);
+ my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
if (my >= 0xffff)
return AVERROR_INVALIDDATA;
mot_val[0] = mx;
@@ -1205,7 +1210,7 @@ try_again:
}
}
}
- s->mb_x = 0;
+ h->c.mb_x = 0;
}
return mb_num;
@@ -1215,91 +1220,91 @@ try_again:
* decode second partition.
* @return <0 if an error occurred
*/
-static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
+static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
{
int mb_num = 0;
static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
- s->mb_x = s->resync_mb_x;
- s->first_slice_line = 1;
- for (s->mb_y = s->resync_mb_y; mb_num < mb_count; s->mb_y++) {
- ff_init_block_index(s);
- for (; mb_num < mb_count && s->mb_x < s->mb_width; s->mb_x++) {
- const int xy = s->mb_x + s->mb_y * s->mb_stride;
+ h->c.mb_x = h->c.resync_mb_x;
+ h->c.first_slice_line = 1;
+ for (h->c.mb_y = h->c.resync_mb_y; mb_num < mb_count; h->c.mb_y++) {
+ ff_init_block_index(&h->c);
+ for (; mb_num < mb_count && h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
mb_num++;
- ff_update_block_index(s, 8, s->avctx->lowres, 1);
- if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1)
- s->first_slice_line = 0;
+ ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
+ if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1)
+ h->c.first_slice_line = 0;
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- int ac_pred = get_bits1(&s->gb);
- int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
+ int ac_pred = get_bits1(&h->c.gb);
+ int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
- s->cbp_table[xy] |= cbpy << 2;
- s->cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
+ h->c.cbp_table[xy] |= cbpy << 2;
+ h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
} else { /* P || S_TYPE */
- if (IS_INTRA(s->cur_pic.mb_type[xy])) {
+ if (IS_INTRA(h->c.cur_pic.mb_type[xy])) {
int i;
int dir = 0;
- int ac_pred = get_bits1(&s->gb);
- int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ int ac_pred = get_bits1(&h->c.gb);
+ int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "I cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
- if (s->cbp_table[xy] & 8)
- ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
- s->cur_pic.qscale_table[xy] = s->qscale;
+ if (h->c.cbp_table[xy] & 8)
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
+ h->c.cur_pic.qscale_table[xy] = h->c.qscale;
for (i = 0; i < 6; i++) {
int dc_pred_dir;
- int dc = mpeg4_decode_dc(s, i, &dc_pred_dir);
+ int dc = mpeg4_decode_dc(h, i, &dc_pred_dir);
if (dc < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
return dc;
}
dir <<= 1;
if (dc_pred_dir)
dir |= 1;
}
- s->cbp_table[xy] &= 3; // remove dquant
- s->cbp_table[xy] |= cbpy << 2;
- s->cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
- s->pred_dir_table[xy] = dir;
- } else if (IS_SKIP(s->cur_pic.mb_type[xy])) {
- s->cur_pic.qscale_table[xy] = s->qscale;
- s->cbp_table[xy] = 0;
+ h->c.cbp_table[xy] &= 3; // remove dquant
+ h->c.cbp_table[xy] |= cbpy << 2;
+ h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
+ h->c.pred_dir_table[xy] = dir;
+ } else if (IS_SKIP(h->c.cur_pic.mb_type[xy])) {
+ h->c.cur_pic.qscale_table[xy] = h->c.qscale;
+ h->c.cbp_table[xy] = 0;
} else {
- int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "P cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
- if (s->cbp_table[xy] & 8)
- ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
- s->cur_pic.qscale_table[xy] = s->qscale;
+ if (h->c.cbp_table[xy] & 8)
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
+ h->c.cur_pic.qscale_table[xy] = h->c.qscale;
- s->cbp_table[xy] &= 3; // remove dquant
- s->cbp_table[xy] |= (cbpy ^ 0xf) << 2;
+ h->c.cbp_table[xy] &= 3; // remove dquant
+ h->c.cbp_table[xy] |= (cbpy ^ 0xf) << 2;
}
}
}
if (mb_num >= mb_count)
return 0;
- s->mb_x = 0;
+ h->c.mb_x = 0;
}
return 0;
}
@@ -1308,62 +1313,62 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
* Decode the first and second partition.
* @return <0 if error (and sets error type in the error_status_table)
*/
-int ff_mpeg4_decode_partitions(MPVContext *const s)
+int ff_mpeg4_decode_partitions(H263DecContext *const h)
{
- Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
int mb_num;
int ret;
- const int part_a_error = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR;
- const int part_a_end = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END;
+ const int part_a_error = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR;
+ const int part_a_end = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END;
mb_num = mpeg4_decode_partition_a(ctx);
if (mb_num <= 0) {
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x, s->mb_y, part_a_error);
+ 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, part_a_error);
return mb_num ? mb_num : AVERROR_INVALIDDATA;
}
- if (s->resync_mb_x + s->resync_mb_y * s->mb_width + mb_num > s->mb_num) {
- av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n");
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x, s->mb_y, part_a_error);
+ if (h->c.resync_mb_x + h->c.resync_mb_y * h->c.mb_width + mb_num > h->c.mb_num) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "slice below monitor ...\n");
+ 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, part_a_error);
return AVERROR_INVALIDDATA;
}
- s->mb_num_left = mb_num;
+ h->c.mb_num_left = mb_num;
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- while (show_bits(&s->gb, 9) == 1)
- skip_bits(&s->gb, 9);
- if (get_bits(&s->gb, 19) != DC_MARKER) {
- av_log(s->avctx, AV_LOG_ERROR,
+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
+ while (show_bits(&h->c.gb, 9) == 1)
+ skip_bits(&h->c.gb, 9);
+ if (get_bits(&h->c.gb, 19) != DC_MARKER) {
+ av_log(h->c.avctx, AV_LOG_ERROR,
"marker missing after first I partition at %d %d\n",
- s->mb_x, s->mb_y);
+ h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
} else {
- while (show_bits(&s->gb, 10) == 1)
- skip_bits(&s->gb, 10);
- if (get_bits(&s->gb, 17) != MOTION_MARKER) {
- av_log(s->avctx, AV_LOG_ERROR,
+ while (show_bits(&h->c.gb, 10) == 1)
+ skip_bits(&h->c.gb, 10);
+ if (get_bits(&h->c.gb, 17) != MOTION_MARKER) {
+ av_log(h->c.avctx, AV_LOG_ERROR,
"marker missing after first P partition at %d %d\n",
- s->mb_x, s->mb_y);
+ h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
}
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x - 1, s->mb_y, part_a_end);
+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
+ h->c.mb_x - 1, h->c.mb_y, part_a_end);
- ret = mpeg4_decode_partition_b(s, mb_num);
+ ret = mpeg4_decode_partition_b(h, mb_num);
if (ret < 0) {
- if (s->pict_type == AV_PICTURE_TYPE_P)
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x, s->mb_y, ER_DC_ERROR);
+ if (h->c.pict_type == AV_PICTURE_TYPE_P)
+ 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_DC_ERROR);
return ret;
} else {
- if (s->pict_type == AV_PICTURE_TYPE_P)
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x - 1, s->mb_y, ER_DC_END);
+ if (h->c.pict_type == AV_PICTURE_TYPE_P)
+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
+ h->c.mb_x - 1, h->c.mb_y, ER_DC_END);
}
return 0;
@@ -1377,7 +1382,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
int n, int coded, int intra,
int use_intra_dc_vlc, int rvlc)
{
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
int level, i, last, run, qmul, qadd, pred;
int av_uninit(dc_pred_dir);
const RLTable *rl;
@@ -1390,15 +1395,15 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
// FIXME add short header support
if (use_intra_dc_vlc) {
/* DC coef */
- if (s->partitioned_frame) {
- level = s->dc_val[s->block_index[n]];
+ if (h->c.partitioned_frame) {
+ level = h->c.dc_val[h->c.block_index[n]];
if (n < 4)
- level = FASTDIV((level + (s->y_dc_scale >> 1)), s->y_dc_scale);
+ level = FASTDIV((level + (h->c.y_dc_scale >> 1)), h->c.y_dc_scale);
else
- level = FASTDIV((level + (s->c_dc_scale >> 1)), s->c_dc_scale);
- dc_pred_dir = (s->pred_dir_table[s->mb_x + s->mb_y * s->mb_stride] << n) & 32;
+ level = FASTDIV((level + (h->c.c_dc_scale >> 1)), h->c.c_dc_scale);
+ dc_pred_dir = (h->c.pred_dir_table[h->c.mb_x + h->c.mb_y * h->c.mb_stride] << n) & 32;
} else {
- level = mpeg4_decode_dc(s, n, &dc_pred_dir);
+ level = mpeg4_decode_dc(h, n, &dc_pred_dir);
if (level < 0)
return level;
}
@@ -1406,7 +1411,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
i = 0;
} else {
i = -1;
- pred = mpeg4_pred_dc(s, n, &dc_pred_dir);
+ pred = mpeg4_pred_dc(&h->c, n, &dc_pred_dir);
}
if (!coded)
goto not_coded;
@@ -1418,20 +1423,20 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
rl = &ff_mpeg4_rl_intra;
rl_vlc = ff_mpeg4_rl_intra.rl_vlc[0];
}
- if (s->ac_pred) {
+ if (h->c.ac_pred) {
if (dc_pred_dir == 0)
- scan_table = s->permutated_intra_v_scantable; /* left */
+ scan_table = h->c.permutated_intra_v_scantable; /* left */
else
- scan_table = s->permutated_intra_h_scantable; /* top */
+ scan_table = h->c.permutated_intra_h_scantable; /* top */
} else {
- scan_table = s->intra_scantable.permutated;
+ scan_table = h->c.intra_scantable.permutated;
}
qmul = 1;
qadd = 0;
} else {
i = -1;
if (!coded) {
- s->block_last_index[n] = i;
+ h->c.block_last_index[n] = i;
return 0;
}
if (rvlc)
@@ -1439,7 +1444,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
else
rl = &ff_h263_rl_inter;
- scan_table = s->intra_scantable.permutated;
+ scan_table = h->c.intra_scantable.permutated;
if (ctx->mpeg_quant) {
qmul = 1;
@@ -1449,61 +1454,61 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
else
rl_vlc = ff_h263_rl_inter.rl_vlc[0];
} else {
- qmul = s->qscale << 1;
- qadd = (s->qscale - 1) | 1;
+ qmul = h->c.qscale << 1;
+ qadd = (h->c.qscale - 1) | 1;
if (rvlc)
- rl_vlc = ff_rvlc_rl_inter.rl_vlc[s->qscale];
+ rl_vlc = ff_rvlc_rl_inter.rl_vlc[h->c.qscale];
else
- rl_vlc = ff_h263_rl_inter.rl_vlc[s->qscale];
+ rl_vlc = ff_h263_rl_inter.rl_vlc[h->c.qscale];
}
}
{
- OPEN_READER(re, &s->gb);
+ OPEN_READER(re, &h->c.gb);
for (;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
+ UPDATE_CACHE(re, &h->c.gb);
+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0);
if (level == 0) {
/* escape */
if (rvlc) {
- if (SHOW_UBITS(re, &s->gb, 1) == 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR,
"1. marker bit missing in rvlc esc\n");
return AVERROR_INVALIDDATA;
}
- SKIP_CACHE(re, &s->gb, 1);
+ SKIP_CACHE(re, &h->c.gb, 1);
- last = SHOW_UBITS(re, &s->gb, 1);
- SKIP_CACHE(re, &s->gb, 1);
- run = SHOW_UBITS(re, &s->gb, 6);
- SKIP_COUNTER(re, &s->gb, 1 + 1 + 6);
- UPDATE_CACHE(re, &s->gb);
+ last = SHOW_UBITS(re, &h->c.gb, 1);
+ SKIP_CACHE(re, &h->c.gb, 1);
+ run = SHOW_UBITS(re, &h->c.gb, 6);
+ SKIP_COUNTER(re, &h->c.gb, 1 + 1 + 6);
+ UPDATE_CACHE(re, &h->c.gb);
- if (SHOW_UBITS(re, &s->gb, 1) == 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR,
"2. marker bit missing in rvlc esc\n");
return AVERROR_INVALIDDATA;
}
- SKIP_CACHE(re, &s->gb, 1);
+ SKIP_CACHE(re, &h->c.gb, 1);
- level = SHOW_UBITS(re, &s->gb, 11);
- SKIP_CACHE(re, &s->gb, 11);
+ level = SHOW_UBITS(re, &h->c.gb, 11);
+ SKIP_CACHE(re, &h->c.gb, 11);
- if (SHOW_UBITS(re, &s->gb, 5) != 0x10) {
- av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n");
+ if (SHOW_UBITS(re, &h->c.gb, 5) != 0x10) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "reverse esc missing\n");
return AVERROR_INVALIDDATA;
}
- SKIP_CACHE(re, &s->gb, 5);
+ SKIP_CACHE(re, &h->c.gb, 5);
level = level * qmul + qadd;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- SKIP_COUNTER(re, &s->gb, 1 + 11 + 5 + 1);
+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
+ SKIP_COUNTER(re, &h->c.gb, 1 + 11 + 5 + 1);
i += run + 1;
if (last)
i += 192;
} else {
int cache;
- cache = GET_CACHE(re, &s->gb);
+ cache = GET_CACHE(re, &h->c.gb);
if (IS_3IV1)
cache ^= 0xC0000000;
@@ -1511,54 +1516,54 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
if (cache & 0x80000000) {
if (cache & 0x40000000) {
/* third escape */
- SKIP_CACHE(re, &s->gb, 2);
- last = SHOW_UBITS(re, &s->gb, 1);
- SKIP_CACHE(re, &s->gb, 1);
- run = SHOW_UBITS(re, &s->gb, 6);
- SKIP_COUNTER(re, &s->gb, 2 + 1 + 6);
- UPDATE_CACHE(re, &s->gb);
+ SKIP_CACHE(re, &h->c.gb, 2);
+ last = SHOW_UBITS(re, &h->c.gb, 1);
+ SKIP_CACHE(re, &h->c.gb, 1);
+ run = SHOW_UBITS(re, &h->c.gb, 6);
+ SKIP_COUNTER(re, &h->c.gb, 2 + 1 + 6);
+ UPDATE_CACHE(re, &h->c.gb);
if (IS_3IV1) {
- level = SHOW_SBITS(re, &s->gb, 12);
- LAST_SKIP_BITS(re, &s->gb, 12);
+ level = SHOW_SBITS(re, &h->c.gb, 12);
+ LAST_SKIP_BITS(re, &h->c.gb, 12);
} else {
- if (SHOW_UBITS(re, &s->gb, 1) == 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR,
"1. marker bit missing in 3. esc\n");
- if (!(s->avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&s->gb) <= 0)
+ if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0)
return AVERROR_INVALIDDATA;
}
- SKIP_CACHE(re, &s->gb, 1);
+ SKIP_CACHE(re, &h->c.gb, 1);
- level = SHOW_SBITS(re, &s->gb, 12);
- SKIP_CACHE(re, &s->gb, 12);
+ level = SHOW_SBITS(re, &h->c.gb, 12);
+ SKIP_CACHE(re, &h->c.gb, 12);
- if (SHOW_UBITS(re, &s->gb, 1) == 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR,
"2. marker bit missing in 3. esc\n");
- if (!(s->avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&s->gb) <= 0)
+ if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0)
return AVERROR_INVALIDDATA;
}
- SKIP_COUNTER(re, &s->gb, 1 + 12 + 1);
+ SKIP_COUNTER(re, &h->c.gb, 1 + 12 + 1);
}
#if 0
- if (s->error_recognition >= FF_ER_COMPLIANT) {
+ if (h->c.error_recognition >= FF_ER_COMPLIANT) {
const int abs_level= FFABS(level);
if (abs_level<=MAX_LEVEL && run<=MAX_RUN) {
const int run1= run - rl->max_run[last][abs_level] - 1;
if (abs_level <= rl->max_level[last][run]) {
- av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
return AVERROR_INVALIDDATA;
}
- if (s->error_recognition > FF_ER_COMPLIANT) {
+ if (h->c.error_recognition > FF_ER_COMPLIANT) {
if (abs_level <= rl->max_level[last][run]*2) {
- av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
return AVERROR_INVALIDDATA;
}
if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
- av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
return AVERROR_INVALIDDATA;
}
}
@@ -1571,11 +1576,11 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
level = level * qmul - qadd;
if ((unsigned)(level + 2048) > 4095) {
- if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)) {
+ if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)) {
if (level > 2560 || level < -2560) {
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"|level| overflow in 3. esc, qp=%d\n",
- s->qscale);
+ h->c.qscale);
return AVERROR_INVALIDDATA;
}
}
@@ -1587,33 +1592,33 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
i += 192;
} else {
/* second escape */
- SKIP_BITS(re, &s->gb, 2);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
+ SKIP_BITS(re, &h->c.gb, 2);
+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i += run + rl->max_run[run >> 7][level / qmul] + 1; // FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
+ LAST_SKIP_BITS(re, &h->c.gb, 1);
}
} else {
/* first escape */
- SKIP_BITS(re, &s->gb, 1);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
+ SKIP_BITS(re, &h->c.gb, 1);
+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i += run;
level = level + rl->max_level[run >> 7][(run - 1) & 63] * qmul; // FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
+ LAST_SKIP_BITS(re, &h->c.gb, 1);
}
}
} else {
i += run;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
+ LAST_SKIP_BITS(re, &h->c.gb, 1);
}
- ff_tlog(s->avctx, "dct[%d][%d] = %- 4d end?:%d\n", scan_table[i&63]&7, scan_table[i&63] >> 3, level, i>62);
+ ff_tlog(h->c.avctx, "dct[%d][%d] = %- 4d end?:%d\n", scan_table[i&63]&7, scan_table[i&63] >> 3, level, i>62);
if (i > 62) {
i -= 192;
if (i & (~63)) {
- av_log(s->avctx, AV_LOG_ERROR,
- "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "ac-tex damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
@@ -1623,22 +1628,22 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
block[scan_table[i]] = level;
}
- CLOSE_READER(re, &s->gb);
+ CLOSE_READER(re, &h->c.gb);
}
not_coded:
if (intra) {
if (!use_intra_dc_vlc) {
- block[0] = mpeg4_get_level_dc(s, n, pred, block[0]);
+ block[0] = mpeg4_get_level_dc(&h->c, n, pred, block[0]);
i -= i >> 31; // if (i == -1) i = 0;
}
- ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);
- if (s->ac_pred)
+ ff_mpeg4_pred_ac(h, block, n, dc_pred_dir);
+ if (h->c.ac_pred)
i = 63; // FIXME not optimal
}
- s->block_last_index[n] = i;
+ h->c.block_last_index[n] = i;
return 0;
}
@@ -1646,72 +1651,71 @@ not_coded:
* decode partition C of one MB.
* @return <0 if an error occurred
*/
-static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64])
+static int mpeg4_decode_partitioned_mb(H263DecContext *const h, int16_t block[6][64])
{
- Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
- int cbp, mb_type, use_intra_dc_vlc;
- const int xy = s->mb_x + s->mb_y * s->mb_stride;
+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
- mb_type = s->cur_pic.mb_type[xy];
- cbp = s->cbp_table[xy];
+ const int mb_type = h->c.cur_pic.mb_type[xy];
+ int cbp = h->c.cbp_table[xy];
- use_intra_dc_vlc = s->qscale < ctx->intra_dc_threshold;
+ const int use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;
- if (s->cur_pic.qscale_table[xy] != s->qscale)
- ff_set_qscale(s, s->cur_pic.qscale_table[xy]);
+ if (h->c.cur_pic.qscale_table[xy] != h->c.qscale)
+ ff_set_qscale(&h->c, h->c.cur_pic.qscale_table[xy]);
- if (s->pict_type == AV_PICTURE_TYPE_P ||
- s->pict_type == AV_PICTURE_TYPE_S) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_P ||
+ h->c.pict_type == AV_PICTURE_TYPE_S) {
int i;
for (i = 0; i < 4; i++) {
- s->mv[0][i][0] = s->cur_pic.motion_val[0][s->block_index[i]][0];
- s->mv[0][i][1] = s->cur_pic.motion_val[0][s->block_index[i]][1];
+ h->c.mv[0][i][0] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][0];
+ h->c.mv[0][i][1] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][1];
}
- s->mb_intra = IS_INTRA(mb_type);
+ h->c.mb_intra = IS_INTRA(mb_type);
if (IS_SKIP(mb_type)) {
/* skip mb */
for (i = 0; i < 6; i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- if (s->pict_type == AV_PICTURE_TYPE_S
+ h->c.block_last_index[i] = -1;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ if (h->c.pict_type == AV_PICTURE_TYPE_S
&& ctx->vol_sprite_usage == GMC_SPRITE) {
- s->mcsel = 1;
- s->mb_skipped = 0;
- s->cur_pic.mbskip_table[xy] = 0;
+ h->c.mcsel = 1;
+ h->c.mb_skipped = 0;
+ h->c.cur_pic.mbskip_table[xy] = 0;
} else {
- s->mcsel = 0;
- s->mb_skipped = 1;
- s->cur_pic.mbskip_table[xy] = 1;
+ h->c.mcsel = 0;
+ h->c.mb_skipped = 1;
+ h->c.cur_pic.mbskip_table[xy] = 1;
}
- } else if (s->mb_intra) {
- s->ac_pred = IS_ACPRED(s->cur_pic.mb_type[xy]);
- } else if (!s->mb_intra) {
- // s->mcsel = 0; // FIXME do we need to init that?
+ } else if (h->c.mb_intra) {
+ h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]);
+ } else if (!h->c.mb_intra) {
+ // h->c.mcsel = 0; // FIXME do we need to init that?
- s->mv_dir = MV_DIR_FORWARD;
+ h->c.mv_dir = MV_DIR_FORWARD;
if (IS_8X8(mb_type)) {
- s->mv_type = MV_TYPE_8X8;
+ h->c.mv_type = MV_TYPE_8X8;
} else {
- s->mv_type = MV_TYPE_16X16;
+ h->c.mv_type = MV_TYPE_16X16;
}
}
} else { /* I-Frame */
- s->mb_intra = 1;
- s->ac_pred = IS_ACPRED(s->cur_pic.mb_type[xy]);
+ h->c.mb_intra = 1;
+ h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]);
}
if (!IS_SKIP(mb_type)) {
int i;
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
/* decode each block */
for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, s->mb_intra,
+ if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, h->c.mb_intra,
use_intra_dc_vlc, ctx->rvlc) < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"texture corrupted at %d %d %d\n",
- s->mb_x, s->mb_y, s->mb_intra);
+ h->c.mb_x, h->c.mb_y, h->c.mb_intra);
return AVERROR_INVALIDDATA;
}
cbp += cbp;
@@ -1719,300 +1723,300 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64])
}
/* per-MB end of slice check */
- if (--s->mb_num_left <= 0) {
+ if (--h->c.mb_num_left <= 0) {
if (mpeg4_is_resync(ctx))
return SLICE_END;
else
return SLICE_NOEND;
} else {
if (mpeg4_is_resync(ctx)) {
- const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1;
- if (s->cbp_table[xy + delta])
+ const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1;
+ if (h->c.cbp_table[xy + delta])
return SLICE_END;
}
return SLICE_OK;
}
}
-static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
+static int mpeg4_decode_mb(H263DecContext *const h, int16_t block[6][64])
{
- Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
- const int xy = s->mb_x + s->mb_y * s->mb_stride;
+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
int next;
- av_assert2(s->h263_pred);
+ av_assert2(h->c.h263_pred);
- if (s->pict_type == AV_PICTURE_TYPE_P ||
- s->pict_type == AV_PICTURE_TYPE_S) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_P ||
+ h->c.pict_type == AV_PICTURE_TYPE_S) {
do {
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&h->c.gb)) {
/* skip mb */
- s->mb_intra = 0;
+ h->c.mb_intra = 0;
for (i = 0; i < 6; i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- if (s->pict_type == AV_PICTURE_TYPE_S &&
+ h->c.block_last_index[i] = -1;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE) {
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
MB_TYPE_GMC |
MB_TYPE_16x16 |
MB_TYPE_FORWARD_MV;
- s->mcsel = 1;
- s->mv[0][0][0] = get_amv(ctx, 0);
- s->mv[0][0][1] = get_amv(ctx, 1);
- s->cur_pic.mbskip_table[xy] = 0;
- s->mb_skipped = 0;
+ h->c.mcsel = 1;
+ h->c.mv[0][0][0] = get_amv(ctx, 0);
+ h->c.mv[0][0][1] = get_amv(ctx, 1);
+ h->c.cur_pic.mbskip_table[xy] = 0;
+ h->c.mb_skipped = 0;
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 |
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 |
MB_TYPE_FORWARD_MV;
- s->mcsel = 0;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->cur_pic.mbskip_table[xy] = 1;
- s->mb_skipped = 1;
+ h->c.mcsel = 0;
+ h->c.mv[0][0][0] = 0;
+ h->c.mv[0][0][1] = 0;
+ h->c.cur_pic.mbskip_table[xy] = 1;
+ h->c.mb_skipped = 1;
}
goto end;
}
- cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "mcbpc damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "mcbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
} while (cbpc == 20);
dquant = cbpc & 8;
- s->mb_intra = ((cbpc & 4) != 0);
- if (s->mb_intra)
+ h->c.mb_intra = ((cbpc & 4) != 0);
+ if (h->c.mb_intra)
goto intra;
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
- if (s->pict_type == AV_PICTURE_TYPE_S &&
+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)
- s->mcsel = get_bits1(&s->gb);
+ h->c.mcsel = get_bits1(&h->c.gb);
else
- s->mcsel = 0;
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
+ h->c.mcsel = 0;
+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
if (cbpy < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "P cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "P cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
cbp = (cbpc & 3) | (cbpy << 2);
if (dquant)
- ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
- if ((!s->progressive_sequence) &&
- (cbp || (s->workaround_bugs & FF_BUG_XVID_ILACE)))
- s->interlaced_dct = get_bits1(&s->gb);
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
+ if ((!h->c.progressive_sequence) &&
+ (cbp || (h->c.workaround_bugs & FF_BUG_XVID_ILACE)))
+ h->c.interlaced_dct = get_bits1(&h->c.gb);
- s->mv_dir = MV_DIR_FORWARD;
+ h->c.mv_dir = MV_DIR_FORWARD;
if ((cbpc & 16) == 0) {
- if (s->mcsel) {
- s->cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 |
+ if (h->c.mcsel) {
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 |
MB_TYPE_FORWARD_MV;
/* 16x16 global motion prediction */
- s->mv_type = MV_TYPE_16X16;
+ h->c.mv_type = MV_TYPE_16X16;
mx = get_amv(ctx, 0);
my = get_amv(ctx, 1);
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
- } else if ((!s->progressive_sequence) && get_bits1(&s->gb)) {
- s->cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |
+ h->c.mv[0][0][0] = mx;
+ h->c.mv[0][0][1] = my;
+ } else if ((!h->c.progressive_sequence) && get_bits1(&h->c.gb)) {
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |
MB_TYPE_INTERLACED;
/* 16x8 field motion prediction */
- s->mv_type = MV_TYPE_FIELD;
+ h->c.mv_type = MV_TYPE_FIELD;
- s->field_select[0][0] = get_bits1(&s->gb);
- s->field_select[0][1] = get_bits1(&s->gb);
+ h->c.field_select[0][0] = get_bits1(&h->c.gb);
+ h->c.field_select[0][1] = get_bits1(&h->c.gb);
- ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
+ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
for (i = 0; i < 2; i++) {
- mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
if (mx >= 0xffff)
return AVERROR_INVALIDDATA;
- my = ff_h263_decode_motion(s, pred_y / 2, ctx->f_code);
+ my = ff_h263_decode_motion(h, pred_y / 2, ctx->f_code);
if (my >= 0xffff)
return AVERROR_INVALIDDATA;
- s->mv[0][i][0] = mx;
- s->mv[0][i][1] = my;
+ h->c.mv[0][i][0] = mx;
+ h->c.mv[0][i][1] = my;
}
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
/* 16x16 motion prediction */
- s->mv_type = MV_TYPE_16X16;
- ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
- mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
+ h->c.mv_type = MV_TYPE_16X16;
+ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
if (mx >= 0xffff)
return AVERROR_INVALIDDATA;
- my = ff_h263_decode_motion(s, pred_y, ctx->f_code);
+ my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
if (my >= 0xffff)
return AVERROR_INVALIDDATA;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
+ h->c.mv[0][0][0] = mx;
+ h->c.mv[0][0][1] = my;
}
} else {
- s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
- s->mv_type = MV_TYPE_8X8;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
+ h->c.mv_type = MV_TYPE_8X8;
for (i = 0; i < 4; i++) {
- int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
- mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
+ int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
if (mx >= 0xffff)
return AVERROR_INVALIDDATA;
- my = ff_h263_decode_motion(s, pred_y, ctx->f_code);
+ my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
if (my >= 0xffff)
return AVERROR_INVALIDDATA;
- s->mv[0][i][0] = mx;
- s->mv[0][i][1] = my;
+ h->c.mv[0][i][0] = mx;
+ h->c.mv[0][i][1] = my;
mot_val[0] = mx;
mot_val[1] = my;
}
}
- } else if (s->pict_type == AV_PICTURE_TYPE_B) {
+ } else if (h->c.pict_type == AV_PICTURE_TYPE_B) {
int modb1; // first bit of modb
int modb2; // second bit of modb
int mb_type;
- s->mb_intra = 0; // B-frames never contain intra blocks
- s->mcsel = 0; // ... true gmc blocks
+ h->c.mb_intra = 0; // B-frames never contain intra blocks
+ h->c.mcsel = 0; // ... true gmc blocks
- if (s->mb_x == 0) {
+ if (h->c.mb_x == 0) {
for (i = 0; i < 2; i++) {
- s->last_mv[i][0][0] =
- s->last_mv[i][0][1] =
- s->last_mv[i][1][0] =
- s->last_mv[i][1][1] = 0;
+ h->c.last_mv[i][0][0] =
+ h->c.last_mv[i][0][1] =
+ h->c.last_mv[i][1][0] =
+ h->c.last_mv[i][1][1] = 0;
}
- ff_thread_progress_await(&s->next_pic.ptr->progress, s->mb_y);
+ ff_thread_progress_await(&h->c.next_pic.ptr->progress, h->c.mb_y);
}
/* if we skipped it in the future P-frame than skip it now too */
- s->mb_skipped = s->next_pic.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC
+ h->c.mb_skipped = h->c.next_pic.mbskip_table[h->c.mb_y * h->c.mb_stride + h->c.mb_x]; // Note, skiptab=0 if last was GMC
- if (s->mb_skipped) {
+ if (h->c.mb_skipped) {
/* skip mb */
for (i = 0; i < 6; i++)
- s->block_last_index[i] = -1;
-
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] =
- s->mv[0][0][1] =
- s->mv[1][0][0] =
- s->mv[1][0][1] = 0;
- s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
+ h->c.block_last_index[i] = -1;
+
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ h->c.mv[0][0][0] =
+ h->c.mv[0][0][1] =
+ h->c.mv[1][0][0] =
+ h->c.mv[1][0][1] = 0;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
MB_TYPE_16x16 |
MB_TYPE_FORWARD_MV;
goto end;
}
- modb1 = get_bits1(&s->gb);
+ modb1 = get_bits1(&h->c.gb);
if (modb1) {
// like MB_TYPE_B_DIRECT but no vectors coded
mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV;
cbp = 0;
} else {
- modb2 = get_bits1(&s->gb);
- mb_type = get_vlc2(&s->gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
+ modb2 = get_bits1(&h->c.gb);
+ mb_type = get_vlc2(&h->c.gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
if (mb_type < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal MB_type\n");
return AVERROR_INVALIDDATA;
}
if (modb2) {
cbp = 0;
} else {
- s->bdsp.clear_blocks(s->block[0]);
- cbp = get_bits(&s->gb, 6);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
+ cbp = get_bits(&h->c.gb, 6);
}
if ((!IS_DIRECT(mb_type)) && cbp) {
- if (get_bits1(&s->gb))
- ff_set_qscale(s, s->qscale + get_bits1(&s->gb) * 4 - 2);
+ if (get_bits1(&h->c.gb))
+ ff_set_qscale(&h->c, h->c.qscale + get_bits1(&h->c.gb) * 4 - 2);
}
- if (!s->progressive_sequence) {
+ if (!h->c.progressive_sequence) {
if (cbp)
- s->interlaced_dct = get_bits1(&s->gb);
+ h->c.interlaced_dct = get_bits1(&h->c.gb);
- if (!IS_DIRECT(mb_type) && get_bits1(&s->gb)) {
+ if (!IS_DIRECT(mb_type) && get_bits1(&h->c.gb)) {
mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
mb_type &= ~MB_TYPE_16x16;
if (HAS_FORWARD_MV(mb_type)) {
- s->field_select[0][0] = get_bits1(&s->gb);
- s->field_select[0][1] = get_bits1(&s->gb);
+ h->c.field_select[0][0] = get_bits1(&h->c.gb);
+ h->c.field_select[0][1] = get_bits1(&h->c.gb);
}
if (HAS_BACKWARD_MV(mb_type)) {
- s->field_select[1][0] = get_bits1(&s->gb);
- s->field_select[1][1] = get_bits1(&s->gb);
+ h->c.field_select[1][0] = get_bits1(&h->c.gb);
+ h->c.field_select[1][1] = get_bits1(&h->c.gb);
}
}
}
- s->mv_dir = 0;
+ h->c.mv_dir = 0;
if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) {
- s->mv_type = MV_TYPE_16X16;
+ h->c.mv_type = MV_TYPE_16X16;
if (HAS_FORWARD_MV(mb_type)) {
- s->mv_dir = MV_DIR_FORWARD;
-
- mx = ff_h263_decode_motion(s, s->last_mv[0][0][0], ctx->f_code);
- my = ff_h263_decode_motion(s, s->last_mv[0][0][1], ctx->f_code);
- s->last_mv[0][1][0] =
- s->last_mv[0][0][0] =
- s->mv[0][0][0] = mx;
- s->last_mv[0][1][1] =
- s->last_mv[0][0][1] =
- s->mv[0][0][1] = my;
+ h->c.mv_dir = MV_DIR_FORWARD;
+
+ mx = ff_h263_decode_motion(h, h->c.last_mv[0][0][0], ctx->f_code);
+ my = ff_h263_decode_motion(h, h->c.last_mv[0][0][1], ctx->f_code);
+ h->c.last_mv[0][1][0] =
+ h->c.last_mv[0][0][0] =
+ h->c.mv[0][0][0] = mx;
+ h->c.last_mv[0][1][1] =
+ h->c.last_mv[0][0][1] =
+ h->c.mv[0][0][1] = my;
}
if (HAS_BACKWARD_MV(mb_type)) {
- s->mv_dir |= MV_DIR_BACKWARD;
-
- mx = ff_h263_decode_motion(s, s->last_mv[1][0][0], ctx->b_code);
- my = ff_h263_decode_motion(s, s->last_mv[1][0][1], ctx->b_code);
- s->last_mv[1][1][0] =
- s->last_mv[1][0][0] =
- s->mv[1][0][0] = mx;
- s->last_mv[1][1][1] =
- s->last_mv[1][0][1] =
- s->mv[1][0][1] = my;
+ h->c.mv_dir |= MV_DIR_BACKWARD;
+
+ mx = ff_h263_decode_motion(h, h->c.last_mv[1][0][0], ctx->b_code);
+ my = ff_h263_decode_motion(h, h->c.last_mv[1][0][1], ctx->b_code);
+ h->c.last_mv[1][1][0] =
+ h->c.last_mv[1][0][0] =
+ h->c.mv[1][0][0] = mx;
+ h->c.last_mv[1][1][1] =
+ h->c.last_mv[1][0][1] =
+ h->c.mv[1][0][1] = my;
}
} else if (!IS_DIRECT(mb_type)) {
- s->mv_type = MV_TYPE_FIELD;
+ h->c.mv_type = MV_TYPE_FIELD;
if (HAS_FORWARD_MV(mb_type)) {
- s->mv_dir = MV_DIR_FORWARD;
+ h->c.mv_dir = MV_DIR_FORWARD;
for (i = 0; i < 2; i++) {
- mx = ff_h263_decode_motion(s, s->last_mv[0][i][0], ctx->f_code);
- my = ff_h263_decode_motion(s, s->last_mv[0][i][1] / 2, ctx->f_code);
- s->last_mv[0][i][0] =
- s->mv[0][i][0] = mx;
- s->last_mv[0][i][1] = (s->mv[0][i][1] = my) * 2;
+ mx = ff_h263_decode_motion(h, h->c.last_mv[0][i][0], ctx->f_code);
+ my = ff_h263_decode_motion(h, h->c.last_mv[0][i][1] / 2, ctx->f_code);
+ h->c.last_mv[0][i][0] =
+ h->c.mv[0][i][0] = mx;
+ h->c.last_mv[0][i][1] = (h->c.mv[0][i][1] = my) * 2;
}
}
if (HAS_BACKWARD_MV(mb_type)) {
- s->mv_dir |= MV_DIR_BACKWARD;
+ h->c.mv_dir |= MV_DIR_BACKWARD;
for (i = 0; i < 2; i++) {
- mx = ff_h263_decode_motion(s, s->last_mv[1][i][0], ctx->b_code);
- my = ff_h263_decode_motion(s, s->last_mv[1][i][1] / 2, ctx->b_code);
- s->last_mv[1][i][0] =
- s->mv[1][i][0] = mx;
- s->last_mv[1][i][1] = (s->mv[1][i][1] = my) * 2;
+ mx = ff_h263_decode_motion(h, h->c.last_mv[1][i][0], ctx->b_code);
+ my = ff_h263_decode_motion(h, h->c.last_mv[1][i][1] / 2, ctx->b_code);
+ h->c.last_mv[1][i][0] =
+ h->c.mv[1][i][0] = mx;
+ h->c.last_mv[1][i][1] = (h->c.mv[1][i][1] = my) * 2;
}
}
}
@@ -2023,53 +2027,53 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
mx =
my = 0;
} else {
- mx = ff_h263_decode_motion(s, 0, 1);
- my = ff_h263_decode_motion(s, 0, 1);
+ mx = ff_h263_decode_motion(h, 0, 1);
+ my = ff_h263_decode_motion(h, 0, 1);
}
- s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
- mb_type |= ff_mpeg4_set_direct_mv(s, mx, my);
+ h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
+ mb_type |= ff_mpeg4_set_direct_mv(&h->c, mx, my);
}
- s->cur_pic.mb_type[xy] = mb_type;
+ h->c.cur_pic.mb_type[xy] = mb_type;
} else { /* I-Frame */
int use_intra_dc_vlc;
do {
- cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "I cbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
} while (cbpc == 8);
dquant = cbpc & 4;
- s->mb_intra = 1;
+ h->c.mb_intra = 1;
intra:
- s->ac_pred = get_bits1(&s->gb);
- if (s->ac_pred)
- s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
+ h->c.ac_pred = get_bits1(&h->c.gb);
+ if (h->c.ac_pred)
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
else
- s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR,
+ "I cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
cbp = (cbpc & 3) | (cbpy << 2);
- use_intra_dc_vlc = s->qscale < ctx->intra_dc_threshold;
+ use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;
if (dquant)
- ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
- if (!s->progressive_sequence)
- s->interlaced_dct = get_bits1(&s->gb);
+ if (!h->c.progressive_sequence)
+ h->c.interlaced_dct = get_bits1(&h->c.gb);
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
/* decode each block */
for (i = 0; i < 6; i++) {
if (mpeg4_decode_block(ctx, block[i], i, cbp & 32,
@@ -2091,18 +2095,18 @@ end:
/* per-MB end of slice check */
next = mpeg4_is_resync(ctx);
if (next) {
- if (s->mb_x + s->mb_y*s->mb_width + 1 > next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
+ if (h->c.mb_x + h->c.mb_y*h->c.mb_width + 1 > next && (h->c.avctx->err_recognition & AV_EF_AGGRESSIVE)) {
return AVERROR_INVALIDDATA;
- } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next)
+ } else if (h->c.mb_x + h->c.mb_y*h->c.mb_width + 1 >= next)
return SLICE_END;
- if (s->pict_type == AV_PICTURE_TYPE_B) {
- const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1;
- ff_thread_progress_await(&s->next_pic.ptr->progress,
- (s->mb_x + delta >= s->mb_width)
- ? FFMIN(s->mb_y + 1, s->mb_height - 1)
- : s->mb_y);
- if (s->next_pic.mbskip_table[xy + delta])
+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
+ const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1;
+ ff_thread_progress_await(&h->c.next_pic.ptr->progress,
+ (h->c.mb_x + delta >= h->c.mb_width)
+ ? FFMIN(h->c.mb_y + 1, h->c.mb_height - 1)
+ : h->c.mb_y);
+ if (h->c.next_pic.mbskip_table[xy + delta])
return SLICE_OK;
}
@@ -2149,19 +2153,19 @@ static const uint8_t ac_state_tab[22][2] =
{0, 11}
};
-static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n)
+static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[64], int n)
{
- Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
+ H263DecContext *const h = &ctx->h;
int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0,
additional_code_len, sign, mismatch;
const VLCElem *cur_vlc = studio_intra_tab[0];
- const uint8_t *const scantable = s->intra_scantable.permutated;
+ const uint8_t *const scantable = h->c.intra_scantable.permutated;
const uint16_t *quant_matrix;
uint32_t flc;
- const int min = -1 * (1 << (s->avctx->bits_per_raw_sample + 6));
- const int max = ((1 << (s->avctx->bits_per_raw_sample + 6)) - 1);
- int shift = 3 - ctx->dct_precision;
+ const int min = -1 * (1 << (h->c.avctx->bits_per_raw_sample + 6));
+ const int max = ((1 << (h->c.avctx->bits_per_raw_sample + 6)) - 1);
+ int shift = 3 - ctx->dct_precision;
mismatch = 1;
@@ -2169,35 +2173,35 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
if (n < 4) {
cc = 0;
- dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
- quant_matrix = s->intra_matrix;
+ dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
+ quant_matrix = h->c.intra_matrix;
} else {
cc = (n & 1) + 1;
if (ctx->rgb)
- dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
else
- dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
- quant_matrix = s->chroma_intra_matrix;
+ dct_dc_size = get_vlc2(&h->c.gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
+ quant_matrix = h->c.chroma_intra_matrix;
}
if (dct_dc_size == 0) {
dct_diff = 0;
} else {
- dct_diff = get_xbits(&s->gb, dct_dc_size);
+ dct_diff = get_xbits(&h->c.gb, dct_dc_size);
if (dct_dc_size > 8) {
- if(!check_marker(s->avctx, &s->gb, "dct_dc_size > 8"))
+ if(!check_marker(h->c.avctx, &h->c.gb, "dct_dc_size > 8"))
return AVERROR_INVALIDDATA;
}
}
- s->last_dc[cc] += dct_diff;
+ h->c.last_dc[cc] += dct_diff;
if (ctx->mpeg_quant)
- block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision);
+ block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision);
else
- block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision) * (8 >> ctx->dct_precision);
+ block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision) * (8 >> ctx->dct_precision);
/* TODO: support mpeg_quant for AC coefficients */
block[0] = av_clip(block[0], min, max);
@@ -2205,10 +2209,10 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
/* AC Coefficients */
while (1) {
- group = get_vlc2(&s->gb, cur_vlc, STUDIO_INTRA_BITS, 2);
+ group = get_vlc2(&h->c.gb, cur_vlc, STUDIO_INTRA_BITS, 2);
if (group < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n");
return AVERROR_INVALIDDATA;
}
@@ -2222,12 +2226,12 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
/* Zero run length (Table B.47) */
run = 1 << additional_code_len;
if (additional_code_len)
- run += get_bits(&s->gb, additional_code_len);
+ run += get_bits(&h->c.gb, additional_code_len);
idx += run;
continue;
} else if (group >= 7 && group <= 12) {
/* Zero run length and +/-1 level (Table B.48) */
- code = get_bits(&s->gb, additional_code_len);
+ code = get_bits(&h->c.gb, additional_code_len);
sign = code & 1;
code >>= 1;
run = (1 << (additional_code_len - 1)) + code;
@@ -2241,20 +2245,20 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
if (idx > 63)
return AVERROR_INVALIDDATA;
j = scantable[idx++];
- block[j] = get_xbits(&s->gb, additional_code_len);
+ block[j] = get_xbits(&h->c.gb, additional_code_len);
} else if (group == 21) {
/* Escape */
if (idx > 63)
return AVERROR_INVALIDDATA;
j = scantable[idx++];
- additional_code_len = s->avctx->bits_per_raw_sample + ctx->dct_precision + 4;
- flc = get_bits(&s->gb, additional_code_len);
+ additional_code_len = h->c.avctx->bits_per_raw_sample + ctx->dct_precision + 4;
+ flc = get_bits(&h->c.gb, additional_code_len);
if (flc >> (additional_code_len-1))
block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
else
block[j] = flc;
}
- block[j] = ((block[j] * quant_matrix[j] * s->qscale) * (1 << shift)) / 16;
+ block[j] = ((block[j] * quant_matrix[j] * h->c.qscale) * (1 << shift)) / 16;
block[j] = av_clip(block[j], min, max);
mismatch ^= block[j];
}
@@ -2267,23 +2271,23 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n
static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
int16_t macroblock[256], int n)
{
- MPVContext *const s = &ctx->m;
- int i, j, w, h, idx = 0;
+ H263DecContext *const h = &ctx->h;
+ int j, w, height, idx = 0;
int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
dpcm_residual, left, top, topleft, min_left_top, max_left_top, p, p2, output;
- h = 16 >> (n ? s->chroma_y_shift : 0);
- w = 16 >> (n ? s->chroma_x_shift : 0);
+ height = 16 >> (n ? h->c.chroma_y_shift : 0);
+ w = 16 >> (n ? h->c.chroma_x_shift : 0);
- block_mean = get_bits(&s->gb, s->avctx->bits_per_raw_sample);
+ block_mean = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample);
if (block_mean == 0){
- av_log(s->avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
return AVERROR_INVALIDDATA;
}
- s->last_dc[n] = block_mean * (1 << (ctx->dct_precision + s->intra_dc_precision));
+ h->c.last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
- rice_parameter = get_bits(&s->gb, 4);
+ rice_parameter = get_bits(&h->c.gb, 4);
if (rice_parameter == 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
return AVERROR_INVALIDDATA;
}
@@ -2291,29 +2295,29 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
rice_parameter = 0;
if (rice_parameter > 11) {
- av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
return AVERROR_INVALIDDATA;
}
- for (i = 0; i < h; i++) {
- output = 1 << (s->avctx->bits_per_raw_sample - 1);
- top = 1 << (s->avctx->bits_per_raw_sample - 1);
+ for (int i = 0; i < height; i++) {
+ output = 1 << (h->c.avctx->bits_per_raw_sample - 1);
+ top = 1 << (h->c.avctx->bits_per_raw_sample - 1);
for (j = 0; j < w; j++) {
left = output;
topleft = top;
- rice_prefix_code = get_unary(&s->gb, 1, 12);
+ rice_prefix_code = get_unary(&h->c.gb, 1, 12);
/* Escape */
if (rice_prefix_code == 11)
- dpcm_residual = get_bits(&s->gb, s->avctx->bits_per_raw_sample);
+ dpcm_residual = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample);
else {
if (rice_prefix_code == 12) {
- av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n");
return AVERROR_INVALIDDATA;
}
- rice_suffix_code = get_bitsz(&s->gb, rice_parameter);
+ rice_suffix_code = get_bitsz(&h->c.gb, rice_parameter);
dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
}
@@ -2342,56 +2346,56 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
if (p2 > p)
dpcm_residual *= -1;
- macroblock[idx++] = output = (dpcm_residual + p) & ((1 << s->avctx->bits_per_raw_sample) - 1);
+ macroblock[idx++] = output = (dpcm_residual + p) & ((1 << h->c.avctx->bits_per_raw_sample) - 1);
}
}
return 0;
}
-static int mpeg4_decode_studio_mb(MpegEncContext *s, int16_t block_[12][64])
+static int mpeg4_decode_studio_mb(H263DecContext *const h, int16_t block_[12][64])
{
- Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
int i;
ctx->dpcm_direction = 0;
/* StudioMacroblock */
/* Assumes I-VOP */
- s->mb_intra = 1;
- if (get_bits1(&s->gb)) { /* compression_mode */
+ h->c.mb_intra = 1;
+ if (get_bits1(&h->c.gb)) { /* compression_mode */
/* DCT */
/* macroblock_type, 1 or 2-bit VLC */
- if (!get_bits1(&s->gb)) {
- skip_bits1(&s->gb);
- s->qscale = mpeg_get_qscale(s);
+ if (!get_bits1(&h->c.gb)) {
+ skip_bits1(&h->c.gb);
+ h->c.qscale = mpeg_get_qscale(&h->c);
}
- for (i = 0; i < mpeg4_block_count[s->chroma_format]; i++) {
- if (mpeg4_decode_studio_block(s, ctx->block32[i], i) < 0)
+ for (i = 0; i < mpeg4_block_count[h->c.chroma_format]; i++) {
+ if (mpeg4_decode_studio_block(ctx, ctx->block32[i], i) < 0)
return AVERROR_INVALIDDATA;
}
} else {
/* DPCM */
- check_marker(s->avctx, &s->gb, "DPCM block start");
- ctx->dpcm_direction = get_bits1(&s->gb) ? -1 : 1;
+ check_marker(h->c.avctx, &h->c.gb, "DPCM block start");
+ ctx->dpcm_direction = get_bits1(&h->c.gb) ? -1 : 1;
for (i = 0; i < 3; i++) {
if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0)
return AVERROR_INVALIDDATA;
}
}
- if (get_bits_left(&s->gb) >= 24 && show_bits(&s->gb, 23) == 0) {
- next_start_code_studio(&s->gb);
+ if (get_bits_left(&h->c.gb) >= 24 && show_bits(&h->c.gb, 23) == 0) {
+ next_start_code_studio(&h->c.gb);
return SLICE_END;
}
//vcon-stp9L1.bits (first frame)
- if (get_bits_left(&s->gb) == 0)
+ if (get_bits_left(&h->c.gb) == 0)
return SLICE_END;
//vcon-stp2L1.bits, vcon-stp3L1.bits, vcon-stp6L1.bits, vcon-stp7L1.bits, vcon-stp8L1.bits, vcon-stp10L1.bits (first frame)
- if (get_bits_left(&s->gb) < 8U && show_bits(&s->gb, get_bits_left(&s->gb)) == 0)
+ if (get_bits_left(&h->c.gb) < 8U && show_bits(&h->c.gb, get_bits_left(&h->c.gb)) == 0)
return SLICE_END;
return SLICE_OK;
@@ -2550,7 +2554,7 @@ static void extension_and_user_data(MpegEncContext *s, GetBitContext *gb, int id
static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
{
- MpegEncContext *s = &ctx->m;
+ MPVContext *const s = &ctx->h.c;
int width, height, aspect_ratio_info;
int bits_per_raw_sample;
int rgb, chroma_format;
@@ -2636,7 +2640,7 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
{
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
int width, height, vo_ver_id, aspect_ratio_info;
/* vol header */
@@ -2650,12 +2654,12 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
*/
if (ctx->vo_type == CORE_STUDIO_VO_TYPE ||
ctx->vo_type == SIMPLE_STUDIO_VO_TYPE) {
- if (s->avctx->profile != AV_PROFILE_UNKNOWN && s->avctx->profile != AV_PROFILE_MPEG4_SIMPLE_STUDIO)
+ if (h->c.avctx->profile != AV_PROFILE_UNKNOWN && h->c.avctx->profile != AV_PROFILE_MPEG4_SIMPLE_STUDIO)
return AVERROR_INVALIDDATA;
- s->studio_profile = 1;
- s->avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO;
+ h->c.studio_profile = 1;
+ h->c.avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO;
return decode_studio_vol_header(ctx, gb);
- } else if (s->studio_profile) {
+ } else if (h->c.studio_profile) {
return AVERROR_PATCHWELCOME;
}
@@ -2667,97 +2671,97 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
}
aspect_ratio_info = get_bits(gb, 4);
if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
- s->avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width
- s->avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height
+ h->c.avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width
+ h->c.avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height
} else {
- s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[aspect_ratio_info];
+ h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[aspect_ratio_info];
}
if ((ctx->vol_control_parameters = get_bits1(gb))) { /* vol control parameter */
int chroma_format = get_bits(gb, 2);
if (chroma_format != CHROMA_420)
- av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal chroma format\n");
- s->low_delay = get_bits1(gb);
+ h->c.low_delay = get_bits1(gb);
if (get_bits1(gb)) { /* vbv parameters */
get_bits(gb, 15); /* first_half_bitrate */
- check_marker(s->avctx, gb, "after first_half_bitrate");
+ check_marker(h->c.avctx, gb, "after first_half_bitrate");
get_bits(gb, 15); /* latter_half_bitrate */
- check_marker(s->avctx, gb, "after latter_half_bitrate");
+ check_marker(h->c.avctx, gb, "after latter_half_bitrate");
get_bits(gb, 15); /* first_half_vbv_buffer_size */
- check_marker(s->avctx, gb, "after first_half_vbv_buffer_size");
+ check_marker(h->c.avctx, gb, "after first_half_vbv_buffer_size");
get_bits(gb, 3); /* latter_half_vbv_buffer_size */
get_bits(gb, 11); /* first_half_vbv_occupancy */
- check_marker(s->avctx, gb, "after first_half_vbv_occupancy");
+ check_marker(h->c.avctx, gb, "after first_half_vbv_occupancy");
get_bits(gb, 15); /* latter_half_vbv_occupancy */
- check_marker(s->avctx, gb, "after latter_half_vbv_occupancy");
+ check_marker(h->c.avctx, gb, "after latter_half_vbv_occupancy");
}
} else {
/* is setting low delay flag only once the smartest thing to do?
* low delay detection will not be overridden. */
- if (s->picture_number == 0) {
+ if (h->c.picture_number == 0) {
switch (ctx->vo_type) {
case SIMPLE_VO_TYPE:
case ADV_SIMPLE_VO_TYPE:
- s->low_delay = 1;
+ h->c.low_delay = 1;
break;
default:
- s->low_delay = 0;
+ h->c.low_delay = 0;
}
}
}
ctx->shape = get_bits(gb, 2); /* vol shape */
if (ctx->shape != RECT_SHAPE)
- av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "only rectangular vol supported\n");
if (ctx->shape == GRAY_SHAPE && vo_ver_id != 1) {
- av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Gray shape not supported\n");
skip_bits(gb, 4); /* video_object_layer_shape_extension */
}
- check_marker(s->avctx, gb, "before time_increment_resolution");
+ check_marker(h->c.avctx, gb, "before time_increment_resolution");
- s->avctx->framerate.num = get_bits(gb, 16);
- if (!s->avctx->framerate.num) {
- av_log(s->avctx, AV_LOG_ERROR, "framerate==0\n");
+ h->c.avctx->framerate.num = get_bits(gb, 16);
+ if (!h->c.avctx->framerate.num) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "framerate==0\n");
return AVERROR_INVALIDDATA;
}
- ctx->time_increment_bits = av_log2(s->avctx->framerate.num - 1) + 1;
+ ctx->time_increment_bits = av_log2(h->c.avctx->framerate.num - 1) + 1;
if (ctx->time_increment_bits < 1)
ctx->time_increment_bits = 1;
- check_marker(s->avctx, gb, "before fixed_vop_rate");
+ check_marker(h->c.avctx, gb, "before fixed_vop_rate");
if (get_bits1(gb) != 0) /* fixed_vop_rate */
- s->avctx->framerate.den = get_bits(gb, ctx->time_increment_bits);
+ h->c.avctx->framerate.den = get_bits(gb, ctx->time_increment_bits);
else
- s->avctx->framerate.den = 1;
+ h->c.avctx->framerate.den = 1;
ctx->t_frame = 0;
if (ctx->shape != BIN_ONLY_SHAPE) {
if (ctx->shape == RECT_SHAPE) {
- check_marker(s->avctx, gb, "before width");
+ check_marker(h->c.avctx, gb, "before width");
width = get_bits(gb, 13);
- check_marker(s->avctx, gb, "before height");
+ check_marker(h->c.avctx, gb, "before height");
height = get_bits(gb, 13);
- check_marker(s->avctx, gb, "after height");
+ check_marker(h->c.avctx, gb, "after height");
if (width && height && /* they should be non zero but who knows */
- !(s->width && s->codec_tag == AV_RL32("MP4S"))) {
- if (s->width && s->height &&
- (s->width != width || s->height != height))
- s->context_reinit = 1;
- s->width = width;
- s->height = height;
+ !(h->c.width && h->c.codec_tag == AV_RL32("MP4S"))) {
+ if (h->c.width && h->c.height &&
+ (h->c.width != width || h->c.height != height))
+ h->c.context_reinit = 1;
+ h->c.width = width;
+ h->c.height = height;
}
}
- s->progressive_sequence =
- s->progressive_frame = get_bits1(gb) ^ 1;
- s->interlaced_dct = 0;
- if (!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO))
- av_log(s->avctx, AV_LOG_INFO, /* OBMC Disable */
+ h->c.progressive_sequence =
+ h->c.progressive_frame = get_bits1(gb) ^ 1;
+ h->c.interlaced_dct = 0;
+ if (!get_bits1(gb) && (h->c.avctx->debug & FF_DEBUG_PICT_INFO))
+ av_log(h->c.avctx, AV_LOG_INFO, /* OBMC Disable */
"MPEG-4 OBMC not supported (very likely buggy encoder)\n");
if (vo_ver_id == 1)
ctx->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */
@@ -2765,22 +2769,22 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
ctx->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */
if (ctx->vol_sprite_usage == STATIC_SPRITE)
- av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Static Sprites not supported\n");
if (ctx->vol_sprite_usage == STATIC_SPRITE ||
ctx->vol_sprite_usage == GMC_SPRITE) {
if (ctx->vol_sprite_usage == STATIC_SPRITE) {
skip_bits(gb, 13); // sprite_width
- check_marker(s->avctx, gb, "after sprite_width");
+ check_marker(h->c.avctx, gb, "after sprite_width");
skip_bits(gb, 13); // sprite_height
- check_marker(s->avctx, gb, "after sprite_height");
+ check_marker(h->c.avctx, gb, "after sprite_height");
skip_bits(gb, 13); // sprite_left
- check_marker(s->avctx, gb, "after sprite_left");
+ check_marker(h->c.avctx, gb, "after sprite_left");
skip_bits(gb, 13); // sprite_top
- check_marker(s->avctx, gb, "after sprite_top");
+ check_marker(h->c.avctx, gb, "after sprite_top");
}
ctx->num_sprite_warping_points = get_bits(gb, 6);
if (ctx->num_sprite_warping_points > 3) {
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"%d sprite_warping_points\n",
ctx->num_sprite_warping_points);
ctx->num_sprite_warping_points = 0;
@@ -2796,9 +2800,9 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
if (get_bits1(gb) == 1) { /* not_8_bit */
ctx->quant_precision = get_bits(gb, 4); /* quant_precision */
if (get_bits(gb, 4) != 8) /* bits_per_pixel */
- av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "N-bit not supported\n");
if (ctx->quant_precision != 5)
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"quant precision %d\n", ctx->quant_precision);
if (ctx->quant_precision < 3 || ctx->quant_precision > 9)
ctx->quant_precision = 5;
@@ -2811,7 +2815,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
if ((ctx->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */
int i, v;
- mpeg4_load_default_matrices(s);
+ mpeg4_load_default_matrices(&h->c);
/* load custom intra matrix */
if (get_bits1(gb)) {
@@ -2819,7 +2823,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
for (i = 0; i < 64; i++) {
int j;
if (get_bits_left(gb) < 8) {
- av_log(s->avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
return AVERROR_INVALIDDATA;
}
v = get_bits(gb, 8);
@@ -2827,14 +2831,14 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
break;
last = v;
- j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
- s->intra_matrix[j] = last;
+ j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
+ h->c.intra_matrix[j] = last;
}
/* replicate last value */
for (; i < 64; i++) {
- int j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
- s->intra_matrix[j] = last;
+ int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
+ h->c.intra_matrix[j] = last;
}
}
@@ -2844,7 +2848,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
for (i = 0; i < 64; i++) {
int j;
if (get_bits_left(gb) < 8) {
- av_log(s->avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
return AVERROR_INVALIDDATA;
}
v = get_bits(gb, 8);
@@ -2852,14 +2856,14 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
break;
last = v;
- j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
- s->inter_matrix[j] = v;
+ j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
+ h->c.inter_matrix[j] = v;
}
/* replicate last value */
for (; i < 64; i++) {
- int j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
- s->inter_matrix[j] = last;
+ int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
+ h->c.inter_matrix[j] = last;
}
}
@@ -2867,12 +2871,12 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
}
if (vo_ver_id != 1)
- s->quarter_sample = get_bits1(gb);
+ h->c.quarter_sample = get_bits1(gb);
else
- s->quarter_sample = 0;
+ h->c.quarter_sample = 0;
if (get_bits_left(gb) < 4) {
- av_log(s->avctx, AV_LOG_ERROR, "VOL Header truncated\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "VOL Header truncated\n");
return AVERROR_INVALIDDATA;
}
@@ -2894,7 +2898,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter4v_blocks */
ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* not coded blocks */
}
- if (!check_marker(s->avctx, gb, "in complexity estimation part 1")) {
+ if (!check_marker(h->c.avctx, gb, "in complexity estimation part 1")) {
skip_bits_long(gb, pos - get_bits_count(gb));
goto no_cplx_est;
}
@@ -2912,7 +2916,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel2 */
ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel4 */
}
- if (!check_marker(s->avctx, gb, "in complexity estimation part 2")) {
+ if (!check_marker(h->c.avctx, gb, "in complexity estimation part 2")) {
skip_bits_long(gb, pos - get_bits_count(gb));
goto no_cplx_est;
}
@@ -2921,7 +2925,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* qpel */
}
} else
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"Invalid Complexity estimation method %d\n",
estimation_method);
} else {
@@ -2934,19 +2938,19 @@ no_cplx_est:
ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */
- s->data_partitioning = get_bits1(gb);
- if (s->data_partitioning)
+ h->c.data_partitioning = get_bits1(gb);
+ if (h->c.data_partitioning)
ctx->rvlc = get_bits1(gb);
if (vo_ver_id != 1) {
ctx->new_pred = get_bits1(gb);
if (ctx->new_pred) {
- av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "new pred not supported\n");
skip_bits(gb, 2); /* requested upstream message type */
skip_bits1(gb); /* newpred segment type */
}
if (get_bits1(gb)) // reduced_res_vop
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"reduced resolution VOP not supported\n");
} else {
ctx->new_pred = 0;
@@ -2977,21 +2981,23 @@ no_cplx_est:
ctx->scalability = 0;
*gb = bak;
} else
- av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "scalability not supported\n");
// bin shape stuff FIXME
}
}
- if (s->avctx->debug&FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n",
- s->avctx->framerate.den, s->avctx->framerate.num,
+ if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {
+ av_log(h->c.avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n",
+ h->c.avctx->framerate.den, h->c.avctx->framerate.num,
ctx->time_increment_bits,
ctx->quant_precision,
- s->progressive_sequence,
- s->low_delay,
- ctx->scalability ? "scalability " :"" , s->quarter_sample ? "qpel " : "",
- s->data_partitioning ? "partition " : "", ctx->rvlc ? "rvlc " : ""
+ h->c.progressive_sequence,
+ h->c.low_delay,
+ ctx->scalability ? "scalability " :"" ,
+ h->c.quarter_sample ? "qpel " : "",
+ h->c.data_partitioning ? "partition " : "",
+ ctx->rvlc ? "rvlc " : ""
);
}
@@ -3004,7 +3010,7 @@ no_cplx_est:
*/
static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
{
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
char buf[256];
int i;
int e;
@@ -3025,7 +3031,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
if (e >= 2) {
ctx->divx_version = ver;
ctx->divx_build = build;
- s->divx_packed = e == 3 && last == 'p';
+ h->c.divx_packed = e == 3 && last == 'p';
}
/* libavcodec detection */
@@ -3036,7 +3042,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
e = sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
if (e > 1) {
if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) {
- av_log(s->avctx, AV_LOG_WARNING,
+ av_log(h->c.avctx, AV_LOG_WARNING,
"Unknown Lavc version string encountered, %d.%d.%d; "
"clamping sub-version values to 8-bits.\n",
ver, ver2, ver3);
@@ -3091,19 +3097,19 @@ static av_cold void switch_to_xvid_idct(AVCodecContext *const avctx,
void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
{
Mpeg4DecContext *ctx = avctx->priv_data;
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) {
- if (s->codec_tag == AV_RL32("XVID") ||
- s->codec_tag == AV_RL32("XVIX") ||
- s->codec_tag == AV_RL32("RMP4") ||
- s->codec_tag == AV_RL32("ZMP4") ||
- s->codec_tag == AV_RL32("SIPP"))
+ if (h->c.codec_tag == AV_RL32("XVID") ||
+ h->c.codec_tag == AV_RL32("XVIX") ||
+ h->c.codec_tag == AV_RL32("RMP4") ||
+ h->c.codec_tag == AV_RL32("ZMP4") ||
+ h->c.codec_tag == AV_RL32("SIPP"))
ctx->xvid_build = 0;
}
if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1)
- if (s->codec_tag == AV_RL32("DIVX") && ctx->vo_type == 0 &&
+ if (h->c.codec_tag == AV_RL32("DIVX") && ctx->vo_type == 0 &&
ctx->vol_control_parameters == 0)
ctx->divx_version = 400; // divx 4
@@ -3112,68 +3118,68 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
ctx->divx_build = -1;
}
- if (s->workaround_bugs & FF_BUG_AUTODETECT) {
- if (s->codec_tag == AV_RL32("XVIX"))
- s->workaround_bugs |= FF_BUG_XVID_ILACE;
+ if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
+ if (h->c.codec_tag == AV_RL32("XVIX"))
+ h->c.workaround_bugs |= FF_BUG_XVID_ILACE;
- if (s->codec_tag == AV_RL32("UMP4"))
- s->workaround_bugs |= FF_BUG_UMP4;
+ if (h->c.codec_tag == AV_RL32("UMP4"))
+ h->c.workaround_bugs |= FF_BUG_UMP4;
if (ctx->divx_version >= 500 && ctx->divx_build < 1814)
- s->workaround_bugs |= FF_BUG_QPEL_CHROMA;
+ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA;
if (ctx->divx_version > 502 && ctx->divx_build < 1814)
- s->workaround_bugs |= FF_BUG_QPEL_CHROMA2;
+ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA2;
if (ctx->xvid_build <= 3U)
- s->padding_bug_score = 256 * 256 * 256 * 64;
+ h->c.padding_bug_score = 256 * 256 * 256 * 64;
if (ctx->xvid_build <= 1U)
- s->workaround_bugs |= FF_BUG_QPEL_CHROMA;
+ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA;
if (ctx->xvid_build <= 12U)
- s->workaround_bugs |= FF_BUG_EDGE;
+ h->c.workaround_bugs |= FF_BUG_EDGE;
if (ctx->xvid_build <= 32U)
- s->workaround_bugs |= FF_BUG_DC_CLIP;
+ h->c.workaround_bugs |= FF_BUG_DC_CLIP;
#define SET_QPEL_FUNC(postfix1, postfix2) \
- s->qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
- s->qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
- s->qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
+ h->c.qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
+ h->c.qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
+ h->c.qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
if (ctx->lavc_build < 4653U)
- s->workaround_bugs |= FF_BUG_STD_QPEL;
+ h->c.workaround_bugs |= FF_BUG_STD_QPEL;
if (ctx->lavc_build < 4655U)
- s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
+ h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
if (ctx->lavc_build < 4670U)
- s->workaround_bugs |= FF_BUG_EDGE;
+ h->c.workaround_bugs |= FF_BUG_EDGE;
if (ctx->lavc_build <= 4712U)
- s->workaround_bugs |= FF_BUG_DC_CLIP;
+ h->c.workaround_bugs |= FF_BUG_DC_CLIP;
if ((ctx->lavc_build&0xFF) >= 100) {
if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752552 &&
(ctx->lavc_build < 3752037 || ctx->lavc_build > 3752191) // 3.2.1+
)
- s->workaround_bugs |= FF_BUG_IEDGE;
+ h->c.workaround_bugs |= FF_BUG_IEDGE;
}
if (ctx->divx_version >= 0)
- s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
+ h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
if (ctx->divx_version == 501 && ctx->divx_build == 20020416)
- s->padding_bug_score = 256 * 256 * 256 * 64;
+ h->c.padding_bug_score = 256 * 256 * 256 * 64;
if (ctx->divx_version < 500U)
- s->workaround_bugs |= FF_BUG_EDGE;
+ h->c.workaround_bugs |= FF_BUG_EDGE;
if (ctx->divx_version >= 0)
- s->workaround_bugs |= FF_BUG_HPEL_CHROMA;
+ h->c.workaround_bugs |= FF_BUG_HPEL_CHROMA;
}
- if (s->workaround_bugs & FF_BUG_STD_QPEL) {
+ if (h->c.workaround_bugs & FF_BUG_STD_QPEL) {
SET_QPEL_FUNC(qpel_pixels_tab[0][5], qpel16_mc11_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][7], qpel16_mc31_old_c)
SET_QPEL_FUNC(qpel_pixels_tab[0][9], qpel16_mc12_old_c)
@@ -3190,54 +3196,54 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
}
if (avctx->debug & FF_DEBUG_BUGS)
- av_log(s->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",
- s->workaround_bugs, ctx->lavc_build, ctx->xvid_build,
- ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : "");
+ h->c.workaround_bugs, ctx->lavc_build, ctx->xvid_build,
+ ctx->divx_version, ctx->divx_build, h->c.divx_packed ? "p" : "");
if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 &&
- avctx->idct_algo == FF_IDCT_AUTO && !s->studio_profile) {
- switch_to_xvid_idct(avctx, s);
+ avctx->idct_algo == FF_IDCT_AUTO && !h->c.studio_profile) {
+ switch_to_xvid_idct(avctx, &h->c);
}
}
static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
int parse_only)
{
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
int time_incr, time_increment;
int64_t pts;
- s->mcsel = 0;
- s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */
- if (s->pict_type == AV_PICTURE_TYPE_B && s->low_delay &&
- ctx->vol_control_parameters == 0 && !(s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) {
- av_log(s->avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n");
- s->low_delay = 0;
+ h->c.mcsel = 0;
+ h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */
+ if (h->c.pict_type == AV_PICTURE_TYPE_B && h->c.low_delay &&
+ ctx->vol_control_parameters == 0 && !(h->c.avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n");
+ h->c.low_delay = 0;
}
- s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B;
- if (s->partitioned_frame)
- s->decode_mb = mpeg4_decode_partitioned_mb;
+ h->c.partitioned_frame = h->c.data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B;
+ if (h->c.partitioned_frame)
+ h->decode_mb = mpeg4_decode_partitioned_mb;
else
- s->decode_mb = mpeg4_decode_mb;
+ h->decode_mb = mpeg4_decode_mb;
time_incr = 0;
while (get_bits1(gb) != 0)
time_incr++;
- check_marker(s->avctx, gb, "before time_increment");
+ check_marker(h->c.avctx, gb, "before time_increment");
if (ctx->time_increment_bits == 0 ||
!(show_bits(gb, ctx->time_increment_bits + 1) & 1)) {
- av_log(s->avctx, AV_LOG_WARNING,
+ av_log(h->c.avctx, AV_LOG_WARNING,
"time_increment_bits %d is invalid in relation to the current bitstream, this is likely caused by a missing VOL header\n", ctx->time_increment_bits);
for (ctx->time_increment_bits = 1;
ctx->time_increment_bits < 16;
ctx->time_increment_bits++) {
- if (s->pict_type == AV_PICTURE_TYPE_P ||
- (s->pict_type == AV_PICTURE_TYPE_S &&
+ if (h->c.pict_type == AV_PICTURE_TYPE_P ||
+ (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE)) {
if ((show_bits(gb, ctx->time_increment_bits + 6) & 0x37) == 0x30)
break;
@@ -3245,7 +3251,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
break;
}
- av_log(s->avctx, AV_LOG_WARNING,
+ av_log(h->c.avctx, AV_LOG_WARNING,
"time_increment_bits set to %d bits, based on bitstream analysis\n", ctx->time_increment_bits);
}
@@ -3254,84 +3260,84 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
else
time_increment = get_bits(gb, ctx->time_increment_bits);
- if (s->pict_type != AV_PICTURE_TYPE_B) {
- s->last_time_base = s->time_base;
- s->time_base += time_incr;
- s->time = s->time_base * (int64_t)s->avctx->framerate.num + time_increment;
- if (s->workaround_bugs & FF_BUG_UMP4) {
- if (s->time < s->last_non_b_time) {
+ if (h->c.pict_type != AV_PICTURE_TYPE_B) {
+ h->c.last_time_base = h->c.time_base;
+ h->c.time_base += time_incr;
+ h->c.time = h->c.time_base * (int64_t)h->c.avctx->framerate.num + time_increment;
+ if (h->c.workaround_bugs & FF_BUG_UMP4) {
+ if (h->c.time < h->c.last_non_b_time) {
/* header is not mpeg-4-compatible, broken encoder,
* trying to workaround */
- s->time_base++;
- s->time += s->avctx->framerate.num;
+ h->c.time_base++;
+ h->c.time += h->c.avctx->framerate.num;
}
}
- s->pp_time = s->time - s->last_non_b_time;
- s->last_non_b_time = s->time;
+ h->c.pp_time = h->c.time - h->c.last_non_b_time;
+ h->c.last_non_b_time = h->c.time;
} else {
- s->time = (s->last_time_base + time_incr) * (int64_t)s->avctx->framerate.num + time_increment;
- s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
- if (s->pp_time <= s->pb_time ||
- s->pp_time <= s->pp_time - s->pb_time ||
- s->pp_time <= 0) {
+ h->c.time = (h->c.last_time_base + time_incr) * (int64_t)h->c.avctx->framerate.num + time_increment;
+ h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
+ if (h->c.pp_time <= h->c.pb_time ||
+ h->c.pp_time <= h->c.pp_time - h->c.pb_time ||
+ h->c.pp_time <= 0) {
/* messed up order, maybe after seeking? skipping current B-frame */
return FRAME_SKIPPED;
}
- ff_mpeg4_init_direct_mv(s);
+ ff_mpeg4_init_direct_mv(&h->c);
if (ctx->t_frame == 0)
- ctx->t_frame = s->pb_time;
+ ctx->t_frame = h->c.pb_time;
if (ctx->t_frame == 0)
ctx->t_frame = 1; // 1/0 protection
- s->pp_field_time = (ROUNDED_DIV(s->last_non_b_time, ctx->t_frame) -
- ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2;
- s->pb_field_time = (ROUNDED_DIV(s->time, ctx->t_frame) -
- ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2;
- if (s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1) {
- s->pb_field_time = 2;
- s->pp_field_time = 4;
- if (!s->progressive_sequence)
+ h->c.pp_field_time = (ROUNDED_DIV(h->c.last_non_b_time, ctx->t_frame) -
+ ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2;
+ h->c.pb_field_time = (ROUNDED_DIV(h->c.time, ctx->t_frame) -
+ ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2;
+ if (h->c.pp_field_time <= h->c.pb_field_time || h->c.pb_field_time <= 1) {
+ h->c.pb_field_time = 2;
+ h->c.pp_field_time = 4;
+ if (!h->c.progressive_sequence)
return FRAME_SKIPPED;
}
}
- if (s->avctx->framerate.den)
- pts = ROUNDED_DIV(s->time, s->avctx->framerate.den);
+ if (h->c.avctx->framerate.den)
+ pts = ROUNDED_DIV(h->c.time, h->c.avctx->framerate.den);
else
pts = AV_NOPTS_VALUE;
- ff_dlog(s->avctx, "MPEG4 PTS: %"PRId64"\n", pts);
+ ff_dlog(h->c.avctx, "MPEG4 PTS: %"PRId64"\n", pts);
- check_marker(s->avctx, gb, "before vop_coded");
+ check_marker(h->c.avctx, gb, "before vop_coded");
/* vop coded */
if (get_bits1(gb) != 1) {
- if (s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n");
- s->skipped_last_frame = 1;
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(h->c.avctx, AV_LOG_ERROR, "vop not coded\n");
+ h->c.skipped_last_frame = 1;
return FRAME_SKIPPED;
}
if (ctx->new_pred)
decode_new_pred(ctx, gb);
if (ctx->shape != BIN_ONLY_SHAPE &&
- (s->pict_type == AV_PICTURE_TYPE_P ||
- (s->pict_type == AV_PICTURE_TYPE_S &&
+ (h->c.pict_type == AV_PICTURE_TYPE_P ||
+ (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE))) {
/* rounding type for motion estimation */
- s->no_rounding = get_bits1(gb);
+ h->c.no_rounding = get_bits1(gb);
} else {
- s->no_rounding = 0;
+ h->c.no_rounding = 0;
}
// FIXME reduced res stuff
if (ctx->shape != RECT_SHAPE) {
- if (ctx->vol_sprite_usage != 1 || s->pict_type != AV_PICTURE_TYPE_I) {
+ if (ctx->vol_sprite_usage != 1 || h->c.pict_type != AV_PICTURE_TYPE_I) {
skip_bits(gb, 13); /* width */
- check_marker(s->avctx, gb, "after width");
+ check_marker(h->c.avctx, gb, "after width");
skip_bits(gb, 13); /* height */
- check_marker(s->avctx, gb, "after height");
+ check_marker(h->c.avctx, gb, "after height");
skip_bits(gb, 13); /* hor_spat_ref */
- check_marker(s->avctx, gb, "after hor_spat_ref");
+ check_marker(h->c.avctx, gb, "after hor_spat_ref");
skip_bits(gb, 13); /* ver_spat_ref */
}
skip_bits1(gb); /* change_CR_disable */
@@ -3344,21 +3350,21 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
if (ctx->shape != BIN_ONLY_SHAPE) {
skip_bits_long(gb, ctx->cplx_estimation_trash_i);
- if (s->pict_type != AV_PICTURE_TYPE_I)
+ if (h->c.pict_type != AV_PICTURE_TYPE_I)
skip_bits_long(gb, ctx->cplx_estimation_trash_p);
- if (s->pict_type == AV_PICTURE_TYPE_B)
+ if (h->c.pict_type == AV_PICTURE_TYPE_B)
skip_bits_long(gb, ctx->cplx_estimation_trash_b);
if (get_bits_left(gb) < 3) {
- av_log(s->avctx, AV_LOG_ERROR, "Header truncated\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "Header truncated\n");
return AVERROR_INVALIDDATA;
}
ctx->intra_dc_threshold = ff_mpeg4_dc_threshold[get_bits(gb, 3)];
- if (!s->progressive_sequence) {
- s->top_field_first = get_bits1(gb);
- s->alternate_scan = get_bits1(gb);
+ if (!h->c.progressive_sequence) {
+ h->c.top_field_first = get_bits1(gb);
+ h->c.alternate_scan = get_bits1(gb);
} else
- s->alternate_scan = 0;
+ h->c.alternate_scan = 0;
}
/* Skip at this point when only parsing since the remaining
* data is not useful for a parser and requires the
@@ -3366,28 +3372,28 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
if (parse_only)
goto end;
- if (s->alternate_scan) {
- ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);
- ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_vertical_scan,
- s->idsp.idct_permutation);
+ if (h->c.alternate_scan) {
+ ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_alternate_vertical_scan);
+ ff_permute_scantable(h->c.permutated_intra_h_scantable, ff_alternate_vertical_scan,
+ h->c.idsp.idct_permutation);
} else {
- ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
- ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_horizontal_scan,
- s->idsp.idct_permutation);
+ ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_zigzag_direct);
+ ff_permute_scantable(h->c.permutated_intra_h_scantable, ff_alternate_horizontal_scan,
+ h->c.idsp.idct_permutation);
}
- ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
- s->idsp.idct_permutation);
+ ff_permute_scantable(h->c.permutated_intra_v_scantable, ff_alternate_vertical_scan,
+ h->c.idsp.idct_permutation);
- if (s->pict_type == AV_PICTURE_TYPE_S) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_S) {
if((ctx->vol_sprite_usage == STATIC_SPRITE ||
ctx->vol_sprite_usage == GMC_SPRITE)) {
if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0)
return AVERROR_INVALIDDATA;
if (ctx->sprite_brightness_change)
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"sprite_brightness_change not supported\n");
if (ctx->vol_sprite_usage == STATIC_SPRITE)
- av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "static sprite not supported\n");
} else {
memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset));
memset(ctx->sprite_delta, 0, sizeof(ctx->sprite_delta));
@@ -3397,102 +3403,102 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
ctx->f_code = 1;
ctx->b_code = 1;
if (ctx->shape != BIN_ONLY_SHAPE) {
- s->chroma_qscale = s->qscale = get_bits(gb, ctx->quant_precision);
- if (s->qscale == 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ h->c.chroma_qscale = h->c.qscale = get_bits(gb, ctx->quant_precision);
+ if (h->c.qscale == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR,
"Error, header damaged or not MPEG-4 header (qscale=0)\n");
return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then
}
- if (s->pict_type != AV_PICTURE_TYPE_I) {
+ if (h->c.pict_type != AV_PICTURE_TYPE_I) {
ctx->f_code = get_bits(gb, 3); /* fcode_for */
if (ctx->f_code == 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"Error, header damaged or not MPEG-4 header (f_code=0)\n");
ctx->f_code = 1;
return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then
}
}
- if (s->pict_type == AV_PICTURE_TYPE_B) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
ctx->b_code = get_bits(gb, 3);
if (ctx->b_code == 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"Error, header damaged or not MPEG4 header (b_code=0)\n");
ctx->b_code=1;
return AVERROR_INVALIDDATA; // makes no sense to continue, as the MV decoding will break very quickly
}
}
- if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_DEBUG,
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
+ av_log(h->c.avctx, AV_LOG_DEBUG,
"qp:%d fc:%d,%d %c size:%d pro:%d alt:%d top:%d %cpel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64" tincr:%d\n",
- s->qscale, ctx->f_code, ctx->b_code,
- s->pict_type == AV_PICTURE_TYPE_I ? 'I' : (s->pict_type == AV_PICTURE_TYPE_P ? 'P' : (s->pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')),
- gb->size_in_bits,s->progressive_sequence, s->alternate_scan,
- s->top_field_first, s->quarter_sample ? 'q' : 'h',
- s->data_partitioning, ctx->resync_marker,
+ h->c.qscale, ctx->f_code, ctx->b_code,
+ h->c.pict_type == AV_PICTURE_TYPE_I ? 'I' : (h->c.pict_type == AV_PICTURE_TYPE_P ? 'P' : (h->c.pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')),
+ gb->size_in_bits,h->c.progressive_sequence, h->c.alternate_scan,
+ h->c.top_field_first, h->c.quarter_sample ? 'q' : 'h',
+ h->c.data_partitioning, ctx->resync_marker,
ctx->num_sprite_warping_points, ctx->sprite_warping_accuracy,
- 1 - s->no_rounding, ctx->vo_type,
+ 1 - h->c.no_rounding, ctx->vo_type,
ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold,
ctx->cplx_estimation_trash_i, ctx->cplx_estimation_trash_p,
ctx->cplx_estimation_trash_b,
- s->time,
+ h->c.time,
time_increment
);
}
if (!ctx->scalability) {
- if (ctx->shape != RECT_SHAPE && s->pict_type != AV_PICTURE_TYPE_I)
+ if (ctx->shape != RECT_SHAPE && h->c.pict_type != AV_PICTURE_TYPE_I)
skip_bits1(gb); // vop shape coding type
} else {
if (ctx->enhancement_type) {
int load_backward_shape = get_bits1(gb);
if (load_backward_shape)
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"load backward shape isn't supported\n");
}
skip_bits(gb, 2); // ref_select_code
}
}
- s->dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
- : ctx->dct_unquantize_h263_intra;
+ h->c.dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
+ : ctx->dct_unquantize_h263_intra;
// The following tells ff_mpv_reconstruct_mb() to unquantize iff mpeg_quant
- s->dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
+ h->c.dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
end:
/* detect buggy encoders which don't set the low_delay flag
* (divx4/xvid/opendivx). Note we cannot detect divx5 without B-frames
* easily (although it's buggy too) */
if (ctx->vo_type == 0 && ctx->vol_control_parameters == 0 &&
- ctx->divx_version == -1 && s->picture_number == 0) {
- av_log(s->avctx, AV_LOG_WARNING,
+ ctx->divx_version == -1 && h->c.picture_number == 0) {
+ av_log(h->c.avctx, AV_LOG_WARNING,
"looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
- s->low_delay = 1;
+ h->c.low_delay = 1;
}
- s->picture_number++; // better than pic number==0 always ;)
+ h->c.picture_number++; // better than pic number==0 always ;)
- if (s->workaround_bugs & FF_BUG_EDGE) {
- s->h_edge_pos = s->width;
- s->v_edge_pos = s->height;
+ if (h->c.workaround_bugs & FF_BUG_EDGE) {
+ h->c.h_edge_pos = h->c.width;
+ h->c.v_edge_pos = h->c.height;
}
return 0;
}
static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb)
{
- MpegEncContext *s = &ctx->m;
+ AVCodecContext *const avctx = ctx->h.c.avctx;
skip_bits(gb, 16); /* Time_code[63..48] */
- check_marker(s->avctx, gb, "after Time_code[63..48]");
+ check_marker(avctx, gb, "after Time_code[63..48]");
skip_bits(gb, 16); /* Time_code[47..32] */
- check_marker(s->avctx, gb, "after Time_code[47..32]");
+ check_marker(avctx, gb, "after Time_code[47..32]");
skip_bits(gb, 16); /* Time_code[31..16] */
- check_marker(s->avctx, gb, "after Time_code[31..16]");
+ check_marker(avctx, gb, "after Time_code[31..16]");
skip_bits(gb, 16); /* Time_code[15..0] */
- check_marker(s->avctx, gb, "after Time_code[15..0]");
+ check_marker(avctx, gb, "after Time_code[15..0]");
skip_bits(gb, 4); /* reserved_bits */
}
@@ -3502,64 +3508,63 @@ static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb)
*/
static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
{
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
if (get_bits_left(gb) <= 32)
return 0;
- s->partitioned_frame = 0;
- s->interlaced_dct = 0;
- s->decode_mb = mpeg4_decode_studio_mb;
+ h->c.partitioned_frame = 0;
+ h->c.interlaced_dct = 0;
+ h->decode_mb = mpeg4_decode_studio_mb;
decode_smpte_tc(ctx, gb);
skip_bits(gb, 10); /* temporal_reference */
skip_bits(gb, 2); /* vop_structure */
- s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */
+ h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */
if (get_bits1(gb)) { /* vop_coded */
skip_bits1(gb); /* top_field_first */
skip_bits1(gb); /* repeat_first_field */
- s->progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */
+ h->c.progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */
}
- if (s->pict_type == AV_PICTURE_TYPE_I) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
if (get_bits1(gb))
reset_studio_dc_predictors(ctx);
}
if (ctx->shape != BIN_ONLY_SHAPE) {
- s->alternate_scan = get_bits1(gb);
- s->frame_pred_frame_dct = get_bits1(gb);
- ctx->dct_precision = get_bits(gb, 2);
- s->intra_dc_precision = get_bits(gb, 2);
- s->q_scale_type = get_bits1(gb);
+ h->c.alternate_scan = get_bits1(gb);
+ h->c.frame_pred_frame_dct = get_bits1(gb);
+ ctx->dct_precision = get_bits(gb, 2);
+ h->c.intra_dc_precision = get_bits(gb, 2);
+ h->c.q_scale_type = get_bits1(gb);
}
- ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable,
- s->alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct);
+ ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable,
+ h->c.alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct);
- mpeg4_load_default_matrices(s);
+ mpeg4_load_default_matrices(&h->c);
next_start_code_studio(gb);
- extension_and_user_data(s, gb, 4);
+ extension_and_user_data(&h->c, gb, 4);
return 0;
}
static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
{
- MpegEncContext *s = &ctx->m;
int visual_object_type;
skip_bits(gb, 4); /* visual_object_verid */
visual_object_type = get_bits(gb, 4);
if (visual_object_type != VOT_VIDEO_ID) {
- avpriv_request_sample(s->avctx, "VO type %u", visual_object_type);
+ avpriv_request_sample(ctx->h.c.avctx, "VO type %u", visual_object_type);
return AVERROR_PATCHWELCOME;
}
next_start_code_studio(gb);
- extension_and_user_data(s, gb, 1);
+ extension_and_user_data(&ctx->h.c, gb, 1);
return 0;
}
@@ -3577,7 +3582,7 @@ static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
int header, int parse_only)
{
- MpegEncContext *s = &ctx->m;
+ MPVContext *const s = &ctx->h.c;
unsigned startcode, v;
int ret;
int vol = 0;
@@ -3731,22 +3736,22 @@ end:
return decode_vop_header(ctx, gb, parse_only);
}
-int ff_mpeg4_decode_picture_header(MpegEncContext *s)
+int ff_mpeg4_decode_picture_header(H263DecContext *const h)
{
- Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
- s->skipped_last_frame = 0;
+ h->c.skipped_last_frame = 0;
if (ctx->bitstream_buffer) {
- int buf_size = get_bits_left(&s->gb) / 8U;
+ int buf_size = get_bits_left(&h->c.gb) / 8U;
int bitstream_buffer_size = ctx->bitstream_buffer->size;
- const uint8_t *buf = s->gb.buffer;
+ const uint8_t *buf = h->c.gb.buffer;
- if (s->divx_packed) {
+ if (h->c.divx_packed) {
for (int i = 0; i < buf_size - 3; i++) {
if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) {
if (buf[i+3] == 0xB0) {
- av_log(s->avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
+ av_log(h->c.avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
bitstream_buffer_size = 0;
}
break;
@@ -3754,8 +3759,8 @@ int ff_mpeg4_decode_picture_header(MpegEncContext *s)
}
}
ctx->bitstream_buffer->size = 0;
- if (bitstream_buffer_size && (s->divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder
- int ret = init_get_bits8(&s->gb, ctx->bitstream_buffer->data,
+ if (bitstream_buffer_size && (h->c.divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder
+ int ret = init_get_bits8(&h->c.gb, ctx->bitstream_buffer->data,
bitstream_buffer_size);
if (ret < 0)
return ret;
@@ -3763,20 +3768,20 @@ int ff_mpeg4_decode_picture_header(MpegEncContext *s)
av_buffer_unref(&ctx->bitstream_buffer);
}
- return ff_mpeg4_parse_picture_header(ctx, &s->gb, 0, 0);
+ return ff_mpeg4_parse_picture_header(ctx, &h->c.gb, 0, 0);
}
int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
{
Mpeg4DecContext *ctx = avctx->priv_data;
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
int ret;
av_assert1(!ctx->bitstream_buffer || !ctx->bitstream_buffer->size);
/* divx 5.01+ bitstream reorder stuff */
- if (s->divx_packed) {
- int current_pos = ctx->bitstream_buffer && s->gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&s->gb) >> 3);
+ if (h->c.divx_packed) {
+ int current_pos = ctx->bitstream_buffer && h->c.gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->c.gb) >> 3);
int startcode_found = 0;
uint8_t *buf = pkt->data;
int buf_size = pkt->size;
@@ -3797,7 +3802,7 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
if (startcode_found) {
if (!ctx->showed_packed_warning) {
- av_log(s->avctx, AV_LOG_INFO, "Video uses a non-standard and "
+ av_log(h->c.avctx, AV_LOG_INFO, "Video uses a non-standard and "
"wasteful way to store B-frames ('packed B-frames'). "
"Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n");
ctx->showed_packed_warning = 1;
@@ -3874,11 +3879,11 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
{
Mpeg4DecContext *s = dst->priv_data;
const Mpeg4DecContext *s1 = src->priv_data;
- int init = s->m.context_initialized;
+ int init = s->h.c.context_initialized;
int ret;
if (!init) {
- ret = update_mpvctx(&s->m, &s1->m);
+ ret = update_mpvctx(&s->h.c, &s1->h.c);
if (ret < 0)
return ret;
}
@@ -3894,7 +3899,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
s->sprite_brightness_change = s1->sprite_brightness_change;
s->sprite_warping_accuracy = s1->sprite_warping_accuracy;
s->num_sprite_warping_points = s1->num_sprite_warping_points;
- s->m.data_partitioning = s1->m.data_partitioning;
+ s->h.c.data_partitioning = s1->h.c.data_partitioning;
s->mpeg_quant = s1->mpeg_quant;
s->rvlc = s1->rvlc;
s->resync_marker = s1->resync_marker;
@@ -3903,7 +3908,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
s->enhancement_type = s1->enhancement_type;
s->scalability = s1->scalability;
s->intra_dc_threshold = s1->intra_dc_threshold;
- s->m.divx_packed = s1->m.divx_packed;
+ s->h.c.divx_packed = s1->h.c.divx_packed;
s->divx_version = s1->divx_version;
s->divx_build = s1->divx_build;
s->xvid_build = s1->xvid_build;
@@ -3915,7 +3920,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
s->cplx_estimation_trash_p = s1->cplx_estimation_trash_p;
s->cplx_estimation_trash_b = s1->cplx_estimation_trash_b;
s->rgb = s1->rgb;
- s->m.skipped_last_frame = s1->m.skipped_last_frame;
+ s->h.c.skipped_last_frame = s1->h.c.skipped_last_frame;
memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift));
memcpy(s->sprite_traj, s1->sprite_traj, sizeof(s1->sprite_traj));
@@ -3985,7 +3990,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
{
static AVOnce init_static_once = AV_ONCE_INIT;
Mpeg4DecContext *ctx = avctx->priv_data;
- MpegEncContext *s = &ctx->m;
+ H263DecContext *const h = &ctx->h;
MPVUnquantDSPContext unquant_dsp_ctx;
int ret;
@@ -4006,18 +4011,18 @@ static av_cold int decode_init(AVCodecContext *avctx)
// so that is all we keep.
ctx->dct_unquantize_mpeg2_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
- s->y_dc_scale_table = ff_mpeg4_y_dc_scale_table;
- s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table;
+ h->c.y_dc_scale_table = ff_mpeg4_y_dc_scale_table;
+ h->c.c_dc_scale_table = ff_mpeg4_c_dc_scale_table;
- s->h263_pred = 1;
- s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */
- s->decode_mb = mpeg4_decode_mb;
+ h->c.h263_pred = 1;
+ h->c.low_delay = 0; /* default, might be overridden in the vol header during header parsing */
+ h->decode_mb = mpeg4_decode_mb;
ctx->time_increment_bits = 4; /* default value for broken headers */
ctx->quant_precision = 5;
avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
- ff_qpeldsp_init(&s->qdsp);
+ ff_qpeldsp_init(&h->c.qdsp);
ff_mpeg4videodsp_init(&ctx->mdsp);
ff_thread_once(&init_static_once, mpeg4_init_static);
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 9598429d08..337125d4e3 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -26,13 +26,14 @@
#include <stdint.h>
#include "get_bits.h"
+#include "h263dec.h"
#include "mpegvideo.h"
#include "mpeg4videodsp.h"
#include "libavutil/mem_internal.h"
typedef struct Mpeg4DecContext {
- MpegEncContext m;
+ H263DecContext h;
int f_code; ///< forward MV resolution
int b_code; ///< backward MV resolution for B-frames
@@ -108,7 +109,7 @@ typedef struct Mpeg4DecContext {
int dct_precision;
} Mpeg4DecContext;
-int ff_mpeg4_decode_picture_header(MpegEncContext *s);
+int ff_mpeg4_decode_picture_header(H263DecContext *const h);
int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
int header, int parse_only);
void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb,
@@ -117,11 +118,11 @@ void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb
void ff_mpeg4_mcsel_motion(MpegEncContext *s,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
uint8_t *const *ref_picture);
-int ff_mpeg4_decode_partitions(MPVContext *const s);
-int ff_mpeg4_decode_video_packet_header(MPVContext *const s);
-int ff_mpeg4_decode_studio_slice_header(MPVContext *const s);
+int ff_mpeg4_decode_partitions(H263DecContext *const h);
+int ff_mpeg4_decode_video_packet_header(H263DecContext *const h);
+int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h);
void ff_mpeg4_workaround_bugs(AVCodecContext *avctx);
-void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n,
+void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n,
int dir);
int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt);
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 81d2675f50..f76158040d 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -307,7 +307,6 @@ typedef struct MpegEncContext {
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
int16_t (*block)[64];
- int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
#define SLICE_OK 0
#define SLICE_ERROR -1
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 55e51aff3c..0cb14d5762 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -74,23 +74,24 @@ static VLCElem v2_mb_type_vlc[128];
VLCElem ff_inter_intra_vlc[8];
/* This is identical to H.263 except that its range is multiplied by 2. */
-static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
+static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code)
{
int code, val, sign, shift;
- code = get_vlc2(&s->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
- ff_dlog(s->avctx, "MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
+ code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
+ ff_dlog(h->c.avctx, "MV code %d at %d %d pred: %d\n",
+ code, h->c.mb_x,h->c.mb_y, pred);
if (code < 0)
return 0xffff;
if (code == 0)
return pred;
- sign = get_bits1(&s->gb);
+ sign = get_bits1(&h->c.gb);
shift = f_code - 1;
val = code;
if (shift) {
val = (val - 1) << shift;
- val |= get_bits(&s->gb, shift);
+ val |= get_bits(&h->c.gb, shift);
val++;
}
if (sign)
@@ -105,151 +106,155 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
return val;
}
-static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
+static int msmpeg4v12_decode_mb(H263DecContext *const h, int16_t block[6][64])
{
- MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
+ MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
int cbp, code, i;
- uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride];
+ uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride];
- if (s->pict_type == AV_PICTURE_TYPE_P) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_P) {
if (ms->use_skip_mb_code) {
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&h->c.gb)) {
/* skip mb */
- s->mb_intra = 0;
+ h->c.mb_intra = 0;
for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mb_skipped = 1;
+ h->c.block_last_index[i] = -1;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ h->c.mv[0][0][0] = 0;
+ h->c.mv[0][0][1] = 0;
+ h->c.mb_skipped = 1;
*mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
return 0;
}
}
- if (s->msmpeg4_version == MSMP4_V2)
- code = get_vlc2(&s->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1);
+ if (h->c.msmpeg4_version == MSMP4_V2)
+ code = get_vlc2(&h->c.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);
+ code = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if(code<0 || code>7){
- av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",
+ code, h->c.mb_x, h->c.mb_y);
return -1;
}
- s->mb_intra = code >>2;
+ h->c.mb_intra = code >>2;
cbp = code & 0x3;
} else {
- s->mb_intra = 1;
- if (s->msmpeg4_version == MSMP4_V2)
- cbp = get_vlc2(&s->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1);
+ h->c.mb_intra = 1;
+ if (h->c.msmpeg4_version == MSMP4_V2)
+ cbp = get_vlc2(&h->c.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);
+ cbp = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if(cbp<0 || cbp>3){
- av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",
+ cbp, h->c.mb_x, h->c.mb_y);
return -1;
}
}
- if (!s->mb_intra) {
+ if (!h->c.mb_intra) {
int mx, my, cbpy;
- cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if(cbpy<0){
- av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n",
+ cbp, h->c.mb_x, h->c.mb_y);
return -1;
}
cbp|= cbpy<<2;
- if (s->msmpeg4_version == MSMP4_V1 || (cbp&3) != 3)
+ if (h->c.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);
- my= msmpeg4v2_decode_motion(s, my, 1);
+ ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);
+ mx = msmpeg4v2_decode_motion(h, mx, 1);
+ my = msmpeg4v2_decode_motion(h, my, 1);
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ h->c.mv[0][0][0] = mx;
+ h->c.mv[0][0][1] = my;
*mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
} else {
int v;
- 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 (h->c.msmpeg4_version == MSMP4_V2) {
+ h->c.ac_pred = get_bits1(&h->c.gb);
+ v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (v < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
return -1;
}
cbp|= v<<2;
} else{
- s->ac_pred = 0;
- v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ h->c.ac_pred = 0;
+ v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (v < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
return -1;
}
cbp|= v<<2;
- if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
+ if (h->c.pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
}
*mb_type_ptr = MB_TYPE_INTRA;
}
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
for (i = 0; i < 6; i++) {
if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
{
- av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
+ av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
+ h->c.mb_x, h->c.mb_y, i);
return -1;
}
}
return 0;
}
-static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
+static int msmpeg4v34_decode_mb(H263DecContext *const h, int16_t block[6][64])
{
- MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
+ MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
int cbp, code, i;
uint8_t *coded_val;
- uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride];
+ uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride];
- if (get_bits_left(&s->gb) <= 0)
+ if (get_bits_left(&h->c.gb) <= 0)
return AVERROR_INVALIDDATA;
- if (s->pict_type == AV_PICTURE_TYPE_P) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_P) {
if (ms->use_skip_mb_code) {
- if (get_bits1(&s->gb)) {
+ if (get_bits1(&h->c.gb)) {
/* skip mb */
- s->mb_intra = 0;
+ h->c.mb_intra = 0;
for(i=0;i<6;i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mb_skipped = 1;
+ h->c.block_last_index[i] = -1;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ h->c.mv[0][0][0] = 0;
+ h->c.mv[0][0][1] = 0;
+ h->c.mb_skipped = 1;
*mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
return 0;
}
}
- code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
- //s->mb_intra = (code & 0x40) ? 0 : 1;
- s->mb_intra = (~code & 0x40) >> 6;
+ code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
+ //h->c.mb_intra = (code & 0x40) ? 0 : 1;
+ h->c.mb_intra = (~code & 0x40) >> 6;
cbp = code & 0x3f;
} else {
- s->mb_intra = 1;
- code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
+ h->c.mb_intra = 1;
+ code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
/* predict coded block pattern */
cbp = 0;
for(i=0;i<6;i++) {
int val = ((code >> (5 - i)) & 1);
if (i < 4) {
- int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
+ int pred = ff_msmpeg4_coded_block_pred(&h->c, i, &coded_val);
val = val ^ pred;
*coded_val = val;
}
@@ -257,41 +262,42 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
}
}
- if (!s->mb_intra) {
+ if (!h->c.mb_intra) {
int mx, my;
if (ms->per_mb_rl_table && cbp) {
- ms->rl_table_index = decode012(&s->gb);
+ ms->rl_table_index = decode012(&h->c.gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
- ff_h263_pred_motion(s, 0, 0, &mx, &my);
+ ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);
ff_msmpeg4_decode_motion(ms, &mx, &my);
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ h->c.mv[0][0][0] = mx;
+ h->c.mv[0][0][1] = my;
*mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
} else {
- ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
+ ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
- show_bits(&s->gb, 24));
- s->ac_pred = get_bits1(&s->gb);
+ show_bits(&h->c.gb, 24));
+ h->c.ac_pred = get_bits1(&h->c.gb);
*mb_type_ptr = MB_TYPE_INTRA;
- if(s->inter_intra_pred){
- s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
- ff_dlog(s->avctx, "%d%d %d %d/",
- s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
+ if (h->c.inter_intra_pred) {
+ h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
+ ff_dlog(h->c.avctx, "%d%d %d %d/",
+ h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
}
if (ms->per_mb_rl_table && cbp) {
- ms->rl_table_index = decode012(&s->gb);
+ ms->rl_table_index = decode012(&h->c.gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
}
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
for (i = 0; i < 6; i++) {
if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
{
- av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
+ av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
+ h->c.mb_x, h->c.mb_y, i);
return -1;
}
}
@@ -357,7 +363,7 @@ static av_cold void msmpeg4_decode_init_static(void)
av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
{
static AVOnce init_static_once = AV_ONCE_INIT;
- MpegEncContext *s = avctx->priv_data;
+ H263DecContext *const h = avctx->priv_data;
int ret;
if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
@@ -367,18 +373,18 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
return -1;
// We unquantize inter blocks as we parse them.
- s->dct_unquantize_inter = NULL;
+ h->c.dct_unquantize_inter = NULL;
- ff_msmpeg4_common_init(s);
+ ff_msmpeg4_common_init(&h->c);
- switch (s->msmpeg4_version) {
+ switch (h->c.msmpeg4_version) {
case MSMP4_V1:
case MSMP4_V2:
- s->decode_mb= msmpeg4v12_decode_mb;
+ h->decode_mb = msmpeg4v12_decode_mb;
break;
case MSMP4_V3:
case MSMP4_WMV1:
- s->decode_mb= msmpeg4v34_decode_mb;
+ h->decode_mb = msmpeg4v34_decode_mb;
break;
case MSMP4_WMV2:
break;
@@ -386,16 +392,16 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
av_unreachable("List contains all cases using ff_msmpeg4_decode_init()");
}
- s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe
+ h->c.slice_height = h->c.mb_height; //to avoid 1/0 if the first frame is not a keyframe
ff_thread_once(&init_static_once, msmpeg4_decode_init_static);
return 0;
}
-int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
+int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
{
- MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
+ MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
int code;
// at minimum one bit per macroblock is required at least in a valid frame,
@@ -403,51 +409,51 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
// smallest "black/skip" frame generally contain not much recoverable content
// while at the same time they have the highest computational requirements
// per byte
- if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
+ if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
return AVERROR_INVALIDDATA;
- if (s->msmpeg4_version == MSMP4_V1) {
- int start_code = get_bits_long(&s->gb, 32);
+ if (h->c.msmpeg4_version == MSMP4_V1) {
+ int start_code = get_bits_long(&h->c.gb, 32);
if(start_code!=0x00000100){
- av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "invalid startcode\n");
return -1;
}
- skip_bits(&s->gb, 5); // frame number */
+ skip_bits(&h->c.gb, 5); // frame number */
}
- s->pict_type = get_bits(&s->gb, 2) + 1;
- if (s->pict_type != AV_PICTURE_TYPE_I &&
- s->pict_type != AV_PICTURE_TYPE_P){
- av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
+ h->c.pict_type = get_bits(&h->c.gb, 2) + 1;
+ if (h->c.pict_type != AV_PICTURE_TYPE_I &&
+ h->c.pict_type != AV_PICTURE_TYPE_P){
+ av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n");
return -1;
}
- s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
- if(s->qscale==0){
- av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
+ if (h->c.qscale == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n");
return -1;
}
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- code = get_bits(&s->gb, 5);
- 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);
+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
+ code = get_bits(&h->c.gb, 5);
+ if (h->c.msmpeg4_version == MSMP4_V1) {
+ if(code==0 || code>h->c.mb_height) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
return -1;
}
- s->slice_height = code;
+ h->c.slice_height = code;
}else{
/* 0x17: one slice, 0x18: two slices, ... */
if (code < 0x17){
- av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
+ av_log(h->c.avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
return -1;
}
- s->slice_height = s->mb_height / (code - 0x16);
+ h->c.slice_height = h->c.mb_height / (code - 0x16);
}
- switch(s->msmpeg4_version){
+ switch (h->c.msmpeg4_version) {
case MSMP4_V1:
case MSMP4_V2:
ms->rl_chroma_table_index = 2;
@@ -456,102 +462,102 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
ms->dc_table_index = 0; //not used
break;
case MSMP4_V3:
- ms->rl_chroma_table_index = decode012(&s->gb);
- ms->rl_table_index = decode012(&s->gb);
+ ms->rl_chroma_table_index = decode012(&h->c.gb);
+ ms->rl_table_index = decode012(&h->c.gb);
- ms->dc_table_index = get_bits1(&s->gb);
+ ms->dc_table_index = get_bits1(&h->c.gb);
break;
case MSMP4_WMV1:
- ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
+ ff_msmpeg4_decode_ext_header(h, (2+5+5+17+7)/8);
if (ms->bit_rate > MBAC_BITRATE)
- ms->per_mb_rl_table = get_bits1(&s->gb);
+ ms->per_mb_rl_table = get_bits1(&h->c.gb);
else
ms->per_mb_rl_table = 0;
if (!ms->per_mb_rl_table) {
- ms->rl_chroma_table_index = decode012(&s->gb);
- ms->rl_table_index = decode012(&s->gb);
+ ms->rl_chroma_table_index = decode012(&h->c.gb);
+ ms->rl_table_index = decode012(&h->c.gb);
}
- ms->dc_table_index = get_bits1(&s->gb);
- s->inter_intra_pred= 0;
+ ms->dc_table_index = get_bits1(&h->c.gb);
+ h->c.inter_intra_pred= 0;
break;
default:
av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
}
- s->no_rounding = 1;
- if(s->avctx->debug&FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
- s->qscale,
+ h->c.no_rounding = 1;
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(h->c.avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
+ h->c.qscale,
ms->rl_chroma_table_index,
ms->rl_table_index,
ms->dc_table_index,
ms->per_mb_rl_table,
- s->slice_height);
+ h->c.slice_height);
} else {
- switch(s->msmpeg4_version){
+ switch (h->c.msmpeg4_version) {
case MSMP4_V1:
case MSMP4_V2:
- if (s->msmpeg4_version == MSMP4_V1)
+ if (h->c.msmpeg4_version == MSMP4_V1)
ms->use_skip_mb_code = 1;
else
- ms->use_skip_mb_code = get_bits1(&s->gb);
+ ms->use_skip_mb_code = get_bits1(&h->c.gb);
ms->rl_table_index = 2;
ms->rl_chroma_table_index = ms->rl_table_index;
ms->dc_table_index = 0; //not used
ms->mv_table_index = 0;
break;
case MSMP4_V3:
- ms->use_skip_mb_code = get_bits1(&s->gb);
- ms->rl_table_index = decode012(&s->gb);
+ ms->use_skip_mb_code = get_bits1(&h->c.gb);
+ ms->rl_table_index = decode012(&h->c.gb);
ms->rl_chroma_table_index = ms->rl_table_index;
- ms->dc_table_index = get_bits1(&s->gb);
+ ms->dc_table_index = get_bits1(&h->c.gb);
- ms->mv_table_index = get_bits1(&s->gb);
+ ms->mv_table_index = get_bits1(&h->c.gb);
break;
case MSMP4_WMV1:
- ms->use_skip_mb_code = get_bits1(&s->gb);
+ ms->use_skip_mb_code = get_bits1(&h->c.gb);
if (ms->bit_rate > MBAC_BITRATE)
- ms->per_mb_rl_table = get_bits1(&s->gb);
+ ms->per_mb_rl_table = get_bits1(&h->c.gb);
else
ms->per_mb_rl_table = 0;
if (!ms->per_mb_rl_table) {
- ms->rl_table_index = decode012(&s->gb);
+ ms->rl_table_index = decode012(&h->c.gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
- ms->dc_table_index = get_bits1(&s->gb);
+ ms->dc_table_index = get_bits1(&h->c.gb);
- ms->mv_table_index = get_bits1(&s->gb);
- s->inter_intra_pred = s->width*s->height < 320*240 &&
+ ms->mv_table_index = get_bits1(&h->c.gb);
+ h->c.inter_intra_pred = h->c.width*h->c.height < 320*240 &&
ms->bit_rate <= II_BITRATE;
break;
default:
av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
}
- if(s->avctx->debug&FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
+ if (h->c.avctx->debug&FF_DEBUG_PICT_INFO)
+ av_log(h->c.avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
ms->use_skip_mb_code,
ms->rl_table_index,
ms->rl_chroma_table_index,
ms->dc_table_index,
ms->mv_table_index,
ms->per_mb_rl_table,
- s->qscale);
+ h->c.qscale);
if (ms->flipflop_rounding) {
- s->no_rounding ^= 1;
+ h->c.no_rounding ^= 1;
}else{
- s->no_rounding = 0;
+ h->c.no_rounding = 0;
}
}
- ff_dlog(s->avctx, "%d %d %d %d %d\n", s->pict_type, ms->bit_rate,
- s->inter_intra_pred, s->width, s->height);
+ ff_dlog(h->c.avctx, "%d %d %d %d %d\n", h->c.pict_type, ms->bit_rate,
+ h->c.inter_intra_pred, h->c.width, h->c.height);
ms->esc3_level_length = 0;
ms->esc3_run_length = 0;
@@ -559,30 +565,30 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
return 0;
}
-int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
+int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)
{
- MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
- int left= buf_size*8 - get_bits_count(&s->gb);
- int length = s->msmpeg4_version >= MSMP4_V3 ? 17 : 16;
+ MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
+ int left= buf_size*8 - get_bits_count(&h->c.gb);
+ int length = h->c.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 */
- ms->bit_rate = get_bits(&s->gb, 11) * 1024;
- if (s->msmpeg4_version >= MSMP4_V3)
- ms->flipflop_rounding = get_bits1(&s->gb);
+ skip_bits(&h->c.gb, 5); /* fps */
+ ms->bit_rate = get_bits(&h->c.gb, 11) * 1024;
+ if (h->c.msmpeg4_version >= MSMP4_V3)
+ ms->flipflop_rounding = get_bits1(&h->c.gb);
else
ms->flipflop_rounding = 0;
}
else if(left<length+8)
{
ms->flipflop_rounding = 0;
- if (s->msmpeg4_version != MSMP4_V2)
- av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
+ if (h->c.msmpeg4_version != MSMP4_V2)
+ av_log(h->c.avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
}
else
{
- av_log(s->avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n");
}
return 0;
@@ -590,52 +596,52 @@ int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
{
- MpegEncContext *const s = &ms->m;
+ H263DecContext *const h = &ms->h;
int level, pred;
- if (s->msmpeg4_version <= MSMP4_V2) {
+ if (h->c.msmpeg4_version <= MSMP4_V2) {
if (n < 4) {
- level = get_vlc2(&s->gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
+ level = get_vlc2(&h->c.gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
} else {
- level = get_vlc2(&s->gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
+ level = get_vlc2(&h->c.gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
}
if (level < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
*dir_ptr = 0;
return -1;
}
level-=256;
} else {
- level = get_vlc2(&s->gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
+ level = get_vlc2(&h->c.gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
MSMP4_DC_VLC_BITS, 3);
if (level == DC_MAX) {
- level = get_bits(&s->gb, 8);
- if (get_bits1(&s->gb))
+ level = get_bits(&h->c.gb, 8);
+ if (get_bits1(&h->c.gb))
level = -level;
} else if (level != 0) {
- if (get_bits1(&s->gb))
+ if (get_bits1(&h->c.gb))
level = -level;
}
}
- if (s->msmpeg4_version == MSMP4_V1) {
+ if (h->c.msmpeg4_version == MSMP4_V1) {
int32_t *dc_val;
- pred = msmpeg4v1_pred_dc(s, n, &dc_val);
+ pred = msmpeg4v1_pred_dc(&h->c, n, &dc_val);
level += pred;
/* update predictor */
*dc_val= level;
}else{
int16_t *dc_val;
- pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
+ pred = ff_msmpeg4_pred_dc(&h->c, n, &dc_val, dir_ptr);
level += pred;
/* update predictor */
if (n < 4) {
- *dc_val = level * s->y_dc_scale;
+ *dc_val = level * h->c.y_dc_scale;
} else {
- *dc_val = level * s->c_dc_scale;
+ *dc_val = level * h->c.c_dc_scale;
}
}
@@ -645,14 +651,14 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
int n, int coded, const uint8_t *scan_table)
{
- MpegEncContext *const s = &ms->m;
+ H263DecContext *const h = &ms->h;
int level, i, last, run, run_diff;
int dc_pred_dir = -1; //unused but its passed around, so it needs to be initialized
const RLTable *rl;
const RL_VLC_ELEM *rl_vlc;
int qmul, qadd;
- if (s->mb_intra) {
+ if (h->c.mb_intra) {
qmul=1;
qadd=0;
@@ -660,110 +666,113 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
level = msmpeg4_decode_dc(ms, n, &dc_pred_dir);
if (level < 0){
- av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
- if(s->inter_intra_pred) level=0;
+ av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, h->c.qscale);
+ if (h->c.inter_intra_pred)
+ level = 0;
}
if (n < 4) {
rl = &ff_rl_table[ms->rl_table_index];
- if(level > 256*s->y_dc_scale){
- av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
- if(!s->inter_intra_pred) return -1;
+ if (level > 256 * h->c.y_dc_scale) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", h->c.qscale);
+ if (!h->c.inter_intra_pred)
+ return -1;
}
} else {
rl = &ff_rl_table[3 + ms->rl_chroma_table_index];
- if(level > 256*s->c_dc_scale){
- av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
- if(!s->inter_intra_pred) return -1;
+ if (level > 256 * h->c.c_dc_scale) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", h->c.qscale);
+ if (!h->c.inter_intra_pred)
+ return -1;
}
}
block[0] = level;
- run_diff = s->msmpeg4_version >= MSMP4_WMV1;
+ run_diff = h->c.msmpeg4_version >= MSMP4_WMV1;
i = 0;
if (!coded) {
goto not_coded;
}
- if (s->ac_pred) {
+ if (h->c.ac_pred) {
if (dc_pred_dir == 0)
- scan_table = s->permutated_intra_v_scantable; /* left */
+ scan_table = h->c.permutated_intra_v_scantable; /* left */
else
- scan_table = s->permutated_intra_h_scantable; /* top */
+ scan_table = h->c.permutated_intra_h_scantable; /* top */
} else {
- scan_table = s->intra_scantable.permutated;
+ scan_table = h->c.intra_scantable.permutated;
}
rl_vlc= rl->rl_vlc[0];
} else {
- qmul = s->qscale << 1;
- qadd = (s->qscale - 1) | 1;
+ qmul = h->c.qscale << 1;
+ qadd = (h->c.qscale - 1) | 1;
i = -1;
rl = &ff_rl_table[3 + ms->rl_table_index];
- if (s->msmpeg4_version == MSMP4_V2)
+ if (h->c.msmpeg4_version == MSMP4_V2)
run_diff = 0;
else
run_diff = 1;
if (!coded) {
- s->block_last_index[n] = i;
+ h->c.block_last_index[n] = i;
return 0;
}
if(!scan_table)
- scan_table = s->inter_scantable.permutated;
- rl_vlc= rl->rl_vlc[s->qscale];
+ scan_table = h->c.inter_scantable.permutated;
+ rl_vlc= rl->rl_vlc[h->c.qscale];
}
{
- OPEN_READER(re, &s->gb);
+ OPEN_READER(re, &h->c.gb);
for(;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
+ UPDATE_CACHE(re, &h->c.gb);
+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0);
if (level==0) {
int cache;
- cache= GET_CACHE(re, &s->gb);
+ cache= GET_CACHE(re, &h->c.gb);
/* escape */
- if (s->msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {
- if (s->msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {
+ if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {
+ if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {
/* third escape */
- if (s->msmpeg4_version != MSMP4_V1)
- LAST_SKIP_BITS(re, &s->gb, 2);
- UPDATE_CACHE(re, &s->gb);
- 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);
- SKIP_COUNTER(re, &s->gb, 1+6+8);
+ if (h->c.msmpeg4_version != MSMP4_V1)
+ LAST_SKIP_BITS(re, &h->c.gb, 2);
+ UPDATE_CACHE(re, &h->c.gb);
+ if (h->c.msmpeg4_version <= MSMP4_V3) {
+ last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_CACHE(re, &h->c.gb, 1);
+ run = SHOW_UBITS(re, &h->c.gb, 6); SKIP_CACHE(re, &h->c.gb, 6);
+ level = SHOW_SBITS(re, &h->c.gb, 8);
+ SKIP_COUNTER(re, &h->c.gb, 1 + 6 + 8);
}else{
int sign;
- last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
+ last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1);
if (!ms->esc3_level_length) {
int ll;
- ff_dlog(s->avctx, "ESC-3 %X at %d %d\n",
- show_bits(&s->gb, 24), s->mb_x, s->mb_y);
- if(s->qscale<8){
- ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
+ ff_dlog(h->c.avctx, "ESC-3 %X at %d %d\n",
+ show_bits(&h->c.gb, 24), h->c.mb_x, h->c.mb_y);
+ if (h->c.qscale < 8) {
+ ll = SHOW_UBITS(re, &h->c.gb, 3); SKIP_BITS(re, &h->c.gb, 3);
if(ll==0){
- ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
+ ll = 8+SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1);
}
}else{
ll=2;
- while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
+ while (ll < 8 && SHOW_UBITS(re, &h->c.gb, 1) == 0) {
ll++;
- SKIP_BITS(re, &s->gb, 1);
+ SKIP_BITS(re, &h->c.gb, 1);
}
- if(ll<8) SKIP_BITS(re, &s->gb, 1);
+ if (ll<8) SKIP_BITS(re, &h->c.gb, 1);
}
ms->esc3_level_length = ll;
- ms->esc3_run_length = SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
- UPDATE_CACHE(re, &s->gb);
+ ms->esc3_run_length = SHOW_UBITS(re, &h->c.gb, 2) + 3; SKIP_BITS(re, &h->c.gb, 2);
+ UPDATE_CACHE(re, &h->c.gb);
}
- run = SHOW_UBITS(re, &s->gb, ms->esc3_run_length);
- SKIP_BITS(re, &s->gb, ms->esc3_run_length);
+ run = SHOW_UBITS(re, &h->c.gb, ms->esc3_run_length);
+ SKIP_BITS(re, &h->c.gb, ms->esc3_run_length);
- sign= SHOW_UBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
+ sign= SHOW_UBITS(re, &h->c.gb, 1);
+ SKIP_BITS(re, &h->c.gb, 1);
- level = SHOW_UBITS(re, &s->gb, ms->esc3_level_length);
- SKIP_BITS(re, &s->gb, ms->esc3_level_length);
+ level = SHOW_UBITS(re, &h->c.gb, ms->esc3_level_length);
+ SKIP_BITS(re, &h->c.gb, ms->esc3_level_length);
if(sign) level= -level;
}
@@ -774,38 +783,40 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
if(last) i+=192;
} else {
/* second escape */
- SKIP_BITS(re, &s->gb, 2);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
+ SKIP_BITS(re, &h->c.gb, 2);
+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
+ LAST_SKIP_BITS(re, &h->c.gb, 1);
}
} else {
/* first escape */
- SKIP_BITS(re, &s->gb, 1);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
+ SKIP_BITS(re, &h->c.gb, 1);
+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i+= run;
level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
+ LAST_SKIP_BITS(re, &h->c.gb, 1);
}
} else {
i+= run;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
+ LAST_SKIP_BITS(re, &h->c.gb, 1);
}
if (i > 62){
i-= 192;
if(i&(~63)){
- const int left= get_bits_left(&s->gb);
+ const int left = get_bits_left(&h->c.gb);
if (((i + 192 == 64 && level / qmul == -1) ||
- !(s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
+ !(h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
left >= 0) {
- av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n",
+ h->c.mb_x, h->c.mb_y);
i = 63;
break;
}else{
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
+ av_log(h->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
+ h->c.mb_x, h->c.mb_y);
return -1;
}
}
@@ -816,13 +827,13 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
block[scan_table[i]] = level;
}
- CLOSE_READER(re, &s->gb);
+ CLOSE_READER(re, &h->c.gb);
}
- if (s->mb_intra) {
+ if (h->c.mb_intra) {
not_coded:
- ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);
+ ff_mpeg4_pred_ac(h, block, n, dc_pred_dir);
}
- s->block_last_index[n] = i;
+ h->c.block_last_index[n] = i;
return 0;
}
@@ -830,17 +841,17 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr)
{
const VLCElem *const mv_vlc = mv_tables[ms->mv_table_index];
- MpegEncContext *const s = &ms->m;
+ H263DecContext *const h = &ms->h;
int sym, mx, my;
- sym = get_vlc2(&s->gb, mv_vlc, MV_VLC_BITS, 2);
+ sym = get_vlc2(&h->c.gb, mv_vlc, MV_VLC_BITS, 2);
if (sym) {
mx = sym >> 8;
my = sym & 0xFF;
} else {
/* Escape */
- mx = get_bits(&s->gb, 6);
- my = get_bits(&s->gb, 6);
+ mx = get_bits(&h->c.gb, 6);
+ my = get_bits(&h->c.gb, 6);
}
mx += *mx_ptr - 32;
diff --git a/libavcodec/msmpeg4dec.h b/libavcodec/msmpeg4dec.h
index 862c50b3f0..11a36f2136 100644
--- a/libavcodec/msmpeg4dec.h
+++ b/libavcodec/msmpeg4dec.h
@@ -23,13 +23,14 @@
#define AVCODEC_MSMPEG4DEC_H
#include "avcodec.h"
+#include "h263dec.h"
#include "mpegvideo.h"
#define INTER_INTRA_VLC_BITS 3
#define MB_NON_INTRA_VLC_BITS 9
typedef struct MSMP4DecContext {
- MpegEncContext m;
+ H263DecContext h;
int bit_rate;
int flipflop_rounding;
int mv_table_index;
@@ -42,18 +43,18 @@ typedef struct MSMP4DecContext {
int esc3_run_length;
} MSMP4DecContext;
-static inline MSMP4DecContext *mpv_to_msmpeg4(MpegEncContext *s)
+static inline MSMP4DecContext *mpv_to_msmpeg4(H263DecContext *const h)
{
// Only legal because no MSMPEG-4 decoder uses slice-threading.
- return (MSMP4DecContext*)s;
+ return (MSMP4DecContext*)h;
}
extern const VLCElem *ff_mb_non_intra_vlc[4];
extern VLCElem ff_inter_intra_vlc[8];
int ff_msmpeg4_decode_init(AVCodecContext *avctx);
-int ff_msmpeg4_decode_picture_header(MpegEncContext *s);
-int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size);
+int ff_msmpeg4_decode_picture_header(H263DecContext *const h);
+int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size);
void ff_msmpeg4_decode_motion(MSMP4DecContext *ms, int *mx_ptr, int *my_ptr);
int ff_msmpeg4_decode_block(MSMP4DecContext *ms, int16_t * block,
int n, int coded, const uint8_t *scan_table);
diff --git a/libavcodec/nvdec_mpeg4.c b/libavcodec/nvdec_mpeg4.c
index 8272439031..0351ee169e 100644
--- a/libavcodec/nvdec_mpeg4.c
+++ b/libavcodec/nvdec_mpeg4.c
@@ -33,7 +33,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx,
const uint8_t *buffer, uint32_t size)
{
Mpeg4DecContext *m = avctx->priv_data;
- MpegEncContext *s = &m->m;
+ MPVContext *const s = &m->h.c;
NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
CUVIDPICPARAMS *pp = &ctx->pic_params;
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 9f4dea6141..0a245e90a3 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -52,7 +52,7 @@
#define DC_VLC_BITS 9
typedef struct RVDecContext {
- MpegEncContext m;
+ H263DecContext h;
int sub_id;
int orig_width, orig_height;
} RVDecContext;
@@ -80,16 +80,16 @@ static const uint16_t rv_chrom_len_count[15] = {
static VLCElem rv_dc_lum[1472], rv_dc_chrom[992];
-int ff_rv_decode_dc(MpegEncContext *s, int n)
+int ff_rv_decode_dc(H263DecContext *const h, int n)
{
int code;
if (n < 4) {
- code = get_vlc2(&s->gb, rv_dc_lum, DC_VLC_BITS, 2);
+ code = get_vlc2(&h->c.gb, rv_dc_lum, DC_VLC_BITS, 2);
} else {
- code = get_vlc2(&s->gb, rv_dc_chrom, DC_VLC_BITS, 2);
+ code = get_vlc2(&h->c.gb, rv_dc_chrom, DC_VLC_BITS, 2);
if (code < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "chroma dc error\n");
return -1;
}
}
@@ -97,59 +97,59 @@ int ff_rv_decode_dc(MpegEncContext *s, int n)
}
/* read RV 1.0 compatible frame header */
-static int rv10_decode_picture_header(MpegEncContext *s)
+static int rv10_decode_picture_header(H263DecContext *const h)
{
int mb_count, pb_frame, marker, mb_xy;
- marker = get_bits1(&s->gb);
+ marker = get_bits1(&h->c.gb);
- if (get_bits1(&s->gb))
- s->pict_type = AV_PICTURE_TYPE_P;
+ if (get_bits1(&h->c.gb))
+ h->c.pict_type = AV_PICTURE_TYPE_P;
else
- s->pict_type = AV_PICTURE_TYPE_I;
+ h->c.pict_type = AV_PICTURE_TYPE_I;
if (!marker)
- av_log(s->avctx, AV_LOG_ERROR, "marker missing\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "marker missing\n");
- pb_frame = get_bits1(&s->gb);
+ pb_frame = get_bits1(&h->c.gb);
- ff_dlog(s->avctx, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
+ ff_dlog(h->c.avctx, "pict_type=%d pb_frame=%d\n", h->c.pict_type, pb_frame);
if (pb_frame) {
- avpriv_request_sample(s->avctx, "PB-frame");
+ avpriv_request_sample(h->c.avctx, "PB-frame");
return AVERROR_PATCHWELCOME;
}
- s->qscale = get_bits(&s->gb, 5);
- if (s->qscale == 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
+ h->c.qscale = get_bits(&h->c.gb, 5);
+ if (h->c.qscale == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
return AVERROR_INVALIDDATA;
}
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- if (s->rv10_version == 3) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
+ if (h->c.rv10_version == 3) {
/* specific MPEG like DC coding not used */
- s->last_dc[0] = get_bits(&s->gb, 8);
- s->last_dc[1] = get_bits(&s->gb, 8);
- s->last_dc[2] = get_bits(&s->gb, 8);
- ff_dlog(s->avctx, "DC:%d %d %d\n", s->last_dc[0],
- s->last_dc[1], s->last_dc[2]);
+ h->c.last_dc[0] = get_bits(&h->c.gb, 8);
+ h->c.last_dc[1] = get_bits(&h->c.gb, 8);
+ h->c.last_dc[2] = get_bits(&h->c.gb, 8);
+ ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->c.last_dc[0],
+ h->c.last_dc[1], h->c.last_dc[2]);
}
}
/* if multiple packets per frame are sent, the position at which
* to display the macroblocks is coded here */
- mb_xy = s->mb_x + s->mb_y * s->mb_width;
- if (show_bits(&s->gb, 12) == 0 || (mb_xy && mb_xy < s->mb_num)) {
- s->mb_x = get_bits(&s->gb, 6); /* mb_x */
- s->mb_y = get_bits(&s->gb, 6); /* mb_y */
- mb_count = get_bits(&s->gb, 12);
+ mb_xy = h->c.mb_x + h->c.mb_y * h->c.mb_width;
+ if (show_bits(&h->c.gb, 12) == 0 || (mb_xy && mb_xy < h->c.mb_num)) {
+ h->c.mb_x = get_bits(&h->c.gb, 6); /* mb_x */
+ h->c.mb_y = get_bits(&h->c.gb, 6); /* mb_y */
+ mb_count = get_bits(&h->c.gb, 12);
} else {
- s->mb_x = 0;
- s->mb_y = 0;
- mb_count = s->mb_width * s->mb_height;
+ h->c.mb_x = 0;
+ h->c.mb_y = 0;
+ mb_count = h->c.mb_width * h->c.mb_height;
}
- skip_bits(&s->gb, 3); /* ignored */
+ skip_bits(&h->c.gb, 3); /* ignored */
return mb_count;
}
@@ -159,151 +159,151 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
static const enum AVPictureType pict_types[] =
{ AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */,
AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B };
- MpegEncContext *s = &rv->m;
+ H263DecContext *const h = &rv->h;
int seq, mb_pos, ret;
int rpr_max;
- s->pict_type = pict_types[get_bits(&s->gb, 2)];
+ h->c.pict_type = pict_types[get_bits(&h->c.gb, 2)];
- if (s->low_delay && s->pict_type == AV_PICTURE_TYPE_B) {
- av_log(s->avctx, AV_LOG_ERROR, "low delay B\n");
+ if (h->c.low_delay && h->c.pict_type == AV_PICTURE_TYPE_B) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "low delay B\n");
return -1;
}
- if (!s->last_pic.ptr && s->pict_type == AV_PICTURE_TYPE_B) {
- av_log(s->avctx, AV_LOG_ERROR, "early B-frame\n");
+ if (!h->c.last_pic.ptr && h->c.pict_type == AV_PICTURE_TYPE_B) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "early B-frame\n");
return AVERROR_INVALIDDATA;
}
- if (get_bits1(&s->gb)) {
- av_log(s->avctx, AV_LOG_ERROR, "reserved bit set\n");
+ if (get_bits1(&h->c.gb)) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "reserved bit set\n");
return AVERROR_INVALIDDATA;
}
- s->qscale = get_bits(&s->gb, 5);
- if (s->qscale == 0) {
- av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
+ h->c.qscale = get_bits(&h->c.gb, 5);
+ if (h->c.qscale == 0) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
return AVERROR_INVALIDDATA;
}
if (RV_GET_MINOR_VER(rv->sub_id) >= 2)
- s->loop_filter = get_bits1(&s->gb) && !s->avctx->lowres;
+ h->c.loop_filter = get_bits1(&h->c.gb) && !h->c.avctx->lowres;
if (RV_GET_MINOR_VER(rv->sub_id) <= 1)
- seq = get_bits(&s->gb, 8) << 7;
+ seq = get_bits(&h->c.gb, 8) << 7;
else
- seq = get_bits(&s->gb, 13) << 2;
+ seq = get_bits(&h->c.gb, 13) << 2;
- rpr_max = s->avctx->extradata[1] & 7;
+ rpr_max = h->c.avctx->extradata[1] & 7;
if (rpr_max) {
int f, new_w, new_h;
int rpr_bits = av_log2(rpr_max) + 1;
- f = get_bits(&s->gb, rpr_bits);
+ f = get_bits(&h->c.gb, rpr_bits);
if (f) {
- if (s->avctx->extradata_size < 8 + 2 * f) {
- av_log(s->avctx, AV_LOG_ERROR, "Extradata too small.\n");
+ if (h->c.avctx->extradata_size < 8 + 2 * f) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Extradata too small.\n");
return AVERROR_INVALIDDATA;
}
- new_w = 4 * s->avctx->extradata[6 + 2 * f];
- new_h = 4 * s->avctx->extradata[7 + 2 * f];
+ new_w = 4 * h->c.avctx->extradata[6 + 2 * f];
+ new_h = 4 * h->c.avctx->extradata[7 + 2 * f];
} else {
new_w = rv->orig_width;
new_h = rv->orig_height;
}
- if (new_w != s->width || new_h != s->height || !s->context_initialized) {
- AVRational old_aspect = s->avctx->sample_aspect_ratio;
- av_log(s->avctx, AV_LOG_DEBUG,
+ if (new_w != h->c.width || new_h != h->c.height || !h->c.context_initialized) {
+ AVRational old_aspect = h->c.avctx->sample_aspect_ratio;
+ av_log(h->c.avctx, AV_LOG_DEBUG,
"attempting to change resolution to %dx%d\n", new_w, new_h);
- if (av_image_check_size(new_w, new_h, 0, s->avctx) < 0)
+ if (av_image_check_size(new_w, new_h, 0, h->c.avctx) < 0)
return AVERROR_INVALIDDATA;
if (whole_size < (new_w + 15)/16 * ((new_h + 15)/16) / 8)
return AVERROR_INVALIDDATA;
- ff_mpv_common_end(s);
+ ff_mpv_common_end(&h->c);
// attempt to keep aspect during typical resolution switches
if (!old_aspect.num)
old_aspect = (AVRational){1, 1};
- if (2 * (int64_t)new_w * s->height == (int64_t)new_h * s->width)
- s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1});
- if ((int64_t)new_w * s->height == 2 * (int64_t)new_h * s->width)
- s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2});
+ if (2 * (int64_t)new_w * h->c.height == (int64_t)new_h * h->c.width)
+ h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1});
+ if ((int64_t)new_w * h->c.height == 2 * (int64_t)new_h * h->c.width)
+ h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2});
- ret = ff_set_dimensions(s->avctx, new_w, new_h);
+ ret = ff_set_dimensions(h->c.avctx, new_w, new_h);
if (ret < 0)
return ret;
- s->width = new_w;
- s->height = new_h;
- if ((ret = ff_mpv_common_init(s)) < 0)
+ h->c.width = new_w;
+ h->c.height = new_h;
+ if ((ret = ff_mpv_common_init(&h->c)) < 0)
return ret;
}
- if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max);
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
+ av_log(h->c.avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max);
}
}
- if (av_image_check_size(s->width, s->height, 0, s->avctx) < 0)
+ if (av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx) < 0)
return AVERROR_INVALIDDATA;
- mb_pos = ff_h263_decode_mba(s);
+ mb_pos = ff_h263_decode_mba(h);
- seq |= s->time & ~0x7FFF;
- if (seq - s->time > 0x4000)
+ seq |= h->c.time & ~0x7FFF;
+ if (seq - h->c.time > 0x4000)
seq -= 0x8000;
- if (seq - s->time < -0x4000)
+ if (seq - h->c.time < -0x4000)
seq += 0x8000;
- if (seq != s->time) {
- if (s->pict_type != AV_PICTURE_TYPE_B) {
- s->time = seq;
- s->pp_time = s->time - s->last_non_b_time;
- s->last_non_b_time = s->time;
+ if (seq != h->c.time) {
+ if (h->c.pict_type != AV_PICTURE_TYPE_B) {
+ h->c.time = seq;
+ h->c.pp_time = h->c.time - h->c.last_non_b_time;
+ h->c.last_non_b_time = h->c.time;
} else {
- s->time = seq;
- s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
+ h->c.time = seq;
+ h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
}
}
- if (s->pict_type == AV_PICTURE_TYPE_B) {
- if (s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0) {
- av_log(s->avctx, AV_LOG_DEBUG,
+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
+ if (h->c.pp_time <=h->c.pb_time || h->c.pp_time <= h->c.pp_time - h->c.pb_time || h->c.pp_time<=0) {
+ av_log(h->c.avctx, AV_LOG_DEBUG,
"messed up order, possible from seeking? skipping current B-frame\n");
#define ERROR_SKIP_FRAME -123
return ERROR_SKIP_FRAME;
}
- ff_mpeg4_init_direct_mv(s);
+ ff_mpeg4_init_direct_mv(&h->c);
}
- s->no_rounding = get_bits1(&s->gb);
+ h->c.no_rounding = get_bits1(&h->c.gb);
- if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B)
+ if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && h->c.pict_type == AV_PICTURE_TYPE_B)
// binary decoder reads 3+2 bits here but they don't seem to be used
- skip_bits(&s->gb, 5);
+ skip_bits(&h->c.gb, 5);
- s->h263_aic = s->pict_type == AV_PICTURE_TYPE_I;
- if (s->h263_aic) {
- s->y_dc_scale_table =
- s->c_dc_scale_table = ff_aic_dc_scale_table;
+ h->c.h263_aic = h->c.pict_type == AV_PICTURE_TYPE_I;
+ if (h->c.h263_aic) {
+ h->c.y_dc_scale_table =
+ h->c.c_dc_scale_table = ff_aic_dc_scale_table;
} else {
- s->y_dc_scale_table =
- s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
+ h->c.y_dc_scale_table =
+ h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table;
}
- if (!s->avctx->lowres)
- s->loop_filter = 1;
+ if (!h->c.avctx->lowres)
+ h->c.loop_filter = 1;
- if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_INFO,
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
+ av_log(h->c.avctx, AV_LOG_INFO,
"num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n",
- seq, s->mb_x, s->mb_y, s->pict_type, s->qscale,
- s->no_rounding);
+ seq, h->c.mb_x, h->c.mb_y, h->c.pict_type, h->c.qscale,
+ h->c.no_rounding);
}
- av_assert0(s->pict_type != AV_PICTURE_TYPE_B || !s->low_delay);
+ av_assert0(h->c.pict_type != AV_PICTURE_TYPE_B || !h->c.low_delay);
- return s->mb_width * s->mb_height - mb_pos;
+ return h->c.mb_width * h->c.mb_height - mb_pos;
}
static av_cold void rv10_build_vlc(VLCElem vlc[], int table_size,
@@ -351,7 +351,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
{
static AVOnce init_static_once = AV_ONCE_INIT;
RVDecContext *rv = avctx->priv_data;
- MpegEncContext *s = &rv->m;
+ H263DecContext *const h = &rv->h;
int major_ver, minor_ver, micro_ver, ret;
if (avctx->extradata_size < 8) {
@@ -369,11 +369,11 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
rv->orig_width = avctx->coded_width;
rv->orig_height = avctx->coded_height;
- s->h263_long_vectors = avctx->extradata[3] & 1;
+ h->c.h263_long_vectors = avctx->extradata[3] & 1;
rv->sub_id = AV_RB32A(avctx->extradata + 4);
if (avctx->codec_id == AV_CODEC_ID_RV20) {
- s->modified_quant = 1;
- s->chroma_qscale_table = ff_h263_chroma_qscale_table;
+ h->c.modified_quant = 1;
+ h->c.chroma_qscale_table = ff_h263_chroma_qscale_table;
}
major_ver = RV_GET_MAJOR_VER(rv->sub_id);
@@ -382,12 +382,12 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
switch (major_ver) {
case 1:
- s->rv10_version = micro_ver ? 3 : 1;
- s->obmc = micro_ver == 2;
+ h->c.rv10_version = micro_ver ? 3 : 1;
+ h->c.obmc = micro_ver == 2;
break;
case 2:
if (minor_ver >= 2) {
- s->low_delay = 0;
+ h->c.low_delay = 0;
avctx->has_b_frames = 1;
}
break;
@@ -412,126 +412,126 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
int buf_size, int buf_size2, int whole_size)
{
RVDecContext *rv = avctx->priv_data;
- MpegEncContext *s = &rv->m;
+ H263DecContext *const h = &rv->h;
int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret;
active_bits_size = buf_size * 8;
- init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8);
- if (s->codec_id == AV_CODEC_ID_RV10)
- mb_count = rv10_decode_picture_header(s);
+ init_get_bits(&h->c.gb, buf, FFMAX(buf_size, buf_size2) * 8);
+ if (h->c.codec_id == AV_CODEC_ID_RV10)
+ mb_count = rv10_decode_picture_header(h);
else
mb_count = rv20_decode_picture_header(rv, whole_size);
if (mb_count < 0) {
if (mb_count != ERROR_SKIP_FRAME)
- av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "HEADER ERROR\n");
return AVERROR_INVALIDDATA;
}
- if (s->mb_x >= s->mb_width ||
- s->mb_y >= s->mb_height) {
- av_log(s->avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", s->mb_x, s->mb_y);
+ if (h->c.mb_x >= h->c.mb_width ||
+ h->c.mb_y >= h->c.mb_height) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
- mb_pos = s->mb_y * s->mb_width + s->mb_x;
- left = s->mb_width * s->mb_height - mb_pos;
+ mb_pos = h->c.mb_y * h->c.mb_width + h->c.mb_x;
+ left = h->c.mb_width * h->c.mb_height - mb_pos;
if (mb_count > left) {
- av_log(s->avctx, AV_LOG_ERROR, "COUNT ERROR\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "COUNT ERROR\n");
return AVERROR_INVALIDDATA;
}
- if (whole_size < s->mb_width * s->mb_height / 8)
+ if (whole_size < h->c.mb_width * h->c.mb_height / 8)
return AVERROR_INVALIDDATA;
- if ((s->mb_x == 0 && s->mb_y == 0) || !s->cur_pic.ptr) {
+ if ((h->c.mb_x == 0 && h->c.mb_y == 0) || !h->c.cur_pic.ptr) {
// FIXME write parser so we always have complete frames?
- if (s->cur_pic.ptr) {
- ff_er_frame_end(&s->er, NULL);
- ff_mpv_frame_end(s);
- s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
+ if (h->c.cur_pic.ptr) {
+ ff_er_frame_end(&h->c.er, NULL);
+ ff_mpv_frame_end(&h->c);
+ h->c.mb_x = h->c.mb_y = h->c.resync_mb_x = h->c.resync_mb_y = 0;
}
- if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
+ if ((ret = ff_mpv_frame_start(&h->c, avctx)) < 0)
return ret;
- ff_mpeg_er_frame_start(s);
+ ff_mpeg_er_frame_start(&h->c);
} else {
- if (s->cur_pic.ptr->f->pict_type != s->pict_type) {
- av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n");
+ if (h->c.cur_pic.ptr->f->pict_type != h->c.pict_type) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "Slice type mismatch\n");
return AVERROR_INVALIDDATA;
}
}
- ff_dlog(avctx, "qscale=%d\n", s->qscale);
+ ff_dlog(avctx, "qscale=%d\n", h->c.qscale);
/* default quantization values */
- if (s->codec_id == AV_CODEC_ID_RV10) {
- if (s->mb_y == 0)
- s->first_slice_line = 1;
+ if (h->c.codec_id == AV_CODEC_ID_RV10) {
+ if (h->c.mb_y == 0)
+ h->c.first_slice_line = 1;
} else {
- s->first_slice_line = 1;
- s->resync_mb_x = s->mb_x;
+ h->c.first_slice_line = 1;
+ h->c.resync_mb_x = h->c.mb_x;
}
- start_mb_x = s->mb_x;
- s->resync_mb_y = s->mb_y;
+ start_mb_x = h->c.mb_x;
+ h->c.resync_mb_y = h->c.mb_y;
- ff_set_qscale(s, s->qscale);
+ ff_set_qscale(&h->c, h->c.qscale);
- s->rv10_first_dc_coded[0] = 0;
- s->rv10_first_dc_coded[1] = 0;
- s->rv10_first_dc_coded[2] = 0;
- ff_init_block_index(s);
+ h->c.rv10_first_dc_coded[0] = 0;
+ h->c.rv10_first_dc_coded[1] = 0;
+ h->c.rv10_first_dc_coded[2] = 0;
+ ff_init_block_index(&h->c);
/* decode each macroblock */
- for (s->mb_num_left = mb_count; s->mb_num_left > 0; s->mb_num_left--) {
+ for (h->c.mb_num_left = mb_count; h->c.mb_num_left > 0; h->c.mb_num_left--) {
int ret;
- ff_update_block_index(s, 8, s->avctx->lowres, 1);
- ff_tlog(avctx, "**mb x=%d y=%d\n", s->mb_x, s->mb_y);
+ ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
+ ff_tlog(avctx, "**mb x=%d y=%d\n", h->c.mb_x, h->c.mb_y);
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- ret = ff_h263_decode_mb(s, s->block);
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ ret = ff_h263_decode_mb(h, h->c.block);
// Repeat the slice end check from ff_h263_decode_mb with our active
// bitstream size
- if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&s->gb)) {
- int v = show_bits(&s->gb, 16);
+ if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->c.gb)) {
+ int v = show_bits(&h->c.gb, 16);
- if (get_bits_count(&s->gb) + 16 > active_bits_size)
- v >>= get_bits_count(&s->gb) + 16 - active_bits_size;
+ if (get_bits_count(&h->c.gb) + 16 > active_bits_size)
+ v >>= get_bits_count(&h->c.gb) + 16 - active_bits_size;
if (!v)
ret = SLICE_END;
}
- if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&s->gb) &&
- 8 * buf_size2 >= get_bits_count(&s->gb)) {
+ if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&h->c.gb) &&
+ 8 * buf_size2 >= get_bits_count(&h->c.gb)) {
active_bits_size = buf_size2 * 8;
av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
8 * buf_size, active_bits_size);
ret = SLICE_OK;
}
- if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) {
- av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x,
- s->mb_y);
+ if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->c.gb)) {
+ av_log(h->c.avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", h->c.mb_x,
+ h->c.mb_y);
return AVERROR_INVALIDDATA;
}
- if (s->pict_type != AV_PICTURE_TYPE_B)
- ff_h263_update_motion_val(s);
- ff_mpv_reconstruct_mb(s, s->block);
- if (s->loop_filter)
- ff_h263_loop_filter(s);
-
- if (++s->mb_x == s->mb_width) {
- s->mb_x = 0;
- s->mb_y++;
- ff_init_block_index(s);
+ if (h->c.pict_type != AV_PICTURE_TYPE_B)
+ ff_h263_update_motion_val(&h->c);
+ ff_mpv_reconstruct_mb(&h->c, h->c.block);
+ if (h->c.loop_filter)
+ ff_h263_loop_filter(&h->c);
+
+ if (++h->c.mb_x == h->c.mb_width) {
+ h->c.mb_x = 0;
+ h->c.mb_y++;
+ ff_init_block_index(&h->c);
}
- if (s->mb_x == s->resync_mb_x)
- s->first_slice_line = 0;
+ if (h->c.mb_x == h->c.resync_mb_x)
+ h->c.first_slice_line = 0;
if (ret == SLICE_END)
break;
}
- ff_er_add_slice(&s->er, start_mb_x, s->resync_mb_y, s->mb_x - 1, s->mb_y,
+ ff_er_add_slice(&h->c.er, start_mb_x, h->c.resync_mb_y, h->c.mb_x - 1, h->c.mb_y,
ER_MB_END);
return active_bits_size;
diff --git a/libavcodec/rv10dec.h b/libavcodec/rv10dec.h
index daa6b8d653..e878e164b3 100644
--- a/libavcodec/rv10dec.h
+++ b/libavcodec/rv10dec.h
@@ -21,8 +21,8 @@
#ifndef AVCODEC_RV10DEC_H
#define AVCODEC_RV10DEC_H
-#include "mpegvideo.h"
+struct H263DecContext;
-int ff_rv_decode_dc(MpegEncContext *s, int n);
+int ff_rv_decode_dc(struct H263DecContext *const h, int n);
#endif /* AVCODEC_RV10DEC_H */
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index 533e6750a1..cc4f6d3345 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -51,7 +51,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx,
av_unused uint32_t size)
{
Mpeg4DecContext *ctx = avctx->priv_data;
- MpegEncContext *s = &ctx->m;
+ MPVContext *const s = &ctx->h.c;
VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
VAPictureParameterBufferMPEG4 pic_param;
int i, err;
diff --git a/libavcodec/vdpau_mpeg4.c b/libavcodec/vdpau_mpeg4.c
index 7ec7a74ad1..668720a231 100644
--- a/libavcodec/vdpau_mpeg4.c
+++ b/libavcodec/vdpau_mpeg4.c
@@ -34,7 +34,7 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx,
const uint8_t *buffer, uint32_t size)
{
Mpeg4DecContext *ctx = avctx->priv_data;
- MpegEncContext * const s = &ctx->m;
+ MPVContext *const s = &ctx->h.c;
MPVPicture *pic = s->cur_pic.ptr;
struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
diff --git a/libavcodec/wmv2.h b/libavcodec/wmv2.h
index 6fc9704c3d..409d9456ab 100644
--- a/libavcodec/wmv2.h
+++ b/libavcodec/wmv2.h
@@ -44,7 +44,7 @@ void ff_mspel_motion(MpegEncContext *s,
int motion_x, int motion_y, int h);
-static av_always_inline int wmv2_get_cbp_table_index(MpegEncContext *s, int cbp_index)
+static av_always_inline int wmv2_get_cbp_table_index(int qscale, int cbp_index)
{
static const uint8_t map[3][3] = {
{ 0, 2, 1 },
@@ -52,7 +52,7 @@ static av_always_inline int wmv2_get_cbp_table_index(MpegEncContext *s, int cbp_
{ 2, 1, 0 },
};
- return map[(s->qscale > 10) + (s->qscale > 20)][cbp_index];
+ return map[(qscale > 10) + (qscale > 20)][cbp_index];
}
#endif /* AVCODEC_WMV2_H */
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 301c786633..c7b000ec7a 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -59,9 +59,9 @@ typedef struct WMV2DecContext {
static void wmv2_add_block(WMV2DecContext *w, int16_t *block1,
uint8_t *dst, int stride, int n)
{
- MpegEncContext *const s = &w->ms.m;
+ H263DecContext *const h = &w->ms.h;
- if (s->block_last_index[n] >= 0) {
+ if (h->c.block_last_index[n] >= 0) {
switch (w->abt_type_table[n]) {
case 0:
w->common.wdsp.idct_add(dst, stride, block1);
@@ -69,15 +69,15 @@ static void wmv2_add_block(WMV2DecContext *w, int16_t *block1,
case 1:
ff_simple_idct84_add(dst, stride, block1);
ff_simple_idct84_add(dst + 4 * stride, stride, w->abt_block2[n]);
- s->bdsp.clear_block(w->abt_block2[n]);
+ h->c.bdsp.clear_block(w->abt_block2[n]);
break;
case 2:
ff_simple_idct48_add(dst, stride, block1);
ff_simple_idct48_add(dst + 4, stride, w->abt_block2[n]);
- s->bdsp.clear_block(w->abt_block2[n]);
+ h->c.bdsp.clear_block(w->abt_block2[n]);
break;
default:
- av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
+ av_log(h->c.avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
}
}
}
@@ -101,64 +101,63 @@ void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64],
static int parse_mb_skip(WMV2DecContext *w)
{
- int mb_x, mb_y;
+ H263DecContext *const h = &w->ms.h;
int coded_mb_count = 0;
- MpegEncContext *const s = &w->ms.m;
- uint32_t *const mb_type = s->cur_pic.mb_type;
+ uint32_t *const mb_type = h->c.cur_pic.mb_type;
- w->skip_type = get_bits(&s->gb, 2);
+ w->skip_type = get_bits(&h->c.gb, 2);
switch (w->skip_type) {
case SKIP_TYPE_NONE:
- for (mb_y = 0; mb_y < s->mb_height; mb_y++)
- for (mb_x = 0; mb_x < s->mb_width; mb_x++)
- mb_type[mb_y * s->mb_stride + mb_x] =
+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
+ mb_type[mb_y * h->c.mb_stride + mb_x] =
MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
break;
case SKIP_TYPE_MPEG:
- if (get_bits_left(&s->gb) < s->mb_height * s->mb_width)
+ if (get_bits_left(&h->c.gb) < h->c.mb_height * h->c.mb_width)
return AVERROR_INVALIDDATA;
- for (mb_y = 0; mb_y < s->mb_height; mb_y++)
- for (mb_x = 0; mb_x < s->mb_width; mb_x++)
- mb_type[mb_y * s->mb_stride + mb_x] =
- (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
+ mb_type[mb_y * h->c.mb_stride + mb_x] =
+ (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
break;
case SKIP_TYPE_ROW:
- for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
- if (get_bits_left(&s->gb) < 1)
+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) {
+ if (get_bits_left(&h->c.gb) < 1)
return AVERROR_INVALIDDATA;
- if (get_bits1(&s->gb)) {
- for (mb_x = 0; mb_x < s->mb_width; mb_x++)
- mb_type[mb_y * s->mb_stride + mb_x] =
+ if (get_bits1(&h->c.gb)) {
+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
+ mb_type[mb_y * h->c.mb_stride + mb_x] =
MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
} else {
- for (mb_x = 0; mb_x < s->mb_width; mb_x++)
- mb_type[mb_y * s->mb_stride + mb_x] =
- (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
+ mb_type[mb_y * h->c.mb_stride + mb_x] =
+ (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
}
}
break;
case SKIP_TYPE_COL:
- for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
- if (get_bits_left(&s->gb) < 1)
+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) {
+ if (get_bits_left(&h->c.gb) < 1)
return AVERROR_INVALIDDATA;
- if (get_bits1(&s->gb)) {
- for (mb_y = 0; mb_y < s->mb_height; mb_y++)
- mb_type[mb_y * s->mb_stride + mb_x] =
+ if (get_bits1(&h->c.gb)) {
+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
+ mb_type[mb_y * h->c.mb_stride + mb_x] =
MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
} else {
- for (mb_y = 0; mb_y < s->mb_height; mb_y++)
- mb_type[mb_y * s->mb_stride + mb_x] =
- (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
+ mb_type[mb_y * h->c.mb_stride + mb_x] =
+ (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
}
}
break;
}
- for (mb_y = 0; mb_y < s->mb_height; mb_y++)
- for (mb_x = 0; mb_x < s->mb_width; mb_x++)
- coded_mb_count += !IS_SKIP(mb_type[mb_y * s->mb_stride + mb_x]);
+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
+ coded_mb_count += !IS_SKIP(mb_type[mb_y * h->c.mb_stride + mb_x]);
- if (coded_mb_count > get_bits_left(&s->gb))
+ if (coded_mb_count > get_bits_left(&h->c.gb))
return AVERROR_INVALIDDATA;
return 0;
@@ -166,20 +165,20 @@ static int parse_mb_skip(WMV2DecContext *w)
static int decode_ext_header(WMV2DecContext *w)
{
- MpegEncContext *const s = &w->ms.m;
+ H263DecContext *const h = &w->ms.h;
GetBitContext gb;
int fps;
int code;
- if (s->avctx->extradata_size < 4)
+ if (h->c.avctx->extradata_size < 4)
return AVERROR_INVALIDDATA;
- init_get_bits(&gb, s->avctx->extradata, 32);
+ init_get_bits(&gb, h->c.avctx->extradata, 32);
fps = get_bits(&gb, 5);
w->ms.bit_rate = get_bits(&gb, 11) * 1024;
w->mspel_bit = get_bits1(&gb);
- s->loop_filter = get_bits1(&gb);
+ h->c.loop_filter = get_bits1(&gb);
w->abt_flag = get_bits1(&gb);
w->j_type_bit = get_bits1(&gb);
w->top_left_mv_flag = get_bits1(&gb);
@@ -189,36 +188,36 @@ static int decode_ext_header(WMV2DecContext *w)
if (code == 0)
return AVERROR_INVALIDDATA;
- s->slice_height = s->mb_height / code;
+ h->c.slice_height = h->c.mb_height / code;
- if (s->avctx->debug & FF_DEBUG_PICT_INFO)
- av_log(s->avctx, AV_LOG_DEBUG,
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
+ av_log(h->c.avctx, AV_LOG_DEBUG,
"fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, "
"tl_mv_flag:%d, mbrl_bit:%d, code:%d, loop_filter:%d, "
"slices:%d\n",
fps, w->ms.bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit,
- w->top_left_mv_flag, w->per_mb_rl_bit, code, s->loop_filter,
+ w->top_left_mv_flag, w->per_mb_rl_bit, code, h->c.loop_filter,
code);
return 0;
}
-int ff_wmv2_decode_picture_header(MpegEncContext *s)
+int ff_wmv2_decode_picture_header(H263DecContext *const h)
{
int code;
- s->pict_type = get_bits1(&s->gb) + 1;
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- code = get_bits(&s->gb, 7);
- av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
+ h->c.pict_type = get_bits1(&h->c.gb) + 1;
+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
+ code = get_bits(&h->c.gb, 7);
+ av_log(h->c.avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
}
- s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
- if (s->qscale <= 0)
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
+ if (h->c.qscale <= 0)
return AVERROR_INVALIDDATA;
- if (s->pict_type != AV_PICTURE_TYPE_I && show_bits(&s->gb, 1)) {
- GetBitContext gb = s->gb;
+ if (h->c.pict_type != AV_PICTURE_TYPE_I && show_bits(&h->c.gb, 1)) {
+ GetBitContext gb = h->c.gb;
int skip_type = get_bits(&gb, 2);
- int run = skip_type == SKIP_TYPE_COL ? s->mb_width : s->mb_height;
+ int run = skip_type == SKIP_TYPE_COL ? h->c.mb_width : h->c.mb_height;
while (run > 0) {
int block = FFMIN(run, 25);
@@ -233,46 +232,46 @@ int ff_wmv2_decode_picture_header(MpegEncContext *s)
return 0;
}
-int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
+int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)
{
- WMV2DecContext *const w = (WMV2DecContext *) s;
+ WMV2DecContext *const w = (WMV2DecContext *)h;
- if (s->pict_type == AV_PICTURE_TYPE_I) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
/* Is filling with zeroes really the right thing to do? */
- memset(s->cur_pic.mb_type, 0,
- sizeof(*s->cur_pic.mb_type) * s->mb_height * s->mb_stride);
+ memset(h->c.cur_pic.mb_type, 0,
+ sizeof(*h->c.cur_pic.mb_type) * h->c.mb_height * h->c.mb_stride);
if (w->j_type_bit)
- w->j_type = get_bits1(&s->gb);
+ w->j_type = get_bits1(&h->c.gb);
else
w->j_type = 0; // FIXME check
if (!w->j_type) {
if (w->per_mb_rl_bit)
- w->ms.per_mb_rl_table = get_bits1(&s->gb);
+ w->ms.per_mb_rl_table = get_bits1(&h->c.gb);
else
w->ms.per_mb_rl_table = 0;
if (!w->ms.per_mb_rl_table) {
- w->ms.rl_chroma_table_index = decode012(&s->gb);
- w->ms.rl_table_index = decode012(&s->gb);
+ w->ms.rl_chroma_table_index = decode012(&h->c.gb);
+ w->ms.rl_table_index = decode012(&h->c.gb);
}
- w->ms.dc_table_index = get_bits1(&s->gb);
+ w->ms.dc_table_index = get_bits1(&h->c.gb);
// at minimum one bit per macroblock is required at least in a valid frame,
// we discard frames much smaller than this. Frames smaller than 1/8 of the
// smallest "black/skip" frame generally contain not much recoverable content
// while at the same time they have the highest computational requirements
// per byte
- if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
+ if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
return AVERROR_INVALIDDATA;
}
- s->inter_intra_pred = 0;
- s->no_rounding = 1;
- if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_DEBUG,
+ h->c.inter_intra_pred = 0;
+ h->c.no_rounding = 1;
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
+ av_log(h->c.avctx, AV_LOG_DEBUG,
"qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
- s->qscale, w->ms.rl_chroma_table_index, w->ms.rl_table_index,
+ h->c.qscale, w->ms.rl_chroma_table_index, w->ms.rl_table_index,
w->ms.dc_table_index, w->ms.per_mb_rl_table, w->j_type);
}
} else {
@@ -283,61 +282,61 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
ret = parse_mb_skip(w);
if (ret < 0)
return ret;
- cbp_index = decode012(&s->gb);
- w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index);
+ cbp_index = decode012(&h->c.gb);
+ w->cbp_table_index = wmv2_get_cbp_table_index(h->c.qscale, cbp_index);
if (w->mspel_bit)
- s->mspel = get_bits1(&s->gb);
+ h->c.mspel = get_bits1(&h->c.gb);
else
- s->mspel = 0; // FIXME check
+ h->c.mspel = 0; // FIXME check
if (w->abt_flag) {
- w->per_mb_abt = get_bits1(&s->gb) ^ 1;
+ w->per_mb_abt = get_bits1(&h->c.gb) ^ 1;
if (!w->per_mb_abt)
- w->abt_type = decode012(&s->gb);
+ w->abt_type = decode012(&h->c.gb);
}
if (w->per_mb_rl_bit)
- w->ms.per_mb_rl_table = get_bits1(&s->gb);
+ w->ms.per_mb_rl_table = get_bits1(&h->c.gb);
else
w->ms.per_mb_rl_table = 0;
if (!w->ms.per_mb_rl_table) {
- w->ms.rl_table_index = decode012(&s->gb);
+ w->ms.rl_table_index = decode012(&h->c.gb);
w->ms.rl_chroma_table_index = w->ms.rl_table_index;
}
- if (get_bits_left(&s->gb) < 2)
+ if (get_bits_left(&h->c.gb) < 2)
return AVERROR_INVALIDDATA;
- w->ms.dc_table_index = get_bits1(&s->gb);
- w->ms.mv_table_index = get_bits1(&s->gb);
+ w->ms.dc_table_index = get_bits1(&h->c.gb);
+ w->ms.mv_table_index = get_bits1(&h->c.gb);
- s->inter_intra_pred = 0; // (s->width * s->height < 320 * 240 && w->ms.bit_rate <= II_BITRATE);
- s->no_rounding ^= 1;
+ h->c.inter_intra_pred = 0; // (h->c.width * h->c.height < 320 * 240 && w->ms.bit_rate <= II_BITRATE);
+ h->c.no_rounding ^= 1;
- if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_DEBUG,
+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
+ av_log(h->c.avctx, AV_LOG_DEBUG,
"rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d "
"per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
w->ms.rl_table_index, w->ms.rl_chroma_table_index,
w->ms.dc_table_index, w->ms.mv_table_index,
- w->ms.per_mb_rl_table, s->qscale, s->mspel,
+ w->ms.per_mb_rl_table, h->c.qscale, h->c.mspel,
w->per_mb_abt, w->abt_type, w->cbp_table_index,
- s->inter_intra_pred);
+ h->c.inter_intra_pred);
}
}
w->ms.esc3_level_length = 0;
w->ms.esc3_run_length = 0;
if (w->j_type) {
- ff_intrax8_decode_picture(&w->x8, s->cur_pic.ptr,
- &s->gb, &s->mb_x, &s->mb_y,
- 2 * s->qscale, (s->qscale - 1) | 1,
- s->loop_filter, s->low_delay);
+ ff_intrax8_decode_picture(&w->x8, h->c.cur_pic.ptr,
+ &h->c.gb, &h->c.mb_x, &h->c.mb_y,
+ 2 * h->c.qscale, (h->c.qscale - 1) | 1,
+ h->c.loop_filter, h->c.low_delay);
- ff_er_add_slice(&s->er, 0, 0,
- (s->mb_x >> 1) - 1, (s->mb_y >> 1) - 1,
+ ff_er_add_slice(&h->c.er, 0, 0,
+ (h->c.mb_x >> 1) - 1, (h->c.mb_y >> 1) - 1,
ER_MB_END);
return 1;
}
@@ -347,38 +346,37 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
static inline void wmv2_decode_motion(WMV2DecContext *w, int *mx_ptr, int *my_ptr)
{
- MpegEncContext *const s = &w->ms.m;
+ H263DecContext *const h = &w->ms.h;
ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr);
- if ((((*mx_ptr) | (*my_ptr)) & 1) && s->mspel)
- w->common.hshift = get_bits1(&s->gb);
+ if ((((*mx_ptr) | (*my_ptr)) & 1) && h->c.mspel)
+ w->common.hshift = get_bits1(&h->c.gb);
else
w->common.hshift = 0;
}
static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py)
{
- MpegEncContext *const s = &w->ms.m;
- int xy, wrap, diff, type;
- int16_t *A, *B, *C, *mot_val;
+ H263DecContext *const h = &w->ms.h;
+ int diff, type;
- wrap = s->b8_stride;
- xy = s->block_index[0];
+ int wrap = h->c.b8_stride;
+ int xy = h->c.block_index[0];
- mot_val = s->cur_pic.motion_val[0][xy];
+ int16_t *mot_val = h->c.cur_pic.motion_val[0][xy];
- A = s->cur_pic.motion_val[0][xy - 1];
- B = s->cur_pic.motion_val[0][xy - wrap];
- C = s->cur_pic.motion_val[0][xy + 2 - wrap];
+ const int16_t *A = h->c.cur_pic.motion_val[0][xy - 1];
+ const int16_t *B = h->c.cur_pic.motion_val[0][xy - wrap];
+ const int16_t *C = h->c.cur_pic.motion_val[0][xy + 2 - wrap];
- if (s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag)
+ if (h->c.mb_x && !h->c.first_slice_line && !h->c.mspel && w->top_left_mv_flag)
diff = FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1]));
else
diff = 0;
if (diff >= 8)
- type = get_bits1(&s->gb);
+ type = get_bits1(&h->c.gb);
else
type = 2;
@@ -390,7 +388,7 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py)
*py = B[1];
} else {
/* special case for first (slice) line */
- if (s->first_slice_line) {
+ if (h->c.first_slice_line) {
*px = A[0];
*py = A[1];
} else {
@@ -405,23 +403,23 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py)
static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block,
int n, int cbp)
{
- MpegEncContext *const s = &w->ms.m;
+ H263DecContext *const h = &w->ms.h;
static const int sub_cbp_table[3] = { 2, 3, 1 };
int sub_cbp, ret;
if (!cbp) {
- s->block_last_index[n] = -1;
+ h->c.block_last_index[n] = -1;
return 0;
}
if (w->per_block_abt)
- w->abt_type = decode012(&s->gb);
+ w->abt_type = decode012(&h->c.gb);
w->abt_type_table[n] = w->abt_type;
if (w->abt_type) {
const uint8_t *scantable = w->abt_type == 1 ? ff_wmv2_scantableA : ff_wmv2_scantableB;
- sub_cbp = sub_cbp_table[decode012(&s->gb)];
+ sub_cbp = sub_cbp_table[decode012(&h->c.gb)];
if (sub_cbp & 1) {
ret = ff_msmpeg4_decode_block(&w->ms, block, n, 1, scantable);
@@ -435,20 +433,20 @@ static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block,
return ret;
}
- s->block_last_index[n] = 63;
+ h->c.block_last_index[n] = 63;
return 0;
} else {
return ff_msmpeg4_decode_block(&w->ms, block, n, 1,
- s->inter_scantable.permutated);
+ h->c.inter_scantable.permutated);
}
}
-static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
+static int wmv2_decode_mb(H263DecContext *const h, int16_t block[6][64])
{
- /* The following is only allowed because this encoder
+ /* The following is only allowed because this decoder
* does not use slice threading. */
- WMV2DecContext *const w = (WMV2DecContext *) s;
+ WMV2DecContext *const w = (WMV2DecContext *) h;
MSMP4DecContext *const ms = &w->ms;
int cbp, code, i, ret;
uint8_t *coded_val;
@@ -456,40 +454,40 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
if (w->j_type)
return 0;
- if (s->pict_type == AV_PICTURE_TYPE_P) {
- if (IS_SKIP(s->cur_pic.mb_type[s->mb_y * s->mb_stride + s->mb_x])) {
+ if (h->c.pict_type == AV_PICTURE_TYPE_P) {
+ if (IS_SKIP(h->c.cur_pic.mb_type[h->c.mb_y * h->c.mb_stride + h->c.mb_x])) {
/* skip mb */
- s->mb_intra = 0;
+ h->c.mb_intra = 0;
for (i = 0; i < 6; i++)
- s->block_last_index[i] = -1;
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
- s->mb_skipped = 1;
+ h->c.block_last_index[i] = -1;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ h->c.mv[0][0][0] = 0;
+ h->c.mv[0][0][1] = 0;
+ h->c.mb_skipped = 1;
w->common.hshift = 0;
return 0;
}
- if (get_bits_left(&s->gb) <= 0)
+ if (get_bits_left(&h->c.gb) <= 0)
return AVERROR_INVALIDDATA;
- code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[w->cbp_table_index],
+ code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[w->cbp_table_index],
MB_NON_INTRA_VLC_BITS, 3);
- s->mb_intra = (~code & 0x40) >> 6;
+ h->c.mb_intra = (~code & 0x40) >> 6;
cbp = code & 0x3f;
} else {
- s->mb_intra = 1;
- if (get_bits_left(&s->gb) <= 0)
+ h->c.mb_intra = 1;
+ if (get_bits_left(&h->c.gb) <= 0)
return AVERROR_INVALIDDATA;
- code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc,
+ code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc,
MSMP4_MB_INTRA_VLC_BITS, 2);
/* predict coded block pattern */
cbp = 0;
for (i = 0; i < 6; i++) {
int val = ((code >> (5 - i)) & 1);
if (i < 4) {
- int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
+ int pred = ff_msmpeg4_coded_block_pred(&h->c, i, &coded_val);
val = val ^ pred;
*coded_val = val;
}
@@ -497,65 +495,65 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
}
}
- if (!s->mb_intra) {
+ if (!h->c.mb_intra) {
int mx, my;
wmv2_pred_motion(w, &mx, &my);
if (cbp) {
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
if (ms->per_mb_rl_table) {
- ms->rl_table_index = decode012(&s->gb);
+ ms->rl_table_index = decode012(&h->c.gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
if (w->abt_flag && w->per_mb_abt) {
- w->per_block_abt = get_bits1(&s->gb);
+ w->per_block_abt = get_bits1(&h->c.gb);
if (!w->per_block_abt)
- w->abt_type = decode012(&s->gb);
+ w->abt_type = decode012(&h->c.gb);
} else
w->per_block_abt = 0;
}
wmv2_decode_motion(w, &mx, &my);
- s->mv_dir = MV_DIR_FORWARD;
- s->mv_type = MV_TYPE_16X16;
- s->mv[0][0][0] = mx;
- s->mv[0][0][1] = my;
+ h->c.mv_dir = MV_DIR_FORWARD;
+ h->c.mv_type = MV_TYPE_16X16;
+ h->c.mv[0][0][0] = mx;
+ h->c.mv[0][0][1] = my;
for (i = 0; i < 6; i++) {
if ((ret = wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1)) < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"\nerror while decoding inter block: %d x %d (%d)\n",
- s->mb_x, s->mb_y, i);
+ h->c.mb_x, h->c.mb_y, i);
return ret;
}
}
} else {
- if (s->pict_type == AV_PICTURE_TYPE_P)
- ff_dlog(s->avctx, "%d%d ", s->inter_intra_pred, cbp);
- ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
+ if (h->c.pict_type == AV_PICTURE_TYPE_P)
+ ff_dlog(h->c.avctx, "%d%d ", h->c.inter_intra_pred, cbp);
+ ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0),
- show_bits(&s->gb, 24));
- s->ac_pred = get_bits1(&s->gb);
- if (s->inter_intra_pred) {
- s->h263_aic_dir = get_vlc2(&s->gb, ff_inter_intra_vlc,
+ show_bits(&h->c.gb, 24));
+ h->c.ac_pred = get_bits1(&h->c.gb);
+ if (h->c.inter_intra_pred) {
+ h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc,
INTER_INTRA_VLC_BITS, 1);
- ff_dlog(s->avctx, "%d%d %d %d/",
- s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
+ ff_dlog(h->c.avctx, "%d%d %d %d/",
+ h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
}
if (ms->per_mb_rl_table && cbp) {
- ms->rl_table_index = decode012(&s->gb);
+ ms->rl_table_index = decode012(&h->c.gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
- s->bdsp.clear_blocks(s->block[0]);
+ h->c.bdsp.clear_blocks(h->c.block[0]);
for (i = 0; i < 6; i++) {
ret = ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL);
if (ret < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ av_log(h->c.avctx, AV_LOG_ERROR,
"\nerror while decoding intra block: %d x %d (%d)\n",
- s->mb_x, s->mb_y, i);
+ h->c.mb_x, h->c.mb_y, i);
return ret;
}
}
@@ -567,7 +565,8 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
static av_cold int wmv2_decode_init(AVCodecContext *avctx)
{
WMV2DecContext *const w = avctx->priv_data;
- MpegEncContext *const s = &w->ms.m;
+ H263DecContext *const h = &w->ms.h;
+ MpegEncContext *const s = &h->c;
int ret;
s->private_ctx = &w->common;
@@ -575,13 +574,13 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx)
if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
return ret;
- s->decode_mb = wmv2_decode_mb;
+ h->decode_mb = wmv2_decode_mb;
ff_wmv2_common_init(s);
decode_ext_header(w);
- return ff_intrax8_common_init(avctx, &w->x8, s->block[0],
+ return ff_intrax8_common_init(avctx, &w->x8, h->c.block[0],
s->mb_width, s->mb_height);
}
diff --git a/libavcodec/wmv2dec.h b/libavcodec/wmv2dec.h
index bc8745bf6f..4dd9359dc9 100644
--- a/libavcodec/wmv2dec.h
+++ b/libavcodec/wmv2dec.h
@@ -22,9 +22,10 @@
#define AVCODEC_WMV2DEC_H
#include "mpegvideo.h"
+struct H263DecContext;
-int ff_wmv2_decode_picture_header(MpegEncContext * s);
-int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
+int ff_wmv2_decode_picture_header(struct H263DecContext *const h);
+int ff_wmv2_decode_secondary_picture_header(struct H263DecContext *const h);
void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64],
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index 0eef5b7cfb..9e1d62b90e 100644
--- a/libavcodec/wmv2enc.c
+++ b/libavcodec/wmv2enc.c
@@ -118,7 +118,7 @@ static int wmv2_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb, 2, SKIP_TYPE_NONE);
ff_msmpeg4_code012(&s->pb, cbp_index = 0);
- w->cbp_table_index = wmv2_get_cbp_table_index(&s->c, cbp_index);
+ w->cbp_table_index = wmv2_get_cbp_table_index(s->c.qscale, cbp_index);
if (w->mspel_bit)
put_bits(&s->pb, 1, s->c.mspel);
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 27/48] avcodec/h263dec: Remove redundant block parameter from decode_mb
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (25 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 26/48] avcodec/h263dec: Add H263DecContext Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 28/48] avcodec/h263dec: Don't use MpegEncContext.block Andreas Rheinhardt
` (20 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
With the exception of mpeg4_decode_studio_mb(), all decode_mb
functions implicitly presumed that the block provided as
argument coincides with MpegEncContext.block (they zeroed the latter
and then used the former to decode the block); mpeg4_decode_studio_mb()
meanwhile did not use the provided block at all (it uses blocks of
int32_t). So remove said parameter.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 2 +-
libavcodec/h263dec.h | 5 ++---
libavcodec/ituh263dec.c | 8 ++++----
libavcodec/mpeg4videodec.c | 12 ++++++------
libavcodec/msmpeg4dec.c | 8 ++++----
libavcodec/rv10.c | 2 +-
libavcodec/wmv2dec.c | 6 +++---
7 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 22bcf40681..5a5a91e675 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -256,7 +256,7 @@ static int decode_slice(H263DecContext *const h)
get_bits_count(&h->c.gb), show_bits(&h->c.gb, 24));
ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y);
- ret = h->decode_mb(h, h->c.block);
+ ret = h->decode_mb(h);
if (h->c.h263_pred || h->c.h263_aic) {
int mb_xy = h->c.mb_y * h->c.mb_stride + h->c.mb_x;
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index 0600e0bcb0..f414da16b1 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -46,7 +46,7 @@ extern VLCElem ff_h263_mv_vlc[];
typedef struct H263DecContext {
MPVContext c;
- int (*decode_mb)(struct H263DecContext *h, int16_t block[6][64]);
+ int (*decode_mb)(struct H263DecContext *h);
} H263DecContext;
int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code);
@@ -64,8 +64,7 @@ int ff_h263_decode_mba(H263DecContext *const h);
void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus);
int ff_intel_h263_decode_picture_header(H263DecContext *const h);
-int ff_h263_decode_mb(H263DecContext *const h,
- int16_t block[6][64]);
+int ff_h263_decode_mb(H263DecContext *const h);
int ff_h263_resync(H263DecContext *const h);
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index d37ebaeb0b..25a0781024 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -776,7 +776,7 @@ static int set_direct_mv(MpegEncContext *s)
}
}
-int ff_h263_decode_mb(H263DecContext *const h, int16_t block[6][64])
+int ff_h263_decode_mb(H263DecContext *const h)
{
int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
int16_t *mot_val;
@@ -947,7 +947,7 @@ int ff_h263_decode_mb(H263DecContext *const h, int16_t block[6][64])
//FIXME UMV
if (HAS_FORWARD_MV(mb_type)) {
- int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
+ int16_t *mot_val = ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
h->c.mv_dir = MV_DIR_FORWARD;
if (h->c.umvplus)
@@ -974,7 +974,7 @@ int ff_h263_decode_mb(H263DecContext *const h, int16_t block[6][64])
}
if (HAS_BACKWARD_MV(mb_type)) {
- int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 1, &pred_x, &pred_y);
+ int16_t *mot_val = ff_h263_pred_motion(&h->c, 0, 1, &pred_x, &pred_y);
h->c.mv_dir |= MV_DIR_BACKWARD;
if (h->c.umvplus)
@@ -1051,7 +1051,7 @@ intra:
/* decode each block */
for (i = 0; i < 6; i++) {
- if (h263_decode_block(h, block[i], i, cbp&32) < 0)
+ if (h263_decode_block(h, h->c.block[i], i, cbp&32) < 0)
return -1;
cbp+=cbp;
}
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index e3503b1aca..b2f675b9bc 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1651,7 +1651,7 @@ not_coded:
* decode partition C of one MB.
* @return <0 if an error occurred
*/
-static int mpeg4_decode_partitioned_mb(H263DecContext *const h, int16_t block[6][64])
+static int mpeg4_decode_partitioned_mb(H263DecContext *const h)
{
Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
@@ -1711,7 +1711,7 @@ static int mpeg4_decode_partitioned_mb(H263DecContext *const h, int16_t block[6]
h->c.bdsp.clear_blocks(h->c.block[0]);
/* decode each block */
for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, h->c.mb_intra,
+ if (mpeg4_decode_block(ctx, h->c.block[i], i, cbp & 32, h->c.mb_intra,
use_intra_dc_vlc, ctx->rvlc) < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"texture corrupted at %d %d %d\n",
@@ -1738,7 +1738,7 @@ static int mpeg4_decode_partitioned_mb(H263DecContext *const h, int16_t block[6]
}
}
-static int mpeg4_decode_mb(H263DecContext *const h, int16_t block[6][64])
+static int mpeg4_decode_mb(H263DecContext *const h)
{
Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
@@ -2076,7 +2076,7 @@ intra:
h->c.bdsp.clear_blocks(h->c.block[0]);
/* decode each block */
for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(ctx, block[i], i, cbp & 32,
+ if (mpeg4_decode_block(ctx, h->c.block[i], i, cbp & 32,
1, use_intra_dc_vlc, 0) < 0)
return AVERROR_INVALIDDATA;
cbp += cbp;
@@ -2086,7 +2086,7 @@ intra:
/* decode each block */
for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, 0, 0, 0) < 0)
+ if (mpeg4_decode_block(ctx, h->c.block[i], i, cbp & 32, 0, 0, 0) < 0)
return AVERROR_INVALIDDATA;
cbp += cbp;
}
@@ -2353,7 +2353,7 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
return 0;
}
-static int mpeg4_decode_studio_mb(H263DecContext *const h, int16_t block_[12][64])
+static int mpeg4_decode_studio_mb(H263DecContext *const h)
{
Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
int i;
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 0cb14d5762..9d6fddf89a 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -106,7 +106,7 @@ static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code
return val;
}
-static int msmpeg4v12_decode_mb(H263DecContext *const h, int16_t block[6][64])
+static int msmpeg4v12_decode_mb(H263DecContext *const h)
{
MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
int cbp, code, i;
@@ -203,7 +203,7 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h, int16_t block[6][64])
h->c.bdsp.clear_blocks(h->c.block[0]);
for (i = 0; i < 6; i++) {
- if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
+ if (ff_msmpeg4_decode_block(ms, h->c.block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
{
av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
h->c.mb_x, h->c.mb_y, i);
@@ -213,7 +213,7 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h, int16_t block[6][64])
return 0;
}
-static int msmpeg4v34_decode_mb(H263DecContext *const h, int16_t block[6][64])
+static int msmpeg4v34_decode_mb(H263DecContext *const h)
{
MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
int cbp, code, i;
@@ -294,7 +294,7 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h, int16_t block[6][64])
h->c.bdsp.clear_blocks(h->c.block[0]);
for (i = 0; i < 6; i++) {
- if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
+ if (ff_msmpeg4_decode_block(ms, h->c.block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
{
av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
h->c.mb_x, h->c.mb_y, i);
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 0a245e90a3..e6e3c4adc0 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -488,7 +488,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
h->c.mv_dir = MV_DIR_FORWARD;
h->c.mv_type = MV_TYPE_16X16;
- ret = ff_h263_decode_mb(h, h->c.block);
+ ret = ff_h263_decode_mb(h);
// Repeat the slice end check from ff_h263_decode_mb with our active
// bitstream size
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index c7b000ec7a..e0f0826159 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -442,7 +442,7 @@ static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block,
}
}
-static int wmv2_decode_mb(H263DecContext *const h, int16_t block[6][64])
+static int wmv2_decode_mb(H263DecContext *const h)
{
/* The following is only allowed because this decoder
* does not use slice threading. */
@@ -522,7 +522,7 @@ static int wmv2_decode_mb(H263DecContext *const h, int16_t block[6][64])
h->c.mv[0][0][1] = my;
for (i = 0; i < 6; i++) {
- if ((ret = wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1)) < 0) {
+ if ((ret = wmv2_decode_inter_block(w, h->c.block[i], i, (cbp >> (5 - i)) & 1)) < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"\nerror while decoding inter block: %d x %d (%d)\n",
h->c.mb_x, h->c.mb_y, i);
@@ -549,7 +549,7 @@ static int wmv2_decode_mb(H263DecContext *const h, int16_t block[6][64])
h->c.bdsp.clear_blocks(h->c.block[0]);
for (i = 0; i < 6; i++) {
- ret = ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL);
+ ret = ff_msmpeg4_decode_block(ms, h->c.block[i], i, (cbp >> (5 - i)) & 1, NULL);
if (ret < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"\nerror while decoding intra block: %d x %d (%d)\n",
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 28/48] avcodec/h263dec: Don't use MpegEncContext.block
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (26 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 27/48] avcodec/h263dec: Remove redundant block parameter from decode_mb Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 29/48] avcodec/h263dec: Stop using MpegEncContext.gb Andreas Rheinhardt
` (19 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Instead add the necessary blocks directly to H263DecContext
(only six are needed, not 12 as ff_mpv_common_init()
currently allocates).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 4 ++--
libavcodec/h263dec.h | 3 +++
libavcodec/ituh263dec.c | 8 ++++----
libavcodec/mpeg4videodec.c | 14 +++++++-------
libavcodec/msmpeg4dec.c | 8 ++++----
libavcodec/rv10.c | 2 +-
libavcodec/wmv2dec.c | 10 +++++-----
7 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 5a5a91e675..161f13b1e1 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -272,7 +272,7 @@ static int decode_slice(H263DecContext *const h)
if (ret < 0) {
const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
if (ret == SLICE_END) {
- ff_mpv_reconstruct_mb(&h->c, h->c.block);
+ ff_mpv_reconstruct_mb(&h->c, h->block);
if (h->c.loop_filter)
ff_h263_loop_filter(&h->c);
@@ -305,7 +305,7 @@ static int decode_slice(H263DecContext *const h)
return AVERROR_INVALIDDATA;
}
- ff_mpv_reconstruct_mb(&h->c, h->c.block);
+ ff_mpv_reconstruct_mb(&h->c, h->block);
if (h->c.loop_filter)
ff_h263_loop_filter(&h->c);
}
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index f414da16b1..dd5e37a719 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -22,6 +22,7 @@
#include "mpegvideo.h"
#include "vlc.h"
+#include "libavutil/mem_internal.h"
/**
* Return value for header parsers if frame is not coded.
@@ -47,6 +48,8 @@ typedef struct H263DecContext {
MPVContext c;
int (*decode_mb)(struct H263DecContext *h);
+
+ DECLARE_ALIGNED_32(int16_t, block)[6][64];
} H263DecContext;
int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code);
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 25a0781024..0c8531dea9 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -808,7 +808,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
}
}while(cbpc == 20);
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
dquant = cbpc & 8;
h->c.mb_intra = ((cbpc & 4) != 0);
@@ -910,7 +910,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
h->c.mb_intra = IS_INTRA(mb_type);
if(HAS_CBP(mb_type)){
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
cbpc = get_vlc2(&h->c.gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
if (h->c.mb_intra) {
dquant = IS_QUANT(mb_type);
@@ -1012,7 +1012,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
}
}while(cbpc == 8);
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
dquant = cbpc & 4;
h->c.mb_intra = 1;
@@ -1051,7 +1051,7 @@ intra:
/* decode each block */
for (i = 0; i < 6; i++) {
- if (h263_decode_block(h, h->c.block[i], i, cbp&32) < 0)
+ if (h263_decode_block(h, h->block[i], i, cbp&32) < 0)
return -1;
cbp+=cbp;
}
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index b2f675b9bc..88ddacc87f 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1708,10 +1708,10 @@ static int mpeg4_decode_partitioned_mb(H263DecContext *const h)
if (!IS_SKIP(mb_type)) {
int i;
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
/* decode each block */
for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(ctx, h->c.block[i], i, cbp & 32, h->c.mb_intra,
+ if (mpeg4_decode_block(ctx, h->block[i], i, cbp & 32, h->c.mb_intra,
use_intra_dc_vlc, ctx->rvlc) < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"texture corrupted at %d %d %d\n",
@@ -1792,7 +1792,7 @@ static int mpeg4_decode_mb(H263DecContext *const h)
h->c.mb_intra = ((cbpc & 4) != 0);
if (h->c.mb_intra)
goto intra;
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)
@@ -1936,7 +1936,7 @@ static int mpeg4_decode_mb(H263DecContext *const h)
if (modb2) {
cbp = 0;
} else {
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
cbp = get_bits(&h->c.gb, 6);
}
@@ -2073,10 +2073,10 @@ intra:
if (!h->c.progressive_sequence)
h->c.interlaced_dct = get_bits1(&h->c.gb);
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
/* decode each block */
for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(ctx, h->c.block[i], i, cbp & 32,
+ if (mpeg4_decode_block(ctx, h->block[i], i, cbp & 32,
1, use_intra_dc_vlc, 0) < 0)
return AVERROR_INVALIDDATA;
cbp += cbp;
@@ -2086,7 +2086,7 @@ intra:
/* decode each block */
for (i = 0; i < 6; i++) {
- if (mpeg4_decode_block(ctx, h->c.block[i], i, cbp & 32, 0, 0, 0) < 0)
+ if (mpeg4_decode_block(ctx, h->block[i], i, cbp & 32, 0, 0, 0) < 0)
return AVERROR_INVALIDDATA;
cbp += cbp;
}
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 9d6fddf89a..06f6367a38 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -201,9 +201,9 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h)
*mb_type_ptr = MB_TYPE_INTRA;
}
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
for (i = 0; i < 6; i++) {
- if (ff_msmpeg4_decode_block(ms, h->c.block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
+ if (ff_msmpeg4_decode_block(ms, h->block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
{
av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
h->c.mb_x, h->c.mb_y, i);
@@ -292,9 +292,9 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h)
}
}
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
for (i = 0; i < 6; i++) {
- if (ff_msmpeg4_decode_block(ms, h->c.block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
+ if (ff_msmpeg4_decode_block(ms, h->block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
{
av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
h->c.mb_x, h->c.mb_y, i);
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index e6e3c4adc0..c678851ded 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -516,7 +516,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
}
if (h->c.pict_type != AV_PICTURE_TYPE_B)
ff_h263_update_motion_val(&h->c);
- ff_mpv_reconstruct_mb(&h->c, h->c.block);
+ ff_mpv_reconstruct_mb(&h->c, h->block);
if (h->c.loop_filter)
ff_h263_loop_filter(&h->c);
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index e0f0826159..4eb4d00383 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -500,7 +500,7 @@ static int wmv2_decode_mb(H263DecContext *const h)
wmv2_pred_motion(w, &mx, &my);
if (cbp) {
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
if (ms->per_mb_rl_table) {
ms->rl_table_index = decode012(&h->c.gb);
ms->rl_chroma_table_index = ms->rl_table_index;
@@ -522,7 +522,7 @@ static int wmv2_decode_mb(H263DecContext *const h)
h->c.mv[0][0][1] = my;
for (i = 0; i < 6; i++) {
- if ((ret = wmv2_decode_inter_block(w, h->c.block[i], i, (cbp >> (5 - i)) & 1)) < 0) {
+ if ((ret = wmv2_decode_inter_block(w, h->block[i], i, (cbp >> (5 - i)) & 1)) < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"\nerror while decoding inter block: %d x %d (%d)\n",
h->c.mb_x, h->c.mb_y, i);
@@ -547,9 +547,9 @@ static int wmv2_decode_mb(H263DecContext *const h)
ms->rl_chroma_table_index = ms->rl_table_index;
}
- h->c.bdsp.clear_blocks(h->c.block[0]);
+ h->c.bdsp.clear_blocks(h->block[0]);
for (i = 0; i < 6; i++) {
- ret = ff_msmpeg4_decode_block(ms, h->c.block[i], i, (cbp >> (5 - i)) & 1, NULL);
+ ret = ff_msmpeg4_decode_block(ms, h->block[i], i, (cbp >> (5 - i)) & 1, NULL);
if (ret < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"\nerror while decoding intra block: %d x %d (%d)\n",
@@ -580,7 +580,7 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx)
decode_ext_header(w);
- return ff_intrax8_common_init(avctx, &w->x8, h->c.block[0],
+ return ff_intrax8_common_init(avctx, &w->x8, h->block[0],
s->mb_width, s->mb_height);
}
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 29/48] avcodec/h263dec: Stop using MpegEncContext.gb
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (27 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 28/48] avcodec/h263dec: Don't use MpegEncContext.block Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 30/48] avcodec/mpeg12dec: Add Mpeg12SliceContext Andreas Rheinhardt
` (18 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Add a GetBitContext to H263DecContext instead. This is in preparation
for removing MpegEncContext.gb.
Also move last_resync_gb to H263DecContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/flvdec.c | 24 +--
libavcodec/h263dec.c | 52 +++---
libavcodec/h263dec.h | 5 +
libavcodec/intelh263dec.c | 64 +++----
libavcodec/ituh263dec.c | 339 +++++++++++++++++++------------------
libavcodec/mpeg12dec.c | 10 +-
libavcodec/mpeg4videodec.c | 320 +++++++++++++++++-----------------
libavcodec/mpegvideo.h | 1 -
libavcodec/mpegvideodec.h | 6 +-
libavcodec/msmpeg4dec.c | 188 ++++++++++----------
libavcodec/rv10.c | 62 +++----
libavcodec/vaapi_mpeg4.c | 8 +-
libavcodec/wmv2dec.c | 92 +++++-----
13 files changed, 588 insertions(+), 583 deletions(-)
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index a5d96584f1..f2d0b642b7 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -31,26 +31,26 @@ int ff_flv_decode_picture_header(H263DecContext *const h)
int format, width, height;
/* picture header */
- if (get_bits(&h->c.gb, 17) != 1) {
+ if (get_bits(&h->gb, 17) != 1) {
av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
return AVERROR_INVALIDDATA;
}
- format = get_bits(&h->c.gb, 5);
+ format = get_bits(&h->gb, 5);
if (format != 0 && format != 1) {
av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");
return AVERROR_INVALIDDATA;
}
h->c.h263_flv = format + 1;
- h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */
- format = get_bits(&h->c.gb, 3);
+ h->c.picture_number = get_bits(&h->gb, 8); /* picture timestamp */
+ format = get_bits(&h->gb, 3);
switch (format) {
case 0:
- width = get_bits(&h->c.gb, 8);
- height = get_bits(&h->c.gb, 8);
+ width = get_bits(&h->gb, 8);
+ height = get_bits(&h->gb, 8);
break;
case 1:
- width = get_bits(&h->c.gb, 16);
- height = get_bits(&h->c.gb, 16);
+ width = get_bits(&h->gb, 16);
+ height = get_bits(&h->gb, 16);
break;
case 2:
width = 352;
@@ -81,18 +81,18 @@ int ff_flv_decode_picture_header(H263DecContext *const h)
h->c.width = width;
h->c.height = height;
- h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->c.gb, 2);
+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->gb, 2);
h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P;
if (h->c.droppable)
h->c.pict_type = AV_PICTURE_TYPE_P;
- skip_bits1(&h->c.gb); /* deblocking flag */
- h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
+ skip_bits1(&h->gb); /* deblocking flag */
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
h->c.h263_long_vectors = 0;
/* PEI */
- if (skip_1stop_8data_bits(&h->c.gb) < 0)
+ if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA;
if (h->c.ehc_mode)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 161f13b1e1..fc63e8a5d8 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -187,7 +187,7 @@ static int decode_slice(H263DecContext *const h)
const int mb_size = 16 >> h->c.avctx->lowres;
int ret;
- h->c.last_resync_gb = h->c.gb;
+ h->last_resync_gb = h->gb;
h->c.first_slice_line = 1;
h->c.resync_mb_x = h->c.mb_x;
h->c.resync_mb_y = h->c.mb_y;
@@ -200,8 +200,8 @@ static int decode_slice(H263DecContext *const h)
}
if (h->c.avctx->hwaccel) {
- const uint8_t *start = h->c.gb.buffer + get_bits_count(&h->c.gb) / 8;
- ret = FF_HW_CALL(h->c.avctx, decode_slice, start, h->c.gb.buffer_end - start);
+ const uint8_t *start = h->gb.buffer + get_bits_count(&h->gb) / 8;
+ ret = FF_HW_CALL(h->c.avctx, decode_slice, start, h->gb.buffer_end - start);
// ensure we exit decode loop
h->c.mb_y = h->c.mb_height;
return ret;
@@ -253,7 +253,7 @@ static int decode_slice(H263DecContext *const h)
h->c.mv_dir = MV_DIR_FORWARD;
h->c.mv_type = MV_TYPE_16X16;
ff_dlog(h->c.avctx, "%d %06X\n",
- get_bits_count(&h->c.gb), show_bits(&h->c.gb, 24));
+ get_bits_count(&h->gb), show_bits(&h->gb, 24));
ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y);
ret = h->decode_mb(h);
@@ -300,7 +300,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,
h->c.mb_x, h->c.mb_y, ER_MB_ERROR & part_mask);
- if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->c.gb) > 0)
+ if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->gb) > 0)
continue;
return AVERROR_INVALIDDATA;
}
@@ -321,29 +321,29 @@ static int decode_slice(H263DecContext *const h)
// Detect incorrect padding with wrong stuffing codes used by NEC N-02B
if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
(h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
- get_bits_left(&h->c.gb) >= 48 &&
- show_bits(&h->c.gb, 24) == 0x4010 &&
+ get_bits_left(&h->gb) >= 48 &&
+ show_bits(&h->gb, 24) == 0x4010 &&
!h->c.data_partitioning)
h->c.padding_bug_score += 32;
/* try to detect the padding bug */
if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
(h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
- get_bits_left(&h->c.gb) >= 0 &&
- get_bits_left(&h->c.gb) < 137 &&
+ get_bits_left(&h->gb) >= 0 &&
+ get_bits_left(&h->gb) < 137 &&
!h->c.data_partitioning) {
- const int bits_count = get_bits_count(&h->c.gb);
- const int bits_left = h->c.gb.size_in_bits - bits_count;
+ const int bits_count = get_bits_count(&h->gb);
+ const int bits_left = h->gb.size_in_bits - bits_count;
if (bits_left == 0) {
h->c.padding_bug_score += 16;
} else if (bits_left != 1) {
- int v = show_bits(&h->c.gb, 8);
+ int v = show_bits(&h->gb, 8);
v |= 0x7F >> (7 - (bits_count & 7));
if (v == 0x7F && bits_left <= 8)
h->c.padding_bug_score--;
- else if (v == 0x7F && ((get_bits_count(&h->c.gb) + 8) & 8) &&
+ else if (v == 0x7F && ((get_bits_count(&h->gb) + 8) & 8) &&
bits_left <= 16)
h->c.padding_bug_score += 4;
else
@@ -353,10 +353,10 @@ static int decode_slice(H263DecContext *const h)
if (h->c.codec_id == AV_CODEC_ID_H263 &&
(h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
- get_bits_left(&h->c.gb) >= 8 &&
- get_bits_left(&h->c.gb) < 300 &&
+ get_bits_left(&h->gb) >= 8 &&
+ get_bits_left(&h->gb) < 300 &&
h->c.pict_type == AV_PICTURE_TYPE_I &&
- show_bits(&h->c.gb, 8) == 0 &&
+ show_bits(&h->gb, 8) == 0 &&
!h->c.data_partitioning) {
h->c.padding_bug_score += 32;
@@ -364,8 +364,8 @@ static int decode_slice(H263DecContext *const h)
if (h->c.codec_id == AV_CODEC_ID_H263 &&
(h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
- get_bits_left(&h->c.gb) >= 64 &&
- AV_RB64(h->c.gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
+ get_bits_left(&h->gb) >= 64 &&
+ AV_RB64(h->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
h->c.padding_bug_score += 32;
}
@@ -380,7 +380,7 @@ static int decode_slice(H263DecContext *const h)
// handle formats which don't have unique end markers
if (h->c.msmpeg4_version != MSMP4_UNUSED || (h->c.workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
- int left = get_bits_left(&h->c.gb);
+ int left = get_bits_left(&h->gb);
int max_extra = 7;
/* no markers in M$ crap */
@@ -398,7 +398,7 @@ static int decode_slice(H263DecContext *const h)
if (left > max_extra)
av_log(h->c.avctx, AV_LOG_ERROR,
"discarding %d junk bits at end, next would be %X\n",
- left, show_bits(&h->c.gb, 24));
+ left, show_bits(&h->gb, 24));
else if (left < 0)
av_log(h->c.avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
else
@@ -410,7 +410,7 @@ static int decode_slice(H263DecContext *const h)
av_log(h->c.avctx, AV_LOG_ERROR,
"slice end not reached but screenspace end (%d left %06X, score= %d)\n",
- get_bits_left(&h->c.gb), show_bits(&h->c.gb, 24), h->c.padding_bug_score);
+ get_bits_left(&h->gb), show_bits(&h->gb, 24), h->c.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,
ER_MB_END & part_mask);
@@ -452,8 +452,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
return 0;
}
- // h->c.gb might be overridden in ff_mpeg4_decode_picture_header() below.
- ret = init_get_bits8(&h->c.gb, buf, buf_size);
+ // h->gb might be overridden in ff_mpeg4_decode_picture_header() below.
+ ret = init_get_bits8(&h->gb, buf, buf_size);
if (ret < 0)
return ret;
@@ -504,7 +504,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
avctx->has_b_frames = !h->c.low_delay;
if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
- if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->c.gb))
+ if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->gb))
return AVERROR_INVALIDDATA;
ff_mpeg4_workaround_bugs(avctx);
if (h->c.studio_profile != (h->c.idsp.idct == NULL))
@@ -556,7 +556,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
if (avctx->hwaccel) {
ret = FF_HW_CALL(avctx, start_frame, NULL,
- h->c.gb.buffer, h->c.gb.buffer_end - h->c.gb.buffer);
+ h->gb.buffer, h->gb.buffer_end - h->gb.buffer);
if (ret < 0 )
return ret;
}
@@ -584,7 +584,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
while (h->c.mb_y < h->c.mb_height) {
if (h->c.msmpeg4_version != MSMP4_UNUSED) {
if (h->c.slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 ||
- (h->c.mb_y % h->c.slice_height) != 0 || get_bits_left(&h->c.gb) < 0)
+ (h->c.mb_y % h->c.slice_height) != 0 || get_bits_left(&h->gb) < 0)
break;
} else {
int prev_x = h->c.mb_x, prev_y = h->c.mb_y;
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index dd5e37a719..dfa056f08e 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -20,6 +20,7 @@
#ifndef AVCODEC_H263DEC_H
#define AVCODEC_H263DEC_H
+#include "get_bits.h"
#include "mpegvideo.h"
#include "vlc.h"
#include "libavutil/mem_internal.h"
@@ -47,8 +48,12 @@ extern VLCElem ff_h263_mv_vlc[];
typedef struct H263DecContext {
MPVContext c;
+ GetBitContext gb;
+
int (*decode_mb)(struct H263DecContext *h);
+ GetBitContext last_resync_gb; ///< used to search for the next resync marker
+
DECLARE_ALIGNED_32(int16_t, block)[6][64];
} H263DecContext;
diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c
index d7242f4922..3800e6f1cc 100644
--- a/libavcodec/intelh263dec.c
+++ b/libavcodec/intelh263dec.c
@@ -30,44 +30,44 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
{
int format;
- if (get_bits_left(&h->c.gb) == 64) { /* special dummy frames */
+ if (get_bits_left(&h->gb) == 64) { /* special dummy frames */
return FRAME_SKIPPED;
}
/* picture header */
- if (get_bits(&h->c.gb, 22) != 0x20) {
+ if (get_bits(&h->gb, 22) != 0x20) {
av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
return -1;
}
- h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */
+ h->c.picture_number = get_bits(&h->gb, 8); /* picture timestamp */
- if (check_marker(h->c.avctx, &h->c.gb, "after picture_number") != 1) {
+ if (check_marker(h->c.avctx, &h->gb, "after picture_number") != 1) {
return -1; /* marker */
}
- if (get_bits1(&h->c.gb) != 0) {
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
return -1; /* H.263 id */
}
- skip_bits1(&h->c.gb); /* split screen off */
- skip_bits1(&h->c.gb); /* camera off */
- skip_bits1(&h->c.gb); /* freeze picture release off */
+ skip_bits1(&h->gb); /* split screen off */
+ skip_bits1(&h->gb); /* camera off */
+ skip_bits1(&h->gb); /* freeze picture release off */
- format = get_bits(&h->c.gb, 3);
+ format = get_bits(&h->gb, 3);
if (format == 0 || format == 6) {
av_log(h->c.avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
return -1;
}
- h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb);
+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
- h->c.h263_long_vectors = get_bits1(&h->c.gb);
+ h->c.h263_long_vectors = get_bits1(&h->gb);
- if (get_bits1(&h->c.gb) != 0) {
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n");
return -1; /* SAC: off */
}
- h->c.obmc = get_bits1(&h->c.gb);
- h->c.pb_frame = get_bits1(&h->c.gb);
+ h->c.obmc = get_bits1(&h->gb);
+ h->c.pb_frame = get_bits1(&h->gb);
if (format < 6) {
h->c.width = ff_h263_format[format][0];
@@ -75,31 +75,31 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
h->c.avctx->sample_aspect_ratio.num = 12;
h->c.avctx->sample_aspect_ratio.den = 11;
} else {
- format = get_bits(&h->c.gb, 3);
+ format = get_bits(&h->gb, 3);
if(format == 0 || format == 7){
av_log(h->c.avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
return -1;
}
- if (get_bits(&h->c.gb, 2))
+ if (get_bits(&h->gb, 2))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
- h->c.loop_filter = get_bits1(&h->c.gb) * !h->c.avctx->lowres;
- if (get_bits1(&h->c.gb))
+ h->c.loop_filter = get_bits1(&h->gb) * !h->c.avctx->lowres;
+ if (get_bits1(&h->gb))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
- if (get_bits1(&h->c.gb))
+ if (get_bits1(&h->gb))
h->c.pb_frame = 2;
- if (get_bits(&h->c.gb, 5))
+ if (get_bits(&h->gb, 5))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
- if (get_bits(&h->c.gb, 5) != 1)
+ if (get_bits(&h->gb, 5) != 1)
av_log(h->c.avctx, AV_LOG_ERROR, "Invalid marker\n");
}
if(format == 6){
- int ar = get_bits(&h->c.gb, 4);
- skip_bits(&h->c.gb, 9); // display width
- check_marker(h->c.avctx, &h->c.gb, "in dimensions");
- skip_bits(&h->c.gb, 9); // display height
+ int ar = get_bits(&h->gb, 4);
+ skip_bits(&h->gb, 9); // display width
+ check_marker(h->c.avctx, &h->gb, "in dimensions");
+ skip_bits(&h->gb, 9); // display height
if (ar == 15) {
- h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8); // aspect ratio - width
- h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8); // aspect ratio - height
+ h->c.avctx->sample_aspect_ratio.num = get_bits(&h->gb, 8); // aspect ratio - width
+ h->c.avctx->sample_aspect_ratio.den = get_bits(&h->gb, 8); // aspect ratio - height
} else {
h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
}
@@ -107,16 +107,16 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
av_log(h->c.avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
}
- h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
- skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
+ skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
if (h->c.pb_frame) {
- skip_bits(&h->c.gb, 3); //temporal reference for B-frame
- skip_bits(&h->c.gb, 2); //dbquant
+ skip_bits(&h->gb, 3); //temporal reference for B-frame
+ skip_bits(&h->gb, 2); //dbquant
}
/* PEI */
- if (skip_1stop_8data_bits(&h->c.gb) < 0)
+ if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA;
h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 0c8531dea9..c19134b0d4 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -82,7 +82,7 @@ void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {
av_log(h->c.avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
h->c.qscale, av_get_picture_type_char(h->c.pict_type),
- h->c.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.umvplus ? " UMV" : "",
h->c.h263_long_vectors ? " LONG" : "",
@@ -146,7 +146,7 @@ int ff_h263_decode_mba(H263DecContext *const h)
for (i = 0; i < 6; i++)
if (h->c.mb_num - 1 <= ff_mba_max[i])
break;
- mb_pos = get_bits(&h->c.gb, ff_mba_length[i]);
+ mb_pos = get_bits(&h->gb, ff_mba_length[i]);
h->c.mb_x = mb_pos % h->c.mb_width;
h->c.mb_y = mb_pos / h->c.mb_width;
@@ -163,41 +163,42 @@ static int h263_decode_gob_header(H263DecContext *const h)
int left;
/* Check for GOB Start Code */
- val = show_bits(&h->c.gb, 16);
+ val = show_bits(&h->gb, 16);
if(val)
return -1;
/* We have a GBSC probably with GSTUFF */
- skip_bits(&h->c.gb, 16); /* Drop the zeros */
- left = get_bits_left(&h->c.gb);
+ skip_bits(&h->gb, 16); /* Drop the zeros */
+ left = get_bits_left(&h->gb);
left = FFMIN(left, 32);
//MN: we must check the bits left or we might end in an infinite loop (or segfault)
for(;left>13; left--){
- if (get_bits1(&h->c.gb)) break; /* Seek the '1' bit */
+ if (get_bits1(&h->gb))
+ break; /* Seek the '1' bit */
}
if(left<=13)
return -1;
if (h->c.h263_slice_structured) {
- if (check_marker(h->c.avctx, &h->c.gb, "before MBA")==0)
+ if (check_marker(h->c.avctx, &h->gb, "before MBA")==0)
return -1;
ff_h263_decode_mba(h);
if (h->c.mb_num > 1583)
- if (check_marker(h->c.avctx, &h->c.gb, "after MBA")==0)
+ if (check_marker(h->c.avctx, &h->gb, "after MBA")==0)
return -1;
- h->c.qscale = get_bits(&h->c.gb, 5); /* SQUANT */
- if (check_marker(h->c.avctx, &h->c.gb, "after SQUANT")==0)
+ h->c.qscale = get_bits(&h->gb, 5); /* SQUANT */
+ if (check_marker(h->c.avctx, &h->gb, "after SQUANT")==0)
return -1;
- skip_bits(&h->c.gb, 2); /* GFID */
+ skip_bits(&h->gb, 2); /* GFID */
}else{
- gob_number = get_bits(&h->c.gb, 5); /* GN */
+ gob_number = get_bits(&h->gb, 5); /* GN */
h->c.mb_x = 0;
h->c.mb_y = h->c.gob_index* gob_number;
- skip_bits(&h->c.gb, 2); /* GFID */
- h->c.qscale = get_bits(&h->c.gb, 5); /* GQUANT */
+ skip_bits(&h->gb, 2); /* GFID */
+ h->c.qscale = get_bits(&h->gb, 5); /* GQUANT */
}
if (h->c.mb_y >= h->c.mb_height)
@@ -220,25 +221,25 @@ int ff_h263_resync(H263DecContext *const h)
/* In MPEG-4 studio mode look for a new slice startcode
* and decode slice header */
if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) {
- align_get_bits(&h->c.gb);
+ align_get_bits(&h->gb);
- while (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) != SLICE_STARTCODE) {
- get_bits(&h->c.gb, 8);
+ while (get_bits_left(&h->gb) >= 32 && show_bits_long(&h->gb, 32) != SLICE_STARTCODE) {
+ get_bits(&h->gb, 8);
}
- if (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) == SLICE_STARTCODE)
- return get_bits_count(&h->c.gb);
+ if (get_bits_left(&h->gb) >= 32 && show_bits_long(&h->gb, 32) == SLICE_STARTCODE)
+ return get_bits_count(&h->gb);
else
return -1;
}
if (h->c.codec_id==AV_CODEC_ID_MPEG4){
- skip_bits1(&h->c.gb);
- align_get_bits(&h->c.gb);
+ skip_bits1(&h->gb);
+ align_get_bits(&h->gb);
}
- if (show_bits(&h->c.gb, 16) ==0) {
- pos = get_bits_count(&h->c.gb);
+ if (show_bits(&h->gb, 16) ==0) {
+ pos = get_bits_count(&h->gb);
if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)
ret = ff_mpeg4_decode_video_packet_header(h);
else
@@ -247,15 +248,15 @@ int ff_h263_resync(H263DecContext *const h)
return pos;
}
//OK, it's not where it is supposed to be ...
- h->c.gb = h->c.last_resync_gb;
- align_get_bits(&h->c.gb);
- left = get_bits_left(&h->c.gb);
+ h->gb = h->last_resync_gb;
+ align_get_bits(&h->gb);
+ left = get_bits_left(&h->gb);
for(;left>16+1+5+5; left-=8){
- if (show_bits(&h->c.gb, 16) == 0){
- GetBitContext bak = h->c.gb;
+ if (show_bits(&h->gb, 16) == 0){
+ GetBitContext bak = h->gb;
- pos = get_bits_count(&h->c.gb);
+ pos = get_bits_count(&h->gb);
if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)
ret = ff_mpeg4_decode_video_packet_header(h);
else
@@ -263,9 +264,9 @@ int ff_h263_resync(H263DecContext *const h)
if(ret>=0)
return pos;
- h->c.gb = bak;
+ h->gb = bak;
}
- skip_bits(&h->c.gb, 8);
+ skip_bits(&h->gb, 8);
}
return -1;
@@ -274,19 +275,19 @@ int ff_h263_resync(H263DecContext *const h)
int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
{
int code, val, sign, shift;
- code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
+ code = get_vlc2(&h->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
if (code == 0)
return pred;
if (code < 0)
return 0xffff;
- sign = get_bits1(&h->c.gb);
+ sign = get_bits1(&h->gb);
shift = f_code - 1;
val = code;
if (shift) {
val = (val - 1) << shift;
- val |= get_bits(&h->c.gb, shift);
+ val |= get_bits(&h->gb, shift);
val++;
}
if (sign)
@@ -313,15 +314,15 @@ static int h263p_decode_umotion(H263DecContext *const h, int pred)
{
int code = 0, sign;
- if (get_bits1(&h->c.gb)) /* Motion difference = 0 */
+ if (get_bits1(&h->gb)) /* Motion difference = 0 */
return pred;
- code = 2 + get_bits1(&h->c.gb);
+ code = 2 + get_bits1(&h->gb);
- while (get_bits1(&h->c.gb))
+ while (get_bits1(&h->gb))
{
code <<= 1;
- code += get_bits1(&h->c.gb);
+ code += get_bits1(&h->gb);
if (code >= 32768) {
avpriv_request_sample(h->c.avctx, "Huge DMV");
return 0xffff;
@@ -341,7 +342,7 @@ static int h263p_decode_umotion(H263DecContext *const h, int pred)
*/
static void preview_obmc(H263DecContext *const h)
{
- GetBitContext gb = h->c.gb;
+ GetBitContext gb = h->gb;
int cbpc, i, pred_x, pred_y, mx, my;
int16_t *mot_val;
@@ -357,7 +358,7 @@ static void preview_obmc(H263DecContext *const h)
av_assert2(h->c.pict_type == AV_PICTURE_TYPE_P);
do{
- if (get_bits1(&h->c.gb)) {
+ if (get_bits1(&h->gb)) {
/* skip mb */
mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
mot_val[0 ]= mot_val[2 ]=
@@ -368,15 +369,15 @@ static void preview_obmc(H263DecContext *const h)
h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
goto end;
}
- cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
}while(cbpc == 20);
if(cbpc & 4){
h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
}else{
- get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpc & 8) {
- skip_bits(&h->c.gb, h->c.modified_quant ? (get_bits1(&h->c.gb) ? 1 : 5) : 2);
+ skip_bits(&h->gb, h->c.modified_quant ? (get_bits1(&h->gb) ? 1 : 5) : 2);
}
if ((cbpc & 16) == 0) {
@@ -411,7 +412,7 @@ static void preview_obmc(H263DecContext *const h)
else
my = ff_h263_decode_motion(h, pred_y, 1);
if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
+ skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
mot_val[0] = mx;
mot_val[1] = my;
}
@@ -425,7 +426,7 @@ end:
h->c.block_index[i] -= 1;
h->c.mb_x--;
- h->c.gb = gb;
+ h->gb = gb;
}
static void h263_decode_dquant(H263DecContext *const h)
@@ -434,12 +435,12 @@ static void h263_decode_dquant(H263DecContext *const h)
int qscale;
if (h->c.modified_quant) {
- if (get_bits1(&h->c.gb))
- qscale = ff_modified_quant_tab[get_bits1(&h->c.gb)][h->c.qscale];
+ if (get_bits1(&h->gb))
+ qscale = ff_modified_quant_tab[get_bits1(&h->gb)][h->c.qscale];
else
- qscale = get_bits(&h->c.gb, 5);
+ qscale = get_bits(&h->gb, 5);
}else
- qscale = h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)];
+ qscale = h->c.qscale + quant_tab[get_bits(&h->gb, 2)];
ff_set_qscale(&h->c, qscale);
}
@@ -527,7 +528,7 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64],
int level, i, j, run;
const RLTable *rl = &ff_h263_rl_inter;
const uint8_t *scan_table;
- GetBitContext gb = h->c.gb;
+ GetBitContext gb = h->gb;
scan_table = h->c.intra_scantable.permutated;
if (h->c.h263_aic && h->c.mb_intra) {
@@ -558,12 +559,12 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64],
h->c.rv10_first_dc_coded[component] = 1;
}
} else {
- level = get_bits(&h->c.gb, 8);
+ level = get_bits(&h->gb, 8);
if (level == 255)
level = 128;
}
}else{
- level = get_bits(&h->c.gb, 8);
+ level = get_bits(&h->gb, 8);
if((level&0x7F) == 0){
av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
level, h->c.mb_x, h->c.mb_y);
@@ -584,60 +585,60 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64],
}
retry:
{
- OPEN_READER(re, &h->c.gb);
+ OPEN_READER(re, &h->gb);
i--; // offset by -1 to allow direct indexing of scan_table
for(;;) {
- UPDATE_CACHE(re, &h->c.gb);
- GET_RL_VLC(level, run, re, &h->c.gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
+ UPDATE_CACHE(re, &h->gb);
+ GET_RL_VLC(level, run, re, &h->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
if (run == 66) {
if (level){
- CLOSE_READER(re, &h->c.gb);
+ CLOSE_READER(re, &h->gb);
av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
h->c.mb_x, h->c.mb_y);
return -1;
}
/* escape */
if (CONFIG_FLV_DECODER && h->c.h263_flv > 1) {
- int is11 = SHOW_UBITS(re, &h->c.gb, 1);
- SKIP_CACHE(re, &h->c.gb, 1);
- run = SHOW_UBITS(re, &h->c.gb, 7) + 1;
+ int is11 = SHOW_UBITS(re, &h->gb, 1);
+ SKIP_CACHE(re, &h->gb, 1);
+ run = SHOW_UBITS(re, &h->gb, 7) + 1;
if (is11) {
- SKIP_COUNTER(re, &h->c.gb, 1 + 7);
- UPDATE_CACHE(re, &h->c.gb);
- level = SHOW_SBITS(re, &h->c.gb, 11);
- SKIP_COUNTER(re, &h->c.gb, 11);
+ SKIP_COUNTER(re, &h->gb, 1 + 7);
+ UPDATE_CACHE(re, &h->gb);
+ level = SHOW_SBITS(re, &h->gb, 11);
+ SKIP_COUNTER(re, &h->gb, 11);
} else {
- SKIP_CACHE(re, &h->c.gb, 7);
- level = SHOW_SBITS(re, &h->c.gb, 7);
- SKIP_COUNTER(re, &h->c.gb, 1 + 7 + 7);
+ SKIP_CACHE(re, &h->gb, 7);
+ level = SHOW_SBITS(re, &h->gb, 7);
+ SKIP_COUNTER(re, &h->gb, 1 + 7 + 7);
}
} else {
- run = SHOW_UBITS(re, &h->c.gb, 7) + 1;
- SKIP_CACHE(re, &h->c.gb, 7);
- level = (int8_t)SHOW_UBITS(re, &h->c.gb, 8);
- SKIP_COUNTER(re, &h->c.gb, 7 + 8);
+ run = SHOW_UBITS(re, &h->gb, 7) + 1;
+ SKIP_CACHE(re, &h->gb, 7);
+ level = (int8_t)SHOW_UBITS(re, &h->gb, 8);
+ SKIP_COUNTER(re, &h->gb, 7 + 8);
if(level == -128){
- UPDATE_CACHE(re, &h->c.gb);
+ UPDATE_CACHE(re, &h->gb);
if (h->c.codec_id == AV_CODEC_ID_RV10) {
/* XXX: should patch encoder too */
- level = SHOW_SBITS(re, &h->c.gb, 12);
- SKIP_COUNTER(re, &h->c.gb, 12);
+ level = SHOW_SBITS(re, &h->gb, 12);
+ SKIP_COUNTER(re, &h->gb, 12);
}else{
- level = SHOW_UBITS(re, &h->c.gb, 5);
- SKIP_CACHE(re, &h->c.gb, 5);
- level |= SHOW_SBITS(re, &h->c.gb, 6) * (1<<5);
- SKIP_COUNTER(re, &h->c.gb, 5 + 6);
+ level = SHOW_UBITS(re, &h->gb, 5);
+ SKIP_CACHE(re, &h->gb, 5);
+ level |= SHOW_SBITS(re, &h->gb, 6) * (1<<5);
+ SKIP_COUNTER(re, &h->gb, 5 + 6);
}
}
}
} else {
- if (SHOW_UBITS(re, &h->c.gb, 1))
+ if (SHOW_UBITS(re, &h->gb, 1))
level = -level;
- SKIP_COUNTER(re, &h->c.gb, 1);
+ SKIP_COUNTER(re, &h->gb, 1);
}
i += run;
if (i >= 64){
- CLOSE_READER(re, &h->c.gb);
+ CLOSE_READER(re, &h->gb);
// redo update without last flag, revert -1 offset
i = i - run + ((run-1)&63) + 1;
if (i < 64) {
@@ -649,7 +650,7 @@ retry:
//Looks like a hack but no, it's the way it is supposed to work ...
rl = &ff_rl_intra_aic;
i = 0;
- h->c.gb = gb;
+ h->gb = gb;
h->c.bdsp.clear_block(block);
goto retry;
}
@@ -787,7 +788,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
if (h->c.pict_type == AV_PICTURE_TYPE_P) {
do{
- if (get_bits1(&h->c.gb)) {
+ if (get_bits1(&h->gb)) {
/* skip mb */
h->c.mb_intra = 0;
for(i=0;i<6;i++)
@@ -800,7 +801,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
h->c.mb_skipped = !(h->c.obmc | h->c.loop_filter);
goto end;
}
- cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0){
av_log(h->c.avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n",
h->c.mb_x, h->c.mb_y);
@@ -815,9 +816,9 @@ int ff_h263_decode_mb(H263DecContext *const h)
if (h->c.mb_intra)
goto intra;
- if(h->c.pb_frame && get_bits1(&h->c.gb))
- pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb);
- cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ if (h->c.pb_frame && get_bits1(&h->gb))
+ pb_mv_count = h263_get_modb(&h->gb, h->c.pb_frame, &cbpb);
+ cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n",
@@ -858,7 +859,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
h->c.mv[0][0][1] = my;
if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
+ skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
} else {
h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
h->c.mv_type = MV_TYPE_8X8;
@@ -880,7 +881,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
h->c.mv[0][i][0] = mx;
h->c.mv[0][i][1] = my;
if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
+ skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
mot_val[0] = mx;
mot_val[1] = my;
}
@@ -899,7 +900,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
do{
- mb_type = get_vlc2(&h->c.gb, h263_mbtype_b_vlc,
+ mb_type = get_vlc2(&h->gb, h263_mbtype_b_vlc,
H263_MBTYPE_B_VLC_BITS, 2);
if (mb_type < 0){
av_log(h->c.avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n",
@@ -911,13 +912,13 @@ int ff_h263_decode_mb(H263DecContext *const h)
h->c.mb_intra = IS_INTRA(mb_type);
if(HAS_CBP(mb_type)){
h->c.bdsp.clear_blocks(h->block[0]);
- cbpc = get_vlc2(&h->c.gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
+ cbpc = get_vlc2(&h->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
if (h->c.mb_intra) {
dquant = IS_QUANT(mb_type);
goto intra;
}
- cbpy = get_vlc2(&h->c.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){
av_log(h->c.avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n",
@@ -965,7 +966,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
return SLICE_ERROR;
if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
+ skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
h->c.mv[0][0][0] = mx;
h->c.mv[0][0][1] = my;
@@ -992,7 +993,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
return SLICE_ERROR;
if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
- skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
+ skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
h->c.mv[1][0][0] = mx;
h->c.mv[1][0][1] = my;
@@ -1004,7 +1005,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
h->c.cur_pic.mb_type[xy] = mb_type;
} else { /* I-Frame */
do{
- cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0){
av_log(h->c.avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n",
h->c.mb_x, h->c.mb_y);
@@ -1019,18 +1020,18 @@ int ff_h263_decode_mb(H263DecContext *const h)
intra:
h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
if (h->c.h263_aic) {
- h->c.ac_pred = get_bits1(&h->c.gb);
+ h->c.ac_pred = get_bits1(&h->gb);
if (h->c.ac_pred) {
h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
- h->c.h263_aic_dir = get_bits1(&h->c.gb);
+ h->c.h263_aic_dir = get_bits1(&h->gb);
}
}else
h->c.ac_pred = 0;
- if (h->c.pb_frame && get_bits1(&h->c.gb))
- pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb);
- cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ if (h->c.pb_frame && get_bits1(&h->gb))
+ pb_mv_count = h263_get_modb(&h->gb, h->c.pb_frame, &cbpb);
+ cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if(cbpy<0){
av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",
h->c.mb_x, h->c.mb_y);
@@ -1065,15 +1066,15 @@ intra:
}
end:
- if (get_bits_left(&h->c.gb) < 0)
+ if (get_bits_left(&h->gb) < 0)
return AVERROR_INVALIDDATA;
/* per-MB end of slice check */
{
- int v = show_bits(&h->c.gb, 16);
+ int v = show_bits(&h->gb, 16);
- if (get_bits_left(&h->c.gb) < 16) {
- v >>= 16 - get_bits_left(&h->c.gb);
+ if (get_bits_left(&h->gb) < 16) {
+ v >>= 16 - get_bits_left(&h->gb);
}
if(v==0)
@@ -1089,16 +1090,16 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
int width, height, i, ret;
int h263_plus;
- align_get_bits(&h->c.gb);
+ align_get_bits(&h->gb);
- if (show_bits(&h->c.gb, 2) == 2 && h->c.avctx->frame_num == 0) {
+ if (show_bits(&h->gb, 2) == 2 && h->c.avctx->frame_num == 0) {
av_log(h->c.avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
}
- uint32_t startcode = get_bits(&h->c.gb, 22-8);
+ uint32_t startcode = get_bits(&h->gb, 22-8);
- for (i = get_bits_left(&h->c.gb); i>24; i -= 8) {
- startcode = ((startcode << 8) | get_bits(&h->c.gb, 8)) & 0x003FFFFF;
+ for (i = get_bits_left(&h->gb); i>24; i -= 8) {
+ startcode = ((startcode << 8) | get_bits(&h->gb, 8)) & 0x003FFFFF;
if(startcode == 0x20)
break;
@@ -1109,25 +1110,25 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
return -1;
}
/* temporal reference */
- i = get_bits(&h->c.gb, 8); /* picture timestamp */
+ i = get_bits(&h->gb, 8); /* picture timestamp */
i -= (i - (h->c.picture_number & 0xFF) + 128) & ~0xFF;
h->c.picture_number = (h->c.picture_number&~0xFF) + i;
/* PTYPE starts here */
- if (check_marker(h->c.avctx, &h->c.gb, "in PTYPE") != 1) {
+ if (check_marker(h->c.avctx, &h->gb, "in PTYPE") != 1) {
return -1;
}
- if (get_bits1(&h->c.gb) != 0) {
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
return -1; /* H.263 id */
}
- skip_bits1(&h->c.gb); /* split screen off */
- skip_bits1(&h->c.gb); /* camera off */
- skip_bits1(&h->c.gb); /* freeze picture release off */
+ skip_bits1(&h->gb); /* split screen off */
+ skip_bits1(&h->gb); /* camera off */
+ skip_bits1(&h->gb); /* freeze picture release off */
- int format = get_bits(&h->c.gb, 3);
+ int format = get_bits(&h->gb, 3);
/*
0 forbidden
1 sub-QCIF
@@ -1143,19 +1144,19 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
if (!width)
return -1;
- h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb);
+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
- h->c.h263_long_vectors = get_bits1(&h->c.gb);
+ h->c.h263_long_vectors = get_bits1(&h->gb);
- if (get_bits1(&h->c.gb) != 0) {
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
return -1; /* SAC: off */
}
- h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */
+ h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
- h->c.pb_frame = get_bits1(&h->c.gb);
- h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
- skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */
+ h->c.pb_frame = get_bits1(&h->gb);
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
+ skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
h->c.width = width;
h->c.height = height;
@@ -1166,46 +1167,46 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
/* H.263v2 */
h263_plus = 1;
- ufep = get_bits(&h->c.gb, 3); /* Update Full Extended PTYPE */
+ ufep = get_bits(&h->gb, 3); /* Update Full Extended PTYPE */
/* ufep other than 0 and 1 are reserved */
if (ufep == 1) {
/* OPPTYPE */
- format = get_bits(&h->c.gb, 3);
+ format = get_bits(&h->gb, 3);
ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);
- h->c.custom_pcf = get_bits1(&h->c.gb);
- h->c.umvplus = get_bits1(&h->c.gb); /* Unrestricted Motion Vector */
- if (get_bits1(&h->c.gb) != 0) {
+ h->c.custom_pcf = get_bits1(&h->gb);
+ h->c.umvplus = get_bits1(&h->gb); /* Unrestricted Motion Vector */
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
}
- h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */
- h->c.h263_aic = get_bits1(&h->c.gb); /* Advanced Intra Coding (AIC) */
- h->c.loop_filter = get_bits1(&h->c.gb);
+ h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
+ h->c.h263_aic = get_bits1(&h->gb); /* Advanced Intra Coding (AIC) */
+ h->c.loop_filter = get_bits1(&h->gb);
if (h->c.avctx->lowres)
h->c.loop_filter = 0;
- h->c.h263_slice_structured= get_bits1(&h->c.gb);
- if (get_bits1(&h->c.gb) != 0) {
+ h->c.h263_slice_structured = get_bits1(&h->gb);
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
}
- if (get_bits1(&h->c.gb) != 0) {
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
}
- h->c.alt_inter_vlc = get_bits1(&h->c.gb);
- h->c.modified_quant = get_bits1(&h->c.gb);
+ h->c.alt_inter_vlc = get_bits1(&h->gb);
+ h->c.modified_quant = get_bits1(&h->gb);
if (h->c.modified_quant)
h->c.chroma_qscale_table= ff_h263_chroma_qscale_table;
- skip_bits(&h->c.gb, 1); /* Prevent start code emulation */
+ skip_bits(&h->gb, 1); /* Prevent start code emulation */
- skip_bits(&h->c.gb, 3); /* Reserved */
+ skip_bits(&h->gb, 3); /* Reserved */
} else if (ufep != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
return -1;
}
/* MPPTYPE */
- h->c.pict_type = get_bits(&h->c.gb, 3);
+ h->c.pict_type = get_bits(&h->gb, 3);
switch (h->c.pict_type) {
case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break;
case 1: h->c.pict_type = AV_PICTURE_TYPE_P; break;
@@ -1215,15 +1216,15 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
default:
return -1;
}
- skip_bits(&h->c.gb, 2);
- h->c.no_rounding = get_bits1(&h->c.gb);
- skip_bits(&h->c.gb, 4);
+ skip_bits(&h->gb, 2);
+ h->c.no_rounding = get_bits1(&h->gb);
+ skip_bits(&h->gb, 4);
/* Get the picture dimensions */
if (ufep) {
if (format == 6) {
/* Custom Picture Format (CPFMT) */
- int aspect_ratio_info = get_bits(&h->c.gb, 4);
+ int aspect_ratio_info = get_bits(&h->gb, 4);
ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info);
/* aspect ratios:
0 - forbidden
@@ -1234,14 +1235,14 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
5 - 40:33 (525-type 16:9)
6-14 - reserved
*/
- width = (get_bits(&h->c.gb, 9) + 1) * 4;
- check_marker(h->c.avctx, &h->c.gb, "in dimensions");
- height = get_bits(&h->c.gb, 9) * 4;
+ width = (get_bits(&h->gb, 9) + 1) * 4;
+ check_marker(h->c.avctx, &h->gb, "in dimensions");
+ height = get_bits(&h->gb, 9) * 4;
ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
/* expected dimensions */
- h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8);
- h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8);
+ h->c.avctx->sample_aspect_ratio.num = get_bits(&h->gb, 8);
+ h->c.avctx->sample_aspect_ratio.den = get_bits(&h->gb, 8);
}else{
h->c.avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
}
@@ -1258,8 +1259,8 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
if (h->c.custom_pcf) {
h->c.avctx->framerate.num = 1800000;
- h->c.avctx->framerate.den = 1000 + get_bits1(&h->c.gb);
- h->c.avctx->framerate.den *= get_bits(&h->c.gb, 7);
+ h->c.avctx->framerate.den = 1000 + get_bits1(&h->gb);
+ h->c.avctx->framerate.den *= get_bits(&h->gb, 7);
if (h->c.avctx->framerate.den == 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n");
return -1;
@@ -1273,30 +1274,30 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
}
if (h->c.custom_pcf)
- skip_bits(&h->c.gb, 2); //extended Temporal reference
+ skip_bits(&h->gb, 2); //extended Temporal reference
if (ufep) {
if (h->c.umvplus) {
- if(get_bits1(&h->c.gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
- skip_bits1(&h->c.gb);
+ if (get_bits1(&h->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
+ skip_bits1(&h->gb);
}
if (h->c.h263_slice_structured) {
- if (get_bits1(&h->c.gb) != 0) {
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
}
- if (get_bits1(&h->c.gb) != 0) {
+ if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "unordered slices not supported\n");
}
}
if (h->c.pict_type == AV_PICTURE_TYPE_B) {
- skip_bits(&h->c.gb, 4); //ELNUM
+ skip_bits(&h->gb, 4); //ELNUM
if (ufep == 1) {
- skip_bits(&h->c.gb, 4); // RLNUM
+ skip_bits(&h->gb, 4); // RLNUM
}
}
}
- h->c.qscale = get_bits(&h->c.gb, 5);
+ h->c.qscale = get_bits(&h->gb, 5);
}
ret = av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx);
@@ -1304,7 +1305,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
return ret;
if (!(h->c.avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
- if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->c.gb))
+ if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->gb))
return AVERROR_INVALIDDATA;
}
@@ -1315,10 +1316,10 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
if (h->c.pb_frame) {
- skip_bits(&h->c.gb, 3); /* Temporal reference for B-pictures */
+ skip_bits(&h->gb, 3); /* Temporal reference for B-pictures */
if (h->c.custom_pcf)
- skip_bits(&h->c.gb, 2); //extended Temporal reference
- skip_bits(&h->c.gb, 2); /* Quantization information for B-pictures */
+ skip_bits(&h->gb, 2); //extended Temporal reference
+ skip_bits(&h->gb, 2); /* Quantization information for B-pictures */
}
if (h->c.pict_type!=AV_PICTURE_TYPE_B) {
@@ -1338,17 +1339,17 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
}
/* PEI */
- if (skip_1stop_8data_bits(&h->c.gb) < 0)
+ if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA;
if (h->c.h263_slice_structured) {
- if (check_marker(h->c.avctx, &h->c.gb, "SEPB1") != 1) {
+ if (check_marker(h->c.avctx, &h->gb, "SEPB1") != 1) {
return -1;
}
ff_h263_decode_mba(h);
- if (check_marker(h->c.avctx, &h->c.gb, "SEPB2") != 1) {
+ if (check_marker(h->c.avctx, &h->gb, "SEPB2") != 1) {
return -1;
}
}
@@ -1366,19 +1367,19 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
ff_h263_show_pict_info(h, h263_plus);
- if (h->c.pict_type == AV_PICTURE_TYPE_I && h->c.codec_tag == AV_RL32("ZYGO") && get_bits_left(&h->c.gb) >= 85 + 13*3*16 + 50){
+ if (h->c.pict_type == AV_PICTURE_TYPE_I && h->c.codec_tag == AV_RL32("ZYGO") && get_bits_left(&h->gb) >= 85 + 13*3*16 + 50){
int i,j;
- for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb));
+ for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->gb));
av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
for(i=0; i<13; i++){
for(j=0; j<3; j++){
- int v= get_bits(&h->c.gb, 8);
- v |= get_sbits(&h->c.gb, 8) * (1 << 8);
+ int v= get_bits(&h->gb, 8);
+ v |= get_sbits(&h->gb, 8) * (1 << 8);
av_log(h->c.avctx, AV_LOG_DEBUG, " %5d", v);
}
av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
}
- for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb));
+ for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->gb));
}
return 0;
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index cba57369cd..15bfab9623 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -479,7 +479,7 @@ static int mpeg_decode_mb(MPVContext *const s)
s->interlaced_dct = get_bits1(&s->gb);
if (IS_QUANT(mb_type))
- s->qscale = mpeg_get_qscale(s);
+ s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
if (s->concealment_motion_vectors) {
/* just parse them */
@@ -537,7 +537,7 @@ static int mpeg_decode_mb(MPVContext *const s)
}
if (IS_QUANT(mb_type))
- s->qscale = mpeg_get_qscale(s);
+ s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
s->last_mv[0][0][0] = 0;
s->last_mv[0][0][1] = 0;
@@ -558,7 +558,7 @@ static int mpeg_decode_mb(MPVContext *const s)
}
if (IS_QUANT(mb_type))
- s->qscale = mpeg_get_qscale(s);
+ s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
/* motion vectors */
s->mv_dir = MB_TYPE_MV_2_MV_DIR(mb_type);
@@ -1370,7 +1370,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
ff_mpeg1_clean_buffers(s);
s->interlaced_dct = 0;
- s->qscale = mpeg_get_qscale(s);
+ s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
if (s->qscale == 0) {
av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
@@ -2805,7 +2805,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
skip_bits1(gb);
if (intraquant)
- m->qscale = mpeg_get_qscale(m);
+ m->qscale = mpeg_get_qscale(&m->gb, m->q_scale_type);
memset(s->block, 0, sizeof(s->block));
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 88ddacc87f..c6ed9d31bb 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -383,8 +383,8 @@ void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, int dir)
static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
{
H263DecContext *const h = &ctx->h;
- int bits_count = get_bits_count(&h->c.gb);
- int v = show_bits(&h->c.gb, 16);
+ int bits_count = get_bits_count(&h->gb);
+ int v = show_bits(&h->gb, 16);
if (h->c.workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)
return 0;
@@ -393,12 +393,12 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
if (h->c.pict_type == AV_PICTURE_TYPE_B ||
(v >> (8 - h->c.pict_type) != 1) || h->c.partitioned_frame)
break;
- skip_bits(&h->c.gb, 8 + h->c.pict_type);
+ skip_bits(&h->gb, 8 + h->c.pict_type);
bits_count += 8 + h->c.pict_type;
- v = show_bits(&h->c.gb, 16);
+ v = show_bits(&h->gb, 16);
}
- if (bits_count + 8 >= h->c.gb.size_in_bits) {
+ if (bits_count + 8 >= h->gb.size_in_bits) {
v >>= 8;
v |= 0x7F >> (7 - (bits_count & 7));
@@ -412,20 +412,20 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
if (v == mpeg4_resync_prefix[bits_count & 7]) {
int len, mb_num;
int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;
- GetBitContext gb = h->c.gb;
+ GetBitContext gb = h->gb;
- skip_bits(&h->c.gb, 1);
- align_get_bits(&h->c.gb);
+ skip_bits(&h->gb, 1);
+ align_get_bits(&h->gb);
for (len = 0; len < 32; len++)
- if (get_bits1(&h->c.gb))
+ if (get_bits1(&h->gb))
break;
- mb_num = get_bits(&h->c.gb, mb_num_bits);
- if (!mb_num || mb_num > h->c.mb_num || get_bits_count(&h->c.gb) + 6 > h->c.gb.size_in_bits)
+ mb_num = get_bits(&h->gb, mb_num_bits);
+ if (!mb_num || mb_num > h->c.mb_num || get_bits_count(&h->gb) + 6 > h->gb.size_in_bits)
mb_num= -1;
- h->c.gb = gb;
+ h->gb = gb;
if (len >= ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code))
return mb_num;
@@ -713,11 +713,11 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
int header_extension = 0, mb_num, len;
/* is there enough space left for a video packet + header */
- if (get_bits_count(&h->c.gb) > h->c.gb.size_in_bits - 20)
+ if (get_bits_count(&h->gb) > h->gb.size_in_bits - 20)
return AVERROR_INVALIDDATA;
for (len = 0; len < 32; len++)
- if (get_bits1(&h->c.gb))
+ if (get_bits1(&h->gb))
break;
if (len != ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) {
@@ -726,11 +726,11 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
}
if (ctx->shape != RECT_SHAPE) {
- header_extension = get_bits1(&h->c.gb);
+ header_extension = get_bits1(&h->gb);
// FIXME more stuff here
}
- mb_num = get_bits(&h->c.gb, mb_num_bits);
+ mb_num = get_bits(&h->gb, mb_num_bits);
if (mb_num >= h->c.mb_num || !mb_num) {
av_log(h->c.avctx, AV_LOG_ERROR,
"illegal mb_num in video packet (%d %d) \n", mb_num, h->c.mb_num);
@@ -741,31 +741,31 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
h->c.mb_y = mb_num / h->c.mb_width;
if (ctx->shape != BIN_ONLY_SHAPE) {
- int qscale = get_bits(&h->c.gb, ctx->quant_precision);
+ int qscale = get_bits(&h->gb, ctx->quant_precision);
if (qscale)
h->c.chroma_qscale = h->c.qscale = qscale;
}
if (ctx->shape == RECT_SHAPE)
- header_extension = get_bits1(&h->c.gb);
+ header_extension = get_bits1(&h->gb);
if (header_extension) {
- while (get_bits1(&h->c.gb) != 0)
+ while (get_bits1(&h->gb) != 0)
;
- check_marker(h->c.avctx, &h->c.gb, "before time_increment in video packed header");
- skip_bits(&h->c.gb, ctx->time_increment_bits); /* time_increment */
- check_marker(h->c.avctx, &h->c.gb, "before vop_coding_type in video packed header");
+ check_marker(h->c.avctx, &h->gb, "before time_increment in video packed header");
+ skip_bits(&h->gb, ctx->time_increment_bits); /* time_increment */
+ check_marker(h->c.avctx, &h->gb, "before vop_coding_type in video packed header");
- skip_bits(&h->c.gb, 2); /* vop coding type */
+ skip_bits(&h->gb, 2); /* vop coding type */
// FIXME not rect stuff here
if (ctx->shape != BIN_ONLY_SHAPE) {
- skip_bits(&h->c.gb, 3); /* intra dc vlc threshold */
+ skip_bits(&h->gb, 3); /* intra dc vlc threshold */
// FIXME don't just ignore everything
if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE) {
- if (mpeg4_decode_sprite_trajectory(ctx, &h->c.gb) < 0)
+ if (mpeg4_decode_sprite_trajectory(ctx, &h->gb) < 0)
return AVERROR_INVALIDDATA;
av_log(h->c.avctx, AV_LOG_ERROR, "untested\n");
}
@@ -773,13 +773,13 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
// FIXME reduced res stuff here
if (h->c.pict_type != AV_PICTURE_TYPE_I) {
- int f_code = get_bits(&h->c.gb, 3); /* fcode_for */
+ int f_code = get_bits(&h->gb, 3); /* fcode_for */
if (f_code == 0)
av_log(h->c.avctx, AV_LOG_ERROR,
"Error, video packet header damaged (f_code=0)\n");
}
if (h->c.pict_type == AV_PICTURE_TYPE_B) {
- int b_code = get_bits(&h->c.gb, 3);
+ int b_code = get_bits(&h->gb, 3);
if (b_code == 0)
av_log(h->c.avctx, AV_LOG_ERROR,
"Error, video packet header damaged (b_code=0)\n");
@@ -787,7 +787,7 @@ int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
}
}
if (ctx->new_pred)
- decode_new_pred(ctx, &h->c.gb);
+ decode_new_pred(ctx, &h->gb);
return 0;
}
@@ -808,7 +808,7 @@ static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
{
Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
- GetBitContext *gb = &h->c.gb;
+ GetBitContext *gb = &h->gb;
unsigned vlc_len;
uint16_t mb_num;
@@ -823,7 +823,7 @@ int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
h->c.mb_y = mb_num / h->c.mb_width;
if (ctx->shape != BIN_ONLY_SHAPE)
- h->c.qscale = mpeg_get_qscale(&h->c);
+ h->c.qscale = mpeg_get_qscale(&h->gb, h->c.q_scale_type);
if (get_bits1(gb)) { /* slice_extension_flag */
skip_bits1(gb); /* intra_slice */
@@ -985,9 +985,9 @@ static inline int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr)
int level, code, pred;
if (n < 4)
- code = get_vlc2(&h->c.gb, dc_lum, DC_VLC_BITS, 1);
+ code = get_vlc2(&h->gb, dc_lum, DC_VLC_BITS, 1);
else
- code = get_vlc2(&h->c.gb, dc_chrom, DC_VLC_BITS, 1);
+ code = get_vlc2(&h->gb, dc_chrom, DC_VLC_BITS, 1);
if (code < 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
@@ -999,19 +999,19 @@ static inline int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr)
} else {
if (IS_3IV1) {
if (code == 1)
- level = 2 * get_bits1(&h->c.gb) - 1;
+ level = 2 * get_bits1(&h->gb) - 1;
else {
- if (get_bits1(&h->c.gb))
- level = get_bits(&h->c.gb, code - 1) + (1 << (code - 1));
+ if (get_bits1(&h->gb))
+ level = get_bits(&h->gb, code - 1) + (1 << (code - 1));
else
- level = -get_bits(&h->c.gb, code - 1) - (1 << (code - 1));
+ level = -get_bits(&h->gb, code - 1) - (1 << (code - 1));
}
} else {
- level = get_xbits(&h->c.gb, code);
+ level = get_xbits(&h->gb, code);
}
if (code > 8) {
- if (get_bits1(&h->c.gb) == 0) { /* marker */
+ if (get_bits1(&h->gb) == 0) { /* marker */
if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {
av_log(h->c.avctx, AV_LOG_ERROR, "dc marker bit missing\n");
return AVERROR_INVALIDDATA;
@@ -1052,10 +1052,10 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
int i;
do {
- if (show_bits(&h->c.gb, 19) == DC_MARKER)
+ if (show_bits(&h->gb, 19) == DC_MARKER)
return mb_num - 1;
- cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1068,7 +1068,7 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
h->c.mb_intra = 1;
if (cbpc & 4)
- ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
h->c.cur_pic.qscale_table[xy] = h->c.qscale;
@@ -1092,11 +1092,11 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
const int stride = h->c.b8_stride * 2;
try_again:
- bits = show_bits(&h->c.gb, 17);
+ bits = show_bits(&h->gb, 17);
if (bits == MOTION_MARKER)
return mb_num - 1;
- skip_bits1(&h->c.gb);
+ skip_bits1(&h->gb);
if (bits & 0x10000) {
/* skip mb */
if (h->c.pict_type == AV_PICTURE_TYPE_S &&
@@ -1126,7 +1126,7 @@ try_again:
continue;
}
- cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1156,7 +1156,7 @@ try_again:
if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE &&
(cbpc & 16) == 0)
- h->c.mcsel = get_bits1(&h->c.gb);
+ h->c.mcsel = get_bits1(&h->gb);
else
h->c.mcsel = 0;
@@ -1238,8 +1238,8 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
h->c.first_slice_line = 0;
if (h->c.pict_type == AV_PICTURE_TYPE_I) {
- int ac_pred = get_bits1(&h->c.gb);
- int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ int ac_pred = get_bits1(&h->gb);
+ int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1252,8 +1252,8 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
if (IS_INTRA(h->c.cur_pic.mb_type[xy])) {
int i;
int dir = 0;
- int ac_pred = get_bits1(&h->c.gb);
- int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ int ac_pred = get_bits1(&h->gb);
+ int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
@@ -1262,7 +1262,7 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
}
if (h->c.cbp_table[xy] & 8)
- ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
h->c.cur_pic.qscale_table[xy] = h->c.qscale;
for (i = 0; i < 6; i++) {
@@ -1285,7 +1285,7 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
h->c.cur_pic.qscale_table[xy] = h->c.qscale;
h->c.cbp_table[xy] = 0;
} else {
- int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpy < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
@@ -1294,7 +1294,7 @@ static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
}
if (h->c.cbp_table[xy] & 8)
- ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
h->c.cur_pic.qscale_table[xy] = h->c.qscale;
h->c.cbp_table[xy] &= 3; // remove dquant
@@ -1338,18 +1338,18 @@ int ff_mpeg4_decode_partitions(H263DecContext *const h)
h->c.mb_num_left = mb_num;
if (h->c.pict_type == AV_PICTURE_TYPE_I) {
- while (show_bits(&h->c.gb, 9) == 1)
- skip_bits(&h->c.gb, 9);
- if (get_bits(&h->c.gb, 19) != DC_MARKER) {
+ while (show_bits(&h->gb, 9) == 1)
+ skip_bits(&h->gb, 9);
+ if (get_bits(&h->gb, 19) != DC_MARKER) {
av_log(h->c.avctx, AV_LOG_ERROR,
"marker missing after first I partition at %d %d\n",
h->c.mb_x, h->c.mb_y);
return AVERROR_INVALIDDATA;
}
} else {
- while (show_bits(&h->c.gb, 10) == 1)
- skip_bits(&h->c.gb, 10);
- if (get_bits(&h->c.gb, 17) != MOTION_MARKER) {
+ while (show_bits(&h->gb, 10) == 1)
+ skip_bits(&h->gb, 10);
+ if (get_bits(&h->gb, 17) != MOTION_MARKER) {
av_log(h->c.avctx, AV_LOG_ERROR,
"marker missing after first P partition at %d %d\n",
h->c.mb_x, h->c.mb_y);
@@ -1463,52 +1463,52 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
}
}
{
- OPEN_READER(re, &h->c.gb);
+ OPEN_READER(re, &h->gb);
for (;;) {
- UPDATE_CACHE(re, &h->c.gb);
- GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0);
+ UPDATE_CACHE(re, &h->gb);
+ GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
if (level == 0) {
/* escape */
if (rvlc) {
- if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ if (SHOW_UBITS(re, &h->gb, 1) == 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"1. marker bit missing in rvlc esc\n");
return AVERROR_INVALIDDATA;
}
- SKIP_CACHE(re, &h->c.gb, 1);
+ SKIP_CACHE(re, &h->gb, 1);
- last = SHOW_UBITS(re, &h->c.gb, 1);
- SKIP_CACHE(re, &h->c.gb, 1);
- run = SHOW_UBITS(re, &h->c.gb, 6);
- SKIP_COUNTER(re, &h->c.gb, 1 + 1 + 6);
- UPDATE_CACHE(re, &h->c.gb);
+ last = SHOW_UBITS(re, &h->gb, 1);
+ SKIP_CACHE(re, &h->gb, 1);
+ run = SHOW_UBITS(re, &h->gb, 6);
+ SKIP_COUNTER(re, &h->gb, 1 + 1 + 6);
+ UPDATE_CACHE(re, &h->gb);
- if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ if (SHOW_UBITS(re, &h->gb, 1) == 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"2. marker bit missing in rvlc esc\n");
return AVERROR_INVALIDDATA;
}
- SKIP_CACHE(re, &h->c.gb, 1);
+ SKIP_CACHE(re, &h->gb, 1);
- level = SHOW_UBITS(re, &h->c.gb, 11);
- SKIP_CACHE(re, &h->c.gb, 11);
+ level = SHOW_UBITS(re, &h->gb, 11);
+ SKIP_CACHE(re, &h->gb, 11);
- if (SHOW_UBITS(re, &h->c.gb, 5) != 0x10) {
+ if (SHOW_UBITS(re, &h->gb, 5) != 0x10) {
av_log(h->c.avctx, AV_LOG_ERROR, "reverse esc missing\n");
return AVERROR_INVALIDDATA;
}
- SKIP_CACHE(re, &h->c.gb, 5);
+ SKIP_CACHE(re, &h->gb, 5);
level = level * qmul + qadd;
- level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
- SKIP_COUNTER(re, &h->c.gb, 1 + 11 + 5 + 1);
+ level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
+ SKIP_COUNTER(re, &h->gb, 1 + 11 + 5 + 1);
i += run + 1;
if (last)
i += 192;
} else {
int cache;
- cache = GET_CACHE(re, &h->c.gb);
+ cache = GET_CACHE(re, &h->gb);
if (IS_3IV1)
cache ^= 0xC0000000;
@@ -1516,36 +1516,36 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
if (cache & 0x80000000) {
if (cache & 0x40000000) {
/* third escape */
- SKIP_CACHE(re, &h->c.gb, 2);
- last = SHOW_UBITS(re, &h->c.gb, 1);
- SKIP_CACHE(re, &h->c.gb, 1);
- run = SHOW_UBITS(re, &h->c.gb, 6);
- SKIP_COUNTER(re, &h->c.gb, 2 + 1 + 6);
- UPDATE_CACHE(re, &h->c.gb);
+ SKIP_CACHE(re, &h->gb, 2);
+ last = SHOW_UBITS(re, &h->gb, 1);
+ SKIP_CACHE(re, &h->gb, 1);
+ run = SHOW_UBITS(re, &h->gb, 6);
+ SKIP_COUNTER(re, &h->gb, 2 + 1 + 6);
+ UPDATE_CACHE(re, &h->gb);
if (IS_3IV1) {
- level = SHOW_SBITS(re, &h->c.gb, 12);
- LAST_SKIP_BITS(re, &h->c.gb, 12);
+ level = SHOW_SBITS(re, &h->gb, 12);
+ LAST_SKIP_BITS(re, &h->gb, 12);
} else {
- if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ if (SHOW_UBITS(re, &h->gb, 1) == 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"1. marker bit missing in 3. esc\n");
- if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0)
+ if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->gb) <= 0)
return AVERROR_INVALIDDATA;
}
- SKIP_CACHE(re, &h->c.gb, 1);
+ SKIP_CACHE(re, &h->gb, 1);
- level = SHOW_SBITS(re, &h->c.gb, 12);
- SKIP_CACHE(re, &h->c.gb, 12);
+ level = SHOW_SBITS(re, &h->gb, 12);
+ SKIP_CACHE(re, &h->gb, 12);
- if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ if (SHOW_UBITS(re, &h->gb, 1) == 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"2. marker bit missing in 3. esc\n");
- if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0)
+ if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->gb) <= 0)
return AVERROR_INVALIDDATA;
}
- SKIP_COUNTER(re, &h->c.gb, 1 + 12 + 1);
+ SKIP_COUNTER(re, &h->gb, 1 + 12 + 1);
}
#if 0
@@ -1592,26 +1592,26 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
i += 192;
} else {
/* second escape */
- SKIP_BITS(re, &h->c.gb, 2);
- GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
+ SKIP_BITS(re, &h->gb, 2);
+ GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i += run + rl->max_run[run >> 7][level / qmul] + 1; // FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
- LAST_SKIP_BITS(re, &h->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
+ LAST_SKIP_BITS(re, &h->gb, 1);
}
} else {
/* first escape */
- SKIP_BITS(re, &h->c.gb, 1);
- GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
+ SKIP_BITS(re, &h->gb, 1);
+ GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i += run;
level = level + rl->max_level[run >> 7][(run - 1) & 63] * qmul; // FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
- LAST_SKIP_BITS(re, &h->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
+ LAST_SKIP_BITS(re, &h->gb, 1);
}
}
} else {
i += run;
- level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
- LAST_SKIP_BITS(re, &h->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
+ LAST_SKIP_BITS(re, &h->gb, 1);
}
ff_tlog(h->c.avctx, "dct[%d][%d] = %- 4d end?:%d\n", scan_table[i&63]&7, scan_table[i&63] >> 3, level, i>62);
if (i > 62) {
@@ -1628,7 +1628,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
block[scan_table[i]] = level;
}
- CLOSE_READER(re, &h->c.gb);
+ CLOSE_READER(re, &h->gb);
}
not_coded:
@@ -1751,7 +1751,7 @@ static int mpeg4_decode_mb(H263DecContext *const h)
if (h->c.pict_type == AV_PICTURE_TYPE_P ||
h->c.pict_type == AV_PICTURE_TYPE_S) {
do {
- if (get_bits1(&h->c.gb)) {
+ if (get_bits1(&h->gb)) {
/* skip mb */
h->c.mb_intra = 0;
for (i = 0; i < 6; i++)
@@ -1780,7 +1780,7 @@ static int mpeg4_decode_mb(H263DecContext *const h)
}
goto end;
}
- cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"mcbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1796,10 +1796,10 @@ static int mpeg4_decode_mb(H263DecContext *const h)
if (h->c.pict_type == AV_PICTURE_TYPE_S &&
ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)
- h->c.mcsel = get_bits1(&h->c.gb);
+ h->c.mcsel = get_bits1(&h->gb);
else
h->c.mcsel = 0;
- cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
+ cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
if (cbpy < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"P cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -1808,10 +1808,10 @@ static int mpeg4_decode_mb(H263DecContext *const h)
cbp = (cbpc & 3) | (cbpy << 2);
if (dquant)
- ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
if ((!h->c.progressive_sequence) &&
(cbp || (h->c.workaround_bugs & FF_BUG_XVID_ILACE)))
- h->c.interlaced_dct = get_bits1(&h->c.gb);
+ h->c.interlaced_dct = get_bits1(&h->gb);
h->c.mv_dir = MV_DIR_FORWARD;
if ((cbpc & 16) == 0) {
@@ -1824,14 +1824,14 @@ static int mpeg4_decode_mb(H263DecContext *const h)
my = get_amv(ctx, 1);
h->c.mv[0][0][0] = mx;
h->c.mv[0][0][1] = my;
- } else if ((!h->c.progressive_sequence) && get_bits1(&h->c.gb)) {
+ } else if ((!h->c.progressive_sequence) && get_bits1(&h->gb)) {
h->c.cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |
MB_TYPE_INTERLACED;
/* 16x8 field motion prediction */
h->c.mv_type = MV_TYPE_FIELD;
- h->c.field_select[0][0] = get_bits1(&h->c.gb);
- h->c.field_select[0][1] = get_bits1(&h->c.gb);
+ h->c.field_select[0][0] = get_bits1(&h->gb);
+ h->c.field_select[0][1] = get_bits1(&h->gb);
ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
@@ -1921,14 +1921,14 @@ static int mpeg4_decode_mb(H263DecContext *const h)
goto end;
}
- modb1 = get_bits1(&h->c.gb);
+ modb1 = get_bits1(&h->gb);
if (modb1) {
// like MB_TYPE_B_DIRECT but no vectors coded
mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV;
cbp = 0;
} else {
- modb2 = get_bits1(&h->c.gb);
- mb_type = get_vlc2(&h->c.gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
+ modb2 = get_bits1(&h->gb);
+ mb_type = get_vlc2(&h->gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
if (mb_type < 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "illegal MB_type\n");
return AVERROR_INVALIDDATA;
@@ -1937,29 +1937,29 @@ static int mpeg4_decode_mb(H263DecContext *const h)
cbp = 0;
} else {
h->c.bdsp.clear_blocks(h->block[0]);
- cbp = get_bits(&h->c.gb, 6);
+ cbp = get_bits(&h->gb, 6);
}
if ((!IS_DIRECT(mb_type)) && cbp) {
- if (get_bits1(&h->c.gb))
- ff_set_qscale(&h->c, h->c.qscale + get_bits1(&h->c.gb) * 4 - 2);
+ if (get_bits1(&h->gb))
+ ff_set_qscale(&h->c, h->c.qscale + get_bits1(&h->gb) * 4 - 2);
}
if (!h->c.progressive_sequence) {
if (cbp)
- h->c.interlaced_dct = get_bits1(&h->c.gb);
+ h->c.interlaced_dct = get_bits1(&h->gb);
- if (!IS_DIRECT(mb_type) && get_bits1(&h->c.gb)) {
+ if (!IS_DIRECT(mb_type) && get_bits1(&h->gb)) {
mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
mb_type &= ~MB_TYPE_16x16;
if (HAS_FORWARD_MV(mb_type)) {
- h->c.field_select[0][0] = get_bits1(&h->c.gb);
- h->c.field_select[0][1] = get_bits1(&h->c.gb);
+ h->c.field_select[0][0] = get_bits1(&h->gb);
+ h->c.field_select[0][1] = get_bits1(&h->gb);
}
if (HAS_BACKWARD_MV(mb_type)) {
- h->c.field_select[1][0] = get_bits1(&h->c.gb);
- h->c.field_select[1][1] = get_bits1(&h->c.gb);
+ h->c.field_select[1][0] = get_bits1(&h->gb);
+ h->c.field_select[1][1] = get_bits1(&h->gb);
}
}
}
@@ -2039,7 +2039,7 @@ static int mpeg4_decode_mb(H263DecContext *const h)
int use_intra_dc_vlc;
do {
- cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
+ cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if (cbpc < 0) {
av_log(h->c.avctx, AV_LOG_ERROR,
"I cbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -2051,13 +2051,13 @@ static int mpeg4_decode_mb(H263DecContext *const h)
h->c.mb_intra = 1;
intra:
- h->c.ac_pred = get_bits1(&h->c.gb);
+ h->c.ac_pred = get_bits1(&h->gb);
if (h->c.ac_pred)
h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
else
h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
- cbpy = get_vlc2(&h->c.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) {
av_log(h->c.avctx, AV_LOG_ERROR,
"I cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
@@ -2068,10 +2068,10 @@ intra:
use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;
if (dquant)
- ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
if (!h->c.progressive_sequence)
- h->c.interlaced_dct = get_bits1(&h->c.gb);
+ h->c.interlaced_dct = get_bits1(&h->gb);
h->c.bdsp.clear_blocks(h->block[0]);
/* decode each block */
@@ -2173,24 +2173,24 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6
if (n < 4) {
cc = 0;
- dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&h->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
quant_matrix = h->c.intra_matrix;
} else {
cc = (n & 1) + 1;
if (ctx->rgb)
- dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&h->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
else
- dct_dc_size = get_vlc2(&h->c.gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
+ dct_dc_size = get_vlc2(&h->gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
quant_matrix = h->c.chroma_intra_matrix;
}
if (dct_dc_size == 0) {
dct_diff = 0;
} else {
- dct_diff = get_xbits(&h->c.gb, dct_dc_size);
+ dct_diff = get_xbits(&h->gb, dct_dc_size);
if (dct_dc_size > 8) {
- if(!check_marker(h->c.avctx, &h->c.gb, "dct_dc_size > 8"))
+ if(!check_marker(h->c.avctx, &h->gb, "dct_dc_size > 8"))
return AVERROR_INVALIDDATA;
}
@@ -2209,7 +2209,7 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6
/* AC Coefficients */
while (1) {
- group = get_vlc2(&h->c.gb, cur_vlc, STUDIO_INTRA_BITS, 2);
+ group = get_vlc2(&h->gb, cur_vlc, STUDIO_INTRA_BITS, 2);
if (group < 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n");
@@ -2226,12 +2226,12 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6
/* Zero run length (Table B.47) */
run = 1 << additional_code_len;
if (additional_code_len)
- run += get_bits(&h->c.gb, additional_code_len);
+ run += get_bits(&h->gb, additional_code_len);
idx += run;
continue;
} else if (group >= 7 && group <= 12) {
/* Zero run length and +/-1 level (Table B.48) */
- code = get_bits(&h->c.gb, additional_code_len);
+ code = get_bits(&h->gb, additional_code_len);
sign = code & 1;
code >>= 1;
run = (1 << (additional_code_len - 1)) + code;
@@ -2245,14 +2245,14 @@ static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[6
if (idx > 63)
return AVERROR_INVALIDDATA;
j = scantable[idx++];
- block[j] = get_xbits(&h->c.gb, additional_code_len);
+ block[j] = get_xbits(&h->gb, additional_code_len);
} else if (group == 21) {
/* Escape */
if (idx > 63)
return AVERROR_INVALIDDATA;
j = scantable[idx++];
additional_code_len = h->c.avctx->bits_per_raw_sample + ctx->dct_precision + 4;
- flc = get_bits(&h->c.gb, additional_code_len);
+ flc = get_bits(&h->gb, additional_code_len);
if (flc >> (additional_code_len-1))
block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
else
@@ -2278,14 +2278,14 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
height = 16 >> (n ? h->c.chroma_y_shift : 0);
w = 16 >> (n ? h->c.chroma_x_shift : 0);
- block_mean = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample);
+ block_mean = get_bits(&h->gb, h->c.avctx->bits_per_raw_sample);
if (block_mean == 0){
av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
return AVERROR_INVALIDDATA;
}
h->c.last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
- rice_parameter = get_bits(&h->c.gb, 4);
+ rice_parameter = get_bits(&h->gb, 4);
if (rice_parameter == 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
return AVERROR_INVALIDDATA;
@@ -2307,17 +2307,17 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
left = output;
topleft = top;
- rice_prefix_code = get_unary(&h->c.gb, 1, 12);
+ rice_prefix_code = get_unary(&h->gb, 1, 12);
/* Escape */
if (rice_prefix_code == 11)
- dpcm_residual = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample);
+ dpcm_residual = get_bits(&h->gb, h->c.avctx->bits_per_raw_sample);
else {
if (rice_prefix_code == 12) {
av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n");
return AVERROR_INVALIDDATA;
}
- rice_suffix_code = get_bitsz(&h->c.gb, rice_parameter);
+ rice_suffix_code = get_bitsz(&h->gb, rice_parameter);
dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
}
@@ -2363,12 +2363,12 @@ static int mpeg4_decode_studio_mb(H263DecContext *const h)
/* StudioMacroblock */
/* Assumes I-VOP */
h->c.mb_intra = 1;
- if (get_bits1(&h->c.gb)) { /* compression_mode */
+ if (get_bits1(&h->gb)) { /* compression_mode */
/* DCT */
/* macroblock_type, 1 or 2-bit VLC */
- if (!get_bits1(&h->c.gb)) {
- skip_bits1(&h->c.gb);
- h->c.qscale = mpeg_get_qscale(&h->c);
+ if (!get_bits1(&h->gb)) {
+ skip_bits1(&h->gb);
+ h->c.qscale = mpeg_get_qscale(&h->gb, h->c.q_scale_type);
}
for (i = 0; i < mpeg4_block_count[h->c.chroma_format]; i++) {
@@ -2377,25 +2377,25 @@ static int mpeg4_decode_studio_mb(H263DecContext *const h)
}
} else {
/* DPCM */
- check_marker(h->c.avctx, &h->c.gb, "DPCM block start");
- ctx->dpcm_direction = get_bits1(&h->c.gb) ? -1 : 1;
+ check_marker(h->c.avctx, &h->gb, "DPCM block start");
+ ctx->dpcm_direction = get_bits1(&h->gb) ? -1 : 1;
for (i = 0; i < 3; i++) {
if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0)
return AVERROR_INVALIDDATA;
}
}
- if (get_bits_left(&h->c.gb) >= 24 && show_bits(&h->c.gb, 23) == 0) {
- next_start_code_studio(&h->c.gb);
+ if (get_bits_left(&h->gb) >= 24 && show_bits(&h->gb, 23) == 0) {
+ next_start_code_studio(&h->gb);
return SLICE_END;
}
//vcon-stp9L1.bits (first frame)
- if (get_bits_left(&h->c.gb) == 0)
+ if (get_bits_left(&h->gb) == 0)
return SLICE_END;
//vcon-stp2L1.bits, vcon-stp3L1.bits, vcon-stp6L1.bits, vcon-stp7L1.bits, vcon-stp8L1.bits, vcon-stp10L1.bits (first frame)
- if (get_bits_left(&h->c.gb) < 8U && show_bits(&h->c.gb, get_bits_left(&h->c.gb)) == 0)
+ if (get_bits_left(&h->gb) < 8U && show_bits(&h->gb, get_bits_left(&h->gb)) == 0)
return SLICE_END;
return SLICE_OK;
@@ -3743,9 +3743,9 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h)
h->c.skipped_last_frame = 0;
if (ctx->bitstream_buffer) {
- int buf_size = get_bits_left(&h->c.gb) / 8U;
+ int buf_size = get_bits_left(&h->gb) / 8U;
int bitstream_buffer_size = ctx->bitstream_buffer->size;
- const uint8_t *buf = h->c.gb.buffer;
+ const uint8_t *buf = h->gb.buffer;
if (h->c.divx_packed) {
for (int i = 0; i < buf_size - 3; i++) {
@@ -3760,7 +3760,7 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h)
}
ctx->bitstream_buffer->size = 0;
if (bitstream_buffer_size && (h->c.divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder
- int ret = init_get_bits8(&h->c.gb, ctx->bitstream_buffer->data,
+ int ret = init_get_bits8(&h->gb, ctx->bitstream_buffer->data,
bitstream_buffer_size);
if (ret < 0)
return ret;
@@ -3768,7 +3768,7 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h)
av_buffer_unref(&ctx->bitstream_buffer);
}
- return ff_mpeg4_parse_picture_header(ctx, &h->c.gb, 0, 0);
+ return ff_mpeg4_parse_picture_header(ctx, &h->gb, 0, 0);
}
int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
@@ -3781,7 +3781,7 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
/* divx 5.01+ bitstream reorder stuff */
if (h->c.divx_packed) {
- int current_pos = ctx->bitstream_buffer && h->c.gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->c.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;
uint8_t *buf = pkt->data;
int buf_size = pkt->size;
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index f76158040d..8b94cc1ff0 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -219,7 +219,6 @@ typedef struct MpegEncContext {
/* error concealment / resync */
int resync_mb_x; ///< x position of last resync marker
int resync_mb_y; ///< y position of last resync marker
- GetBitContext last_resync_gb; ///< used to search for the next resync marker
int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
/* H.263 specific */
diff --git a/libavcodec/mpegvideodec.h b/libavcodec/mpegvideodec.h
index 5b2a38d1c8..16b3eb1b17 100644
--- a/libavcodec/mpegvideodec.h
+++ b/libavcodec/mpegvideodec.h
@@ -77,10 +77,10 @@ int ff_mpv_decode_close(AVCodecContext *avctx);
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict);
-static inline int mpeg_get_qscale(MpegEncContext *s)
+static inline int mpeg_get_qscale(GetBitContext *const gb, int q_scale_type)
{
- int qscale = get_bits(&s->gb, 5);
- if (s->q_scale_type)
+ int qscale = get_bits(gb, 5);
+ if (q_scale_type)
return ff_mpeg2_non_linear_qscale[qscale];
else
return qscale << 1;
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 06f6367a38..36243e14c9 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -78,7 +78,7 @@ static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code
{
int code, val, sign, shift;
- code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
+ code = get_vlc2(&h->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
ff_dlog(h->c.avctx, "MV code %d at %d %d pred: %d\n",
code, h->c.mb_x,h->c.mb_y, pred);
if (code < 0)
@@ -86,12 +86,12 @@ static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code
if (code == 0)
return pred;
- sign = get_bits1(&h->c.gb);
+ sign = get_bits1(&h->gb);
shift = f_code - 1;
val = code;
if (shift) {
val = (val - 1) << shift;
- val |= get_bits(&h->c.gb, shift);
+ val |= get_bits(&h->gb, shift);
val++;
}
if (sign)
@@ -114,7 +114,7 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h)
if (h->c.pict_type == AV_PICTURE_TYPE_P) {
if (ms->use_skip_mb_code) {
- if (get_bits1(&h->c.gb)) {
+ if (get_bits1(&h->gb)) {
/* skip mb */
h->c.mb_intra = 0;
for(i=0;i<6;i++)
@@ -130,9 +130,9 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h)
}
if (h->c.msmpeg4_version == MSMP4_V2)
- code = get_vlc2(&h->c.gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1);
+ code = get_vlc2(&h->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1);
else
- code = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
+ code = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
if(code<0 || code>7){
av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",
code, h->c.mb_x, h->c.mb_y);
@@ -145,9 +145,9 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h)
} else {
h->c.mb_intra = 1;
if (h->c.msmpeg4_version == MSMP4_V2)
- cbp = get_vlc2(&h->c.gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1);
+ cbp = get_vlc2(&h->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1);
else
- cbp = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
+ cbp = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
if(cbp<0 || cbp>3){
av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",
cbp, h->c.mb_x, h->c.mb_y);
@@ -158,7 +158,7 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h)
if (!h->c.mb_intra) {
int mx, my, cbpy;
- cbpy = get_vlc2(&h->c.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){
av_log(h->c.avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n",
cbp, h->c.mb_x, h->c.mb_y);
@@ -181,8 +181,8 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h)
} else {
int v;
if (h->c.msmpeg4_version == MSMP4_V2) {
- h->c.ac_pred = get_bits1(&h->c.gb);
- v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ h->c.ac_pred = get_bits1(&h->gb);
+ v = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (v < 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
return -1;
@@ -190,7 +190,7 @@ static int msmpeg4v12_decode_mb(H263DecContext *const h)
cbp|= v<<2;
} else{
h->c.ac_pred = 0;
- v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
+ v = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (v < 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
return -1;
@@ -220,12 +220,12 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h)
uint8_t *coded_val;
uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride];
- if (get_bits_left(&h->c.gb) <= 0)
+ if (get_bits_left(&h->gb) <= 0)
return AVERROR_INVALIDDATA;
if (h->c.pict_type == AV_PICTURE_TYPE_P) {
if (ms->use_skip_mb_code) {
- if (get_bits1(&h->c.gb)) {
+ if (get_bits1(&h->gb)) {
/* skip mb */
h->c.mb_intra = 0;
for(i=0;i<6;i++)
@@ -241,14 +241,14 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h)
}
}
- code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
+ code = get_vlc2(&h->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
//h->c.mb_intra = (code & 0x40) ? 0 : 1;
h->c.mb_intra = (~code & 0x40) >> 6;
cbp = code & 0x3f;
} else {
h->c.mb_intra = 1;
- code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
+ code = get_vlc2(&h->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
/* predict coded block pattern */
cbp = 0;
for(i=0;i<6;i++) {
@@ -265,7 +265,7 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h)
if (!h->c.mb_intra) {
int mx, my;
if (ms->per_mb_rl_table && cbp) {
- ms->rl_table_index = decode012(&h->c.gb);
+ ms->rl_table_index = decode012(&h->gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);
@@ -278,16 +278,16 @@ static int msmpeg4v34_decode_mb(H263DecContext *const h)
} else {
ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
- show_bits(&h->c.gb, 24));
- h->c.ac_pred = get_bits1(&h->c.gb);
+ show_bits(&h->gb, 24));
+ h->c.ac_pred = get_bits1(&h->gb);
*mb_type_ptr = MB_TYPE_INTRA;
if (h->c.inter_intra_pred) {
- h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
+ h->c.h263_aic_dir = get_vlc2(&h->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
ff_dlog(h->c.avctx, "%d%d %d %d/",
h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
}
if (ms->per_mb_rl_table && cbp) {
- ms->rl_table_index = decode012(&h->c.gb);
+ ms->rl_table_index = decode012(&h->gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
}
@@ -409,33 +409,33 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
// smallest "black/skip" frame generally contain not much recoverable content
// while at the same time they have the highest computational requirements
// per byte
- if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
+ if (get_bits_left(&h->gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
return AVERROR_INVALIDDATA;
if (h->c.msmpeg4_version == MSMP4_V1) {
- int start_code = get_bits_long(&h->c.gb, 32);
+ int start_code = get_bits_long(&h->gb, 32);
if(start_code!=0x00000100){
av_log(h->c.avctx, AV_LOG_ERROR, "invalid startcode\n");
return -1;
}
- skip_bits(&h->c.gb, 5); // frame number */
+ skip_bits(&h->gb, 5); // frame number */
}
- h->c.pict_type = get_bits(&h->c.gb, 2) + 1;
+ h->c.pict_type = get_bits(&h->gb, 2) + 1;
if (h->c.pict_type != AV_PICTURE_TYPE_I &&
h->c.pict_type != AV_PICTURE_TYPE_P){
av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n");
return -1;
}
- h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
if (h->c.qscale == 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n");
return -1;
}
if (h->c.pict_type == AV_PICTURE_TYPE_I) {
- code = get_bits(&h->c.gb, 5);
+ code = get_bits(&h->gb, 5);
if (h->c.msmpeg4_version == MSMP4_V1) {
if(code==0 || code>h->c.mb_height) {
av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
@@ -462,25 +462,25 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
ms->dc_table_index = 0; //not used
break;
case MSMP4_V3:
- ms->rl_chroma_table_index = decode012(&h->c.gb);
- ms->rl_table_index = decode012(&h->c.gb);
+ ms->rl_chroma_table_index = decode012(&h->gb);
+ ms->rl_table_index = decode012(&h->gb);
- ms->dc_table_index = get_bits1(&h->c.gb);
+ ms->dc_table_index = get_bits1(&h->gb);
break;
case MSMP4_WMV1:
ff_msmpeg4_decode_ext_header(h, (2+5+5+17+7)/8);
if (ms->bit_rate > MBAC_BITRATE)
- ms->per_mb_rl_table = get_bits1(&h->c.gb);
+ ms->per_mb_rl_table = get_bits1(&h->gb);
else
ms->per_mb_rl_table = 0;
if (!ms->per_mb_rl_table) {
- ms->rl_chroma_table_index = decode012(&h->c.gb);
- ms->rl_table_index = decode012(&h->c.gb);
+ ms->rl_chroma_table_index = decode012(&h->gb);
+ ms->rl_table_index = decode012(&h->gb);
}
- ms->dc_table_index = get_bits1(&h->c.gb);
+ ms->dc_table_index = get_bits1(&h->gb);
h->c.inter_intra_pred= 0;
break;
default:
@@ -502,37 +502,37 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
if (h->c.msmpeg4_version == MSMP4_V1)
ms->use_skip_mb_code = 1;
else
- ms->use_skip_mb_code = get_bits1(&h->c.gb);
+ ms->use_skip_mb_code = get_bits1(&h->gb);
ms->rl_table_index = 2;
ms->rl_chroma_table_index = ms->rl_table_index;
ms->dc_table_index = 0; //not used
ms->mv_table_index = 0;
break;
case MSMP4_V3:
- ms->use_skip_mb_code = get_bits1(&h->c.gb);
- ms->rl_table_index = decode012(&h->c.gb);
+ ms->use_skip_mb_code = get_bits1(&h->gb);
+ ms->rl_table_index = decode012(&h->gb);
ms->rl_chroma_table_index = ms->rl_table_index;
- ms->dc_table_index = get_bits1(&h->c.gb);
+ ms->dc_table_index = get_bits1(&h->gb);
- ms->mv_table_index = get_bits1(&h->c.gb);
+ ms->mv_table_index = get_bits1(&h->gb);
break;
case MSMP4_WMV1:
- ms->use_skip_mb_code = get_bits1(&h->c.gb);
+ ms->use_skip_mb_code = get_bits1(&h->gb);
if (ms->bit_rate > MBAC_BITRATE)
- ms->per_mb_rl_table = get_bits1(&h->c.gb);
+ ms->per_mb_rl_table = get_bits1(&h->gb);
else
ms->per_mb_rl_table = 0;
if (!ms->per_mb_rl_table) {
- ms->rl_table_index = decode012(&h->c.gb);
+ ms->rl_table_index = decode012(&h->gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
- ms->dc_table_index = get_bits1(&h->c.gb);
+ ms->dc_table_index = get_bits1(&h->gb);
- ms->mv_table_index = get_bits1(&h->c.gb);
+ ms->mv_table_index = get_bits1(&h->gb);
h->c.inter_intra_pred = h->c.width*h->c.height < 320*240 &&
ms->bit_rate <= II_BITRATE;
break;
@@ -568,15 +568,15 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)
{
MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
- int left= buf_size*8 - get_bits_count(&h->c.gb);
+ int left = buf_size*8 - get_bits_count(&h->gb);
int length = h->c.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(&h->c.gb, 5); /* fps */
- ms->bit_rate = get_bits(&h->c.gb, 11) * 1024;
+ skip_bits(&h->gb, 5); /* fps */
+ ms->bit_rate = get_bits(&h->gb, 11) * 1024;
if (h->c.msmpeg4_version >= MSMP4_V3)
- ms->flipflop_rounding = get_bits1(&h->c.gb);
+ ms->flipflop_rounding = get_bits1(&h->gb);
else
ms->flipflop_rounding = 0;
}
@@ -601,9 +601,9 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
if (h->c.msmpeg4_version <= MSMP4_V2) {
if (n < 4) {
- level = get_vlc2(&h->c.gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
+ level = get_vlc2(&h->gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
} else {
- level = get_vlc2(&h->c.gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
+ level = get_vlc2(&h->gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
}
if (level < 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
@@ -612,15 +612,15 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
}
level-=256;
} else {
- level = get_vlc2(&h->c.gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
+ level = get_vlc2(&h->gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
MSMP4_DC_VLC_BITS, 3);
if (level == DC_MAX) {
- level = get_bits(&h->c.gb, 8);
- if (get_bits1(&h->c.gb))
+ level = get_bits(&h->gb, 8);
+ if (get_bits1(&h->gb))
level = -level;
} else if (level != 0) {
- if (get_bits1(&h->c.gb))
+ if (get_bits1(&h->gb))
level = -level;
}
}
@@ -721,58 +721,58 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
rl_vlc= rl->rl_vlc[h->c.qscale];
}
{
- OPEN_READER(re, &h->c.gb);
+ OPEN_READER(re, &h->gb);
for(;;) {
- UPDATE_CACHE(re, &h->c.gb);
- GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0);
+ UPDATE_CACHE(re, &h->gb);
+ GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
if (level==0) {
int cache;
- cache= GET_CACHE(re, &h->c.gb);
+ cache= GET_CACHE(re, &h->gb);
/* escape */
if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {
if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {
/* third escape */
if (h->c.msmpeg4_version != MSMP4_V1)
- LAST_SKIP_BITS(re, &h->c.gb, 2);
- UPDATE_CACHE(re, &h->c.gb);
+ LAST_SKIP_BITS(re, &h->gb, 2);
+ UPDATE_CACHE(re, &h->gb);
if (h->c.msmpeg4_version <= MSMP4_V3) {
- last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_CACHE(re, &h->c.gb, 1);
- run = SHOW_UBITS(re, &h->c.gb, 6); SKIP_CACHE(re, &h->c.gb, 6);
- level = SHOW_SBITS(re, &h->c.gb, 8);
- SKIP_COUNTER(re, &h->c.gb, 1 + 6 + 8);
+ last = SHOW_UBITS(re, &h->gb, 1); SKIP_CACHE(re, &h->gb, 1);
+ run = SHOW_UBITS(re, &h->gb, 6); SKIP_CACHE(re, &h->gb, 6);
+ level = SHOW_SBITS(re, &h->gb, 8);
+ SKIP_COUNTER(re, &h->gb, 1 + 6 + 8);
}else{
int sign;
- last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1);
+ last = SHOW_UBITS(re, &h->gb, 1); SKIP_BITS(re, &h->gb, 1);
if (!ms->esc3_level_length) {
int ll;
ff_dlog(h->c.avctx, "ESC-3 %X at %d %d\n",
- show_bits(&h->c.gb, 24), h->c.mb_x, h->c.mb_y);
+ show_bits(&h->gb, 24), h->c.mb_x, h->c.mb_y);
if (h->c.qscale < 8) {
- ll = SHOW_UBITS(re, &h->c.gb, 3); SKIP_BITS(re, &h->c.gb, 3);
+ ll = SHOW_UBITS(re, &h->gb, 3); SKIP_BITS(re, &h->gb, 3);
if(ll==0){
- ll = 8+SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1);
+ ll = 8+SHOW_UBITS(re, &h->gb, 1); SKIP_BITS(re, &h->gb, 1);
}
}else{
ll=2;
- while (ll < 8 && SHOW_UBITS(re, &h->c.gb, 1) == 0) {
+ while (ll < 8 && SHOW_UBITS(re, &h->gb, 1) == 0) {
ll++;
- SKIP_BITS(re, &h->c.gb, 1);
+ SKIP_BITS(re, &h->gb, 1);
}
- if (ll<8) SKIP_BITS(re, &h->c.gb, 1);
+ if (ll<8) SKIP_BITS(re, &h->gb, 1);
}
ms->esc3_level_length = ll;
- ms->esc3_run_length = SHOW_UBITS(re, &h->c.gb, 2) + 3; SKIP_BITS(re, &h->c.gb, 2);
- UPDATE_CACHE(re, &h->c.gb);
+ ms->esc3_run_length = SHOW_UBITS(re, &h->gb, 2) + 3; SKIP_BITS(re, &h->gb, 2);
+ UPDATE_CACHE(re, &h->gb);
}
- run = SHOW_UBITS(re, &h->c.gb, ms->esc3_run_length);
- SKIP_BITS(re, &h->c.gb, ms->esc3_run_length);
+ run = SHOW_UBITS(re, &h->gb, ms->esc3_run_length);
+ SKIP_BITS(re, &h->gb, ms->esc3_run_length);
- sign= SHOW_UBITS(re, &h->c.gb, 1);
- SKIP_BITS(re, &h->c.gb, 1);
+ sign= SHOW_UBITS(re, &h->gb, 1);
+ SKIP_BITS(re, &h->gb, 1);
- level = SHOW_UBITS(re, &h->c.gb, ms->esc3_level_length);
- SKIP_BITS(re, &h->c.gb, ms->esc3_level_length);
+ level = SHOW_UBITS(re, &h->gb, ms->esc3_level_length);
+ SKIP_BITS(re, &h->gb, ms->esc3_level_length);
if(sign) level= -level;
}
@@ -783,30 +783,30 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
if(last) i+=192;
} else {
/* second escape */
- SKIP_BITS(re, &h->c.gb, 2);
- GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
+ SKIP_BITS(re, &h->gb, 2);
+ GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
- LAST_SKIP_BITS(re, &h->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
+ LAST_SKIP_BITS(re, &h->gb, 1);
}
} else {
/* first escape */
- SKIP_BITS(re, &h->c.gb, 1);
- GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
+ SKIP_BITS(re, &h->gb, 1);
+ GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
i+= run;
level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
- level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
- LAST_SKIP_BITS(re, &h->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
+ LAST_SKIP_BITS(re, &h->gb, 1);
}
} else {
i+= run;
- level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
- LAST_SKIP_BITS(re, &h->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
+ LAST_SKIP_BITS(re, &h->gb, 1);
}
if (i > 62){
i-= 192;
if(i&(~63)){
- const int left = get_bits_left(&h->c.gb);
+ const int left = get_bits_left(&h->gb);
if (((i + 192 == 64 && level / qmul == -1) ||
!(h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
left >= 0) {
@@ -827,7 +827,7 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
block[scan_table[i]] = level;
}
- CLOSE_READER(re, &h->c.gb);
+ CLOSE_READER(re, &h->gb);
}
if (h->c.mb_intra) {
not_coded:
@@ -844,14 +844,14 @@ void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_pt
H263DecContext *const h = &ms->h;
int sym, mx, my;
- sym = get_vlc2(&h->c.gb, mv_vlc, MV_VLC_BITS, 2);
+ sym = get_vlc2(&h->gb, mv_vlc, MV_VLC_BITS, 2);
if (sym) {
mx = sym >> 8;
my = sym & 0xFF;
} else {
/* Escape */
- mx = get_bits(&h->c.gb, 6);
- my = get_bits(&h->c.gb, 6);
+ mx = get_bits(&h->gb, 6);
+ my = get_bits(&h->gb, 6);
}
mx += *mx_ptr - 32;
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index c678851ded..01cdd1a9dc 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -85,9 +85,9 @@ int ff_rv_decode_dc(H263DecContext *const h, int n)
int code;
if (n < 4) {
- code = get_vlc2(&h->c.gb, rv_dc_lum, DC_VLC_BITS, 2);
+ code = get_vlc2(&h->gb, rv_dc_lum, DC_VLC_BITS, 2);
} else {
- code = get_vlc2(&h->c.gb, rv_dc_chrom, DC_VLC_BITS, 2);
+ code = get_vlc2(&h->gb, rv_dc_chrom, DC_VLC_BITS, 2);
if (code < 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "chroma dc error\n");
return -1;
@@ -101,9 +101,9 @@ static int rv10_decode_picture_header(H263DecContext *const h)
{
int mb_count, pb_frame, marker, mb_xy;
- marker = get_bits1(&h->c.gb);
+ marker = get_bits1(&h->gb);
- if (get_bits1(&h->c.gb))
+ if (get_bits1(&h->gb))
h->c.pict_type = AV_PICTURE_TYPE_P;
else
h->c.pict_type = AV_PICTURE_TYPE_I;
@@ -111,7 +111,7 @@ static int rv10_decode_picture_header(H263DecContext *const h)
if (!marker)
av_log(h->c.avctx, AV_LOG_ERROR, "marker missing\n");
- pb_frame = get_bits1(&h->c.gb);
+ pb_frame = get_bits1(&h->gb);
ff_dlog(h->c.avctx, "pict_type=%d pb_frame=%d\n", h->c.pict_type, pb_frame);
@@ -120,7 +120,7 @@ static int rv10_decode_picture_header(H263DecContext *const h)
return AVERROR_PATCHWELCOME;
}
- h->c.qscale = get_bits(&h->c.gb, 5);
+ h->c.qscale = get_bits(&h->gb, 5);
if (h->c.qscale == 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
return AVERROR_INVALIDDATA;
@@ -129,9 +129,9 @@ static int rv10_decode_picture_header(H263DecContext *const h)
if (h->c.pict_type == AV_PICTURE_TYPE_I) {
if (h->c.rv10_version == 3) {
/* specific MPEG like DC coding not used */
- h->c.last_dc[0] = get_bits(&h->c.gb, 8);
- h->c.last_dc[1] = get_bits(&h->c.gb, 8);
- h->c.last_dc[2] = get_bits(&h->c.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[2] = get_bits(&h->gb, 8);
ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->c.last_dc[0],
h->c.last_dc[1], h->c.last_dc[2]);
}
@@ -140,16 +140,16 @@ static int rv10_decode_picture_header(H263DecContext *const h)
* to display the macroblocks is coded here */
mb_xy = h->c.mb_x + h->c.mb_y * h->c.mb_width;
- if (show_bits(&h->c.gb, 12) == 0 || (mb_xy && mb_xy < h->c.mb_num)) {
- h->c.mb_x = get_bits(&h->c.gb, 6); /* mb_x */
- h->c.mb_y = get_bits(&h->c.gb, 6); /* mb_y */
- mb_count = get_bits(&h->c.gb, 12);
+ if (show_bits(&h->gb, 12) == 0 || (mb_xy && mb_xy < h->c.mb_num)) {
+ h->c.mb_x = get_bits(&h->gb, 6); /* mb_x */
+ h->c.mb_y = get_bits(&h->gb, 6); /* mb_y */
+ mb_count = get_bits(&h->gb, 12);
} else {
h->c.mb_x = 0;
h->c.mb_y = 0;
mb_count = h->c.mb_width * h->c.mb_height;
}
- skip_bits(&h->c.gb, 3); /* ignored */
+ skip_bits(&h->gb, 3); /* ignored */
return mb_count;
}
@@ -163,7 +163,7 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
int seq, mb_pos, ret;
int rpr_max;
- h->c.pict_type = pict_types[get_bits(&h->c.gb, 2)];
+ h->c.pict_type = pict_types[get_bits(&h->gb, 2)];
if (h->c.low_delay && h->c.pict_type == AV_PICTURE_TYPE_B) {
av_log(h->c.avctx, AV_LOG_ERROR, "low delay B\n");
@@ -174,31 +174,31 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
return AVERROR_INVALIDDATA;
}
- if (get_bits1(&h->c.gb)) {
+ if (get_bits1(&h->gb)) {
av_log(h->c.avctx, AV_LOG_ERROR, "reserved bit set\n");
return AVERROR_INVALIDDATA;
}
- h->c.qscale = get_bits(&h->c.gb, 5);
+ h->c.qscale = get_bits(&h->gb, 5);
if (h->c.qscale == 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
return AVERROR_INVALIDDATA;
}
if (RV_GET_MINOR_VER(rv->sub_id) >= 2)
- h->c.loop_filter = get_bits1(&h->c.gb) && !h->c.avctx->lowres;
+ h->c.loop_filter = get_bits1(&h->gb) && !h->c.avctx->lowres;
if (RV_GET_MINOR_VER(rv->sub_id) <= 1)
- seq = get_bits(&h->c.gb, 8) << 7;
+ seq = get_bits(&h->gb, 8) << 7;
else
- seq = get_bits(&h->c.gb, 13) << 2;
+ seq = get_bits(&h->gb, 13) << 2;
rpr_max = h->c.avctx->extradata[1] & 7;
if (rpr_max) {
int f, new_w, new_h;
int rpr_bits = av_log2(rpr_max) + 1;
- f = get_bits(&h->c.gb, rpr_bits);
+ f = get_bits(&h->gb, rpr_bits);
if (f) {
if (h->c.avctx->extradata_size < 8 + 2 * f) {
@@ -277,11 +277,11 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
ff_mpeg4_init_direct_mv(&h->c);
}
- h->c.no_rounding = get_bits1(&h->c.gb);
+ h->c.no_rounding = get_bits1(&h->gb);
if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && h->c.pict_type == AV_PICTURE_TYPE_B)
// binary decoder reads 3+2 bits here but they don't seem to be used
- skip_bits(&h->c.gb, 5);
+ skip_bits(&h->gb, 5);
h->c.h263_aic = h->c.pict_type == AV_PICTURE_TYPE_I;
if (h->c.h263_aic) {
@@ -416,7 +416,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret;
active_bits_size = buf_size * 8;
- init_get_bits(&h->c.gb, buf, FFMAX(buf_size, buf_size2) * 8);
+ init_get_bits(&h->gb, buf, FFMAX(buf_size, buf_size2) * 8);
if (h->c.codec_id == AV_CODEC_ID_RV10)
mb_count = rv10_decode_picture_header(h);
else
@@ -492,24 +492,24 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
// Repeat the slice end check from ff_h263_decode_mb with our active
// bitstream size
- if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->c.gb)) {
- int v = show_bits(&h->c.gb, 16);
+ if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->gb)) {
+ int v = show_bits(&h->gb, 16);
- if (get_bits_count(&h->c.gb) + 16 > active_bits_size)
- v >>= get_bits_count(&h->c.gb) + 16 - active_bits_size;
+ if (get_bits_count(&h->gb) + 16 > active_bits_size)
+ v >>= get_bits_count(&h->gb) + 16 - active_bits_size;
if (!v)
ret = SLICE_END;
}
- if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&h->c.gb) &&
- 8 * buf_size2 >= get_bits_count(&h->c.gb)) {
+ if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&h->gb) &&
+ 8 * buf_size2 >= get_bits_count(&h->gb)) {
active_bits_size = buf_size2 * 8;
av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
8 * buf_size, active_bits_size);
ret = SLICE_OK;
}
- if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->c.gb)) {
+ if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->gb)) {
av_log(h->c.avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", h->c.mb_x,
h->c.mb_y);
return AVERROR_INVALIDDATA;
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index cc4f6d3345..20f96f791b 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -157,8 +157,8 @@ fail:
static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
{
- MpegEncContext *s = avctx->priv_data;
- VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
+ H263DecContext *const h = avctx->priv_data;
+ VAAPIDecodePicture *pic = h->c.cur_pic.ptr->hwaccel_picture_private;
VASliceParameterBufferMPEG4 slice_param;
int err;
@@ -166,9 +166,9 @@ static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer
.slice_data_size = size,
.slice_data_offset = 0,
.slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
- .macroblock_offset = get_bits_count(&s->gb) % 8,
+ .macroblock_offset = get_bits_count(&h->gb) % 8,
.macroblock_number = 0,
- .quant_scale = s->qscale,
+ .quant_scale = h->c.qscale,
};
err = ff_vaapi_decode_make_slice_buffer(avctx, pic,
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 4eb4d00383..4ceae05bdf 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -105,7 +105,7 @@ static int parse_mb_skip(WMV2DecContext *w)
int coded_mb_count = 0;
uint32_t *const mb_type = h->c.cur_pic.mb_type;
- w->skip_type = get_bits(&h->c.gb, 2);
+ w->skip_type = get_bits(&h->gb, 2);
switch (w->skip_type) {
case SKIP_TYPE_NONE:
for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
@@ -114,40 +114,40 @@ static int parse_mb_skip(WMV2DecContext *w)
MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
break;
case SKIP_TYPE_MPEG:
- if (get_bits_left(&h->c.gb) < h->c.mb_height * h->c.mb_width)
+ if (get_bits_left(&h->gb) < h->c.mb_height * h->c.mb_width)
return AVERROR_INVALIDDATA;
for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
mb_type[mb_y * h->c.mb_stride + mb_x] =
- (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ (get_bits1(&h->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
break;
case SKIP_TYPE_ROW:
for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) {
- if (get_bits_left(&h->c.gb) < 1)
+ if (get_bits_left(&h->gb) < 1)
return AVERROR_INVALIDDATA;
- if (get_bits1(&h->c.gb)) {
+ if (get_bits1(&h->gb)) {
for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
mb_type[mb_y * h->c.mb_stride + mb_x] =
MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
} else {
for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
mb_type[mb_y * h->c.mb_stride + mb_x] =
- (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ (get_bits1(&h->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
}
}
break;
case SKIP_TYPE_COL:
for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) {
- if (get_bits_left(&h->c.gb) < 1)
+ if (get_bits_left(&h->gb) < 1)
return AVERROR_INVALIDDATA;
- if (get_bits1(&h->c.gb)) {
+ if (get_bits1(&h->gb)) {
for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
mb_type[mb_y * h->c.mb_stride + mb_x] =
MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
} else {
for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
mb_type[mb_y * h->c.mb_stride + mb_x] =
- (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
+ (get_bits1(&h->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
}
}
break;
@@ -157,7 +157,7 @@ static int parse_mb_skip(WMV2DecContext *w)
for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
coded_mb_count += !IS_SKIP(mb_type[mb_y * h->c.mb_stride + mb_x]);
- if (coded_mb_count > get_bits_left(&h->c.gb))
+ if (coded_mb_count > get_bits_left(&h->gb))
return AVERROR_INVALIDDATA;
return 0;
@@ -205,17 +205,17 @@ int ff_wmv2_decode_picture_header(H263DecContext *const h)
{
int code;
- h->c.pict_type = get_bits1(&h->c.gb) + 1;
+ h->c.pict_type = get_bits1(&h->gb) + 1;
if (h->c.pict_type == AV_PICTURE_TYPE_I) {
- code = get_bits(&h->c.gb, 7);
+ code = get_bits(&h->gb, 7);
av_log(h->c.avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
}
- h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
if (h->c.qscale <= 0)
return AVERROR_INVALIDDATA;
- if (h->c.pict_type != AV_PICTURE_TYPE_I && show_bits(&h->c.gb, 1)) {
- GetBitContext gb = h->c.gb;
+ if (h->c.pict_type != AV_PICTURE_TYPE_I && show_bits(&h->gb, 1)) {
+ GetBitContext gb = h->gb;
int skip_type = get_bits(&gb, 2);
int run = skip_type == SKIP_TYPE_COL ? h->c.mb_width : h->c.mb_height;
@@ -241,29 +241,29 @@ int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)
memset(h->c.cur_pic.mb_type, 0,
sizeof(*h->c.cur_pic.mb_type) * h->c.mb_height * h->c.mb_stride);
if (w->j_type_bit)
- w->j_type = get_bits1(&h->c.gb);
+ w->j_type = get_bits1(&h->gb);
else
w->j_type = 0; // FIXME check
if (!w->j_type) {
if (w->per_mb_rl_bit)
- w->ms.per_mb_rl_table = get_bits1(&h->c.gb);
+ w->ms.per_mb_rl_table = get_bits1(&h->gb);
else
w->ms.per_mb_rl_table = 0;
if (!w->ms.per_mb_rl_table) {
- w->ms.rl_chroma_table_index = decode012(&h->c.gb);
- w->ms.rl_table_index = decode012(&h->c.gb);
+ w->ms.rl_chroma_table_index = decode012(&h->gb);
+ w->ms.rl_table_index = decode012(&h->gb);
}
- w->ms.dc_table_index = get_bits1(&h->c.gb);
+ w->ms.dc_table_index = get_bits1(&h->gb);
// at minimum one bit per macroblock is required at least in a valid frame,
// we discard frames much smaller than this. Frames smaller than 1/8 of the
// smallest "black/skip" frame generally contain not much recoverable content
// while at the same time they have the highest computational requirements
// per byte
- if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
+ if (get_bits_left(&h->gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
return AVERROR_INVALIDDATA;
}
h->c.inter_intra_pred = 0;
@@ -282,35 +282,35 @@ int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)
ret = parse_mb_skip(w);
if (ret < 0)
return ret;
- cbp_index = decode012(&h->c.gb);
+ cbp_index = decode012(&h->gb);
w->cbp_table_index = wmv2_get_cbp_table_index(h->c.qscale, cbp_index);
if (w->mspel_bit)
- h->c.mspel = get_bits1(&h->c.gb);
+ h->c.mspel = get_bits1(&h->gb);
else
h->c.mspel = 0; // FIXME check
if (w->abt_flag) {
- w->per_mb_abt = get_bits1(&h->c.gb) ^ 1;
+ w->per_mb_abt = get_bits1(&h->gb) ^ 1;
if (!w->per_mb_abt)
- w->abt_type = decode012(&h->c.gb);
+ w->abt_type = decode012(&h->gb);
}
if (w->per_mb_rl_bit)
- w->ms.per_mb_rl_table = get_bits1(&h->c.gb);
+ w->ms.per_mb_rl_table = get_bits1(&h->gb);
else
w->ms.per_mb_rl_table = 0;
if (!w->ms.per_mb_rl_table) {
- w->ms.rl_table_index = decode012(&h->c.gb);
+ w->ms.rl_table_index = decode012(&h->gb);
w->ms.rl_chroma_table_index = w->ms.rl_table_index;
}
- if (get_bits_left(&h->c.gb) < 2)
+ if (get_bits_left(&h->gb) < 2)
return AVERROR_INVALIDDATA;
- w->ms.dc_table_index = get_bits1(&h->c.gb);
- w->ms.mv_table_index = get_bits1(&h->c.gb);
+ w->ms.dc_table_index = get_bits1(&h->gb);
+ w->ms.mv_table_index = get_bits1(&h->gb);
h->c.inter_intra_pred = 0; // (h->c.width * h->c.height < 320 * 240 && w->ms.bit_rate <= II_BITRATE);
h->c.no_rounding ^= 1;
@@ -331,7 +331,7 @@ int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)
if (w->j_type) {
ff_intrax8_decode_picture(&w->x8, h->c.cur_pic.ptr,
- &h->c.gb, &h->c.mb_x, &h->c.mb_y,
+ &h->gb, &h->c.mb_x, &h->c.mb_y,
2 * h->c.qscale, (h->c.qscale - 1) | 1,
h->c.loop_filter, h->c.low_delay);
@@ -351,7 +351,7 @@ static inline void wmv2_decode_motion(WMV2DecContext *w, int *mx_ptr, int *my_pt
ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr);
if ((((*mx_ptr) | (*my_ptr)) & 1) && h->c.mspel)
- w->common.hshift = get_bits1(&h->c.gb);
+ w->common.hshift = get_bits1(&h->gb);
else
w->common.hshift = 0;
}
@@ -376,7 +376,7 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py)
diff = 0;
if (diff >= 8)
- type = get_bits1(&h->c.gb);
+ type = get_bits1(&h->gb);
else
type = 2;
@@ -413,13 +413,13 @@ static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block,
}
if (w->per_block_abt)
- w->abt_type = decode012(&h->c.gb);
+ w->abt_type = decode012(&h->gb);
w->abt_type_table[n] = w->abt_type;
if (w->abt_type) {
const uint8_t *scantable = w->abt_type == 1 ? ff_wmv2_scantableA : ff_wmv2_scantableB;
- sub_cbp = sub_cbp_table[decode012(&h->c.gb)];
+ sub_cbp = sub_cbp_table[decode012(&h->gb)];
if (sub_cbp & 1) {
ret = ff_msmpeg4_decode_block(&w->ms, block, n, 1, scantable);
@@ -468,19 +468,19 @@ static int wmv2_decode_mb(H263DecContext *const h)
w->common.hshift = 0;
return 0;
}
- if (get_bits_left(&h->c.gb) <= 0)
+ if (get_bits_left(&h->gb) <= 0)
return AVERROR_INVALIDDATA;
- code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[w->cbp_table_index],
+ code = get_vlc2(&h->gb, ff_mb_non_intra_vlc[w->cbp_table_index],
MB_NON_INTRA_VLC_BITS, 3);
h->c.mb_intra = (~code & 0x40) >> 6;
cbp = code & 0x3f;
} else {
h->c.mb_intra = 1;
- if (get_bits_left(&h->c.gb) <= 0)
+ if (get_bits_left(&h->gb) <= 0)
return AVERROR_INVALIDDATA;
- code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc,
+ code = get_vlc2(&h->gb, ff_msmp4_mb_i_vlc,
MSMP4_MB_INTRA_VLC_BITS, 2);
/* predict coded block pattern */
cbp = 0;
@@ -502,14 +502,14 @@ static int wmv2_decode_mb(H263DecContext *const h)
if (cbp) {
h->c.bdsp.clear_blocks(h->block[0]);
if (ms->per_mb_rl_table) {
- ms->rl_table_index = decode012(&h->c.gb);
+ ms->rl_table_index = decode012(&h->gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
if (w->abt_flag && w->per_mb_abt) {
- w->per_block_abt = get_bits1(&h->c.gb);
+ w->per_block_abt = get_bits1(&h->gb);
if (!w->per_block_abt)
- w->abt_type = decode012(&h->c.gb);
+ w->abt_type = decode012(&h->gb);
} else
w->per_block_abt = 0;
}
@@ -534,16 +534,16 @@ static int wmv2_decode_mb(H263DecContext *const h)
ff_dlog(h->c.avctx, "%d%d ", h->c.inter_intra_pred, cbp);
ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0),
- show_bits(&h->c.gb, 24));
- h->c.ac_pred = get_bits1(&h->c.gb);
+ show_bits(&h->gb, 24));
+ h->c.ac_pred = get_bits1(&h->gb);
if (h->c.inter_intra_pred) {
- h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc,
+ h->c.h263_aic_dir = get_vlc2(&h->gb, ff_inter_intra_vlc,
INTER_INTRA_VLC_BITS, 1);
ff_dlog(h->c.avctx, "%d%d %d %d/",
h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
}
if (ms->per_mb_rl_table && cbp) {
- ms->rl_table_index = decode012(&h->c.gb);
+ ms->rl_table_index = decode012(&h->gb);
ms->rl_chroma_table_index = ms->rl_table_index;
}
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 30/48] avcodec/mpeg12dec: Add Mpeg12SliceContext
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (28 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 29/48] avcodec/h263dec: Stop using MpegEncContext.gb Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 31/48] avcodec/mpegvideo: Add missing headers Andreas Rheinhardt
` (17 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is in preparation for removing the GetBitContext
from MPVContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 863 +++++++++++++++++++++--------------------
libavcodec/mpegvideo.c | 2 +-
libavcodec/mpegvideo.h | 1 +
3 files changed, 436 insertions(+), 430 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 15bfab9623..1ef581ff99 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -70,8 +70,12 @@ enum Mpeg2ClosedCaptionsFormat {
CC_FORMAT_DISH
};
+typedef struct Mpeg12SliceContext {
+ MPVContext c;
+} Mpeg12SliceContext;
+
typedef struct Mpeg1Context {
- MpegEncContext mpeg_enc_ctx;
+ Mpeg12SliceContext slice;
AVPanScan pan_scan; /* some temporary storage for the panscan */
enum AVStereo3DType stereo3d_type;
int has_stereo3d;
@@ -95,22 +99,22 @@ typedef struct Mpeg1Context {
} Mpeg1Context;
/* as H.263, but only 17 codes */
-static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
+static int mpeg_decode_motion(Mpeg12SliceContext *const s, int fcode, int pred)
{
int code, sign, val, shift;
- code = get_vlc2(&s->gb, ff_mv_vlc, MV_VLC_BITS, 2);
+ code = get_vlc2(&s->c.gb, ff_mv_vlc, MV_VLC_BITS, 2);
if (code == 0)
return pred;
if (code < 0)
return 0xffff;
- sign = get_bits1(&s->gb);
+ sign = get_bits1(&s->c.gb);
shift = fcode - 1;
val = code;
if (shift) {
val = (val - 1) << shift;
- val |= get_bits(&s->gb, shift);
+ val |= get_bits(&s->c.gb, shift);
val++;
}
if (sign)
@@ -125,39 +129,39 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
#define check_scantable_index(ctx, x) \
do { \
if ((x) > MAX_INDEX) { \
- av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
- ctx->mb_x, ctx->mb_y); \
+ av_log(ctx->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
+ ctx->c.mb_x, ctx->c.mb_y); \
return AVERROR_INVALIDDATA; \
} \
} while (0)
-static inline int mpeg1_decode_block_inter(MpegEncContext *s,
+static inline int mpeg1_decode_block_inter(Mpeg12SliceContext *const s,
int16_t *block, int n)
{
int level, i, j, run;
- const uint8_t *const scantable = s->intra_scantable.permutated;
- const uint16_t *quant_matrix = s->inter_matrix;
- const int qscale = s->qscale;
+ const uint8_t *const scantable = s->c.intra_scantable.permutated;
+ const uint16_t *quant_matrix = s->c.inter_matrix;
+ const int qscale = s->c.qscale;
{
- OPEN_READER(re, &s->gb);
+ OPEN_READER(re, &s->c.gb);
i = -1;
// special case for first coefficient, no need to add second VLC table
- UPDATE_CACHE(re, &s->gb);
- if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
+ UPDATE_CACHE(re, &s->c.gb);
+ if (((int32_t) GET_CACHE(re, &s->c.gb)) < 0) {
level = (3 * qscale * quant_matrix[0]) >> 5;
level = (level - 1) | 1;
- if (GET_CACHE(re, &s->gb) & 0x40000000)
+ if (GET_CACHE(re, &s->c.gb) & 0x40000000)
level = -level;
block[0] = level;
i++;
- SKIP_BITS(re, &s->gb, 2);
- if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
+ SKIP_BITS(re, &s->c.gb, 2);
+ if (((int32_t) GET_CACHE(re, &s->c.gb)) <= (int32_t) 0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
for (;;) {
- GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc,
+ GET_RL_VLC(level, run, re, &s->c.gb, ff_mpeg1_rl_vlc,
TEX_VLC_BITS, 2, 0);
if (level != 0) {
@@ -167,22 +171,22 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s,
j = scantable[i];
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = (level - 1) | 1;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
- SHOW_SBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &s->c.gb, 1)) -
+ SHOW_SBITS(re, &s->c.gb, 1);
+ SKIP_BITS(re, &s->c.gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6) + 1;
- LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 8);
- SKIP_BITS(re, &s->gb, 8);
+ run = SHOW_UBITS(re, &s->c.gb, 6) + 1;
+ LAST_SKIP_BITS(re, &s->c.gb, 6);
+ UPDATE_CACHE(re, &s->c.gb);
+ level = SHOW_SBITS(re, &s->c.gb, 8);
+ SKIP_BITS(re, &s->c.gb, 8);
if (level == -128) {
- level = SHOW_UBITS(re, &s->gb, 8) - 256;
- SKIP_BITS(re, &s->gb, 8);
+ level = SHOW_UBITS(re, &s->c.gb, 8) - 256;
+ SKIP_BITS(re, &s->c.gb, 8);
} else if (level == 0) {
- level = SHOW_UBITS(re, &s->gb, 8);
- SKIP_BITS(re, &s->gb, 8);
+ level = SHOW_UBITS(re, &s->c.gb, 8);
+ SKIP_BITS(re, &s->c.gb, 8);
}
i += run;
if (i > MAX_INDEX)
@@ -200,57 +204,57 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s,
}
block[j] = level;
- if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
+ if (((int32_t) GET_CACHE(re, &s->c.gb)) <= (int32_t) 0xBFFFFFFF)
break;
- UPDATE_CACHE(re, &s->gb);
+ UPDATE_CACHE(re, &s->c.gb);
}
end:
- LAST_SKIP_BITS(re, &s->gb, 2);
- CLOSE_READER(re, &s->gb);
+ LAST_SKIP_BITS(re, &s->c.gb, 2);
+ CLOSE_READER(re, &s->c.gb);
}
check_scantable_index(s, i);
- s->block_last_index[n] = i;
+ s->c.block_last_index[n] = i;
return 0;
}
-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
+static inline int mpeg2_decode_block_non_intra(Mpeg12SliceContext *const s,
int16_t *block, int n)
{
int level, i, j, run;
- const uint8_t *const scantable = s->intra_scantable.permutated;
+ const uint8_t *const scantable = s->c.intra_scantable.permutated;
const uint16_t *quant_matrix;
- const int qscale = s->qscale;
+ const int qscale = s->c.qscale;
int mismatch;
mismatch = 1;
{
- OPEN_READER(re, &s->gb);
+ OPEN_READER(re, &s->c.gb);
i = -1;
if (n < 4)
- quant_matrix = s->inter_matrix;
+ quant_matrix = s->c.inter_matrix;
else
- quant_matrix = s->chroma_inter_matrix;
+ quant_matrix = s->c.chroma_inter_matrix;
// Special case for first coefficient, no need to add second VLC table.
- UPDATE_CACHE(re, &s->gb);
- if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
+ UPDATE_CACHE(re, &s->c.gb);
+ if (((int32_t) GET_CACHE(re, &s->c.gb)) < 0) {
level = (3 * qscale * quant_matrix[0]) >> 5;
- if (GET_CACHE(re, &s->gb) & 0x40000000)
+ if (GET_CACHE(re, &s->c.gb) & 0x40000000)
level = -level;
block[0] = level;
mismatch ^= level;
i++;
- SKIP_BITS(re, &s->gb, 2);
- if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
+ SKIP_BITS(re, &s->c.gb, 2);
+ if (((int32_t) GET_CACHE(re, &s->c.gb)) <= (int32_t) 0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
for (;;) {
- GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc,
+ GET_RL_VLC(level, run, re, &s->c.gb, ff_mpeg1_rl_vlc,
TEX_VLC_BITS, 2, 0);
if (level != 0) {
@@ -259,16 +263,16 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
break;
j = scantable[i];
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
- SHOW_SBITS(re, &s->gb, 1);
- SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &s->c.gb, 1)) -
+ SHOW_SBITS(re, &s->c.gb, 1);
+ SKIP_BITS(re, &s->c.gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6) + 1;
- LAST_SKIP_BITS(re, &s->gb, 6);
- UPDATE_CACHE(re, &s->gb);
- level = SHOW_SBITS(re, &s->gb, 12);
- SKIP_BITS(re, &s->gb, 12);
+ run = SHOW_UBITS(re, &s->c.gb, 6) + 1;
+ LAST_SKIP_BITS(re, &s->c.gb, 6);
+ UPDATE_CACHE(re, &s->c.gb);
+ level = SHOW_SBITS(re, &s->c.gb, 12);
+ SKIP_BITS(re, &s->c.gb, 12);
i += run;
if (i > MAX_INDEX)
@@ -284,60 +288,60 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
mismatch ^= level;
block[j] = level;
- if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
+ if (((int32_t) GET_CACHE(re, &s->c.gb)) <= (int32_t) 0xBFFFFFFF)
break;
- UPDATE_CACHE(re, &s->gb);
+ UPDATE_CACHE(re, &s->c.gb);
}
end:
- LAST_SKIP_BITS(re, &s->gb, 2);
- CLOSE_READER(re, &s->gb);
+ LAST_SKIP_BITS(re, &s->c.gb, 2);
+ CLOSE_READER(re, &s->c.gb);
}
block[63] ^= (mismatch & 1);
check_scantable_index(s, i);
- s->block_last_index[n] = i;
+ s->c.block_last_index[n] = i;
return 0;
}
-static inline int mpeg2_decode_block_intra(MpegEncContext *s,
+static inline int mpeg2_decode_block_intra(Mpeg12SliceContext *const s,
int16_t *block, int n)
{
int level, dc, diff, i, j, run;
int component;
const RL_VLC_ELEM *rl_vlc;
- const uint8_t *const scantable = s->intra_scantable.permutated;
+ const uint8_t *const scantable = s->c.intra_scantable.permutated;
const uint16_t *quant_matrix;
- const int qscale = s->qscale;
+ const int qscale = s->c.qscale;
int mismatch;
/* DC coefficient */
if (n < 4) {
- quant_matrix = s->intra_matrix;
+ quant_matrix = s->c.intra_matrix;
component = 0;
} else {
- quant_matrix = s->chroma_intra_matrix;
+ quant_matrix = s->c.chroma_intra_matrix;
component = (n & 1) + 1;
}
- diff = decode_dc(&s->gb, component);
- dc = s->last_dc[component];
+ diff = decode_dc(&s->c.gb, component);
+ dc = s->c.last_dc[component];
dc += diff;
- s->last_dc[component] = dc;
- block[0] = dc * (1 << (3 - s->intra_dc_precision));
- ff_tlog(s->avctx, "dc=%d\n", block[0]);
+ s->c.last_dc[component] = dc;
+ block[0] = dc * (1 << (3 - s->c.intra_dc_precision));
+ ff_tlog(s->c.avctx, "dc=%d\n", block[0]);
mismatch = block[0] ^ 1;
i = 0;
- if (s->intra_vlc_format)
+ if (s->c.intra_vlc_format)
rl_vlc = ff_mpeg2_rl_vlc;
else
rl_vlc = ff_mpeg1_rl_vlc;
{
- OPEN_READER(re, &s->gb);
+ OPEN_READER(re, &s->c.gb);
/* now quantify & encode AC coefficients */
for (;;) {
- UPDATE_CACHE(re, &s->gb);
- GET_RL_VLC(level, run, re, &s->gb, rl_vlc,
+ UPDATE_CACHE(re, &s->c.gb);
+ GET_RL_VLC(level, run, re, &s->c.gb, rl_vlc,
TEX_VLC_BITS, 2, 0);
if (level == 127) {
@@ -348,15 +352,15 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s,
break;
j = scantable[i];
level = (level * qscale * quant_matrix[j]) >> 4;
- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
- SHOW_SBITS(re, &s->gb, 1);
- LAST_SKIP_BITS(re, &s->gb, 1);
+ level = (level ^ SHOW_SBITS(re, &s->c.gb, 1)) -
+ SHOW_SBITS(re, &s->c.gb, 1);
+ LAST_SKIP_BITS(re, &s->c.gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->gb, 6) + 1;
- SKIP_BITS(re, &s->gb, 6);
- level = SHOW_SBITS(re, &s->gb, 12);
- LAST_SKIP_BITS(re, &s->gb, 12);
+ run = SHOW_UBITS(re, &s->c.gb, 6) + 1;
+ SKIP_BITS(re, &s->c.gb, 6);
+ level = SHOW_SBITS(re, &s->c.gb, 12);
+ LAST_SKIP_BITS(re, &s->c.gb, 12);
i += run;
if (i > MAX_INDEX)
break;
@@ -372,7 +376,7 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s,
mismatch ^= level;
block[j] = level;
}
- CLOSE_READER(re, &s->gb);
+ CLOSE_READER(re, &s->c.gb);
}
block[63] ^= mismatch & 1;
@@ -381,10 +385,10 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s,
return 0;
}
-static inline int get_dmv(MpegEncContext *s)
+static inline int get_dmv(Mpeg12SliceContext *const s)
{
- if (get_bits1(&s->gb))
- return 1 - (get_bits1(&s->gb) << 1);
+ if (get_bits1(&s->c.gb))
+ return 1 - (get_bits1(&s->c.gb) << 1);
else
return 0;
}
@@ -395,51 +399,51 @@ static inline int get_dmv(MpegEncContext *s)
#define MT_16X8 2
#define MT_DMV 3
-static int mpeg_decode_mb(MPVContext *const s)
+static int mpeg_decode_mb(Mpeg12SliceContext *const s)
{
int i, j, k, cbp, val, mb_type, motion_type;
- const int mb_block_count = 4 + (1 << s->chroma_format);
+ const int mb_block_count = 4 + (1 << s->c.chroma_format);
int ret;
- ff_tlog(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
+ ff_tlog(s->c.avctx, "decode_mb: x=%d y=%d\n", s->c.mb_x, s->c.mb_y);
- av_assert2(s->mb_skipped == 0);
+ av_assert2(s->c.mb_skipped == 0);
- if (s->mb_skip_run-- != 0) {
- if (s->pict_type == AV_PICTURE_TYPE_P) {
- s->mb_skipped = 1;
- s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
+ if (s->c.mb_skip_run-- != 0) {
+ if (s->c.pict_type == AV_PICTURE_TYPE_P) {
+ s->c.mb_skipped = 1;
+ s->c.cur_pic.mb_type[s->c.mb_x + s->c.mb_y * s->c.mb_stride] =
MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
} else {
int mb_type;
- if (s->mb_x)
- mb_type = s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride - 1];
+ if (s->c.mb_x)
+ mb_type = s->c.cur_pic.mb_type[s->c.mb_x + s->c.mb_y * s->c.mb_stride - 1];
else
// FIXME not sure if this is allowed in MPEG at all
- mb_type = s->cur_pic.mb_type[s->mb_width + (s->mb_y - 1) * s->mb_stride - 1];
+ mb_type = s->c.cur_pic.mb_type[s->c.mb_width + (s->c.mb_y - 1) * s->c.mb_stride - 1];
if (IS_INTRA(mb_type)) {
- av_log(s->avctx, AV_LOG_ERROR, "skip with previntra\n");
+ av_log(s->c.avctx, AV_LOG_ERROR, "skip with previntra\n");
return AVERROR_INVALIDDATA;
}
- s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
+ s->c.cur_pic.mb_type[s->c.mb_x + s->c.mb_y * s->c.mb_stride] =
mb_type | MB_TYPE_SKIP;
- if ((s->mv[0][0][0] | s->mv[0][0][1] | s->mv[1][0][0] | s->mv[1][0][1]) == 0)
- s->mb_skipped = 1;
+ if ((s->c.mv[0][0][0] | s->c.mv[0][0][1] | s->c.mv[1][0][0] | s->c.mv[1][0][1]) == 0)
+ s->c.mb_skipped = 1;
}
return 0;
}
- switch (s->pict_type) {
+ switch (s->c.pict_type) {
default:
case AV_PICTURE_TYPE_I:
- if (get_bits1(&s->gb) == 0) {
- if (get_bits1(&s->gb) == 0) {
- av_log(s->avctx, AV_LOG_ERROR,
+ if (get_bits1(&s->c.gb) == 0) {
+ if (get_bits1(&s->c.gb) == 0) {
+ av_log(s->c.avctx, AV_LOG_ERROR,
"Invalid mb type in I-frame at %d %d\n",
- s->mb_x, s->mb_y);
+ s->c.mb_x, s->c.mb_y);
return AVERROR_INVALIDDATA;
}
mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA;
@@ -448,74 +452,74 @@ static int mpeg_decode_mb(MPVContext *const s)
}
break;
case AV_PICTURE_TYPE_P:
- mb_type = get_vlc2(&s->gb, ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 1);
+ mb_type = get_vlc2(&s->c.gb, ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 1);
if (mb_type < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Invalid mb type in P-frame at %d %d\n", s->mb_x, s->mb_y);
+ av_log(s->c.avctx, AV_LOG_ERROR,
+ "Invalid mb type in P-frame at %d %d\n", s->c.mb_x, s->c.mb_y);
return AVERROR_INVALIDDATA;
}
break;
case AV_PICTURE_TYPE_B:
- mb_type = get_vlc2(&s->gb, ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 1);
+ mb_type = get_vlc2(&s->c.gb, ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 1);
if (mb_type < 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "Invalid mb type in B-frame at %d %d\n", s->mb_x, s->mb_y);
+ av_log(s->c.avctx, AV_LOG_ERROR,
+ "Invalid mb type in B-frame at %d %d\n", s->c.mb_x, s->c.mb_y);
return AVERROR_INVALIDDATA;
}
break;
}
- ff_tlog(s->avctx, "mb_type=%x\n", mb_type);
+ ff_tlog(s->c.avctx, "mb_type=%x\n", mb_type);
// motion_type = 0; /* avoid warning */
if (IS_INTRA(mb_type)) {
- s->bdsp.clear_blocks(s->block[0]);
+ s->c.bdsp.clear_blocks(s->c.block[0]);
- if (!s->chroma_y_shift)
- s->bdsp.clear_blocks(s->block[6]);
+ if (!s->c.chroma_y_shift)
+ s->c.bdsp.clear_blocks(s->c.block[6]);
/* compute DCT type */
// FIXME: add an interlaced_dct coded var?
- if (s->picture_structure == PICT_FRAME &&
- !s->frame_pred_frame_dct)
- s->interlaced_dct = get_bits1(&s->gb);
+ if (s->c.picture_structure == PICT_FRAME &&
+ !s->c.frame_pred_frame_dct)
+ s->c.interlaced_dct = get_bits1(&s->c.gb);
if (IS_QUANT(mb_type))
- s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
+ s->c.qscale = mpeg_get_qscale(&s->c.gb, s->c.q_scale_type);
- if (s->concealment_motion_vectors) {
+ if (s->c.concealment_motion_vectors) {
/* just parse them */
- if (s->picture_structure != PICT_FRAME)
- skip_bits1(&s->gb); /* field select */
-
- s->mv[0][0][0] =
- s->last_mv[0][0][0] =
- s->last_mv[0][1][0] = mpeg_decode_motion(s, s->mpeg_f_code[0][0],
- s->last_mv[0][0][0]);
- s->mv[0][0][1] =
- s->last_mv[0][0][1] =
- s->last_mv[0][1][1] = mpeg_decode_motion(s, s->mpeg_f_code[0][1],
- s->last_mv[0][0][1]);
-
- check_marker(s->avctx, &s->gb, "after concealment_motion_vectors");
+ if (s->c.picture_structure != PICT_FRAME)
+ skip_bits1(&s->c.gb); /* field select */
+
+ s->c.mv[0][0][0] =
+ s->c.last_mv[0][0][0] =
+ s->c.last_mv[0][1][0] = mpeg_decode_motion(s, s->c.mpeg_f_code[0][0],
+ s->c.last_mv[0][0][0]);
+ s->c.mv[0][0][1] =
+ s->c.last_mv[0][0][1] =
+ s->c.last_mv[0][1][1] = mpeg_decode_motion(s, s->c.mpeg_f_code[0][1],
+ s->c.last_mv[0][0][1]);
+
+ check_marker(s->c.avctx, &s->c.gb, "after concealment_motion_vectors");
} else {
/* reset mv prediction */
- memset(s->last_mv, 0, sizeof(s->last_mv));
+ memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
}
- s->mb_intra = 1;
+ s->c.mb_intra = 1;
- if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+ if (s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO) {
for (i = 0; i < mb_block_count; i++)
- if ((ret = mpeg2_decode_block_intra(s, s->block[i], i)) < 0)
+ if ((ret = mpeg2_decode_block_intra(s, s->c.block[i], i)) < 0)
return ret;
} else {
for (i = 0; i < 6; i++) {
- ret = ff_mpeg1_decode_block_intra(&s->gb,
- s->intra_matrix,
- s->intra_scantable.permutated,
- s->last_dc, s->block[i],
- i, s->qscale);
+ ret = ff_mpeg1_decode_block_intra(&s->c.gb,
+ s->c.intra_matrix,
+ s->c.intra_scantable.permutated,
+ s->c.last_dc, s->c.block[i],
+ i, s->c.qscale);
if (ret < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
- s->mb_x, s->mb_y);
+ av_log(s->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
+ s->c.mb_x, s->c.mb_y);
return ret;
}
}
@@ -524,83 +528,83 @@ static int mpeg_decode_mb(MPVContext *const s)
if (mb_type & MB_TYPE_ZERO_MV) {
av_assert2(mb_type & MB_TYPE_CBP);
- s->mv_dir = MV_DIR_FORWARD;
- if (s->picture_structure == PICT_FRAME) {
- if (s->picture_structure == PICT_FRAME
- && !s->frame_pred_frame_dct)
- s->interlaced_dct = get_bits1(&s->gb);
- s->mv_type = MV_TYPE_16X16;
+ s->c.mv_dir = MV_DIR_FORWARD;
+ if (s->c.picture_structure == PICT_FRAME) {
+ if (s->c.picture_structure == PICT_FRAME
+ && !s->c.frame_pred_frame_dct)
+ s->c.interlaced_dct = get_bits1(&s->c.gb);
+ s->c.mv_type = MV_TYPE_16X16;
} else {
- s->mv_type = MV_TYPE_FIELD;
+ s->c.mv_type = MV_TYPE_FIELD;
mb_type |= MB_TYPE_INTERLACED;
- s->field_select[0][0] = s->picture_structure - 1;
+ s->c.field_select[0][0] = s->c.picture_structure - 1;
}
if (IS_QUANT(mb_type))
- s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
-
- s->last_mv[0][0][0] = 0;
- s->last_mv[0][0][1] = 0;
- s->last_mv[0][1][0] = 0;
- s->last_mv[0][1][1] = 0;
- s->mv[0][0][0] = 0;
- s->mv[0][0][1] = 0;
+ s->c.qscale = mpeg_get_qscale(&s->c.gb, s->c.q_scale_type);
+
+ s->c.last_mv[0][0][0] = 0;
+ s->c.last_mv[0][0][1] = 0;
+ s->c.last_mv[0][1][0] = 0;
+ s->c.last_mv[0][1][1] = 0;
+ s->c.mv[0][0][0] = 0;
+ s->c.mv[0][0][1] = 0;
} else {
av_assert2(mb_type & MB_TYPE_BIDIR_MV);
// FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED
/* get additional motion vector type */
- if (s->picture_structure == PICT_FRAME && s->frame_pred_frame_dct) {
+ if (s->c.picture_structure == PICT_FRAME && s->c.frame_pred_frame_dct) {
motion_type = MT_FRAME;
} else {
- motion_type = get_bits(&s->gb, 2);
- if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type))
- s->interlaced_dct = get_bits1(&s->gb);
+ motion_type = get_bits(&s->c.gb, 2);
+ if (s->c.picture_structure == PICT_FRAME && HAS_CBP(mb_type))
+ s->c.interlaced_dct = get_bits1(&s->c.gb);
}
if (IS_QUANT(mb_type))
- s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
+ s->c.qscale = mpeg_get_qscale(&s->c.gb, s->c.q_scale_type);
/* motion vectors */
- s->mv_dir = MB_TYPE_MV_2_MV_DIR(mb_type);
- ff_tlog(s->avctx, "motion_type=%d\n", motion_type);
+ s->c.mv_dir = MB_TYPE_MV_2_MV_DIR(mb_type);
+ ff_tlog(s->c.avctx, "motion_type=%d\n", motion_type);
switch (motion_type) {
case MT_FRAME: /* or MT_16X8 */
- if (s->picture_structure == PICT_FRAME) {
+ if (s->c.picture_structure == PICT_FRAME) {
mb_type |= MB_TYPE_16x16;
- s->mv_type = MV_TYPE_16X16;
+ s->c.mv_type = MV_TYPE_16X16;
for (i = 0; i < 2; i++) {
if (HAS_MV(mb_type, i)) {
/* MT_FRAME */
- s->mv[i][0][0] =
- s->last_mv[i][0][0] =
- s->last_mv[i][1][0] =
- mpeg_decode_motion(s, s->mpeg_f_code[i][0],
- s->last_mv[i][0][0]);
- s->mv[i][0][1] =
- s->last_mv[i][0][1] =
- s->last_mv[i][1][1] =
- mpeg_decode_motion(s, s->mpeg_f_code[i][1],
- s->last_mv[i][0][1]);
+ s->c.mv[i][0][0] =
+ s->c.last_mv[i][0][0] =
+ s->c.last_mv[i][1][0] =
+ mpeg_decode_motion(s, s->c.mpeg_f_code[i][0],
+ s->c.last_mv[i][0][0]);
+ s->c.mv[i][0][1] =
+ s->c.last_mv[i][0][1] =
+ s->c.last_mv[i][1][1] =
+ mpeg_decode_motion(s, s->c.mpeg_f_code[i][1],
+ s->c.last_mv[i][0][1]);
/* full_pel: only for MPEG-1 */
- if (s->full_pel[i]) {
- s->mv[i][0][0] *= 2;
- s->mv[i][0][1] *= 2;
+ if (s->c.full_pel[i]) {
+ s->c.mv[i][0][0] *= 2;
+ s->c.mv[i][0][1] *= 2;
}
}
}
} else {
mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
- s->mv_type = MV_TYPE_16X8;
+ s->c.mv_type = MV_TYPE_16X8;
for (i = 0; i < 2; i++) {
if (HAS_MV(mb_type, i)) {
/* MT_16X8 */
for (j = 0; j < 2; j++) {
- s->field_select[i][j] = get_bits1(&s->gb);
+ s->c.field_select[i][j] = get_bits1(&s->c.gb);
for (k = 0; k < 2; k++) {
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
- s->last_mv[i][j][k]);
- s->last_mv[i][j][k] = val;
- s->mv[i][j][k] = val;
+ val = mpeg_decode_motion(s, s->c.mpeg_f_code[i][k],
+ s->c.last_mv[i][j][k]);
+ s->c.last_mv[i][j][k] = val;
+ s->c.mv[i][j][k] = val;
}
}
}
@@ -608,151 +612,151 @@ static int mpeg_decode_mb(MPVContext *const s)
}
break;
case MT_FIELD:
- s->mv_type = MV_TYPE_FIELD;
- if (s->picture_structure == PICT_FRAME) {
+ s->c.mv_type = MV_TYPE_FIELD;
+ if (s->c.picture_structure == PICT_FRAME) {
mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
for (i = 0; i < 2; i++) {
if (HAS_MV(mb_type, i)) {
for (j = 0; j < 2; j++) {
- s->field_select[i][j] = get_bits1(&s->gb);
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
- s->last_mv[i][j][0]);
- s->last_mv[i][j][0] = val;
- s->mv[i][j][0] = val;
- ff_tlog(s->avctx, "fmx=%d\n", val);
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
- s->last_mv[i][j][1] >> 1);
- s->last_mv[i][j][1] = 2 * val;
- s->mv[i][j][1] = val;
- ff_tlog(s->avctx, "fmy=%d\n", val);
+ s->c.field_select[i][j] = get_bits1(&s->c.gb);
+ val = mpeg_decode_motion(s, s->c.mpeg_f_code[i][0],
+ s->c.last_mv[i][j][0]);
+ s->c.last_mv[i][j][0] = val;
+ s->c.mv[i][j][0] = val;
+ ff_tlog(s->c.avctx, "fmx=%d\n", val);
+ val = mpeg_decode_motion(s, s->c.mpeg_f_code[i][1],
+ s->c.last_mv[i][j][1] >> 1);
+ s->c.last_mv[i][j][1] = 2 * val;
+ s->c.mv[i][j][1] = val;
+ ff_tlog(s->c.avctx, "fmy=%d\n", val);
}
}
}
} else {
- av_assert0(!s->progressive_sequence);
+ av_assert0(!s->c.progressive_sequence);
mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
for (i = 0; i < 2; i++) {
if (HAS_MV(mb_type, i)) {
- s->field_select[i][0] = get_bits1(&s->gb);
+ s->c.field_select[i][0] = get_bits1(&s->c.gb);
for (k = 0; k < 2; k++) {
- val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
- s->last_mv[i][0][k]);
- s->last_mv[i][0][k] = val;
- s->last_mv[i][1][k] = val;
- s->mv[i][0][k] = val;
+ val = mpeg_decode_motion(s, s->c.mpeg_f_code[i][k],
+ s->c.last_mv[i][0][k]);
+ s->c.last_mv[i][0][k] = val;
+ s->c.last_mv[i][1][k] = val;
+ s->c.mv[i][0][k] = val;
}
}
}
}
break;
case MT_DMV:
- if (s->progressive_sequence){
- av_log(s->avctx, AV_LOG_ERROR, "MT_DMV in progressive_sequence\n");
+ if (s->c.progressive_sequence){
+ av_log(s->c.avctx, AV_LOG_ERROR, "MT_DMV in progressive_sequence\n");
return AVERROR_INVALIDDATA;
}
- s->mv_type = MV_TYPE_DMV;
+ s->c.mv_type = MV_TYPE_DMV;
for (i = 0; i < 2; i++) {
if (HAS_MV(mb_type, i)) {
int dmx, dmy, mx, my, m;
- const int my_shift = s->picture_structure == PICT_FRAME;
+ const int my_shift = s->c.picture_structure == PICT_FRAME;
- mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
- s->last_mv[i][0][0]);
- s->last_mv[i][0][0] = mx;
- s->last_mv[i][1][0] = mx;
+ mx = mpeg_decode_motion(s, s->c.mpeg_f_code[i][0],
+ s->c.last_mv[i][0][0]);
+ s->c.last_mv[i][0][0] = mx;
+ s->c.last_mv[i][1][0] = mx;
dmx = get_dmv(s);
- my = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
- s->last_mv[i][0][1] >> my_shift);
+ my = mpeg_decode_motion(s, s->c.mpeg_f_code[i][1],
+ s->c.last_mv[i][0][1] >> my_shift);
dmy = get_dmv(s);
- s->last_mv[i][0][1] = my * (1 << my_shift);
- s->last_mv[i][1][1] = my * (1 << my_shift);
+ s->c.last_mv[i][0][1] = my * (1 << my_shift);
+ s->c.last_mv[i][1][1] = my * (1 << my_shift);
- s->mv[i][0][0] = mx;
- s->mv[i][0][1] = my;
- s->mv[i][1][0] = mx; // not used
- s->mv[i][1][1] = my; // not used
+ s->c.mv[i][0][0] = mx;
+ s->c.mv[i][0][1] = my;
+ s->c.mv[i][1][0] = mx; // not used
+ s->c.mv[i][1][1] = my; // not used
- if (s->picture_structure == PICT_FRAME) {
+ if (s->c.picture_structure == PICT_FRAME) {
mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
- // m = 1 + 2 * s->top_field_first;
- m = s->top_field_first ? 1 : 3;
+ // m = 1 + 2 * s->c.top_field_first;
+ m = s->c.top_field_first ? 1 : 3;
/* top -> top pred */
- s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
- s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
+ s->c.mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
+ s->c.mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
m = 4 - m;
- s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
- s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
+ s->c.mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
+ s->c.mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
} else {
mb_type |= MB_TYPE_16x16;
- s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
- s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
- if (s->picture_structure == PICT_TOP_FIELD)
- s->mv[i][2][1]--;
+ s->c.mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
+ s->c.mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
+ if (s->c.picture_structure == PICT_TOP_FIELD)
+ s->c.mv[i][2][1]--;
else
- s->mv[i][2][1]++;
+ s->c.mv[i][2][1]++;
}
}
}
break;
default:
- av_log(s->avctx, AV_LOG_ERROR,
- "00 motion_type at %d %d\n", s->mb_x, s->mb_y);
+ av_log(s->c.avctx, AV_LOG_ERROR,
+ "00 motion_type at %d %d\n", s->c.mb_x, s->c.mb_y);
return AVERROR_INVALIDDATA;
}
}
- s->mb_intra = 0;
- s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->intra_dc_precision;
+ s->c.mb_intra = 0;
+ s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
if (HAS_CBP(mb_type)) {
- s->bdsp.clear_blocks(s->block[0]);
+ s->c.bdsp.clear_blocks(s->c.block[0]);
- cbp = get_vlc2(&s->gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
+ cbp = get_vlc2(&s->c.gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
if (mb_block_count > 6) {
cbp *= 1 << mb_block_count - 6;
- cbp |= get_bits(&s->gb, mb_block_count - 6);
- s->bdsp.clear_blocks(s->block[6]);
+ cbp |= get_bits(&s->c.gb, mb_block_count - 6);
+ s->c.bdsp.clear_blocks(s->c.block[6]);
}
if (cbp <= 0) {
- av_log(s->avctx, AV_LOG_ERROR,
- "invalid cbp %d at %d %d\n", cbp, s->mb_x, s->mb_y);
+ av_log(s->c.avctx, AV_LOG_ERROR,
+ "invalid cbp %d at %d %d\n", cbp, s->c.mb_x, s->c.mb_y);
return AVERROR_INVALIDDATA;
}
- if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
+ if (s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO) {
cbp <<= 12 - mb_block_count;
for (i = 0; i < mb_block_count; i++) {
if (cbp & (1 << 11)) {
- if ((ret = mpeg2_decode_block_non_intra(s, s->block[i], i)) < 0)
+ if ((ret = mpeg2_decode_block_non_intra(s, s->c.block[i], i)) < 0)
return ret;
} else {
- s->block_last_index[i] = -1;
+ s->c.block_last_index[i] = -1;
}
cbp += cbp;
}
} else {
for (i = 0; i < 6; i++) {
if (cbp & 32) {
- if ((ret = mpeg1_decode_block_inter(s, s->block[i], i)) < 0)
+ if ((ret = mpeg1_decode_block_inter(s, s->c.block[i], i)) < 0)
return ret;
} else {
- s->block_last_index[i] = -1;
+ s->c.block_last_index[i] = -1;
}
cbp += cbp;
}
}
} else {
for (i = 0; i < 12; i++)
- s->block_last_index[i] = -1;
+ s->c.block_last_index[i] = -1;
}
}
- s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride] = mb_type;
+ s->c.cur_pic.mb_type[s->c.mb_x + s->c.mb_y * s->c.mb_stride] = mb_type;
return 0;
}
@@ -760,9 +764,10 @@ static int mpeg_decode_mb(MPVContext *const s)
static av_cold int mpeg_decode_init(AVCodecContext *avctx)
{
Mpeg1Context *s = avctx->priv_data;
- MpegEncContext *s2 = &s->mpeg_enc_ctx;
+ MPVContext *const s2 = &s->slice.c;
int ret;
+ s2->slice_ctx_size = sizeof(s->slice);
s2->out_format = FMT_MPEG1;
if ( avctx->codec_tag != AV_RL32("VCR2")
@@ -830,7 +835,7 @@ static const enum AVPixelFormat mpeg12_pixfmt_list_444[] = {
static enum AVPixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
{
Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
const enum AVPixelFormat *pix_fmts;
if (CONFIG_GRAY && (avctx->flags & AV_CODEC_FLAG_GRAY))
@@ -853,7 +858,7 @@ static enum AVPixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
static int mpeg_decode_postinit(AVCodecContext *avctx)
{
Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
int ret;
if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
@@ -969,7 +974,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf,
int buf_size)
{
Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
GetBitContext gb0, *const gb = &gb0;
int ref, f_code, vbv_delay, ret;
@@ -1014,7 +1019,7 @@ static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf,
static void mpeg_decode_sequence_extension(Mpeg1Context *const s1,
GetBitContext *const gb)
{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
int horiz_size_ext, vert_size_ext;
int bit_rate_ext;
@@ -1058,7 +1063,7 @@ static void mpeg_decode_sequence_extension(Mpeg1Context *const s1,
static void mpeg_decode_sequence_display_extension(Mpeg1Context *const s1,
GetBitContext *const gb)
{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
int color_description, w, h;
skip_bits(gb, 3); /* video format */
@@ -1083,7 +1088,7 @@ static void mpeg_decode_sequence_display_extension(Mpeg1Context *const s1,
static void mpeg_decode_picture_display_extension(Mpeg1Context *const s1,
GetBitContext *const gb)
{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
int i, nofco;
nofco = 1;
@@ -1156,7 +1161,7 @@ static void mpeg_decode_quant_matrix_extension(MPVContext *const s,
static int mpeg_decode_picture_coding_extension(Mpeg1Context *const s1,
GetBitContext *const gb)
{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
s->full_pel[0] = s->full_pel[1] = 0;
s->mpeg_f_code[0][0] = get_bits(gb, 4);
@@ -1214,7 +1219,7 @@ static int mpeg_decode_picture_coding_extension(Mpeg1Context *const s1,
static int mpeg_field_start(Mpeg1Context *s1, const uint8_t *buf, int buf_size)
{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
AVCodecContext *avctx = s->avctx;
int second_field = 0;
int ret;
@@ -1343,69 +1348,69 @@ static int mpeg_field_start(Mpeg1Context *s1, const uint8_t *buf, int buf_size)
/**
* Decode a slice.
- * MpegEncContext.mb_y must be set to the MB row from the startcode.
+ * Mpeg12SliceContext.c.mb_y must be set to the MB row from the startcode.
* @return DECODE_SLICE_ERROR if the slice is damaged,
* DECODE_SLICE_OK if this slice is OK
*/
-static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
+static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
const uint8_t **buf, int buf_size)
{
- AVCodecContext *avctx = s->avctx;
- const int lowres = s->avctx->lowres;
- const int field_pic = s->picture_structure != PICT_FRAME;
+ AVCodecContext *avctx = s->c.avctx;
+ const int lowres = s->c.avctx->lowres;
+ const int field_pic = s->c.picture_structure != PICT_FRAME;
int ret;
- s->resync_mb_x =
- s->resync_mb_y = -1;
+ s->c.resync_mb_x =
+ s->c.resync_mb_y = -1;
- av_assert0(mb_y < s->mb_height);
+ av_assert0(mb_y < s->c.mb_height);
- ret = init_get_bits8(&s->gb, *buf, buf_size);
+ ret = init_get_bits8(&s->c.gb, *buf, buf_size);
if (ret < 0)
return ret;
- if (s->codec_id != AV_CODEC_ID_MPEG1VIDEO && s->mb_height > 2800/16)
- skip_bits(&s->gb, 3);
+ if (s->c.codec_id != AV_CODEC_ID_MPEG1VIDEO && s->c.mb_height > 2800/16)
+ skip_bits(&s->c.gb, 3);
- ff_mpeg1_clean_buffers(s);
- s->interlaced_dct = 0;
+ ff_mpeg1_clean_buffers(&s->c);
+ s->c.interlaced_dct = 0;
- s->qscale = mpeg_get_qscale(&s->gb, s->q_scale_type);
+ s->c.qscale = mpeg_get_qscale(&s->c.gb, s->c.q_scale_type);
- if (s->qscale == 0) {
- av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
+ if (s->c.qscale == 0) {
+ av_log(s->c.avctx, AV_LOG_ERROR, "qscale == 0\n");
return AVERROR_INVALIDDATA;
}
/* extra slice info */
- if (skip_1stop_8data_bits(&s->gb) < 0)
+ if (skip_1stop_8data_bits(&s->c.gb) < 0)
return AVERROR_INVALIDDATA;
- s->mb_x = 0;
+ s->c.mb_x = 0;
- if (mb_y == 0 && s->codec_tag == AV_RL32("SLIF")) {
- skip_bits1(&s->gb);
+ if (mb_y == 0 && s->c.codec_tag == AV_RL32("SLIF")) {
+ skip_bits1(&s->c.gb);
} else {
- while (get_bits_left(&s->gb) > 0) {
- int code = get_vlc2(&s->gb, ff_mbincr_vlc,
+ while (get_bits_left(&s->c.gb) > 0) {
+ int code = get_vlc2(&s->c.gb, ff_mbincr_vlc,
MBINCR_VLC_BITS, 2);
if (code < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
+ av_log(s->c.avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
return AVERROR_INVALIDDATA;
}
if (code >= 33) {
if (code == 33)
- s->mb_x += 33;
+ s->c.mb_x += 33;
/* otherwise, stuffing, nothing to do */
} else {
- s->mb_x += code;
+ s->c.mb_x += code;
break;
}
}
}
- if (s->mb_x >= (unsigned) s->mb_width) {
- av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n");
+ if (s->c.mb_x >= (unsigned) s->c.mb_width) {
+ av_log(s->c.avctx, AV_LOG_ERROR, "initial skip overflow\n");
return AVERROR_INVALIDDATA;
}
@@ -1415,36 +1420,36 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
buf_end = avpriv_find_start_code(buf_start + 2, *buf + buf_size, &start_code);
if (buf_end < *buf + buf_size)
buf_end -= 4;
- s->mb_y = mb_y;
+ s->c.mb_y = mb_y;
if (FF_HW_CALL(avctx, decode_slice, buf_start, buf_end - buf_start) < 0)
return DECODE_SLICE_ERROR;
*buf = buf_end;
return DECODE_SLICE_OK;
}
- s->resync_mb_x = s->mb_x;
- s->resync_mb_y = s->mb_y = mb_y;
- s->mb_skip_run = 0;
- ff_init_block_index(s);
+ s->c.resync_mb_x = s->c.mb_x;
+ s->c.resync_mb_y = s->c.mb_y = mb_y;
+ s->c.mb_skip_run = 0;
+ ff_init_block_index(&s->c);
- if (s->mb_y == 0 && s->mb_x == 0 && (s->first_field || s->picture_structure == PICT_FRAME)) {
- if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
- av_log(s->avctx, AV_LOG_DEBUG,
+ if (s->c.mb_y == 0 && s->c.mb_x == 0 && (s->c.first_field || s->c.picture_structure == PICT_FRAME)) {
+ if (s->c.avctx->debug & FF_DEBUG_PICT_INFO) {
+ av_log(s->c.avctx, AV_LOG_DEBUG,
"qp:%d fc:%2d%2d%2d%2d %c %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
- s->qscale,
- s->mpeg_f_code[0][0], s->mpeg_f_code[0][1],
- s->mpeg_f_code[1][0], s->mpeg_f_code[1][1],
- s->pict_type == AV_PICTURE_TYPE_I ? 'I' :
- (s->pict_type == AV_PICTURE_TYPE_P ? 'P' :
- (s->pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')),
- s->progressive_sequence ? "ps" : "",
- s->progressive_frame ? "pf" : "",
- s->alternate_scan ? "alt" : "",
- s->top_field_first ? "top" : "",
- s->intra_dc_precision, s->picture_structure,
- s->frame_pred_frame_dct, s->concealment_motion_vectors,
- s->q_scale_type, s->intra_vlc_format,
- s->repeat_first_field, s->chroma_420_type ? "420" : "");
+ s->c.qscale,
+ s->c.mpeg_f_code[0][0], s->c.mpeg_f_code[0][1],
+ s->c.mpeg_f_code[1][0], s->c.mpeg_f_code[1][1],
+ s->c.pict_type == AV_PICTURE_TYPE_I ? 'I' :
+ (s->c.pict_type == AV_PICTURE_TYPE_P ? 'P' :
+ (s->c.pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')),
+ s->c.progressive_sequence ? "ps" : "",
+ s->c.progressive_frame ? "pf" : "",
+ s->c.alternate_scan ? "alt" : "",
+ s->c.top_field_first ? "top" : "",
+ s->c.intra_dc_precision, s->c.picture_structure,
+ s->c.frame_pred_frame_dct, s->c.concealment_motion_vectors,
+ s->c.q_scale_type, s->c.intra_vlc_format,
+ s->c.repeat_first_field, s->c.chroma_420_type ? "420" : "");
}
}
@@ -1454,67 +1459,67 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
return ret;
// Note motion_val is normally NULL unless we want to extract the MVs.
- if (s->cur_pic.motion_val[0]) {
- const int wrap = s->b8_stride;
- int xy = s->mb_x * 2 + s->mb_y * 2 * wrap;
- int b8_xy = 4 * (s->mb_x + s->mb_y * s->mb_stride);
+ if (s->c.cur_pic.motion_val[0]) {
+ const int wrap = s->c.b8_stride;
+ int xy = s->c.mb_x * 2 + s->c.mb_y * 2 * wrap;
+ int b8_xy = 4 * (s->c.mb_x + s->c.mb_y * s->c.mb_stride);
int motion_x, motion_y, dir, i;
for (i = 0; i < 2; i++) {
for (dir = 0; dir < 2; dir++) {
- if (s->mb_intra ||
- (dir == 1 && s->pict_type != AV_PICTURE_TYPE_B)) {
+ if (s->c.mb_intra ||
+ (dir == 1 && s->c.pict_type != AV_PICTURE_TYPE_B)) {
motion_x = motion_y = 0;
- } else if (s->mv_type == MV_TYPE_16X16 ||
- (s->mv_type == MV_TYPE_FIELD && field_pic)) {
- motion_x = s->mv[dir][0][0];
- motion_y = s->mv[dir][0][1];
- } else { /* if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8)) */
- motion_x = s->mv[dir][i][0];
- motion_y = s->mv[dir][i][1];
+ } else if (s->c.mv_type == MV_TYPE_16X16 ||
+ (s->c.mv_type == MV_TYPE_FIELD && field_pic)) {
+ motion_x = s->c.mv[dir][0][0];
+ motion_y = s->c.mv[dir][0][1];
+ } else { /* if ((s->c.mv_type == MV_TYPE_FIELD) || (s->c.mv_type == MV_TYPE_16X8)) */
+ motion_x = s->c.mv[dir][i][0];
+ motion_y = s->c.mv[dir][i][1];
}
- s->cur_pic.motion_val[dir][xy][0] = motion_x;
- s->cur_pic.motion_val[dir][xy][1] = motion_y;
- s->cur_pic.motion_val[dir][xy + 1][0] = motion_x;
- s->cur_pic.motion_val[dir][xy + 1][1] = motion_y;
- s->cur_pic.ref_index [dir][b8_xy] =
- s->cur_pic.ref_index [dir][b8_xy + 1] = s->field_select[dir][i];
- av_assert2(s->field_select[dir][i] == 0 ||
- s->field_select[dir][i] == 1);
+ s->c.cur_pic.motion_val[dir][xy][0] = motion_x;
+ s->c.cur_pic.motion_val[dir][xy][1] = motion_y;
+ s->c.cur_pic.motion_val[dir][xy + 1][0] = motion_x;
+ s->c.cur_pic.motion_val[dir][xy + 1][1] = motion_y;
+ s->c.cur_pic.ref_index [dir][b8_xy] =
+ s->c.cur_pic.ref_index [dir][b8_xy + 1] = s->c.field_select[dir][i];
+ av_assert2(s->c.field_select[dir][i] == 0 ||
+ s->c.field_select[dir][i] == 1);
}
xy += wrap;
b8_xy += 2;
}
}
- s->dest[0] += 16 >> lowres;
- s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift;
- s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
+ s->c.dest[0] += 16 >> lowres;
+ s->c.dest[1] +=(16 >> lowres) >> s->c.chroma_x_shift;
+ s->c.dest[2] +=(16 >> lowres) >> s->c.chroma_x_shift;
- ff_mpv_reconstruct_mb(s, s->block);
+ ff_mpv_reconstruct_mb(&s->c, s->c.block);
- if (++s->mb_x >= s->mb_width) {
- const int mb_size = 16 >> s->avctx->lowres;
+ if (++s->c.mb_x >= s->c.mb_width) {
+ const int mb_size = 16 >> s->c.avctx->lowres;
int left;
- ff_mpeg_draw_horiz_band(s, mb_size * (s->mb_y >> field_pic), mb_size);
+ ff_mpeg_draw_horiz_band(&s->c, mb_size * (s->c.mb_y >> field_pic), mb_size);
- s->mb_x = 0;
- s->mb_y += 1 << field_pic;
+ s->c.mb_x = 0;
+ s->c.mb_y += 1 << field_pic;
- if (s->mb_y >= s->mb_height) {
- int left = get_bits_left(&s->gb);
- int is_d10 = s->chroma_format == CHROMA_422 &&
- s->pict_type == AV_PICTURE_TYPE_I &&
+ if (s->c.mb_y >= s->c.mb_height) {
+ int left = get_bits_left(&s->c.gb);
+ int is_d10 = s->c.chroma_format == CHROMA_422 &&
+ s->c.pict_type == AV_PICTURE_TYPE_I &&
avctx->profile == 0 && avctx->level == 5 &&
- s->intra_dc_precision == 2 &&
- s->q_scale_type == 1 && s->alternate_scan == 0 &&
- s->progressive_frame == 0
+ s->c.intra_dc_precision == 2 &&
+ s->c.q_scale_type == 1 && s->c.alternate_scan == 0 &&
+ s->c.progressive_frame == 0
/* vbv_delay == 0xBBB || 0xE10 */;
if (left >= 32 && !is_d10) {
- GetBitContext gb = s->gb;
+ GetBitContext gb = s->c.gb;
align_get_bits(&gb);
if (show_bits(&gb, 24) == 0x060E2B) {
av_log(avctx, AV_LOG_DEBUG, "Invalid MXF data found in video stream\n");
@@ -1527,10 +1532,10 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
}
if (left < 0 ||
- (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10) ||
+ (left && show_bits(&s->c.gb, FFMIN(left, 23)) && !is_d10) ||
((avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) && left > 8)) {
av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X at %d %d\n",
- left, left>0 ? show_bits(&s->gb, FFMIN(left, 23)) : 0, s->mb_x, s->mb_y);
+ left, left>0 ? show_bits(&s->c.gb, FFMIN(left, 23)) : 0, s->c.mb_x, s->c.mb_y);
return AVERROR_INVALIDDATA;
} else
goto eos;
@@ -1539,136 +1544,136 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
// in cases where the slice is completely outside the visible
// area, we detect this here instead of running into the end expecting
// more data
- left = get_bits_left(&s->gb);
- if (s->mb_y >= ((s->height + 15) >> 4) &&
- !s->progressive_sequence &&
+ left = get_bits_left(&s->c.gb);
+ if (s->c.mb_y >= ((s->c.height + 15) >> 4) &&
+ !s->c.progressive_sequence &&
left <= 25 &&
left >= 0 &&
- s->mb_skip_run == -1 &&
- (!left || show_bits(&s->gb, left) == 0))
+ s->c.mb_skip_run == -1 &&
+ (!left || show_bits(&s->c.gb, left) == 0))
goto eos;
- ff_init_block_index(s);
+ ff_init_block_index(&s->c);
}
/* skip mb handling */
- if (s->mb_skip_run == -1) {
+ if (s->c.mb_skip_run == -1) {
/* read increment again */
- s->mb_skip_run = 0;
+ s->c.mb_skip_run = 0;
for (;;) {
- int code = get_vlc2(&s->gb, ff_mbincr_vlc,
+ int code = get_vlc2(&s->c.gb, ff_mbincr_vlc,
MBINCR_VLC_BITS, 2);
if (code < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
+ av_log(s->c.avctx, AV_LOG_ERROR, "mb incr damaged\n");
return AVERROR_INVALIDDATA;
}
if (code >= 33) {
if (code == 33) {
- s->mb_skip_run += 33;
+ s->c.mb_skip_run += 33;
} else if (code == 35) {
- if (s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
- av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
+ if (s->c.mb_skip_run != 0 || show_bits(&s->c.gb, 15) != 0) {
+ av_log(s->c.avctx, AV_LOG_ERROR, "slice mismatch\n");
return AVERROR_INVALIDDATA;
}
goto eos; /* end of slice */
}
/* otherwise, stuffing, nothing to do */
} else {
- s->mb_skip_run += code;
+ s->c.mb_skip_run += code;
break;
}
}
- if (s->mb_skip_run) {
+ if (s->c.mb_skip_run) {
int i;
- if (s->pict_type == AV_PICTURE_TYPE_I) {
- av_log(s->avctx, AV_LOG_ERROR,
- "skipped MB in I-frame at %d %d\n", s->mb_x, s->mb_y);
+ if (s->c.pict_type == AV_PICTURE_TYPE_I) {
+ av_log(s->c.avctx, AV_LOG_ERROR,
+ "skipped MB in I-frame at %d %d\n", s->c.mb_x, s->c.mb_y);
return AVERROR_INVALIDDATA;
}
/* skip mb */
- s->mb_intra = 0;
+ s->c.mb_intra = 0;
for (i = 0; i < 12; i++)
- s->block_last_index[i] = -1;
- s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 128 << s->intra_dc_precision;
- if (s->picture_structure == PICT_FRAME)
- s->mv_type = MV_TYPE_16X16;
+ s->c.block_last_index[i] = -1;
+ s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
+ if (s->c.picture_structure == PICT_FRAME)
+ s->c.mv_type = MV_TYPE_16X16;
else
- s->mv_type = MV_TYPE_FIELD;
- if (s->pict_type == AV_PICTURE_TYPE_P) {
+ s->c.mv_type = MV_TYPE_FIELD;
+ if (s->c.pict_type == AV_PICTURE_TYPE_P) {
/* if P type, zero motion vector is implied */
- s->mv_dir = MV_DIR_FORWARD;
- s->mv[0][0][0] = s->mv[0][0][1] = 0;
- s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
- s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
- s->field_select[0][0] = (s->picture_structure - 1) & 1;
+ s->c.mv_dir = MV_DIR_FORWARD;
+ s->c.mv[0][0][0] = s->c.mv[0][0][1] = 0;
+ s->c.last_mv[0][0][0] = s->c.last_mv[0][0][1] = 0;
+ s->c.last_mv[0][1][0] = s->c.last_mv[0][1][1] = 0;
+ s->c.field_select[0][0] = (s->c.picture_structure - 1) & 1;
} else {
/* if B type, reuse previous vectors and directions */
- s->mv[0][0][0] = s->last_mv[0][0][0];
- s->mv[0][0][1] = s->last_mv[0][0][1];
- s->mv[1][0][0] = s->last_mv[1][0][0];
- s->mv[1][0][1] = s->last_mv[1][0][1];
- s->field_select[0][0] = (s->picture_structure - 1) & 1;
- s->field_select[1][0] = (s->picture_structure - 1) & 1;
+ s->c.mv[0][0][0] = s->c.last_mv[0][0][0];
+ s->c.mv[0][0][1] = s->c.last_mv[0][0][1];
+ s->c.mv[1][0][0] = s->c.last_mv[1][0][0];
+ s->c.mv[1][0][1] = s->c.last_mv[1][0][1];
+ s->c.field_select[0][0] = (s->c.picture_structure - 1) & 1;
+ s->c.field_select[1][0] = (s->c.picture_structure - 1) & 1;
}
}
}
}
eos: // end of slice
- if (get_bits_left(&s->gb) < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "overread %d\n", -get_bits_left(&s->gb));
+ if (get_bits_left(&s->c.gb) < 0) {
+ av_log(s->c.avctx, AV_LOG_ERROR, "overread %d\n", -get_bits_left(&s->c.gb));
return AVERROR_INVALIDDATA;
}
- *buf += (get_bits_count(&s->gb) - 1) / 8;
- ff_dlog(s->avctx, "Slice start:%d %d end:%d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
+ *buf += (get_bits_count(&s->c.gb) - 1) / 8;
+ ff_dlog(s->c.avctx, "Slice start:%d %d end:%d %d\n", s->c.resync_mb_x, s->c.resync_mb_y, s->c.mb_x, s->c.mb_y);
return 0;
}
static int slice_decode_thread(AVCodecContext *c, void *arg)
{
- MpegEncContext *s = *(void **) arg;
- const uint8_t *buf = s->gb.buffer;
- int mb_y = s->start_mb_y;
- const int field_pic = s->picture_structure != PICT_FRAME;
+ Mpeg12SliceContext *const s = *(void **) arg;
+ const uint8_t *buf = s->c.gb.buffer;
+ int mb_y = s->c.start_mb_y;
+ const int field_pic = s->c.picture_structure != PICT_FRAME;
- s->er.error_count = (3 * (s->end_mb_y - s->start_mb_y) * s->mb_width) >> field_pic;
+ s->c.er.error_count = (3 * (s->c.end_mb_y - s->c.start_mb_y) * s->c.mb_width) >> field_pic;
for (;;) {
uint32_t start_code;
int ret;
- ret = mpeg_decode_slice(s, mb_y, &buf, s->gb.buffer_end - buf);
+ ret = mpeg_decode_slice(s, mb_y, &buf, s->c.gb.buffer_end - buf);
emms_c();
ff_dlog(c, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
- ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y,
- s->start_mb_y, s->end_mb_y, s->er.error_count);
+ ret, s->c.resync_mb_x, s->c.resync_mb_y, s->c.mb_x, s->c.mb_y,
+ s->c.start_mb_y, s->c.end_mb_y, s->c.er.error_count);
if (ret < 0) {
if (c->err_recognition & AV_EF_EXPLODE)
return ret;
- if (s->resync_mb_x >= 0 && s->resync_mb_y >= 0)
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x, s->mb_y,
+ if (s->c.resync_mb_x >= 0 && s->c.resync_mb_y >= 0)
+ ff_er_add_slice(&s->c.er, s->c.resync_mb_x, s->c.resync_mb_y,
+ s->c.mb_x, s->c.mb_y,
ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR);
} else {
- ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
- s->mb_x - 1, s->mb_y,
+ ff_er_add_slice(&s->c.er, s->c.resync_mb_x, s->c.resync_mb_y,
+ s->c.mb_x - 1, s->c.mb_y,
ER_AC_END | ER_DC_END | ER_MV_END);
}
- if (s->mb_y == s->end_mb_y)
+ if (s->c.mb_y == s->c.end_mb_y)
return 0;
start_code = -1;
- buf = avpriv_find_start_code(buf, s->gb.buffer_end, &start_code);
+ buf = avpriv_find_start_code(buf, s->c.gb.buffer_end, &start_code);
if (start_code < SLICE_MIN_START_CODE || start_code > SLICE_MAX_START_CODE)
return AVERROR_INVALIDDATA;
mb_y = start_code - SLICE_MIN_START_CODE;
- if (s->codec_id != AV_CODEC_ID_MPEG1VIDEO && s->mb_height > 2800/16)
+ if (s->c.codec_id != AV_CODEC_ID_MPEG1VIDEO && s->c.mb_height > 2800/16)
mb_y += (*buf&0xE0)<<2;
mb_y <<= field_pic;
- if (s->picture_structure == PICT_BOTTOM_FIELD)
+ if (s->c.picture_structure == PICT_BOTTOM_FIELD)
mb_y++;
- if (mb_y >= s->end_mb_y)
+ if (mb_y >= s->c.end_mb_y)
return AVERROR_INVALIDDATA;
}
}
@@ -1680,7 +1685,7 @@ static int slice_decode_thread(AVCodecContext *c, void *arg)
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
{
Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
if (!s->context_initialized || !s->cur_pic.ptr)
return 0;
@@ -1731,7 +1736,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
GetBitContext gb0, *const gb = &gb0;
int width, height;
int i, v, j;
@@ -1820,7 +1825,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
static int vcr2_init_sequence(AVCodecContext *avctx)
{
Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
int i, v, ret;
/* start new MPEG-1 context decoding */
@@ -1951,7 +1956,7 @@ static int mpeg_decode_a53_cc(AVCodecContext *avctx,
cap[0] = cap[1] = cap[2] = 0x00;
} else {
field = (field == 2 ? 1 : 0);
- if (!s1->mpeg_enc_ctx.top_field_first) field = !field;
+ if (!s1->slice.c.top_field_first) field = !field;
cap[0] = 0x04 | field;
cap[1] = ff_reverse[cc1];
cap[2] = ff_reverse[cc2];
@@ -2165,7 +2170,7 @@ static int mpeg_decode_gop(AVCodecContext *avctx,
const uint8_t *buf, int buf_size)
{
Mpeg1Context *s1 = avctx->priv_data;
- MpegEncContext *s = &s1->mpeg_enc_ctx;
+ MPVContext *const s = &s1->slice.c;
GetBitContext gb0, *const gb = &gb0;
int broken_link;
int64_t tc;
@@ -2198,12 +2203,12 @@ static void mpeg12_execute_slice_threads(AVCodecContext *avctx,
{
if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) &&
!avctx->hwaccel) {
- MpegEncContext *const s2 = &s->mpeg_enc_ctx;
+ MPVContext *const s2 = &s->slice.c;
int error_count = 0;
avctx->execute(avctx, slice_decode_thread,
- s2->thread_context, NULL,
- s->slice_count, sizeof(void *));
+ s2->mpeg12_contexts, NULL,
+ s->slice_count, sizeof(s2->mpeg12_contexts[0]));
for (int i = 0; i < s->slice_count; i++) {
MpegEncContext *const slice = s2->thread_context[i];
@@ -2226,7 +2231,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
int *got_output, const uint8_t *buf, int buf_size)
{
Mpeg1Context *s = avctx->priv_data;
- MpegEncContext *s2 = &s->mpeg_enc_ctx;
+ MPVContext *const s2 = &s->slice.c;
const uint8_t *buf_ptr = buf;
const uint8_t *buf_end = buf + buf_size;
int ret, input_size;
@@ -2501,24 +2506,24 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
s2->slice_context_count / 2) /
s2->slice_context_count;
if (threshold <= mb_y) {
- MpegEncContext *thread_context = s2->thread_context[s->slice_count];
+ Mpeg12SliceContext *const thread_context = s2->mpeg12_contexts[s->slice_count];
- thread_context->start_mb_y = mb_y;
- thread_context->end_mb_y = s2->mb_height;
+ thread_context->c.start_mb_y = mb_y;
+ thread_context->c.end_mb_y = s2->mb_height;
if (s->slice_count) {
s2->thread_context[s->slice_count - 1]->end_mb_y = mb_y;
- ret = ff_update_duplicate_context(thread_context, s2);
+ ret = ff_update_duplicate_context(&thread_context->c, s2);
if (ret < 0)
return ret;
}
- ret = init_get_bits8(&thread_context->gb, buf_ptr, input_size);
+ ret = init_get_bits8(&thread_context->c.gb, buf_ptr, input_size);
if (ret < 0)
return ret;
s->slice_count++;
}
buf_ptr += 2; // FIXME add minimum number of bytes per slice
} else {
- ret = mpeg_decode_slice(s2, mb_y, &buf_ptr, input_size);
+ ret = mpeg_decode_slice(&s->slice, mb_y, &buf_ptr, input_size);
emms_c();
if (ret < 0) {
@@ -2547,7 +2552,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture,
int ret;
int buf_size = avpkt->size;
Mpeg1Context *s = avctx->priv_data;
- MpegEncContext *s2 = &s->mpeg_enc_ctx;
+ MPVContext *const s2 = &s->slice.c;
if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
/* special case for last picture */
@@ -2746,7 +2751,7 @@ const FFCodec ff_mpegvideo_decoder = {
};
typedef struct IPUContext {
- MpegEncContext m;
+ Mpeg12SliceContext m;
int flags;
DECLARE_ALIGNED(32, int16_t, block)[6][64];
@@ -2756,7 +2761,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
int *got_frame, AVPacket *avpkt)
{
IPUContext *s = avctx->priv_data;
- MpegEncContext *m = &s->m;
+ MPVContext *const m = &s->m.c;
GetBitContext *gb = &m->gb;
int ret;
@@ -2817,7 +2822,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
m->last_dc, s->block[n],
n, m->qscale);
} else {
- ret = mpeg2_decode_block_intra(m, s->block[n], n);
+ ret = mpeg2_decode_block_intra(&s->m, s->block[n], n);
}
if (ret < 0)
@@ -2851,7 +2856,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
static av_cold int ipu_decode_init(AVCodecContext *avctx)
{
IPUContext *s = avctx->priv_data;
- MpegEncContext *m = &s->m;
+ MPVContext *const m = &s->m.c;
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
m->avctx = avctx;
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 3cbd686558..ae294e9dd8 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -128,7 +128,7 @@ static av_cold int init_duplicate_context(MpegEncContext *s)
av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
{
int nb_slices = s->slice_context_count, ret;
- size_t slice_size = s->slice_ctx_size ? s->slice_ctx_size : sizeof(*s);
+ const size_t slice_size = s->slice_ctx_size;
/* We initialize the copies before the original so that
* fields allocated in init_duplicate_context are NULL after
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 8b94cc1ff0..2581641d0c 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -116,6 +116,7 @@ typedef struct MpegEncContext {
int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y)
union {
struct MpegEncContext *thread_context[MAX_THREADS];
+ struct Mpeg12SliceContext *mpeg12_contexts[MAX_THREADS];
struct MPVEncContext *enc_contexts[MAX_THREADS];
};
int slice_context_count; ///< number of used thread_contexts
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 31/48] avcodec/mpegvideo: Add missing headers
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (29 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 30/48] avcodec/mpeg12dec: Add Mpeg12SliceContext Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 32/48] avcodec/mpeg12dec: Move MpegEncContext.gb to Mpeg12SliceContext Andreas Rheinhardt
` (16 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
These files currently rely on implicit inclusions of avassert.h
and/or mathops.h via get_bits.h.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/error_resilience.c | 2 ++
libavcodec/me_cmp.c | 1 +
libavcodec/mips/mpegvideo_msa.c | 1 +
libavcodec/mpeg4videoenc.c | 1 +
libavcodec/mpegvideo.c | 1 +
libavcodec/msmpeg4.c | 1 +
libavcodec/ppc/mpegvideo_altivec.c | 1 +
libavcodec/speedhqenc.c | 1 +
libavcodec/x86/mpegvideo.c | 2 +-
libavcodec/x86/mpegvideoenc.c | 1 -
libavcodec/x86/mpegvideoenc_template.c | 1 +
11 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 6edc2dc15f..cf6f83e096 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -27,9 +27,11 @@
#include <limits.h>
+#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "avcodec.h"
#include "error_resilience.h"
+#include "mathops.h"
#include "me_cmp.h"
#include "mpegutils.h"
#include "mpegvideo.h"
diff --git a/libavcodec/me_cmp.c b/libavcodec/me_cmp.c
index 419b8d30c9..8e53f6d573 100644
--- a/libavcodec/me_cmp.c
+++ b/libavcodec/me_cmp.c
@@ -27,6 +27,7 @@
#include "libavutil/mem_internal.h"
#include "avcodec.h"
#include "copy_block.h"
+#include "mathops.h"
#include "simple_idct.h"
#include "me_cmp.h"
#include "mpegvideoenc.h"
diff --git a/libavcodec/mips/mpegvideo_msa.c b/libavcodec/mips/mpegvideo_msa.c
index aa9ef770eb..cd4adc0f77 100644
--- a/libavcodec/mips/mpegvideo_msa.c
+++ b/libavcodec/mips/mpegvideo_msa.c
@@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/avassert.h"
#include "libavutil/mips/generic_macros_msa.h"
#include "h263dsp_mips.h"
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 1aa35aa70a..540ab8e4c3 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -29,6 +29,7 @@
#include "mpegvideo.h"
#include "h263.h"
#include "h263enc.h"
+#include "mathops.h"
#include "mpeg4video.h"
#include "mpeg4videodata.h"
#include "mpeg4videodefs.h"
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index ae294e9dd8..7ef0dacc80 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -31,6 +31,7 @@
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
+#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "avcodec.h"
diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c
index 740dbdcba8..3073ca6193 100644
--- a/libavcodec/msmpeg4.c
+++ b/libavcodec/msmpeg4.c
@@ -36,6 +36,7 @@
#include "avcodec.h"
#include "idctdsp.h"
+#include "mathops.h"
#include "mpegvideo.h"
#include "msmpeg4.h"
#include "mpeg4videodata.h"
diff --git a/libavcodec/ppc/mpegvideo_altivec.c b/libavcodec/ppc/mpegvideo_altivec.c
index 8cc213efe4..26e98acfb8 100644
--- a/libavcodec/ppc/mpegvideo_altivec.c
+++ b/libavcodec/ppc/mpegvideo_altivec.c
@@ -27,6 +27,7 @@
#include "config.h"
#include "libavutil/attributes.h"
+#include "libavutil/avassert.h"
#include "libavutil/cpu.h"
#include "libavutil/mem_internal.h"
#include "libavutil/ppc/cpu.h"
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 23ab86e8e2..da7aba6ec9 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -32,6 +32,7 @@
#include "avcodec.h"
#include "codec_internal.h"
+#include "mathops.h"
#include "mpeg12data.h"
#include "mpeg12vlc.h"
#include "mpegvideo.h"
diff --git a/libavcodec/x86/mpegvideo.c b/libavcodec/x86/mpegvideo.c
index 24f1e14007..8632acd412 100644
--- a/libavcodec/x86/mpegvideo.c
+++ b/libavcodec/x86/mpegvideo.c
@@ -20,10 +20,10 @@
*/
#include "libavutil/attributes.h"
+#include "libavutil/avassert.h"
#include "libavutil/cpu.h"
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
-#include "libavcodec/avcodec.h"
#include "libavcodec/mpegvideo.h"
#include "libavcodec/mpegvideodata.h"
#include "libavcodec/mpegvideo_unquantize.h"
diff --git a/libavcodec/x86/mpegvideoenc.c b/libavcodec/x86/mpegvideoenc.c
index d81a8ef14d..eac9947590 100644
--- a/libavcodec/x86/mpegvideoenc.c
+++ b/libavcodec/x86/mpegvideoenc.c
@@ -25,7 +25,6 @@
#include "libavutil/x86/asm.h"
#include "libavutil/x86/cpu.h"
#include "libavcodec/avcodec.h"
-#include "libavcodec/dct.h"
#include "libavcodec/mpegvideoenc.h"
/* not permutated inverse zigzag_direct + 1 for MMX quantizer */
diff --git a/libavcodec/x86/mpegvideoenc_template.c b/libavcodec/x86/mpegvideoenc_template.c
index dbb2187121..f0b95c1621 100644
--- a/libavcodec/x86/mpegvideoenc_template.c
+++ b/libavcodec/x86/mpegvideoenc_template.c
@@ -25,6 +25,7 @@
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
#include "libavutil/x86/asm.h"
+#include "libavcodec/mathops.h"
#include "libavcodec/mpegutils.h"
#include "libavcodec/mpegvideoenc.h"
#include "fdct.h"
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 32/48] avcodec/mpeg12dec: Move MpegEncContext.gb to Mpeg12SliceContext
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (30 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 31/48] avcodec/mpegvideo: Add missing headers Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 33/48] avcodec/mpeg12dec: Don't use MPVContext.block Andreas Rheinhardt
` (15 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It was its last user.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 207 +++++++++++++++++++++--------------------
libavcodec/mpegvideo.h | 4 -
2 files changed, 104 insertions(+), 107 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 1ef581ff99..8ca26c0d37 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -72,6 +72,7 @@ enum Mpeg2ClosedCaptionsFormat {
typedef struct Mpeg12SliceContext {
MPVContext c;
+ GetBitContext gb;
} Mpeg12SliceContext;
typedef struct Mpeg1Context {
@@ -103,18 +104,18 @@ static int mpeg_decode_motion(Mpeg12SliceContext *const s, int fcode, int pred)
{
int code, sign, val, shift;
- code = get_vlc2(&s->c.gb, ff_mv_vlc, MV_VLC_BITS, 2);
+ code = get_vlc2(&s->gb, ff_mv_vlc, MV_VLC_BITS, 2);
if (code == 0)
return pred;
if (code < 0)
return 0xffff;
- sign = get_bits1(&s->c.gb);
+ sign = get_bits1(&s->gb);
shift = fcode - 1;
val = code;
if (shift) {
val = (val - 1) << shift;
- val |= get_bits(&s->c.gb, shift);
+ val |= get_bits(&s->gb, shift);
val++;
}
if (sign)
@@ -144,24 +145,24 @@ static inline int mpeg1_decode_block_inter(Mpeg12SliceContext *const s,
const int qscale = s->c.qscale;
{
- OPEN_READER(re, &s->c.gb);
+ OPEN_READER(re, &s->gb);
i = -1;
// special case for first coefficient, no need to add second VLC table
- UPDATE_CACHE(re, &s->c.gb);
- if (((int32_t) GET_CACHE(re, &s->c.gb)) < 0) {
+ UPDATE_CACHE(re, &s->gb);
+ if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
level = (3 * qscale * quant_matrix[0]) >> 5;
level = (level - 1) | 1;
- if (GET_CACHE(re, &s->c.gb) & 0x40000000)
+ if (GET_CACHE(re, &s->gb) & 0x40000000)
level = -level;
block[0] = level;
i++;
- SKIP_BITS(re, &s->c.gb, 2);
- if (((int32_t) GET_CACHE(re, &s->c.gb)) <= (int32_t) 0xBFFFFFFF)
+ SKIP_BITS(re, &s->gb, 2);
+ if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
for (;;) {
- GET_RL_VLC(level, run, re, &s->c.gb, ff_mpeg1_rl_vlc,
+ GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc,
TEX_VLC_BITS, 2, 0);
if (level != 0) {
@@ -171,22 +172,22 @@ static inline int mpeg1_decode_block_inter(Mpeg12SliceContext *const s,
j = scantable[i];
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
level = (level - 1) | 1;
- level = (level ^ SHOW_SBITS(re, &s->c.gb, 1)) -
- SHOW_SBITS(re, &s->c.gb, 1);
- SKIP_BITS(re, &s->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
+ SHOW_SBITS(re, &s->gb, 1);
+ SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->c.gb, 6) + 1;
- LAST_SKIP_BITS(re, &s->c.gb, 6);
- UPDATE_CACHE(re, &s->c.gb);
- level = SHOW_SBITS(re, &s->c.gb, 8);
- SKIP_BITS(re, &s->c.gb, 8);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1;
+ LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 8);
+ SKIP_BITS(re, &s->gb, 8);
if (level == -128) {
- level = SHOW_UBITS(re, &s->c.gb, 8) - 256;
- SKIP_BITS(re, &s->c.gb, 8);
+ level = SHOW_UBITS(re, &s->gb, 8) - 256;
+ SKIP_BITS(re, &s->gb, 8);
} else if (level == 0) {
- level = SHOW_UBITS(re, &s->c.gb, 8);
- SKIP_BITS(re, &s->c.gb, 8);
+ level = SHOW_UBITS(re, &s->gb, 8);
+ SKIP_BITS(re, &s->gb, 8);
}
i += run;
if (i > MAX_INDEX)
@@ -204,13 +205,13 @@ static inline int mpeg1_decode_block_inter(Mpeg12SliceContext *const s,
}
block[j] = level;
- if (((int32_t) GET_CACHE(re, &s->c.gb)) <= (int32_t) 0xBFFFFFFF)
+ if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
break;
- UPDATE_CACHE(re, &s->c.gb);
+ UPDATE_CACHE(re, &s->gb);
}
end:
- LAST_SKIP_BITS(re, &s->c.gb, 2);
- CLOSE_READER(re, &s->c.gb);
+ LAST_SKIP_BITS(re, &s->gb, 2);
+ CLOSE_READER(re, &s->gb);
}
check_scantable_index(s, i);
@@ -231,7 +232,7 @@ static inline int mpeg2_decode_block_non_intra(Mpeg12SliceContext *const s,
mismatch = 1;
{
- OPEN_READER(re, &s->c.gb);
+ OPEN_READER(re, &s->gb);
i = -1;
if (n < 4)
quant_matrix = s->c.inter_matrix;
@@ -239,22 +240,22 @@ static inline int mpeg2_decode_block_non_intra(Mpeg12SliceContext *const s,
quant_matrix = s->c.chroma_inter_matrix;
// Special case for first coefficient, no need to add second VLC table.
- UPDATE_CACHE(re, &s->c.gb);
- if (((int32_t) GET_CACHE(re, &s->c.gb)) < 0) {
+ UPDATE_CACHE(re, &s->gb);
+ if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
level = (3 * qscale * quant_matrix[0]) >> 5;
- if (GET_CACHE(re, &s->c.gb) & 0x40000000)
+ if (GET_CACHE(re, &s->gb) & 0x40000000)
level = -level;
block[0] = level;
mismatch ^= level;
i++;
- SKIP_BITS(re, &s->c.gb, 2);
- if (((int32_t) GET_CACHE(re, &s->c.gb)) <= (int32_t) 0xBFFFFFFF)
+ SKIP_BITS(re, &s->gb, 2);
+ if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
goto end;
}
/* now quantify & encode AC coefficients */
for (;;) {
- GET_RL_VLC(level, run, re, &s->c.gb, ff_mpeg1_rl_vlc,
+ GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc,
TEX_VLC_BITS, 2, 0);
if (level != 0) {
@@ -263,16 +264,16 @@ static inline int mpeg2_decode_block_non_intra(Mpeg12SliceContext *const s,
break;
j = scantable[i];
level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
- level = (level ^ SHOW_SBITS(re, &s->c.gb, 1)) -
- SHOW_SBITS(re, &s->c.gb, 1);
- SKIP_BITS(re, &s->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
+ SHOW_SBITS(re, &s->gb, 1);
+ SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->c.gb, 6) + 1;
- LAST_SKIP_BITS(re, &s->c.gb, 6);
- UPDATE_CACHE(re, &s->c.gb);
- level = SHOW_SBITS(re, &s->c.gb, 12);
- SKIP_BITS(re, &s->c.gb, 12);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1;
+ LAST_SKIP_BITS(re, &s->gb, 6);
+ UPDATE_CACHE(re, &s->gb);
+ level = SHOW_SBITS(re, &s->gb, 12);
+ SKIP_BITS(re, &s->gb, 12);
i += run;
if (i > MAX_INDEX)
@@ -288,13 +289,13 @@ static inline int mpeg2_decode_block_non_intra(Mpeg12SliceContext *const s,
mismatch ^= level;
block[j] = level;
- if (((int32_t) GET_CACHE(re, &s->c.gb)) <= (int32_t) 0xBFFFFFFF)
+ if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
break;
- UPDATE_CACHE(re, &s->c.gb);
+ UPDATE_CACHE(re, &s->gb);
}
end:
- LAST_SKIP_BITS(re, &s->c.gb, 2);
- CLOSE_READER(re, &s->c.gb);
+ LAST_SKIP_BITS(re, &s->gb, 2);
+ CLOSE_READER(re, &s->gb);
}
block[63] ^= (mismatch & 1);
@@ -323,7 +324,7 @@ static inline int mpeg2_decode_block_intra(Mpeg12SliceContext *const s,
quant_matrix = s->c.chroma_intra_matrix;
component = (n & 1) + 1;
}
- diff = decode_dc(&s->c.gb, component);
+ diff = decode_dc(&s->gb, component);
dc = s->c.last_dc[component];
dc += diff;
s->c.last_dc[component] = dc;
@@ -337,11 +338,11 @@ static inline int mpeg2_decode_block_intra(Mpeg12SliceContext *const s,
rl_vlc = ff_mpeg1_rl_vlc;
{
- OPEN_READER(re, &s->c.gb);
+ OPEN_READER(re, &s->gb);
/* now quantify & encode AC coefficients */
for (;;) {
- UPDATE_CACHE(re, &s->c.gb);
- GET_RL_VLC(level, run, re, &s->c.gb, rl_vlc,
+ UPDATE_CACHE(re, &s->gb);
+ GET_RL_VLC(level, run, re, &s->gb, rl_vlc,
TEX_VLC_BITS, 2, 0);
if (level == 127) {
@@ -352,15 +353,15 @@ static inline int mpeg2_decode_block_intra(Mpeg12SliceContext *const s,
break;
j = scantable[i];
level = (level * qscale * quant_matrix[j]) >> 4;
- level = (level ^ SHOW_SBITS(re, &s->c.gb, 1)) -
- SHOW_SBITS(re, &s->c.gb, 1);
- LAST_SKIP_BITS(re, &s->c.gb, 1);
+ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
+ SHOW_SBITS(re, &s->gb, 1);
+ LAST_SKIP_BITS(re, &s->gb, 1);
} else {
/* escape */
- run = SHOW_UBITS(re, &s->c.gb, 6) + 1;
- SKIP_BITS(re, &s->c.gb, 6);
- level = SHOW_SBITS(re, &s->c.gb, 12);
- LAST_SKIP_BITS(re, &s->c.gb, 12);
+ run = SHOW_UBITS(re, &s->gb, 6) + 1;
+ SKIP_BITS(re, &s->gb, 6);
+ level = SHOW_SBITS(re, &s->gb, 12);
+ LAST_SKIP_BITS(re, &s->gb, 12);
i += run;
if (i > MAX_INDEX)
break;
@@ -376,7 +377,7 @@ static inline int mpeg2_decode_block_intra(Mpeg12SliceContext *const s,
mismatch ^= level;
block[j] = level;
}
- CLOSE_READER(re, &s->c.gb);
+ CLOSE_READER(re, &s->gb);
}
block[63] ^= mismatch & 1;
@@ -387,8 +388,8 @@ static inline int mpeg2_decode_block_intra(Mpeg12SliceContext *const s,
static inline int get_dmv(Mpeg12SliceContext *const s)
{
- if (get_bits1(&s->c.gb))
- return 1 - (get_bits1(&s->c.gb) << 1);
+ if (get_bits1(&s->gb))
+ return 1 - (get_bits1(&s->gb) << 1);
else
return 0;
}
@@ -439,8 +440,8 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
switch (s->c.pict_type) {
default:
case AV_PICTURE_TYPE_I:
- if (get_bits1(&s->c.gb) == 0) {
- if (get_bits1(&s->c.gb) == 0) {
+ if (get_bits1(&s->gb) == 0) {
+ if (get_bits1(&s->gb) == 0) {
av_log(s->c.avctx, AV_LOG_ERROR,
"Invalid mb type in I-frame at %d %d\n",
s->c.mb_x, s->c.mb_y);
@@ -452,7 +453,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
}
break;
case AV_PICTURE_TYPE_P:
- mb_type = get_vlc2(&s->c.gb, ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 1);
+ mb_type = get_vlc2(&s->gb, ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 1);
if (mb_type < 0) {
av_log(s->c.avctx, AV_LOG_ERROR,
"Invalid mb type in P-frame at %d %d\n", s->c.mb_x, s->c.mb_y);
@@ -460,7 +461,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
}
break;
case AV_PICTURE_TYPE_B:
- mb_type = get_vlc2(&s->c.gb, ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 1);
+ mb_type = get_vlc2(&s->gb, ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 1);
if (mb_type < 0) {
av_log(s->c.avctx, AV_LOG_ERROR,
"Invalid mb type in B-frame at %d %d\n", s->c.mb_x, s->c.mb_y);
@@ -480,15 +481,15 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
// FIXME: add an interlaced_dct coded var?
if (s->c.picture_structure == PICT_FRAME &&
!s->c.frame_pred_frame_dct)
- s->c.interlaced_dct = get_bits1(&s->c.gb);
+ s->c.interlaced_dct = get_bits1(&s->gb);
if (IS_QUANT(mb_type))
- s->c.qscale = mpeg_get_qscale(&s->c.gb, s->c.q_scale_type);
+ s->c.qscale = mpeg_get_qscale(&s->gb, s->c.q_scale_type);
if (s->c.concealment_motion_vectors) {
/* just parse them */
if (s->c.picture_structure != PICT_FRAME)
- skip_bits1(&s->c.gb); /* field select */
+ skip_bits1(&s->gb); /* field select */
s->c.mv[0][0][0] =
s->c.last_mv[0][0][0] =
@@ -499,7 +500,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
s->c.last_mv[0][1][1] = mpeg_decode_motion(s, s->c.mpeg_f_code[0][1],
s->c.last_mv[0][0][1]);
- check_marker(s->c.avctx, &s->c.gb, "after concealment_motion_vectors");
+ check_marker(s->c.avctx, &s->gb, "after concealment_motion_vectors");
} else {
/* reset mv prediction */
memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
@@ -512,7 +513,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
return ret;
} else {
for (i = 0; i < 6; i++) {
- ret = ff_mpeg1_decode_block_intra(&s->c.gb,
+ ret = ff_mpeg1_decode_block_intra(&s->gb,
s->c.intra_matrix,
s->c.intra_scantable.permutated,
s->c.last_dc, s->c.block[i],
@@ -532,7 +533,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
if (s->c.picture_structure == PICT_FRAME) {
if (s->c.picture_structure == PICT_FRAME
&& !s->c.frame_pred_frame_dct)
- s->c.interlaced_dct = get_bits1(&s->c.gb);
+ s->c.interlaced_dct = get_bits1(&s->gb);
s->c.mv_type = MV_TYPE_16X16;
} else {
s->c.mv_type = MV_TYPE_FIELD;
@@ -541,7 +542,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
}
if (IS_QUANT(mb_type))
- s->c.qscale = mpeg_get_qscale(&s->c.gb, s->c.q_scale_type);
+ s->c.qscale = mpeg_get_qscale(&s->gb, s->c.q_scale_type);
s->c.last_mv[0][0][0] = 0;
s->c.last_mv[0][0][1] = 0;
@@ -556,13 +557,13 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
if (s->c.picture_structure == PICT_FRAME && s->c.frame_pred_frame_dct) {
motion_type = MT_FRAME;
} else {
- motion_type = get_bits(&s->c.gb, 2);
+ motion_type = get_bits(&s->gb, 2);
if (s->c.picture_structure == PICT_FRAME && HAS_CBP(mb_type))
- s->c.interlaced_dct = get_bits1(&s->c.gb);
+ s->c.interlaced_dct = get_bits1(&s->gb);
}
if (IS_QUANT(mb_type))
- s->c.qscale = mpeg_get_qscale(&s->c.gb, s->c.q_scale_type);
+ s->c.qscale = mpeg_get_qscale(&s->gb, s->c.q_scale_type);
/* motion vectors */
s->c.mv_dir = MB_TYPE_MV_2_MV_DIR(mb_type);
@@ -599,7 +600,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
if (HAS_MV(mb_type, i)) {
/* MT_16X8 */
for (j = 0; j < 2; j++) {
- s->c.field_select[i][j] = get_bits1(&s->c.gb);
+ s->c.field_select[i][j] = get_bits1(&s->gb);
for (k = 0; k < 2; k++) {
val = mpeg_decode_motion(s, s->c.mpeg_f_code[i][k],
s->c.last_mv[i][j][k]);
@@ -618,7 +619,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
for (i = 0; i < 2; i++) {
if (HAS_MV(mb_type, i)) {
for (j = 0; j < 2; j++) {
- s->c.field_select[i][j] = get_bits1(&s->c.gb);
+ s->c.field_select[i][j] = get_bits1(&s->gb);
val = mpeg_decode_motion(s, s->c.mpeg_f_code[i][0],
s->c.last_mv[i][j][0]);
s->c.last_mv[i][j][0] = val;
@@ -637,7 +638,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
for (i = 0; i < 2; i++) {
if (HAS_MV(mb_type, i)) {
- s->c.field_select[i][0] = get_bits1(&s->c.gb);
+ s->c.field_select[i][0] = get_bits1(&s->gb);
for (k = 0; k < 2; k++) {
val = mpeg_decode_motion(s, s->c.mpeg_f_code[i][k],
s->c.last_mv[i][0][k]);
@@ -715,10 +716,10 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
if (HAS_CBP(mb_type)) {
s->c.bdsp.clear_blocks(s->c.block[0]);
- cbp = get_vlc2(&s->c.gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
+ cbp = get_vlc2(&s->gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
if (mb_block_count > 6) {
cbp *= 1 << mb_block_count - 6;
- cbp |= get_bits(&s->c.gb, mb_block_count - 6);
+ cbp |= get_bits(&s->gb, mb_block_count - 6);
s->c.bdsp.clear_blocks(s->c.block[6]);
}
if (cbp <= 0) {
@@ -1365,17 +1366,17 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
av_assert0(mb_y < s->c.mb_height);
- ret = init_get_bits8(&s->c.gb, *buf, buf_size);
+ ret = init_get_bits8(&s->gb, *buf, buf_size);
if (ret < 0)
return ret;
if (s->c.codec_id != AV_CODEC_ID_MPEG1VIDEO && s->c.mb_height > 2800/16)
- skip_bits(&s->c.gb, 3);
+ skip_bits(&s->gb, 3);
ff_mpeg1_clean_buffers(&s->c);
s->c.interlaced_dct = 0;
- s->c.qscale = mpeg_get_qscale(&s->c.gb, s->c.q_scale_type);
+ s->c.qscale = mpeg_get_qscale(&s->gb, s->c.q_scale_type);
if (s->c.qscale == 0) {
av_log(s->c.avctx, AV_LOG_ERROR, "qscale == 0\n");
@@ -1383,16 +1384,16 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
/* extra slice info */
- if (skip_1stop_8data_bits(&s->c.gb) < 0)
+ if (skip_1stop_8data_bits(&s->gb) < 0)
return AVERROR_INVALIDDATA;
s->c.mb_x = 0;
if (mb_y == 0 && s->c.codec_tag == AV_RL32("SLIF")) {
- skip_bits1(&s->c.gb);
+ skip_bits1(&s->gb);
} else {
- while (get_bits_left(&s->c.gb) > 0) {
- int code = get_vlc2(&s->c.gb, ff_mbincr_vlc,
+ while (get_bits_left(&s->gb) > 0) {
+ int code = get_vlc2(&s->gb, ff_mbincr_vlc,
MBINCR_VLC_BITS, 2);
if (code < 0) {
av_log(s->c.avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
@@ -1509,7 +1510,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
s->c.mb_y += 1 << field_pic;
if (s->c.mb_y >= s->c.mb_height) {
- int left = get_bits_left(&s->c.gb);
+ int left = get_bits_left(&s->gb);
int is_d10 = s->c.chroma_format == CHROMA_422 &&
s->c.pict_type == AV_PICTURE_TYPE_I &&
avctx->profile == 0 && avctx->level == 5 &&
@@ -1519,7 +1520,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
/* vbv_delay == 0xBBB || 0xE10 */;
if (left >= 32 && !is_d10) {
- GetBitContext gb = s->c.gb;
+ GetBitContext gb = s->gb;
align_get_bits(&gb);
if (show_bits(&gb, 24) == 0x060E2B) {
av_log(avctx, AV_LOG_DEBUG, "Invalid MXF data found in video stream\n");
@@ -1532,10 +1533,10 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
if (left < 0 ||
- (left && show_bits(&s->c.gb, FFMIN(left, 23)) && !is_d10) ||
+ (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10) ||
((avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) && left > 8)) {
av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X at %d %d\n",
- left, left>0 ? show_bits(&s->c.gb, FFMIN(left, 23)) : 0, s->c.mb_x, s->c.mb_y);
+ left, left>0 ? show_bits(&s->gb, FFMIN(left, 23)) : 0, s->c.mb_x, s->c.mb_y);
return AVERROR_INVALIDDATA;
} else
goto eos;
@@ -1544,13 +1545,13 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
// in cases where the slice is completely outside the visible
// area, we detect this here instead of running into the end expecting
// more data
- left = get_bits_left(&s->c.gb);
+ left = get_bits_left(&s->gb);
if (s->c.mb_y >= ((s->c.height + 15) >> 4) &&
!s->c.progressive_sequence &&
left <= 25 &&
left >= 0 &&
s->c.mb_skip_run == -1 &&
- (!left || show_bits(&s->c.gb, left) == 0))
+ (!left || show_bits(&s->gb, left) == 0))
goto eos;
ff_init_block_index(&s->c);
@@ -1561,7 +1562,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
/* read increment again */
s->c.mb_skip_run = 0;
for (;;) {
- int code = get_vlc2(&s->c.gb, ff_mbincr_vlc,
+ int code = get_vlc2(&s->gb, ff_mbincr_vlc,
MBINCR_VLC_BITS, 2);
if (code < 0) {
av_log(s->c.avctx, AV_LOG_ERROR, "mb incr damaged\n");
@@ -1571,7 +1572,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
if (code == 33) {
s->c.mb_skip_run += 33;
} else if (code == 35) {
- if (s->c.mb_skip_run != 0 || show_bits(&s->c.gb, 15) != 0) {
+ if (s->c.mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
av_log(s->c.avctx, AV_LOG_ERROR, "slice mismatch\n");
return AVERROR_INVALIDDATA;
}
@@ -1620,11 +1621,11 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
}
eos: // end of slice
- if (get_bits_left(&s->c.gb) < 0) {
- av_log(s->c.avctx, AV_LOG_ERROR, "overread %d\n", -get_bits_left(&s->c.gb));
+ if (get_bits_left(&s->gb) < 0) {
+ av_log(s->c.avctx, AV_LOG_ERROR, "overread %d\n", -get_bits_left(&s->gb));
return AVERROR_INVALIDDATA;
}
- *buf += (get_bits_count(&s->c.gb) - 1) / 8;
+ *buf += (get_bits_count(&s->gb) - 1) / 8;
ff_dlog(s->c.avctx, "Slice start:%d %d end:%d %d\n", s->c.resync_mb_x, s->c.resync_mb_y, s->c.mb_x, s->c.mb_y);
return 0;
}
@@ -1632,7 +1633,7 @@ eos: // end of slice
static int slice_decode_thread(AVCodecContext *c, void *arg)
{
Mpeg12SliceContext *const s = *(void **) arg;
- const uint8_t *buf = s->c.gb.buffer;
+ const uint8_t *buf = s->gb.buffer;
int mb_y = s->c.start_mb_y;
const int field_pic = s->c.picture_structure != PICT_FRAME;
@@ -1642,7 +1643,7 @@ static int slice_decode_thread(AVCodecContext *c, void *arg)
uint32_t start_code;
int ret;
- ret = mpeg_decode_slice(s, mb_y, &buf, s->c.gb.buffer_end - buf);
+ ret = mpeg_decode_slice(s, mb_y, &buf, s->gb.buffer_end - buf);
emms_c();
ff_dlog(c, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
ret, s->c.resync_mb_x, s->c.resync_mb_y, s->c.mb_x, s->c.mb_y,
@@ -1664,7 +1665,7 @@ static int slice_decode_thread(AVCodecContext *c, void *arg)
return 0;
start_code = -1;
- buf = avpriv_find_start_code(buf, s->c.gb.buffer_end, &start_code);
+ buf = avpriv_find_start_code(buf, s->gb.buffer_end, &start_code);
if (start_code < SLICE_MIN_START_CODE || start_code > SLICE_MAX_START_CODE)
return AVERROR_INVALIDDATA;
mb_y = start_code - SLICE_MIN_START_CODE;
@@ -2516,7 +2517,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
if (ret < 0)
return ret;
}
- ret = init_get_bits8(&thread_context->c.gb, buf_ptr, input_size);
+ ret = init_get_bits8(&thread_context->gb, buf_ptr, input_size);
if (ret < 0)
return ret;
s->slice_count++;
@@ -2762,7 +2763,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
{
IPUContext *s = avctx->priv_data;
MPVContext *const m = &s->m.c;
- GetBitContext *gb = &m->gb;
+ GetBitContext *const gb = &s->m.gb;
int ret;
// Check for minimal intra MB size (considering mb header, luma & chroma dc VLC, ac EOB VLC)
@@ -2810,13 +2811,13 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
skip_bits1(gb);
if (intraquant)
- m->qscale = mpeg_get_qscale(&m->gb, m->q_scale_type);
+ m->qscale = mpeg_get_qscale(gb, m->q_scale_type);
memset(s->block, 0, sizeof(s->block));
for (int n = 0; n < 6; n++) {
if (s->flags & 0x80) {
- ret = ff_mpeg1_decode_block_intra(&m->gb,
+ ret = ff_mpeg1_decode_block_intra(gb,
m->intra_matrix,
m->intra_scantable.permutated,
m->last_dc, s->block[n],
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 2581641d0c..4b3c7f894d 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -30,7 +30,6 @@
#include "blockdsp.h"
#include "error_resilience.h"
-#include "get_bits.h"
#include "h264chroma.h"
#include "h263dsp.h"
#include "hpeldsp.h"
@@ -275,9 +274,6 @@ typedef struct MpegEncContext {
int inter_intra_pred;
int mspel;
- /* decompression specific */
- GetBitContext gb;
-
/* MPEG-2-specific - I wished not to have to support this mess. */
int progressive_sequence;
int mpeg_f_code[2][2];
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 33/48] avcodec/mpeg12dec: Don't use MPVContext.block
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (31 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 32/48] avcodec/mpeg12dec: Move MpegEncContext.gb to Mpeg12SliceContext Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 34/48] avcodec/mpegvideo: Move fields only used by H.263 decoders to H263DecCtx Andreas Rheinhardt
` (14 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Instead add the necessary blocks directly into Mpeg12SliceContext.
This allows to completely remove MPVContext.block.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 40 ++++++++++++++++++++------------------
libavcodec/mpeg4videodec.c | 1 -
libavcodec/mpegvideo.c | 23 ++--------------------
libavcodec/mpegvideo.h | 2 --
4 files changed, 23 insertions(+), 43 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 8ca26c0d37..db6f9d66a5 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -73,6 +73,8 @@ enum Mpeg2ClosedCaptionsFormat {
typedef struct Mpeg12SliceContext {
MPVContext c;
GetBitContext gb;
+
+ DECLARE_ALIGNED_32(int16_t, block)[12][64];
} Mpeg12SliceContext;
typedef struct Mpeg1Context {
@@ -472,10 +474,10 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
ff_tlog(s->c.avctx, "mb_type=%x\n", mb_type);
// motion_type = 0; /* avoid warning */
if (IS_INTRA(mb_type)) {
- s->c.bdsp.clear_blocks(s->c.block[0]);
+ s->c.bdsp.clear_blocks(s->block[0]);
if (!s->c.chroma_y_shift)
- s->c.bdsp.clear_blocks(s->c.block[6]);
+ s->c.bdsp.clear_blocks(s->block[6]);
/* compute DCT type */
// FIXME: add an interlaced_dct coded var?
@@ -509,14 +511,14 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
if (s->c.codec_id == AV_CODEC_ID_MPEG2VIDEO) {
for (i = 0; i < mb_block_count; i++)
- if ((ret = mpeg2_decode_block_intra(s, s->c.block[i], i)) < 0)
+ if ((ret = mpeg2_decode_block_intra(s, s->block[i], i)) < 0)
return ret;
} else {
for (i = 0; i < 6; i++) {
ret = ff_mpeg1_decode_block_intra(&s->gb,
s->c.intra_matrix,
s->c.intra_scantable.permutated,
- s->c.last_dc, s->c.block[i],
+ s->c.last_dc, s->block[i],
i, s->c.qscale);
if (ret < 0) {
av_log(s->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
@@ -714,13 +716,13 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
s->c.mb_intra = 0;
s->c.last_dc[0] = s->c.last_dc[1] = s->c.last_dc[2] = 128 << s->c.intra_dc_precision;
if (HAS_CBP(mb_type)) {
- s->c.bdsp.clear_blocks(s->c.block[0]);
+ s->c.bdsp.clear_blocks(s->block[0]);
cbp = get_vlc2(&s->gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
if (mb_block_count > 6) {
cbp *= 1 << mb_block_count - 6;
cbp |= get_bits(&s->gb, mb_block_count - 6);
- s->c.bdsp.clear_blocks(s->c.block[6]);
+ s->c.bdsp.clear_blocks(s->block[6]);
}
if (cbp <= 0) {
av_log(s->c.avctx, AV_LOG_ERROR,
@@ -733,7 +735,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
for (i = 0; i < mb_block_count; i++) {
if (cbp & (1 << 11)) {
- if ((ret = mpeg2_decode_block_non_intra(s, s->c.block[i], i)) < 0)
+ if ((ret = mpeg2_decode_block_non_intra(s, s->block[i], i)) < 0)
return ret;
} else {
s->c.block_last_index[i] = -1;
@@ -743,7 +745,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
} else {
for (i = 0; i < 6; i++) {
if (cbp & 32) {
- if ((ret = mpeg1_decode_block_inter(s, s->c.block[i], i)) < 0)
+ if ((ret = mpeg1_decode_block_inter(s, s->block[i], i)) < 0)
return ret;
} else {
s->c.block_last_index[i] = -1;
@@ -1498,7 +1500,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
s->c.dest[1] +=(16 >> lowres) >> s->c.chroma_x_shift;
s->c.dest[2] +=(16 >> lowres) >> s->c.chroma_x_shift;
- ff_mpv_reconstruct_mb(&s->c, s->c.block);
+ ff_mpv_reconstruct_mb(&s->c, s->block);
if (++s->c.mb_x >= s->c.mb_width) {
const int mb_size = 16 >> s->c.avctx->lowres;
@@ -2755,7 +2757,6 @@ typedef struct IPUContext {
Mpeg12SliceContext m;
int flags;
- DECLARE_ALIGNED(32, int16_t, block)[6][64];
} IPUContext;
static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
@@ -2764,6 +2765,7 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
IPUContext *s = avctx->priv_data;
MPVContext *const m = &s->m.c;
GetBitContext *const gb = &s->m.gb;
+ int16_t (*const block)[64] = s->m.block;
int ret;
// Check for minimal intra MB size (considering mb header, luma & chroma dc VLC, ac EOB VLC)
@@ -2813,17 +2815,17 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
if (intraquant)
m->qscale = mpeg_get_qscale(gb, m->q_scale_type);
- memset(s->block, 0, sizeof(s->block));
+ memset(block, 0, 6 * sizeof(*block));
for (int n = 0; n < 6; n++) {
if (s->flags & 0x80) {
ret = ff_mpeg1_decode_block_intra(gb,
m->intra_matrix,
m->intra_scantable.permutated,
- m->last_dc, s->block[n],
+ m->last_dc, block[n],
n, m->qscale);
} else {
- ret = mpeg2_decode_block_intra(&s->m, s->block[n], n);
+ ret = mpeg2_decode_block_intra(&s->m, block[n], n);
}
if (ret < 0)
@@ -2831,17 +2833,17 @@ static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
}
m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x,
- frame->linesize[0], s->block[0]);
+ frame->linesize[0], block[0]);
m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x + 8,
- frame->linesize[0], s->block[1]);
+ frame->linesize[0], block[1]);
m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x,
- frame->linesize[0], s->block[2]);
+ frame->linesize[0], block[2]);
m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x + 8,
- frame->linesize[0], s->block[3]);
+ frame->linesize[0], block[3]);
m->idsp.idct_put(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
- frame->linesize[1], s->block[4]);
+ frame->linesize[1], block[4]);
m->idsp.idct_put(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
- frame->linesize[2], s->block[5]);
+ frame->linesize[2], block[5]);
}
}
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index c6ed9d31bb..ee78e7119f 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3830,7 +3830,6 @@ static av_cold void clear_context(MpegEncContext *s)
memset(s->thread_context, 0, sizeof(s->thread_context));
- s->block = NULL;
s->ac_val_base = NULL;
s->ac_val = NULL;
memset(&s->sc, 0, sizeof(s->sc));
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 7ef0dacc80..9c3589752c 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -115,31 +115,15 @@ av_cold void ff_mpv_idct_init(MpegEncContext *s)
s->idsp.idct_permutation);
}
-static av_cold int init_duplicate_context(MpegEncContext *s)
-{
- if (!s->encoding) {
- s->block = av_mallocz(12 * sizeof(*s->block));
- if (!s->block)
- return AVERROR(ENOMEM);
- }
-
- return 0;
-}
-
av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
{
- int nb_slices = s->slice_context_count, ret;
+ const int nb_slices = s->slice_context_count;
const size_t slice_size = s->slice_ctx_size;
- /* We initialize the copies before the original so that
- * fields allocated in init_duplicate_context are NULL after
- * copying. This prevents double-frees upon allocation error. */
for (int i = 1; i < nb_slices; i++) {
s->thread_context[i] = av_memdup(s, slice_size);
if (!s->thread_context[i])
return AVERROR(ENOMEM);
- if ((ret = init_duplicate_context(s->thread_context[i])) < 0)
- return ret;
s->thread_context[i]->start_mb_y =
(s->mb_height * (i ) + nb_slices / 2) / nb_slices;
s->thread_context[i]->end_mb_y =
@@ -148,7 +132,7 @@ av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
s->start_mb_y = 0;
s->end_mb_y = nb_slices > 1 ? (s->mb_height + nb_slices / 2) / nb_slices
: s->mb_height;
- return init_duplicate_context(s);
+ return 0;
}
static av_cold void free_duplicate_context(MpegEncContext *s)
@@ -160,8 +144,6 @@ static av_cold void free_duplicate_context(MpegEncContext *s)
av_freep(&s->sc.scratchpad_buf);
s->sc.obmc_scratchpad = NULL;
s->sc.linesize = 0;
-
- av_freep(&s->block);
}
static av_cold void free_duplicate_contexts(MpegEncContext *s)
@@ -177,7 +159,6 @@ int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
{
#define COPY(M) \
M(ScratchpadContext, sc) \
- M(void*, block) \
M(int, start_mb_y) \
M(int, end_mb_y) \
M(int16_t*, dc_val) \
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 4b3c7f894d..4b215bf65f 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -302,8 +302,6 @@ typedef struct MpegEncContext {
int interlaced_dct;
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
- int16_t (*block)[64];
-
#define SLICE_OK 0
#define SLICE_ERROR -1
#define SLICE_END -2 ///<end marker found
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 34/48] avcodec/mpegvideo: Move fields only used by H.263 decoders to H263DecCtx
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (32 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 33/48] avcodec/mpeg12dec: Don't use MPVContext.block Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 35/48] avcodec/mpegvideo: Move mb_num_left to {H263, RV34}DecContext Andreas Rheinhardt
` (13 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/flvdec.c | 4 ++--
libavcodec/h263dec.c | 28 +++++++++++++-------------
libavcodec/h263dec.h | 20 +++++++++++++++++++
libavcodec/intelh263dec.c | 8 ++++----
libavcodec/ituh263dec.c | 40 +++++++++++++++++++-------------------
libavcodec/mpeg4videodec.c | 36 ++++++++++++++++++----------------
libavcodec/mpegvideo.h | 15 --------------
libavcodec/mpegvideo_dec.c | 1 -
libavcodec/nvdec_mpeg4.c | 2 +-
libavcodec/rv10.c | 12 ++++++------
10 files changed, 86 insertions(+), 80 deletions(-)
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index f2d0b642b7..c70d79f483 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -89,13 +89,13 @@ int ff_flv_decode_picture_header(H263DecContext *const h)
skip_bits1(&h->gb); /* deblocking flag */
h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
- h->c.h263_long_vectors = 0;
+ h->h263_long_vectors = 0;
/* PEI */
if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA;
- if (h->c.ehc_mode)
+ if (h->ehc_mode)
h->c.avctx->sample_aspect_ratio= (AVRational){1,2};
if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index fc63e8a5d8..541eb34789 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -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->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 */
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,
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) {
h->c.mb_x = 0;
@@ -324,7 +324,7 @@ static int decode_slice(H263DecContext *const h)
get_bits_left(&h->gb) >= 48 &&
show_bits(&h->gb, 24) == 0x4010 &&
!h->c.data_partitioning)
- h->c.padding_bug_score += 32;
+ h->padding_bug_score += 32;
/* try to detect the padding bug */
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;
if (bits_left == 0) {
- h->c.padding_bug_score += 16;
+ h->padding_bug_score += 16;
} else if (bits_left != 1) {
int v = show_bits(&h->gb, 8);
v |= 0x7F >> (7 - (bits_count & 7));
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) &&
bits_left <= 16)
- h->c.padding_bug_score += 4;
+ h->padding_bug_score += 4;
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 &&
!h->c.data_partitioning) {
- h->c.padding_bug_score += 32;
+ h->padding_bug_score += 32;
}
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 &&
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.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;
else
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,
"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,
ER_MB_END & part_mask);
@@ -432,10 +432,10 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
/* no supplementary picture */
if (buf_size == 0) {
/* 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)
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
* in display order, but with the props from the last input
* packet so that the stream's end time is correct. */
@@ -551,7 +551,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
return ret;
- if (!h->c.divx_packed)
+ if (!h->divx_packed)
ff_thread_finish_setup(avctx);
if (avctx->hwaccel) {
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index dfa056f08e..dd63eca5be 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -50,6 +50,26 @@ typedef struct H263DecContext {
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);
GetBitContext last_resync_gb; ///< used to search for the next resync marker
diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c
index 3800e6f1cc..1640defaab 100644
--- a/libavcodec/intelh263dec.c
+++ b/libavcodec/intelh263dec.c
@@ -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.h263_long_vectors = get_bits1(&h->gb);
+ h->h263_long_vectors = get_bits1(&h->gb);
if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n");
return -1; /* SAC: off */
}
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) {
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))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
if (get_bits1(&h->gb))
- h->c.pb_frame = 2;
+ h->pb_frame = 2;
if (get_bits(&h->gb, 5))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
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);
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, 2); //dbquant
}
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index c19134b0d4..11be8189a6 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -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->c.obmc ? " AP" : "",
h->c.umvplus ? " UMV" : "",
- h->c.h263_long_vectors ? " LONG" : "",
+ h->h263_long_vectors ? " LONG" : "",
h263_plus ? " +" : "",
h->c.h263_aic ? " AIC" : "",
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;
/* modulo decoding */
- if (!h->c.h263_long_vectors) {
+ if (!h->h263_long_vectors) {
val = sign_extend(val, 5 + f_code);
} else {
/* 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) {
/* DC coef */
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);
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);
if (diff < 0)
return -1;
@@ -556,7 +556,7 @@ static int h263_decode_block(H263DecContext *const h, int16_t block[64],
level = level & 0xff; /* handle wrap round */
h->c.last_dc[component] = level;
} else {
- h->c.rv10_first_dc_coded[component] = 1;
+ h->rv10_first_dc_coded[component] = 1;
}
} else {
level = get_bits(&h->gb, 8);
@@ -816,8 +816,8 @@ int ff_h263_decode_mb(H263DecContext *const h)
if (h->c.mb_intra)
goto intra;
- if (h->c.pb_frame && get_bits1(&h->gb))
- pb_mv_count = h263_get_modb(&h->gb, h->c.pb_frame, &cbpb);
+ if (h->pb_frame && get_bits1(&h->gb))
+ 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);
if (cbpy < 0) {
@@ -1029,8 +1029,8 @@ intra:
}else
h->c.ac_pred = 0;
- if (h->c.pb_frame && get_bits1(&h->gb))
- pb_mv_count = h263_get_modb(&h->gb, h->c.pb_frame, &cbpb);
+ if (h->pb_frame && get_bits1(&h->gb))
+ 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);
if(cbpy<0){
av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",
@@ -1042,7 +1042,7 @@ intra:
h263_decode_dquant(h);
}
- pb_mv_count += !!h->c.pb_frame;
+ pb_mv_count += !!h->pb_frame;
}
while(pb_mv_count--){
@@ -1057,7 +1057,7 @@ intra:
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;
if (h->c.obmc && !h->c.mb_intra) {
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.h263_long_vectors = get_bits1(&h->gb);
+ h->h263_long_vectors = get_bits1(&h->gb);
if (get_bits1(&h->gb) != 0) {
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.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);
skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
@@ -1174,7 +1174,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
/* OPPTYPE */
format = get_bits(&h->gb, 3);
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 */
if (get_bits1(&h->gb) != 0) {
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) {
case 0: h->c.pict_type = AV_PICTURE_TYPE_I; 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 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO
default:
@@ -1251,13 +1251,13 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
height = ff_h263_format[format][1];
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))
return -1;
h->c.width = width;
h->c.height = height;
- if (h->c.custom_pcf) {
+ if (h->custom_pcf) {
h->c.avctx->framerate.num = 1800000;
h->c.avctx->framerate.den = 1000 + get_bits1(&h->gb);
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
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);
- if (h->c.pb_frame) {
+ if (h->pb_frame) {
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); /* Quantization information for B-pictures */
}
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index ee78e7119f..f3af523b7c 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3031,7 +3031,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
if (e >= 2) {
ctx->divx_version = ver;
ctx->divx_build = build;
- h->c.divx_packed = e == 3 && last == 'p';
+ h->divx_packed = e == 3 && last == 'p';
}
/* libavcodec detection */
@@ -3132,7 +3132,7 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA2;
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)
h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA;
@@ -3170,7 +3170,7 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
if (ctx->divx_version >= 0)
h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
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)
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,
"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,
- 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 &&
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 (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
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;
}
if (ctx->new_pred)
@@ -3740,14 +3740,14 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h)
{
Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
- h->c.skipped_last_frame = 0;
+ h->skipped_last_frame = 0;
if (ctx->bitstream_buffer) {
int buf_size = get_bits_left(&h->gb) / 8U;
int bitstream_buffer_size = ctx->bitstream_buffer->size;
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++) {
if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) {
if (buf[i+3] == 0xB0) {
@@ -3759,7 +3759,7 @@ int ff_mpeg4_decode_picture_header(H263DecContext *const h)
}
}
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,
bitstream_buffer_size);
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);
/* 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 startcode_found = 0;
uint8_t *buf = pkt->data;
@@ -3907,7 +3907,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
s->enhancement_type = s1->enhancement_type;
s->scalability = s1->scalability;
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_build = s1->divx_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_b = s1->cplx_estimation_trash_b;
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_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,
const AVCodecContext *src)
{
- MpegEncContext *m = dst->priv_data;
- const MpegEncContext *m1 = src->priv_data;
+ H263DecContext *const h = dst->priv_data;
+ const H263DecContext *const h1 = src->priv_data;
- m->quarter_sample = m1->quarter_sample;
- m->divx_packed = m1->divx_packed;
+ h->c.quarter_sample = h1->c.quarter_sample;
+ h->divx_packed = h1->divx_packed;
return 0;
}
@@ -4054,10 +4056,10 @@ static av_cold int mpeg4_close(AVCodecContext *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
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},
{NULL}
};
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 4b215bf65f..ff3a249512 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -86,7 +86,6 @@ typedef struct MpegEncContext {
int width, height;///< picture size. must be a multiple of 16
enum OutputFormat out_format; ///< output format
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 */
int h263_flv; ///< use flv H.263 header
@@ -138,7 +137,6 @@ typedef struct MpegEncContext {
*/
MPVWorkPicture cur_pic;
- int skipped_last_frame;
int last_dc[3]; ///< last DC values for MPEG-1
int16_t *dc_val_base;
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 droppable;
- /* motion compensation */
- int h263_long_vectors; ///< use horrible H.263v1 long vector mode
-
BlockDSPContext bdsp;
H264ChromaContext h264chroma;
HpelDSPContext hdsp;
@@ -224,7 +219,6 @@ typedef struct MpegEncContext {
/* H.263 specific */
int gob_index;
int obmc; ///< overlapped block motion compensation
- int ehc_mode;
/* H.263+ specific */
int umvplus; ///< == H.263+ && unrestricted_mv
@@ -233,7 +227,6 @@ typedef struct MpegEncContext {
int alt_inter_vlc; ///< alternative inter vlc
int modified_quant;
int loop_filter;
- int custom_pcf;
/* MPEG-4 specific */
int studio_profile;
@@ -250,14 +243,6 @@ typedef struct MpegEncContext {
int data_partitioning; ///< data partitioning flag from header
int partitioned_frame; ///< is current frame partitioned
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 */
int slice_height; ///< in macroblocks
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index c4831bf85b..1ae36dc751 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -108,7 +108,6 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
// Error/bug resilience
s->workaround_bugs = s1->workaround_bugs;
- s->padding_bug_score = s1->padding_bug_score;
// MPEG-4 timing info
memcpy(&s->last_time_base, &s1->last_time_base,
diff --git a/libavcodec/nvdec_mpeg4.c b/libavcodec/nvdec_mpeg4.c
index 0351ee169e..369bd5b997 100644
--- a/libavcodec/nvdec_mpeg4.c
+++ b/libavcodec/nvdec_mpeg4.c
@@ -73,7 +73,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx,
.quant_type = m->mpeg_quant,
.quarter_sample = s->quarter_sample,
.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_coded = 1,
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 01cdd1a9dc..bbd0482d59 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -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.rv10_version == 3) {
+ if (h->rv10_version == 3) {
/* specific MPEG like DC coding not used */
h->c.last_dc[0] = 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_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);
if (avctx->codec_id == AV_CODEC_ID_RV20) {
h->c.modified_quant = 1;
@@ -382,7 +382,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
switch (major_ver) {
case 1:
- h->c.rv10_version = micro_ver ? 3 : 1;
+ h->rv10_version = micro_ver ? 3 : 1;
h->c.obmc = micro_ver == 2;
break;
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);
- h->c.rv10_first_dc_coded[0] = 0;
- h->c.rv10_first_dc_coded[1] = 0;
- h->c.rv10_first_dc_coded[2] = 0;
+ h->rv10_first_dc_coded[0] = 0;
+ h->rv10_first_dc_coded[1] = 0;
+ h->rv10_first_dc_coded[2] = 0;
ff_init_block_index(&h->c);
/* decode each macroblock */
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 35/48] avcodec/mpegvideo: Move mb_num_left to {H263, RV34}DecContext
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (33 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 34/48] avcodec/mpegvideo: Move fields only used by H.263 decoders to H263DecCtx Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 36/48] avcodec/mpeg12dec: Put mb_skip_run on the stack Andreas Rheinhardt
` (12 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.h | 2 ++
libavcodec/ituh263dec.c | 2 +-
libavcodec/mpeg4videodec.c | 4 ++--
libavcodec/mpegvideo.h | 1 -
libavcodec/rv10.c | 2 +-
libavcodec/rv34.c | 16 ++++++++--------
libavcodec/rv34.h | 2 ++
7 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index dd63eca5be..90340a59bd 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -50,6 +50,8 @@ typedef struct H263DecContext {
GetBitContext gb;
+ int mb_num_left; ///< number of MBs left in this video packet (for partitioned slices only)
+
int pb_frame; ///< PB-frame mode (0 = none, 1 = base, 2 = improved)
/* motion compensation */
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 11be8189a6..94cde850b5 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -1061,7 +1061,7 @@ intra:
return -1;
if (h->c.obmc && !h->c.mb_intra) {
if (h->c.pict_type == AV_PICTURE_TYPE_P &&
- h->c.mb_x + 1 < h->c.mb_width && h->c.mb_num_left != 1)
+ h->c.mb_x + 1 < h->c.mb_width && h->mb_num_left != 1)
preview_obmc(h);
}
end:
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index f3af523b7c..c53f5c103a 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1335,7 +1335,7 @@ int ff_mpeg4_decode_partitions(H263DecContext *const h)
return AVERROR_INVALIDDATA;
}
- h->c.mb_num_left = mb_num;
+ h->mb_num_left = mb_num;
if (h->c.pict_type == AV_PICTURE_TYPE_I) {
while (show_bits(&h->gb, 9) == 1)
@@ -1723,7 +1723,7 @@ static int mpeg4_decode_partitioned_mb(H263DecContext *const h)
}
/* per-MB end of slice check */
- if (--h->c.mb_num_left <= 0) {
+ if (--h->mb_num_left <= 0) {
if (mpeg4_is_resync(ctx))
return SLICE_END;
else
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index ff3a249512..7e92ac8be9 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -214,7 +214,6 @@ typedef struct MpegEncContext {
/* error concealment / resync */
int resync_mb_x; ///< x position of last resync marker
int resync_mb_y; ///< y position of last resync marker
- int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only)
/* H.263 specific */
int gob_index;
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index bbd0482d59..c104efc212 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -481,7 +481,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
ff_init_block_index(&h->c);
/* decode each macroblock */
- for (h->c.mb_num_left = mb_count; h->c.mb_num_left > 0; h->c.mb_num_left--) {
+ for (h->mb_num_left = mb_count; h->mb_num_left > 0; h->mb_num_left--) {
int ret;
ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
ff_tlog(avctx, "**mb x=%d y=%d\n", h->c.mb_x, h->c.mb_y);
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 9f8a0f12b8..bb08c9bc5c 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1362,7 +1362,7 @@ static int check_slice_end(RV34DecContext *r, MpegEncContext *s)
int bits;
if(s->mb_y >= s->mb_height)
return 1;
- if(!s->mb_num_left)
+ if (!r->mb_num_left)
return 1;
if(r->s.mb_skip_run > 1)
return 0;
@@ -1446,7 +1446,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int
r->si.end = end;
s->qscale = r->si.quant;
- s->mb_num_left = r->si.end - r->si.start;
+ r->mb_num_left = r->si.end - r->si.start;
r->s.mb_skip_run = 0;
mb_pos = s->mb_x + s->mb_y * s->mb_width;
@@ -1492,7 +1492,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int
}
if(s->mb_x == s->resync_mb_x)
s->first_slice_line=0;
- s->mb_num_left--;
+ r->mb_num_left--;
}
ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END);
@@ -1579,7 +1579,7 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
ff_er_frame_end(&s->er, NULL);
ff_mpv_frame_end(s);
- s->mb_num_left = 0;
+ r->mb_num_left = 0;
if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX);
@@ -1667,9 +1667,9 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
/* first slice */
if (si.start == 0) {
- if (s->mb_num_left > 0 && s->cur_pic.ptr) {
+ if (r->mb_num_left > 0 && s->cur_pic.ptr) {
av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n",
- s->mb_num_left);
+ r->mb_num_left);
if (!s->context_reinit)
ff_er_frame_end(&s->er, NULL);
ff_mpv_frame_end(s);
@@ -1772,7 +1772,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
size = offset1 - offset;
r->si.end = s->mb_width * s->mb_height;
- s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start;
+ r->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start;
if(i+1 < slice_count){
int offset2 = get_slice_offset(avctx, slices_hdr, i+2, slice_count, buf_size);
@@ -1808,7 +1808,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
* only complete frames */
ff_er_frame_end(&s->er, NULL);
ff_mpv_frame_end(s);
- s->mb_num_left = 0;
+ r->mb_num_left = 0;
ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX);
return AVERROR_INVALIDDATA;
}
diff --git a/libavcodec/rv34.h b/libavcodec/rv34.h
index 5bed46ea4f..92bcbba933 100644
--- a/libavcodec/rv34.h
+++ b/libavcodec/rv34.h
@@ -98,6 +98,8 @@ typedef struct RV34DecContext{
H264PredContext h; ///< functions for 4x4 and 16x16 intra block prediction
SliceInfo si; ///< current slice information
+ int mb_num_left; ///< number of MBs left in this video packet
+
int *mb_type; ///< internal macroblock types
int block_type; ///< current block type
int luma_vlc; ///< which VLC set will be used for decoding of luma blocks
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 36/48] avcodec/mpeg12dec: Put mb_skip_run on the stack
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (34 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 35/48] avcodec/mpegvideo: Move mb_num_left to {H263, RV34}DecContext Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 37/48] avcodec/mpegvideo: Move mb_skip_run to {RV34Dec, MPVEnc}Context Andreas Rheinhardt
` (11 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/mpeg12dec.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index db6f9d66a5..998f6aa2e5 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -402,7 +402,7 @@ static inline int get_dmv(Mpeg12SliceContext *const s)
#define MT_16X8 2
#define MT_DMV 3
-static int mpeg_decode_mb(Mpeg12SliceContext *const s)
+static int mpeg_decode_mb(Mpeg12SliceContext *const s, int *mb_skip_run)
{
int i, j, k, cbp, val, mb_type, motion_type;
const int mb_block_count = 4 + (1 << s->c.chroma_format);
@@ -412,7 +412,7 @@ static int mpeg_decode_mb(Mpeg12SliceContext *const s)
av_assert2(s->c.mb_skipped == 0);
- if (s->c.mb_skip_run-- != 0) {
+ if ((*mb_skip_run)-- != 0) {
if (s->c.pict_type == AV_PICTURE_TYPE_P) {
s->c.mb_skipped = 1;
s->c.cur_pic.mb_type[s->c.mb_x + s->c.mb_y * s->c.mb_stride] =
@@ -1432,7 +1432,6 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
s->c.resync_mb_x = s->c.mb_x;
s->c.resync_mb_y = s->c.mb_y = mb_y;
- s->c.mb_skip_run = 0;
ff_init_block_index(&s->c);
if (s->c.mb_y == 0 && s->c.mb_x == 0 && (s->c.first_field || s->c.picture_structure == PICT_FRAME)) {
@@ -1456,8 +1455,8 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
}
- for (;;) {
- ret = mpeg_decode_mb(s);
+ for (int mb_skip_run = 0;;) {
+ ret = mpeg_decode_mb(s, &mb_skip_run);
if (ret < 0)
return ret;
@@ -1552,7 +1551,7 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
!s->c.progressive_sequence &&
left <= 25 &&
left >= 0 &&
- s->c.mb_skip_run == -1 &&
+ mb_skip_run == -1 &&
(!left || show_bits(&s->gb, left) == 0))
goto eos;
@@ -1560,9 +1559,9 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
/* skip mb handling */
- if (s->c.mb_skip_run == -1) {
+ if (mb_skip_run == -1) {
/* read increment again */
- s->c.mb_skip_run = 0;
+ mb_skip_run = 0;
for (;;) {
int code = get_vlc2(&s->gb, ff_mbincr_vlc,
MBINCR_VLC_BITS, 2);
@@ -1572,9 +1571,9 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
if (code >= 33) {
if (code == 33) {
- s->c.mb_skip_run += 33;
+ mb_skip_run += 33;
} else if (code == 35) {
- if (s->c.mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
+ if (mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
av_log(s->c.avctx, AV_LOG_ERROR, "slice mismatch\n");
return AVERROR_INVALIDDATA;
}
@@ -1582,11 +1581,11 @@ static int mpeg_decode_slice(Mpeg12SliceContext *const s, int mb_y,
}
/* otherwise, stuffing, nothing to do */
} else {
- s->c.mb_skip_run += code;
+ mb_skip_run += code;
break;
}
}
- if (s->c.mb_skip_run) {
+ if (mb_skip_run) {
int i;
if (s->c.pict_type == AV_PICTURE_TYPE_I) {
av_log(s->c.avctx, AV_LOG_ERROR,
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 37/48] avcodec/mpegvideo: Move mb_skip_run to {RV34Dec, MPVEnc}Context
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (35 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 36/48] avcodec/mpeg12dec: Put mb_skip_run on the stack Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 38/48] avcodec/mpegvideo: Move SLICE_* defs to h263dec.h, h261dec.c Andreas Rheinhardt
` (10 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261enc.c | 12 ++++++------
libavcodec/mpeg12enc.c | 8 ++++----
libavcodec/mpegvideo.h | 1 -
libavcodec/mpegvideo_enc.c | 11 ++++++-----
libavcodec/mpegvideoenc.h | 2 ++
libavcodec/rv34.c | 4 ++--
libavcodec/rv34.h | 1 +
libavcodec/rv40.c | 8 ++++----
8 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index c217fb6233..466a0387c5 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -92,7 +92,7 @@ static int h261_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb, 1, 0); /* no PEI */
h->gob_number = h->format - 1;
- s->c.mb_skip_run = 0;
+ s->mb_skip_run = 0;
return 0;
}
@@ -112,7 +112,7 @@ static void h261_encode_gob_header(MPVEncContext *const s, int mb_line)
put_bits(&s->pb, 4, h->gob_number); /* GN */
put_bits(&s->pb, 5, s->c.qscale); /* GQUANT */
put_bits(&s->pb, 1, 0); /* no GEI */
- s->c.mb_skip_run = 0;
+ s->mb_skip_run = 0;
s->c.last_mv[0][0][0] = 0;
s->c.last_mv[0][0][1] = 0;
}
@@ -248,7 +248,7 @@ static void h261_encode_mb(MPVEncContext *const s, int16_t block[6][64],
if ((cbp | mvd) == 0) {
/* skip macroblock */
- s->c.mb_skip_run++;
+ s->mb_skip_run++;
s->c.last_mv[0][0][0] = 0;
s->c.last_mv[0][0][1] = 0;
s->c.qscale -= s->dquant;
@@ -258,9 +258,9 @@ static void h261_encode_mb(MPVEncContext *const s, int16_t block[6][64],
/* MB is not skipped, encode MBA */
put_bits(&s->pb,
- ff_h261_mba_bits[s->c.mb_skip_run],
- ff_h261_mba_code[s->c.mb_skip_run]);
- s->c.mb_skip_run = 0;
+ ff_h261_mba_bits[s->mb_skip_run],
+ ff_h261_mba_code[s->mb_skip_run]);
+ s->mb_skip_run = 0;
/* calculate MTYPE */
if (!s->c.mb_intra) {
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 96957235e9..521a915aa0 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -688,7 +688,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *const s,
((s->c.mv_dir & MV_DIR_BACKWARD)
? ((s->c.mv[1][0][0] - s->c.last_mv[1][0][0]) |
(s->c.mv[1][0][1] - s->c.last_mv[1][0][1])) : 0)) == 0))) {
- s->c.mb_skip_run++;
+ s->mb_skip_run++;
s->c.qscale -= s->dquant;
s->misc_bits++;
s->last_bits++;
@@ -700,10 +700,10 @@ static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *const s,
}
} else {
if (first_mb) {
- av_assert0(s->c.mb_skip_run == 0);
+ av_assert0(s->mb_skip_run == 0);
encode_mb_skip_run(s, s->c.mb_x);
} else {
- encode_mb_skip_run(s, s->c.mb_skip_run);
+ encode_mb_skip_run(s, s->mb_skip_run);
}
if (s->c.pict_type == AV_PICTURE_TYPE_I) {
@@ -925,7 +925,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MPVEncContext *const s,
for (i = 0; i < mb_block_count; i++)
if (cbp & (1 << (mb_block_count - 1 - i)))
mpeg1_encode_block(s, block[i], i);
- s->c.mb_skip_run = 0;
+ s->mb_skip_run = 0;
if (s->c.mb_intra)
s->i_tex_bits += get_bits_diff(s);
else
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 7e92ac8be9..4c5f034690 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -196,7 +196,6 @@ typedef struct MpegEncContext {
/* macroblock layer */
int mb_x, mb_y;
- int mb_skip_run;
int mb_intra;
int block_index[6]; ///< index to current MB in block based arrays with edges
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index afdc2fb787..a16cb6bd19 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -2647,11 +2647,12 @@ typedef struct MBBackup {
int last_mv[2][2][2];
int mv_type, mv_dir;
int last_dc[3];
- int mb_intra, mb_skipped, mb_skip_run;
+ int mb_intra, mb_skipped;
int qscale;
int block_last_index[8];
int interlaced_dct;
} c;
+ int mb_skip_run;
int mv_bits, i_tex_bits, p_tex_bits, i_count, misc_bits, last_bits;
int dquant;
int esc3_level_length;
@@ -2667,7 +2668,7 @@ static inline void BEFORE ##_context_before_encode(DST_TYPE *const d, \
memcpy(d->c.last_mv, s->c.last_mv, 2*2*2*sizeof(int)); \
\
/* MPEG-1 */ \
- d->c.mb_skip_run = s->c.mb_skip_run; \
+ d->mb_skip_run = s->mb_skip_run; \
for (int i = 0; i < 3; i++) \
d->c.last_dc[i] = s->c.last_dc[i]; \
\
@@ -2695,7 +2696,7 @@ static inline void AFTER ## _context_after_encode(DST_TYPE *const d, \
memcpy(d->c.last_mv, s->c.last_mv, 2*2*2*sizeof(int)); \
\
/* MPEG-1 */ \
- d->c.mb_skip_run = s->c.mb_skip_run; \
+ d->mb_skip_run = s->mb_skip_run; \
for (int i = 0; i < 3; i++) \
d->c.last_dc[i] = s->c.last_dc[i]; \
\
@@ -3029,7 +3030,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
ff_mpeg4_init_partitions(s);
#endif
}
- s->c.mb_skip_run = 0;
+ s->mb_skip_run = 0;
memset(s->c.last_mv, 0, sizeof(s->c.last_mv));
s->last_mv_dir = 0;
@@ -3108,7 +3109,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
if (s->c.mb_x == 0 && s->c.mb_y != 0) is_gob_start = 1;
case AV_CODEC_ID_MPEG1VIDEO:
if (s->c.codec_id == AV_CODEC_ID_MPEG1VIDEO && s->c.mb_y >= 175 ||
- s->c.mb_skip_run)
+ s->mb_skip_run)
is_gob_start=0;
break;
case AV_CODEC_ID_MJPEG:
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 2a04abab26..7aa8af5412 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -136,6 +136,8 @@ typedef struct MPVEncContext {
int misc_bits; ///< cbp, mb_type
int last_bits; ///< temp var used for calculating the above vars
+ int mb_skip_run;
+
/* H.263 specific */
int mb_info; ///< interval for outputting info about mb offsets as side data
int prev_mb_info, last_mb_info;
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index bb08c9bc5c..4feab95eb5 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1364,7 +1364,7 @@ static int check_slice_end(RV34DecContext *r, MpegEncContext *s)
return 1;
if (!r->mb_num_left)
return 1;
- if(r->s.mb_skip_run > 1)
+ if (r->mb_skip_run > 1)
return 0;
bits = get_bits_left(&r->gb);
if (bits <= 0 || (bits < 8 && !show_bits(&r->gb, bits)))
@@ -1447,7 +1447,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int
r->si.end = end;
s->qscale = r->si.quant;
r->mb_num_left = r->si.end - r->si.start;
- r->s.mb_skip_run = 0;
+ r->mb_skip_run = 0;
mb_pos = s->mb_x + s->mb_y * s->mb_width;
if(r->si.start != mb_pos){
diff --git a/libavcodec/rv34.h b/libavcodec/rv34.h
index 92bcbba933..85ab6b4c2c 100644
--- a/libavcodec/rv34.h
+++ b/libavcodec/rv34.h
@@ -99,6 +99,7 @@ typedef struct RV34DecContext{
SliceInfo si; ///< current slice information
int mb_num_left; ///< number of MBs left in this video packet
+ int mb_skip_run;
int *mb_type; ///< internal macroblock types
int block_type; ///< current block type
diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c
index 79e99e9efd..2b010295dd 100644
--- a/libavcodec/rv40.c
+++ b/libavcodec/rv40.c
@@ -231,13 +231,13 @@ static int rv40_decode_mb_info(RV34DecContext *r)
int prev_type = 0;
int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
- if(!r->s.mb_skip_run) {
- r->s.mb_skip_run = get_interleaved_ue_golomb(gb) + 1;
- if(r->s.mb_skip_run > (unsigned)s->mb_num)
+ if (!r->mb_skip_run) {
+ r->mb_skip_run = get_interleaved_ue_golomb(gb) + 1;
+ if (r->mb_skip_run > (unsigned)s->mb_num)
return -1;
}
- if(--r->s.mb_skip_run)
+ if (--r->mb_skip_run)
return RV34_MB_SKIP;
if(r->avail_cache[6-4]){
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 38/48] avcodec/mpegvideo: Move SLICE_* defs to h263dec.h, h261dec.c
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (36 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 37/48] avcodec/mpegvideo: Move mb_skip_run to {RV34Dec, MPVEnc}Context Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 39/48] avcodec/msmpeg4dec: Move ff_msmpeg4_decode_init() down Andreas Rheinhardt
` (9 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h261dec.c | 4 ++++
libavcodec/h263dec.h | 4 ++++
libavcodec/mpegvideo.h | 5 -----
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c
index e47bc00a71..32d41903e7 100644
--- a/libavcodec/h261dec.c
+++ b/libavcodec/h261dec.c
@@ -37,6 +37,10 @@
#include "mpegvideodec.h"
#include "h261.h"
+#define SLICE_OK 0
+#define SLICE_ERROR -1
+#define SLICE_END -2 ///<end marker found
+
#define H261_MBA_VLC_BITS 8
#define H261_MTYPE_VLC_BITS 6
#define H261_MV_VLC_BITS 7
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index 90340a59bd..0c6228f9d9 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -73,6 +73,10 @@ typedef struct H263DecContext {
int rv10_first_dc_coded[3];
int (*decode_mb)(struct H263DecContext *h);
+#define SLICE_OK 0
+#define SLICE_ERROR -1
+#define SLICE_END -2 ///<end marker found
+#define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
GetBitContext last_resync_gb; ///< used to search for the next resync marker
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 4c5f034690..9318801019 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -285,11 +285,6 @@ typedef struct MpegEncContext {
int interlaced_dct;
int first_field; ///< is 1 for the first field of a field picture 0 otherwise
-#define SLICE_OK 0
-#define SLICE_ERROR -1
-#define SLICE_END -2 ///<end marker found
-#define SLICE_NOEND -3 ///<no end marker or error found but mb count exceeded
-
void (*dct_unquantize_intra)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
int16_t *block/*align 16*/, int n, int qscale);
void (*dct_unquantize_inter)(struct MpegEncContext *s, // unquantizer to use (MPEG-4 can use both)
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 39/48] avcodec/msmpeg4dec: Move ff_msmpeg4_decode_init() down
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (37 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 38/48] avcodec/mpegvideo: Move SLICE_* defs to h263dec.h, h261dec.c Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 40/48] avcodec/h263dec: Use function ptr for decode_picture_header Andreas Rheinhardt
` (8 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Will avoid a forward declaration lateron.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/msmpeg4dec.c | 79 +++++++++++++++++++++--------------------
1 file changed, 40 insertions(+), 39 deletions(-)
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 36243e14c9..59ceb7dac6 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -360,45 +360,6 @@ static av_cold void msmpeg4_decode_init_static(void)
ff_msmp4_vc1_vlcs_init_once();
}
-av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
-{
- static AVOnce init_static_once = AV_ONCE_INIT;
- H263DecContext *const h = avctx->priv_data;
- int ret;
-
- if ((ret = av_image_check_size(avctx->width, avctx->height, 0, avctx)) < 0)
- return ret;
-
- if (ff_h263_decode_init(avctx) < 0)
- return -1;
-
- // We unquantize inter blocks as we parse them.
- h->c.dct_unquantize_inter = NULL;
-
- ff_msmpeg4_common_init(&h->c);
-
- switch (h->c.msmpeg4_version) {
- case MSMP4_V1:
- case MSMP4_V2:
- h->decode_mb = msmpeg4v12_decode_mb;
- break;
- case MSMP4_V3:
- case MSMP4_WMV1:
- h->decode_mb = msmpeg4v34_decode_mb;
- break;
- case MSMP4_WMV2:
- break;
- default:
- av_unreachable("List contains all cases using ff_msmpeg4_decode_init()");
- }
-
- h->c.slice_height = h->c.mb_height; //to avoid 1/0 if the first frame is not a keyframe
-
- ff_thread_once(&init_static_once, msmpeg4_decode_init_static);
-
- return 0;
-}
-
int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
{
MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
@@ -870,6 +831,46 @@ void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_pt
*my_ptr = my;
}
+av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
+{
+ static AVOnce init_static_once = AV_ONCE_INIT;
+ H263DecContext *const h = avctx->priv_data;
+ int ret;
+
+ ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
+ if (ret < 0)
+ return ret;
+
+ if (ff_h263_decode_init(avctx) < 0)
+ return -1;
+
+ // We unquantize inter blocks as we parse them.
+ h->c.dct_unquantize_inter = NULL;
+
+ ff_msmpeg4_common_init(&h->c);
+
+ switch (h->c.msmpeg4_version) {
+ case MSMP4_V1:
+ case MSMP4_V2:
+ h->decode_mb = msmpeg4v12_decode_mb;
+ break;
+ case MSMP4_V3:
+ case MSMP4_WMV1:
+ h->decode_mb = msmpeg4v34_decode_mb;
+ break;
+ case MSMP4_WMV2:
+ break;
+ default:
+ av_unreachable("List contains all cases using ff_msmpeg4_decode_init()");
+ }
+
+ h->c.slice_height = h->c.mb_height; //to avoid 1/0 if the first frame is not a keyframe
+
+ ff_thread_once(&init_static_once, msmpeg4_decode_init_static);
+
+ return 0;
+}
+
const FFCodec ff_msmpeg4v1_decoder = {
.p.name = "msmpeg4v1",
CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 1"),
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 40/48] avcodec/h263dec: Use function ptr for decode_picture_header
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (38 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 39/48] avcodec/msmpeg4dec: Move ff_msmpeg4_decode_init() down Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 41/48] avcodec/ituh263enc: Inline value of h263_flv Andreas Rheinhardt
` (7 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 27 ++++++++++-----------------
libavcodec/h263dec.h | 8 +++-----
libavcodec/mpeg4videodec.c | 3 ++-
libavcodec/mpeg4videodec.h | 1 -
libavcodec/msmpeg4dec.c | 8 +++++---
libavcodec/msmpeg4dec.h | 1 -
libavcodec/wmv2dec.c | 3 ++-
libavcodec/wmv2dec.h | 1 -
8 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 541eb34789..592a22df0d 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -121,6 +121,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
case AV_CODEC_ID_H263:
case AV_CODEC_ID_H263P:
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
+ h->decode_header = ff_h263_decode_picture_header;
break;
case AV_CODEC_ID_MPEG4:
break;
@@ -144,13 +145,20 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
s->h263_pred = 1;
s->msmpeg4_version = MSMP4_WMV2;
break;
- case AV_CODEC_ID_H263I:
case AV_CODEC_ID_RV10:
case AV_CODEC_ID_RV20:
break;
+#if CONFIG_H263I_DECODER
+ case AV_CODEC_ID_H263I:
+ h->decode_header = ff_intel_h263_decode_picture_header;
+ break;
+#endif
+#if CONFIG_FLV_DECODER
case AV_CODEC_ID_FLV1:
s->h263_flv = 1;
+ h->decode_header = ff_flv_decode_picture_header;
break;
+#endif
default:
av_unreachable("Switch contains a case for every codec using ff_h263_decode_init()");
}
@@ -461,22 +469,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
bak_height = h->c.height;
/* let's go :-) */
- if (CONFIG_WMV2_DECODER && h->c.msmpeg4_version == MSMP4_WMV2) {
- ret = ff_wmv2_decode_picture_header(h);
-#if CONFIG_MSMPEG4DEC
- } else if (h->c.msmpeg4_version != MSMP4_UNUSED) {
- ret = ff_msmpeg4_decode_picture_header(h);
-#endif
- } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
- ret = ff_mpeg4_decode_picture_header(h);
- } else if (CONFIG_H263I_DECODER && h->c.codec_id == AV_CODEC_ID_H263I) {
- ret = ff_intel_h263_decode_picture_header(h);
- } else if (CONFIG_FLV_DECODER && h->c.h263_flv) {
- ret = ff_flv_decode_picture_header(h);
- } else {
- ret = ff_h263_decode_picture_header(h);
- }
-
+ ret = h->decode_header(h);
if (ret < 0 || ret == FRAME_SKIPPED) {
if ( h->c.width != bak_width
|| h->c.height != bak_height) {
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index 0c6228f9d9..2b43dda568 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -25,11 +25,6 @@
#include "vlc.h"
#include "libavutil/mem_internal.h"
-/**
- * Return value for header parsers if frame is not coded.
- * */
-#define FRAME_SKIPPED 100
-
// The defines below define the number of bits that are read at once for
// reading vlc values. Changing these may improve speed and data cache needs
// be aware though that decreasing them may need the number of stages that is
@@ -72,6 +67,9 @@ typedef struct H263DecContext {
int rv10_version; ///< RV10 version: 0 or 3
int rv10_first_dc_coded[3];
+ int (*decode_header)(struct H263DecContext *const h);
+#define FRAME_SKIPPED 100 ///< Frame is not coded
+
int (*decode_mb)(struct H263DecContext *h);
#define SLICE_OK 0
#define SLICE_ERROR -1
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index c53f5c103a..bc17b0ed09 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3736,7 +3736,7 @@ end:
return decode_vop_header(ctx, gb, parse_only);
}
-int ff_mpeg4_decode_picture_header(H263DecContext *const h)
+static int mpeg4_decode_picture_header(H263DecContext *const h)
{
Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
@@ -4017,6 +4017,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
h->c.h263_pred = 1;
h->c.low_delay = 0; /* default, might be overridden in the vol header during header parsing */
+ h->decode_header = mpeg4_decode_picture_header;
h->decode_mb = mpeg4_decode_mb;
ctx->time_increment_bits = 4; /* default value for broken headers */
ctx->quant_precision = 5;
diff --git a/libavcodec/mpeg4videodec.h b/libavcodec/mpeg4videodec.h
index 337125d4e3..aafde454ea 100644
--- a/libavcodec/mpeg4videodec.h
+++ b/libavcodec/mpeg4videodec.h
@@ -109,7 +109,6 @@ typedef struct Mpeg4DecContext {
int dct_precision;
} Mpeg4DecContext;
-int ff_mpeg4_decode_picture_header(H263DecContext *const h);
int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
int header, int parse_only);
void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb,
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index 59ceb7dac6..a96a0335f7 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -360,7 +360,7 @@ static av_cold void msmpeg4_decode_init_static(void)
ff_msmp4_vc1_vlcs_init_once();
}
-int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
+static int msmpeg4_decode_picture_header(H263DecContext *const h)
{
MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
int code;
@@ -445,7 +445,7 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
h->c.inter_intra_pred= 0;
break;
default:
- av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
+ av_unreachable("msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
}
h->c.no_rounding = 1;
if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
@@ -498,7 +498,7 @@ int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
ms->bit_rate <= II_BITRATE;
break;
default:
- av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
+ av_unreachable("msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
}
if (h->c.avctx->debug&FF_DEBUG_PICT_INFO)
@@ -847,6 +847,8 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
// We unquantize inter blocks as we parse them.
h->c.dct_unquantize_inter = NULL;
+ h->decode_header = msmpeg4_decode_picture_header;
+
ff_msmpeg4_common_init(&h->c);
switch (h->c.msmpeg4_version) {
diff --git a/libavcodec/msmpeg4dec.h b/libavcodec/msmpeg4dec.h
index 11a36f2136..e0fb3cf483 100644
--- a/libavcodec/msmpeg4dec.h
+++ b/libavcodec/msmpeg4dec.h
@@ -53,7 +53,6 @@ extern const VLCElem *ff_mb_non_intra_vlc[4];
extern VLCElem ff_inter_intra_vlc[8];
int ff_msmpeg4_decode_init(AVCodecContext *avctx);
-int ff_msmpeg4_decode_picture_header(H263DecContext *const h);
int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size);
void ff_msmpeg4_decode_motion(MSMP4DecContext *ms, int *mx_ptr, int *my_ptr);
int ff_msmpeg4_decode_block(MSMP4DecContext *ms, int16_t * block,
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 4ceae05bdf..53d127d37f 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -201,7 +201,7 @@ static int decode_ext_header(WMV2DecContext *w)
return 0;
}
-int ff_wmv2_decode_picture_header(H263DecContext *const h)
+static int wmv2_decode_picture_header(H263DecContext *const h)
{
int code;
@@ -574,6 +574,7 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx)
if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
return ret;
+ h->decode_header = wmv2_decode_picture_header;
h->decode_mb = wmv2_decode_mb;
ff_wmv2_common_init(s);
diff --git a/libavcodec/wmv2dec.h b/libavcodec/wmv2dec.h
index 4dd9359dc9..1bd0d13725 100644
--- a/libavcodec/wmv2dec.h
+++ b/libavcodec/wmv2dec.h
@@ -24,7 +24,6 @@
#include "mpegvideo.h"
struct H263DecContext;
-int ff_wmv2_decode_picture_header(struct H263DecContext *const h);
int ff_wmv2_decode_secondary_picture_header(struct H263DecContext *const h);
void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64],
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 41/48] avcodec/ituh263enc: Inline value of h263_flv
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (39 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 40/48] avcodec/h263dec: Use function ptr for decode_picture_header Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 42/48] avcodec/flvdec: Binarize h263_flv Andreas Rheinhardt
` (6 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It is always two when we encode FLV1.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/flvenc.c | 2 +-
libavcodec/ituh263enc.c | 12 ++++--------
libavcodec/mpegvideo_enc.c | 1 -
3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 4143e7eecf..91e1f07365 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -33,7 +33,7 @@ int ff_flv_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb, 17, 1);
/* 0: H.263 escape codes 1: 11-bit escape codes */
- put_bits(&s->pb, 5, (s->c.h263_flv - 1));
+ put_bits(&s->pb, 5, 1);
put_bits(&s->pb, 8,
(((int64_t) s->c.picture_number * 30 * s->c.avctx->time_base.num) / // FIXME use timestamp
s->c.avctx->time_base.den) & 0xff); /* TemporalReference */
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 4ec851cab9..682d4bd24e 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -536,7 +536,7 @@ static void h263_encode_block(MPVEncContext *const s, int16_t block[], int n)
code = get_rl_index(rl, last, run, level);
put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
if (code == rl->n) {
- if (!CONFIG_FLV_ENCODER || s->c.h263_flv <= 1) {
+ if (!CONFIG_FLV_ENCODER || s->c.codec_id != AV_CODEC_ID_FLV1) {
put_bits(&s->pb, 1, last);
put_bits(&s->pb, 6, run);
@@ -861,13 +861,9 @@ av_cold void ff_h263_encode_init(MPVMainEncContext *const m)
#if CONFIG_FLV_ENCODER
case AV_CODEC_ID_FLV1:
m->encode_picture_header = ff_flv_encode_picture_header;
- if (s->c.h263_flv > 1) {
- s->min_qcoeff= -1023;
- s->max_qcoeff= 1023;
- } else {
- s->min_qcoeff= -127;
- s->max_qcoeff= 127;
- }
+ /* format = 1; 11-bit codes */
+ s->min_qcoeff = -1023;
+ s->max_qcoeff = 1023;
break;
#endif
default: //nothing needed - default table already set in mpegvideo.c
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index a16cb6bd19..f54f458ab8 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -936,7 +936,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
break;
case AV_CODEC_ID_FLV1:
s->c.out_format = FMT_H263;
- s->c.h263_flv = 2; /* format = 1; 11-bit codes */
s->me.unrestricted_mv = 1;
s->rtp_mode = 0; /* don't allow GOB */
avctx->delay = 0;
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 42/48] avcodec/flvdec: Binarize h263_flv
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (40 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 41/48] avcodec/ituh263enc: Inline value of h263_flv Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 43/48] avcodec/mpegvideo: Move fields to {H263Dec, MPVEnc}Context when possible Andreas Rheinhardt
` (5 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It used to be a tri-state encoding both whether to use FLV picture
headers and whether to use the FLV way of encoding escape values,
but the former is now unnecessary due to the switch to a function
pointer for reading the header. So binarize h263_flv.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/flvdec.c | 4 ++--
libavcodec/h263dec.c | 1 -
libavcodec/ituh263dec.c | 2 +-
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index c70d79f483..881f63ed1a 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -40,7 +40,7 @@ int ff_flv_decode_picture_header(H263DecContext *const h)
av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");
return AVERROR_INVALIDDATA;
}
- h->c.h263_flv = format + 1;
+ h->c.h263_flv = format;
h->c.picture_number = get_bits(&h->gb, 8); /* picture timestamp */
format = get_bits(&h->gb, 3);
switch (format) {
@@ -101,7 +101,7 @@ int ff_flv_decode_picture_header(H263DecContext *const h)
if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(h->c.avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
h->c.droppable ? 'D' : av_get_picture_type_char(h->c.pict_type),
- h->c.h263_flv - 1, h->c.qscale, h->c.picture_number);
+ h->c.h263_flv, h->c.qscale, h->c.picture_number);
}
return 0;
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 592a22df0d..0bbc8e989e 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -155,7 +155,6 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
#endif
#if CONFIG_FLV_DECODER
case AV_CODEC_ID_FLV1:
- s->h263_flv = 1;
h->decode_header = ff_flv_decode_picture_header;
break;
#endif
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 94cde850b5..0cd5d073ed 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -598,7 +598,7 @@ retry:
return -1;
}
/* escape */
- if (CONFIG_FLV_DECODER && h->c.h263_flv > 1) {
+ if (CONFIG_FLV_DECODER && h->c.h263_flv) {
int is11 = SHOW_UBITS(re, &h->gb, 1);
SKIP_CACHE(re, &h->gb, 1);
run = SHOW_UBITS(re, &h->gb, 7) + 1;
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 43/48] avcodec/mpegvideo: Move fields to {H263Dec, MPVEnc}Context when possible
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (41 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 42/48] avcodec/flvdec: Binarize h263_flv Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 44/48] avcodec/mpeg_er: Allow to skip setting partitioned_frame, p[pb]_time Andreas Rheinhardt
` (4 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/flvdec.c | 6 +--
libavcodec/flvenc.c | 2 +-
libavcodec/h261enc.c | 2 +-
libavcodec/h263dec.c | 14 +++----
libavcodec/h263dec.h | 14 +++++++
libavcodec/intelh263dec.c | 4 +-
libavcodec/ituh263dec.c | 84 +++++++++++++++++++-------------------
libavcodec/ituh263enc.c | 44 ++++++++++----------
libavcodec/mpeg12enc.c | 3 +-
libavcodec/mpeg4videodec.c | 20 +++++----
libavcodec/mpeg4videoenc.c | 18 ++++----
libavcodec/mpegvideo.c | 2 -
libavcodec/mpegvideo.h | 11 -----
libavcodec/mpegvideo_dec.c | 2 -
libavcodec/mpegvideo_enc.c | 40 +++++++++---------
libavcodec/mpegvideoenc.h | 11 +++++
libavcodec/msmpeg4dec.c | 8 ++--
libavcodec/msmpeg4enc.c | 6 +--
libavcodec/ratecontrol.c | 4 +-
libavcodec/rv10.c | 2 +-
libavcodec/rv20enc.c | 8 ++--
libavcodec/snowenc.c | 2 +-
libavcodec/vaapi_mpeg4.c | 2 +-
libavcodec/wmv2dec.c | 2 +-
libavcodec/wmv2enc.c | 2 +-
25 files changed, 162 insertions(+), 151 deletions(-)
diff --git a/libavcodec/flvdec.c b/libavcodec/flvdec.c
index 881f63ed1a..0f6eaad5c6 100644
--- a/libavcodec/flvdec.c
+++ b/libavcodec/flvdec.c
@@ -40,8 +40,8 @@ int ff_flv_decode_picture_header(H263DecContext *const h)
av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");
return AVERROR_INVALIDDATA;
}
- h->c.h263_flv = format;
- h->c.picture_number = get_bits(&h->gb, 8); /* picture timestamp */
+ h->flv = format;
+ h->picture_number = get_bits(&h->gb, 8); /* picture timestamp */
format = get_bits(&h->gb, 3);
switch (format) {
case 0:
@@ -101,7 +101,7 @@ int ff_flv_decode_picture_header(H263DecContext *const h)
if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(h->c.avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
h->c.droppable ? 'D' : av_get_picture_type_char(h->c.pict_type),
- h->c.h263_flv, h->c.qscale, h->c.picture_number);
+ h->flv, h->c.qscale, h->picture_number);
}
return 0;
diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
index 91e1f07365..0b6e73b11e 100644
--- a/libavcodec/flvenc.c
+++ b/libavcodec/flvenc.c
@@ -35,7 +35,7 @@ int ff_flv_encode_picture_header(MPVMainEncContext *const m)
/* 0: H.263 escape codes 1: 11-bit escape codes */
put_bits(&s->pb, 5, 1);
put_bits(&s->pb, 8,
- (((int64_t) s->c.picture_number * 30 * s->c.avctx->time_base.num) / // FIXME use timestamp
+ (((int64_t) s->picture_number * 30 * s->c.avctx->time_base.num) / // FIXME use timestamp
s->c.avctx->time_base.den) & 0xff); /* TemporalReference */
if (s->c.width == 352 && s->c.height == 288)
format = 2;
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 466a0387c5..89a6a69755 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -77,7 +77,7 @@ static int h261_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb, 20, 0x10); /* PSC */
- temp_ref = s->c.picture_number * 30000LL * s->c.avctx->time_base.num /
+ temp_ref = s->picture_number * 30000LL * s->c.avctx->time_base.num /
(1001LL * s->c.avctx->time_base.den); // FIXME maybe this should use a timestamp
put_sbits(&s->pb, 5, temp_ref); /* TemporalReference */
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 0bbc8e989e..723040146f 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -231,7 +231,7 @@ static int decode_slice(H263DecContext *const h)
for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) {
/* per-row end of slice checks */
if (h->c.msmpeg4_version != MSMP4_UNUSED) {
- if (h->c.resync_mb_y + h->c.slice_height == h->c.mb_y) {
+ if (h->c.resync_mb_y + h->slice_height == 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 - 1, h->c.mb_y, ER_MB_END);
@@ -330,7 +330,7 @@ static int decode_slice(H263DecContext *const h)
(h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
get_bits_left(&h->gb) >= 48 &&
show_bits(&h->gb, 24) == 0x4010 &&
- !h->c.data_partitioning)
+ !h->data_partitioning)
h->padding_bug_score += 32;
/* try to detect the padding bug */
@@ -338,7 +338,7 @@ static int decode_slice(H263DecContext *const h)
(h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
get_bits_left(&h->gb) >= 0 &&
get_bits_left(&h->gb) < 137 &&
- !h->c.data_partitioning) {
+ !h->data_partitioning) {
const int bits_count = get_bits_count(&h->gb);
const int bits_left = h->gb.size_in_bits - bits_count;
@@ -364,7 +364,7 @@ static int decode_slice(H263DecContext *const h)
get_bits_left(&h->gb) < 300 &&
h->c.pict_type == AV_PICTURE_TYPE_I &&
show_bits(&h->gb, 8) == 0 &&
- !h->c.data_partitioning) {
+ !h->data_partitioning) {
h->padding_bug_score += 32;
}
@@ -379,7 +379,7 @@ static int decode_slice(H263DecContext *const h)
if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
if (
- (h->padding_bug_score > -2 && !h->c.data_partitioning))
+ (h->padding_bug_score > -2 && !h->data_partitioning))
h->c.workaround_bugs |= FF_BUG_NO_PADDING;
else
h->c.workaround_bugs &= ~FF_BUG_NO_PADDING;
@@ -575,8 +575,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
slice_ret = decode_slice(h);
while (h->c.mb_y < h->c.mb_height) {
if (h->c.msmpeg4_version != MSMP4_UNUSED) {
- if (h->c.slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 ||
- (h->c.mb_y % h->c.slice_height) != 0 || get_bits_left(&h->gb) < 0)
+ if (h->slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 ||
+ (h->c.mb_y % h->slice_height) != 0 || get_bits_left(&h->gb) < 0)
break;
} else {
int prev_x = h->c.mb_x, prev_y = h->c.mb_y;
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index 2b43dda568..a7b5e54ae7 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -47,21 +47,35 @@ typedef struct H263DecContext {
int mb_num_left; ///< number of MBs left in this video packet (for partitioned slices only)
+ int picture_number;
+
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
+ /* FLV specific */
+ int flv; ///< use flv H.263 header
+
/* H.263 specific */
int ehc_mode;
+ int gob_index;
/* H.263+ specific */
int custom_pcf;
+ int umvplus; ///< == H.263+ && unrestricted_mv
+ int h263_slice_structured;
+ int alt_inter_vlc; ///< alternative inter vlc
+ int modified_quant;
/* 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
+ int data_partitioning; ///< data partitioning flag from header
+
+ /* MSMPEG4 specific */
+ int slice_height; ///< in macroblocks
/* RV10 specific */
int rv10_version; ///< RV10 version: 0 or 3
diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c
index 1640defaab..73d56f4195 100644
--- a/libavcodec/intelh263dec.c
+++ b/libavcodec/intelh263dec.c
@@ -39,7 +39,7 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
return -1;
}
- h->c.picture_number = get_bits(&h->gb, 8); /* picture timestamp */
+ h->picture_number = get_bits(&h->gb, 8); /* picture timestamp */
if (check_marker(h->c.avctx, &h->gb, "after picture_number") != 1) {
return -1; /* marker */
@@ -119,7 +119,7 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA;
- h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
+ h->gob_index = H263_GOB_HEIGHT(h->c.height);
ff_h263_show_pict_info(h, 0);
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index 0cd5d073ed..b99100590c 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -84,14 +84,14 @@ void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
h->c.qscale, av_get_picture_type_char(h->c.pict_type),
h->gb.size_in_bits, 1-h->c.no_rounding,
h->c.obmc ? " AP" : "",
- h->c.umvplus ? " UMV" : "",
+ h->umvplus ? " UMV" : "",
h->h263_long_vectors ? " LONG" : "",
h263_plus ? " +" : "",
h->c.h263_aic ? " AIC" : "",
- h->c.alt_inter_vlc ? " AIV" : "",
- h->c.modified_quant ? " MQ" : "",
+ h->alt_inter_vlc ? " AIV" : "",
+ h->modified_quant ? " MQ" : "",
h->c.loop_filter ? " LOOP" : "",
- h->c.h263_slice_structured ? " SS" : "",
+ h->h263_slice_structured ? " SS" : "",
h->c.avctx->framerate.num, h->c.avctx->framerate.den);
}
}
@@ -179,7 +179,7 @@ static int h263_decode_gob_header(H263DecContext *const h)
if(left<=13)
return -1;
- if (h->c.h263_slice_structured) {
+ if (h->h263_slice_structured) {
if (check_marker(h->c.avctx, &h->gb, "before MBA")==0)
return -1;
@@ -196,7 +196,7 @@ static int h263_decode_gob_header(H263DecContext *const h)
}else{
gob_number = get_bits(&h->gb, 5); /* GN */
h->c.mb_x = 0;
- h->c.mb_y = h->c.gob_index* gob_number;
+ h->c.mb_y = h->gob_index* gob_number;
skip_bits(&h->gb, 2); /* GFID */
h->c.qscale = get_bits(&h->gb, 5); /* GQUANT */
}
@@ -377,19 +377,19 @@ static void preview_obmc(H263DecContext *const h)
}else{
get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
if (cbpc & 8) {
- skip_bits(&h->gb, h->c.modified_quant ? (get_bits1(&h->gb) ? 1 : 5) : 2);
+ skip_bits(&h->gb, h->modified_quant ? (get_bits1(&h->gb) ? 1 : 5) : 2);
}
if ((cbpc & 16) == 0) {
h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
/* 16x16 motion prediction */
mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
- if (h->c.umvplus)
+ if (h->umvplus)
mx = h263p_decode_umotion(h, pred_x);
else
mx = ff_h263_decode_motion(h, pred_x, 1);
- if (h->c.umvplus)
+ if (h->umvplus)
my = h263p_decode_umotion(h, pred_y);
else
my = ff_h263_decode_motion(h, pred_y, 1);
@@ -402,16 +402,16 @@ static void preview_obmc(H263DecContext *const h)
h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
for(i=0;i<4;i++) {
mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
- if (h->c.umvplus)
+ if (h->umvplus)
mx = h263p_decode_umotion(h, pred_x);
else
mx = ff_h263_decode_motion(h, pred_x, 1);
- if (h->c.umvplus)
+ if (h->umvplus)
my = h263p_decode_umotion(h, pred_y);
else
my = ff_h263_decode_motion(h, pred_y, 1);
- if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
mot_val[0] = mx;
mot_val[1] = my;
@@ -434,7 +434,7 @@ static void h263_decode_dquant(H263DecContext *const h)
static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
int qscale;
- if (h->c.modified_quant) {
+ if (h->modified_quant) {
if (get_bits1(&h->gb))
qscale = ff_modified_quant_tab[get_bits1(&h->gb)][h->c.qscale];
else
@@ -598,7 +598,7 @@ retry:
return -1;
}
/* escape */
- if (CONFIG_FLV_DECODER && h->c.h263_flv) {
+ if (CONFIG_FLV_DECODER && h->flv) {
int is11 = SHOW_UBITS(re, &h->gb, 1);
SKIP_CACHE(re, &h->gb, 1);
run = SHOW_UBITS(re, &h->gb, 7) + 1;
@@ -646,7 +646,7 @@ retry:
block[scan_table[i]] = level;
break;
}
- if(h->c.alt_inter_vlc && rl == &ff_h263_rl_inter && !h->c.mb_intra){
+ if(h->alt_inter_vlc && rl == &ff_h263_rl_inter && !h->c.mb_intra){
//Looks like a hack but no, it's the way it is supposed to work ...
rl = &ff_rl_intra_aic;
i = 0;
@@ -826,7 +826,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
return SLICE_ERROR;
}
- if (!h->c.alt_inter_vlc|| (cbpc & 3)!=3)
+ if (!h->alt_inter_vlc|| (cbpc & 3)!=3)
cbpy ^= 0xF;
cbp = (cbpc & 3) | (cbpy << 2);
@@ -840,7 +840,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
/* 16x16 motion prediction */
h->c.mv_type = MV_TYPE_16X16;
ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
- if (h->c.umvplus)
+ if (h->umvplus)
mx = h263p_decode_umotion(h, pred_x);
else
mx = ff_h263_decode_motion(h, pred_x, 1);
@@ -848,7 +848,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
if (mx >= 0xffff)
return SLICE_ERROR;
- if (h->c.umvplus)
+ if (h->umvplus)
my = h263p_decode_umotion(h, pred_y);
else
my = ff_h263_decode_motion(h, pred_y, 1);
@@ -858,21 +858,21 @@ int ff_h263_decode_mb(H263DecContext *const h)
h->c.mv[0][0][0] = mx;
h->c.mv[0][0][1] = my;
- if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
} else {
h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
h->c.mv_type = MV_TYPE_8X8;
for(i=0;i<4;i++) {
mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
- if (h->c.umvplus)
+ if (h->umvplus)
mx = h263p_decode_umotion(h, pred_x);
else
mx = ff_h263_decode_motion(h, pred_x, 1);
if (mx >= 0xffff)
return SLICE_ERROR;
- if (h->c.umvplus)
+ if (h->umvplus)
my = h263p_decode_umotion(h, pred_y);
else
my = ff_h263_decode_motion(h, pred_y, 1);
@@ -880,7 +880,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
return SLICE_ERROR;
h->c.mv[0][i][0] = mx;
h->c.mv[0][i][1] = my;
- if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
mot_val[0] = mx;
mot_val[1] = my;
@@ -926,7 +926,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
return SLICE_ERROR;
}
- if (!h->c.alt_inter_vlc || (cbpc & 3)!=3)
+ if (!h->alt_inter_vlc || (cbpc & 3)!=3)
cbpy ^= 0xF;
cbp = (cbpc & 3) | (cbpy << 2);
@@ -951,21 +951,21 @@ int ff_h263_decode_mb(H263DecContext *const h)
int16_t *mot_val = ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
h->c.mv_dir = MV_DIR_FORWARD;
- if (h->c.umvplus)
+ if (h->umvplus)
mx = h263p_decode_umotion(h, pred_x);
else
mx = ff_h263_decode_motion(h, pred_x, 1);
if (mx >= 0xffff)
return SLICE_ERROR;
- if (h->c.umvplus)
+ if (h->umvplus)
my = h263p_decode_umotion(h, pred_y);
else
my = ff_h263_decode_motion(h, pred_y, 1);
if (my >= 0xffff)
return SLICE_ERROR;
- if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
h->c.mv[0][0][0] = mx;
@@ -978,21 +978,21 @@ int ff_h263_decode_mb(H263DecContext *const h)
int16_t *mot_val = ff_h263_pred_motion(&h->c, 0, 1, &pred_x, &pred_y);
h->c.mv_dir |= MV_DIR_BACKWARD;
- if (h->c.umvplus)
+ if (h->umvplus)
mx = h263p_decode_umotion(h, pred_x);
else
mx = ff_h263_decode_motion(h, pred_x, 1);
if (mx >= 0xffff)
return SLICE_ERROR;
- if (h->c.umvplus)
+ if (h->umvplus)
my = h263p_decode_umotion(h, pred_y);
else
my = ff_h263_decode_motion(h, pred_y, 1);
if (my >= 0xffff)
return SLICE_ERROR;
- if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
+ if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
h->c.mv[1][0][0] = mx;
@@ -1112,9 +1112,9 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
/* temporal reference */
i = get_bits(&h->gb, 8); /* picture timestamp */
- i -= (i - (h->c.picture_number & 0xFF) + 128) & ~0xFF;
+ i -= (i - (h->picture_number & 0xFF) + 128) & ~0xFF;
- h->c.picture_number = (h->c.picture_number&~0xFF) + i;
+ h->picture_number = (h->picture_number&~0xFF) + i;
/* PTYPE starts here */
if (check_marker(h->c.avctx, &h->gb, "in PTYPE") != 1) {
@@ -1175,7 +1175,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
format = get_bits(&h->gb, 3);
ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);
h->custom_pcf = get_bits1(&h->gb);
- h->c.umvplus = get_bits1(&h->gb); /* Unrestricted Motion Vector */
+ h->umvplus = get_bits1(&h->gb); /* Unrestricted Motion Vector */
if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
}
@@ -1185,16 +1185,16 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
if (h->c.avctx->lowres)
h->c.loop_filter = 0;
- h->c.h263_slice_structured = get_bits1(&h->gb);
+ h->h263_slice_structured = get_bits1(&h->gb);
if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
}
if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
}
- h->c.alt_inter_vlc = get_bits1(&h->gb);
- h->c.modified_quant = get_bits1(&h->gb);
- if (h->c.modified_quant)
+ h->alt_inter_vlc = get_bits1(&h->gb);
+ h->modified_quant = get_bits1(&h->gb);
+ if (h->modified_quant)
h->c.chroma_qscale_table= ff_h263_chroma_qscale_table;
skip_bits(&h->gb, 1); /* Prevent start code emulation */
@@ -1277,11 +1277,11 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
skip_bits(&h->gb, 2); //extended Temporal reference
if (ufep) {
- if (h->c.umvplus) {
+ if (h->umvplus) {
if (get_bits1(&h->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
skip_bits1(&h->gb);
}
- if (h->c.h263_slice_structured) {
+ if (h->h263_slice_structured) {
if (get_bits1(&h->gb) != 0) {
av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
}
@@ -1313,7 +1313,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
h->c.mb_height = (h->c.height + 15U) / 16;
h->c.mb_num = h->c.mb_width * h->c.mb_height;
- h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
+ h->gob_index = H263_GOB_HEIGHT(h->c.height);
if (h->pb_frame) {
skip_bits(&h->gb, 3); /* Temporal reference for B-pictures */
@@ -1323,11 +1323,11 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
}
if (h->c.pict_type!=AV_PICTURE_TYPE_B) {
- h->c.time = h->c.picture_number;
+ h->c.time = h->picture_number;
h->c.pp_time = h->c.time - h->c.last_non_b_time;
h->c.last_non_b_time = h->c.time;
}else{
- h->c.time = h->c.picture_number;
+ h->c.time = h->picture_number;
h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
if (h->c.pp_time <= h->c.pb_time ||
h->c.pp_time <= h->c.pp_time - h->c.pb_time ||
@@ -1342,7 +1342,7 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
if (skip_1stop_8data_bits(&h->gb) < 0)
return AVERROR_INVALIDDATA;
- if (h->c.h263_slice_structured) {
+ if (h->h263_slice_structured) {
if (check_marker(h->c.avctx, &h->gb, "SEPB1") != 1) {
return -1;
}
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 682d4bd24e..250ce0b043 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -244,7 +244,7 @@ static int h263_encode_picture_header(MPVMainEncContext *const m)
coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
put_bits(&s->pb, 22, 0x20); /* PSC */
- temp_ref= s->c.picture_number * (int64_t)coded_frame_rate * s->c.avctx->time_base.num / //FIXME use timestamp
+ temp_ref = s->picture_number * (int64_t)coded_frame_rate * s->c.avctx->time_base.num / //FIXME use timestamp
(coded_frame_rate_base * (int64_t)s->c.avctx->time_base.den);
put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */
@@ -281,16 +281,16 @@ static int h263_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb, 3, format);
put_bits(&s->pb,1, custom_pcf);
- put_bits(&s->pb,1, s->c.umvplus); /* Unrestricted Motion Vector */
+ put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */
put_bits(&s->pb,1,0); /* SAC: off */
put_bits(&s->pb,1,s->c.obmc); /* Advanced Prediction Mode */
put_bits(&s->pb,1,s->c.h263_aic); /* Advanced Intra Coding */
put_bits(&s->pb,1,s->c.loop_filter); /* Deblocking Filter */
- put_bits(&s->pb,1,s->c.h263_slice_structured); /* Slice Structured */
+ put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */
put_bits(&s->pb,1,0); /* Reference Picture Selection: off */
put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */
- put_bits(&s->pb,1,s->c.alt_inter_vlc); /* Alternative Inter VLC */
- put_bits(&s->pb,1,s->c.modified_quant); /* Modified Quantization: */
+ put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */
+ put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */
put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
put_bits(&s->pb,3,0); /* Reserved */
@@ -327,11 +327,11 @@ static int h263_encode_picture_header(MPVMainEncContext *const m)
}
/* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
- if (s->c.umvplus)
+ if (s->umvplus)
// put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
//FIXME check actual requested range
put_bits(&s->pb,2,1); /* unlimited */
- if(s->c.h263_slice_structured)
+ if (s->h263_slice_structured)
put_bits(&s->pb,2,0); /* no weird submodes */
put_bits(&s->pb, 5, s->c.qscale);
@@ -339,7 +339,7 @@ static int h263_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb, 1, 0); /* no PEI */
- if(s->c.h263_slice_structured){
+ if (s->h263_slice_structured) {
put_bits(&s->pb, 1, 1);
av_assert1(s->c.mb_x == 0 && s->c.mb_y == 0);
@@ -374,7 +374,7 @@ void ff_h263_encode_gob_header(MPVEncContext *const s, int mb_line)
{
put_bits(&s->pb, 17, 1); /* GBSC */
- if(s->c.h263_slice_structured){
+ if (s->h263_slice_structured) {
put_bits(&s->pb, 1, 1);
ff_h263_encode_mba(s);
@@ -385,7 +385,7 @@ void ff_h263_encode_gob_header(MPVEncContext *const s, int mb_line)
put_bits(&s->pb, 1, 1);
put_bits(&s->pb, 2, s->c.pict_type == AV_PICTURE_TYPE_I); /* GFID */
}else{
- int gob_number= mb_line / s->c.gob_index;
+ int gob_number = mb_line / s->gob_index;
put_bits(&s->pb, 5, gob_number); /* GN */
put_bits(&s->pb, 2, s->c.pict_type == AV_PICTURE_TYPE_I); /* GFID */
@@ -479,7 +479,7 @@ static void h263_encode_block(MPVEncContext *const s, int16_t block[], int n)
if (s->c.h263_aic && s->c.mb_intra)
rl = &ff_rl_intra_aic;
- if(s->c.alt_inter_vlc && !s->c.mb_intra){
+ if (s->alt_inter_vlc && !s->c.mb_intra) {
int aic_vlc_bits=0;
int inter_vlc_bits=0;
int wrong_pos=-1;
@@ -634,7 +634,7 @@ static void h263_encode_mb(MPVEncContext *const s,
cbpc = cbp & 3;
cbpy = cbp >> 2;
- if(s->c.alt_inter_vlc==0 || cbpc!=3)
+ if (!s->alt_inter_vlc || cbpc!=3)
cbpy ^= 0xF;
if(s->dquant) cbpc+= 8;
if(s->c.mv_type==MV_TYPE_16X16){
@@ -653,7 +653,7 @@ static void h263_encode_mb(MPVEncContext *const s,
/* motion vectors: 16x16 mode */
ff_h263_pred_motion(&s->c, 0, 0, &pred_x, &pred_y);
- if (!s->c.umvplus) {
+ if (!s->umvplus) {
ff_h263_encode_motion_vector(s, motion_x - pred_x,
motion_y - pred_y, 1);
}
@@ -682,7 +682,7 @@ static void h263_encode_mb(MPVEncContext *const s,
motion_x = s->c.cur_pic.motion_val[0][s->c.block_index[i]][0];
motion_y = s->c.cur_pic.motion_val[0][s->c.block_index[i]][1];
- if (!s->c.umvplus) {
+ if (!s->umvplus) {
ff_h263_encode_motion_vector(s, motion_x - pred_x,
motion_y - pred_y, 1);
}
@@ -718,7 +718,7 @@ static void h263_encode_mb(MPVEncContext *const s,
else
level = (level - (scale>>1))/scale;
- if (!s->c.modified_quant) {
+ if (!s->modified_quant) {
if (level < -127)
level = -127;
else if (level > 127)
@@ -838,18 +838,18 @@ av_cold void ff_h263_encode_init(MPVMainEncContext *const m)
}
s->ac_esc_length= 7+1+6+8;
- if (s->c.modified_quant)
+ if (s->modified_quant)
s->c.chroma_qscale_table = ff_h263_chroma_qscale_table;
// Only used for H.263 and H.263+
- s->c.gob_index = H263_GOB_HEIGHT(s->c.height);
+ s->gob_index = H263_GOB_HEIGHT(s->c.height);
// use fcodes >1 only for MPEG-4 & H.263 & H.263+ FIXME
switch(s->c.codec_id){
case AV_CODEC_ID_H263P:
- if (s->c.umvplus)
+ if (s->umvplus)
m->fcode_tab = umv_fcode_tab + MAX_MV;
- if (s->c.modified_quant) {
+ if (s->modified_quant) {
s->min_qcoeff= -2047;
s->max_qcoeff= 2047;
}else{
@@ -922,10 +922,10 @@ const FFCodec ff_h263_encoder = {
};
static const AVOption h263p_options[] = {
- { "umv", "Use unlimited motion vectors.", OFFSET(umvplus), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
- { "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ { "umv", "Use unlimited motion vectors.", FF_MPV_OFFSET(umvplus), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ { "aiv", "Use alternative inter VLC.", FF_MPV_OFFSET(alt_inter_vlc), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
- { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
+ { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", FF_MPV_OFFSET(h263_slice_structured), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
FF_MPV_COMMON_OPTS
FF_MPV_COMMON_MOTION_EST_OPTS
{ NULL },
diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
index 521a915aa0..fb480d0eec 100644
--- a/libavcodec/mpeg12enc.c
+++ b/libavcodec/mpeg12enc.c
@@ -350,9 +350,8 @@ static int mpeg1_encode_picture_header(MPVMainEncContext *const m)
put_header(s, PICTURE_START_CODE);
/* temporal reference */
- // RAL: s->c.picture_number instead of s->fake_picture_number
put_bits(&s->pb, 10,
- (s->c.picture_number - mpeg12->gop_picture_number) & 0x3ff);
+ (s->picture_number - mpeg12->gop_picture_number) & 0x3ff);
put_bits(&s->pb, 3, s->c.pict_type);
m->vbv_delay_pos = put_bytes_count(&s->pb, 0);
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index bc17b0ed09..aaf2ecf7c4 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -2699,7 +2699,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
} else {
/* is setting low delay flag only once the smartest thing to do?
* low delay detection will not be overridden. */
- if (h->c.picture_number == 0) {
+ if (h->picture_number == 0) {
switch (ctx->vo_type) {
case SIMPLE_VO_TYPE:
case ADV_SIMPLE_VO_TYPE:
@@ -2938,8 +2938,8 @@ no_cplx_est:
ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */
- h->c.data_partitioning = get_bits1(gb);
- if (h->c.data_partitioning)
+ h->data_partitioning = get_bits1(gb);
+ if (h->data_partitioning)
ctx->rvlc = get_bits1(gb);
if (vo_ver_id != 1) {
@@ -2996,7 +2996,7 @@ no_cplx_est:
h->c.low_delay,
ctx->scalability ? "scalability " :"" ,
h->c.quarter_sample ? "qpel " : "",
- h->c.data_partitioning ? "partition " : "",
+ h->data_partitioning ? "partition " : "",
ctx->rvlc ? "rvlc " : ""
);
}
@@ -3222,7 +3222,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
h->c.low_delay = 0;
}
- h->c.partitioned_frame = h->c.data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B;
+ h->c.partitioned_frame = h->data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B;
if (h->c.partitioned_frame)
h->decode_mb = mpeg4_decode_partitioned_mb;
else
@@ -3437,7 +3437,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
h->c.pict_type == AV_PICTURE_TYPE_I ? 'I' : (h->c.pict_type == AV_PICTURE_TYPE_P ? 'P' : (h->c.pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')),
gb->size_in_bits,h->c.progressive_sequence, h->c.alternate_scan,
h->c.top_field_first, h->c.quarter_sample ? 'q' : 'h',
- h->c.data_partitioning, ctx->resync_marker,
+ h->data_partitioning, ctx->resync_marker,
ctx->num_sprite_warping_points, ctx->sprite_warping_accuracy,
1 - h->c.no_rounding, ctx->vo_type,
ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold,
@@ -3472,13 +3472,13 @@ end:
* (divx4/xvid/opendivx). Note we cannot detect divx5 without B-frames
* easily (although it's buggy too) */
if (ctx->vo_type == 0 && ctx->vol_control_parameters == 0 &&
- ctx->divx_version == -1 && h->c.picture_number == 0) {
+ ctx->divx_version == -1 && h->picture_number == 0) {
av_log(h->c.avctx, AV_LOG_WARNING,
"looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
h->c.low_delay = 1;
}
- h->c.picture_number++; // better than pic number==0 always ;)
+ h->picture_number++; // better than pic number==0 always ;)
if (h->c.workaround_bugs & FF_BUG_EDGE) {
h->c.h_edge_pos = h->c.width;
@@ -3898,7 +3898,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
s->sprite_brightness_change = s1->sprite_brightness_change;
s->sprite_warping_accuracy = s1->sprite_warping_accuracy;
s->num_sprite_warping_points = s1->num_sprite_warping_points;
- s->h.c.data_partitioning = s1->h.c.data_partitioning;
+ s->h.data_partitioning = s1->h.data_partitioning;
s->mpeg_quant = s1->mpeg_quant;
s->rvlc = s1->rvlc;
s->resync_marker = s1->resync_marker;
@@ -3923,6 +3923,8 @@ static int mpeg4_update_thread_context(AVCodecContext *dst,
s->h.skipped_last_frame = s1->h.skipped_last_frame;
s->h.padding_bug_score = s1->h.padding_bug_score; // FIXME: racy
+ s->h.picture_number = s1->h.picture_number;
+
memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift));
memcpy(s->sprite_traj, s1->sprite_traj, sizeof(s1->sprite_traj));
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 540ab8e4c3..7432c1f9bd 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -453,10 +453,10 @@ static void mpeg4_encode_mb(MPVEncContext *const s, int16_t block[][64],
int motion_x, int motion_y)
{
int cbpc, cbpy, pred_x, pred_y;
- PutBitContext *const pb2 = s->c.data_partitioning ? &s->pb2 : &s->pb;
- PutBitContext *const tex_pb = s->c.data_partitioning && s->c.pict_type != AV_PICTURE_TYPE_B ? &s->tex_pb : &s->pb;
- PutBitContext *const dc_pb = s->c.data_partitioning && s->c.pict_type != AV_PICTURE_TYPE_I ? &s->pb2 : &s->pb;
- const int interleaved_stats = (s->c.avctx->flags & AV_CODEC_FLAG_PASS1) && !s->c.data_partitioning ? 1 : 0;
+ PutBitContext *const pb2 = s->data_partitioning ? &s->pb2 : &s->pb;
+ PutBitContext *const tex_pb = s->data_partitioning && s->c.pict_type != AV_PICTURE_TYPE_B ? &s->tex_pb : &s->pb;
+ PutBitContext *const dc_pb = s->data_partitioning && s->c.pict_type != AV_PICTURE_TYPE_I ? &s->pb2 : &s->pb;
+ const int interleaved_stats = (s->c.avctx->flags & AV_CODEC_FLAG_PASS1) && !s->data_partitioning;
if (!s->c.mb_intra) {
int i, cbp;
@@ -994,8 +994,8 @@ static void mpeg4_encode_vol_header(Mpeg4EncContext *const m4,
put_bits(&s->pb, 1, s->c.quarter_sample);
put_bits(&s->pb, 1, 1); /* complexity estimation disable */
put_bits(&s->pb, 1, s->rtp_mode ? 0 : 1); /* resync marker disable */
- put_bits(&s->pb, 1, s->c.data_partitioning ? 1 : 0);
- if (s->c.data_partitioning)
+ put_bits(&s->pb, 1, s->data_partitioning);
+ if (s->data_partitioning)
put_bits(&s->pb, 1, 0); /* no rvlc */
if (vo_ver_id != 1) {
@@ -1027,13 +1027,13 @@ static int mpeg4_encode_picture_header(MPVMainEncContext *const m)
if (!(s->c.avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) {
if (s->c.avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) // HACK, the reference sw is buggy
mpeg4_encode_visual_object_header(m);
- if (s->c.avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || s->c.picture_number == 0) // HACK, the reference sw is buggy
+ if (s->c.avctx->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || s->picture_number == 0) // HACK, the reference sw is buggy
mpeg4_encode_vol_header(m4, 0, 0);
}
mpeg4_encode_gop_header(m);
}
- s->c.partitioned_frame = s->c.data_partitioning && s->c.pict_type != AV_PICTURE_TYPE_B;
+ s->c.partitioned_frame = s->data_partitioning && s->c.pict_type != AV_PICTURE_TYPE_B;
put_bits32(&s->pb, VOP_STARTCODE); /* vop header */
put_bits(&s->pb, 2, s->c.pict_type - 1); /* pict type: I = 0 , P = 1 */
@@ -1338,7 +1338,7 @@ void ff_mpeg4_encode_video_packet_header(MPVEncContext *const s)
#define OFFSET(x) offsetof(MPVEncContext, x)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
- { "data_partitioning", "Use data partitioning.", OFFSET(c.data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ { "data_partitioning", "Use data partitioning.", FF_MPV_OFFSET(data_partitioning), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "alternate_scan", "Enable alternate scantable.", OFFSET(c.alternate_scan), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "mpeg_quant", "Use MPEG quantizers instead of H.263",
OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, VE },
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 9c3589752c..a137fe31db 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -194,8 +194,6 @@ av_cold void ff_mpv_common_defaults(MpegEncContext *s)
s->progressive_sequence = 1;
s->picture_structure = PICT_FRAME;
- s->picture_number = 0;
-
s->slice_context_count = 1;
}
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 9318801019..3b47a02ae1 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -87,9 +87,6 @@ typedef struct MpegEncContext {
enum OutputFormat out_format; ///< output format
int h263_pred; ///< use MPEG-4/H.263 ac/dc predictions
-/* the following codec id fields are deprecated in favor of codec_id */
- int h263_flv; ///< use flv H.263 header
-
enum AVCodecID codec_id; /* see AV_CODEC_ID_xxx */
int encoding; ///< true if we are encoding (vs decoding)
int workaround_bugs; ///< workaround bugs in encoders which cannot be detected automatically
@@ -98,7 +95,6 @@ typedef struct MpegEncContext {
/* sequence parameters */
int context_initialized;
- int picture_number; //FIXME remove, unclear definition
int mb_width, mb_height; ///< number of MBs horizontally & vertically
int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11
int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
@@ -215,15 +211,10 @@ typedef struct MpegEncContext {
int resync_mb_y; ///< y position of last resync marker
/* H.263 specific */
- int gob_index;
int obmc; ///< overlapped block motion compensation
/* H.263+ specific */
- int umvplus; ///< == H.263+ && unrestricted_mv
int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
- int h263_slice_structured;
- int alt_inter_vlc; ///< alternative inter vlc
- int modified_quant;
int loop_filter;
/* MPEG-4 specific */
@@ -238,12 +229,10 @@ typedef struct MpegEncContext {
uint16_t pb_field_time; ///< like above, just for interlaced
int mcsel;
int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
- int data_partitioning; ///< data partitioning flag from header
int partitioned_frame; ///< is current frame partitioned
int low_delay; ///< no reordering needed / has no B-frames
/* MSMPEG4 specific */
- int slice_height; ///< in macroblocks
int first_slice_line; ///< used in MPEG-4 too to handle resync markers
enum {
MSMP4_UNUSED,
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 1ae36dc751..e9d0009f3c 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -97,8 +97,6 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst,
s->quarter_sample = s1->quarter_sample;
- s->picture_number = s1->picture_number;
-
ff_mpv_replace_picture(&s->cur_pic, &s1->cur_pic);
ff_mpv_replace_picture(&s->last_pic, &s1->last_pic);
ff_mpv_replace_picture(&s->next_pic, &s1->next_pic);
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index f54f458ab8..ff6d6a8cd7 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -924,9 +924,9 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.out_format = FMT_H263;
/* Fx */
s->c.h263_aic = (avctx->flags & AV_CODEC_FLAG_AC_PRED) ? 1 : 0;
- s->c.modified_quant = s->c.h263_aic;
+ s->modified_quant = s->c.h263_aic;
s->c.loop_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
- s->me.unrestricted_mv = s->c.obmc || s->c.loop_filter || s->c.umvplus;
+ s->me.unrestricted_mv = s->c.obmc || s->c.loop_filter || s->umvplus;
s->flipflop_rounding = 1;
/* /Fx */
@@ -955,7 +955,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
s->c.out_format = FMT_H263;
avctx->delay = 0;
s->c.low_delay = 1;
- s->c.modified_quant = 1;
+ s->modified_quant = 1;
// Set here to force allocation of dc_val;
// will be set later on a per-frame basis.
s->c.h263_aic = 1;
@@ -1078,7 +1078,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
if (s->c.slice_context_count > 1) {
s->rtp_mode = 1;
if (avctx->codec_id == AV_CODEC_ID_H263P)
- s->c.h263_slice_structured = 1;
+ s->h263_slice_structured = 1;
}
ret = ff_mpv_init_duplicate_contexts(&s->c);
if (ret < 0)
@@ -1853,7 +1853,7 @@ static int select_input_picture(MPVMainEncContext *const m)
ff_mpv_unref_picture(&s->c.cur_pic);
return ret;
}
- s->c.picture_number = s->c.cur_pic.ptr->display_picture_number;
+ s->picture_number = s->c.cur_pic.ptr->display_picture_number;
}
return 0;
@@ -1963,7 +1963,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
/* output? */
if (s->new_pic->data[0]) {
- int growing_buffer = context_count == 1 && !s->c.data_partitioning;
+ int growing_buffer = context_count == 1 && !s->data_partitioning;
size_t pkt_size = 10000 + s->c.mb_width * s->c.mb_height *
(growing_buffer ? 64 : (MAX_MB_BYTES + 100));
if (CONFIG_MJPEG_ENCODER && avctx->codec_id == AV_CODEC_ID_MJPEG) {
@@ -2738,7 +2738,7 @@ static void encode_mb_hq(MPVEncContext *const s, MBBackup *const backup, MBBacku
s->block = s->blocks[*next_block];
s->pb = pb[*next_block];
- if (s->c.data_partitioning) {
+ if (s->data_partitioning) {
s->pb2 = pb2 [*next_block];
s->tex_pb= tex_pb[*next_block];
}
@@ -2754,7 +2754,7 @@ static void encode_mb_hq(MPVEncContext *const s, MBBackup *const backup, MBBacku
encode_mb(s, motion_x, motion_y);
score= put_bits_count(&s->pb);
- if (s->c.data_partitioning) {
+ if (s->data_partitioning) {
score+= put_bits_count(&s->pb2);
score+= put_bits_count(&s->tex_pb);
}
@@ -2774,7 +2774,7 @@ static void encode_mb_hq(MPVEncContext *const s, MBBackup *const backup, MBBacku
*dmin= score;
*next_block^=1;
- save_context_after_encode(best, s, s->c.data_partitioning);
+ save_context_after_encode(best, s, s->data_partitioning);
}
}
@@ -2915,8 +2915,8 @@ static void write_mb_info(MPVEncContext *const s)
{
uint8_t *ptr = s->mb_info_ptr + s->mb_info_size - 12;
int offset = put_bits_count(&s->pb);
- int mba = s->c.mb_x + s->c.mb_width * (s->c.mb_y % s->c.gob_index);
- int gobn = s->c.mb_y / s->c.gob_index;
+ int mba = s->c.mb_x + s->c.mb_width * (s->c.mb_y % s->gob_index);
+ int gobn = s->c.mb_y / s->gob_index;
int pred_x, pred_y;
if (CONFIG_H263_ENCODER)
ff_h263_pred_motion(&s->c, 0, 0, &pred_x, &pred_y);
@@ -3068,7 +3068,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
av_log(s->c.avctx, AV_LOG_ERROR, "encoded frame too large\n");
return -1;
}
- if (s->c.data_partitioning) {
+ if (s->data_partitioning) {
if (put_bytes_left(&s->pb2, 0) < MAX_MB_BYTES ||
put_bytes_left(&s->tex_pb, 0) < MAX_MB_BYTES) {
av_log(s->c.avctx, AV_LOG_ERROR, "encoded partitioned frame too large\n");
@@ -3101,8 +3101,8 @@ static int encode_thread(AVCodecContext *c, void *arg){
switch (s->c.codec_id) {
case AV_CODEC_ID_H263:
case AV_CODEC_ID_H263P:
- if (!s->c.h263_slice_structured)
- if (s->c.mb_x || s->c.mb_y % s->c.gob_index) is_gob_start = 0;
+ if (!s->h263_slice_structured)
+ if (s->c.mb_x || s->c.mb_y % s->gob_index) is_gob_start = 0;
break;
case AV_CODEC_ID_MPEG2VIDEO:
if (s->c.mb_x == 0 && s->c.mb_y != 0) is_gob_start = 1;
@@ -3128,7 +3128,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
current_packet_size= put_bits_ptr(&s->pb) - s->ptr_lastgob;
if (s->error_rate && s->c.resync_mb_x + s->c.resync_mb_y > 0) {
- int r = put_bytes_count(&s->pb, 0) + s->c.picture_number + 16 + s->c.mb_x + s->c.mb_y;
+ int r = put_bytes_count(&s->pb, 0) + s->picture_number + 16 + s->c.mb_x + s->c.mb_y;
int d = 100 / s->error_rate;
if(r % d == 0){
current_packet_size=0;
@@ -3194,7 +3194,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
backup_context_before_encode(&backup_s, s);
backup_s.pb= s->pb;
- if (s->c.data_partitioning) {
+ if (s->data_partitioning) {
backup_s.pb2= s->pb2;
backup_s.tex_pb= s->tex_pb;
}
@@ -3417,14 +3417,14 @@ static int encode_thread(AVCodecContext *c, void *arg){
}
}
- store_context_after_encode(s, &best_s, s->c.data_partitioning);
+ store_context_after_encode(s, &best_s, s->data_partitioning);
pb_bits_count= put_bits_count(&s->pb);
flush_put_bits(&s->pb);
ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count);
s->pb= backup_s.pb;
- if (s->c.data_partitioning) {
+ if (s->data_partitioning) {
pb2_bits_count= put_bits_count(&s->pb2);
flush_put_bits(&s->pb2);
ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count);
@@ -3711,7 +3711,7 @@ static void set_frame_distances(MPVEncContext *const s)
}else{
s->c.pp_time = s->c.time - s->c.last_non_b_time;
s->c.last_non_b_time = s->c.time;
- av_assert1(s->c.picture_number == 0 || s->c.pp_time > 0);
+ av_assert1(s->picture_number == 0 || s->c.pp_time > 0);
}
}
@@ -3814,7 +3814,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
m->mb_var_sum, m->mc_mb_var_sum);
}
- if (!s->c.umvplus) {
+ if (!s->umvplus) {
if (s->c.pict_type == AV_PICTURE_TYPE_P || s->c.pict_type == AV_PICTURE_TYPE_S) {
s->f_code = ff_get_best_fcode(m, s->p_mv_table, CANDIDATE_MB_TYPE_INTER);
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 7aa8af5412..ad48ce6df3 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -128,6 +128,8 @@ typedef struct MPVEncContext {
int dct_count[2];
uint16_t (*dct_offset)[64];
+ int picture_number;
+
/* statistics, used for 2-pass encoding */
int mv_bits;
int i_tex_bits;
@@ -139,11 +141,18 @@ typedef struct MPVEncContext {
int mb_skip_run;
/* H.263 specific */
+ int gob_index;
int mb_info; ///< interval for outputting info about mb offsets as side data
int prev_mb_info, last_mb_info;
int mb_info_size;
uint8_t *mb_info_ptr;
+ /* H.263+ specific */
+ int umvplus; ///< == H.263+ && unrestricted_mv
+ int h263_slice_structured;
+ int alt_inter_vlc; ///< alternative inter vlc
+ int modified_quant;
+
/* MJPEG specific */
struct MJpegContext *mjpeg_ctx;
int esc_pos;
@@ -152,11 +161,13 @@ typedef struct MPVEncContext {
int last_mv_dir; ///< last mv_dir, used for B-frame encoding
/* MPEG-4 specific */
+ int data_partitioning; ///< data partitioning flag, set via option
int mpeg_quant;
PutBitContext tex_pb; ///< used for data partitioned VOPs
PutBitContext pb2; ///< used for data partitioned VOPs
/* MSMPEG4 specific */
+ int slice_height; ///< in macroblocks
int flipflop_rounding; ///< also used for MPEG-4, H.263+
int esc3_level_length;
diff --git a/libavcodec/msmpeg4dec.c b/libavcodec/msmpeg4dec.c
index a96a0335f7..d2249559c9 100644
--- a/libavcodec/msmpeg4dec.c
+++ b/libavcodec/msmpeg4dec.c
@@ -403,7 +403,7 @@ static int msmpeg4_decode_picture_header(H263DecContext *const h)
return -1;
}
- h->c.slice_height = code;
+ h->slice_height = code;
}else{
/* 0x17: one slice, 0x18: two slices, ... */
if (code < 0x17){
@@ -411,7 +411,7 @@ static int msmpeg4_decode_picture_header(H263DecContext *const h)
return -1;
}
- h->c.slice_height = h->c.mb_height / (code - 0x16);
+ h->slice_height = h->c.mb_height / (code - 0x16);
}
switch (h->c.msmpeg4_version) {
@@ -455,7 +455,7 @@ static int msmpeg4_decode_picture_header(H263DecContext *const h)
ms->rl_table_index,
ms->dc_table_index,
ms->per_mb_rl_table,
- h->c.slice_height);
+ h->slice_height);
} else {
switch (h->c.msmpeg4_version) {
case MSMP4_V1:
@@ -866,7 +866,7 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
av_unreachable("List contains all cases using ff_msmpeg4_decode_init()");
}
- h->c.slice_height = h->c.mb_height; //to avoid 1/0 if the first frame is not a keyframe
+ h->slice_height = h->c.mb_height; //to avoid 1/0 if the first frame is not a keyframe
ff_thread_once(&init_static_once, msmpeg4_decode_init_static);
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index bcb4af23e9..874e0c1f2b 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -243,8 +243,8 @@ static int msmpeg4_encode_picture_header(MPVMainEncContext *const m)
s->c.inter_intra_pred, s->c.width, s->c.height);
if (s->c.pict_type == AV_PICTURE_TYPE_I) {
- s->c.slice_height = s->c.mb_height/1;
- put_bits(&s->pb, 5, 0x16 + s->c.mb_height/s->c.slice_height);
+ s->slice_height = s->c.mb_height/1;
+ put_bits(&s->pb, 5, 0x16 + s->c.mb_height / s->slice_height);
if (s->c.msmpeg4_version == MSMP4_WMV1) {
ff_msmpeg4_encode_ext_header(s);
@@ -332,7 +332,7 @@ void ff_msmpeg4_encode_motion(MSMPEG4EncContext *const ms,
void ff_msmpeg4_handle_slices(MPVEncContext *const s)
{
if (s->c.mb_x == 0) {
- if (s->c.slice_height && (s->c.mb_y % s->c.slice_height) == 0) {
+ if (s->slice_height && (s->c.mb_y % s->slice_height) == 0) {
if (s->c.msmpeg4_version < MSMP4_WMV1)
ff_mpeg4_clean_buffers(&s->c);
s->c.first_slice_line = 1;
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 3dc44683d0..7f89b5b218 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -901,7 +901,7 @@ void ff_get_2pass_fcode(MPVMainEncContext *const m)
{
MPVEncContext *const s = &m->s;
const RateControlContext *rcc = &m->rc_context;
- const RateControlEntry *rce = &rcc->entry[s->c.picture_number];
+ const RateControlEntry *rce = &rcc->entry[s->picture_number];
s->f_code = rce->f_code;
s->b_code = rce->b_code;
@@ -920,7 +920,7 @@ float ff_rate_estimate_qscale(MPVMainEncContext *const m, int dry_run)
double diff;
double short_term_q;
double fps;
- int picture_number = s->c.picture_number;
+ int picture_number = s->picture_number;
int64_t wanted_bits;
RateControlEntry local_rce, *rce;
double bits;
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index c104efc212..ed702dfb66 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -372,7 +372,7 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
h->h263_long_vectors = avctx->extradata[3] & 1;
rv->sub_id = AV_RB32A(avctx->extradata + 4);
if (avctx->codec_id == AV_CODEC_ID_RV20) {
- h->c.modified_quant = 1;
+ h->modified_quant = 1;
h->c.chroma_qscale_table = ff_h263_chroma_qscale_table;
}
diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c
index ef2228bb26..31fc33ddc7 100644
--- a/libavcodec/rv20enc.c
+++ b/libavcodec/rv20enc.c
@@ -44,7 +44,7 @@ int ff_rv20_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb, 1, 0); /* unknown bit */
put_bits(&s->pb, 5, s->c.qscale);
- put_sbits(&s->pb, 8, s->c.picture_number); //FIXME wrong, but correct is not known
+ put_sbits(&s->pb, 8, s->picture_number); //FIXME wrong, but correct is not known
s->c.mb_x = s->c.mb_y = 0;
ff_h263_encode_mba(s);
@@ -52,9 +52,9 @@ int ff_rv20_encode_picture_header(MPVMainEncContext *const m)
av_assert1(s->f_code == 1);
av_assert1(!s->me.unrestricted_mv);
- av_assert1(!s->c.alt_inter_vlc);
- av_assert1(!s->c.umvplus);
- av_assert1(s->c.modified_quant == 1);
+ av_assert1(!s->alt_inter_vlc);
+ av_assert1(!s->umvplus);
+ av_assert1(s->modified_quant == 1);
av_assert1(s->c.loop_filter == 1);
s->c.h263_aic = s->c.pict_type == AV_PICTURE_TYPE_I;
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index 68da7f55e7..1db2429a3f 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -1792,7 +1792,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
pic->pict_type = pict->pict_type;
pic->quality = pict->quality;
- mpv->c.picture_number = avctx->frame_num;
+ mpv->picture_number = avctx->frame_num;
if(avctx->flags&AV_CODEC_FLAG_PASS2){
mpv->c.pict_type = pic->pict_type = enc->m.rc_context.entry[avctx->frame_num].new_pict_type;
s->keyframe = pic->pict_type == AV_PICTURE_TYPE_I;
diff --git a/libavcodec/vaapi_mpeg4.c b/libavcodec/vaapi_mpeg4.c
index 20f96f791b..d936a290cd 100644
--- a/libavcodec/vaapi_mpeg4.c
+++ b/libavcodec/vaapi_mpeg4.c
@@ -72,7 +72,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx,
.sprite_warping_accuracy = ctx->sprite_warping_accuracy,
.quant_type = ctx->mpeg_quant,
.quarter_sample = s->quarter_sample,
- .data_partitioned = s->data_partitioning,
+ .data_partitioned = ctx->h.data_partitioning,
.reversible_vlc = ctx->rvlc,
.resync_marker_disable = !ctx->resync_marker,
},
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index 53d127d37f..a5c47b722e 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -188,7 +188,7 @@ static int decode_ext_header(WMV2DecContext *w)
if (code == 0)
return AVERROR_INVALIDDATA;
- h->c.slice_height = h->c.mb_height / code;
+ h->slice_height = h->c.mb_height / code;
if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
av_log(h->c.avctx, AV_LOG_DEBUG,
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index 9e1d62b90e..5c78712e4e 100644
--- a/libavcodec/wmv2enc.c
+++ b/libavcodec/wmv2enc.c
@@ -68,7 +68,7 @@ static int encode_ext_header(WMV2EncContext *w)
flush_put_bits(&pb);
- s->c.slice_height = s->c.mb_height / code;
+ s->slice_height = s->c.mb_height / code;
return 0;
}
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 44/48] avcodec/mpeg_er: Allow to skip setting partitioned_frame, p[pb]_time
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (42 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 43/48] avcodec/mpegvideo: Move fields to {H263Dec, MPVEnc}Context when possible Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 45/48] avcodec/mpegvideo: Move partitioned_frame to {H263Dec, MPVEnc}Context Andreas Rheinhardt
` (3 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Instead of setting these unconditionally (they are always zero
for H.261, MPEG-1/2, RV30/40, VC-1), add a variant of
ff_mpeg_er_frame_start() that sets them and remove setting them
from ff_mpeg_er_frame_start(). Also pass these values via parameters
instead of reading them from the MPVContext itself.
This will allow to move them from MPVContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 3 ++-
libavcodec/mpeg_er.c | 3 ---
libavcodec/mpeg_er.h | 9 +++++++++
libavcodec/rv10.c | 2 +-
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 723040146f..aee52dd2b2 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -553,7 +553,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
return ret;
}
- ff_mpeg_er_frame_start(s);
+ ff_mpv_er_frame_start_ext(s, s->partitioned_frame,
+ s->pp_time, s->pb_time);
/* 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
diff --git a/libavcodec/mpeg_er.c b/libavcodec/mpeg_er.c
index 951167a478..5df75d8e85 100644
--- a/libavcodec/mpeg_er.c
+++ b/libavcodec/mpeg_er.c
@@ -51,10 +51,7 @@ void ff_mpeg_er_frame_start(MpegEncContext *s)
set_erpic(&er->next_pic, s->next_pic.ptr);
set_erpic(&er->last_pic, s->last_pic.ptr);
- er->pp_time = s->pp_time;
- er->pb_time = s->pb_time;
er->quarter_sample = s->quarter_sample;
- er->partitioned_frame = s->partitioned_frame;
ff_er_frame_start(er);
}
diff --git a/libavcodec/mpeg_er.h b/libavcodec/mpeg_er.h
index bb627a4d06..145d1866ed 100644
--- a/libavcodec/mpeg_er.h
+++ b/libavcodec/mpeg_er.h
@@ -24,4 +24,13 @@
int ff_mpeg_er_init(MpegEncContext *s);
void ff_mpeg_er_frame_start(MpegEncContext *s);
+static inline void ff_mpv_er_frame_start_ext(MPVContext *const s, int partitioned_frame,
+ uint16_t pp_time, uint16_t pb_time)
+{
+ s->er.partitioned_frame = partitioned_frame;
+ s->er.pp_time = pp_time;
+ s->er.pb_time = pb_time;
+ ff_mpeg_er_frame_start(s);
+}
+
#endif /* AVCODEC_MPEG_ER_H */
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index ed702dfb66..677db1cd42 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -451,7 +451,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
}
if ((ret = ff_mpv_frame_start(&h->c, avctx)) < 0)
return ret;
- ff_mpeg_er_frame_start(&h->c);
+ ff_mpv_er_frame_start_ext(&h->c, 0, h->c.pp_time, h->c.pb_time);
} else {
if (h->c.cur_pic.ptr->f->pict_type != h->c.pict_type) {
av_log(h->c.avctx, AV_LOG_ERROR, "Slice type mismatch\n");
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 45/48] avcodec/mpegvideo: Move partitioned_frame to {H263Dec, MPVEnc}Context
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (43 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 44/48] avcodec/mpeg_er: Allow to skip setting partitioned_frame, p[pb]_time Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 46/48] avcodec/mpegvideo: Move loop_filter to {H263Dec, MPVEnc, VC1}Context Andreas Rheinhardt
` (2 subsequent siblings)
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/h263dec.c | 16 ++++++++--------
libavcodec/h263dec.h | 1 +
libavcodec/mpeg4videodec.c | 10 +++++-----
libavcodec/mpeg4videoenc.c | 2 +-
libavcodec/mpegvideo.h | 1 -
libavcodec/mpegvideo_enc.c | 10 +++++-----
libavcodec/mpegvideoenc.h | 1 +
7 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index aee52dd2b2..7cd8be850b 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -181,15 +181,15 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
return 0;
}
-static void report_decode_progress(MpegEncContext *s)
+static void report_decode_progress(H263DecContext *const h)
{
- if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred)
- ff_thread_progress_report(&s->cur_pic.ptr->progress, s->mb_y);
+ if (h->c.pict_type != AV_PICTURE_TYPE_B && !h->partitioned_frame && !h->c.er.error_occurred)
+ ff_thread_progress_report(&h->c.cur_pic.ptr->progress, h->c.mb_y);
}
static int decode_slice(H263DecContext *const h)
{
- const int part_mask = h->c.partitioned_frame
+ const int part_mask = h->partitioned_frame
? (ER_AC_END | ER_AC_ERROR) : 0x7F;
const int mb_size = 16 >> h->c.avctx->lowres;
int ret;
@@ -214,7 +214,7 @@ static int decode_slice(H263DecContext *const h)
return ret;
}
- if (h->c.partitioned_frame) {
+ if (h->partitioned_frame) {
const int qscale = h->c.qscale;
if (CONFIG_MPEG4_DECODER && h->c.codec_id == AV_CODEC_ID_MPEG4)
@@ -290,7 +290,7 @@ static int decode_slice(H263DecContext *const h)
if (++h->c.mb_x >= h->c.mb_width) {
h->c.mb_x = 0;
- report_decode_progress(&h->c);
+ report_decode_progress(h);
ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
h->c.mb_y++;
}
@@ -317,7 +317,7 @@ static int decode_slice(H263DecContext *const h)
ff_h263_loop_filter(&h->c);
}
- report_decode_progress(&h->c);
+ report_decode_progress(h);
ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
h->c.mb_x = 0;
@@ -553,7 +553,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
return ret;
}
- ff_mpv_er_frame_start_ext(s, s->partitioned_frame,
+ ff_mpv_er_frame_start_ext(s, h->partitioned_frame,
s->pp_time, s->pb_time);
/* the second part of the wmv2 header contains the MB skip bits which
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index a7b5e54ae7..c2cca57dea 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -73,6 +73,7 @@ typedef struct H263DecContext {
int skipped_last_frame;
int divx_packed; ///< divx specific, used to workaround (many) bugs in divx5
int data_partitioning; ///< data partitioning flag from header
+ int partitioned_frame; ///< is current frame partitioned
/* MSMPEG4 specific */
int slice_height; ///< in macroblocks
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index aaf2ecf7c4..df6cfff04b 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -391,7 +391,7 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
while (v <= 0xFF) {
if (h->c.pict_type == AV_PICTURE_TYPE_B ||
- (v >> (8 - h->c.pict_type) != 1) || h->c.partitioned_frame)
+ (v >> (8 - h->c.pict_type) != 1) || h->partitioned_frame)
break;
skip_bits(&h->gb, 8 + h->c.pict_type);
bits_count += 8 + h->c.pict_type;
@@ -1395,7 +1395,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
// FIXME add short header support
if (use_intra_dc_vlc) {
/* DC coef */
- if (h->c.partitioned_frame) {
+ if (h->partitioned_frame) {
level = h->c.dc_val[h->c.block_index[n]];
if (n < 4)
level = FASTDIV((level + (h->c.y_dc_scale >> 1)), h->c.y_dc_scale);
@@ -3222,8 +3222,8 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
h->c.low_delay = 0;
}
- h->c.partitioned_frame = h->data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B;
- if (h->c.partitioned_frame)
+ h->partitioned_frame = h->data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B;
+ if (h->partitioned_frame)
h->decode_mb = mpeg4_decode_partitioned_mb;
else
h->decode_mb = mpeg4_decode_mb;
@@ -3513,7 +3513,7 @@ static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
if (get_bits_left(gb) <= 32)
return 0;
- h->c.partitioned_frame = 0;
+ h->partitioned_frame = 0;
h->c.interlaced_dct = 0;
h->decode_mb = mpeg4_decode_studio_mb;
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 7432c1f9bd..ced4ad24e7 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -1033,7 +1033,7 @@ static int mpeg4_encode_picture_header(MPVMainEncContext *const m)
mpeg4_encode_gop_header(m);
}
- s->c.partitioned_frame = s->data_partitioning && s->c.pict_type != AV_PICTURE_TYPE_B;
+ s->partitioned_frame = s->data_partitioning && s->c.pict_type != AV_PICTURE_TYPE_B;
put_bits32(&s->pb, VOP_STARTCODE); /* vop header */
put_bits(&s->pb, 2, s->c.pict_type - 1); /* pict type: I = 0 , P = 1 */
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index 3b47a02ae1..eb8739014b 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -229,7 +229,6 @@ typedef struct MpegEncContext {
uint16_t pb_field_time; ///< like above, just for interlaced
int mcsel;
int quarter_sample; ///< 1->qpel, 0->half pel ME/MC
- int partitioned_frame; ///< is current frame partitioned
int low_delay; ///< no reordering needed / has no B-frames
/* MSMPEG4 specific */
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index ff6d6a8cd7..e7f40f5d60 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -265,7 +265,7 @@ static void update_duplicate_context_after_me(MPVEncContext *const dst,
COPY(lambda2);
COPY(c.frame_pred_frame_dct); // FIXME don't set in encode_header
COPY(c.progressive_frame); // FIXME don't set in encode_header
- COPY(c.partitioned_frame); // FIXME don't set in encode_header
+ COPY(partitioned_frame); // FIXME don't set in encode_header
#undef COPY
}
@@ -2894,7 +2894,7 @@ static int mb_var_thread(AVCodecContext *c, void *arg){
static void write_slice_end(MPVEncContext *const s)
{
if (CONFIG_MPEG4_ENCODER && s->c.codec_id == AV_CODEC_ID_MPEG4) {
- if (s->c.partitioned_frame)
+ if (s->partitioned_frame)
ff_mpeg4_merge_partitions(s);
ff_mpeg4_stuffing(&s->pb);
@@ -2907,7 +2907,7 @@ static void write_slice_end(MPVEncContext *const s)
flush_put_bits(&s->pb);
- if ((s->c.avctx->flags & AV_CODEC_FLAG_PASS1) && !s->c.partitioned_frame)
+ if ((s->c.avctx->flags & AV_CODEC_FLAG_PASS1) && !s->partitioned_frame)
s->misc_bits+= get_bits_diff(s);
}
@@ -3024,7 +3024,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
s->c.last_dc[1] = 128 * 8 / 14;
s->c.last_dc[2] = 128 * 8 / 14;
#if CONFIG_MPEG4_ENCODER
- } else if (s->c.partitioned_frame) {
+ } else if (s->partitioned_frame) {
av_assert1(s->c.codec_id == AV_CODEC_ID_MPEG4);
ff_mpeg4_init_partitions(s);
#endif
@@ -3120,7 +3120,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
if (s->c.start_mb_y != mb_y || mb_x != 0) {
write_slice_end(s);
- if (CONFIG_MPEG4_ENCODER && s->c.codec_id == AV_CODEC_ID_MPEG4 && s->c.partitioned_frame)
+ if (CONFIG_MPEG4_ENCODER && s->c.codec_id == AV_CODEC_ID_MPEG4 && s->partitioned_frame)
ff_mpeg4_init_partitions(s);
}
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index ad48ce6df3..0ad1561851 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -162,6 +162,7 @@ typedef struct MPVEncContext {
/* MPEG-4 specific */
int data_partitioning; ///< data partitioning flag, set via option
+ int partitioned_frame; ///< is current frame partitioned
int mpeg_quant;
PutBitContext tex_pb; ///< used for data partitioned VOPs
PutBitContext pb2; ///< used for data partitioned VOPs
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 46/48] avcodec/mpegvideo: Move loop_filter to {H263Dec, MPVEnc, VC1}Context
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (44 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 45/48] avcodec/mpegvideo: Move partitioned_frame to {H263Dec, MPVEnc}Context Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 47/48] avcodec/rv34: Don't report progress unnecessarily Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 48/48] avcodec/rv34: Fix spelling mistake Andreas Rheinhardt
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/dxva2_vc1.c | 4 ++--
libavcodec/h261enc.c | 4 ++--
libavcodec/h263dec.c | 4 ++--
libavcodec/h263dec.h | 1 +
libavcodec/intelh263dec.c | 2 +-
libavcodec/ituh263dec.c | 8 ++++----
libavcodec/ituh263enc.c | 2 +-
libavcodec/mpegvideo.h | 1 -
libavcodec/mpegvideo_enc.c | 10 +++++-----
libavcodec/mpegvideoenc.h | 1 +
libavcodec/mss2.c | 2 +-
libavcodec/nvdec_vc1.c | 2 +-
libavcodec/rv10.c | 6 +++---
libavcodec/rv20enc.c | 2 +-
libavcodec/vaapi_vc1.c | 2 +-
libavcodec/vc1.c | 16 ++++++++--------
libavcodec/vc1.h | 1 +
libavcodec/vc1_block.c | 14 +++++++-------
libavcodec/vdpau_vc1.c | 2 +-
libavcodec/wmv2dec.c | 6 +++---
libavcodec/wmv2enc.c | 2 +-
21 files changed, 47 insertions(+), 45 deletions(-)
diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c
index 3400480f1f..f1dcea1e84 100644
--- a/libavcodec/dxva2_vc1.c
+++ b/libavcodec/dxva2_vc1.c
@@ -108,7 +108,7 @@ void ff_dxva2_vc1_fill_picture_parameters(AVCodecContext *avctx,
pp->bRcontrol = v->rnd;
pp->bPicSpatialResid8 = (v->panscanflag << 7) |
(v->refdist_flag << 6) |
- (s->loop_filter << 5) |
+ (v->loop_filter << 5) |
(v->fastuvmc << 4) |
(v->extended_mv << 3) |
(v->dquant << 1) |
@@ -121,7 +121,7 @@ void ff_dxva2_vc1_fill_picture_parameters(AVCodecContext *avctx,
pp->bPicExtrapolation = (!v->interlace || v->fcm == PROGRESSIVE) ? 1 : 2;
pp->bPicDeblocked = ((!pp->bPicBackwardPrediction && v->overlap) << 6) |
((v->profile != PROFILE_ADVANCED && v->rangeredfrm) << 5) |
- (s->loop_filter << 1);
+ (v->loop_filter << 1);
pp->bPicDeblockConfined = (v->postprocflag << 7) |
(v->broadcast << 6) |
(v->interlace << 5) |
diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
index 89a6a69755..c75e029d68 100644
--- a/libavcodec/h261enc.c
+++ b/libavcodec/h261enc.c
@@ -266,9 +266,9 @@ static void h261_encode_mb(MPVEncContext *const s, int16_t block[6][64],
if (!s->c.mb_intra) {
com->mtype++;
- if (mvd || s->c.loop_filter)
+ if (mvd || s->loop_filter)
com->mtype += 3;
- if (s->c.loop_filter)
+ if (s->loop_filter)
com->mtype += 3;
if (cbp)
com->mtype++;
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 7cd8be850b..204476dfd6 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -280,7 +280,7 @@ static int decode_slice(H263DecContext *const h)
const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
if (ret == SLICE_END) {
ff_mpv_reconstruct_mb(&h->c, h->block);
- if (h->c.loop_filter)
+ if (h->loop_filter)
ff_h263_loop_filter(&h->c);
ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
@@ -313,7 +313,7 @@ static int decode_slice(H263DecContext *const h)
}
ff_mpv_reconstruct_mb(&h->c, h->block);
- if (h->c.loop_filter)
+ if (h->loop_filter)
ff_h263_loop_filter(&h->c);
}
diff --git a/libavcodec/h263dec.h b/libavcodec/h263dec.h
index c2cca57dea..ace210b036 100644
--- a/libavcodec/h263dec.h
+++ b/libavcodec/h263dec.h
@@ -66,6 +66,7 @@ typedef struct H263DecContext {
int umvplus; ///< == H.263+ && unrestricted_mv
int h263_slice_structured;
int alt_inter_vlc; ///< alternative inter vlc
+ int loop_filter;
int modified_quant;
/* MPEG-4 specific */
diff --git a/libavcodec/intelh263dec.c b/libavcodec/intelh263dec.c
index 73d56f4195..27a3cadbad 100644
--- a/libavcodec/intelh263dec.c
+++ b/libavcodec/intelh263dec.c
@@ -82,7 +82,7 @@ int ff_intel_h263_decode_picture_header(H263DecContext *const h)
}
if (get_bits(&h->gb, 2))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
- h->c.loop_filter = get_bits1(&h->gb) * !h->c.avctx->lowres;
+ h->loop_filter = get_bits1(&h->gb) * !h->c.avctx->lowres;
if (get_bits1(&h->gb))
av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
if (get_bits1(&h->gb))
diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index b99100590c..7a78b95c50 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -90,7 +90,7 @@ void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
h->c.h263_aic ? " AIC" : "",
h->alt_inter_vlc ? " AIV" : "",
h->modified_quant ? " MQ" : "",
- h->c.loop_filter ? " LOOP" : "",
+ h->loop_filter ? " LOOP" : "",
h->h263_slice_structured ? " SS" : "",
h->c.avctx->framerate.num, h->c.avctx->framerate.den);
}
@@ -798,7 +798,7 @@ int ff_h263_decode_mb(H263DecContext *const h)
h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
h->c.mv[0][0][0] = 0;
h->c.mv[0][0][1] = 0;
- h->c.mb_skipped = !(h->c.obmc | h->c.loop_filter);
+ h->c.mb_skipped = !(h->c.obmc | h->loop_filter);
goto end;
}
cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
@@ -1181,9 +1181,9 @@ int ff_h263_decode_picture_header(H263DecContext *const h)
}
h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
h->c.h263_aic = get_bits1(&h->gb); /* Advanced Intra Coding (AIC) */
- h->c.loop_filter = get_bits1(&h->gb);
+ h->loop_filter = get_bits1(&h->gb);
if (h->c.avctx->lowres)
- h->c.loop_filter = 0;
+ h->loop_filter = 0;
h->h263_slice_structured = get_bits1(&h->gb);
if (get_bits1(&h->gb) != 0) {
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 250ce0b043..85008443da 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -285,7 +285,7 @@ static int h263_encode_picture_header(MPVMainEncContext *const m)
put_bits(&s->pb,1,0); /* SAC: off */
put_bits(&s->pb,1,s->c.obmc); /* Advanced Prediction Mode */
put_bits(&s->pb,1,s->c.h263_aic); /* Advanced Intra Coding */
- put_bits(&s->pb,1,s->c.loop_filter); /* Deblocking Filter */
+ put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */
put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */
put_bits(&s->pb,1,0); /* Reference Picture Selection: off */
put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */
diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h
index eb8739014b..4a30986eac 100644
--- a/libavcodec/mpegvideo.h
+++ b/libavcodec/mpegvideo.h
@@ -215,7 +215,6 @@ typedef struct MpegEncContext {
/* H.263+ specific */
int h263_aic_dir; ///< AIC direction: 0 = left, 1 = top
- int loop_filter;
/* MPEG-4 specific */
int studio_profile;
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index e7f40f5d60..3ab097d6f6 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -654,7 +654,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
(s->mpv_flags & FF_MPV_FLAG_QP_RD)) &&
!m->fixed_qscale;
- s->c.loop_filter = !!(avctx->flags & AV_CODEC_FLAG_LOOP_FILTER);
+ s->loop_filter = !!(avctx->flags & AV_CODEC_FLAG_LOOP_FILTER);
if (avctx->rc_max_rate && !avctx->rc_buffer_size) {
switch(avctx->codec_id) {
@@ -925,8 +925,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
/* Fx */
s->c.h263_aic = (avctx->flags & AV_CODEC_FLAG_AC_PRED) ? 1 : 0;
s->modified_quant = s->c.h263_aic;
- s->c.loop_filter = (avctx->flags & AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
- s->me.unrestricted_mv = s->c.obmc || s->c.loop_filter || s->umvplus;
+ s->loop_filter = !!(avctx->flags & AV_CODEC_FLAG_LOOP_FILTER);
+ s->me.unrestricted_mv = s->c.obmc || s->loop_filter || s->umvplus;
s->flipflop_rounding = 1;
/* /Fx */
@@ -959,7 +959,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
// Set here to force allocation of dc_val;
// will be set later on a per-frame basis.
s->c.h263_aic = 1;
- s->c.loop_filter = 1;
+ s->loop_filter = 1;
s->me.unrestricted_mv = 0;
break;
#endif
@@ -3603,7 +3603,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
s, s->new_pic->data[2] + s->c.mb_x*8 + s->c.mb_y*s->c.uvlinesize*chr_h,
s->c.dest[2], w>>1, h>>s->c.chroma_y_shift, s->c.uvlinesize);
}
- if (s->c.loop_filter) {
+ if (s->loop_filter) {
if (CONFIG_H263_ENCODER && s->c.out_format == FMT_H263)
ff_h263_loop_filter(&s->c);
}
diff --git a/libavcodec/mpegvideoenc.h b/libavcodec/mpegvideoenc.h
index 0ad1561851..ee115c3611 100644
--- a/libavcodec/mpegvideoenc.h
+++ b/libavcodec/mpegvideoenc.h
@@ -152,6 +152,7 @@ typedef struct MPVEncContext {
int h263_slice_structured;
int alt_inter_vlc; ///< alternative inter vlc
int modified_quant;
+ int loop_filter;
/* MJPEG specific */
struct MJpegContext *mjpeg_ctx;
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 3758313fa8..aaeceb055d 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -390,7 +390,7 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
if ((ret = init_get_bits8(&v->gb, buf, buf_size)) < 0)
return ret;
- s->loop_filter = avctx->skip_loop_filter < AVDISCARD_ALL;
+ v->loop_filter = avctx->skip_loop_filter < AVDISCARD_ALL;
if (ff_vc1_parse_frame_header(v, &v->gb) < 0) {
av_log(v->s.avctx, AV_LOG_ERROR, "header error\n");
diff --git a/libavcodec/nvdec_vc1.c b/libavcodec/nvdec_vc1.c
index 7cdfdec42d..d00cf5237a 100644
--- a/libavcodec/nvdec_vc1.c
+++ b/libavcodec/nvdec_vc1.c
@@ -94,7 +94,7 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx,
.extended_mv = v->extended_mv,
.dquant = v->dquant,
.vstransform = v->vstransform,
- .loopfilter = v->s.loop_filter,
+ .loopfilter = v->loop_filter,
.fastuvmc = v->fastuvmc,
.overlap = v->overlap,
.quantizer = v->quantizer_mode,
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 677db1cd42..b4545f7624 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -186,7 +186,7 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
}
if (RV_GET_MINOR_VER(rv->sub_id) >= 2)
- h->c.loop_filter = get_bits1(&h->gb) && !h->c.avctx->lowres;
+ h->loop_filter = get_bits1(&h->gb) && !h->c.avctx->lowres;
if (RV_GET_MINOR_VER(rv->sub_id) <= 1)
seq = get_bits(&h->gb, 8) << 7;
@@ -292,7 +292,7 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size)
h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table;
}
if (!h->c.avctx->lowres)
- h->c.loop_filter = 1;
+ h->loop_filter = 1;
if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(h->c.avctx, AV_LOG_INFO,
@@ -517,7 +517,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
if (h->c.pict_type != AV_PICTURE_TYPE_B)
ff_h263_update_motion_val(&h->c);
ff_mpv_reconstruct_mb(&h->c, h->block);
- if (h->c.loop_filter)
+ if (h->loop_filter)
ff_h263_loop_filter(&h->c);
if (++h->c.mb_x == h->c.mb_width) {
diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c
index 31fc33ddc7..8bf93e7c09 100644
--- a/libavcodec/rv20enc.c
+++ b/libavcodec/rv20enc.c
@@ -55,7 +55,7 @@ int ff_rv20_encode_picture_header(MPVMainEncContext *const m)
av_assert1(!s->alt_inter_vlc);
av_assert1(!s->umvplus);
av_assert1(s->modified_quant == 1);
- av_assert1(s->c.loop_filter == 1);
+ av_assert1(s->loop_filter == 1);
s->c.h263_aic = s->c.pict_type == AV_PICTURE_TYPE_I;
if (s->c.h263_aic) {
diff --git a/libavcodec/vaapi_vc1.c b/libavcodec/vaapi_vc1.c
index 7a955ac7f3..a3dd3140e2 100644
--- a/libavcodec/vaapi_vc1.c
+++ b/libavcodec/vaapi_vc1.c
@@ -285,7 +285,7 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx,
.broken_link = v->broken_link,
.closed_entry = v->closed_entry,
.panscan_flag = v->panscanflag,
- .loopfilter = s->loop_filter,
+ .loopfilter = v->loop_filter,
},
.conditional_overlap_flag = v->condover,
.fast_uvmc_flag = v->fastuvmc,
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index c136f14c82..e365aaec84 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -300,13 +300,13 @@ int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitCo
v->frmrtq_postproc = get_bits(gb, 3); //common
// (bitrate-32kbps)/64kbps
v->bitrtq_postproc = get_bits(gb, 5); //common
- v->s.loop_filter = get_bits1(gb); //common
- if (v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE) {
+ v->loop_filter = get_bits1(gb); //common
+ if (v->loop_filter == 1 && v->profile == PROFILE_SIMPLE) {
av_log(avctx, AV_LOG_ERROR,
"LOOPFILTER shall not be enabled in Simple Profile\n");
}
if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
- v->s.loop_filter = 0;
+ v->loop_filter = 0;
v->res_x8 = get_bits1(gb); //reserved
v->multires = get_bits1(gb);
@@ -376,7 +376,7 @@ int ff_vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitCo
"Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n"
"DQuant=%i, Quantizer mode=%i, Max B-frames=%i\n",
v->profile, v->frmrtq_postproc, v->bitrtq_postproc,
- v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv,
+ v->loop_filter, v->multires, v->fastuvmc, v->extended_mv,
v->rangered, v->vstransform, v->overlap, v->resync_marker,
v->dquant, v->quantizer_mode, avctx->max_b_frames);
return 0;
@@ -415,7 +415,7 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
"LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n"
"TFCTRflag=%i, FINTERPflag=%i\n",
v->level, v->frmrtq_postproc, v->bitrtq_postproc,
- v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
+ v->loop_filter, v->chromaformat, v->broadcast, v->interlace,
v->tfcntrflag, v->finterpflag);
v->psf = get_bits1(gb);
@@ -501,9 +501,9 @@ int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContex
v->closed_entry = get_bits1(gb);
v->panscanflag = get_bits1(gb);
v->refdist_flag = get_bits1(gb);
- v->s.loop_filter = get_bits1(gb);
+ v->loop_filter = get_bits1(gb);
if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL)
- v->s.loop_filter = 0;
+ v->loop_filter = 0;
v->fastuvmc = get_bits1(gb);
v->extended_mv = get_bits1(gb);
v->dquant = get_bits(gb, 2);
@@ -544,7 +544,7 @@ int ff_vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContex
"BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n"
"RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n"
"DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n",
- v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter,
+ v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->loop_filter,
v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
return 0;
diff --git a/libavcodec/vc1.h b/libavcodec/vc1.h
index 5eee646e31..f2a52c19c1 100644
--- a/libavcodec/vc1.h
+++ b/libavcodec/vc1.h
@@ -220,6 +220,7 @@ typedef struct VC1Context{
int profile; ///< 2 bits, Profile
int frmrtq_postproc; ///< 3 bits,
int bitrtq_postproc; ///< 5 bits, quantized framerate-based postprocessing strength
+ int loop_filter;
int max_coded_width, max_coded_height;
int fastuvmc; ///< Rounding of qpel vector to hpel ? (not in Simple)
int extended_mv; ///< Ext MV in P/B (not in Simple)
diff --git a/libavcodec/vc1_block.c b/libavcodec/vc1_block.c
index 165d875458..4fa03f287a 100644
--- a/libavcodec/vc1_block.c
+++ b/libavcodec/vc1_block.c
@@ -2595,7 +2595,7 @@ static void vc1_decode_i_blocks(VC1Context *v)
vc1_put_blocks_clamped(v, 0);
}
- if (v->s.loop_filter)
+ if (v->loop_filter)
ff_vc1_i_loop_filter(v);
if (get_bits_left(&v->gb) < 0) {
@@ -2733,7 +2733,7 @@ static int vc1_decode_i_blocks_adv(VC1Context *v)
if (v->overlap && (v->pq >= 9 || v->condover != CONDOVER_NONE))
ff_vc1_i_overlap_filter(v);
vc1_put_blocks_clamped(v, 1);
- if (v->s.loop_filter)
+ if (v->loop_filter)
ff_vc1_i_loop_filter(v);
if (get_bits_left(gb) < 0) {
@@ -2787,7 +2787,7 @@ static void vc1_decode_p_blocks(VC1Context *v)
break;
}
- apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
+ apply_loop_filter = v->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY);
s->first_slice_line = 1;
memset(v->cbp_base, 0, sizeof(v->cbp_base[0]) * 3 * s->mb_stride);
for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) {
@@ -2889,15 +2889,15 @@ static void vc1_decode_b_blocks(VC1Context *v)
if (v->fcm == ILACE_FIELD) {
vc1_decode_b_mb_intfi(v);
- if (v->s.loop_filter)
+ if (v->loop_filter)
ff_vc1_b_intfi_loop_filter(v);
} else if (v->fcm == ILACE_FRAME) {
vc1_decode_b_mb_intfr(v);
- if (v->s.loop_filter)
+ if (v->loop_filter)
ff_vc1_p_intfr_loop_filter(v);
} else {
vc1_decode_b_mb(v);
- if (v->s.loop_filter)
+ if (v->loop_filter)
ff_vc1_i_loop_filter(v);
}
if (get_bits_left(&v->gb) < 0 || get_bits_count(&v->gb) < 0) {
@@ -2951,7 +2951,7 @@ void ff_vc1_decode_blocks(VC1Context *v)
ff_intrax8_decode_picture(&v->x8, v->s.cur_pic.ptr,
&v->gb, &v->s.mb_x, &v->s.mb_y,
2 * v->pq + v->halfpq, v->pq * !v->pquantizer,
- v->s.loop_filter, v->s.low_delay);
+ v->loop_filter, v->s.low_delay);
ff_er_add_slice(&v->s.er, 0, 0,
(v->s.mb_x >> 1) - 1, (v->s.mb_y >> 1) - 1,
diff --git a/libavcodec/vdpau_vc1.c b/libavcodec/vdpau_vc1.c
index af6973ea6a..a5fd8156f4 100644
--- a/libavcodec/vdpau_vc1.c
+++ b/libavcodec/vdpau_vc1.c
@@ -83,7 +83,7 @@ static int vdpau_vc1_start_frame(AVCodecContext *avctx,
info->extended_dmv = v->extended_dmv;
info->overlap = v->overlap;
info->vstransform = v->vstransform;
- info->loopfilter = v->s.loop_filter;
+ info->loopfilter = v->loop_filter;
info->fastuvmc = v->fastuvmc;
info->range_mapy_flag = v->range_mapy_flag;
info->range_mapy = v->range_mapy;
diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c
index a5c47b722e..082ebf7a84 100644
--- a/libavcodec/wmv2dec.c
+++ b/libavcodec/wmv2dec.c
@@ -178,7 +178,7 @@ static int decode_ext_header(WMV2DecContext *w)
fps = get_bits(&gb, 5);
w->ms.bit_rate = get_bits(&gb, 11) * 1024;
w->mspel_bit = get_bits1(&gb);
- h->c.loop_filter = get_bits1(&gb);
+ h->loop_filter = get_bits1(&gb);
w->abt_flag = get_bits1(&gb);
w->j_type_bit = get_bits1(&gb);
w->top_left_mv_flag = get_bits1(&gb);
@@ -196,7 +196,7 @@ static int decode_ext_header(WMV2DecContext *w)
"tl_mv_flag:%d, mbrl_bit:%d, code:%d, loop_filter:%d, "
"slices:%d\n",
fps, w->ms.bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit,
- w->top_left_mv_flag, w->per_mb_rl_bit, code, h->c.loop_filter,
+ w->top_left_mv_flag, w->per_mb_rl_bit, code, h->loop_filter,
code);
return 0;
}
@@ -333,7 +333,7 @@ int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)
ff_intrax8_decode_picture(&w->x8, h->c.cur_pic.ptr,
&h->gb, &h->c.mb_x, &h->c.mb_y,
2 * h->c.qscale, (h->c.qscale - 1) | 1,
- h->c.loop_filter, h->c.low_delay);
+ h->loop_filter, h->c.low_delay);
ff_er_add_slice(&h->c.er, 0, 0,
(h->c.mb_x >> 1) - 1, (h->c.mb_y >> 1) - 1,
diff --git a/libavcodec/wmv2enc.c b/libavcodec/wmv2enc.c
index 5c78712e4e..b6811fde0e 100644
--- a/libavcodec/wmv2enc.c
+++ b/libavcodec/wmv2enc.c
@@ -59,7 +59,7 @@ static int encode_ext_header(WMV2EncContext *w)
put_bits(&pb, 11, FFMIN(w->msmpeg4.m.bit_rate / 1024, 2047));
put_bits(&pb, 1, w->mspel_bit = 1);
- put_bits(&pb, 1, s->c.loop_filter);
+ put_bits(&pb, 1, s->loop_filter);
put_bits(&pb, 1, w->abt_flag = 1);
put_bits(&pb, 1, w->j_type_bit = 1);
put_bits(&pb, 1, w->top_left_mv_flag = 0);
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 47/48] avcodec/rv34: Don't report progress unnecessarily
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (45 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 46/48] avcodec/mpegvideo: Move loop_filter to {H263Dec, MPVEnc, VC1}Context Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 48/48] avcodec/rv34: Fix spelling mistake Andreas Rheinhardt
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
ff_mpv_frame_end() already does it.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv34.c | 4 ----
1 file changed, 4 deletions(-)
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index 4feab95eb5..bd8800ee5d 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1581,9 +1581,6 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
ff_mpv_frame_end(s);
r->mb_num_left = 0;
- if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
- ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX);
-
if (s->pict_type == AV_PICTURE_TYPE_B) {
if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
return ret;
@@ -1809,7 +1806,6 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
ff_er_frame_end(&s->er, NULL);
ff_mpv_frame_end(s);
r->mb_num_left = 0;
- ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX);
return AVERROR_INVALIDDATA;
}
}
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread
* [FFmpeg-devel] [PATCH 48/48] avcodec/rv34: Fix spelling mistake
2025-06-23 13:36 [FFmpeg-devel] [PATCH 00/48] H263DecContext ffmpegagent
` (46 preceding siblings ...)
2025-06-23 13:36 ` [FFmpeg-devel] [PATCH 47/48] avcodec/rv34: Don't report progress unnecessarily Andreas Rheinhardt
@ 2025-06-23 13:36 ` Andreas Rheinhardt
47 siblings, 0 replies; 49+ messages in thread
From: Andreas Rheinhardt @ 2025-06-23 13:36 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/rv34.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index bd8800ee5d..f78b91e7df 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1800,7 +1800,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
*got_picture_ptr = ret;
} else if (HAVE_THREADS &&
(s->avctx->active_thread_type & FF_THREAD_FRAME)) {
- av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n");
+ av_log(avctx, AV_LOG_INFO, "marking unfinished frame as finished\n");
/* always mark the current frame as finished, frame-mt supports
* only complete frames */
ff_er_frame_end(&s->er, NULL);
--
ffmpeg-codebot
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 49+ messages in thread