FFmpeg
dovi_rpudec.c
Go to the documentation of this file.
1 /*
2  * Dolby Vision RPU decoder
3  *
4  * Copyright (C) 2021 Jan Ekström
5  * Copyright (C) 2021-2024 Niklas Haas
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "libavutil/mem.h"
25 #include "libavutil/crc.h"
26 
27 #include "avcodec.h"
28 #include "dovi_rpu.h"
29 #include "golomb.h"
30 #include "get_bits.h"
31 #include "refstruct.h"
32 
34 {
35  AVFrameSideData *sd;
36  AVBufferRef *buf;
37  AVDOVIMetadata *dovi;
38  size_t dovi_size, ext_sz;
39 
40  if (!s->mapping || !s->color)
41  return 0; /* incomplete dovi metadata */
42 
43  dovi = av_dovi_metadata_alloc(&dovi_size);
44  if (!dovi)
45  return AVERROR(ENOMEM);
46 
47  buf = av_buffer_create((uint8_t *) dovi, dovi_size, NULL, NULL, 0);
48  if (!buf) {
49  av_free(dovi);
50  return AVERROR(ENOMEM);
51  }
52 
54  if (!sd) {
55  av_buffer_unref(&buf);
56  return AVERROR(ENOMEM);
57  }
58 
59  /* Copy only the parts of these structs known to us at compiler-time. */
60 #define COPY(t, a, b, last) memcpy(a, b, offsetof(t, last) + sizeof((b)->last))
61  COPY(AVDOVIRpuDataHeader, av_dovi_get_header(dovi), &s->header, ext_mapping_idc_5_7);
62  COPY(AVDOVIDataMapping, av_dovi_get_mapping(dovi), s->mapping, nlq_pivots);
63  COPY(AVDOVIColorMetadata, av_dovi_get_color(dovi), s->color, source_diagonal);
64  ext_sz = FFMIN(sizeof(AVDOVIDmData), dovi->ext_block_size);
65  for (int i = 0; i < s->num_ext_blocks; i++)
66  memcpy(av_dovi_get_ext(dovi, i), &s->ext_blocks[i], ext_sz);
67  dovi->num_ext_blocks = s->num_ext_blocks;
68  return 0;
69 }
70 
71 static inline uint64_t get_ue_coef(GetBitContext *gb, const AVDOVIRpuDataHeader *hdr)
72 {
73  uint64_t ipart;
74  union { uint32_t u32; float f32; } fpart;
75 
76  switch (hdr->coef_data_type) {
77  case RPU_COEFF_FIXED:
78  ipart = get_ue_golomb_long(gb);
79  fpart.u32 = get_bits_long(gb, hdr->coef_log2_denom);
80  return (ipart << hdr->coef_log2_denom) | fpart.u32;
81 
82  case RPU_COEFF_FLOAT:
83  fpart.u32 = get_bits_long(gb, 32);
84  return fpart.f32 * (1LL << hdr->coef_log2_denom);
85  }
86 
87  return 0; /* unreachable */
88 }
89 
90 static inline int64_t get_se_coef(GetBitContext *gb, const AVDOVIRpuDataHeader *hdr)
91 {
92  int64_t ipart;
93  union { uint32_t u32; float f32; } fpart;
94 
95  switch (hdr->coef_data_type) {
96  case RPU_COEFF_FIXED:
97  ipart = get_se_golomb_long(gb);
98  fpart.u32 = get_bits_long(gb, hdr->coef_log2_denom);
99  return ipart * (1LL << hdr->coef_log2_denom) | fpart.u32;
100 
101  case RPU_COEFF_FLOAT:
102  fpart.u32 = get_bits_long(gb, 32);
103  return fpart.f32 * (1LL << hdr->coef_log2_denom);
104  }
105 
106  return 0; /* unreachable */
107 }
108 
109 static inline unsigned get_variable_bits(GetBitContext *gb, int n)
110 {
111  unsigned int value = get_bits(gb, n);
112  int read_more = get_bits1(gb);
113  while (read_more) {
114  value = (value + 1) << n;
115  value |= get_bits(gb, n);
116  read_more = get_bits1(gb);
117  }
118  return value;
119 }
120 
121 #define VALIDATE(VAR, MIN, MAX) \
122  do { \
123  if (VAR < MIN || VAR > MAX) { \
124  av_log(s->logctx, AV_LOG_ERROR, "RPU validation failed: " \
125  #MIN" <= "#VAR" = %d <= "#MAX"\n", (int) VAR); \
126  ff_dovi_ctx_unref(s); \
127  return AVERROR_INVALIDDATA; \
128  } \
129  } while (0)
130 
132 {
133  switch (dm->level) {
134  case 1:
135  dm->l1.min_pq = get_bits(gb, 12);
136  dm->l1.max_pq = get_bits(gb, 12);
137  dm->l1.avg_pq = get_bits(gb, 12);
138  break;
139  case 2:
140  dm->l2.target_max_pq = get_bits(gb, 12);
141  dm->l2.trim_slope = get_bits(gb, 12);
142  dm->l2.trim_offset = get_bits(gb, 12);
143  dm->l2.trim_power = get_bits(gb, 12);
144  dm->l2.trim_chroma_weight = get_bits(gb, 12);
145  dm->l2.trim_saturation_gain = get_bits(gb, 12);
146  dm->l2.ms_weight = get_sbits(gb, 13);
147  VALIDATE(dm->l2.ms_weight, -1, 4095);
148  break;
149  case 4:
150  dm->l4.anchor_pq = get_bits(gb, 12);
151  dm->l4.anchor_power = get_bits(gb, 12);
152  break;
153  case 5:
154  dm->l5.left_offset = get_bits(gb, 13);
155  dm->l5.right_offset = get_bits(gb, 13);
156  dm->l5.top_offset = get_bits(gb, 13);
157  dm->l5.bottom_offset = get_bits(gb, 13);
158  break;
159  case 6:
160  dm->l6.max_luminance = get_bits(gb, 16);
161  dm->l6.min_luminance = get_bits(gb, 16);
162  dm->l6.max_cll = get_bits(gb, 16);
163  dm->l6.max_fall = get_bits(gb, 16);
164  break;
165  case 255:
166  dm->l255.dm_run_mode = get_bits(gb, 8);
167  dm->l255.dm_run_version = get_bits(gb, 8);
168  for (int i = 0; i < 4; i++)
169  dm->l255.dm_debug[i] = get_bits(gb, 8);
170  break;
171  default:
172  av_log(s->logctx, AV_LOG_WARNING,
173  "Unknown Dolby Vision DM v1 level: %u\n", dm->level);
174  }
175 
176  return 0;
177 }
178 
180 {
181  AVCIExy xy;
182  const int denom = 32767;
183  xy.x = av_make_q(get_sbits(gb, 16), denom);
184  xy.y = av_make_q(get_sbits(gb, 16), denom);
185  return xy;
186 }
187 
189  int ext_block_length)
190 {
191  switch (dm->level) {
192  case 3:
193  dm->l3.min_pq_offset = get_bits(gb, 12);
194  dm->l3.max_pq_offset = get_bits(gb, 12);
195  dm->l3.avg_pq_offset = get_bits(gb, 12);
196  break;
197  case 8:
198  dm->l8.target_display_index = get_bits(gb, 8);
199  dm->l8.trim_slope = get_bits(gb, 12);
200  dm->l8.trim_offset = get_bits(gb, 12);
201  dm->l8.trim_power = get_bits(gb, 12);
202  dm->l8.trim_chroma_weight = get_bits(gb, 12);
203  dm->l8.trim_saturation_gain = get_bits(gb, 12);
204  dm->l8.ms_weight = get_bits(gb, 12);
205  if (ext_block_length < 12)
206  break;
207  dm->l8.target_mid_contrast = get_bits(gb, 12);
208  if (ext_block_length < 13)
209  break;
210  dm->l8.clip_trim = get_bits(gb, 12);
211  if (ext_block_length < 19)
212  break;
213  for (int i = 0; i < 6; i++)
214  dm->l8.saturation_vector_field[i] = get_bits(gb, 8);
215  if (ext_block_length < 25)
216  break;
217  for (int i = 0; i < 6; i++)
218  dm->l8.hue_vector_field[i] = get_bits(gb, 8);
219  break;
220  case 9:
221  dm->l9.source_primary_index = get_bits(gb, 8);
222  if (ext_block_length < 17)
223  break;
228  break;
229  case 10:
230  dm->l10.target_display_index = get_bits(gb, 8);
231  dm->l10.target_max_pq = get_bits(gb, 12);
232  dm->l10.target_min_pq = get_bits(gb, 12);
233  dm->l10.target_primary_index = get_bits(gb, 8);
234  if (ext_block_length < 21)
235  break;
240  break;
241  case 11:
242  dm->l11.content_type = get_bits(gb, 8);
243  dm->l11.whitepoint = get_bits(gb, 4);
245  skip_bits(gb, 3); /* reserved */
246  dm->l11.sharpness = get_bits(gb, 2);
247  dm->l11.noise_reduction = get_bits(gb, 2);
248  dm->l11.mpeg_noise_reduction = get_bits(gb, 2);
249  dm->l11.frame_rate_conversion = get_bits(gb, 2);
250  dm->l11.brightness = get_bits(gb, 2);
251  dm->l11.color = get_bits(gb, 2);
252  break;
253  case 254:
254  dm->l254.dm_mode = get_bits(gb, 8);
255  dm->l254.dm_version_index = get_bits(gb, 8);
256  break;
257  default:
258  av_log(s->logctx, AV_LOG_WARNING,
259  "Unknown Dolby Vision DM v2 level: %u\n", dm->level);
260  }
261 
262  return 0;
263 }
264 
265 static int parse_ext_blocks(DOVIContext *s, GetBitContext *gb, int ver)
266 {
267  int num_ext_blocks, ext_block_length, start_pos, parsed_bits, ret;
268 
269  num_ext_blocks = get_ue_golomb_31(gb);
270  align_get_bits(gb);
271  if (s->num_ext_blocks + num_ext_blocks > AV_DOVI_MAX_EXT_BLOCKS)
272  return AVERROR_INVALIDDATA;
273 
274  if (!s->ext_blocks) {
275  s->ext_blocks = ff_refstruct_allocz(sizeof(AVDOVIDmData) * AV_DOVI_MAX_EXT_BLOCKS);
276  if (!s->ext_blocks)
277  return AVERROR(ENOMEM);
278  }
279 
280  while (num_ext_blocks--) {
281  AVDOVIDmData *dm = &s->ext_blocks[s->num_ext_blocks++];
282  ext_block_length = get_ue_golomb_31(gb);
283  dm->level = get_bits(gb, 8);
284  start_pos = get_bits_count(gb);
285 
286  switch (ver) {
287  case 1: ret = parse_ext_v1(s, gb, dm); break;
288  case 2: ret = parse_ext_v2(s, gb, dm, ext_block_length); break;
289  default: return AVERROR_BUG;
290  }
291 
292  if (ret < 0)
293  return ret;
294 
295  parsed_bits = get_bits_count(gb) - start_pos;
296  if (parsed_bits > ext_block_length * 8)
297  return AVERROR_INVALIDDATA;
298  skip_bits(gb, ext_block_length * 8 - parsed_bits);
299  }
300 
301  return 0;
302 }
303 
304 int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
305  int err_recognition)
306 {
307  AVDOVIRpuDataHeader *hdr = &s->header;
308  GetBitContext *gb = &(GetBitContext){0};
309  int ret;
310 
311  uint8_t rpu_type;
312  uint8_t vdr_seq_info_present;
313  uint8_t vdr_dm_metadata_present;
314  uint8_t use_prev_vdr_rpu;
315  uint8_t use_nlq;
316  uint8_t profile;
317 
318  if (rpu_size < 5)
319  return AVERROR_INVALIDDATA;
320 
321  /* Container */
322  if (s->cfg.dv_profile == 10 /* dav1.10 */) {
323  /* DV inside AV1 re-uses an EMDF container skeleton, but with fixed
324  * values - so we can effectively treat this as a magic byte sequence.
325  *
326  * The exact fields are, as follows:
327  * emdf_version : f(2) = 0
328  * key_id : f(3) = 6
329  * emdf_payload_id : f(5) = 31
330  * emdf_payload_id_ext : var(5) = 225
331  * smploffste : f(1) = 0
332  * duratione : f(1) = 0
333  * groupide : f(1) = 0
334  * codecdatae : f(1) = 0
335  * discard_unknown_payload : f(1) = 1
336  */
337  const unsigned header_magic = 0x01be6841u;
338  unsigned emdf_header, emdf_payload_size, emdf_protection;
339  if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
340  return ret;
341  emdf_header = get_bits_long(gb, 27);
342  VALIDATE(emdf_header, header_magic, header_magic);
343  emdf_payload_size = get_variable_bits(gb, 8);
344  VALIDATE(emdf_payload_size, 6, 512);
345  if (emdf_payload_size * 8 > get_bits_left(gb))
346  return AVERROR_INVALIDDATA;
347 
348  /* The payload is not byte-aligned (off by *one* bit, curse Dolby),
349  * so copy into a fresh buffer to preserve byte alignment of the
350  * RPU struct */
351  av_fast_padded_malloc(&s->rpu_buf, &s->rpu_buf_sz, emdf_payload_size);
352  if (!s->rpu_buf)
353  return AVERROR(ENOMEM);
354  for (int i = 0; i < emdf_payload_size; i++)
355  s->rpu_buf[i] = get_bits(gb, 8);
356  rpu = s->rpu_buf;
357  rpu_size = emdf_payload_size;
358 
359  /* Validate EMDF footer */
360  emdf_protection = get_bits(gb, 5 + 12);
361  VALIDATE(emdf_protection, 0x400, 0x400);
362  } else {
363  /* NAL RBSP with prefix and trailing zeroes */
364  VALIDATE(rpu[0], 25, 25); /* NAL prefix */
365  rpu++;
366  rpu_size--;
367  /* Strip trailing padding bytes */
368  while (rpu_size && rpu[rpu_size - 1] == 0)
369  rpu_size--;
370  }
371 
372  if (!rpu_size || rpu[rpu_size - 1] != 0x80)
373  return AVERROR_INVALIDDATA;
374 
375  if (err_recognition & AV_EF_CRCCHECK) {
377  -1, rpu, rpu_size - 1)); /* exclude 0x80 */
378  if (crc) {
379  av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc);
380  if (err_recognition & AV_EF_EXPLODE)
381  return AVERROR_INVALIDDATA;
382  }
383  }
384 
385  if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
386  return ret;
387 
388  /* RPU header */
389  rpu_type = get_bits(gb, 6);
390  if (rpu_type != 2) {
391  av_log(s->logctx, AV_LOG_WARNING, "Unrecognized RPU type "
392  "%"PRIu8", ignoring\n", rpu_type);
393  return 0;
394  }
395 
396  hdr->rpu_type = rpu_type;
397  hdr->rpu_format = get_bits(gb, 11);
398 
399  /* Values specific to RPU type 2 */
400  hdr->vdr_rpu_profile = get_bits(gb, 4);
401  hdr->vdr_rpu_level = get_bits(gb, 4);
402 
403  vdr_seq_info_present = get_bits1(gb);
404  if (vdr_seq_info_present) {
406  hdr->coef_data_type = get_bits(gb, 2);
408  switch (hdr->coef_data_type) {
409  case RPU_COEFF_FIXED:
410  hdr->coef_log2_denom = get_ue_golomb(gb);
411  VALIDATE(hdr->coef_log2_denom, 13, 32);
412  break;
413  case RPU_COEFF_FLOAT:
414  hdr->coef_log2_denom = 32; /* arbitrary, choose maximum precision */
415  break;
416  }
417 
418  hdr->vdr_rpu_normalized_idc = get_bits(gb, 2);
420 
421  if ((hdr->rpu_format & 0x700) == 0) {
422  int bl_bit_depth_minus8 = get_ue_golomb_31(gb);
423  int el_bit_depth_minus8 = get_ue_golomb_31(gb);
424  int vdr_bit_depth_minus8 = get_ue_golomb_31(gb);
425  int reserved_zero_3bits;
426  /* ext_mapping_idc is in the upper 8 bits of el_bit_depth_minus8 */
427  int ext_mapping_idc = el_bit_depth_minus8 >> 8;
428  el_bit_depth_minus8 = el_bit_depth_minus8 & 0xFF;
429  VALIDATE(bl_bit_depth_minus8, 0, 8);
430  VALIDATE(el_bit_depth_minus8, 0, 8);
431  VALIDATE(ext_mapping_idc, 0, 0xFF);
432  VALIDATE(vdr_bit_depth_minus8, 0, 8);
433  hdr->bl_bit_depth = bl_bit_depth_minus8 + 8;
434  hdr->el_bit_depth = el_bit_depth_minus8 + 8;
435  hdr->ext_mapping_idc_0_4 = ext_mapping_idc & 0x1f; /* 5 bits */
436  hdr->ext_mapping_idc_5_7 = ext_mapping_idc >> 5;
437  hdr->vdr_bit_depth = vdr_bit_depth_minus8 + 8;
439  reserved_zero_3bits = get_bits(gb, 3);
440  VALIDATE(reserved_zero_3bits, 0, 0);
442  hdr->disable_residual_flag = get_bits1(gb);
443  }
444  } else {
445  /* lack of documentation/samples */
446  avpriv_request_sample(s->logctx, "Missing RPU VDR sequence info\n");
448  return AVERROR_PATCHWELCOME;
449  }
450 
451  vdr_dm_metadata_present = get_bits1(gb);
452  use_prev_vdr_rpu = get_bits1(gb);
453  use_nlq = (hdr->rpu_format & 0x700) == 0 && !hdr->disable_residual_flag;
454 
455  profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr);
456  if (profile == 5 && use_nlq) {
457  av_log(s->logctx, AV_LOG_ERROR, "Profile 5 RPUs should not use NLQ\n");
459  return AVERROR_INVALIDDATA;
460  }
461 
462  if (use_prev_vdr_rpu) {
463  int prev_vdr_rpu_id = get_ue_golomb_31(gb);
464  VALIDATE(prev_vdr_rpu_id, 0, DOVI_MAX_DM_ID);
465  if (!s->vdr[prev_vdr_rpu_id])
466  prev_vdr_rpu_id = 0;
467  if (!s->vdr[prev_vdr_rpu_id]) {
468  /* FIXME: Technically, the spec says that in this case we should
469  * synthesize "neutral" vdr metadata, but easier to just error
470  * out as this corner case is not hit in practice */
471  av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n",
472  prev_vdr_rpu_id);
474  return AVERROR_INVALIDDATA;
475  }
476  s->mapping = s->vdr[prev_vdr_rpu_id];
477  } else {
478  AVDOVIDataMapping *mapping;
479  int vdr_rpu_id = get_ue_golomb_31(gb);
480  VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID);
481  if (!s->vdr[vdr_rpu_id]) {
482  s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(AVDOVIDataMapping));
483  if (!s->vdr[vdr_rpu_id]) {
485  return AVERROR(ENOMEM);
486  }
487  }
488 
489  s->mapping = mapping = s->vdr[vdr_rpu_id];
490  mapping->vdr_rpu_id = vdr_rpu_id;
491  mapping->mapping_color_space = get_ue_golomb_31(gb);
493 
494  for (int c = 0; c < 3; c++) {
495  AVDOVIReshapingCurve *curve = &mapping->curves[c];
496  int num_pivots_minus_2 = get_ue_golomb_31(gb);
497  int pivot = 0;
498 
499  VALIDATE(num_pivots_minus_2, 0, AV_DOVI_MAX_PIECES - 1);
500  curve->num_pivots = num_pivots_minus_2 + 2;
501  for (int i = 0; i < curve->num_pivots; i++) {
502  pivot += get_bits(gb, hdr->bl_bit_depth);
503  curve->pivots[i] = av_clip_uint16(pivot);
504  }
505  }
506 
507  if (use_nlq) {
508  int nlq_pivot = 0;
509  mapping->nlq_method_idc = get_bits(gb, 3);
510 
511  for (int i = 0; i < 2; i++) {
512  nlq_pivot += get_bits(gb, hdr->bl_bit_depth);
513  mapping->nlq_pivots[i] = av_clip_uint16(nlq_pivot);
514  }
515 
516  /**
517  * The patent mentions another legal value, NLQ_MU_LAW, but it's
518  * not documented anywhere how to parse or apply that type of NLQ.
519  */
521  } else {
522  mapping->nlq_method_idc = AV_DOVI_NLQ_NONE;
523  }
524 
525  mapping->num_x_partitions = get_ue_golomb_long(gb) + 1;
526  mapping->num_y_partitions = get_ue_golomb_long(gb) + 1;
527  /* End of rpu_data_header(), start of vdr_rpu_data_payload() */
528 
529  for (int c = 0; c < 3; c++) {
530  AVDOVIReshapingCurve *curve = &mapping->curves[c];
531  for (int i = 0; i < curve->num_pivots - 1; i++) {
532  int mapping_idc = get_ue_golomb_31(gb);
533  VALIDATE(mapping_idc, 0, 1);
534  curve->mapping_idc[i] = mapping_idc;
535  switch (mapping_idc) {
537  int poly_order_minus1 = get_ue_golomb_31(gb);
538  VALIDATE(poly_order_minus1, 0, 1);
539  curve->poly_order[i] = poly_order_minus1 + 1;
540  if (poly_order_minus1 == 0) {
541  int linear_interp_flag = get_bits1(gb);
542  if (linear_interp_flag) {
543  /* lack of documentation/samples */
544  avpriv_request_sample(s->logctx, "Dolby Vision "
545  "linear interpolation");
547  return AVERROR_PATCHWELCOME;
548  }
549  }
550  for (int k = 0; k <= curve->poly_order[i]; k++)
551  curve->poly_coef[i][k] = get_se_coef(gb, hdr);
552  break;
553  }
554  case AV_DOVI_MAPPING_MMR: {
555  int mmr_order_minus1 = get_bits(gb, 2);
556  VALIDATE(mmr_order_minus1, 0, 2);
557  curve->mmr_order[i] = mmr_order_minus1 + 1;
558  curve->mmr_constant[i] = get_se_coef(gb, hdr);
559  for (int j = 0; j < curve->mmr_order[i]; j++) {
560  for (int k = 0; k < 7; k++)
561  curve->mmr_coef[i][j][k] = get_se_coef(gb, hdr);
562  }
563  break;
564  }
565  }
566  }
567  }
568 
569  if (use_nlq) {
570  for (int c = 0; c < 3; c++) {
571  AVDOVINLQParams *nlq = &mapping->nlq[c];
572  nlq->nlq_offset = get_bits(gb, hdr->el_bit_depth);
573  nlq->vdr_in_max = get_ue_coef(gb, hdr);
574  switch (mapping->nlq_method_idc) {
576  nlq->linear_deadzone_slope = get_ue_coef(gb, hdr);
577  nlq->linear_deadzone_threshold = get_ue_coef(gb, hdr);
578  break;
579  }
580  }
581  }
582  }
583 
584  if (vdr_dm_metadata_present) {
586  int affected_dm_id = get_ue_golomb_31(gb);
587  int current_dm_id = get_ue_golomb_31(gb);
588  VALIDATE(affected_dm_id, 0, DOVI_MAX_DM_ID);
589  VALIDATE(current_dm_id, 0, DOVI_MAX_DM_ID);
590  if (affected_dm_id != current_dm_id) {
591  /* The spec does not explain these fields at all, and there is
592  * a lack of samples to understand how they're supposed to work,
593  * so just assert them being equal for now */
594  avpriv_request_sample(s->logctx, "affected/current_dm_metadata_id "
595  "mismatch? %u != %u\n", affected_dm_id, current_dm_id);
597  return AVERROR_PATCHWELCOME;
598  }
599 
600  if (!s->dm) {
602  if (!s->dm) {
604  return AVERROR(ENOMEM);
605  }
606  }
607 
608  s->color = color = s->dm;
609  color->dm_metadata_id = affected_dm_id;
610  color->scene_refresh_flag = get_ue_golomb_31(gb);
611  for (int i = 0; i < 9; i++)
612  color->ycc_to_rgb_matrix[i] = av_make_q(get_sbits(gb, 16), 1 << 13);
613  for (int i = 0; i < 3; i++) {
614  int denom = profile == 4 ? (1 << 30) : (1 << 28);
615  unsigned offset = get_bits_long(gb, 32);
616  if (offset > INT_MAX) {
617  /* Ensure the result fits inside AVRational */
618  offset >>= 1;
619  denom >>= 1;
620  }
621  color->ycc_to_rgb_offset[i] = av_make_q(offset, denom);
622  }
623  for (int i = 0; i < 9; i++)
624  color->rgb_to_lms_matrix[i] = av_make_q(get_sbits(gb, 16), 1 << 14);
625 
626  color->signal_eotf = get_bits(gb, 16);
627  color->signal_eotf_param0 = get_bits(gb, 16);
628  color->signal_eotf_param1 = get_bits(gb, 16);
629  color->signal_eotf_param2 = get_bits_long(gb, 32);
630  color->signal_bit_depth = get_bits(gb, 5);
631  VALIDATE(color->signal_bit_depth, 8, 16);
632  color->signal_color_space = get_bits(gb, 2);
633  color->signal_chroma_format = get_bits(gb, 2);
634  color->signal_full_range_flag = get_bits(gb, 2);
635  color->source_min_pq = get_bits(gb, 12);
636  color->source_max_pq = get_bits(gb, 12);
637  color->source_diagonal = get_bits(gb, 10);
638 
639  /* Parse extension blocks */
640  s->num_ext_blocks = 0;
641  if ((ret = parse_ext_blocks(s, gb, 1)) < 0) {
643  return ret;
644  }
645 
646  if (get_bits_left(gb) > 48 /* padding + CRC32 + terminator */) {
647  if ((ret = parse_ext_blocks(s, gb, 2)) < 0) {
649  return ret;
650  }
651  }
652  } else {
653  s->color = &ff_dovi_color_default;
654  s->num_ext_blocks = 0;
655  }
656 
657  return 0;
658 }
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVDOVIDataMapping::nlq_method_idc
enum AVDOVINLQMethod nlq_method_idc
Definition: dovi_meta.h:150
AVDOVIDmLevel2::trim_chroma_weight
uint16_t trim_chroma_weight
Definition: dovi_meta.h:207
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
AVDOVIDmLevel8::trim_power
uint16_t trim_power
Definition: dovi_meta.h:244
AVDOVIDmLevel8::saturation_vector_field
uint8_t saturation_vector_field[6]
Definition: dovi_meta.h:250
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:695
AVERROR
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
ff_dovi_ctx_unref
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
Definition: dovi_rpu.c:29
AVDOVIDmLevel8::trim_offset
uint16_t trim_offset
Definition: dovi_meta.h:243
AVColorPrimariesDesc::wp
AVWhitepointCoefficients wp
Definition: csp.h:79
DOVI_MAX_DM_ID
#define DOVI_MAX_DM_ID
Definition: dovi_rpu.h:31
color
Definition: vf_paletteuse.c:512
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:251
get_se_golomb_long
static int get_se_golomb_long(GetBitContext *gb)
Definition: golomb.h:294
AV_DOVI_MAX_EXT_BLOCKS
#define AV_DOVI_MAX_EXT_BLOCKS
Definition: dovi_meta.h:340
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
AV_FRAME_DATA_DOVI_METADATA
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
Definition: frame.h:208
AVDOVIRpuDataHeader::ext_mapping_idc_0_4
uint8_t ext_mapping_idc_0_4
Definition: dovi_meta.h:94
AVDOVIDmLevel9::source_display_primaries
AVColorPrimariesDesc source_display_primaries
Definition: dovi_meta.h:257
parse_ext_blocks
static int parse_ext_blocks(DOVIContext *s, GetBitContext *gb, int ver)
Definition: dovi_rpudec.c:265
AVDOVIDmLevel8::trim_saturation_gain
uint16_t trim_saturation_gain
Definition: dovi_meta.h:246
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
AVDOVIDmLevel5::top_offset
uint16_t top_offset
Definition: dovi_meta.h:227
AVDOVIDmLevel11::frame_rate_conversion
uint8_t frame_rate_conversion
Definition: dovi_meta.h:276
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
av_dovi_get_ext
static av_always_inline AVDOVIDmData * av_dovi_get_ext(const AVDOVIMetadata *data, int index)
Definition: dovi_meta.h:362
ff_dovi_color_default
const AVDOVIColorMetadata ff_dovi_color_default
Definition: dovi_rpu.c:93
get_ue_golomb
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition: golomb.h:53
AVDOVIReshapingCurve::mmr_coef
int64_t mmr_coef[AV_DOVI_MAX_PIECES][3][7]
Definition: dovi_meta.h:118
AVDOVIDmLevel10::target_primary_index
uint8_t target_primary_index
Definition: dovi_meta.h:265
AV_DOVI_NLQ_NONE
@ AV_DOVI_NLQ_NONE
Definition: dovi_meta.h:122
AVDOVIDmLevel8::ms_weight
uint16_t ms_weight
Definition: dovi_meta.h:247
AVDOVIReshapingCurve::mapping_idc
enum AVDOVIMappingMethod mapping_idc[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:111
AVDOVIDmLevel6::min_luminance
uint16_t min_luminance
Definition: dovi_meta.h:234
AVDOVIDmLevel10::target_display_index
uint8_t target_display_index
Definition: dovi_meta.h:262
AVDOVIDmLevel1::max_pq
uint16_t max_pq
Definition: dovi_meta.h:197
AVDOVIDmData::l11
AVDOVIDmLevel11 l11
Definition: dovi_meta.h:312
AVDOVIRpuDataHeader::rpu_format
uint16_t rpu_format
Definition: dovi_meta.h:80
AVDOVIDataMapping::mapping_color_space
uint8_t mapping_color_space
Definition: dovi_meta.h:145
AVDOVIRpuDataHeader
Dolby Vision RPU data header.
Definition: dovi_meta.h:78
parse_ext_v2
static int parse_ext_v2(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm, int ext_block_length)
Definition: dovi_rpudec.c:188
AVDOVIDmLevel8::hue_vector_field
uint8_t hue_vector_field[6]
Definition: dovi_meta.h:251
AVDOVIRpuDataHeader::coef_data_type
uint8_t coef_data_type
Definition: dovi_meta.h:84
crc.h
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
golomb.h
exp golomb vlc stuff
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
AVDOVIDmLevel11::color
uint8_t color
Definition: dovi_meta.h:278
AVDOVIDmLevel11::reference_mode_flag
uint8_t reference_mode_flag
Definition: dovi_meta.h:272
AVDOVIDmLevel11::brightness
uint8_t brightness
Definition: dovi_meta.h:277
DOVIContext
Definition: dovi_rpu.h:32
AVDOVIRpuDataHeader::el_bit_depth
uint8_t el_bit_depth
Definition: dovi_meta.h:89
GetBitContext
Definition: get_bits.h:108
AVDOVIDmLevel2::trim_power
uint16_t trim_power
Definition: dovi_meta.h:206
dovi_rpu.h
AVDOVIDmLevel2::trim_slope
uint16_t trim_slope
Definition: dovi_meta.h:204
AVDOVIDmLevel2::ms_weight
int16_t ms_weight
Definition: dovi_meta.h:209
refstruct.h
AVDOVIRpuDataHeader::vdr_rpu_normalized_idc
uint8_t vdr_rpu_normalized_idc
Definition: dovi_meta.h:86
AVDOVIRpuDataHeader::el_spatial_resampling_filter_flag
uint8_t el_spatial_resampling_filter_flag
Definition: dovi_meta.h:92
AVDOVIDmLevel8::clip_trim
uint16_t clip_trim
Definition: dovi_meta.h:249
AVDOVIDmLevel3::avg_pq_offset
uint16_t avg_pq_offset
Definition: dovi_meta.h:215
RPU_COEFF_FLOAT
@ RPU_COEFF_FLOAT
Definition: dovi_rpu.h:148
AVDOVIDmData
Dolby Vision metadata extension block.
Definition: dovi_meta.h:299
ff_dovi_rpu_parse
int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, int err_recognition)
Parse the contents of a Dovi RPU NAL and update the parsed values in the DOVIContext struct.
Definition: dovi_rpudec.c:304
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVDOVIRpuDataHeader::chroma_resampling_explicit_filter_flag
uint8_t chroma_resampling_explicit_filter_flag
Definition: dovi_meta.h:83
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
AVDOVIDmLevel6::max_cll
uint16_t max_cll
Definition: dovi_meta.h:235
AVDOVIRpuDataHeader::vdr_bit_depth
uint8_t vdr_bit_depth
Definition: dovi_meta.h:90
AVDOVIRpuDataHeader::rpu_type
uint8_t rpu_type
Definition: dovi_meta.h:79
AVDOVIMetadata
Combined struct representing a combination of header, mapping and color metadata, for attaching to fr...
Definition: dovi_meta.h:326
AVDOVIDmLevel8::trim_slope
uint16_t trim_slope
Definition: dovi_meta.h:242
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVDOVIDmLevel4::anchor_power
uint16_t anchor_power
Definition: dovi_meta.h:220
AVDOVIReshapingCurve::mmr_order
uint8_t mmr_order[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:116
AVDOVIDmData::l3
AVDOVIDmLevel3 l3
Definition: dovi_meta.h:304
AVDOVIDmLevel11::noise_reduction
uint8_t noise_reduction
Definition: dovi_meta.h:274
AVDOVIRpuDataHeader::spatial_resampling_filter_flag
uint8_t spatial_resampling_filter_flag
Definition: dovi_meta.h:91
AVDOVIDmLevel10::target_min_pq
uint16_t target_min_pq
Definition: dovi_meta.h:264
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:320
get_bits.h
AV_DOVI_MAPPING_POLYNOMIAL
@ AV_DOVI_MAPPING_POLYNOMIAL
Definition: dovi_meta.h:99
av_dovi_get_header
static av_always_inline AVDOVIRpuDataHeader * av_dovi_get_header(const AVDOVIMetadata *data)
Definition: dovi_meta.h:344
AVDOVIReshapingCurve::poly_order
uint8_t poly_order[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:113
AVDOVINLQParams::linear_deadzone_threshold
uint64_t linear_deadzone_threshold
Definition: dovi_meta.h:135
AVDOVIDmLevel8::target_mid_contrast
uint16_t target_mid_contrast
Definition: dovi_meta.h:248
get_se_coef
static int64_t get_se_coef(GetBitContext *gb, const AVDOVIRpuDataHeader *hdr)
Definition: dovi_rpudec.c:90
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AV_DOVI_MAPPING_MMR
@ AV_DOVI_MAPPING_MMR
Definition: dovi_meta.h:100
AVDOVIDmLevel5::bottom_offset
uint16_t bottom_offset
Definition: dovi_meta.h:228
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
AVDOVIDmData::l9
AVDOVIDmLevel9 l9
Definition: dovi_meta.h:310
ff_refstruct_allocz
static void * ff_refstruct_allocz(size_t size)
Equivalent to ff_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition: refstruct.h:105
av_frame_new_side_data_from_buf
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.
Definition: frame.c:786
AVDOVIDmLevel4::anchor_pq
uint16_t anchor_pq
Definition: dovi_meta.h:219
AVDOVIReshapingCurve::mmr_constant
int64_t mmr_constant[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:117
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
AVDOVIDmLevel9::source_primary_index
uint8_t source_primary_index
Definition: dovi_meta.h:256
AVCIExy
Struct containing chromaticity x and y values for the standard CIE 1931 chromaticity definition.
Definition: csp.h:56
c
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
Definition: undefined.txt:32
av_buffer_create
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.
Definition: buffer.c:55
AVDOVIDmLevel2::target_max_pq
uint16_t target_max_pq
Definition: dovi_meta.h:203
AVDOVIDmLevel6::max_luminance
uint16_t max_luminance
Definition: dovi_meta.h:233
AVCIExy::x
AVRational x
Definition: csp.h:57
AVDOVIDmData::l2
AVDOVIDmLevel2 l2
Definition: dovi_meta.h:303
AVDOVIDataMapping::nlq_pivots
uint16_t nlq_pivots[2]
Definition: dovi_meta.h:154
AVPrimaryCoefficients::b
AVCIExy b
Definition: csp.h:65
AVDOVIDmLevel6::max_fall
uint16_t max_fall
Definition: dovi_meta.h:236
AVPrimaryCoefficients::r
AVCIExy r
Definition: csp.h:65
AVDOVIDmLevel8::target_display_index
uint8_t target_display_index
Definition: dovi_meta.h:241
AVDOVIDmData::l254
AVDOVIDmLevel254 l254
Definition: dovi_meta.h:313
AVDOVIDmLevel10::target_display_primaries
AVColorPrimariesDesc target_display_primaries
Definition: dovi_meta.h:266
AV_DOVI_NLQ_LINEAR_DZ
@ AV_DOVI_NLQ_LINEAR_DZ
Definition: dovi_meta.h:123
AVDOVIRpuDataHeader::vdr_rpu_profile
uint8_t vdr_rpu_profile
Definition: dovi_meta.h:81
av_bswap32
#define av_bswap32
Definition: bswap.h:47
AVDOVIDmLevel2::trim_saturation_gain
uint16_t trim_saturation_gain
Definition: dovi_meta.h:208
color
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
av_make_q
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition: rational.h:71
AVDOVIDmLevel8::trim_chroma_weight
uint16_t trim_chroma_weight
Definition: dovi_meta.h:245
AVDOVIDmLevel255::dm_run_mode
uint8_t dm_run_mode
Definition: dovi_meta.h:289
av_dovi_metadata_alloc
AVDOVIMetadata * av_dovi_metadata_alloc(size_t *size)
Allocate an AVDOVIMetadata structure and initialize its fields to default values.
Definition: dovi_meta.c:47
AVDOVIDmLevel1::min_pq
uint16_t min_pq
Definition: dovi_meta.h:196
ff_dovi_attach_side_data
int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame)
Attach the decoded AVDOVIMetadata as side data to an AVFrame.
Definition: dovi_rpudec.c:33
AVPrimaryCoefficients::g
AVCIExy g
Definition: csp.h:65
AVDOVIDmLevel11::content_type
uint8_t content_type
Definition: dovi_meta.h:270
AVDOVIDmData::l10
AVDOVIDmLevel10 l10
Definition: dovi_meta.h:311
AVDOVIRpuDataHeader::coef_log2_denom
uint8_t coef_log2_denom
Definition: dovi_meta.h:85
AVDOVIRpuDataHeader::bl_video_full_range_flag
uint8_t bl_video_full_range_flag
Definition: dovi_meta.h:87
AVDOVIReshapingCurve::poly_coef
int64_t poly_coef[AV_DOVI_MAX_PIECES][3]
Definition: dovi_meta.h:114
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
offset
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
Definition: writing_filters.txt:86
AVDOVIDmData::l255
AVDOVIDmLevel255 l255
Definition: dovi_meta.h:314
AVDOVIDmData::l8
AVDOVIDmLevel8 l8
Definition: dovi_meta.h:309
AVDOVIDmLevel2::trim_offset
uint16_t trim_offset
Definition: dovi_meta.h:205
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVDOVIDmLevel10::target_max_pq
uint16_t target_max_pq
Definition: dovi_meta.h:263
AVDOVIDataMapping::num_y_partitions
uint32_t num_y_partitions
Definition: dovi_meta.h:152
av_fast_padded_malloc
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...
Definition: utils.c:52
value
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
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
get_cie_xy
static AVCIExy get_cie_xy(GetBitContext *gb)
Definition: dovi_rpudec.c:179
profile
int profile
Definition: mxfenc.c:2228
AVDOVINLQParams
Coefficients of the non-linear inverse quantization.
Definition: dovi_meta.h:130
AV_CRC_32_IEEE
@ AV_CRC_32_IEEE
Definition: crc.h:52
AVDOVIDmData::l4
AVDOVIDmLevel4 l4
Definition: dovi_meta.h:305
AVDOVIDmData::l1
AVDOVIDmLevel1 l1
Definition: dovi_meta.h:302
AVDOVIDataMapping::curves
AVDOVIReshapingCurve curves[3]
Definition: dovi_meta.h:147
avcodec.h
AVDOVINLQParams::linear_deadzone_slope
uint64_t linear_deadzone_slope
Definition: dovi_meta.h:134
AVDOVIReshapingCurve
Definition: dovi_meta.h:108
ret
ret
Definition: filter_design.txt:187
AVDOVIDmLevel11::mpeg_noise_reduction
uint8_t mpeg_noise_reduction
Definition: dovi_meta.h:275
frame
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
Definition: filter_design.txt:264
AVDOVIDmLevel11::sharpness
uint8_t sharpness
Definition: dovi_meta.h:273
AVDOVINLQParams::vdr_in_max
uint64_t vdr_in_max
Definition: dovi_meta.h:132
AVCIExy::y
AVRational y
Definition: csp.h:57
align_get_bits
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:561
parse_ext_v1
static int parse_ext_v1(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm)
Definition: dovi_rpudec.c:131
COPY
#define COPY(t, a, b, last)
AVDOVIDmData::l6
AVDOVIDmLevel6 l6
Definition: dovi_meta.h:307
AVDOVIReshapingCurve::num_pivots
uint8_t num_pivots
Definition: dovi_meta.h:109
AVDOVIDmLevel3::min_pq_offset
uint16_t min_pq_offset
Definition: dovi_meta.h:213
get_ue_coef
static uint64_t get_ue_coef(GetBitContext *gb, const AVDOVIRpuDataHeader *hdr)
Definition: dovi_rpudec.c:71
AVDOVIRpuDataHeader::vdr_rpu_level
uint8_t vdr_rpu_level
Definition: dovi_meta.h:82
av_dovi_get_color
static av_always_inline AVDOVIColorMetadata * av_dovi_get_color(const AVDOVIMetadata *data)
Definition: dovi_meta.h:356
AVDOVIDmLevel5::left_offset
uint16_t left_offset
Definition: dovi_meta.h:225
get_ue_golomb_31
static int get_ue_golomb_31(GetBitContext *gb)
read unsigned exp golomb code, constraint to a max of 31.
Definition: golomb.h:120
AVDOVIDmData::l5
AVDOVIDmLevel5 l5
Definition: dovi_meta.h:306
AVDOVIDataMapping::mapping_chroma_format_idc
uint8_t mapping_chroma_format_idc
Definition: dovi_meta.h:146
AVDOVIDmLevel5::right_offset
uint16_t right_offset
Definition: dovi_meta.h:226
RPU_COEFF_FIXED
@ RPU_COEFF_FIXED
Definition: dovi_rpu.h:147
AVDOVIDmLevel255::dm_run_version
uint8_t dm_run_version
Definition: dovi_meta.h:290
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
AVDOVIDmLevel1::avg_pq
uint16_t avg_pq
Definition: dovi_meta.h:198
AVDOVIRpuDataHeader::bl_bit_depth
uint8_t bl_bit_depth
Definition: dovi_meta.h:88
VALIDATE
#define VALIDATE(VAR, MIN, MAX)
Definition: dovi_rpudec.c:121
AVDOVIColorMetadata
Dolby Vision RPU colorspace metadata parameters.
Definition: dovi_meta.h:162
AVDOVIDmData::level
uint8_t level
Definition: dovi_meta.h:300
av_clip_uint16
#define av_clip_uint16
Definition: common.h:112
AVDOVIDmLevel3::max_pq_offset
uint16_t max_pq_offset
Definition: dovi_meta.h:214
AVDOVIDmLevel254::dm_version_index
uint8_t dm_version_index
Definition: dovi_meta.h:284
get_variable_bits
static unsigned get_variable_bits(GetBitContext *gb, int n)
Definition: dovi_rpudec.c:109
AVDOVIDmLevel11::whitepoint
uint8_t whitepoint
Definition: dovi_meta.h:271
AVDOVIDmLevel254::dm_mode
uint8_t dm_mode
Definition: dovi_meta.h:283
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVDOVIRpuDataHeader::ext_mapping_idc_5_7
uint8_t ext_mapping_idc_5_7
Definition: dovi_meta.h:95
get_ue_golomb_long
static unsigned get_ue_golomb_long(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1.
Definition: golomb.h:104
av_dovi_get_mapping
static av_always_inline AVDOVIDataMapping * av_dovi_get_mapping(const AVDOVIMetadata *data)
Definition: dovi_meta.h:350
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:250
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDOVIReshapingCurve::pivots
uint16_t pivots[AV_DOVI_MAX_PIECES+1]
Definition: dovi_meta.h:110
AVColorPrimariesDesc::prim
AVPrimaryCoefficients prim
Definition: csp.h:80
AVDOVINLQParams::nlq_offset
uint16_t nlq_offset
Definition: dovi_meta.h:131
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVDOVIDataMapping::vdr_rpu_id
uint8_t vdr_rpu_id
Definition: dovi_meta.h:144
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AVDOVIRpuDataHeader::disable_residual_flag
uint8_t disable_residual_flag
Definition: dovi_meta.h:93
AVDOVIDataMapping::nlq
AVDOVINLQParams nlq[3]
Definition: dovi_meta.h:153
AVDOVIDataMapping
Dolby Vision RPU data mapping parameters.
Definition: dovi_meta.h:143
AV_DOVI_MAX_PIECES
#define AV_DOVI_MAX_PIECES
Coefficients of a piece-wise function.
Definition: dovi_meta.h:107
AVDOVIDataMapping::num_x_partitions
uint32_t num_x_partitions
Definition: dovi_meta.h:151
ff_dovi_guess_profile_hevc
int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr)
Internal helper function to guess the correct DV profile for HEVC.
Definition: dovi_rpu.c:71
AVDOVIDmLevel255::dm_debug
uint8_t dm_debug[4]
Definition: dovi_meta.h:291