Go to the documentation of this file.
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))
84 uint8_t *aligned_ptr, *
data[4];
109 aligned_ptr = (uint8_t *)
FFALIGN((uintptr_t)buf->
data, DAV1D_PICTURE_ALIGNMENT);
111 DAV1D_PICTURE_ALIGNMENT);
117 p->data[0] =
data[0];
118 p->data[1] =
data[1];
119 p->data[2] =
data[2];
120 p->stride[0] = linesize[0];
121 p->stride[1] = linesize[1];
122 p->allocator_data = buf;
136 c->profile = seq->profile;
137 c->level = ((seq->operating_points[0].major_level - 2) << 2)
138 | seq->operating_points[0].minor_level;
141 case DAV1D_CHR_VERTICAL:
144 case DAV1D_CHR_COLOCATED:
153 if (seq->layout == DAV1D_PIXEL_LAYOUT_I444 &&
154 seq->mtrx == DAV1D_MC_IDENTITY &&
155 seq->pri == DAV1D_COLOR_PRI_BT709 &&
156 seq->trc == DAV1D_TRC_SRGB)
159 c->pix_fmt =
pix_fmt[seq->layout][seq->hbd];
162 (
unsigned)seq->num_units_in_tick,
163 (
unsigned)seq->time_scale);
165 if (seq->film_grain_present)
173 Dav1dSequenceHeader seq;
177 if (!
c->extradata ||
c->extradata_size <= 0)
180 if (
c->extradata[0] & 0x80) {
181 int version =
c->extradata[0] & 0x7F;
183 if (
version != 1 ||
c->extradata_size < 4) {
186 "Error decoding extradata\n");
191 if (
c->extradata_size == 4)
197 res = dav1d_parse_sequence_header(&seq,
c->extradata +
offset,
214 #if FF_DAV1D_VERSION_AT_LEAST(6,0)
215 int threads =
c->thread_count;
217 int threads = (
c->thread_count ?
c->thread_count :
av_cpu_count()) * 3 / 2;
224 dav1d_default_settings(&
s);
227 s.allocator.cookie = dav1d;
230 s.frame_size_limit =
c->max_pixels;
239 #if FF_DAV1D_VERSION_AT_LEAST(6,2)
240 s.strict_std_compliance =
c->strict_std_compliance > 0;
243 #if FF_DAV1D_VERSION_AT_LEAST(6,0)
247 s.n_threads =
FFMIN(threads, DAV1D_MAX_THREADS);
252 s.n_threads,
s.max_frame_delay);
263 s.n_frame_threads,
s.n_tile_threads);
266 #if FF_DAV1D_VERSION_AT_LEAST(6,8)
268 s.decode_frame_type = DAV1D_DECODEFRAMETYPE_KEY;
270 s.decode_frame_type = DAV1D_DECODEFRAMETYPE_INTRA;
272 s.decode_frame_type = DAV1D_DECODEFRAMETYPE_REFERENCE;
279 res = dav1d_open(&dav1d->
c, &
s);
283 #if FF_DAV1D_VERSION_AT_LEAST(6,7)
284 res = dav1d_get_frame_delay(&
s);
289 c->delay = res > 1 ? res : 0;
295 if (sd && sd->
size > 0)
304 dav1d_data_unref(&dav1d->
data);
305 dav1d_flush(dav1d->
c);
348 res = dav1d_data_wrap_user_data(
data, (
const uint8_t *)
pkt,
352 dav1d_data_unref(
data);
363 res = dav1d_send_data(dav1d->
c,
data);
368 dav1d_data_unref(
data);
373 res = dav1d_get_picture(dav1d->
c, p);
377 else if (res ==
AVERROR(EAGAIN))
387 Dav1dPicture pic = { 0 }, *p = &pic;
389 #if FF_DAV1D_VERSION_AT_LEAST(5,1)
390 enum Dav1dEventFlags event_flags = 0;
406 dav1d_picture_unref(p);
417 #if FF_DAV1D_VERSION_AT_LEAST(5,1)
418 dav1d_get_event_flags(dav1d->
c, &event_flags);
420 event_flags & DAV1D_EVENT_FLAG_NEW_SEQUENCE)
429 if (
c->width != p->p.w ||
c->height != p->p.h) {
450 if (p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY)
455 switch (p->frame_hdr->frame_type) {
456 case DAV1D_FRAME_TYPE_KEY:
457 case DAV1D_FRAME_TYPE_INTRA:
460 case DAV1D_FRAME_TYPE_INTER:
463 case DAV1D_FRAME_TYPE_SWITCH:
471 if (p->mastering_display) {
479 for (
int i = 0;
i < 3;
i++) {
493 if (p->content_light) {
501 light->
MaxCLL = p->content_light->max_content_light_level;
502 light->
MaxFALL = p->content_light->max_frame_average_light_level;
506 #if FF_DAV1D_VERSION_AT_LEAST(6,9)
507 for (
size_t i = 0;
i < p->n_itut_t35;
i++) {
508 const Dav1dITUTT35 *itut_t35 = &p->itut_t35[
i];
510 const Dav1dITUTT35 *itut_t35 = p->itut_t35;
517 provider_code = bytestream2_get_be16(&gb);
518 switch (provider_code) {
520 uint32_t user_identifier = bytestream2_get_be32(&gb);
521 switch (user_identifier) {
522 case MKBETAG(
'G',
'A',
'9',
'4'): {
545 int provider_oriented_code = bytestream2_get_be16(&gb);
546 int application_identifier = bytestream2_get_byte(&gb);
549 provider_oriented_code != 1 || application_identifier != 4)
565 int provider_oriented_code = bytestream2_get_be32(&gb);
567 provider_oriented_code != 0x800)
584 #if FF_DAV1D_VERSION_AT_LEAST(6,9)
588 if (p->frame_hdr->film_grain.present && (!dav1d->
apply_grain ||
599 fgp->
seed = p->frame_hdr->film_grain.data.seed;
629 memcpy(&fgp->
codec.
aom.
uv_mult, &p->frame_hdr->film_grain.data.uv_mult,
639 dav1d_picture_unref(p);
651 dav1d_data_unref(&dav1d->
data);
652 dav1d_close(&dav1d->
c);
657 #ifndef DAV1D_MAX_FRAME_THREADS
658 #define DAV1D_MAX_FRAME_THREADS DAV1D_MAX_THREADS
660 #ifndef DAV1D_MAX_TILE_THREADS
661 #define DAV1D_MAX_TILE_THREADS DAV1D_MAX_THREADS
663 #ifndef DAV1D_MAX_FRAME_DELAY
664 #define DAV1D_MAX_FRAME_DELAY DAV1D_MAX_FRAME_THREADS
667 #define OFFSET(x) offsetof(Libdav1dContext, x)
668 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
674 {
"oppoint",
"Select an operating point of the scalable bitstream",
OFFSET(operating_point),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 31,
VD },
687 .
p.
name =
"libdav1d",
700 .p.wrapper_name =
"libdav1d",
const AVPacketSideData * ff_get_coded_side_data(const AVCodecContext *avctx, enum AVPacketSideDataType type)
Get side data of the given type from a decoding context.
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.
enum AVColorTransferCharacteristic color_trc
AVBufferPool * av_buffer_pool_init(size_t size, AVBufferRef *(*alloc)(size_t size))
Allocate and initialize a buffer pool.
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
#define AV_LOG_WARNING
Something somehow does not look correct.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
AVPixelFormat
Pixel format.
#define AV_EF_EXPLODE
abort decoding on minor error detection
static int libdav1d_picture_allocator(Dav1dPicture *p, void *cookie)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef **buf, AVFrameSideData **psd)
Similar to ff_frame_new_side_data, but using an existing buffer ref.
AVColorTransferCharacteristic
Color Transfer Characteristic.
static const AVClass libdav1d_class
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
uint8_t uv_points[2][10][2]
enum AVColorPrimaries color_primaries
unsigned MaxCLL
Max content light level (cd/m^2).
enum AVColorSpace colorspace
YUV colorspace type.
This structure describes decoded (raw) audio or video data.
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUV420P10
enum AVColorSpace color_space
#define AV_LOG_VERBOSE
Detailed information.
static void libdav1d_user_data_free(const uint8_t *data, void *opaque)
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
enum AVColorTransferCharacteristic color_trc
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
AVCodec p
The public AVCodec.
int grain_scale_shift
Signals the down shift applied to the generated gaussian numbers during synthesis.
#define AV_PIX_FMT_GBRP10
static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *seq)
static av_cold int libdav1d_init(AVCodecContext *c)
#define AV_CODEC_FLAG_LOW_DELAY
Force low delay.
int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt)
Set various frame properties from the provided packet.
int limit_output_range
Signals to clip to limited color levels after film grain application.
int num_y_points
Number of points, and the scale and value for each point of the piecewise linear scaling function for...
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define ITU_T_T35_PROVIDER_CODE_ATSC
#define AV_PIX_FMT_YUV444P10
#define DAV1D_MAX_FRAME_THREADS
static __device__ float ceil(float a)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int width
Intended display resolution.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
static __device__ float floor(float a)
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
AVFilmGrainParams * av_film_grain_params_create_side_data(AVFrame *frame)
Allocate a complete AVFilmGrainParams and add it to the frame.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int libdav1d_receive_frame_internal(AVCodecContext *c, Dav1dPicture *p)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define CODEC_LONG_NAME(str)
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...
#define FF_CODEC_PROPERTY_FILM_GRAIN
#define AV_PIX_FMT_GRAY10
int ff_parse_a53_cc(AVBufferRef **pbuf, const uint8_t *data, int size)
Parse a data array for ATSC A53 Part 4 Closed Captions and store them in an AVBufferRef.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
const char * av_default_item_name(void *ptr)
Return the context name.
@ AV_PICTURE_TYPE_I
Intra.
void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord *cfg)
Read the contents of an AVDOVIDecoderConfigurationRecord (usually provided by stream side data) and u...
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
static void libdav1d_picture_release(Dav1dPicture *p, void *cookie)
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
void(* flush)(AVBSFContext *ctx)
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
#define AV_PIX_FMT_YUV422P10
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
int subsampling_x
Intended subsampling ratio, or 0 for luma-only streams.
@ AV_PICTURE_TYPE_SP
Switching Predicted.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
int num_uv_points[2]
If chroma_scaling_from_luma is set to 0, signals the chroma scaling function parameters.
#define DAV1D_MAX_FRAME_DELAY
#define ITU_T_T35_PROVIDER_CODE_DOLBY
@ AVDISCARD_NONKEY
discard all frames except keyframes
enum AVPictureType pict_type
Picture type of the frame.
int(* init)(AVBSFContext *ctx)
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.
static void libdav1d_log_callback(void *opaque, const char *fmt, va_list vl)
static enum AVPixelFormat pix_fmt_rgb[3]
static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
#define FF_CODEC_CAP_SETS_FRAME_PROPS
Codec handles output frame properties internally instead of letting the internal logic derive them fr...
#define AV_PIX_FMT_YUV422P12
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define MKBETAG(a, b, c, d)
#define AV_PIX_FMT_YUV444P12
This structure describes how to handle film grain synthesis in video for specific codecs.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick, int64_t time_scale)
union AVFilmGrainParams::@357 codec
Additional fields may be added both here and in any structure included.
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.
#define AVERROR_EXTERNAL
Generic error in an external library.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int8_t ar_coeffs_y[24]
Luma auto-regression coefficients.
#define AV_OPT_FLAG_DEPRECATED
Set if option is deprecated, users should refer to AVOption.help text for more information.
const FFCodec ff_libdav1d_decoder
enum AVColorPrimaries color_primaries
@ AVDISCARD_NONINTRA
discard all non intra frames
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_PIX_FMT_GBRP12
AVColorSpace
YUV colorspace type.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int scaling_shift
Specifies the shift applied to the chroma components.
const char * name
Name of the codec implementation.
const uint8_t * buffer_end
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
This struct represents dynamic metadata for color volume transform - application 4 of SMPTE 2094-40:2...
int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size)
Parse the contents of a Dovi RPU NAL and update the parsed values in the DOVIContext struct.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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...
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
#define AV_PIX_FMT_YUV420P12
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
main external API structure.
int ar_coeff_lag
Specifies the auto-regression lag.
#define FF_CODEC_RECEIVE_FRAME_CB(func)
int uv_offset[2]
Offset used for component scaling function.
static enum AVPixelFormat pix_fmt[][3]
int uv_mult[2]
Specifies the luma/chroma multipliers for the index to the component scaling function.
#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 FF_CODEC_PROPERTY_CLOSED_CAPTIONS
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
enum AVColorRange color_range
Intended video signal characteristics.
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
int overlap_flag
Signals whether to overlap film grain blocks.
static const AVOption libdav1d_options[]
@ AV_PICTURE_TYPE_P
Predicted.
static void libdav1d_flush(AVCodecContext *c)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
A reference to a data buffer.
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
#define ITU_T_T35_COUNTRY_CODE_US
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static void libdav1d_data_free(const uint8_t *data, void *opaque)
#define ITU_T_T35_PROVIDER_CODE_SMTPE
unsigned MaxFALL
Max average light level per frame (cd/m^2).
This structure stores compressed data.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_PIX_FMT_GRAY12
int chroma_scaling_from_luma
Signals whether to derive the chroma scaling function from the luma.
@ AVDISCARD_NONREF
discard all non reference
@ AV_FILM_GRAIN_PARAMS_AV1
The union is valid when interpreted as AVFilmGrainAOMParams (codec.aom)
enum AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
#define DAV1D_MAX_TILE_THREADS
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
Attach the decoded AVDOVIMetadata as side data to an AVFrame.
#define AV_CODEC_EXPORT_DATA_FILM_GRAIN
Decoding only.
static av_cold int libdav1d_parse_extradata(AVCodecContext *c)
int ar_coeff_shift
Specifies the range of the auto-regressive coefficients.
static av_cold int libdav1d_close(AVCodecContext *c)
int8_t ar_coeffs_uv[2][25]
Chroma auto-regression coefficients.