FFmpeg
Loading...
Searching...
No Matches
cbs_av1.c
Go to the documentation of this file.
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
20#include "libavutil/avassert.h"
21#include "libavutil/opt.h"
22#include "libavutil/pixfmt.h"
23
24#include "cbs.h"
25#include "cbs_internal.h"
26#include "cbs_av1.h"
27#include "defs.h"
28#include "libavutil/refstruct.h"
29
30#define MAX_FRAGMENT_OBUS (1 << 16)
31
32
33#if CBS_READ
34static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc,
35 const char *name, uint32_t *write_to,
36 uint32_t range_min, uint32_t range_max)
37{
38 uint32_t zeroes, bits_value, value;
39
41
42 zeroes = 0;
43 while (zeroes < 32) {
44 if (get_bits_left(gbc) < 1) {
45 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid uvlc code at "
46 "%s: bitstream ended.\n", name);
48 }
49
50 if (get_bits1(gbc))
51 break;
52 ++zeroes;
53 }
54
55 if (zeroes >= 32) {
56 // The spec allows at least thirty-two zero bits followed by a
57 // one to mean 2^32-1, with no constraint on the number of
58 // zeroes. The libaom reference decoder does not match this,
59 // instead reading thirty-two zeroes but not the following one
60 // to mean 2^32-1. These two interpretations are incompatible
61 // and other implementations may follow one or the other.
62 // Therefore we reject thirty-two zeroes because the intended
63 // behaviour is not clear.
64 av_log(ctx->log_ctx, AV_LOG_ERROR, "Thirty-two zero bits in "
65 "%s uvlc code: considered invalid due to conflicting "
66 "standard and reference decoder behaviour.\n", name);
68 } else {
69 if (get_bits_left(gbc) < zeroes) {
70 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid uvlc code at "
71 "%s: bitstream ended.\n", name);
73 }
74
75 bits_value = get_bits_long(gbc, zeroes);
76 value = bits_value + (UINT32_C(1) << zeroes) - 1;
77 }
78
80
81 if (value < range_min || value > range_max) {
82 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
83 "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
84 name, value, range_min, range_max);
86 }
87
88 *write_to = value;
89 return 0;
90}
91#endif
92
93#if CBS_WRITE
94static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc,
95 const char *name, uint32_t value,
96 uint32_t range_min, uint32_t range_max)
97{
98 uint32_t v;
99 int zeroes;
100
102
103 if (value < range_min || value > range_max) {
104 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
105 "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
106 name, value, range_min, range_max);
107 return AVERROR_INVALIDDATA;
108 }
109
110 zeroes = av_log2(value + 1);
111 v = value - (1U << zeroes) + 1;
112
113 if (put_bits_left(pbc) < 2 * zeroes + 1)
114 return AVERROR(ENOSPC);
115
116 put_bits(pbc, zeroes, 0);
117 put_bits(pbc, 1, 1);
118 put_bits(pbc, zeroes, v);
119
121
122 return 0;
123}
124#endif
125
126#if CBS_READ
127static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc,
128 const char *name, uint64_t *write_to)
129{
130 uint64_t value;
131 uint32_t byte;
132 int i;
133
135
136 value = 0;
137 for (i = 0; i < 8; i++) {
138 if (get_bits_left(gbc) < 8) {
139 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid leb128 at "
140 "%s: bitstream ended.\n", name);
141 return AVERROR_INVALIDDATA;
142 }
143 byte = get_bits(gbc, 8);
144 value |= (uint64_t)(byte & 0x7f) << (i * 7);
145 if (!(byte & 0x80))
146 break;
147 }
148
149 if (value > UINT32_MAX)
150 return AVERROR_INVALIDDATA;
151
153
154 *write_to = value;
155 return 0;
156}
157#endif
158
159#if CBS_WRITE
160static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc,
161 const char *name, uint64_t value, int fixed_length)
162{
163 int len, i;
164 uint8_t byte;
165
167
168 len = (av_log2(value) + 7) / 7;
169
170 if (fixed_length) {
171 if (fixed_length < len) {
172 av_log(ctx->log_ctx, AV_LOG_ERROR, "OBU is too large for "
173 "fixed length size field (%d > %d).\n",
174 len, fixed_length);
175 return AVERROR(EINVAL);
176 }
177 len = fixed_length;
178 }
179
180 for (i = 0; i < len; i++) {
181 if (put_bits_left(pbc) < 8)
182 return AVERROR(ENOSPC);
183
184 byte = value >> (7 * i) & 0x7f;
185 if (i < len - 1)
186 byte |= 0x80;
187
188 put_bits(pbc, 8, byte);
189 }
190
192
193 return 0;
194}
195#endif
196
197#if CBS_READ
198static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc,
199 uint32_t n, const char *name,
200 const int *subscripts, uint32_t *write_to)
201{
202 uint32_t m, v, extra_bit, value;
203 int w;
204
206
207 av_assert0(n > 0);
208
209 w = av_log2(n) + 1;
210 m = (1 << w) - n;
211
212 if (get_bits_left(gbc) < w) {
213 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid non-symmetric value at "
214 "%s: bitstream ended.\n", name);
215 return AVERROR_INVALIDDATA;
216 }
217
218 if (w - 1 > 0)
219 v = get_bits(gbc, w - 1);
220 else
221 v = 0;
222
223 if (v < m) {
224 value = v;
225 } else {
226 extra_bit = get_bits1(gbc);
227 value = (v << 1) - m + extra_bit;
228 }
229
231
232 *write_to = value;
233 return 0;
234}
235#endif
236
237#if CBS_WRITE
238static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc,
239 uint32_t n, const char *name,
240 const int *subscripts, uint32_t value)
241{
242 uint32_t w, m, v, extra_bit;
243
245
246 if (value > n) {
247 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
248 "%"PRIu32", but must be in [0,%"PRIu32"].\n",
249 name, value, n);
250 return AVERROR_INVALIDDATA;
251 }
252
253 w = av_log2(n) + 1;
254 m = (1 << w) - n;
255
256 if (put_bits_left(pbc) < w)
257 return AVERROR(ENOSPC);
258
259 if (value < m) {
260 v = value;
261 put_bits(pbc, w - 1, v);
262 } else {
263 v = m + ((value - m) >> 1);
264 extra_bit = (value - m) & 1;
265 put_bits(pbc, w - 1, v);
266 put_bits(pbc, 1, extra_bit);
267 }
268
270
271 return 0;
272}
273#endif
274
275#if CBS_READ
276static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc,
277 uint32_t range_min, uint32_t range_max,
278 const char *name, uint32_t *write_to)
279{
280 uint32_t value;
281
283
284 av_assert0(range_min <= range_max && range_max - range_min < 32);
285
286 for (value = range_min; value < range_max;) {
287 if (get_bits_left(gbc) < 1) {
288 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid increment value at "
289 "%s: bitstream ended.\n", name);
290 return AVERROR_INVALIDDATA;
291 }
292 if (get_bits1(gbc))
293 ++value;
294 else
295 break;
296 }
297
299
300 *write_to = value;
301 return 0;
302}
303#endif
304
305#if CBS_WRITE
306static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc,
307 uint32_t range_min, uint32_t range_max,
308 const char *name, uint32_t value)
309{
310 int len;
311
313
314 av_assert0(range_min <= range_max && range_max - range_min < 32);
315 if (value < range_min || value > range_max) {
316 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
317 "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
318 name, value, range_min, range_max);
319 return AVERROR_INVALIDDATA;
320 }
321
322 if (value == range_max)
323 len = range_max - range_min;
324 else
325 len = value - range_min + 1;
326 if (put_bits_left(pbc) < len)
327 return AVERROR(ENOSPC);
328
329 if (len > 0)
330 put_bits(pbc, len, (1U << len) - 1 - (value != range_max));
331
333
334 return 0;
335}
336#endif
337
338#if CBS_READ
339static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc,
340 uint32_t range_max, const char *name,
341 const int *subscripts, uint32_t *write_to)
342{
343 uint32_t value, max_len, len, range_offset, range_bits;
344 int err;
345
347
348 av_assert0(range_max > 0);
349 max_len = av_log2(range_max - 1) - 3;
350
351 err = cbs_av1_read_increment(ctx, gbc, 0, max_len,
352 "subexp_more_bits", &len);
353 if (err < 0)
354 return err;
355
356 if (len) {
357 range_bits = 2 + len;
358 range_offset = 1 << range_bits;
359 } else {
360 range_bits = 3;
361 range_offset = 0;
362 }
363
364 if (len < max_len) {
365 err = CBS_FUNC(read_simple_unsigned)(ctx, gbc, range_bits,
366 "subexp_bits", &value);
367 if (err < 0)
368 return err;
369
370 } else {
371 err = cbs_av1_read_ns(ctx, gbc, range_max - range_offset,
372 "subexp_final_bits", NULL, &value);
373 if (err < 0)
374 return err;
375 }
376 value += range_offset;
377
379
380 *write_to = value;
381 return err;
382}
383#endif
384
385#if CBS_WRITE
386static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc,
387 uint32_t range_max, const char *name,
388 const int *subscripts, uint32_t value)
389{
390 int err;
391 uint32_t max_len, len, range_offset, range_bits;
392
394
395 if (value > range_max) {
396 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
397 "%"PRIu32", but must be in [0,%"PRIu32"].\n",
398 name, value, range_max);
399 return AVERROR_INVALIDDATA;
400 }
401
402 av_assert0(range_max > 0);
403 max_len = av_log2(range_max - 1) - 3;
404
405 if (value < 8) {
406 range_bits = 3;
407 range_offset = 0;
408 len = 0;
409 } else {
410 range_bits = av_log2(value);
411 len = range_bits - 2;
412 if (len > max_len) {
413 // The top bin is combined with the one below it.
414 av_assert0(len == max_len + 1);
415 --range_bits;
416 len = max_len;
417 }
418 range_offset = 1 << range_bits;
419 }
420
421 err = cbs_av1_write_increment(ctx, pbc, 0, max_len,
422 "subexp_more_bits", len);
423 if (err < 0)
424 return err;
425
426 if (len < max_len) {
427 err = CBS_FUNC(write_simple_unsigned)(ctx, pbc, range_bits,
428 "subexp_bits",
429 value - range_offset);
430 if (err < 0)
431 return err;
432
433 } else {
434 err = cbs_av1_write_ns(ctx, pbc, range_max - range_offset,
435 "subexp_final_bits", NULL,
436 value - range_offset);
437 if (err < 0)
438 return err;
439 }
440
442
443 return err;
444}
445#endif
446
447
448static int cbs_av1_tile_log2(int blksize, int target)
449{
450 int k;
451 for (k = 0; (blksize << k) < target; k++);
452 return k;
453}
454
456 unsigned int a, unsigned int b)
457{
458 unsigned int diff, m;
459 if (!seq->enable_order_hint)
460 return 0;
461 diff = a - b;
462 m = 1 << seq->order_hint_bits_minus_1;
463 diff = (diff & (m - 1)) - (diff & m);
464 return diff;
465}
466
468{
469 GetBitContext tmp = *gbc;
470 size_t size = 0;
471 for (int i = 0; get_bits_left(&tmp) >= 8; i++) {
472 if (get_bits(&tmp, 8))
473 size = i;
474 }
475 return size;
476}
477
478
479#define HEADER(name) do { \
480 CBS_FUNC(trace_header)(ctx, name); \
481 } while (0)
482
483#define CHECK(call) do { \
484 err = (call); \
485 if (err < 0) \
486 return err; \
487 } while (0)
488
489#define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
490#define FUNC_AV1(rw, name) FUNC_NAME(rw, av1, name)
491#define FUNC(name) FUNC_AV1(READWRITE, name)
492
493#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
494
495#if CBS_READ
496#define fc(width, name, range_min, range_max) \
497 xf(width, name, current->name, range_min, range_max, 0, )
498#define flag(name) fb(1, name)
499#define su(width, name) \
500 xsu(width, name, current->name, 0, )
501
502#define fbs(width, name, subs, ...) \
503 xf(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
504#define fcs(width, name, range_min, range_max, subs, ...) \
505 xf(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
506#define flags(name, subs, ...) \
507 xf(1, name, current->name, 0, 1, subs, __VA_ARGS__)
508#define sus(width, name, subs, ...) \
509 xsu(width, name, current->name, subs, __VA_ARGS__)
510
511#define fixed(width, name, value) do { \
512 av_unused uint32_t fixed_value = value; \
513 xf(width, name, fixed_value, value, value, 0, ); \
514 } while (0)
515
516
517#define READ
518#define READWRITE read
519#define RWContext GetBitContext
520
521#define fb(width, name) do { \
522 uint32_t value; \
523 CHECK(CBS_FUNC(read_simple_unsigned)(ctx, rw, width, \
524 #name, &value)); \
525 current->name = value; \
526 } while (0)
527
528#define xf(width, name, var, range_min, range_max, subs, ...) do { \
529 uint32_t value; \
530 CHECK(CBS_FUNC(read_unsigned)(ctx, rw, width, #name, \
531 SUBSCRIPTS(subs, __VA_ARGS__), \
532 &value, range_min, range_max)); \
533 var = value; \
534 } while (0)
535
536#define xsu(width, name, var, subs, ...) do { \
537 int32_t value; \
538 CHECK(CBS_FUNC(read_signed)(ctx, rw, width, #name, \
539 SUBSCRIPTS(subs, __VA_ARGS__), &value, \
540 MIN_INT_BITS(width), \
541 MAX_INT_BITS(width))); \
542 var = value; \
543 } while (0)
544
545#define uvlc(name, range_min, range_max) do { \
546 uint32_t value; \
547 CHECK(cbs_av1_read_uvlc(ctx, rw, #name, \
548 &value, range_min, range_max)); \
549 current->name = value; \
550 } while (0)
551
552#define ns(max_value, name, subs, ...) do { \
553 uint32_t value; \
554 CHECK(cbs_av1_read_ns(ctx, rw, max_value, #name, \
555 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
556 current->name = value; \
557 } while (0)
558
559#define increment(name, min, max) do { \
560 uint32_t value; \
561 CHECK(cbs_av1_read_increment(ctx, rw, min, max, #name, &value)); \
562 current->name = value; \
563 } while (0)
564
565#define subexp(name, max, subs, ...) do { \
566 uint32_t value; \
567 CHECK(cbs_av1_read_subexp(ctx, rw, max, #name, \
568 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
569 current->name = value; \
570 } while (0)
571
572#define delta_q(name) do { \
573 uint8_t delta_coded; \
574 int8_t delta_q; \
575 xf(1, name.delta_coded, delta_coded, 0, 1, 0, ); \
576 if (delta_coded) \
577 xsu(1 + 6, name.delta_q, delta_q, 0, ); \
578 else \
579 delta_q = 0; \
580 current->name = delta_q; \
581 } while (0)
582
583#define leb128(name) do { \
584 uint64_t value; \
585 CHECK(cbs_av1_read_leb128(ctx, rw, #name, &value)); \
586 current->name = value; \
587 } while (0)
588
589#define infer(name, value) do { \
590 current->name = value; \
591 } while (0)
592
593#define byte_alignment(rw) (get_bits_count(rw) % 8)
594
596
597#undef READ
598#undef READWRITE
599#undef RWContext
600#undef fb
601#undef xf
602#undef xsu
603#undef uvlc
604#undef ns
605#undef increment
606#undef subexp
607#undef delta_q
608#undef leb128
609#undef infer
610#undef byte_alignment
611#endif // CBS_READ
612
613
614#if CBS_WRITE
615#define WRITE
616#define READWRITE write
617#define RWContext PutBitContext
618
619#define fb(width, name) do { \
620 CHECK(CBS_FUNC(write_simple_unsigned)(ctx, rw, width, #name, \
621 current->name)); \
622 } while (0)
623
624#define xf(width, name, var, range_min, range_max, subs, ...) do { \
625 CHECK(CBS_FUNC(write_unsigned)(ctx, rw, width, #name, \
626 SUBSCRIPTS(subs, __VA_ARGS__), \
627 var, range_min, range_max)); \
628 } while (0)
629
630#define xsu(width, name, var, subs, ...) do { \
631 CHECK(CBS_FUNC(write_signed)(ctx, rw, width, #name, \
632 SUBSCRIPTS(subs, __VA_ARGS__), var, \
633 MIN_INT_BITS(width), \
634 MAX_INT_BITS(width))); \
635 } while (0)
636
637#define uvlc(name, range_min, range_max) do { \
638 CHECK(cbs_av1_write_uvlc(ctx, rw, #name, current->name, \
639 range_min, range_max)); \
640 } while (0)
641
642#define ns(max_value, name, subs, ...) do { \
643 CHECK(cbs_av1_write_ns(ctx, rw, max_value, #name, \
644 SUBSCRIPTS(subs, __VA_ARGS__), \
645 current->name)); \
646 } while (0)
647
648#define increment(name, min, max) do { \
649 CHECK(cbs_av1_write_increment(ctx, rw, min, max, #name, \
650 current->name)); \
651 } while (0)
652
653#define subexp(name, max, subs, ...) do { \
654 CHECK(cbs_av1_write_subexp(ctx, rw, max, #name, \
655 SUBSCRIPTS(subs, __VA_ARGS__), \
656 current->name)); \
657 } while (0)
658
659#define delta_q(name) do { \
660 xf(1, name.delta_coded, current->name != 0, 0, 1, 0, ); \
661 if (current->name) \
662 xsu(1 + 6, name.delta_q, current->name, 0, ); \
663 } while (0)
664
665#define leb128(name) do { \
666 CHECK(cbs_av1_write_leb128(ctx, rw, #name, current->name, 0)); \
667 } while (0)
668
669#define infer(name, value) do { \
670 if (current->name != (value)) { \
671 av_log(ctx->log_ctx, AV_LOG_ERROR, \
672 "%s does not match inferred value: " \
673 "%"PRId64", but should be %"PRId64".\n", \
674 #name, (int64_t)current->name, (int64_t)(value)); \
675 return AVERROR_INVALIDDATA; \
676 } \
677 } while (0)
678
679#define byte_alignment(rw) (put_bits_count(rw) % 8)
680
682
683#undef WRITE
684#undef READWRITE
685#undef RWContext
686#undef fb
687#undef xf
688#undef xsu
689#undef uvlc
690#undef ns
691#undef increment
692#undef subexp
693#undef delta_q
694#undef leb128
695#undef infer
696#undef byte_alignment
697#endif // CBS_WRITE
698
701 int header)
702{
703#if CBS_READ
704 GetBitContext gbc;
705 uint8_t *data;
706 size_t size;
707 uint64_t obu_length;
708 int pos, err, trace;
709
710 // Don't include this parsing in trace output.
711 trace = ctx->trace_enable;
712 ctx->trace_enable = 0;
713
714 data = frag->data;
715 size = frag->data_size;
716
717 if (INT_MAX / 8 < size) {
718 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid fragment: "
719 "too large (%zu bytes).\n", size);
721 goto fail;
722 }
723
724 if (header && size && data[0] & 0x80) {
725 // first bit is nonzero, the extradata does not consist purely of
726 // OBUs. Expect MP4/Matroska AV1CodecConfigurationRecord
727 int config_record_version = data[0] & 0x7f;
728
729 if (config_record_version != 1) {
730 av_log(ctx->log_ctx, AV_LOG_ERROR,
731 "Unknown version %d of AV1CodecConfigurationRecord "
732 "found!\n",
733 config_record_version);
735 goto fail;
736 }
737
738 if (size <= 4) {
739 if (size < 4) {
740 av_log(ctx->log_ctx, AV_LOG_WARNING,
741 "Undersized AV1CodecConfigurationRecord v%d found!\n",
742 config_record_version);
744 goto fail;
745 }
746
747 goto success;
748 }
749
750 // In AV1CodecConfigurationRecord v1, actual OBUs start after
751 // four bytes. Thus set the offset as required for properly
752 // parsing them.
753 data += 4;
754 size -= 4;
755 }
756
757 while (size > 0) {
759 uint64_t obu_size;
760
761 init_get_bits(&gbc, data, 8 * size);
762
763 err = cbs_av1_read_obu_header(ctx, &gbc, &obu_header);
764 if (err < 0)
765 goto fail;
766
767 if (obu_header.obu_has_size_field) {
768 if (get_bits_left(&gbc) < 8) {
769 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid OBU: fragment "
770 "too short (%zu bytes).\n", size);
772 goto fail;
773 }
774 err = cbs_av1_read_leb128(ctx, &gbc, "obu_size", &obu_size);
775 if (err < 0)
776 goto fail;
777 } else
778 obu_size = size - 1 - obu_header.obu_extension_flag;
779
780 pos = get_bits_count(&gbc);
781 av_assert0(pos % 8 == 0 && pos / 8 <= size);
782
783 obu_length = pos / 8 + obu_size;
784
785 if (size < obu_length) {
786 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid OBU length: "
787 "%"PRIu64", but only %zu bytes remaining in fragment.\n",
788 obu_length, size);
790 goto fail;
791 }
792
793 if (frag->nb_units >= MAX_FRAGMENT_OBUS) {
794 av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many OBUs in a fragment.\n");
796 goto fail;
797 }
798
799 err = CBS_FUNC(append_unit_data)(frag, obu_header.obu_type,
800 data, obu_length, frag->data_ref);
801 if (err < 0)
802 goto fail;
803
804 data += obu_length;
805 size -= obu_length;
806 }
807
808success:
809 err = 0;
810fail:
811 ctx->trace_enable = trace;
812 return err;
813#else
814 return AVERROR(ENOSYS);
815#endif
816}
817
818#if CBS_READ
819static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx,
820 CodedBitstreamUnit *unit,
821 GetBitContext *gbc,
822 AVBufferRef **data_ref,
823 uint8_t **data, size_t *data_size)
824{
825 int pos;
826
827 pos = get_bits_count(gbc);
828 if (pos >= 8 * unit->data_size) {
829 av_log(ctx->log_ctx, AV_LOG_ERROR, "Bitstream ended before "
830 "any data in tile group (%d bits read).\n", pos);
831 return AVERROR_INVALIDDATA;
832 }
833 // Must be byte-aligned at this point.
834 av_assert0(pos % 8 == 0);
835
836 *data_ref = av_buffer_ref(unit->data_ref);
837 if (!*data_ref)
838 return AVERROR(ENOMEM);
839
840 *data = unit->data + pos / 8;
841 *data_size = unit->data_size - pos / 8;
842
843 return 0;
844}
845#endif
846
848 CodedBitstreamUnit *unit)
849{
850#if CBS_READ
851 CodedBitstreamAV1Context *priv = ctx->priv_data;
852 AV1RawOBU *obu;
853 GetBitContext gbc;
854 int err, start_pos, end_pos;
855
856 err = CBS_FUNC(alloc_unit_content)(ctx, unit);
857 if (err < 0)
858 return err;
859 obu = unit->content;
860
861 err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
862 if (err < 0)
863 return err;
864
865 err = cbs_av1_read_obu_header(ctx, &gbc, &obu->header);
866 if (err < 0)
867 return err;
868 av_assert0(obu->header.obu_type == unit->type);
869
870 if (obu->header.obu_has_size_field) {
871 uint64_t obu_size;
872 err = cbs_av1_read_leb128(ctx, &gbc, "obu_size", &obu_size);
873 if (err < 0)
874 return err;
875 obu->obu_size = obu_size;
876 } else {
877 if (unit->data_size < 1 + obu->header.obu_extension_flag) {
878 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid OBU length: "
879 "unit too short (%zu).\n", unit->data_size);
880 return AVERROR_INVALIDDATA;
881 }
882 obu->obu_size = unit->data_size - 1 - obu->header.obu_extension_flag;
883 }
884
885 start_pos = get_bits_count(&gbc);
886
887 if (obu->header.obu_extension_flag) {
890 priv->operating_point_idc) {
891 int in_temporal_layer =
892 (priv->operating_point_idc >> priv->temporal_id ) & 1;
893 int in_spatial_layer =
894 (priv->operating_point_idc >> (priv->spatial_id + 8)) & 1;
895 if (!in_temporal_layer || !in_spatial_layer) {
896 return AVERROR(EAGAIN); // drop_obu()
897 }
898 }
899 }
900
901 switch (obu->header.obu_type) {
903 {
904 err = cbs_av1_read_sequence_header_obu(ctx, &gbc,
905 &obu->obu.sequence_header);
906 if (err < 0)
907 return err;
908
909 if (priv->operating_point >= 0) {
911
912 if (priv->operating_point > sequence_header->operating_points_cnt_minus_1) {
913 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid Operating Point %d requested. "
914 "Must not be higher than %u.\n",
915 priv->operating_point, sequence_header->operating_points_cnt_minus_1);
916 return AVERROR(EINVAL);
917 }
918 priv->operating_point_idc = sequence_header->operating_point_idc[priv->operating_point];
919 }
920
922 priv->sequence_header = &obu->obu.sequence_header;
923 }
924 break;
926 {
927 err = cbs_av1_read_temporal_delimiter_obu(ctx, &gbc);
928 if (err < 0)
929 return err;
930 }
931 break;
934 {
935 err = cbs_av1_read_frame_header_obu(ctx, &gbc,
936 &obu->obu.frame_header,
937 obu->header.obu_type ==
939 unit->data_ref);
940 if (err < 0)
941 return err;
942 }
943 break;
944 case AV1_OBU_FRAME:
945 err = cbs_av1_read_frame_obu(ctx, &gbc, &obu->obu.frame,
946 unit->data_ref);
947 if (err < 0)
948 return err;
951 {
952 AV1RawTileGroup *tile_group = obu->header.obu_type == AV1_OBU_FRAME ? &obu->obu.frame.tile_group
953 : &obu->obu.tile_group;
954
955 if (!priv->seen_frame_header)
956 return AVERROR_INVALIDDATA;
957
958 err = cbs_av1_ref_tile_data(ctx, unit, &gbc,
959 &tile_group->data_ref,
960 &tile_group->data,
961 &tile_group->data_size);
962 if (err < 0)
963 return err;
964
965 err = cbs_av1_read_tile_group_obu(ctx, &gbc, tile_group);
966 if (err < 0)
967 return err;
968
969 err = cbs_av1_ref_tile_data(ctx, unit, &gbc,
970 &tile_group->tile_data.data_ref,
971 &tile_group->tile_data.data,
972 &tile_group->tile_data.data_size);
973 if (err < 0)
974 return err;
975 }
976 break;
977#if CBS_AV1_OBU_TILE_LIST
979 {
980 err = cbs_av1_read_tile_list_obu(ctx, &gbc,
981 &obu->obu.tile_list);
982 if (err < 0)
983 return err;
984
985 err = cbs_av1_ref_tile_data(ctx, unit, &gbc,
986 &obu->obu.tile_list.tile_data.data_ref,
987 &obu->obu.tile_list.tile_data.data,
988 &obu->obu.tile_list.tile_data.data_size);
989 if (err < 0)
990 return err;
991 }
992 break;
993#endif
994#if CBS_AV1_OBU_METADATA
995 case AV1_OBU_METADATA:
996 {
997 err = cbs_av1_read_metadata_obu(ctx, &gbc, &obu->obu.metadata);
998 if (err < 0)
999 return err;
1000 }
1001 break;
1002#endif
1003#if CBS_AV1_OBU_PADDING
1004 case AV1_OBU_PADDING:
1005 {
1006 err = cbs_av1_read_padding_obu(ctx, &gbc, &obu->obu.padding);
1007 if (err < 0)
1008 return err;
1009 }
1010 break;
1011#endif
1012 default:
1013 return AVERROR(ENOSYS);
1014 }
1015
1016 end_pos = get_bits_count(&gbc);
1017 av_assert0(end_pos <= unit->data_size * 8);
1018
1019 if (obu->obu_size > 0 &&
1022 obu->header.obu_type != AV1_OBU_FRAME) {
1023 int nb_bits = obu->obu_size * 8 + start_pos - end_pos;
1024
1025 if (nb_bits <= 0)
1026 return AVERROR_INVALIDDATA;
1027
1028 err = cbs_av1_read_trailing_bits(ctx, &gbc, nb_bits);
1029 if (err < 0)
1030 return err;
1031 }
1032
1033 return 0;
1034#else
1035 return AVERROR(ENOSYS);
1036#endif
1037}
1038
1040 CodedBitstreamUnit *unit,
1041 PutBitContext *pbc)
1042{
1043#if CBS_WRITE
1044 CodedBitstreamAV1Context *priv = ctx->priv_data;
1045 AV1RawOBU *obu = unit->content;
1046 PutBitContext pbc_tmp;
1047 AV1RawTileData *td;
1048 size_t header_size;
1049 int err, start_pos, end_pos, data_pos;
1051
1052 // OBUs in the normal bitstream format must contain a size field
1053 // in every OBU (in annex B it is optional, but we don't support
1054 // writing that).
1055 obu->header.obu_has_size_field = 1;
1056 av1ctx = *priv;
1057
1058 if (priv->sequence_header_ref) {
1060 }
1061
1062 if (priv->frame_header_ref) {
1064 if (!av1ctx.frame_header_ref) {
1065 err = AVERROR(ENOMEM);
1066 goto error;
1067 }
1068 }
1069
1070 err = cbs_av1_write_obu_header(ctx, pbc, &obu->header);
1071 if (err < 0)
1072 goto error;
1073
1074 if (obu->header.obu_has_size_field) {
1075 pbc_tmp = *pbc;
1076 if (priv->fixed_obu_size_length) {
1077 for (int i = 0; i < priv->fixed_obu_size_length; i++)
1078 put_bits(pbc, 8, 0);
1079 } else {
1080 // Add space for the size field to fill later.
1081 put_bits32(pbc, 0);
1082 put_bits32(pbc, 0);
1083 }
1084 }
1085
1086 td = NULL;
1087 start_pos = put_bits_count(pbc);
1088
1089 switch (obu->header.obu_type) {
1091 {
1092 err = cbs_av1_write_sequence_header_obu(ctx, pbc,
1093 &obu->obu.sequence_header);
1094 if (err < 0)
1095 goto error;
1096
1098 priv->sequence_header = NULL;
1099
1100 err = CBS_FUNC(make_unit_refcounted)(ctx, unit);
1101 if (err < 0)
1102 goto error;
1103
1105 priv->sequence_header = &obu->obu.sequence_header;
1106 }
1107 break;
1109 {
1110 err = cbs_av1_write_temporal_delimiter_obu(ctx, pbc);
1111 if (err < 0)
1112 goto error;
1113 }
1114 break;
1117 {
1118 err = cbs_av1_write_frame_header_obu(ctx, pbc,
1119 &obu->obu.frame_header,
1120 obu->header.obu_type ==
1122 NULL);
1123 if (err < 0)
1124 goto error;
1125 }
1126 break;
1127 case AV1_OBU_FRAME:
1128 err = cbs_av1_write_frame_obu(ctx, pbc, &obu->obu.frame, NULL);
1129 if (err < 0)
1130 goto error;
1132 case AV1_OBU_TILE_GROUP:
1133 {
1134 AV1RawTileGroup *tile_group = obu->header.obu_type == AV1_OBU_FRAME ? &obu->obu.frame.tile_group
1135 : &obu->obu.tile_group;
1136 err = cbs_av1_write_tile_group_obu(ctx, pbc, tile_group);
1137 if (err < 0)
1138 goto error;
1139
1140 td = &tile_group->tile_data;
1141 }
1142 break;
1143#if CBS_AV1_OBU_TILE_LIST
1144 case AV1_OBU_TILE_LIST:
1145 {
1146 err = cbs_av1_write_tile_list_obu(ctx, pbc, &obu->obu.tile_list);
1147 if (err < 0)
1148 goto error;
1149
1150 td = &obu->obu.tile_list.tile_data;
1151 }
1152 break;
1153#endif
1154#if CBS_AV1_OBU_METADATA
1155 case AV1_OBU_METADATA:
1156 {
1157 err = cbs_av1_write_metadata_obu(ctx, pbc, &obu->obu.metadata);
1158 if (err < 0)
1159 goto error;
1160 }
1161 break;
1162#endif
1163#if CBS_AV1_OBU_PADDING
1164 case AV1_OBU_PADDING:
1165 {
1166 err = cbs_av1_write_padding_obu(ctx, pbc, &obu->obu.padding);
1167 if (err < 0)
1168 goto error;
1169 }
1170 break;
1171#endif
1172 default:
1173 err = AVERROR(ENOSYS);
1174 goto error;
1175 }
1176
1177 end_pos = put_bits_count(pbc);
1178 header_size = (end_pos - start_pos + 7) / 8;
1179 if (td) {
1180 obu->obu_size = header_size + td->data_size;
1181 } else if (header_size > 0) {
1182 // Add trailing bits and recalculate.
1183 err = cbs_av1_write_trailing_bits(ctx, pbc, 8 - end_pos % 8);
1184 if (err < 0)
1185 goto error;
1186 end_pos = put_bits_count(pbc);
1187 obu->obu_size = header_size = (end_pos - start_pos + 7) / 8;
1188 } else {
1189 // Empty OBU.
1190 obu->obu_size = 0;
1191 }
1192
1193 end_pos = put_bits_count(pbc);
1194 // Must now be byte-aligned.
1195 av_assert0(end_pos % 8 == 0);
1196 flush_put_bits(pbc);
1197 start_pos /= 8;
1198 end_pos /= 8;
1199
1200 *pbc = pbc_tmp;
1201 err = cbs_av1_write_leb128(ctx, pbc, "obu_size", obu->obu_size,
1202 priv->fixed_obu_size_length);
1203 if (err < 0)
1204 goto error;
1205
1206 data_pos = put_bits_count(pbc) / 8;
1207 flush_put_bits(pbc);
1208 av_assert0(data_pos <= start_pos);
1209
1210 if (obu->obu_size > put_bits_left(pbc) / 8) {
1213 *priv = av1ctx;
1214
1215 return AVERROR(ENOSPC);
1216 }
1217
1218 if (obu->obu_size > 0) {
1219 if (!priv->fixed_obu_size_length) {
1220 memmove(pbc->buf + data_pos,
1221 pbc->buf + start_pos, header_size);
1222 } else {
1223 // The size was fixed so the following data was
1224 // already written in the correct place.
1225 }
1226 skip_put_bytes(pbc, header_size);
1227
1228 if (td) {
1229 memcpy(pbc->buf + data_pos + header_size,
1230 td->data, td->data_size);
1231 skip_put_bytes(pbc, td->data_size);
1232 }
1233 }
1234
1235 // OBU data must be byte-aligned.
1236 av_assert0(put_bits_count(pbc) % 8 == 0);
1237 err = 0;
1238
1239error:
1242
1243 return err;
1244#else
1245 return AVERROR(ENOSYS);
1246#endif
1247}
1248
1251{
1252#if CBS_WRITE
1253 size_t size, pos;
1254 int i;
1255
1256 size = 0;
1257 for (i = 0; i < frag->nb_units; i++)
1258 size += frag->units[i].data_size;
1259
1261 if (!frag->data_ref)
1262 return AVERROR(ENOMEM);
1263 frag->data = frag->data_ref->data;
1264 memset(frag->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1265
1266 pos = 0;
1267 for (i = 0; i < frag->nb_units; i++) {
1268 memcpy(frag->data + pos, frag->units[i].data,
1269 frag->units[i].data_size);
1270 pos += frag->units[i].data_size;
1271 }
1272 av_assert0(pos == size);
1273 frag->data_size = size;
1274
1275 return 0;
1276#else
1277 return AVERROR(ENOSYS);
1278#endif
1279}
1280
1282{
1283 CodedBitstreamAV1Context *priv = ctx->priv_data;
1284
1286 priv->sequence_header = NULL;
1287 priv->frame_header = NULL;
1288
1289 memset(priv->ref, 0, sizeof(priv->ref));
1290 priv->operating_point_idc = 0;
1291 priv->seen_frame_header = 0;
1292 priv->tile_num = 0;
1293}
1294
1302
1303#if CBS_AV1_OBU_METADATA
1304static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content)
1305{
1306 AV1RawOBU *obu = content;
1308
1310 md = &obu->obu.metadata;
1311
1312 switch (md->metadata_type) {
1317 break;
1319 av_buffer_unref(&md->metadata.itut_t35.payload_ref);
1320 break;
1321 default:
1322 av_buffer_unref(&md->metadata.unknown.payload_ref);
1323 }
1324}
1325#endif
1326
1332 {
1333 .nb_unit_types = 1,
1334 .unit_type.list[0] = AV1_OBU_TILE_GROUP,
1335 .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
1336 .content_size = sizeof(AV1RawOBU),
1337 .type.ref = {
1338 .nb_offsets = 2,
1339 .offsets = { offsetof(AV1RawOBU, obu.tile_group.data),
1340 offsetof(AV1RawOBU, obu.tile_group.tile_data.data) }
1341 },
1342 },
1343
1344 {
1345 .nb_unit_types = 1,
1346 .unit_type.list[0] = AV1_OBU_FRAME,
1347 .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
1348 .content_size = sizeof(AV1RawOBU),
1349 .type.ref = {
1350 .nb_offsets = 2,
1351 .offsets = { offsetof(AV1RawOBU, obu.frame.tile_group.data),
1352 offsetof(AV1RawOBU, obu.frame.tile_group.tile_data.data) }
1353 },
1354 },
1355#if CBS_AV1_OBU_TILE_LIST
1357 obu.tile_list.tile_data.data),
1358#endif
1359#if CBS_AV1_OBU_PADDING
1361 obu.padding.payload),
1362#endif
1363
1364#if CBS_AV1_OBU_METADATA
1366 &cbs_av1_free_metadata),
1367#endif
1368
1370};
1371
1372#define OFFSET(x) offsetof(CodedBitstreamAV1Context, x)
1373static const AVOption cbs_av1_options[] = {
1374 { "operating_point", "Set operating point to select layers to parse from a scalable bitstream",
1375 OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AV1_MAX_OPERATING_POINTS - 1, 0 },
1376 { "fixed_obu_size_length", "Set fixed length of the obu_size field",
1377 OFFSET(fixed_obu_size_length), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8, 0 },
1378 { NULL }
1379};
1380
1381static const AVClass cbs_av1_class = {
1382 .class_name = "cbs_av1",
1383 .item_name = av_default_item_name,
1384 .option = cbs_av1_options,
1385 .version = LIBAVUTIL_VERSION_INT,
1386};
1387
1388const CodedBitstreamType CBS_FUNC(type_av1) = {
1389 .codec_id = AV_CODEC_ID_AV1,
1390
1391 .priv_class = &cbs_av1_class,
1392 .priv_data_size = sizeof(CodedBitstreamAV1Context),
1393
1394 .unit_types = cbs_av1_unit_types,
1395
1396 .split_fragment = &cbs_av1_split_fragment,
1397 .read_unit = &cbs_av1_read_unit,
1398 .write_unit = &cbs_av1_write_obu,
1399 .assemble_fragment = &cbs_av1_assemble_fragment,
1400
1401 .flush = &cbs_av1_flush,
1402 .close = &cbs_av1_close,
1403};
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_WB16 unsigned int_TMPL byte
Definition bytestream.h:99
static int FUNC obu_header(CodedBitstreamContext *ctx, RWContext *rw, AV1RawOBUHeader *current)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define CBS_UNIT_TYPE_POD(type_, structure)
int CBS_FUNC read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to)
#define CBS_TRACE_READ_END()
#define CBS_UNIT_TYPE_END_OF_LIST
#define CBS_TRACE_READ_END_VALUE_ONLY()
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
@ CBS_CONTENT_TYPE_INTERNAL_REFS
#define CBS_TRACE_WRITE_END_NO_SUBSCRIPTS()
#define CBS_TRACE_WRITE_END_VALUE_ONLY()
#define CBS_TRACE_READ_START()
#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func)
#define CBS_TRACE_READ_END_NO_SUBSCRIPTS()
int CBS_FUNC write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value)
#define CBS_TRACE_WRITE_END()
#define CBS_TRACE_WRITE_START()
static int FUNC sequence_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current)
#define NULL
Definition coverity.c:32
Misc types and constants that do not belong anywhere else.
void(* flush)(AVBSFContext *ctx)
Definition dts2pts.c:615
double value
Definition eval.c:102
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition get_bits.h:424
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static unsigned int get_bits1(GetBitContext *s)
Definition get_bits.h:391
static int get_bits_count(const GetBitContext *s)
Definition get_bits.h:254
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition get_bits.h:517
#define fail
Definition test.h:479
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition buffer.c:78
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:247
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int a
#define b
Definition input.c:43
#define av_log2
Definition intmath.h:84
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition j2kenc.c:154
enum MPFType type
Definition jpegmpfenc.c:55
@ AV1_METADATA_TYPE_SCALABILITY
Definition av1.h:46
@ AV1_METADATA_TYPE_HDR_MDCV
Definition av1.h:45
@ AV1_METADATA_TYPE_TIMECODE
Definition av1.h:48
@ AV1_METADATA_TYPE_ITUT_T35
Definition av1.h:47
@ AV1_METADATA_TYPE_HDR_CLL
Definition av1.h:44
@ AV1_OBU_TILE_LIST
Definition av1.h:37
@ AV1_OBU_TEMPORAL_DELIMITER
Definition av1.h:31
@ AV1_OBU_METADATA
Definition av1.h:34
@ AV1_OBU_TILE_GROUP
Definition av1.h:33
@ AV1_OBU_REDUNDANT_FRAME_HEADER
Definition av1.h:36
@ AV1_OBU_FRAME_HEADER
Definition av1.h:32
@ AV1_OBU_PADDING
Definition av1.h:39
@ AV1_OBU_FRAME
Definition av1.h:35
@ AV1_OBU_SEQUENCE_HEADER
Definition av1.h:30
@ AV1_MAX_OPERATING_POINTS
Definition av1.h:74
int CBS_FUNC alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
Definition cbs.c:911
int CBS_FUNC append_unit_data(CodedBitstreamFragment *frag, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Add a new unit to a fragment with the given data bitstream.
Definition cbs.c:838
int CBS_FUNC make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
Definition cbs.c:1023
av_cold void CBS_FUNC close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition cbs.c:118
#define CBS_FUNC(name)
Definition cbs.h:38
static const AVOption cbs_av1_options[]
Definition cbs_av1.c:1373
static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition cbs_av1.c:699
#define MAX_FRAGMENT_OBUS
Definition cbs_av1.c:30
static int cbs_av1_write_obu(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition cbs_av1.c:1039
static CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[]
Definition cbs_av1.c:1327
static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition cbs_av1.c:1249
static av_cold void cbs_av1_close(CodedBitstreamContext *ctx)
Definition cbs_av1.c:1295
static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq, unsigned int a, unsigned int b)
Definition cbs_av1.c:455
static const AVClass cbs_av1_class
Definition cbs_av1.c:1381
static av_cold void cbs_av1_flush(CodedBitstreamContext *ctx)
Definition cbs_av1.c:1281
#define OFFSET(x)
Definition cbs_av1.c:1372
static av_unused size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
Definition cbs_av1.c:467
static int cbs_av1_tile_log2(int blksize, int target)
Definition cbs_av1.c:448
static int cbs_av1_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition cbs_av1.c:847
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define av_unused
Definition attributes.h:164
#define av_cold
Definition attributes.h:117
uint8_t w
Definition llvidencdsp.c:39
const char data[16]
Definition mxf.c:149
AVOptions.
pixel format definitions
static int put_bits_count(PutBitContext *s)
Definition put_bits.h:90
static int put_bits_left(PutBitContext *s)
Definition put_bits.h:135
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition put_bits.h:153
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
Definition put_bits.h:411
static av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition put_bits.h:301
const char * name
Definition qsvenc.c:142
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:121
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition refstruct.c:161
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition refstruct.c:141
static const uint8_t header[24]
Definition sdr2.c:68
unsigned int pos
Definition spdifenc.c:431
AV1RawTileGroup tile_group
Definition cbs_av1.h:320
uint8_t obu_extension_flag
Definition cbs_av1.h:41
uint8_t obu_has_size_field
Definition cbs_av1.h:42
uint8_t obu_type
Definition cbs_av1.h:40
AV1RawFrameHeader frame_header
Definition cbs_av1.h:420
AV1RawOBUHeader header
Definition cbs_av1.h:414
size_t obu_size
Definition cbs_av1.h:416
AV1RawTileGroup tile_group
Definition cbs_av1.h:422
AV1RawSequenceHeader sequence_header
Definition cbs_av1.h:419
AV1RawFrame frame
Definition cbs_av1.h:421
union AV1RawOBU::@016362317061177152367125047142162076164261250366 obu
uint8_t order_hint_bits_minus_1
Definition cbs_av1.h:131
uint8_t enable_order_hint
Definition cbs_av1.h:122
uint8_t * data
Definition cbs_av1.h:301
size_t data_size
Definition cbs_av1.h:303
AVBufferRef * data_ref
Definition cbs_av1.h:302
AV1RawTileData tile_data
Definition cbs_av1.h:315
size_t data_size
Definition cbs_av1.h:309
AVBufferRef * data_ref
Definition cbs_av1.h:308
uint8_t * data
Definition cbs_av1.h:307
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Describe the class of an AVClass context structure.
Definition log.h:76
AVOption.
Definition opt.h:428
AV1RawOBU * sequence_header_ref
A RefStruct reference backing sequence_header.
Definition cbs_av1.h:462
AV1RawSequenceHeader * sequence_header
Definition cbs_av1.h:460
AVBufferRef * frame_header_ref
Definition cbs_av1.h:465
AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]
Definition cbs_av1.h:491
Context structure for coded bitstream operations.
Definition cbs.h:226
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition cbs.h:175
int nb_units
Number of units in this fragment.
Definition cbs.h:160
size_t data_size
The number of bytes in the bitstream.
Definition cbs.h:142
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition cbs.h:135
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition cbs.h:152
Coded bitstream unit structure.
Definition cbs.h:77
void * content
Pointer to the decomposed form of this unit.
Definition cbs.h:114
void * content_ref
If content is reference counted, a RefStruct reference backing content.
Definition cbs.h:119
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition cbs.h:88
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition cbs.h:81
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition cbs.h:93
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition cbs.h:105
uint8_t * buf
Definition put_bits.h:53
#define av_log(a,...)
static void error(const char *err)
static uint8_t tmp[40]
Definition aes_ctr.c:52
int size
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition refstruct.h:58
#define md
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
int len