History

avcodec/mpegpicture: Split MPVPicture into WorkPicture and ordinary Pic

There are two types of MPVPictures: Three (cur_pic, last_pic, next_pic) that are directly part of MpegEncContext and an array of MPVPictures that are separately allocated and are mostly accessed via pointers (cur|last|next)_pic_ptr; they are also used to store AVFrames in the encoder (necessary due to B-frames). As the name implies, each of the former is directly associated with one of the _ptr pointers: They actually share the same underlying buffers, but the ones that are part of the context can have their data pointers offset and their linesize doubled for field pictures. Up until now, each of these had their own references; in particular, there was an underlying av_frame_ref() to sync cur_pic and cur_pic_ptr etc. This is wasteful. This commit changes this relationship: cur_pic, last_pic and next_pic now become MPVWorkPictures; this structure does not have an AVFrame at all any more, but only the cached values of data and linesize. It also contains a pointer to the corresponding MPVPicture, establishing a more natural relationsship between the two. This already means that creating the context-pictures from the pointers can no longer fail. What has not been changed is the fact that the MPVPicture* pointers are not ownership pointers and that the MPVPictures are part of an array of MPVPictures that is owned by a single AVCodecContext. Doing so will be done in a latter commit.

Andreas Rheinhardt committed 3 years ago

Commit fe6037f1 parent dac15a543 files · +386 −418Browse files

Unified · Split

43 files
  1. libavcodec/d3d12va_mpeg2.c +5 −5
  2. libavcodec/d3d12va_vc1.c +5 −5
  3. libavcodec/dxva2_mpeg2.c +8 −8
  4. libavcodec/dxva2_vc1.c +10 −10
  5. libavcodec/h261dec.c +3 −4
  6. libavcodec/h263dec.c +16 −17
  7. libavcodec/ituh263dec.c +2 −2
  8. libavcodec/mpeg12dec.c +28 −28
  9. libavcodec/mpeg12enc.c +7 −7
  10. libavcodec/mpeg4videodec.c +2 −2
  11. libavcodec/mpeg4videoenc.c +2 −2
  12. libavcodec/mpeg_er.c +3 −3
  13. libavcodec/mpegpicture.c +42 −14
  14. libavcodec/mpegpicture.h +25 −5
  15. libavcodec/mpegvideo.c +0 −11
  16. libavcodec/mpegvideo.h +3 −6
  17. libavcodec/mpegvideo_dec.c +52 −91
  18. libavcodec/mpegvideo_enc.c +35 −64
  19. libavcodec/mpegvideo_motion.c +4 −4
  20. libavcodec/mpv_reconstruct_mb_template.c +2 −2
  21. libavcodec/mss2.c +1 −1
  22. libavcodec/nvdec_mpeg12.c +3 −3
  23. libavcodec/nvdec_mpeg4.c +3 −3
  24. libavcodec/nvdec_vc1.c +3 −3
  25. libavcodec/ratecontrol.c +5 −5
  26. libavcodec/rv10.c +14 −14
  27. libavcodec/rv34.c +19 −19
  28. libavcodec/snowenc.c +9 −8
  29. libavcodec/svq1enc.c +3 −2
  30. libavcodec/vaapi_mpeg2.c +6 −6
  31. libavcodec/vaapi_mpeg4.c +7 −7
  32. libavcodec/vaapi_vc1.c +8 −6
  33. libavcodec/vc1.c +1 −1
  34. libavcodec/vc1_block.c +6 −6
  35. libavcodec/vc1_mc.c +7 −7
  36. libavcodec/vc1_pred.c +1 −1
  37. libavcodec/vc1dec.c +20 −20
  38. libavcodec/vdpau.c +1 −1
  39. libavcodec/vdpau_mpeg12.c +4 −4
  40. libavcodec/vdpau_mpeg4.c +3 −3
  41. libavcodec/vdpau_vc1.c +6 −6
  42. libavcodec/videotoolbox.c +1 −1
  43. libavcodec/wmv2dec.c +1 −1
