FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/cbs_sei_syntax_template.c
Date: 2024-04-20 14:10:07
Exec Total Coverage
Lines: 111 149 74.5%
Functions: 14 30 46.7%
Branches: 45 97 46.4%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 SEI_FUNC(filler_payload, (CodedBitstreamContext *ctx, RWContext *rw,
20 SEIRawFillerPayload *current,
21 SEIMessageState *state))
22 {
23 int err, i;
24
25 HEADER("Filler Payload");
26
27 #ifdef READ
28 current->payload_size = state->payload_size;
29 #endif
30
31 for (i = 0; i < current->payload_size; i++)
32 fixed(8, ff_byte, 0xff);
33
34 return 0;
35 }
36
37 300 SEI_FUNC(user_data_registered, (CodedBitstreamContext *ctx, RWContext *rw,
38 SEIRawUserDataRegistered *current,
39 SEIMessageState *state))
40 {
41 int err, i, j;
42
43 150 HEADER("User Data Registered ITU-T T.35");
44
45
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
150 u(8, itu_t_t35_country_code, 0x00, 0xff);
46
1/2
✓ Branch 0 taken 75 times.
✗ Branch 1 not taken.
150 if (current->itu_t_t35_country_code != 0xff)
47 150 i = 1;
48 else {
49 u(8, itu_t_t35_country_code_extension_byte, 0x00, 0xff);
50 i = 2;
51 }
52
53 #ifdef READ
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
50 if (state->payload_size < i) {
55 av_log(ctx->log_ctx, AV_LOG_ERROR,
56 "Invalid SEI user data registered payload.\n");
57 return AVERROR_INVALIDDATA;
58 }
59 50 current->data_length = state->payload_size - i;
60 #endif
61
62
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 25 times.
150 allocate(current->data, current->data_length);
63
2/2
✓ Branch 0 taken 729 times.
✓ Branch 1 taken 75 times.
1608 for (j = 0; j < current->data_length; j++)
64
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 729 times.
1458 xu(8, itu_t_t35_payload_byte[], current->data[j], 0x00, 0xff, 1, i + j);
65
66 150 return 0;
67 }
68
69 240 SEI_FUNC(user_data_unregistered, (CodedBitstreamContext *ctx, RWContext *rw,
70 SEIRawUserDataUnregistered *current,
71 SEIMessageState *state))
72 {
73 int err, i;
74
75 120 HEADER("User Data Unregistered");
76
77 #ifdef READ
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
40 if (state->payload_size < 16) {
79 av_log(ctx->log_ctx, AV_LOG_ERROR,
80 "Invalid SEI user data unregistered payload.\n");
81 return AVERROR_INVALIDDATA;
82 }
83 40 current->data_length = state->payload_size - 16;
84 #endif
85
86
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 60 times.
2040 for (i = 0; i < 16; i++)
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 960 times.
1920 us(8, uuid_iso_iec_11578[i], 0x00, 0xff, 1, i);
88
89
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
✓ Branch 2 taken 20 times.
120 allocate(current->data, current->data_length);
90
91
2/2
✓ Branch 0 taken 14379 times.
✓ Branch 1 taken 60 times.
28878 for (i = 0; i < current->data_length; i++)
92
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14379 times.
28758 xu(8, user_data_payload_byte[i], current->data[i], 0x00, 0xff, 1, i);
93
94 120 return 0;
95 }
96
97 12 SEI_FUNC(mastering_display_colour_volume,
98 (CodedBitstreamContext *ctx, RWContext *rw,
99 SEIRawMasteringDisplayColourVolume *current,
100 SEIMessageState *state))
101 {
102 int err, c;
103
104 6 HEADER("Mastering Display Colour Volume");
105
106
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
24 for (c = 0; c < 3; c++) {
107
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
18 ubs(16, display_primaries_x[c], 1, c);
108
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
18 ubs(16, display_primaries_y[c], 1, c);
109 }
110
111
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
6 ub(16, white_point_x);
112
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
6 ub(16, white_point_y);
113
114
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
6 ub(32, max_display_mastering_luminance);
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
6 ub(32, min_display_mastering_luminance);
116
117 6 return 0;
118 }
119
120 SEI_FUNC(content_light_level_info, (CodedBitstreamContext *ctx, RWContext *rw,
121 SEIRawContentLightLevelInfo *current,
122 SEIMessageState *state))
123 {
124 int err;
125
126 HEADER("Content Light Level Information");
127
128 ub(16, max_content_light_level);
129 ub(16, max_pic_average_light_level);
130
131 return 0;
132 }
133
134 SEI_FUNC(alternative_transfer_characteristics,
135 (CodedBitstreamContext *ctx, RWContext *rw,
136 SEIRawAlternativeTransferCharacteristics *current,
137 SEIMessageState *state))
138 {
139 int err;
140
141 HEADER("Alternative Transfer Characteristics");
142
143 ub(8, preferred_transfer_characteristics);
144
145 return 0;
146 }
147
148 SEI_FUNC(ambient_viewing_environment,
149 (CodedBitstreamContext *ctx, RWContext *rw,
150 SEIRawAmbientViewingEnvironment *current,
151 SEIMessageState *state))
152 {
153 static const uint16_t max_ambient_light_value = 50000;
154 int err;
155
156 HEADER("Ambient Viewing Environment");
157
158 u(32, ambient_illuminance, 1, MAX_UINT_BITS(32));
159 u(16, ambient_light_x, 0, max_ambient_light_value);
160 u(16, ambient_light_y, 0, max_ambient_light_value);
161
162 return 0;
163 }
164
165 28676 static int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw,
166 SEIRawMessage *current)
167 {
168 const SEIMessageTypeDescriptor *desc;
169 int err, i;
170
171 28676 desc = ff_cbs_sei_find_type(ctx, current->payload_type);
172
2/2
✓ Branch 0 taken 14072 times.
✓ Branch 1 taken 266 times.
28676 if (desc) {
173 28144 SEIMessageState state = {
174 28144 .payload_type = current->payload_type,
175 28144 .payload_size = current->payload_size,
176 28144 .extension_present = current->extension_bit_length > 0,
177 };
178 int start_position, current_position, bits_written;
179
180 #ifdef READ
181
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5652 times.
11304 CHECK(ff_cbs_sei_alloc_message_payload(current, desc));
182 #endif
183
184 28144 start_position = bit_position(rw);
185
186
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14072 times.
28144 CHECK(desc->READWRITE(ctx, rw, current->payload, &state));
187
188 28144 current_position = bit_position(rw);
189 28144 bits_written = current_position - start_position;
190
191
3/4
✓ Branch 1 taken 11789 times.
✓ Branch 2 taken 2283 times.
✓ Branch 3 taken 11789 times.
✗ Branch 4 not taken.
28144 if (byte_alignment(rw) || state.extension_present ||
192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11789 times.
23578 bits_written < 8 * current->payload_size) {
193 size_t bits_left;
194
195 #ifdef READ
196 2066 GetBitContext tmp = *rw;
197 int trailing_bits, trailing_zero_bits;
198
199 2066 bits_left = 8 * current->payload_size - bits_written;
200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1033 times.
2066 if (bits_left > 8)
201 skip_bits_long(&tmp, bits_left - 8);
202 2066 trailing_bits = get_bits(&tmp, FFMIN(bits_left, 8));
203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1033 times.
2066 if (trailing_bits == 0) {
204 // The trailing bits must contain a bit_equal_to_one, so
205 // they can't all be zero.
206 return AVERROR_INVALIDDATA;
207 }
208 2066 trailing_zero_bits = ff_ctz(trailing_bits);
209 2066 current->extension_bit_length =
210 2066 bits_left - 1 - trailing_zero_bits;
211 #endif
212
213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2283 times.
4566 if (current->extension_bit_length > 0) {
214 allocate(current->extension_data,
215 (current->extension_bit_length + 7) / 8);
216
217 bits_left = current->extension_bit_length;
218 for (i = 0; bits_left > 0; i++) {
219 int length = FFMIN(bits_left, 8);
220 xu(length, reserved_payload_extension_data,
221 current->extension_data[i],
222 0, MAX_UINT_BITS(length), 0);
223 bits_left -= length;
224 }
225 }
226
227
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2283 times.
4566 fixed(1, bit_equal_to_one, 1);
228
2/2
✓ Branch 1 taken 3102 times.
✓ Branch 2 taken 2283 times.
10770 while (byte_alignment(rw))
229
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3102 times.
6204 fixed(1, bit_equal_to_zero, 0);
230 }
231
232 #ifdef WRITE
233 16840 current->payload_size = (put_bits_count(rw) - start_position) / 8;
234 #endif
235 } else {
236 uint8_t *data;
237
238 #ifdef READ
239
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
264 allocate(current->payload_ref, current->payload_size);
240 264 current->payload = current->payload_ref;
241 #else
242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 134 times.
268 allocate(current->payload, current->payload_size);
243 #endif
244 532 data = current->payload;
245
246
2/2
✓ Branch 0 taken 6335 times.
✓ Branch 1 taken 266 times.
13202 for (i = 0; i < current->payload_size; i++)
247
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6335 times.
12670 xu(8, payload_byte[i], data[i], 0, 255, 1, i);
248 }
249
250 28676 return 0;
251 }
252
253 10021 static int FUNC(message_list)(CodedBitstreamContext *ctx, RWContext *rw,
254 SEIRawMessageList *current, int prefix)
255 {
256 SEIRawMessage *message;
257 int err, k;
258
259 #ifdef READ
260 5784 for (k = 0;; k++) {
261 5784 uint32_t payload_type = 0;
262 5784 uint32_t payload_size = 0;
263 uint32_t tmp;
264 GetBitContext payload_gbc;
265
266 5804 while (show_bits(rw, 8) == 0xff) {
267 20 fixed(8, ff_byte, 0xff);
268 20 payload_type += 255;
269 }
270 5784 xu(8, last_payload_type_byte, tmp, 0, 254, 0);
271 5784 payload_type += tmp;
272
273 5803 while (show_bits(rw, 8) == 0xff) {
274 19 fixed(8, ff_byte, 0xff);
275 19 payload_size += 255;
276 }
277 5784 xu(8, last_payload_size_byte, tmp, 0, 254, 0);
278 5784 payload_size += tmp;
279
280 // There must be space remaining for both the payload and
281 // the trailing bits on the SEI NAL unit.
282 5784 if (payload_size + 1 > get_bits_left(rw) / 8) {
283 av_log(ctx->log_ctx, AV_LOG_ERROR,
284 "Invalid SEI message: payload_size too large "
285 "(%"PRIu32" bytes).\n", payload_size);
286 return AVERROR_INVALIDDATA;
287 }
288 5784 CHECK(init_get_bits(&payload_gbc, rw->buffer,
289 get_bits_count(rw) + 8 * payload_size));
290 5784 skip_bits_long(&payload_gbc, get_bits_count(rw));
291
292 5784 CHECK(ff_cbs_sei_list_add(current));
293 5784 message = &current->messages[k];
294
295 5784 message->payload_type = payload_type;
296 5784 message->payload_size = payload_size;
297
298 5784 CHECK(FUNC(message)(ctx, &payload_gbc, message));
299
300 5784 skip_bits_long(rw, 8 * payload_size);
301
302 5784 if (!cbs_h2645_read_more_rbsp_data(rw))
303 5764 break;
304 }
305 #else
306 8534 for (k = 0; k < current->nb_messages; k++) {
307 PutBitContext start_state;
308 uint32_t tmp;
309 int trace, i;
310
311 4277 message = &current->messages[k];
312
313 // We write the payload twice in order to find the size. Trace
314 // output is switched off for the first write.
315 4277 trace = ctx->trace_enable;
316 4277 ctx->trace_enable = 0;
317
318 4277 start_state = *rw;
319 12831 for (i = 0; i < 2; i++) {
320 8554 *rw = start_state;
321
322 8554 tmp = message->payload_type;
323 8594 while (tmp >= 255) {
324 40 fixed(8, ff_byte, 0xff);
325 40 tmp -= 255;
326 }
327 8554 xu(8, last_payload_type_byte, tmp, 0, 254, 0);
328
329 8554 tmp = message->payload_size;
330 8592 while (tmp >= 255) {
331 38 fixed(8, ff_byte, 0xff);
332 38 tmp -= 255;
333 }
334 8554 xu(8, last_payload_size_byte, tmp, 0, 254, 0);
335
336 8554 err = FUNC(message)(ctx, rw, message);
337 8554 ctx->trace_enable = trace;
338 8554 if (err < 0)
339 return err;
340 }
341 }
342 #endif
343
344 10021 return 0;
345 }
346