1 /*
2 * AV1 helper functions for muxers
3 * Copyright (c) 2018 James Almer <jamrial@gmail.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
31
34 {
35 const uint8_t *start = buf, *end = buf +
size;
36 int64_t obu_size;
37 int off, start_pos,
type, temporal_id, spatial_id;
38 enum {
39 START_NOT_FOUND,
40 START_FOUND,
41 END_FOUND,
42 OFFSET_IMPOSSIBLE,
43 }
state = START_NOT_FOUND;
44
46 while (buf < end) {
48 &
type, &temporal_id, &spatial_id);
51
57 if (
state == START_FOUND)
59 break;
60 default:
61 if (
state == START_NOT_FOUND) {
62 off = buf - start;
64 }
else if (
state == END_FOUND) {
65 state = OFFSET_IMPOSSIBLE;
66 }
67 if (pb)
70 break;
71 }
73 }
74
77
79 }
80
82 {
84 }
85
88 {
90 uint8_t *buf;
92
96 }
97 if (off >= 0) {
101
102 return 0;
103 }
104
106 if (!buf)
108
110
113
115
119
120 return 0;
121 }
122
124 {
125 int leading_zeros = 0;
126
129 break;
130 leading_zeros++;
131 }
132
133 if (leading_zeros >= 32)
134 return;
135
137 }
138
140 {
141 int twelve_bit = 0;
145
146 seq_params->
bitdepth = 8 + (high_bitdepth * 2) + (twelve_bit * 2);
147
150 else
152
158 } else {
162 }
163
169 return 0;
175 } else {
177
184 } else {
185 if (twelve_bit) {
189 else
191 } else {
194 }
195 }
198 }
199
201
202 return 0;
203 }
204
206 {
208 int reduced_still_picture_header;
209 int frame_width_bits_minus_1, frame_height_bits_minus_1;
211
213 if (size_bits < 0)
214 return size_bits;
215
219
220 memset(seq_params, 0, sizeof(*seq_params));
221
223
225 reduced_still_picture_header =
get_bits1(&gb);
226
227 if (reduced_still_picture_header) {
229 seq_params->
tier = 0;
230 } else {
231 int initial_display_delay_present_flag, operating_points_cnt_minus_1;
232 int decoder_model_info_present_flag, buffer_delay_length_minus_1;
233
234 if (
get_bits1(&gb)) {
// timing_info_present_flag
237
238 if (
get_bits1(&gb))
// equal_picture_interval
239 uvlc(&gb);
// num_ticks_per_picture_minus_1
240
241 decoder_model_info_present_flag =
get_bits1(&gb);
242 if (decoder_model_info_present_flag) {
243 buffer_delay_length_minus_1 =
get_bits(&gb, 5);
245 skip_bits(&gb, 10);
// buffer_removal_time_length_minus_1 (5)
246 // frame_presentation_time_length_minus_1 (5)
247 }
248 } else
249 decoder_model_info_present_flag = 0;
250
251 initial_display_delay_present_flag =
get_bits1(&gb);
252
253 operating_points_cnt_minus_1 =
get_bits(&gb, 5);
254 for (
int i = 0;
i <= operating_points_cnt_minus_1;
i++) {
255 int seq_level_idx, seq_tier;
256
257 skip_bits(&gb, 12);
// operating_point_idc
259
260 if (seq_level_idx > 7)
262 else
263 seq_tier = 0;
264
265 if (decoder_model_info_present_flag) {
266 if (
get_bits1(&gb)) {
// decoder_model_present_for_this_op
267 skip_bits_long(&gb, buffer_delay_length_minus_1 + 1);
// decoder_buffer_delay
268 skip_bits_long(&gb, buffer_delay_length_minus_1 + 1);
// encoder_buffer_delay
270 }
271 }
272
273 if (initial_display_delay_present_flag) {
274 if (
get_bits1(&gb))
// initial_display_delay_present_for_this_op
275 skip_bits(&gb, 4);
// initial_display_delay_minus_1
276 }
277
279 seq_params->
level = seq_level_idx;
280 seq_params->
tier = seq_tier;
281 }
282 }
283 }
284
285 frame_width_bits_minus_1 =
get_bits(&gb, 4);
286 frame_height_bits_minus_1 =
get_bits(&gb, 4);
287
288 skip_bits(&gb, frame_width_bits_minus_1 + 1);
// max_frame_width_minus_1
289 skip_bits(&gb, frame_height_bits_minus_1 + 1);
// max_frame_height_minus_1
290
291 if (!reduced_still_picture_header) {
292 if (
get_bits1(&gb))
// frame_id_numbers_present_flag
293 skip_bits(&gb, 7);
// delta_frame_id_length_minus_2 (4), additional_frame_id_length_minus_1 (3)
294 }
295
296 skip_bits(&gb, 3);
// use_128x128_superblock (1), enable_filter_intra (1), enable_intra_edge_filter (1)
297
298 if (!reduced_still_picture_header) {
299 int enable_order_hint, seq_force_screen_content_tools;
300
301 skip_bits(&gb, 4);
// enable_interintra_compound (1), enable_masked_compound (1)
302 // enable_warped_motion (1), enable_dual_filter (1)
303
305 if (enable_order_hint)
306 skip_bits(&gb, 2);
// enable_jnt_comp (1), enable_ref_frame_mvs (1)
307
308 if (
get_bits1(&gb))
// seq_choose_screen_content_tools
309 seq_force_screen_content_tools = 2;
310 else
311 seq_force_screen_content_tools =
get_bits1(&gb);
312
313 if (seq_force_screen_content_tools) {
314 if (!
get_bits1(&gb))
// seq_choose_integer_mv
316 }
317
318 if (enable_order_hint)
319 skip_bits(&gb, 3);
// order_hint_bits_minus_1
320 }
321
322 skip_bits(&gb, 3);
// enable_superres (1), enable_cdef (1), enable_restoration (1)
323
325
327
330
331 return 0;
332 }
333
335 {
336 int64_t obu_size;
337 int start_pos,
type, temporal_id, spatial_id;
338
341
344 &
type, &temporal_id, &spatial_id);
347
350 if (!obu_size)
352
354 default:
355 break;
356 }
359 }
360
362 }
363
365 {
370 const uint8_t *seq;
371 int64_t obu_size;
372 int start_pos,
type, temporal_id, spatial_id;
373 int ret, nb_seq = 0, seq_size, meta_size;
374
377
378 if (buf[0] & 0x80) {
379 // first bit is nonzero, the passed data does not consist purely of
380 // OBUs. Expect that the data is already in AV1CodecConfigurationRecord
381 // format.
382 int config_record_version = buf[0] & 0x7f;
383 if (config_record_version != 1 ||
size < 4) {
385 }
386
388
389 return 0;
390 }
391
395
398 &
type, &temporal_id, &spatial_id);
402 }
403
406 nb_seq++;
407 if (!obu_size || nb_seq > 1) {
410 }
414
415 seq = buf;
417 break;
419 if (!obu_size) {
422 }
424 break;
425 default:
426 break;
427 }
430 }
431
432 if (!nb_seq) {
435 }
436
438
452
455
457 if (meta_size)
459
462
464 }