diff options
author | James Almer <jamrial@gmail.com> | 2024-02-20 19:09:12 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2024-02-29 14:48:00 -0300 |
commit | 194414f62d987ad831654c45fff6ee27898b832e (patch) | |
tree | b5a139000aba099ab5a75d8a7007ef04f8efe326 /libavcodec | |
parent | ec7937f4a56e2fbd4070660ff19f0e02c039768a (diff) | |
download | ffmpeg-194414f62d987ad831654c45fff6ee27898b832e.tar.gz |
avcodec/av1dec: implement FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
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>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/av1dec.c | 58 | ||||
-rw-r--r-- | libavcodec/av1dec.h | 2 |
2 files changed, 39 insertions, 21 deletions
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 820fa79f48..704b9d6298 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, @@ -1215,6 +1240,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; @@ -1228,25 +1259,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) @@ -1423,6 +1437,8 @@ end: ff_cbs_fragment_reset(&s->current_obu); s->nb_unit = 0; } + if (!ret && !frame->buf[0]) + ret = AVERROR(EAGAIN); return ret; } @@ -1507,7 +1523,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 |