22#include <dav1d/dav1d.h>
42#define FF_DAV1D_VERSION_AT_LEAST(x,y) \
43 (DAV1D_API_VERSION_MAJOR > (x) || DAV1D_API_VERSION_MAJOR == (x) && DAV1D_API_VERSION_MINOR >= (y))
82 uint8_t *aligned_ptr, *
data[4];
107 aligned_ptr = (uint8_t *)
FFALIGN((uintptr_t)buf->
data, DAV1D_PICTURE_ALIGNMENT);
109 DAV1D_PICTURE_ALIGNMENT);
115 p->data[0] =
data[0];
116 p->data[1] =
data[1];
117 p->data[2] =
data[2];
118 p->stride[0] = linesize[0];
119 p->stride[1] = linesize[1];
120 p->allocator_data = buf;
134 c->profile = seq->profile;
135 c->level = ((seq->operating_points[0].major_level - 2) << 2)
136 | seq->operating_points[0].minor_level;
139 case DAV1D_CHR_VERTICAL:
142 case DAV1D_CHR_COLOCATED:
146 if (seq->color_description_present) {
153 if (seq->layout == DAV1D_PIXEL_LAYOUT_I444 &&
c->colorspace ==
AVCOL_SPC_RGB)
156 c->pix_fmt =
pix_fmt[seq->layout][seq->hbd];
159 (
unsigned)seq->num_units_in_tick,
160 (
unsigned)seq->time_scale);
165 Dav1dSequenceHeader seq;
169 if (!
c->extradata ||
c->extradata_size <= 0)
172 if (
c->extradata[0] & 0x80) {
173 int version =
c->extradata[0] & 0x7F;
175 if (
version != 1 ||
c->extradata_size < 4) {
178 "Error decoding extradata\n");
183 if (
c->extradata_size == 4)
189 res = dav1d_parse_sequence_header(&seq,
c->extradata +
offset,
206 int threads =
c->thread_count;
212 dav1d_default_settings(&
s);
215 s.allocator.cookie = dav1d;
218 s.frame_size_limit =
c->max_pixels;
227 s.strict_std_compliance =
c->strict_std_compliance > 0;
229 s.n_threads =
FFMIN(threads, DAV1D_MAX_THREADS);
234 s.n_threads,
s.max_frame_delay);
236#if FF_DAV1D_VERSION_AT_LEAST(6,8)
238 s.decode_frame_type = DAV1D_DECODEFRAMETYPE_KEY;
240 s.decode_frame_type = DAV1D_DECODEFRAMETYPE_INTRA;
242 s.decode_frame_type = DAV1D_DECODEFRAMETYPE_REFERENCE;
249 res = dav1d_open(&dav1d->
c, &
s);
253#if FF_DAV1D_VERSION_AT_LEAST(6,7)
254 res = dav1d_get_frame_delay(&
s);
259 c->delay = res > 1 ? res : 0;
274 dav1d_data_unref(&dav1d->
data);
275 dav1d_flush(dav1d->
c);
309 res = dav1d_data_wrap(
data,
pkt->data,
pkt->size,
318 res = dav1d_data_wrap_user_data(
data, (
const uint8_t *)
pkt,
322 dav1d_data_unref(
data);
333 res = dav1d_send_data(dav1d->
c,
data);
338 dav1d_data_unref(
data);
343 res = dav1d_get_picture(dav1d->
c, p);
346 dav1d_data_unref(
data);
348 }
else if (res ==
AVERROR(EAGAIN))
358 FFITUTT35 itut35 = { .country_code = itut_t35->country_code };
377 Dav1dPicture pic = { 0 }, *p = &pic;
379 enum Dav1dEventFlags event_flags = 0;
393 if (!
frame->buf[0]) {
394 dav1d_picture_unref(p);
398 frame->data[0] = p->data[0];
399 frame->data[1] = p->data[1];
400 frame->data[2] = p->data[2];
401 frame->linesize[0] = p->stride[0];
402 frame->linesize[1] = p->stride[1];
403 frame->linesize[2] = p->stride[1];
405 dav1d_get_event_flags(dav1d->
c, &event_flags);
406 if (
c->pix_fmt ==
AV_PIX_FMT_NONE || event_flags & DAV1D_EVENT_FLAG_NEW_SEQUENCE)
413 frame->width = p->p.w;
414 frame->height = p->p.h;
415 if (
c->width != p->p.w ||
c->height != p->p.h) {
422 &
frame->sample_aspect_ratio.den,
436 if (p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY)
441 switch (p->frame_hdr->frame_type) {
442 case DAV1D_FRAME_TYPE_KEY:
443 case DAV1D_FRAME_TYPE_INTRA:
446 case DAV1D_FRAME_TYPE_INTER:
449 case DAV1D_FRAME_TYPE_SWITCH:
457 if (p->mastering_display) {
465 for (
int i = 0;
i < 3;
i++) {
479 if (p->content_light) {
487 light->
MaxCLL = p->content_light->max_content_light_level;
488 light->
MaxFALL = p->content_light->max_frame_average_light_level;
492#if FF_DAV1D_VERSION_AT_LEAST(6,9)
493 for (
size_t i = 0;
i < p->n_itut_t35;
i++) {
494 const Dav1dITUTT35 *itut_t35 = &p->itut_t35[
i];
496 const Dav1dITUTT35 *itut_t35 = p->itut_t35;
501#if FF_DAV1D_VERSION_AT_LEAST(6,9)
505 if (p->frame_hdr->film_grain.present && (!dav1d->
apply_grain ||
516 fgp->
seed = p->frame_hdr->film_grain.data.seed;
546 memcpy(&fgp->
codec.
aom.
uv_mult, &p->frame_hdr->film_grain.data.uv_mult,
560 dav1d_picture_unref(p);
572 dav1d_data_unref(&dav1d->
data);
573 dav1d_close(&dav1d->
c);
578#ifndef DAV1D_MAX_FRAME_THREADS
579#define DAV1D_MAX_FRAME_THREADS DAV1D_MAX_THREADS
581#ifndef DAV1D_MAX_TILE_THREADS
582#define DAV1D_MAX_TILE_THREADS DAV1D_MAX_THREADS
584#ifndef DAV1D_MAX_FRAME_DELAY
585#define DAV1D_MAX_FRAME_DELAY DAV1D_MAX_FRAME_THREADS
588#define OFFSET(x) offsetof(Libdav1dContext, x)
589#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
593 {
"oppoint",
"Select an operating point of the scalable bitstream",
OFFSET(operating_point),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 31,
VD },
599 .class_name =
"libdav1d decoder",
606 .p.name =
"libdav1d",
619 .p.wrapper_name =
"libdav1d",
static const char *const format[]
const FFCodec ff_libdav1d_decoder
static av_cold void close(AVCodecParserContext *s)
AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick, int64_t time_scale)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_RECEIVE_FRAME_CB(func)
#define FF_CODEC_CAP_SETS_FRAME_PROPS
Codec handles output frame properties internally instead of letting the internal logic derive them fr...
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame)
int ff_decode_content_light_new(const AVCodecContext *avctx, AVFrame *frame, AVContentLightMetadata **clm)
Wrapper around av_content_light_metadata_create_side_data(), which rejects side data overridden by th...
const AVPacketSideData * ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type)
Get side data of the given type from a decoding context.
int ff_decode_mastering_display_new(const AVCodecContext *avctx, AVFrame *frame, AVMasteringDisplayMetadata **mdm)
Wrapper around av_mastering_display_metadata_create_side_data(), which rejects side data overridden b...
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt)
Set various frame properties from the provided packet.
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
#define AV_EF_EXPLODE
abort decoding on minor error detection
static enum AVPixelFormat pix_fmt
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
void(* flush)(AVBSFContext *ctx)
int(* init)(AVBSFContext *ctx)
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
@ AV_FILM_GRAIN_PARAMS_AV1
The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
#define AV_OPT_FLAG_DEPRECATED
Set if option is deprecated, users should refer to AVOption.help text for more information.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_NONINTRA
discard all non intra frames
@ AVDISCARD_NONREF
discard all non reference
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
AVBufferPool * av_buffer_pool_init(size_t size, AVBufferRef *(*alloc)(size_t size))
Allocate and initialize a buffer pool.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static AVRational av_make_q(int num, int den)
Create an AVRational.
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4], const uint8_t *src, enum AVPixelFormat pix_fmt, int width, int height, int align)
Setup the data pointers and linesizes based on the specified image parameters and the provided array.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_SP
Switching Predicted.
@ AV_PICTURE_TYPE_P
Predicted.
#define LIBAVUTIL_VERSION_INT
int ff_itut_t35_parse_buffer(FFITUTT35 *const itut_t35, const uint8_t *buf, size_t buf_size, int flags)
Parse a raw ITU-T T35 buffer to get the country code, provider code, and set them plus the pointer an...
int ff_itut_t35_parse_payload_to_frame(FFITUTT35 *const itut_t35, FFITUTT35Aux *const aux, AVCodecContext *const avctx, AVFrame *const frame)
Parse a pre-processed ITU-T T35 payload to fill a frame's side data.
#define FF_ITUT_T35_FLAG_COUNTRY_CODE
country_code is assumed to not be the first byte of the buffer and must be set by the caller beforeha...
common internal api header.
static void libdav1d_data_free(const uint8_t *data, void *opaque)
static int libdav1d_picture_allocator(Dav1dPicture *p, void *cookie)
static av_cold int libdav1d_init(AVCodecContext *c)
static enum AVPixelFormat pix_fmt_rgb[3]
static void libdav1d_user_data_free(const uint8_t *data, void *opaque)
static int libdav1d_receive_frame_internal(AVCodecContext *c, Dav1dPicture *p)
static void libdav1d_picture_release(Dav1dPicture *p, void *cookie)
static const AVOption libdav1d_options[]
static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *seq)
static const AVClass libdav1d_class
static av_cold int libdav1d_parse_extradata(AVCodecContext *c)
#define DAV1D_MAX_FRAME_DELAY
static av_cold int libdav1d_close(AVCodecContext *c)
static void libdav1d_log_callback(void *opaque, const char *fmt, va_list vl)
static void libdav1d_flush(AVCodecContext *c)
static int parse_itut_t35_metadata(Libdav1dContext *dav1d, Dav1dPicture *p, const Dav1dITUTT35 *itut_t35, AVCodecContext *c, AVFrame *frame)
static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUV444P12
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
#define AV_PIX_FMT_YUV420P10
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GBRP12
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AV_PIX_FMT_GRAY10
AVColorPrimaries
Chromaticity coordinates of the source primaries.
AVColorTransferCharacteristic
Color Transfer Characteristic.
#define AV_PIX_FMT_YUV444P10
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
A reference to a data buffer.
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
main external API structure.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
int chroma_scaling_from_luma
Signals whether to derive the chroma scaling function from the luma.
int limit_output_range
Signals to clip to limited color levels after film grain application.
int scaling_shift
Specifies the shift applied to the chroma components.
int grain_scale_shift
Signals the down shift applied to the generated gaussian numbers during synthesis.
int num_uv_points[2]
If chroma_scaling_from_luma is set to 0, signals the chroma scaling function parameters.
int overlap_flag
Signals whether to overlap film grain blocks.
int ar_coeff_lag
Specifies the auto-regression lag.
int uv_offset[2]
Offset used for component scaling function.
int ar_coeff_shift
Specifies the range of the auto-regressive coefficients.
uint8_t uv_points[2][10][2]
int8_t ar_coeffs_uv[2][25]
Chroma auto-regression coefficients.
int uv_mult[2]
Specifies the luma/chroma multipliers for the index to the component scaling function.
int8_t ar_coeffs_y[24]
Luma auto-regression coefficients.
int num_y_points
Number of points, and the scale and value for each point of the piecewise linear scaling function for...
This structure describes how to handle film grain synthesis in video for specific codecs.
enum AVColorPrimaries color_primaries
enum AVColorRange color_range
Intended video signal characteristics.
int subsampling_x
Intended subsampling ratio, or 0 for luma-only streams.
union AVFilmGrainParams::@177057277273004265167152242113040056044005264354 codec
Additional fields may be added both here and in any structure included.
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
int width
Intended display resolution.
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
enum AVColorTransferCharacteristic color_trc
enum AVColorSpace color_space
This structure describes decoded (raw) audio or video data.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
AVDOVIDecoderConfigurationRecord cfg
Currently active dolby vision configuration, or {0} for none.