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