Commit 194414f6 authored by James Almer's avatar James Almer

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: 's avatarJames Almer <jamrial@gmail.com>
parent ec7937f4
...@@ -620,6 +620,12 @@ static int get_pixel_format(AVCodecContext *avctx) ...@@ -620,6 +620,12 @@ static int get_pixel_format(AVCodecContext *avctx)
*fmtp++ = pix_fmt; *fmtp++ = pix_fmt;
*fmtp = AV_PIX_FMT_NONE; *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); ret = ff_get_format(avctx, pix_fmts);
/** /**
...@@ -715,6 +721,7 @@ static av_cold int av1_decode_free(AVCodecContext *avctx) ...@@ -715,6 +721,7 @@ static av_cold int av1_decode_free(AVCodecContext *avctx)
av1_frame_unref(&s->cur_frame); av1_frame_unref(&s->cur_frame);
av_frame_free(&s->cur_frame.f); av_frame_free(&s->cur_frame.f);
} }
av_buffer_unref(&s->seq_data_ref);
ff_refstruct_unref(&s->seq_ref); ff_refstruct_unref(&s->seq_ref);
ff_refstruct_unref(&s->header_ref); ff_refstruct_unref(&s->header_ref);
ff_refstruct_unref(&s->cll_ref); ff_refstruct_unref(&s->cll_ref);
...@@ -771,6 +778,9 @@ static int set_context_with_sequence(AVCodecContext *avctx, ...@@ -771,6 +778,9 @@ static int set_context_with_sequence(AVCodecContext *avctx,
seq->timing_info.num_units_in_display_tick, seq->timing_info.num_units_in_display_tick,
seq->timing_info.time_scale); seq->timing_info.time_scale);
if (avctx->pix_fmt == AV_PIX_FMT_NONE)
avctx->pix_fmt = get_sw_pixel_format(avctx, seq);
return 0; return 0;
} }
...@@ -869,8 +879,6 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) ...@@ -869,8 +879,6 @@ static av_cold int av1_decode_init(AVCodecContext *avctx)
goto end; goto end;
} }
avctx->pix_fmt = get_sw_pixel_format(avctx, seq);
end: end:
ff_cbs_fragment_reset(&s->current_obu); ff_cbs_fragment_reset(&s->current_obu);
} }
...@@ -1174,6 +1182,23 @@ static int get_current_frame(AVCodecContext *avctx) ...@@ -1174,6 +1182,23 @@ static int get_current_frame(AVCodecContext *avctx)
avctx->skip_frame >= AVDISCARD_ALL) avctx->skip_frame >= AVDISCARD_ALL)
return 0; 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); ret = av1_frame_alloc(avctx, &s->cur_frame);
if (ret < 0) { if (ret < 0) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
...@@ -1215,6 +1240,12 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) ...@@ -1215,6 +1240,12 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
switch (unit->type) { switch (unit->type) {
case AV1_OBU_SEQUENCE_HEADER: 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); ff_refstruct_replace(&s->seq_ref, unit->content_ref);
s->raw_seq = &obu->obu.sequence_header; s->raw_seq = &obu->obu.sequence_header;
...@@ -1228,25 +1259,8 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) ...@@ -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]; s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point];
if (s->pix_fmt == AV_PIX_FMT_NONE) { 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;
}
}
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; break;
case AV1_OBU_REDUNDANT_FRAME_HEADER: case AV1_OBU_REDUNDANT_FRAME_HEADER:
if (s->raw_frame_header) if (s->raw_frame_header)
...@@ -1423,6 +1437,8 @@ end: ...@@ -1423,6 +1437,8 @@ end:
ff_cbs_fragment_reset(&s->current_obu); ff_cbs_fragment_reset(&s->current_obu);
s->nb_unit = 0; s->nb_unit = 0;
} }
if (!ret && !frame->buf[0])
ret = AVERROR(EAGAIN);
return ret; return ret;
} }
...@@ -1507,7 +1523,7 @@ const FFCodec ff_av1_decoder = { ...@@ -1507,7 +1523,7 @@ const FFCodec ff_av1_decoder = {
.close = av1_decode_free, .close = av1_decode_free,
FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame), FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame),
.p.capabilities = AV_CODEC_CAP_DR1, .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, .flush = av1_decode_flush,
.p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
.p.priv_class = &av1_class, .p.priv_class = &av1_class,
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <stdint.h> #include <stdint.h>
#include "libavutil/buffer.h"
#include "libavutil/fifo.h" #include "libavutil/fifo.h"
#include "libavutil/frame.h" #include "libavutil/frame.h"
#include "libavutil/pixfmt.h" #include "libavutil/pixfmt.h"
...@@ -69,6 +70,7 @@ typedef struct AV1DecContext { ...@@ -69,6 +70,7 @@ typedef struct AV1DecContext {
CodedBitstreamFragment current_obu; CodedBitstreamFragment current_obu;
AVPacket *pkt; AVPacket *pkt;
AVBufferRef *seq_data_ref;
AV1RawOBU *seq_ref; ///< RefStruct reference backing raw_seq AV1RawOBU *seq_ref; ///< RefStruct reference backing raw_seq
AV1RawSequenceHeader *raw_seq; AV1RawSequenceHeader *raw_seq;
AV1RawOBU *header_ref; ///< RefStruct reference backing raw_frame_header AV1RawOBU *header_ref; ///< RefStruct reference backing raw_frame_header
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment