History

avcodec/mpegvideo_dec: Factor allocating dummy frame out

Andreas Rheinhardt committed 3 years ago

Commit b7cf2d01 parent b00c6971 file · +32 −32Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/mpegvideo_dec.c+32−32
@@ -270,6 +270,32 @@ fail: · 269 unmodified lines
270270 return ret;
271271 }
272272
273+static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp)
274+{
275+ int idx = ff_find_unused_picture(s->avctx, s->picture, 0);
276+ Picture *pic;
277+ int ret;
278+
279+ if (idx < 0)
280+ return idx;
281+
282+ pic = &s->picture[idx];
283+
284+ pic->reference = 3;
285+ pic->f->pict_type = AV_PICTURE_TYPE_P;
286+
287+ ret = alloc_picture(s, pic);
288+ if (ret < 0)
289+ return ret;
290+
291+ ff_thread_report_progress(&pic->tf, INT_MAX, 0);
292+ ff_thread_report_progress(&pic->tf, INT_MAX, 1);
293+
294+ *picp = pic;
295+
296+ return 0;
297+}
298+
273299 static void color_frame(AVFrame *frame, int luma)
274300 {
275301 int h_chroma_shift, v_chroma_shift;
@@ -379,48 +405,22 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) · 103 unmodified lines
379405 "warning: first frame is no keyframe\n");
380406
381407 /* Allocate a dummy frame */
382− idx = ff_find_unused_picture(s->avctx, s->picture, 0);
383− if (idx < 0) {
384− av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
385− return idx;
386− }
387− s->last_picture_ptr = &s->picture[idx];
388−
389− s->last_picture_ptr->reference = 3;
390− s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
391−
392− if (alloc_picture(s, s->last_picture_ptr) < 0) {
393− s->last_picture_ptr = NULL;
394− return -1;
395− }
408+ ret = alloc_dummy_frame(s, &s->last_picture_ptr);
409+ if (ret < 0)
410+ return ret;
396411
397412 if (!avctx->hwaccel) {
398413 int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80;
399414 color_frame(s->last_picture_ptr->f, luma_val);
400415 }
401416
402− ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
403− ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1);
404417 }
405418 if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
406419 s->pict_type == AV_PICTURE_TYPE_B) {
407420 /* Allocate a dummy frame */
408− idx = ff_find_unused_picture(s->avctx, s->picture, 0);
409− if (idx < 0) {
410− av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
411− return idx;
412− }
413− s->next_picture_ptr = &s->picture[idx];
414−
415− s->next_picture_ptr->reference = 3;
416− s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
417−
418− if (alloc_picture(s, s->next_picture_ptr) < 0) {
419− s->next_picture_ptr = NULL;
420− return -1;
421− }
422− ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 0);
423− ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1);
421+ ret = alloc_dummy_frame(s, &s->next_picture_ptr);
422+ if (ret < 0)
423+ return ret;
424424 }
425425
426426 if (s->last_picture_ptr) {

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