History

avcodec/decode: factor out filling frame props

James Almer committed 3 years ago

Commit 31979121 parent c541ecf1 file · +24 −45Browse files

Unified · Split

libavcodec/decode.c+24−45
@@ -541,28 +541,31 @@ static int detect_colorspace(av_unused AVCodecContext *c, av_unused AVFrame *f) · 540 unmodified lines
541541 }
542542 #endif
543543
544−static int fill_frame_props(AVCodecContext *avctx, AVFrame *frame)
544+static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
545545 {
546546 int ret;
547547
548+ if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
549+ frame->color_primaries = avctx->color_primaries;
550+ if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
551+ frame->color_trc = avctx->color_trc;
552+ if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
553+ frame->colorspace = avctx->colorspace;
554+ if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
555+ frame->color_range = avctx->color_range;
556+ if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
557+ frame->chroma_location = avctx->chroma_sample_location;
558+
548559 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
549− //FIXME these should be under if(!avctx->has_b_frames)
550− /* get_buffer is supposed to set frame parameters */
551− if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) {
552560 if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
553− if (!frame->width) frame->width = avctx->width;
554− if (!frame->height) frame->height = avctx->height;
555561 if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
556− }
557562 } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
558563 if (frame->format == AV_SAMPLE_FMT_NONE)
559564 frame->format = avctx->sample_fmt;
560565 if (!frame->ch_layout.nb_channels) {
561566 ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
562− if (ret < 0) {
563− av_frame_unref(frame);
567+ if (ret < 0)
564568 return ret;
565− }
566569 }
567570 #if FF_API_OLD_CHANNEL_LAYOUT
568571 FF_DISABLE_DEPRECATION_WARNINGS
@@ -629,7 +632,12 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 60 unmodified lines
629632 }
630633
631634 if (!ret) {
632− if (avctx->codec_type != AVMEDIA_TYPE_VIDEO)
635+ if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
636+ if (!frame->width)
637+ frame->width = avctx->width;
638+ if (!frame->height)
639+ frame->height = avctx->height;
640+ } else
633641 frame->flags |= AV_FRAME_FLAG_KEY;
634642
635643 ret = fill_frame_props(avctx, frame);
@@ -1453,9 +1461,10 @@ FF_ENABLE_DEPRECATION_WARNINGS · 817 unmodified lines
14531461 int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
14541462 {
14551463 const AVPacket *pkt = avctx->internal->last_pkt_props;
1464+ int ret;
14561465
14571466 if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
1458− int ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt);
1467+ ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt);
14591468 if (ret < 0)
14601469 return ret;
14611470 #if FF_API_FRAME_PKT
@@ -1470,23 +1479,12 @@ FF_DISABLE_DEPRECATION_WARNINGS · 8 unmodified lines
14701479 FF_ENABLE_DEPRECATION_WARNINGS
14711480 #endif
14721481
1473− if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
1474− frame->color_primaries = avctx->color_primaries;
1475− if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)
1476− frame->color_trc = avctx->color_trc;
1477− if (frame->colorspace == AVCOL_SPC_UNSPECIFIED)
1478− frame->colorspace = avctx->colorspace;
1479− if (frame->color_range == AVCOL_RANGE_UNSPECIFIED)
1480− frame->color_range = avctx->color_range;
1481− if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
1482− frame->chroma_location = avctx->chroma_sample_location;
1482+ ret = fill_frame_props(avctx, frame);
1483+ if (ret < 0)
1484+ return ret;
14831485
14841486 switch (avctx->codec->type) {
14851487 case AVMEDIA_TYPE_VIDEO:
1486− frame->format = avctx->pix_fmt;
1487− if (!frame->sample_aspect_ratio.num)
1488− frame->sample_aspect_ratio = avctx->sample_aspect_ratio;
1489−
14901488 if (frame->width && frame->height &&
14911489 av_image_check_sar(frame->width, frame->height,
14921490 frame->sample_aspect_ratio) < 0) {
@@ -1495,25 +1493,6 @@ FF_ENABLE_DEPRECATION_WARNINGS · 2 unmodified lines
14951493 frame->sample_aspect_ratio.den);
14961494 frame->sample_aspect_ratio = (AVRational){ 0, 1 };
14971495 }
1498−
1499− break;
1500− case AVMEDIA_TYPE_AUDIO:
1501− if (!frame->sample_rate)
1502− frame->sample_rate = avctx->sample_rate;
1503− if (frame->format < 0)
1504− frame->format = avctx->sample_fmt;
1505− if (!frame->ch_layout.nb_channels) {
1506− int ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
1507− if (ret < 0)
1508− return ret;
1509− }
1510−#if FF_API_OLD_CHANNEL_LAYOUT
1511−FF_DISABLE_DEPRECATION_WARNINGS
1512− frame->channels = frame->ch_layout.nb_channels;
1513− frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
1514− frame->ch_layout.u.mask : 0;
1515−FF_ENABLE_DEPRECATION_WARNINGS
1516−#endif
15171496 break;
15181497 }
15191498 return 0;

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