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 | #include "libavutil/attributes.h" | ||
20 | #include "libavutil/avassert.h" | ||
21 | |||
22 | #include "bytestream.h" | ||
23 | #include "cbs.h" | ||
24 | #include "cbs_internal.h" | ||
25 | #include "cbs_h264.h" | ||
26 | #include "cbs_h265.h" | ||
27 | #include "h264.h" | ||
28 | #include "h2645_parse.h" | ||
29 | #include "hevc.h" | ||
30 | |||
31 | |||
32 | 73240 | static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc, | |
33 | const char *name, const int *subscripts, | ||
34 | uint32_t *write_to, | ||
35 | uint32_t range_min, uint32_t range_max) | ||
36 | { | ||
37 | uint32_t value; | ||
38 | int position, i, j; | ||
39 | unsigned int k; | ||
40 | char bits[65]; | ||
41 | |||
42 | 73240 | position = get_bits_count(gbc); | |
43 | |||
44 |
1/2✓ Branch 0 taken 124496 times.
✗ Branch 1 not taken.
|
124496 | for (i = 0; i < 32; i++) { |
45 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 124496 times.
|
124496 | if (get_bits_left(gbc) < i + 1) { |
46 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at " | |
47 | "%s: bitstream ended.\n", name); | ||
48 | ✗ | return AVERROR_INVALIDDATA; | |
49 | } | ||
50 | 124496 | k = get_bits1(gbc); | |
51 |
2/2✓ Branch 0 taken 73240 times.
✓ Branch 1 taken 51256 times.
|
124496 | bits[i] = k ? '1' : '0'; |
52 |
2/2✓ Branch 0 taken 73240 times.
✓ Branch 1 taken 51256 times.
|
124496 | if (k) |
53 | 73240 | break; | |
54 | } | ||
55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 73240 times.
|
73240 | if (i >= 32) { |
56 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at " | |
57 | "%s: more than 31 zeroes.\n", name); | ||
58 | ✗ | return AVERROR_INVALIDDATA; | |
59 | } | ||
60 | 73240 | value = 1; | |
61 |
2/2✓ Branch 0 taken 51256 times.
✓ Branch 1 taken 73240 times.
|
124496 | for (j = 0; j < i; j++) { |
62 | 51256 | k = get_bits1(gbc); | |
63 |
2/2✓ Branch 0 taken 18410 times.
✓ Branch 1 taken 32846 times.
|
51256 | bits[i + j + 1] = k ? '1' : '0'; |
64 | 51256 | value = value << 1 | k; | |
65 | } | ||
66 | 73240 | bits[i + j + 1] = 0; | |
67 | 73240 | --value; | |
68 | |||
69 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 73240 times.
|
73240 | if (ctx->trace_enable) |
70 | ✗ | ff_cbs_trace_syntax_element(ctx, position, name, subscripts, | |
71 | bits, value); | ||
72 | |||
73 |
2/4✓ Branch 0 taken 73240 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73240 times.
|
73240 | if (value < range_min || value > range_max) { |
74 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
75 | "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n", | ||
76 | name, value, range_min, range_max); | ||
77 | ✗ | return AVERROR_INVALIDDATA; | |
78 | } | ||
79 | |||
80 | 73240 | *write_to = value; | |
81 | 73240 | return 0; | |
82 | } | ||
83 | |||
84 | 77271 | static int cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc, | |
85 | const char *name, const int *subscripts, | ||
86 | int32_t *write_to, | ||
87 | int32_t range_min, int32_t range_max) | ||
88 | { | ||
89 | int32_t value; | ||
90 | int position, i, j; | ||
91 | unsigned int k; | ||
92 | uint32_t v; | ||
93 | char bits[65]; | ||
94 | |||
95 | 77271 | position = get_bits_count(gbc); | |
96 | |||
97 |
1/2✓ Branch 0 taken 272093 times.
✗ Branch 1 not taken.
|
272093 | for (i = 0; i < 32; i++) { |
98 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 272093 times.
|
272093 | if (get_bits_left(gbc) < i + 1) { |
99 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at " | |
100 | "%s: bitstream ended.\n", name); | ||
101 | ✗ | return AVERROR_INVALIDDATA; | |
102 | } | ||
103 | 272093 | k = get_bits1(gbc); | |
104 |
2/2✓ Branch 0 taken 77271 times.
✓ Branch 1 taken 194822 times.
|
272093 | bits[i] = k ? '1' : '0'; |
105 |
2/2✓ Branch 0 taken 77271 times.
✓ Branch 1 taken 194822 times.
|
272093 | if (k) |
106 | 77271 | break; | |
107 | } | ||
108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 77271 times.
|
77271 | if (i >= 32) { |
109 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at " | |
110 | "%s: more than 31 zeroes.\n", name); | ||
111 | ✗ | return AVERROR_INVALIDDATA; | |
112 | } | ||
113 | 77271 | v = 1; | |
114 |
2/2✓ Branch 0 taken 194822 times.
✓ Branch 1 taken 77271 times.
|
272093 | for (j = 0; j < i; j++) { |
115 | 194822 | k = get_bits1(gbc); | |
116 |
2/2✓ Branch 0 taken 86655 times.
✓ Branch 1 taken 108167 times.
|
194822 | bits[i + j + 1] = k ? '1' : '0'; |
117 | 194822 | v = v << 1 | k; | |
118 | } | ||
119 | 77271 | bits[i + j + 1] = 0; | |
120 |
2/2✓ Branch 0 taken 44736 times.
✓ Branch 1 taken 32535 times.
|
77271 | if (v & 1) |
121 | 44736 | value = -(int32_t)(v / 2); | |
122 | else | ||
123 | 32535 | value = v / 2; | |
124 | |||
125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 77271 times.
|
77271 | if (ctx->trace_enable) |
126 | ✗ | ff_cbs_trace_syntax_element(ctx, position, name, subscripts, | |
127 | bits, value); | ||
128 | |||
129 |
2/4✓ Branch 0 taken 77271 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 77271 times.
|
77271 | if (value < range_min || value > range_max) { |
130 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
131 | "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n", | ||
132 | name, value, range_min, range_max); | ||
133 | ✗ | return AVERROR_INVALIDDATA; | |
134 | } | ||
135 | |||
136 | 77271 | *write_to = value; | |
137 | 77271 | return 0; | |
138 | } | ||
139 | |||
140 | 74616 | static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, | |
141 | const char *name, const int *subscripts, | ||
142 | uint32_t value, | ||
143 | uint32_t range_min, uint32_t range_max) | ||
144 | { | ||
145 | int len; | ||
146 | |||
147 |
2/4✓ Branch 0 taken 74616 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 74616 times.
|
74616 | if (value < range_min || value > range_max) { |
148 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
149 | "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n", | ||
150 | name, value, range_min, range_max); | ||
151 | ✗ | return AVERROR_INVALIDDATA; | |
152 | } | ||
153 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 74616 times.
|
74616 | av_assert0(value != UINT32_MAX); |
154 | |||
155 | 74616 | len = av_log2(value + 1); | |
156 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 74616 times.
|
74616 | if (put_bits_left(pbc) < 2 * len + 1) |
157 | ✗ | return AVERROR(ENOSPC); | |
158 | |||
159 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 74616 times.
|
74616 | if (ctx->trace_enable) { |
160 | char bits[65]; | ||
161 | int i; | ||
162 | |||
163 | ✗ | for (i = 0; i < len; i++) | |
164 | ✗ | bits[i] = '0'; | |
165 | ✗ | bits[len] = '1'; | |
166 | ✗ | for (i = 0; i < len; i++) | |
167 | ✗ | bits[len + i + 1] = (value + 1) >> (len - i - 1) & 1 ? '1' : '0'; | |
168 | ✗ | bits[len + len + 1] = 0; | |
169 | |||
170 | ✗ | ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc), | |
171 | name, subscripts, bits, value); | ||
172 | } | ||
173 | |||
174 | 74616 | put_bits(pbc, len, 0); | |
175 |
1/2✓ Branch 0 taken 74616 times.
✗ Branch 1 not taken.
|
74616 | if (len + 1 < 32) |
176 | 74616 | put_bits(pbc, len + 1, value + 1); | |
177 | else | ||
178 | ✗ | put_bits32(pbc, value + 1); | |
179 | |||
180 | 74616 | return 0; | |
181 | } | ||
182 | |||
183 | 77295 | static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, | |
184 | const char *name, const int *subscripts, | ||
185 | int32_t value, | ||
186 | int32_t range_min, int32_t range_max) | ||
187 | { | ||
188 | int len; | ||
189 | uint32_t uvalue; | ||
190 | |||
191 |
2/4✓ Branch 0 taken 77295 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 77295 times.
|
77295 | if (value < range_min || value > range_max) { |
192 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
193 | "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n", | ||
194 | name, value, range_min, range_max); | ||
195 | ✗ | return AVERROR_INVALIDDATA; | |
196 | } | ||
197 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 77295 times.
|
77295 | av_assert0(value != INT32_MIN); |
198 | |||
199 |
2/2✓ Branch 0 taken 17899 times.
✓ Branch 1 taken 59396 times.
|
77295 | if (value == 0) |
200 | 17899 | uvalue = 0; | |
201 |
2/2✓ Branch 0 taken 32637 times.
✓ Branch 1 taken 26759 times.
|
59396 | else if (value > 0) |
202 | 32637 | uvalue = 2 * (uint32_t)value - 1; | |
203 | else | ||
204 | 26759 | uvalue = 2 * (uint32_t)-value; | |
205 | |||
206 | 77295 | len = av_log2(uvalue + 1); | |
207 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 77295 times.
|
77295 | if (put_bits_left(pbc) < 2 * len + 1) |
208 | ✗ | return AVERROR(ENOSPC); | |
209 | |||
210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 77295 times.
|
77295 | if (ctx->trace_enable) { |
211 | char bits[65]; | ||
212 | int i; | ||
213 | |||
214 | ✗ | for (i = 0; i < len; i++) | |
215 | ✗ | bits[i] = '0'; | |
216 | ✗ | bits[len] = '1'; | |
217 | ✗ | for (i = 0; i < len; i++) | |
218 | ✗ | bits[len + i + 1] = (uvalue + 1) >> (len - i - 1) & 1 ? '1' : '0'; | |
219 | ✗ | bits[len + len + 1] = 0; | |
220 | |||
221 | ✗ | ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc), | |
222 | name, subscripts, bits, value); | ||
223 | } | ||
224 | |||
225 | 77295 | put_bits(pbc, len, 0); | |
226 |
1/2✓ Branch 0 taken 77295 times.
✗ Branch 1 not taken.
|
77295 | if (len + 1 < 32) |
227 | 77295 | put_bits(pbc, len + 1, uvalue + 1); | |
228 | else | ||
229 | ✗ | put_bits32(pbc, uvalue + 1); | |
230 | |||
231 | 77295 | return 0; | |
232 | } | ||
233 | |||
234 | // payload_extension_present() - true if we are before the last 1-bit | ||
235 | // in the payload structure, which must be in the last byte. | ||
236 | 5 | static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t payload_size, | |
237 | int cur_pos) | ||
238 | { | ||
239 | 5 | int bits_left = payload_size * 8 - cur_pos; | |
240 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
5 | return (bits_left > 0 && |
241 | ✗ | (bits_left > 7 || show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1))); | |
242 | } | ||
243 | |||
244 | #define HEADER(name) do { \ | ||
245 | ff_cbs_trace_header(ctx, name); \ | ||
246 | } while (0) | ||
247 | |||
248 | #define CHECK(call) do { \ | ||
249 | err = (call); \ | ||
250 | if (err < 0) \ | ||
251 | return err; \ | ||
252 | } while (0) | ||
253 | |||
254 | #define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name | ||
255 | #define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name) | ||
256 | #define FUNC_H264(name) FUNC_NAME1(READWRITE, h264, name) | ||
257 | #define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name) | ||
258 | #define FUNC_SEI(name) FUNC_NAME1(READWRITE, sei, name) | ||
259 | |||
260 | #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) | ||
261 | |||
262 | #define u(width, name, range_min, range_max) \ | ||
263 | xu(width, name, current->name, range_min, range_max, 0, ) | ||
264 | #define ub(width, name) \ | ||
265 | xu(width, name, current->name, 0, MAX_UINT_BITS(width), 0, ) | ||
266 | #define flag(name) ub(1, name) | ||
267 | #define ue(name, range_min, range_max) \ | ||
268 | xue(name, current->name, range_min, range_max, 0, ) | ||
269 | #define i(width, name, range_min, range_max) \ | ||
270 | xi(width, name, current->name, range_min, range_max, 0, ) | ||
271 | #define ib(width, name) \ | ||
272 | xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, ) | ||
273 | #define se(name, range_min, range_max) \ | ||
274 | xse(name, current->name, range_min, range_max, 0, ) | ||
275 | |||
276 | #define us(width, name, range_min, range_max, subs, ...) \ | ||
277 | xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__) | ||
278 | #define ubs(width, name, subs, ...) \ | ||
279 | xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__) | ||
280 | #define flags(name, subs, ...) \ | ||
281 | xu(1, name, current->name, 0, 1, subs, __VA_ARGS__) | ||
282 | #define ues(name, range_min, range_max, subs, ...) \ | ||
283 | xue(name, current->name, range_min, range_max, subs, __VA_ARGS__) | ||
284 | #define is(width, name, range_min, range_max, subs, ...) \ | ||
285 | xi(width, name, current->name, range_min, range_max, subs, __VA_ARGS__) | ||
286 | #define ibs(width, name, subs, ...) \ | ||
287 | xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), subs, __VA_ARGS__) | ||
288 | #define ses(name, range_min, range_max, subs, ...) \ | ||
289 | xse(name, current->name, range_min, range_max, subs, __VA_ARGS__) | ||
290 | |||
291 | #define fixed(width, name, value) do { \ | ||
292 | av_unused uint32_t fixed_value = value; \ | ||
293 | xu(width, name, fixed_value, value, value, 0, ); \ | ||
294 | } while (0) | ||
295 | |||
296 | |||
297 | #define READ | ||
298 | #define READWRITE read | ||
299 | #define RWContext GetBitContext | ||
300 | |||
301 | #define xu(width, name, var, range_min, range_max, subs, ...) do { \ | ||
302 | uint32_t value; \ | ||
303 | CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \ | ||
304 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
305 | &value, range_min, range_max)); \ | ||
306 | var = value; \ | ||
307 | } while (0) | ||
308 | #define xue(name, var, range_min, range_max, subs, ...) do { \ | ||
309 | uint32_t value; \ | ||
310 | CHECK(cbs_read_ue_golomb(ctx, rw, #name, \ | ||
311 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
312 | &value, range_min, range_max)); \ | ||
313 | var = value; \ | ||
314 | } while (0) | ||
315 | #define xi(width, name, var, range_min, range_max, subs, ...) do { \ | ||
316 | int32_t value; \ | ||
317 | CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \ | ||
318 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
319 | &value, range_min, range_max)); \ | ||
320 | var = value; \ | ||
321 | } while (0) | ||
322 | #define xse(name, var, range_min, range_max, subs, ...) do { \ | ||
323 | int32_t value; \ | ||
324 | CHECK(cbs_read_se_golomb(ctx, rw, #name, \ | ||
325 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
326 | &value, range_min, range_max)); \ | ||
327 | var = value; \ | ||
328 | } while (0) | ||
329 | |||
330 | |||
331 | #define infer(name, value) do { \ | ||
332 | current->name = value; \ | ||
333 | } while (0) | ||
334 | |||
335 | 14740 | static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) | |
336 | { | ||
337 | 14740 | int bits_left = get_bits_left(gbc); | |
338 |
2/2✓ Branch 0 taken 11354 times.
✓ Branch 1 taken 3386 times.
|
14740 | if (bits_left > 8) |
339 | 11354 | return 1; | |
340 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3386 times.
|
3386 | if (bits_left == 0) |
341 | ✗ | return 0; | |
342 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3383 times.
|
3386 | if (show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1)) |
343 | 3 | return 1; | |
344 | 3383 | return 0; | |
345 | } | ||
346 | |||
347 | #define more_rbsp_data(var) ((var) = cbs_h2645_read_more_rbsp_data(rw)) | ||
348 | |||
349 | #define bit_position(rw) (get_bits_count(rw)) | ||
350 | #define byte_alignment(rw) (get_bits_count(rw) % 8) | ||
351 | |||
352 | #define allocate(name, size) do { \ | ||
353 | name ## _ref = av_buffer_allocz(size + \ | ||
354 | AV_INPUT_BUFFER_PADDING_SIZE); \ | ||
355 | if (!name ## _ref) \ | ||
356 | return AVERROR(ENOMEM); \ | ||
357 | name = name ## _ref->data; \ | ||
358 | } while (0) | ||
359 | |||
360 | #define FUNC(name) FUNC_SEI(name) | ||
361 | #include "cbs_sei_syntax_template.c" | ||
362 | #undef FUNC | ||
363 | |||
364 | #define FUNC(name) FUNC_H264(name) | ||
365 | #include "cbs_h264_syntax_template.c" | ||
366 | #undef FUNC | ||
367 | |||
368 | #define FUNC(name) FUNC_H265(name) | ||
369 | #include "cbs_h265_syntax_template.c" | ||
370 | #undef FUNC | ||
371 | |||
372 | #undef READ | ||
373 | #undef READWRITE | ||
374 | #undef RWContext | ||
375 | #undef xu | ||
376 | #undef xi | ||
377 | #undef xue | ||
378 | #undef xse | ||
379 | #undef infer | ||
380 | #undef more_rbsp_data | ||
381 | #undef bit_position | ||
382 | #undef byte_alignment | ||
383 | #undef allocate | ||
384 | |||
385 | |||
386 | #define WRITE | ||
387 | #define READWRITE write | ||
388 | #define RWContext PutBitContext | ||
389 | |||
390 | #define xu(width, name, var, range_min, range_max, subs, ...) do { \ | ||
391 | uint32_t value = var; \ | ||
392 | CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \ | ||
393 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
394 | value, range_min, range_max)); \ | ||
395 | } while (0) | ||
396 | #define xue(name, var, range_min, range_max, subs, ...) do { \ | ||
397 | uint32_t value = var; \ | ||
398 | CHECK(cbs_write_ue_golomb(ctx, rw, #name, \ | ||
399 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
400 | value, range_min, range_max)); \ | ||
401 | } while (0) | ||
402 | #define xi(width, name, var, range_min, range_max, subs, ...) do { \ | ||
403 | int32_t value = var; \ | ||
404 | CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \ | ||
405 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
406 | value, range_min, range_max)); \ | ||
407 | } while (0) | ||
408 | #define xse(name, var, range_min, range_max, subs, ...) do { \ | ||
409 | int32_t value = var; \ | ||
410 | CHECK(cbs_write_se_golomb(ctx, rw, #name, \ | ||
411 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
412 | value, range_min, range_max)); \ | ||
413 | } while (0) | ||
414 | |||
415 | #define infer(name, value) do { \ | ||
416 | if (current->name != (value)) { \ | ||
417 | av_log(ctx->log_ctx, AV_LOG_ERROR, \ | ||
418 | "%s does not match inferred value: " \ | ||
419 | "%"PRId64", but should be %"PRId64".\n", \ | ||
420 | #name, (int64_t)current->name, (int64_t)(value)); \ | ||
421 | return AVERROR_INVALIDDATA; \ | ||
422 | } \ | ||
423 | } while (0) | ||
424 | |||
425 | #define more_rbsp_data(var) (var) | ||
426 | |||
427 | #define bit_position(rw) (put_bits_count(rw)) | ||
428 | #define byte_alignment(rw) (put_bits_count(rw) % 8) | ||
429 | |||
430 | #define allocate(name, size) do { \ | ||
431 | if (!name) { \ | ||
432 | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s must be set " \ | ||
433 | "for writing.\n", #name); \ | ||
434 | return AVERROR_INVALIDDATA; \ | ||
435 | } \ | ||
436 | } while (0) | ||
437 | |||
438 | #define FUNC(name) FUNC_SEI(name) | ||
439 | #include "cbs_sei_syntax_template.c" | ||
440 | #undef FUNC | ||
441 | |||
442 | #define FUNC(name) FUNC_H264(name) | ||
443 | #include "cbs_h264_syntax_template.c" | ||
444 | #undef FUNC | ||
445 | |||
446 | #define FUNC(name) FUNC_H265(name) | ||
447 | #include "cbs_h265_syntax_template.c" | ||
448 | #undef FUNC | ||
449 | |||
450 | #undef WRITE | ||
451 | #undef READWRITE | ||
452 | #undef RWContext | ||
453 | #undef xu | ||
454 | #undef xi | ||
455 | #undef xue | ||
456 | #undef xse | ||
457 | #undef u | ||
458 | #undef i | ||
459 | #undef flag | ||
460 | #undef ue | ||
461 | #undef se | ||
462 | #undef infer | ||
463 | #undef more_rbsp_data | ||
464 | #undef bit_position | ||
465 | #undef byte_alignment | ||
466 | #undef allocate | ||
467 | |||
468 | |||
469 | 4979 | static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, | |
470 | CodedBitstreamFragment *frag, | ||
471 | const H2645Packet *packet) | ||
472 | { | ||
473 | int err, i; | ||
474 | |||
475 |
2/2✓ Branch 0 taken 15494 times.
✓ Branch 1 taken 4979 times.
|
20473 | for (i = 0; i < packet->nb_nals; i++) { |
476 | 15494 | const H2645NAL *nal = &packet->nals[i]; | |
477 | AVBufferRef *ref; | ||
478 | 15494 | size_t size = nal->size; | |
479 | |||
480 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15494 times.
|
15494 | if (nal->nuh_layer_id > 0) |
481 | ✗ | continue; | |
482 | |||
483 | // Remove trailing zeroes. | ||
484 |
3/4✓ Branch 0 taken 23790 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8296 times.
✓ Branch 3 taken 15494 times.
|
23790 | while (size > 0 && nal->data[size - 1] == 0) |
485 | 8296 | --size; | |
486 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15494 times.
|
15494 | if (size == 0) { |
487 | ✗ | av_log(ctx->log_ctx, AV_LOG_VERBOSE, "Discarding empty 0 NAL unit\n"); | |
488 | ✗ | continue; | |
489 | } | ||
490 | |||
491 | 30988 | ref = (nal->data == nal->raw_data) ? frag->data_ref | |
492 |
2/2✓ Branch 0 taken 9276 times.
✓ Branch 1 taken 6218 times.
|
15494 | : packet->rbsp.rbsp_buffer_ref; |
493 | |||
494 | 15494 | err = ff_cbs_append_unit_data(frag, nal->type, | |
495 | 15494 | (uint8_t*)nal->data, size, ref); | |
496 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15494 times.
|
15494 | if (err < 0) |
497 | ✗ | return err; | |
498 | } | ||
499 | |||
500 | 4979 | return 0; | |
501 | } | ||
502 | |||
503 | 4974 | static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, | |
504 | CodedBitstreamFragment *frag, | ||
505 | int header) | ||
506 | { | ||
507 | 4974 | enum AVCodecID codec_id = ctx->codec->codec_id; | |
508 | 4974 | CodedBitstreamH2645Context *priv = ctx->priv_data; | |
509 | GetByteContext gbc; | ||
510 | int err; | ||
511 | |||
512 |
2/4✓ Branch 0 taken 4974 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4974 times.
|
4974 | av_assert0(frag->data && frag->nb_units == 0); |
513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4974 times.
|
4974 | if (frag->data_size == 0) |
514 | ✗ | return 0; | |
515 | |||
516 |
5/6✓ Branch 0 taken 42 times.
✓ Branch 1 taken 4932 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 37 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
4979 | if (header && frag->data[0] && codec_id == AV_CODEC_ID_H264) { |
517 | // AVCC header. | ||
518 | size_t size, start, end; | ||
519 | int i, count, version; | ||
520 | |||
521 | 5 | priv->mp4 = 1; | |
522 | |||
523 | 5 | bytestream2_init(&gbc, frag->data, frag->data_size); | |
524 | |||
525 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
|
5 | if (bytestream2_get_bytes_left(&gbc) < 6) |
526 | ✗ | return AVERROR_INVALIDDATA; | |
527 | |||
528 | 5 | version = bytestream2_get_byte(&gbc); | |
529 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (version != 1) { |
530 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid AVCC header: " | |
531 | "first byte %u.\n", version); | ||
532 | ✗ | return AVERROR_INVALIDDATA; | |
533 | } | ||
534 | |||
535 | 5 | bytestream2_skip(&gbc, 3); | |
536 | 5 | priv->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1; | |
537 | |||
538 | // SPS array. | ||
539 | 5 | count = bytestream2_get_byte(&gbc) & 0x1f; | |
540 | 5 | start = bytestream2_tell(&gbc); | |
541 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
|
9 | for (i = 0; i < count; i++) { |
542 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i)) |
543 | ✗ | return AVERROR_INVALIDDATA; | |
544 | 4 | size = bytestream2_get_be16(&gbc); | |
545 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (bytestream2_get_bytes_left(&gbc) < size) |
546 | ✗ | return AVERROR_INVALIDDATA; | |
547 | 4 | bytestream2_skip(&gbc, size); | |
548 | } | ||
549 | 5 | end = bytestream2_tell(&gbc); | |
550 | |||
551 | 5 | err = ff_h2645_packet_split(&priv->read_packet, | |
552 | 5 | frag->data + start, end - start, | |
553 | ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); | ||
554 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (err < 0) { |
555 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n"); | |
556 | ✗ | return err; | |
557 | } | ||
558 | 5 | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
559 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (err < 0) |
560 | ✗ | return err; | |
561 | |||
562 | // PPS array. | ||
563 | 5 | count = bytestream2_get_byte(&gbc); | |
564 | 5 | start = bytestream2_tell(&gbc); | |
565 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
|
9 | for (i = 0; i < count; i++) { |
566 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i)) |
567 | ✗ | return AVERROR_INVALIDDATA; | |
568 | 4 | size = bytestream2_get_be16(&gbc); | |
569 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (bytestream2_get_bytes_left(&gbc) < size) |
570 | ✗ | return AVERROR_INVALIDDATA; | |
571 | 4 | bytestream2_skip(&gbc, size); | |
572 | } | ||
573 | 5 | end = bytestream2_tell(&gbc); | |
574 | |||
575 | 5 | err = ff_h2645_packet_split(&priv->read_packet, | |
576 | 5 | frag->data + start, end - start, | |
577 | ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); | ||
578 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (err < 0) { |
579 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n"); | |
580 | ✗ | return err; | |
581 | } | ||
582 | 5 | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
583 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (err < 0) |
584 | ✗ | return err; | |
585 | |||
586 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3 times.
|
5 | if (bytestream2_get_bytes_left(&gbc) > 0) { |
587 | 2 | av_log(ctx->log_ctx, AV_LOG_WARNING, "%u bytes left at end of AVCC " | |
588 | "header.\n", bytestream2_get_bytes_left(&gbc)); | ||
589 | } | ||
590 | |||
591 |
3/6✓ Branch 0 taken 37 times.
✓ Branch 1 taken 4932 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 37 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
4969 | } else if (header && frag->data[0] && codec_id == AV_CODEC_ID_HEVC) { |
592 | // HVCC header. | ||
593 | size_t size, start, end; | ||
594 | int i, j, nb_arrays, nal_unit_type, nb_nals, version; | ||
595 | |||
596 | ✗ | priv->mp4 = 1; | |
597 | |||
598 | ✗ | bytestream2_init(&gbc, frag->data, frag->data_size); | |
599 | |||
600 | ✗ | if (bytestream2_get_bytes_left(&gbc) < 23) | |
601 | ✗ | return AVERROR_INVALIDDATA; | |
602 | |||
603 | ✗ | version = bytestream2_get_byte(&gbc); | |
604 | ✗ | if (version != 1) { | |
605 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid HVCC header: " | |
606 | "first byte %u.\n", version); | ||
607 | ✗ | return AVERROR_INVALIDDATA; | |
608 | } | ||
609 | |||
610 | ✗ | bytestream2_skip(&gbc, 20); | |
611 | ✗ | priv->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1; | |
612 | |||
613 | ✗ | nb_arrays = bytestream2_get_byte(&gbc); | |
614 | ✗ | for (i = 0; i < nb_arrays; i++) { | |
615 | ✗ | nal_unit_type = bytestream2_get_byte(&gbc) & 0x3f; | |
616 | ✗ | nb_nals = bytestream2_get_be16(&gbc); | |
617 | |||
618 | ✗ | start = bytestream2_tell(&gbc); | |
619 | ✗ | for (j = 0; j < nb_nals; j++) { | |
620 | ✗ | if (bytestream2_get_bytes_left(&gbc) < 2) | |
621 | ✗ | return AVERROR_INVALIDDATA; | |
622 | ✗ | size = bytestream2_get_be16(&gbc); | |
623 | ✗ | if (bytestream2_get_bytes_left(&gbc) < size) | |
624 | ✗ | return AVERROR_INVALIDDATA; | |
625 | ✗ | bytestream2_skip(&gbc, size); | |
626 | } | ||
627 | ✗ | end = bytestream2_tell(&gbc); | |
628 | |||
629 | ✗ | err = ff_h2645_packet_split(&priv->read_packet, | |
630 | ✗ | frag->data + start, end - start, | |
631 | ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 1); | ||
632 | ✗ | if (err < 0) { | |
633 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " | |
634 | "HVCC array %d (%d NAL units of type %d).\n", | ||
635 | i, nb_nals, nal_unit_type); | ||
636 | ✗ | return err; | |
637 | } | ||
638 | ✗ | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
639 | ✗ | if (err < 0) | |
640 | ✗ | return err; | |
641 | } | ||
642 | |||
643 | } else { | ||
644 | // Annex B, or later MP4 with already-known parameters. | ||
645 | |||
646 | 4969 | err = ff_h2645_packet_split(&priv->read_packet, | |
647 | 4969 | frag->data, frag->data_size, | |
648 | ctx->log_ctx, | ||
649 | priv->mp4, priv->nal_length_size, | ||
650 | codec_id, 1, 1); | ||
651 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4969 times.
|
4969 | if (err < 0) |
652 | ✗ | return err; | |
653 | |||
654 | 4969 | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
655 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4969 times.
|
4969 | if (err < 0) |
656 | ✗ | return err; | |
657 | } | ||
658 | |||
659 | 4974 | return 0; | |
660 | } | ||
661 | |||
662 | #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \ | ||
663 | static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \ | ||
664 | CodedBitstreamUnit *unit) \ | ||
665 | { \ | ||
666 | CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \ | ||
667 | H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \ | ||
668 | unsigned int id = ps_var->id_element; \ | ||
669 | int err = ff_cbs_make_unit_refcounted(ctx, unit); \ | ||
670 | if (err < 0) \ | ||
671 | return err; \ | ||
672 | if (priv->ps_var[id] == priv->active_ ## ps_var) \ | ||
673 | priv->active_ ## ps_var = NULL ; \ | ||
674 | av_buffer_unref(&priv->ps_var ## _ref[id]); \ | ||
675 | av_assert0(unit->content_ref); \ | ||
676 | priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \ | ||
677 | if (!priv->ps_var ## _ref[id]) \ | ||
678 | return AVERROR(ENOMEM); \ | ||
679 | priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \ | ||
680 | return 0; \ | ||
681 | } | ||
682 | |||
683 |
5/8✗ Branch 1 not taken.
✓ Branch 2 taken 138 times.
✓ Branch 3 taken 102 times.
✓ Branch 4 taken 36 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 138 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 138 times.
|
138 | cbs_h2645_replace_ps(4, SPS, sps, seq_parameter_set_id) |
684 |
5/8✗ Branch 1 not taken.
✓ Branch 2 taken 2982 times.
✓ Branch 3 taken 2932 times.
✓ Branch 4 taken 50 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2982 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2982 times.
|
2982 | cbs_h2645_replace_ps(4, PPS, pps, pic_parameter_set_id) |
685 |
4/8✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 96 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 96 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 96 times.
|
96 | cbs_h2645_replace_ps(5, VPS, vps, vps_video_parameter_set_id) |
686 |
5/8✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 98 times.
✓ Branch 4 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 100 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 100 times.
|
100 | cbs_h2645_replace_ps(5, SPS, sps, sps_seq_parameter_set_id) |
687 |
5/8✗ Branch 1 not taken.
✓ Branch 2 taken 550 times.
✓ Branch 3 taken 378 times.
✓ Branch 4 taken 172 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 550 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 550 times.
|
550 | cbs_h2645_replace_ps(5, PPS, pps, pps_pic_parameter_set_id) |
688 | |||
689 | 7662 | static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, | |
690 | CodedBitstreamUnit *unit) | ||
691 | { | ||
692 | GetBitContext gbc; | ||
693 | int err; | ||
694 | |||
695 | 7662 | err = init_get_bits(&gbc, unit->data, 8 * unit->data_size); | |
696 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7662 times.
|
7662 | if (err < 0) |
697 | ✗ | return err; | |
698 | |||
699 | 7662 | err = ff_cbs_alloc_unit_content(ctx, unit); | |
700 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7662 times.
|
7662 | if (err < 0) |
701 | ✗ | return err; | |
702 | |||
703 |
7/9✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1491 times.
✓ Branch 3 taken 5469 times.
✓ Branch 4 taken 235 times.
✓ Branch 5 taken 361 times.
✓ Branch 6 taken 34 times.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
7662 | switch (unit->type) { |
704 | 69 | case H264_NAL_SPS: | |
705 | { | ||
706 | 69 | H264RawSPS *sps = unit->content; | |
707 | |||
708 | 69 | err = cbs_h264_read_sps(ctx, &gbc, sps); | |
709 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
|
69 | if (err < 0) |
710 | ✗ | return err; | |
711 | |||
712 | 69 | err = cbs_h264_replace_sps(ctx, unit); | |
713 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
|
69 | if (err < 0) |
714 | ✗ | return err; | |
715 | } | ||
716 | 69 | break; | |
717 | |||
718 | ✗ | case H264_NAL_SPS_EXT: | |
719 | { | ||
720 | ✗ | err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content); | |
721 | ✗ | if (err < 0) | |
722 | ✗ | return err; | |
723 | } | ||
724 | ✗ | break; | |
725 | |||
726 | 1491 | case H264_NAL_PPS: | |
727 | { | ||
728 | 1491 | H264RawPPS *pps = unit->content; | |
729 | |||
730 | 1491 | err = cbs_h264_read_pps(ctx, &gbc, pps); | |
731 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1491 times.
|
1491 | if (err < 0) |
732 | ✗ | return err; | |
733 | |||
734 | 1491 | err = cbs_h264_replace_pps(ctx, unit); | |
735 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1491 times.
|
1491 | if (err < 0) |
736 | ✗ | return err; | |
737 | } | ||
738 | 1491 | break; | |
739 | |||
740 | 5469 | case H264_NAL_SLICE: | |
741 | case H264_NAL_IDR_SLICE: | ||
742 | case H264_NAL_AUXILIARY_SLICE: | ||
743 | { | ||
744 | 5469 | H264RawSlice *slice = unit->content; | |
745 | int pos, len; | ||
746 | |||
747 | 5469 | err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header); | |
748 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5469 times.
|
5469 | if (err < 0) |
749 | ✗ | return err; | |
750 | |||
751 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5469 times.
|
5469 | if (!cbs_h2645_read_more_rbsp_data(&gbc)) |
752 | ✗ | return AVERROR_INVALIDDATA; | |
753 | |||
754 | 5469 | pos = get_bits_count(&gbc); | |
755 | 5469 | len = unit->data_size; | |
756 | |||
757 | 5469 | slice->data_size = len - pos / 8; | |
758 | 5469 | slice->data_ref = av_buffer_ref(unit->data_ref); | |
759 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5469 times.
|
5469 | if (!slice->data_ref) |
760 | ✗ | return AVERROR(ENOMEM); | |
761 | 5469 | slice->data = unit->data + pos / 8; | |
762 | 5469 | slice->data_bit_start = pos % 8; | |
763 | } | ||
764 | 5469 | break; | |
765 | |||
766 | 235 | case H264_NAL_AUD: | |
767 | { | ||
768 | 235 | err = cbs_h264_read_aud(ctx, &gbc, unit->content); | |
769 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 235 times.
|
235 | if (err < 0) |
770 | ✗ | return err; | |
771 | } | ||
772 | 235 | break; | |
773 | |||
774 | 361 | case H264_NAL_SEI: | |
775 | { | ||
776 | 361 | err = cbs_h264_read_sei(ctx, &gbc, unit->content); | |
777 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 361 times.
|
361 | if (err < 0) |
778 | ✗ | return err; | |
779 | } | ||
780 | 361 | break; | |
781 | |||
782 | 34 | case H264_NAL_FILLER_DATA: | |
783 | { | ||
784 | 34 | err = cbs_h264_read_filler(ctx, &gbc, unit->content); | |
785 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 33 times.
|
34 | if (err < 0) |
786 | 1 | return err; | |
787 | } | ||
788 | 33 | break; | |
789 | |||
790 | 3 | case H264_NAL_END_SEQUENCE: | |
791 | case H264_NAL_END_STREAM: | ||
792 | { | ||
793 | 3 | err = (unit->type == H264_NAL_END_SEQUENCE ? | |
794 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | cbs_h264_read_end_of_sequence : |
795 | 3 | cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content); | |
796 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (err < 0) |
797 | ✗ | return err; | |
798 | } | ||
799 | 3 | break; | |
800 | |||
801 | ✗ | default: | |
802 | ✗ | return AVERROR(ENOSYS); | |
803 | } | ||
804 | |||
805 | 7661 | return 0; | |
806 | } | ||
807 | |||
808 | 7832 | static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, | |
809 | CodedBitstreamUnit *unit) | ||
810 | { | ||
811 | GetBitContext gbc; | ||
812 | int err; | ||
813 | |||
814 | 7832 | err = init_get_bits(&gbc, unit->data, 8 * unit->data_size); | |
815 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7832 times.
|
7832 | if (err < 0) |
816 | ✗ | return err; | |
817 | |||
818 | 7832 | err = ff_cbs_alloc_unit_content(ctx, unit); | |
819 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7832 times.
|
7832 | if (err < 0) |
820 | ✗ | return err; | |
821 | |||
822 |
6/7✓ Branch 0 taken 48 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 275 times.
✓ Branch 3 taken 5864 times.
✓ Branch 4 taken 60 times.
✓ Branch 5 taken 1535 times.
✗ Branch 6 not taken.
|
7832 | switch (unit->type) { |
823 | 48 | case HEVC_NAL_VPS: | |
824 | { | ||
825 | 48 | H265RawVPS *vps = unit->content; | |
826 | |||
827 | 48 | err = cbs_h265_read_vps(ctx, &gbc, vps); | |
828 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (err < 0) |
829 | ✗ | return err; | |
830 | |||
831 | 48 | err = cbs_h265_replace_vps(ctx, unit); | |
832 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (err < 0) |
833 | ✗ | return err; | |
834 | } | ||
835 | 48 | break; | |
836 | 50 | case HEVC_NAL_SPS: | |
837 | { | ||
838 | 50 | H265RawSPS *sps = unit->content; | |
839 | |||
840 | 50 | err = cbs_h265_read_sps(ctx, &gbc, sps); | |
841 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
|
50 | if (err < 0) |
842 | ✗ | return err; | |
843 | |||
844 | 50 | err = cbs_h265_replace_sps(ctx, unit); | |
845 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
|
50 | if (err < 0) |
846 | ✗ | return err; | |
847 | } | ||
848 | 50 | break; | |
849 | |||
850 | 275 | case HEVC_NAL_PPS: | |
851 | { | ||
852 | 275 | H265RawPPS *pps = unit->content; | |
853 | |||
854 | 275 | err = cbs_h265_read_pps(ctx, &gbc, pps); | |
855 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 275 times.
|
275 | if (err < 0) |
856 | ✗ | return err; | |
857 | |||
858 | 275 | err = cbs_h265_replace_pps(ctx, unit); | |
859 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 275 times.
|
275 | if (err < 0) |
860 | ✗ | return err; | |
861 | } | ||
862 | 275 | break; | |
863 | |||
864 | 5864 | case HEVC_NAL_TRAIL_N: | |
865 | case HEVC_NAL_TRAIL_R: | ||
866 | case HEVC_NAL_TSA_N: | ||
867 | case HEVC_NAL_TSA_R: | ||
868 | case HEVC_NAL_STSA_N: | ||
869 | case HEVC_NAL_STSA_R: | ||
870 | case HEVC_NAL_RADL_N: | ||
871 | case HEVC_NAL_RADL_R: | ||
872 | case HEVC_NAL_RASL_N: | ||
873 | case HEVC_NAL_RASL_R: | ||
874 | case HEVC_NAL_BLA_W_LP: | ||
875 | case HEVC_NAL_BLA_W_RADL: | ||
876 | case HEVC_NAL_BLA_N_LP: | ||
877 | case HEVC_NAL_IDR_W_RADL: | ||
878 | case HEVC_NAL_IDR_N_LP: | ||
879 | case HEVC_NAL_CRA_NUT: | ||
880 | { | ||
881 | 5864 | H265RawSlice *slice = unit->content; | |
882 | int pos, len; | ||
883 | |||
884 | 5864 | err = cbs_h265_read_slice_segment_header(ctx, &gbc, &slice->header); | |
885 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5864 times.
|
5864 | if (err < 0) |
886 | ✗ | return err; | |
887 | |||
888 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5864 times.
|
5864 | if (!cbs_h2645_read_more_rbsp_data(&gbc)) |
889 | ✗ | return AVERROR_INVALIDDATA; | |
890 | |||
891 | 5864 | pos = get_bits_count(&gbc); | |
892 | 5864 | len = unit->data_size; | |
893 | |||
894 | 5864 | slice->data_size = len - pos / 8; | |
895 | 5864 | slice->data_ref = av_buffer_ref(unit->data_ref); | |
896 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5864 times.
|
5864 | if (!slice->data_ref) |
897 | ✗ | return AVERROR(ENOMEM); | |
898 | 5864 | slice->data = unit->data + pos / 8; | |
899 | 5864 | slice->data_bit_start = pos % 8; | |
900 | } | ||
901 | 5864 | break; | |
902 | |||
903 | 60 | case HEVC_NAL_AUD: | |
904 | { | ||
905 | 60 | err = cbs_h265_read_aud(ctx, &gbc, unit->content); | |
906 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | if (err < 0) |
907 | ✗ | return err; | |
908 | } | ||
909 | 60 | break; | |
910 | |||
911 | 1535 | case HEVC_NAL_SEI_PREFIX: | |
912 | case HEVC_NAL_SEI_SUFFIX: | ||
913 | { | ||
914 | 1535 | err = cbs_h265_read_sei(ctx, &gbc, unit->content, | |
915 | 1535 | unit->type == HEVC_NAL_SEI_PREFIX); | |
916 | |||
917 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1535 times.
|
1535 | if (err < 0) |
918 | ✗ | return err; | |
919 | } | ||
920 | 1535 | break; | |
921 | |||
922 | ✗ | default: | |
923 | ✗ | return AVERROR(ENOSYS); | |
924 | } | ||
925 | |||
926 | 7832 | return 0; | |
927 | } | ||
928 | |||
929 | 11332 | static int cbs_h2645_write_slice_data(CodedBitstreamContext *ctx, | |
930 | PutBitContext *pbc, const uint8_t *data, | ||
931 | size_t data_size, int data_bit_start) | ||
932 | { | ||
933 | 11332 | size_t rest = data_size - (data_bit_start + 7) / 8; | |
934 | 11332 | const uint8_t *pos = data + data_bit_start / 8; | |
935 | |||
936 |
2/4✓ Branch 0 taken 11332 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11332 times.
|
11332 | av_assert0(data_bit_start >= 0 && |
937 | data_size > data_bit_start / 8); | ||
938 | |||
939 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11332 times.
|
11332 | if (data_size * 8 + 8 > put_bits_left(pbc)) |
940 | ✗ | return AVERROR(ENOSPC); | |
941 | |||
942 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11331 times.
|
11332 | if (!rest) |
943 | 1 | goto rbsp_stop_one_bit; | |
944 | |||
945 | // First copy the remaining bits of the first byte | ||
946 | // The above check ensures that we do not accidentally | ||
947 | // copy beyond the rbsp_stop_one_bit. | ||
948 |
2/2✓ Branch 0 taken 3729 times.
✓ Branch 1 taken 7602 times.
|
11331 | if (data_bit_start % 8) |
949 | 3729 | put_bits(pbc, 8 - data_bit_start % 8, | |
950 | 3729 | *pos++ & MAX_UINT_BITS(8 - data_bit_start % 8)); | |
951 | |||
952 |
2/2✓ Branch 1 taken 11222 times.
✓ Branch 2 taken 109 times.
|
11331 | if (put_bits_count(pbc) % 8 == 0) { |
953 | // If the writer is aligned at this point, | ||
954 | // memcpy can be used to improve performance. | ||
955 | // This happens normally for CABAC. | ||
956 | 11222 | flush_put_bits(pbc); | |
957 | 11222 | memcpy(put_bits_ptr(pbc), pos, rest); | |
958 | 11222 | skip_put_bytes(pbc, rest); | |
959 | } else { | ||
960 | // If not, we have to copy manually. | ||
961 | // rbsp_stop_one_bit forces us to special-case | ||
962 | // the last byte. | ||
963 | uint8_t temp; | ||
964 | int i; | ||
965 | |||
966 |
2/2✓ Branch 0 taken 98762 times.
✓ Branch 1 taken 109 times.
|
98871 | for (; rest > 4; rest -= 4, pos += 4) |
967 | 98762 | put_bits32(pbc, AV_RB32(pos)); | |
968 | |||
969 |
2/2✓ Branch 0 taken 165 times.
✓ Branch 1 taken 109 times.
|
274 | for (; rest > 1; rest--, pos++) |
970 | 165 | put_bits(pbc, 8, *pos); | |
971 | |||
972 | 109 | rbsp_stop_one_bit: | |
973 |
2/2✓ Branch 0 taken 109 times.
✓ Branch 1 taken 1 times.
|
110 | temp = rest ? *pos : *pos & MAX_UINT_BITS(8 - data_bit_start % 8); |
974 | |||
975 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 110 times.
|
110 | av_assert0(temp); |
976 | 110 | i = ff_ctz(*pos); | |
977 | 110 | temp = temp >> i; | |
978 |
2/2✓ Branch 0 taken 109 times.
✓ Branch 1 taken 1 times.
|
110 | i = rest ? (8 - i) : (8 - i - data_bit_start % 8); |
979 | 110 | put_bits(pbc, i, temp); | |
980 |
2/2✓ Branch 1 taken 92 times.
✓ Branch 2 taken 18 times.
|
110 | if (put_bits_count(pbc) % 8) |
981 | 92 | put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0); | |
982 | } | ||
983 | |||
984 | 11332 | return 0; | |
985 | } | ||
986 | |||
987 | 7586 | static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx, | |
988 | CodedBitstreamUnit *unit, | ||
989 | PutBitContext *pbc) | ||
990 | { | ||
991 | int err; | ||
992 | |||
993 |
7/10✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1491 times.
✓ Branch 3 taken 5468 times.
✓ Branch 4 taken 195 times.
✓ Branch 5 taken 360 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
|
7586 | switch (unit->type) { |
994 | 69 | case H264_NAL_SPS: | |
995 | { | ||
996 | 69 | H264RawSPS *sps = unit->content; | |
997 | |||
998 | 69 | err = cbs_h264_write_sps(ctx, pbc, sps); | |
999 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
|
69 | if (err < 0) |
1000 | ✗ | return err; | |
1001 | |||
1002 | 69 | err = cbs_h264_replace_sps(ctx, unit); | |
1003 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
|
69 | if (err < 0) |
1004 | ✗ | return err; | |
1005 | } | ||
1006 | 69 | break; | |
1007 | |||
1008 | ✗ | case H264_NAL_SPS_EXT: | |
1009 | { | ||
1010 | ✗ | H264RawSPSExtension *sps_ext = unit->content; | |
1011 | |||
1012 | ✗ | err = cbs_h264_write_sps_extension(ctx, pbc, sps_ext); | |
1013 | ✗ | if (err < 0) | |
1014 | ✗ | return err; | |
1015 | } | ||
1016 | ✗ | break; | |
1017 | |||
1018 | 1491 | case H264_NAL_PPS: | |
1019 | { | ||
1020 | 1491 | H264RawPPS *pps = unit->content; | |
1021 | |||
1022 | 1491 | err = cbs_h264_write_pps(ctx, pbc, pps); | |
1023 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1491 times.
|
1491 | if (err < 0) |
1024 | ✗ | return err; | |
1025 | |||
1026 | 1491 | err = cbs_h264_replace_pps(ctx, unit); | |
1027 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1491 times.
|
1491 | if (err < 0) |
1028 | ✗ | return err; | |
1029 | } | ||
1030 | 1491 | break; | |
1031 | |||
1032 | 5468 | case H264_NAL_SLICE: | |
1033 | case H264_NAL_IDR_SLICE: | ||
1034 | case H264_NAL_AUXILIARY_SLICE: | ||
1035 | { | ||
1036 | 5468 | H264RawSlice *slice = unit->content; | |
1037 | |||
1038 | 5468 | err = cbs_h264_write_slice_header(ctx, pbc, &slice->header); | |
1039 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5468 times.
|
5468 | if (err < 0) |
1040 | ✗ | return err; | |
1041 | |||
1042 |
1/2✓ Branch 0 taken 5468 times.
✗ Branch 1 not taken.
|
5468 | if (slice->data) { |
1043 | 5468 | err = cbs_h2645_write_slice_data(ctx, pbc, slice->data, | |
1044 | slice->data_size, | ||
1045 | slice->data_bit_start); | ||
1046 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5468 times.
|
5468 | if (err < 0) |
1047 | ✗ | return err; | |
1048 | } else { | ||
1049 | // No slice data - that was just the header. | ||
1050 | // (Bitstream may be unaligned!) | ||
1051 | } | ||
1052 | } | ||
1053 | 5468 | break; | |
1054 | |||
1055 | 195 | case H264_NAL_AUD: | |
1056 | { | ||
1057 | 195 | err = cbs_h264_write_aud(ctx, pbc, unit->content); | |
1058 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 195 times.
|
195 | if (err < 0) |
1059 | ✗ | return err; | |
1060 | } | ||
1061 | 195 | break; | |
1062 | |||
1063 | 360 | case H264_NAL_SEI: | |
1064 | { | ||
1065 | 360 | err = cbs_h264_write_sei(ctx, pbc, unit->content); | |
1066 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 360 times.
|
360 | if (err < 0) |
1067 | ✗ | return err; | |
1068 | } | ||
1069 | 360 | break; | |
1070 | |||
1071 | ✗ | case H264_NAL_FILLER_DATA: | |
1072 | { | ||
1073 | ✗ | err = cbs_h264_write_filler(ctx, pbc, unit->content); | |
1074 | ✗ | if (err < 0) | |
1075 | ✗ | return err; | |
1076 | } | ||
1077 | ✗ | break; | |
1078 | |||
1079 | 1 | case H264_NAL_END_SEQUENCE: | |
1080 | { | ||
1081 | 1 | err = cbs_h264_write_end_of_sequence(ctx, pbc, unit->content); | |
1082 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
1083 | ✗ | return err; | |
1084 | } | ||
1085 | 1 | break; | |
1086 | |||
1087 | 2 | case H264_NAL_END_STREAM: | |
1088 | { | ||
1089 | 2 | err = cbs_h264_write_end_of_stream(ctx, pbc, unit->content); | |
1090 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (err < 0) |
1091 | ✗ | return err; | |
1092 | } | ||
1093 | 2 | break; | |
1094 | |||
1095 | ✗ | default: | |
1096 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for " | |
1097 | "NAL unit type %"PRIu32".\n", unit->type); | ||
1098 | ✗ | return AVERROR_PATCHWELCOME; | |
1099 | } | ||
1100 | |||
1101 | 7586 | return 0; | |
1102 | } | ||
1103 | |||
1104 | 7832 | static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx, | |
1105 | CodedBitstreamUnit *unit, | ||
1106 | PutBitContext *pbc) | ||
1107 | { | ||
1108 | int err; | ||
1109 | |||
1110 |
6/7✓ Branch 0 taken 48 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 275 times.
✓ Branch 3 taken 5864 times.
✓ Branch 4 taken 60 times.
✓ Branch 5 taken 1535 times.
✗ Branch 6 not taken.
|
7832 | switch (unit->type) { |
1111 | 48 | case HEVC_NAL_VPS: | |
1112 | { | ||
1113 | 48 | H265RawVPS *vps = unit->content; | |
1114 | |||
1115 | 48 | err = cbs_h265_write_vps(ctx, pbc, vps); | |
1116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (err < 0) |
1117 | ✗ | return err; | |
1118 | |||
1119 | 48 | err = cbs_h265_replace_vps(ctx, unit); | |
1120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (err < 0) |
1121 | ✗ | return err; | |
1122 | } | ||
1123 | 48 | break; | |
1124 | |||
1125 | 50 | case HEVC_NAL_SPS: | |
1126 | { | ||
1127 | 50 | H265RawSPS *sps = unit->content; | |
1128 | |||
1129 | 50 | err = cbs_h265_write_sps(ctx, pbc, sps); | |
1130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
|
50 | if (err < 0) |
1131 | ✗ | return err; | |
1132 | |||
1133 | 50 | err = cbs_h265_replace_sps(ctx, unit); | |
1134 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
|
50 | if (err < 0) |
1135 | ✗ | return err; | |
1136 | } | ||
1137 | 50 | break; | |
1138 | |||
1139 | 275 | case HEVC_NAL_PPS: | |
1140 | { | ||
1141 | 275 | H265RawPPS *pps = unit->content; | |
1142 | |||
1143 | 275 | err = cbs_h265_write_pps(ctx, pbc, pps); | |
1144 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 275 times.
|
275 | if (err < 0) |
1145 | ✗ | return err; | |
1146 | |||
1147 | 275 | err = cbs_h265_replace_pps(ctx, unit); | |
1148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 275 times.
|
275 | if (err < 0) |
1149 | ✗ | return err; | |
1150 | } | ||
1151 | 275 | break; | |
1152 | |||
1153 | 5864 | case HEVC_NAL_TRAIL_N: | |
1154 | case HEVC_NAL_TRAIL_R: | ||
1155 | case HEVC_NAL_TSA_N: | ||
1156 | case HEVC_NAL_TSA_R: | ||
1157 | case HEVC_NAL_STSA_N: | ||
1158 | case HEVC_NAL_STSA_R: | ||
1159 | case HEVC_NAL_RADL_N: | ||
1160 | case HEVC_NAL_RADL_R: | ||
1161 | case HEVC_NAL_RASL_N: | ||
1162 | case HEVC_NAL_RASL_R: | ||
1163 | case HEVC_NAL_BLA_W_LP: | ||
1164 | case HEVC_NAL_BLA_W_RADL: | ||
1165 | case HEVC_NAL_BLA_N_LP: | ||
1166 | case HEVC_NAL_IDR_W_RADL: | ||
1167 | case HEVC_NAL_IDR_N_LP: | ||
1168 | case HEVC_NAL_CRA_NUT: | ||
1169 | { | ||
1170 | 5864 | H265RawSlice *slice = unit->content; | |
1171 | |||
1172 | 5864 | err = cbs_h265_write_slice_segment_header(ctx, pbc, &slice->header); | |
1173 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5864 times.
|
5864 | if (err < 0) |
1174 | ✗ | return err; | |
1175 | |||
1176 |
1/2✓ Branch 0 taken 5864 times.
✗ Branch 1 not taken.
|
5864 | if (slice->data) { |
1177 | 5864 | err = cbs_h2645_write_slice_data(ctx, pbc, slice->data, | |
1178 | slice->data_size, | ||
1179 | slice->data_bit_start); | ||
1180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5864 times.
|
5864 | if (err < 0) |
1181 | ✗ | return err; | |
1182 | } else { | ||
1183 | // No slice data - that was just the header. | ||
1184 | } | ||
1185 | } | ||
1186 | 5864 | break; | |
1187 | |||
1188 | 60 | case HEVC_NAL_AUD: | |
1189 | { | ||
1190 | 60 | err = cbs_h265_write_aud(ctx, pbc, unit->content); | |
1191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | if (err < 0) |
1192 | ✗ | return err; | |
1193 | } | ||
1194 | 60 | break; | |
1195 | |||
1196 | 1535 | case HEVC_NAL_SEI_PREFIX: | |
1197 | case HEVC_NAL_SEI_SUFFIX: | ||
1198 | { | ||
1199 | 1535 | err = cbs_h265_write_sei(ctx, pbc, unit->content, | |
1200 | 1535 | unit->type == HEVC_NAL_SEI_PREFIX); | |
1201 | |||
1202 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1535 times.
|
1535 | if (err < 0) |
1203 | ✗ | return err; | |
1204 | } | ||
1205 | 1535 | break; | |
1206 | |||
1207 | ✗ | default: | |
1208 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for " | |
1209 | "NAL unit type %"PRIu32".\n", unit->type); | ||
1210 | ✗ | return AVERROR_PATCHWELCOME; | |
1211 | } | ||
1212 | |||
1213 | 7832 | return 0; | |
1214 | } | ||
1215 | |||
1216 | 15418 | static int cbs_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, | |
1217 | CodedBitstreamUnitType type, | ||
1218 | int nal_unit_index) | ||
1219 | { | ||
1220 | // Section B.1.2 in H.264, section B.2.2 in H.265. | ||
1221 |
2/2✓ Branch 0 taken 4972 times.
✓ Branch 1 taken 10446 times.
|
15418 | if (nal_unit_index == 0) { |
1222 | // Assume that this is the first NAL unit in an access unit. | ||
1223 | 4972 | return 1; | |
1224 | } | ||
1225 |
2/2✓ Branch 0 taken 4766 times.
✓ Branch 1 taken 5680 times.
|
10446 | if (codec_id == AV_CODEC_ID_H264) |
1226 |
4/4✓ Branch 0 taken 4758 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 444 times.
✓ Branch 3 taken 4314 times.
|
4766 | return type == H264_NAL_SPS || type == H264_NAL_PPS; |
1227 |
1/2✓ Branch 0 taken 5680 times.
✗ Branch 1 not taken.
|
5680 | if (codec_id == AV_CODEC_ID_HEVC) |
1228 |
6/6✓ Branch 0 taken 5677 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5627 times.
✓ Branch 3 taken 50 times.
✓ Branch 4 taken 48 times.
✓ Branch 5 taken 5579 times.
|
5680 | return type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS; |
1229 | ✗ | return 0; | |
1230 | } | ||
1231 | |||
1232 | 4973 | static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, | |
1233 | CodedBitstreamFragment *frag) | ||
1234 | { | ||
1235 | uint8_t *data; | ||
1236 | size_t max_size, dp, sp; | ||
1237 | int err, i, zero_run; | ||
1238 | |||
1239 |
2/2✓ Branch 0 taken 15418 times.
✓ Branch 1 taken 4973 times.
|
20391 | for (i = 0; i < frag->nb_units; i++) { |
1240 | // Data should already all have been written when we get here. | ||
1241 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15418 times.
|
15418 | av_assert0(frag->units[i].data); |
1242 | } | ||
1243 | |||
1244 | 4973 | max_size = 0; | |
1245 |
2/2✓ Branch 0 taken 15418 times.
✓ Branch 1 taken 4973 times.
|
20391 | for (i = 0; i < frag->nb_units; i++) { |
1246 | // Start code + content with worst-case emulation prevention. | ||
1247 | 15418 | max_size += 4 + frag->units[i].data_size * 3 / 2; | |
1248 | } | ||
1249 | |||
1250 | 4973 | data = av_realloc(NULL, max_size + AV_INPUT_BUFFER_PADDING_SIZE); | |
1251 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4973 times.
|
4973 | if (!data) |
1252 | ✗ | return AVERROR(ENOMEM); | |
1253 | |||
1254 | 4973 | dp = 0; | |
1255 |
2/2✓ Branch 0 taken 15418 times.
✓ Branch 1 taken 4973 times.
|
20391 | for (i = 0; i < frag->nb_units; i++) { |
1256 | 15418 | CodedBitstreamUnit *unit = &frag->units[i]; | |
1257 | |||
1258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15418 times.
|
15418 | if (unit->data_bit_padding > 0) { |
1259 | ✗ | if (i < frag->nb_units - 1) | |
1260 | ✗ | av_log(ctx->log_ctx, AV_LOG_WARNING, "Probably invalid " | |
1261 | "unaligned padding on non-final NAL unit.\n"); | ||
1262 | else | ||
1263 | ✗ | frag->data_bit_padding = unit->data_bit_padding; | |
1264 | } | ||
1265 | |||
1266 |
2/2✓ Branch 1 taken 5525 times.
✓ Branch 2 taken 9893 times.
|
15418 | if (cbs_h2645_unit_requires_zero_byte(ctx->codec->codec_id, unit->type, i)) { |
1267 | // zero_byte | ||
1268 | 5525 | data[dp++] = 0; | |
1269 | } | ||
1270 | // start_code_prefix_one_3bytes | ||
1271 | 15418 | data[dp++] = 0; | |
1272 | 15418 | data[dp++] = 0; | |
1273 | 15418 | data[dp++] = 1; | |
1274 | |||
1275 | 15418 | zero_run = 0; | |
1276 |
2/2✓ Branch 0 taken 11780295 times.
✓ Branch 1 taken 15418 times.
|
11795713 | for (sp = 0; sp < unit->data_size; sp++) { |
1277 |
2/2✓ Branch 0 taken 11776047 times.
✓ Branch 1 taken 4248 times.
|
11780295 | if (zero_run < 2) { |
1278 |
2/2✓ Branch 0 taken 115218 times.
✓ Branch 1 taken 11660829 times.
|
11776047 | if (unit->data[sp] == 0) |
1279 | 115218 | ++zero_run; | |
1280 | else | ||
1281 | 11660829 | zero_run = 0; | |
1282 | } else { | ||
1283 |
2/2✓ Branch 0 taken 804 times.
✓ Branch 1 taken 3444 times.
|
4248 | if ((unit->data[sp] & ~3) == 0) { |
1284 | // emulation_prevention_three_byte | ||
1285 | 804 | data[dp++] = 3; | |
1286 | } | ||
1287 | 4248 | zero_run = unit->data[sp] == 0; | |
1288 | } | ||
1289 | 11780295 | data[dp++] = unit->data[sp]; | |
1290 | } | ||
1291 | } | ||
1292 | |||
1293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4973 times.
|
4973 | av_assert0(dp <= max_size); |
1294 | 4973 | err = av_reallocp(&data, dp + AV_INPUT_BUFFER_PADDING_SIZE); | |
1295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4973 times.
|
4973 | if (err) |
1296 | ✗ | return err; | |
1297 | 4973 | memset(data + dp, 0, AV_INPUT_BUFFER_PADDING_SIZE); | |
1298 | |||
1299 | 4973 | frag->data_ref = av_buffer_create(data, dp + AV_INPUT_BUFFER_PADDING_SIZE, | |
1300 | NULL, NULL, 0); | ||
1301 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4973 times.
|
4973 | if (!frag->data_ref) { |
1302 | ✗ | av_freep(&data); | |
1303 | ✗ | return AVERROR(ENOMEM); | |
1304 | } | ||
1305 | |||
1306 | 4973 | frag->data = data; | |
1307 | 4973 | frag->data_size = dp; | |
1308 | |||
1309 | 4973 | return 0; | |
1310 | } | ||
1311 | |||
1312 | ✗ | static void cbs_h264_flush(CodedBitstreamContext *ctx) | |
1313 | { | ||
1314 | ✗ | CodedBitstreamH264Context *h264 = ctx->priv_data; | |
1315 | |||
1316 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) { | |
1317 | ✗ | av_buffer_unref(&h264->sps_ref[i]); | |
1318 | ✗ | h264->sps[i] = NULL; | |
1319 | } | ||
1320 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) { | |
1321 | ✗ | av_buffer_unref(&h264->pps_ref[i]); | |
1322 | ✗ | h264->pps[i] = NULL; | |
1323 | } | ||
1324 | |||
1325 | ✗ | h264->active_sps = NULL; | |
1326 | ✗ | h264->active_pps = NULL; | |
1327 | ✗ | h264->last_slice_nal_unit_type = 0; | |
1328 | } | ||
1329 | |||
1330 | 40 | static void cbs_h264_close(CodedBitstreamContext *ctx) | |
1331 | { | ||
1332 | 40 | CodedBitstreamH264Context *h264 = ctx->priv_data; | |
1333 | int i; | ||
1334 | |||
1335 | 40 | ff_h2645_packet_uninit(&h264->common.read_packet); | |
1336 | |||
1337 |
2/2✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 40 times.
|
1320 | for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) |
1338 | 1280 | av_buffer_unref(&h264->sps_ref[i]); | |
1339 |
2/2✓ Branch 0 taken 10240 times.
✓ Branch 1 taken 40 times.
|
10280 | for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) |
1340 | 10240 | av_buffer_unref(&h264->pps_ref[i]); | |
1341 | 40 | } | |
1342 | |||
1343 | ✗ | static void cbs_h265_flush(CodedBitstreamContext *ctx) | |
1344 | { | ||
1345 | ✗ | CodedBitstreamH265Context *h265 = ctx->priv_data; | |
1346 | |||
1347 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) { | |
1348 | ✗ | av_buffer_unref(&h265->vps_ref[i]); | |
1349 | ✗ | h265->vps[i] = NULL; | |
1350 | } | ||
1351 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) { | |
1352 | ✗ | av_buffer_unref(&h265->sps_ref[i]); | |
1353 | ✗ | h265->sps[i] = NULL; | |
1354 | } | ||
1355 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) { | |
1356 | ✗ | av_buffer_unref(&h265->pps_ref[i]); | |
1357 | ✗ | h265->pps[i] = NULL; | |
1358 | } | ||
1359 | |||
1360 | ✗ | h265->active_vps = NULL; | |
1361 | ✗ | h265->active_sps = NULL; | |
1362 | ✗ | h265->active_pps = NULL; | |
1363 | } | ||
1364 | |||
1365 | 40 | static void cbs_h265_close(CodedBitstreamContext *ctx) | |
1366 | { | ||
1367 | 40 | CodedBitstreamH265Context *h265 = ctx->priv_data; | |
1368 | int i; | ||
1369 | |||
1370 | 40 | ff_h2645_packet_uninit(&h265->common.read_packet); | |
1371 | |||
1372 |
2/2✓ Branch 0 taken 640 times.
✓ Branch 1 taken 40 times.
|
680 | for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) |
1373 | 640 | av_buffer_unref(&h265->vps_ref[i]); | |
1374 |
2/2✓ Branch 0 taken 640 times.
✓ Branch 1 taken 40 times.
|
680 | for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) |
1375 | 640 | av_buffer_unref(&h265->sps_ref[i]); | |
1376 |
2/2✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 40 times.
|
2600 | for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) |
1377 | 2560 | av_buffer_unref(&h265->pps_ref[i]); | |
1378 | 40 | } | |
1379 | |||
1380 | 361 | static void cbs_h264_free_sei(void *opaque, uint8_t *content) | |
1381 | { | ||
1382 | 361 | H264RawSEI *sei = (H264RawSEI*)content; | |
1383 | 361 | ff_cbs_sei_free_message_list(&sei->message_list); | |
1384 | 361 | av_free(content); | |
1385 | 361 | } | |
1386 | |||
1387 | static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = { | ||
1388 | CBS_UNIT_TYPE_POD(H264_NAL_SPS, H264RawSPS), | ||
1389 | CBS_UNIT_TYPE_POD(H264_NAL_SPS_EXT, H264RawSPSExtension), | ||
1390 | |||
1391 | CBS_UNIT_TYPE_INTERNAL_REF(H264_NAL_PPS, H264RawPPS, slice_group_id), | ||
1392 | |||
1393 | CBS_UNIT_TYPES_INTERNAL_REF((H264_NAL_IDR_SLICE, | ||
1394 | H264_NAL_SLICE, | ||
1395 | H264_NAL_AUXILIARY_SLICE), H264RawSlice, data), | ||
1396 | |||
1397 | CBS_UNIT_TYPE_POD(H264_NAL_AUD, H264RawAUD), | ||
1398 | CBS_UNIT_TYPE_POD(H264_NAL_FILLER_DATA, H264RawFiller), | ||
1399 | CBS_UNIT_TYPE_POD(H264_NAL_END_SEQUENCE, H264RawNALUnitHeader), | ||
1400 | CBS_UNIT_TYPE_POD(H264_NAL_END_STREAM, H264RawNALUnitHeader), | ||
1401 | |||
1402 | CBS_UNIT_TYPE_COMPLEX(H264_NAL_SEI, H264RawSEI, &cbs_h264_free_sei), | ||
1403 | |||
1404 | CBS_UNIT_TYPE_END_OF_LIST | ||
1405 | }; | ||
1406 | |||
1407 | 1535 | static void cbs_h265_free_sei(void *opaque, uint8_t *content) | |
1408 | { | ||
1409 | 1535 | H265RawSEI *sei = (H265RawSEI*)content; | |
1410 | 1535 | ff_cbs_sei_free_message_list(&sei->message_list); | |
1411 | 1535 | av_free(content); | |
1412 | 1535 | } | |
1413 | |||
1414 | static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = { | ||
1415 | CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_VPS, H265RawVPS, extension_data.data), | ||
1416 | CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_SPS, H265RawSPS, extension_data.data), | ||
1417 | CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_PPS, H265RawPPS, extension_data.data), | ||
1418 | |||
1419 | CBS_UNIT_TYPE_POD(HEVC_NAL_AUD, H265RawAUD), | ||
1420 | |||
1421 | // Slices of non-IRAP pictures. | ||
1422 | CBS_UNIT_RANGE_INTERNAL_REF(HEVC_NAL_TRAIL_N, HEVC_NAL_RASL_R, | ||
1423 | H265RawSlice, data), | ||
1424 | // Slices of IRAP pictures. | ||
1425 | CBS_UNIT_RANGE_INTERNAL_REF(HEVC_NAL_BLA_W_LP, HEVC_NAL_CRA_NUT, | ||
1426 | H265RawSlice, data), | ||
1427 | |||
1428 | CBS_UNIT_TYPES_COMPLEX((HEVC_NAL_SEI_PREFIX, HEVC_NAL_SEI_SUFFIX), | ||
1429 | H265RawSEI, cbs_h265_free_sei), | ||
1430 | |||
1431 | CBS_UNIT_TYPE_END_OF_LIST | ||
1432 | }; | ||
1433 | |||
1434 | const CodedBitstreamType ff_cbs_type_h264 = { | ||
1435 | .codec_id = AV_CODEC_ID_H264, | ||
1436 | |||
1437 | .priv_data_size = sizeof(CodedBitstreamH264Context), | ||
1438 | |||
1439 | .unit_types = cbs_h264_unit_types, | ||
1440 | |||
1441 | .split_fragment = &cbs_h2645_split_fragment, | ||
1442 | .read_unit = &cbs_h264_read_nal_unit, | ||
1443 | .write_unit = &cbs_h264_write_nal_unit, | ||
1444 | .assemble_fragment = &cbs_h2645_assemble_fragment, | ||
1445 | |||
1446 | .flush = &cbs_h264_flush, | ||
1447 | .close = &cbs_h264_close, | ||
1448 | }; | ||
1449 | |||
1450 | const CodedBitstreamType ff_cbs_type_h265 = { | ||
1451 | .codec_id = AV_CODEC_ID_HEVC, | ||
1452 | |||
1453 | .priv_data_size = sizeof(CodedBitstreamH265Context), | ||
1454 | |||
1455 | .unit_types = cbs_h265_unit_types, | ||
1456 | |||
1457 | .split_fragment = &cbs_h2645_split_fragment, | ||
1458 | .read_unit = &cbs_h265_read_nal_unit, | ||
1459 | .write_unit = &cbs_h265_write_nal_unit, | ||
1460 | .assemble_fragment = &cbs_h2645_assemble_fragment, | ||
1461 | |||
1462 | .flush = &cbs_h265_flush, | ||
1463 | .close = &cbs_h265_close, | ||
1464 | }; | ||
1465 | |||
1466 | static const SEIMessageTypeDescriptor cbs_sei_common_types[] = { | ||
1467 | { | ||
1468 | SEI_TYPE_FILLER_PAYLOAD, | ||
1469 | 1, 1, | ||
1470 | sizeof(SEIRawFillerPayload), | ||
1471 | SEI_MESSAGE_RW(sei, filler_payload), | ||
1472 | }, | ||
1473 | { | ||
1474 | SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35, | ||
1475 | 1, 1, | ||
1476 | sizeof(SEIRawUserDataRegistered), | ||
1477 | SEI_MESSAGE_RW(sei, user_data_registered), | ||
1478 | }, | ||
1479 | { | ||
1480 | SEI_TYPE_USER_DATA_UNREGISTERED, | ||
1481 | 1, 1, | ||
1482 | sizeof(SEIRawUserDataUnregistered), | ||
1483 | SEI_MESSAGE_RW(sei, user_data_unregistered), | ||
1484 | }, | ||
1485 | { | ||
1486 | SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME, | ||
1487 | 1, 0, | ||
1488 | sizeof(SEIRawMasteringDisplayColourVolume), | ||
1489 | SEI_MESSAGE_RW(sei, mastering_display_colour_volume), | ||
1490 | }, | ||
1491 | { | ||
1492 | SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO, | ||
1493 | 1, 0, | ||
1494 | sizeof(SEIRawContentLightLevelInfo), | ||
1495 | SEI_MESSAGE_RW(sei, content_light_level_info), | ||
1496 | }, | ||
1497 | { | ||
1498 | SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS, | ||
1499 | 1, 0, | ||
1500 | sizeof(SEIRawAlternativeTransferCharacteristics), | ||
1501 | SEI_MESSAGE_RW(sei, alternative_transfer_characteristics), | ||
1502 | }, | ||
1503 | { | ||
1504 | SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT, | ||
1505 | 1, 0, | ||
1506 | sizeof(SEIRawAmbientViewingEnvironment), | ||
1507 | SEI_MESSAGE_RW(sei, ambient_viewing_environment), | ||
1508 | }, | ||
1509 | SEI_MESSAGE_TYPE_END, | ||
1510 | }; | ||
1511 | |||
1512 | static const SEIMessageTypeDescriptor cbs_sei_h264_types[] = { | ||
1513 | { | ||
1514 | SEI_TYPE_BUFFERING_PERIOD, | ||
1515 | 1, 0, | ||
1516 | sizeof(H264RawSEIBufferingPeriod), | ||
1517 | SEI_MESSAGE_RW(h264, sei_buffering_period), | ||
1518 | }, | ||
1519 | { | ||
1520 | SEI_TYPE_PIC_TIMING, | ||
1521 | 1, 0, | ||
1522 | sizeof(H264RawSEIPicTiming), | ||
1523 | SEI_MESSAGE_RW(h264, sei_pic_timing), | ||
1524 | }, | ||
1525 | { | ||
1526 | SEI_TYPE_PAN_SCAN_RECT, | ||
1527 | 1, 0, | ||
1528 | sizeof(H264RawSEIPanScanRect), | ||
1529 | SEI_MESSAGE_RW(h264, sei_pan_scan_rect), | ||
1530 | }, | ||
1531 | { | ||
1532 | SEI_TYPE_RECOVERY_POINT, | ||
1533 | 1, 0, | ||
1534 | sizeof(H264RawSEIRecoveryPoint), | ||
1535 | SEI_MESSAGE_RW(h264, sei_recovery_point), | ||
1536 | }, | ||
1537 | { | ||
1538 | SEI_TYPE_FILM_GRAIN_CHARACTERISTICS, | ||
1539 | 1, 0, | ||
1540 | sizeof(H264RawFilmGrainCharacteristics), | ||
1541 | SEI_MESSAGE_RW(h264, film_grain_characteristics), | ||
1542 | }, | ||
1543 | { | ||
1544 | SEI_TYPE_DISPLAY_ORIENTATION, | ||
1545 | 1, 0, | ||
1546 | sizeof(H264RawSEIDisplayOrientation), | ||
1547 | SEI_MESSAGE_RW(h264, sei_display_orientation), | ||
1548 | }, | ||
1549 | SEI_MESSAGE_TYPE_END | ||
1550 | }; | ||
1551 | |||
1552 | static const SEIMessageTypeDescriptor cbs_sei_h265_types[] = { | ||
1553 | { | ||
1554 | SEI_TYPE_BUFFERING_PERIOD, | ||
1555 | 1, 0, | ||
1556 | sizeof(H265RawSEIBufferingPeriod), | ||
1557 | SEI_MESSAGE_RW(h265, sei_buffering_period), | ||
1558 | }, | ||
1559 | { | ||
1560 | SEI_TYPE_PIC_TIMING, | ||
1561 | 1, 0, | ||
1562 | sizeof(H265RawSEIPicTiming), | ||
1563 | SEI_MESSAGE_RW(h265, sei_pic_timing), | ||
1564 | }, | ||
1565 | { | ||
1566 | SEI_TYPE_PAN_SCAN_RECT, | ||
1567 | 1, 0, | ||
1568 | sizeof(H265RawSEIPanScanRect), | ||
1569 | SEI_MESSAGE_RW(h265, sei_pan_scan_rect), | ||
1570 | }, | ||
1571 | { | ||
1572 | SEI_TYPE_RECOVERY_POINT, | ||
1573 | 1, 0, | ||
1574 | sizeof(H265RawSEIRecoveryPoint), | ||
1575 | SEI_MESSAGE_RW(h265, sei_recovery_point), | ||
1576 | }, | ||
1577 | { | ||
1578 | SEI_TYPE_FILM_GRAIN_CHARACTERISTICS, | ||
1579 | 1, 0, | ||
1580 | sizeof(H265RawFilmGrainCharacteristics), | ||
1581 | SEI_MESSAGE_RW(h265, film_grain_characteristics), | ||
1582 | }, | ||
1583 | { | ||
1584 | SEI_TYPE_DISPLAY_ORIENTATION, | ||
1585 | 1, 0, | ||
1586 | sizeof(H265RawSEIDisplayOrientation), | ||
1587 | SEI_MESSAGE_RW(h265, sei_display_orientation), | ||
1588 | }, | ||
1589 | { | ||
1590 | SEI_TYPE_ACTIVE_PARAMETER_SETS, | ||
1591 | 1, 0, | ||
1592 | sizeof(H265RawSEIActiveParameterSets), | ||
1593 | SEI_MESSAGE_RW(h265, sei_active_parameter_sets), | ||
1594 | }, | ||
1595 | { | ||
1596 | SEI_TYPE_DECODED_PICTURE_HASH, | ||
1597 | 0, 1, | ||
1598 | sizeof(H265RawSEIDecodedPictureHash), | ||
1599 | SEI_MESSAGE_RW(h265, sei_decoded_picture_hash), | ||
1600 | }, | ||
1601 | { | ||
1602 | SEI_TYPE_TIME_CODE, | ||
1603 | 1, 0, | ||
1604 | sizeof(H265RawSEITimeCode), | ||
1605 | SEI_MESSAGE_RW(h265, sei_time_code), | ||
1606 | }, | ||
1607 | { | ||
1608 | SEI_TYPE_ALPHA_CHANNEL_INFO, | ||
1609 | 1, 0, | ||
1610 | sizeof(H265RawSEIAlphaChannelInfo), | ||
1611 | SEI_MESSAGE_RW(h265, sei_alpha_channel_info), | ||
1612 | }, | ||
1613 | SEI_MESSAGE_TYPE_END | ||
1614 | }; | ||
1615 | |||
1616 | 5746 | const SEIMessageTypeDescriptor *ff_cbs_sei_find_type(CodedBitstreamContext *ctx, | |
1617 | int payload_type) | ||
1618 | { | ||
1619 | const SEIMessageTypeDescriptor *codec_list; | ||
1620 | int i; | ||
1621 | |||
1622 |
2/2✓ Branch 0 taken 39646 times.
✓ Branch 1 taken 5620 times.
|
45266 | for (i = 0; cbs_sei_common_types[i].type >= 0; i++) { |
1623 |
2/2✓ Branch 0 taken 126 times.
✓ Branch 1 taken 39520 times.
|
39646 | if (cbs_sei_common_types[i].type == payload_type) |
1624 | 126 | return &cbs_sei_common_types[i]; | |
1625 | } | ||
1626 | |||
1627 |
2/3✓ Branch 0 taken 1015 times.
✓ Branch 1 taken 4605 times.
✗ Branch 2 not taken.
|
5620 | switch (ctx->codec->codec_id) { |
1628 | 1015 | case AV_CODEC_ID_H264: | |
1629 | 1015 | codec_list = cbs_sei_h264_types; | |
1630 | 1015 | break; | |
1631 | 4605 | case AV_CODEC_ID_H265: | |
1632 | 4605 | codec_list = cbs_sei_h265_types; | |
1633 | 4605 | break; | |
1634 | ✗ | default: | |
1635 | ✗ | return NULL; | |
1636 | } | ||
1637 | |||
1638 |
2/2✓ Branch 0 taken 35978 times.
✓ Branch 1 taken 15 times.
|
35993 | for (i = 0; codec_list[i].type >= 0; i++) { |
1639 |
2/2✓ Branch 0 taken 5605 times.
✓ Branch 1 taken 30373 times.
|
35978 | if (codec_list[i].type == payload_type) |
1640 | 5605 | return &codec_list[i]; | |
1641 | } | ||
1642 | |||
1643 | 15 | return NULL; | |
1644 | } | ||
1645 |