FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cbs.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 <string.h>
20 
21 #include "libavutil/avassert.h"
22 #include "libavutil/buffer.h"
23 #include "libavutil/common.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/opt.h"
26 
27 #include "avcodec.h"
28 #include "cbs.h"
29 #include "cbs_internal.h"
30 #include "libavutil/refstruct.h"
31 
32 
33 static const CodedBitstreamType *const cbs_type_table[] = {
34 #if CBS_AV1
35  &CBS_FUNC(type_av1),
36 #endif
37 #if CBS_H264
38  &CBS_FUNC(type_h264),
39 #endif
40 #if CBS_H265
41  &CBS_FUNC(type_h265),
42 #endif
43 #if CBS_H266
44  &CBS_FUNC(type_h266),
45 #endif
46 #if CBS_JPEG
47  &CBS_FUNC(type_jpeg),
48 #endif
49 #if CBS_MPEG2
50  &CBS_FUNC(type_mpeg2),
51 #endif
52 #if CBS_VP8
53  &CBS_FUNC(type_vp8),
54 #endif
55 #if CBS_VP9
56  &CBS_FUNC(type_vp9),
57 #endif
58 };
59 
60 const enum AVCodecID CBS_FUNC(all_codec_ids)[] = {
61 #if CBS_AV1
63 #endif
64 #if CBS_H264
66 #endif
67 #if CBS_H265
69 #endif
70 #if CBS_H266
72 #endif
73 #if CBS_JPEG
75 #endif
76 #if CBS_MPEG2
78 #endif
79 #if CBS_VP8
81 #endif
82 #if CBS_VP9
84 #endif
86 };
87 
89  enum AVCodecID codec_id, void *log_ctx)
90 {
92  const CodedBitstreamType *type;
93  int i;
94 
95  type = NULL;
96  for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
97  if (cbs_type_table[i]->codec_id == codec_id) {
99  break;
100  }
101  }
102  if (!type)
103  return AVERROR(EINVAL);
104 
105  ctx = av_mallocz(sizeof(*ctx));
106  if (!ctx)
107  return AVERROR(ENOMEM);
108 
109  ctx->log_ctx = log_ctx;
110  ctx->codec = type; /* Must be before any error */
111 
112  if (type->priv_data_size) {
113  ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
114  if (!ctx->priv_data) {
115  av_freep(&ctx);
116  return AVERROR(ENOMEM);
117  }
118  if (type->priv_class) {
119  *(const AVClass **)ctx->priv_data = type->priv_class;
121  }
122  }
123 
124  ctx->decompose_unit_types = NULL;
125 
126  ctx->trace_enable = 0;
127  ctx->trace_level = AV_LOG_TRACE;
128  ctx->trace_context = ctx;
129 
130  *ctx_ptr = ctx;
131  return 0;
132 }
133 
135 {
136  if (ctx->codec->flush)
137  ctx->codec->flush(ctx);
138 }
139 
141 {
142  CodedBitstreamContext *ctx = *ctx_ptr;
143 
144  if (!ctx)
145  return;
146 
147  if (ctx->codec->close)
148  ctx->codec->close(ctx);
149 
150  av_freep(&ctx->write_buffer);
151 
152  if (ctx->codec->priv_class && ctx->priv_data)
154 
156  av_freep(ctx_ptr);
157 }
158 
160 {
162  unit->content = NULL;
163 
164  av_buffer_unref(&unit->data_ref);
165  unit->data = NULL;
166  unit->data_size = 0;
167  unit->data_bit_padding = 0;
168 }
169 
171 {
172  int i;
173 
174  for (i = 0; i < frag->nb_units; i++)
175  cbs_unit_uninit(&frag->units[i]);
176  frag->nb_units = 0;
177 
178  av_buffer_unref(&frag->data_ref);
179  frag->data = NULL;
180  frag->data_size = 0;
181  frag->data_bit_padding = 0;
182 }
183 
185 {
186  CBS_FUNC(fragment_reset)(frag);
187 
188  av_freep(&frag->units);
189  frag->nb_units_allocated = 0;
190 }
191 
192 #if CBS_READ
195 {
196  int err, i, j;
197 
198  for (i = 0; i < frag->nb_units; i++) {
199  CodedBitstreamUnit *unit = &frag->units[i];
200 
201  if (ctx->decompose_unit_types) {
202  for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
203  if (ctx->decompose_unit_types[j] == unit->type)
204  break;
205  }
206  if (j >= ctx->nb_decompose_unit_types)
207  continue;
208  }
209 
211  unit->content = NULL;
212 
213  av_assert0(unit->data && unit->data_ref);
214 
215  err = ctx->codec->read_unit(ctx, unit);
216  if (err == AVERROR(ENOSYS)) {
217  av_log(ctx->log_ctx, AV_LOG_VERBOSE,
218  "Decomposition unimplemented for unit %d "
219  "(type %"PRIu32").\n", i, unit->type);
220  } else if (err == AVERROR(EAGAIN)) {
221  av_log(ctx->log_ctx, AV_LOG_VERBOSE,
222  "Skipping decomposition of unit %d "
223  "(type %"PRIu32").\n", i, unit->type);
225  unit->content = NULL;
226  } else if (err < 0) {
227  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
228  "(type %"PRIu32").\n", i, unit->type);
229  return err;
230  }
231  }
232 
233  return 0;
234 }
235 
237  const uint8_t *data, size_t size)
238 {
239  av_assert0(!frag->data && !frag->data_ref);
240 
241  frag->data_ref =
243  if (!frag->data_ref)
244  return AVERROR(ENOMEM);
245 
246  frag->data = frag->data_ref->data;
247  frag->data_size = size;
248 
249  memcpy(frag->data, data, size);
250  memset(frag->data + size, 0,
252 
253  return 0;
254 }
255 
258  AVBufferRef *buf,
259  const uint8_t *data, size_t size,
260  int header)
261 {
262  int err;
263 
264  if (buf) {
265  frag->data_ref = av_buffer_ref(buf);
266  if (!frag->data_ref)
267  return AVERROR(ENOMEM);
268 
269  frag->data = (uint8_t *)data;
270  frag->data_size = size;
271 
272  } else {
273  err = cbs_fill_fragment_data(frag, data, size);
274  if (err < 0)
275  return err;
276  }
277 
278  err = ctx->codec->split_fragment(ctx, frag, header);
279  if (err < 0)
280  return err;
281 
282  return cbs_read_fragment_content(ctx, frag);
283 }
284 
287  const AVCodecParameters *par)
288 {
289  return cbs_read_data(ctx, frag, NULL,
290  par->extradata,
291  par->extradata_size, 1);
292 }
293 
296  const AVCodecContext *avctx)
297 {
298  return cbs_read_data(ctx, frag, NULL,
299  avctx->extradata,
300  avctx->extradata_size, 1);
301 }
302 
305  const AVPacket *pkt)
306 {
307  return cbs_read_data(ctx, frag, pkt->buf,
308  pkt->data, pkt->size, 0);
309 }
310 
313  const AVPacket *pkt)
314 {
315  size_t side_data_size;
316  const uint8_t *side_data =
318  &side_data_size);
319 
320  return cbs_read_data(ctx, frag, NULL,
321  side_data, side_data_size, 1);
322 }
323 
326  const uint8_t *data, size_t size)
327 {
328  return cbs_read_data(ctx, frag, NULL,
329  data, size, 0);
330 }
331 #endif
332 
333 #if CBS_WRITE
334 /**
335  * Allocate a new internal data buffer of the given size in the unit.
336  *
337  * The data buffer will have input padding.
338  */
340  size_t size)
341 {
342  av_assert0(!unit->data && !unit->data_ref);
343 
345  if (!unit->data_ref)
346  return AVERROR(ENOMEM);
347 
348  unit->data = unit->data_ref->data;
349  unit->data_size = size;
350 
351  memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
352 
353  return 0;
354 }
355 
357  CodedBitstreamUnit *unit)
358 {
359  PutBitContext pbc;
360  int ret;
361 
362  if (!ctx->write_buffer) {
363  // Initial write buffer size is 1MB.
364  ctx->write_buffer_size = 1024 * 1024;
365 
366  reallocate_and_try_again:
367  ret = av_reallocp(&ctx->write_buffer, ctx->write_buffer_size);
368  if (ret < 0) {
369  av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
370  "sufficiently large write buffer (last attempt "
371  "%"SIZE_SPECIFIER" bytes).\n", ctx->write_buffer_size);
372  return ret;
373  }
374  }
375 
376  init_put_bits(&pbc, ctx->write_buffer, ctx->write_buffer_size);
377 
378  ret = ctx->codec->write_unit(ctx, unit, &pbc);
379  if (ret < 0) {
380  if (ret == AVERROR(ENOSPC)) {
381  // Overflow.
382  if (ctx->write_buffer_size == INT_MAX / 8)
383  return AVERROR(ENOMEM);
384  ctx->write_buffer_size = FFMIN(2 * ctx->write_buffer_size, INT_MAX / 8);
385  goto reallocate_and_try_again;
386  }
387  // Write failed for some other reason.
388  return ret;
389  }
390 
391  // Overflow but we didn't notice.
392  av_assert0(put_bits_count(&pbc) <= 8 * ctx->write_buffer_size);
393 
394  if (put_bits_count(&pbc) % 8)
395  unit->data_bit_padding = 8 - put_bits_count(&pbc) % 8;
396  else
397  unit->data_bit_padding = 0;
398 
399  flush_put_bits(&pbc);
400 
402  if (ret < 0)
403  return ret;
404 
405  memcpy(unit->data, ctx->write_buffer, unit->data_size);
406 
407  return 0;
408 }
409 
412 {
413  int err, i;
414 
415  for (i = 0; i < frag->nb_units; i++) {
416  CodedBitstreamUnit *unit = &frag->units[i];
417 
418  if (!unit->content)
419  continue;
420 
421  av_buffer_unref(&unit->data_ref);
422  unit->data = NULL;
423 
424  err = cbs_write_unit_data(ctx, unit);
425  if (err < 0) {
426  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
427  "(type %"PRIu32").\n", i, unit->type);
428  return err;
429  }
430  av_assert0(unit->data && unit->data_ref);
431  }
432 
433  av_buffer_unref(&frag->data_ref);
434  frag->data = NULL;
435 
436  err = ctx->codec->assemble_fragment(ctx, frag);
437  if (err < 0) {
438  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
439  return err;
440  }
441  av_assert0(frag->data && frag->data_ref);
442 
443  return 0;
444 }
445 
447  AVCodecParameters *par,
449 {
450  int err;
451 
452  err = CBS_FUNC(write_fragment_data)(ctx, frag);
453  if (err < 0)
454  return err;
455 
456  av_freep(&par->extradata);
457  par->extradata_size = 0;
458 
459  if (!frag->data_size)
460  return 0;
461 
462  par->extradata = av_malloc(frag->data_size +
464  if (!par->extradata)
465  return AVERROR(ENOMEM);
466 
467  memcpy(par->extradata, frag->data, frag->data_size);
468  memset(par->extradata + frag->data_size, 0,
470  par->extradata_size = frag->data_size;
471 
472  return 0;
473 }
474 
476  AVPacket *pkt,
478 {
479  AVBufferRef *buf;
480  int err;
481 
482  err = CBS_FUNC(write_fragment_data)(ctx, frag);
483  if (err < 0)
484  return err;
485 
486  buf = av_buffer_ref(frag->data_ref);
487  if (!buf)
488  return AVERROR(ENOMEM);
489 
491 
492  pkt->buf = buf;
493  pkt->data = frag->data;
494  pkt->size = frag->data_size;
495 
496  return 0;
497 }
498 #endif
499 
500 
502  const char *name)
503 {
504 #if CBS_TRACE
505  if (!ctx->trace_enable)
506  return;
507 
508  av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
509 #endif
510 }
511 
512 void CBS_FUNC(trace_read_log)(void *trace_context,
513  GetBitContext *gbc, int length,
514  const char *str, const int *subscripts,
515  int64_t value)
516 {
517 #if CBS_TRACE
518  CodedBitstreamContext *ctx = trace_context;
519  char name[256];
520  char bits[256];
521  size_t name_len, bits_len;
522  int pad, subs, i, j, k, n;
523  int position;
524 
525  av_assert0(value >= INT_MIN && value <= UINT32_MAX);
526 
527  position = get_bits_count(gbc);
528 
529  av_assert0(length < 256);
530  for (i = 0; i < length; i++)
531  bits[i] = get_bits1(gbc) ? '1' : '0';
532  bits[length] = 0;
533 
534  subs = subscripts ? subscripts[0] : 0;
535  n = 0;
536  for (i = j = 0; str[i];) {
537  if (str[i] == '[') {
538  if (n < subs) {
539  ++n;
540  k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
541  av_assert0(k > 0 && j + k < sizeof(name));
542  j += k;
543  for (++i; str[i] && str[i] != ']'; i++);
544  av_assert0(str[i] == ']');
545  } else {
546  while (str[i] && str[i] != ']')
547  name[j++] = str[i++];
548  av_assert0(str[i] == ']');
549  }
550  } else {
551  av_assert0(j + 1 < sizeof(name));
552  name[j++] = str[i++];
553  }
554  }
555  av_assert0(j + 1 < sizeof(name));
556  name[j] = 0;
557  av_assert0(n == subs);
558 
559  name_len = strlen(name);
560  bits_len = length;
561 
562  if (name_len + bits_len > 60)
563  pad = bits_len + 2;
564  else
565  pad = 61 - name_len;
566 
567  av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
568  position, name, pad, bits, value);
569 #endif
570 }
571 
572 void CBS_FUNC(trace_write_log)(void *trace_context,
573  PutBitContext *pbc, int length,
574  const char *str, const int *subscripts,
575  int64_t value)
576 {
577 #if CBS_TRACE
578  CodedBitstreamContext *ctx = trace_context;
579 
580  // Ensure that the syntax element is written to the output buffer,
581  // make a GetBitContext pointed at the start position, then call the
582  // read log function which can read the bits back to log them.
583 
584  GetBitContext gbc;
585  int position;
586 
587  if (length > 0) {
589  flush = *pbc;
591  }
592 
593  position = put_bits_count(pbc);
594  av_assert0(position >= length);
595 
596  init_get_bits(&gbc, pbc->buf, position);
597 
598  skip_bits_long(&gbc, position - length);
599 
600  CBS_FUNC(trace_read_log)(ctx, &gbc, length, str, subscripts, value);
601 #endif
602 }
603 
604 #if CBS_READ
606  GetBitContext *gbc,
607  int width, const char *name,
608  const int *subscripts,
609  uint32_t *write_to,
610  uint32_t range_min,
611  uint32_t range_max)
612 {
613  uint32_t value;
614 
616 
617  av_assert0(width > 0 && width <= 32);
618 
619  if (get_bits_left(gbc) < width) {
620  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
621  "%s: bitstream ended.\n", name);
622  return AVERROR_INVALIDDATA;
623  }
624 
625  value = get_bits_long(gbc, width);
626 
628 
629  if (value < range_min || value > range_max) {
630  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
631  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
632  name, value, range_min, range_max);
633  return AVERROR_INVALIDDATA;
634  }
635 
636  *write_to = value;
637  return 0;
638 }
639 
641  int width, const char *name,
642  const int *subscripts, uint32_t *write_to,
643  uint32_t range_min, uint32_t range_max)
644 {
645  return cbs_read_unsigned(ctx, gbc, width, name, subscripts,
646  write_to, range_min, range_max);
647 }
648 
650  int width, const char *name, uint32_t *write_to)
651 {
652  return cbs_read_unsigned(ctx, gbc, width, name, NULL,
653  write_to, 0, UINT32_MAX);
654 }
655 #endif
656 
657 #if CBS_WRITE
659  int width, const char *name,
660  const int *subscripts, uint32_t value,
661  uint32_t range_min, uint32_t range_max)
662 {
664 
665  av_assert0(width > 0 && width <= 32);
666 
667  if (value < range_min || value > range_max) {
668  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
669  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
670  name, value, range_min, range_max);
671  return AVERROR_INVALIDDATA;
672  }
673 
674  if (put_bits_left(pbc) < width)
675  return AVERROR(ENOSPC);
676 
677  if (width < 32)
678  put_bits(pbc, width, value);
679  else
680  put_bits32(pbc, value);
681 
683 
684  return 0;
685 }
686 
688  int width, const char *name, uint32_t value)
689 {
690  return CBS_FUNC(write_unsigned)(ctx, pbc, width, name, NULL,
691  value, 0, MAX_UINT_BITS(width));
692 }
693 #endif
694 
695 #if CBS_READ
697  int width, const char *name,
698  const int *subscripts, int32_t *write_to,
699  int32_t range_min, int32_t range_max)
700 {
701  int32_t value;
702 
704 
705  av_assert0(width > 0 && width <= 32);
706 
707  if (get_bits_left(gbc) < width) {
708  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
709  "%s: bitstream ended.\n", name);
710  return AVERROR_INVALIDDATA;
711  }
712 
713  value = get_sbits_long(gbc, width);
714 
716 
717  if (value < range_min || value > range_max) {
718  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
719  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
720  name, value, range_min, range_max);
721  return AVERROR_INVALIDDATA;
722  }
723 
724  *write_to = value;
725  return 0;
726 }
727 #endif
728 
729 #if CBS_WRITE
731  int width, const char *name,
732  const int *subscripts, int32_t value,
733  int32_t range_min, int32_t range_max)
734 {
736 
737  av_assert0(width > 0 && width <= 32);
738 
739  if (value < range_min || value > range_max) {
740  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
741  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
742  name, value, range_min, range_max);
743  return AVERROR_INVALIDDATA;
744  }
745 
746  if (put_bits_left(pbc) < width)
747  return AVERROR(ENOSPC);
748 
749  if (width < 32)
750  put_sbits(pbc, width, value);
751  else
752  put_bits32(pbc, value);
753 
755 
756  return 0;
757 }
758 #endif
759 
760 
762  int position)
763 {
764  CodedBitstreamUnit *units;
765 
766  if (frag->nb_units < frag->nb_units_allocated) {
767  units = frag->units;
768 
769  if (position < frag->nb_units)
770  memmove(units + position + 1, units + position,
771  (frag->nb_units - position) * sizeof(*units));
772  } else {
773  units = av_malloc_array(frag->nb_units*2 + 1, sizeof(*units));
774  if (!units)
775  return AVERROR(ENOMEM);
776 
777  frag->nb_units_allocated = 2*frag->nb_units_allocated + 1;
778 
779  if (position > 0)
780  memcpy(units, frag->units, position * sizeof(*units));
781 
782  if (position < frag->nb_units)
783  memcpy(units + position + 1, frag->units + position,
784  (frag->nb_units - position) * sizeof(*units));
785  }
786 
787  memset(units + position, 0, sizeof(*units));
788 
789  if (units != frag->units) {
790  av_free(frag->units);
791  frag->units = units;
792  }
793 
794  ++frag->nb_units;
795 
796  return 0;
797 }
798 
800  int position,
802  void *content,
803  void *content_ref)
804 {
805  CodedBitstreamUnit *unit;
806  int err;
807 
808  if (position == -1)
809  position = frag->nb_units;
810  av_assert0(position >= 0 && position <= frag->nb_units);
811 
812  err = cbs_insert_unit(frag, position);
813  if (err < 0)
814  return err;
815 
816  if (content_ref) {
817  // Create our own reference out of the user-supplied one.
818  content_ref = av_refstruct_ref(content_ref);
819  }
820 
821  unit = &frag->units[position];
822  unit->type = type;
823  unit->content = content;
824  unit->content_ref = content_ref;
825 
826  return 0;
827 }
828 
831  uint8_t *data, size_t data_size,
832  AVBufferRef *data_buf,
833  int position)
834 {
835  CodedBitstreamUnit *unit;
836  AVBufferRef *data_ref;
837  int err;
838 
839  av_assert0(position >= 0 && position <= frag->nb_units);
840 
841  if (data_buf)
842  data_ref = av_buffer_ref(data_buf);
843  else
844  data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
845  if (!data_ref) {
846  if (!data_buf)
847  av_free(data);
848  return AVERROR(ENOMEM);
849  }
850 
851  err = cbs_insert_unit(frag, position);
852  if (err < 0) {
853  av_buffer_unref(&data_ref);
854  return err;
855  }
856 
857  unit = &frag->units[position];
858  unit->type = type;
859  unit->data = data;
860  unit->data_size = data_size;
861  unit->data_ref = data_ref;
862 
863  return 0;
864 }
865 
868  uint8_t *data, size_t data_size,
869  AVBufferRef *data_buf)
870 {
871  return cbs_insert_unit_data(frag, type,
872  data, data_size, data_buf,
873  frag->nb_units);
874 }
875 
877  int position)
878 {
879  av_assert0(0 <= position && position < frag->nb_units
880  && "Unit to be deleted not in fragment.");
881 
882  cbs_unit_uninit(&frag->units[position]);
883 
884  --frag->nb_units;
885 
886  if (frag->nb_units > 0)
887  memmove(frag->units + position,
888  frag->units + position + 1,
889  (frag->nb_units - position) * sizeof(*frag->units));
890 }
891 
892 static void cbs_default_free_unit_content(AVRefStructOpaque opaque, void *content)
893 {
894  const CodedBitstreamUnitTypeDescriptor *desc = opaque.c;
895 
896  for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
897  void **ptr = (void**)((char*)content + desc->type.ref.offsets[i]);
898  av_buffer_unref((AVBufferRef**)(ptr + 1));
899  }
900 }
901 
904  CodedBitstreamUnit *unit)
905 {
907  int i, j;
908 
909  if (!ctx->codec->unit_types)
910  return NULL;
911 
912  for (i = 0;; i++) {
913  desc = &ctx->codec->unit_types[i];
914  if (desc->nb_unit_types == 0)
915  break;
916  if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
917  if (unit->type >= desc->unit_type.range.start &&
918  unit->type <= desc->unit_type.range.end)
919  return desc;
920  } else {
921  for (j = 0; j < desc->nb_unit_types; j++) {
922  if (desc->unit_type.list[j] == unit->type)
923  return desc;
924  }
925  }
926  }
927  return NULL;
928 }
929 
931 {
932  return av_refstruct_alloc_ext_c(desc->content_size, 0,
933  (AVRefStructOpaque){ .c = desc },
934  desc->content_type == CBS_CONTENT_TYPE_COMPLEX
935  ? desc->type.complex.content_free
937 }
938 
940  CodedBitstreamUnit *unit)
941 {
943 
944  av_assert0(!unit->content && !unit->content_ref);
945 
947  if (!desc)
948  return AVERROR(ENOSYS);
949 
950  unit->content_ref = cbs_alloc_content(desc);
951  if (!unit->content_ref)
952  return AVERROR(ENOMEM);
953  unit->content = unit->content_ref;
954 
955  return 0;
956 }
957 
958 static int cbs_clone_noncomplex_unit_content(void **clonep,
959  const CodedBitstreamUnit *unit,
961 {
962  const uint8_t *src;
963  uint8_t *copy;
964  int err, i;
965 
966  av_assert0(unit->content);
967  src = unit->content;
968 
970  if (!copy)
971  return AVERROR(ENOMEM);
972  memcpy(copy, src, desc->content_size);
973  for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
974  void **ptr = (void**)(copy + desc->type.ref.offsets[i]);
975  /* Zero all the AVBufferRefs as they are owned by src. */
976  *(ptr + 1) = NULL;
977  }
978 
979  for (i = 0; i < desc->type.ref.nb_offsets; i++) {
980  const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->type.ref.offsets[i]);
981  const AVBufferRef *src_buf = *(AVBufferRef**)(src_ptr + 1);
982  uint8_t **copy_ptr = (uint8_t**)(copy + desc->type.ref.offsets[i]);
983  AVBufferRef **copy_buf = (AVBufferRef**)(copy_ptr + 1);
984 
985  if (!*src_ptr) {
986  av_assert0(!src_buf);
987  continue;
988  }
989  if (!src_buf) {
990  // We can't handle a non-refcounted pointer here - we don't
991  // have enough information to handle whatever structure lies
992  // at the other end of it.
993  err = AVERROR(EINVAL);
994  goto fail;
995  }
996 
997  *copy_buf = av_buffer_ref(src_buf);
998  if (!*copy_buf) {
999  err = AVERROR(ENOMEM);
1000  goto fail;
1001  }
1002  }
1003  *clonep = copy;
1004 
1005  return 0;
1006 
1007 fail:
1009  return err;
1010 }
1011 
1012 /*
1013  * On success, unit->content and unit->content_ref are updated with
1014  * the new content; unit is untouched on failure.
1015  * Any old content_ref is simply overwritten and not freed.
1016  */
1018  CodedBitstreamUnit *unit)
1019 {
1021  void *new_content;
1022  int err;
1023 
1024  desc = cbs_find_unit_type_desc(ctx, unit);
1025  if (!desc)
1026  return AVERROR(ENOSYS);
1027 
1028  switch (desc->content_type) {
1030  err = cbs_clone_noncomplex_unit_content(&new_content, unit, desc);
1031  break;
1032 
1034  if (!desc->type.complex.content_clone)
1035  return AVERROR_PATCHWELCOME;
1036  err = desc->type.complex.content_clone(&new_content, unit);
1037  break;
1038 
1039  default:
1040  av_assert0(0 && "Invalid content type.");
1041  }
1042 
1043  if (err < 0)
1044  return err;
1045 
1046  unit->content_ref = new_content;
1047  unit->content = new_content;
1048  return 0;
1049 }
1050 
1052  CodedBitstreamUnit *unit)
1053 {
1054  av_assert0(unit->content);
1055  if (unit->content_ref)
1056  return 0;
1057  return cbs_clone_unit_content(ctx, unit);
1058 }
1059 
1061  CodedBitstreamUnit *unit)
1062 {
1063  void *ref = unit->content_ref;
1064  int err;
1065 
1066  av_assert0(unit->content);
1067  if (ref && av_refstruct_exclusive(ref))
1068  return 0;
1069 
1070  err = cbs_clone_unit_content(ctx, unit);
1071  if (err < 0)
1072  return err;
1074  return 0;
1075 }
1076 
1078  CodedBitstreamFragment *frag,
1079  enum AVDiscard skip,
1080  int flags)
1081 {
1082  if (!ctx->codec->discarded_unit)
1083  return;
1084 
1085  for (int i = frag->nb_units - 1; i >= 0; i--) {
1086  if (ctx->codec->discarded_unit(ctx, &frag->units[i], skip)) {
1087  // discard all units
1088  if (!(flags & DISCARD_FLAG_KEEP_NON_VCL)) {
1089  CBS_FUNC(fragment_free)(frag);
1090  return;
1091  }
1092 
1093  CBS_FUNC(delete_unit)(frag, i);
1094  }
1095  }
1096 }
make_unit_writable
int CBS_FUNC() make_unit_writable(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit writable so that internal fields can be modified.
Definition: cbs.c:1060
flags
const SwsFlags flags[]
Definition: swscale.c:61
cbs.h
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:261
read_extradata
int CBS_FUNC() read_extradata(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecParameters *par)
Read the extradata bitstream found in codec parameters into a fragment, then split into units and dec...
Definition: cbs.c:285
CodedBitstreamUnit::content_ref
void * content_ref
If content is reference counted, a RefStruct reference backing content.
Definition: cbs.h:119
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
av_opt_set_defaults
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1678
delete_unit
void CBS_FUNC() delete_unit(CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
Definition: cbs.c:876
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:678
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
put_bits32
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:291
put_bytes_output
static int put_bytes_output(const PutBitContext *s)
Definition: put_bits.h:89
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:47
AV_PKT_DATA_NEW_EXTRADATA
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition: packet.h:56
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
read_packet_side_data
int CBS_FUNC() read_packet_side_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Definition: cbs.c:311
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:404
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:114
int64_t
long long int64_t
Definition: coverity.c:34
put_sbits
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:281
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:249
read_simple_unsigned
int CBS_FUNC() read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to)
Definition: cbs.c:649
append_unit_data
int CBS_FUNC() append_unit_data(CodedBitstreamFragment *frag, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Add a new unit to a fragment with the given data bitstream.
Definition: cbs.c:866
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:223
AVPacket::data
uint8_t * data
Definition: packet.h:535
cbs_fill_fragment_data
static int cbs_fill_fragment_data(CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Definition: cbs.c:236
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:226
trace_read_log
void CBS_FUNC() trace_read_log(void *trace_context, GetBitContext *gbc, int length, const char *str, const int *subscripts, int64_t value)
Helper function for read tracing which formats the syntax element and logs the result.
Definition: cbs.c:512
data
const char data[16]
Definition: mxf.c:149
discard_units
void CBS_FUNC() discard_units(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, enum AVDiscard skip, int flags)
Discard units accroding to 'skip'.
Definition: cbs.c:1077
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:81
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVRefStructOpaque::c
const void * c
Definition: refstruct.h:60
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:497
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:77
write_unsigned
int CBS_FUNC() 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:658
av_refstruct_exclusive
int av_refstruct_exclusive(const void *obj)
Check whether the reference count of an object managed via this API is 1.
Definition: refstruct.c:174
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
cbs_unit_uninit
static void cbs_unit_uninit(CodedBitstreamUnit *unit)
Definition: cbs.c:159
write_simple_unsigned
int CBS_FUNC() write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value)
Definition: cbs.c:687
cbs_read_unsigned
static av_always_inline int 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:605
fail
#define fail()
Definition: checkasm.h:193
GetBitContext
Definition: get_bits.h:108
CBS_CONTENT_TYPE_INTERNAL_REFS
@ CBS_CONTENT_TYPE_INTERNAL_REFS
Definition: cbs_internal.h:74
put_bits_left
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:125
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1949
cbs_alloc_content
static void * cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc)
Definition: cbs.c:930
type
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 type
Definition: writing_filters.txt:86
alloc_unit_content
int CBS_FUNC() alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
Definition: cbs.c:939
CodedBitstreamUnit::data
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:88
refstruct.h
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:175
insert_unit_content
int CBS_FUNC() insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, void *content_ref)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:799
avassert.h
CodedBitstreamUnitTypeDescriptor
Definition: cbs_internal.h:92
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:235
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:129
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:142
av_refstruct_alloc_ext_c
void * av_refstruct_alloc_ext_c(size_t size, unsigned flags, AVRefStructOpaque opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
Allocate a refcounted object of usable size size managed via the RefStruct API.
Definition: refstruct.c:102
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:222
cbs_insert_unit_data
static int cbs_insert_unit_data(CodedBitstreamFragment *frag, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf, int position)
Definition: cbs.c:829
bits
uint8_t bits
Definition: vp3data.h:128
cbs_read_data
static int cbs_read_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, AVBufferRef *buf, const uint8_t *data, size_t size, int header)
Definition: cbs.c:256
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:54
read_unsigned
int CBS_FUNC() 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:640
ctx
AVFormatContext * ctx
Definition: movenc.c:49
cbs_internal.h
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
cbs_find_unit_type_desc
static const CodedBitstreamUnitTypeDescriptor * cbs_find_unit_type_desc(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:903
MAX_UINT_BITS
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:232
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
PutBitContext
Definition: put_bits.h:50
CBS_TRACE_WRITE_END
#define CBS_TRACE_WRITE_END()
Definition: cbs_internal.h:291
init
av_cold int CBS_FUNC() init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:88
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:518
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
AV_CODEC_ID_H266
#define AV_CODEC_ID_H266
Definition: codec_id.h:253
write_packet
int CBS_FUNC() write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to a packet.
Definition: cbs.c:475
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:371
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:93
read
int CBS_FUNC() read(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Read a bitstream from a memory region into a fragment, then split into units and decompose.
Definition: cbs.c:324
close
av_cold void CBS_FUNC() close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:140
cbs_clone_noncomplex_unit_content
static int cbs_clone_noncomplex_unit_content(void **clonep, const CodedBitstreamUnit *unit, const CodedBitstreamUnitTypeDescriptor *desc)
Definition: cbs.c:958
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
read_extradata_from_codec
int CBS_FUNC() read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Definition: cbs.c:294
CBS_FUNC
enum AVCodecID CBS_FUNC(all_codec_ids)[]
cbs_alloc_unit_data
static int cbs_alloc_unit_data(CodedBitstreamUnit *unit, size_t size)
Allocate a new internal data buffer of the given size in the unit.
Definition: cbs.c:339
AVPacket::size
int size
Definition: packet.h:536
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:186
flush
av_cold void CBS_FUNC() flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
Definition: cbs.c:134
write_fragment_data
int CBS_FUNC() write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:410
size
int size
Definition: twinvq_data.h:10344
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:135
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:188
CodedBitstreamUnit::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:99
make_unit_refcounted
int CBS_FUNC() make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
Definition: cbs.c:1051
CBS_CONTENT_TYPE_COMPLEX
@ CBS_CONTENT_TYPE_COMPLEX
Definition: cbs_internal.h:77
trace_header
void CBS_FUNC() trace_header(CodedBitstreamContext *ctx, const char *name)
Definition: cbs.c:501
header
static const uint8_t header[24]
Definition: sdr2.c:68
buffer.h
cbs_insert_unit
static int cbs_insert_unit(CodedBitstreamFragment *frag, int position)
Definition: cbs.c:761
av_refstruct_ref
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition: refstruct.c:140
CodedBitstreamType
Definition: cbs_internal.h:138
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:77
cbs_write_unit_data
static int cbs_write_unit_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:356
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:59
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
CodedBitstreamUnit::data_ref
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:105
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
put_bits_count
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:80
read_packet
int CBS_FUNC() read_packet(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Read the data bitstream from a packet into a fragment, then split into units and decompose.
Definition: cbs.c:303
av_packet_get_side_data
uint8_t * av_packet_get_side_data(const AVPacket *pkt, enum AVPacketSideDataType type, size_t *size)
Get side information from packet.
Definition: packet.c:253
trace_write_log
void CBS_FUNC() trace_write_log(void *trace_context, PutBitContext *pbc, int length, const char *str, const int *subscripts, int64_t value)
Helper function for write tracing which formats the syntax element and logs the result.
Definition: cbs.c:572
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
common.h
av_always_inline
#define av_always_inline
Definition: attributes.h:49
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
write_signed
int CBS_FUNC() write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, int32_t value, int32_t range_min, int32_t range_max)
Definition: cbs.c:730
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
cbs_default_free_unit_content
static void cbs_default_free_unit_content(AVRefStructOpaque opaque, void *content)
Definition: cbs.c:892
CodedBitstreamFragment::nb_units_allocated
int nb_units_allocated
Number of allocated units.
Definition: cbs.h:167
avcodec.h
CBS_UNIT_TYPE_RANGE
@ CBS_UNIT_TYPE_RANGE
Definition: cbs_internal.h:89
ret
ret
Definition: filter_design.txt:187
cbs_type_table
static const CodedBitstreamType *const cbs_type_table[]
Definition: cbs.c:33
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
cbs_clone_unit_content
static int cbs_clone_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:1017
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:129
AVCodecContext
main external API structure.
Definition: avcodec.h:431
DISCARD_FLAG_KEEP_NON_VCL
@ DISCARD_FLAG_KEEP_NON_VCL
keep non-vcl units even if the picture has been dropped.
Definition: cbs.h:514
AV_CODEC_ID_H265
#define AV_CODEC_ID_H265
Definition: codec_id.h:229
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
desc
const char * desc
Definition: libsvtav1.c:79
cbs_read_fragment_content
static int cbs_read_fragment_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs.c:193
read_signed
int CBS_FUNC() read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, int32_t *write_to, int32_t range_min, int32_t range_max)
Definition: cbs.c:696
mem.h
fragment_free
av_cold void CBS_FUNC() fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:184
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
fragment_reset
void CBS_FUNC() fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Definition: cbs.c:170
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVPacket
This structure stores compressed data.
Definition: packet.h:512
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
int32_t
int32_t
Definition: audioconvert.c:56
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
write_extradata
int CBS_FUNC() write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to the extradata in codec parameters.
Definition: cbs.c:446
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
CodedBitstreamFragment::data_ref
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:152
width
#define width
Definition: dsp.h:85
AVDiscard
AVDiscard
Definition: defs.h:212
get_sbits_long
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition: get_bits.h:454
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
CBS_TRACE_READ_START
#define CBS_TRACE_READ_START()
Definition: cbs_internal.h:245
snprintf
#define snprintf
Definition: snprintf.h:34
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1293
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
src
#define src
Definition: vp8dsp.c:248
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:160
CBS_TRACE_READ_END
#define CBS_TRACE_READ_END()
Definition: cbs_internal.h:253
CBS_TRACE_WRITE_START
#define CBS_TRACE_WRITE_START()
Definition: cbs_internal.h:283