FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/dovi_rpu.c
Date: 2024-07-26 21:54:09
Exec Total Coverage
Lines: 31 44 70.5%
Functions: 3 4 75.0%
Branches: 6 17 35.3%

Line Branch Exec Source
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
29 459 void ff_dovi_ctx_unref(DOVIContext *s)
30 {
31 459 ff_refstruct_unref(&s->dm);
32
2/2
✓ Branch 0 taken 7344 times.
✓ Branch 1 taken 459 times.
7803 for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
33 7344 ff_refstruct_unref(&s->vdr[i]);
34 459 ff_refstruct_unref(&s->ext_blocks);
35 459 av_free(s->rpu_buf);
36
37 459 *s = (DOVIContext) {
38 459 .logctx = s->logctx,
39 };
40 459 }
41
42 8 void ff_dovi_ctx_flush(DOVIContext *s)
43 {
44 8 ff_refstruct_unref(&s->dm);
45
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 8 times.
136 for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++)
46 128 ff_refstruct_unref(&s->vdr[i]);
47 8 ff_refstruct_unref(&s->ext_blocks);
48
49 8 *s = (DOVIContext) {
50 8 .logctx = s->logctx,
51 8 .cfg = s->cfg,
52 /* preserve temporary buffer */
53 8 .rpu_buf = s->rpu_buf,
54 8 .rpu_buf_sz = s->rpu_buf_sz,
55 };
56 8 }
57
58 32 void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0)
59 {
60 32 s->logctx = s0->logctx;
61 32 s->cfg = s0->cfg;
62 32 s->header = s0->header;
63 32 s->mapping = s0->mapping;
64 32 s->color = s0->color;
65 32 ff_refstruct_replace(&s->dm, s0->dm);
66
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 32 times.
544 for (int i = 0; i <= DOVI_MAX_DM_ID; i++)
67 512 ff_refstruct_replace(&s->vdr[i], s0->vdr[i]);
68 32 ff_refstruct_replace(&s->ext_blocks, s0->ext_blocks);
69 32 }
70
71 int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr)
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:
79 if (hdr->el_spatial_resampling_filter_flag && !hdr->disable_residual_flag) {
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
93 const AVDOVIColorMetadata ff_dovi_color_default = {
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 };
135