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 #include "refstruct.h"
32 
33 
34 static const CodedBitstreamType *const cbs_type_table[] = {
35 #if CONFIG_CBS_AV1
37 #endif
38 #if CONFIG_CBS_H264
40 #endif
41 #if CONFIG_CBS_H265
43 #endif
44 #if CONFIG_CBS_H266
46 #endif
47 #if CONFIG_CBS_JPEG
49 #endif
50 #if CONFIG_CBS_MPEG2
52 #endif
53 #if CONFIG_CBS_VP9
55 #endif
56 };
57 
59 #if CONFIG_CBS_AV1
61 #endif
62 #if CONFIG_CBS_H264
64 #endif
65 #if CONFIG_CBS_H265
67 #endif
68 #if CONFIG_CBS_H266
70 #endif
71 #if CONFIG_CBS_JPEG
73 #endif
74 #if CONFIG_CBS_MPEG2
76 #endif
77 #if CONFIG_CBS_VP9
79 #endif
81 };
82 
84  enum AVCodecID codec_id, void *log_ctx)
85 {
87  const CodedBitstreamType *type;
88  int i;
89 
90  type = NULL;
91  for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
92  if (cbs_type_table[i]->codec_id == codec_id) {
94  break;
95  }
96  }
97  if (!type)
98  return AVERROR(EINVAL);
99 
100  ctx = av_mallocz(sizeof(*ctx));
101  if (!ctx)
102  return AVERROR(ENOMEM);
103 
104  ctx->log_ctx = log_ctx;
105  ctx->codec = type; /* Must be before any error */
106 
107  if (type->priv_data_size) {
108  ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
109  if (!ctx->priv_data) {
110  av_freep(&ctx);
111  return AVERROR(ENOMEM);
112  }
113  if (type->priv_class) {
114  *(const AVClass **)ctx->priv_data = type->priv_class;
116  }
117  }
118 
119  ctx->decompose_unit_types = NULL;
120 
121  ctx->trace_enable = 0;
122  ctx->trace_level = AV_LOG_TRACE;
123  ctx->trace_context = ctx;
124 
125  *ctx_ptr = ctx;
126  return 0;
127 }
128 
130 {
131  if (ctx->codec->flush)
132  ctx->codec->flush(ctx);
133 }
134 
136 {
137  CodedBitstreamContext *ctx = *ctx_ptr;
138 
139  if (!ctx)
140  return;
141 
142  if (ctx->codec->close)
143  ctx->codec->close(ctx);
144 
145  av_freep(&ctx->write_buffer);
146 
147  if (ctx->codec->priv_class && ctx->priv_data)
149 
151  av_freep(ctx_ptr);
152 }
153 
155 {
157  unit->content = NULL;
158 
159  av_buffer_unref(&unit->data_ref);
160  unit->data = NULL;
161  unit->data_size = 0;
162  unit->data_bit_padding = 0;
163 }
164 
166 {
167  int i;
168 
169  for (i = 0; i < frag->nb_units; i++)
170  cbs_unit_uninit(&frag->units[i]);
171  frag->nb_units = 0;
172 
173  av_buffer_unref(&frag->data_ref);
174  frag->data = NULL;
175  frag->data_size = 0;
176  frag->data_bit_padding = 0;
177 }
178 
180 {
181  ff_cbs_fragment_reset(frag);
182 
183  av_freep(&frag->units);
184  frag->nb_units_allocated = 0;
185 }
186 
189 {
190  int err, i, j;
191 
192  for (i = 0; i < frag->nb_units; i++) {
193  CodedBitstreamUnit *unit = &frag->units[i];
194 
195  if (ctx->decompose_unit_types) {
196  for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
197  if (ctx->decompose_unit_types[j] == unit->type)
198  break;
199  }
200  if (j >= ctx->nb_decompose_unit_types)
201  continue;
202  }
203 
205  unit->content = NULL;
206 
207  av_assert0(unit->data && unit->data_ref);
208 
209  err = ctx->codec->read_unit(ctx, unit);
210  if (err == AVERROR(ENOSYS)) {
211  av_log(ctx->log_ctx, AV_LOG_VERBOSE,
212  "Decomposition unimplemented for unit %d "
213  "(type %"PRIu32").\n", i, unit->type);
214  } else if (err == AVERROR(EAGAIN)) {
215  av_log(ctx->log_ctx, AV_LOG_VERBOSE,
216  "Skipping decomposition of unit %d "
217  "(type %"PRIu32").\n", i, unit->type);
219  unit->content = NULL;
220  } else if (err < 0) {
221  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
222  "(type %"PRIu32").\n", i, unit->type);
223  return err;
224  }
225  }
226 
227  return 0;
228 }
229 
231  const uint8_t *data, size_t size)
232 {
233  av_assert0(!frag->data && !frag->data_ref);
234 
235  frag->data_ref =
237  if (!frag->data_ref)
238  return AVERROR(ENOMEM);
239 
240  frag->data = frag->data_ref->data;
241  frag->data_size = size;
242 
243  memcpy(frag->data, data, size);
244  memset(frag->data + size, 0,
246 
247  return 0;
248 }
249 
252  AVBufferRef *buf,
253  const uint8_t *data, size_t size,
254  int header)
255 {
256  int err;
257 
258  if (buf) {
259  frag->data_ref = av_buffer_ref(buf);
260  if (!frag->data_ref)
261  return AVERROR(ENOMEM);
262 
263  frag->data = (uint8_t *)data;
264  frag->data_size = size;
265 
266  } else {
267  err = cbs_fill_fragment_data(frag, data, size);
268  if (err < 0)
269  return err;
270  }
271 
272  err = ctx->codec->split_fragment(ctx, frag, header);
273  if (err < 0)
274  return err;
275 
276  return cbs_read_fragment_content(ctx, frag);
277 }
278 
281  const AVCodecParameters *par)
282 {
283  return cbs_read_data(ctx, frag, NULL,
284  par->extradata,
285  par->extradata_size, 1);
286 }
287 
290  const AVCodecContext *avctx)
291 {
292  return cbs_read_data(ctx, frag, NULL,
293  avctx->extradata,
294  avctx->extradata_size, 1);
295 }
296 
299  const AVPacket *pkt)
300 {
301  return cbs_read_data(ctx, frag, pkt->buf,
302  pkt->data, pkt->size, 0);
303 }
304 
307  const AVPacket *pkt)
308 {
309  size_t side_data_size;
310  const uint8_t *side_data =
312  &side_data_size);
313 
314  return cbs_read_data(ctx, frag, NULL,
315  side_data, side_data_size, 1);
316 }
317 
320  const uint8_t *data, size_t size)
321 {
322  return cbs_read_data(ctx, frag, NULL,
323  data, size, 0);
324 }
325 
326 /**
327  * Allocate a new internal data buffer of the given size in the unit.
328  *
329  * The data buffer will have input padding.
330  */
332  size_t size)
333 {
334  av_assert0(!unit->data && !unit->data_ref);
335 
337  if (!unit->data_ref)
338  return AVERROR(ENOMEM);
339 
340  unit->data = unit->data_ref->data;
341  unit->data_size = size;
342 
343  memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
344 
345  return 0;
346 }
347 
349  CodedBitstreamUnit *unit)
350 {
351  PutBitContext pbc;
352  int ret;
353 
354  if (!ctx->write_buffer) {
355  // Initial write buffer size is 1MB.
356  ctx->write_buffer_size = 1024 * 1024;
357 
358  reallocate_and_try_again:
359  ret = av_reallocp(&ctx->write_buffer, ctx->write_buffer_size);
360  if (ret < 0) {
361  av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
362  "sufficiently large write buffer (last attempt "
363  "%"SIZE_SPECIFIER" bytes).\n", ctx->write_buffer_size);
364  return ret;
365  }
366  }
367 
368  init_put_bits(&pbc, ctx->write_buffer, ctx->write_buffer_size);
369 
370  ret = ctx->codec->write_unit(ctx, unit, &pbc);
371  if (ret < 0) {
372  if (ret == AVERROR(ENOSPC)) {
373  // Overflow.
374  if (ctx->write_buffer_size == INT_MAX / 8)
375  return AVERROR(ENOMEM);
376  ctx->write_buffer_size = FFMIN(2 * ctx->write_buffer_size, INT_MAX / 8);
377  goto reallocate_and_try_again;
378  }
379  // Write failed for some other reason.
380  return ret;
381  }
382 
383  // Overflow but we didn't notice.
384  av_assert0(put_bits_count(&pbc) <= 8 * ctx->write_buffer_size);
385 
386  if (put_bits_count(&pbc) % 8)
387  unit->data_bit_padding = 8 - put_bits_count(&pbc) % 8;
388  else
389  unit->data_bit_padding = 0;
390 
391  flush_put_bits(&pbc);
392 
394  if (ret < 0)
395  return ret;
396 
397  memcpy(unit->data, ctx->write_buffer, unit->data_size);
398 
399  return 0;
400 }
401 
404 {
405  int err, i;
406 
407  for (i = 0; i < frag->nb_units; i++) {
408  CodedBitstreamUnit *unit = &frag->units[i];
409 
410  if (!unit->content)
411  continue;
412 
413  av_buffer_unref(&unit->data_ref);
414  unit->data = NULL;
415 
416  err = cbs_write_unit_data(ctx, unit);
417  if (err < 0) {
418  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
419  "(type %"PRIu32").\n", i, unit->type);
420  return err;
421  }
422  av_assert0(unit->data && unit->data_ref);
423  }
424 
425  av_buffer_unref(&frag->data_ref);
426  frag->data = NULL;
427 
428  err = ctx->codec->assemble_fragment(ctx, frag);
429  if (err < 0) {
430  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
431  return err;
432  }
433  av_assert0(frag->data && frag->data_ref);
434 
435  return 0;
436 }
437 
439  AVCodecParameters *par,
441 {
442  int err;
443 
444  err = ff_cbs_write_fragment_data(ctx, frag);
445  if (err < 0)
446  return err;
447 
448  av_freep(&par->extradata);
449  par->extradata_size = 0;
450 
451  if (!frag->data_size)
452  return 0;
453 
454  par->extradata = av_malloc(frag->data_size +
456  if (!par->extradata)
457  return AVERROR(ENOMEM);
458 
459  memcpy(par->extradata, frag->data, frag->data_size);
460  memset(par->extradata + frag->data_size, 0,
462  par->extradata_size = frag->data_size;
463 
464  return 0;
465 }
466 
468  AVPacket *pkt,
470 {
471  AVBufferRef *buf;
472  int err;
473 
474  err = ff_cbs_write_fragment_data(ctx, frag);
475  if (err < 0)
476  return err;
477 
478  buf = av_buffer_ref(frag->data_ref);
479  if (!buf)
480  return AVERROR(ENOMEM);
481 
483 
484  pkt->buf = buf;
485  pkt->data = frag->data;
486  pkt->size = frag->data_size;
487 
488  return 0;
489 }
490 
491 
493  const char *name)
494 {
495  if (!ctx->trace_enable)
496  return;
497 
498  av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
499 }
500 
501 void ff_cbs_trace_read_log(void *trace_context,
502  GetBitContext *gbc, int length,
503  const char *str, const int *subscripts,
504  int64_t value)
505 {
506  CodedBitstreamContext *ctx = trace_context;
507  char name[256];
508  char bits[256];
509  size_t name_len, bits_len;
510  int pad, subs, i, j, k, n;
511  int position;
512 
513  av_assert0(value >= INT_MIN && value <= UINT32_MAX);
514 
515  position = get_bits_count(gbc);
516 
517  av_assert0(length < 256);
518  for (i = 0; i < length; i++)
519  bits[i] = get_bits1(gbc) ? '1' : '0';
520  bits[length] = 0;
521 
522  subs = subscripts ? subscripts[0] : 0;
523  n = 0;
524  for (i = j = 0; str[i];) {
525  if (str[i] == '[') {
526  if (n < subs) {
527  ++n;
528  k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
529  av_assert0(k > 0 && j + k < sizeof(name));
530  j += k;
531  for (++i; str[i] && str[i] != ']'; i++);
532  av_assert0(str[i] == ']');
533  } else {
534  while (str[i] && str[i] != ']')
535  name[j++] = str[i++];
536  av_assert0(str[i] == ']');
537  }
538  } else {
539  av_assert0(j + 1 < sizeof(name));
540  name[j++] = str[i++];
541  }
542  }
543  av_assert0(j + 1 < sizeof(name));
544  name[j] = 0;
545  av_assert0(n == subs);
546 
547  name_len = strlen(name);
548  bits_len = length;
549 
550  if (name_len + bits_len > 60)
551  pad = bits_len + 2;
552  else
553  pad = 61 - name_len;
554 
555  av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
556  position, name, pad, bits, value);
557 }
558 
559 void ff_cbs_trace_write_log(void *trace_context,
560  PutBitContext *pbc, int length,
561  const char *str, const int *subscripts,
562  int64_t value)
563 {
564  CodedBitstreamContext *ctx = trace_context;
565 
566  // Ensure that the syntax element is written to the output buffer,
567  // make a GetBitContext pointed at the start position, then call the
568  // read log function which can read the bits back to log them.
569 
570  GetBitContext gbc;
571  int position;
572 
573  if (length > 0) {
575  flush = *pbc;
577  }
578 
579  position = put_bits_count(pbc);
580  av_assert0(position >= length);
581 
582  init_get_bits(&gbc, pbc->buf, position);
583 
584  skip_bits_long(&gbc, position - length);
585 
586  ff_cbs_trace_read_log(ctx, &gbc, length, str, subscripts, value);
587 }
588 
590  GetBitContext *gbc,
591  int width, const char *name,
592  const int *subscripts,
593  uint32_t *write_to,
594  uint32_t range_min,
595  uint32_t range_max)
596 {
597  uint32_t value;
598 
600 
601  av_assert0(width > 0 && width <= 32);
602 
603  if (get_bits_left(gbc) < width) {
604  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
605  "%s: bitstream ended.\n", name);
606  return AVERROR_INVALIDDATA;
607  }
608 
609  value = get_bits_long(gbc, width);
610 
612 
613  if (value < range_min || value > range_max) {
614  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
615  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
616  name, value, range_min, range_max);
617  return AVERROR_INVALIDDATA;
618  }
619 
620  *write_to = value;
621  return 0;
622 }
623 
625  int width, const char *name,
626  const int *subscripts, uint32_t *write_to,
627  uint32_t range_min, uint32_t range_max)
628 {
629  return cbs_read_unsigned(ctx, gbc, width, name, subscripts,
630  write_to, range_min, range_max);
631 }
632 
634  int width, const char *name, uint32_t *write_to)
635 {
636  return cbs_read_unsigned(ctx, gbc, width, name, NULL,
637  write_to, 0, UINT32_MAX);
638 }
639 
641  int width, const char *name,
642  const int *subscripts, uint32_t value,
643  uint32_t range_min, uint32_t range_max)
644 {
646 
647  av_assert0(width > 0 && width <= 32);
648 
649  if (value < range_min || value > range_max) {
650  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
651  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
652  name, value, range_min, range_max);
653  return AVERROR_INVALIDDATA;
654  }
655 
656  if (put_bits_left(pbc) < width)
657  return AVERROR(ENOSPC);
658 
659  if (width < 32)
660  put_bits(pbc, width, value);
661  else
662  put_bits32(pbc, value);
663 
665 
666  return 0;
667 }
668 
670  int width, const char *name, uint32_t value)
671 {
672  return ff_cbs_write_unsigned(ctx, pbc, width, name, NULL,
673  value, 0, MAX_UINT_BITS(width));
674 }
675 
677  int width, const char *name,
678  const int *subscripts, int32_t *write_to,
679  int32_t range_min, int32_t range_max)
680 {
681  int32_t value;
682 
684 
685  av_assert0(width > 0 && width <= 32);
686 
687  if (get_bits_left(gbc) < width) {
688  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
689  "%s: bitstream ended.\n", name);
690  return AVERROR_INVALIDDATA;
691  }
692 
693  value = get_sbits_long(gbc, width);
694 
696 
697  if (value < range_min || value > range_max) {
698  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
699  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
700  name, value, range_min, range_max);
701  return AVERROR_INVALIDDATA;
702  }
703 
704  *write_to = value;
705  return 0;
706 }
707 
709  int width, const char *name,
710  const int *subscripts, int32_t value,
711  int32_t range_min, int32_t range_max)
712 {
714 
715  av_assert0(width > 0 && width <= 32);
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  if (put_bits_left(pbc) < width)
725  return AVERROR(ENOSPC);
726 
727  if (width < 32)
728  put_sbits(pbc, width, value);
729  else
730  put_bits32(pbc, value);
731 
733 
734  return 0;
735 }
736 
737 
739  int position)
740 {
741  CodedBitstreamUnit *units;
742 
743  if (frag->nb_units < frag->nb_units_allocated) {
744  units = frag->units;
745 
746  if (position < frag->nb_units)
747  memmove(units + position + 1, units + position,
748  (frag->nb_units - position) * sizeof(*units));
749  } else {
750  units = av_malloc_array(frag->nb_units*2 + 1, sizeof(*units));
751  if (!units)
752  return AVERROR(ENOMEM);
753 
754  frag->nb_units_allocated = 2*frag->nb_units_allocated + 1;
755 
756  if (position > 0)
757  memcpy(units, frag->units, position * sizeof(*units));
758 
759  if (position < frag->nb_units)
760  memcpy(units + position + 1, frag->units + position,
761  (frag->nb_units - position) * sizeof(*units));
762  }
763 
764  memset(units + position, 0, sizeof(*units));
765 
766  if (units != frag->units) {
767  av_free(frag->units);
768  frag->units = units;
769  }
770 
771  ++frag->nb_units;
772 
773  return 0;
774 }
775 
777  int position,
779  void *content,
780  void *content_ref)
781 {
782  CodedBitstreamUnit *unit;
783  int err;
784 
785  if (position == -1)
786  position = frag->nb_units;
787  av_assert0(position >= 0 && position <= frag->nb_units);
788 
789  err = cbs_insert_unit(frag, position);
790  if (err < 0)
791  return err;
792 
793  if (content_ref) {
794  // Create our own reference out of the user-supplied one.
795  content_ref = ff_refstruct_ref(content_ref);
796  }
797 
798  unit = &frag->units[position];
799  unit->type = type;
800  unit->content = content;
801  unit->content_ref = content_ref;
802 
803  return 0;
804 }
805 
808  uint8_t *data, size_t data_size,
809  AVBufferRef *data_buf,
810  int position)
811 {
812  CodedBitstreamUnit *unit;
813  AVBufferRef *data_ref;
814  int err;
815 
816  av_assert0(position >= 0 && position <= frag->nb_units);
817 
818  if (data_buf)
819  data_ref = av_buffer_ref(data_buf);
820  else
821  data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
822  if (!data_ref) {
823  if (!data_buf)
824  av_free(data);
825  return AVERROR(ENOMEM);
826  }
827 
828  err = cbs_insert_unit(frag, position);
829  if (err < 0) {
830  av_buffer_unref(&data_ref);
831  return err;
832  }
833 
834  unit = &frag->units[position];
835  unit->type = type;
836  unit->data = data;
837  unit->data_size = data_size;
838  unit->data_ref = data_ref;
839 
840  return 0;
841 }
842 
845  uint8_t *data, size_t data_size,
846  AVBufferRef *data_buf)
847 {
848  return cbs_insert_unit_data(frag, type,
849  data, data_size, data_buf,
850  frag->nb_units);
851 }
852 
854  int position)
855 {
856  av_assert0(0 <= position && position < frag->nb_units
857  && "Unit to be deleted not in fragment.");
858 
859  cbs_unit_uninit(&frag->units[position]);
860 
861  --frag->nb_units;
862 
863  if (frag->nb_units > 0)
864  memmove(frag->units + position,
865  frag->units + position + 1,
866  (frag->nb_units - position) * sizeof(*frag->units));
867 }
868 
869 static void cbs_default_free_unit_content(FFRefStructOpaque opaque, void *content)
870 {
871  const CodedBitstreamUnitTypeDescriptor *desc = opaque.c;
872 
873  for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
874  void **ptr = (void**)((char*)content + desc->type.ref.offsets[i]);
875  av_buffer_unref((AVBufferRef**)(ptr + 1));
876  }
877 }
878 
881  CodedBitstreamUnit *unit)
882 {
884  int i, j;
885 
886  if (!ctx->codec->unit_types)
887  return NULL;
888 
889  for (i = 0;; i++) {
890  desc = &ctx->codec->unit_types[i];
891  if (desc->nb_unit_types == 0)
892  break;
893  if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
894  if (unit->type >= desc->unit_type.range.start &&
895  unit->type <= desc->unit_type.range.end)
896  return desc;
897  } else {
898  for (j = 0; j < desc->nb_unit_types; j++) {
899  if (desc->unit_type.list[j] == unit->type)
900  return desc;
901  }
902  }
903  }
904  return NULL;
905 }
906 
908 {
909  return ff_refstruct_alloc_ext_c(desc->content_size, 0,
910  (FFRefStructOpaque){ .c = desc },
911  desc->content_type == CBS_CONTENT_TYPE_COMPLEX
912  ? desc->type.complex.content_free
914 }
915 
917  CodedBitstreamUnit *unit)
918 {
920 
921  av_assert0(!unit->content && !unit->content_ref);
922 
924  if (!desc)
925  return AVERROR(ENOSYS);
926 
928  if (!unit->content_ref)
929  return AVERROR(ENOMEM);
930  unit->content = unit->content_ref;
931 
932  return 0;
933 }
934 
935 static int cbs_clone_noncomplex_unit_content(void **clonep,
936  const CodedBitstreamUnit *unit,
938 {
939  const uint8_t *src;
940  uint8_t *copy;
941  int err, i;
942 
943  av_assert0(unit->content);
944  src = unit->content;
945 
947  if (!copy)
948  return AVERROR(ENOMEM);
949  memcpy(copy, src, desc->content_size);
950  for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
951  void **ptr = (void**)(copy + desc->type.ref.offsets[i]);
952  /* Zero all the AVBufferRefs as they are owned by src. */
953  *(ptr + 1) = NULL;
954  }
955 
956  for (i = 0; i < desc->type.ref.nb_offsets; i++) {
957  const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->type.ref.offsets[i]);
958  const AVBufferRef *src_buf = *(AVBufferRef**)(src_ptr + 1);
959  uint8_t **copy_ptr = (uint8_t**)(copy + desc->type.ref.offsets[i]);
960  AVBufferRef **copy_buf = (AVBufferRef**)(copy_ptr + 1);
961 
962  if (!*src_ptr) {
963  av_assert0(!src_buf);
964  continue;
965  }
966  if (!src_buf) {
967  // We can't handle a non-refcounted pointer here - we don't
968  // have enough information to handle whatever structure lies
969  // at the other end of it.
970  err = AVERROR(EINVAL);
971  goto fail;
972  }
973 
974  *copy_buf = av_buffer_ref(src_buf);
975  if (!*copy_buf) {
976  err = AVERROR(ENOMEM);
977  goto fail;
978  }
979  }
980  *clonep = copy;
981 
982  return 0;
983 
984 fail:
986  return err;
987 }
988 
989 /*
990  * On success, unit->content and unit->content_ref are updated with
991  * the new content; unit is untouched on failure.
992  * Any old content_ref is simply overwritten and not freed.
993  */
995  CodedBitstreamUnit *unit)
996 {
998  void *new_content;
999  int err;
1000 
1001  desc = cbs_find_unit_type_desc(ctx, unit);
1002  if (!desc)
1003  return AVERROR(ENOSYS);
1004 
1005  switch (desc->content_type) {
1007  err = cbs_clone_noncomplex_unit_content(&new_content, unit, desc);
1008  break;
1009 
1011  if (!desc->type.complex.content_clone)
1012  return AVERROR_PATCHWELCOME;
1013  err = desc->type.complex.content_clone(&new_content, unit);
1014  break;
1015 
1016  default:
1017  av_assert0(0 && "Invalid content type.");
1018  }
1019 
1020  if (err < 0)
1021  return err;
1022 
1023  unit->content_ref = new_content;
1024  unit->content = new_content;
1025  return 0;
1026 }
1027 
1029  CodedBitstreamUnit *unit)
1030 {
1031  av_assert0(unit->content);
1032  if (unit->content_ref)
1033  return 0;
1034  return cbs_clone_unit_content(ctx, unit);
1035 }
1036 
1038  CodedBitstreamUnit *unit)
1039 {
1040  void *ref = unit->content_ref;
1041  int err;
1042 
1043  av_assert0(unit->content);
1044  if (ref && ff_refstruct_exclusive(ref))
1045  return 0;
1046 
1047  err = cbs_clone_unit_content(ctx, unit);
1048  if (err < 0)
1049  return err;
1051  return 0;
1052 }
1053 
1055  CodedBitstreamFragment *frag,
1056  enum AVDiscard skip,
1057  int flags)
1058 {
1059  if (!ctx->codec->discarded_unit)
1060  return;
1061 
1062  for (int i = frag->nb_units - 1; i >= 0; i--) {
1063  if (ctx->codec->discarded_unit(ctx, &frag->units[i], skip)) {
1064  // discard all units
1065  if (!(flags & DISCARD_FLAG_KEEP_NON_VCL)) {
1066  ff_cbs_fragment_free(frag);
1067  return;
1068  }
1069 
1070  ff_cbs_delete_unit(frag, i);
1071  }
1072  }
1073 }
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
CodedBitstreamUnit::content_ref
void * content_ref
If content is reference counted, a RefStruct reference backing content.
Definition: cbs.h:112
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:69
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
ff_refstruct_ref
void * ff_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition: refstruct.c:136
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
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
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:1459
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
ff_cbs_fragment_free
av_cold 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:179
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
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:279
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:107
cbs_fill_fragment_data
static int cbs_fill_fragment_data(CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Definition: cbs.c:230
ff_cbs_insert_unit_content
int ff_cbs_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:776
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:266
ff_cbs_read_packet_side_data
int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt)
Definition: cbs.c:305
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:250
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:222
ff_cbs_type_vp9
const CodedBitstreamType ff_cbs_type_vp9
Definition: cbs_vp9.c:602
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:165
AVPacket::data
uint8_t * data
Definition: packet.h:491
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
data
const char data[16]
Definition: mxf.c:148
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:74
cbs.h
ff_refstruct_alloc_ext_c
void * ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, void(*free_cb)(FFRefStructOpaque opaque, void *obj))
Allocate a refcounted object of usable size size managed via the RefStruct API.
Definition: refstruct.c:98
FFRefStructOpaque
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition: refstruct.h:58
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:514
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:70
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:135
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
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:640
DISCARD_FLAG_KEEP_NON_VCL
@ DISCARD_FLAG_KEEP_NON_VCL
keep non-vcl units even if the picture has been dropped.
Definition: cbs.h:507
ff_cbs_trace_header
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
Definition: cbs.c:492
fail
#define fail()
Definition: checkasm.h:138
GetBitContext
Definition: get_bits.h:108
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:318
ff_cbs_trace_read_log
void ff_cbs_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:501
CBS_CONTENT_TYPE_INTERNAL_REFS
@ CBS_CONTENT_TYPE_INTERNAL_REFS
Definition: cbs_internal.h:38
put_bits_left
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:125
ff_cbs_type_av1
const CodedBitstreamType ff_cbs_type_av1
Definition: cbs_av1.c:1285
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:81
cbs_write_unit_data
static int cbs_write_unit_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:348
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:438
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:1037
refstruct.h
ff_refstruct_exclusive
int ff_refstruct_exclusive(const void *obj)
Check whether the reference count of an object managed via this API is 1.
Definition: refstruct.c:170
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:168
avassert.h
CodedBitstreamUnitTypeDescriptor
Definition: cbs_internal.h:56
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
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:180
ff_cbs_type_mpeg2
const CodedBitstreamType ff_cbs_type_mpeg2
Definition: cbs_mpeg2.c:427
cbs_unit_uninit
static void cbs_unit_uninit(CodedBitstreamUnit *unit)
Definition: cbs.c:154
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:543
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
cbs_alloc_content
static void * cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc)
Definition: cbs.c:907
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:467
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:135
AV_CODEC_ID_VP9
@ AV_CODEC_ID_VP9
Definition: codec_id.h:220
bits
uint8_t bits
Definition: vp3data.h:128
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
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:806
ctx
AVFormatContext * ctx
Definition: movenc.c:48
ff_cbs_append_unit_data
int ff_cbs_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:843
cbs_internal.h
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:389
CodedBitstreamFragment::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:139
MAX_UINT_BITS
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:196
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:254
cbs_type_table
static const CodedBitstreamType *const cbs_type_table[]
Definition: cbs.c:34
ff_cbs_trace_write_log
void ff_cbs_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:559
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:474
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
PutBitContext::buf
uint8_t * buf
Definition: put_bits.h:53
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:283
AV_CODEC_ID_H266
#define AV_CODEC_ID_H266
Definition: codec_id.h:251
ff_cbs_all_codec_ids
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
Definition: cbs.c:58
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
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:86
cbs_clone_unit_content
static int cbs_clone_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:994
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1719
ff_cbs_read_simple_unsigned
int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to)
Definition: cbs.c:633
cbs_find_unit_type_desc
static const CodedBitstreamUnitTypeDescriptor * cbs_find_unit_type_desc(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:880
cbs_default_free_unit_content
static void cbs_default_free_unit_content(FFRefStructOpaque opaque, void *content)
Definition: cbs.c:869
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
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:73
AVPacket::size
int size
Definition: packet.h:492
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:185
size
int size
Definition: twinvq_data.h:10344
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:128
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:186
CodedBitstreamUnit::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:92
ff_cbs_type_jpeg
const CodedBitstreamType ff_cbs_type_jpeg
Definition: cbs_jpeg.c:435
CBS_CONTENT_TYPE_COMPLEX
@ CBS_CONTENT_TYPE_COMPLEX
Definition: cbs_internal.h:41
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:708
CodedBitstreamType
Definition: cbs_internal.h:102
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:77
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:676
ff_cbs_discard_units
void ff_cbs_discard_units(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, enum AVDiscard skip, int flags)
Discard units accroding to 'skip'.
Definition: cbs.c:1054
ff_cbs_read_extradata_from_codec
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Definition: cbs.c:288
cbs_clone_noncomplex_unit_content
static int cbs_clone_noncomplex_unit_content(void **clonep, const CodedBitstreamUnit *unit, const CodedBitstreamUnitTypeDescriptor *desc)
Definition: cbs.c:935
CBS_UNIT_TYPE_RANGE
@ CBS_UNIT_TYPE_RANGE
Definition: cbs_internal.h:53
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:98
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
put_bits_count
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:80
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:542
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: avpacket.c:252
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
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
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:254
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:1028
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:624
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:402
cbs_insert_unit
static int cbs_insert_unit(CodedBitstreamFragment *frag, int position)
Definition: cbs.c:738
CodedBitstreamFragment::nb_units_allocated
int nb_units_allocated
Number of allocated units.
Definition: cbs.h:160
avcodec.h
ret
ret
Definition: filter_design.txt:187
ff_cbs_alloc_unit_content
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
Definition: cbs.c:916
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:141
AVCodecContext
main external API structure.
Definition: avcodec.h:441
ff_cbs_write_simple_unsigned
int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value)
Definition: cbs.c:669
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:47
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:331
AV_CODEC_ID_H265
#define AV_CODEC_ID_H265
Definition: codec_id.h:227
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
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:297
desc
const char * desc
Definition: libsvtav1.c:83
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:367
FFRefStructOpaque::c
const void * c
Definition: refstruct.h:60
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
ff_cbs_init
av_cold 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:83
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
ff_cbs_type_h266
const CodedBitstreamType ff_cbs_type_h266
Definition: cbs_h2645.c:2066
AVPacket
This structure stores compressed data.
Definition: packet.h:468
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
int32_t
int32_t
Definition: audioconvert.c:56
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_cbs_type_h264
const CodedBitstreamType ff_cbs_type_h264
Definition: cbs_h2645.c:2032
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:145
cbs_read_fragment_content
static int cbs_read_fragment_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs.c:187
ff_cbs_flush
av_cold void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
Definition: cbs.c:129
AVDiscard
AVDiscard
Definition: defs.h:210
get_sbits_long
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition: get_bits.h:471
ff_cbs_type_h265
const CodedBitstreamType ff_cbs_type_h265
Definition: cbs_h2645.c:2049
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:208
snprintf
#define snprintf
Definition: snprintf.h:34
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1143
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:116
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:153
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:853
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:589
CBS_TRACE_READ_END
#define CBS_TRACE_READ_END()
Definition: cbs_internal.h:216
CBS_TRACE_WRITE_START
#define CBS_TRACE_WRITE_START()
Definition: cbs_internal.h:246