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
541}541}
542#endif542#endif
543 543
544static int fill_frame_props(AVCodecContext *avctx, AVFrame *frame)544static int fill_frame_props(const AVCodecContext *avctx, AVFrame *frame)
545{545{
546 int ret;546 int ret;
547 547
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
548 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {559 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)) {
552 if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio;560 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;
555 if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;561 if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt;
556 }
557 } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {562 } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
558 if (frame->format == AV_SAMPLE_FMT_NONE)563 if (frame->format == AV_SAMPLE_FMT_NONE)
559 frame->format = avctx->sample_fmt;564 frame->format = avctx->sample_fmt;
560 if (!frame->ch_layout.nb_channels) {565 if (!frame->ch_layout.nb_channels) {
561 ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);566 ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
562 if (ret < 0) {567 if (ret < 0)
563 av_frame_unref(frame);
564 return ret;568 return ret;
565 }
566 }569 }
567#if FF_API_OLD_CHANNEL_LAYOUT570#if FF_API_OLD_CHANNEL_LAYOUT
568FF_DISABLE_DEPRECATION_WARNINGS571FF_DISABLE_DEPRECATION_WARNINGS
@@ -629,7 +632,12 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 60 unmodified lines
629 }632 }
630 633
631 if (!ret) {634 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
633 frame->flags |= AV_FRAME_FLAG_KEY;641 frame->flags |= AV_FRAME_FLAG_KEY;
634 642
635 ret = fill_frame_props(avctx, frame);643 ret = fill_frame_props(avctx, frame);
@@ -1453,9 +1461,10 @@ FF_ENABLE_DEPRECATION_WARNINGS · 817 unmodified lines
1453int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)1461int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
1454{1462{
1455 const AVPacket *pkt = avctx->internal->last_pkt_props;1463 const AVPacket *pkt = avctx->internal->last_pkt_props;
1464 int ret;
1456 1465
1457 if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {1466 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);
1459 if (ret < 0)1468 if (ret < 0)
1460 return ret;1469 return ret;
1461#if FF_API_FRAME_PKT1470#if FF_API_FRAME_PKT
@@ -1470,23 +1479,12 @@ FF_DISABLE_DEPRECATION_WARNINGS · 8 unmodified lines
1470FF_ENABLE_DEPRECATION_WARNINGS1479FF_ENABLE_DEPRECATION_WARNINGS
1471#endif1480#endif
1472 1481
1473 if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)1482 ret = fill_frame_props(avctx, frame);
1474 frame->color_primaries = avctx->color_primaries;1483 if (ret < 0)
1475 if (frame->color_trc == AVCOL_TRC_UNSPECIFIED)1484 return ret;
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;
1483 1485
1484 switch (avctx->codec->type) {1486 switch (avctx->codec->type) {
1485 case AVMEDIA_TYPE_VIDEO:1487 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
1490 if (frame->width && frame->height &&1488 if (frame->width && frame->height &&
1491 av_image_check_sar(frame->width, frame->height,1489 av_image_check_sar(frame->width, frame->height,
1492 frame->sample_aspect_ratio) < 0) {1490 frame->sample_aspect_ratio) < 0) {
@@ -1495,25 +1493,6 @@ FF_ENABLE_DEPRECATION_WARNINGS · 2 unmodified lines
1495 frame->sample_aspect_ratio.den);1493 frame->sample_aspect_ratio.den);
1496 frame->sample_aspect_ratio = (AVRational){ 0, 1 };1494 frame->sample_aspect_ratio = (AVRational){ 0, 1 };
1497 }1495 }
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
1511FF_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;
1515FF_ENABLE_DEPRECATION_WARNINGS
1516#endif
1517 break;1496 break;
1518 }1497 }
1519 return 0;1498 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