FFmpeg  4.3
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 - (1 << zeroes) + 1;
129  put_bits(pbc, zeroes + 1, 1);
130  put_bits(pbc, zeroes, v);
131  }
132 
133  if (ctx->trace_enable) {
134  char bits[65];
135  int i, j;
136  i = 0;
137  for (j = 0; j < zeroes; j++)
138  bits[i++] = '0';
139  bits[i++] = '1';
140  for (j = 0; j < zeroes; j++)
141  bits[i++] = (v >> (zeroes - j - 1) & 1) ? '1' : '0';
142  bits[i++] = 0;
144  bits, value);
145  }
146 
147  return 0;
148 }
149 
151  const char *name, uint64_t *write_to)
152 {
153  uint64_t value;
154  int position, err, i;
155 
156  if (ctx->trace_enable)
157  position = get_bits_count(gbc);
158 
159  value = 0;
160  for (i = 0; i < 8; i++) {
161  int subscript[2] = { 1, i };
162  uint32_t byte;
163  err = ff_cbs_read_unsigned(ctx, gbc, 8, "leb128_byte[i]", subscript,
164  &byte, 0x00, 0xff);
165  if (err < 0)
166  return err;
167 
168  value |= (uint64_t)(byte & 0x7f) << (i * 7);
169  if (!(byte & 0x80))
170  break;
171  }
172 
173  if (value > UINT32_MAX)
174  return AVERROR_INVALIDDATA;
175 
176  if (ctx->trace_enable)
177  ff_cbs_trace_syntax_element(ctx, position, name, NULL, "", value);
178 
179  *write_to = value;
180  return 0;
181 }
182 
184  const char *name, uint64_t value)
185 {
186  int position, err, len, i;
187  uint8_t byte;
188 
189  len = (av_log2(value) + 7) / 7;
190 
191  if (ctx->trace_enable)
192  position = put_bits_count(pbc);
193 
194  for (i = 0; i < len; i++) {
195  int subscript[2] = { 1, i };
196 
197  byte = value >> (7 * i) & 0x7f;
198  if (i < len - 1)
199  byte |= 0x80;
200 
201  err = ff_cbs_write_unsigned(ctx, pbc, 8, "leb128_byte[i]", subscript,
202  byte, 0x00, 0xff);
203  if (err < 0)
204  return err;
205  }
206 
207  if (ctx->trace_enable)
208  ff_cbs_trace_syntax_element(ctx, position, name, NULL, "", value);
209 
210  return 0;
211 }
212 
214  uint32_t n, const char *name,
215  const int *subscripts, uint32_t *write_to)
216 {
217  uint32_t m, v, extra_bit, value;
218  int position, w;
219 
220  av_assert0(n > 0);
221 
222  if (ctx->trace_enable)
223  position = get_bits_count(gbc);
224 
225  w = av_log2(n) + 1;
226  m = (1 << w) - n;
227 
228  if (get_bits_left(gbc) < w) {
229  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid non-symmetric value at "
230  "%s: bitstream ended.\n", name);
231  return AVERROR_INVALIDDATA;
232  }
233 
234  if (w - 1 > 0)
235  v = get_bits(gbc, w - 1);
236  else
237  v = 0;
238 
239  if (v < m) {
240  value = v;
241  } else {
242  extra_bit = get_bits1(gbc);
243  value = (v << 1) - m + extra_bit;
244  }
245 
246  if (ctx->trace_enable) {
247  char bits[33];
248  int i;
249  for (i = 0; i < w - 1; i++)
250  bits[i] = (v >> i & 1) ? '1' : '0';
251  if (v >= m)
252  bits[i++] = extra_bit ? '1' : '0';
253  bits[i] = 0;
254 
256  name, subscripts, bits, value);
257  }
258 
259  *write_to = value;
260  return 0;
261 }
262 
264  uint32_t n, const char *name,
265  const int *subscripts, uint32_t value)
266 {
267  uint32_t w, m, v, extra_bit;
268  int position;
269 
270  if (value > n) {
271  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
272  "%"PRIu32", but must be in [0,%"PRIu32"].\n",
273  name, value, n);
274  return AVERROR_INVALIDDATA;
275  }
276 
277  if (ctx->trace_enable)
278  position = put_bits_count(pbc);
279 
280  w = av_log2(n) + 1;
281  m = (1 << w) - n;
282 
283  if (put_bits_left(pbc) < w)
284  return AVERROR(ENOSPC);
285 
286  if (value < m) {
287  v = value;
288  put_bits(pbc, w - 1, v);
289  } else {
290  v = m + ((value - m) >> 1);
291  extra_bit = (value - m) & 1;
292  put_bits(pbc, w - 1, v);
293  put_bits(pbc, 1, extra_bit);
294  }
295 
296  if (ctx->trace_enable) {
297  char bits[33];
298  int i;
299  for (i = 0; i < w - 1; i++)
300  bits[i] = (v >> i & 1) ? '1' : '0';
301  if (value >= m)
302  bits[i++] = extra_bit ? '1' : '0';
303  bits[i] = 0;
304 
306  name, subscripts, bits, value);
307  }
308 
309  return 0;
310 }
311 
313  uint32_t range_min, uint32_t range_max,
314  const char *name, uint32_t *write_to)
315 {
316  uint32_t value;
317  int position, i;
318  char bits[33];
319 
320  av_assert0(range_min <= range_max && range_max - range_min < sizeof(bits) - 1);
321  if (ctx->trace_enable)
322  position = get_bits_count(gbc);
323 
324  for (i = 0, value = range_min; value < range_max;) {
325  if (get_bits_left(gbc) < 1) {
326  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid increment value at "
327  "%s: bitstream ended.\n", name);
328  return AVERROR_INVALIDDATA;
329  }
330  if (get_bits1(gbc)) {
331  bits[i++] = '1';
332  ++value;
333  } else {
334  bits[i++] = '0';
335  break;
336  }
337  }
338 
339  if (ctx->trace_enable) {
340  bits[i] = 0;
342  name, NULL, bits, value);
343  }
344 
345  *write_to = value;
346  return 0;
347 }
348 
350  uint32_t range_min, uint32_t range_max,
351  const char *name, uint32_t value)
352 {
353  int len;
354 
355  av_assert0(range_min <= range_max && range_max - range_min < 32);
356  if (value < range_min || value > range_max) {
357  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
358  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
359  name, value, range_min, range_max);
360  return AVERROR_INVALIDDATA;
361  }
362 
363  if (value == range_max)
364  len = range_max - range_min;
365  else
366  len = value - range_min + 1;
367  if (put_bits_left(pbc) < len)
368  return AVERROR(ENOSPC);
369 
370  if (ctx->trace_enable) {
371  char bits[33];
372  int i;
373  for (i = 0; i < len; i++) {
374  if (range_min + i == value)
375  bits[i] = '0';
376  else
377  bits[i] = '1';
378  }
379  bits[i] = 0;
381  name, NULL, bits, value);
382  }
383 
384  if (len > 0)
385  put_bits(pbc, len, (1 << len) - 1 - (value != range_max));
386 
387  return 0;
388 }
389 
391  uint32_t range_max, const char *name,
392  const int *subscripts, uint32_t *write_to)
393 {
394  uint32_t value;
395  int position, err;
396  uint32_t max_len, len, range_offset, range_bits;
397 
398  if (ctx->trace_enable)
399  position = get_bits_count(gbc);
400 
401  av_assert0(range_max > 0);
402  max_len = av_log2(range_max - 1) - 3;
403 
404  err = cbs_av1_read_increment(ctx, gbc, 0, max_len,
405  "subexp_more_bits", &len);
406  if (err < 0)
407  return err;
408 
409  if (len) {
410  range_bits = 2 + len;
411  range_offset = 1 << range_bits;
412  } else {
413  range_bits = 3;
414  range_offset = 0;
415  }
416 
417  if (len < max_len) {
418  err = ff_cbs_read_unsigned(ctx, gbc, range_bits,
419  "subexp_bits", NULL, &value,
420  0, MAX_UINT_BITS(range_bits));
421  if (err < 0)
422  return err;
423 
424  } else {
425  err = cbs_av1_read_ns(ctx, gbc, range_max - range_offset,
426  "subexp_final_bits", NULL, &value);
427  if (err < 0)
428  return err;
429  }
430  value += range_offset;
431 
432  if (ctx->trace_enable)
434  name, subscripts, "", value);
435 
436  *write_to = value;
437  return err;
438 }
439 
441  uint32_t range_max, const char *name,
442  const int *subscripts, uint32_t value)
443 {
444  int position, err;
445  uint32_t max_len, len, range_offset, range_bits;
446 
447  if (value > range_max) {
448  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
449  "%"PRIu32", but must be in [0,%"PRIu32"].\n",
450  name, value, range_max);
451  return AVERROR_INVALIDDATA;
452  }
453 
454  if (ctx->trace_enable)
455  position = put_bits_count(pbc);
456 
457  av_assert0(range_max > 0);
458  max_len = av_log2(range_max - 1) - 3;
459 
460  if (value < 8) {
461  range_bits = 3;
462  range_offset = 0;
463  len = 0;
464  } else {
465  range_bits = av_log2(value);
466  len = range_bits - 2;
467  if (len > max_len) {
468  // The top bin is combined with the one below it.
469  av_assert0(len == max_len + 1);
470  --range_bits;
471  len = max_len;
472  }
473  range_offset = 1 << range_bits;
474  }
475 
476  err = cbs_av1_write_increment(ctx, pbc, 0, max_len,
477  "subexp_more_bits", len);
478  if (err < 0)
479  return err;
480 
481  if (len < max_len) {
482  err = ff_cbs_write_unsigned(ctx, pbc, range_bits,
483  "subexp_bits", NULL,
484  value - range_offset,
485  0, MAX_UINT_BITS(range_bits));
486  if (err < 0)
487  return err;
488 
489  } else {
490  err = cbs_av1_write_ns(ctx, pbc, range_max - range_offset,
491  "subexp_final_bits", NULL,
492  value - range_offset);
493  if (err < 0)
494  return err;
495  }
496 
497  if (ctx->trace_enable)
499  name, subscripts, "", value);
500 
501  return err;
502 }
503 
504 
505 static int cbs_av1_tile_log2(int blksize, int target)
506 {
507  int k;
508  for (k = 0; (blksize << k) < target; k++);
509  return k;
510 }
511 
513  unsigned int a, unsigned int b)
514 {
515  unsigned int diff, m;
516  if (!seq->enable_order_hint)
517  return 0;
518  diff = a - b;
519  m = 1 << seq->order_hint_bits_minus_1;
520  diff = (diff & (m - 1)) - (diff & m);
521  return diff;
522 }
523 
525 {
526  GetBitContext tmp = *gbc;
527  size_t size = 0;
528  for (int i = 0; get_bits_left(&tmp) >= 8; i++) {
529  if (get_bits(&tmp, 8))
530  size = i;
531  }
532  return size;
533 }
534 
535 
536 #define HEADER(name) do { \
537  ff_cbs_trace_header(ctx, name); \
538  } while (0)
539 
540 #define CHECK(call) do { \
541  err = (call); \
542  if (err < 0) \
543  return err; \
544  } while (0)
545 
546 #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
547 #define FUNC_AV1(rw, name) FUNC_NAME(rw, av1, name)
548 #define FUNC(name) FUNC_AV1(READWRITE, name)
549 
550 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
551 
552 #define fb(width, name) \
553  xf(width, name, current->name, 0, MAX_UINT_BITS(width), 0, )
554 #define fc(width, name, range_min, range_max) \
555  xf(width, name, current->name, range_min, range_max, 0, )
556 #define flag(name) fb(1, name)
557 #define su(width, name) \
558  xsu(width, name, current->name, 0, )
559 
560 #define fbs(width, name, subs, ...) \
561  xf(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
562 #define fcs(width, name, range_min, range_max, subs, ...) \
563  xf(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
564 #define flags(name, subs, ...) \
565  xf(1, name, current->name, 0, 1, subs, __VA_ARGS__)
566 #define sus(width, name, subs, ...) \
567  xsu(width, name, current->name, subs, __VA_ARGS__)
568 
569 #define fixed(width, name, value) do { \
570  av_unused uint32_t fixed_value = value; \
571  xf(width, name, fixed_value, value, value, 0, ); \
572  } while (0)
573 
574 
575 #define READ
576 #define READWRITE read
577 #define RWContext GetBitContext
578 
579 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
580  uint32_t value; \
581  CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
582  SUBSCRIPTS(subs, __VA_ARGS__), \
583  &value, range_min, range_max)); \
584  var = value; \
585  } while (0)
586 
587 #define xsu(width, name, var, subs, ...) do { \
588  int32_t value; \
589  CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
590  SUBSCRIPTS(subs, __VA_ARGS__), &value, \
591  MIN_INT_BITS(width), \
592  MAX_INT_BITS(width))); \
593  var = value; \
594  } while (0)
595 
596 #define uvlc(name, range_min, range_max) do { \
597  uint32_t value; \
598  CHECK(cbs_av1_read_uvlc(ctx, rw, #name, \
599  &value, range_min, range_max)); \
600  current->name = value; \
601  } while (0)
602 
603 #define ns(max_value, name, subs, ...) do { \
604  uint32_t value; \
605  CHECK(cbs_av1_read_ns(ctx, rw, max_value, #name, \
606  SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
607  current->name = value; \
608  } while (0)
609 
610 #define increment(name, min, max) do { \
611  uint32_t value; \
612  CHECK(cbs_av1_read_increment(ctx, rw, min, max, #name, &value)); \
613  current->name = value; \
614  } while (0)
615 
616 #define subexp(name, max, subs, ...) do { \
617  uint32_t value; \
618  CHECK(cbs_av1_read_subexp(ctx, rw, max, #name, \
619  SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
620  current->name = value; \
621  } while (0)
622 
623 #define delta_q(name) do { \
624  uint8_t delta_coded; \
625  int8_t delta_q; \
626  xf(1, name.delta_coded, delta_coded, 0, 1, 0, ); \
627  if (delta_coded) \
628  xsu(1 + 6, name.delta_q, delta_q, 0, ); \
629  else \
630  delta_q = 0; \
631  current->name = delta_q; \
632  } while (0)
633 
634 #define leb128(name) do { \
635  uint64_t value; \
636  CHECK(cbs_av1_read_leb128(ctx, rw, #name, &value)); \
637  current->name = value; \
638  } while (0)
639 
640 #define infer(name, value) do { \
641  current->name = value; \
642  } while (0)
643 
644 #define byte_alignment(rw) (get_bits_count(rw) % 8)
645 
646 #include "cbs_av1_syntax_template.c"
647 
648 #undef READ
649 #undef READWRITE
650 #undef RWContext
651 #undef xf
652 #undef xsu
653 #undef uvlc
654 #undef ns
655 #undef increment
656 #undef subexp
657 #undef delta_q
658 #undef leb128
659 #undef infer
660 #undef byte_alignment
661 
662 
663 #define WRITE
664 #define READWRITE write
665 #define RWContext PutBitContext
666 
667 #define xf(width, name, var, range_min, range_max, subs, ...) do { \
668  CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
669  SUBSCRIPTS(subs, __VA_ARGS__), \
670  var, range_min, range_max)); \
671  } while (0)
672 
673 #define xsu(width, name, var, subs, ...) do { \
674  CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
675  SUBSCRIPTS(subs, __VA_ARGS__), var, \
676  MIN_INT_BITS(width), \
677  MAX_INT_BITS(width))); \
678  } while (0)
679 
680 #define uvlc(name, range_min, range_max) do { \
681  CHECK(cbs_av1_write_uvlc(ctx, rw, #name, current->name, \
682  range_min, range_max)); \
683  } while (0)
684 
685 #define ns(max_value, name, subs, ...) do { \
686  CHECK(cbs_av1_write_ns(ctx, rw, max_value, #name, \
687  SUBSCRIPTS(subs, __VA_ARGS__), \
688  current->name)); \
689  } while (0)
690 
691 #define increment(name, min, max) do { \
692  CHECK(cbs_av1_write_increment(ctx, rw, min, max, #name, \
693  current->name)); \
694  } while (0)
695 
696 #define subexp(name, max, subs, ...) do { \
697  CHECK(cbs_av1_write_subexp(ctx, rw, max, #name, \
698  SUBSCRIPTS(subs, __VA_ARGS__), \
699  current->name)); \
700  } while (0)
701 
702 #define delta_q(name) do { \
703  xf(1, name.delta_coded, current->name != 0, 0, 1, 0, ); \
704  if (current->name) \
705  xsu(1 + 6, name.delta_q, current->name, 0, ); \
706  } while (0)
707 
708 #define leb128(name) do { \
709  CHECK(cbs_av1_write_leb128(ctx, rw, #name, current->name)); \
710  } while (0)
711 
712 #define infer(name, value) do { \
713  if (current->name != (value)) { \
714  av_log(ctx->log_ctx, AV_LOG_ERROR, \
715  "%s does not match inferred value: " \
716  "%"PRId64", but should be %"PRId64".\n", \
717  #name, (int64_t)current->name, (int64_t)(value)); \
718  return AVERROR_INVALIDDATA; \
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 (header.obu_has_size_field) {
776  if (get_bits_left(&gbc) < 8) {
777  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid OBU: fragment "
778  "too short (%"SIZE_SPECIFIER" bytes).\n", size);
779  err = AVERROR_INVALIDDATA;
780  goto fail;
781  }
782  err = cbs_av1_read_leb128(ctx, &gbc, "obu_size", &obu_size);
783  if (err < 0)
784  goto fail;
785  } else
786  obu_size = size - 1 - header.obu_extension_flag;
787 
788  pos = get_bits_count(&gbc);
789  av_assert0(pos % 8 == 0 && pos / 8 <= size);
790 
791  obu_length = pos / 8 + obu_size;
792 
793  if (size < obu_length) {
794  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid OBU length: "
795  "%"PRIu64", but only %"SIZE_SPECIFIER" bytes remaining in fragment.\n",
796  obu_length, size);
797  err = AVERROR_INVALIDDATA;
798  goto fail;
799  }
800 
801  err = ff_cbs_insert_unit_data(ctx, frag, -1, header.obu_type,
802  data, obu_length, frag->data_ref);
803  if (err < 0)
804  goto fail;
805 
806  data += obu_length;
807  size -= obu_length;
808  }
809 
810  err = 0;
811 fail:
812  ctx->trace_enable = trace;
813  return err;
814 }
815 
817 {
818  av_buffer_unref(&td->data_ref);
819 }
820 
822 {
824 }
825 
827 {
828  switch (md->metadata_type) {
830  av_buffer_unref(&md->metadata.itut_t35.payload_ref);
831  break;
832  }
833 }
834 
835 static void cbs_av1_free_obu(void *opaque, uint8_t *content)
836 {
837  AV1RawOBU *obu = (AV1RawOBU*)content;
838 
839  switch (obu->header.obu_type) {
840  case AV1_OBU_TILE_GROUP:
842  break;
843  case AV1_OBU_FRAME:
845  break;
846  case AV1_OBU_TILE_LIST:
848  break;
849  case AV1_OBU_METADATA:
851  break;
852  case AV1_OBU_PADDING:
854  break;
855  }
856 
857  av_freep(&obu);
858 }
859 
861  CodedBitstreamUnit *unit,
862  GetBitContext *gbc,
864 {
865  int pos;
866 
867  pos = get_bits_count(gbc);
868  if (pos >= 8 * unit->data_size) {
869  av_log(ctx->log_ctx, AV_LOG_ERROR, "Bitstream ended before "
870  "any data in tile group (%d bits read).\n", pos);
871  return AVERROR_INVALIDDATA;
872  }
873  // Must be byte-aligned at this point.
874  av_assert0(pos % 8 == 0);
875 
876  td->data_ref = av_buffer_ref(unit->data_ref);
877  if (!td->data_ref)
878  return AVERROR(ENOMEM);
879 
880  td->data = unit->data + pos / 8;
881  td->data_size = unit->data_size - pos / 8;
882 
883  return 0;
884 }
885 
887  CodedBitstreamUnit *unit)
888 {
890  AV1RawOBU *obu;
891  GetBitContext gbc;
892  int err, start_pos, end_pos;
893 
894  err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*obu),
896  if (err < 0)
897  return err;
898  obu = unit->content;
899 
900  err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
901  if (err < 0)
902  return err;
903 
904  err = cbs_av1_read_obu_header(ctx, &gbc, &obu->header);
905  if (err < 0)
906  return err;
907  av_assert0(obu->header.obu_type == unit->type);
908 
909  if (obu->header.obu_has_size_field) {
910  uint64_t obu_size;
911  err = cbs_av1_read_leb128(ctx, &gbc, "obu_size", &obu_size);
912  if (err < 0)
913  return err;
914  obu->obu_size = obu_size;
915  } else {
916  if (unit->data_size < 1 + obu->header.obu_extension_flag) {
917  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid OBU length: "
918  "unit too short (%"SIZE_SPECIFIER").\n", unit->data_size);
919  return AVERROR_INVALIDDATA;
920  }
921  obu->obu_size = unit->data_size - 1 - obu->header.obu_extension_flag;
922  }
923 
924  start_pos = get_bits_count(&gbc);
925 
926  if (obu->header.obu_extension_flag) {
927  priv->temporal_id = obu->header.temporal_id;
928  priv->spatial_id = obu->header.spatial_id;
929 
932  priv->operating_point_idc) {
933  int in_temporal_layer =
934  (priv->operating_point_idc >> priv->temporal_id ) & 1;
935  int in_spatial_layer =
936  (priv->operating_point_idc >> (priv->spatial_id + 8)) & 1;
937  if (!in_temporal_layer || !in_spatial_layer) {
938  // Decoding will drop this OBU at this operating point.
939  }
940  }
941  } else {
942  priv->temporal_id = 0;
943  priv->spatial_id = 0;
944  }
945 
946  priv->ref = (AV1ReferenceFrameState *)&priv->read_ref;
947 
948  switch (obu->header.obu_type) {
950  {
951  err = cbs_av1_read_sequence_header_obu(ctx, &gbc,
952  &obu->obu.sequence_header);
953  if (err < 0)
954  return err;
955 
957  priv->sequence_header = NULL;
958 
960  if (!priv->sequence_header_ref)
961  return AVERROR(ENOMEM);
962  priv->sequence_header = &obu->obu.sequence_header;
963  }
964  break;
966  {
967  err = cbs_av1_read_temporal_delimiter_obu(ctx, &gbc);
968  if (err < 0)
969  return err;
970  }
971  break;
974  {
975  err = cbs_av1_read_frame_header_obu(ctx, &gbc,
976  &obu->obu.frame_header,
977  obu->header.obu_type ==
979  unit->data_ref);
980  if (err < 0)
981  return err;
982  }
983  break;
984  case AV1_OBU_TILE_GROUP:
985  {
986  err = cbs_av1_read_tile_group_obu(ctx, &gbc,
987  &obu->obu.tile_group);
988  if (err < 0)
989  return err;
990 
991  err = cbs_av1_ref_tile_data(ctx, unit, &gbc,
992  &obu->obu.tile_group.tile_data);
993  if (err < 0)
994  return err;
995  }
996  break;
997  case AV1_OBU_FRAME:
998  {
999  err = cbs_av1_read_frame_obu(ctx, &gbc, &obu->obu.frame,
1000  unit->data_ref);
1001  if (err < 0)
1002  return err;
1003 
1004  err = cbs_av1_ref_tile_data(ctx, unit, &gbc,
1005  &obu->obu.frame.tile_group.tile_data);
1006  if (err < 0)
1007  return err;
1008  }
1009  break;
1010  case AV1_OBU_TILE_LIST:
1011  {
1012  err = cbs_av1_read_tile_list_obu(ctx, &gbc,
1013  &obu->obu.tile_list);
1014  if (err < 0)
1015  return err;
1016 
1017  err = cbs_av1_ref_tile_data(ctx, unit, &gbc,
1018  &obu->obu.tile_list.tile_data);
1019  if (err < 0)
1020  return err;
1021  }
1022  break;
1023  case AV1_OBU_METADATA:
1024  {
1025  err = cbs_av1_read_metadata_obu(ctx, &gbc, &obu->obu.metadata);
1026  if (err < 0)
1027  return err;
1028  }
1029  break;
1030  case AV1_OBU_PADDING:
1031  {
1032  err = cbs_av1_read_padding_obu(ctx, &gbc, &obu->obu.padding);
1033  if (err < 0)
1034  return err;
1035  }
1036  break;
1037  default:
1038  return AVERROR(ENOSYS);
1039  }
1040 
1041  end_pos = get_bits_count(&gbc);
1042  av_assert0(end_pos <= unit->data_size * 8);
1043 
1044  if (obu->obu_size > 0 &&
1046  obu->header.obu_type != AV1_OBU_TILE_LIST &&
1047  obu->header.obu_type != AV1_OBU_FRAME) {
1048  int nb_bits = obu->obu_size * 8 + start_pos - end_pos;
1049 
1050  if (nb_bits <= 0)
1051  return AVERROR_INVALIDDATA;
1052 
1053  err = cbs_av1_read_trailing_bits(ctx, &gbc, nb_bits);
1054  if (err < 0)
1055  return err;
1056  }
1057 
1058  return 0;
1059 }
1060 
1062  CodedBitstreamUnit *unit,
1063  PutBitContext *pbc)
1064 {
1066  AV1RawOBU *obu = unit->content;
1067  PutBitContext pbc_tmp;
1068  AV1RawTileData *td;
1069  size_t header_size;
1070  int err, start_pos, end_pos, data_pos;
1071 
1072  // OBUs in the normal bitstream format must contain a size field
1073  // in every OBU (in annex B it is optional, but we don't support
1074  // writing that).
1075  obu->header.obu_has_size_field = 1;
1076 
1077  err = cbs_av1_write_obu_header(ctx, pbc, &obu->header);
1078  if (err < 0)
1079  return err;
1080 
1081  if (obu->header.obu_has_size_field) {
1082  pbc_tmp = *pbc;
1083  // Add space for the size field to fill later.
1084  put_bits32(pbc, 0);
1085  put_bits32(pbc, 0);
1086  }
1087 
1088  td = NULL;
1089  start_pos = put_bits_count(pbc);
1090 
1091  priv->ref = (AV1ReferenceFrameState *)&priv->write_ref;
1092 
1093  switch (obu->header.obu_type) {
1095  {
1096  err = cbs_av1_write_sequence_header_obu(ctx, pbc,
1097  &obu->obu.sequence_header);
1098  if (err < 0)
1099  return err;
1100 
1102  priv->sequence_header = NULL;
1103 
1105  if (!priv->sequence_header_ref)
1106  return AVERROR(ENOMEM);
1107  priv->sequence_header = &obu->obu.sequence_header;
1108  }
1109  break;
1111  {
1112  err = cbs_av1_write_temporal_delimiter_obu(ctx, pbc);
1113  if (err < 0)
1114  return err;
1115  }
1116  break;
1117  case AV1_OBU_FRAME_HEADER:
1119  {
1120  err = cbs_av1_write_frame_header_obu(ctx, pbc,
1121  &obu->obu.frame_header,
1122  obu->header.obu_type ==
1124  NULL);
1125  if (err < 0)
1126  return err;
1127  }
1128  break;
1129  case AV1_OBU_TILE_GROUP:
1130  {
1131  err = cbs_av1_write_tile_group_obu(ctx, pbc,
1132  &obu->obu.tile_group);
1133  if (err < 0)
1134  return err;
1135 
1136  td = &obu->obu.tile_group.tile_data;
1137  }
1138  break;
1139  case AV1_OBU_FRAME:
1140  {
1141  err = cbs_av1_write_frame_obu(ctx, pbc, &obu->obu.frame, NULL);
1142  if (err < 0)
1143  return err;
1144 
1145  td = &obu->obu.frame.tile_group.tile_data;
1146  }
1147  break;
1148  case AV1_OBU_TILE_LIST:
1149  {
1150  err = cbs_av1_write_tile_list_obu(ctx, pbc, &obu->obu.tile_list);
1151  if (err < 0)
1152  return err;
1153 
1154  td = &obu->obu.tile_list.tile_data;
1155  }
1156  break;
1157  case AV1_OBU_METADATA:
1158  {
1159  err = cbs_av1_write_metadata_obu(ctx, pbc, &obu->obu.metadata);
1160  if (err < 0)
1161  return err;
1162  }
1163  break;
1164  case AV1_OBU_PADDING:
1165  {
1166  err = cbs_av1_write_padding_obu(ctx, pbc, &obu->obu.padding);
1167  if (err < 0)
1168  return err;
1169  }
1170  break;
1171  default:
1172  return AVERROR(ENOSYS);
1173  }
1174 
1175  end_pos = put_bits_count(pbc);
1176  header_size = (end_pos - start_pos + 7) / 8;
1177  if (td) {
1178  obu->obu_size = header_size + td->data_size;
1179  } else if (header_size > 0) {
1180  // Add trailing bits and recalculate.
1181  err = cbs_av1_write_trailing_bits(ctx, pbc, 8 - end_pos % 8);
1182  if (err < 0)
1183  return err;
1184  end_pos = put_bits_count(pbc);
1185  obu->obu_size = header_size = (end_pos - start_pos + 7) / 8;
1186  } else {
1187  // Empty OBU.
1188  obu->obu_size = 0;
1189  }
1190 
1191  end_pos = put_bits_count(pbc);
1192  // Must now be byte-aligned.
1193  av_assert0(end_pos % 8 == 0);
1194  flush_put_bits(pbc);
1195  start_pos /= 8;
1196  end_pos /= 8;
1197 
1198  *pbc = pbc_tmp;
1199  err = cbs_av1_write_leb128(ctx, pbc, "obu_size", obu->obu_size);
1200  if (err < 0)
1201  return err;
1202 
1203  data_pos = put_bits_count(pbc) / 8;
1204  flush_put_bits(pbc);
1205  av_assert0(data_pos <= start_pos);
1206 
1207  if (8 * obu->obu_size > put_bits_left(pbc))
1208  return AVERROR(ENOSPC);
1209 
1210  if (obu->obu_size > 0) {
1211  memmove(pbc->buf + data_pos,
1212  pbc->buf + start_pos, header_size);
1213  skip_put_bytes(pbc, header_size);
1214 
1215  if (td) {
1216  memcpy(pbc->buf + data_pos + header_size,
1217  td->data, td->data_size);
1218  skip_put_bytes(pbc, td->data_size);
1219  }
1220  }
1221 
1222  // OBU data must be byte-aligned.
1223  av_assert0(put_bits_count(pbc) % 8 == 0);
1224 
1225  return 0;
1226 }
1227 
1229  CodedBitstreamFragment *frag)
1230 {
1231  size_t size, pos;
1232  int i;
1233 
1234  size = 0;
1235  for (i = 0; i < frag->nb_units; i++)
1236  size += frag->units[i].data_size;
1237 
1239  if (!frag->data_ref)
1240  return AVERROR(ENOMEM);
1241  frag->data = frag->data_ref->data;
1242  memset(frag->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1243 
1244  pos = 0;
1245  for (i = 0; i < frag->nb_units; i++) {
1246  memcpy(frag->data + pos, frag->units[i].data,
1247  frag->units[i].data_size);
1248  pos += frag->units[i].data_size;
1249  }
1250  av_assert0(pos == size);
1251  frag->data_size = size;
1252 
1253  return 0;
1254 }
1255 
1257 {
1259 
1262 }
1263 
1266 
1267  .priv_data_size = sizeof(CodedBitstreamAV1Context),
1268 
1273 
1274  .close = &cbs_av1_close,
1275 };
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
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:349
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
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:312
internal.h
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:150
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:213
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:816
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:390
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
fail
#define fail()
Definition: checkasm.h:123
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:1256
ff_cbs_type_av1
const CodedBitstreamType ff_cbs_type_av1
Definition: cbs_av1.c:1264
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:1061
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:183
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:860
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
cbs_av1_free_obu
static void cbs_av1_free_obu(void *opaque, uint8_t *content)
Definition: cbs_av1.c:835
CodedBitstreamType::read_unit
int(* read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_internal.h:44
AV1RawOBU::obu
union AV1RawOBU::@25 obu
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: codec_id.h:274
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:886
cbs_av1_get_payload_bytes_left
static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
Definition: cbs_av1.c:524
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
AV1_METADATA_TYPE_ITUT_T35
@ AV1_METADATA_TYPE_ITUT_T35
Definition: av1.h:47
cbs_av1_free_padding
static void cbs_av1_free_padding(AV1RawPadding *pd)
Definition: cbs_av1.c:821
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:440
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
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
av_log2
#define av_log2
Definition: intmath.h:83
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:1228
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:505
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:269
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:67
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
w
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo ug o o w
Definition: fate.txt:150
pos
unsigned int pos
Definition: spdifenc.c:410
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:215
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:512
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:262
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
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:826
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:263
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:1363
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