History

avcodec/mpegpicture: Make MPVPicture refcounted

Up until now, an initialized MpegEncContext had an array of MPVPictures (way more than were ever needed) and the MPVPicture* contained in the MPVWorkPictures as well as the input_picture and reordered_input_picture arrays (for the encoder) pointed into this array. Several of the pointers could point to the same slot and because there was no reference counting involved, one had to check for aliasing before unreferencing. Furthermore, given that these pointers were not ownership pointers the pointers were often simply reset without unreferencing the slot (happened e.g. for the RV30 and RV40 decoders) or there were moved without resetting the src pointer (happened for the encoders where the entries in the input_picture and reordered_input_picture arrays were not reset). Instead actually releasing these pictures was performed by looping over the whole array and checking which one of the entries needed to be kept. Given that the array had way too many slots (36), this meant that more than 30 MPVPictures have been unnecessarily unreferenced in every ff_mpv_frame_start(); something similar happened for the encoder. This commit changes this by making the MPVPictures refcounted via the RefStruct API. The MPVPictures itself are part of a pool so that this does not entail constant allocations; instead, the amount of allocations actually goes down, because the earlier code used such a large array of MPVPictures (36 entries) and allocated an AVFrame for every one of these on every ff_mpv_common_init(). In fact, the pool is only freed when closing the codec, so that reinitializations don't lead to new allocations (this avoids having to sync the pool in update_thread_context). Making MPVPictures refcounted also has another key benefit: It makes it possible to directly share them across threads (when using frame-threaded decoding), eliminating ugly code with underlying av_frame_ref()'s; sharing these pictures can't fail any more. The pool is allocated in ff_mpv_decode_init() for decoders, which therefore can fail now. This and the fact that the pool is not unreferenced in ff_mpv_common_end() also necessitated to mark several mpegvideo-decoders with the FF_CODEC_CAP_INIT_CLEANUP flag. *: This also means that there is no good reason any more for ff_mpv_common_frame_size_change() to exist.

Andreas Rheinhardt committed 3 years ago

Commit 9ce56f91 parent 99d269319 files · +175 −247Browse files

Unified · Split

19 files
  1. libavcodec/flvdec.c +2 −1
  2. libavcodec/h261dec.c +4 −1
  3. libavcodec/h263dec.c +9 −5
  4. libavcodec/intelh263dec.c +2 −1
  5. libavcodec/mjpegenc.c +1 −1
  6. libavcodec/mpeg12dec.c +7 −4
  7. libavcodec/mpeg4videodec.c +2 −1
  8. libavcodec/mpegpicture.c +49 −108
  9. libavcodec/mpegpicture.h +6 −8
  10. libavcodec/mpegvideo.c +4 −17
  11. libavcodec/mpegvideo.h +1 −1
  12. libavcodec/mpegvideo_dec.c +21 −51
  13. libavcodec/mpegvideo_enc.c +41 −33
  14. libavcodec/mpegvideodec.h +3 −1
  15. libavcodec/msmpeg4dec.c +8 −4
  16. libavcodec/rv10.c +6 −2
  17. libavcodec/rv34.c +4 −2
  18. libavcodec/svq1enc.c +0 −3
  19. libavcodec/vc1dec.c +5 −3
