From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avcodec/decode: factor out filling frame props Date: Fri, 14 Jul 2023 15:20:36 -0300 Message-ID: <20230714182036.32592-1-jamrial@gmail.com> (raw) Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/decode.c | 67 ++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 68525e47a6..51216988a6 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -545,24 +545,27 @@ static int fill_frame_props(AVCodecContext *avctx, AVFrame *frame) { int ret; + if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED) + frame->color_primaries = avctx->color_primaries; + if (frame->color_trc == AVCOL_TRC_UNSPECIFIED) + frame->color_trc = avctx->color_trc; + if (frame->colorspace == AVCOL_SPC_UNSPECIFIED) + frame->colorspace = avctx->colorspace; + if (frame->color_range == AVCOL_RANGE_UNSPECIFIED) + frame->color_range = avctx->color_range; + if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED) + frame->chroma_location = avctx->chroma_sample_location; + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { - //FIXME these should be under if(!avctx->has_b_frames) - /* get_buffer is supposed to set frame parameters */ - if (!(avctx->codec->capabilities & AV_CODEC_CAP_DR1)) { if (!frame->sample_aspect_ratio.num) frame->sample_aspect_ratio = avctx->sample_aspect_ratio; - if (!frame->width) frame->width = avctx->width; - if (!frame->height) frame->height = avctx->height; if (frame->format == AV_PIX_FMT_NONE) frame->format = avctx->pix_fmt; - } } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { if (frame->format == AV_SAMPLE_FMT_NONE) frame->format = avctx->sample_fmt; if (!frame->ch_layout.nb_channels) { ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); - if (ret < 0) { - av_frame_unref(frame); + if (ret < 0) return ret; - } } #if FF_API_OLD_CHANNEL_LAYOUT FF_DISABLE_DEPRECATION_WARNINGS @@ -629,7 +632,12 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) } if (!ret) { - if (avctx->codec_type != AVMEDIA_TYPE_VIDEO) + if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) { + if (!frame->width) + frame->width = avctx->width; + if (!frame->height) + frame->height = avctx->height; + } else frame->flags |= AV_FRAME_FLAG_KEY; ret = fill_frame_props(avctx, frame); @@ -1451,9 +1459,10 @@ FF_ENABLE_DEPRECATION_WARNINGS int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) { const AVPacket *pkt = avctx->internal->last_pkt_props; + int ret; if (!(ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) { - int ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt); + ret = ff_decode_frame_props_from_pkt(avctx, frame, pkt); if (ret < 0) return ret; #if FF_API_FRAME_PKT @@ -1468,23 +1477,12 @@ FF_DISABLE_DEPRECATION_WARNINGS FF_ENABLE_DEPRECATION_WARNINGS #endif - if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED) - frame->color_primaries = avctx->color_primaries; - if (frame->color_trc == AVCOL_TRC_UNSPECIFIED) - frame->color_trc = avctx->color_trc; - if (frame->colorspace == AVCOL_SPC_UNSPECIFIED) - frame->colorspace = avctx->colorspace; - if (frame->color_range == AVCOL_RANGE_UNSPECIFIED) - frame->color_range = avctx->color_range; - if (frame->chroma_location == AVCHROMA_LOC_UNSPECIFIED) - frame->chroma_location = avctx->chroma_sample_location; + ret = fill_frame_props(avctx, frame); + if (ret < 0) + return ret; switch (avctx->codec->type) { case AVMEDIA_TYPE_VIDEO: - frame->format = avctx->pix_fmt; - if (!frame->sample_aspect_ratio.num) - frame->sample_aspect_ratio = avctx->sample_aspect_ratio; - if (frame->width && frame->height && av_image_check_sar(frame->width, frame->height, frame->sample_aspect_ratio) < 0) { @@ -1493,25 +1491,6 @@ FF_ENABLE_DEPRECATION_WARNINGS frame->sample_aspect_ratio.den); frame->sample_aspect_ratio = (AVRational){ 0, 1 }; } - - break; - case AVMEDIA_TYPE_AUDIO: - if (!frame->sample_rate) - frame->sample_rate = avctx->sample_rate; - if (frame->format < 0) - frame->format = avctx->sample_fmt; - if (!frame->ch_layout.nb_channels) { - int ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout); - if (ret < 0) - return ret; - } -#if FF_API_OLD_CHANNEL_LAYOUT -FF_DISABLE_DEPRECATION_WARNINGS - frame->channels = frame->ch_layout.nb_channels; - frame->channel_layout = frame->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ? - frame->ch_layout.u.mask : 0; -FF_ENABLE_DEPRECATION_WARNINGS -#endif break; } return 0; -- 2.41.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next reply other threads:[~2023-07-14 18:20 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-14 18:20 James Almer [this message] 2023-07-17 11:45 ` James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230714182036.32592-1-jamrial@gmail.com \ --to=jamrial@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git