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