libavcodec/flvdec.c+2−1
@@ -121,6 +121,7 @@ const FFCodec ff_flv_decoder = { · 120 unmodified lines
121121 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
122122 .close = ff_mpv_decode_close,
123123 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
124− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
124+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
125+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
125126 .p.max_lowres = 3,
126127 };
libavcodec/h261dec.c+4−1
@@ -84,10 +84,13 @@ static av_cold int h261_decode_init(AVCodecContext *avctx) · 83 unmodified lines
8484 static AVOnce init_static_once = AV_ONCE_INIT;
8585 H261DecContext *const h = avctx->priv_data;
8686 MpegEncContext *const s = &h->s;
87+ int ret;
8788
8889 s->private_ctx = &h->common;
8990 // set defaults
90− ff_mpv_decode_init(s, avctx);
91+ ret = ff_mpv_decode_init(s, avctx);
92+ if (ret < 0)
93+ return ret;
9194
9295 s->out_format = FMT_H261;
9396 s->low_delay = 1;
libavcodec/h263dec.c+9−5
@@ -95,7 +95,9 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx) · 94 unmodified lines
9595 s->out_format = FMT_H263;
9696
9797 // set defaults
98− ff_mpv_decode_init(s, avctx);
98+ ret = ff_mpv_decode_init(s, avctx);
99+ if (ret < 0)
100+ return ret;
99101
100102 s->quant_precision = 5;
101103 s->decode_mb = ff_h263_decode_mb;
@@ -427,7 +429,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 325 unmodified lines
427429 if (s->low_delay == 0 && s->next_pic.ptr) {
428430 if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
429431 return ret;
430− s->next_pic.ptr = NULL;
432+ ff_mpv_unref_picture(&s->next_pic);
431433
432434 *got_frame = 1;
433435 } else if (s->skipped_last_frame && s->cur_pic.ptr) {
@@ -439,7 +441,7 @@ int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 5 unmodified lines
439441 * returned picture would be reused */
440442 if ((ret = ff_decode_frame_props(avctx, pict)) < 0)
441443 return ret;
442− s->cur_pic.ptr = NULL;
444+ ff_mpv_unref_picture(&s->cur_pic);
443445
444446 *got_frame = 1;
445447 }
@@ -698,7 +700,8 @@ const FFCodec ff_h263_decoder = { · 252 unmodified lines
698700 .close = ff_mpv_decode_close,
699701 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
700702 AV_CODEC_CAP_DELAY,
701− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
703+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
704+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
702705 .flush = ff_mpeg_flush,
703706 .p.max_lowres = 3,
704707 .hw_configs = h263_hw_config_list,
@@ -715,7 +718,8 @@ const FFCodec ff_h263p_decoder = { · 10 unmodified lines
715718 .close = ff_mpv_decode_close,
716719 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
717720 AV_CODEC_CAP_DELAY,
718− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
721+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
722+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
719723 .flush = ff_mpeg_flush,
720724 .p.max_lowres = 3,
721725 .hw_configs = h263_hw_config_list,
libavcodec/intelh263dec.c+2−1
@@ -135,5 +135,6 @@ const FFCodec ff_h263i_decoder = { · 134 unmodified lines
135135 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
136136 .close = ff_mpv_decode_close,
137137 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
138− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
138+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
139+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
139140 };
libavcodec/mjpegenc.c+1−1
@@ -80,7 +80,7 @@ static av_cold void init_uni_ac_vlc(const uint8_t huff_size_ac[256], · 79 unmodified lines
8080
8181 static void mjpeg_encode_picture_header(MpegEncContext *s)
8282 {
83− ff_mjpeg_encode_picture_header(s->avctx, &s->pb, s->picture->f, s->mjpeg_ctx,
83+ ff_mjpeg_encode_picture_header(s->avctx, &s->pb, s->cur_pic.ptr->f, s->mjpeg_ctx,
8484 s->intra_scantable.permutated, 0,
8585 s->intra_matrix, s->chroma_intra_matrix,
8686 s->slice_context_count > 1);
libavcodec/mpeg12dec.c+7−4
@@ -793,13 +793,16 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx) · 792 unmodified lines
793793 {
794794 Mpeg1Context *s = avctx->priv_data;
795795 MpegEncContext *s2 = &s->mpeg_enc_ctx;
796+ int ret;
796797
797798 s2->out_format = FMT_MPEG1;
798799
799800 if ( avctx->codec_tag != AV_RL32("VCR2")
800801 && avctx->codec_tag != AV_RL32("BW10"))
801802 avctx->coded_width = avctx->coded_height = 0; // do not trust dimensions from input
802− ff_mpv_decode_init(s2, avctx);
803+ ret = ff_mpv_decode_init(s2, avctx);
804+ if (ret < 0)
805+ return ret;
803806
804807 ff_mpeg12_init_vlcs();
805808
@@ -2529,7 +2532,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture, · 1723 unmodified lines
25292532 if (ret < 0)
25302533 return ret;
25312534
2532− s2->next_pic.ptr = NULL;
2535+ ff_mpv_unref_picture(&s2->next_pic);
25332536
25342537 *got_output = 1;
25352538 }
@@ -2552,14 +2555,14 @@ static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture, · 16 unmodified lines
25522555 }
25532556 s->extradata_decoded = 1;
25542557 if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) {
2555− s2->cur_pic.ptr = NULL;
2558+ ff_mpv_unref_picture(&s2->cur_pic);
25562559 return ret;
25572560 }
25582561 }
25592562
25602563 ret = decode_chunks(avctx, picture, got_output, buf, buf_size);
25612564 if (ret<0 || *got_output) {
2562− s2->cur_pic.ptr = NULL;
2565+ ff_mpv_unref_picture(&s2->cur_pic);
25632566
25642567 if (s->timecode_frame_start != -1 && *got_output) {
25652568 char tcbuf[AV_TIMECODE_STR_SIZE];
libavcodec/mpeg4videodec.c+2−1
@@ -3866,7 +3866,8 @@ const FFCodec ff_mpeg4_decoder = { · 3865 unmodified lines
38663866 .close = ff_mpv_decode_close,
38673867 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
38683868 AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS,
3869− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
3869+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
3870+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
38703871 .flush = ff_mpeg_flush,
38713872 .p.max_lowres = 3,
38723873 .p.profiles = NULL_IF_CONFIG_SMALL(ff_mpeg4_video_profiles),
libavcodec/mpegpicture.c+49−108
@@ -30,8 +30,14 @@ · 29 unmodified lines
3030 #include "refstruct.h"
3131 #include "threadframe.h"
3232
33−static void av_noinline free_picture_tables(MPVPicture *pic)
33+static void mpv_pic_reset(FFRefStructOpaque unused, void *obj)
3434 {
35+ MPVPicture *pic = obj;
36+
37+ ff_thread_release_ext_buffer(&pic->tf);
38+
39+ ff_refstruct_unref(&pic->hwaccel_picture_private);
40+
3541 ff_refstruct_unref(&pic->mbskip_table);
3642 ff_refstruct_unref(&pic->qscale_table_base);
3743 ff_refstruct_unref(&pic->mb_type_base);
@@ -39,16 +45,53 @@ static void av_noinline free_picture_tables(MPVPicture *pic) · 1 unmodified line
3945 for (int i = 0; i < 2; i++) {
4046 ff_refstruct_unref(&pic->motion_val_base[i]);
4147 ff_refstruct_unref(&pic->ref_index[i]);
48+
49+ pic->motion_val[i] = NULL;
4250 }
4351
52+ pic->mb_type = NULL;
53+ pic->qscale_table = NULL;
54+
55+ pic->mb_stride =
4456 pic->mb_width =
4557 pic->mb_height = 0;
58+
59+ pic->dummy = 0;
60+ pic->field_picture = 0;
61+ pic->b_frame_score = 0;
62+ pic->reference = 0;
63+ pic->shared = 0;
64+ pic->display_picture_number = 0;
65+ pic->coded_picture_number = 0;
66+}
67+
68+static int av_cold mpv_pic_init(FFRefStructOpaque unused, void *obj)
69+{
70+ MPVPicture *pic = obj;
71+
72+ pic->f = av_frame_alloc();
73+ if (!pic->f)
74+ return AVERROR(ENOMEM);
75+ pic->tf.f = pic->f;
76+ return 0;
77+}
78+
79+static void av_cold mpv_pic_free(FFRefStructOpaque unused, void *obj)
80+{
81+ MPVPicture *pic = obj;
82+
83+ av_frame_free(&pic->f);
84+}
85+
86+av_cold FFRefStructPool *ff_mpv_alloc_pic_pool(void)
87+{
88+ return ff_refstruct_pool_alloc_ext(sizeof(MPVPicture), 0, NULL,
89+ mpv_pic_init, mpv_pic_reset, mpv_pic_free, NULL);
4690 }
4791
4892 void ff_mpv_unref_picture(MPVWorkPicture *pic)
4993 {
50− if (pic->ptr)
51− ff_mpeg_unref_picture(pic->ptr);
94+ ff_refstruct_unref(&pic->ptr);
5295 memset(pic, 0, sizeof(*pic));
5396 }
5497
@@ -71,16 +114,18 @@ static void set_workpic_from_pic(MPVWorkPicture *wpic, const MPVPicture *pic) · 16 unmodified lines
71114
72115 void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src)
73116 {
117+ av_assert1(dst != src);
118+ ff_refstruct_replace(&dst->ptr, src->ptr);
74119 memcpy(dst, src, sizeof(*dst));
75120 }
76121
77122 void ff_mpv_workpic_from_pic(MPVWorkPicture *wpic, MPVPicture *pic)
78123 {
124+ ff_refstruct_replace(&wpic->ptr, pic);
79125 if (!pic) {
80126 memset(wpic, 0, sizeof(*wpic));
81127 return;
82128 }
83− wpic->ptr = pic;
84129 set_workpic_from_pic(wpic, pic);
85130 }
86131
@@ -212,107 +257,3 @@ fail: · 125 unmodified lines
212257 av_log(avctx, AV_LOG_ERROR, "Error allocating picture accessories.\n");
213258 return ret;
214259 }
215−
216−/**
217− * Deallocate a picture; frees the picture tables in case they
218− * need to be reallocated anyway.
219− */
220−void ff_mpeg_unref_picture(MPVPicture *pic)
221−{
222− pic->tf.f = pic->f;
223− ff_thread_release_ext_buffer(&pic->tf);
224−
225− ff_refstruct_unref(&pic->hwaccel_picture_private);
226−
227− free_picture_tables(pic);
228−
229− pic->dummy = 0;
230−
231− pic->field_picture = 0;
232− pic->b_frame_score = 0;
233− pic->reference = 0;
234− pic->shared = 0;
235− pic->display_picture_number = 0;
236− pic->coded_picture_number = 0;
237−}
238−
239−static void update_picture_tables(MPVPicture *dst, const MPVPicture *src)
240−{
241− ff_refstruct_replace(&dst->mbskip_table, src->mbskip_table);
242− ff_refstruct_replace(&dst->qscale_table_base, src->qscale_table_base);
243− ff_refstruct_replace(&dst->mb_type_base, src->mb_type_base);
244− for (int i = 0; i < 2; i++) {
245− ff_refstruct_replace(&dst->motion_val_base[i], src->motion_val_base[i]);
246− ff_refstruct_replace(&dst->ref_index[i], src->ref_index[i]);
247− }
248−
249− dst->qscale_table = src->qscale_table;
250− dst->mb_type = src->mb_type;
251− for (int i = 0; i < 2; i++)
252− dst->motion_val[i] = src->motion_val[i];
253−
254− dst->mb_width = src->mb_width;
255− dst->mb_height = src->mb_height;
256− dst->mb_stride = src->mb_stride;
257−}
258−
259−int ff_mpeg_ref_picture(MPVPicture *dst, MPVPicture *src)
260−{
261− int ret;
262−
263− av_assert0(!dst->f->buf[0]);
264− av_assert0(src->f->buf[0]);
265−
266− src->tf.f = src->f;
267− dst->tf.f = dst->f;
268− ret = ff_thread_ref_frame(&dst->tf, &src->tf);
269− if (ret < 0)
270− goto fail;
271−
272− update_picture_tables(dst, src);
273−
274− ff_refstruct_replace(&dst->hwaccel_picture_private,
275− src->hwaccel_picture_private);
276−
277− dst->dummy = src->dummy;
278− dst->field_picture = src->field_picture;
279− dst->b_frame_score = src->b_frame_score;
280− dst->reference = src->reference;
281− dst->shared = src->shared;
282− dst->display_picture_number = src->display_picture_number;
283− dst->coded_picture_number = src->coded_picture_number;
284−
285− return 0;
286−fail:
287− ff_mpeg_unref_picture(dst);
288− return ret;
289−}
290−
291−int ff_find_unused_picture(AVCodecContext *avctx, MPVPicture *picture, int shared)
292−{
293− for (int i = 0; i < MAX_PICTURE_COUNT; i++)
294− if (!picture[i].f->buf[0])
295− return i;
296−
297− av_log(avctx, AV_LOG_FATAL,
298− "Internal error, picture buffer overflow\n");
299− /* We could return -1, but the codec would crash trying to draw into a
300− * non-existing frame anyway. This is safer than waiting for a random crash.
301− * Also the return of this is never useful, an encoder must only allocate
302− * as much as allowed in the specification. This has no relationship to how
303− * much libavcodec could allocate (and MAX_PICTURE_COUNT is always large
304− * enough for such valid streams).
305− * Plus, a decoder has to check stream validity and remove frames if too
306− * many reference frames are around. Waiting for "OOM" is not correct at
307− * all. Similarly, missing reference frames have to be replaced by
308− * interpolated/MC frames, anything else is a bug in the codec ...
309− */
310− abort();
311− return -1;
312−}
313−
314−void av_cold ff_mpv_picture_free(MPVPicture *pic)
315−{
316− ff_mpeg_unref_picture(pic);
317− av_frame_free(&pic->f);
318−}
libavcodec/mpegpicture.h+6−8
@@ -29,7 +29,6 @@ · 28 unmodified lines
2929 #include "threadframe.h"
3030
3131 #define MPV_MAX_PLANES 3
32−#define MAX_PICTURE_COUNT 36
3332 #define EDGE_WIDTH 16
3433
3534 typedef struct ScratchpadContext {
@@ -94,7 +93,7 @@ typedef struct MPVWorkPicture { · 58 unmodified lines
9493 uint8_t *data[MPV_MAX_PLANES];
9594 ptrdiff_t linesize[MPV_MAX_PLANES];
9695
97− MPVPicture *ptr;
96+ MPVPicture *ptr; ///< RefStruct reference
9897
9998 int8_t *qscale_table;
10099
@@ -109,6 +108,11 @@ typedef struct MPVWorkPicture { · 8 unmodified lines
109108 int reference;
110109 } MPVWorkPicture;
111110
111+/**
112+ * Allocate a pool of MPVPictures.
113+ */
114+struct FFRefStructPool *ff_mpv_alloc_pic_pool(void);
115+
112116 /**
113117 * Allocate an MPVPicture's accessories (but not the AVFrame's buffer itself)
114118 * and set the MPVWorkPicture's fields.
@@ -129,14 +133,8 @@ int ff_mpv_pic_check_linesize(void *logctx, const struct AVFrame *f, · 14 unmodified lines
129133 int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me,
130134 ScratchpadContext *sc, int linesize);
131135
132−int ff_mpeg_ref_picture(MPVPicture *dst, MPVPicture *src);
133136 void ff_mpv_unref_picture(MPVWorkPicture *pic);
134137 void ff_mpv_workpic_from_pic(MPVWorkPicture *wpic, MPVPicture *pic);
135138 void ff_mpv_replace_picture(MPVWorkPicture *dst, const MPVWorkPicture *src);
136−void ff_mpeg_unref_picture(MPVPicture *picture);
137−
138−void ff_mpv_picture_free(MPVPicture *pic);
139−
140−int ff_find_unused_picture(AVCodecContext *avctx, MPVPicture *picture, int shared);
141139
142140 #endif /* AVCODEC_MPEGPICTURE_H */
libavcodec/mpegvideo.c+4−17
@@ -701,7 +701,6 @@ static void clear_context(MpegEncContext *s) · 700 unmodified lines
701701
702702 s->bitstream_buffer = NULL;
703703 s->allocated_bitstream_buffer_size = 0;
704− s->picture = NULL;
705704 s->p_field_mv_table_base = NULL;
706705 for (int i = 0; i < 2; i++)
707706 for (int j = 0; j < 2; j++)
@@ -726,10 +725,10 @@ static void clear_context(MpegEncContext *s) · 18 unmodified lines
726725 */
727726 av_cold int ff_mpv_common_init(MpegEncContext *s)
728727 {
729− int i, ret;
730728 int nb_slices = (HAVE_THREADS &&
731729 s->avctx->active_thread_type & FF_THREAD_SLICE) ?
732730 s->avctx->thread_count : 1;
731+ int ret;
733732
734733 clear_context(s);
735734
@@ -755,14 +754,6 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) · 19 unmodified lines
755754 if (ret)
756755 return ret;
757756
758− if (!FF_ALLOCZ_TYPED_ARRAY(s->picture, MAX_PICTURE_COUNT))
759− return AVERROR(ENOMEM);
760− for (i = 0; i < MAX_PICTURE_COUNT; i++) {
761− s->picture[i].f = av_frame_alloc();
762− if (!s->picture[i].f)
763− goto fail_nomem;
764− }
765−
766757 if ((ret = ff_mpv_init_context_frame(s)))
767758 goto fail;
768759
@@ -789,8 +780,6 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) · 20 unmodified lines
789780 // }
790781
791782 return 0;
792− fail_nomem:
793− ret = AVERROR(ENOMEM);
794783 fail:
795784 ff_mpv_common_end(s);
796785 return ret;
@@ -830,11 +819,9 @@ void ff_mpv_common_end(MpegEncContext *s) · 33 unmodified lines
830819 av_freep(&s->bitstream_buffer);
831820 s->allocated_bitstream_buffer_size = 0;
832821
833− if (s->picture) {
834− for (int i = 0; i < MAX_PICTURE_COUNT; i++)
835− ff_mpv_picture_free(&s->picture[i]);
836− }
837− av_freep(&s->picture);
822+ ff_mpv_unref_picture(&s->last_pic);
823+ ff_mpv_unref_picture(&s->cur_pic);
824+ ff_mpv_unref_picture(&s->next_pic);
838825
839826 s->context_initialized = 0;
840827 s->context_reinit = 0;
libavcodec/mpegvideo.h+1−1
@@ -128,7 +128,7 @@ typedef struct MpegEncContext { · 127 unmodified lines
128128 int mb_num; ///< number of MBs of a picture
129129 ptrdiff_t linesize; ///< line size, in bytes, may be different from width
130130 ptrdiff_t uvlinesize; ///< line size, for chroma in bytes, may be different from width
131− MPVPicture *picture; ///< main picture buffer
131+ struct FFRefStructPool *picture_pool; ///< Pool for MPVPictures
132132 MPVPicture **input_picture;///< next pictures on display order for encoding
133133 MPVPicture **reordered_input_picture; ///< pointer to the next pictures in coded order for encoding
134134
libavcodec/mpegvideo_dec.c+21−51
@@ -38,11 +38,12 @@ · 37 unmodified lines
3838 #include "mpegvideo.h"
3939 #include "mpegvideodec.h"
4040 #include "mpeg4videodec.h"
41+#include "refstruct.h"
4142 #include "thread.h"
4243 #include "threadframe.h"
4344 #include "wmv2dec.h"
4445
45−void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
46+int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
4647 {
4748 ff_mpv_common_defaults(s);
4849
@@ -57,6 +58,14 @@ void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx) · 8 unmodified lines
5758
5859 ff_mpv_idct_init(s);
5960 ff_h264chroma_init(&s->h264chroma, 8); //for lowres
61+
62+ if (!s->picture_pool && // VC-1 can call this multiple times
63+ ff_thread_sync_ref(avctx, offsetof(MpegEncContext, picture_pool))) {
64+ s->picture_pool = ff_mpv_alloc_pic_pool();
65+ if (!s->picture_pool)
66+ return AVERROR(ENOMEM);
67+ }
68+ return 0;
6069 }
6170
6271 int ff_mpeg_update_thread_context(AVCodecContext *dst,
@@ -103,26 +112,9 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, · 40 unmodified lines
103112 s->coded_picture_number = s1->coded_picture_number;
104113 s->picture_number = s1->picture_number;
105114
106− av_assert0(!s->picture || s->picture != s1->picture);
107− if (s->picture)
108− for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
109− ff_mpeg_unref_picture(&s->picture[i]);
110− if (s1->picture && s1->picture[i].f->buf[0] &&
111− (ret = ff_mpeg_ref_picture(&s->picture[i], &s1->picture[i])) < 0)
112− return ret;
113− }
114−
115−#define UPDATE_PICTURE(pic)\
116−do {\
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);\
121−} while (0)
122−
123− UPDATE_PICTURE(cur_pic);
124− UPDATE_PICTURE(last_pic);
125− UPDATE_PICTURE(next_pic);
115+ ff_mpv_replace_picture(&s->cur_pic, &s1->cur_pic);
116+ ff_mpv_replace_picture(&s->last_pic, &s1->last_pic);
117+ ff_mpv_replace_picture(&s->next_pic, &s1->next_pic);
126118
127119 s->linesize = s1->linesize;
128120 s->uvlinesize = s1->uvlinesize;
@@ -177,6 +169,7 @@ int ff_mpv_decode_close(AVCodecContext *avctx) · 48 unmodified lines
177169 {
178170 MpegEncContext *s = avctx->priv_data;
179171
172+ ff_refstruct_pool_uninit(&s->picture_pool);
180173 ff_mpv_common_end(s);
181174 return 0;
182175 }
@@ -190,9 +183,9 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) · 7 unmodified lines
190183
191184 ff_mpv_free_context_frame(s);
192185
193− s->last_pic.ptr =
194− s->next_pic.ptr =
195− s->cur_pic.ptr = NULL;
186+ ff_mpv_unref_picture(&s->last_pic);
187+ ff_mpv_unref_picture(&s->next_pic);
188+ ff_mpv_unref_picture(&s->cur_pic);
196189
197190 if ((s->width || s->height) &&
198191 (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
@@ -228,14 +221,12 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) · 29 unmodified lines
228221 static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference)
229222 {
230223 AVCodecContext *avctx = s->avctx;
231− int idx = ff_find_unused_picture(s->avctx, s->picture, 0);
232− MPVPicture *pic;
224+ MPVPicture *pic = ff_refstruct_pool_get(s->picture_pool);
233225 int ret;
234226
235− if (idx < 0)
236− return idx;
227+ if (!pic)
228+ return AVERROR(ENOMEM);
237229
238− pic = &s->picture[idx];
239230 dst->ptr = pic;
240231
241232 pic->tf.f = pic->f;
@@ -368,22 +359,7 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) · 126 unmodified lines
368359 return AVERROR_BUG;
369360 }
370361
371− /* mark & release old frames */
372− if (s->pict_type != AV_PICTURE_TYPE_B && s->last_pic.ptr &&
373− s->last_pic.ptr != s->next_pic.ptr &&
374− s->last_pic.ptr->f->buf[0]) {
375− ff_mpeg_unref_picture(s->last_pic.ptr);
376− }
377−
378− /* release non reference/forgotten frames */
379− for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
380− if (!s->picture[i].reference ||
381− (&s->picture[i] != s->last_pic.ptr &&
382− &s->picture[i] != s->next_pic.ptr)) {
383− ff_mpeg_unref_picture(&s->picture[i]);
384− }
385− }
386−
362+ ff_mpv_unref_picture(&s->cur_pic);
387363 ret = alloc_picture(s, &s->cur_pic,
388364 s->pict_type != AV_PICTURE_TYPE_B && !s->droppable);
389365 if (ret < 0)
@@ -495,12 +471,6 @@ void ff_mpeg_flush(AVCodecContext *avctx) · 105 unmodified lines
495471 {
496472 MpegEncContext *const s = avctx->priv_data;
497473
498− if (!s->picture)
499− return;
500−
501− for (int i = 0; i < MAX_PICTURE_COUNT; i++)
502− ff_mpeg_unref_picture(&s->picture[i]);
503−
504474 ff_mpv_unref_picture(&s->cur_pic);
505475 ff_mpv_unref_picture(&s->last_pic);
506476 ff_mpv_unref_picture(&s->next_pic);
libavcodec/mpegvideo_enc.c+41−33
@@ -75,6 +75,7 @@ · 74 unmodified lines
7575 #include "wmv2enc.h"
7676 #include "rv10enc.h"
7777 #include "packet_internal.h"
78+#include "refstruct.h"
7879 #include <limits.h>
7980 #include "sp5x.h"
8081
@@ -821,7 +822,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 740 unmodified lines
821822 !FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16, 32) ||
822823 !FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_B_FRAMES + 1) ||
823824 !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_B_FRAMES + 1) ||
824− !(s->new_pic = av_frame_alloc()))
825+ !(s->new_pic = av_frame_alloc()) ||
826+ !(s->picture_pool = ff_mpv_alloc_pic_pool()))
825827 return AVERROR(ENOMEM);
826828
827829 /* Allocate MV tables; the MV and MB tables will be copied
@@ -992,7 +994,14 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) · 164 unmodified lines
992994 ff_rate_control_uninit(&s->rc_context);
993995
994996 ff_mpv_common_end(s);
997+ ff_refstruct_pool_uninit(&s->picture_pool);
995998
999+ if (s->input_picture && s->reordered_input_picture) {
1000+ for (int i = 0; i < MAX_B_FRAMES + 1; i++) {
1001+ ff_refstruct_unref(&s->input_picture[i]);
1002+ ff_refstruct_unref(&s->reordered_input_picture[i]);
1003+ }
1004+ }
9961005 for (i = 0; i < FF_ARRAY_ELEMS(s->tmp_frames); i++)
9971006 av_frame_free(&s->tmp_frames[i]);
9981007
@@ -1131,12 +1140,14 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) · 132 unmodified lines
11311140 {
11321141 MPVPicture *pic = NULL;
11331142 int64_t pts;
1134− int i, display_picture_number = 0, ret;
1143+ int display_picture_number = 0, ret;
11351144 int encoding_delay = s->max_b_frames ? s->max_b_frames
11361145 : (s->low_delay ? 0 : 1);
11371146 int flush_offset = 1;
11381147 int direct = 1;
11391148
1149+ av_assert1(!s->input_picture[0]);
1150+
11401151 if (pic_arg) {
11411152 pts = pic_arg->pts;
11421153 display_picture_number = s->input_picture_number++;
@@ -1182,16 +1193,13 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) · 39 unmodified lines
11821193 ff_dlog(s->avctx, "%d %d %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"\n", pic_arg->linesize[0],
11831194 pic_arg->linesize[1], s->linesize, s->uvlinesize);
11841195
1185− i = ff_find_unused_picture(s->avctx, s->picture, direct);
1186− if (i < 0)
1187− return i;
1188−
1189− pic = &s->picture[i];
1190− pic->reference = 3;
1196+ pic = ff_refstruct_pool_get(s->picture_pool);
1197+ if (!pic)
1198+ return AVERROR(ENOMEM);
11911199
11921200 if (direct) {
11931201 if ((ret = av_frame_ref(pic->f, pic_arg)) < 0)
1194− return ret;
1202+ goto fail;
11951203 pic->shared = 1;
11961204 } else {
11971205 ret = prepare_picture(s, pic->f, pic_arg);
@@ -1241,17 +1249,17 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) · 43 unmodified lines
12411249
12421250 pic->display_picture_number = display_picture_number;
12431251 pic->f->pts = pts; // we set this here to avoid modifying pic_arg
1244− } else {
1245− /* Flushing: When we have not received enough input frames,
1246− * ensure s->input_picture[0] contains the first picture */
1252+ } else if (!s->reordered_input_picture[1]) {
1253+ /* Flushing: When the above check is true, the encoder is about to run
1254+ * out of frames to encode. Check if there are input_pictures left;
1255+ * if so, ensure s->input_picture[0] contains the first picture.
1256+ * A flush_offset != 1 will only happen if we did not receive enough
1257+ * input frames. */
12471258 for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++)
12481259 if (s->input_picture[flush_offset])
12491260 break;
12501261
1251− if (flush_offset <= 1)
1252− flush_offset = 1;
1253− else
1254− encoding_delay = encoding_delay - flush_offset + 1;
1262+ encoding_delay -= flush_offset - 1;
12551263 }
12561264
12571265 /* shift buffer entries */
@@ -1262,7 +1270,7 @@ static int load_input_picture(MpegEncContext *s, const AVFrame *pic_arg) · 4 unmodified lines
12621270
12631271 return 0;
12641272 fail:
1265− ff_mpeg_unref_picture(pic);
1273+ ff_refstruct_unref(&pic);
12661274 return ret;
12671275 }
12681276
@@ -1475,8 +1483,10 @@ fail: · 206 unmodified lines
14751483 /**
14761484 * Determines whether an input picture is discarded or not
14771485 * and if not determines the length of the next chain of B frames
1478− * and puts these pictures (including the P frame) into
1486+ * and moves these pictures (including the P frame) into
14791487 * reordered_input_picture.
1488+ * input_picture[0] is always NULL when exiting this function, even on error;
1489+ * reordered_input_picture[0] is always NULL when exiting this function on error.
14801490 */
14811491 static int set_bframe_chain_length(MpegEncContext *s)
14821492 {
@@ -1490,7 +1500,7 @@ static int set_bframe_chain_length(MpegEncContext *s) · 7 unmodified lines
14901500 s->next_pic.ptr &&
14911501 skip_check(s, s->input_picture[0], s->next_pic.ptr)) {
14921502 // FIXME check that the gop check above is +-1 correct
1493− ff_mpeg_unref_picture(s->input_picture[0]);
1503+ ff_refstruct_unref(&s->input_picture[0]);
14941504
14951505 ff_vbv_update(s, 0);
14961506
@@ -1501,6 +1511,7 @@ static int set_bframe_chain_length(MpegEncContext *s) · 4 unmodified lines
15011511 if (/*s->picture_in_gop_number >= s->gop_size ||*/
15021512 !s->next_pic.ptr || s->intra_only) {
15031513 s->reordered_input_picture[0] = s->input_picture[0];
1514+ s->input_picture[0] = NULL;
15041515 s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I;
15051516 s->reordered_input_picture[0]->coded_picture_number =
15061517 s->coded_picture_number++;
@@ -1555,7 +1566,7 @@ static int set_bframe_chain_length(MpegEncContext *s) · 48 unmodified lines
15551566 } else if (s->b_frame_strategy == 2) {
15561567 b_frames = estimate_best_b_count(s);
15571568 if (b_frames < 0) {
1558− ff_mpeg_unref_picture(s->input_picture[0]);
1569+ ff_refstruct_unref(&s->input_picture[0]);
15591570 return b_frames;
15601571 }
15611572 }
@@ -1589,12 +1600,14 @@ static int set_bframe_chain_length(MpegEncContext *s) · 27 unmodified lines
15891600 b_frames--;
15901601
15911602 s->reordered_input_picture[0] = s->input_picture[b_frames];
1603+ s->input_picture[b_frames] = NULL;
15921604 if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I)
15931605 s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P;
15941606 s->reordered_input_picture[0]->coded_picture_number =
15951607 s->coded_picture_number++;
15961608 for (int i = 0; i < b_frames; i++) {
15971609 s->reordered_input_picture[i + 1] = s->input_picture[i];
1610+ s->input_picture[i] = NULL;
15981611 s->reordered_input_picture[i + 1]->f->pict_type =
15991612 AV_PICTURE_TYPE_B;
16001613 s->reordered_input_picture[i + 1]->coded_picture_number =
@@ -1609,11 +1622,14 @@ static int select_input_picture(MpegEncContext *s) · 8 unmodified lines
16091622 {
16101623 int ret;
16111624
1625+ av_assert1(!s->reordered_input_picture[0]);
1626+
16121627 for (int i = 1; i <= MAX_B_FRAMES; i++)
16131628 s->reordered_input_picture[i - 1] = s->reordered_input_picture[i];
16141629 s->reordered_input_picture[MAX_B_FRAMES] = NULL;
16151630
16161631 ret = set_bframe_chain_length(s);
1632+ av_assert1(!s->input_picture[0]);
16171633 if (ret < 0)
16181634 return ret;
16191635
@@ -1643,6 +1659,7 @@ static int select_input_picture(MpegEncContext *s) · 23 unmodified lines
16431659 }
16441660 }
16451661 s->cur_pic.ptr = s->reordered_input_picture[0];
1662+ s->reordered_input_picture[0] = NULL;
16461663 av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width);
16471664 av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height);
16481665 av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride);
@@ -1657,7 +1674,7 @@ static int select_input_picture(MpegEncContext *s) · 8 unmodified lines
16571674 }
16581675 return 0;
16591676 fail:
1660− ff_mpeg_unref_picture(s->reordered_input_picture[0]);
1677+ ff_refstruct_unref(&s->reordered_input_picture[0]);
16611678 return ret;
16621679 }
16631680
@@ -1720,13 +1737,6 @@ static void update_noise_reduction(MpegEncContext *s) · 56 unmodified lines
17201737
17211738 static void frame_start(MpegEncContext *s)
17221739 {
1723− /* mark & release old frames */
1724− if (s->pict_type != AV_PICTURE_TYPE_B && s->last_pic.ptr &&
1725− s->last_pic.ptr != s->next_pic.ptr &&
1726− s->last_pic.ptr->f->buf[0]) {
1727− ff_mpv_unref_picture(&s->last_pic);
1728− }
1729−
17301740 s->cur_pic.ptr->f->pict_type = s->pict_type;
17311741
17321742 if (s->pict_type != AV_PICTURE_TYPE_B) {
@@ -1747,6 +1757,8 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, · 14 unmodified lines
17471757 int i, stuffing_count, ret;
17481758 int context_count = s->slice_context_count;
17491759
1760+ ff_mpv_unref_picture(&s->cur_pic);
1761+
17501762 s->vbv_ignore_qmax = 0;
17511763
17521764 s->picture_in_gop_number++;
@@ -1973,11 +1985,7 @@ vbv_retry: · 220 unmodified lines
19731985 s->frame_bits = 0;
19741986 }
19751987
1976− /* release non-reference frames */
1977− for (i = 0; i < MAX_PICTURE_COUNT; i++) {
1978− if (!s->picture[i].reference)
1979− ff_mpeg_unref_picture(&s->picture[i]);
1980− }
1988+ ff_mpv_unref_picture(&s->cur_pic);
19811989
19821990 av_assert1((s->frame_bits & 7) == 0);
19831991
libavcodec/mpegvideodec.h+3−1
@@ -44,8 +44,10 @@ · 43 unmodified lines
4444 * Initialize the given MpegEncContext for decoding.
4545 * the changed fields will not depend upon
4646 * the prior state of the MpegEncContext.
47+ *
48+ * Also initialize the picture pool.
4749 */
48−void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx);
50+int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx);
4951
5052 int ff_mpv_common_frame_size_change(MpegEncContext *s);
5153
libavcodec/msmpeg4dec.c+8−4
@@ -852,7 +852,8 @@ const FFCodec ff_msmpeg4v1_decoder = { · 851 unmodified lines
852852 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
853853 .close = ff_mpv_decode_close,
854854 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
855− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
855+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
856+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
856857 .p.max_lowres = 3,
857858 };
858859
@@ -866,7 +867,8 @@ const FFCodec ff_msmpeg4v2_decoder = { · 7 unmodified lines
866867 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
867868 .close = ff_mpv_decode_close,
868869 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
869− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
870+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
871+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
870872 .p.max_lowres = 3,
871873 };
872874
@@ -880,7 +882,8 @@ const FFCodec ff_msmpeg4v3_decoder = { · 7 unmodified lines
880882 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
881883 .close = ff_mpv_decode_close,
882884 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
883− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
885+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
886+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
884887 .p.max_lowres = 3,
885888 };
886889
@@ -894,6 +897,7 @@ const FFCodec ff_wmv1_decoder = { · 7 unmodified lines
894897 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
895898 .close = ff_mpv_decode_close,
896899 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
897− .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
900+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
901+ FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
898902 .p.max_lowres = 3,
899903 };
libavcodec/rv10.c+6−2
@@ -364,7 +364,9 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx) · 363 unmodified lines
364364 avctx->coded_height, 0, avctx)) < 0)
365365 return ret;
366366
367− ff_mpv_decode_init(s, avctx);
367+ ret = ff_mpv_decode_init(s, avctx);
368+ if (ret < 0)
369+ return ret;
368370
369371 s->out_format = FMT_H263;
370372
@@ -645,7 +647,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 274 unmodified lines
645647 }
646648
647649 // so we can detect if frame_end was not called (find some nicer solution...)
648− s->cur_pic.ptr = NULL;
650+ ff_mpv_unref_picture(&s->cur_pic);
649651 }
650652
651653 return avpkt->size;
@@ -662,6 +664,7 @@ const FFCodec ff_rv10_decoder = { · 10 unmodified lines
662664 .close = ff_mpv_decode_close,
663665 .p.capabilities = AV_CODEC_CAP_DR1,
664666 .p.max_lowres = 3,
667+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
665668 };
666669
667670 const FFCodec ff_rv20_decoder = {
@@ -676,4 +679,5 @@ const FFCodec ff_rv20_decoder = { · 8 unmodified lines
676679 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
677680 .flush = ff_mpeg_flush,
678681 .p.max_lowres = 3,
682+ .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
679683 };
libavcodec/rv34.c+4−2
@@ -1510,7 +1510,9 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx) · 1509 unmodified lines
15101510 MpegEncContext *s = &r->s;
15111511 int ret;
15121512
1513− ff_mpv_decode_init(s, avctx);
1513+ ret = ff_mpv_decode_init(s, avctx);
1514+ if (ret < 0)
1515+ return ret;
15141516 s->out_format = FMT_H263;
15151517
15161518 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
@@ -1632,7 +1634,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 115 unmodified lines
16321634 if (s->next_pic.ptr) {
16331635 if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
16341636 return ret;
1635− s->next_pic.ptr = NULL;
1637+ ff_mpv_unref_picture(&s->next_pic);
16361638
16371639 *got_picture_ptr = 1;
16381640 }
libavcodec/svq1enc.c+0−3
@@ -60,7 +60,6 @@ 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;
6463 AVCodecContext *avctx;
6564 MECmpContext mecc;
6665 HpelDSPContext hdsp;
@@ -327,8 +326,6 @@ static int svq1_encode_plane(SVQ1EncContext *s, int plane, · 260 unmodified lines
327326
328327 if (s->pict_type == AV_PICTURE_TYPE_P) {
329328 s->m.avctx = s->avctx;
330− s->m.cur_pic.ptr = &s->cur_pic;
331− s->m.last_pic.ptr = &s->last_pic;
332329 s->m.last_pic.data[0] = ref_plane;
333330 s->m.linesize =
334331 s->m.last_pic.linesize[0] =
libavcodec/vc1dec.c+5−3
@@ -461,7 +461,9 @@ av_cold int ff_vc1_decode_init(AVCodecContext *avctx) · 460 unmodified lines
461461 if (ret < 0)
462462 return ret;
463463
464− ff_mpv_decode_init(s, avctx);
464+ ret = ff_mpv_decode_init(s, avctx);
465+ if (ret < 0)
466+ return ret;
465467
466468 avctx->pix_fmt = vc1_get_format(avctx);
467469
@@ -846,7 +848,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 378 unmodified lines
846848 if (s->low_delay == 0 && s->next_pic.ptr) {
847849 if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
848850 return ret;
849− s->next_pic.ptr = NULL;
851+ ff_mpv_unref_picture(&s->next_pic);
850852
851853 *got_frame = 1;
852854 }
@@ -997,7 +999,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 144 unmodified lines
997999 if (s->context_initialized &&
9981000 (s->width != avctx->coded_width ||
9991001 s->height != avctx->coded_height)) {
1000− ff_vc1_decode_end(avctx);
1002+ vc1_decode_reset(avctx);
10011003 }
10021004
10031005 if (!s->context_initialized) {

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