From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avcodec/av1dec: implement FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM Date: Tue, 20 Feb 2024 19:33:23 -0300 Message-ID: <20240220223323.4165-1-jamrial@gmail.com> (raw) Fixes errors when opening streams with no extradata (like those from raw OBU sources). It also calls get_format() on new Sequence Headers when required. Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/av1dec.c | 58 +++++++++++++++++++++++++++++---------------- libavcodec/av1dec.h | 2 ++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 7debc4deda..48a3af2fca 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -620,6 +620,12 @@ static int get_pixel_format(AVCodecContext *avctx) *fmtp++ = pix_fmt; *fmtp = AV_PIX_FMT_NONE; + for (int i = 0; pix_fmts[i] != pix_fmt; i++) + if (pix_fmts[i] == avctx->pix_fmt) { + s->pix_fmt = pix_fmt; + return 1; + } + ret = ff_get_format(avctx, pix_fmts); /** @@ -715,6 +721,7 @@ static av_cold int av1_decode_free(AVCodecContext *avctx) av1_frame_unref(&s->cur_frame); av_frame_free(&s->cur_frame.f); } + av_buffer_unref(&s->seq_data_ref); ff_refstruct_unref(&s->seq_ref); ff_refstruct_unref(&s->header_ref); ff_refstruct_unref(&s->cll_ref); @@ -771,6 +778,9 @@ static int set_context_with_sequence(AVCodecContext *avctx, seq->timing_info.num_units_in_display_tick, seq->timing_info.time_scale); + if (avctx->pix_fmt == AV_PIX_FMT_NONE) + avctx->pix_fmt = get_sw_pixel_format(avctx, seq); + return 0; } @@ -869,8 +879,6 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) goto end; } - avctx->pix_fmt = get_sw_pixel_format(avctx, seq); - end: ff_cbs_fragment_reset(&s->current_obu); } @@ -1174,6 +1182,23 @@ static int get_current_frame(AVCodecContext *avctx) avctx->skip_frame >= AVDISCARD_ALL) return 0; + if (s->pix_fmt == AV_PIX_FMT_NONE) { + ret = get_pixel_format(avctx); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "Failed to get pixel format.\n"); + return ret; + } + + if (!ret && FF_HW_HAS_CB(avctx, decode_params)) { + ret = FF_HW_CALL(avctx, decode_params, AV1_OBU_SEQUENCE_HEADER, + s->seq_data_ref->data, s->seq_data_ref->size); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n"); + return ret; + } + } + } + ret = av1_frame_alloc(avctx, &s->cur_frame); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, @@ -1208,6 +1233,12 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) switch (unit->type) { case AV1_OBU_SEQUENCE_HEADER: + ret = av_buffer_replace(&s->seq_data_ref, unit->data_ref); + if (ret < 0) + goto end; + + s->seq_data_ref->data = unit->data; + s->seq_data_ref->size = unit->data_size; ff_refstruct_replace(&s->seq_ref, unit->content_ref); s->raw_seq = &obu->obu.sequence_header; @@ -1221,25 +1252,8 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point]; - if (s->pix_fmt == AV_PIX_FMT_NONE) { - ret = get_pixel_format(avctx); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, - "Failed to get pixel format.\n"); - s->raw_seq = NULL; - goto end; - } - } + s->pix_fmt = AV_PIX_FMT_NONE; - if (FF_HW_HAS_CB(avctx, decode_params)) { - ret = FF_HW_CALL(avctx, decode_params, unit->type, - unit->data, unit->data_size); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "HW accel decode params fail.\n"); - s->raw_seq = NULL; - goto end; - } - } break; case AV1_OBU_REDUNDANT_FRAME_HEADER: if (s->raw_frame_header) @@ -1416,6 +1430,8 @@ end: ff_cbs_fragment_reset(&s->current_obu); s->nb_unit = 0; } + if (!ret && !frame->buf[0]) + ret = AVERROR(EAGAIN); return ret; } @@ -1500,7 +1516,7 @@ const FFCodec ff_av1_decoder = { .close = av1_decode_free, FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame), .p.capabilities = AV_CODEC_CAP_DR1, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = av1_decode_flush, .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), .p.priv_class = &av1_class, diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index b6a0c08e48..a6ad80c12a 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -23,6 +23,7 @@ #include <stdint.h> +#include "libavutil/buffer.h" #include "libavutil/fifo.h" #include "libavutil/frame.h" #include "libavutil/pixfmt.h" @@ -69,6 +70,7 @@ typedef struct AV1DecContext { CodedBitstreamFragment current_obu; AVPacket *pkt; + AVBufferRef *seq_data_ref; AV1RawOBU *seq_ref; ///< RefStruct reference backing raw_seq AV1RawSequenceHeader *raw_seq; AV1RawOBU *header_ref; ///< RefStruct reference backing raw_frame_header -- 2.43.2 _______________________________________________ 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:[~2024-02-20 22:33 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-20 22:33 James Almer [this message] 2024-02-29 13:32 ` 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=20240220223323.4165-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