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