History

avcodec/svq3: Deduplicate allocating dummy frame

Andreas Rheinhardt committed 1 year ago

Commit eacde6e1 parent cb54eca1 file · +19 −16Browse files

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

Unified · Split

libavcodec/svq3.c+19−16
@@ -1377,6 +1377,23 @@ fail: · 1376 unmodified lines
13771377 return ret;
13781378 }
13791379
1380+static av_cold int alloc_dummy_frame(AVCodecContext *avctx, SVQ3Frame *pic)
1381+{
1382+ av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
1383+ av_frame_unref(pic->f);
1384+ int ret = get_buffer(avctx, pic);
1385+ if (ret < 0)
1386+ return ret;
1387+
1388+ memset(pic->f->data[0], 0, avctx->height * pic->f->linesize[0]);
1389+ memset(pic->f->data[1], 0x80, (avctx->height / 2) *
1390+ pic->f->linesize[1]);
1391+ memset(pic->f->data[2], 0x80, (avctx->height / 2) *
1392+ pic->f->linesize[2]);
1393+
1394+ return 0;
1395+}
1396+
13801397 static int svq3_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
13811398 int *got_frame, AVPacket *avpkt)
13821399 {
@@ -1441,29 +1458,15 @@ static int svq3_decode_frame(AVCodecContext *avctx, AVFrame *rframe, · 58 unmodified lines
14411458
14421459 if (s->pict_type != AV_PICTURE_TYPE_I) {
14431460 if (!s->last_pic->f->data[0]) {
1444− av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
1445− av_frame_unref(s->last_pic->f);
1446− ret = get_buffer(avctx, s->last_pic);
1461+ ret = alloc_dummy_frame(avctx, s->last_pic);
14471462 if (ret < 0)
14481463 return ret;
1449− memset(s->last_pic->f->data[0], 0, avctx->height * s->last_pic->f->linesize[0]);
1450− memset(s->last_pic->f->data[1], 0x80, (avctx->height / 2) *
1451− s->last_pic->f->linesize[1]);
1452− memset(s->last_pic->f->data[2], 0x80, (avctx->height / 2) *
1453− s->last_pic->f->linesize[2]);
14541464 }
14551465
14561466 if (s->pict_type == AV_PICTURE_TYPE_B && !s->next_pic->f->data[0]) {
1457− av_log(avctx, AV_LOG_ERROR, "Missing reference frame.\n");
1458− av_frame_unref(s->next_pic->f);
1459− ret = get_buffer(avctx, s->next_pic);
1467+ ret = alloc_dummy_frame(avctx, s->next_pic);
14601468 if (ret < 0)
14611469 return ret;
1462− memset(s->next_pic->f->data[0], 0, avctx->height * s->next_pic->f->linesize[0]);
1463− memset(s->next_pic->f->data[1], 0x80, (avctx->height / 2) *
1464− s->next_pic->f->linesize[1]);
1465− memset(s->next_pic->f->data[2], 0x80, (avctx->height / 2) *
1466− s->next_pic->f->linesize[2]);
14671470 }
14681471 }
14691472

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