summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-14 23:00:42 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2024-04-08 15:00:02 +0200
commitb7cf2d0efcd20384b6ddbc2c1bfd04e0ea591474 (patch)
treeaf8d756e2f672545eac5840b5e42b6669ba962e8
parentb00c6976547c4d08b32c6ecd7ecdfebb916ffab7 (diff)
avcodec/mpegvideo_dec: Factor allocating dummy frame out
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r--libavcodec/mpegvideo_dec.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c
index 4fa89e4aef..b6ef4e5582 100644
--- a/libavcodec/mpegvideo_dec.c
+++ b/libavcodec/mpegvideo_dec.c
@@ -270,6 +270,32 @@ fail:
return ret;
}
+static int av_cold alloc_dummy_frame(MpegEncContext *s, Picture **picp)
+{
+ int idx = ff_find_unused_picture(s->avctx, s->picture, 0);
+ Picture *pic;
+ int ret;
+
+ if (idx < 0)
+ return idx;
+
+ pic = &s->picture[idx];
+
+ pic->reference = 3;
+ pic->f->pict_type = AV_PICTURE_TYPE_P;
+
+ ret = alloc_picture(s, pic);
+ if (ret < 0)
+ return ret;
+
+ ff_thread_report_progress(&pic->tf, INT_MAX, 0);
+ ff_thread_report_progress(&pic->tf, INT_MAX, 1);
+
+ *picp = pic;
+
+ return 0;
+}
+
static void color_frame(AVFrame *frame, int luma)
{
int h_chroma_shift, v_chroma_shift;
@@ -379,48 +405,22 @@ int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
"warning: first frame is no keyframe\n");
/* Allocate a dummy frame */
- idx = ff_find_unused_picture(s->avctx, s->picture, 0);
- if (idx < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
- return idx;
- }
- s->last_picture_ptr = &s->picture[idx];
-
- s->last_picture_ptr->reference = 3;
- s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
-
- if (alloc_picture(s, s->last_picture_ptr) < 0) {
- s->last_picture_ptr = NULL;
- return -1;
- }
+ ret = alloc_dummy_frame(s, &s->last_picture_ptr);
+ if (ret < 0)
+ return ret;
if (!avctx->hwaccel) {
int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80;
color_frame(s->last_picture_ptr->f, luma_val);
}
- ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
- ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1);
}
if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
s->pict_type == AV_PICTURE_TYPE_B) {
/* Allocate a dummy frame */
- idx = ff_find_unused_picture(s->avctx, s->picture, 0);
- if (idx < 0) {
- av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
- return idx;
- }
- s->next_picture_ptr = &s->picture[idx];
-
- s->next_picture_ptr->reference = 3;
- s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
-
- if (alloc_picture(s, s->next_picture_ptr) < 0) {
- s->next_picture_ptr = NULL;
- return -1;
- }
- ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 0);
- ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1);
+ ret = alloc_dummy_frame(s, &s->next_picture_ptr);
+ if (ret < 0)
+ return ret;
}
if (s->last_picture_ptr) {