FFmpeg
dovi_rpuenc.c
Go to the documentation of this file.
1 /*
2  * Dolby Vision RPU encoder
3  *
4  * Copyright (C) 2024 Niklas Haas
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/avassert.h"
24 #include "libavutil/crc.h"
25 #include "libavutil/mem.h"
26 
27 #include "avcodec.h"
28 #include "dovi_rpu.h"
29 #include "itut35.h"
30 #include "put_bits.h"
31 #include "put_golomb.h"
32 #include "refstruct.h"
33 
34 static struct {
35  uint64_t pps; // maximum pixels per second
36  int width; // maximum width
37  int main; // maximum bitrate in main tier
38  int high; // maximum bitrate in high tier
39 } dv_levels[] = {
40  [1] = {1280*720*24, 1280, 20, 50},
41  [2] = {1280*720*30, 1280, 20, 50},
42  [3] = {1920*1080*24, 1920, 20, 70},
43  [4] = {1920*1080*30, 2560, 20, 70},
44  [5] = {1920*1080*60, 3840, 20, 70},
45  [6] = {3840*2160*24, 3840, 25, 130},
46  [7] = {3840*2160*30, 3840, 25, 130},
47  [8] = {3840*2160*48, 3840, 40, 130},
48  [9] = {3840*2160*60, 3840, 40, 130},
49  [10] = {3840*2160*120, 3840, 60, 240},
50  [11] = {3840*2160*120, 7680, 60, 240},
51  [12] = {7680*4320*60, 7680, 120, 450},
52  [13] = {7680*4320*120u, 7680, 240, 800},
53 };
54 
56 {
58  const AVDOVIRpuDataHeader *hdr = NULL;
59  const AVFrameSideData *sd;
60  int dv_profile, dv_level, bl_compat_id = -1;
61  size_t cfg_size;
62  uint64_t pps;
63 
64  if (!s->enable)
65  goto skip;
66 
69 
70  if (sd)
71  hdr = av_dovi_get_header((const AVDOVIMetadata *) sd->data);
72 
73  if (s->enable == FF_DOVI_AUTOMATIC && !hdr)
74  goto skip;
75 
76  switch (avctx->codec_id) {
77  case AV_CODEC_ID_AV1: dv_profile = 10; break;
78  case AV_CODEC_ID_H264: dv_profile = 9; break;
79  case AV_CODEC_ID_HEVC: dv_profile = hdr ? ff_dovi_guess_profile_hevc(hdr) : 8; break;
80  default:
81  /* No other encoder should be calling this! */
82  av_assert0(0);
83  return AVERROR_BUG;
84  }
85 
87  if (dv_profile == 9) {
88  if (avctx->pix_fmt != AV_PIX_FMT_YUV420P)
89  dv_profile = 0;
90  } else {
91  if (avctx->pix_fmt != AV_PIX_FMT_YUV420P10)
92  dv_profile = 0;
93  }
94  }
95 
96  switch (dv_profile) {
97  case 4: /* HEVC with enhancement layer */
98  case 7:
99  if (s->enable > 0) {
100  av_log(s->logctx, AV_LOG_ERROR, "Coding of Dolby Vision enhancement "
101  "layers is currently unsupported.");
102  return AVERROR_PATCHWELCOME;
103  } else {
104  goto skip;
105  }
106  case 5: /* HEVC with proprietary IPTPQc2 */
107  bl_compat_id = 0;
108  break;
109  case 10:
110  /* FIXME: check for proper H.273 tags once those are added */
111  if (hdr && hdr->bl_video_full_range_flag) {
112  /* AV1 with proprietary IPTPQc2 */
113  bl_compat_id = 0;
114  break;
115  }
116  /* fall through */
117  case 8: /* HEVC (or AV1) with BL compatibility */
118  if (avctx->colorspace == AVCOL_SPC_BT2020_NCL &&
119  avctx->color_primaries == AVCOL_PRI_BT2020 &&
120  avctx->color_trc == AVCOL_TRC_SMPTE2084) {
121  bl_compat_id = 1;
122  } else if (avctx->colorspace == AVCOL_SPC_BT2020_NCL &&
123  avctx->color_primaries == AVCOL_PRI_BT2020 &&
124  avctx->color_trc == AVCOL_TRC_ARIB_STD_B67) {
125  bl_compat_id = 4;
126  } else if (avctx->colorspace == AVCOL_SPC_BT709 &&
127  avctx->color_primaries == AVCOL_PRI_BT709 &&
128  avctx->color_trc == AVCOL_TRC_BT709) {
129  bl_compat_id = 2;
130  }
131  }
132 
133  if (!dv_profile || bl_compat_id < 0) {
134  if (s->enable > 0) {
135  av_log(s->logctx, AV_LOG_ERROR, "Dolby Vision enabled, but could "
136  "not determine profile and compatibility mode. Double-check "
137  "colorspace and format settings for compatibility?\n");
138  return AVERROR(EINVAL);
139  }
140  goto skip;
141  }
142 
143  pps = avctx->width * avctx->height;
144  if (avctx->framerate.num) {
145  pps = pps * avctx->framerate.num / avctx->framerate.den;
146  } else {
147  pps *= 25; /* sanity fallback */
148  }
149 
150  dv_level = 0;
151  for (int i = 1; i < FF_ARRAY_ELEMS(dv_levels); i++) {
152  if (pps > dv_levels[i].pps)
153  continue;
154  if (avctx->width > dv_levels[i].width)
155  continue;
156  /* In theory, we should also test the bitrate when known, and
157  * distinguish between main and high tier. In practice, just ignore
158  * the bitrate constraints and hope they work out. This would ideally
159  * be handled by either the encoder or muxer directly. */
160  dv_level = i;
161  break;
162  }
163 
164  if (!dv_level) {
166  av_log(s->logctx, AV_LOG_ERROR, "Coded PPS (%"PRIu64") and width (%d) "
167  "exceed Dolby Vision limitations\n", pps, avctx->width);
168  return AVERROR(EINVAL);
169  } else {
170  av_log(s->logctx, AV_LOG_WARNING, "Coded PPS (%"PRIu64") and width (%d) "
171  "exceed Dolby Vision limitations. Ignoring, resulting file "
172  "may be non-conforming.\n", pps, avctx->width);
173  dv_level = FF_ARRAY_ELEMS(dv_levels) - 1;
174  }
175  }
176 
177  cfg = av_dovi_alloc(&cfg_size);
178  if (!cfg)
179  return AVERROR(ENOMEM);
180 
182  AV_PKT_DATA_DOVI_CONF, cfg, cfg_size, 0)) {
183  av_free(cfg);
184  return AVERROR(ENOMEM);
185  }
186 
187  cfg->dv_version_major = 1;
188  cfg->dv_version_minor = 0;
189  cfg->dv_profile = dv_profile;
190  cfg->dv_level = dv_level;
191  cfg->rpu_present_flag = 1;
192  cfg->el_present_flag = 0;
193  cfg->bl_present_flag = 1;
194  cfg->dv_bl_signal_compatibility_id = bl_compat_id;
195 
196  s->cfg = *cfg;
197  return 0;
198 
199 skip:
200  s->cfg = (AVDOVIDecoderConfigurationRecord) {0};
201  return 0;
202 }
203 
204 static inline void put_ue_coef(PutBitContext *pb, const AVDOVIRpuDataHeader *hdr,
205  uint64_t coef)
206 {
207  union { uint32_t u32; float f32; } fpart;
208 
209  switch (hdr->coef_data_type) {
210  case RPU_COEFF_FIXED:
211  set_ue_golomb(pb, coef >> hdr->coef_log2_denom);
212  put_bits64(pb, hdr->coef_log2_denom,
213  coef & ((1LL << hdr->coef_log2_denom) - 1));
214  break;
215  case RPU_COEFF_FLOAT:
216  fpart.f32 = coef / (float) (1LL << hdr->coef_log2_denom);
217  put_bits64(pb, hdr->coef_log2_denom, fpart.u32);
218  break;
219  }
220 }
221 
222 static inline void put_se_coef(PutBitContext *pb, const AVDOVIRpuDataHeader *hdr,
223  uint64_t coef)
224 {
225  union { uint32_t u32; float f32; } fpart;
226 
227  switch (hdr->coef_data_type) {
228  case RPU_COEFF_FIXED:
229  set_se_golomb(pb, coef >> hdr->coef_log2_denom);
230  put_bits64(pb, hdr->coef_log2_denom,
231  coef & ((1LL << hdr->coef_log2_denom) - 1));
232  break;
233  case RPU_COEFF_FLOAT:
234  fpart.f32 = coef / (float) (1LL << hdr->coef_log2_denom);
235  put_bits64(pb, hdr->coef_log2_denom, fpart.u32);
236  break;
237  }
238 }
239 
240 static int av_q2den(AVRational q, int den)
241 {
242  if (!q.den || q.den == den)
243  return q.num;
244  q = av_mul_q(q, av_make_q(den, 1));
245  return (q.num + (q.den >> 1)) / q.den;
246 }
247 
248 static void generate_ext_v1(PutBitContext *pb, const AVDOVIDmData *dm)
249 {
250  int ext_block_length, start_pos, pad_bits;
251 
252  switch (dm->level) {
253  case 1: ext_block_length = 5; break;
254  case 2: ext_block_length = 11; break;
255  case 4: ext_block_length = 3; break;
256  case 5: ext_block_length = 7; break;
257  case 6: ext_block_length = 8; break;
258  case 255: ext_block_length = 6; break;
259  default: return;
260  }
261 
262  set_ue_golomb(pb, ext_block_length);
263  put_bits(pb, 8, dm->level);
264  start_pos = put_bits_count(pb);
265 
266  switch (dm->level) {
267  case 1:
268  put_bits(pb, 12, dm->l1.min_pq);
269  put_bits(pb, 12, dm->l1.max_pq);
270  put_bits(pb, 12, dm->l1.avg_pq);
271  break;
272  case 2:
273  put_bits(pb, 12, dm->l2.target_max_pq);
274  put_bits(pb, 12, dm->l2.trim_slope);
275  put_bits(pb, 12, dm->l2.trim_offset);
276  put_bits(pb, 12, dm->l2.trim_power);
277  put_bits(pb, 12, dm->l2.trim_chroma_weight);
278  put_bits(pb, 12, dm->l2.trim_saturation_gain);
279  put_bits(pb, 13, dm->l2.ms_weight + 8192);
280  break;
281  case 4:
282  put_bits(pb, 12, dm->l4.anchor_pq);
283  put_bits(pb, 12, dm->l4.anchor_power);
284  break;
285  case 5:
286  put_bits(pb, 13, dm->l5.left_offset);
287  put_bits(pb, 13, dm->l5.right_offset);
288  put_bits(pb, 13, dm->l5.top_offset);
289  put_bits(pb, 13, dm->l5.bottom_offset);
290  break;
291  case 6:
292  put_bits(pb, 16, dm->l6.max_luminance);
293  put_bits(pb, 16, dm->l6.min_luminance);
294  put_bits(pb, 16, dm->l6.max_cll);
295  put_bits(pb, 16, dm->l6.max_fall);
296  break;
297  case 255:
298  put_bits(pb, 8, dm->l255.dm_run_mode);
299  put_bits(pb, 8, dm->l255.dm_run_version);
300  for (int i = 0; i < 4; i++)
301  put_bits(pb, 8, dm->l255.dm_debug[i]);
302  break;
303  }
304 
305  pad_bits = ext_block_length * 8 - (put_bits_count(pb) - start_pos);
306  av_assert1(pad_bits >= 0);
307  put_bits(pb, pad_bits, 0);
308 }
309 
310 static void put_cie_xy(PutBitContext *pb, AVCIExy xy)
311 {
312  const int denom = 32767;
313  put_sbits(pb, 16, av_q2den(xy.x, denom));
314  put_sbits(pb, 16, av_q2den(xy.y, denom));
315 }
316 
317 #define ANY6(arr) (arr[0] || arr[1] || arr[2] || arr[3] || arr[4] || arr[5])
318 #define ANY_XY(xy) (xy.x.num || xy.y.num)
319 #define ANY_CSP(csp) (ANY_XY(csp.prim.r) || ANY_XY(csp.prim.g) || \
320  ANY_XY(csp.prim.b) || ANY_XY(csp.wp))
321 
322 static void generate_ext_v2(PutBitContext *pb, const AVDOVIDmData *dm)
323 {
324  int ext_block_length, start_pos, pad_bits;
325 
326  switch (dm->level) {
327  case 3: ext_block_length = 5; break;
328  case 8:
329  if (ANY6(dm->l8.hue_vector_field)) {
330  ext_block_length = 25;
331  } else if (ANY6(dm->l8.saturation_vector_field)) {
332  ext_block_length = 19;
333  } else if (dm->l8.clip_trim) {
334  ext_block_length = 13;
335  } else if (dm->l8.target_mid_contrast) {
336  ext_block_length = 12;
337  } else {
338  ext_block_length = 10;
339  }
340  break;
341  case 9:
343  ext_block_length = 17;
344  } else {
345  ext_block_length = 1;
346  }
347  break;
348  case 10:
350  ext_block_length = 21;
351  } else {
352  ext_block_length = 5;
353  }
354  break;
355  case 11: ext_block_length = 4; break;
356  case 254: ext_block_length = 2; break;
357  default: return;
358  }
359 
360  set_ue_golomb(pb, ext_block_length);
361  put_bits(pb, 8, dm->level);
362  start_pos = put_bits_count(pb);
363 
364  switch (dm->level) {
365  case 3:
366  put_bits(pb, 12, dm->l3.min_pq_offset);
367  put_bits(pb, 12, dm->l3.max_pq_offset);
368  put_bits(pb, 12, dm->l3.avg_pq_offset);
369  break;
370  case 8:
371  put_bits(pb, 8, dm->l8.target_display_index);
372  put_bits(pb, 12, dm->l8.trim_slope);
373  put_bits(pb, 12, dm->l8.trim_offset);
374  put_bits(pb, 12, dm->l8.trim_power);
375  put_bits(pb, 12, dm->l8.trim_chroma_weight);
376  put_bits(pb, 12, dm->l8.trim_saturation_gain);
377  put_bits(pb, 12, dm->l8.ms_weight + 8192);
378  if (ext_block_length < 12)
379  break;
380  put_bits(pb, 12, dm->l8.target_mid_contrast);
381  if (ext_block_length < 13)
382  break;
383  put_bits(pb, 12, dm->l8.clip_trim);
384  if (ext_block_length < 19)
385  break;
386  for (int i = 0; i < 6; i++)
387  put_bits(pb, 8, dm->l8.saturation_vector_field[i]);
388  if (ext_block_length < 25)
389  break;
390  for (int i = 0; i < 6; i++)
391  put_bits(pb, 8, dm->l8.hue_vector_field[i]);
392  break;
393  case 9:
394  put_bits(pb, 8, dm->l9.source_primary_index);
395  if (ext_block_length < 17)
396  break;
401  break;
402  case 10:
403  put_bits(pb, 8, dm->l10.target_display_index);
404  put_bits(pb, 12, dm->l10.target_max_pq);
405  put_bits(pb, 12, dm->l10.target_min_pq);
406  put_bits(pb, 8, dm->l10.target_primary_index);
407  if (ext_block_length < 21)
408  break;
413  break;
414  case 11:
415  put_bits(pb, 8, dm->l11.content_type);
416  put_bits(pb, 4, dm->l11.whitepoint);
417  put_bits(pb, 1, dm->l11.reference_mode_flag);
418  put_bits(pb, 3, 0); /* reserved */
419  put_bits(pb, 2, dm->l11.sharpness);
420  put_bits(pb, 2, dm->l11.noise_reduction);
421  put_bits(pb, 2, dm->l11.mpeg_noise_reduction);
422  put_bits(pb, 2, dm->l11.frame_rate_conversion);
423  put_bits(pb, 2, dm->l11.brightness);
424  put_bits(pb, 2, dm->l11.color);
425  break;
426  case 254:
427  put_bits(pb, 8, dm->l254.dm_mode);
428  put_bits(pb, 8, dm->l254.dm_version_index);
429  break;
430  }
431 
432  pad_bits = ext_block_length * 8 - (put_bits_count(pb) - start_pos);
433  av_assert1(pad_bits >= 0);
434  put_bits(pb, pad_bits, 0);
435 }
436 
438  uint8_t **out_rpu, int *out_size)
439 {
440  PutBitContext *pb = &(PutBitContext){0};
441  const AVDOVIRpuDataHeader *hdr;
442  const AVDOVIDataMapping *mapping;
443  const AVDOVIColorMetadata *color;
444  int vdr_dm_metadata_changed, vdr_rpu_id, use_prev_vdr_rpu, profile,
445  buffer_size, rpu_size, pad, zero_run;
446  int num_ext_blocks_v1, num_ext_blocks_v2;
447  uint32_t crc;
448  uint8_t *dst;
449  if (!metadata) {
450  *out_rpu = NULL;
451  *out_size = 0;
452  return 0;
453  }
454 
455  hdr = av_dovi_get_header(metadata);
456  mapping = av_dovi_get_mapping(metadata);
457  color = av_dovi_get_color(metadata);
458  av_assert0(s->cfg.dv_profile);
459 
460  if (hdr->rpu_type != 2) {
461  av_log(s->logctx, AV_LOG_ERROR, "Unhandled RPU type %"PRIu8"\n",
462  hdr->rpu_type);
463  return AVERROR_INVALIDDATA;
464  }
465 
466  vdr_rpu_id = -1;
467  for (int i = 0; i <= DOVI_MAX_DM_ID; i++) {
468  if (s->vdr[i] && !memcmp(&s->vdr[i]->mapping, mapping, sizeof(*mapping))) {
469  vdr_rpu_id = i;
470  break;
471  } else if (vdr_rpu_id < 0 && (!s->vdr[i] || i == DOVI_MAX_DM_ID)) {
472  vdr_rpu_id = i;
473  }
474  }
475 
476  if (!s->vdr[vdr_rpu_id]) {
477  s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(DOVIVdr));
478  if (!s->vdr[vdr_rpu_id])
479  return AVERROR(ENOMEM);
480  }
481 
482  if (!s->vdr[color->dm_metadata_id]) {
483  s->vdr[color->dm_metadata_id] = ff_refstruct_allocz(sizeof(DOVIVdr));
484  if (!s->vdr[color->dm_metadata_id])
485  return AVERROR(ENOMEM);
486  }
487 
488  num_ext_blocks_v1 = num_ext_blocks_v2 = 0;
489  for (int i = 0; i < metadata->num_ext_blocks; i++) {
490  const AVDOVIDmData *dm = av_dovi_get_ext(metadata, i);
491  switch (dm->level) {
492  case 1:
493  case 2:
494  case 4:
495  case 5:
496  case 6:
497  case 255:
498  num_ext_blocks_v1++;
499  break;
500  case 3:
501  case 8:
502  case 9:
503  case 10:
504  case 11:
505  case 254:
506  num_ext_blocks_v2++;
507  break;
508  default:
509  av_log(s->logctx, AV_LOG_ERROR, "Invalid ext block level %d\n",
510  dm->level);
511  return AVERROR_INVALIDDATA;
512  }
513  }
514 
515  vdr_dm_metadata_changed = !s->color || memcmp(s->color, color, sizeof(*color));
516  use_prev_vdr_rpu = !memcmp(&s->vdr[vdr_rpu_id]->mapping, mapping, sizeof(*mapping));
517 
518  buffer_size = 12 /* vdr seq info */ + 5 /* CRC32 + terminator */;
519  buffer_size += num_ext_blocks_v1 * 13;
520  buffer_size += num_ext_blocks_v2 * 28;
521  if (!use_prev_vdr_rpu) {
522  buffer_size += 160;
523  for (int c = 0; c < 3; c++) {
524  for (int i = 0; i < mapping->curves[c].num_pivots - 1; i++) {
525  switch (mapping->curves[c].mapping_idc[i]) {
526  case AV_DOVI_MAPPING_POLYNOMIAL: buffer_size += 26; break;
527  case AV_DOVI_MAPPING_MMR: buffer_size += 177; break;
528  }
529  }
530  }
531  }
532  if (vdr_dm_metadata_changed)
533  buffer_size += 67;
534 
535  av_fast_padded_malloc(&s->rpu_buf, &s->rpu_buf_sz, buffer_size);
536  if (!s->rpu_buf)
537  return AVERROR(ENOMEM);
538  init_put_bits(pb, s->rpu_buf, s->rpu_buf_sz);
539 
540  /* RPU header */
541  put_bits(pb, 6, hdr->rpu_type);
542  put_bits(pb, 11, hdr->rpu_format);
543  put_bits(pb, 4, hdr->vdr_rpu_profile);
544  put_bits(pb, 4, hdr->vdr_rpu_level);
545  put_bits(pb, 1, 1); /* vdr_seq_info_present */
547  put_bits(pb, 2, hdr->coef_data_type);
548  if (hdr->coef_data_type == RPU_COEFF_FIXED)
549  set_ue_golomb(pb, hdr->coef_log2_denom);
550  put_bits(pb, 2, hdr->vdr_rpu_normalized_idc);
551  put_bits(pb, 1, hdr->bl_video_full_range_flag);
552  if ((hdr->rpu_format & 0x700) == 0) {
553  set_ue_golomb(pb, hdr->bl_bit_depth - 8);
554  set_ue_golomb(pb, hdr->el_bit_depth - 8);
555  set_ue_golomb(pb, hdr->vdr_bit_depth - 8);
557  put_bits(pb, 3, 0); /* reserved_zero_3bits */
559  put_bits(pb, 1, hdr->disable_residual_flag);
560  }
561  s->header = *hdr;
562 
563  put_bits(pb, 1, vdr_dm_metadata_changed);
564  put_bits(pb, 1, use_prev_vdr_rpu);
565  set_ue_golomb(pb, vdr_rpu_id);
566  s->mapping = &s->vdr[vdr_rpu_id]->mapping;
567 
568  profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr);
569 
570  if (!use_prev_vdr_rpu) {
571  set_ue_golomb(pb, mapping->mapping_color_space);
573  for (int c = 0; c < 3; c++) {
574  const AVDOVIReshapingCurve *curve = &mapping->curves[c];
575  int prev = 0;
576  set_ue_golomb(pb, curve->num_pivots - 2);
577  for (int i = 0; i < curve->num_pivots; i++) {
578  put_bits(pb, hdr->bl_bit_depth, curve->pivots[i] - prev);
579  prev = curve->pivots[i];
580  }
581  }
582 
583  if (mapping->nlq_method_idc != AV_DOVI_NLQ_NONE) {
584  put_bits(pb, 3, mapping->nlq_method_idc);
585  put_bits(pb, hdr->bl_bit_depth, mapping->nlq_pivots[0]);
586  put_bits(pb, hdr->bl_bit_depth, mapping->nlq_pivots[1] - mapping->nlq_pivots[0]);
587  }
588 
589  set_ue_golomb(pb, mapping->num_x_partitions - 1);
590  set_ue_golomb(pb, mapping->num_y_partitions - 1);
591 
592  for (int c = 0; c < 3; c++) {
593  const AVDOVIReshapingCurve *curve = &mapping->curves[c];
594  for (int i = 0; i < curve->num_pivots - 1; i++) {
595  set_ue_golomb(pb, curve->mapping_idc[i]);
596  switch (curve->mapping_idc[i]) {
598  set_ue_golomb(pb, curve->poly_order[i] - 1);
599  if (curve->poly_order[i] == 1)
600  put_bits(pb, 1, 0); /* linear_interp_flag */
601  for (int k = 0; k <= curve->poly_order[i]; k++)
602  put_se_coef(pb, hdr, curve->poly_coef[i][k]);
603  break;
604  }
605  case AV_DOVI_MAPPING_MMR: {
606  put_bits(pb, 2, curve->mmr_order[i] - 1);
607  put_se_coef(pb, hdr, curve->mmr_constant[i]);
608  for (int j = 0; j < curve->mmr_order[i]; j++) {
609  for (int k = 0; k < 7; k++)
610  put_se_coef(pb, hdr, curve->mmr_coef[i][j][k]);
611  }
612  break;
613  }
614  }
615  }
616  }
617 
618  if (mapping->nlq_method_idc != AV_DOVI_NLQ_NONE) {
619  for (int c = 0; c < 3; c++) {
620  const AVDOVINLQParams *nlq = &mapping->nlq[c];
621  put_bits(pb, hdr->el_bit_depth, nlq->nlq_offset);
622  put_ue_coef(pb, hdr, nlq->vdr_in_max);
623  switch (mapping->nlq_method_idc) {
625  put_ue_coef(pb, hdr, nlq->linear_deadzone_slope);
626  put_ue_coef(pb, hdr, nlq->linear_deadzone_threshold);
627  break;
628  }
629  }
630  }
631 
632  memcpy(&s->vdr[vdr_rpu_id]->mapping, mapping, sizeof(*mapping));
633  }
634 
635  if (vdr_dm_metadata_changed) {
636  const int denom = profile == 4 ? (1 << 30) : (1 << 28);
637  set_ue_golomb(pb, color->dm_metadata_id); /* affected_dm_id */
638  set_ue_golomb(pb, color->dm_metadata_id); /* current_dm_id */
639  set_ue_golomb(pb, color->scene_refresh_flag);
640  for (int i = 0; i < 9; i++)
641  put_sbits(pb, 16, av_q2den(color->ycc_to_rgb_matrix[i], 1 << 13));
642  for (int i = 0; i < 3; i++)
643  put_bits32(pb, av_q2den(color->ycc_to_rgb_offset[i], denom));
644  for (int i = 0; i < 9; i++)
645  put_sbits(pb, 16, av_q2den(color->rgb_to_lms_matrix[i], 1 << 14));
646  put_bits(pb, 16, color->signal_eotf);
647  put_bits(pb, 16, color->signal_eotf_param0);
648  put_bits(pb, 16, color->signal_eotf_param1);
649  put_bits32(pb, color->signal_eotf_param2);
650  put_bits(pb, 5, color->signal_bit_depth);
651  put_bits(pb, 2, color->signal_color_space);
652  put_bits(pb, 2, color->signal_chroma_format);
653  put_bits(pb, 2, color->signal_full_range_flag);
654  put_bits(pb, 12, color->source_min_pq);
655  put_bits(pb, 12, color->source_max_pq);
656  put_bits(pb, 10, color->source_diagonal);
657 
658  memcpy(&s->vdr[color->dm_metadata_id]->color, color, sizeof(*color));
659  s->color = &s->vdr[color->dm_metadata_id]->color;
660  }
661 
662  set_ue_golomb(pb, num_ext_blocks_v1);
663  align_put_bits(pb);
664  for (int i = 0; i < metadata->num_ext_blocks; i++)
665  generate_ext_v1(pb, av_dovi_get_ext(metadata, i));
666 
667  if (num_ext_blocks_v2) {
668  set_ue_golomb(pb, num_ext_blocks_v2);
669  align_put_bits(pb);
670  for (int i = 0; i < metadata->num_ext_blocks; i++)
671  generate_ext_v2(pb, av_dovi_get_ext(metadata, i));
672  }
673 
674  flush_put_bits(pb);
676  s->rpu_buf, put_bytes_output(pb)));
677  put_bits32(pb, crc);
678  put_bits(pb, 8, 0x80); /* terminator */
679  flush_put_bits(pb);
680 
681  rpu_size = put_bytes_output(pb);
682  switch (s->cfg.dv_profile) {
683  case 10:
684  /* AV1 uses T.35 OBU with EMDF header */
685  *out_rpu = av_malloc(rpu_size + 15);
686  if (!*out_rpu)
687  return AVERROR(ENOMEM);
688  init_put_bits(pb, *out_rpu, rpu_size + 15);
691  put_bits32(pb, 0x800); /* provider_oriented_code */
692  put_bits(pb, 27, 0x01be6841u); /* fixed EMDF header, see above */
693  if (rpu_size > 0xFF) {
694  av_assert2(rpu_size <= 0x10000);
695  put_bits(pb, 8, (rpu_size >> 8) - 1);
696  put_bits(pb, 1, 1); /* read_more */
697  put_bits(pb, 8, rpu_size & 0xFF);
698  put_bits(pb, 1, 0);
699  } else {
700  put_bits(pb, 8, rpu_size);
701  put_bits(pb, 1, 0);
702  }
703  ff_copy_bits(pb, s->rpu_buf, rpu_size * 8);
704  put_bits(pb, 17, 0x400); /* emdf payload id + emdf_protection */
705 
706  pad = pb->bit_left & 7;
707  put_bits(pb, pad, (1 << pad) - 1); /* pad to next byte with 1 bits */
708  flush_put_bits(pb);
709  *out_size = put_bytes_output(pb);
710  return 0;
711 
712  case 5:
713  case 8:
714  *out_rpu = dst = av_malloc(1 + rpu_size * 3 / 2); /* worst case */
715  if (!*out_rpu)
716  return AVERROR(ENOMEM);
717  *dst++ = 25; /* NAL prefix */
718  zero_run = 0;
719  for (int i = 0; i < rpu_size; i++) {
720  if (zero_run < 2) {
721  if (s->rpu_buf[i] == 0) {
722  zero_run++;
723  } else {
724  zero_run = 0;
725  }
726  } else {
727  if ((s->rpu_buf[i] & ~3) == 0) {
728  /* emulation prevention */
729  *dst++ = 3;
730  }
731  zero_run = s->rpu_buf[i] == 0;
732  }
733  *dst++ = s->rpu_buf[i];
734  }
735  *out_size = dst - *out_rpu;
736  return 0;
737 
738  default:
739  /* Should be unreachable */
740  av_assert0(0);
741  return AVERROR_BUG;
742  }
743 }
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:148
AVDOVIDmLevel2::trim_chroma_weight
uint16_t trim_chroma_weight
Definition: dovi_meta.h:205
AVDOVIDmLevel8::trim_power
uint16_t trim_power
Definition: dovi_meta.h:242
AVDOVIDmLevel8::saturation_vector_field
uint8_t saturation_vector_field[6]
Definition: dovi_meta.h:248
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
AVDOVIDmLevel8::trim_offset
uint16_t trim_offset
Definition: dovi_meta.h:241
put_bits32
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:291
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
align_put_bits
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
Definition: put_bits.h:420
AVCodecContext::decoded_side_data
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition: avcodec.h:2077
AVColorPrimariesDesc::wp
AVWhitepointCoefficients wp
Definition: csp.h:79
put_bytes_output
static int put_bytes_output(const PutBitContext *s)
Definition: put_bits.h:89
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
ANY_CSP
#define ANY_CSP(csp)
Definition: dovi_rpuenc.c:319
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
AVCodecContext::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition: avcodec.h:1916
put_sbits
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:281
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
AVDOVIDmLevel9::source_display_primaries
AVColorPrimariesDesc source_display_primaries
Definition: dovi_meta.h:255
AVDOVIDmLevel8::trim_saturation_gain
uint16_t trim_saturation_gain
Definition: dovi_meta.h:244
out_size
int out_size
Definition: movenc.c:56
AVDOVIDmLevel5::top_offset
uint16_t top_offset
Definition: dovi_meta.h:225
AVDOVIDmLevel11::frame_rate_conversion
uint8_t frame_rate_conversion
Definition: dovi_meta.h:274
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:223
av_dovi_get_ext
static av_always_inline AVDOVIDmData * av_dovi_get_ext(const AVDOVIMetadata *data, int index)
Definition: dovi_meta.h:360
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:678
AVDOVIReshapingCurve::mmr_coef
int64_t mmr_coef[AV_DOVI_MAX_PIECES][3][7]
Definition: dovi_meta.h:116
put_bits64
static void put_bits64(PutBitContext *s, int n, uint64_t value)
Write up to 64 bits into a bitstream.
Definition: put_bits.h:334
AVDOVIDmLevel10::target_primary_index
uint8_t target_primary_index
Definition: dovi_meta.h:263
AV_DOVI_NLQ_NONE
@ AV_DOVI_NLQ_NONE
Definition: dovi_meta.h:120
AVDOVIDmLevel8::ms_weight
uint16_t ms_weight
Definition: dovi_meta.h:245
FF_COMPLIANCE_STRICT
#define FF_COMPLIANCE_STRICT
Strictly conform to all the things in the spec no matter what consequences.
Definition: defs.h:59
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
high
int high
Definition: dovi_rpuenc.c:38
AVDOVIReshapingCurve::mapping_idc
enum AVDOVIMappingMethod mapping_idc[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:109
AVDOVIDmLevel6::min_luminance
uint16_t min_luminance
Definition: dovi_meta.h:232
AVDOVIDmLevel10::target_display_index
uint8_t target_display_index
Definition: dovi_meta.h:260
AVDOVIDmLevel1::max_pq
uint16_t max_pq
Definition: dovi_meta.h:195
AVDOVIDmData::l11
AVDOVIDmLevel11 l11
Definition: dovi_meta.h:310
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:143
AVDOVIRpuDataHeader
Dolby Vision RPU data header.
Definition: dovi_meta.h:78
AVDOVIDmLevel8::hue_vector_field
uint8_t hue_vector_field[6]
Definition: dovi_meta.h:249
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AV_PKT_DATA_DOVI_CONF
@ AV_PKT_DATA_DOVI_CONF
DOVI configuration ref: dolby-vision-bitstreams-within-the-iso-base-media-file-format-v2....
Definition: packet.h:284
AVDOVIRpuDataHeader::coef_data_type
uint8_t coef_data_type
Definition: dovi_meta.h:84
crc.h
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:560
AVDOVIDmLevel11::color
uint8_t color
Definition: dovi_meta.h:276
AVDOVIDmLevel11::reference_mode_flag
uint8_t reference_mode_flag
Definition: dovi_meta.h:270
AVDOVIDmLevel11::brightness
uint8_t brightness
Definition: dovi_meta.h:275
DOVIContext
Definition: dovi_rpu.h:32
AVDOVIRpuDataHeader::el_bit_depth
uint8_t el_bit_depth
Definition: dovi_meta.h:89
RPU_COEFF_FLOAT
@ RPU_COEFF_FLOAT
Definition: dovi_rpu.h:136
AVDOVIDmLevel2::trim_power
uint16_t trim_power
Definition: dovi_meta.h:204
dovi_rpu.h
AVDOVIDmLevel2::trim_slope
uint16_t trim_slope
Definition: dovi_meta.h:202
AVDOVIDmLevel2::ms_weight
int16_t ms_weight
Definition: dovi_meta.h:207
AVRational::num
int num
Numerator.
Definition: rational.h:59
ff_dovi_rpu_generate
int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, uint8_t **out_rpu, int *out_size)
Synthesize a Dolby Vision RPU reflecting the current state.
Definition: dovi_rpuenc.c:437
refstruct.h
FF_DOVI_AUTOMATIC
#define FF_DOVI_AUTOMATIC
Enable tri-state.
Definition: dovi_rpu.h:39
generate_ext_v1
static void generate_ext_v1(PutBitContext *pb, const AVDOVIDmData *dm)
Definition: dovi_rpuenc.c:248
AVDOVIRpuDataHeader::vdr_rpu_normalized_idc
uint8_t vdr_rpu_normalized_idc
Definition: dovi_meta.h:86
av_dovi_alloc
AVDOVIDecoderConfigurationRecord * av_dovi_alloc(size_t *size)
Allocate a AVDOVIDecoderConfigurationRecord structure and initialize its fields to default values.
Definition: dovi_meta.c:26
AVDOVIRpuDataHeader::el_spatial_resampling_filter_flag
uint8_t el_spatial_resampling_filter_flag
Definition: dovi_meta.h:92
AVDOVIDmLevel3::avg_pq_offset
uint16_t avg_pq_offset
Definition: dovi_meta.h:213
AVDOVIDmLevel8::clip_trim
uint16_t clip_trim
Definition: dovi_meta.h:247
AVDOVIDmData
Dolby Vision metadata extension block.
Definition: dovi_meta.h:297
avassert.h
put_golomb.h
exp golomb vlc writing stuff
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:671
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVDOVIRpuDataHeader::chroma_resampling_explicit_filter_flag
uint8_t chroma_resampling_explicit_filter_flag
Definition: dovi_meta.h:83
main
int main
Definition: dovi_rpuenc.c:37
AVDOVIDmLevel6::max_cll
uint16_t max_cll
Definition: dovi_meta.h:233
float
float
Definition: af_crystalizer.c:121
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:324
AVDOVIDmLevel8::trim_slope
uint16_t trim_slope
Definition: dovi_meta.h:240
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVDOVIDmLevel4::anchor_power
uint16_t anchor_power
Definition: dovi_meta.h:218
AVDOVIReshapingCurve::mmr_order
uint8_t mmr_order[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:114
AVDOVIDmData::l3
AVDOVIDmLevel3 l3
Definition: dovi_meta.h:302
AVDOVIDmLevel11::noise_reduction
uint8_t noise_reduction
Definition: dovi_meta.h:272
AVCodecContext::nb_decoded_side_data
int nb_decoded_side_data
Definition: avcodec.h:2078
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:262
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVDOVIDecoderConfigurationRecord::dv_profile
uint8_t dv_profile
Definition: dovi_meta.h:57
AV_DOVI_MAPPING_POLYNOMIAL
@ AV_DOVI_MAPPING_POLYNOMIAL
Definition: dovi_meta.h:97
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
put_se_coef
static void put_se_coef(PutBitContext *pb, const AVDOVIRpuDataHeader *hdr, uint64_t coef)
Definition: dovi_rpuenc.c:222
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
PutBitContext
Definition: put_bits.h:50
AVDOVIDecoderConfigurationRecord::dv_version_major
uint8_t dv_version_major
Definition: dovi_meta.h:55
av_dovi_get_header
static av_always_inline AVDOVIRpuDataHeader * av_dovi_get_header(const AVDOVIMetadata *data)
Definition: dovi_meta.h:342
AVDOVIReshapingCurve::poly_order
uint8_t poly_order[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:111
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:455
AVDOVINLQParams::linear_deadzone_threshold
uint64_t linear_deadzone_threshold
Definition: dovi_meta.h:133
AVDOVIDmLevel8::target_mid_contrast
uint16_t target_mid_contrast
Definition: dovi_meta.h:246
NULL
#define NULL
Definition: coverity.c:32
AVDOVIDecoderConfigurationRecord::dv_level
uint8_t dv_level
Definition: dovi_meta.h:58
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AVDOVIDecoderConfigurationRecord::dv_bl_signal_compatibility_id
uint8_t dv_bl_signal_compatibility_id
Definition: dovi_meta.h:62
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:280
AV_DOVI_MAPPING_MMR
@ AV_DOVI_MAPPING_MMR
Definition: dovi_meta.h:98
AVDOVIDmLevel5::bottom_offset
uint16_t bottom_offset
Definition: dovi_meta.h:226
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCodecContext::nb_coded_side_data
int nb_coded_side_data
Definition: avcodec.h:1917
AVCOL_PRI_BT709
@ AVCOL_PRI_BT709
also ITU-R BT1361 / IEC 61966-2-4 / SMPTE RP 177 Annex B
Definition: pixfmt.h:557
AVDOVIDmData::l9
AVDOVIDmLevel9 l9
Definition: dovi_meta.h:308
put_cie_xy
static void put_cie_xy(PutBitContext *pb, AVCIExy xy)
Definition: dovi_rpuenc.c: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
AVDOVIDmLevel4::anchor_pq
uint16_t anchor_pq
Definition: dovi_meta.h:217
AVDOVIReshapingCurve::mmr_constant
int64_t mmr_constant[AV_DOVI_MAX_PIECES]
Definition: dovi_meta.h:115
AVDOVIDmLevel9::source_primary_index
uint8_t source_primary_index
Definition: dovi_meta.h:254
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
AVDOVIDmLevel2::target_max_pq
uint16_t target_max_pq
Definition: dovi_meta.h:201
AVCOL_PRI_BT2020
@ AVCOL_PRI_BT2020
ITU-R BT2020.
Definition: pixfmt.h:566
AVDOVIDmLevel6::max_luminance
uint16_t max_luminance
Definition: dovi_meta.h:231
RPU_COEFF_FIXED
@ RPU_COEFF_FIXED
Definition: dovi_rpu.h:135
AVCIExy::x
AVRational x
Definition: csp.h:57
AVDOVIDmData::l2
AVDOVIDmLevel2 l2
Definition: dovi_meta.h:301
AVDOVIDataMapping::nlq_pivots
uint16_t nlq_pivots[2]
Definition: dovi_meta.h:152
AVCOL_TRC_SMPTE2084
@ AVCOL_TRC_SMPTE2084
SMPTE ST 2084 for 10-, 12-, 14- and 16-bit systems.
Definition: pixfmt.h:597
AVPrimaryCoefficients::b
AVCIExy b
Definition: csp.h:65
AVDOVIDmLevel6::max_fall
uint16_t max_fall
Definition: dovi_meta.h:234
ITU_T_T35_PROVIDER_CODE_DOLBY
#define ITU_T_T35_PROVIDER_CODE_DOLBY
Definition: itut35.h:27
AVPrimaryCoefficients::r
AVCIExy r
Definition: csp.h:65
AVDOVIDmLevel8::target_display_index
uint8_t target_display_index
Definition: dovi_meta.h:239
AVDOVIDmData::l254
AVDOVIDmLevel254 l254
Definition: dovi_meta.h:311
av_q2den
static int av_q2den(AVRational q, int den)
Definition: dovi_rpuenc.c:240
AVDOVIDmLevel10::target_display_primaries
AVColorPrimariesDesc target_display_primaries
Definition: dovi_meta.h:264
AV_DOVI_NLQ_LINEAR_DZ
@ AV_DOVI_NLQ_LINEAR_DZ
Definition: dovi_meta.h:121
AVDOVIRpuDataHeader::vdr_rpu_profile
uint8_t vdr_rpu_profile
Definition: dovi_meta.h:81
av_bswap32
#define av_bswap32
Definition: bswap.h:28
AVDOVIDmLevel2::trim_saturation_gain
uint16_t trim_saturation_gain
Definition: dovi_meta.h:206
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:243
AVDOVIDmLevel255::dm_run_mode
uint8_t dm_run_mode
Definition: dovi_meta.h:287
AVDOVIDmLevel1::min_pq
uint16_t min_pq
Definition: dovi_meta.h:194
set_se_golomb
static void set_se_golomb(PutBitContext *pb, int i)
write signed exp golomb code.
Definition: put_golomb.h:86
AVFrameSideData::data
uint8_t * data
Definition: frame.h:252
AVPrimaryCoefficients::g
AVCIExy g
Definition: csp.h:65
AVDOVIDmLevel11::content_type
uint8_t content_type
Definition: dovi_meta.h:268
AVDOVIDmData::l10
AVDOVIDmLevel10 l10
Definition: dovi_meta.h:309
PutBitContext::bit_left
int bit_left
Definition: put_bits.h:52
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:112
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
av_packet_side_data_add
AVPacketSideData * av_packet_side_data_add(AVPacketSideData **psd, int *pnb_sd, enum AVPacketSideDataType type, void *data, size_t size, int flags)
Wrap existing data as packet side data.
Definition: packet.c:697
FF_COMPLIANCE_UNOFFICIAL
#define FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
Definition: defs.h:61
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:582
AVDOVIDmData::l255
AVDOVIDmLevel255 l255
Definition: dovi_meta.h:312
AVDOVIDmData::l8
AVDOVIDmLevel8 l8
Definition: dovi_meta.h:307
AVDOVIDmLevel2::trim_offset
uint16_t trim_offset
Definition: dovi_meta.h:203
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
put_bits_count
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:80
AVCOL_SPC_BT2020_NCL
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:620
AVDOVIDmLevel10::target_max_pq
uint16_t target_max_pq
Definition: dovi_meta.h:261
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
AVDOVIDataMapping::num_y_partitions
uint32_t num_y_partitions
Definition: dovi_meta.h:150
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
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
profile
int profile
Definition: mxfenc.c:2227
AVDOVINLQParams
Coefficients of the non-linear inverse quantization.
Definition: dovi_meta.h:128
AV_CRC_32_IEEE
@ AV_CRC_32_IEEE
Definition: crc.h:52
AVCodecContext::height
int height
Definition: avcodec.h:618
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
AVDOVIDmData::l4
AVDOVIDmLevel4 l4
Definition: dovi_meta.h:303
set_ue_golomb
static void set_ue_golomb(PutBitContext *pb, int i)
write unsigned exp golomb code.
Definition: put_golomb.h:41
AVDOVIDmData::l1
AVDOVIDmLevel1 l1
Definition: dovi_meta.h:300
AVDOVIDataMapping::curves
AVDOVIReshapingCurve curves[3]
Definition: dovi_meta.h:145
avcodec.h
AVDOVINLQParams::linear_deadzone_slope
uint64_t linear_deadzone_slope
Definition: dovi_meta.h:132
dv_levels
static struct @93 dv_levels[]
AVDOVIReshapingCurve
Definition: dovi_meta.h:106
generate_ext_v2
static void generate_ext_v2(PutBitContext *pb, const AVDOVIDmData *dm)
Definition: dovi_rpuenc.c:322
ff_dovi_configure
int ff_dovi_configure(DOVIContext *s, AVCodecContext *avctx)
Configure the encoder for Dolby Vision encoding.
Definition: dovi_rpuenc.c:55
AVDOVIDmLevel11::mpeg_noise_reduction
uint8_t mpeg_noise_reduction
Definition: dovi_meta.h:273
DOVIVdr
Definition: dovi_rpu.h:129
AVDOVIDmLevel11::sharpness
uint8_t sharpness
Definition: dovi_meta.h:271
AVDOVINLQParams::vdr_in_max
uint64_t vdr_in_max
Definition: dovi_meta.h:130
AVCodecContext::strict_std_compliance
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
Definition: avcodec.h:1379
AVCIExy::y
AVRational y
Definition: csp.h:57
AVDOVIDmData::l6
AVDOVIDmLevel6 l6
Definition: dovi_meta.h:305
ff_copy_bits
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
Definition: bitstream.c:49
AVDOVIReshapingCurve::num_pivots
uint8_t num_pivots
Definition: dovi_meta.h:107
AVDOVIDmLevel3::min_pq_offset
uint16_t min_pq_offset
Definition: dovi_meta.h:211
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:354
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVDOVIDmLevel5::left_offset
uint16_t left_offset
Definition: dovi_meta.h:223
AVCOL_TRC_ARIB_STD_B67
@ AVCOL_TRC_ARIB_STD_B67
ARIB STD-B67, known as "Hybrid log-gamma".
Definition: pixfmt.h:601
AVDOVIDmData::l5
AVDOVIDmLevel5 l5
Definition: dovi_meta.h:304
itut35.h
AVDOVIDataMapping::mapping_chroma_format_idc
uint8_t mapping_chroma_format_idc
Definition: dovi_meta.h:144
AVDOVIDmLevel5::right_offset
uint16_t right_offset
Definition: dovi_meta.h:224
AVDOVIDmLevel255::dm_run_version
uint8_t dm_run_version
Definition: dovi_meta.h:288
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:196
AVRational::den
int den
Denominator.
Definition: rational.h:60
AVDOVIDecoderConfigurationRecord::bl_present_flag
uint8_t bl_present_flag
Definition: dovi_meta.h:61
AVDOVIRpuDataHeader::bl_bit_depth
uint8_t bl_bit_depth
Definition: dovi_meta.h:88
AVDOVIColorMetadata
Dolby Vision RPU colorspace metadata parameters.
Definition: dovi_meta.h:160
AVDOVIDecoderConfigurationRecord::rpu_present_flag
uint8_t rpu_present_flag
Definition: dovi_meta.h:59
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
AVDOVIDecoderConfigurationRecord::el_present_flag
uint8_t el_present_flag
Definition: dovi_meta.h:60
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
AVDOVIDmData::level
uint8_t level
Definition: dovi_meta.h:298
AVDOVIDmLevel3::max_pq_offset
uint16_t max_pq_offset
Definition: dovi_meta.h:212
AVDOVIDmLevel254::dm_version_index
uint8_t dm_version_index
Definition: dovi_meta.h:282
AVDOVIDecoderConfigurationRecord::dv_version_minor
uint8_t dv_version_minor
Definition: dovi_meta.h:56
AVDOVIDmLevel11::whitepoint
uint8_t whitepoint
Definition: dovi_meta.h:269
AVDOVIDmLevel254::dm_mode
uint8_t dm_mode
Definition: dovi_meta.h:281
mem.h
width
int width
Definition: dovi_rpuenc.c:36
av_dovi_get_mapping
static av_always_inline AVDOVIDataMapping * av_dovi_get_mapping(const AVDOVIMetadata *data)
Definition: dovi_meta.h:348
ITU_T_T35_COUNTRY_CODE_US
#define ITU_T_T35_COUNTRY_CODE_US
Definition: itut35.h:23
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:250
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
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:108
AVColorPrimariesDesc::prim
AVPrimaryCoefficients prim
Definition: csp.h:80
av_frame_side_data_get
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
Definition: frame.h:1143
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
ANY6
#define ANY6(arr)
Definition: dovi_rpuenc.c:317
AVDOVINLQParams::nlq_offset
uint16_t nlq_offset
Definition: dovi_meta.h:129
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
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
AVCOL_SPC_BT709
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
Definition: pixfmt.h:611
put_bits.h
put_ue_coef
static void put_ue_coef(PutBitContext *pb, const AVDOVIRpuDataHeader *hdr, uint64_t coef)
Definition: dovi_rpuenc.c:204
AVDOVIDataMapping::nlq
AVDOVINLQParams nlq[3]
Definition: dovi_meta.h:151
AVDOVIDataMapping
Dolby Vision RPU data mapping parameters.
Definition: dovi_meta.h:141
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
AVDOVIDataMapping::num_x_partitions
uint32_t num_x_partitions
Definition: dovi_meta.h:149
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:68
AVDOVIDmLevel255::dm_debug
uint8_t dm_debug[4]
Definition: dovi_meta.h:289
AVDOVIDecoderConfigurationRecord
Definition: dovi_meta.h:54
AVDOVIMetadata::num_ext_blocks
int num_ext_blocks
Definition: dovi_meta.h:335