History

avcodec/h263dec: Add H263DecContext

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*).

Andreas Rheinhardt committed 1 year ago

Commit 584d50c1 parent 3f5c20421 files · +2251 −2223Browse files

Unified · Split

21 files
  1. libavcodec/flvdec.c +30 −30
  2. libavcodec/flvdec.h +2 −2
  3. libavcodec/h263dec.c +206 −206
  4. libavcodec/h263dec.h +14 −8
  5. libavcodec/intelh263dec.c +55 −55
  6. libavcodec/ituh263dec.c +476 −471
  7. libavcodec/mpeg4video_parser.c +2 −2
  8. libavcodec/mpeg4videodec.c +854 −849
  9. libavcodec/mpeg4videodec.h +7 −6
  10. libavcodec/mpegvideo.h +0 −1
  11. libavcodec/msmpeg4dec.c +258 −247
  12. libavcodec/msmpeg4dec.h +6 −5
  13. libavcodec/nvdec_mpeg4.c +1 −1
  14. libavcodec/rv10.c +170 −170
  15. libavcodec/rv10dec.h +2 −2
  16. libavcodec/vaapi_mpeg4.c +1 −1
  17. libavcodec/vdpau_mpeg4.c +1 −1
  18. libavcodec/wmv2.h +2 −2
  19. libavcodec/wmv2dec.c +160 −161
  20. libavcodec/wmv2dec.h +3 −2
  21. libavcodec/wmv2enc.c +1 −1
libavcodec/flvdec.c+30−30
@@ -26,31 +26,31 @@ · 25 unmodified lines
2626 #include "mpegvideo.h"
2727 #include "mpegvideodec.h"
2828
29−int ff_flv_decode_picture_header(MpegEncContext *s)
29+int ff_flv_decode_picture_header(H263DecContext *const h)
3030 {
3131 int format, width, height;
3232
3333 /* picture header */
34− if (get_bits(&s->gb, 17) != 1) {
35− av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
34+ if (get_bits(&h->c.gb, 17) != 1) {
35+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
3636 return AVERROR_INVALIDDATA;
3737 }
38− format = get_bits(&s->gb, 5);
38+ format = get_bits(&h->c.gb, 5);
3939 if (format != 0 && format != 1) {
40− av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n");
40+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture format\n");
4141 return AVERROR_INVALIDDATA;
4242 }
43− s->h263_flv = format + 1;
44− s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
45− format = get_bits(&s->gb, 3);
43+ h->c.h263_flv = format + 1;
44+ h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */
45+ format = get_bits(&h->c.gb, 3);
4646 switch (format) {
4747 case 0:
48− width = get_bits(&s->gb, 8);
49− height = get_bits(&s->gb, 8);
48+ width = get_bits(&h->c.gb, 8);
49+ height = get_bits(&h->c.gb, 8);
5050 break;
5151 case 1:
52− width = get_bits(&s->gb, 16);
53− height = get_bits(&s->gb, 16);
52+ width = get_bits(&h->c.gb, 16);
53+ height = get_bits(&h->c.gb, 16);
5454 break;
5555 case 2:
5656 width = 352;
@@ -76,32 +76,32 @@ int ff_flv_decode_picture_header(MpegEncContext *s) · 19 unmodified lines
7676 width = height = 0;
7777 break;
7878 }
79− if (av_image_check_size(width, height, 0, s->avctx))
79+ if (av_image_check_size(width, height, 0, h->c.avctx))
8080 return AVERROR(EINVAL);
81− s->width = width;
82− s->height = height;
81+ h->c.width = width;
82+ h->c.height = height;
8383
84− s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2);
85− s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
86− if (s->droppable)
87− s->pict_type = AV_PICTURE_TYPE_P;
84+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits(&h->c.gb, 2);
85+ h->c.droppable = h->c.pict_type > AV_PICTURE_TYPE_P;
86+ if (h->c.droppable)
87+ h->c.pict_type = AV_PICTURE_TYPE_P;
8888
89− skip_bits1(&s->gb); /* deblocking flag */
90− s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
89+ skip_bits1(&h->c.gb); /* deblocking flag */
90+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
9191
92− s->h263_long_vectors = 0;
92+ h->c.h263_long_vectors = 0;
9393
9494 /* PEI */
95− if (skip_1stop_8data_bits(&s->gb) < 0)
95+ if (skip_1stop_8data_bits(&h->c.gb) < 0)
9696 return AVERROR_INVALIDDATA;
9797
98− if (s->ehc_mode)
99− s->avctx->sample_aspect_ratio= (AVRational){1,2};
98+ if (h->c.ehc_mode)
99+ h->c.avctx->sample_aspect_ratio= (AVRational){1,2};
100100
101− if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
102− av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
103− s->droppable ? 'D' : av_get_picture_type_char(s->pict_type),
104− s->h263_flv - 1, s->qscale, s->picture_number);
101+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
102+ av_log(h->c.avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n",
103+ h->c.droppable ? 'D' : av_get_picture_type_char(h->c.pict_type),
104+ h->c.h263_flv - 1, h->c.qscale, h->c.picture_number);
105105 }
106106
107107 return 0;
@@ -112,7 +112,7 @@ const FFCodec ff_flv_decoder = { · 4 unmodified lines
112112 CODEC_LONG_NAME("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"),
113113 .p.type = AVMEDIA_TYPE_VIDEO,
114114 .p.id = AV_CODEC_ID_FLV1,
115− .priv_data_size = sizeof(MpegEncContext),
115+ .priv_data_size = sizeof(H263DecContext),
116116 .init = ff_h263_decode_init,
117117 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
118118 .close = ff_mpv_decode_close,
libavcodec/flvdec.h+2−2
@@ -21,8 +21,8 @@ · 20 unmodified lines
2121 #ifndef AVCODEC_FLVDEC_H
2222 #define AVCODEC_FLVDEC_H
2323
24−#include "mpegvideo.h"
24+struct H263DecContext;
2525
26−int ff_flv_decode_picture_header(MpegEncContext *s);
26+int ff_flv_decode_picture_header(struct H263DecContext *const h);
2727
2828 #endif /* AVCODEC_FLVDEC_H */
libavcodec/h263dec.c+206−206
@@ -90,7 +90,8 @@ static enum AVPixelFormat h263_get_format(AVCodecContext *avctx) · 89 unmodified lines
9090
9191 av_cold int ff_h263_decode_init(AVCodecContext *avctx)
9292 {
93− MpegEncContext *s = avctx->priv_data;
93+ H263DecContext *const h = avctx->priv_data;
94+ MPVContext *const s = &h->c;
9495 MPVUnquantDSPContext unquant_dsp_ctx;
9596 int ret;
9697
@@ -101,7 +102,7 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) · 4 unmodified lines
101102 if (ret < 0)
102103 return ret;
103104
104− s->decode_mb = ff_h263_decode_mb;
105+ h->decode_mb = ff_h263_decode_mb;
105106 s->low_delay = 1;
106107
107108 s->y_dc_scale_table =
@@ -179,239 +180,239 @@ static void report_decode_progress(MpegEncContext *s) · 71 unmodified lines
179180 ff_thread_progress_report(&s->cur_pic.ptr->progress, s->mb_y);
180181 }
181182
182−static int decode_slice(MpegEncContext *s)
183+static int decode_slice(H263DecContext *const h)
183184 {
184− const int part_mask = s->partitioned_frame
185+ const int part_mask = h->c.partitioned_frame
185186 ? (ER_AC_END | ER_AC_ERROR) : 0x7F;
186− const int mb_size = 16 >> s->avctx->lowres;
187+ const int mb_size = 16 >> h->c.avctx->lowres;
187188 int ret;
188189
189− s->last_resync_gb = s->gb;
190− s->first_slice_line = 1;
191− s->resync_mb_x = s->mb_x;
192− s->resync_mb_y = s->mb_y;
190+ h->c.last_resync_gb = h->c.gb;
191+ h->c.first_slice_line = 1;
192+ h->c.resync_mb_x = h->c.mb_x;
193+ h->c.resync_mb_y = h->c.mb_y;
193194
194− ff_set_qscale(s, s->qscale);
195+ ff_set_qscale(&h->c, h->c.qscale);
195196
196− if (s->studio_profile) {
197− if ((ret = ff_mpeg4_decode_studio_slice_header(s)) < 0)
197+ if (h->c.studio_profile) {
198+ if ((ret = ff_mpeg4_decode_studio_slice_header(h)) < 0)
198199 return ret;
199200 }
200201
201− if (s->avctx->hwaccel) {
202− const uint8_t *start = s->gb.buffer + get_bits_count(&s->gb) / 8;
203− ret = FF_HW_CALL(s->avctx, decode_slice, start, s->gb.buffer_end - start);
202+ if (h->c.avctx->hwaccel) {
203+ const uint8_t *start = h->c.gb.buffer + get_bits_count(&h->c.gb) / 8;
204+ ret = FF_HW_CALL(h->c.avctx, decode_slice, start, h->c.gb.buffer_end - start);
204205 // ensure we exit decode loop
205− s->mb_y = s->mb_height;
206+ h->c.mb_y = h->c.mb_height;
206207 return ret;
207208 }
208209
209− if (s->partitioned_frame) {
210− const int qscale = s->qscale;
210+ if (h->c.partitioned_frame) {
211+ const int qscale = h->c.qscale;
211212
212− if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4)
213− if ((ret = ff_mpeg4_decode_partitions(s)) < 0)
213+ if (CONFIG_MPEG4_DECODER && h->c.codec_id == AV_CODEC_ID_MPEG4)
214+ if ((ret = ff_mpeg4_decode_partitions(h)) < 0)
214215 return ret;
215216
216217 /* restore variables which were modified */
217− s->first_slice_line = 1;
218− s->mb_x = s->resync_mb_x;
219− s->mb_y = s->resync_mb_y;
220− ff_set_qscale(s, qscale);
218+ h->c.first_slice_line = 1;
219+ h->c.mb_x = h->c.resync_mb_x;
220+ h->c.mb_y = h->c.resync_mb_y;
221+ ff_set_qscale(&h->c, qscale);
221222 }
222223
223− for (; s->mb_y < s->mb_height; s->mb_y++) {
224+ for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) {
224225 /* per-row end of slice checks */
225− if (s->msmpeg4_version != MSMP4_UNUSED) {
226− if (s->resync_mb_y + s->slice_height == s->mb_y) {
227− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
228− s->mb_x - 1, s->mb_y, ER_MB_END);
226+ if (h->c.msmpeg4_version != MSMP4_UNUSED) {
227+ if (h->c.resync_mb_y + h->c.slice_height == h->c.mb_y) {
228+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
229+ h->c.mb_x - 1, h->c.mb_y, ER_MB_END);
229230
230231 return 0;
231232 }
232233 }
233234
234− if (s->msmpeg4_version == MSMP4_V1) {
235− s->last_dc[0] =
236− s->last_dc[1] =
237− s->last_dc[2] = 128;
235+ if (h->c.msmpeg4_version == MSMP4_V1) {
236+ h->c.last_dc[0] =
237+ h->c.last_dc[1] =
238+ h->c.last_dc[2] = 128;
238239 }
239240
240− ff_init_block_index(s);
241− for (; s->mb_x < s->mb_width; s->mb_x++) {
241+ ff_init_block_index(&h->c);
242+ for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
242243 int ret;
243244
244− ff_update_block_index(s, s->avctx->bits_per_raw_sample,
245− s->avctx->lowres, s->chroma_x_shift);
245+ ff_update_block_index(&h->c, h->c.avctx->bits_per_raw_sample,
246+ h->c.avctx->lowres, h->c.chroma_x_shift);
246247
247− if (s->resync_mb_x == s->mb_x && s->resync_mb_y + 1 == s->mb_y)
248− s->first_slice_line = 0;
248+ if (h->c.resync_mb_x == h->c.mb_x && h->c.resync_mb_y + 1 == h->c.mb_y)
249+ h->c.first_slice_line = 0;
249250
250251 /* DCT & quantize */
251252
252− s->mv_dir = MV_DIR_FORWARD;
253− s->mv_type = MV_TYPE_16X16;
254− ff_dlog(s->avctx, "%d %06X\n",
255− get_bits_count(&s->gb), show_bits(&s->gb, 24));
253+ h->c.mv_dir = MV_DIR_FORWARD;
254+ h->c.mv_type = MV_TYPE_16X16;
255+ ff_dlog(h->c.avctx, "%d %06X\n",
256+ get_bits_count(&h->c.gb), show_bits(&h->c.gb, 24));
256257
257− ff_tlog(NULL, "Decoding MB at %dx%d\n", s->mb_x, s->mb_y);
258− ret = s->decode_mb(s, s->block);
258+ ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y);
259+ ret = h->decode_mb(h, h->c.block);
259260
260− if (s->h263_pred || s->h263_aic) {
261− int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
262− if (!s->mb_intra) {
263− ff_h263_clean_intra_table_entries(s, mb_xy);
261+ if (h->c.h263_pred || h->c.h263_aic) {
262+ int mb_xy = h->c.mb_y * h->c.mb_stride + h->c.mb_x;
263+ if (!h->c.mb_intra) {
264+ ff_h263_clean_intra_table_entries(&h->c, mb_xy);
264265 } else
265− s->mbintra_table[mb_xy] = 1;
266+ h->c.mbintra_table[mb_xy] = 1;
266267 }
267268
268− if (s->pict_type != AV_PICTURE_TYPE_B)
269− ff_h263_update_motion_val(s);
269+ if (h->c.pict_type != AV_PICTURE_TYPE_B)
270+ ff_h263_update_motion_val(&h->c);
270271
271272 if (ret < 0) {
272− const int xy = s->mb_x + s->mb_y * s->mb_stride;
273+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
273274 if (ret == SLICE_END) {
274− ff_mpv_reconstruct_mb(s, s->block);
275− if (s->loop_filter)
276− ff_h263_loop_filter(s);
275+ ff_mpv_reconstruct_mb(&h->c, h->c.block);
276+ if (h->c.loop_filter)
277+ ff_h263_loop_filter(&h->c);
277278
278− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
279− s->mb_x, s->mb_y, ER_MB_END & part_mask);
279+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
280+ h->c.mb_x, h->c.mb_y, ER_MB_END & part_mask);
280281
281− s->padding_bug_score--;
282+ h->c.padding_bug_score--;
282283
283− if (++s->mb_x >= s->mb_width) {
284− s->mb_x = 0;
285− report_decode_progress(s);
286− ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
287− s->mb_y++;
284+ if (++h->c.mb_x >= h->c.mb_width) {
285+ h->c.mb_x = 0;
286+ report_decode_progress(&h->c);
287+ ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
288+ h->c.mb_y++;
288289 }
289290 return 0;
290291 } else if (ret == SLICE_NOEND) {
291− av_log(s->avctx, AV_LOG_ERROR,
292+ av_log(h->c.avctx, AV_LOG_ERROR,
292293 "Slice mismatch at MB: %d\n", xy);
293− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
294− s->mb_x + 1, s->mb_y,
294+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
295+ h->c.mb_x + 1, h->c.mb_y,
295296 ER_MB_END & part_mask);
296297 return AVERROR_INVALIDDATA;
297298 }
298− av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
299− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
300− s->mb_x, s->mb_y, ER_MB_ERROR & part_mask);
299+ av_log(h->c.avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
300+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
301+ h->c.mb_x, h->c.mb_y, ER_MB_ERROR & part_mask);
301302
302− if ((s->avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&s->gb) > 0)
303+ if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->c.gb) > 0)
303304 continue;
304305 return AVERROR_INVALIDDATA;
305306 }
306307
307− ff_mpv_reconstruct_mb(s, s->block);
308− if (s->loop_filter)
309− ff_h263_loop_filter(s);
308+ ff_mpv_reconstruct_mb(&h->c, h->c.block);
309+ if (h->c.loop_filter)
310+ ff_h263_loop_filter(&h->c);
310311 }
311312
312− report_decode_progress(s);
313− ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
313+ report_decode_progress(&h->c);
314+ ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
314315
315− s->mb_x = 0;
316+ h->c.mb_x = 0;
316317 }
317318
318− av_assert1(s->mb_x == 0 && s->mb_y == s->mb_height);
319+ av_assert1(h->c.mb_x == 0 && h->c.mb_y == h->c.mb_height);
319320
320321 // Detect incorrect padding with wrong stuffing codes used by NEC N-02B
321− if (s->codec_id == AV_CODEC_ID_MPEG4 &&
322− (s->workaround_bugs & FF_BUG_AUTODETECT) &&
323− get_bits_left(&s->gb) >= 48 &&
324− show_bits(&s->gb, 24) == 0x4010 &&
325− !s->data_partitioning)
326− s->padding_bug_score += 32;
322+ if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
323+ (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
324+ get_bits_left(&h->c.gb) >= 48 &&
325+ show_bits(&h->c.gb, 24) == 0x4010 &&
326+ !h->c.data_partitioning)
327+ h->c.padding_bug_score += 32;
327328
328329 /* try to detect the padding bug */
329− if (s->codec_id == AV_CODEC_ID_MPEG4 &&
330− (s->workaround_bugs & FF_BUG_AUTODETECT) &&
331− get_bits_left(&s->gb) >= 0 &&
332− get_bits_left(&s->gb) < 137 &&
333− !s->data_partitioning) {
334− const int bits_count = get_bits_count(&s->gb);
335− const int bits_left = s->gb.size_in_bits - bits_count;
330+ if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
331+ (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
332+ get_bits_left(&h->c.gb) >= 0 &&
333+ get_bits_left(&h->c.gb) < 137 &&
334+ !h->c.data_partitioning) {
335+ const int bits_count = get_bits_count(&h->c.gb);
336+ const int bits_left = h->c.gb.size_in_bits - bits_count;
336337
337338 if (bits_left == 0) {
338− s->padding_bug_score += 16;
339+ h->c.padding_bug_score += 16;
339340 } else if (bits_left != 1) {
340− int v = show_bits(&s->gb, 8);
341+ int v = show_bits(&h->c.gb, 8);
341342 v |= 0x7F >> (7 - (bits_count & 7));
342343
343344 if (v == 0x7F && bits_left <= 8)
344− s->padding_bug_score--;
345− else if (v == 0x7F && ((get_bits_count(&s->gb) + 8) & 8) &&
345+ h->c.padding_bug_score--;
346+ else if (v == 0x7F && ((get_bits_count(&h->c.gb) + 8) & 8) &&
346347 bits_left <= 16)
347− s->padding_bug_score += 4;
348+ h->c.padding_bug_score += 4;
348349 else
349− s->padding_bug_score++;
350+ h->c.padding_bug_score++;
350351 }
351352 }
352353
353− if (s->codec_id == AV_CODEC_ID_H263 &&
354− (s->workaround_bugs & FF_BUG_AUTODETECT) &&
355− get_bits_left(&s->gb) >= 8 &&
356− get_bits_left(&s->gb) < 300 &&
357− s->pict_type == AV_PICTURE_TYPE_I &&
358− show_bits(&s->gb, 8) == 0 &&
359− !s->data_partitioning) {
354+ if (h->c.codec_id == AV_CODEC_ID_H263 &&
355+ (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
356+ get_bits_left(&h->c.gb) >= 8 &&
357+ get_bits_left(&h->c.gb) < 300 &&
358+ h->c.pict_type == AV_PICTURE_TYPE_I &&
359+ show_bits(&h->c.gb, 8) == 0 &&
360+ !h->c.data_partitioning) {
360361
361− s->padding_bug_score += 32;
362+ h->c.padding_bug_score += 32;
362363 }
363364
364− if (s->codec_id == AV_CODEC_ID_H263 &&
365− (s->workaround_bugs & FF_BUG_AUTODETECT) &&
366− get_bits_left(&s->gb) >= 64 &&
367− AV_RB64(s->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
365+ if (h->c.codec_id == AV_CODEC_ID_H263 &&
366+ (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
367+ get_bits_left(&h->c.gb) >= 64 &&
368+ AV_RB64(h->c.gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
368369
369− s->padding_bug_score += 32;
370+ h->c.padding_bug_score += 32;
370371 }
371372
372− if (s->workaround_bugs & FF_BUG_AUTODETECT) {
373+ if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
373374 if (
374− (s->padding_bug_score > -2 && !s->data_partitioning))
375− s->workaround_bugs |= FF_BUG_NO_PADDING;
375+ (h->c.padding_bug_score > -2 && !h->c.data_partitioning))
376+ h->c.workaround_bugs |= FF_BUG_NO_PADDING;
376377 else
377− s->workaround_bugs &= ~FF_BUG_NO_PADDING;
378+ h->c.workaround_bugs &= ~FF_BUG_NO_PADDING;
378379 }
379380
380381 // handle formats which don't have unique end markers
381− if (s->msmpeg4_version != MSMP4_UNUSED || (s->workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
382− int left = get_bits_left(&s->gb);
382+ if (h->c.msmpeg4_version != MSMP4_UNUSED || (h->c.workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
383+ int left = get_bits_left(&h->c.gb);
383384 int max_extra = 7;
384385
385386 /* no markers in M$ crap */
386− if (s->msmpeg4_version != MSMP4_UNUSED && s->pict_type == AV_PICTURE_TYPE_I)
387+ if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.pict_type == AV_PICTURE_TYPE_I)
387388 max_extra += 17;
388389
389390 /* buggy padding but the frame should still end approximately at
390391 * the bitstream end */
391− if ((s->workaround_bugs & FF_BUG_NO_PADDING) &&
392− (s->avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
392+ if ((h->c.workaround_bugs & FF_BUG_NO_PADDING) &&
393+ (h->c.avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
393394 max_extra += 48;
394− else if ((s->workaround_bugs & FF_BUG_NO_PADDING))
395+ else if ((h->c.workaround_bugs & FF_BUG_NO_PADDING))
395396 max_extra += 256 * 256 * 256 * 64;
396397
397398 if (left > max_extra)
398− av_log(s->avctx, AV_LOG_ERROR,
399+ av_log(h->c.avctx, AV_LOG_ERROR,
399400 "discarding %d junk bits at end, next would be %X\n",
400− left, show_bits(&s->gb, 24));
401+ left, show_bits(&h->c.gb, 24));
401402 else if (left < 0)
402− av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
403+ av_log(h->c.avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
403404 else
404− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
405− s->mb_x - 1, s->mb_y, ER_MB_END);
405+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
406+ h->c.mb_x - 1, h->c.mb_y, ER_MB_END);
406407
407408 return 0;
408409 }
409410
410− av_log(s->avctx, AV_LOG_ERROR,
411+ av_log(h->c.avctx, AV_LOG_ERROR,
411412 "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
412− get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score);
413+ get_bits_left(&h->c.gb), show_bits(&h->c.gb, 24), h->c.padding_bug_score);
413414
414− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y,
415+ 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,
415416 ER_MB_END & part_mask);
416417
417418 return AVERROR_INVALIDDATA;
@@ -420,9 +421,10 @@ static int decode_slice(MpegEncContext *s) · 2 unmodified lines
420421 int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict,
421422 int *got_frame, AVPacket *avpkt)
422423 {
424+ H263DecContext *const h = avctx->priv_data;
425+ MPVContext *const s = &h->c;
423426 const uint8_t *buf = avpkt->data;
424427 int buf_size = avpkt->size;
425− MpegEncContext *s = avctx->priv_data;
426428 int ret;
427429 int slice_ret = 0;
428430 int bak_width, bak_height;
@@ -430,10 +432,10 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 1 unmodified line
430432 /* no supplementary picture */
431433 if (buf_size == 0) {
432434 /* special case for last picture */
433− if ((!s->low_delay || s->skipped_last_frame) && s->next_pic.ptr) {
434− if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
435+ if ((!h->c.low_delay || h->c.skipped_last_frame) && h->c.next_pic.ptr) {
436+ if ((ret = av_frame_ref(pict, h->c.next_pic.ptr->f)) < 0)
435437 return ret;
436− if (s->skipped_last_frame) {
438+ if (h->c.skipped_last_frame) {
437439 /* If the stream ended with an NVOP, we output the last frame
438440 * in display order, but with the props from the last input
439441 * packet so that the stream's end time is correct. */
@@ -442,7 +444,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 2 unmodified lines
442444 return ret;
443445 }
444446
445− ff_mpv_unref_picture(&s->next_pic);
447+ ff_mpv_unref_picture(&h->c.next_pic);
446448
447449 *got_frame = 1;
448450 }
@@ -450,37 +452,37 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 1 unmodified line
450452 return 0;
451453 }
452454
453− // s->gb might be overridden in ff_mpeg4_decode_picture_header() below.
454− ret = init_get_bits8(&s->gb, buf, buf_size);
455+ // h->c.gb might be overridden in ff_mpeg4_decode_picture_header() below.
456+ ret = init_get_bits8(&h->c.gb, buf, buf_size);
455457 if (ret < 0)
456458 return ret;
457459
458− bak_width = s->width;
459− bak_height = s->height;
460+ bak_width = h->c.width;
461+ bak_height = h->c.height;
460462
461463 /* let's go :-) */
462− if (CONFIG_WMV2_DECODER && s->msmpeg4_version == MSMP4_WMV2) {
463− ret = ff_wmv2_decode_picture_header(s);
464+ if (CONFIG_WMV2_DECODER && h->c.msmpeg4_version == MSMP4_WMV2) {
465+ ret = ff_wmv2_decode_picture_header(h);
464466 #if CONFIG_MSMPEG4DEC
465− } else if (s->msmpeg4_version != MSMP4_UNUSED) {
466− ret = ff_msmpeg4_decode_picture_header(s);
467+ } else if (h->c.msmpeg4_version != MSMP4_UNUSED) {
468+ ret = ff_msmpeg4_decode_picture_header(h);
467469 #endif
468470 } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
469− ret = ff_mpeg4_decode_picture_header(s);
470− } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
471− ret = ff_intel_h263_decode_picture_header(s);
472− } else if (CONFIG_FLV_DECODER && s->h263_flv) {
473− ret = ff_flv_decode_picture_header(s);
471+ ret = ff_mpeg4_decode_picture_header(h);
472+ } else if (CONFIG_H263I_DECODER && h->c.codec_id == AV_CODEC_ID_H263I) {
473+ ret = ff_intel_h263_decode_picture_header(h);
474+ } else if (CONFIG_FLV_DECODER && h->c.h263_flv) {
475+ ret = ff_flv_decode_picture_header(h);
474476 } else {
475− ret = ff_h263_decode_picture_header(s);
477+ ret = ff_h263_decode_picture_header(h);
476478 }
477479
478480 if (ret < 0 || ret == FRAME_SKIPPED) {
479− if ( s->width != bak_width
480− || s->height != bak_height) {
481− av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
482− s->width = bak_width;
483− s->height= bak_height;
481+ if ( h->c.width != bak_width
482+ || h->c.height != bak_height) {
483+ av_log(h->c.avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
484+ h->c.width = bak_width;
485+ h->c.height= bak_height;
484486
485487 }
486488 }
@@ -489,37 +491,35 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 2 unmodified lines
489491
490492 /* skip if the header was thrashed */
491493 if (ret < 0) {
492− av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
494+ av_log(h->c.avctx, AV_LOG_ERROR, "header damaged\n");
493495 return ret;
494496 }
495497
496− if (!s->context_initialized) {
498+ if (!h->c.context_initialized) {
497499 avctx->pix_fmt = h263_get_format(avctx);
498500 if ((ret = ff_mpv_common_init(s)) < 0)
499501 return ret;
500502 }
501503
502− avctx->has_b_frames = !s->low_delay;
504+ avctx->has_b_frames = !h->c.low_delay;
503505
504506 if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
505− if (s->pict_type != AV_PICTURE_TYPE_B && s->mb_num/2 > get_bits_left(&s->gb))
507+ if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->c.gb))
506508 return AVERROR_INVALIDDATA;
507509 ff_mpeg4_workaround_bugs(avctx);
508− if (s->studio_profile != (s->idsp.idct == NULL))
510+ if (h->c.studio_profile != (h->c.idsp.idct == NULL))
509511 ff_mpv_idct_init(s);
510512 }
511513
512514 /* After H.263 & MPEG-4 header decode we have the height, width,
513− * and other parameters. So then we could init the picture.
514− * FIXME: By the way H.263 decoder is evolving it should have
515− * an H263EncContext */
516− if (s->width != avctx->coded_width ||
517− s->height != avctx->coded_height ||
518− s->context_reinit) {
515+ * and other parameters. So then we could init the picture. */
516+ if (h->c.width != avctx->coded_width ||
517+ h->c.height != avctx->coded_height ||
518+ h->c.context_reinit) {
519519 /* H.263 could change picture size any time */
520− s->context_reinit = 0;
520+ h->c.context_reinit = 0;
521521
522− ret = ff_set_dimensions(avctx, s->width, s->height);
522+ ret = ff_set_dimensions(avctx, h->c.width, h->c.height);
523523 if (ret < 0)
524524 return ret;
525525
@@ -536,25 +536,25 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 10 unmodified lines
536536 }
537537
538538 /* skip B-frames if we don't have reference frames */
539− if (!s->last_pic.ptr &&
540− (s->pict_type == AV_PICTURE_TYPE_B || s->droppable))
539+ if (!h->c.last_pic.ptr &&
540+ (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.droppable))
541541 return buf_size;
542542 if ((avctx->skip_frame >= AVDISCARD_NONREF &&
543− s->pict_type == AV_PICTURE_TYPE_B) ||
543+ h->c.pict_type == AV_PICTURE_TYPE_B) ||
544544 (avctx->skip_frame >= AVDISCARD_NONKEY &&
545− s->pict_type != AV_PICTURE_TYPE_I) ||
545+ h->c.pict_type != AV_PICTURE_TYPE_I) ||
546546 avctx->skip_frame >= AVDISCARD_ALL)
547547 return buf_size;
548548
549549 if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
550550 return ret;
551551
552− if (!s->divx_packed)
552+ if (!h->c.divx_packed)
553553 ff_thread_finish_setup(avctx);
554554
555555 if (avctx->hwaccel) {
556556 ret = FF_HW_CALL(avctx, start_frame, NULL,
557− s->gb.buffer, s->gb.buffer_end - s->gb.buffer);
557+ h->c.gb.buffer, h->c.gb.buffer_end - h->c.gb.buffer);
558558 if (ret < 0 )
559559 return ret;
560560 }
@@ -565,8 +565,8 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 4 unmodified lines
565565 * are stored in current_picture->mb_type which is not available before
566566 * ff_mpv_frame_start() */
567567 #if CONFIG_WMV2_DECODER
568− if (s->msmpeg4_version == MSMP4_WMV2) {
569− ret = ff_wmv2_decode_secondary_picture_header(s);
568+ if (h->c.msmpeg4_version == MSMP4_WMV2) {
569+ ret = ff_wmv2_decode_secondary_picture_header(h);
570570 if (ret < 0)
571571 return ret;
572572 if (ret == 1)
@@ -575,39 +575,39 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 2 unmodified lines
575575 #endif
576576
577577 /* decode each macroblock */
578− s->mb_x = 0;
579− s->mb_y = 0;
580−
581− slice_ret = decode_slice(s);
582− while (s->mb_y < s->mb_height) {
583− if (s->msmpeg4_version != MSMP4_UNUSED) {
584− if (s->slice_height == 0 || s->mb_x != 0 || slice_ret < 0 ||
585− (s->mb_y % s->slice_height) != 0 || get_bits_left(&s->gb) < 0)
578+ h->c.mb_x = 0;
579+ h->c.mb_y = 0;
580+
581+ slice_ret = decode_slice(h);
582+ while (h->c.mb_y < h->c.mb_height) {
583+ if (h->c.msmpeg4_version != MSMP4_UNUSED) {
584+ if (h->c.slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 ||
585+ (h->c.mb_y % h->c.slice_height) != 0 || get_bits_left(&h->c.gb) < 0)
586586 break;
587587 } else {
588− int prev_x = s->mb_x, prev_y = s->mb_y;
589− if (ff_h263_resync(s) < 0)
588+ int prev_x = h->c.mb_x, prev_y = h->c.mb_y;
589+ if (ff_h263_resync(h) < 0)
590590 break;
591− if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x)
592− s->er.error_occurred = 1;
591+ if (prev_y * h->c.mb_width + prev_x < h->c.mb_y * h->c.mb_width + h->c.mb_x)
592+ h->c.er.error_occurred = 1;
593593 }
594594
595− if (s->msmpeg4_version < MSMP4_WMV1 && s->h263_pred)
595+ if (h->c.msmpeg4_version < MSMP4_WMV1 && h->c.h263_pred)
596596 ff_mpeg4_clean_buffers(s);
597597
598− if (decode_slice(s) < 0)
598+ if (decode_slice(h) < 0)
599599 slice_ret = AVERROR_INVALIDDATA;
600600 }
601601
602− if (s->msmpeg4_version != MSMP4_UNUSED && s->msmpeg4_version < MSMP4_WMV1 &&
603− s->pict_type == AV_PICTURE_TYPE_I)
602+ if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.msmpeg4_version < MSMP4_WMV1 &&
603+ h->c.pict_type == AV_PICTURE_TYPE_I)
604604 if (!CONFIG_MSMPEG4DEC ||
605− ff_msmpeg4_decode_ext_header(s, buf_size) < 0)
606− s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR;
605+ ff_msmpeg4_decode_ext_header(h, buf_size) < 0)
606+ h->c.er.error_status_table[h->c.mb_num - 1] = ER_MB_ERROR;
607607
608608 frame_end:
609− if (!s->studio_profile)
610− ff_er_frame_end(&s->er, NULL);
609+ if (!h->c.studio_profile)
610+ ff_er_frame_end(&h->c.er, NULL);
611611
612612 if (avctx->hwaccel) {
613613 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
@@ -620,22 +620,22 @@ frame_end: · 6 unmodified lines
620620 if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
621621 ff_mpeg4_frame_end(avctx, avpkt);
622622
623− av_assert1(s->pict_type == s->cur_pic.ptr->f->pict_type);
624− if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
625− if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
623+ av_assert1(h->c.pict_type == h->c.cur_pic.ptr->f->pict_type);
624+ if (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.low_delay) {
625+ if ((ret = av_frame_ref(pict, h->c.cur_pic.ptr->f)) < 0)
626626 return ret;
627− ff_print_debug_info(s, s->cur_pic.ptr, pict);
628− ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
629− } else if (s->last_pic.ptr) {
630− if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0)
627+ ff_print_debug_info(s, h->c.cur_pic.ptr, pict);
628+ ff_mpv_export_qp_table(s, pict, h->c.cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
629+ } else if (h->c.last_pic.ptr) {
630+ if ((ret = av_frame_ref(pict, h->c.last_pic.ptr->f)) < 0)
631631 return ret;
632− ff_print_debug_info(s, s->last_pic.ptr, pict);
633− ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
632+ ff_print_debug_info(s, h->c.last_pic.ptr, pict);
633+ ff_mpv_export_qp_table(s, pict, h->c.last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
634634 }
635635
636− if (s->last_pic.ptr || s->low_delay) {
636+ if (h->c.last_pic.ptr || h->c.low_delay) {
637637 if ( pict->format == AV_PIX_FMT_YUV420P
638− && (s->codec_tag == AV_RL32("GEOV") || s->codec_tag == AV_RL32("GEOX"))) {
638+ && (h->c.codec_tag == AV_RL32("GEOV") || h->c.codec_tag == AV_RL32("GEOX"))) {
639639 for (int p = 0; p < 3; p++) {
640640 int h = AV_CEIL_RSHIFT(pict->height, !!p);
641641
@@ -673,7 +673,7 @@ const FFCodec ff_h263_decoder = { · 31 unmodified lines
673673 CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
674674 .p.type = AVMEDIA_TYPE_VIDEO,
675675 .p.id = AV_CODEC_ID_H263,
676− .priv_data_size = sizeof(MpegEncContext),
676+ .priv_data_size = sizeof(H263DecContext),
677677 .init = ff_h263_decode_init,
678678 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
679679 .close = ff_mpv_decode_close,
@@ -691,7 +691,7 @@ const FFCodec ff_h263p_decoder = { · 11 unmodified lines
691691 CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
692692 .p.type = AVMEDIA_TYPE_VIDEO,
693693 .p.id = AV_CODEC_ID_H263P,
694− .priv_data_size = sizeof(MpegEncContext),
694+ .priv_data_size = sizeof(H263DecContext),
695695 .init = ff_h263_decode_init,
696696 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
697697 .close = ff_mpv_decode_close,
libavcodec/h263dec.h+14−8
@@ -43,24 +43,30 @@ extern VLCElem ff_h263_inter_MCBPC_vlc[]; · 42 unmodified lines
4343 extern VLCElem ff_h263_cbpy_vlc[];
4444 extern VLCElem ff_h263_mv_vlc[];
4545
46−int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code);
46+typedef struct H263DecContext {
47+ MPVContext c;
48+
49+ int (*decode_mb)(struct H263DecContext *h, int16_t block[6][64]);
50+} H263DecContext;
51+
52+int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code);
4753 int ff_h263_decode_init(AVCodecContext *avctx);
4854 int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *frame,
4955 int *got_frame, AVPacket *avpkt);
5056 void ff_h263_decode_init_vlc(void);
51−int ff_h263_decode_picture_header(MpegEncContext *s);
52−int ff_h263_decode_gob_header(MpegEncContext *s);
53−int ff_h263_decode_mba(MpegEncContext *s);
57+int ff_h263_decode_picture_header(H263DecContext *const h);
58+int ff_h263_decode_gob_header(H263DecContext *const h);
59+int ff_h263_decode_mba(H263DecContext *const h);
5460
5561 /**
5662 * Print picture info if FF_DEBUG_PICT_INFO is set.
5763 */
58−void ff_h263_show_pict_info(MpegEncContext *s, int h263_plus);
64+void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus);
5965
60−int ff_intel_h263_decode_picture_header(MpegEncContext *s);
61−int ff_h263_decode_mb(MpegEncContext *s,
66+int ff_intel_h263_decode_picture_header(H263DecContext *const h);
67+int ff_h263_decode_mb(H263DecContext *const h,
6268 int16_t block[6][64]);
6369
64−int ff_h263_resync(MpegEncContext *s);
70+int ff_h263_resync(H263DecContext *const h);
6571
6672 #endif
libavcodec/intelh263dec.c+55−55
@@ -26,102 +26,102 @@ · 25 unmodified lines
2626 #include "h263dec.h"
2727
2828 /* don't understand why they choose a different header ! */
29−int ff_intel_h263_decode_picture_header(MpegEncContext *s)
29+int ff_intel_h263_decode_picture_header(H263DecContext *const h)
3030 {
3131 int format;
3232
33− if (get_bits_left(&s->gb) == 64) { /* special dummy frames */
33+ if (get_bits_left(&h->c.gb) == 64) { /* special dummy frames */
3434 return FRAME_SKIPPED;
3535 }
3636
3737 /* picture header */
38− if (get_bits(&s->gb, 22) != 0x20) {
39− av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
38+ if (get_bits(&h->c.gb, 22) != 0x20) {
39+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
4040 return -1;
4141 }
42− s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */
42+ h->c.picture_number = get_bits(&h->c.gb, 8); /* picture timestamp */
4343
44− if (check_marker(s->avctx, &s->gb, "after picture_number") != 1) {
44+ if (check_marker(h->c.avctx, &h->c.gb, "after picture_number") != 1) {
4545 return -1; /* marker */
4646 }
47− if (get_bits1(&s->gb) != 0) {
48− av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
47+ if (get_bits1(&h->c.gb) != 0) {
48+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
4949 return -1; /* H.263 id */
5050 }
51− skip_bits1(&s->gb); /* split screen off */
52− skip_bits1(&s->gb); /* camera off */
53− skip_bits1(&s->gb); /* freeze picture release off */
51+ skip_bits1(&h->c.gb); /* split screen off */
52+ skip_bits1(&h->c.gb); /* camera off */
53+ skip_bits1(&h->c.gb); /* freeze picture release off */
5454
55− format = get_bits(&s->gb, 3);
55+ format = get_bits(&h->c.gb, 3);
5656 if (format == 0 || format == 6) {
57− av_log(s->avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
57+ av_log(h->c.avctx, AV_LOG_ERROR, "Intel H.263 free format not supported\n");
5858 return -1;
5959 }
6060
61− s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
61+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb);
6262
63− s->h263_long_vectors = get_bits1(&s->gb);
63+ h->c.h263_long_vectors = get_bits1(&h->c.gb);
6464
65− if (get_bits1(&s->gb) != 0) {
66− av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n");
65+ if (get_bits1(&h->c.gb) != 0) {
66+ av_log(h->c.avctx, AV_LOG_ERROR, "SAC not supported\n");
6767 return -1; /* SAC: off */
6868 }
69− s->obmc= get_bits1(&s->gb);
70− s->pb_frame = get_bits1(&s->gb);
69+ h->c.obmc = get_bits1(&h->c.gb);
70+ h->c.pb_frame = get_bits1(&h->c.gb);
7171
7272 if (format < 6) {
73− s->width = ff_h263_format[format][0];
74− s->height = ff_h263_format[format][1];
75− s->avctx->sample_aspect_ratio.num = 12;
76− s->avctx->sample_aspect_ratio.den = 11;
73+ h->c.width = ff_h263_format[format][0];
74+ h->c.height = ff_h263_format[format][1];
75+ h->c.avctx->sample_aspect_ratio.num = 12;
76+ h->c.avctx->sample_aspect_ratio.den = 11;
7777 } else {
78− format = get_bits(&s->gb, 3);
78+ format = get_bits(&h->c.gb, 3);
7979 if(format == 0 || format == 7){
80− av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
80+ av_log(h->c.avctx, AV_LOG_ERROR, "Wrong Intel H.263 format\n");
8181 return -1;
8282 }
83− if(get_bits(&s->gb, 2))
84− av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
85− s->loop_filter = get_bits1(&s->gb) * !s->avctx->lowres;
86− if(get_bits1(&s->gb))
87− av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
88− if(get_bits1(&s->gb))
89− s->pb_frame = 2;
90− if(get_bits(&s->gb, 5))
91− av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
92− if(get_bits(&s->gb, 5) != 1)
93− av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n");
83+ if (get_bits(&h->c.gb, 2))
84+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
85+ h->c.loop_filter = get_bits1(&h->c.gb) * !h->c.avctx->lowres;
86+ if (get_bits1(&h->c.gb))
87+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
88+ if (get_bits1(&h->c.gb))
89+ h->c.pb_frame = 2;
90+ if (get_bits(&h->c.gb, 5))
91+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad value for reserved field\n");
92+ if (get_bits(&h->c.gb, 5) != 1)
93+ av_log(h->c.avctx, AV_LOG_ERROR, "Invalid marker\n");
9494 }
9595 if(format == 6){
96− int ar = get_bits(&s->gb, 4);
97− skip_bits(&s->gb, 9); // display width
98− check_marker(s->avctx, &s->gb, "in dimensions");
99− skip_bits(&s->gb, 9); // display height
100− if(ar == 15){
101− s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width
102− s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height
96+ int ar = get_bits(&h->c.gb, 4);
97+ skip_bits(&h->c.gb, 9); // display width
98+ check_marker(h->c.avctx, &h->c.gb, "in dimensions");
99+ skip_bits(&h->c.gb, 9); // display height
100+ if (ar == 15) {
101+ h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8); // aspect ratio - width
102+ h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8); // aspect ratio - height
103103 } else {
104− s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
104+ h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar];
105105 }
106− if (s->avctx->sample_aspect_ratio.num == 0)
107− av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
106+ if (h->c.avctx->sample_aspect_ratio.num == 0)
107+ av_log(h->c.avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n");
108108 }
109109
110− s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
111− skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
110+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
111+ skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */
112112
113− if(s->pb_frame){
114− skip_bits(&s->gb, 3); //temporal reference for B-frame
115− skip_bits(&s->gb, 2); //dbquant
113+ if (h->c.pb_frame) {
114+ skip_bits(&h->c.gb, 3); //temporal reference for B-frame
115+ skip_bits(&h->c.gb, 2); //dbquant
116116 }
117117
118118 /* PEI */
119− if (skip_1stop_8data_bits(&s->gb) < 0)
119+ if (skip_1stop_8data_bits(&h->c.gb) < 0)
120120 return AVERROR_INVALIDDATA;
121121
122− s->gob_index = H263_GOB_HEIGHT(s->height);
122+ h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
123123
124− ff_h263_show_pict_info(s, 0);
124+ ff_h263_show_pict_info(h, 0);
125125
126126 return 0;
127127 }
@@ -131,7 +131,7 @@ const FFCodec ff_h263i_decoder = { · 3 unmodified lines
131131 CODEC_LONG_NAME("Intel H.263"),
132132 .p.type = AVMEDIA_TYPE_VIDEO,
133133 .p.id = AV_CODEC_ID_H263I,
134− .priv_data_size = sizeof(MpegEncContext),
134+ .priv_data_size = sizeof(H263DecContext),
135135 .init = ff_h263_decode_init,
136136 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
137137 .close = ff_mpv_decode_close,
libavcodec/ituh263dec.c+476−471
@@ -77,23 +77,22 @@ static const int16_t h263_mb_type_b_map[15]= { · 76 unmodified lines
7777 MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT,
7878 };
7979
80−void ff_h263_show_pict_info(MpegEncContext *s, int h263_plus)
80+void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
8181 {
82− if(s->avctx->debug&FF_DEBUG_PICT_INFO){
83− 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",
84− s->qscale, av_get_picture_type_char(s->pict_type),
85− s->gb.size_in_bits, 1-s->no_rounding,
86− s->obmc ? " AP" : "",
87− s->umvplus ? " UMV" : "",
88− s->h263_long_vectors ? " LONG" : "",
89− h263_plus ? " +" : "",
90− s->h263_aic ? " AIC" : "",
91− s->alt_inter_vlc ? " AIV" : "",
92− s->modified_quant ? " MQ" : "",
93− s->loop_filter ? " LOOP" : "",
94− s->h263_slice_structured ? " SS" : "",
95− s->avctx->framerate.num, s->avctx->framerate.den
96− );
82+ if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {
83+ 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",
84+ h->c.qscale, av_get_picture_type_char(h->c.pict_type),
85+ h->c.gb.size_in_bits, 1-h->c.no_rounding,
86+ h->c.obmc ? " AP" : "",
87+ h->c.umvplus ? " UMV" : "",
88+ h->c.h263_long_vectors ? " LONG" : "",
89+ h263_plus ? " +" : "",
90+ h->c.h263_aic ? " AIC" : "",
91+ h->c.alt_inter_vlc ? " AIV" : "",
92+ h->c.modified_quant ? " MQ" : "",
93+ h->c.loop_filter ? " LOOP" : "",
94+ h->c.h263_slice_structured ? " SS" : "",
95+ h->c.avctx->framerate.num, h->c.avctx->framerate.den);
9796 }
9897 }
9998
@@ -140,16 +139,16 @@ av_cold void ff_h263_decode_init_vlc(void) · 40 unmodified lines
140139 ff_thread_once(&init_static_once, h263_decode_init_vlc);
141140 }
142141
143−int ff_h263_decode_mba(MpegEncContext *s)
142+int ff_h263_decode_mba(H263DecContext *const h)
144143 {
145144 int i, mb_pos;
146145
147146 for (i = 0; i < 6; i++)
148− if (s->mb_num - 1 <= ff_mba_max[i])
147+ if (h->c.mb_num - 1 <= ff_mba_max[i])
149148 break;
150− mb_pos = get_bits(&s->gb, ff_mba_length[i]);
151− s->mb_x = mb_pos % s->mb_width;
152− s->mb_y = mb_pos / s->mb_width;
149+ mb_pos = get_bits(&h->c.gb, ff_mba_length[i]);
150+ h->c.mb_x = mb_pos % h->c.mb_width;
151+ h->c.mb_y = mb_pos / h->c.mb_width;
153152
154153 return mb_pos;
155154 }
@@ -158,53 +157,53 @@ int ff_h263_decode_mba(MpegEncContext *s) · 2 unmodified lines
158157 * Decode the group of blocks header or slice header.
159158 * @return <0 if an error occurred
160159 */
161−static int h263_decode_gob_header(MpegEncContext *s)
160+static int h263_decode_gob_header(H263DecContext *const h)
162161 {
163162 unsigned int val, gob_number;
164163 int left;
165164
166165 /* Check for GOB Start Code */
167− val = show_bits(&s->gb, 16);
166+ val = show_bits(&h->c.gb, 16);
168167 if(val)
169168 return -1;
170169
171170 /* We have a GBSC probably with GSTUFF */
172− skip_bits(&s->gb, 16); /* Drop the zeros */
173− left= get_bits_left(&s->gb);
171+ skip_bits(&h->c.gb, 16); /* Drop the zeros */
172+ left = get_bits_left(&h->c.gb);
174173 left = FFMIN(left, 32);
175174 //MN: we must check the bits left or we might end in an infinite loop (or segfault)
176175 for(;left>13; left--){
177− if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
176+ if (get_bits1(&h->c.gb)) break; /* Seek the '1' bit */
178177 }
179178 if(left<=13)
180179 return -1;
181180
182− if(s->h263_slice_structured){
183− if(check_marker(s->avctx, &s->gb, "before MBA")==0)
181+ if (h->c.h263_slice_structured) {
182+ if (check_marker(h->c.avctx, &h->c.gb, "before MBA")==0)
184183 return -1;
185184
186− ff_h263_decode_mba(s);
185+ ff_h263_decode_mba(h);
187186
188− if(s->mb_num > 1583)
189− if(check_marker(s->avctx, &s->gb, "after MBA")==0)
187+ if (h->c.mb_num > 1583)
188+ if (check_marker(h->c.avctx, &h->c.gb, "after MBA")==0)
190189 return -1;
191190
192− s->qscale = get_bits(&s->gb, 5); /* SQUANT */
193− if(check_marker(s->avctx, &s->gb, "after SQUANT")==0)
191+ h->c.qscale = get_bits(&h->c.gb, 5); /* SQUANT */
192+ if (check_marker(h->c.avctx, &h->c.gb, "after SQUANT")==0)
194193 return -1;
195− skip_bits(&s->gb, 2); /* GFID */
194+ skip_bits(&h->c.gb, 2); /* GFID */
196195 }else{
197− gob_number = get_bits(&s->gb, 5); /* GN */
198− s->mb_x= 0;
199− s->mb_y= s->gob_index* gob_number;
200− skip_bits(&s->gb, 2); /* GFID */
201− s->qscale = get_bits(&s->gb, 5); /* GQUANT */
196+ gob_number = get_bits(&h->c.gb, 5); /* GN */
197+ h->c.mb_x = 0;
198+ h->c.mb_y = h->c.gob_index* gob_number;
199+ skip_bits(&h->c.gb, 2); /* GFID */
200+ h->c.qscale = get_bits(&h->c.gb, 5); /* GQUANT */
202201 }
203202
204− if(s->mb_y >= s->mb_height)
203+ if (h->c.mb_y >= h->c.mb_height)
205204 return -1;
206205
207− if(s->qscale==0)
206+ if (h->c.qscale==0)
208207 return -1;
209208
210209 return 0;
@@ -214,79 +213,80 @@ static int h263_decode_gob_header(MpegEncContext *s) · 3 unmodified lines
214213 * Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
215214 * @return bit position of the resync_marker, or <0 if none was found
216215 */
217−int ff_h263_resync(MpegEncContext *s){
216+int ff_h263_resync(H263DecContext *const h)
217+{
218218 int left, pos, ret;
219219
220220 /* In MPEG-4 studio mode look for a new slice startcode
221221 * and decode slice header */
222− if(s->codec_id==AV_CODEC_ID_MPEG4 && s->studio_profile) {
223− align_get_bits(&s->gb);
222+ if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) {
223+ align_get_bits(&h->c.gb);
224224
225− while (get_bits_left(&s->gb) >= 32 && show_bits_long(&s->gb, 32) != SLICE_STARTCODE) {
226− get_bits(&s->gb, 8);
225+ while (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) != SLICE_STARTCODE) {
226+ get_bits(&h->c.gb, 8);
227227 }
228228
229− if (get_bits_left(&s->gb) >= 32 && show_bits_long(&s->gb, 32) == SLICE_STARTCODE)
230− return get_bits_count(&s->gb);
229+ if (get_bits_left(&h->c.gb) >= 32 && show_bits_long(&h->c.gb, 32) == SLICE_STARTCODE)
230+ return get_bits_count(&h->c.gb);
231231 else
232232 return -1;
233233 }
234234
235− if(s->codec_id==AV_CODEC_ID_MPEG4){
236− skip_bits1(&s->gb);
237− align_get_bits(&s->gb);
235+ if (h->c.codec_id==AV_CODEC_ID_MPEG4){
236+ skip_bits1(&h->c.gb);
237+ align_get_bits(&h->c.gb);
238238 }
239239
240− if(show_bits(&s->gb, 16)==0){
241− pos= get_bits_count(&s->gb);
242− if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
243− ret = ff_mpeg4_decode_video_packet_header(s);
240+ if (show_bits(&h->c.gb, 16) ==0) {
241+ pos = get_bits_count(&h->c.gb);
242+ if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)
243+ ret = ff_mpeg4_decode_video_packet_header(h);
244244 else
245− ret= h263_decode_gob_header(s);
245+ ret = h263_decode_gob_header(h);
246246 if(ret>=0)
247247 return pos;
248248 }
249249 //OK, it's not where it is supposed to be ...
250− s->gb= s->last_resync_gb;
251− align_get_bits(&s->gb);
252− left= get_bits_left(&s->gb);
250+ h->c.gb = h->c.last_resync_gb;
251+ align_get_bits(&h->c.gb);
252+ left = get_bits_left(&h->c.gb);
253253
254254 for(;left>16+1+5+5; left-=8){
255− if(show_bits(&s->gb, 16)==0){
256− GetBitContext bak= s->gb;
255+ if (show_bits(&h->c.gb, 16) == 0){
256+ GetBitContext bak = h->c.gb;
257257
258− pos= get_bits_count(&s->gb);
259− if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
260− ret = ff_mpeg4_decode_video_packet_header(s);
258+ pos = get_bits_count(&h->c.gb);
259+ if(CONFIG_MPEG4_DECODER && h->c.codec_id==AV_CODEC_ID_MPEG4)
260+ ret = ff_mpeg4_decode_video_packet_header(h);
261261 else
262− ret= h263_decode_gob_header(s);
262+ ret = h263_decode_gob_header(h);
263263 if(ret>=0)
264264 return pos;
265265
266− s->gb= bak;
266+ h->c.gb = bak;
267267 }
268− skip_bits(&s->gb, 8);
268+ skip_bits(&h->c.gb, 8);
269269 }
270270
271271 return -1;
272272 }
273273
274−int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
274+int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
275275 {
276276 int code, val, sign, shift;
277− code = get_vlc2(&s->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
277+ code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
278278
279279 if (code == 0)
280280 return pred;
281281 if (code < 0)
282282 return 0xffff;
283283
284− sign = get_bits1(&s->gb);
284+ sign = get_bits1(&h->c.gb);
285285 shift = f_code - 1;
286286 val = code;
287287 if (shift) {
288288 val = (val - 1) << shift;
289− val |= get_bits(&s->gb, shift);
289+ val |= get_bits(&h->c.gb, shift);
290290 val++;
291291 }
292292 if (sign)
@@ -294,7 +294,7 @@ int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code) · 1 unmodified line
294294 val += pred;
295295
296296 /* modulo decoding */
297− if (!s->h263_long_vectors) {
297+ if (!h->c.h263_long_vectors) {
298298 val = sign_extend(val, 5 + f_code);
299299 } else {
300300 /* horrible H.263 long vector mode */
@@ -309,21 +309,21 @@ int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code) · 8 unmodified lines
309309
310310
311311 /* Decode RVLC of H.263+ UMV */
312−static int h263p_decode_umotion(MpegEncContext * s, int pred)
312+static int h263p_decode_umotion(H263DecContext *const h, int pred)
313313 {
314314 int code = 0, sign;
315315
316− if (get_bits1(&s->gb)) /* Motion difference = 0 */
316+ if (get_bits1(&h->c.gb)) /* Motion difference = 0 */
317317 return pred;
318318
319− code = 2 + get_bits1(&s->gb);
319+ code = 2 + get_bits1(&h->c.gb);
320320
321− while (get_bits1(&s->gb))
321+ while (get_bits1(&h->c.gb))
322322 {
323323 code <<= 1;
324− code += get_bits1(&s->gb);
324+ code += get_bits1(&h->c.gb);
325325 if (code >= 32768) {
326− avpriv_request_sample(s->avctx, "Huge DMV");
326+ avpriv_request_sample(h->c.avctx, "Huge DMV");
327327 return 0xffff;
328328 }
329329 }
@@ -331,7 +331,7 @@ static int h263p_decode_umotion(MpegEncContext * s, int pred) · 1 unmodified line
331331 code >>= 1;
332332
333333 code = (sign) ? (pred - code) : (pred + code);
334− ff_tlog(s->avctx,"H.263+ UMV Motion = %d\n", code);
334+ ff_tlog(h->c.avctx,"H.263+ UMV Motion = %d\n", code);
335335 return code;
336336
337337 }
@@ -339,82 +339,79 @@ static int h263p_decode_umotion(MpegEncContext * s, int pred) · 1 unmodified line
339339 /**
340340 * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :)
341341 */
342−static void preview_obmc(MpegEncContext *s){
343− GetBitContext gb= s->gb;
342+static void preview_obmc(H263DecContext *const h)
343+{
344+ GetBitContext gb = h->c.gb;
344345
345346 int cbpc, i, pred_x, pred_y, mx, my;
346347 int16_t *mot_val;
347− const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
348− const int stride= s->b8_stride*2;
348+ const int xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride;
349+ const int stride = h->c.b8_stride * 2;
349350
350351 for(i=0; i<4; i++)
351− s->block_index[i]+= 2;
352+ h->c.block_index[i] += 2;
352353 for(i=4; i<6; i++)
353− s->block_index[i]+= 1;
354− s->mb_x++;
354+ h->c.block_index[i] += 1;
355+ h->c.mb_x++;
355356
356− av_assert2(s->pict_type == AV_PICTURE_TYPE_P);
357+ av_assert2(h->c.pict_type == AV_PICTURE_TYPE_P);
357358
358359 do{
359− if (get_bits1(&s->gb)) {
360+ if (get_bits1(&h->c.gb)) {
360361 /* skip mb */
361− mot_val = s->cur_pic.motion_val[0][s->block_index[0]];
362+ mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
362363 mot_val[0 ]= mot_val[2 ]=
363364 mot_val[0+stride]= mot_val[2+stride]= 0;
364365 mot_val[1 ]= mot_val[3 ]=
365366 mot_val[1+stride]= mot_val[3+stride]= 0;
366367
367− s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
368+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
368369 goto end;
369370 }
370− cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
371+ cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
371372 }while(cbpc == 20);
372373
373374 if(cbpc & 4){
374− s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
375+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
375376 }else{
376− get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
377+ get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
377378 if (cbpc & 8) {
378− if(s->modified_quant){
379− if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
380− else skip_bits(&s->gb, 5);
381− }else
382− skip_bits(&s->gb, 2);
379+ skip_bits(&h->c.gb, h->c.modified_quant ? (get_bits1(&h->c.gb) ? 1 : 5) : 2);
383380 }
384381
385382 if ((cbpc & 16) == 0) {
386− s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
383+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
387384 /* 16x16 motion prediction */
388− mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
389− if (s->umvplus)
390− mx = h263p_decode_umotion(s, pred_x);
385+ mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
386+ if (h->c.umvplus)
387+ mx = h263p_decode_umotion(h, pred_x);
391388 else
392− mx = ff_h263_decode_motion(s, pred_x, 1);
389+ mx = ff_h263_decode_motion(h, pred_x, 1);
393390
394− if (s->umvplus)
395− my = h263p_decode_umotion(s, pred_y);
391+ if (h->c.umvplus)
392+ my = h263p_decode_umotion(h, pred_y);
396393 else
397− my = ff_h263_decode_motion(s, pred_y, 1);
394+ my = ff_h263_decode_motion(h, pred_y, 1);
398395
399396 mot_val[0 ]= mot_val[2 ]=
400397 mot_val[0+stride]= mot_val[2+stride]= mx;
401398 mot_val[1 ]= mot_val[3 ]=
402399 mot_val[1+stride]= mot_val[3+stride]= my;
403400 } else {
404− s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
401+ h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
405402 for(i=0;i<4;i++) {
406− mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
407− if (s->umvplus)
408− mx = h263p_decode_umotion(s, pred_x);
403+ mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
404+ if (h->c.umvplus)
405+ mx = h263p_decode_umotion(h, pred_x);
409406 else
410− mx = ff_h263_decode_motion(s, pred_x, 1);
407+ mx = ff_h263_decode_motion(h, pred_x, 1);
411408
412− if (s->umvplus)
413− my = h263p_decode_umotion(s, pred_y);
409+ if (h->c.umvplus)
410+ my = h263p_decode_umotion(h, pred_y);
414411 else
415− my = ff_h263_decode_motion(s, pred_y, 1);
416− if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
417− skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
412+ my = ff_h263_decode_motion(h, pred_y, 1);
413+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
414+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
418415 mot_val[0] = mx;
419416 mot_val[1] = my;
420417 }
@@ -423,26 +420,27 @@ static void preview_obmc(MpegEncContext *s){ · 2 unmodified lines
423420 end:
424421
425422 for(i=0; i<4; i++)
426− s->block_index[i]-= 2;
423+ h->c.block_index[i] -= 2;
427424 for(i=4; i<6; i++)
428− s->block_index[i]-= 1;
429− s->mb_x--;
425+ h->c.block_index[i] -= 1;
426+ h->c.mb_x--;
430427
431− s->gb= gb;
428+ h->c.gb = gb;
432429 }
433430
434−static void h263_decode_dquant(MpegEncContext *s){
431+static void h263_decode_dquant(H263DecContext *const h)
432+{
435433 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
436434 int qscale;
437435
438− if(s->modified_quant){
439− if(get_bits1(&s->gb))
440− qscale = ff_modified_quant_tab[get_bits1(&s->gb)][s->qscale];
436+ if (h->c.modified_quant) {
437+ if (get_bits1(&h->c.gb))
438+ qscale = ff_modified_quant_tab[get_bits1(&h->c.gb)][h->c.qscale];
441439 else
442− qscale = get_bits(&s->gb, 5);
440+ qscale = get_bits(&h->c.gb, 5);
443441 }else
444− qscale = s->qscale + quant_tab[get_bits(&s->gb, 2)];
445− ff_set_qscale(s, qscale);
442+ qscale = h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)];
443+ ff_set_qscale(&h->c, qscale);
446444 }
447445
448446 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) · 74 unmodified lines
523521 ac_val[8 + i] = block[s->idsp.idct_permutation[i]];
524522 }
525523
526−static int h263_decode_block(MpegEncContext * s, int16_t * block,
524+static int h263_decode_block(H263DecContext *const h, int16_t block[64],
527525 int n, int coded)
528526 {
529527 int level, i, j, run;
530528 const RLTable *rl = &ff_h263_rl_inter;
531529 const uint8_t *scan_table;
532− GetBitContext gb= s->gb;
530+ GetBitContext gb = h->c.gb;
533531
534− scan_table = s->intra_scantable.permutated;
535− if (s->h263_aic && s->mb_intra) {
532+ scan_table = h->c.intra_scantable.permutated;
533+ if (h->c.h263_aic && h->c.mb_intra) {
536534 i = 0;
537535 if (!coded)
538536 goto not_coded;
539537 rl = &ff_rl_intra_aic;
540− if (s->ac_pred) {
541− if (s->h263_aic_dir)
542− scan_table = s->permutated_intra_v_scantable; /* left */
538+ if (h->c.ac_pred) {
539+ if (h->c.h263_aic_dir)
540+ scan_table = h->c.permutated_intra_v_scantable; /* left */
543541 else
544− scan_table = s->permutated_intra_h_scantable; /* top */
542+ scan_table = h->c.permutated_intra_h_scantable; /* top */
545543 }
546− } else if (s->mb_intra) {
544+ } else if (h->c.mb_intra) {
547545 /* DC coef */
548− if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) {
549− if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {
546+ if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) {
547+ if (h->c.rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) {
550548 int component = (n <= 3 ? 0 : n - 4 + 1);
551− level = s->last_dc[component];
552− if (s->rv10_first_dc_coded[component]) {
553− int diff = ff_rv_decode_dc(s, n);
549+ level = h->c.last_dc[component];
550+ if (h->c.rv10_first_dc_coded[component]) {
551+ int diff = ff_rv_decode_dc(h, n);
554552 if (diff < 0)
555553 return -1;
556554 level += diff;
557555 level = level & 0xff; /* handle wrap round */
558− s->last_dc[component] = level;
556+ h->c.last_dc[component] = level;
559557 } else {
560− s->rv10_first_dc_coded[component] = 1;
558+ h->c.rv10_first_dc_coded[component] = 1;
561559 }
562560 } else {
563− level = get_bits(&s->gb, 8);
561+ level = get_bits(&h->c.gb, 8);
564562 if (level == 255)
565563 level = 128;
566564 }
567565 }else{
568− level = get_bits(&s->gb, 8);
566+ level = get_bits(&h->c.gb, 8);
569567 if((level&0x7F) == 0){
570− av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
571− if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
568+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
569+ level, h->c.mb_x, h->c.mb_y);
570+ if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
572571 return -1;
573572 }
574573 if (level == 255)
@@ -580,64 +579,65 @@ static int h263_decode_block(MpegEncContext * s, int16_t * block, · 5 unmodified lines
580579 i = 0;
581580 }
582581 if (!coded) {
583− s->block_last_index[n] = i - 1;
582+ h->c.block_last_index[n] = i - 1;
584583 return 0;
585584 }
586585 retry:
587586 {
588− OPEN_READER(re, &s->gb);
587+ OPEN_READER(re, &h->c.gb);
589588 i--; // offset by -1 to allow direct indexing of scan_table
590589 for(;;) {
591− UPDATE_CACHE(re, &s->gb);
592− GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
590+ UPDATE_CACHE(re, &h->c.gb);
591+ GET_RL_VLC(level, run, re, &h->c.gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
593592 if (run == 66) {
594593 if (level){
595− CLOSE_READER(re, &s->gb);
596− av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
594+ CLOSE_READER(re, &h->c.gb);
595+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
596+ h->c.mb_x, h->c.mb_y);
597597 return -1;
598598 }
599599 /* escape */
600− if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
601− int is11 = SHOW_UBITS(re, &s->gb, 1);
602− SKIP_CACHE(re, &s->gb, 1);
603− run = SHOW_UBITS(re, &s->gb, 7) + 1;
600+ if (CONFIG_FLV_DECODER && h->c.h263_flv > 1) {
601+ int is11 = SHOW_UBITS(re, &h->c.gb, 1);
602+ SKIP_CACHE(re, &h->c.gb, 1);
603+ run = SHOW_UBITS(re, &h->c.gb, 7) + 1;
604604 if (is11) {
605− SKIP_COUNTER(re, &s->gb, 1 + 7);
606− UPDATE_CACHE(re, &s->gb);
607− level = SHOW_SBITS(re, &s->gb, 11);
608− SKIP_COUNTER(re, &s->gb, 11);
605+ SKIP_COUNTER(re, &h->c.gb, 1 + 7);
606+ UPDATE_CACHE(re, &h->c.gb);
607+ level = SHOW_SBITS(re, &h->c.gb, 11);
608+ SKIP_COUNTER(re, &h->c.gb, 11);
609609 } else {
610− SKIP_CACHE(re, &s->gb, 7);
611− level = SHOW_SBITS(re, &s->gb, 7);
612− SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);
610+ SKIP_CACHE(re, &h->c.gb, 7);
611+ level = SHOW_SBITS(re, &h->c.gb, 7);
612+ SKIP_COUNTER(re, &h->c.gb, 1 + 7 + 7);
613613 }
614614 } else {
615− run = SHOW_UBITS(re, &s->gb, 7) + 1;
616− SKIP_CACHE(re, &s->gb, 7);
617− level = (int8_t)SHOW_UBITS(re, &s->gb, 8);
618− SKIP_COUNTER(re, &s->gb, 7 + 8);
615+ run = SHOW_UBITS(re, &h->c.gb, 7) + 1;
616+ SKIP_CACHE(re, &h->c.gb, 7);
617+ level = (int8_t)SHOW_UBITS(re, &h->c.gb, 8);
618+ SKIP_COUNTER(re, &h->c.gb, 7 + 8);
619619 if(level == -128){
620− UPDATE_CACHE(re, &s->gb);
621− if (s->codec_id == AV_CODEC_ID_RV10) {
620+ UPDATE_CACHE(re, &h->c.gb);
621+ if (h->c.codec_id == AV_CODEC_ID_RV10) {
622622 /* XXX: should patch encoder too */
623− level = SHOW_SBITS(re, &s->gb, 12);
624− SKIP_COUNTER(re, &s->gb, 12);
623+ level = SHOW_SBITS(re, &h->c.gb, 12);
624+ SKIP_COUNTER(re, &h->c.gb, 12);
625625 }else{
626− level = SHOW_UBITS(re, &s->gb, 5);
627− SKIP_CACHE(re, &s->gb, 5);
628− level |= SHOW_SBITS(re, &s->gb, 6) * (1<<5);
629− SKIP_COUNTER(re, &s->gb, 5 + 6);
626+ level = SHOW_UBITS(re, &h->c.gb, 5);
627+ SKIP_CACHE(re, &h->c.gb, 5);
628+ level |= SHOW_SBITS(re, &h->c.gb, 6) * (1<<5);
629+ SKIP_COUNTER(re, &h->c.gb, 5 + 6);
630630 }
631631 }
632632 }
633633 } else {
634− if (SHOW_UBITS(re, &s->gb, 1))
634+ if (SHOW_UBITS(re, &h->c.gb, 1))
635635 level = -level;
636− SKIP_COUNTER(re, &s->gb, 1);
636+ SKIP_COUNTER(re, &h->c.gb, 1);
637637 }
638638 i += run;
639639 if (i >= 64){
640− CLOSE_READER(re, &s->gb);
640+ CLOSE_READER(re, &h->c.gb);
641641 // redo update without last flag, revert -1 offset
642642 i = i - run + ((run-1)&63) + 1;
643643 if (i < 64) {
@@ -645,48 +645,49 @@ retry: · 1 unmodified line
645645 block[scan_table[i]] = level;
646646 break;
647647 }
648− if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
648+ if(h->c.alt_inter_vlc && rl == &ff_h263_rl_inter && !h->c.mb_intra){
649649 //Looks like a hack but no, it's the way it is supposed to work ...
650650 rl = &ff_rl_intra_aic;
651651 i = 0;
652− s->gb= gb;
653− s->bdsp.clear_block(block);
652+ h->c.gb = gb;
653+ h->c.bdsp.clear_block(block);
654654 goto retry;
655655 }
656− av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
656+ av_log(h->c.avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n",
657+ h->c.mb_x, h->c.mb_y, h->c.mb_intra);
657658 return -1;
658659 }
659660 j = scan_table[i];
660661 block[j] = level;
661662 }
662663 }
663− if (s->mb_intra && s->h263_aic) {
664+ if (h->c.mb_intra && h->c.h263_aic) {
664665 not_coded:
665− h263_pred_acdc(s, block, n);
666+ h263_pred_acdc(&h->c, block, n);
666667 }
667− s->block_last_index[n] = i;
668+ h->c.block_last_index[n] = i;
668669 return 0;
669670 }
670671
671−static int h263_skip_b_part(MpegEncContext *s, int cbp)
672+static int h263_skip_b_part(H263DecContext *const h, int cbp)
672673 {
673674 LOCAL_ALIGNED_32(int16_t, dblock, [64]);
674675 int i, mbi;
675676 int bli[6];
676677
677− /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
678+ /* we have to set h->c.mb_intra to zero to decode B-part of PB-frame correctly
678679 * but real value should be restored in order to be used later (in OBMC condition)
679680 */
680− mbi = s->mb_intra;
681− memcpy(bli, s->block_last_index, sizeof(bli));
682− s->mb_intra = 0;
681+ mbi = h->c.mb_intra;
682+ memcpy(bli, h->c.block_last_index, sizeof(bli));
683+ h->c.mb_intra = 0;
683684 for (i = 0; i < 6; i++) {
684− if (h263_decode_block(s, dblock, i, cbp&32) < 0)
685+ if (h263_decode_block(h, dblock, i, cbp&32) < 0)
685686 return -1;
686687 cbp+=cbp;
687688 }
688− s->mb_intra = mbi;
689− memcpy(s->block_last_index, bli, sizeof(bli));
689+ h->c.mb_intra = mbi;
690+ memcpy(h->c.block_last_index, bli, sizeof(bli));
690691 return 0;
691692 }
692693
@@ -775,119 +776,121 @@ static int set_direct_mv(MpegEncContext *s) · 82 unmodified lines
775776 }
776777 }
777778
778−int ff_h263_decode_mb(MpegEncContext *s,
779− int16_t block[6][64])
779+int ff_h263_decode_mb(H263DecContext *const h, int16_t block[6][64])
780780 {
781781 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
782782 int16_t *mot_val;
783− const int xy= s->mb_x + s->mb_y * s->mb_stride;
783+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
784784 int cbpb = 0, pb_mv_count = 0;
785785
786− av_assert2(!s->h263_pred);
786+ av_assert2(!h->c.h263_pred);
787787
788− if (s->pict_type == AV_PICTURE_TYPE_P) {
788+ if (h->c.pict_type == AV_PICTURE_TYPE_P) {
789789 do{
790− if (get_bits1(&s->gb)) {
790+ if (get_bits1(&h->c.gb)) {
791791 /* skip mb */
792− s->mb_intra = 0;
792+ h->c.mb_intra = 0;
793793 for(i=0;i<6;i++)
794− s->block_last_index[i] = -1;
795− s->mv_dir = MV_DIR_FORWARD;
796− s->mv_type = MV_TYPE_16X16;
797− s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
798− s->mv[0][0][0] = 0;
799− s->mv[0][0][1] = 0;
800− s->mb_skipped = !(s->obmc | s->loop_filter);
794+ h->c.block_last_index[i] = -1;
795+ h->c.mv_dir = MV_DIR_FORWARD;
796+ h->c.mv_type = MV_TYPE_16X16;
797+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
798+ h->c.mv[0][0][0] = 0;
799+ h->c.mv[0][0][1] = 0;
800+ h->c.mb_skipped = !(h->c.obmc | h->c.loop_filter);
801801 goto end;
802802 }
803− cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
803+ cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
804804 if (cbpc < 0){
805− av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
805+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n",
806+ h->c.mb_x, h->c.mb_y);
806807 return SLICE_ERROR;
807808 }
808809 }while(cbpc == 20);
809810
810− s->bdsp.clear_blocks(s->block[0]);
811+ h->c.bdsp.clear_blocks(h->c.block[0]);
811812
812813 dquant = cbpc & 8;
813− s->mb_intra = ((cbpc & 4) != 0);
814− if (s->mb_intra) goto intra;
814+ h->c.mb_intra = ((cbpc & 4) != 0);
815+ if (h->c.mb_intra)
816+ goto intra;
815817
816− if(s->pb_frame && get_bits1(&s->gb))
817− pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
818− cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
818+ if(h->c.pb_frame && get_bits1(&h->c.gb))
819+ pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb);
820+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
819821
820822 if (cbpy < 0) {
821− av_log(s->avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
823+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n",
824+ h->c.mb_x, h->c.mb_y);
822825 return SLICE_ERROR;
823826 }
824827
825− if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
828+ if (!h->c.alt_inter_vlc|| (cbpc & 3)!=3)
826829 cbpy ^= 0xF;
827830
828831 cbp = (cbpc & 3) | (cbpy << 2);
829832 if (dquant) {
830− h263_decode_dquant(s);
833+ h263_decode_dquant(h);
831834 }
832835
833− s->mv_dir = MV_DIR_FORWARD;
836+ h->c.mv_dir = MV_DIR_FORWARD;
834837 if ((cbpc & 16) == 0) {
835− s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
838+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
836839 /* 16x16 motion prediction */
837− s->mv_type = MV_TYPE_16X16;
838− ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
839− if (s->umvplus)
840− mx = h263p_decode_umotion(s, pred_x);
840+ h->c.mv_type = MV_TYPE_16X16;
841+ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
842+ if (h->c.umvplus)
843+ mx = h263p_decode_umotion(h, pred_x);
841844 else
842− mx = ff_h263_decode_motion(s, pred_x, 1);
845+ mx = ff_h263_decode_motion(h, pred_x, 1);
843846
844847 if (mx >= 0xffff)
845848 return SLICE_ERROR;
846849
847− if (s->umvplus)
848− my = h263p_decode_umotion(s, pred_y);
850+ if (h->c.umvplus)
851+ my = h263p_decode_umotion(h, pred_y);
849852 else
850− my = ff_h263_decode_motion(s, pred_y, 1);
853+ my = ff_h263_decode_motion(h, pred_y, 1);
851854
852855 if (my >= 0xffff)
853856 return SLICE_ERROR;
854− s->mv[0][0][0] = mx;
855− s->mv[0][0][1] = my;
857+ h->c.mv[0][0][0] = mx;
858+ h->c.mv[0][0][1] = my;
856859
857− if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
858− skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
860+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
861+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
859862 } else {
860− s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
861− s->mv_type = MV_TYPE_8X8;
863+ h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
864+ h->c.mv_type = MV_TYPE_8X8;
862865 for(i=0;i<4;i++) {
863− mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
864− if (s->umvplus)
865− mx = h263p_decode_umotion(s, pred_x);
866+ mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
867+ if (h->c.umvplus)
868+ mx = h263p_decode_umotion(h, pred_x);
866869 else
867− mx = ff_h263_decode_motion(s, pred_x, 1);
870+ mx = ff_h263_decode_motion(h, pred_x, 1);
868871 if (mx >= 0xffff)
869872 return SLICE_ERROR;
870873
871− if (s->umvplus)
872− my = h263p_decode_umotion(s, pred_y);
874+ if (h->c.umvplus)
875+ my = h263p_decode_umotion(h, pred_y);
873876 else
874− my = ff_h263_decode_motion(s, pred_y, 1);
877+ my = ff_h263_decode_motion(h, pred_y, 1);
875878 if (my >= 0xffff)
876879 return SLICE_ERROR;
877− s->mv[0][i][0] = mx;
878− s->mv[0][i][1] = my;
879− if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
880− skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
880+ h->c.mv[0][i][0] = mx;
881+ h->c.mv[0][i][1] = my;
882+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
883+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
881884 mot_val[0] = mx;
882885 mot_val[1] = my;
883886 }
884887 }
885− } else if(s->pict_type==AV_PICTURE_TYPE_B) {
888+ } else if (h->c.pict_type==AV_PICTURE_TYPE_B) {
886889 int mb_type;
887− const int stride= s->b8_stride;
888− int16_t *mot_val0 = s->cur_pic.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
889− int16_t *mot_val1 = s->cur_pic.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
890−// const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
890+ const int stride = h->c.b8_stride;
891+ int16_t *mot_val0 = h->c.cur_pic.motion_val[0][2 * (h->c.mb_x + h->c.mb_y * stride)];
892+ int16_t *mot_val1 = h->c.cur_pic.motion_val[1][2 * (h->c.mb_x + h->c.mb_y * stride)];
893+// const int mv_xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride;
891894
892895 //FIXME ugly
893896 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, · 2 unmodified lines
896899 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
897900
898901 do{
899− mb_type = get_vlc2(&s->gb, h263_mbtype_b_vlc,
902+ mb_type = get_vlc2(&h->c.gb, h263_mbtype_b_vlc,
900903 H263_MBTYPE_B_VLC_BITS, 2);
901904 if (mb_type < 0){
902− av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
905+ av_log(h->c.avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n",
906+ h->c.mb_x, h->c.mb_y);
903907 return SLICE_ERROR;
904908 }
905909 }while(!mb_type);
906910
907− s->mb_intra = IS_INTRA(mb_type);
911+ h->c.mb_intra = IS_INTRA(mb_type);
908912 if(HAS_CBP(mb_type)){
909− s->bdsp.clear_blocks(s->block[0]);
910− cbpc = get_vlc2(&s->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
911− if(s->mb_intra){
913+ h->c.bdsp.clear_blocks(h->c.block[0]);
914+ cbpc = get_vlc2(&h->c.gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
915+ if (h->c.mb_intra) {
912916 dquant = IS_QUANT(mb_type);
913917 goto intra;
914918 }
915919
916− cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
920+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
917921
918922 if (cbpy < 0){
919− av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
923+ av_log(h->c.avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n",
924+ h->c.mb_x, h->c.mb_y);
920925 return SLICE_ERROR;
921926 }
922927
923− if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
928+ if (!h->c.alt_inter_vlc || (cbpc & 3)!=3)
924929 cbpy ^= 0xF;
925930
926931 cbp = (cbpc & 3) | (cbpy << 2);
927932 }else
928933 cbp=0;
929934
930− av_assert2(!s->mb_intra);
935+ av_assert2(!h->c.mb_intra);
931936
932937 if(IS_QUANT(mb_type)){
933− h263_decode_dquant(s);
938+ h263_decode_dquant(h);
934939 }
935940
936941 if(IS_DIRECT(mb_type)){
937− s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
938− mb_type |= set_direct_mv(s);
942+ h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
943+ mb_type |= set_direct_mv(&h->c);
939944 }else{
940− s->mv_dir = 0;
941− s->mv_type= MV_TYPE_16X16;
945+ h->c.mv_dir = 0;
946+ h->c.mv_type = MV_TYPE_16X16;
942947 //FIXME UMV
943948
944949 if (HAS_FORWARD_MV(mb_type)) {
945− int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
946− s->mv_dir = MV_DIR_FORWARD;
950+ int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
951+ h->c.mv_dir = MV_DIR_FORWARD;
947952
948− if (s->umvplus)
949− mx = h263p_decode_umotion(s, pred_x);
953+ if (h->c.umvplus)
954+ mx = h263p_decode_umotion(h, pred_x);
950955 else
951− mx = ff_h263_decode_motion(s, pred_x, 1);
956+ mx = ff_h263_decode_motion(h, pred_x, 1);
952957 if (mx >= 0xffff)
953958 return SLICE_ERROR;
954959
955− if (s->umvplus)
956− my = h263p_decode_umotion(s, pred_y);
960+ if (h->c.umvplus)
961+ my = h263p_decode_umotion(h, pred_y);
957962 else
958− my = ff_h263_decode_motion(s, pred_y, 1);
963+ my = ff_h263_decode_motion(h, pred_y, 1);
959964 if (my >= 0xffff)
960965 return SLICE_ERROR;
961966
962− if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
963− skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
967+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
968+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
964969
965− s->mv[0][0][0] = mx;
966− s->mv[0][0][1] = my;
970+ h->c.mv[0][0][0] = mx;
971+ h->c.mv[0][0][1] = my;
967972 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
968973 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
969974 }
970975
971976 if (HAS_BACKWARD_MV(mb_type)) {
972− int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &pred_x, &pred_y);
973− s->mv_dir |= MV_DIR_BACKWARD;
977+ int16_t *mot_val= ff_h263_pred_motion(&h->c, 0, 1, &pred_x, &pred_y);
978+ h->c.mv_dir |= MV_DIR_BACKWARD;
974979
975− if (s->umvplus)
976− mx = h263p_decode_umotion(s, pred_x);
980+ if (h->c.umvplus)
981+ mx = h263p_decode_umotion(h, pred_x);
977982 else
978− mx = ff_h263_decode_motion(s, pred_x, 1);
983+ mx = ff_h263_decode_motion(h, pred_x, 1);
979984 if (mx >= 0xffff)
980985 return SLICE_ERROR;
981986
982− if (s->umvplus)
983− my = h263p_decode_umotion(s, pred_y);
987+ if (h->c.umvplus)
988+ my = h263p_decode_umotion(h, pred_y);
984989 else
985− my = ff_h263_decode_motion(s, pred_y, 1);
990+ my = ff_h263_decode_motion(h, pred_y, 1);
986991 if (my >= 0xffff)
987992 return SLICE_ERROR;
988993
989− if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
990− skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
994+ if (h->c.umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
995+ skip_bits1(&h->c.gb); /* Bit stuffing to prevent PSC */
991996
992− s->mv[1][0][0] = mx;
993− s->mv[1][0][1] = my;
997+ h->c.mv[1][0][0] = mx;
998+ h->c.mv[1][0][1] = my;
994999 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
9951000 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
9961001 }
9971002 }
9981003
999− s->cur_pic.mb_type[xy] = mb_type;
1004+ h->c.cur_pic.mb_type[xy] = mb_type;
10001005 } else { /* I-Frame */
10011006 do{
1002− cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
1007+ cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
10031008 if (cbpc < 0){
1004− av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
1009+ av_log(h->c.avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n",
1010+ h->c.mb_x, h->c.mb_y);
10051011 return SLICE_ERROR;
10061012 }
10071013 }while(cbpc == 8);
10081014
1009− s->bdsp.clear_blocks(s->block[0]);
1015+ h->c.bdsp.clear_blocks(h->c.block[0]);
10101016
10111017 dquant = cbpc & 4;
1012− s->mb_intra = 1;
1018+ h->c.mb_intra = 1;
10131019 intra:
1014− s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1015− if (s->h263_aic) {
1016− s->ac_pred = get_bits1(&s->gb);
1017− if(s->ac_pred){
1018− s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
1020+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1021+ if (h->c.h263_aic) {
1022+ h->c.ac_pred = get_bits1(&h->c.gb);
1023+ if (h->c.ac_pred) {
1024+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
10191025
1020− s->h263_aic_dir = get_bits1(&s->gb);
1026+ h->c.h263_aic_dir = get_bits1(&h->c.gb);
10211027 }
10221028 }else
1023− s->ac_pred = 0;
1029+ h->c.ac_pred = 0;
10241030
1025− if(s->pb_frame && get_bits1(&s->gb))
1026− pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
1027− cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1031+ if (h->c.pb_frame && get_bits1(&h->c.gb))
1032+ pb_mv_count = h263_get_modb(&h->c.gb, h->c.pb_frame, &cbpb);
1033+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
10281034 if(cbpy<0){
1029− av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
1035+ av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",
1036+ h->c.mb_x, h->c.mb_y);
10301037 return SLICE_ERROR;
10311038 }
10321039 cbp = (cbpc & 3) | (cbpy << 2);
10331040 if (dquant) {
1034− h263_decode_dquant(s);
1041+ h263_decode_dquant(h);
10351042 }
10361043
1037− pb_mv_count += !!s->pb_frame;
1044+ pb_mv_count += !!h->c.pb_frame;
10381045 }
10391046
10401047 while(pb_mv_count--){
1041− ff_h263_decode_motion(s, 0, 1);
1042− ff_h263_decode_motion(s, 0, 1);
1048+ ff_h263_decode_motion(h, 0, 1);
1049+ ff_h263_decode_motion(h, 0, 1);
10431050 }
10441051
10451052 /* decode each block */
10461053 for (i = 0; i < 6; i++) {
1047− if (h263_decode_block(s, block[i], i, cbp&32) < 0)
1054+ if (h263_decode_block(h, block[i], i, cbp&32) < 0)
10481055 return -1;
10491056 cbp+=cbp;
10501057 }
10511058
1052− if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0)
1059+ if (h->c.pb_frame && h263_skip_b_part(h, cbpb) < 0)
10531060 return -1;
1054− if(s->obmc && !s->mb_intra){
1055− if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
1056− preview_obmc(s);
1061+ if (h->c.obmc && !h->c.mb_intra) {
1062+ if (h->c.pict_type == AV_PICTURE_TYPE_P &&
1063+ h->c.mb_x + 1 < h->c.mb_width && h->c.mb_num_left != 1)
1064+ preview_obmc(h);
10571065 }
10581066 end:
10591067
1060− if (get_bits_left(&s->gb) < 0)
1068+ if (get_bits_left(&h->c.gb) < 0)
10611069 return AVERROR_INVALIDDATA;
10621070
10631071 /* per-MB end of slice check */
10641072 {
1065− int v= show_bits(&s->gb, 16);
1073+ int v = show_bits(&h->c.gb, 16);
10661074
1067− if (get_bits_left(&s->gb) < 16) {
1068− v >>= 16 - get_bits_left(&s->gb);
1075+ if (get_bits_left(&h->c.gb) < 16) {
1076+ v >>= 16 - get_bits_left(&h->c.gb);
10691077 }
10701078
10711079 if(v==0)
@@ -1076,51 +1084,50 @@ end: · 4 unmodified lines
10761084 }
10771085
10781086 /* Most is hardcoded; should extend to handle all H.263 streams. */
1079−int ff_h263_decode_picture_header(MpegEncContext *s)
1087+int ff_h263_decode_picture_header(H263DecContext *const h)
10801088 {
1081− int format, width, height, i, ret;
1082− uint32_t startcode;
1089+ int width, height, i, ret;
10831090 int h263_plus;
10841091
1085− align_get_bits(&s->gb);
1092+ align_get_bits(&h->c.gb);
10861093
1087− if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_num == 0) {
1088− av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
1094+ if (show_bits(&h->c.gb, 2) == 2 && h->c.avctx->frame_num == 0) {
1095+ av_log(h->c.avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
10891096 }
10901097
1091− startcode= get_bits(&s->gb, 22-8);
1098+ uint32_t startcode = get_bits(&h->c.gb, 22-8);
10921099
1093− for(i= get_bits_left(&s->gb); i>24; i-=8) {
1094− startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
1100+ for (i = get_bits_left(&h->c.gb); i>24; i -= 8) {
1101+ startcode = ((startcode << 8) | get_bits(&h->c.gb, 8)) & 0x003FFFFF;
10951102
10961103 if(startcode == 0x20)
10971104 break;
10981105 }
10991106
11001107 if (startcode != 0x20) {
1101− av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
1108+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
11021109 return -1;
11031110 }
11041111 /* temporal reference */
1105− i = get_bits(&s->gb, 8); /* picture timestamp */
1112+ i = get_bits(&h->c.gb, 8); /* picture timestamp */
11061113
1107− i -= (i - (s->picture_number & 0xFF) + 128) & ~0xFF;
1114+ i -= (i - (h->c.picture_number & 0xFF) + 128) & ~0xFF;
11081115
1109− s->picture_number= (s->picture_number&~0xFF) + i;
1116+ h->c.picture_number = (h->c.picture_number&~0xFF) + i;
11101117
11111118 /* PTYPE starts here */
1112− if (check_marker(s->avctx, &s->gb, "in PTYPE") != 1) {
1119+ if (check_marker(h->c.avctx, &h->c.gb, "in PTYPE") != 1) {
11131120 return -1;
11141121 }
1115− if (get_bits1(&s->gb) != 0) {
1116− av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
1122+ if (get_bits1(&h->c.gb) != 0) {
1123+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
11171124 return -1; /* H.263 id */
11181125 }
1119− skip_bits1(&s->gb); /* split screen off */
1120− skip_bits1(&s->gb); /* camera off */
1121− skip_bits1(&s->gb); /* freeze picture release off */
1126+ skip_bits1(&h->c.gb); /* split screen off */
1127+ skip_bits1(&h->c.gb); /* camera off */
1128+ skip_bits1(&h->c.gb); /* freeze picture release off */
11221129
1123− format = get_bits(&s->gb, 3);
1130+ int format = get_bits(&h->c.gb, 3);
11241131 /*
11251132 0 forbidden
11261133 1 sub-QCIF
@@ -1136,88 +1143,88 @@ int ff_h263_decode_picture_header(MpegEncContext *s) · 9 unmodified lines
11361143 if (!width)
11371144 return -1;
11381145
1139− s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
1146+ h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->c.gb);
11401147
1141− s->h263_long_vectors = get_bits1(&s->gb);
1148+ h->c.h263_long_vectors = get_bits1(&h->c.gb);
11421149
1143− if (get_bits1(&s->gb) != 0) {
1144− av_log(s->avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
1150+ if (get_bits1(&h->c.gb) != 0) {
1151+ av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
11451152 return -1; /* SAC: off */
11461153 }
1147− s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
1154+ h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */
11481155
1149− s->pb_frame = get_bits1(&s->gb);
1150− s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
1151− skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
1156+ h->c.pb_frame = get_bits1(&h->c.gb);
1157+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
1158+ skip_bits1(&h->c.gb); /* Continuous Presence Multipoint mode: off */
11521159
1153− s->width = width;
1154− s->height = height;
1155− s->avctx->sample_aspect_ratio= (AVRational){12,11};
1156− s->avctx->framerate = (AVRational){ 30000, 1001 };
1160+ h->c.width = width;
1161+ h->c.height = height;
1162+ h->c.avctx->sample_aspect_ratio= (AVRational){12,11};
1163+ h->c.avctx->framerate = (AVRational){ 30000, 1001 };
11571164 } else {
11581165 int ufep;
11591166
11601167 /* H.263v2 */
11611168 h263_plus = 1;
1162− ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
1169+ ufep = get_bits(&h->c.gb, 3); /* Update Full Extended PTYPE */
11631170
11641171 /* ufep other than 0 and 1 are reserved */
11651172 if (ufep == 1) {
11661173 /* OPPTYPE */
1167− format = get_bits(&s->gb, 3);
1168− ff_dlog(s->avctx, "ufep=1, format: %d\n", format);
1169− s->custom_pcf= get_bits1(&s->gb);
1170− s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
1171− if (get_bits1(&s->gb) != 0) {
1172− av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
1174+ format = get_bits(&h->c.gb, 3);
1175+ ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);
1176+ h->c.custom_pcf = get_bits1(&h->c.gb);
1177+ h->c.umvplus = get_bits1(&h->c.gb); /* Unrestricted Motion Vector */
1178+ if (get_bits1(&h->c.gb) != 0) {
1179+ av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
11731180 }
1174− s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
1175− s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
1176− s->loop_filter= get_bits1(&s->gb);
1177− if(s->avctx->lowres)
1178− s->loop_filter = 0;
1179−
1180− s->h263_slice_structured= get_bits1(&s->gb);
1181− if (get_bits1(&s->gb) != 0) {
1182− av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
1181+ h->c.obmc = get_bits1(&h->c.gb); /* Advanced prediction mode */
1182+ h->c.h263_aic = get_bits1(&h->c.gb); /* Advanced Intra Coding (AIC) */
1183+ h->c.loop_filter = get_bits1(&h->c.gb);
1184+ if (h->c.avctx->lowres)
1185+ h->c.loop_filter = 0;
1186+
1187+ h->c.h263_slice_structured= get_bits1(&h->c.gb);
1188+ if (get_bits1(&h->c.gb) != 0) {
1189+ av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
11831190 }
1184− if (get_bits1(&s->gb) != 0) {
1185− av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
1191+ if (get_bits1(&h->c.gb) != 0) {
1192+ av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
11861193 }
1187− s->alt_inter_vlc= get_bits1(&s->gb);
1188− s->modified_quant= get_bits1(&s->gb);
1189− if(s->modified_quant)
1190− s->chroma_qscale_table= ff_h263_chroma_qscale_table;
1194+ h->c.alt_inter_vlc = get_bits1(&h->c.gb);
1195+ h->c.modified_quant = get_bits1(&h->c.gb);
1196+ if (h->c.modified_quant)
1197+ h->c.chroma_qscale_table= ff_h263_chroma_qscale_table;
11911198
1192− skip_bits(&s->gb, 1); /* Prevent start code emulation */
1199+ skip_bits(&h->c.gb, 1); /* Prevent start code emulation */
11931200
1194− skip_bits(&s->gb, 3); /* Reserved */
1201+ skip_bits(&h->c.gb, 3); /* Reserved */
11951202 } else if (ufep != 0) {
1196− av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
1203+ av_log(h->c.avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
11971204 return -1;
11981205 }
11991206
12001207 /* MPPTYPE */
1201− s->pict_type = get_bits(&s->gb, 3);
1202− switch(s->pict_type){
1203− case 0: s->pict_type= AV_PICTURE_TYPE_I;break;
1204− case 1: s->pict_type= AV_PICTURE_TYPE_P;break;
1205− case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;
1206− case 3: s->pict_type= AV_PICTURE_TYPE_B;break;
1207− case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO
1208+ h->c.pict_type = get_bits(&h->c.gb, 3);
1209+ switch (h->c.pict_type) {
1210+ case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break;
1211+ case 1: h->c.pict_type = AV_PICTURE_TYPE_P; break;
1212+ case 2: h->c.pict_type = AV_PICTURE_TYPE_P; h->c.pb_frame = 3; break;
1213+ case 3: h->c.pict_type = AV_PICTURE_TYPE_B; break;
1214+ case 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO
12081215 default:
12091216 return -1;
12101217 }
1211− skip_bits(&s->gb, 2);
1212− s->no_rounding = get_bits1(&s->gb);
1213− skip_bits(&s->gb, 4);
1218+ skip_bits(&h->c.gb, 2);
1219+ h->c.no_rounding = get_bits1(&h->c.gb);
1220+ skip_bits(&h->c.gb, 4);
12141221
12151222 /* Get the picture dimensions */
12161223 if (ufep) {
12171224 if (format == 6) {
12181225 /* Custom Picture Format (CPFMT) */
1219− int aspect_ratio_info = get_bits(&s->gb, 4);
1220− ff_dlog(s->avctx, "aspect: %d\n", aspect_ratio_info);
1226+ int aspect_ratio_info = get_bits(&h->c.gb, 4);
1227+ ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info);
12211228 /* aspect ratios:
12221229 0 - forbidden
12231230 1 - 1:1
@@ -1227,153 +1234,151 @@ int ff_h263_decode_picture_header(MpegEncContext *s) · 3 unmodified lines
12271234 5 - 40:33 (525-type 16:9)
12281235 6-14 - reserved
12291236 */
1230− width = (get_bits(&s->gb, 9) + 1) * 4;
1231− check_marker(s->avctx, &s->gb, "in dimensions");
1232− height = get_bits(&s->gb, 9) * 4;
1233− ff_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
1237+ width = (get_bits(&h->c.gb, 9) + 1) * 4;
1238+ check_marker(h->c.avctx, &h->c.gb, "in dimensions");
1239+ height = get_bits(&h->c.gb, 9) * 4;
1240+ ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
12341241 if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
12351242 /* expected dimensions */
1236− s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
1237− s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);
1243+ h->c.avctx->sample_aspect_ratio.num = get_bits(&h->c.gb, 8);
1244+ h->c.avctx->sample_aspect_ratio.den = get_bits(&h->c.gb, 8);
12381245 }else{
1239− s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
1246+ h->c.avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
12401247 }
12411248 } else {
12421249 width = ff_h263_format[format][0];
12431250 height = ff_h263_format[format][1];
1244− s->avctx->sample_aspect_ratio= (AVRational){12,11};
1251+ h->c.avctx->sample_aspect_ratio = (AVRational){12,11};
12451252 }
1246− s->avctx->sample_aspect_ratio.den <<= s->ehc_mode;
1253+ h->c.avctx->sample_aspect_ratio.den <<= h->c.ehc_mode;
12471254 if ((width == 0) || (height == 0))
12481255 return -1;
1249− s->width = width;
1250− s->height = height;
1251−
1252− if(s->custom_pcf){
1253− int gcd;
1254− s->avctx->framerate.num = 1800000;
1255− s->avctx->framerate.den = 1000 + get_bits1(&s->gb);
1256− s->avctx->framerate.den *= get_bits(&s->gb, 7);
1257− if(s->avctx->framerate.den == 0){
1258− av_log(s->avctx, AV_LOG_ERROR, "zero framerate\n");
1256+ h->c.width = width;
1257+ h->c.height = height;
1258+
1259+ if (h->c.custom_pcf) {
1260+ h->c.avctx->framerate.num = 1800000;
1261+ h->c.avctx->framerate.den = 1000 + get_bits1(&h->c.gb);
1262+ h->c.avctx->framerate.den *= get_bits(&h->c.gb, 7);
1263+ if (h->c.avctx->framerate.den == 0) {
1264+ av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n");
12591265 return -1;
12601266 }
1261− gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num);
1262− s->avctx->framerate.den /= gcd;
1263− s->avctx->framerate.num /= gcd;
1267+ int gcd = av_gcd(h->c.avctx->framerate.den, h->c.avctx->framerate.num);
1268+ h->c.avctx->framerate.den /= gcd;
1269+ h->c.avctx->framerate.num /= gcd;
12641270 }else{
1265− s->avctx->framerate = (AVRational){ 30000, 1001 };
1271+ h->c.avctx->framerate = (AVRational){ 30000, 1001 };
12661272 }
12671273 }
12681274
1269− if(s->custom_pcf){
1270− skip_bits(&s->gb, 2); //extended Temporal reference
1271− }
1275+ if (h->c.custom_pcf)
1276+ skip_bits(&h->c.gb, 2); //extended Temporal reference
12721277
12731278 if (ufep) {
1274− if (s->umvplus) {
1275− if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1276− skip_bits1(&s->gb);
1279+ if (h->c.umvplus) {
1280+ if(get_bits1(&h->c.gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1281+ skip_bits1(&h->c.gb);
12771282 }
1278− if(s->h263_slice_structured){
1279− if (get_bits1(&s->gb) != 0) {
1280− av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
1283+ if (h->c.h263_slice_structured) {
1284+ if (get_bits1(&h->c.gb) != 0) {
1285+ av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
12811286 }
1282− if (get_bits1(&s->gb) != 0) {
1283− av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
1287+ if (get_bits1(&h->c.gb) != 0) {
1288+ av_log(h->c.avctx, AV_LOG_ERROR, "unordered slices not supported\n");
12841289 }
12851290 }
1286− if (s->pict_type == AV_PICTURE_TYPE_B) {
1287− skip_bits(&s->gb, 4); //ELNUM
1291+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
1292+ skip_bits(&h->c.gb, 4); //ELNUM
12881293 if (ufep == 1) {
1289− skip_bits(&s->gb, 4); // RLNUM
1294+ skip_bits(&h->c.gb, 4); // RLNUM
12901295 }
12911296 }
12921297 }
12931298
1294− s->qscale = get_bits(&s->gb, 5);
1299+ h->c.qscale = get_bits(&h->c.gb, 5);
12951300 }
12961301
1297− ret = av_image_check_size(s->width, s->height, 0, s->avctx);
1302+ ret = av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx);
12981303 if (ret < 0)
12991304 return ret;
13001305
1301− if (!(s->avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
1302− if ((s->width * s->height / 256 / 8) > get_bits_left(&s->gb))
1306+ if (!(h->c.avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
1307+ if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->c.gb))
13031308 return AVERROR_INVALIDDATA;
13041309 }
13051310
1306− s->mb_width = (s->width + 15) / 16;
1307− s->mb_height = (s->height + 15) / 16;
1308− s->mb_num = s->mb_width * s->mb_height;
1311+ h->c.mb_width = (h->c.width + 15U) / 16;
1312+ h->c.mb_height = (h->c.height + 15U) / 16;
1313+ h->c.mb_num = h->c.mb_width * h->c.mb_height;
13091314
1310− s->gob_index = H263_GOB_HEIGHT(s->height);
1315+ h->c.gob_index = H263_GOB_HEIGHT(h->c.height);
13111316
1312− if (s->pb_frame) {
1313− skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
1314− if (s->custom_pcf)
1315− skip_bits(&s->gb, 2); //extended Temporal reference
1316− skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
1317+ if (h->c.pb_frame) {
1318+ skip_bits(&h->c.gb, 3); /* Temporal reference for B-pictures */
1319+ if (h->c.custom_pcf)
1320+ skip_bits(&h->c.gb, 2); //extended Temporal reference
1321+ skip_bits(&h->c.gb, 2); /* Quantization information for B-pictures */
13171322 }
13181323
1319− if (s->pict_type!=AV_PICTURE_TYPE_B) {
1320− s->time = s->picture_number;
1321− s->pp_time = s->time - s->last_non_b_time;
1322− s->last_non_b_time = s->time;
1324+ if (h->c.pict_type!=AV_PICTURE_TYPE_B) {
1325+ h->c.time = h->c.picture_number;
1326+ h->c.pp_time = h->c.time - h->c.last_non_b_time;
1327+ h->c.last_non_b_time = h->c.time;
13231328 }else{
1324− s->time = s->picture_number;
1325− s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
1326− if (s->pp_time <=s->pb_time ||
1327− s->pp_time <= s->pp_time - s->pb_time ||
1328− s->pp_time <= 0){
1329− s->pp_time = 2;
1330− s->pb_time = 1;
1329+ h->c.time = h->c.picture_number;
1330+ h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
1331+ if (h->c.pp_time <= h->c.pb_time ||
1332+ h->c.pp_time <= h->c.pp_time - h->c.pb_time ||
1333+ h->c.pp_time <= 0) {
1334+ h->c.pp_time = 2;
1335+ h->c.pb_time = 1;
13311336 }
1332− ff_mpeg4_init_direct_mv(s);
1337+ ff_mpeg4_init_direct_mv(&h->c);
13331338 }
13341339
13351340 /* PEI */
1336− if (skip_1stop_8data_bits(&s->gb) < 0)
1341+ if (skip_1stop_8data_bits(&h->c.gb) < 0)
13371342 return AVERROR_INVALIDDATA;
13381343
1339− if(s->h263_slice_structured){
1340− if (check_marker(s->avctx, &s->gb, "SEPB1") != 1) {
1344+ if (h->c.h263_slice_structured) {
1345+ if (check_marker(h->c.avctx, &h->c.gb, "SEPB1") != 1) {
13411346 return -1;
13421347 }
13431348
1344− ff_h263_decode_mba(s);
1349+ ff_h263_decode_mba(h);
13451350
1346− if (check_marker(s->avctx, &s->gb, "SEPB2") != 1) {
1351+ if (check_marker(h->c.avctx, &h->c.gb, "SEPB2") != 1) {
13471352 return -1;
13481353 }
13491354 }
13501355
1351− if (s->pict_type == AV_PICTURE_TYPE_B)
1352− s->low_delay = 0;
1356+ if (h->c.pict_type == AV_PICTURE_TYPE_B)
1357+ h->c.low_delay = 0;
13531358
1354− if(s->h263_aic){
1355− s->y_dc_scale_table=
1356− s->c_dc_scale_table= ff_aic_dc_scale_table;
1359+ if (h->c.h263_aic) {
1360+ h->c.y_dc_scale_table =
1361+ h->c.c_dc_scale_table = ff_aic_dc_scale_table;
13571362 }else{
1358− s->y_dc_scale_table=
1359− s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
1363+ h->c.y_dc_scale_table =
1364+ h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table;
13601365 }
13611366
1362− ff_h263_show_pict_info(s, h263_plus);
1367+ ff_h263_show_pict_info(h, h263_plus);
13631368
1364− if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){
1369+ 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){
13651370 int i,j;
1366− for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1367− av_log(s->avctx, AV_LOG_DEBUG, "\n");
1371+ for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb));
1372+ av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
13681373 for(i=0; i<13; i++){
13691374 for(j=0; j<3; j++){
1370− int v= get_bits(&s->gb, 8);
1371− v |= get_sbits(&s->gb, 8) * (1 << 8);
1372− av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
1375+ int v= get_bits(&h->c.gb, 8);
1376+ v |= get_sbits(&h->c.gb, 8) * (1 << 8);
1377+ av_log(h->c.avctx, AV_LOG_DEBUG, " %5d", v);
13731378 }
1374− av_log(s->avctx, AV_LOG_DEBUG, "\n");
1379+ av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
13751380 }
1376− for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1381+ for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->c.gb));
13771382 }
13781383
13791384 return 0;
libavcodec/mpeg4video_parser.c+2−2
@@ -84,7 +84,7 @@ static int mpeg4_decode_header(AVCodecParserContext *s1, AVCodecContext *avctx, · 83 unmodified lines
8484 {
8585 struct Mp4vParseContext *pc = s1->priv_data;
8686 Mpeg4DecContext *dec_ctx = &pc->dec_ctx;
87− MpegEncContext *s = &dec_ctx->m;
87+ MPVContext *const s = &dec_ctx->h.c;
8888 GetBitContext gb1, *gb = &gb1;
8989 int ret;
9090
@@ -124,7 +124,7 @@ static av_cold int mpeg4video_parse_init(AVCodecParserContext *s) · 33 unmodified lines
124124
125125 pc->first_picture = 1;
126126 pc->dec_ctx.quant_precision = 5;
127− pc->dec_ctx.m.slice_context_count = 1;
127+ pc->dec_ctx.h.c.slice_context_count = 1;
128128 pc->dec_ctx.showed_packed_warning = 1;
129129 return 0;
130130 }
libavcodec/mpeg4videodec.c+854−849
@@ -81,6 +81,12 @@ static const int16_t mb_type_b_map[4] = { · 80 unmodified lines
8181 MB_TYPE_FORWARD_MV | MB_TYPE_16x16,
8282 };
8383
84+static inline Mpeg4DecContext *h263_to_mpeg4(H263DecContext *h)
85+{
86+ av_assert2(h->c.codec_id == AV_CODEC_ID_MPEG4 && h->c.avctx->priv_data == h);
87+ return (Mpeg4DecContext*)h;
88+}
89+
8490 static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
8591 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
8692 uint8_t *const *ref_picture)
@@ -319,55 +325,55 @@ void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb · 232 unmodified lines
319325 * @param n block index (0-3 are luma, 4-5 are chroma)
320326 * @param dir the ac prediction direction
321327 */
322−void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir)
328+void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, int dir)
323329 {
324330 int i;
325331 int16_t *ac_val, *ac_val1;
326− int8_t *const qscale_table = s->cur_pic.qscale_table;
332+ int8_t *const qscale_table = h->c.cur_pic.qscale_table;
327333
328334 /* find prediction */
329− ac_val = &s->ac_val[0][0] + s->block_index[n] * 16;
335+ ac_val = &h->c.ac_val[0][0] + h->c.block_index[n] * 16;
330336 ac_val1 = ac_val;
331− if (s->ac_pred) {
337+ if (h->c.ac_pred) {
332338 if (dir == 0) {
333− const int xy = s->mb_x - 1 + s->mb_y * s->mb_stride;
339+ const int xy = h->c.mb_x - 1 + h->c.mb_y * h->c.mb_stride;
334340 /* left prediction */
335341 ac_val -= 16;
336342
337− if (s->mb_x == 0 || s->qscale == qscale_table[xy] ||
343+ if (h->c.mb_x == 0 || h->c.qscale == qscale_table[xy] ||
338344 n == 1 || n == 3) {
339345 /* same qscale */
340346 for (i = 1; i < 8; i++)
341− block[s->idsp.idct_permutation[i << 3]] += ac_val[i];
347+ block[h->c.idsp.idct_permutation[i << 3]] += ac_val[i];
342348 } else {
343349 /* different qscale, we must rescale */
344350 for (i = 1; i < 8; i++)
345− block[s->idsp.idct_permutation[i << 3]] += ROUNDED_DIV(ac_val[i] * qscale_table[xy], s->qscale);
351+ block[h->c.idsp.idct_permutation[i << 3]] += ROUNDED_DIV(ac_val[i] * qscale_table[xy], h->c.qscale);
346352 }
347353 } else {
348− const int xy = s->mb_x + s->mb_y * s->mb_stride - s->mb_stride;
354+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride - h->c.mb_stride;
349355 /* top prediction */
350− ac_val -= 16 * s->block_wrap[n];
356+ ac_val -= 16 * h->c.block_wrap[n];
351357
352− if (s->mb_y == 0 || s->qscale == qscale_table[xy] ||
358+ if (h->c.mb_y == 0 || h->c.qscale == qscale_table[xy] ||
353359 n == 2 || n == 3) {
354360 /* same qscale */
355361 for (i = 1; i < 8; i++)
356− block[s->idsp.idct_permutation[i]] += ac_val[i + 8];
362+ block[h->c.idsp.idct_permutation[i]] += ac_val[i + 8];
357363 } else {
358364 /* different qscale, we must rescale */
359365 for (i = 1; i < 8; i++)
360− block[s->idsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], s->qscale);
366+ block[h->c.idsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], h->c.qscale);
361367 }
362368 }
363369 }
364370 /* left copy */
365371 for (i = 1; i < 8; i++)
366− ac_val1[i] = block[s->idsp.idct_permutation[i << 3]];
372+ ac_val1[i] = block[h->c.idsp.idct_permutation[i << 3]];
367373
368374 /* top copy */
369375 for (i = 1; i < 8; i++)
370− ac_val1[8 + i] = block[s->idsp.idct_permutation[i]];
376+ ac_val1[8 + i] = block[h->c.idsp.idct_permutation[i]];
371377 }
372378
373379 /**
@@ -376,28 +382,28 @@ void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n, int dir) · 2 unmodified lines
376382 */
377383 static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
378384 {
379− MpegEncContext *s = &ctx->m;
380− int bits_count = get_bits_count(&s->gb);
381− int v = show_bits(&s->gb, 16);
385+ H263DecContext *const h = &ctx->h;
386+ int bits_count = get_bits_count(&h->c.gb);
387+ int v = show_bits(&h->c.gb, 16);
382388
383− if (s->workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)
389+ if (h->c.workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)
384390 return 0;
385391
386392 while (v <= 0xFF) {
387− if (s->pict_type == AV_PICTURE_TYPE_B ||
388− (v >> (8 - s->pict_type) != 1) || s->partitioned_frame)
393+ if (h->c.pict_type == AV_PICTURE_TYPE_B ||
394+ (v >> (8 - h->c.pict_type) != 1) || h->c.partitioned_frame)
389395 break;
390− skip_bits(&s->gb, 8 + s->pict_type);
391− bits_count += 8 + s->pict_type;
392− v = show_bits(&s->gb, 16);
396+ skip_bits(&h->c.gb, 8 + h->c.pict_type);
397+ bits_count += 8 + h->c.pict_type;
398+ v = show_bits(&h->c.gb, 16);
393399 }
394400
395− if (bits_count + 8 >= s->gb.size_in_bits) {
401+ if (bits_count + 8 >= h->c.gb.size_in_bits) {
396402 v >>= 8;
397403 v |= 0x7F >> (7 - (bits_count & 7));
398404
399405 if (v == 0x7F)
400− return s->mb_num;
406+ return h->c.mb_num;
401407 } else {
402408 static const uint16_t mpeg4_resync_prefix[8] = {
403409 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000
@@ -405,23 +411,23 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) · 1 unmodified line
405411
406412 if (v == mpeg4_resync_prefix[bits_count & 7]) {
407413 int len, mb_num;
408− int mb_num_bits = av_log2(s->mb_num - 1) + 1;
409− GetBitContext gb = s->gb;
414+ int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;
415+ GetBitContext gb = h->c.gb;
410416
411− skip_bits(&s->gb, 1);
412− align_get_bits(&s->gb);
417+ skip_bits(&h->c.gb, 1);
418+ align_get_bits(&h->c.gb);
413419
414420 for (len = 0; len < 32; len++)
415− if (get_bits1(&s->gb))
421+ if (get_bits1(&h->c.gb))
416422 break;
417423
418− mb_num = get_bits(&s->gb, mb_num_bits);
419− if (!mb_num || mb_num > s->mb_num || get_bits_count(&s->gb)+6 > s->gb.size_in_bits)
424+ mb_num = get_bits(&h->c.gb, mb_num_bits);
425+ if (!mb_num || mb_num > h->c.mb_num || get_bits_count(&h->c.gb) + 6 > h->c.gb.size_in_bits)
420426 mb_num= -1;
421427
422− s->gb = gb;
428+ h->c.gb = gb;
423429
424− if (len >= ff_mpeg4_get_video_packet_prefix_length(s->pict_type, ctx->f_code, ctx->b_code))
430+ if (len >= ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code))
425431 return mb_num;
426432 }
427433 }
@@ -430,7 +436,7 @@ static inline int mpeg4_is_resync(Mpeg4DecContext *ctx) · 2 unmodified lines
430436
431437 static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb)
432438 {
433− MpegEncContext *s = &ctx->m;
439+ MpegEncContext *s = &ctx->h.c;
434440 int a = 2 << ctx->sprite_warping_accuracy;
435441 int rho = 3 - ctx->sprite_warping_accuracy;
436442 int r = 16 / a;
@@ -685,13 +691,12 @@ overflow: · 248 unmodified lines
685691 }
686692
687693 static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) {
688− MpegEncContext *s = &ctx->m;
689694 int len = FFMIN(ctx->time_increment_bits + 3, 15);
690695
691696 get_bits(gb, len);
692697 if (get_bits1(gb))
693698 get_bits(gb, len);
694− check_marker(s->avctx, gb, "after new_pred");
699+ check_marker(ctx->h.c.avctx, gb, "after new_pred");
695700
696701 return 0;
697702 }
@@ -700,96 +705,96 @@ static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) { · 2 unmodified lines
700705 * Decode the next video packet.
701706 * @return <0 if something went wrong
702707 */
703−int ff_mpeg4_decode_video_packet_header(MPVContext *const s)
708+int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
704709 {
705− Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
710+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
706711
707− int mb_num_bits = av_log2(s->mb_num - 1) + 1;
712+ int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;
708713 int header_extension = 0, mb_num, len;
709714
710715 /* is there enough space left for a video packet + header */
711− if (get_bits_count(&s->gb) > s->gb.size_in_bits - 20)
716+ if (get_bits_count(&h->c.gb) > h->c.gb.size_in_bits - 20)
712717 return AVERROR_INVALIDDATA;
713718
714719 for (len = 0; len < 32; len++)
715− if (get_bits1(&s->gb))
720+ if (get_bits1(&h->c.gb))
716721 break;
717722
718− if (len != ff_mpeg4_get_video_packet_prefix_length(s->pict_type, ctx->f_code, ctx->b_code)) {
719− av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n");
723+ if (len != ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) {
724+ av_log(h->c.avctx, AV_LOG_ERROR, "marker does not match f_code\n");
720725 return AVERROR_INVALIDDATA;
721726 }
722727
723728 if (ctx->shape != RECT_SHAPE) {
724− header_extension = get_bits1(&s->gb);
729+ header_extension = get_bits1(&h->c.gb);
725730 // FIXME more stuff here
726731 }
727732
728− mb_num = get_bits(&s->gb, mb_num_bits);
729− if (mb_num >= s->mb_num || !mb_num) {
730− av_log(s->avctx, AV_LOG_ERROR,
731− "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);
733+ mb_num = get_bits(&h->c.gb, mb_num_bits);
734+ if (mb_num >= h->c.mb_num || !mb_num) {
735+ av_log(h->c.avctx, AV_LOG_ERROR,
736+ "illegal mb_num in video packet (%d %d) \n", mb_num, h->c.mb_num);
732737 return AVERROR_INVALIDDATA;
733738 }
734739
735− s->mb_x = mb_num % s->mb_width;
736− s->mb_y = mb_num / s->mb_width;
740+ h->c.mb_x = mb_num % h->c.mb_width;
741+ h->c.mb_y = mb_num / h->c.mb_width;
737742
738743 if (ctx->shape != BIN_ONLY_SHAPE) {
739− int qscale = get_bits(&s->gb, ctx->quant_precision);
744+ int qscale = get_bits(&h->c.gb, ctx->quant_precision);
740745 if (qscale)
741− s->chroma_qscale = s->qscale = qscale;
746+ h->c.chroma_qscale = h->c.qscale = qscale;
742747 }
743748
744749 if (ctx->shape == RECT_SHAPE)
745− header_extension = get_bits1(&s->gb);
750+ header_extension = get_bits1(&h->c.gb);
746751
747752 if (header_extension) {
748− while (get_bits1(&s->gb) != 0)
753+ while (get_bits1(&h->c.gb) != 0)
749754 ;
750755
751− check_marker(s->avctx, &s->gb, "before time_increment in video packed header");
752− skip_bits(&s->gb, ctx->time_increment_bits); /* time_increment */
753− check_marker(s->avctx, &s->gb, "before vop_coding_type in video packed header");
756+ check_marker(h->c.avctx, &h->c.gb, "before time_increment in video packed header");
757+ skip_bits(&h->c.gb, ctx->time_increment_bits); /* time_increment */
758+ check_marker(h->c.avctx, &h->c.gb, "before vop_coding_type in video packed header");
754759
755− skip_bits(&s->gb, 2); /* vop coding type */
760+ skip_bits(&h->c.gb, 2); /* vop coding type */
756761 // FIXME not rect stuff here
757762
758763 if (ctx->shape != BIN_ONLY_SHAPE) {
759− skip_bits(&s->gb, 3); /* intra dc vlc threshold */
764+ skip_bits(&h->c.gb, 3); /* intra dc vlc threshold */
760765 // FIXME don't just ignore everything
761− if (s->pict_type == AV_PICTURE_TYPE_S &&
766+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
762767 ctx->vol_sprite_usage == GMC_SPRITE) {
763− if (mpeg4_decode_sprite_trajectory(ctx, &s->gb) < 0)
768+ if (mpeg4_decode_sprite_trajectory(ctx, &h->c.gb) < 0)
764769 return AVERROR_INVALIDDATA;
765− av_log(s->avctx, AV_LOG_ERROR, "untested\n");
770+ av_log(h->c.avctx, AV_LOG_ERROR, "untested\n");
766771 }
767772
768773 // FIXME reduced res stuff here
769774
770− if (s->pict_type != AV_PICTURE_TYPE_I) {
771− int f_code = get_bits(&s->gb, 3); /* fcode_for */
775+ if (h->c.pict_type != AV_PICTURE_TYPE_I) {
776+ int f_code = get_bits(&h->c.gb, 3); /* fcode_for */
772777 if (f_code == 0)
773− av_log(s->avctx, AV_LOG_ERROR,
778+ av_log(h->c.avctx, AV_LOG_ERROR,
774779 "Error, video packet header damaged (f_code=0)\n");
775780 }
776− if (s->pict_type == AV_PICTURE_TYPE_B) {
777− int b_code = get_bits(&s->gb, 3);
781+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
782+ int b_code = get_bits(&h->c.gb, 3);
778783 if (b_code == 0)
779− av_log(s->avctx, AV_LOG_ERROR,
784+ av_log(h->c.avctx, AV_LOG_ERROR,
780785 "Error, video packet header damaged (b_code=0)\n");
781786 }
782787 }
783788 }
784789 if (ctx->new_pred)
785− decode_new_pred(ctx, &s->gb);
790+ decode_new_pred(ctx, &h->c.gb);
786791
787792 return 0;
788793 }
789794
790795 static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
791796 {
792− MPVContext *const s = &ctx->m;
797+ MPVContext *const s = &ctx->h.c;
793798 /* Reset DC Predictors */
794799 s->last_dc[0] =
795800 s->last_dc[1] =
@@ -800,25 +805,25 @@ static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx) · 4 unmodified lines
800805 * Decode the next video packet.
801806 * @return <0 if something went wrong
802807 */
803−int ff_mpeg4_decode_studio_slice_header(MPVContext *const s)
808+int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
804809 {
805− Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
806− GetBitContext *gb = &s->gb;
810+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
811+ GetBitContext *gb = &h->c.gb;
807812 unsigned vlc_len;
808813 uint16_t mb_num;
809814
810815 if (get_bits_left(gb) >= 32 && get_bits_long(gb, 32) == SLICE_STARTCODE) {
811− vlc_len = av_log2(s->mb_width * s->mb_height) + 1;
816+ vlc_len = av_log2(h->c.mb_width * h->c.mb_height) + 1;
812817 mb_num = get_bits(gb, vlc_len);
813818
814− if (mb_num >= s->mb_num)
819+ if (mb_num >= h->c.mb_num)
815820 return AVERROR_INVALIDDATA;
816821
817− s->mb_x = mb_num % s->mb_width;
818− s->mb_y = mb_num / s->mb_width;
822+ h->c.mb_x = mb_num % h->c.mb_width;
823+ h->c.mb_y = mb_num / h->c.mb_width;
819824
820825 if (ctx->shape != BIN_ONLY_SHAPE)
821− s->qscale = mpeg_get_qscale(s);
826+ h->c.qscale = mpeg_get_qscale(&h->c);
822827
823828 if (get_bits1(gb)) { /* slice_extension_flag */
824829 skip_bits1(gb); /* intra_slice */
@@ -844,7 +849,7 @@ int ff_mpeg4_decode_studio_slice_header(MPVContext *const s) · 19 unmodified lines
844849 */
845850 static inline int get_amv(Mpeg4DecContext *ctx, int n)
846851 {
847− MpegEncContext *s = &ctx->m;
852+ MPVContext *const s = &ctx->h.c;
848853 int x, y, mb_v, sum, dx, dy, shift;
849854 int len = 1 << (ctx->f_code + 4);
850855 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 · 124 unmodified lines
975980 * @param dir_ptr the prediction direction will be stored here
976981 * @return the quantized dc
977982 */
978−static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr)
983+static inline int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr)
979984 {
980985 int level, code, pred;
981986
982987 if (n < 4)
983− code = get_vlc2(&s->gb, dc_lum, DC_VLC_BITS, 1);
988+ code = get_vlc2(&h->c.gb, dc_lum, DC_VLC_BITS, 1);
984989 else
985− code = get_vlc2(&s->gb, dc_chrom, DC_VLC_BITS, 1);
990+ code = get_vlc2(&h->c.gb, dc_chrom, DC_VLC_BITS, 1);
986991
987992 if (code < 0) {
988− av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
993+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
989994 return AVERROR_INVALIDDATA;
990995 }
991996
@@ -994,29 +999,29 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr) · 2 unmodified lines
994999 } else {
9951000 if (IS_3IV1) {
9961001 if (code == 1)
997− level = 2 * get_bits1(&s->gb) - 1;
1002+ level = 2 * get_bits1(&h->c.gb) - 1;
9981003 else {
999− if (get_bits1(&s->gb))
1000− level = get_bits(&s->gb, code - 1) + (1 << (code - 1));
1004+ if (get_bits1(&h->c.gb))
1005+ level = get_bits(&h->c.gb, code - 1) + (1 << (code - 1));
10011006 else
1002− level = -get_bits(&s->gb, code - 1) - (1 << (code - 1));
1007+ level = -get_bits(&h->c.gb, code - 1) - (1 << (code - 1));
10031008 }
10041009 } else {
1005− level = get_xbits(&s->gb, code);
1010+ level = get_xbits(&h->c.gb, code);
10061011 }
10071012
10081013 if (code > 8) {
1009− if (get_bits1(&s->gb) == 0) { /* marker */
1010− if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {
1011− av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n");
1014+ if (get_bits1(&h->c.gb) == 0) { /* marker */
1015+ if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {
1016+ av_log(h->c.avctx, AV_LOG_ERROR, "dc marker bit missing\n");
10121017 return AVERROR_INVALIDDATA;
10131018 }
10141019 }
10151020 }
10161021 }
10171022
1018− pred = mpeg4_pred_dc(s, n, dir_ptr);
1019− return mpeg4_get_level_dc(s, n, pred, level);
1023+ pred = mpeg4_pred_dc(&h->c, n, dir_ptr);
1024+ return mpeg4_get_level_dc(&h->c, n, pred, level);
10201025 }
10211026
10221027 /**
@@ -1025,85 +1030,85 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, int *dir_ptr) · 2 unmodified lines
10251030 */
10261031 static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
10271032 {
1028− MpegEncContext *s = &ctx->m;
1033+ H263DecContext *const h = &ctx->h;
10291034 int mb_num = 0;
10301035 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
10311036
10321037 /* decode first partition */
1033− s->first_slice_line = 1;
1034− for (; s->mb_y < s->mb_height; s->mb_y++) {
1035− ff_init_block_index(s);
1036− for (; s->mb_x < s->mb_width; s->mb_x++) {
1037− const int xy = s->mb_x + s->mb_y * s->mb_stride;
1038+ h->c.first_slice_line = 1;
1039+ for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) {
1040+ ff_init_block_index(&h->c);
1041+ for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
1042+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
10381043 int cbpc;
10391044 int dir = 0;
10401045
10411046 mb_num++;
1042− ff_update_block_index(s, 8, s->avctx->lowres, 1);
1043− if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1)
1044− s->first_slice_line = 0;
1047+ ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
1048+ if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1)
1049+ h->c.first_slice_line = 0;
10451050
1046− if (s->pict_type == AV_PICTURE_TYPE_I) {
1051+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
10471052 int i;
10481053
10491054 do {
1050− if (show_bits(&s->gb, 19) == DC_MARKER)
1055+ if (show_bits(&h->c.gb, 19) == DC_MARKER)
10511056 return mb_num - 1;
10521057
1053− cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
1058+ cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
10541059 if (cbpc < 0) {
1055− av_log(s->avctx, AV_LOG_ERROR,
1056− "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
1060+ av_log(h->c.avctx, AV_LOG_ERROR,
1061+ "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
10571062 return AVERROR_INVALIDDATA;
10581063 }
10591064 } while (cbpc == 8);
10601065
1061− s->cbp_table[xy] = cbpc & 3;
1062− s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1063− s->mb_intra = 1;
1066+ h->c.cbp_table[xy] = cbpc & 3;
1067+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1068+ h->c.mb_intra = 1;
10641069
10651070 if (cbpc & 4)
1066− ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
1071+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
10671072
1068− s->cur_pic.qscale_table[xy] = s->qscale;
1073+ h->c.cur_pic.qscale_table[xy] = h->c.qscale;
10691074
1070− s->mbintra_table[xy] = 1;
1075+ h->c.mbintra_table[xy] = 1;
10711076 for (i = 0; i < 6; i++) {
10721077 int dc_pred_dir;
1073− int dc = mpeg4_decode_dc(s, i, &dc_pred_dir);
1078+ int dc = mpeg4_decode_dc(h, i, &dc_pred_dir);
10741079 if (dc < 0) {
1075− av_log(s->avctx, AV_LOG_ERROR,
1076− "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
1080+ av_log(h->c.avctx, AV_LOG_ERROR,
1081+ "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
10771082 return dc;
10781083 }
10791084 dir <<= 1;
10801085 if (dc_pred_dir)
10811086 dir |= 1;
10821087 }
1083− s->pred_dir_table[xy] = dir;
1088+ h->c.pred_dir_table[xy] = dir;
10841089 } else { /* P/S_TYPE */
10851090 int mx, my, pred_x, pred_y, bits;
1086− int16_t *const mot_val = s->cur_pic.motion_val[0][s->block_index[0]];
1087− const int stride = s->b8_stride * 2;
1091+ int16_t *const mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
1092+ const int stride = h->c.b8_stride * 2;
10881093
10891094 try_again:
1090− bits = show_bits(&s->gb, 17);
1095+ bits = show_bits(&h->c.gb, 17);
10911096 if (bits == MOTION_MARKER)
10921097 return mb_num - 1;
10931098
1094− skip_bits1(&s->gb);
1099+ skip_bits1(&h->c.gb);
10951100 if (bits & 0x10000) {
10961101 /* skip mb */
1097− if (s->pict_type == AV_PICTURE_TYPE_S &&
1102+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
10981103 ctx->vol_sprite_usage == GMC_SPRITE) {
1099− s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
1104+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
11001105 MB_TYPE_16x16 |
11011106 MB_TYPE_GMC |
11021107 MB_TYPE_FORWARD_MV;
11031108 mx = get_amv(ctx, 0);
11041109 my = get_amv(ctx, 1);
11051110 } else {
1106− s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
1111+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
11071112 MB_TYPE_16x16 |
11081113 MB_TYPE_FORWARD_MV;
11091114 mx = my = 0;
@@ -1117,26 +1122,26 @@ try_again: · 7 unmodified lines
11171122 mot_val[1 + stride] =
11181123 mot_val[3 + stride] = my;
11191124
1120− ff_h263_clean_intra_table_entries(s, xy);
1125+ ff_h263_clean_intra_table_entries(&h->c, xy);
11211126 continue;
11221127 }
11231128
1124− cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
1129+ cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
11251130 if (cbpc < 0) {
1126− av_log(s->avctx, AV_LOG_ERROR,
1127− "mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
1131+ av_log(h->c.avctx, AV_LOG_ERROR,
1132+ "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
11281133 return AVERROR_INVALIDDATA;
11291134 }
11301135 if (cbpc == 20)
11311136 goto try_again;
11321137
1133− s->cbp_table[xy] = cbpc & (8 + 3); // 8 is dquant
1138+ h->c.cbp_table[xy] = cbpc & (8 + 3); // 8 is dquant
11341139
1135− s->mb_intra = ((cbpc & 4) != 0);
1140+ h->c.mb_intra = ((cbpc & 4) != 0);
11361141
1137− if (s->mb_intra) {
1138− s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1139− s->mbintra_table[xy] = 1;
1142+ if (h->c.mb_intra) {
1143+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1144+ h->c.mbintra_table[xy] = 1;
11401145 mot_val[0] =
11411146 mot_val[2] =
11421147 mot_val[0 + stride] =
@@ -1146,33 +1151,33 @@ try_again: · 3 unmodified lines
11461151 mot_val[1 + stride] =
11471152 mot_val[3 + stride] = 0;
11481153 } else {
1149− ff_h263_clean_intra_table_entries(s, xy);
1154+ ff_h263_clean_intra_table_entries(&h->c, xy);
11501155
1151− if (s->pict_type == AV_PICTURE_TYPE_S &&
1156+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
11521157 ctx->vol_sprite_usage == GMC_SPRITE &&
11531158 (cbpc & 16) == 0)
1154− s->mcsel = get_bits1(&s->gb);
1159+ h->c.mcsel = get_bits1(&h->c.gb);
11551160 else
1156− s->mcsel = 0;
1161+ h->c.mcsel = 0;
11571162
11581163 if ((cbpc & 16) == 0) {
11591164 /* 16x16 motion prediction */
11601165
1161− ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
1162− if (!s->mcsel) {
1163− mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
1166+ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
1167+ if (!h->c.mcsel) {
1168+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
11641169 if (mx >= 0xffff)
11651170 return AVERROR_INVALIDDATA;
11661171
1167− my = ff_h263_decode_motion(s, pred_y, ctx->f_code);
1172+ my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
11681173 if (my >= 0xffff)
11691174 return AVERROR_INVALIDDATA;
1170− s->cur_pic.mb_type[xy] = MB_TYPE_16x16 |
1175+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 |
11711176 MB_TYPE_FORWARD_MV;
11721177 } else {
11731178 mx = get_amv(ctx, 0);
11741179 my = get_amv(ctx, 1);
1175− s->cur_pic.mb_type[xy] = MB_TYPE_16x16 |
1180+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 |
11761181 MB_TYPE_GMC |
11771182 MB_TYPE_FORWARD_MV;
11781183 }
@@ -1187,15 +1192,15 @@ try_again: · 8 unmodified lines
11871192 mot_val[3 + stride] = my;
11881193 } else {
11891194 int i;
1190− s->cur_pic.mb_type[xy] = MB_TYPE_8x8 |
1195+ h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 |
11911196 MB_TYPE_FORWARD_MV;
11921197 for (i = 0; i < 4; i++) {
1193− int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
1194− mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
1198+ int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
1199+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
11951200 if (mx >= 0xffff)
11961201 return AVERROR_INVALIDDATA;
11971202
1198− my = ff_h263_decode_motion(s, pred_y, ctx->f_code);
1203+ my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
11991204 if (my >= 0xffff)
12001205 return AVERROR_INVALIDDATA;
12011206 mot_val[0] = mx;
@@ -1205,7 +1210,7 @@ try_again: · 3 unmodified lines
12051210 }
12061211 }
12071212 }
1208− s->mb_x = 0;
1213+ h->c.mb_x = 0;
12091214 }
12101215
12111216 return mb_num;
@@ -1215,91 +1220,91 @@ try_again: · 3 unmodified lines
12151220 * decode second partition.
12161221 * @return <0 if an error occurred
12171222 */
1218−static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count)
1223+static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
12191224 {
12201225 int mb_num = 0;
12211226 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
12221227
1223− s->mb_x = s->resync_mb_x;
1224− s->first_slice_line = 1;
1225− for (s->mb_y = s->resync_mb_y; mb_num < mb_count; s->mb_y++) {
1226− ff_init_block_index(s);
1227− for (; mb_num < mb_count && s->mb_x < s->mb_width; s->mb_x++) {
1228− const int xy = s->mb_x + s->mb_y * s->mb_stride;
1228+ h->c.mb_x = h->c.resync_mb_x;
1229+ h->c.first_slice_line = 1;
1230+ for (h->c.mb_y = h->c.resync_mb_y; mb_num < mb_count; h->c.mb_y++) {
1231+ ff_init_block_index(&h->c);
1232+ for (; mb_num < mb_count && h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
1233+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
12291234
12301235 mb_num++;
1231− ff_update_block_index(s, 8, s->avctx->lowres, 1);
1232− if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1)
1233− s->first_slice_line = 0;
1236+ ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
1237+ if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1)
1238+ h->c.first_slice_line = 0;
12341239
1235− if (s->pict_type == AV_PICTURE_TYPE_I) {
1236− int ac_pred = get_bits1(&s->gb);
1237− int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1240+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
1241+ int ac_pred = get_bits1(&h->c.gb);
1242+ int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
12381243 if (cbpy < 0) {
1239− av_log(s->avctx, AV_LOG_ERROR,
1240− "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
1244+ av_log(h->c.avctx, AV_LOG_ERROR,
1245+ "cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
12411246 return AVERROR_INVALIDDATA;
12421247 }
12431248
1244− s->cbp_table[xy] |= cbpy << 2;
1245− s->cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
1249+ h->c.cbp_table[xy] |= cbpy << 2;
1250+ h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
12461251 } else { /* P || S_TYPE */
1247− if (IS_INTRA(s->cur_pic.mb_type[xy])) {
1252+ if (IS_INTRA(h->c.cur_pic.mb_type[xy])) {
12481253 int i;
12491254 int dir = 0;
1250− int ac_pred = get_bits1(&s->gb);
1251− int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1255+ int ac_pred = get_bits1(&h->c.gb);
1256+ int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
12521257
12531258 if (cbpy < 0) {
1254− av_log(s->avctx, AV_LOG_ERROR,
1255− "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
1259+ av_log(h->c.avctx, AV_LOG_ERROR,
1260+ "I cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
12561261 return AVERROR_INVALIDDATA;
12571262 }
12581263
1259− if (s->cbp_table[xy] & 8)
1260− ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
1261− s->cur_pic.qscale_table[xy] = s->qscale;
1264+ if (h->c.cbp_table[xy] & 8)
1265+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
1266+ h->c.cur_pic.qscale_table[xy] = h->c.qscale;
12621267
12631268 for (i = 0; i < 6; i++) {
12641269 int dc_pred_dir;
1265− int dc = mpeg4_decode_dc(s, i, &dc_pred_dir);
1270+ int dc = mpeg4_decode_dc(h, i, &dc_pred_dir);
12661271 if (dc < 0) {
1267− av_log(s->avctx, AV_LOG_ERROR,
1268− "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
1272+ av_log(h->c.avctx, AV_LOG_ERROR,
1273+ "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
12691274 return dc;
12701275 }
12711276 dir <<= 1;
12721277 if (dc_pred_dir)
12731278 dir |= 1;
12741279 }
1275− s->cbp_table[xy] &= 3; // remove dquant
1276− s->cbp_table[xy] |= cbpy << 2;
1277− s->cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
1278− s->pred_dir_table[xy] = dir;
1279− } else if (IS_SKIP(s->cur_pic.mb_type[xy])) {
1280− s->cur_pic.qscale_table[xy] = s->qscale;
1281− s->cbp_table[xy] = 0;
1280+ h->c.cbp_table[xy] &= 3; // remove dquant
1281+ h->c.cbp_table[xy] |= cbpy << 2;
1282+ h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
1283+ h->c.pred_dir_table[xy] = dir;
1284+ } else if (IS_SKIP(h->c.cur_pic.mb_type[xy])) {
1285+ h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1286+ h->c.cbp_table[xy] = 0;
12821287 } else {
1283− int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1288+ int cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
12841289
12851290 if (cbpy < 0) {
1286− av_log(s->avctx, AV_LOG_ERROR,
1287− "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
1291+ av_log(h->c.avctx, AV_LOG_ERROR,
1292+ "P cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
12881293 return AVERROR_INVALIDDATA;
12891294 }
12901295
1291− if (s->cbp_table[xy] & 8)
1292− ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
1293− s->cur_pic.qscale_table[xy] = s->qscale;
1296+ if (h->c.cbp_table[xy] & 8)
1297+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
1298+ h->c.cur_pic.qscale_table[xy] = h->c.qscale;
12941299
1295− s->cbp_table[xy] &= 3; // remove dquant
1296− s->cbp_table[xy] |= (cbpy ^ 0xf) << 2;
1300+ h->c.cbp_table[xy] &= 3; // remove dquant
1301+ h->c.cbp_table[xy] |= (cbpy ^ 0xf) << 2;
12971302 }
12981303 }
12991304 }
13001305 if (mb_num >= mb_count)
13011306 return 0;
1302− s->mb_x = 0;
1307+ h->c.mb_x = 0;
13031308 }
13041309 return 0;
13051310 }
@@ -1308,62 +1313,62 @@ static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count) · 2 unmodified lines
13081313 * Decode the first and second partition.
13091314 * @return <0 if error (and sets error type in the error_status_table)
13101315 */
1311−int ff_mpeg4_decode_partitions(MPVContext *const s)
1316+int ff_mpeg4_decode_partitions(H263DecContext *const h)
13121317 {
1313− Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
1318+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
13141319 int mb_num;
13151320 int ret;
1316− const int part_a_error = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR;
1317− const int part_a_end = s->pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END;
1321+ const int part_a_error = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR;
1322+ const int part_a_end = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END;
13181323
13191324 mb_num = mpeg4_decode_partition_a(ctx);
13201325 if (mb_num <= 0) {
1321− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
1322− s->mb_x, s->mb_y, part_a_error);
1326+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1327+ h->c.mb_x, h->c.mb_y, part_a_error);
13231328 return mb_num ? mb_num : AVERROR_INVALIDDATA;
13241329 }
13251330
1326− if (s->resync_mb_x + s->resync_mb_y * s->mb_width + mb_num > s->mb_num) {
1327− av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n");
1328− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
1329− s->mb_x, s->mb_y, part_a_error);
1331+ if (h->c.resync_mb_x + h->c.resync_mb_y * h->c.mb_width + mb_num > h->c.mb_num) {
1332+ av_log(h->c.avctx, AV_LOG_ERROR, "slice below monitor ...\n");
1333+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1334+ h->c.mb_x, h->c.mb_y, part_a_error);
13301335 return AVERROR_INVALIDDATA;
13311336 }
13321337
1333− s->mb_num_left = mb_num;
1338+ h->c.mb_num_left = mb_num;
13341339
1335− if (s->pict_type == AV_PICTURE_TYPE_I) {
1336− while (show_bits(&s->gb, 9) == 1)
1337− skip_bits(&s->gb, 9);
1338− if (get_bits(&s->gb, 19) != DC_MARKER) {
1339− av_log(s->avctx, AV_LOG_ERROR,
1340+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
1341+ while (show_bits(&h->c.gb, 9) == 1)
1342+ skip_bits(&h->c.gb, 9);
1343+ if (get_bits(&h->c.gb, 19) != DC_MARKER) {
1344+ av_log(h->c.avctx, AV_LOG_ERROR,
13401345 "marker missing after first I partition at %d %d\n",
1341− s->mb_x, s->mb_y);
1346+ h->c.mb_x, h->c.mb_y);
13421347 return AVERROR_INVALIDDATA;
13431348 }
13441349 } else {
1345− while (show_bits(&s->gb, 10) == 1)
1346− skip_bits(&s->gb, 10);
1347− if (get_bits(&s->gb, 17) != MOTION_MARKER) {
1348− av_log(s->avctx, AV_LOG_ERROR,
1350+ while (show_bits(&h->c.gb, 10) == 1)
1351+ skip_bits(&h->c.gb, 10);
1352+ if (get_bits(&h->c.gb, 17) != MOTION_MARKER) {
1353+ av_log(h->c.avctx, AV_LOG_ERROR,
13491354 "marker missing after first P partition at %d %d\n",
1350− s->mb_x, s->mb_y);
1355+ h->c.mb_x, h->c.mb_y);
13511356 return AVERROR_INVALIDDATA;
13521357 }
13531358 }
1354− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
1355− s->mb_x - 1, s->mb_y, part_a_end);
1359+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1360+ h->c.mb_x - 1, h->c.mb_y, part_a_end);
13561361
1357− ret = mpeg4_decode_partition_b(s, mb_num);
1362+ ret = mpeg4_decode_partition_b(h, mb_num);
13581363 if (ret < 0) {
1359− if (s->pict_type == AV_PICTURE_TYPE_P)
1360− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
1361− s->mb_x, s->mb_y, ER_DC_ERROR);
1364+ if (h->c.pict_type == AV_PICTURE_TYPE_P)
1365+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1366+ h->c.mb_x, h->c.mb_y, ER_DC_ERROR);
13621367 return ret;
13631368 } else {
1364− if (s->pict_type == AV_PICTURE_TYPE_P)
1365− ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
1366− s->mb_x - 1, s->mb_y, ER_DC_END);
1369+ if (h->c.pict_type == AV_PICTURE_TYPE_P)
1370+ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1371+ h->c.mb_x - 1, h->c.mb_y, ER_DC_END);
13671372 }
13681373
13691374 return 0;
@@ -1377,7 +1382,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 7 unmodified lines
13771382 int n, int coded, int intra,
13781383 int use_intra_dc_vlc, int rvlc)
13791384 {
1380− MpegEncContext *s = &ctx->m;
1385+ H263DecContext *const h = &ctx->h;
13811386 int level, i, last, run, qmul, qadd, pred;
13821387 int av_uninit(dc_pred_dir);
13831388 const RLTable *rl;
@@ -1390,15 +1395,15 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 6 unmodified lines
13901395 // FIXME add short header support
13911396 if (use_intra_dc_vlc) {
13921397 /* DC coef */
1393− if (s->partitioned_frame) {
1394− level = s->dc_val[s->block_index[n]];
1398+ if (h->c.partitioned_frame) {
1399+ level = h->c.dc_val[h->c.block_index[n]];
13951400 if (n < 4)
1396− level = FASTDIV((level + (s->y_dc_scale >> 1)), s->y_dc_scale);
1401+ level = FASTDIV((level + (h->c.y_dc_scale >> 1)), h->c.y_dc_scale);
13971402 else
1398− level = FASTDIV((level + (s->c_dc_scale >> 1)), s->c_dc_scale);
1399− dc_pred_dir = (s->pred_dir_table[s->mb_x + s->mb_y * s->mb_stride] << n) & 32;
1403+ level = FASTDIV((level + (h->c.c_dc_scale >> 1)), h->c.c_dc_scale);
1404+ dc_pred_dir = (h->c.pred_dir_table[h->c.mb_x + h->c.mb_y * h->c.mb_stride] << n) & 32;
14001405 } else {
1401− level = mpeg4_decode_dc(s, n, &dc_pred_dir);
1406+ level = mpeg4_decode_dc(h, n, &dc_pred_dir);
14021407 if (level < 0)
14031408 return level;
14041409 }
@@ -1406,7 +1411,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line
14061411 i = 0;
14071412 } else {
14081413 i = -1;
1409− pred = mpeg4_pred_dc(s, n, &dc_pred_dir);
1414+ pred = mpeg4_pred_dc(&h->c, n, &dc_pred_dir);
14101415 }
14111416 if (!coded)
14121417 goto not_coded;
@@ -1418,20 +1423,20 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 5 unmodified lines
14181423 rl = &ff_mpeg4_rl_intra;
14191424 rl_vlc = ff_mpeg4_rl_intra.rl_vlc[0];
14201425 }
1421− if (s->ac_pred) {
1426+ if (h->c.ac_pred) {
14221427 if (dc_pred_dir == 0)
1423− scan_table = s->permutated_intra_v_scantable; /* left */
1428+ scan_table = h->c.permutated_intra_v_scantable; /* left */
14241429 else
1425− scan_table = s->permutated_intra_h_scantable; /* top */
1430+ scan_table = h->c.permutated_intra_h_scantable; /* top */
14261431 } else {
1427− scan_table = s->intra_scantable.permutated;
1432+ scan_table = h->c.intra_scantable.permutated;
14281433 }
14291434 qmul = 1;
14301435 qadd = 0;
14311436 } else {
14321437 i = -1;
14331438 if (!coded) {
1434− s->block_last_index[n] = i;
1439+ h->c.block_last_index[n] = i;
14351440 return 0;
14361441 }
14371442 if (rvlc)
@@ -1439,7 +1444,7 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line
14391444 else
14401445 rl = &ff_h263_rl_inter;
14411446
1442− scan_table = s->intra_scantable.permutated;
1447+ scan_table = h->c.intra_scantable.permutated;
14431448
14441449 if (ctx->mpeg_quant) {
14451450 qmul = 1;
@@ -1449,61 +1454,61 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 3 unmodified lines
14491454 else
14501455 rl_vlc = ff_h263_rl_inter.rl_vlc[0];
14511456 } else {
1452− qmul = s->qscale << 1;
1453− qadd = (s->qscale - 1) | 1;
1457+ qmul = h->c.qscale << 1;
1458+ qadd = (h->c.qscale - 1) | 1;
14541459 if (rvlc)
1455− rl_vlc = ff_rvlc_rl_inter.rl_vlc[s->qscale];
1460+ rl_vlc = ff_rvlc_rl_inter.rl_vlc[h->c.qscale];
14561461 else
1457− rl_vlc = ff_h263_rl_inter.rl_vlc[s->qscale];
1462+ rl_vlc = ff_h263_rl_inter.rl_vlc[h->c.qscale];
14581463 }
14591464 }
14601465 {
1461− OPEN_READER(re, &s->gb);
1466+ OPEN_READER(re, &h->c.gb);
14621467 for (;;) {
1463− UPDATE_CACHE(re, &s->gb);
1464− GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
1468+ UPDATE_CACHE(re, &h->c.gb);
1469+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0);
14651470 if (level == 0) {
14661471 /* escape */
14671472 if (rvlc) {
1468− if (SHOW_UBITS(re, &s->gb, 1) == 0) {
1469− av_log(s->avctx, AV_LOG_ERROR,
1473+ if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
1474+ av_log(h->c.avctx, AV_LOG_ERROR,
14701475 "1. marker bit missing in rvlc esc\n");
14711476 return AVERROR_INVALIDDATA;
14721477 }
1473− SKIP_CACHE(re, &s->gb, 1);
1478+ SKIP_CACHE(re, &h->c.gb, 1);
14741479
1475− last = SHOW_UBITS(re, &s->gb, 1);
1476− SKIP_CACHE(re, &s->gb, 1);
1477− run = SHOW_UBITS(re, &s->gb, 6);
1478− SKIP_COUNTER(re, &s->gb, 1 + 1 + 6);
1479− UPDATE_CACHE(re, &s->gb);
1480+ last = SHOW_UBITS(re, &h->c.gb, 1);
1481+ SKIP_CACHE(re, &h->c.gb, 1);
1482+ run = SHOW_UBITS(re, &h->c.gb, 6);
1483+ SKIP_COUNTER(re, &h->c.gb, 1 + 1 + 6);
1484+ UPDATE_CACHE(re, &h->c.gb);
14801485
1481− if (SHOW_UBITS(re, &s->gb, 1) == 0) {
1482− av_log(s->avctx, AV_LOG_ERROR,
1486+ if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
1487+ av_log(h->c.avctx, AV_LOG_ERROR,
14831488 "2. marker bit missing in rvlc esc\n");
14841489 return AVERROR_INVALIDDATA;
14851490 }
1486− SKIP_CACHE(re, &s->gb, 1);
1491+ SKIP_CACHE(re, &h->c.gb, 1);
14871492
1488− level = SHOW_UBITS(re, &s->gb, 11);
1489− SKIP_CACHE(re, &s->gb, 11);
1493+ level = SHOW_UBITS(re, &h->c.gb, 11);
1494+ SKIP_CACHE(re, &h->c.gb, 11);
14901495
1491− if (SHOW_UBITS(re, &s->gb, 5) != 0x10) {
1492− av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n");
1496+ if (SHOW_UBITS(re, &h->c.gb, 5) != 0x10) {
1497+ av_log(h->c.avctx, AV_LOG_ERROR, "reverse esc missing\n");
14931498 return AVERROR_INVALIDDATA;
14941499 }
1495− SKIP_CACHE(re, &s->gb, 5);
1500+ SKIP_CACHE(re, &h->c.gb, 5);
14961501
14971502 level = level * qmul + qadd;
1498− level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
1499− SKIP_COUNTER(re, &s->gb, 1 + 11 + 5 + 1);
1503+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
1504+ SKIP_COUNTER(re, &h->c.gb, 1 + 11 + 5 + 1);
15001505
15011506 i += run + 1;
15021507 if (last)
15031508 i += 192;
15041509 } else {
15051510 int cache;
1506− cache = GET_CACHE(re, &s->gb);
1511+ cache = GET_CACHE(re, &h->c.gb);
15071512
15081513 if (IS_3IV1)
15091514 cache ^= 0xC0000000;
@@ -1511,54 +1516,54 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 1 unmodified line
15111516 if (cache & 0x80000000) {
15121517 if (cache & 0x40000000) {
15131518 /* third escape */
1514− SKIP_CACHE(re, &s->gb, 2);
1515− last = SHOW_UBITS(re, &s->gb, 1);
1516− SKIP_CACHE(re, &s->gb, 1);
1517− run = SHOW_UBITS(re, &s->gb, 6);
1518− SKIP_COUNTER(re, &s->gb, 2 + 1 + 6);
1519− UPDATE_CACHE(re, &s->gb);
1519+ SKIP_CACHE(re, &h->c.gb, 2);
1520+ last = SHOW_UBITS(re, &h->c.gb, 1);
1521+ SKIP_CACHE(re, &h->c.gb, 1);
1522+ run = SHOW_UBITS(re, &h->c.gb, 6);
1523+ SKIP_COUNTER(re, &h->c.gb, 2 + 1 + 6);
1524+ UPDATE_CACHE(re, &h->c.gb);
15201525
15211526 if (IS_3IV1) {
1522− level = SHOW_SBITS(re, &s->gb, 12);
1523− LAST_SKIP_BITS(re, &s->gb, 12);
1527+ level = SHOW_SBITS(re, &h->c.gb, 12);
1528+ LAST_SKIP_BITS(re, &h->c.gb, 12);
15241529 } else {
1525− if (SHOW_UBITS(re, &s->gb, 1) == 0) {
1526− av_log(s->avctx, AV_LOG_ERROR,
1530+ if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
1531+ av_log(h->c.avctx, AV_LOG_ERROR,
15271532 "1. marker bit missing in 3. esc\n");
1528− if (!(s->avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&s->gb) <= 0)
1533+ if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0)
15291534 return AVERROR_INVALIDDATA;
15301535 }
1531− SKIP_CACHE(re, &s->gb, 1);
1536+ SKIP_CACHE(re, &h->c.gb, 1);
15321537
1533− level = SHOW_SBITS(re, &s->gb, 12);
1534− SKIP_CACHE(re, &s->gb, 12);
1538+ level = SHOW_SBITS(re, &h->c.gb, 12);
1539+ SKIP_CACHE(re, &h->c.gb, 12);
15351540
1536− if (SHOW_UBITS(re, &s->gb, 1) == 0) {
1537− av_log(s->avctx, AV_LOG_ERROR,
1541+ if (SHOW_UBITS(re, &h->c.gb, 1) == 0) {
1542+ av_log(h->c.avctx, AV_LOG_ERROR,
15381543 "2. marker bit missing in 3. esc\n");
1539− if (!(s->avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&s->gb) <= 0)
1544+ if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->c.gb) <= 0)
15401545 return AVERROR_INVALIDDATA;
15411546 }
15421547
1543− SKIP_COUNTER(re, &s->gb, 1 + 12 + 1);
1548+ SKIP_COUNTER(re, &h->c.gb, 1 + 12 + 1);
15441549 }
15451550
15461551 #if 0
1547− if (s->error_recognition >= FF_ER_COMPLIANT) {
1552+ if (h->c.error_recognition >= FF_ER_COMPLIANT) {
15481553 const int abs_level= FFABS(level);
15491554 if (abs_level<=MAX_LEVEL && run<=MAX_RUN) {
15501555 const int run1= run - rl->max_run[last][abs_level] - 1;
15511556 if (abs_level <= rl->max_level[last][run]) {
1552− av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
1557+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
15531558 return AVERROR_INVALIDDATA;
15541559 }
1555− if (s->error_recognition > FF_ER_COMPLIANT) {
1560+ if (h->c.error_recognition > FF_ER_COMPLIANT) {
15561561 if (abs_level <= rl->max_level[last][run]*2) {
1557− av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
1562+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
15581563 return AVERROR_INVALIDDATA;
15591564 }
15601565 if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
1561− av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
1566+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
15621567 return AVERROR_INVALIDDATA;
15631568 }
15641569 }
@@ -1571,11 +1576,11 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 6 unmodified lines
15711576 level = level * qmul - qadd;
15721577
15731578 if ((unsigned)(level + 2048) > 4095) {
1574− if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)) {
1579+ if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)) {
15751580 if (level > 2560 || level < -2560) {
1576− av_log(s->avctx, AV_LOG_ERROR,
1581+ av_log(h->c.avctx, AV_LOG_ERROR,
15771582 "|level| overflow in 3. esc, qp=%d\n",
1578− s->qscale);
1583+ h->c.qscale);
15791584 return AVERROR_INVALIDDATA;
15801585 }
15811586 }
@@ -1587,33 +1592,33 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 5 unmodified lines
15871592 i += 192;
15881593 } else {
15891594 /* second escape */
1590− SKIP_BITS(re, &s->gb, 2);
1591− GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
1595+ SKIP_BITS(re, &h->c.gb, 2);
1596+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
15921597 i += run + rl->max_run[run >> 7][level / qmul] + 1; // FIXME opt indexing
1593− level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
1594− LAST_SKIP_BITS(re, &s->gb, 1);
1598+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
1599+ LAST_SKIP_BITS(re, &h->c.gb, 1);
15951600 }
15961601 } else {
15971602 /* first escape */
1598− SKIP_BITS(re, &s->gb, 1);
1599− GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
1603+ SKIP_BITS(re, &h->c.gb, 1);
1604+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
16001605 i += run;
16011606 level = level + rl->max_level[run >> 7][(run - 1) & 63] * qmul; // FIXME opt indexing
1602− level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
1603− LAST_SKIP_BITS(re, &s->gb, 1);
1607+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
1608+ LAST_SKIP_BITS(re, &h->c.gb, 1);
16041609 }
16051610 }
16061611 } else {
16071612 i += run;
1608− level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
1609− LAST_SKIP_BITS(re, &s->gb, 1);
1613+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
1614+ LAST_SKIP_BITS(re, &h->c.gb, 1);
16101615 }
1611− ff_tlog(s->avctx, "dct[%d][%d] = %- 4d end?:%d\n", scan_table[i&63]&7, scan_table[i&63] >> 3, level, i>62);
1616+ 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);
16121617 if (i > 62) {
16131618 i -= 192;
16141619 if (i & (~63)) {
1615− av_log(s->avctx, AV_LOG_ERROR,
1616− "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
1620+ av_log(h->c.avctx, AV_LOG_ERROR,
1621+ "ac-tex damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
16171622 return AVERROR_INVALIDDATA;
16181623 }
16191624
@@ -1623,22 +1628,22 @@ static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block, · 3 unmodified lines
16231628
16241629 block[scan_table[i]] = level;
16251630 }
1626− CLOSE_READER(re, &s->gb);
1631+ CLOSE_READER(re, &h->c.gb);
16271632 }
16281633
16291634 not_coded:
16301635 if (intra) {
16311636 if (!use_intra_dc_vlc) {
1632− block[0] = mpeg4_get_level_dc(s, n, pred, block[0]);
1637+ block[0] = mpeg4_get_level_dc(&h->c, n, pred, block[0]);
16331638
16341639 i -= i >> 31; // if (i == -1) i = 0;
16351640 }
16361641
1637− ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);
1638− if (s->ac_pred)
1642+ ff_mpeg4_pred_ac(h, block, n, dc_pred_dir);
1643+ if (h->c.ac_pred)
16391644 i = 63; // FIXME not optimal
16401645 }
1641− s->block_last_index[n] = i;
1646+ h->c.block_last_index[n] = i;
16421647 return 0;
16431648 }
16441649
@@ -1646,72 +1651,71 @@ not_coded: · 1 unmodified line
16461651 * decode partition C of one MB.
16471652 * @return <0 if an error occurred
16481653 */
1649−static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64])
1654+static int mpeg4_decode_partitioned_mb(H263DecContext *const h, int16_t block[6][64])
16501655 {
1651− Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
1652− int cbp, mb_type, use_intra_dc_vlc;
1653− const int xy = s->mb_x + s->mb_y * s->mb_stride;
1656+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
1657+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
16541658
1655− mb_type = s->cur_pic.mb_type[xy];
1656− cbp = s->cbp_table[xy];
1659+ const int mb_type = h->c.cur_pic.mb_type[xy];
1660+ int cbp = h->c.cbp_table[xy];
16571661
1658− use_intra_dc_vlc = s->qscale < ctx->intra_dc_threshold;
1662+ const int use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;
16591663
1660− if (s->cur_pic.qscale_table[xy] != s->qscale)
1661− ff_set_qscale(s, s->cur_pic.qscale_table[xy]);
1664+ if (h->c.cur_pic.qscale_table[xy] != h->c.qscale)
1665+ ff_set_qscale(&h->c, h->c.cur_pic.qscale_table[xy]);
16621666
1663− if (s->pict_type == AV_PICTURE_TYPE_P ||
1664− s->pict_type == AV_PICTURE_TYPE_S) {
1667+ if (h->c.pict_type == AV_PICTURE_TYPE_P ||
1668+ h->c.pict_type == AV_PICTURE_TYPE_S) {
16651669 int i;
16661670 for (i = 0; i < 4; i++) {
1667− s->mv[0][i][0] = s->cur_pic.motion_val[0][s->block_index[i]][0];
1668− s->mv[0][i][1] = s->cur_pic.motion_val[0][s->block_index[i]][1];
1671+ h->c.mv[0][i][0] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][0];
1672+ h->c.mv[0][i][1] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][1];
16691673 }
1670− s->mb_intra = IS_INTRA(mb_type);
1674+ h->c.mb_intra = IS_INTRA(mb_type);
16711675
16721676 if (IS_SKIP(mb_type)) {
16731677 /* skip mb */
16741678 for (i = 0; i < 6; i++)
1675− s->block_last_index[i] = -1;
1676− s->mv_dir = MV_DIR_FORWARD;
1677− s->mv_type = MV_TYPE_16X16;
1678− if (s->pict_type == AV_PICTURE_TYPE_S
1679+ h->c.block_last_index[i] = -1;
1680+ h->c.mv_dir = MV_DIR_FORWARD;
1681+ h->c.mv_type = MV_TYPE_16X16;
1682+ if (h->c.pict_type == AV_PICTURE_TYPE_S
16791683 && ctx->vol_sprite_usage == GMC_SPRITE) {
1680− s->mcsel = 1;
1681− s->mb_skipped = 0;
1682− s->cur_pic.mbskip_table[xy] = 0;
1684+ h->c.mcsel = 1;
1685+ h->c.mb_skipped = 0;
1686+ h->c.cur_pic.mbskip_table[xy] = 0;
16831687 } else {
1684− s->mcsel = 0;
1685− s->mb_skipped = 1;
1686− s->cur_pic.mbskip_table[xy] = 1;
1688+ h->c.mcsel = 0;
1689+ h->c.mb_skipped = 1;
1690+ h->c.cur_pic.mbskip_table[xy] = 1;
16871691 }
1688− } else if (s->mb_intra) {
1689− s->ac_pred = IS_ACPRED(s->cur_pic.mb_type[xy]);
1690− } else if (!s->mb_intra) {
1691− // s->mcsel = 0; // FIXME do we need to init that?
1692+ } else if (h->c.mb_intra) {
1693+ h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]);
1694+ } else if (!h->c.mb_intra) {
1695+ // h->c.mcsel = 0; // FIXME do we need to init that?
16921696
1693− s->mv_dir = MV_DIR_FORWARD;
1697+ h->c.mv_dir = MV_DIR_FORWARD;
16941698 if (IS_8X8(mb_type)) {
1695− s->mv_type = MV_TYPE_8X8;
1699+ h->c.mv_type = MV_TYPE_8X8;
16961700 } else {
1697− s->mv_type = MV_TYPE_16X16;
1701+ h->c.mv_type = MV_TYPE_16X16;
16981702 }
16991703 }
17001704 } else { /* I-Frame */
1701− s->mb_intra = 1;
1702− s->ac_pred = IS_ACPRED(s->cur_pic.mb_type[xy]);
1705+ h->c.mb_intra = 1;
1706+ h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]);
17031707 }
17041708
17051709 if (!IS_SKIP(mb_type)) {
17061710 int i;
1707− s->bdsp.clear_blocks(s->block[0]);
1711+ h->c.bdsp.clear_blocks(h->c.block[0]);
17081712 /* decode each block */
17091713 for (i = 0; i < 6; i++) {
1710− if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, s->mb_intra,
1714+ if (mpeg4_decode_block(ctx, block[i], i, cbp & 32, h->c.mb_intra,
17111715 use_intra_dc_vlc, ctx->rvlc) < 0) {
1712− av_log(s->avctx, AV_LOG_ERROR,
1716+ av_log(h->c.avctx, AV_LOG_ERROR,
17131717 "texture corrupted at %d %d %d\n",
1714− s->mb_x, s->mb_y, s->mb_intra);
1718+ h->c.mb_x, h->c.mb_y, h->c.mb_intra);
17151719 return AVERROR_INVALIDDATA;
17161720 }
17171721 cbp += cbp;
@@ -1719,300 +1723,300 @@ static int mpeg4_decode_partitioned_mb(MpegEncContext *s, int16_t block[6][64]) · 1 unmodified line
17191723 }
17201724
17211725 /* per-MB end of slice check */
1722− if (--s->mb_num_left <= 0) {
1726+ if (--h->c.mb_num_left <= 0) {
17231727 if (mpeg4_is_resync(ctx))
17241728 return SLICE_END;
17251729 else
17261730 return SLICE_NOEND;
17271731 } else {
17281732 if (mpeg4_is_resync(ctx)) {
1729− const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1;
1730− if (s->cbp_table[xy + delta])
1733+ const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1;
1734+ if (h->c.cbp_table[xy + delta])
17311735 return SLICE_END;
17321736 }
17331737 return SLICE_OK;
17341738 }
17351739 }
17361740
1737−static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64])
1741+static int mpeg4_decode_mb(H263DecContext *const h, int16_t block[6][64])
17381742 {
1739− Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
1743+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
17401744 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
17411745 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1742− const int xy = s->mb_x + s->mb_y * s->mb_stride;
1746+ const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
17431747 int next;
17441748
1745− av_assert2(s->h263_pred);
1749+ av_assert2(h->c.h263_pred);
17461750
1747− if (s->pict_type == AV_PICTURE_TYPE_P ||
1748− s->pict_type == AV_PICTURE_TYPE_S) {
1751+ if (h->c.pict_type == AV_PICTURE_TYPE_P ||
1752+ h->c.pict_type == AV_PICTURE_TYPE_S) {
17491753 do {
1750− if (get_bits1(&s->gb)) {
1754+ if (get_bits1(&h->c.gb)) {
17511755 /* skip mb */
1752− s->mb_intra = 0;
1756+ h->c.mb_intra = 0;
17531757 for (i = 0; i < 6; i++)
1754− s->block_last_index[i] = -1;
1755− s->mv_dir = MV_DIR_FORWARD;
1756− s->mv_type = MV_TYPE_16X16;
1757− if (s->pict_type == AV_PICTURE_TYPE_S &&
1758+ h->c.block_last_index[i] = -1;
1759+ h->c.mv_dir = MV_DIR_FORWARD;
1760+ h->c.mv_type = MV_TYPE_16X16;
1761+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
17581762 ctx->vol_sprite_usage == GMC_SPRITE) {
1759− s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
1763+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
17601764 MB_TYPE_GMC |
17611765 MB_TYPE_16x16 |
17621766 MB_TYPE_FORWARD_MV;
1763− s->mcsel = 1;
1764− s->mv[0][0][0] = get_amv(ctx, 0);
1765− s->mv[0][0][1] = get_amv(ctx, 1);
1766− s->cur_pic.mbskip_table[xy] = 0;
1767− s->mb_skipped = 0;
1767+ h->c.mcsel = 1;
1768+ h->c.mv[0][0][0] = get_amv(ctx, 0);
1769+ h->c.mv[0][0][1] = get_amv(ctx, 1);
1770+ h->c.cur_pic.mbskip_table[xy] = 0;
1771+ h->c.mb_skipped = 0;
17681772 } else {
1769− s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 |
1773+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 |
17701774 MB_TYPE_FORWARD_MV;
1771− s->mcsel = 0;
1772− s->mv[0][0][0] = 0;
1773− s->mv[0][0][1] = 0;
1774− s->cur_pic.mbskip_table[xy] = 1;
1775− s->mb_skipped = 1;
1775+ h->c.mcsel = 0;
1776+ h->c.mv[0][0][0] = 0;
1777+ h->c.mv[0][0][1] = 0;
1778+ h->c.cur_pic.mbskip_table[xy] = 1;
1779+ h->c.mb_skipped = 1;
17761780 }
17771781 goto end;
17781782 }
1779− cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
1783+ cbpc = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
17801784 if (cbpc < 0) {
1781− av_log(s->avctx, AV_LOG_ERROR,
1782− "mcbpc damaged at %d %d\n", s->mb_x, s->mb_y);
1785+ av_log(h->c.avctx, AV_LOG_ERROR,
1786+ "mcbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
17831787 return AVERROR_INVALIDDATA;
17841788 }
17851789 } while (cbpc == 20);
17861790
17871791 dquant = cbpc & 8;
1788− s->mb_intra = ((cbpc & 4) != 0);
1789− if (s->mb_intra)
1792+ h->c.mb_intra = ((cbpc & 4) != 0);
1793+ if (h->c.mb_intra)
17901794 goto intra;
1791− s->bdsp.clear_blocks(s->block[0]);
1795+ h->c.bdsp.clear_blocks(h->c.block[0]);
17921796
1793− if (s->pict_type == AV_PICTURE_TYPE_S &&
1797+ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
17941798 ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)
1795− s->mcsel = get_bits1(&s->gb);
1799+ h->c.mcsel = get_bits1(&h->c.gb);
17961800 else
1797− s->mcsel = 0;
1798− cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
1801+ h->c.mcsel = 0;
1802+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
17991803 if (cbpy < 0) {
1800− av_log(s->avctx, AV_LOG_ERROR,
1801− "P cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
1804+ av_log(h->c.avctx, AV_LOG_ERROR,
1805+ "P cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
18021806 return AVERROR_INVALIDDATA;
18031807 }
18041808
18051809 cbp = (cbpc & 3) | (cbpy << 2);
18061810 if (dquant)
1807− ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
1808− if ((!s->progressive_sequence) &&
1809− (cbp || (s->workaround_bugs & FF_BUG_XVID_ILACE)))
1810− s->interlaced_dct = get_bits1(&s->gb);
1811+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
1812+ if ((!h->c.progressive_sequence) &&
1813+ (cbp || (h->c.workaround_bugs & FF_BUG_XVID_ILACE)))
1814+ h->c.interlaced_dct = get_bits1(&h->c.gb);
18111815
1812− s->mv_dir = MV_DIR_FORWARD;
1816+ h->c.mv_dir = MV_DIR_FORWARD;
18131817 if ((cbpc & 16) == 0) {
1814− if (s->mcsel) {
1815− s->cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 |
1818+ if (h->c.mcsel) {
1819+ h->c.cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 |
18161820 MB_TYPE_FORWARD_MV;
18171821 /* 16x16 global motion prediction */
1818− s->mv_type = MV_TYPE_16X16;
1822+ h->c.mv_type = MV_TYPE_16X16;
18191823 mx = get_amv(ctx, 0);
18201824 my = get_amv(ctx, 1);
1821− s->mv[0][0][0] = mx;
1822− s->mv[0][0][1] = my;
1823− } else if ((!s->progressive_sequence) && get_bits1(&s->gb)) {
1824− s->cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |
1825+ h->c.mv[0][0][0] = mx;
1826+ h->c.mv[0][0][1] = my;
1827+ } else if ((!h->c.progressive_sequence) && get_bits1(&h->c.gb)) {
1828+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |
18251829 MB_TYPE_INTERLACED;
18261830 /* 16x8 field motion prediction */
1827− s->mv_type = MV_TYPE_FIELD;
1831+ h->c.mv_type = MV_TYPE_FIELD;
18281832
1829− s->field_select[0][0] = get_bits1(&s->gb);
1830− s->field_select[0][1] = get_bits1(&s->gb);
1833+ h->c.field_select[0][0] = get_bits1(&h->c.gb);
1834+ h->c.field_select[0][1] = get_bits1(&h->c.gb);
18311835
1832− ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
1836+ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
18331837
18341838 for (i = 0; i < 2; i++) {
1835− mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
1839+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
18361840 if (mx >= 0xffff)
18371841 return AVERROR_INVALIDDATA;
18381842
1839− my = ff_h263_decode_motion(s, pred_y / 2, ctx->f_code);
1843+ my = ff_h263_decode_motion(h, pred_y / 2, ctx->f_code);
18401844 if (my >= 0xffff)
18411845 return AVERROR_INVALIDDATA;
18421846
1843− s->mv[0][i][0] = mx;
1844− s->mv[0][i][1] = my;
1847+ h->c.mv[0][i][0] = mx;
1848+ h->c.mv[0][i][1] = my;
18451849 }
18461850 } else {
1847− s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
1851+ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
18481852 /* 16x16 motion prediction */
1849− s->mv_type = MV_TYPE_16X16;
1850− ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
1851− mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
1853+ h->c.mv_type = MV_TYPE_16X16;
1854+ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
1855+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
18521856
18531857 if (mx >= 0xffff)
18541858 return AVERROR_INVALIDDATA;
18551859
1856− my = ff_h263_decode_motion(s, pred_y, ctx->f_code);
1860+ my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
18571861
18581862 if (my >= 0xffff)
18591863 return AVERROR_INVALIDDATA;
1860− s->mv[0][0][0] = mx;
1861− s->mv[0][0][1] = my;
1864+ h->c.mv[0][0][0] = mx;
1865+ h->c.mv[0][0][1] = my;
18621866 }
18631867 } else {
1864− s->cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
1865− s->mv_type = MV_TYPE_8X8;
1868+ h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
1869+ h->c.mv_type = MV_TYPE_8X8;
18661870 for (i = 0; i < 4; i++) {
1867− int16_t *mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
1868− mx = ff_h263_decode_motion(s, pred_x, ctx->f_code);
1871+ int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
1872+ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
18691873 if (mx >= 0xffff)
18701874 return AVERROR_INVALIDDATA;
18711875
1872− my = ff_h263_decode_motion(s, pred_y, ctx->f_code);
1876+ my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
18731877 if (my >= 0xffff)
18741878 return AVERROR_INVALIDDATA;
1875− s->mv[0][i][0] = mx;
1876− s->mv[0][i][1] = my;
1879+ h->c.mv[0][i][0] = mx;
1880+ h->c.mv[0][i][1] = my;
18771881 mot_val[0] = mx;
18781882 mot_val[1] = my;
18791883 }
18801884 }
1881− } else if (s->pict_type == AV_PICTURE_TYPE_B) {
1885+ } else if (h->c.pict_type == AV_PICTURE_TYPE_B) {
18821886 int modb1; // first bit of modb
18831887 int modb2; // second bit of modb
18841888 int mb_type;
18851889
1886− s->mb_intra = 0; // B-frames never contain intra blocks
1887− s->mcsel = 0; // ... true gmc blocks
1890+ h->c.mb_intra = 0; // B-frames never contain intra blocks
1891+ h->c.mcsel = 0; // ... true gmc blocks
18881892
1889− if (s->mb_x == 0) {
1893+ if (h->c.mb_x == 0) {
18901894 for (i = 0; i < 2; i++) {
1891− s->last_mv[i][0][0] =
1892− s->last_mv[i][0][1] =
1893− s->last_mv[i][1][0] =
1894− s->last_mv[i][1][1] = 0;
1895+ h->c.last_mv[i][0][0] =
1896+ h->c.last_mv[i][0][1] =
1897+ h->c.last_mv[i][1][0] =
1898+ h->c.last_mv[i][1][1] = 0;
18951899 }
18961900
1897− ff_thread_progress_await(&s->next_pic.ptr->progress, s->mb_y);
1901+ ff_thread_progress_await(&h->c.next_pic.ptr->progress, h->c.mb_y);
18981902 }
18991903
19001904 /* if we skipped it in the future P-frame than skip it now too */
1901− s->mb_skipped = s->next_pic.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC
1905+ 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
19021906
1903− if (s->mb_skipped) {
1907+ if (h->c.mb_skipped) {
19041908 /* skip mb */
19051909 for (i = 0; i < 6; i++)
1906− s->block_last_index[i] = -1;
1907−
1908− s->mv_dir = MV_DIR_FORWARD;
1909− s->mv_type = MV_TYPE_16X16;
1910− s->mv[0][0][0] =
1911− s->mv[0][0][1] =
1912− s->mv[1][0][0] =
1913− s->mv[1][0][1] = 0;
1914− s->cur_pic.mb_type[xy] = MB_TYPE_SKIP |
1910+ h->c.block_last_index[i] = -1;
1911+
1912+ h->c.mv_dir = MV_DIR_FORWARD;
1913+ h->c.mv_type = MV_TYPE_16X16;
1914+ h->c.mv[0][0][0] =
1915+ h->c.mv[0][0][1] =
1916+ h->c.mv[1][0][0] =
1917+ h->c.mv[1][0][1] = 0;
1918+ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
19151919 MB_TYPE_16x16 |
19161920 MB_TYPE_FORWARD_MV;
19171921 goto end;
19181922 }
19191923
1920− modb1 = get_bits1(&s->gb);
1924+ modb1 = get_bits1(&h->c.gb);
19211925 if (modb1) {
19221926 // like MB_TYPE_B_DIRECT but no vectors coded
19231927 mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV;
19241928 cbp = 0;
19251929 } else {
1926− modb2 = get_bits1(&s->gb);
1927− mb_type = get_vlc2(&s->gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
1930+ modb2 = get_bits1(&h->c.gb);
1931+ mb_type = get_vlc2(&h->c.gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
19281932 if (mb_type < 0) {
1929− av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n");
1933+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal MB_type\n");
19301934 return AVERROR_INVALIDDATA;
19311935 }
19321936 if (modb2) {
19331937 cbp = 0;
19341938 } else {
1935− s->bdsp.clear_blocks(s->block[0]);
1936− cbp = get_bits(&s->gb, 6);
1939+ h->c.bdsp.clear_blocks(h->c.block[0]);
1940+ cbp = get_bits(&h->c.gb, 6);
19371941 }
19381942
19391943 if ((!IS_DIRECT(mb_type)) && cbp) {
1940− if (get_bits1(&s->gb))
1941− ff_set_qscale(s, s->qscale + get_bits1(&s->gb) * 4 - 2);
1944+ if (get_bits1(&h->c.gb))
1945+ ff_set_qscale(&h->c, h->c.qscale + get_bits1(&h->c.gb) * 4 - 2);
19421946 }
19431947
1944− if (!s->progressive_sequence) {
1948+ if (!h->c.progressive_sequence) {
19451949 if (cbp)
1946− s->interlaced_dct = get_bits1(&s->gb);
1950+ h->c.interlaced_dct = get_bits1(&h->c.gb);
19471951
1948− if (!IS_DIRECT(mb_type) && get_bits1(&s->gb)) {
1952+ if (!IS_DIRECT(mb_type) && get_bits1(&h->c.gb)) {
19491953 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
19501954 mb_type &= ~MB_TYPE_16x16;
19511955
19521956 if (HAS_FORWARD_MV(mb_type)) {
1953− s->field_select[0][0] = get_bits1(&s->gb);
1954− s->field_select[0][1] = get_bits1(&s->gb);
1957+ h->c.field_select[0][0] = get_bits1(&h->c.gb);
1958+ h->c.field_select[0][1] = get_bits1(&h->c.gb);
19551959 }
19561960 if (HAS_BACKWARD_MV(mb_type)) {
1957− s->field_select[1][0] = get_bits1(&s->gb);
1958− s->field_select[1][1] = get_bits1(&s->gb);
1961+ h->c.field_select[1][0] = get_bits1(&h->c.gb);
1962+ h->c.field_select[1][1] = get_bits1(&h->c.gb);
19591963 }
19601964 }
19611965 }
19621966
1963− s->mv_dir = 0;
1967+ h->c.mv_dir = 0;
19641968 if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) {
1965− s->mv_type = MV_TYPE_16X16;
1969+ h->c.mv_type = MV_TYPE_16X16;
19661970
19671971 if (HAS_FORWARD_MV(mb_type)) {
1968− s->mv_dir = MV_DIR_FORWARD;
1969−
1970− mx = ff_h263_decode_motion(s, s->last_mv[0][0][0], ctx->f_code);
1971− my = ff_h263_decode_motion(s, s->last_mv[0][0][1], ctx->f_code);
1972− s->last_mv[0][1][0] =
1973− s->last_mv[0][0][0] =
1974− s->mv[0][0][0] = mx;
1975− s->last_mv[0][1][1] =
1976− s->last_mv[0][0][1] =
1977− s->mv[0][0][1] = my;
1972+ h->c.mv_dir = MV_DIR_FORWARD;
1973+
1974+ mx = ff_h263_decode_motion(h, h->c.last_mv[0][0][0], ctx->f_code);
1975+ my = ff_h263_decode_motion(h, h->c.last_mv[0][0][1], ctx->f_code);
1976+ h->c.last_mv[0][1][0] =
1977+ h->c.last_mv[0][0][0] =
1978+ h->c.mv[0][0][0] = mx;
1979+ h->c.last_mv[0][1][1] =
1980+ h->c.last_mv[0][0][1] =
1981+ h->c.mv[0][0][1] = my;
19781982 }
19791983
19801984 if (HAS_BACKWARD_MV(mb_type)) {
1981− s->mv_dir |= MV_DIR_BACKWARD;
1982−
1983− mx = ff_h263_decode_motion(s, s->last_mv[1][0][0], ctx->b_code);
1984− my = ff_h263_decode_motion(s, s->last_mv[1][0][1], ctx->b_code);
1985− s->last_mv[1][1][0] =
1986− s->last_mv[1][0][0] =
1987− s->mv[1][0][0] = mx;
1988− s->last_mv[1][1][1] =
1989− s->last_mv[1][0][1] =
1990− s->mv[1][0][1] = my;
1985+ h->c.mv_dir |= MV_DIR_BACKWARD;
1986+
1987+ mx = ff_h263_decode_motion(h, h->c.last_mv[1][0][0], ctx->b_code);
1988+ my = ff_h263_decode_motion(h, h->c.last_mv[1][0][1], ctx->b_code);
1989+ h->c.last_mv[1][1][0] =
1990+ h->c.last_mv[1][0][0] =
1991+ h->c.mv[1][0][0] = mx;
1992+ h->c.last_mv[1][1][1] =
1993+ h->c.last_mv[1][0][1] =
1994+ h->c.mv[1][0][1] = my;
19911995 }
19921996 } else if (!IS_DIRECT(mb_type)) {
1993− s->mv_type = MV_TYPE_FIELD;
1997+ h->c.mv_type = MV_TYPE_FIELD;
19941998
19951999 if (HAS_FORWARD_MV(mb_type)) {
1996− s->mv_dir = MV_DIR_FORWARD;
2000+ h->c.mv_dir = MV_DIR_FORWARD;
19972001
19982002 for (i = 0; i < 2; i++) {
1999− mx = ff_h263_decode_motion(s, s->last_mv[0][i][0], ctx->f_code);
2000− my = ff_h263_decode_motion(s, s->last_mv[0][i][1] / 2, ctx->f_code);
2001− s->last_mv[0][i][0] =
2002− s->mv[0][i][0] = mx;
2003− s->last_mv[0][i][1] = (s->mv[0][i][1] = my) * 2;
2003+ mx = ff_h263_decode_motion(h, h->c.last_mv[0][i][0], ctx->f_code);
2004+ my = ff_h263_decode_motion(h, h->c.last_mv[0][i][1] / 2, ctx->f_code);
2005+ h->c.last_mv[0][i][0] =
2006+ h->c.mv[0][i][0] = mx;
2007+ h->c.last_mv[0][i][1] = (h->c.mv[0][i][1] = my) * 2;
20042008 }
20052009 }
20062010
20072011 if (HAS_BACKWARD_MV(mb_type)) {
2008− s->mv_dir |= MV_DIR_BACKWARD;
2012+ h->c.mv_dir |= MV_DIR_BACKWARD;
20092013
20102014 for (i = 0; i < 2; i++) {
2011− mx = ff_h263_decode_motion(s, s->last_mv[1][i][0], ctx->b_code);
2012− my = ff_h263_decode_motion(s, s->last_mv[1][i][1] / 2, ctx->b_code);
2013− s->last_mv[1][i][0] =
2014− s->mv[1][i][0] = mx;
2015− s->last_mv[1][i][1] = (s->mv[1][i][1] = my) * 2;
2015+ mx = ff_h263_decode_motion(h, h->c.last_mv[1][i][0], ctx->b_code);
2016+ my = ff_h263_decode_motion(h, h->c.last_mv[1][i][1] / 2, ctx->b_code);
2017+ h->c.last_mv[1][i][0] =
2018+ h->c.mv[1][i][0] = mx;
2019+ h->c.last_mv[1][i][1] = (h->c.mv[1][i][1] = my) * 2;
20162020 }
20172021 }
20182022 }
@@ -2023,53 +2027,53 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 4 unmodified lines
20232027 mx =
20242028 my = 0;
20252029 } else {
2026− mx = ff_h263_decode_motion(s, 0, 1);
2027− my = ff_h263_decode_motion(s, 0, 1);
2030+ mx = ff_h263_decode_motion(h, 0, 1);
2031+ my = ff_h263_decode_motion(h, 0, 1);
20282032 }
20292033
2030− s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
2031− mb_type |= ff_mpeg4_set_direct_mv(s, mx, my);
2034+ h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
2035+ mb_type |= ff_mpeg4_set_direct_mv(&h->c, mx, my);
20322036 }
2033− s->cur_pic.mb_type[xy] = mb_type;
2037+ h->c.cur_pic.mb_type[xy] = mb_type;
20342038 } else { /* I-Frame */
20352039 int use_intra_dc_vlc;
20362040
20372041 do {
2038− cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
2042+ cbpc = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
20392043 if (cbpc < 0) {
2040− av_log(s->avctx, AV_LOG_ERROR,
2041− "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
2044+ av_log(h->c.avctx, AV_LOG_ERROR,
2045+ "I cbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
20422046 return AVERROR_INVALIDDATA;
20432047 }
20442048 } while (cbpc == 8);
20452049
20462050 dquant = cbpc & 4;
2047− s->mb_intra = 1;
2051+ h->c.mb_intra = 1;
20482052
20492053 intra:
2050− s->ac_pred = get_bits1(&s->gb);
2051− if (s->ac_pred)
2052− s->cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
2054+ h->c.ac_pred = get_bits1(&h->c.gb);
2055+ if (h->c.ac_pred)
2056+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
20532057 else
2054− s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
2058+ h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
20552059
2056− cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
2060+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
20572061 if (cbpy < 0) {
2058− av_log(s->avctx, AV_LOG_ERROR,
2059− "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
2062+ av_log(h->c.avctx, AV_LOG_ERROR,
2063+ "I cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
20602064 return AVERROR_INVALIDDATA;
20612065 }
20622066 cbp = (cbpc & 3) | (cbpy << 2);
20632067
2064− use_intra_dc_vlc = s->qscale < ctx->intra_dc_threshold;
2068+ use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;
20652069
20662070 if (dquant)
2067− ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
2071+ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->c.gb, 2)]);
20682072
2069− if (!s->progressive_sequence)
2070− s->interlaced_dct = get_bits1(&s->gb);
2073+ if (!h->c.progressive_sequence)
2074+ h->c.interlaced_dct = get_bits1(&h->c.gb);
20712075
2072− s->bdsp.clear_blocks(s->block[0]);
2076+ h->c.bdsp.clear_blocks(h->c.block[0]);
20732077 /* decode each block */
20742078 for (i = 0; i < 6; i++) {
20752079 if (mpeg4_decode_block(ctx, block[i], i, cbp & 32,
@@ -2091,18 +2095,18 @@ end: · 15 unmodified lines
20912095 /* per-MB end of slice check */
20922096 next = mpeg4_is_resync(ctx);
20932097 if (next) {
2094− if (s->mb_x + s->mb_y*s->mb_width + 1 > next && (s->avctx->err_recognition & AV_EF_AGGRESSIVE)) {
2098+ if (h->c.mb_x + h->c.mb_y*h->c.mb_width + 1 > next && (h->c.avctx->err_recognition & AV_EF_AGGRESSIVE)) {
20952099 return AVERROR_INVALIDDATA;
2096− } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next)
2100+ } else if (h->c.mb_x + h->c.mb_y*h->c.mb_width + 1 >= next)
20972101 return SLICE_END;
20982102
2099− if (s->pict_type == AV_PICTURE_TYPE_B) {
2100− const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1;
2101− ff_thread_progress_await(&s->next_pic.ptr->progress,
2102− (s->mb_x + delta >= s->mb_width)
2103− ? FFMIN(s->mb_y + 1, s->mb_height - 1)
2104− : s->mb_y);
2105− if (s->next_pic.mbskip_table[xy + delta])
2103+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
2104+ const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1;
2105+ ff_thread_progress_await(&h->c.next_pic.ptr->progress,
2106+ (h->c.mb_x + delta >= h->c.mb_width)
2107+ ? FFMIN(h->c.mb_y + 1, h->c.mb_height - 1)
2108+ : h->c.mb_y);
2109+ if (h->c.next_pic.mbskip_table[xy + delta])
21062110 return SLICE_OK;
21072111 }
21082112
@@ -2149,19 +2153,19 @@ static const uint8_t ac_state_tab[22][2] = · 40 unmodified lines
21492153 {0, 11}
21502154 };
21512155
2152−static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n)
2156+static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[64], int n)
21532157 {
2154− Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
2158+ H263DecContext *const h = &ctx->h;
21552159
21562160 int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0,
21572161 additional_code_len, sign, mismatch;
21582162 const VLCElem *cur_vlc = studio_intra_tab[0];
2159− const uint8_t *const scantable = s->intra_scantable.permutated;
2163+ const uint8_t *const scantable = h->c.intra_scantable.permutated;
21602164 const uint16_t *quant_matrix;
21612165 uint32_t flc;
2162− const int min = -1 * (1 << (s->avctx->bits_per_raw_sample + 6));
2163− const int max = ((1 << (s->avctx->bits_per_raw_sample + 6)) - 1);
2164− int shift = 3 - ctx->dct_precision;
2166+ const int min = -1 * (1 << (h->c.avctx->bits_per_raw_sample + 6));
2167+ const int max = ((1 << (h->c.avctx->bits_per_raw_sample + 6)) - 1);
2168+ int shift = 3 - ctx->dct_precision;
21652169
21662170 mismatch = 1;
21672171
@@ -2169,35 +2173,35 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 1 unmodified line
21692173
21702174 if (n < 4) {
21712175 cc = 0;
2172− dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
2173− quant_matrix = s->intra_matrix;
2176+ dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
2177+ quant_matrix = h->c.intra_matrix;
21742178 } else {
21752179 cc = (n & 1) + 1;
21762180 if (ctx->rgb)
2177− dct_dc_size = get_vlc2(&s->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
2181+ dct_dc_size = get_vlc2(&h->c.gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
21782182 else
2179− dct_dc_size = get_vlc2(&s->gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
2180− quant_matrix = s->chroma_intra_matrix;
2183+ dct_dc_size = get_vlc2(&h->c.gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
2184+ quant_matrix = h->c.chroma_intra_matrix;
21812185 }
21822186
21832187 if (dct_dc_size == 0) {
21842188 dct_diff = 0;
21852189 } else {
2186− dct_diff = get_xbits(&s->gb, dct_dc_size);
2190+ dct_diff = get_xbits(&h->c.gb, dct_dc_size);
21872191
21882192 if (dct_dc_size > 8) {
2189− if(!check_marker(s->avctx, &s->gb, "dct_dc_size > 8"))
2193+ if(!check_marker(h->c.avctx, &h->c.gb, "dct_dc_size > 8"))
21902194 return AVERROR_INVALIDDATA;
21912195 }
21922196
21932197 }
21942198
2195− s->last_dc[cc] += dct_diff;
2199+ h->c.last_dc[cc] += dct_diff;
21962200
21972201 if (ctx->mpeg_quant)
2198− block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision);
2202+ block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision);
21992203 else
2200− block[0] = s->last_dc[cc] * (8 >> s->intra_dc_precision) * (8 >> ctx->dct_precision);
2204+ block[0] = h->c.last_dc[cc] * (8 >> h->c.intra_dc_precision) * (8 >> ctx->dct_precision);
22012205 /* TODO: support mpeg_quant for AC coefficients */
22022206
22032207 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 · 1 unmodified line
22052209
22062210 /* AC Coefficients */
22072211 while (1) {
2208− group = get_vlc2(&s->gb, cur_vlc, STUDIO_INTRA_BITS, 2);
2212+ group = get_vlc2(&h->c.gb, cur_vlc, STUDIO_INTRA_BITS, 2);
22092213
22102214 if (group < 0) {
2211− av_log(s->avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n");
2215+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n");
22122216 return AVERROR_INVALIDDATA;
22132217 }
22142218
@@ -2222,12 +2226,12 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 7 unmodified lines
22222226 /* Zero run length (Table B.47) */
22232227 run = 1 << additional_code_len;
22242228 if (additional_code_len)
2225− run += get_bits(&s->gb, additional_code_len);
2229+ run += get_bits(&h->c.gb, additional_code_len);
22262230 idx += run;
22272231 continue;
22282232 } else if (group >= 7 && group <= 12) {
22292233 /* Zero run length and +/-1 level (Table B.48) */
2230− code = get_bits(&s->gb, additional_code_len);
2234+ code = get_bits(&h->c.gb, additional_code_len);
22312235 sign = code & 1;
22322236 code >>= 1;
22332237 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 · 7 unmodified lines
22412245 if (idx > 63)
22422246 return AVERROR_INVALIDDATA;
22432247 j = scantable[idx++];
2244− block[j] = get_xbits(&s->gb, additional_code_len);
2248+ block[j] = get_xbits(&h->c.gb, additional_code_len);
22452249 } else if (group == 21) {
22462250 /* Escape */
22472251 if (idx > 63)
22482252 return AVERROR_INVALIDDATA;
22492253 j = scantable[idx++];
2250− additional_code_len = s->avctx->bits_per_raw_sample + ctx->dct_precision + 4;
2251− flc = get_bits(&s->gb, additional_code_len);
2254+ additional_code_len = h->c.avctx->bits_per_raw_sample + ctx->dct_precision + 4;
2255+ flc = get_bits(&h->c.gb, additional_code_len);
22522256 if (flc >> (additional_code_len-1))
22532257 block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
22542258 else
22552259 block[j] = flc;
22562260 }
2257− block[j] = ((block[j] * quant_matrix[j] * s->qscale) * (1 << shift)) / 16;
2261+ block[j] = ((block[j] * quant_matrix[j] * h->c.qscale) * (1 << shift)) / 16;
22582262 block[j] = av_clip(block[j], min, max);
22592263 mismatch ^= block[j];
22602264 }
@@ -2267,23 +2271,23 @@ static int mpeg4_decode_studio_block(MpegEncContext *s, int32_t block[64], int n · 6 unmodified lines
22672271 static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
22682272 int16_t macroblock[256], int n)
22692273 {
2270− MPVContext *const s = &ctx->m;
2271− int i, j, w, h, idx = 0;
2274+ H263DecContext *const h = &ctx->h;
2275+ int j, w, height, idx = 0;
22722276 int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
22732277 dpcm_residual, left, top, topleft, min_left_top, max_left_top, p, p2, output;
2274− h = 16 >> (n ? s->chroma_y_shift : 0);
2275− w = 16 >> (n ? s->chroma_x_shift : 0);
2278+ height = 16 >> (n ? h->c.chroma_y_shift : 0);
2279+ w = 16 >> (n ? h->c.chroma_x_shift : 0);
22762280
2277− block_mean = get_bits(&s->gb, s->avctx->bits_per_raw_sample);
2281+ block_mean = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample);
22782282 if (block_mean == 0){
2279− av_log(s->avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
2283+ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
22802284 return AVERROR_INVALIDDATA;
22812285 }
2282− s->last_dc[n] = block_mean * (1 << (ctx->dct_precision + s->intra_dc_precision));
2286+ h->c.last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
22832287
2284− rice_parameter = get_bits(&s->gb, 4);
2288+ rice_parameter = get_bits(&h->c.gb, 4);
22852289 if (rice_parameter == 0) {
2286− av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
2290+ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
22872291 return AVERROR_INVALIDDATA;
22882292 }
22892293
@@ -2291,29 +2295,29 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, · 1 unmodified line
22912295 rice_parameter = 0;
22922296
22932297 if (rice_parameter > 11) {
2294− av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
2298+ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
22952299 return AVERROR_INVALIDDATA;
22962300 }
22972301
2298− for (i = 0; i < h; i++) {
2299− output = 1 << (s->avctx->bits_per_raw_sample - 1);
2300− top = 1 << (s->avctx->bits_per_raw_sample - 1);
2302+ for (int i = 0; i < height; i++) {
2303+ output = 1 << (h->c.avctx->bits_per_raw_sample - 1);
2304+ top = 1 << (h->c.avctx->bits_per_raw_sample - 1);
23012305
23022306 for (j = 0; j < w; j++) {
23032307 left = output;
23042308 topleft = top;
23052309
2306− rice_prefix_code = get_unary(&s->gb, 1, 12);
2310+ rice_prefix_code = get_unary(&h->c.gb, 1, 12);
23072311
23082312 /* Escape */
23092313 if (rice_prefix_code == 11)
2310− dpcm_residual = get_bits(&s->gb, s->avctx->bits_per_raw_sample);
2314+ dpcm_residual = get_bits(&h->c.gb, h->c.avctx->bits_per_raw_sample);
23112315 else {
23122316 if (rice_prefix_code == 12) {
2313− av_log(s->avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n");
2317+ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n");
23142318 return AVERROR_INVALIDDATA;
23152319 }
2316− rice_suffix_code = get_bitsz(&s->gb, rice_parameter);
2320+ rice_suffix_code = get_bitsz(&h->c.gb, rice_parameter);
23172321 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
23182322 }
23192323
@@ -2342,56 +2346,56 @@ static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx, · 22 unmodified lines
23422346 if (p2 > p)
23432347 dpcm_residual *= -1;
23442348
2345− macroblock[idx++] = output = (dpcm_residual + p) & ((1 << s->avctx->bits_per_raw_sample) - 1);
2349+ macroblock[idx++] = output = (dpcm_residual + p) & ((1 << h->c.avctx->bits_per_raw_sample) - 1);
23462350 }
23472351 }
23482352
23492353 return 0;
23502354 }
23512355
2352−static int mpeg4_decode_studio_mb(MpegEncContext *s, int16_t block_[12][64])
2356+static int mpeg4_decode_studio_mb(H263DecContext *const h, int16_t block_[12][64])
23532357 {
2354− Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
2358+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
23552359 int i;
23562360
23572361 ctx->dpcm_direction = 0;
23582362
23592363 /* StudioMacroblock */
23602364 /* Assumes I-VOP */
2361− s->mb_intra = 1;
2362− if (get_bits1(&s->gb)) { /* compression_mode */
2365+ h->c.mb_intra = 1;
2366+ if (get_bits1(&h->c.gb)) { /* compression_mode */
23632367 /* DCT */
23642368 /* macroblock_type, 1 or 2-bit VLC */
2365− if (!get_bits1(&s->gb)) {
2366− skip_bits1(&s->gb);
2367− s->qscale = mpeg_get_qscale(s);
2369+ if (!get_bits1(&h->c.gb)) {
2370+ skip_bits1(&h->c.gb);
2371+ h->c.qscale = mpeg_get_qscale(&h->c);
23682372 }
23692373
2370− for (i = 0; i < mpeg4_block_count[s->chroma_format]; i++) {
2371− if (mpeg4_decode_studio_block(s, ctx->block32[i], i) < 0)
2374+ for (i = 0; i < mpeg4_block_count[h->c.chroma_format]; i++) {
2375+ if (mpeg4_decode_studio_block(ctx, ctx->block32[i], i) < 0)
23722376 return AVERROR_INVALIDDATA;
23732377 }
23742378 } else {
23752379 /* DPCM */
2376− check_marker(s->avctx, &s->gb, "DPCM block start");
2377− ctx->dpcm_direction = get_bits1(&s->gb) ? -1 : 1;
2380+ check_marker(h->c.avctx, &h->c.gb, "DPCM block start");
2381+ ctx->dpcm_direction = get_bits1(&h->c.gb) ? -1 : 1;
23782382 for (i = 0; i < 3; i++) {
23792383 if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0)
23802384 return AVERROR_INVALIDDATA;
23812385 }
23822386 }
23832387
2384− if (get_bits_left(&s->gb) >= 24 && show_bits(&s->gb, 23) == 0) {
2385− next_start_code_studio(&s->gb);
2388+ if (get_bits_left(&h->c.gb) >= 24 && show_bits(&h->c.gb, 23) == 0) {
2389+ next_start_code_studio(&h->c.gb);
23862390 return SLICE_END;
23872391 }
23882392
23892393 //vcon-stp9L1.bits (first frame)
2390− if (get_bits_left(&s->gb) == 0)
2394+ if (get_bits_left(&h->c.gb) == 0)
23912395 return SLICE_END;
23922396
23932397 //vcon-stp2L1.bits, vcon-stp3L1.bits, vcon-stp6L1.bits, vcon-stp7L1.bits, vcon-stp8L1.bits, vcon-stp10L1.bits (first frame)
2394− if (get_bits_left(&s->gb) < 8U && show_bits(&s->gb, get_bits_left(&s->gb)) == 0)
2398+ if (get_bits_left(&h->c.gb) < 8U && show_bits(&h->c.gb, get_bits_left(&h->c.gb)) == 0)
23952399 return SLICE_END;
23962400
23972401 return SLICE_OK;
@@ -2550,7 +2554,7 @@ static void extension_and_user_data(MpegEncContext *s, GetBitContext *gb, int id · 152 unmodified lines
25502554
25512555 static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
25522556 {
2553− MpegEncContext *s = &ctx->m;
2557+ MPVContext *const s = &ctx->h.c;
25542558 int width, height, aspect_ratio_info;
25552559 int bits_per_raw_sample;
25562560 int rgb, chroma_format;
@@ -2636,7 +2640,7 @@ static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 79 unmodified lines
26362640
26372641 static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
26382642 {
2639− MpegEncContext *s = &ctx->m;
2643+ H263DecContext *const h = &ctx->h;
26402644 int width, height, vo_ver_id, aspect_ratio_info;
26412645
26422646 /* vol header */
@@ -2650,12 +2654,12 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 7 unmodified lines
26502654 */
26512655 if (ctx->vo_type == CORE_STUDIO_VO_TYPE ||
26522656 ctx->vo_type == SIMPLE_STUDIO_VO_TYPE) {
2653− if (s->avctx->profile != AV_PROFILE_UNKNOWN && s->avctx->profile != AV_PROFILE_MPEG4_SIMPLE_STUDIO)
2657+ if (h->c.avctx->profile != AV_PROFILE_UNKNOWN && h->c.avctx->profile != AV_PROFILE_MPEG4_SIMPLE_STUDIO)
26542658 return AVERROR_INVALIDDATA;
2655− s->studio_profile = 1;
2656− s->avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO;
2659+ h->c.studio_profile = 1;
2660+ h->c.avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO;
26572661 return decode_studio_vol_header(ctx, gb);
2658− } else if (s->studio_profile) {
2662+ } else if (h->c.studio_profile) {
26592663 return AVERROR_PATCHWELCOME;
26602664 }
26612665
@@ -2667,97 +2671,97 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 5 unmodified lines
26672671 }
26682672 aspect_ratio_info = get_bits(gb, 4);
26692673 if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
2670− s->avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width
2671− s->avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height
2674+ h->c.avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width
2675+ h->c.avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height
26722676 } else {
2673− s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[aspect_ratio_info];
2677+ h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[aspect_ratio_info];
26742678 }
26752679
26762680 if ((ctx->vol_control_parameters = get_bits1(gb))) { /* vol control parameter */
26772681 int chroma_format = get_bits(gb, 2);
26782682 if (chroma_format != CHROMA_420)
2679− av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n");
2683+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal chroma format\n");
26802684
2681− s->low_delay = get_bits1(gb);
2685+ h->c.low_delay = get_bits1(gb);
26822686 if (get_bits1(gb)) { /* vbv parameters */
26832687 get_bits(gb, 15); /* first_half_bitrate */
2684− check_marker(s->avctx, gb, "after first_half_bitrate");
2688+ check_marker(h->c.avctx, gb, "after first_half_bitrate");
26852689 get_bits(gb, 15); /* latter_half_bitrate */
2686− check_marker(s->avctx, gb, "after latter_half_bitrate");
2690+ check_marker(h->c.avctx, gb, "after latter_half_bitrate");
26872691 get_bits(gb, 15); /* first_half_vbv_buffer_size */
2688− check_marker(s->avctx, gb, "after first_half_vbv_buffer_size");
2692+ check_marker(h->c.avctx, gb, "after first_half_vbv_buffer_size");
26892693 get_bits(gb, 3); /* latter_half_vbv_buffer_size */
26902694 get_bits(gb, 11); /* first_half_vbv_occupancy */
2691− check_marker(s->avctx, gb, "after first_half_vbv_occupancy");
2695+ check_marker(h->c.avctx, gb, "after first_half_vbv_occupancy");
26922696 get_bits(gb, 15); /* latter_half_vbv_occupancy */
2693− check_marker(s->avctx, gb, "after latter_half_vbv_occupancy");
2697+ check_marker(h->c.avctx, gb, "after latter_half_vbv_occupancy");
26942698 }
26952699 } else {
26962700 /* is setting low delay flag only once the smartest thing to do?
26972701 * low delay detection will not be overridden. */
2698− if (s->picture_number == 0) {
2702+ if (h->c.picture_number == 0) {
26992703 switch (ctx->vo_type) {
27002704 case SIMPLE_VO_TYPE:
27012705 case ADV_SIMPLE_VO_TYPE:
2702− s->low_delay = 1;
2706+ h->c.low_delay = 1;
27032707 break;
27042708 default:
2705− s->low_delay = 0;
2709+ h->c.low_delay = 0;
27062710 }
27072711 }
27082712 }
27092713
27102714 ctx->shape = get_bits(gb, 2); /* vol shape */
27112715 if (ctx->shape != RECT_SHAPE)
2712− av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n");
2716+ av_log(h->c.avctx, AV_LOG_ERROR, "only rectangular vol supported\n");
27132717 if (ctx->shape == GRAY_SHAPE && vo_ver_id != 1) {
2714− av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n");
2718+ av_log(h->c.avctx, AV_LOG_ERROR, "Gray shape not supported\n");
27152719 skip_bits(gb, 4); /* video_object_layer_shape_extension */
27162720 }
27172721
2718− check_marker(s->avctx, gb, "before time_increment_resolution");
2722+ check_marker(h->c.avctx, gb, "before time_increment_resolution");
27192723
2720− s->avctx->framerate.num = get_bits(gb, 16);
2721− if (!s->avctx->framerate.num) {
2722− av_log(s->avctx, AV_LOG_ERROR, "framerate==0\n");
2724+ h->c.avctx->framerate.num = get_bits(gb, 16);
2725+ if (!h->c.avctx->framerate.num) {
2726+ av_log(h->c.avctx, AV_LOG_ERROR, "framerate==0\n");
27232727 return AVERROR_INVALIDDATA;
27242728 }
27252729
2726− ctx->time_increment_bits = av_log2(s->avctx->framerate.num - 1) + 1;
2730+ ctx->time_increment_bits = av_log2(h->c.avctx->framerate.num - 1) + 1;
27272731 if (ctx->time_increment_bits < 1)
27282732 ctx->time_increment_bits = 1;
27292733
2730− check_marker(s->avctx, gb, "before fixed_vop_rate");
2734+ check_marker(h->c.avctx, gb, "before fixed_vop_rate");
27312735
27322736 if (get_bits1(gb) != 0) /* fixed_vop_rate */
2733− s->avctx->framerate.den = get_bits(gb, ctx->time_increment_bits);
2737+ h->c.avctx->framerate.den = get_bits(gb, ctx->time_increment_bits);
27342738 else
2735− s->avctx->framerate.den = 1;
2739+ h->c.avctx->framerate.den = 1;
27362740
27372741 ctx->t_frame = 0;
27382742
27392743 if (ctx->shape != BIN_ONLY_SHAPE) {
27402744 if (ctx->shape == RECT_SHAPE) {
2741− check_marker(s->avctx, gb, "before width");
2745+ check_marker(h->c.avctx, gb, "before width");
27422746 width = get_bits(gb, 13);
2743− check_marker(s->avctx, gb, "before height");
2747+ check_marker(h->c.avctx, gb, "before height");
27442748 height = get_bits(gb, 13);
2745− check_marker(s->avctx, gb, "after height");
2749+ check_marker(h->c.avctx, gb, "after height");
27462750 if (width && height && /* they should be non zero but who knows */
2747− !(s->width && s->codec_tag == AV_RL32("MP4S"))) {
2748− if (s->width && s->height &&
2749− (s->width != width || s->height != height))
2750− s->context_reinit = 1;
2751− s->width = width;
2752− s->height = height;
2751+ !(h->c.width && h->c.codec_tag == AV_RL32("MP4S"))) {
2752+ if (h->c.width && h->c.height &&
2753+ (h->c.width != width || h->c.height != height))
2754+ h->c.context_reinit = 1;
2755+ h->c.width = width;
2756+ h->c.height = height;
27532757 }
27542758 }
27552759
2756− s->progressive_sequence =
2757− s->progressive_frame = get_bits1(gb) ^ 1;
2758− s->interlaced_dct = 0;
2759− if (!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO))
2760− av_log(s->avctx, AV_LOG_INFO, /* OBMC Disable */
2760+ h->c.progressive_sequence =
2761+ h->c.progressive_frame = get_bits1(gb) ^ 1;
2762+ h->c.interlaced_dct = 0;
2763+ if (!get_bits1(gb) && (h->c.avctx->debug & FF_DEBUG_PICT_INFO))
2764+ av_log(h->c.avctx, AV_LOG_INFO, /* OBMC Disable */
27612765 "MPEG-4 OBMC not supported (very likely buggy encoder)\n");
27622766 if (vo_ver_id == 1)
27632767 ctx->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */
@@ -2765,22 +2769,22 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line
27652769 ctx->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */
27662770
27672771 if (ctx->vol_sprite_usage == STATIC_SPRITE)
2768− av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n");
2772+ av_log(h->c.avctx, AV_LOG_ERROR, "Static Sprites not supported\n");
27692773 if (ctx->vol_sprite_usage == STATIC_SPRITE ||
27702774 ctx->vol_sprite_usage == GMC_SPRITE) {
27712775 if (ctx->vol_sprite_usage == STATIC_SPRITE) {
27722776 skip_bits(gb, 13); // sprite_width
2773− check_marker(s->avctx, gb, "after sprite_width");
2777+ check_marker(h->c.avctx, gb, "after sprite_width");
27742778 skip_bits(gb, 13); // sprite_height
2775− check_marker(s->avctx, gb, "after sprite_height");
2779+ check_marker(h->c.avctx, gb, "after sprite_height");
27762780 skip_bits(gb, 13); // sprite_left
2777− check_marker(s->avctx, gb, "after sprite_left");
2781+ check_marker(h->c.avctx, gb, "after sprite_left");
27782782 skip_bits(gb, 13); // sprite_top
2779− check_marker(s->avctx, gb, "after sprite_top");
2783+ check_marker(h->c.avctx, gb, "after sprite_top");
27802784 }
27812785 ctx->num_sprite_warping_points = get_bits(gb, 6);
27822786 if (ctx->num_sprite_warping_points > 3) {
2783− av_log(s->avctx, AV_LOG_ERROR,
2787+ av_log(h->c.avctx, AV_LOG_ERROR,
27842788 "%d sprite_warping_points\n",
27852789 ctx->num_sprite_warping_points);
27862790 ctx->num_sprite_warping_points = 0;
@@ -2796,9 +2800,9 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 9 unmodified lines
27962800 if (get_bits1(gb) == 1) { /* not_8_bit */
27972801 ctx->quant_precision = get_bits(gb, 4); /* quant_precision */
27982802 if (get_bits(gb, 4) != 8) /* bits_per_pixel */
2799− av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n");
2803+ av_log(h->c.avctx, AV_LOG_ERROR, "N-bit not supported\n");
28002804 if (ctx->quant_precision != 5)
2801− av_log(s->avctx, AV_LOG_ERROR,
2805+ av_log(h->c.avctx, AV_LOG_ERROR,
28022806 "quant precision %d\n", ctx->quant_precision);
28032807 if (ctx->quant_precision < 3 || ctx->quant_precision > 9)
28042808 ctx->quant_precision = 5;
@@ -2811,7 +2815,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 6 unmodified lines
28112815 if ((ctx->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */
28122816 int i, v;
28132817
2814− mpeg4_load_default_matrices(s);
2818+ mpeg4_load_default_matrices(&h->c);
28152819
28162820 /* load custom intra matrix */
28172821 if (get_bits1(gb)) {
@@ -2819,7 +2823,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line
28192823 for (i = 0; i < 64; i++) {
28202824 int j;
28212825 if (get_bits_left(gb) < 8) {
2822− av_log(s->avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
2826+ av_log(h->c.avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
28232827 return AVERROR_INVALIDDATA;
28242828 }
28252829 v = get_bits(gb, 8);
@@ -2827,14 +2831,14 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line
28272831 break;
28282832
28292833 last = v;
2830− j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
2831− s->intra_matrix[j] = last;
2834+ j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
2835+ h->c.intra_matrix[j] = last;
28322836 }
28332837
28342838 /* replicate last value */
28352839 for (; i < 64; i++) {
2836− int j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
2837− s->intra_matrix[j] = last;
2840+ int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
2841+ h->c.intra_matrix[j] = last;
28382842 }
28392843 }
28402844
@@ -2844,7 +2848,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 3 unmodified lines
28442848 for (i = 0; i < 64; i++) {
28452849 int j;
28462850 if (get_bits_left(gb) < 8) {
2847− av_log(s->avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
2851+ av_log(h->c.avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
28482852 return AVERROR_INVALIDDATA;
28492853 }
28502854 v = get_bits(gb, 8);
@@ -2852,14 +2856,14 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line
28522856 break;
28532857
28542858 last = v;
2855− j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
2856− s->inter_matrix[j] = v;
2859+ j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
2860+ h->c.inter_matrix[j] = v;
28572861 }
28582862
28592863 /* replicate last value */
28602864 for (; i < 64; i++) {
2861− int j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
2862− s->inter_matrix[j] = last;
2865+ int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
2866+ h->c.inter_matrix[j] = last;
28632867 }
28642868 }
28652869
@@ -2867,12 +2871,12 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 1 unmodified line
28672871 }
28682872
28692873 if (vo_ver_id != 1)
2870− s->quarter_sample = get_bits1(gb);
2874+ h->c.quarter_sample = get_bits1(gb);
28712875 else
2872− s->quarter_sample = 0;
2876+ h->c.quarter_sample = 0;
28732877
28742878 if (get_bits_left(gb) < 4) {
2875− av_log(s->avctx, AV_LOG_ERROR, "VOL Header truncated\n");
2879+ av_log(h->c.avctx, AV_LOG_ERROR, "VOL Header truncated\n");
28762880 return AVERROR_INVALIDDATA;
28772881 }
28782882
@@ -2894,7 +2898,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 15 unmodified lines
28942898 ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter4v_blocks */
28952899 ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* not coded blocks */
28962900 }
2897− if (!check_marker(s->avctx, gb, "in complexity estimation part 1")) {
2901+ if (!check_marker(h->c.avctx, gb, "in complexity estimation part 1")) {
28982902 skip_bits_long(gb, pos - get_bits_count(gb));
28992903 goto no_cplx_est;
29002904 }
@@ -2912,7 +2916,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 11 unmodified lines
29122916 ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel2 */
29132917 ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel4 */
29142918 }
2915− if (!check_marker(s->avctx, gb, "in complexity estimation part 2")) {
2919+ if (!check_marker(h->c.avctx, gb, "in complexity estimation part 2")) {
29162920 skip_bits_long(gb, pos - get_bits_count(gb));
29172921 goto no_cplx_est;
29182922 }
@@ -2921,7 +2925,7 @@ static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb) · 2 unmodified lines
29212925 ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* qpel */
29222926 }
29232927 } else
2924− av_log(s->avctx, AV_LOG_ERROR,
2928+ av_log(h->c.avctx, AV_LOG_ERROR,
29252929 "Invalid Complexity estimation method %d\n",
29262930 estimation_method);
29272931 } else {
@@ -2934,19 +2938,19 @@ no_cplx_est: · 6 unmodified lines
29342938
29352939 ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */
29362940
2937− s->data_partitioning = get_bits1(gb);
2938− if (s->data_partitioning)
2941+ h->c.data_partitioning = get_bits1(gb);
2942+ if (h->c.data_partitioning)
29392943 ctx->rvlc = get_bits1(gb);
29402944
29412945 if (vo_ver_id != 1) {
29422946 ctx->new_pred = get_bits1(gb);
29432947 if (ctx->new_pred) {
2944− av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n");
2948+ av_log(h->c.avctx, AV_LOG_ERROR, "new pred not supported\n");
29452949 skip_bits(gb, 2); /* requested upstream message type */
29462950 skip_bits1(gb); /* newpred segment type */
29472951 }
29482952 if (get_bits1(gb)) // reduced_res_vop
2949− av_log(s->avctx, AV_LOG_ERROR,
2953+ av_log(h->c.avctx, AV_LOG_ERROR,
29502954 "reduced resolution VOP not supported\n");
29512955 } else {
29522956 ctx->new_pred = 0;
@@ -2977,21 +2981,23 @@ no_cplx_est: · 24 unmodified lines
29772981 ctx->scalability = 0;
29782982 *gb = bak;
29792983 } else
2980− av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n");
2984+ av_log(h->c.avctx, AV_LOG_ERROR, "scalability not supported\n");
29812985
29822986 // bin shape stuff FIXME
29832987 }
29842988 }
29852989
2986− if (s->avctx->debug&FF_DEBUG_PICT_INFO) {
2987− 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",
2988− s->avctx->framerate.den, s->avctx->framerate.num,
2990+ if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {
2991+ 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",
2992+ h->c.avctx->framerate.den, h->c.avctx->framerate.num,
29892993 ctx->time_increment_bits,
29902994 ctx->quant_precision,
2991− s->progressive_sequence,
2992− s->low_delay,
2993− ctx->scalability ? "scalability " :"" , s->quarter_sample ? "qpel " : "",
2994− s->data_partitioning ? "partition " : "", ctx->rvlc ? "rvlc " : ""
2995+ h->c.progressive_sequence,
2996+ h->c.low_delay,
2997+ ctx->scalability ? "scalability " :"" ,
2998+ h->c.quarter_sample ? "qpel " : "",
2999+ h->c.data_partitioning ? "partition " : "",
3000+ ctx->rvlc ? "rvlc " : ""
29953001 );
29963002 }
29973003
@@ -3004,7 +3010,7 @@ no_cplx_est: · 6 unmodified lines
30043010 */
30053011 static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
30063012 {
3007− MpegEncContext *s = &ctx->m;
3013+ H263DecContext *const h = &ctx->h;
30083014 char buf[256];
30093015 int i;
30103016 int e;
@@ -3025,7 +3031,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) · 14 unmodified lines
30253031 if (e >= 2) {
30263032 ctx->divx_version = ver;
30273033 ctx->divx_build = build;
3028− s->divx_packed = e == 3 && last == 'p';
3034+ h->c.divx_packed = e == 3 && last == 'p';
30293035 }
30303036
30313037 /* libavcodec detection */
@@ -3036,7 +3042,7 @@ static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb) · 4 unmodified lines
30363042 e = sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
30373043 if (e > 1) {
30383044 if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) {
3039− av_log(s->avctx, AV_LOG_WARNING,
3045+ av_log(h->c.avctx, AV_LOG_WARNING,
30403046 "Unknown Lavc version string encountered, %d.%d.%d; "
30413047 "clamping sub-version values to 8-bits.\n",
30423048 ver, ver2, ver3);
@@ -3091,19 +3097,19 @@ static av_cold void switch_to_xvid_idct(AVCodecContext *const avctx, · 48 unmodified lines
30913097 void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
30923098 {
30933099 Mpeg4DecContext *ctx = avctx->priv_data;
3094− MpegEncContext *s = &ctx->m;
3100+ H263DecContext *const h = &ctx->h;
30953101
30963102 if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) {
3097− if (s->codec_tag == AV_RL32("XVID") ||
3098− s->codec_tag == AV_RL32("XVIX") ||
3099− s->codec_tag == AV_RL32("RMP4") ||
3100− s->codec_tag == AV_RL32("ZMP4") ||
3101− s->codec_tag == AV_RL32("SIPP"))
3103+ if (h->c.codec_tag == AV_RL32("XVID") ||
3104+ h->c.codec_tag == AV_RL32("XVIX") ||
3105+ h->c.codec_tag == AV_RL32("RMP4") ||
3106+ h->c.codec_tag == AV_RL32("ZMP4") ||
3107+ h->c.codec_tag == AV_RL32("SIPP"))
31023108 ctx->xvid_build = 0;
31033109 }
31043110
31053111 if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1)
3106− if (s->codec_tag == AV_RL32("DIVX") && ctx->vo_type == 0 &&
3112+ if (h->c.codec_tag == AV_RL32("DIVX") && ctx->vo_type == 0 &&
31073113 ctx->vol_control_parameters == 0)
31083114 ctx->divx_version = 400; // divx 4
31093115
@@ -3112,68 +3118,68 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx) · 2 unmodified lines
31123118 ctx->divx_build = -1;
31133119 }
31143120
3115− if (s->workaround_bugs & FF_BUG_AUTODETECT) {
3116− if (s->codec_tag == AV_RL32("XVIX"))
3117− s->workaround_bugs |= FF_BUG_XVID_ILACE;
3121+ if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
3122+ if (h->c.codec_tag == AV_RL32("XVIX"))
3123+ h->c.workaround_bugs |= FF_BUG_XVID_ILACE;
31183124
3119− if (s->codec_tag == AV_RL32("UMP4"))
3120− s->workaround_bugs |= FF_BUG_UMP4;
3125+ if (h->c.codec_tag == AV_RL32("UMP4"))
3126+ h->c.workaround_bugs |= FF_BUG_UMP4;
31213127
31223128 if (ctx->divx_version >= 500 && ctx->divx_build < 1814)
3123− s->workaround_bugs |= FF_BUG_QPEL_CHROMA;
3129+ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA;
31243130
31253131 if (ctx->divx_version > 502 && ctx->divx_build < 1814)
3126− s->workaround_bugs |= FF_BUG_QPEL_CHROMA2;
3132+ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA2;
31273133
31283134 if (ctx->xvid_build <= 3U)
3129− s->padding_bug_score = 256 * 256 * 256 * 64;
3135+ h->c.padding_bug_score = 256 * 256 * 256 * 64;
31303136
31313137 if (ctx->xvid_build <= 1U)
3132− s->workaround_bugs |= FF_BUG_QPEL_CHROMA;
3138+ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA;
31333139
31343140 if (ctx->xvid_build <= 12U)
3135− s->workaround_bugs |= FF_BUG_EDGE;
3141+ h->c.workaround_bugs |= FF_BUG_EDGE;
31363142
31373143 if (ctx->xvid_build <= 32U)
3138− s->workaround_bugs |= FF_BUG_DC_CLIP;
3144+ h->c.workaround_bugs |= FF_BUG_DC_CLIP;
31393145
31403146 #define SET_QPEL_FUNC(postfix1, postfix2) \
3141− s->qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
3142− s->qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
3143− s->qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
3147+ h->c.qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
3148+ h->c.qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
3149+ h->c.qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
31443150
31453151 if (ctx->lavc_build < 4653U)
3146− s->workaround_bugs |= FF_BUG_STD_QPEL;
3152+ h->c.workaround_bugs |= FF_BUG_STD_QPEL;
31473153
31483154 if (ctx->lavc_build < 4655U)
3149− s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
3155+ h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
31503156
31513157 if (ctx->lavc_build < 4670U)
3152− s->workaround_bugs |= FF_BUG_EDGE;
3158+ h->c.workaround_bugs |= FF_BUG_EDGE;
31533159
31543160 if (ctx->lavc_build <= 4712U)
3155− s->workaround_bugs |= FF_BUG_DC_CLIP;
3161+ h->c.workaround_bugs |= FF_BUG_DC_CLIP;
31563162
31573163 if ((ctx->lavc_build&0xFF) >= 100) {
31583164 if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752552 &&
31593165 (ctx->lavc_build < 3752037 || ctx->lavc_build > 3752191) // 3.2.1+
31603166 )
3161− s->workaround_bugs |= FF_BUG_IEDGE;
3167+ h->c.workaround_bugs |= FF_BUG_IEDGE;
31623168 }
31633169
31643170 if (ctx->divx_version >= 0)
3165− s->workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
3171+ h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
31663172 if (ctx->divx_version == 501 && ctx->divx_build == 20020416)
3167− s->padding_bug_score = 256 * 256 * 256 * 64;
3173+ h->c.padding_bug_score = 256 * 256 * 256 * 64;
31683174
31693175 if (ctx->divx_version < 500U)
3170− s->workaround_bugs |= FF_BUG_EDGE;
3176+ h->c.workaround_bugs |= FF_BUG_EDGE;
31713177
31723178 if (ctx->divx_version >= 0)
3173− s->workaround_bugs |= FF_BUG_HPEL_CHROMA;
3179+ h->c.workaround_bugs |= FF_BUG_HPEL_CHROMA;
31743180 }
31753181
3176− if (s->workaround_bugs & FF_BUG_STD_QPEL) {
3182+ if (h->c.workaround_bugs & FF_BUG_STD_QPEL) {
31773183 SET_QPEL_FUNC(qpel_pixels_tab[0][5], qpel16_mc11_old_c)
31783184 SET_QPEL_FUNC(qpel_pixels_tab[0][7], qpel16_mc31_old_c)
31793185 SET_QPEL_FUNC(qpel_pixels_tab[0][9], qpel16_mc12_old_c)
@@ -3190,54 +3196,54 @@ void ff_mpeg4_workaround_bugs(AVCodecContext *avctx) · 10 unmodified lines
31903196 }
31913197
31923198 if (avctx->debug & FF_DEBUG_BUGS)
3193− av_log(s->avctx, AV_LOG_DEBUG,
3199+ av_log(h->c.avctx, AV_LOG_DEBUG,
31943200 "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
3195− s->workaround_bugs, ctx->lavc_build, ctx->xvid_build,
3196− ctx->divx_version, ctx->divx_build, s->divx_packed ? "p" : "");
3201+ h->c.workaround_bugs, ctx->lavc_build, ctx->xvid_build,
3202+ ctx->divx_version, ctx->divx_build, h->c.divx_packed ? "p" : "");
31973203
31983204 if (CONFIG_MPEG4_DECODER && ctx->xvid_build >= 0 &&
3199− avctx->idct_algo == FF_IDCT_AUTO && !s->studio_profile) {
3200− switch_to_xvid_idct(avctx, s);
3205+ avctx->idct_algo == FF_IDCT_AUTO && !h->c.studio_profile) {
3206+ switch_to_xvid_idct(avctx, &h->c);
32013207 }
32023208 }
32033209
32043210 static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
32053211 int parse_only)
32063212 {
3207− MpegEncContext *s = &ctx->m;
3213+ H263DecContext *const h = &ctx->h;
32083214 int time_incr, time_increment;
32093215 int64_t pts;
32103216
3211− s->mcsel = 0;
3212− s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */
3213− if (s->pict_type == AV_PICTURE_TYPE_B && s->low_delay &&
3214− ctx->vol_control_parameters == 0 && !(s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) {
3215− av_log(s->avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n");
3216− s->low_delay = 0;
3217+ h->c.mcsel = 0;
3218+ h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */
3219+ if (h->c.pict_type == AV_PICTURE_TYPE_B && h->c.low_delay &&
3220+ ctx->vol_control_parameters == 0 && !(h->c.avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) {
3221+ av_log(h->c.avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n");
3222+ h->c.low_delay = 0;
32173223 }
32183224
3219− s->partitioned_frame = s->data_partitioning && s->pict_type != AV_PICTURE_TYPE_B;
3220− if (s->partitioned_frame)
3221− s->decode_mb = mpeg4_decode_partitioned_mb;
3225+ h->c.partitioned_frame = h->c.data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B;
3226+ if (h->c.partitioned_frame)
3227+ h->decode_mb = mpeg4_decode_partitioned_mb;
32223228 else
3223− s->decode_mb = mpeg4_decode_mb;
3229+ h->decode_mb = mpeg4_decode_mb;
32243230
32253231 time_incr = 0;
32263232 while (get_bits1(gb) != 0)
32273233 time_incr++;
32283234
3229− check_marker(s->avctx, gb, "before time_increment");
3235+ check_marker(h->c.avctx, gb, "before time_increment");
32303236
32313237 if (ctx->time_increment_bits == 0 ||
32323238 !(show_bits(gb, ctx->time_increment_bits + 1) & 1)) {
3233− av_log(s->avctx, AV_LOG_WARNING,
3239+ av_log(h->c.avctx, AV_LOG_WARNING,
32343240 "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);
32353241
32363242 for (ctx->time_increment_bits = 1;
32373243 ctx->time_increment_bits < 16;
32383244 ctx->time_increment_bits++) {
3239− if (s->pict_type == AV_PICTURE_TYPE_P ||
3240− (s->pict_type == AV_PICTURE_TYPE_S &&
3245+ if (h->c.pict_type == AV_PICTURE_TYPE_P ||
3246+ (h->c.pict_type == AV_PICTURE_TYPE_S &&
32413247 ctx->vol_sprite_usage == GMC_SPRITE)) {
32423248 if ((show_bits(gb, ctx->time_increment_bits + 6) & 0x37) == 0x30)
32433249 break;
@@ -3245,7 +3251,7 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 1 unmodified line
32453251 break;
32463252 }
32473253
3248− av_log(s->avctx, AV_LOG_WARNING,
3254+ av_log(h->c.avctx, AV_LOG_WARNING,
32493255 "time_increment_bits set to %d bits, based on bitstream analysis\n", ctx->time_increment_bits);
32503256 }
32513257
@@ -3254,84 +3260,84 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 2 unmodified lines
32543260 else
32553261 time_increment = get_bits(gb, ctx->time_increment_bits);
32563262
3257− if (s->pict_type != AV_PICTURE_TYPE_B) {
3258− s->last_time_base = s->time_base;
3259− s->time_base += time_incr;
3260− s->time = s->time_base * (int64_t)s->avctx->framerate.num + time_increment;
3261− if (s->workaround_bugs & FF_BUG_UMP4) {
3262− if (s->time < s->last_non_b_time) {
3263+ if (h->c.pict_type != AV_PICTURE_TYPE_B) {
3264+ h->c.last_time_base = h->c.time_base;
3265+ h->c.time_base += time_incr;
3266+ h->c.time = h->c.time_base * (int64_t)h->c.avctx->framerate.num + time_increment;
3267+ if (h->c.workaround_bugs & FF_BUG_UMP4) {
3268+ if (h->c.time < h->c.last_non_b_time) {
32633269 /* header is not mpeg-4-compatible, broken encoder,
32643270 * trying to workaround */
3265− s->time_base++;
3266− s->time += s->avctx->framerate.num;
3271+ h->c.time_base++;
3272+ h->c.time += h->c.avctx->framerate.num;
32673273 }
32683274 }
3269− s->pp_time = s->time - s->last_non_b_time;
3270− s->last_non_b_time = s->time;
3275+ h->c.pp_time = h->c.time - h->c.last_non_b_time;
3276+ h->c.last_non_b_time = h->c.time;
32713277 } else {
3272− s->time = (s->last_time_base + time_incr) * (int64_t)s->avctx->framerate.num + time_increment;
3273− s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
3274− if (s->pp_time <= s->pb_time ||
3275− s->pp_time <= s->pp_time - s->pb_time ||
3276− s->pp_time <= 0) {
3278+ h->c.time = (h->c.last_time_base + time_incr) * (int64_t)h->c.avctx->framerate.num + time_increment;
3279+ h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
3280+ if (h->c.pp_time <= h->c.pb_time ||
3281+ h->c.pp_time <= h->c.pp_time - h->c.pb_time ||
3282+ h->c.pp_time <= 0) {
32773283 /* messed up order, maybe after seeking? skipping current B-frame */
32783284 return FRAME_SKIPPED;
32793285 }
3280− ff_mpeg4_init_direct_mv(s);
3286+ ff_mpeg4_init_direct_mv(&h->c);
32813287
32823288 if (ctx->t_frame == 0)
3283− ctx->t_frame = s->pb_time;
3289+ ctx->t_frame = h->c.pb_time;
32843290 if (ctx->t_frame == 0)
32853291 ctx->t_frame = 1; // 1/0 protection
3286− s->pp_field_time = (ROUNDED_DIV(s->last_non_b_time, ctx->t_frame) -
3287− ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2;
3288− s->pb_field_time = (ROUNDED_DIV(s->time, ctx->t_frame) -
3289− ROUNDED_DIV(s->last_non_b_time - s->pp_time, ctx->t_frame)) * 2;
3290− if (s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1) {
3291− s->pb_field_time = 2;
3292− s->pp_field_time = 4;
3293− if (!s->progressive_sequence)
3292+ h->c.pp_field_time = (ROUNDED_DIV(h->c.last_non_b_time, ctx->t_frame) -
3293+ ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2;
3294+ h->c.pb_field_time = (ROUNDED_DIV(h->c.time, ctx->t_frame) -
3295+ ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2;
3296+ if (h->c.pp_field_time <= h->c.pb_field_time || h->c.pb_field_time <= 1) {
3297+ h->c.pb_field_time = 2;
3298+ h->c.pp_field_time = 4;
3299+ if (!h->c.progressive_sequence)
32943300 return FRAME_SKIPPED;
32953301 }
32963302 }
32973303
3298− if (s->avctx->framerate.den)
3299− pts = ROUNDED_DIV(s->time, s->avctx->framerate.den);
3304+ if (h->c.avctx->framerate.den)
3305+ pts = ROUNDED_DIV(h->c.time, h->c.avctx->framerate.den);
33003306 else
33013307 pts = AV_NOPTS_VALUE;
3302− ff_dlog(s->avctx, "MPEG4 PTS: %"PRId64"\n", pts);
3308+ ff_dlog(h->c.avctx, "MPEG4 PTS: %"PRId64"\n", pts);
33033309
3304− check_marker(s->avctx, gb, "before vop_coded");
3310+ check_marker(h->c.avctx, gb, "before vop_coded");
33053311
33063312 /* vop coded */
33073313 if (get_bits1(gb) != 1) {
3308− if (s->avctx->debug & FF_DEBUG_PICT_INFO)
3309− av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n");
3310− s->skipped_last_frame = 1;
3314+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
3315+ av_log(h->c.avctx, AV_LOG_ERROR, "vop not coded\n");
3316+ h->c.skipped_last_frame = 1;
33113317 return FRAME_SKIPPED;
33123318 }
33133319 if (ctx->new_pred)
33143320 decode_new_pred(ctx, gb);
33153321
33163322 if (ctx->shape != BIN_ONLY_SHAPE &&
3317− (s->pict_type == AV_PICTURE_TYPE_P ||
3318− (s->pict_type == AV_PICTURE_TYPE_S &&
3323+ (h->c.pict_type == AV_PICTURE_TYPE_P ||
3324+ (h->c.pict_type == AV_PICTURE_TYPE_S &&
33193325 ctx->vol_sprite_usage == GMC_SPRITE))) {
33203326 /* rounding type for motion estimation */
3321− s->no_rounding = get_bits1(gb);
3327+ h->c.no_rounding = get_bits1(gb);
33223328 } else {
3323− s->no_rounding = 0;
3329+ h->c.no_rounding = 0;
33243330 }
33253331 // FIXME reduced res stuff
33263332
33273333 if (ctx->shape != RECT_SHAPE) {
3328− if (ctx->vol_sprite_usage != 1 || s->pict_type != AV_PICTURE_TYPE_I) {
3334+ if (ctx->vol_sprite_usage != 1 || h->c.pict_type != AV_PICTURE_TYPE_I) {
33293335 skip_bits(gb, 13); /* width */
3330− check_marker(s->avctx, gb, "after width");
3336+ check_marker(h->c.avctx, gb, "after width");
33313337 skip_bits(gb, 13); /* height */
3332− check_marker(s->avctx, gb, "after height");
3338+ check_marker(h->c.avctx, gb, "after height");
33333339 skip_bits(gb, 13); /* hor_spat_ref */
3334− check_marker(s->avctx, gb, "after hor_spat_ref");
3340+ check_marker(h->c.avctx, gb, "after hor_spat_ref");
33353341 skip_bits(gb, 13); /* ver_spat_ref */
33363342 }
33373343 skip_bits1(gb); /* change_CR_disable */
@@ -3344,21 +3350,21 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 6 unmodified lines
33443350
33453351 if (ctx->shape != BIN_ONLY_SHAPE) {
33463352 skip_bits_long(gb, ctx->cplx_estimation_trash_i);
3347− if (s->pict_type != AV_PICTURE_TYPE_I)
3353+ if (h->c.pict_type != AV_PICTURE_TYPE_I)
33483354 skip_bits_long(gb, ctx->cplx_estimation_trash_p);
3349− if (s->pict_type == AV_PICTURE_TYPE_B)
3355+ if (h->c.pict_type == AV_PICTURE_TYPE_B)
33503356 skip_bits_long(gb, ctx->cplx_estimation_trash_b);
33513357
33523358 if (get_bits_left(gb) < 3) {
3353− av_log(s->avctx, AV_LOG_ERROR, "Header truncated\n");
3359+ av_log(h->c.avctx, AV_LOG_ERROR, "Header truncated\n");
33543360 return AVERROR_INVALIDDATA;
33553361 }
33563362 ctx->intra_dc_threshold = ff_mpeg4_dc_threshold[get_bits(gb, 3)];
3357− if (!s->progressive_sequence) {
3358− s->top_field_first = get_bits1(gb);
3359− s->alternate_scan = get_bits1(gb);
3363+ if (!h->c.progressive_sequence) {
3364+ h->c.top_field_first = get_bits1(gb);
3365+ h->c.alternate_scan = get_bits1(gb);
33603366 } else
3361− s->alternate_scan = 0;
3367+ h->c.alternate_scan = 0;
33623368 }
33633369 /* Skip at this point when only parsing since the remaining
33643370 * data is not useful for a parser and requires the
@@ -3366,28 +3372,28 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 1 unmodified line
33663372 if (parse_only)
33673373 goto end;
33683374
3369− if (s->alternate_scan) {
3370− ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);
3371− ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_vertical_scan,
3372− s->idsp.idct_permutation);
3375+ if (h->c.alternate_scan) {
3376+ ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_alternate_vertical_scan);
3377+ ff_permute_scantable(h->c.permutated_intra_h_scantable, ff_alternate_vertical_scan,
3378+ h->c.idsp.idct_permutation);
33733379 } else {
3374− ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
3375− ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_horizontal_scan,
3376− s->idsp.idct_permutation);
3380+ ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_zigzag_direct);
3381+ ff_permute_scantable(h->c.permutated_intra_h_scantable, ff_alternate_horizontal_scan,
3382+ h->c.idsp.idct_permutation);
33773383 }
3378− ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
3379− s->idsp.idct_permutation);
3384+ ff_permute_scantable(h->c.permutated_intra_v_scantable, ff_alternate_vertical_scan,
3385+ h->c.idsp.idct_permutation);
33803386
3381− if (s->pict_type == AV_PICTURE_TYPE_S) {
3387+ if (h->c.pict_type == AV_PICTURE_TYPE_S) {
33823388 if((ctx->vol_sprite_usage == STATIC_SPRITE ||
33833389 ctx->vol_sprite_usage == GMC_SPRITE)) {
33843390 if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0)
33853391 return AVERROR_INVALIDDATA;
33863392 if (ctx->sprite_brightness_change)
3387− av_log(s->avctx, AV_LOG_ERROR,
3393+ av_log(h->c.avctx, AV_LOG_ERROR,
33883394 "sprite_brightness_change not supported\n");
33893395 if (ctx->vol_sprite_usage == STATIC_SPRITE)
3390− av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n");
3396+ av_log(h->c.avctx, AV_LOG_ERROR, "static sprite not supported\n");
33913397 } else {
33923398 memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset));
33933399 memset(ctx->sprite_delta, 0, sizeof(ctx->sprite_delta));
@@ -3397,102 +3403,102 @@ static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb, · 3 unmodified lines
33973403 ctx->f_code = 1;
33983404 ctx->b_code = 1;
33993405 if (ctx->shape != BIN_ONLY_SHAPE) {
3400− s->chroma_qscale = s->qscale = get_bits(gb, ctx->quant_precision);
3401− if (s->qscale == 0) {
3402− av_log(s->avctx, AV_LOG_ERROR,
3406+ h->c.chroma_qscale = h->c.qscale = get_bits(gb, ctx->quant_precision);
3407+ if (h->c.qscale == 0) {
3408+ av_log(h->c.avctx, AV_LOG_ERROR,
34033409 "Error, header damaged or not MPEG-4 header (qscale=0)\n");
34043410 return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then
34053411 }
34063412
3407− if (s->pict_type != AV_PICTURE_TYPE_I) {
3413+ if (h->c.pict_type != AV_PICTURE_TYPE_I) {
34083414 ctx->f_code = get_bits(gb, 3); /* fcode_for */
34093415 if (ctx->f_code == 0) {
3410− av_log(s->avctx, AV_LOG_ERROR,
3416+ av_log(h->c.avctx, AV_LOG_ERROR,
34113417 "Error, header damaged or not MPEG-4 header (f_code=0)\n");
34123418 ctx->f_code = 1;
34133419 return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then
34143420 }
34153421 }
34163422
3417− if (s->pict_type == AV_PICTURE_TYPE_B) {
3423+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
34183424 ctx->b_code = get_bits(gb, 3);
34193425 if (ctx->b_code == 0) {
3420− av_log(s->avctx, AV_LOG_ERROR,
3426+ av_log(h->c.avctx, AV_LOG_ERROR,
34213427 "Error, header damaged or not MPEG4 header (b_code=0)\n");
34223428 ctx->b_code=1;
34233429 return AVERROR_INVALIDDATA; // makes no sense to continue, as the MV decoding will break very quickly
34243430 }
34253431 }
34263432
3427− if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
3428− av_log(s->avctx, AV_LOG_DEBUG,
3433+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
3434+ av_log(h->c.avctx, AV_LOG_DEBUG,
34293435 "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",
3430− s->qscale, ctx->f_code, ctx->b_code,
3431− 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')),
3432− gb->size_in_bits,s->progressive_sequence, s->alternate_scan,
3433− s->top_field_first, s->quarter_sample ? 'q' : 'h',
3434− s->data_partitioning, ctx->resync_marker,
3436+ h->c.qscale, ctx->f_code, ctx->b_code,
3437+ 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')),
3438+ gb->size_in_bits,h->c.progressive_sequence, h->c.alternate_scan,
3439+ h->c.top_field_first, h->c.quarter_sample ? 'q' : 'h',
3440+ h->c.data_partitioning, ctx->resync_marker,
34353441 ctx->num_sprite_warping_points, ctx->sprite_warping_accuracy,
3436− 1 - s->no_rounding, ctx->vo_type,
3442+ 1 - h->c.no_rounding, ctx->vo_type,
34373443 ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold,
34383444 ctx->cplx_estimation_trash_i, ctx->cplx_estimation_trash_p,
34393445 ctx->cplx_estimation_trash_b,
3440− s->time,
3446+ h->c.time,
34413447 time_increment
34423448 );
34433449 }
34443450
34453451 if (!ctx->scalability) {
3446− if (ctx->shape != RECT_SHAPE && s->pict_type != AV_PICTURE_TYPE_I)
3452+ if (ctx->shape != RECT_SHAPE && h->c.pict_type != AV_PICTURE_TYPE_I)
34473453 skip_bits1(gb); // vop shape coding type
34483454 } else {
34493455 if (ctx->enhancement_type) {
34503456 int load_backward_shape = get_bits1(gb);
34513457 if (load_backward_shape)
3452− av_log(s->avctx, AV_LOG_ERROR,
3458+ av_log(h->c.avctx, AV_LOG_ERROR,
34533459 "load backward shape isn't supported\n");
34543460 }
34553461 skip_bits(gb, 2); // ref_select_code
34563462 }
34573463 }
34583464
3459− s->dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
3460− : ctx->dct_unquantize_h263_intra;
3465+ h->c.dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
3466+ : ctx->dct_unquantize_h263_intra;
34613467 // The following tells ff_mpv_reconstruct_mb() to unquantize iff mpeg_quant
3462− s->dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
3468+ h->c.dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
34633469
34643470 end:
34653471 /* detect buggy encoders which don't set the low_delay flag
34663472 * (divx4/xvid/opendivx). Note we cannot detect divx5 without B-frames
34673473 * easily (although it's buggy too) */
34683474 if (ctx->vo_type == 0 && ctx->vol_control_parameters == 0 &&
3469− ctx->divx_version == -1 && s->picture_number == 0) {
3470− av_log(s->avctx, AV_LOG_WARNING,
3475+ ctx->divx_version == -1 && h->c.picture_number == 0) {
3476+ av_log(h->c.avctx, AV_LOG_WARNING,
34713477 "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
3472− s->low_delay = 1;
3478+ h->c.low_delay = 1;
34733479 }
34743480
3475− s->picture_number++; // better than pic number==0 always ;)
3481+ h->c.picture_number++; // better than pic number==0 always ;)
34763482
3477− if (s->workaround_bugs & FF_BUG_EDGE) {
3478− s->h_edge_pos = s->width;
3479− s->v_edge_pos = s->height;
3483+ if (h->c.workaround_bugs & FF_BUG_EDGE) {
3484+ h->c.h_edge_pos = h->c.width;
3485+ h->c.v_edge_pos = h->c.height;
34803486 }
34813487 return 0;
34823488 }
34833489
34843490 static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb)
34853491 {
3486− MpegEncContext *s = &ctx->m;
3492+ AVCodecContext *const avctx = ctx->h.c.avctx;
34873493
34883494 skip_bits(gb, 16); /* Time_code[63..48] */
3489− check_marker(s->avctx, gb, "after Time_code[63..48]");
3495+ check_marker(avctx, gb, "after Time_code[63..48]");
34903496 skip_bits(gb, 16); /* Time_code[47..32] */
3491− check_marker(s->avctx, gb, "after Time_code[47..32]");
3497+ check_marker(avctx, gb, "after Time_code[47..32]");
34923498 skip_bits(gb, 16); /* Time_code[31..16] */
3493− check_marker(s->avctx, gb, "after Time_code[31..16]");
3499+ check_marker(avctx, gb, "after Time_code[31..16]");
34943500 skip_bits(gb, 16); /* Time_code[15..0] */
3495− check_marker(s->avctx, gb, "after Time_code[15..0]");
3501+ check_marker(avctx, gb, "after Time_code[15..0]");
34963502 skip_bits(gb, 4); /* reserved_bits */
34973503 }
34983504
@@ -3502,64 +3508,63 @@ static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb) · 3 unmodified lines
35023508 */
35033509 static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
35043510 {
3505− MpegEncContext *s = &ctx->m;
3511+ H263DecContext *const h = &ctx->h;
35063512
35073513 if (get_bits_left(gb) <= 32)
35083514 return 0;
35093515
3510− s->partitioned_frame = 0;
3511− s->interlaced_dct = 0;
3512− s->decode_mb = mpeg4_decode_studio_mb;
3516+ h->c.partitioned_frame = 0;
3517+ h->c.interlaced_dct = 0;
3518+ h->decode_mb = mpeg4_decode_studio_mb;
35133519
35143520 decode_smpte_tc(ctx, gb);
35153521
35163522 skip_bits(gb, 10); /* temporal_reference */
35173523 skip_bits(gb, 2); /* vop_structure */
3518− s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */
3524+ h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */
35193525 if (get_bits1(gb)) { /* vop_coded */
35203526 skip_bits1(gb); /* top_field_first */
35213527 skip_bits1(gb); /* repeat_first_field */
3522− s->progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */
3528+ h->c.progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */
35233529 }
35243530
3525− if (s->pict_type == AV_PICTURE_TYPE_I) {
3531+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
35263532 if (get_bits1(gb))
35273533 reset_studio_dc_predictors(ctx);
35283534 }
35293535
35303536 if (ctx->shape != BIN_ONLY_SHAPE) {
3531− s->alternate_scan = get_bits1(gb);
3532− s->frame_pred_frame_dct = get_bits1(gb);
3533− ctx->dct_precision = get_bits(gb, 2);
3534− s->intra_dc_precision = get_bits(gb, 2);
3535− s->q_scale_type = get_bits1(gb);
3537+ h->c.alternate_scan = get_bits1(gb);
3538+ h->c.frame_pred_frame_dct = get_bits1(gb);
3539+ ctx->dct_precision = get_bits(gb, 2);
3540+ h->c.intra_dc_precision = get_bits(gb, 2);
3541+ h->c.q_scale_type = get_bits1(gb);
35363542 }
35373543
3538− ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable,
3539− s->alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct);
3544+ ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable,
3545+ h->c.alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct);
35403546
3541− mpeg4_load_default_matrices(s);
3547+ mpeg4_load_default_matrices(&h->c);
35423548
35433549 next_start_code_studio(gb);
3544− extension_and_user_data(s, gb, 4);
3550+ extension_and_user_data(&h->c, gb, 4);
35453551
35463552 return 0;
35473553 }
35483554
35493555 static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
35503556 {
3551− MpegEncContext *s = &ctx->m;
35523557 int visual_object_type;
35533558
35543559 skip_bits(gb, 4); /* visual_object_verid */
35553560 visual_object_type = get_bits(gb, 4);
35563561 if (visual_object_type != VOT_VIDEO_ID) {
3557− avpriv_request_sample(s->avctx, "VO type %u", visual_object_type);
3562+ avpriv_request_sample(ctx->h.c.avctx, "VO type %u", visual_object_type);
35583563 return AVERROR_PATCHWELCOME;
35593564 }
35603565
35613566 next_start_code_studio(gb);
3562− extension_and_user_data(s, gb, 1);
3567+ extension_and_user_data(&ctx->h.c, gb, 1);
35633568
35643569 return 0;
35653570 }
@@ -3577,7 +3582,7 @@ static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb) · 11 unmodified lines
35773582 int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
35783583 int header, int parse_only)
35793584 {
3580− MpegEncContext *s = &ctx->m;
3585+ MPVContext *const s = &ctx->h.c;
35813586 unsigned startcode, v;
35823587 int ret;
35833588 int vol = 0;
@@ -3731,22 +3736,22 @@ end: · 147 unmodified lines
37313736 return decode_vop_header(ctx, gb, parse_only);
37323737 }
37333738
3734−int ff_mpeg4_decode_picture_header(MpegEncContext *s)
3739+int ff_mpeg4_decode_picture_header(H263DecContext *const h)
37353740 {
3736− Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
3741+ Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
37373742
3738− s->skipped_last_frame = 0;
3743+ h->c.skipped_last_frame = 0;
37393744
37403745 if (ctx->bitstream_buffer) {
3741− int buf_size = get_bits_left(&s->gb) / 8U;
3746+ int buf_size = get_bits_left(&h->c.gb) / 8U;
37423747 int bitstream_buffer_size = ctx->bitstream_buffer->size;
3743− const uint8_t *buf = s->gb.buffer;
3748+ const uint8_t *buf = h->c.gb.buffer;
37443749
3745− if (s->divx_packed) {
3750+ if (h->c.divx_packed) {
37463751 for (int i = 0; i < buf_size - 3; i++) {
37473752 if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) {
37483753 if (buf[i+3] == 0xB0) {
3749− av_log(s->avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
3754+ av_log(h->c.avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
37503755 bitstream_buffer_size = 0;
37513756 }
37523757 break;
@@ -3754,8 +3759,8 @@ int ff_mpeg4_decode_picture_header(MpegEncContext *s) · 1 unmodified line
37543759 }
37553760 }
37563761 ctx->bitstream_buffer->size = 0;
3757− if (bitstream_buffer_size && (s->divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder
3758− int ret = init_get_bits8(&s->gb, ctx->bitstream_buffer->data,
3762+ if (bitstream_buffer_size && (h->c.divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder
3763+ int ret = init_get_bits8(&h->c.gb, ctx->bitstream_buffer->data,
37593764 bitstream_buffer_size);
37603765 if (ret < 0)
37613766 return ret;
@@ -3763,20 +3768,20 @@ int ff_mpeg4_decode_picture_header(MpegEncContext *s) · 1 unmodified line
37633768 av_buffer_unref(&ctx->bitstream_buffer);
37643769 }
37653770
3766− return ff_mpeg4_parse_picture_header(ctx, &s->gb, 0, 0);
3771+ return ff_mpeg4_parse_picture_header(ctx, &h->c.gb, 0, 0);
37673772 }
37683773
37693774 int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
37703775 {
37713776 Mpeg4DecContext *ctx = avctx->priv_data;
3772− MpegEncContext *s = &ctx->m;
3777+ H263DecContext *const h = &ctx->h;
37733778 int ret;
37743779
37753780 av_assert1(!ctx->bitstream_buffer || !ctx->bitstream_buffer->size);
37763781
37773782 /* divx 5.01+ bitstream reorder stuff */
3778− if (s->divx_packed) {
3779− int current_pos = ctx->bitstream_buffer && s->gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&s->gb) >> 3);
3783+ if (h->c.divx_packed) {
3784+ int current_pos = ctx->bitstream_buffer && h->c.gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->c.gb) >> 3);
37803785 int startcode_found = 0;
37813786 uint8_t *buf = pkt->data;
37823787 int buf_size = pkt->size;
@@ -3797,7 +3802,7 @@ int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt) · 14 unmodified lines
37973802
37983803 if (startcode_found) {
37993804 if (!ctx->showed_packed_warning) {
3800− av_log(s->avctx, AV_LOG_INFO, "Video uses a non-standard and "
3805+ av_log(h->c.avctx, AV_LOG_INFO, "Video uses a non-standard and "
38013806 "wasteful way to store B-frames ('packed B-frames'). "
38023807 "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n");
38033808 ctx->showed_packed_warning = 1;
@@ -3874,11 +3879,11 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 70 unmodified lines
38743879 {
38753880 Mpeg4DecContext *s = dst->priv_data;
38763881 const Mpeg4DecContext *s1 = src->priv_data;
3877− int init = s->m.context_initialized;
3882+ int init = s->h.c.context_initialized;
38783883 int ret;
38793884
38803885 if (!init) {
3881− ret = update_mpvctx(&s->m, &s1->m);
3886+ ret = update_mpvctx(&s->h.c, &s1->h.c);
38823887 if (ret < 0)
38833888 return ret;
38843889 }
@@ -3894,7 +3899,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 9 unmodified lines
38943899 s->sprite_brightness_change = s1->sprite_brightness_change;
38953900 s->sprite_warping_accuracy = s1->sprite_warping_accuracy;
38963901 s->num_sprite_warping_points = s1->num_sprite_warping_points;
3897− s->m.data_partitioning = s1->m.data_partitioning;
3902+ s->h.c.data_partitioning = s1->h.c.data_partitioning;
38983903 s->mpeg_quant = s1->mpeg_quant;
38993904 s->rvlc = s1->rvlc;
39003905 s->resync_marker = s1->resync_marker;
@@ -3903,7 +3908,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 2 unmodified lines
39033908 s->enhancement_type = s1->enhancement_type;
39043909 s->scalability = s1->scalability;
39053910 s->intra_dc_threshold = s1->intra_dc_threshold;
3906− s->m.divx_packed = s1->m.divx_packed;
3911+ s->h.c.divx_packed = s1->h.c.divx_packed;
39073912 s->divx_version = s1->divx_version;
39083913 s->divx_build = s1->divx_build;
39093914 s->xvid_build = s1->xvid_build;
@@ -3915,7 +3920,7 @@ static int mpeg4_update_thread_context(AVCodecContext *dst, · 5 unmodified lines
39153920 s->cplx_estimation_trash_p = s1->cplx_estimation_trash_p;
39163921 s->cplx_estimation_trash_b = s1->cplx_estimation_trash_b;
39173922 s->rgb = s1->rgb;
3918− s->m.skipped_last_frame = s1->m.skipped_last_frame;
3923+ s->h.c.skipped_last_frame = s1->h.c.skipped_last_frame;
39193924
39203925 memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift));
39213926 memcpy(s->sprite_traj, s1->sprite_traj, sizeof(s1->sprite_traj));
@@ -3985,7 +3990,7 @@ static av_cold int decode_init(AVCodecContext *avctx) · 63 unmodified lines
39853990 {
39863991 static AVOnce init_static_once = AV_ONCE_INIT;
39873992 Mpeg4DecContext *ctx = avctx->priv_data;
3988− MpegEncContext *s = &ctx->m;
3993+ H263DecContext *const h = &ctx->h;
39893994 MPVUnquantDSPContext unquant_dsp_ctx;
39903995 int ret;
39913996
@@ -4006,18 +4011,18 @@ static av_cold int decode_init(AVCodecContext *avctx) · 14 unmodified lines
40064011 // so that is all we keep.
40074012 ctx->dct_unquantize_mpeg2_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
40084013
4009− s->y_dc_scale_table = ff_mpeg4_y_dc_scale_table;
4010− s->c_dc_scale_table = ff_mpeg4_c_dc_scale_table;
4014+ h->c.y_dc_scale_table = ff_mpeg4_y_dc_scale_table;
4015+ h->c.c_dc_scale_table = ff_mpeg4_c_dc_scale_table;
40114016
4012− s->h263_pred = 1;
4013− s->low_delay = 0; /* default, might be overridden in the vol header during header parsing */
4014− s->decode_mb = mpeg4_decode_mb;
4017+ h->c.h263_pred = 1;
4018+ h->c.low_delay = 0; /* default, might be overridden in the vol header during header parsing */
4019+ h->decode_mb = mpeg4_decode_mb;
40154020 ctx->time_increment_bits = 4; /* default value for broken headers */
40164021 ctx->quant_precision = 5;
40174022
40184023 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
40194024
4020− ff_qpeldsp_init(&s->qdsp);
4025+ ff_qpeldsp_init(&h->c.qdsp);
40214026 ff_mpeg4videodsp_init(&ctx->mdsp);
40224027
40234028 ff_thread_once(&init_static_once, mpeg4_init_static);
libavcodec/mpeg4videodec.h+7−6
@@ -26,13 +26,14 @@ · 25 unmodified lines
2626 #include <stdint.h>
2727
2828 #include "get_bits.h"
29+#include "h263dec.h"
2930 #include "mpegvideo.h"
3031 #include "mpeg4videodsp.h"
3132
3233 #include "libavutil/mem_internal.h"
3334
3435 typedef struct Mpeg4DecContext {
35− MpegEncContext m;
36+ H263DecContext h;
3637
3738 int f_code; ///< forward MV resolution
3839 int b_code; ///< backward MV resolution for B-frames
@@ -108,7 +109,7 @@ typedef struct Mpeg4DecContext { · 69 unmodified lines
108109 int dct_precision;
109110 } Mpeg4DecContext;
110111
111−int ff_mpeg4_decode_picture_header(MpegEncContext *s);
112+int ff_mpeg4_decode_picture_header(H263DecContext *const h);
112113 int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
113114 int header, int parse_only);
114115 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 · 2 unmodified lines
117118 void ff_mpeg4_mcsel_motion(MpegEncContext *s,
118119 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
119120 uint8_t *const *ref_picture);
120−int ff_mpeg4_decode_partitions(MPVContext *const s);
121−int ff_mpeg4_decode_video_packet_header(MPVContext *const s);
122−int ff_mpeg4_decode_studio_slice_header(MPVContext *const s);
121+int ff_mpeg4_decode_partitions(H263DecContext *const h);
122+int ff_mpeg4_decode_video_packet_header(H263DecContext *const h);
123+int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h);
123124 void ff_mpeg4_workaround_bugs(AVCodecContext *avctx);
124−void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n,
125+void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n,
125126 int dir);
126127 int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt);
127128
libavcodec/mpegvideo.h+0−1
@@ -307,7 +307,6 @@ typedef struct MpegEncContext { · 306 unmodified lines
307307 int first_field; ///< is 1 for the first field of a field picture 0 otherwise
308308
309309 int16_t (*block)[64];
310− int (*decode_mb)(struct MpegEncContext *s, int16_t block[12][64]); // used by some codecs to avoid a switch()
311310
312311 #define SLICE_OK 0
313312 #define SLICE_ERROR -1
libavcodec/msmpeg4dec.c+258−247
@@ -74,23 +74,24 @@ static VLCElem v2_mb_type_vlc[128]; · 73 unmodified lines
7474 VLCElem ff_inter_intra_vlc[8];
7575
7676 /* This is identical to H.263 except that its range is multiplied by 2. */
77−static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
77+static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code)
7878 {
7979 int code, val, sign, shift;
8080
81− code = get_vlc2(&s->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
82− ff_dlog(s->avctx, "MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
81+ code = get_vlc2(&h->c.gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
82+ ff_dlog(h->c.avctx, "MV code %d at %d %d pred: %d\n",
83+ code, h->c.mb_x,h->c.mb_y, pred);
8384 if (code < 0)
8485 return 0xffff;
8586
8687 if (code == 0)
8788 return pred;
88− sign = get_bits1(&s->gb);
89+ sign = get_bits1(&h->c.gb);
8990 shift = f_code - 1;
9091 val = code;
9192 if (shift) {
9293 val = (val - 1) << shift;
93− val |= get_bits(&s->gb, shift);
94+ val |= get_bits(&h->c.gb, shift);
9495 val++;
9596 }
9697 if (sign)
@@ -105,151 +106,155 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) · 8 unmodified lines
105106 return val;
106107 }
107108
108−static int msmpeg4v12_decode_mb(MpegEncContext *s, int16_t block[6][64])
109+static int msmpeg4v12_decode_mb(H263DecContext *const h, int16_t block[6][64])
109110 {
110− MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
111+ MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
111112 int cbp, code, i;
112− uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride];
113+ uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride];
113114
114− if (s->pict_type == AV_PICTURE_TYPE_P) {
115+ if (h->c.pict_type == AV_PICTURE_TYPE_P) {
115116 if (ms->use_skip_mb_code) {
116− if (get_bits1(&s->gb)) {
117+ if (get_bits1(&h->c.gb)) {
117118 /* skip mb */
118− s->mb_intra = 0;
119+ h->c.mb_intra = 0;
119120 for(i=0;i<6;i++)
120− s->block_last_index[i] = -1;
121− s->mv_dir = MV_DIR_FORWARD;
122− s->mv_type = MV_TYPE_16X16;
123− s->mv[0][0][0] = 0;
124− s->mv[0][0][1] = 0;
125− s->mb_skipped = 1;
121+ h->c.block_last_index[i] = -1;
122+ h->c.mv_dir = MV_DIR_FORWARD;
123+ h->c.mv_type = MV_TYPE_16X16;
124+ h->c.mv[0][0][0] = 0;
125+ h->c.mv[0][0][1] = 0;
126+ h->c.mb_skipped = 1;
126127 *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
127128 return 0;
128129 }
129130 }
130131
131− if (s->msmpeg4_version == MSMP4_V2)
132− code = get_vlc2(&s->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1);
132+ if (h->c.msmpeg4_version == MSMP4_V2)
133+ code = get_vlc2(&h->c.gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1);
133134 else
134− code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
135+ code = get_vlc2(&h->c.gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
135136 if(code<0 || code>7){
136− av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
137+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",
138+ code, h->c.mb_x, h->c.mb_y);
137139 return -1;
138140 }
139141
140− s->mb_intra = code >>2;
142+ h->c.mb_intra = code >>2;
141143
142144 cbp = code & 0x3;
143145 } else {
144− s->mb_intra = 1;
145− if (s->msmpeg4_version == MSMP4_V2)
146− cbp = get_vlc2(&s->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1);
146+ h->c.mb_intra = 1;
147+ if (h->c.msmpeg4_version == MSMP4_V2)
148+ cbp = get_vlc2(&h->c.gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1);
147149 else
148− cbp = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
150+ cbp = get_vlc2(&h->c.gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
149151 if(cbp<0 || cbp>3){
150− av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
152+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",
153+ cbp, h->c.mb_x, h->c.mb_y);
151154 return -1;
152155 }
153156 }
154157
155− if (!s->mb_intra) {
158+ if (!h->c.mb_intra) {
156159 int mx, my, cbpy;
157160
158− cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
161+ cbpy = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
159162 if(cbpy<0){
160− av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
163+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n",
164+ cbp, h->c.mb_x, h->c.mb_y);
161165 return -1;
162166 }
163167
164168 cbp|= cbpy<<2;
165− if (s->msmpeg4_version == MSMP4_V1 || (cbp&3) != 3)
169+ if (h->c.msmpeg4_version == MSMP4_V1 || (cbp&3) != 3)
166170 cbp ^= 0x3C;
167171
168− ff_h263_pred_motion(s, 0, 0, &mx, &my);
169− mx= msmpeg4v2_decode_motion(s, mx, 1);
170− my= msmpeg4v2_decode_motion(s, my, 1);
172+ ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);
173+ mx = msmpeg4v2_decode_motion(h, mx, 1);
174+ my = msmpeg4v2_decode_motion(h, my, 1);
171175
172− s->mv_dir = MV_DIR_FORWARD;
173− s->mv_type = MV_TYPE_16X16;
174− s->mv[0][0][0] = mx;
175− s->mv[0][0][1] = my;
176+ h->c.mv_dir = MV_DIR_FORWARD;
177+ h->c.mv_type = MV_TYPE_16X16;
178+ h->c.mv[0][0][0] = mx;
179+ h->c.mv[0][0][1] = my;
176180 *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
177181 } else {
178182 int v;
179− if (s->msmpeg4_version == MSMP4_V2) {
180− s->ac_pred = get_bits1(&s->gb);
181− v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
183+ if (h->c.msmpeg4_version == MSMP4_V2) {
184+ h->c.ac_pred = get_bits1(&h->c.gb);
185+ v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
182186 if (v < 0) {
183− av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
187+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
184188 return -1;
185189 }
186190 cbp|= v<<2;
187191 } else{
188− s->ac_pred = 0;
189− v = get_vlc2(&s->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
192+ h->c.ac_pred = 0;
193+ v = get_vlc2(&h->c.gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
190194 if (v < 0) {
191− av_log(s->avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
195+ av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
192196 return -1;
193197 }
194198 cbp|= v<<2;
195− if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
199+ if (h->c.pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
196200 }
197201 *mb_type_ptr = MB_TYPE_INTRA;
198202 }
199203
200− s->bdsp.clear_blocks(s->block[0]);
204+ h->c.bdsp.clear_blocks(h->c.block[0]);
201205 for (i = 0; i < 6; i++) {
202206 if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
203207 {
204− av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
208+ av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
209+ h->c.mb_x, h->c.mb_y, i);
205210 return -1;
206211 }
207212 }
208213 return 0;
209214 }
210215
211−static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64])
216+static int msmpeg4v34_decode_mb(H263DecContext *const h, int16_t block[6][64])
212217 {
213− MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
218+ MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
214219 int cbp, code, i;
215220 uint8_t *coded_val;
216− uint32_t * const mb_type_ptr = &s->cur_pic.mb_type[s->mb_x + s->mb_y*s->mb_stride];
221+ uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride];
217222
218− if (get_bits_left(&s->gb) <= 0)
223+ if (get_bits_left(&h->c.gb) <= 0)
219224 return AVERROR_INVALIDDATA;
220225
221− if (s->pict_type == AV_PICTURE_TYPE_P) {
226+ if (h->c.pict_type == AV_PICTURE_TYPE_P) {
222227 if (ms->use_skip_mb_code) {
223− if (get_bits1(&s->gb)) {
228+ if (get_bits1(&h->c.gb)) {
224229 /* skip mb */
225− s->mb_intra = 0;
230+ h->c.mb_intra = 0;
226231 for(i=0;i<6;i++)
227− s->block_last_index[i] = -1;
228− s->mv_dir = MV_DIR_FORWARD;
229− s->mv_type = MV_TYPE_16X16;
230− s->mv[0][0][0] = 0;
231− s->mv[0][0][1] = 0;
232− s->mb_skipped = 1;
232+ h->c.block_last_index[i] = -1;
233+ h->c.mv_dir = MV_DIR_FORWARD;
234+ h->c.mv_type = MV_TYPE_16X16;
235+ h->c.mv[0][0][0] = 0;
236+ h->c.mv[0][0][1] = 0;
237+ h->c.mb_skipped = 1;
233238 *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
234239
235240 return 0;
236241 }
237242 }
238243
239− code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
240− //s->mb_intra = (code & 0x40) ? 0 : 1;
241− s->mb_intra = (~code & 0x40) >> 6;
244+ code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
245+ //h->c.mb_intra = (code & 0x40) ? 0 : 1;
246+ h->c.mb_intra = (~code & 0x40) >> 6;
242247
243248 cbp = code & 0x3f;
244249 } else {
245− s->mb_intra = 1;
246− code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
250+ h->c.mb_intra = 1;
251+ code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
247252 /* predict coded block pattern */
248253 cbp = 0;
249254 for(i=0;i<6;i++) {
250255 int val = ((code >> (5 - i)) & 1);
251256 if (i < 4) {
252− int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
257+ int pred = ff_msmpeg4_coded_block_pred(&h->c, i, &coded_val);
253258 val = val ^ pred;
254259 *coded_val = val;
255260 }
@@ -257,41 +262,42 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 1 unmodified line
257262 }
258263 }
259264
260− if (!s->mb_intra) {
265+ if (!h->c.mb_intra) {
261266 int mx, my;
262267 if (ms->per_mb_rl_table && cbp) {
263− ms->rl_table_index = decode012(&s->gb);
268+ ms->rl_table_index = decode012(&h->c.gb);
264269 ms->rl_chroma_table_index = ms->rl_table_index;
265270 }
266− ff_h263_pred_motion(s, 0, 0, &mx, &my);
271+ ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);
267272 ff_msmpeg4_decode_motion(ms, &mx, &my);
268− s->mv_dir = MV_DIR_FORWARD;
269− s->mv_type = MV_TYPE_16X16;
270− s->mv[0][0][0] = mx;
271− s->mv[0][0][1] = my;
273+ h->c.mv_dir = MV_DIR_FORWARD;
274+ h->c.mv_type = MV_TYPE_16X16;
275+ h->c.mv[0][0][0] = mx;
276+ h->c.mv[0][0][1] = my;
272277 *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
273278 } else {
274− ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
279+ ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
275280 ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
276− show_bits(&s->gb, 24));
277− s->ac_pred = get_bits1(&s->gb);
281+ show_bits(&h->c.gb, 24));
282+ h->c.ac_pred = get_bits1(&h->c.gb);
278283 *mb_type_ptr = MB_TYPE_INTRA;
279− if(s->inter_intra_pred){
280− s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
281− ff_dlog(s->avctx, "%d%d %d %d/",
282− s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
284+ if (h->c.inter_intra_pred) {
285+ h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
286+ ff_dlog(h->c.avctx, "%d%d %d %d/",
287+ h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
283288 }
284289 if (ms->per_mb_rl_table && cbp) {
285− ms->rl_table_index = decode012(&s->gb);
290+ ms->rl_table_index = decode012(&h->c.gb);
286291 ms->rl_chroma_table_index = ms->rl_table_index;
287292 }
288293 }
289294
290− s->bdsp.clear_blocks(s->block[0]);
295+ h->c.bdsp.clear_blocks(h->c.block[0]);
291296 for (i = 0; i < 6; i++) {
292297 if (ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
293298 {
294− av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
299+ av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
300+ h->c.mb_x, h->c.mb_y, i);
295301 return -1;
296302 }
297303 }
@@ -357,7 +363,7 @@ static av_cold void msmpeg4_decode_init_static(void) · 59 unmodified lines
357363 av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
358364 {
359365 static AVOnce init_static_once = AV_ONCE_INIT;
360− MpegEncContext *s = avctx->priv_data;
366+ H263DecContext *const h = avctx->priv_data;
361367 int ret;
362368
363369 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) · 3 unmodified lines
367373 return -1;
368374
369375 // We unquantize inter blocks as we parse them.
370− s->dct_unquantize_inter = NULL;
376+ h->c.dct_unquantize_inter = NULL;
371377
372− ff_msmpeg4_common_init(s);
378+ ff_msmpeg4_common_init(&h->c);
373379
374− switch (s->msmpeg4_version) {
380+ switch (h->c.msmpeg4_version) {
375381 case MSMP4_V1:
376382 case MSMP4_V2:
377− s->decode_mb= msmpeg4v12_decode_mb;
383+ h->decode_mb = msmpeg4v12_decode_mb;
378384 break;
379385 case MSMP4_V3:
380386 case MSMP4_WMV1:
381− s->decode_mb= msmpeg4v34_decode_mb;
387+ h->decode_mb = msmpeg4v34_decode_mb;
382388 break;
383389 case MSMP4_WMV2:
384390 break;
@@ -386,16 +392,16 @@ av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx) · 1 unmodified line
386392 av_unreachable("List contains all cases using ff_msmpeg4_decode_init()");
387393 }
388394
389− s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe
395+ h->c.slice_height = h->c.mb_height; //to avoid 1/0 if the first frame is not a keyframe
390396
391397 ff_thread_once(&init_static_once, msmpeg4_decode_init_static);
392398
393399 return 0;
394400 }
395401
396−int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
402+int ff_msmpeg4_decode_picture_header(H263DecContext *const h)
397403 {
398− MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
404+ MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
399405 int code;
400406
401407 // 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) · 1 unmodified line
403409 // smallest "black/skip" frame generally contain not much recoverable content
404410 // while at the same time they have the highest computational requirements
405411 // per byte
406− if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
412+ if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
407413 return AVERROR_INVALIDDATA;
408414
409− if (s->msmpeg4_version == MSMP4_V1) {
410− int start_code = get_bits_long(&s->gb, 32);
415+ if (h->c.msmpeg4_version == MSMP4_V1) {
416+ int start_code = get_bits_long(&h->c.gb, 32);
411417 if(start_code!=0x00000100){
412− av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
418+ av_log(h->c.avctx, AV_LOG_ERROR, "invalid startcode\n");
413419 return -1;
414420 }
415421
416− skip_bits(&s->gb, 5); // frame number */
422+ skip_bits(&h->c.gb, 5); // frame number */
417423 }
418424
419− s->pict_type = get_bits(&s->gb, 2) + 1;
420− if (s->pict_type != AV_PICTURE_TYPE_I &&
421− s->pict_type != AV_PICTURE_TYPE_P){
422− av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
425+ h->c.pict_type = get_bits(&h->c.gb, 2) + 1;
426+ if (h->c.pict_type != AV_PICTURE_TYPE_I &&
427+ h->c.pict_type != AV_PICTURE_TYPE_P){
428+ av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n");
423429 return -1;
424430 }
425− s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
426− if(s->qscale==0){
427− av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
431+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
432+ if (h->c.qscale == 0) {
433+ av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n");
428434 return -1;
429435 }
430436
431− if (s->pict_type == AV_PICTURE_TYPE_I) {
432− code = get_bits(&s->gb, 5);
433− if (s->msmpeg4_version == MSMP4_V1) {
434− if(code==0 || code>s->mb_height){
435− av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
437+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
438+ code = get_bits(&h->c.gb, 5);
439+ if (h->c.msmpeg4_version == MSMP4_V1) {
440+ if(code==0 || code>h->c.mb_height) {
441+ av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
436442 return -1;
437443 }
438444
439− s->slice_height = code;
445+ h->c.slice_height = code;
440446 }else{
441447 /* 0x17: one slice, 0x18: two slices, ... */
442448 if (code < 0x17){
443− av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
449+ av_log(h->c.avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
444450 return -1;
445451 }
446452
447− s->slice_height = s->mb_height / (code - 0x16);
453+ h->c.slice_height = h->c.mb_height / (code - 0x16);
448454 }
449455
450− switch(s->msmpeg4_version){
456+ switch (h->c.msmpeg4_version) {
451457 case MSMP4_V1:
452458 case MSMP4_V2:
453459 ms->rl_chroma_table_index = 2;
@@ -456,102 +462,102 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) · 2 unmodified lines
456462 ms->dc_table_index = 0; //not used
457463 break;
458464 case MSMP4_V3:
459− ms->rl_chroma_table_index = decode012(&s->gb);
460− ms->rl_table_index = decode012(&s->gb);
465+ ms->rl_chroma_table_index = decode012(&h->c.gb);
466+ ms->rl_table_index = decode012(&h->c.gb);
461467
462− ms->dc_table_index = get_bits1(&s->gb);
468+ ms->dc_table_index = get_bits1(&h->c.gb);
463469 break;
464470 case MSMP4_WMV1:
465− ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
471+ ff_msmpeg4_decode_ext_header(h, (2+5+5+17+7)/8);
466472
467473 if (ms->bit_rate > MBAC_BITRATE)
468− ms->per_mb_rl_table = get_bits1(&s->gb);
474+ ms->per_mb_rl_table = get_bits1(&h->c.gb);
469475 else
470476 ms->per_mb_rl_table = 0;
471477
472478 if (!ms->per_mb_rl_table) {
473− ms->rl_chroma_table_index = decode012(&s->gb);
474− ms->rl_table_index = decode012(&s->gb);
479+ ms->rl_chroma_table_index = decode012(&h->c.gb);
480+ ms->rl_table_index = decode012(&h->c.gb);
475481 }
476482
477− ms->dc_table_index = get_bits1(&s->gb);
478− s->inter_intra_pred= 0;
483+ ms->dc_table_index = get_bits1(&h->c.gb);
484+ h->c.inter_intra_pred= 0;
479485 break;
480486 default:
481487 av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
482488 }
483− s->no_rounding = 1;
484− if(s->avctx->debug&FF_DEBUG_PICT_INFO)
485− av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
486− s->qscale,
489+ h->c.no_rounding = 1;
490+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
491+ av_log(h->c.avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
492+ h->c.qscale,
487493 ms->rl_chroma_table_index,
488494 ms->rl_table_index,
489495 ms->dc_table_index,
490496 ms->per_mb_rl_table,
491− s->slice_height);
497+ h->c.slice_height);
492498 } else {
493− switch(s->msmpeg4_version){
499+ switch (h->c.msmpeg4_version) {
494500 case MSMP4_V1:
495501 case MSMP4_V2:
496− if (s->msmpeg4_version == MSMP4_V1)
502+ if (h->c.msmpeg4_version == MSMP4_V1)
497503 ms->use_skip_mb_code = 1;
498504 else
499− ms->use_skip_mb_code = get_bits1(&s->gb);
505+ ms->use_skip_mb_code = get_bits1(&h->c.gb);
500506 ms->rl_table_index = 2;
501507 ms->rl_chroma_table_index = ms->rl_table_index;
502508 ms->dc_table_index = 0; //not used
503509 ms->mv_table_index = 0;
504510 break;
505511 case MSMP4_V3:
506− ms->use_skip_mb_code = get_bits1(&s->gb);
507− ms->rl_table_index = decode012(&s->gb);
512+ ms->use_skip_mb_code = get_bits1(&h->c.gb);
513+ ms->rl_table_index = decode012(&h->c.gb);
508514 ms->rl_chroma_table_index = ms->rl_table_index;
509515
510− ms->dc_table_index = get_bits1(&s->gb);
516+ ms->dc_table_index = get_bits1(&h->c.gb);
511517
512− ms->mv_table_index = get_bits1(&s->gb);
518+ ms->mv_table_index = get_bits1(&h->c.gb);
513519 break;
514520 case MSMP4_WMV1:
515− ms->use_skip_mb_code = get_bits1(&s->gb);
521+ ms->use_skip_mb_code = get_bits1(&h->c.gb);
516522
517523 if (ms->bit_rate > MBAC_BITRATE)
518− ms->per_mb_rl_table = get_bits1(&s->gb);
524+ ms->per_mb_rl_table = get_bits1(&h->c.gb);
519525 else
520526 ms->per_mb_rl_table = 0;
521527
522528 if (!ms->per_mb_rl_table) {
523− ms->rl_table_index = decode012(&s->gb);
529+ ms->rl_table_index = decode012(&h->c.gb);
524530 ms->rl_chroma_table_index = ms->rl_table_index;
525531 }
526532
527− ms->dc_table_index = get_bits1(&s->gb);
533+ ms->dc_table_index = get_bits1(&h->c.gb);
528534
529− ms->mv_table_index = get_bits1(&s->gb);
530− s->inter_intra_pred = s->width*s->height < 320*240 &&
535+ ms->mv_table_index = get_bits1(&h->c.gb);
536+ h->c.inter_intra_pred = h->c.width*h->c.height < 320*240 &&
531537 ms->bit_rate <= II_BITRATE;
532538 break;
533539 default:
534540 av_unreachable("ff_msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
535541 }
536542
537− if(s->avctx->debug&FF_DEBUG_PICT_INFO)
538− av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
543+ if (h->c.avctx->debug&FF_DEBUG_PICT_INFO)
544+ av_log(h->c.avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
539545 ms->use_skip_mb_code,
540546 ms->rl_table_index,
541547 ms->rl_chroma_table_index,
542548 ms->dc_table_index,
543549 ms->mv_table_index,
544550 ms->per_mb_rl_table,
545− s->qscale);
551+ h->c.qscale);
546552
547553 if (ms->flipflop_rounding) {
548− s->no_rounding ^= 1;
554+ h->c.no_rounding ^= 1;
549555 }else{
550− s->no_rounding = 0;
556+ h->c.no_rounding = 0;
551557 }
552558 }
553− ff_dlog(s->avctx, "%d %d %d %d %d\n", s->pict_type, ms->bit_rate,
554− s->inter_intra_pred, s->width, s->height);
559+ ff_dlog(h->c.avctx, "%d %d %d %d %d\n", h->c.pict_type, ms->bit_rate,
560+ h->c.inter_intra_pred, h->c.width, h->c.height);
555561
556562 ms->esc3_level_length = 0;
557563 ms->esc3_run_length = 0;
@@ -559,30 +565,30 @@ int ff_msmpeg4_decode_picture_header(MpegEncContext * s) · 1 unmodified line
559565 return 0;
560566 }
561567
562−int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
568+int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)
563569 {
564− MSMP4DecContext *const ms = mpv_to_msmpeg4(s);
565− int left= buf_size*8 - get_bits_count(&s->gb);
566− int length = s->msmpeg4_version >= MSMP4_V3 ? 17 : 16;
570+ MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
571+ int left= buf_size*8 - get_bits_count(&h->c.gb);
572+ int length = h->c.msmpeg4_version >= MSMP4_V3 ? 17 : 16;
567573 /* the alt_bitstream reader could read over the end so we need to check it */
568574 if(left>=length && left<length+8)
569575 {
570− skip_bits(&s->gb, 5); /* fps */
571− ms->bit_rate = get_bits(&s->gb, 11) * 1024;
572− if (s->msmpeg4_version >= MSMP4_V3)
573− ms->flipflop_rounding = get_bits1(&s->gb);
576+ skip_bits(&h->c.gb, 5); /* fps */
577+ ms->bit_rate = get_bits(&h->c.gb, 11) * 1024;
578+ if (h->c.msmpeg4_version >= MSMP4_V3)
579+ ms->flipflop_rounding = get_bits1(&h->c.gb);
574580 else
575581 ms->flipflop_rounding = 0;
576582 }
577583 else if(left<length+8)
578584 {
579585 ms->flipflop_rounding = 0;
580− if (s->msmpeg4_version != MSMP4_V2)
581− av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
586+ if (h->c.msmpeg4_version != MSMP4_V2)
587+ av_log(h->c.avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
582588 }
583589 else
584590 {
585− av_log(s->avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n");
591+ av_log(h->c.avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n");
586592 }
587593
588594 return 0;
@@ -590,52 +596,52 @@ int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size) · 1 unmodified line
590596
591597 static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
592598 {
593− MpegEncContext *const s = &ms->m;
599+ H263DecContext *const h = &ms->h;
594600 int level, pred;
595601
596− if (s->msmpeg4_version <= MSMP4_V2) {
602+ if (h->c.msmpeg4_version <= MSMP4_V2) {
597603 if (n < 4) {
598− level = get_vlc2(&s->gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
604+ level = get_vlc2(&h->c.gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
599605 } else {
600− level = get_vlc2(&s->gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
606+ level = get_vlc2(&h->c.gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
601607 }
602608 if (level < 0) {
603− av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
609+ av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
604610 *dir_ptr = 0;
605611 return -1;
606612 }
607613 level-=256;
608614 } else {
609− level = get_vlc2(&s->gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
615+ level = get_vlc2(&h->c.gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
610616 MSMP4_DC_VLC_BITS, 3);
611617
612618 if (level == DC_MAX) {
613− level = get_bits(&s->gb, 8);
614− if (get_bits1(&s->gb))
619+ level = get_bits(&h->c.gb, 8);
620+ if (get_bits1(&h->c.gb))
615621 level = -level;
616622 } else if (level != 0) {
617− if (get_bits1(&s->gb))
623+ if (get_bits1(&h->c.gb))
618624 level = -level;
619625 }
620626 }
621627
622− if (s->msmpeg4_version == MSMP4_V1) {
628+ if (h->c.msmpeg4_version == MSMP4_V1) {
623629 int32_t *dc_val;
624− pred = msmpeg4v1_pred_dc(s, n, &dc_val);
630+ pred = msmpeg4v1_pred_dc(&h->c, n, &dc_val);
625631 level += pred;
626632
627633 /* update predictor */
628634 *dc_val= level;
629635 }else{
630636 int16_t *dc_val;
631− pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
637+ pred = ff_msmpeg4_pred_dc(&h->c, n, &dc_val, dir_ptr);
632638 level += pred;
633639
634640 /* update predictor */
635641 if (n < 4) {
636− *dc_val = level * s->y_dc_scale;
642+ *dc_val = level * h->c.y_dc_scale;
637643 } else {
638− *dc_val = level * s->c_dc_scale;
644+ *dc_val = level * h->c.c_dc_scale;
639645 }
640646 }
641647
@@ -645,14 +651,14 @@ static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr) · 3 unmodified lines
645651 int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
646652 int n, int coded, const uint8_t *scan_table)
647653 {
648− MpegEncContext *const s = &ms->m;
654+ H263DecContext *const h = &ms->h;
649655 int level, i, last, run, run_diff;
650656 int dc_pred_dir = -1; //unused but its passed around, so it needs to be initialized
651657 const RLTable *rl;
652658 const RL_VLC_ELEM *rl_vlc;
653659 int qmul, qadd;
654660
655− if (s->mb_intra) {
661+ if (h->c.mb_intra) {
656662 qmul=1;
657663 qadd=0;
658664
@@ -660,110 +666,113 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 1 unmodified line
660666 level = msmpeg4_decode_dc(ms, n, &dc_pred_dir);
661667
662668 if (level < 0){
663− av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
664− if(s->inter_intra_pred) level=0;
669+ av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, h->c.qscale);
670+ if (h->c.inter_intra_pred)
671+ level = 0;
665672 }
666673 if (n < 4) {
667674 rl = &ff_rl_table[ms->rl_table_index];
668− if(level > 256*s->y_dc_scale){
669− av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
670− if(!s->inter_intra_pred) return -1;
675+ if (level > 256 * h->c.y_dc_scale) {
676+ av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", h->c.qscale);
677+ if (!h->c.inter_intra_pred)
678+ return -1;
671679 }
672680 } else {
673681 rl = &ff_rl_table[3 + ms->rl_chroma_table_index];
674− if(level > 256*s->c_dc_scale){
675− av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
676− if(!s->inter_intra_pred) return -1;
682+ if (level > 256 * h->c.c_dc_scale) {
683+ av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", h->c.qscale);
684+ if (!h->c.inter_intra_pred)
685+ return -1;
677686 }
678687 }
679688 block[0] = level;
680689
681− run_diff = s->msmpeg4_version >= MSMP4_WMV1;
690+ run_diff = h->c.msmpeg4_version >= MSMP4_WMV1;
682691 i = 0;
683692 if (!coded) {
684693 goto not_coded;
685694 }
686− if (s->ac_pred) {
695+ if (h->c.ac_pred) {
687696 if (dc_pred_dir == 0)
688− scan_table = s->permutated_intra_v_scantable; /* left */
697+ scan_table = h->c.permutated_intra_v_scantable; /* left */
689698 else
690− scan_table = s->permutated_intra_h_scantable; /* top */
699+ scan_table = h->c.permutated_intra_h_scantable; /* top */
691700 } else {
692− scan_table = s->intra_scantable.permutated;
701+ scan_table = h->c.intra_scantable.permutated;
693702 }
694703 rl_vlc= rl->rl_vlc[0];
695704 } else {
696− qmul = s->qscale << 1;
697− qadd = (s->qscale - 1) | 1;
705+ qmul = h->c.qscale << 1;
706+ qadd = (h->c.qscale - 1) | 1;
698707 i = -1;
699708 rl = &ff_rl_table[3 + ms->rl_table_index];
700709
701− if (s->msmpeg4_version == MSMP4_V2)
710+ if (h->c.msmpeg4_version == MSMP4_V2)
702711 run_diff = 0;
703712 else
704713 run_diff = 1;
705714
706715 if (!coded) {
707− s->block_last_index[n] = i;
716+ h->c.block_last_index[n] = i;
708717 return 0;
709718 }
710719 if(!scan_table)
711− scan_table = s->inter_scantable.permutated;
712− rl_vlc= rl->rl_vlc[s->qscale];
720+ scan_table = h->c.inter_scantable.permutated;
721+ rl_vlc= rl->rl_vlc[h->c.qscale];
713722 }
714723 {
715− OPEN_READER(re, &s->gb);
724+ OPEN_READER(re, &h->c.gb);
716725 for(;;) {
717− UPDATE_CACHE(re, &s->gb);
718− GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
726+ UPDATE_CACHE(re, &h->c.gb);
727+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 0);
719728 if (level==0) {
720729 int cache;
721− cache= GET_CACHE(re, &s->gb);
730+ cache= GET_CACHE(re, &h->c.gb);
722731 /* escape */
723− if (s->msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {
724− if (s->msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {
732+ if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {
733+ if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {
725734 /* third escape */
726− if (s->msmpeg4_version != MSMP4_V1)
727− LAST_SKIP_BITS(re, &s->gb, 2);
728− UPDATE_CACHE(re, &s->gb);
729− if (s->msmpeg4_version <= MSMP4_V3) {
730− last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
731− run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
732− level= SHOW_SBITS(re, &s->gb, 8);
733− SKIP_COUNTER(re, &s->gb, 1+6+8);
735+ if (h->c.msmpeg4_version != MSMP4_V1)
736+ LAST_SKIP_BITS(re, &h->c.gb, 2);
737+ UPDATE_CACHE(re, &h->c.gb);
738+ if (h->c.msmpeg4_version <= MSMP4_V3) {
739+ last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_CACHE(re, &h->c.gb, 1);
740+ run = SHOW_UBITS(re, &h->c.gb, 6); SKIP_CACHE(re, &h->c.gb, 6);
741+ level = SHOW_SBITS(re, &h->c.gb, 8);
742+ SKIP_COUNTER(re, &h->c.gb, 1 + 6 + 8);
734743 }else{
735744 int sign;
736− last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
745+ last = SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1);
737746 if (!ms->esc3_level_length) {
738747 int ll;
739− ff_dlog(s->avctx, "ESC-3 %X at %d %d\n",
740− show_bits(&s->gb, 24), s->mb_x, s->mb_y);
741− if(s->qscale<8){
742− ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
748+ ff_dlog(h->c.avctx, "ESC-3 %X at %d %d\n",
749+ show_bits(&h->c.gb, 24), h->c.mb_x, h->c.mb_y);
750+ if (h->c.qscale < 8) {
751+ ll = SHOW_UBITS(re, &h->c.gb, 3); SKIP_BITS(re, &h->c.gb, 3);
743752 if(ll==0){
744− ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
753+ ll = 8+SHOW_UBITS(re, &h->c.gb, 1); SKIP_BITS(re, &h->c.gb, 1);
745754 }
746755 }else{
747756 ll=2;
748− while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
757+ while (ll < 8 && SHOW_UBITS(re, &h->c.gb, 1) == 0) {
749758 ll++;
750− SKIP_BITS(re, &s->gb, 1);
759+ SKIP_BITS(re, &h->c.gb, 1);
751760 }
752− if(ll<8) SKIP_BITS(re, &s->gb, 1);
761+ if (ll<8) SKIP_BITS(re, &h->c.gb, 1);
753762 }
754763
755764 ms->esc3_level_length = ll;
756− ms->esc3_run_length = SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
757− UPDATE_CACHE(re, &s->gb);
765+ ms->esc3_run_length = SHOW_UBITS(re, &h->c.gb, 2) + 3; SKIP_BITS(re, &h->c.gb, 2);
766+ UPDATE_CACHE(re, &h->c.gb);
758767 }
759− run = SHOW_UBITS(re, &s->gb, ms->esc3_run_length);
760− SKIP_BITS(re, &s->gb, ms->esc3_run_length);
768+ run = SHOW_UBITS(re, &h->c.gb, ms->esc3_run_length);
769+ SKIP_BITS(re, &h->c.gb, ms->esc3_run_length);
761770
762− sign= SHOW_UBITS(re, &s->gb, 1);
763− SKIP_BITS(re, &s->gb, 1);
771+ sign= SHOW_UBITS(re, &h->c.gb, 1);
772+ SKIP_BITS(re, &h->c.gb, 1);
764773
765− level = SHOW_UBITS(re, &s->gb, ms->esc3_level_length);
766− SKIP_BITS(re, &s->gb, ms->esc3_level_length);
774+ level = SHOW_UBITS(re, &h->c.gb, ms->esc3_level_length);
775+ SKIP_BITS(re, &h->c.gb, ms->esc3_level_length);
767776 if(sign) level= -level;
768777 }
769778
@@ -774,38 +783,40 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 4 unmodified lines
774783 if(last) i+=192;
775784 } else {
776785 /* second escape */
777− SKIP_BITS(re, &s->gb, 2);
778− GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
786+ SKIP_BITS(re, &h->c.gb, 2);
787+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
779788 i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
780− level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
781− LAST_SKIP_BITS(re, &s->gb, 1);
789+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
790+ LAST_SKIP_BITS(re, &h->c.gb, 1);
782791 }
783792 } else {
784793 /* first escape */
785− SKIP_BITS(re, &s->gb, 1);
786− GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
794+ SKIP_BITS(re, &h->c.gb, 1);
795+ GET_RL_VLC(level, run, re, &h->c.gb, rl_vlc, TEX_VLC_BITS, 2, 1);
787796 i+= run;
788797 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
789− level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
790− LAST_SKIP_BITS(re, &s->gb, 1);
798+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
799+ LAST_SKIP_BITS(re, &h->c.gb, 1);
791800 }
792801 } else {
793802 i+= run;
794− level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
795− LAST_SKIP_BITS(re, &s->gb, 1);
803+ level = (level ^ SHOW_SBITS(re, &h->c.gb, 1)) - SHOW_SBITS(re, &h->c.gb, 1);
804+ LAST_SKIP_BITS(re, &h->c.gb, 1);
796805 }
797806 if (i > 62){
798807 i-= 192;
799808 if(i&(~63)){
800− const int left= get_bits_left(&s->gb);
809+ const int left = get_bits_left(&h->c.gb);
801810 if (((i + 192 == 64 && level / qmul == -1) ||
802− !(s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
811+ !(h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
803812 left >= 0) {
804− av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
813+ av_log(h->c.avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n",
814+ h->c.mb_x, h->c.mb_y);
805815 i = 63;
806816 break;
807817 }else{
808− av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
818+ av_log(h->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
819+ h->c.mb_x, h->c.mb_y);
809820 return -1;
810821 }
811822 }
@@ -816,13 +827,13 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 4 unmodified lines
816827
817828 block[scan_table[i]] = level;
818829 }
819− CLOSE_READER(re, &s->gb);
830+ CLOSE_READER(re, &h->c.gb);
820831 }
821− if (s->mb_intra) {
832+ if (h->c.mb_intra) {
822833 not_coded:
823− ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);
834+ ff_mpeg4_pred_ac(h, block, n, dc_pred_dir);
824835 }
825− s->block_last_index[n] = i;
836+ h->c.block_last_index[n] = i;
826837
827838 return 0;
828839 }
@@ -830,17 +841,17 @@ int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block, · 1 unmodified line
830841 void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr)
831842 {
832843 const VLCElem *const mv_vlc = mv_tables[ms->mv_table_index];
833− MpegEncContext *const s = &ms->m;
844+ H263DecContext *const h = &ms->h;
834845 int sym, mx, my;
835846
836− sym = get_vlc2(&s->gb, mv_vlc, MV_VLC_BITS, 2);
847+ sym = get_vlc2(&h->c.gb, mv_vlc, MV_VLC_BITS, 2);
837848 if (sym) {
838849 mx = sym >> 8;
839850 my = sym & 0xFF;
840851 } else {
841852 /* Escape */
842− mx = get_bits(&s->gb, 6);
843− my = get_bits(&s->gb, 6);
853+ mx = get_bits(&h->c.gb, 6);
854+ my = get_bits(&h->c.gb, 6);
844855 }
845856
846857 mx += *mx_ptr - 32;
libavcodec/msmpeg4dec.h+6−5
@@ -23,13 +23,14 @@ · 22 unmodified lines
2323 #define AVCODEC_MSMPEG4DEC_H
2424
2525 #include "avcodec.h"
26+#include "h263dec.h"
2627 #include "mpegvideo.h"
2728
2829 #define INTER_INTRA_VLC_BITS 3
2930 #define MB_NON_INTRA_VLC_BITS 9
3031
3132 typedef struct MSMP4DecContext {
32− MpegEncContext m;
33+ H263DecContext h;
3334 int bit_rate;
3435 int flipflop_rounding;
3536 int mv_table_index;
@@ -42,18 +43,18 @@ typedef struct MSMP4DecContext { · 6 unmodified lines
4243 int esc3_run_length;
4344 } MSMP4DecContext;
4445
45−static inline MSMP4DecContext *mpv_to_msmpeg4(MpegEncContext *s)
46+static inline MSMP4DecContext *mpv_to_msmpeg4(H263DecContext *const h)
4647 {
4748 // Only legal because no MSMPEG-4 decoder uses slice-threading.
48− return (MSMP4DecContext*)s;
49+ return (MSMP4DecContext*)h;
4950 }
5051
5152 extern const VLCElem *ff_mb_non_intra_vlc[4];
5253 extern VLCElem ff_inter_intra_vlc[8];
5354
5455 int ff_msmpeg4_decode_init(AVCodecContext *avctx);
55−int ff_msmpeg4_decode_picture_header(MpegEncContext *s);
56−int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size);
56+int ff_msmpeg4_decode_picture_header(H263DecContext *const h);
57+int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size);
5758 void ff_msmpeg4_decode_motion(MSMP4DecContext *ms, int *mx_ptr, int *my_ptr);
5859 int ff_msmpeg4_decode_block(MSMP4DecContext *ms, int16_t * block,
5960 int n, int coded, const uint8_t *scan_table);
libavcodec/nvdec_mpeg4.c+1−1
@@ -33,7 +33,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, · 32 unmodified lines
3333 const uint8_t *buffer, uint32_t size)
3434 {
3535 Mpeg4DecContext *m = avctx->priv_data;
36− MpegEncContext *s = &m->m;
36+ MPVContext *const s = &m->h.c;
3737
3838 NVDECContext *ctx = avctx->internal->hwaccel_priv_data;
3939 CUVIDPICPARAMS *pp = &ctx->pic_params;
libavcodec/rv10.c+170−170
@@ -52,7 +52,7 @@ · 51 unmodified lines
5252 #define DC_VLC_BITS 9
5353
5454 typedef struct RVDecContext {
55− MpegEncContext m;
55+ H263DecContext h;
5656 int sub_id;
5757 int orig_width, orig_height;
5858 } RVDecContext;
@@ -80,16 +80,16 @@ static const uint16_t rv_chrom_len_count[15] = { · 21 unmodified lines
8080
8181 static VLCElem rv_dc_lum[1472], rv_dc_chrom[992];
8282
83−int ff_rv_decode_dc(MpegEncContext *s, int n)
83+int ff_rv_decode_dc(H263DecContext *const h, int n)
8484 {
8585 int code;
8686
8787 if (n < 4) {
88− code = get_vlc2(&s->gb, rv_dc_lum, DC_VLC_BITS, 2);
88+ code = get_vlc2(&h->c.gb, rv_dc_lum, DC_VLC_BITS, 2);
8989 } else {
90− code = get_vlc2(&s->gb, rv_dc_chrom, DC_VLC_BITS, 2);
90+ code = get_vlc2(&h->c.gb, rv_dc_chrom, DC_VLC_BITS, 2);
9191 if (code < 0) {
92− av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n");
92+ av_log(h->c.avctx, AV_LOG_ERROR, "chroma dc error\n");
9393 return -1;
9494 }
9595 }
@@ -97,59 +97,59 @@ int ff_rv_decode_dc(MpegEncContext *s, int n) · 1 unmodified line
9797 }
9898
9999 /* read RV 1.0 compatible frame header */
100−static int rv10_decode_picture_header(MpegEncContext *s)
100+static int rv10_decode_picture_header(H263DecContext *const h)
101101 {
102102 int mb_count, pb_frame, marker, mb_xy;
103103
104− marker = get_bits1(&s->gb);
104+ marker = get_bits1(&h->c.gb);
105105
106− if (get_bits1(&s->gb))
107− s->pict_type = AV_PICTURE_TYPE_P;
106+ if (get_bits1(&h->c.gb))
107+ h->c.pict_type = AV_PICTURE_TYPE_P;
108108 else
109− s->pict_type = AV_PICTURE_TYPE_I;
109+ h->c.pict_type = AV_PICTURE_TYPE_I;
110110
111111 if (!marker)
112− av_log(s->avctx, AV_LOG_ERROR, "marker missing\n");
112+ av_log(h->c.avctx, AV_LOG_ERROR, "marker missing\n");
113113
114− pb_frame = get_bits1(&s->gb);
114+ pb_frame = get_bits1(&h->c.gb);
115115
116− ff_dlog(s->avctx, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame);
116+ ff_dlog(h->c.avctx, "pict_type=%d pb_frame=%d\n", h->c.pict_type, pb_frame);
117117
118118 if (pb_frame) {
119− avpriv_request_sample(s->avctx, "PB-frame");
119+ avpriv_request_sample(h->c.avctx, "PB-frame");
120120 return AVERROR_PATCHWELCOME;
121121 }
122122
123− s->qscale = get_bits(&s->gb, 5);
124− if (s->qscale == 0) {
125− av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
123+ h->c.qscale = get_bits(&h->c.gb, 5);
124+ if (h->c.qscale == 0) {
125+ av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
126126 return AVERROR_INVALIDDATA;
127127 }
128128
129− if (s->pict_type == AV_PICTURE_TYPE_I) {
130− if (s->rv10_version == 3) {
129+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
130+ if (h->c.rv10_version == 3) {
131131 /* specific MPEG like DC coding not used */
132− s->last_dc[0] = get_bits(&s->gb, 8);
133− s->last_dc[1] = get_bits(&s->gb, 8);
134− s->last_dc[2] = get_bits(&s->gb, 8);
135− ff_dlog(s->avctx, "DC:%d %d %d\n", s->last_dc[0],
136− s->last_dc[1], s->last_dc[2]);
132+ h->c.last_dc[0] = get_bits(&h->c.gb, 8);
133+ h->c.last_dc[1] = get_bits(&h->c.gb, 8);
134+ h->c.last_dc[2] = get_bits(&h->c.gb, 8);
135+ ff_dlog(h->c.avctx, "DC:%d %d %d\n", h->c.last_dc[0],
136+ h->c.last_dc[1], h->c.last_dc[2]);
137137 }
138138 }
139139 /* if multiple packets per frame are sent, the position at which
140140 * to display the macroblocks is coded here */
141141
142− mb_xy = s->mb_x + s->mb_y * s->mb_width;
143− if (show_bits(&s->gb, 12) == 0 || (mb_xy && mb_xy < s->mb_num)) {
144− s->mb_x = get_bits(&s->gb, 6); /* mb_x */
145− s->mb_y = get_bits(&s->gb, 6); /* mb_y */
146− mb_count = get_bits(&s->gb, 12);
142+ mb_xy = h->c.mb_x + h->c.mb_y * h->c.mb_width;
143+ if (show_bits(&h->c.gb, 12) == 0 || (mb_xy && mb_xy < h->c.mb_num)) {
144+ h->c.mb_x = get_bits(&h->c.gb, 6); /* mb_x */
145+ h->c.mb_y = get_bits(&h->c.gb, 6); /* mb_y */
146+ mb_count = get_bits(&h->c.gb, 12);
147147 } else {
148− s->mb_x = 0;
149− s->mb_y = 0;
150− mb_count = s->mb_width * s->mb_height;
148+ h->c.mb_x = 0;
149+ h->c.mb_y = 0;
150+ mb_count = h->c.mb_width * h->c.mb_height;
151151 }
152− skip_bits(&s->gb, 3); /* ignored */
152+ skip_bits(&h->c.gb, 3); /* ignored */
153153
154154 return mb_count;
155155 }
@@ -159,151 +159,151 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size) · 3 unmodified lines
159159 static const enum AVPictureType pict_types[] =
160160 { AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I /* hmm ... */,
161161 AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B };
162− MpegEncContext *s = &rv->m;
162+ H263DecContext *const h = &rv->h;
163163 int seq, mb_pos, ret;
164164 int rpr_max;
165165
166− s->pict_type = pict_types[get_bits(&s->gb, 2)];
166+ h->c.pict_type = pict_types[get_bits(&h->c.gb, 2)];
167167
168− if (s->low_delay && s->pict_type == AV_PICTURE_TYPE_B) {
169− av_log(s->avctx, AV_LOG_ERROR, "low delay B\n");
168+ if (h->c.low_delay && h->c.pict_type == AV_PICTURE_TYPE_B) {
169+ av_log(h->c.avctx, AV_LOG_ERROR, "low delay B\n");
170170 return -1;
171171 }
172− if (!s->last_pic.ptr && s->pict_type == AV_PICTURE_TYPE_B) {
173− av_log(s->avctx, AV_LOG_ERROR, "early B-frame\n");
172+ if (!h->c.last_pic.ptr && h->c.pict_type == AV_PICTURE_TYPE_B) {
173+ av_log(h->c.avctx, AV_LOG_ERROR, "early B-frame\n");
174174 return AVERROR_INVALIDDATA;
175175 }
176176
177− if (get_bits1(&s->gb)) {
178− av_log(s->avctx, AV_LOG_ERROR, "reserved bit set\n");
177+ if (get_bits1(&h->c.gb)) {
178+ av_log(h->c.avctx, AV_LOG_ERROR, "reserved bit set\n");
179179 return AVERROR_INVALIDDATA;
180180 }
181181
182− s->qscale = get_bits(&s->gb, 5);
183− if (s->qscale == 0) {
184− av_log(s->avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
182+ h->c.qscale = get_bits(&h->c.gb, 5);
183+ if (h->c.qscale == 0) {
184+ av_log(h->c.avctx, AV_LOG_ERROR, "Invalid qscale value: 0\n");
185185 return AVERROR_INVALIDDATA;
186186 }
187187
188188 if (RV_GET_MINOR_VER(rv->sub_id) >= 2)
189− s->loop_filter = get_bits1(&s->gb) && !s->avctx->lowres;
189+ h->c.loop_filter = get_bits1(&h->c.gb) && !h->c.avctx->lowres;
190190
191191 if (RV_GET_MINOR_VER(rv->sub_id) <= 1)
192− seq = get_bits(&s->gb, 8) << 7;
192+ seq = get_bits(&h->c.gb, 8) << 7;
193193 else
194− seq = get_bits(&s->gb, 13) << 2;
194+ seq = get_bits(&h->c.gb, 13) << 2;
195195
196− rpr_max = s->avctx->extradata[1] & 7;
196+ rpr_max = h->c.avctx->extradata[1] & 7;
197197 if (rpr_max) {
198198 int f, new_w, new_h;
199199 int rpr_bits = av_log2(rpr_max) + 1;
200200
201− f = get_bits(&s->gb, rpr_bits);
201+ f = get_bits(&h->c.gb, rpr_bits);
202202
203203 if (f) {
204− if (s->avctx->extradata_size < 8 + 2 * f) {
205− av_log(s->avctx, AV_LOG_ERROR, "Extradata too small.\n");
204+ if (h->c.avctx->extradata_size < 8 + 2 * f) {
205+ av_log(h->c.avctx, AV_LOG_ERROR, "Extradata too small.\n");
206206 return AVERROR_INVALIDDATA;
207207 }
208208
209− new_w = 4 * s->avctx->extradata[6 + 2 * f];
210− new_h = 4 * s->avctx->extradata[7 + 2 * f];
209+ new_w = 4 * h->c.avctx->extradata[6 + 2 * f];
210+ new_h = 4 * h->c.avctx->extradata[7 + 2 * f];
211211 } else {
212212 new_w = rv->orig_width;
213213 new_h = rv->orig_height;
214214 }
215− if (new_w != s->width || new_h != s->height || !s->context_initialized) {
216− AVRational old_aspect = s->avctx->sample_aspect_ratio;
217− av_log(s->avctx, AV_LOG_DEBUG,
215+ if (new_w != h->c.width || new_h != h->c.height || !h->c.context_initialized) {
216+ AVRational old_aspect = h->c.avctx->sample_aspect_ratio;
217+ av_log(h->c.avctx, AV_LOG_DEBUG,
218218 "attempting to change resolution to %dx%d\n", new_w, new_h);
219− if (av_image_check_size(new_w, new_h, 0, s->avctx) < 0)
219+ if (av_image_check_size(new_w, new_h, 0, h->c.avctx) < 0)
220220 return AVERROR_INVALIDDATA;
221221
222222 if (whole_size < (new_w + 15)/16 * ((new_h + 15)/16) / 8)
223223 return AVERROR_INVALIDDATA;
224224
225− ff_mpv_common_end(s);
225+ ff_mpv_common_end(&h->c);
226226
227227 // attempt to keep aspect during typical resolution switches
228228 if (!old_aspect.num)
229229 old_aspect = (AVRational){1, 1};
230− if (2 * (int64_t)new_w * s->height == (int64_t)new_h * s->width)
231− s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1});
232− if ((int64_t)new_w * s->height == 2 * (int64_t)new_h * s->width)
233− s->avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2});
230+ if (2 * (int64_t)new_w * h->c.height == (int64_t)new_h * h->c.width)
231+ h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){2, 1});
232+ if ((int64_t)new_w * h->c.height == 2 * (int64_t)new_h * h->c.width)
233+ h->c.avctx->sample_aspect_ratio = av_mul_q(old_aspect, (AVRational){1, 2});
234234
235− ret = ff_set_dimensions(s->avctx, new_w, new_h);
235+ ret = ff_set_dimensions(h->c.avctx, new_w, new_h);
236236 if (ret < 0)
237237 return ret;
238238
239− s->width = new_w;
240− s->height = new_h;
241− if ((ret = ff_mpv_common_init(s)) < 0)
239+ h->c.width = new_w;
240+ h->c.height = new_h;
241+ if ((ret = ff_mpv_common_init(&h->c)) < 0)
242242 return ret;
243243 }
244244
245− if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
246− av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max);
245+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
246+ av_log(h->c.avctx, AV_LOG_DEBUG, "F %d/%d/%d\n", f, rpr_bits, rpr_max);
247247 }
248248 }
249− if (av_image_check_size(s->width, s->height, 0, s->avctx) < 0)
249+ if (av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx) < 0)
250250 return AVERROR_INVALIDDATA;
251251
252− mb_pos = ff_h263_decode_mba(s);
252+ mb_pos = ff_h263_decode_mba(h);
253253
254− seq |= s->time & ~0x7FFF;
255− if (seq - s->time > 0x4000)
254+ seq |= h->c.time & ~0x7FFF;
255+ if (seq - h->c.time > 0x4000)
256256 seq -= 0x8000;
257− if (seq - s->time < -0x4000)
257+ if (seq - h->c.time < -0x4000)
258258 seq += 0x8000;
259259
260− if (seq != s->time) {
261− if (s->pict_type != AV_PICTURE_TYPE_B) {
262− s->time = seq;
263− s->pp_time = s->time - s->last_non_b_time;
264− s->last_non_b_time = s->time;
260+ if (seq != h->c.time) {
261+ if (h->c.pict_type != AV_PICTURE_TYPE_B) {
262+ h->c.time = seq;
263+ h->c.pp_time = h->c.time - h->c.last_non_b_time;
264+ h->c.last_non_b_time = h->c.time;
265265 } else {
266− s->time = seq;
267− s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
266+ h->c.time = seq;
267+ h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
268268 }
269269 }
270− if (s->pict_type == AV_PICTURE_TYPE_B) {
271− if (s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0) {
272− av_log(s->avctx, AV_LOG_DEBUG,
270+ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
271+ 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) {
272+ av_log(h->c.avctx, AV_LOG_DEBUG,
273273 "messed up order, possible from seeking? skipping current B-frame\n");
274274 #define ERROR_SKIP_FRAME -123
275275 return ERROR_SKIP_FRAME;
276276 }
277− ff_mpeg4_init_direct_mv(s);
277+ ff_mpeg4_init_direct_mv(&h->c);
278278 }
279279
280− s->no_rounding = get_bits1(&s->gb);
280+ h->c.no_rounding = get_bits1(&h->c.gb);
281281
282− if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B)
282+ if (RV_GET_MINOR_VER(rv->sub_id) <= 1 && h->c.pict_type == AV_PICTURE_TYPE_B)
283283 // binary decoder reads 3+2 bits here but they don't seem to be used
284− skip_bits(&s->gb, 5);
284+ skip_bits(&h->c.gb, 5);
285285
286− s->h263_aic = s->pict_type == AV_PICTURE_TYPE_I;
287− if (s->h263_aic) {
288− s->y_dc_scale_table =
289− s->c_dc_scale_table = ff_aic_dc_scale_table;
286+ h->c.h263_aic = h->c.pict_type == AV_PICTURE_TYPE_I;
287+ if (h->c.h263_aic) {
288+ h->c.y_dc_scale_table =
289+ h->c.c_dc_scale_table = ff_aic_dc_scale_table;
290290 } else {
291− s->y_dc_scale_table =
292− s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
291+ h->c.y_dc_scale_table =
292+ h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table;
293293 }
294− if (!s->avctx->lowres)
295− s->loop_filter = 1;
294+ if (!h->c.avctx->lowres)
295+ h->c.loop_filter = 1;
296296
297− if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
298− av_log(s->avctx, AV_LOG_INFO,
297+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
298+ av_log(h->c.avctx, AV_LOG_INFO,
299299 "num:%5d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n",
300− seq, s->mb_x, s->mb_y, s->pict_type, s->qscale,
301− s->no_rounding);
300+ seq, h->c.mb_x, h->c.mb_y, h->c.pict_type, h->c.qscale,
301+ h->c.no_rounding);
302302 }
303303
304− av_assert0(s->pict_type != AV_PICTURE_TYPE_B || !s->low_delay);
304+ av_assert0(h->c.pict_type != AV_PICTURE_TYPE_B || !h->c.low_delay);
305305
306− return s->mb_width * s->mb_height - mb_pos;
306+ return h->c.mb_width * h->c.mb_height - mb_pos;
307307 }
308308
309309 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) · 41 unmodified lines
351351 {
352352 static AVOnce init_static_once = AV_ONCE_INIT;
353353 RVDecContext *rv = avctx->priv_data;
354− MpegEncContext *s = &rv->m;
354+ H263DecContext *const h = &rv->h;
355355 int major_ver, minor_ver, micro_ver, ret;
356356
357357 if (avctx->extradata_size < 8) {
@@ -369,11 +369,11 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) · 11 unmodified lines
369369 rv->orig_width = avctx->coded_width;
370370 rv->orig_height = avctx->coded_height;
371371
372− s->h263_long_vectors = avctx->extradata[3] & 1;
372+ h->c.h263_long_vectors = avctx->extradata[3] & 1;
373373 rv->sub_id = AV_RB32A(avctx->extradata + 4);
374374 if (avctx->codec_id == AV_CODEC_ID_RV20) {
375− s->modified_quant = 1;
376− s->chroma_qscale_table = ff_h263_chroma_qscale_table;
375+ h->c.modified_quant = 1;
376+ h->c.chroma_qscale_table = ff_h263_chroma_qscale_table;
377377 }
378378
379379 major_ver = RV_GET_MAJOR_VER(rv->sub_id);
@@ -382,12 +382,12 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) · 2 unmodified lines
382382
383383 switch (major_ver) {
384384 case 1:
385− s->rv10_version = micro_ver ? 3 : 1;
386− s->obmc = micro_ver == 2;
385+ h->c.rv10_version = micro_ver ? 3 : 1;
386+ h->c.obmc = micro_ver == 2;
387387 break;
388388 case 2:
389389 if (minor_ver >= 2) {
390− s->low_delay = 0;
390+ h->c.low_delay = 0;
391391 avctx->has_b_frames = 1;
392392 }
393393 break;
@@ -412,126 +412,126 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 18 unmodified lines
412412 int buf_size, int buf_size2, int whole_size)
413413 {
414414 RVDecContext *rv = avctx->priv_data;
415− MpegEncContext *s = &rv->m;
415+ H263DecContext *const h = &rv->h;
416416 int mb_count, mb_pos, left, start_mb_x, active_bits_size, ret;
417417
418418 active_bits_size = buf_size * 8;
419− init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8);
420− if (s->codec_id == AV_CODEC_ID_RV10)
421− mb_count = rv10_decode_picture_header(s);
419+ init_get_bits(&h->c.gb, buf, FFMAX(buf_size, buf_size2) * 8);
420+ if (h->c.codec_id == AV_CODEC_ID_RV10)
421+ mb_count = rv10_decode_picture_header(h);
422422 else
423423 mb_count = rv20_decode_picture_header(rv, whole_size);
424424 if (mb_count < 0) {
425425 if (mb_count != ERROR_SKIP_FRAME)
426− av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n");
426+ av_log(h->c.avctx, AV_LOG_ERROR, "HEADER ERROR\n");
427427 return AVERROR_INVALIDDATA;
428428 }
429429
430− if (s->mb_x >= s->mb_width ||
431− s->mb_y >= s->mb_height) {
432− av_log(s->avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", s->mb_x, s->mb_y);
430+ if (h->c.mb_x >= h->c.mb_width ||
431+ h->c.mb_y >= h->c.mb_height) {
432+ av_log(h->c.avctx, AV_LOG_ERROR, "POS ERROR %d %d\n", h->c.mb_x, h->c.mb_y);
433433 return AVERROR_INVALIDDATA;
434434 }
435− mb_pos = s->mb_y * s->mb_width + s->mb_x;
436− left = s->mb_width * s->mb_height - mb_pos;
435+ mb_pos = h->c.mb_y * h->c.mb_width + h->c.mb_x;
436+ left = h->c.mb_width * h->c.mb_height - mb_pos;
437437 if (mb_count > left) {
438− av_log(s->avctx, AV_LOG_ERROR, "COUNT ERROR\n");
438+ av_log(h->c.avctx, AV_LOG_ERROR, "COUNT ERROR\n");
439439 return AVERROR_INVALIDDATA;
440440 }
441441
442− if (whole_size < s->mb_width * s->mb_height / 8)
442+ if (whole_size < h->c.mb_width * h->c.mb_height / 8)
443443 return AVERROR_INVALIDDATA;
444444
445− if ((s->mb_x == 0 && s->mb_y == 0) || !s->cur_pic.ptr) {
445+ if ((h->c.mb_x == 0 && h->c.mb_y == 0) || !h->c.cur_pic.ptr) {
446446 // FIXME write parser so we always have complete frames?
447− if (s->cur_pic.ptr) {
448− ff_er_frame_end(&s->er, NULL);
449− ff_mpv_frame_end(s);
450− s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
447+ if (h->c.cur_pic.ptr) {
448+ ff_er_frame_end(&h->c.er, NULL);
449+ ff_mpv_frame_end(&h->c);
450+ h->c.mb_x = h->c.mb_y = h->c.resync_mb_x = h->c.resync_mb_y = 0;
451451 }
452− if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
452+ if ((ret = ff_mpv_frame_start(&h->c, avctx)) < 0)
453453 return ret;
454− ff_mpeg_er_frame_start(s);
454+ ff_mpeg_er_frame_start(&h->c);
455455 } else {
456− if (s->cur_pic.ptr->f->pict_type != s->pict_type) {
457− av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n");
456+ if (h->c.cur_pic.ptr->f->pict_type != h->c.pict_type) {
457+ av_log(h->c.avctx, AV_LOG_ERROR, "Slice type mismatch\n");
458458 return AVERROR_INVALIDDATA;
459459 }
460460 }
461461
462462
463− ff_dlog(avctx, "qscale=%d\n", s->qscale);
463+ ff_dlog(avctx, "qscale=%d\n", h->c.qscale);
464464
465465 /* default quantization values */
466− if (s->codec_id == AV_CODEC_ID_RV10) {
467− if (s->mb_y == 0)
468− s->first_slice_line = 1;
466+ if (h->c.codec_id == AV_CODEC_ID_RV10) {
467+ if (h->c.mb_y == 0)
468+ h->c.first_slice_line = 1;
469469 } else {
470− s->first_slice_line = 1;
471− s->resync_mb_x = s->mb_x;
470+ h->c.first_slice_line = 1;
471+ h->c.resync_mb_x = h->c.mb_x;
472472 }
473− start_mb_x = s->mb_x;
474− s->resync_mb_y = s->mb_y;
473+ start_mb_x = h->c.mb_x;
474+ h->c.resync_mb_y = h->c.mb_y;
475475
476− ff_set_qscale(s, s->qscale);
476+ ff_set_qscale(&h->c, h->c.qscale);
477477
478− s->rv10_first_dc_coded[0] = 0;
479− s->rv10_first_dc_coded[1] = 0;
480− s->rv10_first_dc_coded[2] = 0;
481− ff_init_block_index(s);
478+ h->c.rv10_first_dc_coded[0] = 0;
479+ h->c.rv10_first_dc_coded[1] = 0;
480+ h->c.rv10_first_dc_coded[2] = 0;
481+ ff_init_block_index(&h->c);
482482
483483 /* decode each macroblock */
484− for (s->mb_num_left = mb_count; s->mb_num_left > 0; s->mb_num_left--) {
484+ for (h->c.mb_num_left = mb_count; h->c.mb_num_left > 0; h->c.mb_num_left--) {
485485 int ret;
486− ff_update_block_index(s, 8, s->avctx->lowres, 1);
487− ff_tlog(avctx, "**mb x=%d y=%d\n", s->mb_x, s->mb_y);
486+ ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
487+ ff_tlog(avctx, "**mb x=%d y=%d\n", h->c.mb_x, h->c.mb_y);
488488
489− s->mv_dir = MV_DIR_FORWARD;
490− s->mv_type = MV_TYPE_16X16;
491− ret = ff_h263_decode_mb(s, s->block);
489+ h->c.mv_dir = MV_DIR_FORWARD;
490+ h->c.mv_type = MV_TYPE_16X16;
491+ ret = ff_h263_decode_mb(h, h->c.block);
492492
493493 // Repeat the slice end check from ff_h263_decode_mb with our active
494494 // bitstream size
495− if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&s->gb)) {
496− int v = show_bits(&s->gb, 16);
495+ if (ret != SLICE_ERROR && active_bits_size >= get_bits_count(&h->c.gb)) {
496+ int v = show_bits(&h->c.gb, 16);
497497
498− if (get_bits_count(&s->gb) + 16 > active_bits_size)
499− v >>= get_bits_count(&s->gb) + 16 - active_bits_size;
498+ if (get_bits_count(&h->c.gb) + 16 > active_bits_size)
499+ v >>= get_bits_count(&h->c.gb) + 16 - active_bits_size;
500500
501501 if (!v)
502502 ret = SLICE_END;
503503 }
504− if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&s->gb) &&
505− 8 * buf_size2 >= get_bits_count(&s->gb)) {
504+ if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&h->c.gb) &&
505+ 8 * buf_size2 >= get_bits_count(&h->c.gb)) {
506506 active_bits_size = buf_size2 * 8;
507507 av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n",
508508 8 * buf_size, active_bits_size);
509509 ret = SLICE_OK;
510510 }
511511
512− if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) {
513− av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x,
514− s->mb_y);
512+ if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&h->c.gb)) {
513+ av_log(h->c.avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", h->c.mb_x,
514+ h->c.mb_y);
515515 return AVERROR_INVALIDDATA;
516516 }
517− if (s->pict_type != AV_PICTURE_TYPE_B)
518− ff_h263_update_motion_val(s);
519− ff_mpv_reconstruct_mb(s, s->block);
520− if (s->loop_filter)
521− ff_h263_loop_filter(s);
522−
523− if (++s->mb_x == s->mb_width) {
524− s->mb_x = 0;
525− s->mb_y++;
526− ff_init_block_index(s);
517+ if (h->c.pict_type != AV_PICTURE_TYPE_B)
518+ ff_h263_update_motion_val(&h->c);
519+ ff_mpv_reconstruct_mb(&h->c, h->c.block);
520+ if (h->c.loop_filter)
521+ ff_h263_loop_filter(&h->c);
522+
523+ if (++h->c.mb_x == h->c.mb_width) {
524+ h->c.mb_x = 0;
525+ h->c.mb_y++;
526+ ff_init_block_index(&h->c);
527527 }
528− if (s->mb_x == s->resync_mb_x)
529− s->first_slice_line = 0;
528+ if (h->c.mb_x == h->c.resync_mb_x)
529+ h->c.first_slice_line = 0;
530530 if (ret == SLICE_END)
531531 break;
532532 }
533533
534− ff_er_add_slice(&s->er, start_mb_x, s->resync_mb_y, s->mb_x - 1, s->mb_y,
534+ ff_er_add_slice(&h->c.er, start_mb_x, h->c.resync_mb_y, h->c.mb_x - 1, h->c.mb_y,
535535 ER_MB_END);
536536
537537 return active_bits_size;
libavcodec/rv10dec.h+2−2
@@ -21,8 +21,8 @@ · 20 unmodified lines
2121 #ifndef AVCODEC_RV10DEC_H
2222 #define AVCODEC_RV10DEC_H
2323
24−#include "mpegvideo.h"
24+struct H263DecContext;
2525
26−int ff_rv_decode_dc(MpegEncContext *s, int n);
26+int ff_rv_decode_dc(struct H263DecContext *const h, int n);
2727
2828 #endif /* AVCODEC_RV10DEC_H */
libavcodec/vaapi_mpeg4.c+1−1
@@ -51,7 +51,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, · 50 unmodified lines
5151 av_unused uint32_t size)
5252 {
5353 Mpeg4DecContext *ctx = avctx->priv_data;
54− MpegEncContext *s = &ctx->m;
54+ MPVContext *const s = &ctx->h.c;
5555 VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
5656 VAPictureParameterBufferMPEG4 pic_param;
5757 int i, err;
libavcodec/vdpau_mpeg4.c+1−1
@@ -34,7 +34,7 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, · 33 unmodified lines
3434 const uint8_t *buffer, uint32_t size)
3535 {
3636 Mpeg4DecContext *ctx = avctx->priv_data;
37− MpegEncContext * const s = &ctx->m;
37+ MPVContext *const s = &ctx->h.c;
3838 MPVPicture *pic = s->cur_pic.ptr;
3939 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
4040 VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
libavcodec/wmv2.h+2−2
@@ -44,7 +44,7 @@ void ff_mspel_motion(MpegEncContext *s, · 43 unmodified lines
4444 int motion_x, int motion_y, int h);
4545
4646
47−static av_always_inline int wmv2_get_cbp_table_index(MpegEncContext *s, int cbp_index)
47+static av_always_inline int wmv2_get_cbp_table_index(int qscale, int cbp_index)
4848 {
4949 static const uint8_t map[3][3] = {
5050 { 0, 2, 1 },
@@ -52,7 +52,7 @@ static av_always_inline int wmv2_get_cbp_table_index(MpegEncContext *s, int cbp_ · 1 unmodified line
5252 { 2, 1, 0 },
5353 };
5454
55− return map[(s->qscale > 10) + (s->qscale > 20)][cbp_index];
55+ return map[(qscale > 10) + (qscale > 20)][cbp_index];
5656 }
5757
5858 #endif /* AVCODEC_WMV2_H */
libavcodec/wmv2dec.c+160−161
@@ -59,9 +59,9 @@ typedef struct WMV2DecContext { · 58 unmodified lines
5959 static void wmv2_add_block(WMV2DecContext *w, int16_t *block1,
6060 uint8_t *dst, int stride, int n)
6161 {
62− MpegEncContext *const s = &w->ms.m;
62+ H263DecContext *const h = &w->ms.h;
6363
64− if (s->block_last_index[n] >= 0) {
64+ if (h->c.block_last_index[n] >= 0) {
6565 switch (w->abt_type_table[n]) {
6666 case 0:
6767 w->common.wdsp.idct_add(dst, stride, block1);
@@ -69,15 +69,15 @@ static void wmv2_add_block(WMV2DecContext *w, int16_t *block1, · 1 unmodified line
6969 case 1:
7070 ff_simple_idct84_add(dst, stride, block1);
7171 ff_simple_idct84_add(dst + 4 * stride, stride, w->abt_block2[n]);
72− s->bdsp.clear_block(w->abt_block2[n]);
72+ h->c.bdsp.clear_block(w->abt_block2[n]);
7373 break;
7474 case 2:
7575 ff_simple_idct48_add(dst, stride, block1);
7676 ff_simple_idct48_add(dst + 4, stride, w->abt_block2[n]);
77− s->bdsp.clear_block(w->abt_block2[n]);
77+ h->c.bdsp.clear_block(w->abt_block2[n]);
7878 break;
7979 default:
80− av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
80+ av_log(h->c.avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
8181 }
8282 }
8383 }
@@ -101,64 +101,63 @@ void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64], · 17 unmodified lines
101101
102102 static int parse_mb_skip(WMV2DecContext *w)
103103 {
104− int mb_x, mb_y;
104+ H263DecContext *const h = &w->ms.h;
105105 int coded_mb_count = 0;
106− MpegEncContext *const s = &w->ms.m;
107− uint32_t *const mb_type = s->cur_pic.mb_type;
106+ uint32_t *const mb_type = h->c.cur_pic.mb_type;
108107
109− w->skip_type = get_bits(&s->gb, 2);
108+ w->skip_type = get_bits(&h->c.gb, 2);
110109 switch (w->skip_type) {
111110 case SKIP_TYPE_NONE:
112− for (mb_y = 0; mb_y < s->mb_height; mb_y++)
113− for (mb_x = 0; mb_x < s->mb_width; mb_x++)
114− mb_type[mb_y * s->mb_stride + mb_x] =
111+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
112+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
113+ mb_type[mb_y * h->c.mb_stride + mb_x] =
115114 MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
116115 break;
117116 case SKIP_TYPE_MPEG:
118− if (get_bits_left(&s->gb) < s->mb_height * s->mb_width)
117+ if (get_bits_left(&h->c.gb) < h->c.mb_height * h->c.mb_width)
119118 return AVERROR_INVALIDDATA;
120− for (mb_y = 0; mb_y < s->mb_height; mb_y++)
121− for (mb_x = 0; mb_x < s->mb_width; mb_x++)
122− mb_type[mb_y * s->mb_stride + mb_x] =
123− (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
119+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
120+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
121+ mb_type[mb_y * h->c.mb_stride + mb_x] =
122+ (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
124123 break;
125124 case SKIP_TYPE_ROW:
126− for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
127− if (get_bits_left(&s->gb) < 1)
125+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++) {
126+ if (get_bits_left(&h->c.gb) < 1)
128127 return AVERROR_INVALIDDATA;
129− if (get_bits1(&s->gb)) {
130− for (mb_x = 0; mb_x < s->mb_width; mb_x++)
131− mb_type[mb_y * s->mb_stride + mb_x] =
128+ if (get_bits1(&h->c.gb)) {
129+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
130+ mb_type[mb_y * h->c.mb_stride + mb_x] =
132131 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
133132 } else {
134− for (mb_x = 0; mb_x < s->mb_width; mb_x++)
135− mb_type[mb_y * s->mb_stride + mb_x] =
136− (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
133+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
134+ mb_type[mb_y * h->c.mb_stride + mb_x] =
135+ (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
137136 }
138137 }
139138 break;
140139 case SKIP_TYPE_COL:
141− for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
142− if (get_bits_left(&s->gb) < 1)
140+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++) {
141+ if (get_bits_left(&h->c.gb) < 1)
143142 return AVERROR_INVALIDDATA;
144− if (get_bits1(&s->gb)) {
145− for (mb_y = 0; mb_y < s->mb_height; mb_y++)
146− mb_type[mb_y * s->mb_stride + mb_x] =
143+ if (get_bits1(&h->c.gb)) {
144+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
145+ mb_type[mb_y * h->c.mb_stride + mb_x] =
147146 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
148147 } else {
149− for (mb_y = 0; mb_y < s->mb_height; mb_y++)
150− mb_type[mb_y * s->mb_stride + mb_x] =
151− (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
148+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
149+ mb_type[mb_y * h->c.mb_stride + mb_x] =
150+ (get_bits1(&h->c.gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
152151 }
153152 }
154153 break;
155154 }
156155
157− for (mb_y = 0; mb_y < s->mb_height; mb_y++)
158− for (mb_x = 0; mb_x < s->mb_width; mb_x++)
159− coded_mb_count += !IS_SKIP(mb_type[mb_y * s->mb_stride + mb_x]);
156+ for (int mb_y = 0; mb_y < h->c.mb_height; mb_y++)
157+ for (int mb_x = 0; mb_x < h->c.mb_width; mb_x++)
158+ coded_mb_count += !IS_SKIP(mb_type[mb_y * h->c.mb_stride + mb_x]);
160159
161− if (coded_mb_count > get_bits_left(&s->gb))
160+ if (coded_mb_count > get_bits_left(&h->c.gb))
162161 return AVERROR_INVALIDDATA;
163162
164163 return 0;
@@ -166,20 +165,20 @@ static int parse_mb_skip(WMV2DecContext *w) · 1 unmodified line
166165
167166 static int decode_ext_header(WMV2DecContext *w)
168167 {
169− MpegEncContext *const s = &w->ms.m;
168+ H263DecContext *const h = &w->ms.h;
170169 GetBitContext gb;
171170 int fps;
172171 int code;
173172
174− if (s->avctx->extradata_size < 4)
173+ if (h->c.avctx->extradata_size < 4)
175174 return AVERROR_INVALIDDATA;
176175
177− init_get_bits(&gb, s->avctx->extradata, 32);
176+ init_get_bits(&gb, h->c.avctx->extradata, 32);
178177
179178 fps = get_bits(&gb, 5);
180179 w->ms.bit_rate = get_bits(&gb, 11) * 1024;
181180 w->mspel_bit = get_bits1(&gb);
182− s->loop_filter = get_bits1(&gb);
181+ h->c.loop_filter = get_bits1(&gb);
183182 w->abt_flag = get_bits1(&gb);
184183 w->j_type_bit = get_bits1(&gb);
185184 w->top_left_mv_flag = get_bits1(&gb);
@@ -189,36 +188,36 @@ static int decode_ext_header(WMV2DecContext *w) · 3 unmodified lines
189188 if (code == 0)
190189 return AVERROR_INVALIDDATA;
191190
192− s->slice_height = s->mb_height / code;
191+ h->c.slice_height = h->c.mb_height / code;
193192
194− if (s->avctx->debug & FF_DEBUG_PICT_INFO)
195− av_log(s->avctx, AV_LOG_DEBUG,
193+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
194+ av_log(h->c.avctx, AV_LOG_DEBUG,
196195 "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, "
197196 "tl_mv_flag:%d, mbrl_bit:%d, code:%d, loop_filter:%d, "
198197 "slices:%d\n",
199198 fps, w->ms.bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit,
200− w->top_left_mv_flag, w->per_mb_rl_bit, code, s->loop_filter,
199+ w->top_left_mv_flag, w->per_mb_rl_bit, code, h->c.loop_filter,
201200 code);
202201 return 0;
203202 }
204203
205−int ff_wmv2_decode_picture_header(MpegEncContext *s)
204+int ff_wmv2_decode_picture_header(H263DecContext *const h)
206205 {
207206 int code;
208207
209− s->pict_type = get_bits1(&s->gb) + 1;
210− if (s->pict_type == AV_PICTURE_TYPE_I) {
211− code = get_bits(&s->gb, 7);
212− av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
208+ h->c.pict_type = get_bits1(&h->c.gb) + 1;
209+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
210+ code = get_bits(&h->c.gb, 7);
211+ av_log(h->c.avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
213212 }
214− s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
215− if (s->qscale <= 0)
213+ h->c.chroma_qscale = h->c.qscale = get_bits(&h->c.gb, 5);
214+ if (h->c.qscale <= 0)
216215 return AVERROR_INVALIDDATA;
217216
218− if (s->pict_type != AV_PICTURE_TYPE_I && show_bits(&s->gb, 1)) {
219− GetBitContext gb = s->gb;
217+ if (h->c.pict_type != AV_PICTURE_TYPE_I && show_bits(&h->c.gb, 1)) {
218+ GetBitContext gb = h->c.gb;
220219 int skip_type = get_bits(&gb, 2);
221− int run = skip_type == SKIP_TYPE_COL ? s->mb_width : s->mb_height;
220+ int run = skip_type == SKIP_TYPE_COL ? h->c.mb_width : h->c.mb_height;
222221
223222 while (run > 0) {
224223 int block = FFMIN(run, 25);
@@ -233,46 +232,46 @@ int ff_wmv2_decode_picture_header(MpegEncContext *s) · 8 unmodified lines
233232 return 0;
234233 }
235234
236−int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
235+int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)
237236 {
238− WMV2DecContext *const w = (WMV2DecContext *) s;
237+ WMV2DecContext *const w = (WMV2DecContext *)h;
239238
240− if (s->pict_type == AV_PICTURE_TYPE_I) {
239+ if (h->c.pict_type == AV_PICTURE_TYPE_I) {
241240 /* Is filling with zeroes really the right thing to do? */
242− memset(s->cur_pic.mb_type, 0,
243− sizeof(*s->cur_pic.mb_type) * s->mb_height * s->mb_stride);
241+ memset(h->c.cur_pic.mb_type, 0,
242+ sizeof(*h->c.cur_pic.mb_type) * h->c.mb_height * h->c.mb_stride);
244243 if (w->j_type_bit)
245− w->j_type = get_bits1(&s->gb);
244+ w->j_type = get_bits1(&h->c.gb);
246245 else
247246 w->j_type = 0; // FIXME check
248247
249248 if (!w->j_type) {
250249 if (w->per_mb_rl_bit)
251− w->ms.per_mb_rl_table = get_bits1(&s->gb);
250+ w->ms.per_mb_rl_table = get_bits1(&h->c.gb);
252251 else
253252 w->ms.per_mb_rl_table = 0;
254253
255254 if (!w->ms.per_mb_rl_table) {
256− w->ms.rl_chroma_table_index = decode012(&s->gb);
257− w->ms.rl_table_index = decode012(&s->gb);
255+ w->ms.rl_chroma_table_index = decode012(&h->c.gb);
256+ w->ms.rl_table_index = decode012(&h->c.gb);
258257 }
259258
260− w->ms.dc_table_index = get_bits1(&s->gb);
259+ w->ms.dc_table_index = get_bits1(&h->c.gb);
261260
262261 // at minimum one bit per macroblock is required at least in a valid frame,
263262 // we discard frames much smaller than this. Frames smaller than 1/8 of the
264263 // smallest "black/skip" frame generally contain not much recoverable content
265264 // while at the same time they have the highest computational requirements
266265 // per byte
267− if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
266+ if (get_bits_left(&h->c.gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
268267 return AVERROR_INVALIDDATA;
269268 }
270− s->inter_intra_pred = 0;
271− s->no_rounding = 1;
272− if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
273− av_log(s->avctx, AV_LOG_DEBUG,
269+ h->c.inter_intra_pred = 0;
270+ h->c.no_rounding = 1;
271+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
272+ av_log(h->c.avctx, AV_LOG_DEBUG,
274273 "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
275− s->qscale, w->ms.rl_chroma_table_index, w->ms.rl_table_index,
274+ h->c.qscale, w->ms.rl_chroma_table_index, w->ms.rl_table_index,
276275 w->ms.dc_table_index, w->ms.per_mb_rl_table, w->j_type);
277276 }
278277 } else {
@@ -283,61 +282,61 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) · 4 unmodified lines
283282 ret = parse_mb_skip(w);
284283 if (ret < 0)
285284 return ret;
286− cbp_index = decode012(&s->gb);
287− w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index);
285+ cbp_index = decode012(&h->c.gb);
286+ w->cbp_table_index = wmv2_get_cbp_table_index(h->c.qscale, cbp_index);
288287
289288 if (w->mspel_bit)
290− s->mspel = get_bits1(&s->gb);
289+ h->c.mspel = get_bits1(&h->c.gb);
291290 else
292− s->mspel = 0; // FIXME check
291+ h->c.mspel = 0; // FIXME check
293292
294293 if (w->abt_flag) {
295− w->per_mb_abt = get_bits1(&s->gb) ^ 1;
294+ w->per_mb_abt = get_bits1(&h->c.gb) ^ 1;
296295 if (!w->per_mb_abt)
297− w->abt_type = decode012(&s->gb);
296+ w->abt_type = decode012(&h->c.gb);
298297 }
299298
300299 if (w->per_mb_rl_bit)
301− w->ms.per_mb_rl_table = get_bits1(&s->gb);
300+ w->ms.per_mb_rl_table = get_bits1(&h->c.gb);
302301 else
303302 w->ms.per_mb_rl_table = 0;
304303
305304 if (!w->ms.per_mb_rl_table) {
306− w->ms.rl_table_index = decode012(&s->gb);
305+ w->ms.rl_table_index = decode012(&h->c.gb);
307306 w->ms.rl_chroma_table_index = w->ms.rl_table_index;
308307 }
309308
310− if (get_bits_left(&s->gb) < 2)
309+ if (get_bits_left(&h->c.gb) < 2)
311310 return AVERROR_INVALIDDATA;
312311
313− w->ms.dc_table_index = get_bits1(&s->gb);
314− w->ms.mv_table_index = get_bits1(&s->gb);
312+ w->ms.dc_table_index = get_bits1(&h->c.gb);
313+ w->ms.mv_table_index = get_bits1(&h->c.gb);
315314
316− s->inter_intra_pred = 0; // (s->width * s->height < 320 * 240 && w->ms.bit_rate <= II_BITRATE);
317− s->no_rounding ^= 1;
315+ h->c.inter_intra_pred = 0; // (h->c.width * h->c.height < 320 * 240 && w->ms.bit_rate <= II_BITRATE);
316+ h->c.no_rounding ^= 1;
318317
319− if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
320− av_log(s->avctx, AV_LOG_DEBUG,
318+ if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
319+ av_log(h->c.avctx, AV_LOG_DEBUG,
321320 "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d "
322321 "per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
323322 w->ms.rl_table_index, w->ms.rl_chroma_table_index,
324323 w->ms.dc_table_index, w->ms.mv_table_index,
325− w->ms.per_mb_rl_table, s->qscale, s->mspel,
324+ w->ms.per_mb_rl_table, h->c.qscale, h->c.mspel,
326325 w->per_mb_abt, w->abt_type, w->cbp_table_index,
327− s->inter_intra_pred);
326+ h->c.inter_intra_pred);
328327 }
329328 }
330329 w->ms.esc3_level_length = 0;
331330 w->ms.esc3_run_length = 0;
332331
333332 if (w->j_type) {
334− ff_intrax8_decode_picture(&w->x8, s->cur_pic.ptr,
335− &s->gb, &s->mb_x, &s->mb_y,
336− 2 * s->qscale, (s->qscale - 1) | 1,
337− s->loop_filter, s->low_delay);
333+ ff_intrax8_decode_picture(&w->x8, h->c.cur_pic.ptr,
334+ &h->c.gb, &h->c.mb_x, &h->c.mb_y,
335+ 2 * h->c.qscale, (h->c.qscale - 1) | 1,
336+ h->c.loop_filter, h->c.low_delay);
338337
339− ff_er_add_slice(&s->er, 0, 0,
340− (s->mb_x >> 1) - 1, (s->mb_y >> 1) - 1,
338+ ff_er_add_slice(&h->c.er, 0, 0,
339+ (h->c.mb_x >> 1) - 1, (h->c.mb_y >> 1) - 1,
341340 ER_MB_END);
342341 return 1;
343342 }
@@ -347,38 +346,37 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) · 3 unmodified lines
347346
348347 static inline void wmv2_decode_motion(WMV2DecContext *w, int *mx_ptr, int *my_ptr)
349348 {
350− MpegEncContext *const s = &w->ms.m;
349+ H263DecContext *const h = &w->ms.h;
351350
352351 ff_msmpeg4_decode_motion(&w->ms, mx_ptr, my_ptr);
353352
354− if ((((*mx_ptr) | (*my_ptr)) & 1) && s->mspel)
355− w->common.hshift = get_bits1(&s->gb);
353+ if ((((*mx_ptr) | (*my_ptr)) & 1) && h->c.mspel)
354+ w->common.hshift = get_bits1(&h->c.gb);
356355 else
357356 w->common.hshift = 0;
358357 }
359358
360359 static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py)
361360 {
362− MpegEncContext *const s = &w->ms.m;
363− int xy, wrap, diff, type;
364− int16_t *A, *B, *C, *mot_val;
361+ H263DecContext *const h = &w->ms.h;
362+ int diff, type;
365363
366− wrap = s->b8_stride;
367− xy = s->block_index[0];
364+ int wrap = h->c.b8_stride;
365+ int xy = h->c.block_index[0];
368366
369− mot_val = s->cur_pic.motion_val[0][xy];
367+ int16_t *mot_val = h->c.cur_pic.motion_val[0][xy];
370368
371− A = s->cur_pic.motion_val[0][xy - 1];
372− B = s->cur_pic.motion_val[0][xy - wrap];
373− C = s->cur_pic.motion_val[0][xy + 2 - wrap];
369+ const int16_t *A = h->c.cur_pic.motion_val[0][xy - 1];
370+ const int16_t *B = h->c.cur_pic.motion_val[0][xy - wrap];
371+ const int16_t *C = h->c.cur_pic.motion_val[0][xy + 2 - wrap];
374372
375− if (s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag)
373+ if (h->c.mb_x && !h->c.first_slice_line && !h->c.mspel && w->top_left_mv_flag)
376374 diff = FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1]));
377375 else
378376 diff = 0;
379377
380378 if (diff >= 8)
381− type = get_bits1(&s->gb);
379+ type = get_bits1(&h->c.gb);
382380 else
383381 type = 2;
384382
@@ -390,7 +388,7 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) · 5 unmodified lines
390388 *py = B[1];
391389 } else {
392390 /* special case for first (slice) line */
393− if (s->first_slice_line) {
391+ if (h->c.first_slice_line) {
394392 *px = A[0];
395393 *py = A[1];
396394 } else {
@@ -405,23 +403,23 @@ static int16_t *wmv2_pred_motion(WMV2DecContext *w, int *px, int *py) · 8 unmodified lines
405403 static inline int wmv2_decode_inter_block(WMV2DecContext *w, int16_t *block,
406404 int n, int cbp)
407405 {
408− MpegEncContext *const s = &w->ms.m;
406+ H263DecContext *const h = &w->ms.h;
409407 static const int sub_cbp_table[3] = { 2, 3, 1 };
410408 int sub_cbp, ret;
411409
412410 if (!cbp) {
413− s->block_last_index[n] = -1;
411+ h->c.block_last_index[n] = -1;
414412 return 0;
415413 }
416414
417415 if (w->per_block_abt)
418− w->abt_type = decode012(&s->gb);
416+ w->abt_type = decode012(&h->c.gb);
419417 w->abt_type_table[n] = w->abt_type;
420418
421419 if (w->abt_type) {
422420 const uint8_t *scantable = w->abt_type == 1 ? ff_wmv2_scantableA : ff_wmv2_scantableB;
423421
424− sub_cbp = sub_cbp_table[decode012(&s->gb)];
422+ sub_cbp = sub_cbp_table[decode012(&h->c.gb)];
425423
426424 if (sub_cbp & 1) {
427425 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, · 7 unmodified lines
435433 return ret;
436434 }
437435
438− s->block_last_index[n] = 63;
436+ h->c.block_last_index[n] = 63;
439437
440438 return 0;
441439 } else {
442440 return ff_msmpeg4_decode_block(&w->ms, block, n, 1,
443− s->inter_scantable.permutated);
441+ h->c.inter_scantable.permutated);
444442 }
445443 }
446444
447−static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
445+static int wmv2_decode_mb(H263DecContext *const h, int16_t block[6][64])
448446 {
449− /* The following is only allowed because this encoder
447+ /* The following is only allowed because this decoder
450448 * does not use slice threading. */
451− WMV2DecContext *const w = (WMV2DecContext *) s;
449+ WMV2DecContext *const w = (WMV2DecContext *) h;
452450 MSMP4DecContext *const ms = &w->ms;
453451 int cbp, code, i, ret;
454452 uint8_t *coded_val;
@@ -456,40 +454,40 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 1 unmodified line
456454 if (w->j_type)
457455 return 0;
458456
459− if (s->pict_type == AV_PICTURE_TYPE_P) {
460− if (IS_SKIP(s->cur_pic.mb_type[s->mb_y * s->mb_stride + s->mb_x])) {
457+ if (h->c.pict_type == AV_PICTURE_TYPE_P) {
458+ if (IS_SKIP(h->c.cur_pic.mb_type[h->c.mb_y * h->c.mb_stride + h->c.mb_x])) {
461459 /* skip mb */
462− s->mb_intra = 0;
460+ h->c.mb_intra = 0;
463461 for (i = 0; i < 6; i++)
464− s->block_last_index[i] = -1;
465− s->mv_dir = MV_DIR_FORWARD;
466− s->mv_type = MV_TYPE_16X16;
467− s->mv[0][0][0] = 0;
468− s->mv[0][0][1] = 0;
469− s->mb_skipped = 1;
462+ h->c.block_last_index[i] = -1;
463+ h->c.mv_dir = MV_DIR_FORWARD;
464+ h->c.mv_type = MV_TYPE_16X16;
465+ h->c.mv[0][0][0] = 0;
466+ h->c.mv[0][0][1] = 0;
467+ h->c.mb_skipped = 1;
470468 w->common.hshift = 0;
471469 return 0;
472470 }
473− if (get_bits_left(&s->gb) <= 0)
471+ if (get_bits_left(&h->c.gb) <= 0)
474472 return AVERROR_INVALIDDATA;
475473
476− code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[w->cbp_table_index],
474+ code = get_vlc2(&h->c.gb, ff_mb_non_intra_vlc[w->cbp_table_index],
477475 MB_NON_INTRA_VLC_BITS, 3);
478− s->mb_intra = (~code & 0x40) >> 6;
476+ h->c.mb_intra = (~code & 0x40) >> 6;
479477
480478 cbp = code & 0x3f;
481479 } else {
482− s->mb_intra = 1;
483− if (get_bits_left(&s->gb) <= 0)
480+ h->c.mb_intra = 1;
481+ if (get_bits_left(&h->c.gb) <= 0)
484482 return AVERROR_INVALIDDATA;
485− code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc,
483+ code = get_vlc2(&h->c.gb, ff_msmp4_mb_i_vlc,
486484 MSMP4_MB_INTRA_VLC_BITS, 2);
487485 /* predict coded block pattern */
488486 cbp = 0;
489487 for (i = 0; i < 6; i++) {
490488 int val = ((code >> (5 - i)) & 1);
491489 if (i < 4) {
492− int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
490+ int pred = ff_msmpeg4_coded_block_pred(&h->c, i, &coded_val);
493491 val = val ^ pred;
494492 *coded_val = val;
495493 }
@@ -497,65 +495,65 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 1 unmodified line
497495 }
498496 }
499497
500− if (!s->mb_intra) {
498+ if (!h->c.mb_intra) {
501499 int mx, my;
502500 wmv2_pred_motion(w, &mx, &my);
503501
504502 if (cbp) {
505− s->bdsp.clear_blocks(s->block[0]);
503+ h->c.bdsp.clear_blocks(h->c.block[0]);
506504 if (ms->per_mb_rl_table) {
507− ms->rl_table_index = decode012(&s->gb);
505+ ms->rl_table_index = decode012(&h->c.gb);
508506 ms->rl_chroma_table_index = ms->rl_table_index;
509507 }
510508
511509 if (w->abt_flag && w->per_mb_abt) {
512− w->per_block_abt = get_bits1(&s->gb);
510+ w->per_block_abt = get_bits1(&h->c.gb);
513511 if (!w->per_block_abt)
514− w->abt_type = decode012(&s->gb);
512+ w->abt_type = decode012(&h->c.gb);
515513 } else
516514 w->per_block_abt = 0;
517515 }
518516
519517 wmv2_decode_motion(w, &mx, &my);
520518
521− s->mv_dir = MV_DIR_FORWARD;
522− s->mv_type = MV_TYPE_16X16;
523− s->mv[0][0][0] = mx;
524− s->mv[0][0][1] = my;
519+ h->c.mv_dir = MV_DIR_FORWARD;
520+ h->c.mv_type = MV_TYPE_16X16;
521+ h->c.mv[0][0][0] = mx;
522+ h->c.mv[0][0][1] = my;
525523
526524 for (i = 0; i < 6; i++) {
527525 if ((ret = wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1)) < 0) {
528− av_log(s->avctx, AV_LOG_ERROR,
526+ av_log(h->c.avctx, AV_LOG_ERROR,
529527 "\nerror while decoding inter block: %d x %d (%d)\n",
530− s->mb_x, s->mb_y, i);
528+ h->c.mb_x, h->c.mb_y, i);
531529 return ret;
532530 }
533531 }
534532 } else {
535− if (s->pict_type == AV_PICTURE_TYPE_P)
536− ff_dlog(s->avctx, "%d%d ", s->inter_intra_pred, cbp);
537− ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
533+ if (h->c.pict_type == AV_PICTURE_TYPE_P)
534+ ff_dlog(h->c.avctx, "%d%d ", h->c.inter_intra_pred, cbp);
535+ ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
538536 ((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0),
539− show_bits(&s->gb, 24));
540− s->ac_pred = get_bits1(&s->gb);
541− if (s->inter_intra_pred) {
542− s->h263_aic_dir = get_vlc2(&s->gb, ff_inter_intra_vlc,
537+ show_bits(&h->c.gb, 24));
538+ h->c.ac_pred = get_bits1(&h->c.gb);
539+ if (h->c.inter_intra_pred) {
540+ h->c.h263_aic_dir = get_vlc2(&h->c.gb, ff_inter_intra_vlc,
543541 INTER_INTRA_VLC_BITS, 1);
544− ff_dlog(s->avctx, "%d%d %d %d/",
545− s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
542+ ff_dlog(h->c.avctx, "%d%d %d %d/",
543+ h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
546544 }
547545 if (ms->per_mb_rl_table && cbp) {
548− ms->rl_table_index = decode012(&s->gb);
546+ ms->rl_table_index = decode012(&h->c.gb);
549547 ms->rl_chroma_table_index = ms->rl_table_index;
550548 }
551549
552− s->bdsp.clear_blocks(s->block[0]);
550+ h->c.bdsp.clear_blocks(h->c.block[0]);
553551 for (i = 0; i < 6; i++) {
554552 ret = ff_msmpeg4_decode_block(ms, block[i], i, (cbp >> (5 - i)) & 1, NULL);
555553 if (ret < 0) {
556− av_log(s->avctx, AV_LOG_ERROR,
554+ av_log(h->c.avctx, AV_LOG_ERROR,
557555 "\nerror while decoding intra block: %d x %d (%d)\n",
558− s->mb_x, s->mb_y, i);
556+ h->c.mb_x, h->c.mb_y, i);
559557 return ret;
560558 }
561559 }
@@ -567,7 +565,8 @@ static int wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 5 unmodified lines
567565 static av_cold int wmv2_decode_init(AVCodecContext *avctx)
568566 {
569567 WMV2DecContext *const w = avctx->priv_data;
570− MpegEncContext *const s = &w->ms.m;
568+ H263DecContext *const h = &w->ms.h;
569+ MpegEncContext *const s = &h->c;
571570 int ret;
572571
573572 s->private_ctx = &w->common;
@@ -575,13 +574,13 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx) · 1 unmodified line
575574 if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
576575 return ret;
577576
578− s->decode_mb = wmv2_decode_mb;
577+ h->decode_mb = wmv2_decode_mb;
579578
580579 ff_wmv2_common_init(s);
581580
582581 decode_ext_header(w);
583582
584− return ff_intrax8_common_init(avctx, &w->x8, s->block[0],
583+ return ff_intrax8_common_init(avctx, &w->x8, h->c.block[0],
585584 s->mb_width, s->mb_height);
586585 }
587586
libavcodec/wmv2dec.h+3−2
@@ -22,9 +22,10 @@ · 21 unmodified lines
2222 #define AVCODEC_WMV2DEC_H
2323
2424 #include "mpegvideo.h"
25+struct H263DecContext;
2526
26−int ff_wmv2_decode_picture_header(MpegEncContext * s);
27−int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s);
27+int ff_wmv2_decode_picture_header(struct H263DecContext *const h);
28+int ff_wmv2_decode_secondary_picture_header(struct H263DecContext *const h);
2829 void ff_wmv2_add_mb(MpegEncContext *s, int16_t block[6][64],
2930 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr);
3031
libavcodec/wmv2enc.c+1−1
@@ -118,7 +118,7 @@ static int wmv2_encode_picture_header(MPVMainEncContext *const m) · 117 unmodified lines
118118 put_bits(&s->pb, 2, SKIP_TYPE_NONE);
119119
120120 ff_msmpeg4_code012(&s->pb, cbp_index = 0);
121− w->cbp_table_index = wmv2_get_cbp_table_index(&s->c, cbp_index);
121+ w->cbp_table_index = wmv2_get_cbp_table_index(s->c.qscale, cbp_index);
122122
123123 if (w->mspel_bit)
124124 put_bits(&s->pb, 1, s->c.mspel);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t