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