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