Go to the documentation of this file.
38 if (!
s->mapping || !
s->color)
46 #define COPY(t, a, b, last) memcpy(a, b, offsetof(t, last) + sizeof((b)->last))
93 union { uint32_t u32;
float f32; } fpart;
112 union { uint32_t u32;
float f32; } fpart;
140 #define VALIDATE(VAR, MIN, MAX) \
142 if (VAR < MIN || VAR > MAX) { \
143 av_log(s->logctx, AV_LOG_ERROR, "RPU validation failed: " \
144 #MIN" <= "#VAR" = %d <= "#MAX"\n", (int) VAR); \
145 ff_dovi_ctx_unref(s); \
146 return AVERROR_INVALIDDATA; \
187 for (
int i = 0;
i < 4;
i++)
192 "Unknown Dolby Vision DM v1 level: %u\n", dm->
level);
201 const int denom = 32767;
208 int ext_block_length)
224 if (ext_block_length < 12)
227 if (ext_block_length < 13)
230 if (ext_block_length < 19)
232 for (
int i = 0;
i < 6;
i++)
234 if (ext_block_length < 25)
236 for (
int i = 0;
i < 6;
i++)
241 if (ext_block_length < 17)
253 if (ext_block_length < 21)
278 "Unknown Dolby Vision DM v2 level: %u\n", dm->
level);
285 int compression,
int err_recognition)
287 int num_ext_blocks, ext_block_length, start_pos, parsed_bits,
ret;
293 if (num_ext_blocks && !ext) {
299 while (num_ext_blocks--) {
311 "static extension block level %d\n",
level);
326 memset(dm, 0,
sizeof(*dm));
338 if (parsed_bits > ext_block_length * 8)
340 skip_bits(gb, ext_block_length * 8 - parsed_bits);
354 uint8_t vdr_seq_info_present;
355 uint8_t vdr_dm_metadata_present;
356 uint8_t dm_compression = 0;
357 uint8_t use_prev_vdr_rpu;
360 uint8_t compression =
s->cfg.dv_profile ?
s->cfg.dv_md_compression : 0;
366 if (
s->cfg.dv_profile == 10 ) {
381 const unsigned header_magic = 0x01be6841
u;
382 unsigned emdf_header, emdf_payload_size, emdf_protection;
386 VALIDATE(emdf_header, header_magic, header_magic);
388 VALIDATE(emdf_payload_size, 6, 512);
398 for (
int i = 0;
i < emdf_payload_size;
i++)
401 rpu_size = emdf_payload_size;
404 emdf_protection =
get_bits(gb, 5 + 12);
405 VALIDATE(emdf_protection, 0x400, 0x400);
412 while (rpu_size && rpu[rpu_size - 1] == 0)
416 if (!rpu_size || rpu[rpu_size - 1] != 0x80)
421 -1, rpu, rpu_size - 1));
436 "%"PRIu8
", ignoring\n", rpu_type);
448 if (vdr_seq_info_present) {
470 int ext_mapping_idc = el_bit_depth_minus8 >> 8;
471 el_bit_depth_minus8 = el_bit_depth_minus8 & 0xFF;
472 VALIDATE(bl_bit_depth_minus8, 0, 8);
473 VALIDATE(el_bit_depth_minus8, 0, 8);
475 VALIDATE(vdr_bit_depth_minus8, 0, 8);
498 if (dm_compression > 1) {
503 }
else if (dm_compression && !vdr_dm_metadata_present) {
505 "but no DM metadata present");
520 if (
profile < 8 && compression) {
522 "metadata compression.",
profile);
526 if (use_prev_vdr_rpu && !compression) {
528 "use_prev_vdr_rpu=1\n");
532 if (dm_compression && !compression) {
534 "dm_compression=%d\n", dm_compression);
539 if (use_prev_vdr_rpu) {
542 if (!
s->vdr[prev_vdr_rpu_id])
544 if (!
s->vdr[prev_vdr_rpu_id]) {
553 s->mapping =
s->vdr[prev_vdr_rpu_id];
558 if (!
s->vdr[vdr_rpu_id]) {
560 if (!
s->vdr[vdr_rpu_id]) {
566 s->mapping = mapping =
s->vdr[vdr_rpu_id];
571 for (
int c = 0;
c < 3;
c++) {
588 for (
int i = 0;
i < 2;
i++) {
606 for (
int c = 0;
c < 3;
c++) {
612 switch (mapping_idc) {
617 if (poly_order_minus1 == 0) {
619 if (linear_interp_flag) {
622 "linear interpolation");
632 int mmr_order_minus1 =
get_bits(gb, 2);
636 for (
int j = 0; j < curve->
mmr_order[
i]; j++) {
637 for (
int k = 0; k < 7; k++)
647 for (
int c = 0;
c < 3;
c++) {
661 if (vdr_dm_metadata_present) {
667 if (affected_dm_id != current_dm_id) {
672 "mismatch? %u != %u\n", affected_dm_id, current_dm_id);
686 color->dm_metadata_id = affected_dm_id;
688 if (!dm_compression) {
689 for (
int i = 0;
i < 9;
i++)
691 for (
int i = 0;
i < 3;
i++) {
692 int denom =
profile == 4 ? (1 << 30) : (1 << 28);
701 for (
int i = 0;
i < 9;
i++)
#define AV_LOG_WARNING
Something somehow does not look correct.
enum AVDOVINLQMethod nlq_method_idc
uint16_t trim_chroma_weight
#define AV_EF_EXPLODE
abort decoding on minor error detection
uint8_t saturation_vector_field[6]
#define AV_EF_CAREFUL
consider things that violate the spec, are fast to calculate and have not been seen in the wild as er...
static int get_bits_left(GetBitContext *gb)
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.
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
AVWhitepointCoefficients wp
#define u(width, name, range_min, range_max)
static int get_se_golomb_long(GetBitContext *gb)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
AVColorPrimariesDesc source_display_primaries
uint16_t trim_saturation_gain
static int get_bits_count(const GetBitContext *s)
uint8_t frame_rate_conversion
This structure describes decoded (raw) audio or video data.
const AVDOVIColorMetadata ff_dovi_color_default
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
int64_t mmr_coef[AV_DOVI_MAX_PIECES][3][7]
int ff_dovi_get_metadata(DOVIContext *s, AVDOVIMetadata **out_metadata)
Get the decoded AVDOVIMetadata.
uint8_t target_primary_index
enum AVDOVIMappingMethod mapping_idc[AV_DOVI_MAX_PIECES]
uint8_t target_display_index
static int parse_ext_blocks(DOVIContext *s, GetBitContext *gb, int ver, int compression, int err_recognition)
uint8_t mapping_color_space
static int parse_ext_v2(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm, int ext_block_length)
uint8_t hue_vector_field[6]
static void skip_bits(GetBitContext *s, int n)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
uint8_t reference_mode_flag
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
Dolby Vision metadata extension block.
int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, int err_recognition)
Parse the contents of a Dolby Vision RPU and update the parsed values in the DOVIContext struct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
uint8_t mmr_order[AV_DOVI_MAX_PIECES]
AVDOVIDmData dm_static[7]
static extension blocks
static int get_sbits(GetBitContext *s, int n)
uint8_t poly_order[AV_DOVI_MAX_PIECES]
uint64_t linear_deadzone_threshold
uint16_t target_mid_contrast
static int64_t get_se_coef(GetBitContext *gb, const AVDOVIRpuDataHeader *hdr)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
static unsigned int get_bits1(GetBitContext *s)
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.
int64_t mmr_constant[AV_DOVI_MAX_PIECES]
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
uint8_t source_primary_index
Struct containing chromaticity x and y values for the standard CIE 1931 chromaticity definition.
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
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
uint8_t target_display_index
AVColorPrimariesDesc target_display_primaries
uint16_t trim_saturation_gain
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static AVRational av_make_q(int num, int den)
Create an AVRational.
uint16_t trim_chroma_weight
AVDOVIDmData dm_dynamic[25]
dynamic extension blocks
int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
Attach the decoded AVDOVIMetadata as side data to an AVFrame.
int64_t poly_coef[AV_DOVI_MAX_PIECES][3]
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
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
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
#define i(width, name, range_min, range_max)
uint32_t num_y_partitions
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
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 default value
static AVCIExy get_cie_xy(GetBitContext *gb)
Coefficients of the non-linear inverse quantization.
AVDOVIReshapingCurve curves[3]
uint64_t linear_deadzone_slope
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
uint8_t mpeg_noise_reduction
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static const uint8_t * align_get_bits(GetBitContext *s)
static int parse_ext_v1(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm)
#define COPY(t, a, b, last)
static uint64_t get_ue_coef(GetBitContext *gb, const AVDOVIRpuDataHeader *hdr)
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
uint8_t mapping_chroma_format_idc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
static int ff_dovi_rpu_extension_is_static(int level)
#define VALIDATE(VAR, MIN, MAX)
static unsigned get_variable_bits(GetBitContext *gb, int n)
A reference to a data buffer.
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
#define avpriv_request_sample(...)
Structure to hold side data for an AVFrame.
uint16_t pivots[AV_DOVI_MAX_PIECES+1]
AVPrimaryCoefficients prim
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Dolby Vision RPU data mapping parameters.
uint32_t num_x_partitions
int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr)
Internal helper function to guess the correct DV profile for HEVC.