22 #include <dav1d/dav1d.h>
36 #define FF_DAV1D_VERSION_AT_LEAST(x,y) \
37 (DAV1D_API_VERSION_MAJOR > (x) || DAV1D_API_VERSION_MAJOR == (x) && DAV1D_API_VERSION_MINOR >= (y))
103 DAV1D_PICTURE_ALIGNMENT);
109 p->data[0] =
data[0];
110 p->data[1] =
data[1];
111 p->data[2] =
data[2];
112 p->stride[0] = linesize[0];
113 p->stride[1] = linesize[1];
114 p->allocator_data = buf;
130 #if FF_DAV1D_VERSION_AT_LEAST(6,0)
131 int threads =
c->thread_count;
133 int threads = (
c->thread_count ?
c->thread_count :
av_cpu_count()) * 3 / 2;
139 dav1d_default_settings(&
s);
142 s.allocator.cookie = dav1d;
145 s.frame_size_limit =
c->max_pixels;
155 #if FF_DAV1D_VERSION_AT_LEAST(6,0)
159 s.n_threads =
FFMIN(threads, DAV1D_MAX_THREADS);
162 s.n_threads,
s.max_frame_delay);
171 s.n_frame_threads,
s.n_tile_threads);
174 res = dav1d_open(&dav1d->
c, &
s);
185 dav1d_data_unref(&dav1d->
data);
186 dav1d_flush(dav1d->
c);
204 Dav1dPicture pic = { 0 }, *p = &pic;
230 if (!reordered_opaque) {
231 dav1d_data_unref(
data);
235 memcpy(reordered_opaque, &
c->reordered_opaque,
sizeof(
c->reordered_opaque));
236 res = dav1d_data_wrap_user_data(
data, reordered_opaque,
240 dav1d_data_unref(
data);
247 res = dav1d_send_data(dav1d->
c,
data);
252 dav1d_data_unref(
data);
257 res = dav1d_get_picture(dav1d->
c, p);
261 else if (res ==
AVERROR(EAGAIN) &&
c->internal->draining)
272 dav1d_picture_unref(p);
283 c->profile = p->seq_hdr->profile;
284 c->level = ((p->seq_hdr->operating_points[0].major_level - 2) << 2)
285 | p->seq_hdr->operating_points[0].minor_level;
288 if (
c->width != p->p.w ||
c->height != p->p.h) {
301 switch (p->seq_hdr->chr) {
302 case DAV1D_CHR_VERTICAL:
305 case DAV1D_CHR_COLOCATED:
314 if (p->p.layout == DAV1D_PIXEL_LAYOUT_I444 &&
315 p->seq_hdr->mtrx == DAV1D_MC_IDENTITY &&
316 p->seq_hdr->pri == DAV1D_COLOR_PRI_BT709 &&
317 p->seq_hdr->trc == DAV1D_TRC_SRGB)
322 if (p->m.user_data.data)
327 if (p->seq_hdr->num_units_in_tick && p->seq_hdr->time_scale) {
329 p->seq_hdr->num_units_in_tick, p->seq_hdr->time_scale, INT_MAX);
330 if (p->seq_hdr->equal_picture_interval)
331 c->ticks_per_frame = p->seq_hdr->num_ticks_per_picture;
345 frame->
key_frame = p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY;
347 switch (p->frame_hdr->frame_type) {
348 case DAV1D_FRAME_TYPE_KEY:
349 case DAV1D_FRAME_TYPE_INTRA:
352 case DAV1D_FRAME_TYPE_INTER:
355 case DAV1D_FRAME_TYPE_SWITCH:
363 if (p->mastering_display) {
370 for (
int i = 0;
i < 3;
i++) {
383 if (p->content_light) {
389 light->
MaxCLL = p->content_light->max_content_light_level;
390 light->
MaxFALL = p->content_light->max_frame_average_light_level;
394 unsigned int user_identifier;
399 user_identifier = bytestream2_get_be32(&gb);
400 switch (user_identifier) {
401 case MKBETAG(
'G',
'A',
'9',
'4'): {
420 if (p->frame_hdr->film_grain.present && (!dav1d->
apply_grain ||
429 fgp->
seed = p->frame_hdr->film_grain.data.seed;
451 memcpy(&fgp->
codec.
aom.
uv_mult, &p->frame_hdr->film_grain.data.uv_mult,
461 dav1d_picture_unref(p);
472 dav1d_data_unref(&dav1d->
data);
473 dav1d_close(&dav1d->
c);
478 #ifndef DAV1D_MAX_FRAME_THREADS
479 #define DAV1D_MAX_FRAME_THREADS DAV1D_MAX_THREADS
481 #ifndef DAV1D_MAX_TILE_THREADS
482 #define DAV1D_MAX_TILE_THREADS DAV1D_MAX_THREADS
485 #define OFFSET(x) offsetof(Libdav1dContext, x)
486 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
491 {
"oppoint",
"Select an operating point of the scalable bitstream",
OFFSET(operating_point),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 31,
VD },
517 .wrapper_name =
"libdav1d",
static void flush(AVCodecContext *avctx)
static const char *const format[]
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.
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 FF_CODEC_PROPERTY_CLOSED_CAPTIONS
static av_cold int init(AVCodecContext *avctx)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define MKBETAG(a, b, c, d)
static CopyRet receive_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame)
static __device__ float ceil(float a)
static __device__ float floor(float a)
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
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_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.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
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(AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferPool * av_buffer_pool_init(buffer_size_t size, AVBufferRef *(*alloc)(buffer_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.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
const char * av_default_item_name(void *ptr)
Return the context name.
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 AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
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.
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
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]
#define DAV1D_MAX_FRAME_THREADS
static void libdav1d_user_data_free(const uint8_t *data, void *opaque)
AVCodec ff_libdav1d_decoder
static void libdav1d_picture_release(Dav1dPicture *p, void *cookie)
static const AVOption libdav1d_options[]
static const AVClass libdav1d_class
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 enum AVPixelFormat pix_fmt[][3]
#define DAV1D_MAX_TILE_THREADS
static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
#define AV_OPT_FLAG_DEPRECATED
set if option is deprecated, users should refer to AVOption.help text for more information
#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.
A reference to a data buffer.
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
const char * name
Name of the codec implementation.
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 AVFilmGrainParamsType type
Specifies the codec for which this structure is valid.
uint64_t seed
Seed to use for the synthesis process, if the codec allows for it.
union AVFilmGrainParams::@294 codec
Additional fields may be added both here and in any structure included.
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
enum AVChromaLocation chroma_location
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
int key_frame
1 -> keyframe, 0-> not
int64_t pkt_duration
duration of the corresponding packet, expressed in AVStream->time_base units, 0 if unknown.
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
int pkt_size
size of the corresponding packet containing the compressed frame.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
enum AVColorPrimaries color_primaries
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorSpace colorspace
YUV colorspace type.
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVColorTransferCharacteristic color_trc
int64_t reordered_opaque
reordered opaque 64 bits (generally an integer or a double precision float PTS but can be anything).
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t pos
byte position in stream, -1 if unknown