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