FFmpeg
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 "config.h"
22 
23 #include "libavutil/avassert.h"
24 #include "libavutil/buffer.h"
25 #include "libavutil/common.h"
26 #include "libavutil/opt.h"
27 
28 #include "avcodec.h"
29 #include "cbs.h"
30 #include "cbs_internal.h"
31 
32 
33 static const CodedBitstreamType *const cbs_type_table[] = {
34 #if CONFIG_CBS_AV1
36 #endif
37 #if CONFIG_CBS_H264
39 #endif
40 #if CONFIG_CBS_H265
42 #endif
43 #if CONFIG_CBS_JPEG
45 #endif
46 #if CONFIG_CBS_MPEG2
48 #endif
49 #if CONFIG_CBS_VP9
51 #endif
52 };
53 
55 #if CONFIG_CBS_AV1
57 #endif
58 #if CONFIG_CBS_H264
60 #endif
61 #if CONFIG_CBS_H265
63 #endif
64 #if CONFIG_CBS_JPEG
66 #endif
67 #if CONFIG_CBS_MPEG2
69 #endif
70 #if CONFIG_CBS_VP9
72 #endif
74 };
75 
77  enum AVCodecID codec_id, void *log_ctx)
78 {
80  const CodedBitstreamType *type;
81  int i;
82 
83  type = NULL;
84  for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
85  if (cbs_type_table[i]->codec_id == codec_id) {
87  break;
88  }
89  }
90  if (!type)
91  return AVERROR(EINVAL);
92 
93  ctx = av_mallocz(sizeof(*ctx));
94  if (!ctx)
95  return AVERROR(ENOMEM);
96 
97  ctx->log_ctx = log_ctx;
98  ctx->codec = type; /* Must be before any error */
99 
100  if (type->priv_data_size) {
101  ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
102  if (!ctx->priv_data) {
103  av_freep(&ctx);
104  return AVERROR(ENOMEM);
105  }
106  if (type->priv_class) {
107  *(const AVClass **)ctx->priv_data = type->priv_class;
109  }
110  }
111 
112  ctx->decompose_unit_types = NULL;
113 
114  ctx->trace_enable = 0;
115  ctx->trace_level = AV_LOG_TRACE;
116 
117  *ctx_ptr = ctx;
118  return 0;
119 }
120 
122 {
123  if (ctx->codec->flush)
124  ctx->codec->flush(ctx);
125 }
126 
128 {
129  CodedBitstreamContext *ctx = *ctx_ptr;
130 
131  if (!ctx)
132  return;
133 
134  if (ctx->codec->close)
135  ctx->codec->close(ctx);
136 
137  av_freep(&ctx->write_buffer);
138 
139  if (ctx->codec->priv_class && ctx->priv_data)
141 
143  av_freep(ctx_ptr);
144 }
145 
147 {
149  unit->content = NULL;
150 
151  av_buffer_unref(&unit->data_ref);
152  unit->data = NULL;
153  unit->data_size = 0;
154  unit->data_bit_padding = 0;
155 }
156 
158 {
159  int i;
160 
161  for (i = 0; i < frag->nb_units; i++)
162  cbs_unit_uninit(&frag->units[i]);
163  frag->nb_units = 0;
164 
165  av_buffer_unref(&frag->data_ref);
166  frag->data = NULL;
167  frag->data_size = 0;
168  frag->data_bit_padding = 0;
169 }
170 
172 {
173  ff_cbs_fragment_reset(frag);
174 
175  av_freep(&frag->units);
176  frag->nb_units_allocated = 0;
177 }
178 
181 {
182  int err, i, j;
183 
184  for (i = 0; i < frag->nb_units; i++) {
185  CodedBitstreamUnit *unit = &frag->units[i];
186 
187  if (ctx->decompose_unit_types) {
188  for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
189  if (ctx->decompose_unit_types[j] == unit->type)
190  break;
191  }
192  if (j >= ctx->nb_decompose_unit_types)
193  continue;
194  }
195 
197  unit->content = NULL;
198 
199  av_assert0(unit->data && unit->data_ref);
200 
201  err = ctx->codec->read_unit(ctx, unit);
202  if (err == AVERROR(ENOSYS)) {
203  av_log(ctx->log_ctx, AV_LOG_VERBOSE,
204  "Decomposition unimplemented for unit %d "
205  "(type %"PRIu32").\n", i, unit->type);
206  } else if (err == AVERROR(EAGAIN)) {
207  av_log(ctx->log_ctx, AV_LOG_VERBOSE,
208  "Skipping decomposition of unit %d "
209  "(type %"PRIu32").\n", i, unit->type);
211  unit->content = NULL;
212  } else if (err < 0) {
213  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
214  "(type %"PRIu32").\n", i, unit->type);
215  return err;
216  }
217  }
218 
219  return 0;
220 }
221 
223  const uint8_t *data, size_t size)
224 {
225  av_assert0(!frag->data && !frag->data_ref);
226 
227  frag->data_ref =
229  if (!frag->data_ref)
230  return AVERROR(ENOMEM);
231 
232  frag->data = frag->data_ref->data;
233  frag->data_size = size;
234 
235  memcpy(frag->data, data, size);
236  memset(frag->data + size, 0,
238 
239  return 0;
240 }
241 
244  AVBufferRef *buf,
245  const uint8_t *data, size_t size,
246  int header)
247 {
248  int err;
249 
250  if (buf) {
251  frag->data_ref = av_buffer_ref(buf);
252  if (!frag->data_ref)
253  return AVERROR(ENOMEM);
254 
255  frag->data = (uint8_t *)data;
256  frag->data_size = size;
257 
258  } else {
259  err = cbs_fill_fragment_data(frag, data, size);
260  if (err < 0)
261  return err;
262  }
263 
264  err = ctx->codec->split_fragment(ctx, frag, header);
265  if (err < 0)
266  return err;
267 
268  return cbs_read_fragment_content(ctx, frag);
269 }
270 
273  const AVCodecParameters *par)
274 {
275  return cbs_read_data(ctx, frag, NULL,
276  par->extradata,
277  par->extradata_size, 1);
278 }
279 
282  const AVCodecContext *avctx)
283 {
284  return cbs_read_data(ctx, frag, NULL,
285  avctx->extradata,
286  avctx->extradata_size, 1);
287 }
288 
291  const AVPacket *pkt)
292 {
293  return cbs_read_data(ctx, frag, pkt->buf,
294  pkt->data, pkt->size, 0);
295 }
296 
299  const uint8_t *data, size_t size)
300 {
301  return cbs_read_data(ctx, frag, NULL,
302  data, size, 0);
303 }
304 
306  CodedBitstreamUnit *unit)
307 {
308  PutBitContext pbc;
309  int ret;
310 
311  if (!ctx->write_buffer) {
312  // Initial write buffer size is 1MB.
313  ctx->write_buffer_size = 1024 * 1024;
314 
315  reallocate_and_try_again:
316  ret = av_reallocp(&ctx->write_buffer, ctx->write_buffer_size);
317  if (ret < 0) {
318  av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
319  "sufficiently large write buffer (last attempt "
320  "%"SIZE_SPECIFIER" bytes).\n", ctx->write_buffer_size);
321  return ret;
322  }
323  }
324 
325  init_put_bits(&pbc, ctx->write_buffer, ctx->write_buffer_size);
326 
327  ret = ctx->codec->write_unit(ctx, unit, &pbc);
328  if (ret < 0) {
329  if (ret == AVERROR(ENOSPC)) {
330  // Overflow.
331  if (ctx->write_buffer_size == INT_MAX / 8)
332  return AVERROR(ENOMEM);
333  ctx->write_buffer_size = FFMIN(2 * ctx->write_buffer_size, INT_MAX / 8);
334  goto reallocate_and_try_again;
335  }
336  // Write failed for some other reason.
337  return ret;
338  }
339 
340  // Overflow but we didn't notice.
341  av_assert0(put_bits_count(&pbc) <= 8 * ctx->write_buffer_size);
342 
343  if (put_bits_count(&pbc) % 8)
344  unit->data_bit_padding = 8 - put_bits_count(&pbc) % 8;
345  else
346  unit->data_bit_padding = 0;
347 
348  flush_put_bits(&pbc);
349 
351  if (ret < 0)
352  return ret;
353 
354  memcpy(unit->data, ctx->write_buffer, unit->data_size);
355 
356  return 0;
357 }
358 
361 {
362  int err, i;
363 
364  for (i = 0; i < frag->nb_units; i++) {
365  CodedBitstreamUnit *unit = &frag->units[i];
366 
367  if (!unit->content)
368  continue;
369 
370  av_buffer_unref(&unit->data_ref);
371  unit->data = NULL;
372 
373  err = cbs_write_unit_data(ctx, unit);
374  if (err < 0) {
375  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
376  "(type %"PRIu32").\n", i, unit->type);
377  return err;
378  }
379  av_assert0(unit->data && unit->data_ref);
380  }
381 
382  av_buffer_unref(&frag->data_ref);
383  frag->data = NULL;
384 
385  err = ctx->codec->assemble_fragment(ctx, frag);
386  if (err < 0) {
387  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
388  return err;
389  }
390  av_assert0(frag->data && frag->data_ref);
391 
392  return 0;
393 }
394 
396  AVCodecParameters *par,
398 {
399  int err;
400 
401  err = ff_cbs_write_fragment_data(ctx, frag);
402  if (err < 0)
403  return err;
404 
405  av_freep(&par->extradata);
406 
407  par->extradata = av_malloc(frag->data_size +
409  if (!par->extradata)
410  return AVERROR(ENOMEM);
411 
412  memcpy(par->extradata, frag->data, frag->data_size);
413  memset(par->extradata + frag->data_size, 0,
415  par->extradata_size = frag->data_size;
416 
417  return 0;
418 }
419 
421  AVPacket *pkt,
423 {
424  AVBufferRef *buf;
425  int err;
426 
427  err = ff_cbs_write_fragment_data(ctx, frag);
428  if (err < 0)
429  return err;
430 
431  buf = av_buffer_ref(frag->data_ref);
432  if (!buf)
433  return AVERROR(ENOMEM);
434 
436 
437  pkt->buf = buf;
438  pkt->data = frag->data;
439  pkt->size = frag->data_size;
440 
441  return 0;
442 }
443 
444 
446  const char *name)
447 {
448  if (!ctx->trace_enable)
449  return;
450 
451  av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
452 }
453 
455  const char *str, const int *subscripts,
456  const char *bits, int64_t value)
457 {
458  char name[256];
459  size_t name_len, bits_len;
460  int pad, subs, i, j, k, n;
461 
462  if (!ctx->trace_enable)
463  return;
464 
465  av_assert0(value >= INT_MIN && value <= UINT32_MAX);
466 
467  subs = subscripts ? subscripts[0] : 0;
468  n = 0;
469  for (i = j = 0; str[i];) {
470  if (str[i] == '[') {
471  if (n < subs) {
472  ++n;
473  k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
474  av_assert0(k > 0 && j + k < sizeof(name));
475  j += k;
476  for (++i; str[i] && str[i] != ']'; i++);
477  av_assert0(str[i] == ']');
478  } else {
479  while (str[i] && str[i] != ']')
480  name[j++] = str[i++];
481  av_assert0(str[i] == ']');
482  }
483  } else {
484  av_assert0(j + 1 < sizeof(name));
485  name[j++] = str[i++];
486  }
487  }
488  av_assert0(j + 1 < sizeof(name));
489  name[j] = 0;
490  av_assert0(n == subs);
491 
492  name_len = strlen(name);
493  bits_len = strlen(bits);
494 
495  if (name_len + bits_len > 60)
496  pad = bits_len + 2;
497  else
498  pad = 61 - name_len;
499 
500  av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
501  position, name, pad, bits, value);
502 }
503 
505  int width, const char *name,
506  const int *subscripts, uint32_t *write_to,
507  uint32_t range_min, uint32_t range_max)
508 {
509  uint32_t value;
510  int position;
511 
512  av_assert0(width > 0 && width <= 32);
513 
514  if (get_bits_left(gbc) < width) {
515  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
516  "%s: bitstream ended.\n", name);
517  return AVERROR_INVALIDDATA;
518  }
519 
520  if (ctx->trace_enable)
521  position = get_bits_count(gbc);
522 
523  value = get_bits_long(gbc, width);
524 
525  if (ctx->trace_enable) {
526  char bits[33];
527  int i;
528  for (i = 0; i < width; i++)
529  bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
530  bits[i] = 0;
531 
532  ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
533  bits, value);
534  }
535 
536  if (value < range_min || value > range_max) {
537  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
538  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
539  name, value, range_min, range_max);
540  return AVERROR_INVALIDDATA;
541  }
542 
543  *write_to = value;
544  return 0;
545 }
546 
548  int width, const char *name,
549  const int *subscripts, uint32_t value,
550  uint32_t range_min, uint32_t range_max)
551 {
552  av_assert0(width > 0 && width <= 32);
553 
554  if (value < range_min || value > range_max) {
555  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
556  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
557  name, value, range_min, range_max);
558  return AVERROR_INVALIDDATA;
559  }
560 
561  if (put_bits_left(pbc) < width)
562  return AVERROR(ENOSPC);
563 
564  if (ctx->trace_enable) {
565  char bits[33];
566  int i;
567  for (i = 0; i < width; i++)
568  bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
569  bits[i] = 0;
570 
572  name, subscripts, bits, value);
573  }
574 
575  if (width < 32)
576  put_bits(pbc, width, value);
577  else
578  put_bits32(pbc, value);
579 
580  return 0;
581 }
582 
584  int width, const char *name,
585  const int *subscripts, int32_t *write_to,
586  int32_t range_min, int32_t range_max)
587 {
588  int32_t value;
589  int position;
590 
591  av_assert0(width > 0 && width <= 32);
592 
593  if (get_bits_left(gbc) < width) {
594  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
595  "%s: bitstream ended.\n", name);
596  return AVERROR_INVALIDDATA;
597  }
598 
599  if (ctx->trace_enable)
600  position = get_bits_count(gbc);
601 
602  value = get_sbits_long(gbc, width);
603 
604  if (ctx->trace_enable) {
605  char bits[33];
606  int i;
607  for (i = 0; i < width; i++)
608  bits[i] = value & (1U << (width - i - 1)) ? '1' : '0';
609  bits[i] = 0;
610 
611  ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
612  bits, value);
613  }
614 
615  if (value < range_min || value > range_max) {
616  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
617  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
618  name, value, range_min, range_max);
619  return AVERROR_INVALIDDATA;
620  }
621 
622  *write_to = value;
623  return 0;
624 }
625 
627  int width, const char *name,
628  const int *subscripts, int32_t value,
629  int32_t range_min, int32_t range_max)
630 {
631  av_assert0(width > 0 && width <= 32);
632 
633  if (value < range_min || value > range_max) {
634  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
635  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
636  name, value, range_min, range_max);
637  return AVERROR_INVALIDDATA;
638  }
639 
640  if (put_bits_left(pbc) < width)
641  return AVERROR(ENOSPC);
642 
643  if (ctx->trace_enable) {
644  char bits[33];
645  int i;
646  for (i = 0; i < width; i++)
647  bits[i] = value & (1U << (width - i - 1)) ? '1' : '0';
648  bits[i] = 0;
649 
651  name, subscripts, bits, value);
652  }
653 
654  if (width < 32)
655  put_sbits(pbc, width, value);
656  else
657  put_bits32(pbc, value);
658 
659  return 0;
660 }
661 
662 
664  size_t size,
665  void (*free)(void *opaque, uint8_t *data))
666 {
667  av_assert0(!unit->content && !unit->content_ref);
668 
669  unit->content = av_mallocz(size);
670  if (!unit->content)
671  return AVERROR(ENOMEM);
672 
673  unit->content_ref = av_buffer_create(unit->content, size,
674  free, NULL, 0);
675  if (!unit->content_ref) {
676  av_freep(&unit->content);
677  return AVERROR(ENOMEM);
678  }
679 
680  return 0;
681 }
682 
684  size_t size)
685 {
686  av_assert0(!unit->data && !unit->data_ref);
687 
689  if (!unit->data_ref)
690  return AVERROR(ENOMEM);
691 
692  unit->data = unit->data_ref->data;
693  unit->data_size = size;
694 
695  memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
696 
697  return 0;
698 }
699 
701  int position)
702 {
703  CodedBitstreamUnit *units;
704 
705  if (frag->nb_units < frag->nb_units_allocated) {
706  units = frag->units;
707 
708  if (position < frag->nb_units)
709  memmove(units + position + 1, units + position,
710  (frag->nb_units - position) * sizeof(*units));
711  } else {
712  units = av_malloc_array(frag->nb_units*2 + 1, sizeof(*units));
713  if (!units)
714  return AVERROR(ENOMEM);
715 
716  frag->nb_units_allocated = 2*frag->nb_units_allocated + 1;
717 
718  if (position > 0)
719  memcpy(units, frag->units, position * sizeof(*units));
720 
721  if (position < frag->nb_units)
722  memcpy(units + position + 1, frag->units + position,
723  (frag->nb_units - position) * sizeof(*units));
724  }
725 
726  memset(units + position, 0, sizeof(*units));
727 
728  if (units != frag->units) {
729  av_free(frag->units);
730  frag->units = units;
731  }
732 
733  ++frag->nb_units;
734 
735  return 0;
736 }
737 
739  int position,
741  void *content,
742  AVBufferRef *content_buf)
743 {
744  CodedBitstreamUnit *unit;
745  AVBufferRef *content_ref;
746  int err;
747 
748  if (position == -1)
749  position = frag->nb_units;
750  av_assert0(position >= 0 && position <= frag->nb_units);
751 
752  if (content_buf) {
753  content_ref = av_buffer_ref(content_buf);
754  if (!content_ref)
755  return AVERROR(ENOMEM);
756  } else {
757  content_ref = NULL;
758  }
759 
760  err = cbs_insert_unit(frag, position);
761  if (err < 0) {
762  av_buffer_unref(&content_ref);
763  return err;
764  }
765 
766  unit = &frag->units[position];
767  unit->type = type;
768  unit->content = content;
769  unit->content_ref = content_ref;
770 
771  return 0;
772 }
773 
775  int position,
777  uint8_t *data, size_t data_size,
778  AVBufferRef *data_buf)
779 {
780  CodedBitstreamUnit *unit;
781  AVBufferRef *data_ref;
782  int err;
783 
784  if (position == -1)
785  position = frag->nb_units;
786  av_assert0(position >= 0 && position <= frag->nb_units);
787 
788  if (data_buf)
789  data_ref = av_buffer_ref(data_buf);
790  else
791  data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
792  if (!data_ref) {
793  if (!data_buf)
794  av_free(data);
795  return AVERROR(ENOMEM);
796  }
797 
798  err = cbs_insert_unit(frag, position);
799  if (err < 0) {
800  av_buffer_unref(&data_ref);
801  return err;
802  }
803 
804  unit = &frag->units[position];
805  unit->type = type;
806  unit->data = data;
807  unit->data_size = data_size;
808  unit->data_ref = data_ref;
809 
810  return 0;
811 }
812 
814  int position)
815 {
816  av_assert0(0 <= position && position < frag->nb_units
817  && "Unit to be deleted not in fragment.");
818 
819  cbs_unit_uninit(&frag->units[position]);
820 
821  --frag->nb_units;
822 
823  if (frag->nb_units > 0)
824  memmove(frag->units + position,
825  frag->units + position + 1,
826  (frag->nb_units - position) * sizeof(*frag->units));
827 }
828 
829 static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
830 {
831  const CodedBitstreamUnitTypeDescriptor *desc = opaque;
832  if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
833  int i;
834  for (i = 0; i < desc->nb_ref_offsets; i++) {
835  void **ptr = (void**)(data + desc->ref_offsets[i]);
836  av_buffer_unref((AVBufferRef**)(ptr + 1));
837  }
838  }
839  av_free(data);
840 }
841 
844  CodedBitstreamUnit *unit)
845 {
847  int i, j;
848 
849  if (!ctx->codec->unit_types)
850  return NULL;
851 
852  for (i = 0;; i++) {
853  desc = &ctx->codec->unit_types[i];
854  if (desc->nb_unit_types == 0)
855  break;
856  if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
857  if (unit->type >= desc->unit_type_range_start &&
858  unit->type <= desc->unit_type_range_end)
859  return desc;
860  } else {
861  for (j = 0; j < desc->nb_unit_types; j++) {
862  if (desc->unit_types[j] == unit->type)
863  return desc;
864  }
865  }
866  }
867  return NULL;
868 }
869 
871  CodedBitstreamUnit *unit)
872 {
874 
875  av_assert0(!unit->content && !unit->content_ref);
876 
878  if (!desc)
879  return AVERROR(ENOSYS);
880 
881  unit->content = av_mallocz(desc->content_size);
882  if (!unit->content)
883  return AVERROR(ENOMEM);
884 
885  unit->content_ref =
886  av_buffer_create(unit->content, desc->content_size,
887  desc->content_free ? desc->content_free
889  (void*)desc, 0);
890  if (!unit->content_ref) {
891  av_freep(&unit->content);
892  return AVERROR(ENOMEM);
893  }
894 
895  return 0;
896 }
897 
898 static int cbs_clone_unit_content(AVBufferRef **clone_ref,
899  CodedBitstreamUnit *unit,
901 {
902  uint8_t *src, *copy;
903  uint8_t **src_ptr, **copy_ptr;
904  AVBufferRef **src_buf, **copy_buf;
905  int err, i;
906 
907  av_assert0(unit->content);
908  src = unit->content;
909 
910  copy = av_memdup(src, desc->content_size);
911  if (!copy)
912  return AVERROR(ENOMEM);
913 
914  for (i = 0; i < desc->nb_ref_offsets; i++) {
915  src_ptr = (uint8_t**)(src + desc->ref_offsets[i]);
916  src_buf = (AVBufferRef**)(src_ptr + 1);
917  copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
918  copy_buf = (AVBufferRef**)(copy_ptr + 1);
919 
920  if (!*src_ptr) {
921  av_assert0(!*src_buf);
922  continue;
923  }
924  if (!*src_buf) {
925  // We can't handle a non-refcounted pointer here - we don't
926  // have enough information to handle whatever structure lies
927  // at the other end of it.
928  err = AVERROR(EINVAL);
929  goto fail;
930  }
931 
932  // src_ptr is required to point somewhere inside src_buf. If it
933  // doesn't, there is a bug somewhere.
934  av_assert0(*src_ptr >= (*src_buf)->data &&
935  *src_ptr < (*src_buf)->data + (*src_buf)->size);
936 
937  *copy_buf = av_buffer_ref(*src_buf);
938  if (!*copy_buf) {
939  err = AVERROR(ENOMEM);
940  goto fail;
941  }
942  *copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data);
943  }
944 
945  *clone_ref = av_buffer_create(copy, desc->content_size,
946  desc->content_free ? desc->content_free :
948  (void*)desc, 0);
949  if (!*clone_ref) {
950  err = AVERROR(ENOMEM);
951  goto fail;
952  }
953 
954  return 0;
955 
956 fail:
957  for (--i; i >= 0; i--)
958  av_buffer_unref((AVBufferRef**)(copy + desc->ref_offsets[i]));
959  av_freep(&copy);
960  *clone_ref = NULL;
961  return err;
962 }
963 
965  CodedBitstreamUnit *unit)
966 {
968  AVBufferRef *ref;
969  int err;
970 
971  av_assert0(unit->content);
972  if (unit->content_ref) {
973  // Already refcounted, nothing to do.
974  return 0;
975  }
976 
978  if (!desc)
979  return AVERROR(ENOSYS);
980 
981  switch (desc->content_type) {
983  ref = av_buffer_alloc(desc->content_size);
984  if (!ref)
985  return AVERROR(ENOMEM);
986  memcpy(ref->data, unit->content, desc->content_size);
987  err = 0;
988  break;
989 
991  err = cbs_clone_unit_content(&ref, unit, desc);
992  break;
993 
995  if (!desc->content_clone)
996  return AVERROR_PATCHWELCOME;
997  err = desc->content_clone(&ref, unit);
998  break;
999 
1000  default:
1001  av_assert0(0 && "Invalid content type.");
1002  }
1003 
1004  if (err < 0)
1005  return err;
1006 
1007  unit->content_ref = ref;
1008  unit->content = ref->data;
1009  return 0;
1010 }
1011 
1013  CodedBitstreamUnit *unit)
1014 {
1016  AVBufferRef *ref;
1017  int err;
1018 
1019  // This can only be applied to refcounted units.
1020  err = ff_cbs_make_unit_refcounted(ctx, unit);
1021  if (err < 0)
1022  return err;
1023  av_assert0(unit->content && unit->content_ref);
1024 
1026  return 0;
1027 
1028  desc = cbs_find_unit_type_desc(ctx, unit);
1029  if (!desc)
1030  return AVERROR(ENOSYS);
1031 
1032  switch (desc->content_type) {
1033  case CBS_CONTENT_TYPE_POD:
1034  err = av_buffer_make_writable(&unit->content_ref);
1035  break;
1036 
1038  err = cbs_clone_unit_content(&ref, unit, desc);
1039  break;
1040 
1042  if (!desc->content_clone)
1043  return AVERROR_PATCHWELCOME;
1044  err = desc->content_clone(&ref, unit);
1045  break;
1046 
1047  default:
1048  av_assert0(0 && "Invalid content type.");
1049  }
1050  if (err < 0)
1051  return err;
1052 
1053  if (desc->content_type != CBS_CONTENT_TYPE_POD) {
1054  av_buffer_unref(&unit->content_ref);
1055  unit->content_ref = ref;
1056  }
1057  unit->content = unit->content_ref->data;
1058  return 0;
1059 }
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
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
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:850
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
put_bits32
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:290
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:1358
put_bytes_output
static int put_bytes_output(const PutBitContext *s)
Definition: put_bits.h:88
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:92
cbs_default_free_unit_content
static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
Definition: cbs.c:829
CBS_CONTENT_TYPE_POD
@ CBS_CONTENT_TYPE_POD
Definition: cbs_internal.h:35
ff_cbs_read_extradata
int ff_cbs_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:271
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:547
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:106
cbs_fill_fragment_data
static int cbs_fill_fragment_data(CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Definition: cbs.c:222
put_sbits
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:280
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:61
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:220
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:242
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:220
ff_cbs_type_vp9
const CodedBitstreamType ff_cbs_type_vp9
Definition: cbs_vp9.c:649
ff_cbs_fragment_reset
void ff_cbs_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:157
AVPacket::data
uint8_t * data
Definition: packet.h:365
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:173
ff_cbs_close
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:127
data
const char data[16]
Definition: mxf.c:142
ff_cbs_alloc_unit_content2
int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
Definition: cbs.c:870
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:197
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:73
cbs.h
ff_cbs_fragment_free
void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:171
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:69
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:292
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:547
ff_cbs_trace_header
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
Definition: cbs.c:445
ff_cbs_flush
void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
Definition: cbs.c:121
U
#define U(x)
Definition: vp56_arith.h:37
fail
#define fail()
Definition: checkasm.h:134
GetBitContext
Definition: get_bits.h:62
ff_cbs_read
int ff_cbs_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:297
CBS_CONTENT_TYPE_INTERNAL_REFS
@ CBS_CONTENT_TYPE_INTERNAL_REFS
Definition: cbs_internal.h:39
put_bits_left
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:124
ff_cbs_type_av1
const CodedBitstreamType ff_cbs_type_av1
Definition: cbs_av1.c:1321
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
CodedBitstreamUnit::data
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:80
cbs_write_unit_data
static int cbs_write_unit_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:305
ff_cbs_write_extradata
int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to the extradata in codec parameters.
Definition: cbs.c:395
ff_cbs_make_unit_writable
int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit writable so that internal fields can be modified.
Definition: cbs.c:1012
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:167
avassert.h
CodedBitstreamUnitTypeDescriptor
Definition: cbs_internal.h:57
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:207
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:181
ff_cbs_type_mpeg2
const CodedBitstreamType ff_cbs_type_mpeg2
Definition: cbs_mpeg2.c:421
cbs_unit_uninit
static void cbs_unit_uninit(CodedBitstreamUnit *unit)
Definition: cbs.c:146
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:486
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:121
width
#define width
ff_cbs_write_packet
int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to a packet.
Definition: cbs.c:420
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:134
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:218
bits
uint8_t bits
Definition: vp3data.h:141
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
ctx
AVFormatContext * ctx
Definition: movenc.c:48
cbs_internal.h
ff_cbs_alloc_unit_content
int ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
Definition: cbs.c:663
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
CodedBitstreamFragment::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:138
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:77
PutBitContext
Definition: put_bits.h:49
cbs_type_table
static const CodedBitstreamType *const cbs_type_table[]
Definition: cbs.c:33
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:348
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
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:279
ff_cbs_insert_unit_content
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:738
ff_cbs_all_codec_ids
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
Definition: cbs.c:54
src
#define src
Definition: vp8dsp.c:255
CodedBitstreamUnit::data_size
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition: cbs.h:85
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1611
cbs_find_unit_type_desc
static const CodedBitstreamUnitTypeDescriptor * cbs_find_unit_type_desc(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:843
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:29
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
cbs_clone_unit_content
static int cbs_clone_unit_content(AVBufferRef **clone_ref, CodedBitstreamUnit *unit, const CodedBitstreamUnitTypeDescriptor *desc)
Definition: cbs.c:898
AVPacket::size
int size
Definition: packet.h:366
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:194
size
int size
Definition: twinvq_data.h:10344
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:127
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:168
CodedBitstreamUnit::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:91
ff_cbs_type_jpeg
const CodedBitstreamType ff_cbs_type_jpeg
Definition: cbs_jpeg.c:461
CBS_CONTENT_TYPE_COMPLEX
@ CBS_CONTENT_TYPE_COMPLEX
Definition: cbs_internal.h:42
av_buffer_make_writable
int av_buffer_make_writable(AVBufferRef **pbuf)
Create a writable reference from a given buffer reference, avoiding data copy if possible.
Definition: buffer.c:151
header
static const uint8_t header[24]
Definition: sdr2.c:67
buffer.h
ff_cbs_write_signed
int ff_cbs_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:626
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
ff_cbs_insert_unit_data
int ff_cbs_insert_unit_data(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Insert a new unit into a fragment with the given data bitstream.
Definition: cbs.c:774
CodedBitstreamType
Definition: cbs_internal.h:91
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:67
ff_cbs_read_signed
int ff_cbs_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:583
ff_cbs_read_extradata_from_codec
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Definition: cbs.c:280
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:454
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: codec_id.h:57
CBS_UNIT_TYPE_RANGE
@ CBS_UNIT_TYPE_RANGE
Definition: cbs_internal.h:54
i
int i
Definition: input.c:407
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
CodedBitstreamUnit::data_ref
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:97
put_bits_count
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:79
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:485
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
common.h
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
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:244
ff_cbs_make_unit_refcounted
int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
Definition: cbs.c:964
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:504
ff_cbs_write_fragment_data
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:359
cbs_insert_unit
static int cbs_insert_unit(CodedBitstreamFragment *frag, int position)
Definition: cbs.c:700
av_buffer_is_writable
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:133
CodedBitstreamFragment::nb_units_allocated
int nb_units_allocated
Number of allocated units.
Definition: cbs.h:159
avcodec.h
CodedBitstreamUnit::content_ref
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
Definition: cbs.h:111
ret
ret
Definition: filter_design.txt:187
ff_cbs_init
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:76
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:193
AVCodecContext
main external API structure.
Definition: avcodec.h:384
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:46
AV_CODEC_ID_H265
#define AV_CODEC_ID_H265
Definition: codec_id.h:225
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
ff_cbs_read_packet
int ff_cbs_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:289
desc
const char * desc
Definition: libsvtav1.c:79
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:84
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:142
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVPacket
This structure stores compressed data.
Definition: packet.h:342
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
int32_t
int32_t
Definition: audioconvert.c:56
convert_header.str
string str
Definition: convert_header.py:20
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_cbs_type_h264
const CodedBitstreamType ff_cbs_type_h264
Definition: cbs_h2645.c:1476
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:144
cbs_read_fragment_content
static int cbs_read_fragment_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs.c:179
get_sbits_long
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition: get_bits.h:591
ff_cbs_type_h265
const CodedBitstreamType ff_cbs_type_h265
Definition: cbs_h2645.c:1492
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:52
snprintf
#define snprintf
Definition: snprintf.h:34
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1125
ff_cbs_alloc_unit_data
int ff_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:683
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:152
ff_cbs_delete_unit
void ff_cbs_delete_unit(CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
Definition: cbs.c:813