FFmpeg
dovi_rpu.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 
26 #include "dovi_rpu.h"
27 #include "refstruct.h"
28 
30 {
31  ff_refstruct_unref(&s->dm);
32  for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
33  ff_refstruct_unref(&s->vdr[i]);
34  ff_refstruct_unref(&s->ext_blocks);
35  av_free(s->rpu_buf);
36 
37  *s = (DOVIContext) {
38  .logctx = s->logctx,
39  };
40 }
41 
43 {
44  ff_refstruct_unref(&s->dm);
45  for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
46  ff_refstruct_unref(&s->vdr[i]);
47  ff_refstruct_unref(&s->ext_blocks);
48 
49  *s = (DOVIContext) {
50  .logctx = s->logctx,
51  .cfg = s->cfg,
52  /* preserve temporary buffer */
53  .rpu_buf = s->rpu_buf,
54  .rpu_buf_sz = s->rpu_buf_sz,
55  };
56 }
57 
59 {
60  s->logctx = s0->logctx;
61  s->cfg = s0->cfg;
62  s->header = s0->header;
63  s->mapping = s0->mapping;
64  s->color = s0->color;
65  ff_refstruct_replace(&s->dm, s0->dm);
66  for (int i = 0; i <= DOVI_MAX_DM_ID; i++)
67  ff_refstruct_replace(&s->vdr[i], s0->vdr[i]);
68  ff_refstruct_replace(&s->ext_blocks, s0->ext_blocks);
69 }
70 
72 {
73  switch (hdr->vdr_rpu_profile) {
74  case 0:
75  if (hdr->bl_video_full_range_flag)
76  return 5;
77  break;
78  case 1:
80  if (hdr->vdr_bit_depth == 12) {
81  return 7;
82  } else {
83  return 4;
84  }
85  } else {
86  return 8;
87  }
88  }
89 
90  return 0; /* unknown */
91 }
92 
94  .dm_metadata_id = 0,
95  .scene_refresh_flag = 0,
96  .ycc_to_rgb_matrix = {
97  { 9575, 8192 },
98  { 0, 8192 },
99  { 14742, 8192 },
100  { 9575, 8192 },
101  { 1754, 8192 },
102  { 4383, 8192 },
103  { 9575, 8192 },
104  { 17372, 8192 },
105  { 0, 8192 },
106  },
107  .ycc_to_rgb_offset = {
108  { 1, 4 },
109  { 2, 1 },
110  { 2, 1 },
111  },
112  .rgb_to_lms_matrix = {
113  { 5845, 16384 },
114  { 9702, 16384 },
115  { 837, 16384 },
116  { 2568, 16384 },
117  { 12256, 16384 },
118  { 1561, 16384 },
119  { 0, 16384 },
120  { 679, 16384 },
121  { 15705, 16384 },
122  },
123  .signal_eotf = 39322,
124  .signal_eotf_param0 = 15867,
125  .signal_eotf_param1 = 228,
126  .signal_eotf_param2 = 1383604,
127  .signal_bit_depth = 14,
128  .signal_color_space = 0,
129  .signal_chroma_format = 0,
130  .signal_full_range_flag = 1,
131  .source_min_pq = 62,
132  .source_max_pq = 3696,
133  .source_diagonal = 42,
134 };
DOVIContext::ext_blocks
AVDOVIDmData * ext_blocks
Currently active extension blocks, updates on every ff_dovi_rpu_parse() or ff_dovi_rpu_generate().
Definition: dovi_rpu.h:71
DOVIContext::cfg
AVDOVIDecoderConfigurationRecord cfg
Currently active dolby vision configuration, or {0} for none.
Definition: dovi_rpu.h:51
ff_dovi_ctx_unref
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
Definition: dovi_rpu.c:29
DOVI_MAX_DM_ID
#define DOVI_MAX_DM_ID
Definition: dovi_rpu.h:31
ff_dovi_color_default
const AVDOVIColorMetadata ff_dovi_color_default
Definition: dovi_rpu.c:93
AVDOVIRpuDataHeader
Dolby Vision RPU data header.
Definition: dovi_meta.h:78
DOVIContext
Definition: dovi_rpu.h:32
dovi_rpu.h
refstruct.h
AVDOVIRpuDataHeader::el_spatial_resampling_filter_flag
uint8_t el_spatial_resampling_filter_flag
Definition: dovi_meta.h:92
AVDOVIColorMetadata::dm_metadata_id
uint8_t dm_metadata_id
Definition: dovi_meta.h:163
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVDOVIRpuDataHeader::vdr_bit_depth
uint8_t vdr_bit_depth
Definition: dovi_meta.h:90
s
#define s(width, name)
Definition: cbs_vp9.c:198
DOVIContext::mapping
const AVDOVIDataMapping * mapping
Currently active data mappings, or NULL.
Definition: dovi_rpu.h:64
DOVIContext::vdr
AVDOVIDataMapping * vdr[DOVI_MAX_DM_ID+1]
RefStruct references.
Definition: dovi_rpu.h:78
DOVIContext::color
const AVDOVIColorMetadata * color
Definition: dovi_rpu.h:65
ff_dovi_ctx_flush
void ff_dovi_ctx_flush(DOVIContext *s)
Partially reset the internal state.
Definition: dovi_rpu.c:42
AVDOVIRpuDataHeader::vdr_rpu_profile
uint8_t vdr_rpu_profile
Definition: dovi_meta.h:81
AVDOVIRpuDataHeader::bl_video_full_range_flag
uint8_t bl_video_full_range_flag
Definition: dovi_meta.h:87
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
DOVIContext::header
AVDOVIRpuDataHeader header
Currently active RPU data header, updates on every ff_dovi_rpu_parse() or ff_dovi_rpu_generate().
Definition: dovi_rpu.h:57
ff_refstruct_replace
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
DOVIContext::dm
AVDOVIColorMetadata * dm
Private fields internal to dovi_rpu.c.
Definition: dovi_rpu.h:77
AVDOVIColorMetadata
Dolby Vision RPU colorspace metadata parameters.
Definition: dovi_meta.h:162
DOVIContext::logctx
void * logctx
Definition: dovi_rpu.h:33
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDOVIRpuDataHeader::disable_residual_flag
uint8_t disable_residual_flag
Definition: dovi_meta.h:93
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
ff_dovi_ctx_replace
void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
Definition: dovi_rpu.c:58
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