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