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