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_VP8
55 #endif
56 #if CONFIG_CBS_VP9
58 #endif
59 };
60 
62 #if CONFIG_CBS_AV1
64 #endif
65 #if CONFIG_CBS_H264
67 #endif
68 #if CONFIG_CBS_H265
70 #endif
71 #if CONFIG_CBS_H266
73 #endif
74 #if CONFIG_CBS_JPEG
76 #endif
77 #if CONFIG_CBS_MPEG2
79 #endif
80 #if CONFIG_CBS_VP8
82 #endif
83 #if CONFIG_CBS_VP9
85 #endif
87 };
88 
90  enum AVCodecID codec_id, void *log_ctx)
91 {
93  const CodedBitstreamType *type;
94  int i;
95 
96  type = NULL;
97  for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
98  if (cbs_type_table[i]->codec_id == codec_id) {
100  break;
101  }
102  }
103  if (!type)
104  return AVERROR(EINVAL);
105 
106  ctx = av_mallocz(sizeof(*ctx));
107  if (!ctx)
108  return AVERROR(ENOMEM);
109 
110  ctx->log_ctx = log_ctx;
111  ctx->codec = type; /* Must be before any error */
112 
113  if (type->priv_data_size) {
114  ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
115  if (!ctx->priv_data) {
116  av_freep(&ctx);
117  return AVERROR(ENOMEM);
118  }
119  if (type->priv_class) {
120  *(const AVClass **)ctx->priv_data = type->priv_class;
122  }
123  }
124 
125  ctx->decompose_unit_types = NULL;
126 
127  ctx->trace_enable = 0;
128  ctx->trace_level = AV_LOG_TRACE;
129  ctx->trace_context = ctx;
130 
131  *ctx_ptr = ctx;
132  return 0;
133 }
134 
136 {
137  if (ctx->codec->flush)
138  ctx->codec->flush(ctx);
139 }
140 
142 {
143  CodedBitstreamContext *ctx = *ctx_ptr;
144 
145  if (!ctx)
146  return;
147 
148  if (ctx->codec->close)
149  ctx->codec->close(ctx);
150 
151  av_freep(&ctx->write_buffer);
152 
153  if (ctx->codec->priv_class && ctx->priv_data)
155 
157  av_freep(ctx_ptr);
158 }
159 
161 {
163  unit->content = NULL;
164 
165  av_buffer_unref(&unit->data_ref);
166  unit->data = NULL;
167  unit->data_size = 0;
168  unit->data_bit_padding = 0;
169 }
170 
172 {
173  int i;
174 
175  for (i = 0; i < frag->nb_units; i++)
176  cbs_unit_uninit(&frag->units[i]);
177  frag->nb_units = 0;
178 
179  av_buffer_unref(&frag->data_ref);
180  frag->data = NULL;
181  frag->data_size = 0;
182  frag->data_bit_padding = 0;
183 }
184 
186 {
187  ff_cbs_fragment_reset(frag);
188 
189  av_freep(&frag->units);
190  frag->nb_units_allocated = 0;
191 }
192 
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 
332 /**
333  * Allocate a new internal data buffer of the given size in the unit.
334  *
335  * The data buffer will have input padding.
336  */
338  size_t size)
339 {
340  av_assert0(!unit->data && !unit->data_ref);
341 
343  if (!unit->data_ref)
344  return AVERROR(ENOMEM);
345 
346  unit->data = unit->data_ref->data;
347  unit->data_size = size;
348 
349  memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
350 
351  return 0;
352 }
353 
355  CodedBitstreamUnit *unit)
356 {
357  PutBitContext pbc;
358  int ret;
359 
360  if (!ctx->write_buffer) {
361  // Initial write buffer size is 1MB.
362  ctx->write_buffer_size = 1024 * 1024;
363 
364  reallocate_and_try_again:
365  ret = av_reallocp(&ctx->write_buffer, ctx->write_buffer_size);
366  if (ret < 0) {
367  av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
368  "sufficiently large write buffer (last attempt "
369  "%"SIZE_SPECIFIER" bytes).\n", ctx->write_buffer_size);
370  return ret;
371  }
372  }
373 
374  init_put_bits(&pbc, ctx->write_buffer, ctx->write_buffer_size);
375 
376  ret = ctx->codec->write_unit(ctx, unit, &pbc);
377  if (ret < 0) {
378  if (ret == AVERROR(ENOSPC)) {
379  // Overflow.
380  if (ctx->write_buffer_size == INT_MAX / 8)
381  return AVERROR(ENOMEM);
382  ctx->write_buffer_size = FFMIN(2 * ctx->write_buffer_size, INT_MAX / 8);
383  goto reallocate_and_try_again;
384  }
385  // Write failed for some other reason.
386  return ret;
387  }
388 
389  // Overflow but we didn't notice.
390  av_assert0(put_bits_count(&pbc) <= 8 * ctx->write_buffer_size);
391 
392  if (put_bits_count(&pbc) % 8)
393  unit->data_bit_padding = 8 - put_bits_count(&pbc) % 8;
394  else
395  unit->data_bit_padding = 0;
396 
397  flush_put_bits(&pbc);
398 
400  if (ret < 0)
401  return ret;
402 
403  memcpy(unit->data, ctx->write_buffer, unit->data_size);
404 
405  return 0;
406 }
407 
410 {
411  int err, i;
412 
413  for (i = 0; i < frag->nb_units; i++) {
414  CodedBitstreamUnit *unit = &frag->units[i];
415 
416  if (!unit->content)
417  continue;
418 
419  av_buffer_unref(&unit->data_ref);
420  unit->data = NULL;
421 
422  err = cbs_write_unit_data(ctx, unit);
423  if (err < 0) {
424  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
425  "(type %"PRIu32").\n", i, unit->type);
426  return err;
427  }
428  av_assert0(unit->data && unit->data_ref);
429  }
430 
431  av_buffer_unref(&frag->data_ref);
432  frag->data = NULL;
433 
434  err = ctx->codec->assemble_fragment(ctx, frag);
435  if (err < 0) {
436  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
437  return err;
438  }
439  av_assert0(frag->data && frag->data_ref);
440 
441  return 0;
442 }
443 
445  AVCodecParameters *par,
447 {
448  int err;
449 
450  err = ff_cbs_write_fragment_data(ctx, frag);
451  if (err < 0)
452  return err;
453 
454  av_freep(&par->extradata);
455  par->extradata_size = 0;
456 
457  if (!frag->data_size)
458  return 0;
459 
460  par->extradata = av_malloc(frag->data_size +
462  if (!par->extradata)
463  return AVERROR(ENOMEM);
464 
465  memcpy(par->extradata, frag->data, frag->data_size);
466  memset(par->extradata + frag->data_size, 0,
468  par->extradata_size = frag->data_size;
469 
470  return 0;
471 }
472 
474  AVPacket *pkt,
476 {
477  AVBufferRef *buf;
478  int err;
479 
480  err = ff_cbs_write_fragment_data(ctx, frag);
481  if (err < 0)
482  return err;
483 
484  buf = av_buffer_ref(frag->data_ref);
485  if (!buf)
486  return AVERROR(ENOMEM);
487 
489 
490  pkt->buf = buf;
491  pkt->data = frag->data;
492  pkt->size = frag->data_size;
493 
494  return 0;
495 }
496 
497 
499  const char *name)
500 {
501  if (!ctx->trace_enable)
502  return;
503 
504  av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
505 }
506 
507 void ff_cbs_trace_read_log(void *trace_context,
508  GetBitContext *gbc, int length,
509  const char *str, const int *subscripts,
510  int64_t value)
511 {
512  CodedBitstreamContext *ctx = trace_context;
513  char name[256];
514  char bits[256];
515  size_t name_len, bits_len;
516  int pad, subs, i, j, k, n;
517  int position;
518 
519  av_assert0(value >= INT_MIN && value <= UINT32_MAX);
520 
521  position = get_bits_count(gbc);
522 
523  av_assert0(length < 256);
524  for (i = 0; i < length; i++)
525  bits[i] = get_bits1(gbc) ? '1' : '0';
526  bits[length] = 0;
527 
528  subs = subscripts ? subscripts[0] : 0;
529  n = 0;
530  for (i = j = 0; str[i];) {
531  if (str[i] == '[') {
532  if (n < subs) {
533  ++n;
534  k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
535  av_assert0(k > 0 && j + k < sizeof(name));
536  j += k;
537  for (++i; str[i] && str[i] != ']'; i++);
538  av_assert0(str[i] == ']');
539  } else {
540  while (str[i] && str[i] != ']')
541  name[j++] = str[i++];
542  av_assert0(str[i] == ']');
543  }
544  } else {
545  av_assert0(j + 1 < sizeof(name));
546  name[j++] = str[i++];
547  }
548  }
549  av_assert0(j + 1 < sizeof(name));
550  name[j] = 0;
551  av_assert0(n == subs);
552 
553  name_len = strlen(name);
554  bits_len = length;
555 
556  if (name_len + bits_len > 60)
557  pad = bits_len + 2;
558  else
559  pad = 61 - name_len;
560 
561  av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
562  position, name, pad, bits, value);
563 }
564 
565 void ff_cbs_trace_write_log(void *trace_context,
566  PutBitContext *pbc, int length,
567  const char *str, const int *subscripts,
568  int64_t value)
569 {
570  CodedBitstreamContext *ctx = trace_context;
571 
572  // Ensure that the syntax element is written to the output buffer,
573  // make a GetBitContext pointed at the start position, then call the
574  // read log function which can read the bits back to log them.
575 
576  GetBitContext gbc;
577  int position;
578 
579  if (length > 0) {
581  flush = *pbc;
583  }
584 
585  position = put_bits_count(pbc);
586  av_assert0(position >= length);
587 
588  init_get_bits(&gbc, pbc->buf, position);
589 
590  skip_bits_long(&gbc, position - length);
591 
592  ff_cbs_trace_read_log(ctx, &gbc, length, str, subscripts, value);
593 }
594 
596  GetBitContext *gbc,
597  int width, const char *name,
598  const int *subscripts,
599  uint32_t *write_to,
600  uint32_t range_min,
601  uint32_t range_max)
602 {
603  uint32_t value;
604 
606 
607  av_assert0(width > 0 && width <= 32);
608 
609  if (get_bits_left(gbc) < width) {
610  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
611  "%s: bitstream ended.\n", name);
612  return AVERROR_INVALIDDATA;
613  }
614 
615  value = get_bits_long(gbc, width);
616 
618 
619  if (value < range_min || value > range_max) {
620  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
621  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
622  name, value, range_min, range_max);
623  return AVERROR_INVALIDDATA;
624  }
625 
626  *write_to = value;
627  return 0;
628 }
629 
631  int width, const char *name,
632  const int *subscripts, uint32_t *write_to,
633  uint32_t range_min, uint32_t range_max)
634 {
635  return cbs_read_unsigned(ctx, gbc, width, name, subscripts,
636  write_to, range_min, range_max);
637 }
638 
640  int width, const char *name, uint32_t *write_to)
641 {
642  return cbs_read_unsigned(ctx, gbc, width, name, NULL,
643  write_to, 0, UINT32_MAX);
644 }
645 
647  int width, const char *name,
648  const int *subscripts, uint32_t value,
649  uint32_t range_min, uint32_t range_max)
650 {
652 
653  av_assert0(width > 0 && width <= 32);
654 
655  if (value < range_min || value > range_max) {
656  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
657  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
658  name, value, range_min, range_max);
659  return AVERROR_INVALIDDATA;
660  }
661 
662  if (put_bits_left(pbc) < width)
663  return AVERROR(ENOSPC);
664 
665  if (width < 32)
666  put_bits(pbc, width, value);
667  else
668  put_bits32(pbc, value);
669 
671 
672  return 0;
673 }
674 
676  int width, const char *name, uint32_t value)
677 {
678  return ff_cbs_write_unsigned(ctx, pbc, width, name, NULL,
679  value, 0, MAX_UINT_BITS(width));
680 }
681 
683  int width, const char *name,
684  const int *subscripts, int32_t *write_to,
685  int32_t range_min, int32_t range_max)
686 {
687  int32_t value;
688 
690 
691  av_assert0(width > 0 && width <= 32);
692 
693  if (get_bits_left(gbc) < width) {
694  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
695  "%s: bitstream ended.\n", name);
696  return AVERROR_INVALIDDATA;
697  }
698 
699  value = get_sbits_long(gbc, width);
700 
702 
703  if (value < range_min || value > range_max) {
704  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
705  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
706  name, value, range_min, range_max);
707  return AVERROR_INVALIDDATA;
708  }
709 
710  *write_to = value;
711  return 0;
712 }
713 
715  int width, const char *name,
716  const int *subscripts, int32_t value,
717  int32_t range_min, int32_t range_max)
718 {
720 
721  av_assert0(width > 0 && width <= 32);
722 
723  if (value < range_min || value > range_max) {
724  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
725  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
726  name, value, range_min, range_max);
727  return AVERROR_INVALIDDATA;
728  }
729 
730  if (put_bits_left(pbc) < width)
731  return AVERROR(ENOSPC);
732 
733  if (width < 32)
734  put_sbits(pbc, width, value);
735  else
736  put_bits32(pbc, value);
737 
739 
740  return 0;
741 }
742 
743 
745  int position)
746 {
747  CodedBitstreamUnit *units;
748 
749  if (frag->nb_units < frag->nb_units_allocated) {
750  units = frag->units;
751 
752  if (position < frag->nb_units)
753  memmove(units + position + 1, units + position,
754  (frag->nb_units - position) * sizeof(*units));
755  } else {
756  units = av_malloc_array(frag->nb_units*2 + 1, sizeof(*units));
757  if (!units)
758  return AVERROR(ENOMEM);
759 
760  frag->nb_units_allocated = 2*frag->nb_units_allocated + 1;
761 
762  if (position > 0)
763  memcpy(units, frag->units, position * sizeof(*units));
764 
765  if (position < frag->nb_units)
766  memcpy(units + position + 1, frag->units + position,
767  (frag->nb_units - position) * sizeof(*units));
768  }
769 
770  memset(units + position, 0, sizeof(*units));
771 
772  if (units != frag->units) {
773  av_free(frag->units);
774  frag->units = units;
775  }
776 
777  ++frag->nb_units;
778 
779  return 0;
780 }
781 
783  int position,
785  void *content,
786  void *content_ref)
787 {
788  CodedBitstreamUnit *unit;
789  int err;
790 
791  if (position == -1)
792  position = frag->nb_units;
793  av_assert0(position >= 0 && position <= frag->nb_units);
794 
795  err = cbs_insert_unit(frag, position);
796  if (err < 0)
797  return err;
798 
799  if (content_ref) {
800  // Create our own reference out of the user-supplied one.
801  content_ref = ff_refstruct_ref(content_ref);
802  }
803 
804  unit = &frag->units[position];
805  unit->type = type;
806  unit->content = content;
807  unit->content_ref = content_ref;
808 
809  return 0;
810 }
811 
814  uint8_t *data, size_t data_size,
815  AVBufferRef *data_buf,
816  int position)
817 {
818  CodedBitstreamUnit *unit;
819  AVBufferRef *data_ref;
820  int err;
821 
822  av_assert0(position >= 0 && position <= frag->nb_units);
823 
824  if (data_buf)
825  data_ref = av_buffer_ref(data_buf);
826  else
827  data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
828  if (!data_ref) {
829  if (!data_buf)
830  av_free(data);
831  return AVERROR(ENOMEM);
832  }
833 
834  err = cbs_insert_unit(frag, position);
835  if (err < 0) {
836  av_buffer_unref(&data_ref);
837  return err;
838  }
839 
840  unit = &frag->units[position];
841  unit->type = type;
842  unit->data = data;
843  unit->data_size = data_size;
844  unit->data_ref = data_ref;
845 
846  return 0;
847 }
848 
851  uint8_t *data, size_t data_size,
852  AVBufferRef *data_buf)
853 {
854  return cbs_insert_unit_data(frag, type,
855  data, data_size, data_buf,
856  frag->nb_units);
857 }
858 
860  int position)
861 {
862  av_assert0(0 <= position && position < frag->nb_units
863  && "Unit to be deleted not in fragment.");
864 
865  cbs_unit_uninit(&frag->units[position]);
866 
867  --frag->nb_units;
868 
869  if (frag->nb_units > 0)
870  memmove(frag->units + position,
871  frag->units + position + 1,
872  (frag->nb_units - position) * sizeof(*frag->units));
873 }
874 
875 static void cbs_default_free_unit_content(FFRefStructOpaque opaque, void *content)
876 {
877  const CodedBitstreamUnitTypeDescriptor *desc = opaque.c;
878 
879  for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
880  void **ptr = (void**)((char*)content + desc->type.ref.offsets[i]);
881  av_buffer_unref((AVBufferRef**)(ptr + 1));
882  }
883 }
884 
887  CodedBitstreamUnit *unit)
888 {
890  int i, j;
891 
892  if (!ctx->codec->unit_types)
893  return NULL;
894 
895  for (i = 0;; i++) {
896  desc = &ctx->codec->unit_types[i];
897  if (desc->nb_unit_types == 0)
898  break;
899  if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
900  if (unit->type >= desc->unit_type.range.start &&
901  unit->type <= desc->unit_type.range.end)
902  return desc;
903  } else {
904  for (j = 0; j < desc->nb_unit_types; j++) {
905  if (desc->unit_type.list[j] == unit->type)
906  return desc;
907  }
908  }
909  }
910  return NULL;
911 }
912 
914 {
915  return ff_refstruct_alloc_ext_c(desc->content_size, 0,
916  (FFRefStructOpaque){ .c = desc },
917  desc->content_type == CBS_CONTENT_TYPE_COMPLEX
918  ? desc->type.complex.content_free
920 }
921 
923  CodedBitstreamUnit *unit)
924 {
926 
927  av_assert0(!unit->content && !unit->content_ref);
928 
930  if (!desc)
931  return AVERROR(ENOSYS);
932 
934  if (!unit->content_ref)
935  return AVERROR(ENOMEM);
936  unit->content = unit->content_ref;
937 
938  return 0;
939 }
940 
941 static int cbs_clone_noncomplex_unit_content(void **clonep,
942  const CodedBitstreamUnit *unit,
944 {
945  const uint8_t *src;
946  uint8_t *copy;
947  int err, i;
948 
949  av_assert0(unit->content);
950  src = unit->content;
951 
953  if (!copy)
954  return AVERROR(ENOMEM);
955  memcpy(copy, src, desc->content_size);
956  for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
957  void **ptr = (void**)(copy + desc->type.ref.offsets[i]);
958  /* Zero all the AVBufferRefs as they are owned by src. */
959  *(ptr + 1) = NULL;
960  }
961 
962  for (i = 0; i < desc->type.ref.nb_offsets; i++) {
963  const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->type.ref.offsets[i]);
964  const AVBufferRef *src_buf = *(AVBufferRef**)(src_ptr + 1);
965  uint8_t **copy_ptr = (uint8_t**)(copy + desc->type.ref.offsets[i]);
966  AVBufferRef **copy_buf = (AVBufferRef**)(copy_ptr + 1);
967 
968  if (!*src_ptr) {
969  av_assert0(!src_buf);
970  continue;
971  }
972  if (!src_buf) {
973  // We can't handle a non-refcounted pointer here - we don't
974  // have enough information to handle whatever structure lies
975  // at the other end of it.
976  err = AVERROR(EINVAL);
977  goto fail;
978  }
979 
980  *copy_buf = av_buffer_ref(src_buf);
981  if (!*copy_buf) {
982  err = AVERROR(ENOMEM);
983  goto fail;
984  }
985  }
986  *clonep = copy;
987 
988  return 0;
989 
990 fail:
992  return err;
993 }
994 
995 /*
996  * On success, unit->content and unit->content_ref are updated with
997  * the new content; unit is untouched on failure.
998  * Any old content_ref is simply overwritten and not freed.
999  */
1001  CodedBitstreamUnit *unit)
1002 {
1004  void *new_content;
1005  int err;
1006 
1007  desc = cbs_find_unit_type_desc(ctx, unit);
1008  if (!desc)
1009  return AVERROR(ENOSYS);
1010 
1011  switch (desc->content_type) {
1013  err = cbs_clone_noncomplex_unit_content(&new_content, unit, desc);
1014  break;
1015 
1017  if (!desc->type.complex.content_clone)
1018  return AVERROR_PATCHWELCOME;
1019  err = desc->type.complex.content_clone(&new_content, unit);
1020  break;
1021 
1022  default:
1023  av_assert0(0 && "Invalid content type.");
1024  }
1025 
1026  if (err < 0)
1027  return err;
1028 
1029  unit->content_ref = new_content;
1030  unit->content = new_content;
1031  return 0;
1032 }
1033 
1035  CodedBitstreamUnit *unit)
1036 {
1037  av_assert0(unit->content);
1038  if (unit->content_ref)
1039  return 0;
1040  return cbs_clone_unit_content(ctx, unit);
1041 }
1042 
1044  CodedBitstreamUnit *unit)
1045 {
1046  void *ref = unit->content_ref;
1047  int err;
1048 
1049  av_assert0(unit->content);
1050  if (ref && ff_refstruct_exclusive(ref))
1051  return 0;
1052 
1053  err = cbs_clone_unit_content(ctx, unit);
1054  if (err < 0)
1055  return err;
1057  return 0;
1058 }
1059 
1061  CodedBitstreamFragment *frag,
1062  enum AVDiscard skip,
1063  int flags)
1064 {
1065  if (!ctx->codec->discarded_unit)
1066  return;
1067 
1068  for (int i = frag->nb_units - 1; i >= 0; i--) {
1069  if (ctx->codec->discarded_unit(ctx, &frag->units[i], skip)) {
1070  // discard all units
1071  if (!(flags & DISCARD_FLAG_KEEP_NON_VCL)) {
1072  ff_cbs_fragment_free(frag);
1073  return;
1074  }
1075 
1076  ff_cbs_delete_unit(frag, i);
1077  }
1078  }
1079 }
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
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:1638
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:140
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
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:185
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:285
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:236
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:782
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:311
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
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:171
AVPacket::data
uint8_t * data
Definition: packet.h:522
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:102
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:141
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:646
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:498
fail
#define fail()
Definition: checkasm.h:179
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:324
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:507
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
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1908
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:354
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:444
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:1043
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:174
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:160
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:524
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:913
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:473
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:812
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:849
cbs_internal.h
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:386
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_UNIT_TYPE_RANGE
@ CBS_UNIT_TYPE_RANGE
Definition: cbs_internal.h:53
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:565
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:505
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:280
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:61
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:1000
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts.c:367
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:639
cbs_find_unit_type_desc
static const CodedBitstreamUnitTypeDescriptor * cbs_find_unit_type_desc(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:886
cbs_default_free_unit_content
static void cbs_default_free_unit_content(FFRefStructOpaque opaque, void *content)
Definition: cbs.c:875
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:523
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:68
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:714
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:682
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:1060
ff_cbs_read_extradata_from_codec
int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx)
Definition: cbs.c:294
cbs_clone_noncomplex_unit_content
static int cbs_clone_noncomplex_unit_content(void **clonep, const CodedBitstreamUnit *unit, const CodedBitstreamUnitTypeDescriptor *desc)
Definition: cbs.c:941
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:523
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_type_vp8
const CodedBitstreamType ff_cbs_type_vp8
Definition: cbs_vp8.c:361
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:1034
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:630
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:408
cbs_insert_unit
static int cbs_insert_unit(CodedBitstreamFragment *frag, int position)
Definition: cbs.c:744
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:922
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:445
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:675
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:337
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:303
desc
const char * desc
Definition: libsvtav1.c:73
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:89
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:2067
AVPacket
This structure stores compressed data.
Definition: packet.h:499
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
AV_CODEC_ID_VP8
@ AV_CODEC_ID_VP8
Definition: codec_id.h:192
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:2033
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:193
ff_cbs_flush
av_cold void ff_cbs_flush(CodedBitstreamContext *ctx)
Reset all internal state in a context.
Definition: cbs.c:135
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:2050
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:1283
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:120
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:859
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:595
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