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 "cbs_h266.h" | ||
28 | #include "h264.h" | ||
29 | #include "h2645_parse.h" | ||
30 | #include "hevc.h" | ||
31 | #include "refstruct.h" | ||
32 | #include "vvc.h" | ||
33 | |||
34 | |||
35 | 232882 | static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc, | |
36 | const char *name, const int *subscripts, | ||
37 | uint32_t *write_to, | ||
38 | uint32_t range_min, uint32_t range_max) | ||
39 | { | ||
40 | uint32_t leading_bits, value; | ||
41 | int max_length, leading_zeroes; | ||
42 | |||
43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 232882 times.
|
232882 | CBS_TRACE_READ_START(); |
44 | |||
45 |
2/2✓ Branch 1 taken 9487 times.
✓ Branch 2 taken 223395 times.
|
232882 | max_length = FFMIN(get_bits_left(gbc), 32); |
46 | |||
47 |
1/2✓ Branch 0 taken 232882 times.
✗ Branch 1 not taken.
|
232882 | leading_bits = max_length ? show_bits_long(gbc, max_length) : 0; |
48 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 232882 times.
|
232882 | if (leading_bits == 0) { |
49 | ✗ | if (max_length >= 32) { | |
50 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at " | |
51 | "%s: more than 31 zeroes.\n", name); | ||
52 | ✗ | return AVERROR_INVALIDDATA; | |
53 | } else { | ||
54 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at " | |
55 | "%s: bitstream ended.\n", name); | ||
56 | ✗ | return AVERROR_INVALIDDATA; | |
57 | } | ||
58 | } | ||
59 | |||
60 | 232882 | leading_zeroes = max_length - 1 - av_log2(leading_bits); | |
61 | 232882 | skip_bits_long(gbc, leading_zeroes); | |
62 | |||
63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 232882 times.
|
232882 | if (get_bits_left(gbc) < leading_zeroes + 1) { |
64 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at " | |
65 | "%s: bitstream ended.\n", name); | ||
66 | ✗ | return AVERROR_INVALIDDATA; | |
67 | } | ||
68 | |||
69 | 232882 | value = get_bits_long(gbc, leading_zeroes + 1) - 1; | |
70 | |||
71 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 232882 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
232882 | CBS_TRACE_READ_END(); |
72 | |||
73 |
2/4✓ Branch 0 taken 232882 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 232882 times.
|
232882 | 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 | 232882 | *write_to = value; | |
81 | 232882 | return 0; | |
82 | } | ||
83 | |||
84 | 90249 | 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 | uint32_t leading_bits, unsigned_value; | ||
90 | int max_length, leading_zeroes; | ||
91 | int32_t value; | ||
92 | |||
93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 90249 times.
|
90249 | CBS_TRACE_READ_START(); |
94 | |||
95 |
2/2✓ Branch 1 taken 6981 times.
✓ Branch 2 taken 83268 times.
|
90249 | max_length = FFMIN(get_bits_left(gbc), 32); |
96 | |||
97 |
1/2✓ Branch 0 taken 90249 times.
✗ Branch 1 not taken.
|
90249 | leading_bits = max_length ? show_bits_long(gbc, max_length) : 0; |
98 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 90249 times.
|
90249 | if (leading_bits == 0) { |
99 | ✗ | if (max_length >= 32) { | |
100 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at " | |
101 | "%s: more than 31 zeroes.\n", name); | ||
102 | ✗ | return AVERROR_INVALIDDATA; | |
103 | } else { | ||
104 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at " | |
105 | "%s: bitstream ended.\n", name); | ||
106 | ✗ | return AVERROR_INVALIDDATA; | |
107 | } | ||
108 | } | ||
109 | |||
110 | 90249 | leading_zeroes = max_length - 1 - av_log2(leading_bits); | |
111 | 90249 | skip_bits_long(gbc, leading_zeroes); | |
112 | |||
113 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 90249 times.
|
90249 | if (get_bits_left(gbc) < leading_zeroes + 1) { |
114 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at " | |
115 | "%s: bitstream ended.\n", name); | ||
116 | ✗ | return AVERROR_INVALIDDATA; | |
117 | } | ||
118 | |||
119 | 90249 | unsigned_value = get_bits_long(gbc, leading_zeroes + 1); | |
120 | |||
121 |
2/2✓ Branch 0 taken 49577 times.
✓ Branch 1 taken 40672 times.
|
90249 | if (unsigned_value & 1) |
122 | 49577 | value = -(int32_t)(unsigned_value / 2); | |
123 | else | ||
124 | 40672 | value = unsigned_value / 2; | |
125 | |||
126 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 90249 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
90249 | CBS_TRACE_READ_END(); |
127 | |||
128 |
2/4✓ Branch 0 taken 90249 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 90249 times.
|
90249 | if (value < range_min || value > range_max) { |
129 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
130 | "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n", | ||
131 | name, value, range_min, range_max); | ||
132 | ✗ | return AVERROR_INVALIDDATA; | |
133 | } | ||
134 | |||
135 | 90249 | *write_to = value; | |
136 | 90249 | return 0; | |
137 | } | ||
138 | |||
139 | 154844 | static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, | |
140 | const char *name, const int *subscripts, | ||
141 | uint32_t value, | ||
142 | uint32_t range_min, uint32_t range_max) | ||
143 | { | ||
144 | int len; | ||
145 | |||
146 |
2/2✓ Branch 0 taken 151775 times.
✓ Branch 1 taken 3069 times.
|
154844 | CBS_TRACE_WRITE_START(); |
147 | |||
148 |
2/4✓ Branch 0 taken 154844 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 154844 times.
|
154844 | if (value < range_min || value > range_max) { |
149 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
150 | "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n", | ||
151 | name, value, range_min, range_max); | ||
152 | ✗ | return AVERROR_INVALIDDATA; | |
153 | } | ||
154 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 154844 times.
|
154844 | av_assert0(value != UINT32_MAX); |
155 | |||
156 | 154844 | len = av_log2(value + 1); | |
157 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 154844 times.
|
154844 | if (put_bits_left(pbc) < 2 * len + 1) |
158 | ✗ | return AVERROR(ENOSPC); | |
159 | |||
160 | 154844 | put_bits(pbc, len, 0); | |
161 |
1/2✓ Branch 0 taken 154844 times.
✗ Branch 1 not taken.
|
154844 | if (len + 1 < 32) |
162 | 154844 | put_bits(pbc, len + 1, value + 1); | |
163 | else | ||
164 | ✗ | put_bits32(pbc, value + 1); | |
165 | |||
166 |
3/4✓ Branch 0 taken 151775 times.
✓ Branch 1 taken 3069 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 151775 times.
|
154844 | CBS_TRACE_WRITE_END(); |
167 | |||
168 | 154844 | return 0; | |
169 | } | ||
170 | |||
171 | 84001 | static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, | |
172 | const char *name, const int *subscripts, | ||
173 | int32_t value, | ||
174 | int32_t range_min, int32_t range_max) | ||
175 | { | ||
176 | int len; | ||
177 | uint32_t uvalue; | ||
178 | |||
179 |
2/2✓ Branch 0 taken 83431 times.
✓ Branch 1 taken 570 times.
|
84001 | CBS_TRACE_WRITE_START(); |
180 | |||
181 |
2/4✓ Branch 0 taken 84001 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 84001 times.
|
84001 | if (value < range_min || value > range_max) { |
182 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: " | |
183 | "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n", | ||
184 | name, value, range_min, range_max); | ||
185 | ✗ | return AVERROR_INVALIDDATA; | |
186 | } | ||
187 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 84001 times.
|
84001 | av_assert0(value != INT32_MIN); |
188 | |||
189 |
2/2✓ Branch 0 taken 19170 times.
✓ Branch 1 taken 64831 times.
|
84001 | if (value == 0) |
190 | 19170 | uvalue = 0; | |
191 |
2/2✓ Branch 0 taken 36505 times.
✓ Branch 1 taken 28326 times.
|
64831 | else if (value > 0) |
192 | 36505 | uvalue = 2 * (uint32_t)value - 1; | |
193 | else | ||
194 | 28326 | uvalue = 2 * (uint32_t)-value; | |
195 | |||
196 | 84001 | len = av_log2(uvalue + 1); | |
197 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 84001 times.
|
84001 | if (put_bits_left(pbc) < 2 * len + 1) |
198 | ✗ | return AVERROR(ENOSPC); | |
199 | |||
200 | 84001 | put_bits(pbc, len, 0); | |
201 |
1/2✓ Branch 0 taken 84001 times.
✗ Branch 1 not taken.
|
84001 | if (len + 1 < 32) |
202 | 84001 | put_bits(pbc, len + 1, uvalue + 1); | |
203 | else | ||
204 | ✗ | put_bits32(pbc, uvalue + 1); | |
205 | |||
206 |
3/4✓ Branch 0 taken 83431 times.
✓ Branch 1 taken 570 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 83431 times.
|
84001 | CBS_TRACE_WRITE_END(); |
207 | |||
208 | 84001 | return 0; | |
209 | } | ||
210 | |||
211 | // payload_extension_present() - true if we are before the last 1-bit | ||
212 | // in the payload structure, which must be in the last byte. | ||
213 | 5 | static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t payload_size, | |
214 | int cur_pos) | ||
215 | { | ||
216 | 5 | int bits_left = payload_size * 8 - cur_pos; | |
217 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
5 | return (bits_left > 0 && |
218 | ✗ | (bits_left > 7 || show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1))); | |
219 | } | ||
220 | |||
221 | #define HEADER(name) do { \ | ||
222 | ff_cbs_trace_header(ctx, name); \ | ||
223 | } while (0) | ||
224 | |||
225 | #define CHECK(call) do { \ | ||
226 | err = (call); \ | ||
227 | if (err < 0) \ | ||
228 | return err; \ | ||
229 | } while (0) | ||
230 | |||
231 | #define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name | ||
232 | #define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name) | ||
233 | #define FUNC_H264(name) FUNC_NAME1(READWRITE, h264, name) | ||
234 | #define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name) | ||
235 | #define FUNC_H266(name) FUNC_NAME1(READWRITE, h266, name) | ||
236 | #define FUNC_SEI(name) FUNC_NAME1(READWRITE, sei, name) | ||
237 | |||
238 | #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) | ||
239 | |||
240 | #define u(width, name, range_min, range_max) \ | ||
241 | xu(width, name, current->name, range_min, range_max, 0, ) | ||
242 | #define flag(name) ub(1, name) | ||
243 | #define ue(name, range_min, range_max) \ | ||
244 | xue(name, current->name, range_min, range_max, 0, ) | ||
245 | #define i(width, name, range_min, range_max) \ | ||
246 | xi(width, name, current->name, range_min, range_max, 0, ) | ||
247 | #define ib(width, name) \ | ||
248 | xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, ) | ||
249 | #define se(name, range_min, range_max) \ | ||
250 | xse(name, current->name, range_min, range_max, 0, ) | ||
251 | |||
252 | #define us(width, name, range_min, range_max, subs, ...) \ | ||
253 | xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__) | ||
254 | #define ubs(width, name, subs, ...) \ | ||
255 | xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__) | ||
256 | #define flags(name, subs, ...) \ | ||
257 | xu(1, name, current->name, 0, 1, subs, __VA_ARGS__) | ||
258 | #define ues(name, range_min, range_max, subs, ...) \ | ||
259 | xue(name, current->name, range_min, range_max, subs, __VA_ARGS__) | ||
260 | #define is(width, name, range_min, range_max, subs, ...) \ | ||
261 | xi(width, name, current->name, range_min, range_max, subs, __VA_ARGS__) | ||
262 | #define ibs(width, name, subs, ...) \ | ||
263 | xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), subs, __VA_ARGS__) | ||
264 | #define ses(name, range_min, range_max, subs, ...) \ | ||
265 | xse(name, current->name, range_min, range_max, subs, __VA_ARGS__) | ||
266 | |||
267 | #define fixed(width, name, value) do { \ | ||
268 | av_unused uint32_t fixed_value = value; \ | ||
269 | xu(width, name, fixed_value, value, value, 0, ); \ | ||
270 | } while (0) | ||
271 | |||
272 | |||
273 | #define READ | ||
274 | #define READWRITE read | ||
275 | #define RWContext GetBitContext | ||
276 | |||
277 | #define ub(width, name) do { \ | ||
278 | uint32_t value; \ | ||
279 | CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \ | ||
280 | &value)); \ | ||
281 | current->name = value; \ | ||
282 | } while (0) | ||
283 | #define xu(width, name, var, range_min, range_max, subs, ...) do { \ | ||
284 | uint32_t value; \ | ||
285 | CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \ | ||
286 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
287 | &value, range_min, range_max)); \ | ||
288 | var = value; \ | ||
289 | } while (0) | ||
290 | #define xue(name, var, range_min, range_max, subs, ...) do { \ | ||
291 | uint32_t value; \ | ||
292 | CHECK(cbs_read_ue_golomb(ctx, rw, #name, \ | ||
293 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
294 | &value, range_min, range_max)); \ | ||
295 | var = value; \ | ||
296 | } while (0) | ||
297 | #define xi(width, name, var, range_min, range_max, subs, ...) do { \ | ||
298 | int32_t value; \ | ||
299 | CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \ | ||
300 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
301 | &value, range_min, range_max)); \ | ||
302 | var = value; \ | ||
303 | } while (0) | ||
304 | #define xse(name, var, range_min, range_max, subs, ...) do { \ | ||
305 | int32_t value; \ | ||
306 | CHECK(cbs_read_se_golomb(ctx, rw, #name, \ | ||
307 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
308 | &value, range_min, range_max)); \ | ||
309 | var = value; \ | ||
310 | } while (0) | ||
311 | |||
312 | |||
313 | #define infer(name, value) do { \ | ||
314 | current->name = value; \ | ||
315 | } while (0) | ||
316 | |||
317 | 24687 | static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) | |
318 | { | ||
319 | 24687 | int bits_left = get_bits_left(gbc); | |
320 |
2/2✓ Branch 0 taken 18358 times.
✓ Branch 1 taken 6329 times.
|
24687 | if (bits_left > 8) |
321 | 18358 | return 1; | |
322 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6329 times.
|
6329 | if (bits_left == 0) |
323 | ✗ | return 0; | |
324 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 2 taken 6322 times.
|
6329 | if (show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1)) |
325 | 7 | return 1; | |
326 | 6322 | return 0; | |
327 | } | ||
328 | |||
329 | #define more_rbsp_data(var) ((var) = cbs_h2645_read_more_rbsp_data(rw)) | ||
330 | |||
331 | #define bit_position(rw) (get_bits_count(rw)) | ||
332 | #define byte_alignment(rw) (get_bits_count(rw) % 8) | ||
333 | |||
334 | /* The CBS SEI code uses the refstruct API for the allocation | ||
335 | * of its child buffers. */ | ||
336 | #define allocate(name, size) do { \ | ||
337 | name = ff_refstruct_allocz(size + \ | ||
338 | AV_INPUT_BUFFER_PADDING_SIZE); \ | ||
339 | if (!name) \ | ||
340 | return AVERROR(ENOMEM); \ | ||
341 | } while (0) | ||
342 | |||
343 | #define FUNC(name) FUNC_SEI(name) | ||
344 | #include "cbs_sei_syntax_template.c" | ||
345 | #undef FUNC | ||
346 | |||
347 | #undef allocate | ||
348 | |||
349 | /* The other code uses the refstruct API for the allocation | ||
350 | * of its child buffers. */ | ||
351 | #define allocate(name, size) do { \ | ||
352 | name ## _ref = av_buffer_allocz(size + \ | ||
353 | AV_INPUT_BUFFER_PADDING_SIZE); \ | ||
354 | if (!name ## _ref) \ | ||
355 | return AVERROR(ENOMEM); \ | ||
356 | name = name ## _ref->data; \ | ||
357 | } while (0) | ||
358 | |||
359 | #define FUNC(name) FUNC_H264(name) | ||
360 | #include "cbs_h264_syntax_template.c" | ||
361 | #undef FUNC | ||
362 | |||
363 | #define FUNC(name) FUNC_H265(name) | ||
364 | #include "cbs_h265_syntax_template.c" | ||
365 | #undef FUNC | ||
366 | |||
367 | #define FUNC(name) FUNC_H266(name) | ||
368 | #include "cbs_h266_syntax_template.c" | ||
369 | #undef FUNC | ||
370 | |||
371 | #undef READ | ||
372 | #undef READWRITE | ||
373 | #undef RWContext | ||
374 | #undef ub | ||
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 ub(width, name) do { \ | ||
391 | uint32_t value = current->name; \ | ||
392 | CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \ | ||
393 | value)); \ | ||
394 | } while (0) | ||
395 | #define xu(width, name, var, range_min, range_max, subs, ...) do { \ | ||
396 | uint32_t value = var; \ | ||
397 | CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \ | ||
398 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
399 | value, range_min, range_max)); \ | ||
400 | } while (0) | ||
401 | #define xue(name, var, range_min, range_max, subs, ...) do { \ | ||
402 | uint32_t value = var; \ | ||
403 | CHECK(cbs_write_ue_golomb(ctx, rw, #name, \ | ||
404 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
405 | value, range_min, range_max)); \ | ||
406 | } while (0) | ||
407 | #define xi(width, name, var, range_min, range_max, subs, ...) do { \ | ||
408 | int32_t value = var; \ | ||
409 | CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \ | ||
410 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
411 | value, range_min, range_max)); \ | ||
412 | } while (0) | ||
413 | #define xse(name, var, range_min, range_max, subs, ...) do { \ | ||
414 | int32_t value = var; \ | ||
415 | CHECK(cbs_write_se_golomb(ctx, rw, #name, \ | ||
416 | SUBSCRIPTS(subs, __VA_ARGS__), \ | ||
417 | value, range_min, range_max)); \ | ||
418 | } while (0) | ||
419 | |||
420 | #define infer(name, value) do { \ | ||
421 | if (current->name != (value)) { \ | ||
422 | av_log(ctx->log_ctx, AV_LOG_ERROR, \ | ||
423 | "%s does not match inferred value: " \ | ||
424 | "%"PRId64", but should be %"PRId64".\n", \ | ||
425 | #name, (int64_t)current->name, (int64_t)(value)); \ | ||
426 | return AVERROR_INVALIDDATA; \ | ||
427 | } \ | ||
428 | } while (0) | ||
429 | |||
430 | #define more_rbsp_data(var) (var) | ||
431 | |||
432 | #define bit_position(rw) (put_bits_count(rw)) | ||
433 | #define byte_alignment(rw) (put_bits_count(rw) % 8) | ||
434 | |||
435 | #define allocate(name, size) do { \ | ||
436 | if (!name) { \ | ||
437 | av_log(ctx->log_ctx, AV_LOG_ERROR, "%s must be set " \ | ||
438 | "for writing.\n", #name); \ | ||
439 | return AVERROR_INVALIDDATA; \ | ||
440 | } \ | ||
441 | } while (0) | ||
442 | |||
443 | #define FUNC(name) FUNC_SEI(name) | ||
444 | #include "cbs_sei_syntax_template.c" | ||
445 | #undef FUNC | ||
446 | |||
447 | #define FUNC(name) FUNC_H264(name) | ||
448 | #include "cbs_h264_syntax_template.c" | ||
449 | #undef FUNC | ||
450 | |||
451 | #define FUNC(name) FUNC_H265(name) | ||
452 | #include "cbs_h265_syntax_template.c" | ||
453 | #undef FUNC | ||
454 | |||
455 | #define FUNC(name) FUNC_H266(name) | ||
456 | #include "cbs_h266_syntax_template.c" | ||
457 | #undef FUNC | ||
458 | |||
459 | #undef WRITE | ||
460 | #undef READWRITE | ||
461 | #undef RWContext | ||
462 | #undef ub | ||
463 | #undef xu | ||
464 | #undef xi | ||
465 | #undef xue | ||
466 | #undef xse | ||
467 | #undef u | ||
468 | #undef i | ||
469 | #undef flag | ||
470 | #undef ue | ||
471 | #undef se | ||
472 | #undef infer | ||
473 | #undef more_rbsp_data | ||
474 | #undef bit_position | ||
475 | #undef byte_alignment | ||
476 | #undef allocate | ||
477 | |||
478 | |||
479 | 9975 | static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, | |
480 | CodedBitstreamFragment *frag, | ||
481 | const H2645Packet *packet) | ||
482 | { | ||
483 | int err, i; | ||
484 | |||
485 |
2/2✓ Branch 0 taken 30156 times.
✓ Branch 1 taken 9975 times.
|
40131 | for (i = 0; i < packet->nb_nals; i++) { |
486 | 30156 | const H2645NAL *nal = &packet->nals[i]; | |
487 | AVBufferRef *ref; | ||
488 | 30156 | size_t size = nal->size; | |
489 | 30156 | enum AVCodecID codec_id = ctx->codec->codec_id; | |
490 | |||
491 |
3/4✓ Branch 0 taken 18602 times.
✓ Branch 1 taken 11554 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18602 times.
|
30156 | if (codec_id != AV_CODEC_ID_VVC && nal->nuh_layer_id > 0) |
492 | ✗ | continue; | |
493 | |||
494 | // Remove trailing zeroes. | ||
495 |
3/4✓ Branch 0 taken 39718 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9562 times.
✓ Branch 3 taken 30156 times.
|
39718 | while (size > 0 && nal->data[size - 1] == 0) |
496 | 9562 | --size; | |
497 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30156 times.
|
30156 | if (size == 0) { |
498 | ✗ | av_log(ctx->log_ctx, AV_LOG_VERBOSE, "Discarding empty 0 NAL unit\n"); | |
499 | ✗ | continue; | |
500 | } | ||
501 | |||
502 | 60312 | ref = (nal->data == nal->raw_data) ? frag->data_ref | |
503 |
2/2✓ Branch 0 taken 22302 times.
✓ Branch 1 taken 7854 times.
|
30156 | : packet->rbsp.rbsp_buffer_ref; |
504 | |||
505 | 30156 | err = ff_cbs_append_unit_data(frag, nal->type, | |
506 | 30156 | (uint8_t*)nal->data, size, ref); | |
507 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30156 times.
|
30156 | if (err < 0) |
508 | ✗ | return err; | |
509 | } | ||
510 | |||
511 | 9975 | return 0; | |
512 | } | ||
513 | |||
514 | 9966 | static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, | |
515 | CodedBitstreamFragment *frag, | ||
516 | int header) | ||
517 | { | ||
518 | 9966 | enum AVCodecID codec_id = ctx->codec->codec_id; | |
519 | 9966 | CodedBitstreamH2645Context *priv = ctx->priv_data; | |
520 | GetByteContext gbc; | ||
521 | int err; | ||
522 | |||
523 |
2/4✓ Branch 0 taken 9966 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9966 times.
|
9966 | av_assert0(frag->data && frag->nb_units == 0); |
524 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9966 times.
|
9966 | if (frag->data_size == 0) |
525 | ✗ | return 0; | |
526 | |||
527 |
5/6✓ Branch 0 taken 102 times.
✓ Branch 1 taken 9864 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 93 times.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
|
9975 | if (header && frag->data[0] && codec_id == AV_CODEC_ID_H264) { |
528 | // AVCC header. | ||
529 | size_t size, start, end; | ||
530 | int i, count, version; | ||
531 | |||
532 | 9 | priv->mp4 = 1; | |
533 | |||
534 | 9 | bytestream2_init(&gbc, frag->data, frag->data_size); | |
535 | |||
536 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
|
9 | if (bytestream2_get_bytes_left(&gbc) < 6) |
537 | ✗ | return AVERROR_INVALIDDATA; | |
538 | |||
539 | 9 | version = bytestream2_get_byte(&gbc); | |
540 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (version != 1) { |
541 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid AVCC header: " | |
542 | "first byte %u.\n", version); | ||
543 | ✗ | return AVERROR_INVALIDDATA; | |
544 | } | ||
545 | |||
546 | 9 | bytestream2_skip(&gbc, 3); | |
547 | 9 | priv->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1; | |
548 | |||
549 | // SPS array. | ||
550 | 9 | count = bytestream2_get_byte(&gbc) & 0x1f; | |
551 | 9 | start = bytestream2_tell(&gbc); | |
552 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 9 times.
|
17 | for (i = 0; i < count; i++) { |
553 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i)) |
554 | ✗ | return AVERROR_INVALIDDATA; | |
555 | 8 | size = bytestream2_get_be16(&gbc); | |
556 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if (bytestream2_get_bytes_left(&gbc) < size) |
557 | ✗ | return AVERROR_INVALIDDATA; | |
558 | 8 | bytestream2_skip(&gbc, size); | |
559 | } | ||
560 | 9 | end = bytestream2_tell(&gbc); | |
561 | |||
562 | 9 | err = ff_h2645_packet_split(&priv->read_packet, | |
563 | 9 | frag->data + start, end - start, | |
564 | ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); | ||
565 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (err < 0) { |
566 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n"); | |
567 | ✗ | return err; | |
568 | } | ||
569 | 9 | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
570 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (err < 0) |
571 | ✗ | return err; | |
572 | |||
573 | // PPS array. | ||
574 | 9 | count = bytestream2_get_byte(&gbc); | |
575 | 9 | start = bytestream2_tell(&gbc); | |
576 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 9 times.
|
17 | for (i = 0; i < count; i++) { |
577 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i)) |
578 | ✗ | return AVERROR_INVALIDDATA; | |
579 | 8 | size = bytestream2_get_be16(&gbc); | |
580 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if (bytestream2_get_bytes_left(&gbc) < size) |
581 | ✗ | return AVERROR_INVALIDDATA; | |
582 | 8 | bytestream2_skip(&gbc, size); | |
583 | } | ||
584 | 9 | end = bytestream2_tell(&gbc); | |
585 | |||
586 | 9 | err = ff_h2645_packet_split(&priv->read_packet, | |
587 | 9 | frag->data + start, end - start, | |
588 | ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); | ||
589 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (err < 0) { |
590 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n"); | |
591 | ✗ | return err; | |
592 | } | ||
593 | 9 | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
594 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (err < 0) |
595 | ✗ | return err; | |
596 | |||
597 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 7 times.
|
9 | if (bytestream2_get_bytes_left(&gbc) > 0) { |
598 | 2 | av_log(ctx->log_ctx, AV_LOG_WARNING, "%u bytes left at end of AVCC " | |
599 | "header.\n", bytestream2_get_bytes_left(&gbc)); | ||
600 | } | ||
601 | |||
602 |
3/6✓ Branch 0 taken 93 times.
✓ Branch 1 taken 9864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 93 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
9957 | } else if (header && frag->data[0] && codec_id == AV_CODEC_ID_HEVC) { |
603 | // HVCC header. | ||
604 | size_t size, start, end; | ||
605 | int i, j, nb_arrays, nal_unit_type, nb_nals, version; | ||
606 | |||
607 | ✗ | priv->mp4 = 1; | |
608 | |||
609 | ✗ | bytestream2_init(&gbc, frag->data, frag->data_size); | |
610 | |||
611 | ✗ | if (bytestream2_get_bytes_left(&gbc) < 23) | |
612 | ✗ | return AVERROR_INVALIDDATA; | |
613 | |||
614 | ✗ | version = bytestream2_get_byte(&gbc); | |
615 | ✗ | if (version != 1) { | |
616 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid HVCC header: " | |
617 | "first byte %u.\n", version); | ||
618 | ✗ | return AVERROR_INVALIDDATA; | |
619 | } | ||
620 | |||
621 | ✗ | bytestream2_skip(&gbc, 20); | |
622 | ✗ | priv->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1; | |
623 | |||
624 | ✗ | nb_arrays = bytestream2_get_byte(&gbc); | |
625 | ✗ | for (i = 0; i < nb_arrays; i++) { | |
626 | ✗ | nal_unit_type = bytestream2_get_byte(&gbc) & 0x3f; | |
627 | ✗ | nb_nals = bytestream2_get_be16(&gbc); | |
628 | |||
629 | ✗ | start = bytestream2_tell(&gbc); | |
630 | ✗ | for (j = 0; j < nb_nals; j++) { | |
631 | ✗ | if (bytestream2_get_bytes_left(&gbc) < 2) | |
632 | ✗ | return AVERROR_INVALIDDATA; | |
633 | ✗ | size = bytestream2_get_be16(&gbc); | |
634 | ✗ | if (bytestream2_get_bytes_left(&gbc) < size) | |
635 | ✗ | return AVERROR_INVALIDDATA; | |
636 | ✗ | bytestream2_skip(&gbc, size); | |
637 | } | ||
638 | ✗ | end = bytestream2_tell(&gbc); | |
639 | |||
640 | ✗ | err = ff_h2645_packet_split(&priv->read_packet, | |
641 | ✗ | frag->data + start, end - start, | |
642 | ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 1); | ||
643 | ✗ | if (err < 0) { | |
644 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " | |
645 | "HVCC array %d (%d NAL units of type %d).\n", | ||
646 | i, nb_nals, nal_unit_type); | ||
647 | ✗ | return err; | |
648 | } | ||
649 | ✗ | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
650 | ✗ | if (err < 0) | |
651 | ✗ | return err; | |
652 | } | ||
653 | |||
654 |
3/6✓ Branch 0 taken 93 times.
✓ Branch 1 taken 9864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 93 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
9957 | } else if(header && frag->data[0] && codec_id == AV_CODEC_ID_VVC) { |
655 | // VVCC header. | ||
656 | int ptl_present_flag, num_arrays; | ||
657 | int b, i, j; | ||
658 | |||
659 | ✗ | priv->mp4 = 1; | |
660 | |||
661 | ✗ | bytestream2_init(&gbc, frag->data, frag->data_size); | |
662 | |||
663 | ✗ | b = bytestream2_get_byte(&gbc); | |
664 | ✗ | priv->nal_length_size = ((b >> 1) & 3) + 1; | |
665 | ✗ | ptl_present_flag = b & 1; | |
666 | |||
667 | ✗ | if(ptl_present_flag) { | |
668 | int num_sublayers, num_bytes_constraint_info, num_sub_profiles; | ||
669 | ✗ | num_sublayers = (bytestream2_get_be16u(&gbc) >> 4) & 7; | |
670 | ✗ | bytestream2_skip(&gbc, 1); | |
671 | |||
672 | // begin VvcPTLRecord(num_sublayers); | ||
673 | ✗ | num_bytes_constraint_info = bytestream2_get_byte(&gbc) & 0x3f; | |
674 | ✗ | bytestream2_skip(&gbc, 2 + num_bytes_constraint_info); | |
675 | ✗ | if(num_sublayers > 1) { | |
676 | ✗ | int count_present_flags = 0; | |
677 | ✗ | b = bytestream2_get_byte(&gbc); | |
678 | ✗ | for(i = num_sublayers - 2; i >= 0; i--) { | |
679 | ✗ | if((b >> (7 - (num_sublayers - 2 - i))) & 0x01) | |
680 | ✗ | count_present_flags++; | |
681 | } | ||
682 | ✗ | bytestream2_skip(&gbc, count_present_flags); | |
683 | } | ||
684 | ✗ | num_sub_profiles = bytestream2_get_byte(&gbc); | |
685 | ✗ | bytestream2_skip(&gbc, num_sub_profiles * 4); | |
686 | // end VvcPTLRecord(num_sublayers); | ||
687 | |||
688 | ✗ | bytestream2_skip(&gbc, 3 * 2); | |
689 | } | ||
690 | |||
691 | ✗ | num_arrays = bytestream2_get_byte(&gbc); | |
692 | ✗ | for(j = 0; j < num_arrays; j++) { | |
693 | size_t start, end, size; | ||
694 | ✗ | int nal_unit_type = bytestream2_get_byte(&gbc) & 0x1f; | |
695 | ✗ | unsigned int num_nalus = 1; | |
696 | ✗ | if(nal_unit_type != VVC_DCI_NUT && nal_unit_type != VVC_OPI_NUT) | |
697 | ✗ | num_nalus = bytestream2_get_be16(&gbc); | |
698 | |||
699 | ✗ | start = bytestream2_tell(&gbc); | |
700 | ✗ | for(i = 0; i < num_nalus; i++) { | |
701 | ✗ | size = bytestream2_get_be16(&gbc); | |
702 | ✗ | bytestream2_skip(&gbc, size); | |
703 | } | ||
704 | ✗ | end = bytestream2_tell(&gbc); | |
705 | |||
706 | ✗ | err = ff_h2645_packet_split(&priv->read_packet, | |
707 | ✗ | frag->data + start, end - start, | |
708 | ctx->log_ctx, 1, 2, AV_CODEC_ID_VVC, 1, 1); | ||
709 | ✗ | if (err < 0) { | |
710 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " | |
711 | "VVCC array %d (%d NAL units of type %d).\n", | ||
712 | i, num_nalus, nal_unit_type); | ||
713 | ✗ | return err; | |
714 | } | ||
715 | ✗ | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
716 | ✗ | if (err < 0) | |
717 | ✗ | return err; | |
718 | } | ||
719 | } else { | ||
720 | // Annex B, or later MP4 with already-known parameters. | ||
721 | |||
722 | 9957 | err = ff_h2645_packet_split(&priv->read_packet, | |
723 | 9957 | frag->data, frag->data_size, | |
724 | ctx->log_ctx, | ||
725 | priv->mp4, priv->nal_length_size, | ||
726 | codec_id, 1, 1); | ||
727 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9957 times.
|
9957 | if (err < 0) |
728 | ✗ | return err; | |
729 | |||
730 | 9957 | err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet); | |
731 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9957 times.
|
9957 | if (err < 0) |
732 | ✗ | return err; | |
733 | } | ||
734 | |||
735 | 9966 | return 0; | |
736 | } | ||
737 | |||
738 | #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \ | ||
739 | static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \ | ||
740 | CodedBitstreamUnit *unit) \ | ||
741 | { \ | ||
742 | CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \ | ||
743 | H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \ | ||
744 | unsigned int id = ps_var->id_element; \ | ||
745 | int err = ff_cbs_make_unit_refcounted(ctx, unit); \ | ||
746 | if (err < 0) \ | ||
747 | return err; \ | ||
748 | if (priv->ps_var[id] == priv->active_ ## ps_var) \ | ||
749 | priv->active_ ## ps_var = NULL ; \ | ||
750 | av_assert0(unit->content_ref); \ | ||
751 | ff_refstruct_replace(&priv->ps_var[id], unit->content_ref); \ | ||
752 | return 0; \ | ||
753 | } | ||
754 | |||
755 |
4/6✗ Branch 1 not taken.
✓ Branch 2 taken 146 times.
✓ Branch 3 taken 106 times.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 146 times.
|
146 | cbs_h2645_replace_ps(4, SPS, sps, seq_parameter_set_id) |
756 |
4/6✗ Branch 1 not taken.
✓ Branch 2 taken 2990 times.
✓ Branch 3 taken 2936 times.
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2990 times.
|
2990 | cbs_h2645_replace_ps(4, PPS, pps, pic_parameter_set_id) |
757 |
3/6✗ Branch 1 not taken.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 112 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 112 times.
|
112 | cbs_h2645_replace_ps(5, VPS, vps, vps_video_parameter_set_id) |
758 |
4/6✗ Branch 1 not taken.
✓ Branch 2 taken 116 times.
✓ Branch 3 taken 114 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 116 times.
|
116 | cbs_h2645_replace_ps(5, SPS, sps, sps_seq_parameter_set_id) |
759 |
4/6✗ Branch 1 not taken.
✓ Branch 2 taken 566 times.
✓ Branch 3 taken 386 times.
✓ Branch 4 taken 180 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 566 times.
|
566 | cbs_h2645_replace_ps(5, PPS, pps, pps_pic_parameter_set_id) |
760 | |||
761 | #define cbs_h266_replace_ps(h26n, ps_name, ps_var, id_element) \ | ||
762 | static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \ | ||
763 | CodedBitstreamUnit *unit) \ | ||
764 | { \ | ||
765 | CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \ | ||
766 | H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \ | ||
767 | unsigned int id = ps_var->id_element; \ | ||
768 | int err = ff_cbs_make_unit_refcounted(ctx, unit); \ | ||
769 | if (err < 0) \ | ||
770 | return err; \ | ||
771 | av_assert0(unit->content_ref); \ | ||
772 | ff_refstruct_replace(&priv->ps_var[id], unit->content_ref); \ | ||
773 | return 0; \ | ||
774 | } | ||
775 | |||
776 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
|
12 | cbs_h266_replace_ps(6, VPS, vps, vps_video_parameter_set_id) |
777 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1005 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1005 times.
|
1005 | cbs_h266_replace_ps(6, SPS, sps, sps_seq_parameter_set_id) |
778 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1173 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1173 times.
|
1173 | cbs_h266_replace_ps(6, PPS, pps, pps_pic_parameter_set_id) |
779 | |||
780 | 6390 | static int cbs_h266_replace_ph(CodedBitstreamContext *ctx, | |
781 | CodedBitstreamUnit *unit, | ||
782 | H266RawPictureHeader *ph) | ||
783 | { | ||
784 | 6390 | CodedBitstreamH266Context *h266 = ctx->priv_data; | |
785 | int err; | ||
786 | |||
787 | 6390 | err = ff_cbs_make_unit_refcounted(ctx, unit); | |
788 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6390 times.
|
6390 | if (err < 0) |
789 | ✗ | return err; | |
790 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6390 times.
|
6390 | av_assert0(unit->content_ref); |
791 | 6390 | ff_refstruct_replace(&h266->ph_ref, unit->content_ref); | |
792 | 6390 | h266->ph = ph; | |
793 | 6390 | return 0; | |
794 | } | ||
795 | |||
796 | 9230 | static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, | |
797 | CodedBitstreamUnit *unit) | ||
798 | { | ||
799 | GetBitContext gbc; | ||
800 | int err; | ||
801 | |||
802 | 9230 | err = init_get_bits(&gbc, unit->data, 8 * unit->data_size); | |
803 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9230 times.
|
9230 | if (err < 0) |
804 | ✗ | return err; | |
805 | |||
806 | 9230 | err = ff_cbs_alloc_unit_content(ctx, unit); | |
807 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9230 times.
|
9230 | if (err < 0) |
808 | ✗ | return err; | |
809 | |||
810 |
7/9✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1495 times.
✓ Branch 3 taken 5973 times.
✓ Branch 4 taken 739 times.
✓ Branch 5 taken 913 times.
✓ Branch 6 taken 34 times.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
9230 | switch (unit->type) { |
811 | 73 | case H264_NAL_SPS: | |
812 | { | ||
813 | 73 | H264RawSPS *sps = unit->content; | |
814 | |||
815 | 73 | err = cbs_h264_read_sps(ctx, &gbc, sps); | |
816 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
|
73 | if (err < 0) |
817 | ✗ | return err; | |
818 | |||
819 | 73 | err = cbs_h264_replace_sps(ctx, unit); | |
820 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
|
73 | if (err < 0) |
821 | ✗ | return err; | |
822 | } | ||
823 | 73 | break; | |
824 | |||
825 | ✗ | case H264_NAL_SPS_EXT: | |
826 | { | ||
827 | ✗ | err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content); | |
828 | ✗ | if (err < 0) | |
829 | ✗ | return err; | |
830 | } | ||
831 | ✗ | break; | |
832 | |||
833 | 1495 | case H264_NAL_PPS: | |
834 | { | ||
835 | 1495 | H264RawPPS *pps = unit->content; | |
836 | |||
837 | 1495 | err = cbs_h264_read_pps(ctx, &gbc, pps); | |
838 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1495 times.
|
1495 | if (err < 0) |
839 | ✗ | return err; | |
840 | |||
841 | 1495 | err = cbs_h264_replace_pps(ctx, unit); | |
842 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1495 times.
|
1495 | if (err < 0) |
843 | ✗ | return err; | |
844 | } | ||
845 | 1495 | break; | |
846 | |||
847 | 5973 | case H264_NAL_SLICE: | |
848 | case H264_NAL_IDR_SLICE: | ||
849 | case H264_NAL_AUXILIARY_SLICE: | ||
850 | { | ||
851 | 5973 | H264RawSlice *slice = unit->content; | |
852 | int pos, len; | ||
853 | |||
854 | 5973 | err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header); | |
855 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5973 times.
|
5973 | if (err < 0) |
856 | ✗ | return err; | |
857 | |||
858 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5973 times.
|
5973 | if (!cbs_h2645_read_more_rbsp_data(&gbc)) |
859 | ✗ | return AVERROR_INVALIDDATA; | |
860 | |||
861 | 5973 | pos = get_bits_count(&gbc); | |
862 | 5973 | len = unit->data_size; | |
863 | |||
864 | 5973 | slice->data_size = len - pos / 8; | |
865 | 5973 | slice->data_ref = av_buffer_ref(unit->data_ref); | |
866 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5973 times.
|
5973 | if (!slice->data_ref) |
867 | ✗ | return AVERROR(ENOMEM); | |
868 | 5973 | slice->data = unit->data + pos / 8; | |
869 | 5973 | slice->data_bit_start = pos % 8; | |
870 | } | ||
871 | 5973 | break; | |
872 | |||
873 | 739 | case H264_NAL_AUD: | |
874 | { | ||
875 | 739 | err = cbs_h264_read_aud(ctx, &gbc, unit->content); | |
876 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 739 times.
|
739 | if (err < 0) |
877 | ✗ | return err; | |
878 | } | ||
879 | 739 | break; | |
880 | |||
881 | 913 | case H264_NAL_SEI: | |
882 | { | ||
883 | 913 | err = cbs_h264_read_sei(ctx, &gbc, unit->content); | |
884 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 913 times.
|
913 | if (err < 0) |
885 | ✗ | return err; | |
886 | } | ||
887 | 913 | break; | |
888 | |||
889 | 34 | case H264_NAL_FILLER_DATA: | |
890 | { | ||
891 | 34 | err = cbs_h264_read_filler(ctx, &gbc, unit->content); | |
892 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 33 times.
|
34 | if (err < 0) |
893 | 1 | return err; | |
894 | } | ||
895 | 33 | break; | |
896 | |||
897 | 3 | case H264_NAL_END_SEQUENCE: | |
898 | case H264_NAL_END_STREAM: | ||
899 | { | ||
900 | 3 | err = (unit->type == H264_NAL_END_SEQUENCE ? | |
901 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | cbs_h264_read_end_of_sequence : |
902 | 3 | cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content); | |
903 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (err < 0) |
904 | ✗ | return err; | |
905 | } | ||
906 | 3 | break; | |
907 | |||
908 | ✗ | default: | |
909 | ✗ | return AVERROR(ENOSYS); | |
910 | } | ||
911 | |||
912 | 9229 | return 0; | |
913 | } | ||
914 | |||
915 | 9372 | static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, | |
916 | CodedBitstreamUnit *unit) | ||
917 | { | ||
918 | GetBitContext gbc; | ||
919 | int err; | ||
920 | |||
921 | 9372 | err = init_get_bits(&gbc, unit->data, 8 * unit->data_size); | |
922 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9372 times.
|
9372 | if (err < 0) |
923 | ✗ | return err; | |
924 | |||
925 | 9372 | err = ff_cbs_alloc_unit_content(ctx, unit); | |
926 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9372 times.
|
9372 | if (err < 0) |
927 | ✗ | return err; | |
928 | |||
929 |
6/7✓ Branch 0 taken 56 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 283 times.
✓ Branch 3 taken 7188 times.
✓ Branch 4 taken 60 times.
✓ Branch 5 taken 1727 times.
✗ Branch 6 not taken.
|
9372 | switch (unit->type) { |
930 | 56 | case HEVC_NAL_VPS: | |
931 | { | ||
932 | 56 | H265RawVPS *vps = unit->content; | |
933 | |||
934 | 56 | err = cbs_h265_read_vps(ctx, &gbc, vps); | |
935 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (err < 0) |
936 | ✗ | return err; | |
937 | |||
938 | 56 | err = cbs_h265_replace_vps(ctx, unit); | |
939 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (err < 0) |
940 | ✗ | return err; | |
941 | } | ||
942 | 56 | break; | |
943 | 58 | case HEVC_NAL_SPS: | |
944 | { | ||
945 | 58 | H265RawSPS *sps = unit->content; | |
946 | |||
947 | 58 | err = cbs_h265_read_sps(ctx, &gbc, sps); | |
948 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (err < 0) |
949 | ✗ | return err; | |
950 | |||
951 | 58 | err = cbs_h265_replace_sps(ctx, unit); | |
952 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (err < 0) |
953 | ✗ | return err; | |
954 | } | ||
955 | 58 | break; | |
956 | |||
957 | 283 | case HEVC_NAL_PPS: | |
958 | { | ||
959 | 283 | H265RawPPS *pps = unit->content; | |
960 | |||
961 | 283 | err = cbs_h265_read_pps(ctx, &gbc, pps); | |
962 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 283 times.
|
283 | if (err < 0) |
963 | ✗ | return err; | |
964 | |||
965 | 283 | err = cbs_h265_replace_pps(ctx, unit); | |
966 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 283 times.
|
283 | if (err < 0) |
967 | ✗ | return err; | |
968 | } | ||
969 | 283 | break; | |
970 | |||
971 | 7188 | case HEVC_NAL_TRAIL_N: | |
972 | case HEVC_NAL_TRAIL_R: | ||
973 | case HEVC_NAL_TSA_N: | ||
974 | case HEVC_NAL_TSA_R: | ||
975 | case HEVC_NAL_STSA_N: | ||
976 | case HEVC_NAL_STSA_R: | ||
977 | case HEVC_NAL_RADL_N: | ||
978 | case HEVC_NAL_RADL_R: | ||
979 | case HEVC_NAL_RASL_N: | ||
980 | case HEVC_NAL_RASL_R: | ||
981 | case HEVC_NAL_BLA_W_LP: | ||
982 | case HEVC_NAL_BLA_W_RADL: | ||
983 | case HEVC_NAL_BLA_N_LP: | ||
984 | case HEVC_NAL_IDR_W_RADL: | ||
985 | case HEVC_NAL_IDR_N_LP: | ||
986 | case HEVC_NAL_CRA_NUT: | ||
987 | { | ||
988 | 7188 | H265RawSlice *slice = unit->content; | |
989 | int pos, len; | ||
990 | |||
991 | 7188 | err = cbs_h265_read_slice_segment_header(ctx, &gbc, &slice->header); | |
992 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7188 times.
|
7188 | if (err < 0) |
993 | ✗ | return err; | |
994 | |||
995 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7188 times.
|
7188 | if (!cbs_h2645_read_more_rbsp_data(&gbc)) |
996 | ✗ | return AVERROR_INVALIDDATA; | |
997 | |||
998 | 7188 | pos = get_bits_count(&gbc); | |
999 | 7188 | len = unit->data_size; | |
1000 | |||
1001 | 7188 | slice->data_size = len - pos / 8; | |
1002 | 7188 | slice->data_ref = av_buffer_ref(unit->data_ref); | |
1003 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7188 times.
|
7188 | if (!slice->data_ref) |
1004 | ✗ | return AVERROR(ENOMEM); | |
1005 | 7188 | slice->data = unit->data + pos / 8; | |
1006 | 7188 | slice->data_bit_start = pos % 8; | |
1007 | } | ||
1008 | 7188 | break; | |
1009 | |||
1010 | 60 | case HEVC_NAL_AUD: | |
1011 | { | ||
1012 | 60 | err = cbs_h265_read_aud(ctx, &gbc, unit->content); | |
1013 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | if (err < 0) |
1014 | ✗ | return err; | |
1015 | } | ||
1016 | 60 | break; | |
1017 | |||
1018 | 1727 | case HEVC_NAL_SEI_PREFIX: | |
1019 | case HEVC_NAL_SEI_SUFFIX: | ||
1020 | { | ||
1021 | 1727 | err = cbs_h265_read_sei(ctx, &gbc, unit->content, | |
1022 | 1727 | unit->type == HEVC_NAL_SEI_PREFIX); | |
1023 | |||
1024 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1727 times.
|
1727 | if (err < 0) |
1025 | ✗ | return err; | |
1026 | } | ||
1027 | 1727 | break; | |
1028 | |||
1029 | ✗ | default: | |
1030 | ✗ | return AVERROR(ENOSYS); | |
1031 | } | ||
1032 | |||
1033 | 9372 | return 0; | |
1034 | } | ||
1035 | |||
1036 | 9134 | static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx, | |
1037 | CodedBitstreamUnit *unit) | ||
1038 | { | ||
1039 | GetBitContext gbc; | ||
1040 | int err; | ||
1041 | |||
1042 | 9134 | err = init_get_bits8(&gbc, unit->data, unit->data_size); | |
1043 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9134 times.
|
9134 | if (err < 0) |
1044 | ✗ | return err; | |
1045 | |||
1046 | 9134 | err = ff_cbs_alloc_unit_content(ctx, unit); | |
1047 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9134 times.
|
9134 | if (err < 0) |
1048 | ✗ | return err; | |
1049 | |||
1050 |
10/11✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 670 times.
✓ Branch 4 taken 782 times.
✓ Branch 5 taken 228 times.
✓ Branch 6 taken 54 times.
✓ Branch 7 taken 5176 times.
✓ Branch 8 taken 24 times.
✓ Branch 9 taken 2190 times.
✗ Branch 10 not taken.
|
9134 | switch (unit->type) { |
1051 | 1 | case VVC_DCI_NUT: | |
1052 | { | ||
1053 | 1 | err = cbs_h266_read_dci(ctx, &gbc, unit->content); | |
1054 | |||
1055 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
1056 | ✗ | return err; | |
1057 | } | ||
1058 | 1 | break; | |
1059 | 1 | case VVC_OPI_NUT: | |
1060 | { | ||
1061 | 1 | err = cbs_h266_read_opi(ctx, &gbc, unit->content); | |
1062 | |||
1063 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
1064 | ✗ | return err; | |
1065 | } | ||
1066 | 1 | break; | |
1067 | 8 | case VVC_VPS_NUT: | |
1068 | { | ||
1069 | 8 | H266RawVPS *vps = unit->content; | |
1070 | |||
1071 | 8 | err = cbs_h266_read_vps(ctx, &gbc, vps); | |
1072 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (err < 0) |
1073 | ✗ | return err; | |
1074 | |||
1075 | 8 | err = cbs_h266_replace_vps(ctx, unit); | |
1076 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (err < 0) |
1077 | ✗ | return err; | |
1078 | } | ||
1079 | 8 | break; | |
1080 | 670 | case VVC_SPS_NUT: | |
1081 | { | ||
1082 | 670 | H266RawSPS *sps = unit->content; | |
1083 | |||
1084 | 670 | err = cbs_h266_read_sps(ctx, &gbc, sps); | |
1085 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 670 times.
|
670 | if (err < 0) |
1086 | ✗ | return err; | |
1087 | |||
1088 | 670 | err = cbs_h266_replace_sps(ctx, unit); | |
1089 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 670 times.
|
670 | if (err < 0) |
1090 | ✗ | return err; | |
1091 | } | ||
1092 | 670 | break; | |
1093 | |||
1094 | 782 | case VVC_PPS_NUT: | |
1095 | { | ||
1096 | 782 | H266RawPPS *pps = unit->content; | |
1097 | |||
1098 | 782 | err = cbs_h266_read_pps(ctx, &gbc, pps); | |
1099 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 782 times.
|
782 | if (err < 0) |
1100 | ✗ | return err; | |
1101 | |||
1102 | 782 | err = cbs_h266_replace_pps(ctx, unit); | |
1103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 782 times.
|
782 | if (err < 0) |
1104 | ✗ | return err; | |
1105 | } | ||
1106 | 782 | break; | |
1107 | |||
1108 | 228 | case VVC_PREFIX_APS_NUT: | |
1109 | case VVC_SUFFIX_APS_NUT: | ||
1110 | { | ||
1111 | 228 | err = cbs_h266_read_aps(ctx, &gbc, unit->content, | |
1112 | 228 | unit->type == VVC_PREFIX_APS_NUT); | |
1113 | |||
1114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | if (err < 0) |
1115 | ✗ | return err; | |
1116 | } | ||
1117 | 228 | break; | |
1118 | 54 | case VVC_PH_NUT: | |
1119 | { | ||
1120 | 54 | H266RawPH *ph = unit->content; | |
1121 | 54 | err = cbs_h266_read_ph(ctx, &gbc, ph); | |
1122 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
|
54 | if (err < 0) |
1123 | ✗ | return err; | |
1124 | 54 | err = cbs_h266_replace_ph(ctx, unit, &ph->ph_picture_header); | |
1125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
|
54 | if (err < 0) |
1126 | ✗ | return err; | |
1127 | } | ||
1128 | 54 | break; | |
1129 | |||
1130 | 5176 | case VVC_TRAIL_NUT: | |
1131 | case VVC_STSA_NUT: | ||
1132 | case VVC_RADL_NUT: | ||
1133 | case VVC_RASL_NUT: | ||
1134 | case VVC_IDR_W_RADL: | ||
1135 | case VVC_IDR_N_LP: | ||
1136 | case VVC_CRA_NUT: | ||
1137 | case VVC_GDR_NUT: | ||
1138 | { | ||
1139 | 5176 | H266RawSlice *slice = unit->content; | |
1140 | int pos, len; | ||
1141 | |||
1142 | 5176 | err = cbs_h266_read_slice_header(ctx, &gbc, &slice->header); | |
1143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5176 times.
|
5176 | if (err < 0) |
1144 | ✗ | return err; | |
1145 | |||
1146 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 5176 times.
|
5176 | if (!cbs_h2645_read_more_rbsp_data(&gbc)) |
1147 | ✗ | return AVERROR_INVALIDDATA; | |
1148 | |||
1149 | 5176 | pos = get_bits_count(&gbc); | |
1150 | 5176 | len = unit->data_size; | |
1151 | |||
1152 |
2/2✓ Branch 0 taken 4206 times.
✓ Branch 1 taken 970 times.
|
5176 | if (slice->header.sh_picture_header_in_slice_header_flag) { |
1153 | 4206 | err = cbs_h266_replace_ph(ctx, unit, &slice->header.sh_picture_header); | |
1154 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4206 times.
|
4206 | if (err < 0) |
1155 | ✗ | return err; | |
1156 | } | ||
1157 | |||
1158 | 5176 | slice->data_size = len - pos / 8; | |
1159 | 5176 | slice->data_ref = av_buffer_ref(unit->data_ref); | |
1160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5176 times.
|
5176 | if (!slice->data_ref) |
1161 | ✗ | return AVERROR(ENOMEM); | |
1162 | 5176 | slice->data = unit->data + pos / 8; | |
1163 | 5176 | slice->data_bit_start = pos % 8; | |
1164 | } | ||
1165 | 5176 | break; | |
1166 | |||
1167 | 24 | case VVC_AUD_NUT: | |
1168 | { | ||
1169 | 24 | err = cbs_h266_read_aud(ctx, &gbc, unit->content); | |
1170 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (err < 0) |
1171 | ✗ | return err; | |
1172 | } | ||
1173 | 24 | break; | |
1174 | |||
1175 | 2190 | case VVC_PREFIX_SEI_NUT: | |
1176 | case VVC_SUFFIX_SEI_NUT: | ||
1177 | { | ||
1178 | 2190 | err = cbs_h266_read_sei(ctx, &gbc, unit->content, | |
1179 | 2190 | unit->type == VVC_PREFIX_SEI_NUT); | |
1180 | |||
1181 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2190 times.
|
2190 | if (err < 0) |
1182 | ✗ | return err; | |
1183 | } | ||
1184 | 2190 | break; | |
1185 | |||
1186 | ✗ | default: | |
1187 | ✗ | return AVERROR(ENOSYS); | |
1188 | } | ||
1189 | 9134 | return 0; | |
1190 | } | ||
1191 | |||
1192 | 14194 | static int cbs_h2645_write_slice_data(CodedBitstreamContext *ctx, | |
1193 | PutBitContext *pbc, const uint8_t *data, | ||
1194 | size_t data_size, int data_bit_start) | ||
1195 | { | ||
1196 | 14194 | size_t rest = data_size - (data_bit_start + 7) / 8; | |
1197 | 14194 | const uint8_t *pos = data + data_bit_start / 8; | |
1198 | |||
1199 |
2/4✓ Branch 0 taken 14194 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14194 times.
|
14194 | av_assert0(data_bit_start >= 0 && |
1200 | data_size > data_bit_start / 8); | ||
1201 | |||
1202 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 14194 times.
|
14194 | if (data_size * 8 + 8 > put_bits_left(pbc)) |
1203 | ✗ | return AVERROR(ENOSPC); | |
1204 | |||
1205 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 14193 times.
|
14194 | if (!rest) |
1206 | 1 | goto rbsp_stop_one_bit; | |
1207 | |||
1208 | // First copy the remaining bits of the first byte | ||
1209 | // The above check ensures that we do not accidentally | ||
1210 | // copy beyond the rbsp_stop_one_bit. | ||
1211 |
2/2✓ Branch 0 taken 3729 times.
✓ Branch 1 taken 10464 times.
|
14193 | if (data_bit_start % 8) |
1212 | 3729 | put_bits(pbc, 8 - data_bit_start % 8, | |
1213 | 3729 | *pos++ & MAX_UINT_BITS(8 - data_bit_start % 8)); | |
1214 | |||
1215 |
2/2✓ Branch 1 taken 14084 times.
✓ Branch 2 taken 109 times.
|
14193 | if (put_bits_count(pbc) % 8 == 0) { |
1216 | // If the writer is aligned at this point, | ||
1217 | // memcpy can be used to improve performance. | ||
1218 | // This happens normally for CABAC. | ||
1219 | 14084 | flush_put_bits(pbc); | |
1220 | 14084 | memcpy(put_bits_ptr(pbc), pos, rest); | |
1221 | 14084 | skip_put_bytes(pbc, rest); | |
1222 | } else { | ||
1223 | // If not, we have to copy manually. | ||
1224 | // rbsp_stop_one_bit forces us to special-case | ||
1225 | // the last byte. | ||
1226 | uint8_t temp; | ||
1227 | int i; | ||
1228 | |||
1229 |
2/2✓ Branch 0 taken 98762 times.
✓ Branch 1 taken 109 times.
|
98871 | for (; rest > 4; rest -= 4, pos += 4) |
1230 | 98762 | put_bits32(pbc, AV_RB32(pos)); | |
1231 | |||
1232 |
2/2✓ Branch 0 taken 165 times.
✓ Branch 1 taken 109 times.
|
274 | for (; rest > 1; rest--, pos++) |
1233 | 165 | put_bits(pbc, 8, *pos); | |
1234 | |||
1235 | 109 | rbsp_stop_one_bit: | |
1236 |
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); |
1237 | |||
1238 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 110 times.
|
110 | av_assert0(temp); |
1239 | 110 | i = ff_ctz(*pos); | |
1240 | 110 | temp = temp >> i; | |
1241 |
2/2✓ Branch 0 taken 109 times.
✓ Branch 1 taken 1 times.
|
110 | i = rest ? (8 - i) : (8 - i - data_bit_start % 8); |
1242 | 110 | put_bits(pbc, i, temp); | |
1243 |
2/2✓ Branch 1 taken 92 times.
✓ Branch 2 taken 18 times.
|
110 | if (put_bits_count(pbc) % 8) |
1244 | 92 | put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0); | |
1245 | } | ||
1246 | |||
1247 | 14194 | return 0; | |
1248 | } | ||
1249 | |||
1250 | 7953 | static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx, | |
1251 | CodedBitstreamUnit *unit, | ||
1252 | PutBitContext *pbc) | ||
1253 | { | ||
1254 | int err; | ||
1255 | |||
1256 |
7/10✓ Branch 0 taken 73 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1495 times.
✓ Branch 3 taken 5575 times.
✓ Branch 4 taken 302 times.
✓ Branch 5 taken 505 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
|
7953 | switch (unit->type) { |
1257 | 73 | case H264_NAL_SPS: | |
1258 | { | ||
1259 | 73 | H264RawSPS *sps = unit->content; | |
1260 | |||
1261 | 73 | err = cbs_h264_write_sps(ctx, pbc, sps); | |
1262 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
|
73 | if (err < 0) |
1263 | ✗ | return err; | |
1264 | |||
1265 | 73 | err = cbs_h264_replace_sps(ctx, unit); | |
1266 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 73 times.
|
73 | if (err < 0) |
1267 | ✗ | return err; | |
1268 | } | ||
1269 | 73 | break; | |
1270 | |||
1271 | ✗ | case H264_NAL_SPS_EXT: | |
1272 | { | ||
1273 | ✗ | H264RawSPSExtension *sps_ext = unit->content; | |
1274 | |||
1275 | ✗ | err = cbs_h264_write_sps_extension(ctx, pbc, sps_ext); | |
1276 | ✗ | if (err < 0) | |
1277 | ✗ | return err; | |
1278 | } | ||
1279 | ✗ | break; | |
1280 | |||
1281 | 1495 | case H264_NAL_PPS: | |
1282 | { | ||
1283 | 1495 | H264RawPPS *pps = unit->content; | |
1284 | |||
1285 | 1495 | err = cbs_h264_write_pps(ctx, pbc, pps); | |
1286 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1495 times.
|
1495 | if (err < 0) |
1287 | ✗ | return err; | |
1288 | |||
1289 | 1495 | err = cbs_h264_replace_pps(ctx, unit); | |
1290 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1495 times.
|
1495 | if (err < 0) |
1291 | ✗ | return err; | |
1292 | } | ||
1293 | 1495 | break; | |
1294 | |||
1295 | 5575 | case H264_NAL_SLICE: | |
1296 | case H264_NAL_IDR_SLICE: | ||
1297 | case H264_NAL_AUXILIARY_SLICE: | ||
1298 | { | ||
1299 | 5575 | H264RawSlice *slice = unit->content; | |
1300 | |||
1301 | 5575 | err = cbs_h264_write_slice_header(ctx, pbc, &slice->header); | |
1302 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5575 times.
|
5575 | if (err < 0) |
1303 | ✗ | return err; | |
1304 | |||
1305 |
1/2✓ Branch 0 taken 5575 times.
✗ Branch 1 not taken.
|
5575 | if (slice->data) { |
1306 | 5575 | err = cbs_h2645_write_slice_data(ctx, pbc, slice->data, | |
1307 | slice->data_size, | ||
1308 | slice->data_bit_start); | ||
1309 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5575 times.
|
5575 | if (err < 0) |
1310 | ✗ | return err; | |
1311 | } else { | ||
1312 | // No slice data - that was just the header. | ||
1313 | // (Bitstream may be unaligned!) | ||
1314 | } | ||
1315 | } | ||
1316 | 5575 | break; | |
1317 | |||
1318 | 302 | case H264_NAL_AUD: | |
1319 | { | ||
1320 | 302 | err = cbs_h264_write_aud(ctx, pbc, unit->content); | |
1321 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
|
302 | if (err < 0) |
1322 | ✗ | return err; | |
1323 | } | ||
1324 | 302 | break; | |
1325 | |||
1326 | 505 | case H264_NAL_SEI: | |
1327 | { | ||
1328 | 505 | err = cbs_h264_write_sei(ctx, pbc, unit->content); | |
1329 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 505 times.
|
505 | if (err < 0) |
1330 | ✗ | return err; | |
1331 | } | ||
1332 | 505 | break; | |
1333 | |||
1334 | ✗ | case H264_NAL_FILLER_DATA: | |
1335 | { | ||
1336 | ✗ | err = cbs_h264_write_filler(ctx, pbc, unit->content); | |
1337 | ✗ | if (err < 0) | |
1338 | ✗ | return err; | |
1339 | } | ||
1340 | ✗ | break; | |
1341 | |||
1342 | 1 | case H264_NAL_END_SEQUENCE: | |
1343 | { | ||
1344 | 1 | err = cbs_h264_write_end_of_sequence(ctx, pbc, unit->content); | |
1345 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
1346 | ✗ | return err; | |
1347 | } | ||
1348 | 1 | break; | |
1349 | |||
1350 | 2 | case H264_NAL_END_STREAM: | |
1351 | { | ||
1352 | 2 | err = cbs_h264_write_end_of_stream(ctx, pbc, unit->content); | |
1353 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (err < 0) |
1354 | ✗ | return err; | |
1355 | } | ||
1356 | 2 | break; | |
1357 | |||
1358 | ✗ | default: | |
1359 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for " | |
1360 | "NAL unit type %"PRIu32".\n", unit->type); | ||
1361 | ✗ | return AVERROR_PATCHWELCOME; | |
1362 | } | ||
1363 | |||
1364 | 7953 | return 0; | |
1365 | } | ||
1366 | |||
1367 | 8050 | static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx, | |
1368 | CodedBitstreamUnit *unit, | ||
1369 | PutBitContext *pbc) | ||
1370 | { | ||
1371 | int err; | ||
1372 | |||
1373 |
6/7✓ Branch 0 taken 56 times.
✓ Branch 1 taken 58 times.
✓ Branch 2 taken 283 times.
✓ Branch 3 taken 6031 times.
✓ Branch 4 taken 60 times.
✓ Branch 5 taken 1562 times.
✗ Branch 6 not taken.
|
8050 | switch (unit->type) { |
1374 | 56 | case HEVC_NAL_VPS: | |
1375 | { | ||
1376 | 56 | H265RawVPS *vps = unit->content; | |
1377 | |||
1378 | 56 | err = cbs_h265_write_vps(ctx, pbc, vps); | |
1379 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (err < 0) |
1380 | ✗ | return err; | |
1381 | |||
1382 | 56 | err = cbs_h265_replace_vps(ctx, unit); | |
1383 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (err < 0) |
1384 | ✗ | return err; | |
1385 | } | ||
1386 | 56 | break; | |
1387 | |||
1388 | 58 | case HEVC_NAL_SPS: | |
1389 | { | ||
1390 | 58 | H265RawSPS *sps = unit->content; | |
1391 | |||
1392 | 58 | err = cbs_h265_write_sps(ctx, pbc, sps); | |
1393 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (err < 0) |
1394 | ✗ | return err; | |
1395 | |||
1396 | 58 | err = cbs_h265_replace_sps(ctx, unit); | |
1397 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (err < 0) |
1398 | ✗ | return err; | |
1399 | } | ||
1400 | 58 | break; | |
1401 | |||
1402 | 283 | case HEVC_NAL_PPS: | |
1403 | { | ||
1404 | 283 | H265RawPPS *pps = unit->content; | |
1405 | |||
1406 | 283 | err = cbs_h265_write_pps(ctx, pbc, pps); | |
1407 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 283 times.
|
283 | if (err < 0) |
1408 | ✗ | return err; | |
1409 | |||
1410 | 283 | err = cbs_h265_replace_pps(ctx, unit); | |
1411 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 283 times.
|
283 | if (err < 0) |
1412 | ✗ | return err; | |
1413 | } | ||
1414 | 283 | break; | |
1415 | |||
1416 | 6031 | case HEVC_NAL_TRAIL_N: | |
1417 | case HEVC_NAL_TRAIL_R: | ||
1418 | case HEVC_NAL_TSA_N: | ||
1419 | case HEVC_NAL_TSA_R: | ||
1420 | case HEVC_NAL_STSA_N: | ||
1421 | case HEVC_NAL_STSA_R: | ||
1422 | case HEVC_NAL_RADL_N: | ||
1423 | case HEVC_NAL_RADL_R: | ||
1424 | case HEVC_NAL_RASL_N: | ||
1425 | case HEVC_NAL_RASL_R: | ||
1426 | case HEVC_NAL_BLA_W_LP: | ||
1427 | case HEVC_NAL_BLA_W_RADL: | ||
1428 | case HEVC_NAL_BLA_N_LP: | ||
1429 | case HEVC_NAL_IDR_W_RADL: | ||
1430 | case HEVC_NAL_IDR_N_LP: | ||
1431 | case HEVC_NAL_CRA_NUT: | ||
1432 | { | ||
1433 | 6031 | H265RawSlice *slice = unit->content; | |
1434 | |||
1435 | 6031 | err = cbs_h265_write_slice_segment_header(ctx, pbc, &slice->header); | |
1436 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6031 times.
|
6031 | if (err < 0) |
1437 | ✗ | return err; | |
1438 | |||
1439 |
1/2✓ Branch 0 taken 6031 times.
✗ Branch 1 not taken.
|
6031 | if (slice->data) { |
1440 | 6031 | err = cbs_h2645_write_slice_data(ctx, pbc, slice->data, | |
1441 | slice->data_size, | ||
1442 | slice->data_bit_start); | ||
1443 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6031 times.
|
6031 | if (err < 0) |
1444 | ✗ | return err; | |
1445 | } else { | ||
1446 | // No slice data - that was just the header. | ||
1447 | } | ||
1448 | } | ||
1449 | 6031 | break; | |
1450 | |||
1451 | 60 | case HEVC_NAL_AUD: | |
1452 | { | ||
1453 | 60 | err = cbs_h265_write_aud(ctx, pbc, unit->content); | |
1454 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
|
60 | if (err < 0) |
1455 | ✗ | return err; | |
1456 | } | ||
1457 | 60 | break; | |
1458 | |||
1459 | 1562 | case HEVC_NAL_SEI_PREFIX: | |
1460 | case HEVC_NAL_SEI_SUFFIX: | ||
1461 | { | ||
1462 | 1562 | err = cbs_h265_write_sei(ctx, pbc, unit->content, | |
1463 | 1562 | unit->type == HEVC_NAL_SEI_PREFIX); | |
1464 | |||
1465 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1562 times.
|
1562 | if (err < 0) |
1466 | ✗ | return err; | |
1467 | } | ||
1468 | 1562 | break; | |
1469 | |||
1470 | ✗ | default: | |
1471 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for " | |
1472 | "NAL unit type %"PRIu32".\n", unit->type); | ||
1473 | ✗ | return AVERROR_PATCHWELCOME; | |
1474 | } | ||
1475 | |||
1476 | 8050 | return 0; | |
1477 | } | ||
1478 | |||
1479 | 756 | static int cbs_h264_discarded_nal_unit(CodedBitstreamContext *ctx, | |
1480 | const CodedBitstreamUnit *unit, | ||
1481 | enum AVDiscard skip) | ||
1482 | { | ||
1483 | H264RawNALUnitHeader *header; | ||
1484 | H264RawSliceHeader *slice; | ||
1485 | int slice_type_i, slice_type_b, slice_type_si; | ||
1486 | |||
1487 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 756 times.
|
756 | if (skip <= AVDISCARD_DEFAULT) |
1488 | ✗ | return 0; | |
1489 | |||
1490 | // keep non-VCL | ||
1491 |
2/2✓ Branch 0 taken 256 times.
✓ Branch 1 taken 500 times.
|
756 | if (unit->type != H264_NAL_SLICE && |
1492 |
2/2✓ Branch 0 taken 252 times.
✓ Branch 1 taken 4 times.
|
256 | unit->type != H264_NAL_IDR_SLICE && |
1493 |
1/2✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
|
252 | unit->type != H264_NAL_AUXILIARY_SLICE) |
1494 | 252 | return 0; | |
1495 | |||
1496 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 504 times.
|
504 | if (skip >= AVDISCARD_ALL) |
1497 | ✗ | return 1; | |
1498 | |||
1499 |
4/4✓ Branch 0 taken 126 times.
✓ Branch 1 taken 378 times.
✓ Branch 2 taken 125 times.
✓ Branch 3 taken 1 times.
|
504 | if (skip >= AVDISCARD_NONKEY && unit->type != H264_NAL_IDR_SLICE) |
1500 | 125 | return 1; | |
1501 | |||
1502 | 379 | header = (H264RawNALUnitHeader *)unit->content; | |
1503 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 379 times.
|
379 | if (!header) { |
1504 | ✗ | av_log(ctx->log_ctx, AV_LOG_WARNING, | |
1505 | "h264 nal unit header is null, missing decompose?\n"); | ||
1506 | ✗ | return 0; | |
1507 | } | ||
1508 | |||
1509 |
3/4✓ Branch 0 taken 379 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 183 times.
✓ Branch 3 taken 196 times.
|
379 | if (skip >= AVDISCARD_NONREF && !header->nal_ref_idc) |
1510 | 183 | return 1; | |
1511 | |||
1512 | 196 | slice = (H264RawSliceHeader *)unit->content; | |
1513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 196 times.
|
196 | if (!slice) { |
1514 | ✗ | av_log(ctx->log_ctx, AV_LOG_WARNING, | |
1515 | "h264 slice header is null, missing decompose?\n"); | ||
1516 | ✗ | return 0; | |
1517 | } | ||
1518 | |||
1519 | 196 | slice_type_i = slice->slice_type % 5 == 2; | |
1520 | 196 | slice_type_b = slice->slice_type % 5 == 1; | |
1521 | 196 | slice_type_si = slice->slice_type % 5 == 4; | |
1522 | |||
1523 |
4/4✓ Branch 0 taken 131 times.
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 71 times.
|
196 | if (skip >= AVDISCARD_BIDIR && slice_type_b) |
1524 | 60 | return 1; | |
1525 |
5/6✓ Branch 0 taken 36 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 7 times.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
|
136 | if (skip >= AVDISCARD_NONINTRA && !slice_type_i && !slice_type_si) |
1526 | 29 | return 1; | |
1527 | |||
1528 | 107 | return 0; | |
1529 | } | ||
1530 | |||
1531 | 536 | static int cbs_h265_discarded_nal_unit(CodedBitstreamContext *ctx, | |
1532 | const CodedBitstreamUnit *unit, | ||
1533 | enum AVDiscard skip) | ||
1534 | { | ||
1535 | H265RawSliceHeader *slice; | ||
1536 | |||
1537 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 536 times.
|
536 | if (skip <= AVDISCARD_DEFAULT) |
1538 | ✗ | return 0; | |
1539 | |||
1540 |
3/3✓ Branch 0 taken 4 times.
✓ Branch 1 taken 328 times.
✓ Branch 2 taken 204 times.
|
536 | switch (unit->type) { |
1541 | 4 | case HEVC_NAL_BLA_W_LP: | |
1542 | case HEVC_NAL_BLA_W_RADL: | ||
1543 | case HEVC_NAL_BLA_N_LP: | ||
1544 | case HEVC_NAL_IDR_W_RADL: | ||
1545 | case HEVC_NAL_IDR_N_LP: | ||
1546 | case HEVC_NAL_CRA_NUT: | ||
1547 | // IRAP slice | ||
1548 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (skip < AVDISCARD_ALL) |
1549 | 4 | return 0; | |
1550 | ✗ | break; | |
1551 | |||
1552 | 328 | case HEVC_NAL_TRAIL_R: | |
1553 | case HEVC_NAL_TRAIL_N: | ||
1554 | case HEVC_NAL_TSA_N: | ||
1555 | case HEVC_NAL_TSA_R: | ||
1556 | case HEVC_NAL_STSA_N: | ||
1557 | case HEVC_NAL_STSA_R: | ||
1558 | case HEVC_NAL_RADL_N: | ||
1559 | case HEVC_NAL_RADL_R: | ||
1560 | case HEVC_NAL_RASL_N: | ||
1561 | case HEVC_NAL_RASL_R: | ||
1562 | // Slice | ||
1563 | 328 | break; | |
1564 | 204 | default: | |
1565 | // Don't discard non-slice nal. | ||
1566 | 204 | return 0; | |
1567 | } | ||
1568 | |||
1569 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 281 times.
|
328 | if (skip >= AVDISCARD_NONKEY) |
1570 | 47 | return 1; | |
1571 | |||
1572 | 281 | slice = (H265RawSliceHeader *)unit->content; | |
1573 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 281 times.
|
281 | if (!slice) { |
1574 | ✗ | av_log(ctx->log_ctx, AV_LOG_WARNING, | |
1575 | "h265 slice header is null, missing decompose?\n"); | ||
1576 | ✗ | return 0; | |
1577 | } | ||
1578 | |||
1579 |
3/4✓ Branch 0 taken 47 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
|
281 | if (skip >= AVDISCARD_NONINTRA && slice->slice_type != HEVC_SLICE_I) |
1580 | 47 | return 1; | |
1581 |
3/4✓ Branch 0 taken 47 times.
✓ Branch 1 taken 187 times.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
|
234 | if (skip >= AVDISCARD_BIDIR && slice->slice_type == HEVC_SLICE_B) |
1582 | 47 | return 1; | |
1583 | |||
1584 |
1/2✓ Branch 0 taken 187 times.
✗ Branch 1 not taken.
|
187 | if (skip >= AVDISCARD_NONREF) { |
1585 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 163 times.
|
187 | switch (unit->type) { |
1586 | 24 | case HEVC_NAL_TRAIL_N: | |
1587 | case HEVC_NAL_TSA_N: | ||
1588 | case HEVC_NAL_STSA_N: | ||
1589 | case HEVC_NAL_RADL_N: | ||
1590 | case HEVC_NAL_RASL_N: | ||
1591 | case HEVC_NAL_VCL_N10: | ||
1592 | case HEVC_NAL_VCL_N12: | ||
1593 | case HEVC_NAL_VCL_N14: | ||
1594 | // non-ref | ||
1595 | 24 | return 1; | |
1596 | 163 | default: | |
1597 | 163 | break; | |
1598 | } | ||
1599 | } | ||
1600 | |||
1601 | 163 | return 0; | |
1602 | } | ||
1603 | |||
1604 | 5777 | static int cbs_h266_write_nal_unit(CodedBitstreamContext *ctx, | |
1605 | CodedBitstreamUnit *unit, | ||
1606 | PutBitContext *pbc) | ||
1607 | { | ||
1608 | int err; | ||
1609 | |||
1610 |
10/11✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 335 times.
✓ Branch 4 taken 391 times.
✓ Branch 5 taken 228 times.
✓ Branch 6 taken 27 times.
✓ Branch 7 taken 2588 times.
✓ Branch 8 taken 12 times.
✓ Branch 9 taken 2190 times.
✗ Branch 10 not taken.
|
5777 | switch (unit->type) { |
1611 | 1 | case VVC_DCI_NUT: | |
1612 | { | ||
1613 | 1 | H266RawDCI *dci = unit->content; | |
1614 | |||
1615 | 1 | err = cbs_h266_write_dci(ctx, pbc, dci); | |
1616 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
1617 | ✗ | return err; | |
1618 | } | ||
1619 | 1 | break; | |
1620 | 1 | case VVC_OPI_NUT: | |
1621 | { | ||
1622 | 1 | H266RawOPI *opi = unit->content; | |
1623 | |||
1624 | 1 | err = cbs_h266_write_opi(ctx, pbc, opi); | |
1625 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (err < 0) |
1626 | ✗ | return err; | |
1627 | } | ||
1628 | 1 | break; | |
1629 | 4 | case VVC_VPS_NUT: | |
1630 | { | ||
1631 | 4 | H266RawVPS *vps = unit->content; | |
1632 | |||
1633 | 4 | err = cbs_h266_write_vps(ctx, pbc, vps); | |
1634 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (err < 0) |
1635 | ✗ | return err; | |
1636 | |||
1637 | 4 | err = cbs_h266_replace_vps(ctx, unit); | |
1638 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (err < 0) |
1639 | ✗ | return err; | |
1640 | } | ||
1641 | 4 | break; | |
1642 | 335 | case VVC_SPS_NUT: | |
1643 | { | ||
1644 | 335 | H266RawSPS *sps = unit->content; | |
1645 | |||
1646 | 335 | err = cbs_h266_write_sps(ctx, pbc, sps); | |
1647 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 335 times.
|
335 | if (err < 0) |
1648 | ✗ | return err; | |
1649 | |||
1650 | 335 | err = cbs_h266_replace_sps(ctx, unit); | |
1651 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 335 times.
|
335 | if (err < 0) |
1652 | ✗ | return err; | |
1653 | } | ||
1654 | 335 | break; | |
1655 | |||
1656 | 391 | case VVC_PPS_NUT: | |
1657 | { | ||
1658 | 391 | H266RawPPS *pps = unit->content; | |
1659 | |||
1660 | 391 | err = cbs_h266_write_pps(ctx, pbc, pps); | |
1661 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 391 times.
|
391 | if (err < 0) |
1662 | ✗ | return err; | |
1663 | |||
1664 | 391 | err = cbs_h266_replace_pps(ctx, unit); | |
1665 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 391 times.
|
391 | if (err < 0) |
1666 | ✗ | return err; | |
1667 | } | ||
1668 | 391 | break; | |
1669 | |||
1670 | 228 | case VVC_PREFIX_APS_NUT: | |
1671 | case VVC_SUFFIX_APS_NUT: | ||
1672 | { | ||
1673 | 228 | err = cbs_h266_write_aps(ctx, pbc, unit->content, | |
1674 | 228 | unit->type == VVC_PREFIX_APS_NUT); | |
1675 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228 times.
|
228 | if (err < 0) |
1676 | ✗ | return err; | |
1677 | } | ||
1678 | 228 | break; | |
1679 | 27 | case VVC_PH_NUT: | |
1680 | { | ||
1681 | 27 | H266RawPH *ph = unit->content; | |
1682 | 27 | err = cbs_h266_write_ph(ctx, pbc, ph); | |
1683 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (err < 0) |
1684 | ✗ | return err; | |
1685 | |||
1686 | 27 | err = cbs_h266_replace_ph(ctx, unit, &ph->ph_picture_header); | |
1687 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (err < 0) |
1688 | ✗ | return err; | |
1689 | } | ||
1690 | 27 | break; | |
1691 | |||
1692 | 2588 | case VVC_TRAIL_NUT: | |
1693 | case VVC_STSA_NUT: | ||
1694 | case VVC_RADL_NUT: | ||
1695 | case VVC_RASL_NUT: | ||
1696 | case VVC_IDR_W_RADL: | ||
1697 | case VVC_IDR_N_LP: | ||
1698 | case VVC_CRA_NUT: | ||
1699 | case VVC_GDR_NUT: | ||
1700 | { | ||
1701 | 2588 | H266RawSlice *slice = unit->content; | |
1702 | |||
1703 | 2588 | err = cbs_h266_write_slice_header(ctx, pbc, &slice->header); | |
1704 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2588 times.
|
2588 | if (err < 0) |
1705 | ✗ | return err; | |
1706 | |||
1707 |
2/2✓ Branch 0 taken 2103 times.
✓ Branch 1 taken 485 times.
|
2588 | if (slice->header.sh_picture_header_in_slice_header_flag) { |
1708 | 2103 | err = cbs_h266_replace_ph(ctx, unit, &slice->header.sh_picture_header); | |
1709 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2103 times.
|
2103 | if (err < 0) |
1710 | ✗ | return err; | |
1711 | } | ||
1712 | |||
1713 |
1/2✓ Branch 0 taken 2588 times.
✗ Branch 1 not taken.
|
2588 | if (slice->data) { |
1714 | 2588 | err = cbs_h2645_write_slice_data(ctx, pbc, slice->data, | |
1715 | slice->data_size, | ||
1716 | slice->data_bit_start); | ||
1717 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2588 times.
|
2588 | if (err < 0) |
1718 | ✗ | return err; | |
1719 | } else { | ||
1720 | // No slice data - that was just the header. | ||
1721 | } | ||
1722 | } | ||
1723 | 2588 | break; | |
1724 | |||
1725 | 12 | case VVC_AUD_NUT: | |
1726 | { | ||
1727 | 12 | err = cbs_h266_write_aud(ctx, pbc, unit->content); | |
1728 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (err < 0) |
1729 | ✗ | return err; | |
1730 | } | ||
1731 | 12 | break; | |
1732 | |||
1733 | 2190 | case VVC_PREFIX_SEI_NUT: | |
1734 | case VVC_SUFFIX_SEI_NUT: | ||
1735 | { | ||
1736 | 2190 | err = cbs_h266_write_sei(ctx, pbc, unit->content, | |
1737 | 2190 | unit->type == VVC_PREFIX_SEI_NUT); | |
1738 | |||
1739 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2190 times.
|
2190 | if (err < 0) |
1740 | ✗ | return err; | |
1741 | } | ||
1742 | 2190 | break; | |
1743 | |||
1744 | ✗ | default: | |
1745 | ✗ | av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for " | |
1746 | "NAL unit type %"PRIu32".\n", unit->type); | ||
1747 | ✗ | return AVERROR_PATCHWELCOME; | |
1748 | } | ||
1749 | |||
1750 | 5777 | return 0; | |
1751 | } | ||
1752 | |||
1753 | 21780 | static int cbs_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, | |
1754 | CodedBitstreamUnitType type, | ||
1755 | int nal_unit_index) | ||
1756 | { | ||
1757 | // Section B.1.2 in H.264, section B.2.2 in H.265, H.266. | ||
1758 |
2/2✓ Branch 0 taken 7246 times.
✓ Branch 1 taken 14534 times.
|
21780 | if (nal_unit_index == 0) { |
1759 | // Assume that this is the first NAL unit in an access unit. | ||
1760 | 7246 | return 1; | |
1761 | } | ||
1762 |
2/2✓ Branch 0 taken 5022 times.
✓ Branch 1 taken 9512 times.
|
14534 | if (codec_id == AV_CODEC_ID_H264) |
1763 |
4/4✓ Branch 0 taken 5014 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 448 times.
✓ Branch 3 taken 4566 times.
|
5022 | return type == H264_NAL_SPS || type == H264_NAL_PPS; |
1764 |
2/2✓ Branch 0 taken 5867 times.
✓ Branch 1 taken 3645 times.
|
9512 | if (codec_id == AV_CODEC_ID_HEVC) |
1765 |
6/6✓ Branch 0 taken 5864 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5806 times.
✓ Branch 3 taken 58 times.
✓ Branch 4 taken 56 times.
✓ Branch 5 taken 5750 times.
|
5867 | return type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS; |
1766 |
1/2✓ Branch 0 taken 3645 times.
✗ Branch 1 not taken.
|
3645 | if (codec_id == AV_CODEC_ID_VVC) |
1767 |
4/4✓ Branch 0 taken 2642 times.
✓ Branch 1 taken 1003 times.
✓ Branch 2 taken 438 times.
✓ Branch 3 taken 2204 times.
|
3645 | return type >= VVC_OPI_NUT && type <= VVC_SUFFIX_APS_NUT; |
1768 | ✗ | return 0; | |
1769 | } | ||
1770 | |||
1771 | 7247 | static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, | |
1772 | CodedBitstreamFragment *frag) | ||
1773 | { | ||
1774 | uint8_t *data; | ||
1775 | size_t max_size, dp, sp; | ||
1776 | int err, i, zero_run; | ||
1777 | |||
1778 |
2/2✓ Branch 0 taken 21780 times.
✓ Branch 1 taken 7247 times.
|
29027 | for (i = 0; i < frag->nb_units; i++) { |
1779 | // Data should already all have been written when we get here. | ||
1780 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21780 times.
|
21780 | av_assert0(frag->units[i].data); |
1781 | } | ||
1782 | |||
1783 | 7247 | max_size = 0; | |
1784 |
2/2✓ Branch 0 taken 21780 times.
✓ Branch 1 taken 7247 times.
|
29027 | for (i = 0; i < frag->nb_units; i++) { |
1785 | // Start code + content with worst-case emulation prevention. | ||
1786 | 21780 | max_size += 4 + frag->units[i].data_size * 3 / 2; | |
1787 | } | ||
1788 | |||
1789 | 7247 | data = av_realloc(NULL, max_size + AV_INPUT_BUFFER_PADDING_SIZE); | |
1790 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7247 times.
|
7247 | if (!data) |
1791 | ✗ | return AVERROR(ENOMEM); | |
1792 | |||
1793 | 7247 | dp = 0; | |
1794 |
2/2✓ Branch 0 taken 21780 times.
✓ Branch 1 taken 7247 times.
|
29027 | for (i = 0; i < frag->nb_units; i++) { |
1795 | 21780 | CodedBitstreamUnit *unit = &frag->units[i]; | |
1796 | |||
1797 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21780 times.
|
21780 | if (unit->data_bit_padding > 0) { |
1798 | ✗ | if (i < frag->nb_units - 1) | |
1799 | ✗ | av_log(ctx->log_ctx, AV_LOG_WARNING, "Probably invalid " | |
1800 | "unaligned padding on non-final NAL unit.\n"); | ||
1801 | else | ||
1802 | ✗ | frag->data_bit_padding = unit->data_bit_padding; | |
1803 | } | ||
1804 | |||
1805 |
2/2✓ Branch 1 taken 8257 times.
✓ Branch 2 taken 13523 times.
|
21780 | if (cbs_h2645_unit_requires_zero_byte(ctx->codec->codec_id, unit->type, i)) { |
1806 | // zero_byte | ||
1807 | 8257 | data[dp++] = 0; | |
1808 | } | ||
1809 | // start_code_prefix_one_3bytes | ||
1810 | 21780 | data[dp++] = 0; | |
1811 | 21780 | data[dp++] = 0; | |
1812 | 21780 | data[dp++] = 1; | |
1813 | |||
1814 | 21780 | zero_run = 0; | |
1815 |
2/2✓ Branch 0 taken 16462517 times.
✓ Branch 1 taken 21780 times.
|
16484297 | for (sp = 0; sp < unit->data_size; sp++) { |
1816 |
2/2✓ Branch 0 taken 16455111 times.
✓ Branch 1 taken 7406 times.
|
16462517 | if (zero_run < 2) { |
1817 |
2/2✓ Branch 0 taken 147107 times.
✓ Branch 1 taken 16308004 times.
|
16455111 | if (unit->data[sp] == 0) |
1818 | 147107 | ++zero_run; | |
1819 | else | ||
1820 | 16308004 | zero_run = 0; | |
1821 | } else { | ||
1822 |
2/2✓ Branch 0 taken 1287 times.
✓ Branch 1 taken 6119 times.
|
7406 | if ((unit->data[sp] & ~3) == 0) { |
1823 | // emulation_prevention_three_byte | ||
1824 | 1287 | data[dp++] = 3; | |
1825 | } | ||
1826 | 7406 | zero_run = unit->data[sp] == 0; | |
1827 | } | ||
1828 | 16462517 | data[dp++] = unit->data[sp]; | |
1829 | } | ||
1830 | } | ||
1831 | |||
1832 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7247 times.
|
7247 | av_assert0(dp <= max_size); |
1833 | 7247 | err = av_reallocp(&data, dp + AV_INPUT_BUFFER_PADDING_SIZE); | |
1834 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7247 times.
|
7247 | if (err) |
1835 | ✗ | return err; | |
1836 | 7247 | memset(data + dp, 0, AV_INPUT_BUFFER_PADDING_SIZE); | |
1837 | |||
1838 | 7247 | frag->data_ref = av_buffer_create(data, dp + AV_INPUT_BUFFER_PADDING_SIZE, | |
1839 | NULL, NULL, 0); | ||
1840 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7247 times.
|
7247 | if (!frag->data_ref) { |
1841 | ✗ | av_freep(&data); | |
1842 | ✗ | return AVERROR(ENOMEM); | |
1843 | } | ||
1844 | |||
1845 | 7247 | frag->data = data; | |
1846 | 7247 | frag->data_size = dp; | |
1847 | |||
1848 | 7247 | return 0; | |
1849 | } | ||
1850 | |||
1851 | ✗ | static void cbs_h264_flush(CodedBitstreamContext *ctx) | |
1852 | { | ||
1853 | ✗ | CodedBitstreamH264Context *h264 = ctx->priv_data; | |
1854 | |||
1855 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) | |
1856 | ✗ | ff_refstruct_unref(&h264->sps[i]); | |
1857 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) | |
1858 | ✗ | ff_refstruct_unref(&h264->pps[i]); | |
1859 | |||
1860 | ✗ | h264->active_sps = NULL; | |
1861 | ✗ | h264->active_pps = NULL; | |
1862 | ✗ | h264->last_slice_nal_unit_type = 0; | |
1863 | ✗ | } | |
1864 | |||
1865 | 44 | static void cbs_h264_close(CodedBitstreamContext *ctx) | |
1866 | { | ||
1867 | 44 | CodedBitstreamH264Context *h264 = ctx->priv_data; | |
1868 | int i; | ||
1869 | |||
1870 | 44 | ff_h2645_packet_uninit(&h264->common.read_packet); | |
1871 | |||
1872 |
2/2✓ Branch 0 taken 1408 times.
✓ Branch 1 taken 44 times.
|
1452 | for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) |
1873 | 1408 | ff_refstruct_unref(&h264->sps[i]); | |
1874 |
2/2✓ Branch 0 taken 11264 times.
✓ Branch 1 taken 44 times.
|
11308 | for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) |
1875 | 11264 | ff_refstruct_unref(&h264->pps[i]); | |
1876 | 44 | } | |
1877 | |||
1878 | ✗ | static void cbs_h265_flush(CodedBitstreamContext *ctx) | |
1879 | { | ||
1880 | ✗ | CodedBitstreamH265Context *h265 = ctx->priv_data; | |
1881 | |||
1882 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) | |
1883 | ✗ | ff_refstruct_unref(&h265->vps[i]); | |
1884 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) | |
1885 | ✗ | ff_refstruct_unref(&h265->sps[i]); | |
1886 | ✗ | for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) | |
1887 | ✗ | ff_refstruct_unref(&h265->pps[i]); | |
1888 | |||
1889 | ✗ | h265->active_vps = NULL; | |
1890 | ✗ | h265->active_sps = NULL; | |
1891 | ✗ | h265->active_pps = NULL; | |
1892 | ✗ | } | |
1893 | |||
1894 | 44 | static void cbs_h265_close(CodedBitstreamContext *ctx) | |
1895 | { | ||
1896 | 44 | CodedBitstreamH265Context *h265 = ctx->priv_data; | |
1897 | int i; | ||
1898 | |||
1899 | 44 | ff_h2645_packet_uninit(&h265->common.read_packet); | |
1900 | |||
1901 |
2/2✓ Branch 0 taken 704 times.
✓ Branch 1 taken 44 times.
|
748 | for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) |
1902 | 704 | ff_refstruct_unref(&h265->vps[i]); | |
1903 |
2/2✓ Branch 0 taken 704 times.
✓ Branch 1 taken 44 times.
|
748 | for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) |
1904 | 704 | ff_refstruct_unref(&h265->sps[i]); | |
1905 |
2/2✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 44 times.
|
2860 | for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) |
1906 | 2816 | ff_refstruct_unref(&h265->pps[i]); | |
1907 | 44 | } | |
1908 | |||
1909 | 78 | static void cbs_h266_flush(CodedBitstreamContext *ctx) | |
1910 | { | ||
1911 | 78 | CodedBitstreamH266Context *h266 = ctx->priv_data; | |
1912 | |||
1913 |
2/2✓ Branch 0 taken 1248 times.
✓ Branch 1 taken 78 times.
|
1326 | for (int i = 0; i < FF_ARRAY_ELEMS(h266->vps); i++) |
1914 | 1248 | ff_refstruct_unref(&h266->vps[i]); | |
1915 |
2/2✓ Branch 0 taken 1248 times.
✓ Branch 1 taken 78 times.
|
1326 | for (int i = 0; i < FF_ARRAY_ELEMS(h266->sps); i++) |
1916 | 1248 | ff_refstruct_unref(&h266->sps[i]); | |
1917 |
2/2✓ Branch 0 taken 4992 times.
✓ Branch 1 taken 78 times.
|
5070 | for (int i = 0; i < FF_ARRAY_ELEMS(h266->pps); i++) |
1918 | 4992 | ff_refstruct_unref(&h266->pps[i]); | |
1919 | 78 | ff_refstruct_unref(&h266->ph_ref); | |
1920 | 78 | } | |
1921 | |||
1922 | 78 | static void cbs_h266_close(CodedBitstreamContext *ctx) | |
1923 | { | ||
1924 | 78 | CodedBitstreamH266Context *h266 = ctx->priv_data; | |
1925 | |||
1926 | 78 | cbs_h266_flush(ctx); | |
1927 | 78 | ff_h2645_packet_uninit(&h266->common.read_packet); | |
1928 | 78 | } | |
1929 | |||
1930 | 913 | static void cbs_h264_free_sei(FFRefStructOpaque unused, void *content) | |
1931 | { | ||
1932 | 913 | H264RawSEI *sei = content; | |
1933 | 913 | ff_cbs_sei_free_message_list(&sei->message_list); | |
1934 | 913 | } | |
1935 | |||
1936 | static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = { | ||
1937 | CBS_UNIT_TYPE_POD(H264_NAL_SPS, H264RawSPS), | ||
1938 | CBS_UNIT_TYPE_POD(H264_NAL_SPS_EXT, H264RawSPSExtension), | ||
1939 | |||
1940 | CBS_UNIT_TYPE_INTERNAL_REF(H264_NAL_PPS, H264RawPPS, slice_group_id), | ||
1941 | |||
1942 | CBS_UNIT_TYPES_INTERNAL_REF((H264_NAL_IDR_SLICE, | ||
1943 | H264_NAL_SLICE, | ||
1944 | H264_NAL_AUXILIARY_SLICE), H264RawSlice, data), | ||
1945 | |||
1946 | CBS_UNIT_TYPE_POD(H264_NAL_AUD, H264RawAUD), | ||
1947 | CBS_UNIT_TYPE_POD(H264_NAL_FILLER_DATA, H264RawFiller), | ||
1948 | CBS_UNIT_TYPE_POD(H264_NAL_END_SEQUENCE, H264RawNALUnitHeader), | ||
1949 | CBS_UNIT_TYPE_POD(H264_NAL_END_STREAM, H264RawNALUnitHeader), | ||
1950 | |||
1951 | CBS_UNIT_TYPE_COMPLEX(H264_NAL_SEI, H264RawSEI, &cbs_h264_free_sei), | ||
1952 | |||
1953 | CBS_UNIT_TYPE_END_OF_LIST | ||
1954 | }; | ||
1955 | |||
1956 | 1727 | static void cbs_h265_free_sei(FFRefStructOpaque unused, void *content) | |
1957 | { | ||
1958 | 1727 | H265RawSEI *sei = content; | |
1959 | 1727 | ff_cbs_sei_free_message_list(&sei->message_list); | |
1960 | 1727 | } | |
1961 | |||
1962 | static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = { | ||
1963 | CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_VPS, H265RawVPS, extension_data.data), | ||
1964 | CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_SPS, H265RawSPS, extension_data.data), | ||
1965 | CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_PPS, H265RawPPS, extension_data.data), | ||
1966 | |||
1967 | CBS_UNIT_TYPE_POD(HEVC_NAL_AUD, H265RawAUD), | ||
1968 | |||
1969 | // Slices of non-IRAP pictures. | ||
1970 | CBS_UNIT_RANGE_INTERNAL_REF(HEVC_NAL_TRAIL_N, HEVC_NAL_RASL_R, | ||
1971 | H265RawSlice, data), | ||
1972 | // Slices of IRAP pictures. | ||
1973 | CBS_UNIT_RANGE_INTERNAL_REF(HEVC_NAL_BLA_W_LP, HEVC_NAL_CRA_NUT, | ||
1974 | H265RawSlice, data), | ||
1975 | |||
1976 | CBS_UNIT_TYPES_COMPLEX((HEVC_NAL_SEI_PREFIX, HEVC_NAL_SEI_SUFFIX), | ||
1977 | H265RawSEI, cbs_h265_free_sei), | ||
1978 | |||
1979 | CBS_UNIT_TYPE_END_OF_LIST | ||
1980 | }; | ||
1981 | |||
1982 | 2190 | static void cbs_h266_free_sei(FFRefStructOpaque unused, void *content) | |
1983 | { | ||
1984 | 2190 | H266RawSEI *sei = content; | |
1985 | 2190 | ff_cbs_sei_free_message_list(&sei->message_list); | |
1986 | 2190 | } | |
1987 | |||
1988 | static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = { | ||
1989 | CBS_UNIT_TYPE_INTERNAL_REF(VVC_DCI_NUT, H266RawDCI, extension_data.data), | ||
1990 | CBS_UNIT_TYPE_INTERNAL_REF(VVC_OPI_NUT, H266RawOPI, extension_data.data), | ||
1991 | CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS, extension_data.data), | ||
1992 | { | ||
1993 | .nb_unit_types = 1, | ||
1994 | .unit_type.list[0] = VVC_SPS_NUT, | ||
1995 | .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, | ||
1996 | .content_size = sizeof(H266RawSPS), | ||
1997 | .type.ref = { | ||
1998 | .nb_offsets = 2, | ||
1999 | .offsets = { offsetof(H266RawSPS, extension_data.data), | ||
2000 | offsetof(H266RawSPS, vui.extension_data.data) } | ||
2001 | }, | ||
2002 | }, | ||
2003 | CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS, extension_data.data), | ||
2004 | CBS_UNIT_TYPE_INTERNAL_REF(VVC_PREFIX_APS_NUT, H266RawAPS, extension_data.data), | ||
2005 | CBS_UNIT_TYPE_INTERNAL_REF(VVC_SUFFIX_APS_NUT, H266RawAPS, extension_data.data), | ||
2006 | |||
2007 | CBS_UNIT_TYPE_POD(VVC_PH_NUT , H266RawPH), | ||
2008 | CBS_UNIT_TYPE_POD(VVC_AUD_NUT, H266RawAUD), | ||
2009 | |||
2010 | CBS_UNIT_RANGE_INTERNAL_REF(VVC_TRAIL_NUT, VVC_RASL_NUT, | ||
2011 | H266RawSlice, data), | ||
2012 | |||
2013 | CBS_UNIT_RANGE_INTERNAL_REF(VVC_IDR_W_RADL, VVC_GDR_NUT, | ||
2014 | H266RawSlice, data), | ||
2015 | |||
2016 | CBS_UNIT_TYPES_COMPLEX((VVC_PREFIX_SEI_NUT, VVC_SUFFIX_SEI_NUT), | ||
2017 | H266RawSEI, cbs_h266_free_sei), | ||
2018 | |||
2019 | CBS_UNIT_TYPE_END_OF_LIST | ||
2020 | }; | ||
2021 | |||
2022 | const CodedBitstreamType ff_cbs_type_h264 = { | ||
2023 | .codec_id = AV_CODEC_ID_H264, | ||
2024 | |||
2025 | .priv_data_size = sizeof(CodedBitstreamH264Context), | ||
2026 | |||
2027 | .unit_types = cbs_h264_unit_types, | ||
2028 | |||
2029 | .split_fragment = &cbs_h2645_split_fragment, | ||
2030 | .read_unit = &cbs_h264_read_nal_unit, | ||
2031 | .write_unit = &cbs_h264_write_nal_unit, | ||
2032 | .discarded_unit = &cbs_h264_discarded_nal_unit, | ||
2033 | .assemble_fragment = &cbs_h2645_assemble_fragment, | ||
2034 | |||
2035 | .flush = &cbs_h264_flush, | ||
2036 | .close = &cbs_h264_close, | ||
2037 | }; | ||
2038 | |||
2039 | const CodedBitstreamType ff_cbs_type_h265 = { | ||
2040 | .codec_id = AV_CODEC_ID_HEVC, | ||
2041 | |||
2042 | .priv_data_size = sizeof(CodedBitstreamH265Context), | ||
2043 | |||
2044 | .unit_types = cbs_h265_unit_types, | ||
2045 | |||
2046 | .split_fragment = &cbs_h2645_split_fragment, | ||
2047 | .read_unit = &cbs_h265_read_nal_unit, | ||
2048 | .write_unit = &cbs_h265_write_nal_unit, | ||
2049 | .discarded_unit = &cbs_h265_discarded_nal_unit, | ||
2050 | .assemble_fragment = &cbs_h2645_assemble_fragment, | ||
2051 | |||
2052 | .flush = &cbs_h265_flush, | ||
2053 | .close = &cbs_h265_close, | ||
2054 | }; | ||
2055 | |||
2056 | const CodedBitstreamType ff_cbs_type_h266 = { | ||
2057 | .codec_id = AV_CODEC_ID_VVC, | ||
2058 | |||
2059 | .priv_data_size = sizeof(CodedBitstreamH266Context), | ||
2060 | |||
2061 | .unit_types = cbs_h266_unit_types, | ||
2062 | |||
2063 | .split_fragment = &cbs_h2645_split_fragment, | ||
2064 | .read_unit = &cbs_h266_read_nal_unit, | ||
2065 | .write_unit = &cbs_h266_write_nal_unit, | ||
2066 | .assemble_fragment = &cbs_h2645_assemble_fragment, | ||
2067 | |||
2068 | .flush = &cbs_h266_flush, | ||
2069 | .close = &cbs_h266_close, | ||
2070 | }; | ||
2071 | |||
2072 | static const SEIMessageTypeDescriptor cbs_sei_common_types[] = { | ||
2073 | { | ||
2074 | SEI_TYPE_FILLER_PAYLOAD, | ||
2075 | 1, 1, | ||
2076 | sizeof(SEIRawFillerPayload), | ||
2077 | SEI_MESSAGE_RW(sei, filler_payload), | ||
2078 | }, | ||
2079 | { | ||
2080 | SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35, | ||
2081 | 1, 1, | ||
2082 | sizeof(SEIRawUserDataRegistered), | ||
2083 | SEI_MESSAGE_RW(sei, user_data_registered), | ||
2084 | }, | ||
2085 | { | ||
2086 | SEI_TYPE_USER_DATA_UNREGISTERED, | ||
2087 | 1, 1, | ||
2088 | sizeof(SEIRawUserDataUnregistered), | ||
2089 | SEI_MESSAGE_RW(sei, user_data_unregistered), | ||
2090 | }, | ||
2091 | { | ||
2092 | SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME, | ||
2093 | 1, 0, | ||
2094 | sizeof(SEIRawMasteringDisplayColourVolume), | ||
2095 | SEI_MESSAGE_RW(sei, mastering_display_colour_volume), | ||
2096 | }, | ||
2097 | { | ||
2098 | SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO, | ||
2099 | 1, 0, | ||
2100 | sizeof(SEIRawContentLightLevelInfo), | ||
2101 | SEI_MESSAGE_RW(sei, content_light_level_info), | ||
2102 | }, | ||
2103 | { | ||
2104 | SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS, | ||
2105 | 1, 0, | ||
2106 | sizeof(SEIRawAlternativeTransferCharacteristics), | ||
2107 | SEI_MESSAGE_RW(sei, alternative_transfer_characteristics), | ||
2108 | }, | ||
2109 | { | ||
2110 | SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT, | ||
2111 | 1, 0, | ||
2112 | sizeof(SEIRawAmbientViewingEnvironment), | ||
2113 | SEI_MESSAGE_RW(sei, ambient_viewing_environment), | ||
2114 | }, | ||
2115 | SEI_MESSAGE_TYPE_END, | ||
2116 | }; | ||
2117 | |||
2118 | static const SEIMessageTypeDescriptor cbs_sei_h264_types[] = { | ||
2119 | { | ||
2120 | SEI_TYPE_BUFFERING_PERIOD, | ||
2121 | 1, 0, | ||
2122 | sizeof(H264RawSEIBufferingPeriod), | ||
2123 | SEI_MESSAGE_RW(h264, sei_buffering_period), | ||
2124 | }, | ||
2125 | { | ||
2126 | SEI_TYPE_PIC_TIMING, | ||
2127 | 1, 0, | ||
2128 | sizeof(H264RawSEIPicTiming), | ||
2129 | SEI_MESSAGE_RW(h264, sei_pic_timing), | ||
2130 | }, | ||
2131 | { | ||
2132 | SEI_TYPE_PAN_SCAN_RECT, | ||
2133 | 1, 0, | ||
2134 | sizeof(H264RawSEIPanScanRect), | ||
2135 | SEI_MESSAGE_RW(h264, sei_pan_scan_rect), | ||
2136 | }, | ||
2137 | { | ||
2138 | SEI_TYPE_RECOVERY_POINT, | ||
2139 | 1, 0, | ||
2140 | sizeof(H264RawSEIRecoveryPoint), | ||
2141 | SEI_MESSAGE_RW(h264, sei_recovery_point), | ||
2142 | }, | ||
2143 | { | ||
2144 | SEI_TYPE_FILM_GRAIN_CHARACTERISTICS, | ||
2145 | 1, 0, | ||
2146 | sizeof(H264RawFilmGrainCharacteristics), | ||
2147 | SEI_MESSAGE_RW(h264, film_grain_characteristics), | ||
2148 | }, | ||
2149 | { | ||
2150 | SEI_TYPE_DISPLAY_ORIENTATION, | ||
2151 | 1, 0, | ||
2152 | sizeof(H264RawSEIDisplayOrientation), | ||
2153 | SEI_MESSAGE_RW(h264, sei_display_orientation), | ||
2154 | }, | ||
2155 | SEI_MESSAGE_TYPE_END | ||
2156 | }; | ||
2157 | |||
2158 | static const SEIMessageTypeDescriptor cbs_sei_h265_types[] = { | ||
2159 | { | ||
2160 | SEI_TYPE_BUFFERING_PERIOD, | ||
2161 | 1, 0, | ||
2162 | sizeof(H265RawSEIBufferingPeriod), | ||
2163 | SEI_MESSAGE_RW(h265, sei_buffering_period), | ||
2164 | }, | ||
2165 | { | ||
2166 | SEI_TYPE_PIC_TIMING, | ||
2167 | 1, 0, | ||
2168 | sizeof(H265RawSEIPicTiming), | ||
2169 | SEI_MESSAGE_RW(h265, sei_pic_timing), | ||
2170 | }, | ||
2171 | { | ||
2172 | SEI_TYPE_PAN_SCAN_RECT, | ||
2173 | 1, 0, | ||
2174 | sizeof(H265RawSEIPanScanRect), | ||
2175 | SEI_MESSAGE_RW(h265, sei_pan_scan_rect), | ||
2176 | }, | ||
2177 | { | ||
2178 | SEI_TYPE_RECOVERY_POINT, | ||
2179 | 1, 0, | ||
2180 | sizeof(H265RawSEIRecoveryPoint), | ||
2181 | SEI_MESSAGE_RW(h265, sei_recovery_point), | ||
2182 | }, | ||
2183 | { | ||
2184 | SEI_TYPE_FILM_GRAIN_CHARACTERISTICS, | ||
2185 | 1, 0, | ||
2186 | sizeof(H265RawFilmGrainCharacteristics), | ||
2187 | SEI_MESSAGE_RW(h265, film_grain_characteristics), | ||
2188 | }, | ||
2189 | { | ||
2190 | SEI_TYPE_DISPLAY_ORIENTATION, | ||
2191 | 1, 0, | ||
2192 | sizeof(H265RawSEIDisplayOrientation), | ||
2193 | SEI_MESSAGE_RW(h265, sei_display_orientation), | ||
2194 | }, | ||
2195 | { | ||
2196 | SEI_TYPE_ACTIVE_PARAMETER_SETS, | ||
2197 | 1, 0, | ||
2198 | sizeof(H265RawSEIActiveParameterSets), | ||
2199 | SEI_MESSAGE_RW(h265, sei_active_parameter_sets), | ||
2200 | }, | ||
2201 | { | ||
2202 | SEI_TYPE_DECODED_PICTURE_HASH, | ||
2203 | 0, 1, | ||
2204 | sizeof(H265RawSEIDecodedPictureHash), | ||
2205 | SEI_MESSAGE_RW(h265, sei_decoded_picture_hash), | ||
2206 | }, | ||
2207 | { | ||
2208 | SEI_TYPE_TIME_CODE, | ||
2209 | 1, 0, | ||
2210 | sizeof(H265RawSEITimeCode), | ||
2211 | SEI_MESSAGE_RW(h265, sei_time_code), | ||
2212 | }, | ||
2213 | { | ||
2214 | SEI_TYPE_ALPHA_CHANNEL_INFO, | ||
2215 | 1, 0, | ||
2216 | sizeof(H265RawSEIAlphaChannelInfo), | ||
2217 | SEI_MESSAGE_RW(h265, sei_alpha_channel_info), | ||
2218 | }, | ||
2219 | SEI_MESSAGE_TYPE_END | ||
2220 | }; | ||
2221 | |||
2222 | static const SEIMessageTypeDescriptor cbs_sei_h266_types[] = { | ||
2223 | { | ||
2224 | SEI_TYPE_DECODED_PICTURE_HASH, | ||
2225 | 0, 1, | ||
2226 | sizeof(H266RawSEIDecodedPictureHash), | ||
2227 | SEI_MESSAGE_RW(h266, sei_decoded_picture_hash), | ||
2228 | }, | ||
2229 | SEI_MESSAGE_TYPE_END | ||
2230 | }; | ||
2231 | |||
2232 | 13404 | const SEIMessageTypeDescriptor *ff_cbs_sei_find_type(CodedBitstreamContext *ctx, | |
2233 | int payload_type) | ||
2234 | { | ||
2235 | const SEIMessageTypeDescriptor *codec_list; | ||
2236 | int i; | ||
2237 | |||
2238 |
2/2✓ Branch 0 taken 93204 times.
✓ Branch 1 taken 13266 times.
|
106470 | for (i = 0; cbs_sei_common_types[i].type >= 0; i++) { |
2239 |
2/2✓ Branch 0 taken 138 times.
✓ Branch 1 taken 93066 times.
|
93204 | if (cbs_sei_common_types[i].type == payload_type) |
2240 | 138 | return &cbs_sei_common_types[i]; | |
2241 | } | ||
2242 | |||
2243 |
3/4✓ Branch 0 taken 1845 times.
✓ Branch 1 taken 4851 times.
✓ Branch 2 taken 6570 times.
✗ Branch 3 not taken.
|
13266 | switch (ctx->codec->codec_id) { |
2244 | 1845 | case AV_CODEC_ID_H264: | |
2245 | 1845 | codec_list = cbs_sei_h264_types; | |
2246 | 1845 | break; | |
2247 | 4851 | case AV_CODEC_ID_H265: | |
2248 | 4851 | codec_list = cbs_sei_h265_types; | |
2249 | 4851 | break; | |
2250 | 6570 | case AV_CODEC_ID_H266: | |
2251 | 6570 | codec_list = cbs_sei_h266_types; | |
2252 | 6570 | break; | |
2253 | ✗ | default: | |
2254 | ✗ | return NULL; | |
2255 | } | ||
2256 | |||
2257 |
2/2✓ Branch 0 taken 46214 times.
✓ Branch 1 taken 201 times.
|
46415 | for (i = 0; codec_list[i].type >= 0; i++) { |
2258 |
2/2✓ Branch 0 taken 13065 times.
✓ Branch 1 taken 33149 times.
|
46214 | if (codec_list[i].type == payload_type) |
2259 | 13065 | return &codec_list[i]; | |
2260 | } | ||
2261 | |||
2262 | 201 | return NULL; | |
2263 | } | ||
2264 |