libavcodec/d3d12va_mpeg2.c+5−5
@@ -44,7 +44,7 @@ static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint · 43 unmodified lines
4444 {
4545 const MpegEncContext *s = avctx->priv_data;
4646 D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
47− D3D12DecodePictureContext *ctx_pic = s->cur_pic_ptr->hwaccel_picture_private;
47+ D3D12DecodePictureContext *ctx_pic = s->cur_pic.ptr->hwaccel_picture_private;
4848
4949 if (!ctx)
5050 return -1;
@@ -69,7 +69,7 @@ static int d3d12va_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint · 18 unmodified lines
6969 static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
7070 {
7171 const MpegEncContext *s = avctx->priv_data;
72− D3D12DecodePictureContext *ctx_pic = s->cur_pic_ptr->hwaccel_picture_private;
72+ D3D12DecodePictureContext *ctx_pic = s->cur_pic.ptr->hwaccel_picture_private;
7373
7474 if (ctx_pic->slice_count >= MAX_SLICES) {
7575 return AVERROR(ERANGE);
@@ -88,7 +88,7 @@ static int d3d12va_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buff · 12 unmodified lines
8888 static int update_input_arguments(AVCodecContext *avctx, D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
8989 {
9090 const MpegEncContext *s = avctx->priv_data;
91− D3D12DecodePictureContext *ctx_pic = s->cur_pic_ptr->hwaccel_picture_private;
91+ D3D12DecodePictureContext *ctx_pic = s->cur_pic.ptr->hwaccel_picture_private;
9292
9393 const int is_field = s->picture_structure != PICT_FRAME;
9494 const unsigned mb_count = s->mb_width * (s->mb_height >> is_field);
@@ -137,12 +137,12 @@ static int d3d12va_mpeg2_end_frame(AVCodecContext *avctx) · 42 unmodified lines
137137 {
138138 int ret;
139139 MpegEncContext *s = avctx->priv_data;
140− D3D12DecodePictureContext *ctx_pic = s->cur_pic_ptr->hwaccel_picture_private;
140+ D3D12DecodePictureContext *ctx_pic = s->cur_pic.ptr->hwaccel_picture_private;
141141
142142 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
143143 return -1;
144144
145− ret = ff_d3d12va_common_end_frame(avctx, s->cur_pic_ptr->f, &ctx_pic->pp, sizeof(ctx_pic->pp),
145+ ret = ff_d3d12va_common_end_frame(avctx, s->cur_pic.ptr->f, &ctx_pic->pp, sizeof(ctx_pic->pp),
146146 &ctx_pic->qm, sizeof(ctx_pic->qm), update_input_arguments);
147147 if (!ret)
148148 ff_mpeg_draw_horiz_band(s, 0, avctx->height);
libavcodec/d3d12va_vc1.c+5−5
@@ -45,7 +45,7 @@ static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_ · 44 unmodified lines
4545 {
4646 const VC1Context *v = avctx->priv_data;
4747 D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
48− D3D12DecodePictureContext *ctx_pic = v->s.cur_pic_ptr->hwaccel_picture_private;
48+ D3D12DecodePictureContext *ctx_pic = v->s.cur_pic.ptr->hwaccel_picture_private;
4949
5050 if (!ctx)
5151 return -1;
@@ -67,7 +67,7 @@ static int d3d12va_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_ · 15 unmodified lines
6767 static int d3d12va_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
6868 {
6969 const VC1Context *v = avctx->priv_data;
70− D3D12DecodePictureContext *ctx_pic = v->s.cur_pic_ptr->hwaccel_picture_private;
70+ D3D12DecodePictureContext *ctx_pic = v->s.cur_pic.ptr->hwaccel_picture_private;
7171
7272 if (ctx_pic->slice_count >= MAX_SLICES) {
7373 return AVERROR(ERANGE);
@@ -93,7 +93,7 @@ static int update_input_arguments(AVCodecContext *avctx, D3D12_VIDEO_DECODE_INPU · 19 unmodified lines
9393 {
9494 const VC1Context *v = avctx->priv_data;
9595 const MpegEncContext *s = &v->s;
96− D3D12DecodePictureContext *ctx_pic = s->cur_pic_ptr->hwaccel_picture_private;
96+ D3D12DecodePictureContext *ctx_pic = s->cur_pic.ptr->hwaccel_picture_private;
9797 D3D12_VIDEO_DECODE_FRAME_ARGUMENT *args = &input_args->FrameArguments[input_args->NumFrameArguments++];
9898
9999 const unsigned mb_count = s->mb_width * (s->mb_height >> v->field_mode);
@@ -151,12 +151,12 @@ static int update_input_arguments(AVCodecContext *avctx, D3D12_VIDEO_DECODE_INPU · 51 unmodified lines
151151 static int d3d12va_vc1_end_frame(AVCodecContext *avctx)
152152 {
153153 const VC1Context *v = avctx->priv_data;
154− D3D12DecodePictureContext *ctx_pic = v->s.cur_pic_ptr->hwaccel_picture_private;
154+ D3D12DecodePictureContext *ctx_pic = v->s.cur_pic.ptr->hwaccel_picture_private;
155155
156156 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
157157 return -1;
158158
159− return ff_d3d12va_common_end_frame(avctx, v->s.cur_pic_ptr->f,
159+ return ff_d3d12va_common_end_frame(avctx, v->s.cur_pic.ptr->f,
160160 &ctx_pic->pp, sizeof(ctx_pic->pp),
161161 NULL, 0,
162162 update_input_arguments);
libavcodec/dxva2_mpeg2.c+8−8
@@ -45,17 +45,17 @@ void ff_dxva2_mpeg2_fill_picture_parameters(AVCodecContext *avctx, · 44 unmodified lines
4545 DXVA_PictureParameters *pp)
4646 {
4747 const struct MpegEncContext *s = avctx->priv_data;
48− const MPVPicture *current_picture = s->cur_pic_ptr;
48+ const MPVPicture *current_picture = s->cur_pic.ptr;
4949 int is_field = s->picture_structure != PICT_FRAME;
5050
5151 memset(pp, 0, sizeof(*pp));
5252 pp->wDeblockedPictureIndex = 0;
5353 if (s->pict_type != AV_PICTURE_TYPE_I)
54− pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_pic.f, 0);
54+ pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_pic.ptr->f, 0);
5555 else
5656 pp->wForwardRefPictureIndex = 0xffff;
5757 if (s->pict_type == AV_PICTURE_TYPE_B)
58− pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_pic.f, 0);
58+ pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_pic.ptr->f, 0);
5959 else
6060 pp->wBackwardRefPictureIndex = 0xffff;
6161 pp->wDecodedPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, current_picture->f, 1);
@@ -157,7 +157,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 95 unmodified lines
157157 const struct MpegEncContext *s = avctx->priv_data;
158158 AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
159159 struct dxva2_picture_context *ctx_pic =
160− s->cur_pic_ptr->hwaccel_picture_private;
160+ s->cur_pic.ptr->hwaccel_picture_private;
161161 const int is_field = s->picture_structure != PICT_FRAME;
162162 const unsigned mb_count = s->mb_width * (s->mb_height >> is_field);
163163 void *dxva_data_ptr;
@@ -260,7 +260,7 @@ static int dxva2_mpeg2_start_frame(AVCodecContext *avctx, · 96 unmodified lines
260260 const struct MpegEncContext *s = avctx->priv_data;
261261 AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
262262 struct dxva2_picture_context *ctx_pic =
263− s->cur_pic_ptr->hwaccel_picture_private;
263+ s->cur_pic.ptr->hwaccel_picture_private;
264264
265265 if (!DXVA_CONTEXT_VALID(avctx, ctx))
266266 return -1;
@@ -280,7 +280,7 @@ static int dxva2_mpeg2_decode_slice(AVCodecContext *avctx, · 13 unmodified lines
280280 {
281281 const struct MpegEncContext *s = avctx->priv_data;
282282 struct dxva2_picture_context *ctx_pic =
283− s->cur_pic_ptr->hwaccel_picture_private;
283+ s->cur_pic.ptr->hwaccel_picture_private;
284284 unsigned position;
285285
286286 if (ctx_pic->slice_count >= MAX_SLICES) {
@@ -302,12 +302,12 @@ static int dxva2_mpeg2_end_frame(AVCodecContext *avctx) · 15 unmodified lines
302302 {
303303 struct MpegEncContext *s = avctx->priv_data;
304304 struct dxva2_picture_context *ctx_pic =
305− s->cur_pic_ptr->hwaccel_picture_private;
305+ s->cur_pic.ptr->hwaccel_picture_private;
306306 int ret;
307307
308308 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
309309 return -1;
310− ret = ff_dxva2_common_end_frame(avctx, s->cur_pic_ptr->f,
310+ ret = ff_dxva2_common_end_frame(avctx, s->cur_pic.ptr->f,
311311 &ctx_pic->pp, sizeof(ctx_pic->pp),
312312 &ctx_pic->qm, sizeof(ctx_pic->qm),
313313 commit_bitstream_and_slice_buffer);
libavcodec/dxva2_vc1.c+10−10
@@ -46,7 +46,7 @@ void ff_dxva2_vc1_fill_picture_parameters(AVCodecContext *avctx, · 45 unmodified lines
4646 {
4747 const VC1Context *v = avctx->priv_data;
4848 const MpegEncContext *s = &v->s;
49− const MPVPicture *current_picture = s->cur_pic_ptr;
49+ const MPVPicture *current_picture = s->cur_pic.ptr;
5050 int intcomp = 0;
5151
5252 // determine if intensity compensation is needed
@@ -58,12 +58,12 @@ void ff_dxva2_vc1_fill_picture_parameters(AVCodecContext *avctx, · 5 unmodified lines
5858 }
5959
6060 memset(pp, 0, sizeof(*pp));
61− if (s->pict_type != AV_PICTURE_TYPE_I && !v->bi_type)
62− pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_pic.f, 0);
61+ if (s->pict_type != AV_PICTURE_TYPE_I && !v->bi_type && s->last_pic.ptr)
62+ pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->last_pic.ptr->f, 0);
6363 else
6464 pp->wForwardRefPictureIndex = 0xffff;
65− if (s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type)
66− pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_pic.f, 0);
65+ if (s->pict_type == AV_PICTURE_TYPE_B && !v->bi_type && s->next_pic.ptr)
66+ pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(avctx, ctx, s->next_pic.ptr->f, 0);
6767 else
6868 pp->wBackwardRefPictureIndex = 0xffff;
6969 pp->wDecodedPictureIndex =
@@ -191,7 +191,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext *avctx, · 121 unmodified lines
191191 const VC1Context *v = avctx->priv_data;
192192 AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
193193 const MpegEncContext *s = &v->s;
194− struct dxva2_picture_context *ctx_pic = s->cur_pic_ptr->hwaccel_picture_private;
194+ struct dxva2_picture_context *ctx_pic = s->cur_pic.ptr->hwaccel_picture_private;
195195
196196 static const uint8_t start_code[] = { 0, 0, 1, 0x0d };
197197 const unsigned start_code_size = avctx->codec_id == AV_CODEC_ID_VC1 ? sizeof(start_code) : 0;
@@ -317,7 +317,7 @@ static int dxva2_vc1_start_frame(AVCodecContext *avctx, · 119 unmodified lines
317317 {
318318 const VC1Context *v = avctx->priv_data;
319319 AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
320− struct dxva2_picture_context *ctx_pic = v->s.cur_pic_ptr->hwaccel_picture_private;
320+ struct dxva2_picture_context *ctx_pic = v->s.cur_pic.ptr->hwaccel_picture_private;
321321
322322 if (!DXVA_CONTEXT_VALID(avctx, ctx))
323323 return -1;
@@ -336,7 +336,7 @@ static int dxva2_vc1_decode_slice(AVCodecContext *avctx, · 12 unmodified lines
336336 uint32_t size)
337337 {
338338 const VC1Context *v = avctx->priv_data;
339− const MPVPicture *current_picture = v->s.cur_pic_ptr;
339+ const MPVPicture *current_picture = v->s.cur_pic.ptr;
340340 struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private;
341341 unsigned position;
342342
@@ -364,13 +364,13 @@ static int dxva2_vc1_decode_slice(AVCodecContext *avctx, · 21 unmodified lines
364364 static int dxva2_vc1_end_frame(AVCodecContext *avctx)
365365 {
366366 VC1Context *v = avctx->priv_data;
367− struct dxva2_picture_context *ctx_pic = v->s.cur_pic_ptr->hwaccel_picture_private;
367+ struct dxva2_picture_context *ctx_pic = v->s.cur_pic.ptr->hwaccel_picture_private;
368368 int ret;
369369
370370 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
371371 return -1;
372372
373− ret = ff_dxva2_common_end_frame(avctx, v->s.cur_pic_ptr->f,
373+ ret = ff_dxva2_common_end_frame(avctx, v->s.cur_pic.ptr->f,
374374 &ctx_pic->pp, sizeof(ctx_pic->pp),
375375 NULL, 0,
376376 commit_bitstream_and_slice_buffer);
libavcodec/h261dec.c+3−4
@@ -649,12 +649,11 @@ static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 648 unmodified lines
649649 }
650650 ff_mpv_frame_end(s);
651651
652− av_assert0(s->cur_pic.f->pict_type == s->cur_pic_ptr->f->pict_type);
653− av_assert0(s->cur_pic.f->pict_type == s->pict_type);
652+ av_assert0(s->pict_type == s->cur_pic.ptr->f->pict_type);
654653
655− if ((ret = av_frame_ref(pict, s->cur_pic_ptr->f)) < 0)
654+ if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
656655 return ret;
657− ff_print_debug_info(s, s->cur_pic_ptr, pict);
656+ ff_print_debug_info(s, s->cur_pic.ptr, pict);
658657
659658 *got_frame = 1;
660659
libavcodec/h263dec.c+16−17
@@ -432,22 +432,22 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 431 unmodified lines
432432 /* no supplementary picture */
433433 if (buf_size == 0) {
434434 /* special case for last picture */
435− if (s->low_delay == 0 && s->next_pic_ptr) {
436− if ((ret = av_frame_ref(pict, s->next_pic_ptr->f)) < 0)
435+ if (s->low_delay == 0 && s->next_pic.ptr) {
436+ if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
437437 return ret;
438− s->next_pic_ptr = NULL;
438+ s->next_pic.ptr = NULL;
439439
440440 *got_frame = 1;
441− } else if (s->skipped_last_frame && s->cur_pic_ptr) {
441+ } else if (s->skipped_last_frame && s->cur_pic.ptr) {
442442 /* Output the last picture we decoded again if the stream ended with
443443 * an NVOP */
444− if ((ret = av_frame_ref(pict, s->cur_pic_ptr->f)) < 0)
444+ if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
445445 return ret;
446446 /* Copy props from the last input packet. Otherwise, props from the last
447447 * returned picture would be reused */
448448 if ((ret = ff_decode_frame_props(avctx, pict)) < 0)
449449 return ret;
450− s->cur_pic_ptr = NULL;
450+ s->cur_pic.ptr = NULL;
451451
452452 *got_frame = 1;
453453 }
@@ -561,7 +561,7 @@ retry: · 107 unmodified lines
561561 s->gob_index = H263_GOB_HEIGHT(s->height);
562562
563563 /* skip B-frames if we don't have reference frames */
564− if (!s->last_pic_ptr &&
564+ if (!s->last_pic.ptr &&
565565 (s->pict_type == AV_PICTURE_TYPE_B || s->droppable))
566566 return get_consumed_bytes(s, buf_size);
567567 if ((avctx->skip_frame >= AVDISCARD_NONREF &&
@@ -647,21 +647,20 @@ frame_end: · 79 unmodified lines
647647 if (!s->divx_packed && avctx->hwaccel)
648648 ff_thread_finish_setup(avctx);
649649
650− av_assert1(s->cur_pic.f->pict_type == s->cur_pic_ptr->f->pict_type);
651− av_assert1(s->cur_pic.f->pict_type == s->pict_type);
650+ av_assert1(s->pict_type == s->cur_pic.ptr->f->pict_type);
652651 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
653− if ((ret = av_frame_ref(pict, s->cur_pic_ptr->f)) < 0)
652+ if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
654653 return ret;
655− ff_print_debug_info(s, s->cur_pic_ptr, pict);
656− ff_mpv_export_qp_table(s, pict, s->cur_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG1);
657− } else if (s->last_pic_ptr) {
658− if ((ret = av_frame_ref(pict, s->last_pic_ptr->f)) < 0)
654+ ff_print_debug_info(s, s->cur_pic.ptr, pict);
655+ ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
656+ } else if (s->last_pic.ptr) {
657+ if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0)
659658 return ret;
660− ff_print_debug_info(s, s->last_pic_ptr, pict);
661− ff_mpv_export_qp_table(s, pict, s->last_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG1);
659+ ff_print_debug_info(s, s->last_pic.ptr, pict);
660+ ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
662661 }
663662
664− if (s->last_pic_ptr || s->low_delay) {
663+ if (s->last_pic.ptr || s->low_delay) {
665664 if ( pict->format == AV_PIX_FMT_YUV420P
666665 && (s->codec_tag == AV_RL32("GEOV") || s->codec_tag == AV_RL32("GEOX"))) {
667666 for (int p = 0; p < 3; p++) {
libavcodec/ituh263dec.c+2−2
@@ -750,12 +750,12 @@ static inline void set_one_direct_mv(MpegEncContext *s, const MPVPicture *p, int · 749 unmodified lines
750750 static int set_direct_mv(MpegEncContext *s)
751751 {
752752 const int mb_index = s->mb_x + s->mb_y * s->mb_stride;
753− const MPVPicture *p = &s->next_pic;
753+ const MPVPicture *p = s->next_pic.ptr;
754754 int colocated_mb_type = p->mb_type[mb_index];
755755 int i;
756756
757757 if (s->codec_tag == AV_RL32("U263") && p->f->pict_type == AV_PICTURE_TYPE_I) {
758− p = &s->last_pic;
758+ p = s->last_pic.ptr;
759759 colocated_mb_type = p->mb_type[mb_index];
760760 }
761761
libavcodec/mpeg12dec.c+28−28
@@ -1292,7 +1292,7 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) · 1291 unmodified lines
12921292 return ret;
12931293
12941294 if (s->picture_structure != PICT_FRAME) {
1295− s->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST *
1295+ s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST *
12961296 (s->picture_structure == PICT_TOP_FIELD);
12971297
12981298 for (int i = 0; i < 3; i++) {
@@ -1309,19 +1309,19 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) · 10 unmodified lines
13091309 ff_mpeg_er_frame_start(s);
13101310
13111311 /* first check if we must repeat the frame */
1312− s->cur_pic_ptr->f->repeat_pict = 0;
1312+ s->cur_pic.ptr->f->repeat_pict = 0;
13131313 if (s->repeat_first_field) {
13141314 if (s->progressive_sequence) {
13151315 if (s->top_field_first)
1316− s->cur_pic_ptr->f->repeat_pict = 4;
1316+ s->cur_pic.ptr->f->repeat_pict = 4;
13171317 else
1318− s->cur_pic_ptr->f->repeat_pict = 2;
1318+ s->cur_pic.ptr->f->repeat_pict = 2;
13191319 } else if (s->progressive_frame) {
1320− s->cur_pic_ptr->f->repeat_pict = 1;
1320+ s->cur_pic.ptr->f->repeat_pict = 1;
13211321 }
13221322 }
13231323
1324− ret = ff_frame_new_side_data(s->avctx, s->cur_pic_ptr->f,
1324+ ret = ff_frame_new_side_data(s->avctx, s->cur_pic.ptr->f,
13251325 AV_FRAME_DATA_PANSCAN, sizeof(s1->pan_scan),
13261326 &pan_scan);
13271327 if (ret < 0)
@@ -1331,14 +1331,14 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) · 3 unmodified lines
13311331
13321332 if (s1->a53_buf_ref) {
13331333 ret = ff_frame_new_side_data_from_buf(
1334− s->avctx, s->cur_pic_ptr->f, AV_FRAME_DATA_A53_CC,
1334+ s->avctx, s->cur_pic.ptr->f, AV_FRAME_DATA_A53_CC,
13351335 &s1->a53_buf_ref, NULL);
13361336 if (ret < 0)
13371337 return ret;
13381338 }
13391339
13401340 if (s1->has_stereo3d) {
1341− AVStereo3D *stereo = av_stereo3d_create_side_data(s->cur_pic_ptr->f);
1341+ AVStereo3D *stereo = av_stereo3d_create_side_data(s->cur_pic.ptr->f);
13421342 if (!stereo)
13431343 return AVERROR(ENOMEM);
13441344
@@ -1348,7 +1348,7 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) · 3 unmodified lines
13481348
13491349 if (s1->has_afd) {
13501350 AVFrameSideData *sd;
1351− ret = ff_frame_new_side_data(s->avctx, s->cur_pic_ptr->f,
1351+ ret = ff_frame_new_side_data(s->avctx, s->cur_pic.ptr->f,
13521352 AV_FRAME_DATA_AFD, 1, &sd);
13531353 if (ret < 0)
13541354 return ret;
@@ -1360,7 +1360,7 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) · 5 unmodified lines
13601360 if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME))
13611361 ff_thread_finish_setup(avctx);
13621362 } else { // second field
1363− if (!s->cur_pic_ptr) {
1363+ if (!s->cur_pic.ptr) {
13641364 av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
13651365 return AVERROR_INVALIDDATA;
13661366 }
@@ -1377,10 +1377,10 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) · 10 unmodified lines
13771377 return ret;
13781378
13791379 for (int i = 0; i < 3; i++) {
1380− s->cur_pic.data[i] = s->cur_pic_ptr->f->data[i];
1380+ s->cur_pic.data[i] = s->cur_pic.ptr->f->data[i];
13811381 if (s->picture_structure == PICT_BOTTOM_FIELD)
13821382 s->cur_pic.data[i] +=
1383− s->cur_pic_ptr->f->linesize[i];
1383+ s->cur_pic.ptr->f->linesize[i];
13841384 }
13851385 }
13861386
@@ -1735,7 +1735,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output) · 348 unmodified lines
17351735 Mpeg1Context *s1 = avctx->priv_data;
17361736 MpegEncContext *s = &s1->mpeg_enc_ctx;
17371737
1738− if (!s->context_initialized || !s->cur_pic_ptr)
1738+ if (!s->context_initialized || !s->cur_pic.ptr)
17391739 return 0;
17401740
17411741 if (s->avctx->hwaccel) {
@@ -1756,20 +1756,20 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output) · 14 unmodified lines
17561756 ff_mpv_frame_end(s);
17571757
17581758 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
1759− int ret = av_frame_ref(pict, s->cur_pic_ptr->f);
1759+ int ret = av_frame_ref(pict, s->cur_pic.ptr->f);
17601760 if (ret < 0)
17611761 return ret;
1762− ff_print_debug_info(s, s->cur_pic_ptr, pict);
1763− ff_mpv_export_qp_table(s, pict, s->cur_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG2);
1762+ ff_print_debug_info(s, s->cur_pic.ptr, pict);
1763+ ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG2);
17641764 *got_output = 1;
17651765 } else {
17661766 /* latency of 1 frame for I- and P-frames */
1767− if (s->last_pic_ptr && !s->last_pic_ptr->dummy) {
1768− int ret = av_frame_ref(pict, s->last_pic_ptr->f);
1767+ if (s->last_pic.ptr && !s->last_pic.ptr->dummy) {
1768+ int ret = av_frame_ref(pict, s->last_pic.ptr->f);
17691769 if (ret < 0)
17701770 return ret;
1771− ff_print_debug_info(s, s->last_pic_ptr, pict);
1772− ff_mpv_export_qp_table(s, pict, s->last_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG2);
1771+ ff_print_debug_info(s, s->last_pic.ptr, pict);
1772+ ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG2);
17731773 *got_output = 1;
17741774 }
17751775 }
@@ -2405,7 +2405,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, · 629 unmodified lines
24052405 return AVERROR_INVALIDDATA;
24062406 }
24072407
2408− if (!s2->last_pic_ptr) {
2408+ if (!s2->last_pic.ptr) {
24092409 /* Skip B-frames if we do not have reference frames and
24102410 * GOP is not closed. */
24112411 if (s2->pict_type == AV_PICTURE_TYPE_B) {
@@ -2419,7 +2419,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, · 7 unmodified lines
24192419 }
24202420 if (s2->pict_type == AV_PICTURE_TYPE_I || (s2->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL))
24212421 s->sync = 1;
2422− if (!s2->next_pic_ptr) {
2422+ if (!s2->next_pic.ptr) {
24232423 /* Skip P-frames if we do not have a reference frame or
24242424 * we have an invalid header. */
24252425 if (s2->pict_type == AV_PICTURE_TYPE_P && !s->sync) {
@@ -2460,7 +2460,7 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, · 34 unmodified lines
24602460 if ((ret = mpeg_field_start(s2, buf, buf_size)) < 0)
24612461 return ret;
24622462 }
2463− if (!s2->cur_pic_ptr) {
2463+ if (!s2->cur_pic.ptr) {
24642464 av_log(avctx, AV_LOG_ERROR,
24652465 "current_picture not initialized\n");
24662466 return AVERROR_INVALIDDATA;
@@ -2524,12 +2524,12 @@ static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture, · 57 unmodified lines
25242524
25252525 if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
25262526 /* special case for last picture */
2527− if (s2->low_delay == 0 && s2->next_pic_ptr) {
2528− int ret = av_frame_ref(picture, s2->next_pic_ptr->f);
2527+ if (s2->low_delay == 0 && s2->next_pic.ptr) {
2528+ int ret = av_frame_ref(picture, s2->next_pic.ptr->f);
25292529 if (ret < 0)
25302530 return ret;
25312531
2532− s2->next_pic_ptr = NULL;
2532+ s2->next_pic.ptr = NULL;
25332533
25342534 *got_output = 1;
25352535 }
@@ -2552,14 +2552,14 @@ static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture, · 16 unmodified lines
25522552 }
25532553 s->extradata_decoded = 1;
25542554 if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) {
2555− s2->cur_pic_ptr = NULL;
2555+ s2->cur_pic.ptr = NULL;
25562556 return ret;
25572557 }
25582558 }
25592559
25602560 ret = decode_chunks(avctx, picture, got_output, buf, buf_size);
25612561 if (ret<0 || *got_output) {
2562− s2->cur_pic_ptr = NULL;
2562+ s2->cur_pic.ptr = NULL;
25632563
25642564 if (s->timecode_frame_start != -1 && *got_output) {
25652565 char tcbuf[AV_TIMECODE_STR_SIZE];
libavcodec/mpeg12enc.c+7−7
@@ -290,7 +290,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) · 289 unmodified lines
290290 AVRational aspect_ratio = s->avctx->sample_aspect_ratio;
291291 int aspect_ratio_info;
292292
293− if (!(s->cur_pic.f->flags & AV_FRAME_FLAG_KEY))
293+ if (!(s->cur_pic.ptr->f->flags & AV_FRAME_FLAG_KEY))
294294 return;
295295
296296 if (aspect_ratio.num == 0 || aspect_ratio.den == 0)
@@ -382,7 +382,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) · 85 unmodified lines
382382 put_bits(&s->pb, 2, mpeg12->frame_rate_ext.num-1); // frame_rate_ext_n
383383 put_bits(&s->pb, 5, mpeg12->frame_rate_ext.den-1); // frame_rate_ext_d
384384
385− side_data = av_frame_get_side_data(s->cur_pic_ptr->f, AV_FRAME_DATA_PANSCAN);
385+ side_data = av_frame_get_side_data(s->cur_pic.ptr->f, AV_FRAME_DATA_PANSCAN);
386386 if (side_data) {
387387 const AVPanScan *pan_scan = (AVPanScan *)side_data->data;
388388 if (pan_scan->width && pan_scan->height) {
@@ -419,10 +419,10 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s) · 30 unmodified lines
419419 /* time code: we must convert from the real frame rate to a
420420 * fake MPEG frame rate in case of low frame rate */
421421 fps = (framerate.num + framerate.den / 2) / framerate.den;
422− time_code = s->cur_pic_ptr->coded_picture_number +
422+ time_code = s->cur_pic.ptr->coded_picture_number +
423423 mpeg12->timecode_frame_start;
424424
425− mpeg12->gop_picture_number = s->cur_pic_ptr->coded_picture_number;
425+ mpeg12->gop_picture_number = s->cur_pic.ptr->coded_picture_number;
426426
427427 av_assert0(mpeg12->drop_frame_timecode == !!(mpeg12->tc.flags & AV_TIMECODE_FLAG_DROPFRAME));
428428 if (mpeg12->drop_frame_timecode)
@@ -530,7 +530,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s) · 101 unmodified lines
530530 if (s->progressive_sequence)
531531 put_bits(&s->pb, 1, 0); /* no repeat */
532532 else
533− put_bits(&s->pb, 1, !!(s->cur_pic_ptr->f->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST));
533+ put_bits(&s->pb, 1, !!(s->cur_pic.ptr->f->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST));
534534 /* XXX: optimize the generation of this flag with entropy measures */
535535 s->frame_pred_frame_dct = s->progressive_sequence;
536536
@@ -554,7 +554,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s) · 17 unmodified lines
554554 for (i = 0; i < sizeof(svcd_scan_offset_placeholder); i++)
555555 put_bits(&s->pb, 8, svcd_scan_offset_placeholder[i]);
556556 }
557− side_data = av_frame_get_side_data(s->cur_pic_ptr->f,
557+ side_data = av_frame_get_side_data(s->cur_pic.ptr->f,
558558 AV_FRAME_DATA_STEREO3D);
559559 if (side_data) {
560560 const AVStereo3D *stereo = (AVStereo3D *)side_data->data;
@@ -594,7 +594,7 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s) · 33 unmodified lines
594594 }
595595
596596 if (CONFIG_MPEG2VIDEO_ENCODER && mpeg12->a53_cc) {
597− side_data = av_frame_get_side_data(s->cur_pic_ptr->f,
597+ side_data = av_frame_get_side_data(s->cur_pic.ptr->f,
598598 AV_FRAME_DATA_A53_CC);
599599 if (side_data) {
600600 if (side_data->size <= A53_MAX_CC_COUNT * 3 && side_data->size % 3 == 0) {
libavcodec/mpeg4videodec.c+2−2
@@ -1813,7 +1813,7 @@ static int mpeg4_decode_mb(MpegEncContext *s, int16_t block[6][64]) · 1812 unmodified lines
18131813 s->last_mv[i][1][1] = 0;
18141814 }
18151815
1816− ff_thread_await_progress(&s->next_pic_ptr->tf, s->mb_y, 0);
1816+ ff_thread_await_progress(&s->next_pic.ptr->tf, s->mb_y, 0);
18171817 }
18181818
18191819 /* if we skipped it in the future P-frame than skip it now too */
@@ -2018,7 +2018,7 @@ end: · 198 unmodified lines
20182018
20192019 if (s->pict_type == AV_PICTURE_TYPE_B) {
20202020 const int delta = s->mb_x + 1 == s->mb_width ? 2 : 1;
2021− ff_thread_await_progress(&s->next_pic_ptr->tf,
2021+ ff_thread_await_progress(&s->next_pic.ptr->tf,
20222022 (s->mb_x + delta >= s->mb_width)
20232023 ? FFMIN(s->mb_y + 1, s->mb_height - 1)
20242024 : s->mb_y, 0);
libavcodec/mpeg4videoenc.c+2−2
@@ -888,7 +888,7 @@ static void mpeg4_encode_gop_header(MpegEncContext *s) · 887 unmodified lines
888888 put_bits(&s->pb, 16, 0);
889889 put_bits(&s->pb, 16, GOP_STARTCODE);
890890
891− time = s->cur_pic_ptr->f->pts;
891+ time = s->cur_pic.ptr->f->pts;
892892 if (s->reordered_input_picture[1])
893893 time = FFMIN(time, s->reordered_input_picture[1]->f->pts);
894894 time = time * s->avctx->time_base.num;
@@ -1100,7 +1100,7 @@ int ff_mpeg4_encode_picture_header(MpegEncContext *s) · 205 unmodified lines
11001100 }
11011101 put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
11021102 if (!s->progressive_sequence) {
1103− put_bits(&s->pb, 1, !!(s->cur_pic_ptr->f->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST));
1103+ put_bits(&s->pb, 1, !!(s->cur_pic.ptr->f->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST));
11041104 put_bits(&s->pb, 1, s->alternate_scan);
11051105 }
11061106 // FIXME sprite stuff
libavcodec/mpeg_er.c+3−3
@@ -49,9 +49,9 @@ void ff_mpeg_er_frame_start(MpegEncContext *s) · 48 unmodified lines
4949 {
5050 ERContext *er = &s->er;
5151
52− set_erpic(&er->cur_pic, s->cur_pic_ptr);
53− set_erpic(&er->next_pic, s->next_pic_ptr);
54− set_erpic(&er->last_pic, s->last_pic_ptr);
52+ set_erpic(&er->cur_pic, s->cur_pic.ptr);
53+ set_erpic(&er->next_pic, s->next_pic.ptr);
54+ set_erpic(&er->last_pic, s->last_pic.ptr);
5555
5656 er->pp_time = s->pp_time;
5757 er->pb_time = s->pb_time;
libavcodec/mpegpicture.c+42−14
@@ -45,6 +45,45 @@ static void av_noinline free_picture_tables(MPVPicture *pic) · 44 unmodified lines
4545 pic->mb_height = 0;
4646 }
4747
48+void ff_mpv_unref_picture(MPVWorkPicture *pic)
49+{
50+ if (pic->ptr)
51+ ff_mpeg_unref_picture(pic->ptr);
52+ memset(pic, 0, sizeof(*pic));
53+}
54+
55+static void set_workpic_from_pic(MPVWorkPicture *wpic, const MPVPicture *pic)
56+{
57+ for (int i = 0; i < MPV_MAX_PLANES; i++) {
58+ wpic->data[i] = pic->f->data[i];
59+ wpic->linesize[i] = pic->f->linesize[i];
60+ }
61+ wpic->qscale_table = pic->qscale_table;
62+ wpic->mb_type = pic->mb_type;
63+ wpic->mbskip_table = pic->mbskip_table;
64+
65+ for (int i = 0; i < 2; i++) {
66+ wpic->motion_val[i] = pic->motion_val[i];
67+ wpic->ref_index[i] = pic->ref_index[i];
68+ }
69+ wpic->reference = pic->reference;
70+}
71+
72+void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src)
73+{
74+ memcpy(dst, src, sizeof(*dst));
75+}
76+
77+void ff_mpv_workpic_from_pic(MPVWorkPicture *wpic, MPVPicture *pic)
78+{
79+ if (!pic) {
80+ memset(wpic, 0, sizeof(*wpic));
81+ return;
82+ }
83+ wpic->ptr = pic;
84+ set_workpic_from_pic(wpic, pic);
85+}
86+
4887 int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me,
4988 ScratchpadContext *sc, int linesize)
5089 {
@@ -143,17 +182,13 @@ static int alloc_picture_tables(BufferPoolContext *pools, MPVPicture *pic, · 92 unmodified lines
143182 return 0;
144183 }
145184
146−int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, MPVPicture *pic,
185+int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, MPVWorkPicture *wpic,
147186 MotionEstContext *me, ScratchpadContext *sc,
148187 BufferPoolContext *pools, int mb_height)
149188 {
189+ MPVPicture *pic = wpic->ptr;
150190 int ret;
151191
152− for (int i = 0; i < MPV_MAX_PLANES; i++) {
153− pic->data[i] = pic->f->data[i];
154− pic->linesize[i] = pic->f->linesize[i];
155− }
156−
157192 ret = ff_mpeg_framesize_alloc(avctx, me, sc,
158193 pic->f->linesize[0]);
159194 if (ret < 0)
@@ -170,6 +205,7 @@ int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, MPVPicture *pic, · 10 unmodified lines
170205 for (int i = 0; i < 2; i++)
171206 pic->motion_val[i] = pic->motion_val_base[i] + 4;
172207 }
208+ set_workpic_from_pic(wpic, pic);
173209
174210 return 0;
175211 fail:
@@ -190,9 +226,6 @@ void ff_mpeg_unref_picture(MPVPicture *pic) · 14 unmodified lines
190226
191227 free_picture_tables(pic);
192228
193− memset(pic->data, 0, sizeof(pic->data));
194− memset(pic->linesize, 0, sizeof(pic->linesize));
195−
196229 pic->dummy = 0;
197230
198231 pic->field_picture = 0;
@@ -236,11 +269,6 @@ int ff_mpeg_ref_picture(MPVPicture *dst, MPVPicture *src) · 37 unmodified lines
236269 if (ret < 0)
237270 goto fail;
238271
239− for (int i = 0; i < MPV_MAX_PLANES; i++) {
240− dst->data[i] = src->data[i];
241− dst->linesize[i] = src->linesize[i];
242− }
243−
244272 update_picture_tables(dst, src);
245273
246274 ff_refstruct_replace(&dst->hwaccel_picture_private,
libavcodec/mpegpicture.h+25−5
@@ -58,9 +58,6 @@ typedef struct MPVPicture { · 57 unmodified lines
5858 struct AVFrame *f;
5959 ThreadFrame tf;
6060
61− uint8_t *data[MPV_MAX_PLANES];
62− ptrdiff_t linesize[MPV_MAX_PLANES];
63−
6461 int8_t *qscale_table_base;
6562 int8_t *qscale_table;
6663
@@ -93,10 +90,30 @@ typedef struct MPVPicture { · 26 unmodified lines
9390 int coded_picture_number;
9491 } MPVPicture;
9592
93+typedef struct MPVWorkPicture {
94+ uint8_t *data[MPV_MAX_PLANES];
95+ ptrdiff_t linesize[MPV_MAX_PLANES];
96+
97+ MPVPicture *ptr;
98+
99+ int8_t *qscale_table;
100+
101+ int16_t (*motion_val[2])[2];
102+
103+ uint32_t *mb_type; ///< types and macros are defined in mpegutils.h
104+
105+ uint8_t *mbskip_table;
106+
107+ int8_t *ref_index[2];
108+
109+ int reference;
110+} MPVWorkPicture;
111+
96112 /**
97− * Allocate an MPVPicture's accessories, but not the AVFrame's buffer itself.
113+ * Allocate an MPVPicture's accessories (but not the AVFrame's buffer itself)
114+ * and set the MPVWorkPicture's fields.
98115 */
99−int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, MPVPicture *pic,
116+int ff_mpv_alloc_pic_accessories(AVCodecContext *avctx, MPVWorkPicture *pic,
100117 MotionEstContext *me, ScratchpadContext *sc,
101118 BufferPoolContext *pools, int mb_height);
102119
@@ -113,6 +130,9 @@ int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, · 10 unmodified lines
113130 ScratchpadContext *sc, int linesize);
114131
115132 int ff_mpeg_ref_picture(MPVPicture *dst, MPVPicture *src);
133+void ff_mpv_unref_picture(MPVWorkPicture *pic);
134+void ff_mpv_workpic_from_pic(MPVWorkPicture *wpic, MPVPicture *pic);
135+void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src);
116136 void ff_mpeg_unref_picture(MPVPicture *picture);
117137
118138 void ff_mpv_picture_free(MPVPicture *pic);
libavcodec/mpegvideo.c+0−11
@@ -763,11 +763,6 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) · 762 unmodified lines
763763 goto fail_nomem;
764764 }
765765
766− if (!(s->next_pic.f = av_frame_alloc()) ||
767− !(s->last_pic.f = av_frame_alloc()) ||
768− !(s->cur_pic.f = av_frame_alloc()))
769− goto fail_nomem;
770−
771766 if ((ret = ff_mpv_init_context_frame(s)))
772767 goto fail;
773768
@@ -840,15 +835,9 @@ void ff_mpv_common_end(MpegEncContext *s) · 66 unmodified lines
840835 ff_mpv_picture_free(&s->picture[i]);
841836 }
842837 av_freep(&s->picture);
843− ff_mpv_picture_free(&s->last_pic);
844− ff_mpv_picture_free(&s->cur_pic);
845− ff_mpv_picture_free(&s->next_pic);
846838
847839 s->context_initialized = 0;
848840 s->context_reinit = 0;
849− s->last_pic_ptr =
850− s->next_pic_ptr =
851− s->cur_pic_ptr = NULL;
852841 s->linesize = s->uvlinesize = 0;
853842 }
854843
libavcodec/mpegvideo.h+3−6
@@ -156,13 +156,13 @@ typedef struct MpegEncContext { · 155 unmodified lines
156156 * copy of the previous picture structure.
157157 * note, linesize & data, might not match the previous picture (for field pictures)
158158 */
159− MPVPicture last_pic;
159+ MPVWorkPicture last_pic;
160160
161161 /**
162162 * copy of the next picture structure.
163163 * note, linesize & data, might not match the next picture (for field pictures)
164164 */
165− MPVPicture next_pic;
165+ MPVWorkPicture next_pic;
166166
167167 /**
168168 * Reference to the source picture for encoding.
@@ -174,11 +174,8 @@ typedef struct MpegEncContext { · 5 unmodified lines
174174 * copy of the current picture structure.
175175 * note, linesize & data, might not match the current picture (for field pictures)
176176 */
177− MPVPicture cur_pic;
177+ MPVWorkPicture cur_pic;
178178
179− MPVPicture *last_pic_ptr; ///< pointer to the previous picture.
180− MPVPicture *next_pic_ptr; ///< pointer to the next picture (for bidir pred)
181− MPVPicture *cur_pic_ptr; ///< pointer to the current picture
182179 int skipped_last_frame;
183180 int last_dc[3]; ///< last DC values for MPEG-1
184181 int16_t *dc_val_base;
libavcodec/mpegvideo_dec.c+52−91
@@ -114,12 +114,10 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, · 113 unmodified lines
114114
115115 #define UPDATE_PICTURE(pic)\
116116 do {\
117− ff_mpeg_unref_picture(&s->pic);\
118− if (s1->pic.f && s1->pic.f->buf[0]) {\
119− ret = ff_mpeg_ref_picture(&s->pic, &s1->pic);\
120− if (ret < 0)\
121− return ret;\
122− }\
117+ if (s->picture && s1->picture && s1->pic.ptr && s1->pic.ptr->f->buf[0]) {\
118+ ff_mpv_workpic_from_pic(&s->pic, &s->picture[s1->pic.ptr - s1->picture]);\
119+ } else\
120+ ff_mpv_unref_picture(&s->pic);\
123121 } while (0)
124122
125123 UPDATE_PICTURE(cur_pic);
@@ -129,15 +127,6 @@ do {\ · 3 unmodified lines
129127 s->linesize = s1->linesize;
130128 s->uvlinesize = s1->uvlinesize;
131129
132−#define REBASE_PICTURE(pic, new_ctx, old_ctx) \
133− ((pic && pic >= old_ctx->picture && \
134− pic < old_ctx->picture + MAX_PICTURE_COUNT) ? \
135− &new_ctx->picture[pic - old_ctx->picture] : NULL)
136−
137− s->last_pic_ptr = REBASE_PICTURE(s1->last_pic_ptr, s, s1);
138− s->cur_pic_ptr = REBASE_PICTURE(s1->cur_pic_ptr, s, s1);
139− s->next_pic_ptr = REBASE_PICTURE(s1->next_pic_ptr, s, s1);
140−
141130 // Error/bug resilience
142131 s->workaround_bugs = s1->workaround_bugs;
143132 s->padding_bug_score = s1->padding_bug_score;
@@ -193,9 +182,9 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) · 49 unmodified lines
193182
194183 ff_mpv_free_context_frame(s);
195184
196− s->last_pic_ptr =
197− s->next_pic_ptr =
198− s->cur_pic_ptr = NULL;
185+ s->last_pic.ptr =
186+ s->next_pic.ptr =
187+ s->cur_pic.ptr = NULL;
199188
200189 if ((s->width || s->height) &&
201190 (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
@@ -228,7 +217,7 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) · 26 unmodified lines
228217 return err;
229218 }
230219
231−static int alloc_picture(MpegEncContext *s, MPVPicture **picp, int reference)
220+static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference)
232221 {
233222 AVCodecContext *avctx = s->avctx;
234223 int idx = ff_find_unused_picture(s->avctx, s->picture, 0);
@@ -239,6 +228,7 @@ static int alloc_picture(MpegEncContext *s, MPVPicture **picp, int reference) · 4 unmodified lines
239228 return idx;
240229
241230 pic = &s->picture[idx];
231+ dst->ptr = pic;
242232
243233 pic->tf.f = pic->f;
244234 pic->reference = reference;
@@ -271,36 +261,27 @@ static int alloc_picture(MpegEncContext *s, MPVPicture **picp, int reference) · 26 unmodified lines
271261 av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height ||
272262 FFALIGN(s->mb_height, 2) == s->buffer_pools.alloc_mb_height);
273263 av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride);
274− ret = ff_mpv_alloc_pic_accessories(s->avctx, pic, &s->me, &s->sc,
264+ ret = ff_mpv_alloc_pic_accessories(s->avctx, dst, &s->me, &s->sc,
275265 &s->buffer_pools, s->mb_height);
276266 if (ret < 0)
277267 goto fail;
278− *picp = pic;
279268
280269 return 0;
281270 fail:
282− ff_mpeg_unref_picture(pic);
271+ ff_mpv_unref_picture(dst);
283272 return ret;
284273 }
285274
286−static int av_cold alloc_dummy_frame(MpegEncContext *s, MPVPicture **picp, MPVPicture *wpic)
275+static int av_cold alloc_dummy_frame(MpegEncContext *s, MPVWorkPicture *dst)
287276 {
288277 MPVPicture *pic;
289− int ret = alloc_picture(s, &pic, 1);
278+ int ret = alloc_picture(s, dst, 1);
290279 if (ret < 0)
291280 return ret;
292281
282+ pic = dst->ptr;
293283 pic->dummy = 1;
294284
295− ff_mpeg_unref_picture(wpic);
296− ret = ff_mpeg_ref_picture(wpic, pic);
297− if (ret < 0) {
298− ff_mpeg_unref_picture(pic);
299− return ret;
300− }
301−
302− *picp = pic;
303−
304285 ff_thread_report_progress(&pic->tf, INT_MAX, 0);
305286 ff_thread_report_progress(&pic->tf, INT_MAX, 1);
306287
@@ -330,9 +311,9 @@ int ff_mpv_alloc_dummy_frames(MpegEncContext *s) · 23 unmodified lines
330311 AVCodecContext *avctx = s->avctx;
331312 int ret;
332313
333− if ((!s->last_pic_ptr || !s->last_pic_ptr->f->buf[0]) &&
314+ if ((!s->last_pic.ptr || !s->last_pic.ptr->f->buf[0]) &&
334315 (s->pict_type != AV_PICTURE_TYPE_I)) {
335− if (s->pict_type == AV_PICTURE_TYPE_B && s->next_pic_ptr && s->next_pic_ptr->f->buf[0])
316+ if (s->pict_type == AV_PICTURE_TYPE_B && s->next_pic.ptr && s->next_pic.ptr->f->buf[0])
336317 av_log(avctx, AV_LOG_DEBUG,
337318 "allocating dummy last picture for B frame\n");
338319 else if (s->codec_id != AV_CODEC_ID_H261 /* H.261 has no keyframes */ &&
@@ -341,25 +322,25 @@ int ff_mpv_alloc_dummy_frames(MpegEncContext *s) · 2 unmodified lines
341322 "warning: first frame is no keyframe\n");
342323
343324 /* Allocate a dummy frame */
344− ret = alloc_dummy_frame(s, &s->last_pic_ptr, &s->last_pic);
325+ ret = alloc_dummy_frame(s, &s->last_pic);
345326 if (ret < 0)
346327 return ret;
347328
348329 if (!avctx->hwaccel) {
349330 int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80;
350− color_frame(s->last_pic_ptr->f, luma_val);
331+ color_frame(s->last_pic.ptr->f, luma_val);
351332 }
352333 }
353− if ((!s->next_pic_ptr || !s->next_pic_ptr->f->buf[0]) &&
334+ if ((!s->next_pic.ptr || !s->next_pic.ptr->f->buf[0]) &&
354335 s->pict_type == AV_PICTURE_TYPE_B) {
355336 /* Allocate a dummy frame */
356− ret = alloc_dummy_frame(s, &s->next_pic_ptr, &s->next_pic);
337+ ret = alloc_dummy_frame(s, &s->next_pic);
357338 if (ret < 0)
358339 return ret;
359340 }
360341
361− av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_pic_ptr &&
362− s->last_pic_ptr->f->buf[0]));
342+ av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_pic.ptr &&
343+ s->last_pic.ptr->f->buf[0]));
363344
364345 return 0;
365346 }
@@ -380,68 +361,49 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) · 14 unmodified lines
380361 }
381362
382363 /* mark & release old frames */
383− if (s->pict_type != AV_PICTURE_TYPE_B && s->last_pic_ptr &&
384− s->last_pic_ptr != s->next_pic_ptr &&
385− s->last_pic_ptr->f->buf[0]) {
386− ff_mpeg_unref_picture(s->last_pic_ptr);
364+ if (s->pict_type != AV_PICTURE_TYPE_B && s->last_pic.ptr &&
365+ s->last_pic.ptr != s->next_pic.ptr &&
366+ s->last_pic.ptr->f->buf[0]) {
367+ ff_mpeg_unref_picture(s->last_pic.ptr);
387368 }
388369
389370 /* release non reference/forgotten frames */
390371 for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
391372 if (!s->picture[i].reference ||
392− (&s->picture[i] != s->last_pic_ptr &&
393− &s->picture[i] != s->next_pic_ptr)) {
373+ (&s->picture[i] != s->last_pic.ptr &&
374+ &s->picture[i] != s->next_pic.ptr)) {
394375 ff_mpeg_unref_picture(&s->picture[i]);
395376 }
396377 }
397378
398− ff_mpeg_unref_picture(&s->cur_pic);
399− ff_mpeg_unref_picture(&s->last_pic);
400− ff_mpeg_unref_picture(&s->next_pic);
401−
402− ret = alloc_picture(s, &s->cur_pic_ptr,
379+ ret = alloc_picture(s, &s->cur_pic,
403380 s->pict_type != AV_PICTURE_TYPE_B && !s->droppable);
404381 if (ret < 0)
405382 return ret;
406383
407− s->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !!s->top_field_first;
408− s->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_INTERLACED *
384+ s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !!s->top_field_first;
385+ s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_INTERLACED *
409386 (!s->progressive_frame && !s->progressive_sequence);
410− s->cur_pic_ptr->field_picture = s->picture_structure != PICT_FRAME;
387+ s->cur_pic.ptr->field_picture = s->picture_structure != PICT_FRAME;
411388
412− s->cur_pic_ptr->f->pict_type = s->pict_type;
389+ s->cur_pic.ptr->f->pict_type = s->pict_type;
413390 if (s->pict_type == AV_PICTURE_TYPE_I)
414− s->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_KEY;
391+ s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_KEY;
415392 else
416− s->cur_pic_ptr->f->flags &= ~AV_FRAME_FLAG_KEY;
417−
418− if ((ret = ff_mpeg_ref_picture(&s->cur_pic, s->cur_pic_ptr)) < 0)
419− return ret;
393+ s->cur_pic.ptr->f->flags &= ~AV_FRAME_FLAG_KEY;
420394
421395 if (s->pict_type != AV_PICTURE_TYPE_B) {
422− s->last_pic_ptr = s->next_pic_ptr;
396+ ff_mpv_workpic_from_pic(&s->last_pic, s->next_pic.ptr);
423397 if (!s->droppable)
424− s->next_pic_ptr = s->cur_pic_ptr;
398+ ff_mpv_workpic_from_pic(&s->next_pic, s->cur_pic.ptr);
425399 }
426400 ff_dlog(s->avctx, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n",
427− s->last_pic_ptr, s->next_pic_ptr, s->cur_pic_ptr,
428− s->last_pic_ptr ? s->last_pic_ptr->f->data[0] : NULL,
429− s->next_pic_ptr ? s->next_pic_ptr->f->data[0] : NULL,
430− s->cur_pic_ptr ? s->cur_pic_ptr->f->data[0] : NULL,
401+ (void*)s->last_pic.ptr, (void*)s->next_pic.ptr, (void*)s->cur_pic.ptr,
402+ s->last_pic.ptr ? s->last_pic.ptr->f->data[0] : NULL,
403+ s->next_pic.ptr ? s->next_pic.ptr->f->data[0] : NULL,
404+ s->cur_pic.ptr ? s->cur_pic.ptr->f->data[0] : NULL,
431405 s->pict_type, s->droppable);
432406
433− if (s->last_pic_ptr) {
434− if (s->last_pic_ptr->f->buf[0] &&
435− (ret = ff_mpeg_ref_picture(&s->last_pic,
436− s->last_pic_ptr)) < 0)
437− return ret;
438− }
439− if (s->next_pic_ptr) {
440− if (s->next_pic_ptr->f->buf[0] &&
441− (ret = ff_mpeg_ref_picture(&s->next_pic, s->next_pic_ptr)) < 0)
442− return ret;
443− }
444−
445407 ret = ff_mpv_alloc_dummy_frames(s);
446408 if (ret < 0)
447409 return ret;
@@ -461,7 +423,7 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) · 13 unmodified lines
461423 }
462424
463425 if (s->avctx->debug & FF_DEBUG_NOMC)
464− color_frame(s->cur_pic_ptr->f, 0x80);
426+ color_frame(s->cur_pic.ptr->f, 0x80);
465427
466428 return 0;
467429 }
@@ -472,7 +434,7 @@ void ff_mpv_frame_end(MpegEncContext *s) · 4 unmodified lines
472434 emms_c();
473435
474436 if (s->cur_pic.reference)
475− ff_thread_report_progress(&s->cur_pic_ptr->tf, INT_MAX, 0);
437+ ff_thread_report_progress(&s->cur_pic.ptr->tf, INT_MAX, 0);
476438 }
477439
478440 void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
@@ -515,8 +477,8 @@ int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, · 36 unmodified lines
515477
516478 void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
517479 {
518− ff_draw_horiz_band(s->avctx, s->cur_pic_ptr->f,
519− s->last_pic_ptr ? s->last_pic_ptr->f : NULL,
480+ ff_draw_horiz_band(s->avctx, s->cur_pic.ptr->f,
481+ s->last_pic.ptr ? s->last_pic.ptr->f : NULL,
520482 y, h, s->picture_structure,
521483 s->first_field, s->low_delay);
522484 }
@@ -530,11 +492,10 @@ void ff_mpeg_flush(AVCodecContext *avctx) · 7 unmodified lines
530492
531493 for (int i = 0; i < MAX_PICTURE_COUNT; i++)
532494 ff_mpeg_unref_picture(&s->picture[i]);
533− s->cur_pic_ptr = s->last_pic_ptr = s->next_pic_ptr = NULL;
534495
535− ff_mpeg_unref_picture(&s->cur_pic);
536− ff_mpeg_unref_picture(&s->last_pic);
537− ff_mpeg_unref_picture(&s->next_pic);
496+ ff_mpv_unref_picture(&s->cur_pic);
497+ ff_mpv_unref_picture(&s->last_pic);
498+ ff_mpv_unref_picture(&s->next_pic);
538499
539500 s->mb_x = s->mb_y = 0;
540501
@@ -545,7 +506,7 @@ void ff_mpeg_flush(AVCodecContext *avctx) · 4 unmodified lines
545506 void ff_mpv_report_decode_progress(MpegEncContext *s)
546507 {
547508 if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred)
548− ff_thread_report_progress(&s->cur_pic_ptr->tf, s->mb_y, 0);
509+ ff_thread_report_progress(&s->cur_pic.ptr->tf, s->mb_y, 0);
549510 }
550511
551512
@@ -864,7 +825,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, · 312 unmodified lines
864825 } else {
865826 if (s->picture_structure != s->field_select[dir][0] + 1 &&
866827 s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) {
867− ref_picture = s->cur_pic_ptr->f->data;
828+ ref_picture = s->cur_pic.ptr->f->data;
868829 }
869830 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
870831 0, 0, s->field_select[dir][0],
@@ -881,7 +842,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, · 10 unmodified lines
881842 s->pict_type == AV_PICTURE_TYPE_B || s->first_field) {
882843 ref2picture = ref_picture;
883844 } else {
884− ref2picture = s->cur_pic_ptr->f->data;
845+ ref2picture = s->cur_pic.ptr->f->data;
885846 }
886847
887848 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr,
@@ -922,7 +883,7 @@ static inline void MPV_motion_lowres(MpegEncContext *s, · 34 unmodified lines
922883 // opposite parity is always in the same
923884 // frame if this is second field
924885 if (!s->first_field) {
925− ref_picture = s->cur_pic_ptr->f->data;
886+ ref_picture = s->cur_pic.ptr->f->data;
926887 }
927888 }
928889 }
libavcodec/mpegvideo_enc.c+35−64
@@ -1356,7 +1356,7 @@ static int estimate_best_b_count(MpegEncContext *s) · 1355 unmodified lines
13561356
13571357 for (i = 0; i < s->max_b_frames + 2; i++) {
13581358 const MPVPicture *pre_input_ptr = i ? s->input_picture[i - 1] :
1359− s->next_pic_ptr;
1359+ s->next_pic.ptr;
13601360
13611361 if (pre_input_ptr) {
13621362 const uint8_t *data[4];
@@ -1484,8 +1484,8 @@ static int select_input_picture(MpegEncContext *s) · 121 unmodified lines
14841484 if (!s->reordered_input_picture[0] && s->input_picture[0]) {
14851485 if (s->frame_skip_threshold || s->frame_skip_factor) {
14861486 if (s->picture_in_gop_number < s->gop_size &&
1487− s->next_pic_ptr &&
1488− skip_check(s, s->input_picture[0], s->next_pic_ptr)) {
1487+ s->next_pic.ptr &&
1488+ skip_check(s, s->input_picture[0], s->next_pic.ptr)) {
14891489 // FIXME check that the gop check above is +-1 correct
14901490 ff_mpeg_unref_picture(s->input_picture[0]);
14911491
@@ -1496,7 +1496,7 @@ static int select_input_picture(MpegEncContext *s) · 4 unmodified lines
14961496 }
14971497
14981498 if (/*s->picture_in_gop_number >= s->gop_size ||*/
1499− !s->next_pic_ptr || s->intra_only) {
1499+ !s->next_pic.ptr || s->intra_only) {
15001500 s->reordered_input_picture[0] = s->input_picture[0];
15011501 s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;
15021502 s->reordered_input_picture[0]->coded_picture_number =
@@ -1624,17 +1624,17 @@ no_output_pic: · 121 unmodified lines
16241624 s->new_pic->data[i] += INPLACE_OFFSET;
16251625 }
16261626 }
1627− s->cur_pic_ptr = s->reordered_input_picture[0];
1627+ s->cur_pic.ptr = s->reordered_input_picture[0];
16281628 av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width);
16291629 av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height);
16301630 av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride);
1631− ret = ff_mpv_alloc_pic_accessories(s->avctx, s->cur_pic_ptr, &s->me,
1631+ ret = ff_mpv_alloc_pic_accessories(s->avctx, &s->cur_pic, &s->me,
16321632 &s->sc, &s->buffer_pools, s->mb_height);
16331633 if (ret < 0) {
1634− ff_mpeg_unref_picture(s->cur_pic_ptr);
1634+ ff_mpv_unref_picture(&s->cur_pic);
16351635 return ret;
16361636 }
1637− s->picture_number = s->cur_pic_ptr->display_picture_number;
1637+ s->picture_number = s->cur_pic.ptr->display_picture_number;
16381638
16391639 }
16401640 return 0;
@@ -1674,7 +1674,7 @@ static void frame_end(MpegEncContext *s) · 33 unmodified lines
16741674 emms_c();
16751675
16761676 s->last_pict_type = s->pict_type;
1677− s->last_lambda_for [s->pict_type] = s->cur_pic_ptr->f->quality;
1677+ s->last_lambda_for [s->pict_type] = s->cur_pic.ptr->f->quality;
16781678 if (s->pict_type!= AV_PICTURE_TYPE_B)
16791679 s->last_non_b_pict_type = s->pict_type;
16801680 }
@@ -1700,47 +1700,26 @@ static void update_noise_reduction(MpegEncContext *s) · 19 unmodified lines
17001700 }
17011701 }
17021702
1703−static int frame_start(MpegEncContext *s)
1703+static void frame_start(MpegEncContext *s)
17041704 {
1705− int ret;
1706−
17071705 /* mark & release old frames */
1708− if (s->pict_type != AV_PICTURE_TYPE_B && s->last_pic_ptr &&
1709− s->last_pic_ptr != s->next_pic_ptr &&
1710− s->last_pic_ptr->f->buf[0]) {
1711− ff_mpeg_unref_picture(s->last_pic_ptr);
1706+ if (s->pict_type != AV_PICTURE_TYPE_B && s->last_pic.ptr &&
1707+ s->last_pic.ptr != s->next_pic.ptr &&
1708+ s->last_pic.ptr->f->buf[0]) {
1709+ ff_mpv_unref_picture(&s->last_pic);
17121710 }
17131711
1714− s->cur_pic_ptr->f->pict_type = s->pict_type;
1715−
1716− ff_mpeg_unref_picture(&s->cur_pic);
1717− if ((ret = ff_mpeg_ref_picture(&s->cur_pic, s->cur_pic_ptr)) < 0)
1718− return ret;
1712+ s->cur_pic.ptr->f->pict_type = s->pict_type;
17191713
17201714 if (s->pict_type != AV_PICTURE_TYPE_B) {
1721− s->last_pic_ptr = s->next_pic_ptr;
1722− s->next_pic_ptr = s->cur_pic_ptr;
1723− }
1724−
1725− if (s->last_pic_ptr) {
1726− ff_mpeg_unref_picture(&s->last_pic);
1727− if (s->last_pic_ptr->f->buf[0] &&
1728− (ret = ff_mpeg_ref_picture(&s->last_pic, s->last_pic_ptr)) < 0)
1729− return ret;
1730− }
1731− if (s->next_pic_ptr) {
1732− ff_mpeg_unref_picture(&s->next_pic);
1733− if (s->next_pic_ptr->f->buf[0] &&
1734− (ret = ff_mpeg_ref_picture(&s->next_pic, s->next_pic_ptr)) < 0)
1735− return ret;
1715+ ff_mpv_replace_picture(&s->last_pic, &s->next_pic);
1716+ ff_mpv_replace_picture(&s->next_pic, &s->cur_pic);
17361717 }
17371718
17381719 if (s->dct_error_sum) {
17391720 av_assert2(s->noise_reduction && s->encoding);
17401721 update_noise_reduction(s);
17411722 }
1742−
1743− return 0;
17441723 }
17451724
17461725 int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
@@ -1793,9 +1772,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, · 46 unmodified lines
17931772
17941773 s->pict_type = s->new_pic->pict_type;
17951774 //emms_c();
1796− ret = frame_start(s);
1797− if (ret < 0)
1798− return ret;
1775+ frame_start(s);
17991776 vbv_retry:
18001777 ret = encode_picture(s);
18011778 if (growing_buffer) {
@@ -1858,7 +1835,7 @@ vbv_retry: · 56 unmodified lines
18581835
18591836 for (int i = 0; i < MPV_MAX_PLANES; i++)
18601837 avctx->error[i] += s->encoding_error[i];
1861− ff_side_data_set_encoder_stats(pkt, s->cur_pic.f->quality,
1838+ ff_side_data_set_encoder_stats(pkt, s->cur_pic.ptr->f->quality,
18621839 s->encoding_error,
18631840 (avctx->flags&AV_CODEC_FLAG_PSNR) ? MPV_MAX_PLANES : 0,
18641841 s->pict_type);
@@ -1952,10 +1929,10 @@ vbv_retry: · 87 unmodified lines
19521929 }
19531930 s->total_bits += s->frame_bits;
19541931
1955− pkt->pts = s->cur_pic.f->pts;
1956− pkt->duration = s->cur_pic.f->duration;
1932+ pkt->pts = s->cur_pic.ptr->f->pts;
1933+ pkt->duration = s->cur_pic.ptr->f->duration;
19571934 if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) {
1958− if (!s->cur_pic.coded_picture_number)
1935+ if (!s->cur_pic.ptr->coded_picture_number)
19591936 pkt->dts = pkt->pts - s->dts_delta;
19601937 else
19611938 pkt->dts = s->reordered_pts;
@@ -1965,12 +1942,12 @@ vbv_retry: · 3 unmodified lines
19651942
19661943 // the no-delay case is handled in generic code
19671944 if (avctx->codec->capabilities & AV_CODEC_CAP_DELAY) {
1968− ret = ff_encode_reordered_opaque(avctx, pkt, s->cur_pic.f);
1945+ ret = ff_encode_reordered_opaque(avctx, pkt, s->cur_pic.ptr->f);
19691946 if (ret < 0)
19701947 return ret;
19711948 }
19721949
1973− if (s->cur_pic.f->flags & AV_FRAME_FLAG_KEY)
1950+ if (s->cur_pic.ptr->f->flags & AV_FRAME_FLAG_KEY)
19741951 pkt->flags |= AV_PKT_FLAG_KEY;
19751952 if (s->mb_info)
19761953 av_packet_shrink_side_data(pkt, AV_PKT_DATA_H263_MB_INFO, s->mb_info_size);
@@ -3512,14 +3489,12 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src) · 1535 unmodified lines
35123489
35133490 static int estimate_qp(MpegEncContext *s, int dry_run){
35143491 if (s->next_lambda){
3515− s->cur_pic_ptr->f->quality =
3516− s->cur_pic.f->quality = s->next_lambda;
3492+ s->cur_pic.ptr->f->quality = s->next_lambda;
35173493 if(!dry_run) s->next_lambda= 0;
35183494 } else if (!s->fixed_qscale) {
35193495 int quality = ff_rate_estimate_qscale(s, dry_run);
3520− s->cur_pic_ptr->f->quality =
3521− s->cur_pic.f->quality = quality;
3522− if (s->cur_pic.f->quality < 0)
3496+ s->cur_pic.ptr->f->quality = quality;
3497+ if (s->cur_pic.ptr->f->quality < 0)
35233498 return -1;
35243499 }
35253500
@@ -3542,15 +3517,15 @@ static int estimate_qp(MpegEncContext *s, int dry_run){ · 16 unmodified lines
35423517 s->lambda= s->lambda_table[0];
35433518 //FIXME broken
35443519 }else
3545− s->lambda = s->cur_pic.f->quality;
3520+ s->lambda = s->cur_pic.ptr->f->quality;
35463521 update_qscale(s);
35473522 return 0;
35483523 }
35493524
35503525 /* must be called before writing the header */
35513526 static void set_frame_distances(MpegEncContext * s){
3552− av_assert1(s->cur_pic_ptr->f->pts != AV_NOPTS_VALUE);
3553− s->time = s->cur_pic_ptr->f->pts * s->avctx->time_base.num;
3527+ av_assert1(s->cur_pic.ptr->f->pts != AV_NOPTS_VALUE);
3528+ s->time = s->cur_pic.ptr->f->pts * s->avctx->time_base.num;
35543529
35553530 if(s->pict_type==AV_PICTURE_TYPE_B){
35563531 s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
@@ -3581,7 +3556,7 @@ static int encode_picture(MpegEncContext *s) · 24 unmodified lines
35813556
35823557 s->me.scene_change_score=0;
35833558
3584−// s->lambda= s->cur_pic_ptr->quality; //FIXME qscale / ... stuff for ME rate distortion
3559+// s->lambda= s->cur_pic.ptr->quality; //FIXME qscale / ... stuff for ME rate distortion
35853560
35863561 if(s->pict_type==AV_PICTURE_TYPE_I){
35873562 if(s->msmpeg4_version >= 3) s->no_rounding=1;
@@ -3769,18 +3744,14 @@ static int encode_picture(MpegEncContext *s) · 181 unmodified lines
37693744 }
37703745 }
37713746
3772− //FIXME var duplication
37733747 if (s->pict_type == AV_PICTURE_TYPE_I) {
3774− s->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_KEY; //FIXME pic_ptr
3775− s->cur_pic.f->flags |= AV_FRAME_FLAG_KEY;
3748+ s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_KEY;
37763749 } else {
3777− s->cur_pic_ptr->f->flags &= ~AV_FRAME_FLAG_KEY; //FIXME pic_ptr
3778− s->cur_pic.f->flags &= ~AV_FRAME_FLAG_KEY;
3750+ s->cur_pic.ptr->f->flags &= ~AV_FRAME_FLAG_KEY;
37793751 }
3780− s->cur_pic_ptr->f->pict_type =
3781− s->cur_pic.f->pict_type = s->pict_type;
3752+ s->cur_pic.ptr->f->pict_type = s->pict_type;
37823753
3783− if (s->cur_pic.f->flags & AV_FRAME_FLAG_KEY)
3754+ if (s->cur_pic.ptr->f->flags & AV_FRAME_FLAG_KEY)
37843755 s->picture_in_gop_number=0;
37853756
37863757 s->mb_x = s->mb_y = 0;
libavcodec/mpegvideo_motion.c+4−4
@@ -514,7 +514,7 @@ static inline void apply_obmc(MpegEncContext *s, · 513 unmodified lines
514514 const op_pixels_func (*pix_op)[4])
515515 {
516516 LOCAL_ALIGNED_8(int16_t, mv_cache, [4], [4][2]);
517− const MPVPicture *cur_frame = &s->cur_pic;
517+ const MPVWorkPicture *cur_frame = &s->cur_pic;
518518 int mb_x = s->mb_x;
519519 int mb_y = s->mb_y;
520520 const int xy = mb_x + mb_y * s->mb_stride;
@@ -749,7 +749,7 @@ static av_always_inline void mpv_motion_internal(MpegEncContext *s, · 228 unmodified lines
749749 av_assert2(s->out_format == FMT_MPEG1);
750750 if (s->picture_structure != s->field_select[dir][0] + 1 &&
751751 s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) {
752− ref_picture = s->cur_pic_ptr->f->data;
752+ ref_picture = s->cur_pic.ptr->f->data;
753753 }
754754
755755 mpeg_motion(s, dest_y, dest_cb, dest_cr,
@@ -767,7 +767,7 @@ static av_always_inline void mpv_motion_internal(MpegEncContext *s, · 11 unmodified lines
767767 s->pict_type == AV_PICTURE_TYPE_B || s->first_field) {
768768 ref2picture = ref_picture;
769769 } else {
770− ref2picture = s->cur_pic_ptr->f->data;
770+ ref2picture = s->cur_pic.ptr->f->data;
771771 }
772772
773773 mpeg_motion(s, dest_y, dest_cb, dest_cr,
@@ -807,7 +807,7 @@ static av_always_inline void mpv_motion_internal(MpegEncContext *s, · 33 unmodified lines
807807 /* opposite parity is always in the same frame if this is
808808 * second field */
809809 if (!s->first_field)
810− ref_picture = s->cur_pic_ptr->f->data;
810+ ref_picture = s->cur_pic.ptr->f->data;
811811 }
812812 }
813813 break;
libavcodec/mpv_reconstruct_mb_template.c+2−2
@@ -124,11 +124,11 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], · 123 unmodified lines
124124 if (HAVE_THREADS && is_mpeg12 != DEFINITELY_MPEG12 &&
125125 s->avctx->active_thread_type & FF_THREAD_FRAME) {
126126 if (s->mv_dir & MV_DIR_FORWARD) {
127− ff_thread_await_progress(&s->last_pic_ptr->tf,
127+ ff_thread_await_progress(&s->last_pic.ptr->tf,
128128 lowest_referenced_row(s, 0), 0);
129129 }
130130 if (s->mv_dir & MV_DIR_BACKWARD) {
131− ff_thread_await_progress(&s->next_pic_ptr->tf,
131+ ff_thread_await_progress(&s->next_pic.ptr->tf,
132132 lowest_referenced_row(s, 1), 0);
133133 }
134134 }
libavcodec/mss2.c+1−1
@@ -382,7 +382,7 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, · 381 unmodified lines
382382 MSS12Context *c = &ctx->c;
383383 VC1Context *v = avctx->priv_data;
384384 MpegEncContext *s = &v->s;
385− MPVPicture *f;
385+ MPVWorkPicture *f;
386386 int ret;
387387
388388 ff_mpeg_flush(avctx);
libavcodec/nvdec_mpeg12.c+3−3
@@ -39,7 +39,7 @@ static int nvdec_mpeg12_start_frame(AVCodecContext *avctx, const uint8_t *buffer · 38 unmodified lines
3939 CUVIDMPEG2PICPARAMS *ppc = &pp->CodecSpecific.mpeg2;
4040 FrameDecodeData *fdd;
4141 NVDECFrame *cf;
42− AVFrame *cur_frame = s->cur_pic.f;
42+ AVFrame *cur_frame = s->cur_pic.ptr->f;
4343
4444 int ret, i;
4545
@@ -64,8 +64,8 @@ static int nvdec_mpeg12_start_frame(AVCodecContext *avctx, const uint8_t *buffer · 18 unmodified lines
6464 s->pict_type == AV_PICTURE_TYPE_P,
6565
6666 .CodecSpecific.mpeg2 = {
67− .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.f),
68− .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.f),
67+ .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.ptr ? s->last_pic.ptr->f : NULL),
68+ .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.ptr ? s->next_pic.ptr->f : NULL),
6969
7070 .picture_coding_type = s->pict_type,
7171 .full_pel_forward_vector = s->full_pel[0],
libavcodec/nvdec_mpeg4.c+3−3
@@ -38,7 +38,7 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, · 37 unmodified lines
3838 CUVIDMPEG4PICPARAMS *ppc = &pp->CodecSpecific.mpeg4;
3939 FrameDecodeData *fdd;
4040 NVDECFrame *cf;
41− AVFrame *cur_frame = s->cur_pic.f;
41+ AVFrame *cur_frame = s->cur_pic.ptr->f;
4242
4343 int ret, i;
4444
@@ -60,8 +60,8 @@ static int nvdec_mpeg4_start_frame(AVCodecContext *avctx, const uint8_t *buffer, · 15 unmodified lines
6060 s->pict_type == AV_PICTURE_TYPE_S,
6161
6262 .CodecSpecific.mpeg4 = {
63− .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.f),
64− .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.f),
63+ .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.ptr ? s->last_pic.ptr->f : NULL),
64+ .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.ptr ? s->next_pic.ptr->f : NULL),
6565
6666 .video_object_layer_width = s->width,
6767 .video_object_layer_height = s->height,
libavcodec/nvdec_vc1.c+3−3
@@ -38,7 +38,7 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u · 37 unmodified lines
3838 CUVIDPICPARAMS *pp = &ctx->pic_params;
3939 FrameDecodeData *fdd;
4040 NVDECFrame *cf;
41− AVFrame *cur_frame = s->cur_pic.f;
41+ AVFrame *cur_frame = s->cur_pic.ptr->f;
4242
4343 int ret;
4444
@@ -63,8 +63,8 @@ static int nvdec_vc1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u · 18 unmodified lines
6363 s->pict_type == AV_PICTURE_TYPE_P,
6464
6565 .CodecSpecific.vc1 = {
66− .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.f),
67− .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.f),
66+ .ForwardRefIdx = ff_nvdec_get_ref_idx(s->last_pic.ptr ? s->last_pic.ptr->f : NULL),
67+ .BackwardRefIdx = ff_nvdec_get_ref_idx(s->next_pic.ptr ? s->next_pic.ptr->f : NULL),
6868 .FrameWidth = cur_frame->width,
6969 .FrameHeight = cur_frame->height,
7070
libavcodec/ratecontrol.c+5−5
@@ -40,10 +40,10 @@ void ff_write_pass1_stats(MpegEncContext *s) · 39 unmodified lines
4040 snprintf(s->avctx->stats_out, 256,
4141 "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d "
4242 "fcode:%d bcode:%d mc-var:%"PRId64" var:%"PRId64" icount:%d hbits:%d;\n",
43− s->cur_pic_ptr->display_picture_number,
44− s->cur_pic_ptr->coded_picture_number,
43+ s->cur_pic.ptr->display_picture_number,
44+ s->cur_pic.ptr->coded_picture_number,
4545 s->pict_type,
46− s->cur_pic.f->quality,
46+ s->cur_pic.ptr->f->quality,
4747 s->i_tex_bits,
4848 s->p_tex_bits,
4949 s->mv_bits,
@@ -936,9 +936,9 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) · 886 unmodified lines
936936 * here instead of reordering but the reordering is simpler for now
937937 * until H.264 B-pyramid must be handled. */
938938 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)
939− dts_pic = s->cur_pic_ptr;
939+ dts_pic = s->cur_pic.ptr;
940940 else
941− dts_pic = s->last_pic_ptr;
941+ dts_pic = s->last_pic.ptr;
942942
943943 if (!dts_pic || dts_pic->f->pts == AV_NOPTS_VALUE)
944944 wanted_bits = (uint64_t)(s->bit_rate * (double)picture_number / fps);
libavcodec/rv10.c+14−14
@@ -170,7 +170,7 @@ static int rv20_decode_picture_header(RVDecContext *rv, int whole_size) · 169 unmodified lines
170170 av_log(s->avctx, AV_LOG_ERROR, "low delay B\n");
171171 return -1;
172172 }
173− if (!s->last_pic_ptr && s->pict_type == AV_PICTURE_TYPE_B) {
173+ if (!s->last_pic.ptr && s->pict_type == AV_PICTURE_TYPE_B) {
174174 av_log(s->avctx, AV_LOG_ERROR, "early B-frame\n");
175175 return AVERROR_INVALIDDATA;
176176 }
@@ -458,9 +458,9 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 281 unmodified lines
458458 if (whole_size < s->mb_width * s->mb_height / 8)
459459 return AVERROR_INVALIDDATA;
460460
461− if ((s->mb_x == 0 && s->mb_y == 0) || !s->cur_pic_ptr) {
461+ if ((s->mb_x == 0 && s->mb_y == 0) || !s->cur_pic.ptr) {
462462 // FIXME write parser so we always have complete frames?
463− if (s->cur_pic_ptr) {
463+ if (s->cur_pic.ptr) {
464464 ff_er_frame_end(&s->er, NULL);
465465 ff_mpv_frame_end(s);
466466 s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
@@ -469,7 +469,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 2 unmodified lines
469469 return ret;
470470 ff_mpeg_er_frame_start(s);
471471 } else {
472− if (s->cur_pic_ptr->f->pict_type != s->pict_type) {
472+ if (s->cur_pic.ptr->f->pict_type != s->pict_type) {
473473 av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n");
474474 return AVERROR_INVALIDDATA;
475475 }
@@ -632,28 +632,28 @@ static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 156 unmodified lines
632632 i++;
633633 }
634634
635− if (s->cur_pic_ptr && s->mb_y >= s->mb_height) {
635+ if (s->cur_pic.ptr && s->mb_y >= s->mb_height) {
636636 ff_er_frame_end(&s->er, NULL);
637637 ff_mpv_frame_end(s);
638638
639639 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
640− if ((ret = av_frame_ref(pict, s->cur_pic_ptr->f)) < 0)
640+ if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
641641 return ret;
642− ff_print_debug_info(s, s->cur_pic_ptr, pict);
643− ff_mpv_export_qp_table(s, pict, s->cur_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG1);
644− } else if (s->last_pic_ptr) {
645− if ((ret = av_frame_ref(pict, s->last_pic_ptr->f)) < 0)
642+ ff_print_debug_info(s, s->cur_pic.ptr, pict);
643+ ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
644+ } else if (s->last_pic.ptr) {
645+ if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0)
646646 return ret;
647− ff_print_debug_info(s, s->last_pic_ptr, pict);
648− ff_mpv_export_qp_table(s, pict,s->last_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG1);
647+ ff_print_debug_info(s, s->last_pic.ptr, pict);
648+ ff_mpv_export_qp_table(s, pict,s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
649649 }
650650
651− if (s->last_pic_ptr || s->low_delay) {
651+ if (s->last_pic.ptr || s->low_delay) {
652652 *got_frame = 1;
653653 }
654654
655655 // so we can detect if frame_end was not called (find some nicer solution...)
656− s->cur_pic_ptr = NULL;
656+ s->cur_pic.ptr = NULL;
657657 }
658658
659659 return avpkt->size;
libavcodec/rv34.c+19−19
@@ -567,7 +567,7 @@ static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir) · 566 unmodified lines
567567 int has_A = 0, has_B = 0, has_C = 0;
568568 int mx, my;
569569 int i, j;
570− MPVPicture *cur_pic = &s->cur_pic;
570+ MPVWorkPicture *cur_pic = &s->cur_pic;
571571 const int mask = dir ? MB_TYPE_L1 : MB_TYPE_L0;
572572 int type = cur_pic->mb_type[mb_pos];
573573
@@ -721,7 +721,7 @@ static inline void rv34_mc(RV34DecContext *r, const int block_type, · 147 unmodified lines
721721 if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) {
722722 /* wait for the referenced mb row to be finished */
723723 int mb_row = s->mb_y + ((yoff + my + 5 + 8 * height) >> 4);
724− const ThreadFrame *f = dir ? &s->next_pic_ptr->tf : &s->last_pic_ptr->tf;
724+ const ThreadFrame *f = dir ? &s->next_pic.ptr->tf : &s->last_pic.ptr->tf;
725725 ff_thread_await_progress(f, mb_row, 0);
726726 }
727727
@@ -901,7 +901,7 @@ static int rv34_decode_mv(RV34DecContext *r, int block_type) · 173 unmodified lines
901901 //surprisingly, it uses motion scheme from next reference frame
902902 /* wait for the current mb row to be finished */
903903 if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
904− ff_thread_await_progress(&s->next_pic_ptr->tf, FFMAX(0, s->mb_y-1), 0);
904+ ff_thread_await_progress(&s->next_pic.ptr->tf, FFMAX(0, s->mb_y-1), 0);
905905
906906 next_bt = s->next_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride];
907907 if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){
@@ -1485,7 +1485,7 @@ static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int · 577 unmodified lines
14851485 r->loop_filter(r, s->mb_y - 2);
14861486
14871487 if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
1488− ff_thread_report_progress(&s->cur_pic_ptr->tf,
1488+ ff_thread_report_progress(&s->cur_pic.ptr->tf,
14891489 s->mb_y - 2, 0);
14901490
14911491 }
@@ -1583,19 +1583,19 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict) · 91 unmodified lines
15831583 s->mb_num_left = 0;
15841584
15851585 if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
1586− ff_thread_report_progress(&s->cur_pic_ptr->tf, INT_MAX, 0);
1586+ ff_thread_report_progress(&s->cur_pic.ptr->tf, INT_MAX, 0);
15871587
15881588 if (s->pict_type == AV_PICTURE_TYPE_B) {
1589− if ((ret = av_frame_ref(pict, s->cur_pic_ptr->f)) < 0)
1589+ if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
15901590 return ret;
1591− ff_print_debug_info(s, s->cur_pic_ptr, pict);
1592− ff_mpv_export_qp_table(s, pict, s->cur_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG1);
1591+ ff_print_debug_info(s, s->cur_pic.ptr, pict);
1592+ ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
15931593 got_picture = 1;
1594− } else if (s->last_pic_ptr) {
1595− if ((ret = av_frame_ref(pict, s->last_pic_ptr->f)) < 0)
1594+ } else if (s->last_pic.ptr) {
1595+ if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0)
15961596 return ret;
1597− ff_print_debug_info(s, s->last_pic_ptr, pict);
1598− ff_mpv_export_qp_table(s, pict, s->last_pic_ptr, FF_MPV_QSCALE_TYPE_MPEG1);
1597+ ff_print_debug_info(s, s->last_pic.ptr, pict);
1598+ ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
15991599 got_picture = 1;
16001600 }
16011601
@@ -1630,10 +1630,10 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 28 unmodified lines
16301630 /* no supplementary picture */
16311631 if (buf_size == 0) {
16321632 /* special case for last picture */
1633− if (s->next_pic_ptr) {
1634− if ((ret = av_frame_ref(pict, s->next_pic_ptr->f)) < 0)
1633+ if (s->next_pic.ptr) {
1634+ if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
16351635 return ret;
1636− s->next_pic_ptr = NULL;
1636+ s->next_pic.ptr = NULL;
16371637
16381638 *got_picture_ptr = 1;
16391639 }
@@ -1656,7 +1656,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 16 unmodified lines
16561656 av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n");
16571657 return AVERROR_INVALIDDATA;
16581658 }
1659− if ((!s->last_pic_ptr || !s->last_pic_ptr->f->data[0]) &&
1659+ if ((!s->last_pic.ptr || !s->last_pic.ptr->f->data[0]) &&
16601660 si.type == AV_PICTURE_TYPE_B) {
16611661 av_log(avctx, AV_LOG_ERROR, "Invalid decoder state: B-frame without "
16621662 "reference data.\n");
@@ -1669,7 +1669,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 6 unmodified lines
16691669
16701670 /* first slice */
16711671 if (si.start == 0) {
1672− if (s->mb_num_left > 0 && s->cur_pic_ptr) {
1672+ if (s->mb_num_left > 0 && s->cur_pic.ptr) {
16731673 av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n",
16741674 s->mb_num_left);
16751675 if (!s->context_reinit)
@@ -1794,7 +1794,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 118 unmodified lines
17941794 break;
17951795 }
17961796
1797− if (s->cur_pic_ptr) {
1797+ if (s->cur_pic.ptr) {
17981798 if (last) {
17991799 if(r->loop_filter)
18001800 r->loop_filter(r, s->mb_height - 1);
@@ -1811,7 +1811,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 10 unmodified lines
18111811 ff_er_frame_end(&s->er, NULL);
18121812 ff_mpv_frame_end(s);
18131813 s->mb_num_left = 0;
1814− ff_thread_report_progress(&s->cur_pic_ptr->tf, INT_MAX, 0);
1814+ ff_thread_report_progress(&s->cur_pic.ptr->tf, INT_MAX, 0);
18151815 return AVERROR_INVALIDDATA;
18161816 }
18171817 }
libavcodec/snowenc.c+9−8
@@ -62,6 +62,7 @@ typedef struct SnowEncContext { · 61 unmodified lines
6262
6363 MECmpContext mecc;
6464 MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX)
65+ MPVPicture cur_pic, last_pic;
6566 #define ME_CACHE_SIZE 1024
6667 unsigned me_cache[ME_CACHE_SIZE];
6768 unsigned me_cache_generation;
@@ -1834,9 +1835,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 1766 unmodified lines
18341835 if (ret < 0)
18351836 return ret;
18361837
1837− mpv->cur_pic_ptr = &mpv->cur_pic;
1838− mpv->cur_pic.f = s->current_picture;
1839− mpv->cur_pic.f->pts = pict->pts;
1838+ mpv->cur_pic.ptr = &enc->cur_pic;
1839+ mpv->cur_pic.ptr->f = s->current_picture;
1840+ mpv->cur_pic.ptr->f->pts = pict->pts;
18401841 if(pic->pict_type == AV_PICTURE_TYPE_P){
18411842 int block_width = (width +15)>>4;
18421843 int block_height= (height+15)>>4;
@@ -1846,9 +1847,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 3 unmodified lines
18461847 av_assert0(s->last_picture[0]->data[0]);
18471848
18481849 mpv->avctx = s->avctx;
1849− mpv->last_pic.f = s->last_picture[0];
1850+ mpv->last_pic.ptr = &enc->last_pic;
1851+ mpv->last_pic.ptr->f = s->last_picture[0];
18501852 mpv-> new_pic = s->input_picture;
1851− mpv->last_pic_ptr = &mpv->last_pic;
18521853 mpv->linesize = stride;
18531854 mpv->uvlinesize = s->current_picture->linesize[1];
18541855 mpv->width = width;
@@ -2043,9 +2044,9 @@ redo_frame: · 188 unmodified lines
20432044 mpv->frame_bits = 8 * (s->c.bytestream - s->c.bytestream_start);
20442045 mpv->p_tex_bits = mpv->frame_bits - mpv->misc_bits - mpv->mv_bits;
20452046 mpv->total_bits += 8*(s->c.bytestream - s->c.bytestream_start);
2046− mpv->cur_pic.display_picture_number =
2047− mpv->cur_pic.coded_picture_number = avctx->frame_num;
2048− mpv->cur_pic.f->quality = pic->quality;
2047+ enc->cur_pic.display_picture_number =
2048+ enc->cur_pic.coded_picture_number = avctx->frame_num;
2049+ enc->cur_pic.f->quality = pic->quality;
20492050 if (enc->pass1_rc)
20502051 if (ff_rate_estimate_qscale(mpv, 0) < 0)
20512052 return -1;
libavcodec/svq1enc.c+3−2
@@ -60,6 +60,7 @@ typedef struct SVQ1EncContext { · 59 unmodified lines
6060 * else, the idea is to make the motion estimation eventually independent
6161 * of MpegEncContext, so this will be removed then. */
6262 MpegEncContext m;
63+ MPVPicture cur_pic, last_pic;
6364 AVCodecContext *avctx;
6465 MECmpContext mecc;
6566 HpelDSPContext hdsp;
@@ -326,8 +327,8 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane, · 260 unmodified lines
326327
327328 if (s->pict_type == AV_PICTURE_TYPE_P) {
328329 s->m.avctx = s->avctx;
329− s->m.cur_pic_ptr = &s->m.cur_pic;
330− s->m.last_pic_ptr = &s->m.last_pic;
330+ s->m.cur_pic.ptr = &s->cur_pic;
331+ s->m.last_pic.ptr = &s->last_pic;
331332 s->m.last_pic.data[0] = ref_plane;
332333 s->m.linesize =
333334 s->m.last_pic.linesize[0] =
libavcodec/vaapi_mpeg2.c+6−6
@@ -42,12 +42,12 @@ static inline int mpeg2_get_is_frame_start(const MpegEncContext *s) · 41 unmodified lines
4242 static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size)
4343 {
4444 const MpegEncContext *s = avctx->priv_data;
45− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
45+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
4646 VAPictureParameterBufferMPEG2 pic_param;
4747 VAIQMatrixBufferMPEG2 iq_matrix;
4848 int i, err;
4949
50− pic->output_surface = ff_vaapi_get_surface_id(s->cur_pic_ptr->f);
50+ pic->output_surface = ff_vaapi_get_surface_id(s->cur_pic.ptr->f);
5151
5252 pic_param = (VAPictureParameterBufferMPEG2) {
5353 .horizontal_size = s->width,
@@ -73,10 +73,10 @@ static int vaapi_mpeg2_start_frame(AVCodecContext *avctx, av_unused const uint8_ · 19 unmodified lines
7373
7474 switch (s->pict_type) {
7575 case AV_PICTURE_TYPE_B:
76− pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_pic.f);
76+ pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_pic.ptr->f);
7777 // fall-through
7878 case AV_PICTURE_TYPE_P:
79− pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_pic.f);
79+ pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_pic.ptr->f);
8080 break;
8181 }
8282
@@ -115,7 +115,7 @@ fail: · 32 unmodified lines
115115 static int vaapi_mpeg2_end_frame(AVCodecContext *avctx)
116116 {
117117 MpegEncContext *s = avctx->priv_data;
118− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
118+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
119119 int ret;
120120
121121 ret = ff_vaapi_decode_issue(avctx, pic);
@@ -131,7 +131,7 @@ fail: · 9 unmodified lines
131131 static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
132132 {
133133 const MpegEncContext *s = avctx->priv_data;
134− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
134+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
135135 VASliceParameterBufferMPEG2 slice_param;
136136 GetBitContext gb;
137137 uint32_t quantiser_scale_code, intra_slice_flag, macroblock_offset;
libavcodec/vaapi_mpeg4.c+7−7
@@ -49,11 +49,11 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_ · 48 unmodified lines
4949 {
5050 Mpeg4DecContext *ctx = avctx->priv_data;
5151 MpegEncContext *s = &ctx->m;
52− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
52+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
5353 VAPictureParameterBufferMPEG4 pic_param;
5454 int i, err;
5555
56− pic->output_surface = ff_vaapi_get_surface_id(s->cur_pic_ptr->f);
56+ pic->output_surface = ff_vaapi_get_surface_id(s->cur_pic.ptr->f);
5757
5858 pic_param = (VAPictureParameterBufferMPEG4) {
5959 .vop_width = s->width,
@@ -78,7 +78,7 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_ · 18 unmodified lines
7878 .vop_fields.bits = {
7979 .vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I,
8080 .backward_reference_vop_coding_type =
81− s->pict_type == AV_PICTURE_TYPE_B ? s->next_pic.f->pict_type - AV_PICTURE_TYPE_I : 0,
81+ s->pict_type == AV_PICTURE_TYPE_B ? s->next_pic.ptr->f->pict_type - AV_PICTURE_TYPE_I : 0,
8282 .vop_rounding_type = s->no_rounding,
8383 .intra_dc_vlc_thr = mpeg4_get_intra_dc_vlc_thr(ctx),
8484 .top_field_first = s->top_field_first,
@@ -100,9 +100,9 @@ static int vaapi_mpeg4_start_frame(AVCodecContext *avctx, av_unused const uint8_ · 15 unmodified lines
100100 }
101101
102102 if (s->pict_type == AV_PICTURE_TYPE_B)
103− pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_pic.f);
103+ pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_pic.ptr->f);
104104 if (s->pict_type != AV_PICTURE_TYPE_I)
105− pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_pic.f);
105+ pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_pic.ptr->f);
106106
107107 err = ff_vaapi_decode_make_param_buffer(avctx, pic,
108108 VAPictureParameterBufferType,
@@ -139,7 +139,7 @@ fail: · 30 unmodified lines
139139 static int vaapi_mpeg4_end_frame(AVCodecContext *avctx)
140140 {
141141 MpegEncContext *s = avctx->priv_data;
142− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
142+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
143143 int ret;
144144
145145 ret = ff_vaapi_decode_issue(avctx, pic);
@@ -155,7 +155,7 @@ fail: · 9 unmodified lines
155155 static int vaapi_mpeg4_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
156156 {
157157 MpegEncContext *s = avctx->priv_data;
158− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
158+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
159159 VASliceParameterBufferMPEG4 slice_param;
160160 int err;
161161
libavcodec/vaapi_vc1.c+8−6
@@ -253,11 +253,11 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t · 252 unmodified lines
253253 {
254254 const VC1Context *v = avctx->priv_data;
255255 const MpegEncContext *s = &v->s;
256− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
256+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
257257 VAPictureParameterBufferVC1 pic_param;
258258 int err;
259259
260− pic->output_surface = ff_vaapi_get_surface_id(s->cur_pic_ptr->f);
260+ pic->output_surface = ff_vaapi_get_surface_id(s->cur_pic.ptr->f);
261261
262262 pic_param = (VAPictureParameterBufferVC1) {
263263 .forward_reference_picture = VA_INVALID_ID,
@@ -374,10 +374,12 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t · 110 unmodified lines
374374
375375 switch (s->pict_type) {
376376 case AV_PICTURE_TYPE_B:
377− pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_pic.f);
377+ if (s->next_pic.ptr)
378+ pic_param.backward_reference_picture = ff_vaapi_get_surface_id(s->next_pic.ptr->f);
378379 // fall-through
379380 case AV_PICTURE_TYPE_P:
380− pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_pic.f);
381+ if (s->last_pic.ptr)
382+ pic_param.forward_reference_picture = ff_vaapi_get_surface_id(s->last_pic.ptr->f);
381383 break;
382384 }
383385
@@ -450,7 +452,7 @@ static int vaapi_vc1_end_frame(AVCodecContext *avctx) · 66 unmodified lines
450452 {
451453 VC1Context *v = avctx->priv_data;
452454 MpegEncContext *s = &v->s;
453− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
455+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
454456 int ret;
455457
456458 ret = ff_vaapi_decode_issue(avctx, pic);
@@ -465,7 +467,7 @@ static int vaapi_vc1_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, · 8 unmodified lines
465467 {
466468 const VC1Context *v = avctx->priv_data;
467469 const MpegEncContext *s = &v->s;
468− VAAPIDecodePicture *pic = s->cur_pic_ptr->hwaccel_picture_private;
470+ VAAPIDecodePicture *pic = s->cur_pic.ptr->hwaccel_picture_private;
469471 VASliceParameterBufferVC1 slice_param;
470472 int mb_height;
471473 int err;
libavcodec/vc1.c+1−1
@@ -856,7 +856,7 @@ int ff_vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) · 855 unmodified lines
856856 v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B;
857857 else
858858 v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I;
859− v->s.cur_pic_ptr->f->pict_type = v->s.pict_type;
859+ v->s.cur_pic.ptr->f->pict_type = v->s.pict_type;
860860 if (!v->pic_header_flag)
861861 goto parse_common_info;
862862 }
libavcodec/vc1_block.c+6−6
@@ -59,9 +59,9 @@ static inline void init_block_index(VC1Context *v) · 58 unmodified lines
5959 MpegEncContext *s = &v->s;
6060 ff_init_block_index(s);
6161 if (v->field_mode && !(v->second_field ^ v->tff)) {
62− s->dest[0] += s->cur_pic_ptr->f->linesize[0];
63− s->dest[1] += s->cur_pic_ptr->f->linesize[1];
64− s->dest[2] += s->cur_pic_ptr->f->linesize[2];
62+ s->dest[0] += s->cur_pic.ptr->f->linesize[0];
63+ s->dest[1] += s->cur_pic.ptr->f->linesize[1];
64+ s->dest[2] += s->cur_pic.ptr->f->linesize[2];
6565 }
6666 }
6767
@@ -2101,7 +2101,7 @@ static int vc1_decode_b_mb_intfi(VC1Context *v) · 2033 unmodified lines
21012101 if (bmvtype == BMV_TYPE_DIRECT) {
21022102 dmv_x[0] = dmv_y[0] = pred_flag[0] = 0;
21032103 dmv_x[1] = dmv_y[1] = pred_flag[0] = 0;
2104− if (!s->next_pic_ptr->field_picture) {
2104+ if (!s->next_pic.ptr->field_picture) {
21052105 av_log(s->avctx, AV_LOG_ERROR, "Mixed field/frame direct mode not supported\n");
21062106 return AVERROR_INVALIDDATA;
21072107 }
@@ -2267,7 +2267,7 @@ static int vc1_decode_b_mb_intfr(VC1Context *v) · 159 unmodified lines
22672267 direct = v->direct_mb_plane[mb_pos];
22682268
22692269 if (direct) {
2270− if (s->next_pic_ptr->field_picture)
2270+ if (s->next_pic.ptr->field_picture)
22712271 av_log(s->avctx, AV_LOG_WARNING, "Mixed frame/field direct mode not supported\n");
22722272 s->mv[0][0][0] = s->cur_pic.motion_val[0][s->block_index[0]][0] = scale_mv(s->next_pic.motion_val[1][s->block_index[0]][0], v->bfraction, 0, s->quarter_sample);
22732273 s->mv[0][0][1] = s->cur_pic.motion_val[0][s->block_index[0]][1] = scale_mv(s->next_pic.motion_val[1][s->block_index[0]][1], v->bfraction, 0, s->quarter_sample);
@@ -2964,7 +2964,7 @@ void ff_vc1_decode_blocks(VC1Context *v) · 690 unmodified lines
29642964
29652965 v->s.esc3_level_length = 0;
29662966 if (v->x8_type) {
2967− ff_intrax8_decode_picture(&v->x8, &v->s.cur_pic,
2967+ ff_intrax8_decode_picture(&v->x8, v->s.cur_pic.ptr,
29682968 &v->s.gb, &v->s.mb_x, &v->s.mb_y,
29692969 2 * v->pq + v->halfpq, v->pq * !v->pquantizer,
29702970 v->s.loop_filter, v->s.low_delay);
libavcodec/vc1_mc.c+7−7
@@ -187,8 +187,8 @@ void ff_vc1_mc_1mv(VC1Context *v, int dir) · 186 unmodified lines
187187 !v->s.last_pic.data[0])
188188 return;
189189
190− linesize = s->cur_pic_ptr->f->linesize[0];
191− uvlinesize = s->cur_pic_ptr->f->linesize[1];
190+ linesize = s->cur_pic.ptr->f->linesize[0];
191+ uvlinesize = s->cur_pic.ptr->f->linesize[1];
192192
193193 mx = s->mv[dir][0][0];
194194 my = s->mv[dir][0][1];
@@ -467,7 +467,7 @@ void ff_vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg) · 272 unmodified lines
467467 !v->s.last_pic.data[0])
468468 return;
469469
470− linesize = s->cur_pic_ptr->f->linesize[0];
470+ linesize = s->cur_pic.ptr->f->linesize[0];
471471
472472 mx = s->mv[dir][n][0];
473473 my = s->mv[dir][n][1];
@@ -669,7 +669,7 @@ void ff_vc1_mc_4mv_chroma(VC1Context *v, int dir) · 195 unmodified lines
669669 s->cur_pic.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;
670670 s->cur_pic.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;
671671
672− uvlinesize = s->cur_pic_ptr->f->linesize[1];
672+ uvlinesize = s->cur_pic.ptr->f->linesize[1];
673673
674674 uvmx = (tx + ((tx & 3) == 3)) >> 1;
675675 uvmy = (ty + ((ty & 3) == 3)) >> 1;
@@ -856,7 +856,7 @@ void ff_vc1_mc_4mv_chroma4(VC1Context *v, int dir, int dir2, int avg) · 180 unmodified lines
856856 if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
857857 return;
858858
859− uvlinesize = s->cur_pic_ptr->f->linesize[1];
859+ uvlinesize = s->cur_pic.ptr->f->linesize[1];
860860
861861 for (i = 0; i < 4; i++) {
862862 int d = i < 2 ? dir: dir2;
@@ -1015,8 +1015,8 @@ void ff_vc1_interp_mc(VC1Context *v) · 152 unmodified lines
10151015 if (!v->field_mode && !v->s.next_pic.data[0])
10161016 return;
10171017
1018− linesize = s->cur_pic_ptr->f->linesize[0];
1019− uvlinesize = s->cur_pic_ptr->f->linesize[1];
1018+ linesize = s->cur_pic.ptr->f->linesize[0];
1019+ uvlinesize = s->cur_pic.ptr->f->linesize[1];
10201020
10211021 mx = s->mv[1][0][0];
10221022 my = s->mv[1][0][1];
libavcodec/vc1_pred.c+1−1
@@ -719,7 +719,7 @@ void ff_vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], · 718 unmodified lines
719719 s->cur_pic.motion_val[1][xy][1] = 0;
720720 return;
721721 }
722− if (direct && s->next_pic_ptr->field_picture)
722+ if (direct && s->next_pic.ptr->field_picture)
723723 av_log(s->avctx, AV_LOG_WARNING, "Mixed frame/field direct mode not supported\n");
724724
725725 s->mv[0][0][0] = scale_mv(s->next_pic.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample);
libavcodec/vc1dec.c+20−20
@@ -322,7 +322,7 @@ static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb) · 321 unmodified lines
322322 return AVERROR_UNKNOWN;
323323 }
324324
325− if (v->two_sprites && (!s->last_pic_ptr || !s->last_pic.data[0])) {
325+ if (v->two_sprites && (!s->last_pic.ptr || !s->last_pic.data[0])) {
326326 av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n");
327327 v->two_sprites = 0;
328328 }
@@ -340,7 +340,7 @@ static void vc1_sprite_flush(AVCodecContext *avctx) · 11 unmodified lines
340340 {
341341 VC1Context *v = avctx->priv_data;
342342 MpegEncContext *s = &v->s;
343− MPVPicture *f = &s->cur_pic;
343+ MPVWorkPicture *f = &s->cur_pic;
344344 int plane, i;
345345
346346 /* Windows Media Image codecs have a convergence interval of two keyframes.
@@ -837,10 +837,10 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 490 unmodified lines
837837 /* no supplementary picture */
838838 if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) {
839839 /* special case for last picture */
840− if (s->low_delay == 0 && s->next_pic_ptr) {
841− if ((ret = av_frame_ref(pict, s->next_pic_ptr->f)) < 0)
840+ if (s->low_delay == 0 && s->next_pic.ptr) {
841+ if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
842842 return ret;
843− s->next_pic_ptr = NULL;
843+ s->next_pic.ptr = NULL;
844844
845845 *got_frame = 1;
846846 }
@@ -1047,7 +1047,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 200 unmodified lines
10471047 }
10481048
10491049 /* skip B-frames if we don't have reference frames */
1050− if (!s->last_pic_ptr && s->pict_type == AV_PICTURE_TYPE_B) {
1050+ if (!s->last_pic.ptr && s->pict_type == AV_PICTURE_TYPE_B) {
10511051 av_log(v->s.avctx, AV_LOG_DEBUG, "Skipping B frame without reference frames\n");
10521052 goto end;
10531053 }
@@ -1061,21 +1061,21 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 7 unmodified lines
10611061 goto err;
10621062 }
10631063
1064− v->s.cur_pic_ptr->field_picture = v->field_mode;
1065− v->s.cur_pic_ptr->f->flags |= AV_FRAME_FLAG_INTERLACED * (v->fcm != PROGRESSIVE);
1066− v->s.cur_pic_ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !!v->tff;
1067− v->last_interlaced = v->s.last_pic_ptr ? v->s.last_pic_ptr->f->flags & AV_FRAME_FLAG_INTERLACED : 0;
1068− v->next_interlaced = v->s.next_pic_ptr ? v->s.next_pic_ptr->f->flags & AV_FRAME_FLAG_INTERLACED : 0;
1064+ v->s.cur_pic.ptr->field_picture = v->field_mode;
1065+ v->s.cur_pic.ptr->f->flags |= AV_FRAME_FLAG_INTERLACED * (v->fcm != PROGRESSIVE);
1066+ v->s.cur_pic.ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !!v->tff;
1067+ v->last_interlaced = v->s.last_pic.ptr ? v->s.last_pic.ptr->f->flags & AV_FRAME_FLAG_INTERLACED : 0;
1068+ v->next_interlaced = v->s.next_pic.ptr ? v->s.next_pic.ptr->f->flags & AV_FRAME_FLAG_INTERLACED : 0;
10691069
10701070 // process pulldown flags
1071− s->cur_pic_ptr->f->repeat_pict = 0;
1071+ s->cur_pic.ptr->f->repeat_pict = 0;
10721072 // Pulldown flags are only valid when 'broadcast' has been set.
10731073 if (v->rff) {
10741074 // repeat field
1075− s->cur_pic_ptr->f->repeat_pict = 1;
1075+ s->cur_pic.ptr->f->repeat_pict = 1;
10761076 } else if (v->rptfrm) {
10771077 // repeat frames
1078− s->cur_pic_ptr->f->repeat_pict = v->rptfrm * 2;
1078+ s->cur_pic.ptr->f->repeat_pict = v->rptfrm * 2;
10791079 }
10801080
10811081 if (avctx->hwaccel) {
@@ -1137,7 +1137,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 55 unmodified lines
11371137 ret = AVERROR_INVALIDDATA;
11381138 goto err;
11391139 }
1140− v->s.cur_pic_ptr->f->pict_type = v->s.pict_type;
1140+ v->s.cur_pic.ptr->f->pict_type = v->s.pict_type;
11411141
11421142 ret = hwaccel->start_frame(avctx, buf_start_second_field,
11431143 (buf + buf_size) - buf_start_second_field);
@@ -1355,16 +1355,16 @@ image: · 211 unmodified lines
13551355 *got_frame = 1;
13561356 } else {
13571357 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
1358− if ((ret = av_frame_ref(pict, s->cur_pic_ptr->f)) < 0)
1358+ if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
13591359 goto err;
13601360 if (!v->field_mode)
1361− ff_print_debug_info(s, s->cur_pic_ptr, pict);
1361+ ff_print_debug_info(s, s->cur_pic.ptr, pict);
13621362 *got_frame = 1;
1363− } else if (s->last_pic_ptr) {
1364− if ((ret = av_frame_ref(pict, s->last_pic_ptr->f)) < 0)
1363+ } else if (s->last_pic.ptr) {
1364+ if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0)
13651365 goto err;
13661366 if (!v->field_mode)
1367− ff_print_debug_info(s, s->last_pic_ptr, pict);
1367+ ff_print_debug_info(s, s->last_pic.ptr, pict);
13681368 *got_frame = 1;
13691369 }
13701370 }
libavcodec/vdpau.c+1−1
@@ -370,7 +370,7 @@ int ff_vdpau_common_end_frame(AVCodecContext *avctx, AVFrame *frame, · 369 unmodified lines
370370 int ff_vdpau_mpeg_end_frame(AVCodecContext *avctx)
371371 {
372372 MpegEncContext *s = avctx->priv_data;
373− MPVPicture *pic = s->cur_pic_ptr;
373+ MPVPicture *pic = s->cur_pic.ptr;
374374 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
375375 int val;
376376
libavcodec/vdpau_mpeg12.c+4−4
@@ -35,7 +35,7 @@ static int vdpau_mpeg_start_frame(AVCodecContext *avctx, · 34 unmodified lines
3535 const uint8_t *buffer, uint32_t size)
3636 {
3737 MpegEncContext * const s = avctx->priv_data;
38− MPVPicture *pic = s->cur_pic_ptr;
38+ MPVPicture *pic = s->cur_pic.ptr;
3939 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
4040 VdpPictureInfoMPEG1Or2 *info = &pic_ctx->info.mpeg;
4141 VdpVideoSurface ref;
@@ -47,12 +47,12 @@ static int vdpau_mpeg_start_frame(AVCodecContext *avctx, · 5 unmodified lines
4747
4848 switch (s->pict_type) {
4949 case AV_PICTURE_TYPE_B:
50− ref = ff_vdpau_get_surface_id(s->next_pic.f);
50+ ref = ff_vdpau_get_surface_id(s->next_pic.ptr->f);
5151 assert(ref != VDP_INVALID_HANDLE);
5252 info->backward_reference = ref;
5353 /* fall through to forward prediction */
5454 case AV_PICTURE_TYPE_P:
55− ref = ff_vdpau_get_surface_id(s->last_pic.f);
55+ ref = ff_vdpau_get_surface_id(s->last_pic.ptr->f);
5656 info->forward_reference = ref;
5757 }
5858
@@ -87,7 +87,7 @@ static int vdpau_mpeg_decode_slice(AVCodecContext *avctx, · 28 unmodified lines
8787 const uint8_t *buffer, uint32_t size)
8888 {
8989 MpegEncContext * const s = avctx->priv_data;
90− MPVPicture *pic = s->cur_pic_ptr;
90+ MPVPicture *pic = s->cur_pic.ptr;
9191 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
9292 int val;
9393
libavcodec/vdpau_mpeg4.c+3−3
@@ -34,7 +34,7 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, · 33 unmodified lines
3434 {
3535 Mpeg4DecContext *ctx = avctx->priv_data;
3636 MpegEncContext * const s = &ctx->m;
37− MPVPicture *pic = s->cur_pic_ptr;
37+ MPVPicture *pic = s->cur_pic.ptr;
3838 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
3939 VdpPictureInfoMPEG4Part2 *info = &pic_ctx->info.mpeg4;
4040 VdpVideoSurface ref;
@@ -47,13 +47,13 @@ static int vdpau_mpeg4_start_frame(AVCodecContext *avctx, · 6 unmodified lines
4747
4848 switch (s->pict_type) {
4949 case AV_PICTURE_TYPE_B:
50− ref = ff_vdpau_get_surface_id(s->next_pic.f);
50+ ref = ff_vdpau_get_surface_id(s->next_pic.ptr->f);
5151 assert(ref != VDP_INVALID_HANDLE);
5252 info->backward_reference = ref;
5353 info->vop_coding_type = 2;
5454 /* fall-through */
5555 case AV_PICTURE_TYPE_P:
56− ref = ff_vdpau_get_surface_id(s->last_pic.f);
56+ ref = ff_vdpau_get_surface_id(s->last_pic.ptr->f);
5757 assert(ref != VDP_INVALID_HANDLE);
5858 info->forward_reference = ref;
5959 }
libavcodec/vdpau_vc1.c+6−6
@@ -36,7 +36,7 @@ static int vdpau_vc1_start_frame(AVCodecContext *avctx, · 35 unmodified lines
3636 {
3737 VC1Context * const v = avctx->priv_data;
3838 MpegEncContext * const s = &v->s;
39− MPVPicture *pic = s->cur_pic_ptr;
39+ MPVPicture *pic = s->cur_pic.ptr;
4040 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
4141 VdpPictureInfoVC1 *info = &pic_ctx->info.vc1;
4242 VdpVideoSurface ref;
@@ -47,15 +47,15 @@ static int vdpau_vc1_start_frame(AVCodecContext *avctx, · 4 unmodified lines
4747
4848 switch (s->pict_type) {
4949 case AV_PICTURE_TYPE_B:
50− if (s->next_pic_ptr) {
51− ref = ff_vdpau_get_surface_id(s->next_pic.f);
50+ if (s->next_pic.ptr) {
51+ ref = ff_vdpau_get_surface_id(s->next_pic.ptr->f);
5252 assert(ref != VDP_INVALID_HANDLE);
5353 info->backward_reference = ref;
5454 }
5555 /* fall-through */
5656 case AV_PICTURE_TYPE_P:
57− if (s->last_pic_ptr) {
58− ref = ff_vdpau_get_surface_id(s->last_pic.f);
57+ if (s->last_pic.ptr) {
58+ ref = ff_vdpau_get_surface_id(s->last_pic.ptr->f);
5959 assert(ref != VDP_INVALID_HANDLE);
6060 info->forward_reference = ref;
6161 }
@@ -104,7 +104,7 @@ static int vdpau_vc1_decode_slice(AVCodecContext *avctx, · 42 unmodified lines
104104 {
105105 VC1Context * const v = avctx->priv_data;
106106 MpegEncContext * const s = &v->s;
107− MPVPicture *pic = s->cur_pic_ptr;
107+ MPVPicture *pic = s->cur_pic.ptr;
108108 struct vdpau_picture_context *pic_ctx = pic->hwaccel_picture_private;
109109 int val;
110110
libavcodec/videotoolbox.c+1−1
@@ -1108,7 +1108,7 @@ static int videotoolbox_mpeg_decode_slice(AVCodecContext *avctx, · 1107 unmodified lines
11081108 static int videotoolbox_mpeg_end_frame(AVCodecContext *avctx)
11091109 {
11101110 MpegEncContext *s = avctx->priv_data;
1111− AVFrame *frame = s->cur_pic_ptr->f;
1111+ AVFrame *frame = s->cur_pic.ptr->f;
11121112
11131113 return ff_videotoolbox_common_end_frame(avctx, frame);
11141114 }
libavcodec/wmv2dec.c+1−1
@@ -330,7 +330,7 @@ int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s) · 329 unmodified lines
330330 s->esc3_run_length = 0;
331331
332332 if (w->j_type) {
333− ff_intrax8_decode_picture(&w->x8, &s->cur_pic,
333+ ff_intrax8_decode_picture(&w->x8, s->cur_pic.ptr,
334334 &s->gb, &s->mb_x, &s->mb_y,
335335 2 * s->qscale, (s->qscale - 1) | 1,
336336 s->loop_filter, s->low_delay);

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