22 #include <dav1d/dav1d.h> 69 int ret, linesize[4],
h =
FFALIGN(p->p.h, 128);
74 h, DAV1D_PICTURE_ALIGNMENT);
103 p->data[0] = data[0];
104 p->data[1] = data[1];
105 p->data[2] = data[2];
106 p->stride[0] = linesize[0];
107 p->stride[1] = linesize[1];
108 p->allocator_data = buf;
129 dav1d_default_settings(&s);
132 s.allocator.cookie = dav1d;
145 :
FFMIN(floor(sqrt(threads)), DAV1D_MAX_TILE_THREADS);
148 :
FFMIN(ceil(threads / s.n_tile_threads), DAV1D_MAX_FRAME_THREADS);
150 s.n_frame_threads, s.n_tile_threads);
152 res = dav1d_open(&dav1d->
c, &s);
163 dav1d_data_unref(&dav1d->
data);
164 dav1d_flush(dav1d->
c);
182 Dav1dPicture pic = { 0 }, *p = &pic;
199 data->m.timestamp = pkt.
pts;
200 data->m.offset = pkt.
pos;
208 if (!reordered_opaque) {
209 dav1d_data_unref(data);
214 res = dav1d_data_wrap_user_data(data, reordered_opaque,
218 dav1d_data_unref(data);
225 res = dav1d_send_data(dav1d->
c, data);
230 dav1d_data_unref(data);
235 res = dav1d_get_picture(dav1d->
c, p);
249 if (!frame->
buf[0]) {
250 dav1d_picture_unref(p);
254 frame->
data[0] = p->data[0];
255 frame->
data[1] = p->data[1];
256 frame->
data[2] = p->data[2];
261 c->
profile = p->seq_hdr->profile;
262 c->
level = ((p->seq_hdr->operating_points[0].major_level - 2) << 2)
263 | p->seq_hdr->operating_points[0].minor_level;
264 frame->
width = p->p.w;
274 frame->
height * (int64_t)p->frame_hdr->render_width,
275 frame->
width * (int64_t)p->frame_hdr->render_height,
278 switch (p->seq_hdr->chr) {
279 case DAV1D_CHR_VERTICAL:
282 case DAV1D_CHR_COLOCATED:
291 if (p->p.layout == DAV1D_PIXEL_LAYOUT_I444 &&
292 p->seq_hdr->mtrx == DAV1D_MC_IDENTITY &&
293 p->seq_hdr->pri == DAV1D_COLOR_PRI_BT709 &&
294 p->seq_hdr->trc == DAV1D_TRC_SRGB)
299 if (p->m.user_data.data)
304 if (p->seq_hdr->num_units_in_tick && p->seq_hdr->time_scale) {
306 p->seq_hdr->num_units_in_tick, p->seq_hdr->time_scale, INT_MAX);
307 if (p->seq_hdr->equal_picture_interval)
315 frame->
pkt_pts = p->m.timestamp;
318 frame->
pkt_dts = p->m.timestamp;
322 frame->
key_frame = p->frame_hdr->frame_type == DAV1D_FRAME_TYPE_KEY;
324 switch (p->frame_hdr->frame_type) {
325 case DAV1D_FRAME_TYPE_KEY:
326 case DAV1D_FRAME_TYPE_INTRA:
329 case DAV1D_FRAME_TYPE_INTER:
332 case DAV1D_FRAME_TYPE_SWITCH:
340 if (p->mastering_display) {
347 for (
int i = 0;
i < 3;
i++) {
360 if (p->content_light) {
366 light->
MaxCLL = p->content_light->max_content_light_level;
367 light->
MaxFALL = p->content_light->max_frame_average_light_level;
372 dav1d_picture_unref(p);
383 dav1d_data_unref(&dav1d->
data);
384 dav1d_close(&dav1d->
c);
389 #define OFFSET(x) offsetof(Libdav1dContext, x) 390 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM 419 .priv_class = &libdav1d_class,
420 .wrapper_name =
"libdav1d",
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static const char * format[]
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
This structure describes decoded (raw) audio or video data.
unsigned MaxCLL
Max content light level (cd/m^2).
static void flush(AVCodecContext *avctx)
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define LIBAVUTIL_VERSION_INT
int64_t pos
byte position in stream, -1 if unknown
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.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static av_cold int init(AVCodecContext *avctx)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
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...
#define AV_PIX_FMT_GBRP10
const char * av_default_item_name(void *ptr)
Return the context name.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define AV_PIX_FMT_YUV420P12
static CopyRet receive_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame)
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
AVColorTransferCharacteristic
Color Transfer Characteristic.
#define AV_PIX_FMT_GRAY10
static void libdav1d_picture_release(Dav1dPicture *p, void *cookie)
#define AV_PIX_FMT_GRAY12
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#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_assert0(cond)
assert() equivalent, that is always enabled.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
AVColorSpace
YUV colorspace type.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static enum AVPixelFormat pix_fmt_rgb[3]
static void libdav1d_flush(AVCodecContext *c)
#define AVERROR_EOF
End of file.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define AV_PIX_FMT_YUV422P12
AVColorPrimaries
Chromaticity coordinates of the source primaries.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
enum AVColorRange color_range
MPEG vs JPEG YUV range.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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...
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
enum AVColorSpace colorspace
YUV colorspace type.
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
#define AV_PIX_FMT_YUV444P10
int64_t max_pixels
The number of pixels per image to maximally accept.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
static av_cold int libdav1d_init(AVCodecContext *c)
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
static void libdav1d_user_data_free(const uint8_t *data, void *opaque)
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
int64_t reordered_opaque
opaque 64-bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
static const AVOption libdav1d_options[]
int draining
checks API usage: after codec draining, flush is required to resume operation
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
the normal 2^n-1 "JPEG" YUV ranges
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
#define AV_LOG_INFO
Standard information.
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Libavcodec external API header.
int64_t pkt_duration
duration of the corresponding packet, expressed in AVStream->time_base units, 0 if unknown...
static void libdav1d_data_free(const uint8_t *data, void *opaque)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static AVRational av_make_q(int num, int den)
Create an AVRational.
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * data
The data buffer.
static enum AVPixelFormat pix_fmt[][3]
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
#define AV_PIX_FMT_YUV420P10
int64_t reordered_opaque
reordered opaque 64 bits (generally an integer or a double precision float PTS but can be anything)...
Describe the class of an AVClass context structure.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
static const AVClass libdav1d_class
enum AVChromaLocation chroma_location
int64_t best_effort_timestamp
frame timestamp estimated using various heuristics, in stream time base
#define AV_PIX_FMT_GBRP12
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
#define AV_PIX_FMT_YUV422P10
#define FF_CODEC_CAP_SETS_PKT_DTS
Decoders marked with FF_CODEC_CAP_SETS_PKT_DTS want to set AVFrame.pkt_dts manually.
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
the normal 219*2^(n-8) "MPEG" YUV ranges
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
static void libdav1d_log_callback(void *opaque, const char *fmt, va_list vl)
A reference to a data buffer.
static int libdav1d_picture_allocator(Dav1dPicture *p, void *cookie)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
static av_cold int libdav1d_close(AVCodecContext *c)
#define FF_ENABLE_DEPRECATION_WARNINGS
struct AVCodecInternal * internal
Private context used for internal data.
int key_frame
1 -> keyframe, 0-> not
enum AVColorPrimaries color_primaries
enum AVColorTransferCharacteristic color_trc
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
AVCodec ff_libdav1d_decoder
int pkt_size
size of the corresponding packet containing the compressed frame.
AVPixelFormat
Pixel format.
unsigned MaxFALL
Max average light level per frame (cd/m^2).
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)