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  const 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 AVBufferRef *buf,
333  const uint8_t *data, size_t size)
334 {
335  return cbs_read_data(ctx, frag, buf,
336  data, size, 0);
337 }
338 #endif
339 
340 #if CBS_WRITE
341 /**
342  * Allocate a new internal data buffer of the given size in the unit.
343  *
344  * The data buffer will have input padding.
345  */
347  size_t size)
348 {
349  av_assert0(!unit->data && !unit->data_ref);
350 
352  if (!unit->data_ref)
353  return AVERROR(ENOMEM);
354 
355  unit->data = unit->data_ref->data;
356  unit->data_size = size;
357 
358  memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
359 
360  return 0;
361 }
362 
364  CodedBitstreamUnit *unit)
365 {
366  PutBitContext pbc;
367  int ret;
368 
369  if (!ctx->write_buffer) {
370  // Initial write buffer size is 1MB.
371  ctx->write_buffer_size = 1024 * 1024;
372 
373  reallocate_and_try_again:
374  ret = av_reallocp(&ctx->write_buffer, ctx->write_buffer_size);
375  if (ret < 0) {
376  av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
377  "sufficiently large write buffer (last attempt "
378  "%"SIZE_SPECIFIER" bytes).\n", ctx->write_buffer_size);
379  return ret;
380  }
381  }
382 
383  init_put_bits(&pbc, ctx->write_buffer, ctx->write_buffer_size);
384 
385  ret = ctx->codec->write_unit(ctx, unit, &pbc);
386  if (ret < 0) {
387  if (ret == AVERROR(ENOSPC)) {
388  // Overflow.
389  if (ctx->write_buffer_size == INT_MAX / 8)
390  return AVERROR(ENOMEM);
391  ctx->write_buffer_size = FFMIN(2 * ctx->write_buffer_size, INT_MAX / 8);
392  goto reallocate_and_try_again;
393  }
394  // Write failed for some other reason.
395  return ret;
396  }
397 
398  // Overflow but we didn't notice.
399  av_assert0(put_bits_count(&pbc) <= 8 * ctx->write_buffer_size);
400 
401  if (put_bits_count(&pbc) % 8)
402  unit->data_bit_padding = 8 - put_bits_count(&pbc) % 8;
403  else
404  unit->data_bit_padding = 0;
405 
406  flush_put_bits(&pbc);
407 
409  if (ret < 0)
410  return ret;
411 
412  memcpy(unit->data, ctx->write_buffer, unit->data_size);
413 
414  return 0;
415 }
416 
419 {
420  int err, i;
421 
422  for (i = 0; i < frag->nb_units; i++) {
423  CodedBitstreamUnit *unit = &frag->units[i];
424 
425  if (!unit->content)
426  continue;
427 
428  av_buffer_unref(&unit->data_ref);
429  unit->data = NULL;
430 
431  err = cbs_write_unit_data(ctx, unit);
432  if (err < 0) {
433  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
434  "(type %"PRIu32").\n", i, unit->type);
435  return err;
436  }
437  av_assert0(unit->data && unit->data_ref);
438  }
439 
440  av_buffer_unref(&frag->data_ref);
441  frag->data = NULL;
442 
443  err = ctx->codec->assemble_fragment(ctx, frag);
444  if (err < 0) {
445  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
446  return err;
447  }
448  av_assert0(frag->data && frag->data_ref);
449 
450  return 0;
451 }
452 
454  AVCodecParameters *par,
456 {
457  int err;
458 
459  err = CBS_FUNC(write_fragment_data)(ctx, frag);
460  if (err < 0)
461  return err;
462 
463  av_freep(&par->extradata);
464  par->extradata_size = 0;
465 
466  if (!frag->data_size)
467  return 0;
468 
469  par->extradata = av_malloc(frag->data_size +
471  if (!par->extradata)
472  return AVERROR(ENOMEM);
473 
474  memcpy(par->extradata, frag->data, frag->data_size);
475  memset(par->extradata + frag->data_size, 0,
477  par->extradata_size = frag->data_size;
478 
479  return 0;
480 }
481 
483  AVPacket *pkt,
485 {
486  AVBufferRef *buf;
487  int err;
488 
489  err = CBS_FUNC(write_fragment_data)(ctx, frag);
490  if (err < 0)
491  return err;
492 
493  buf = av_buffer_ref(frag->data_ref);
494  if (!buf)
495  return AVERROR(ENOMEM);
496 
498 
499  pkt->buf = buf;
500  pkt->data = frag->data;
501  pkt->size = frag->data_size;
502 
503  return 0;
504 }
505 #endif
506 
507 
509  const char *name)
510 {
511 #if CBS_TRACE
512  if (!ctx->trace_enable)
513  return;
514 
515  av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
516 #endif
517 }
518 
519 void CBS_FUNC(trace_read_log)(void *trace_context,
520  GetBitContext *gbc, int length,
521  const char *str, const int *subscripts,
522  int64_t value)
523 {
524 #if CBS_TRACE
525  CodedBitstreamContext *ctx = trace_context;
526  char name[256];
527  char bits[256];
528  size_t name_len, bits_len;
529  int pad, subs, i, j, k, n;
530  int position;
531 
532  av_assert0(value >= INT_MIN && value <= UINT32_MAX);
533 
534  position = get_bits_count(gbc);
535 
536  av_assert0(length < 256);
537  for (i = 0; i < length; i++)
538  bits[i] = get_bits1(gbc) ? '1' : '0';
539  bits[length] = 0;
540 
541  subs = subscripts ? subscripts[0] : 0;
542  n = 0;
543  for (i = j = 0; str[i];) {
544  if (str[i] == '[') {
545  if (n < subs) {
546  ++n;
547  k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
548  av_assert0(k > 0 && j + k < sizeof(name));
549  j += k;
550  for (++i; str[i] && str[i] != ']'; i++);
551  av_assert0(str[i] == ']');
552  } else {
553  while (str[i] && str[i] != ']')
554  name[j++] = str[i++];
555  av_assert0(str[i] == ']');
556  }
557  } else {
558  av_assert0(j + 1 < sizeof(name));
559  name[j++] = str[i++];
560  }
561  }
562  av_assert0(j + 1 < sizeof(name));
563  name[j] = 0;
564  av_assert0(n == subs);
565 
566  name_len = strlen(name);
567  bits_len = length;
568 
569  if (name_len + bits_len > 60)
570  pad = bits_len + 2;
571  else
572  pad = 61 - name_len;
573 
574  av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
575  position, name, pad, bits, value);
576 #endif
577 }
578 
579 void CBS_FUNC(trace_write_log)(void *trace_context,
580  PutBitContext *pbc, int length,
581  const char *str, const int *subscripts,
582  int64_t value)
583 {
584 #if CBS_TRACE
585  CodedBitstreamContext *ctx = trace_context;
586 
587  // Ensure that the syntax element is written to the output buffer,
588  // make a GetBitContext pointed at the start position, then call the
589  // read log function which can read the bits back to log them.
590 
591  GetBitContext gbc;
592  int position;
593 
594  if (length > 0) {
596  flush = *pbc;
598  }
599 
600  position = put_bits_count(pbc);
601  av_assert0(position >= length);
602 
603  init_get_bits(&gbc, pbc->buf, position);
604 
605  skip_bits_long(&gbc, position - length);
606 
607  CBS_FUNC(trace_read_log)(ctx, &gbc, length, str, subscripts, value);
608 #endif
609 }
610 
611 #if CBS_READ
613  GetBitContext *gbc,
614  int width, const char *name,
615  const int *subscripts,
616  uint32_t *write_to,
617  uint32_t range_min,
618  uint32_t range_max)
619 {
620  uint32_t value;
621 
623 
624  av_assert0(width > 0 && width <= 32);
625 
626  if (get_bits_left(gbc) < width) {
627  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
628  "%s: bitstream ended.\n", name);
629  return AVERROR_INVALIDDATA;
630  }
631 
632  value = get_bits_long(gbc, width);
633 
635 
636  if (value < range_min || value > range_max) {
637  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
638  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
639  name, value, range_min, range_max);
640  return AVERROR_INVALIDDATA;
641  }
642 
643  *write_to = value;
644  return 0;
645 }
646 
648  int width, const char *name,
649  const int *subscripts, uint32_t *write_to,
650  uint32_t range_min, uint32_t range_max)
651 {
652  return cbs_read_unsigned(ctx, gbc, width, name, subscripts,
653  write_to, range_min, range_max);
654 }
655 
657  int width, const char *name, uint32_t *write_to)
658 {
659  return cbs_read_unsigned(ctx, gbc, width, name, NULL,
660  write_to, 0, UINT32_MAX);
661 }
662 #endif
663 
664 #if CBS_WRITE
666  int width, const char *name,
667  const int *subscripts, uint32_t value,
668  uint32_t range_min, uint32_t range_max)
669 {
671 
672  av_assert0(width > 0 && width <= 32);
673 
674  if (value < range_min || value > range_max) {
675  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
676  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
677  name, value, range_min, range_max);
678  return AVERROR_INVALIDDATA;
679  }
680 
681  if (put_bits_left(pbc) < width)
682  return AVERROR(ENOSPC);
683 
684  put_bits63(pbc, width, value);
685 
687 
688  return 0;
689 }
690 
692  int width, const char *name, uint32_t value)
693 {
694  return CBS_FUNC(write_unsigned)(ctx, pbc, width, name, NULL,
695  value, 0, MAX_UINT_BITS(width));
696 }
697 #endif
698 
699 #if CBS_READ
701  int width, const char *name,
702  const int *subscripts, int32_t *write_to,
703  int32_t range_min, int32_t range_max)
704 {
705  int32_t value;
706 
708 
709  av_assert0(width > 0 && width <= 32);
710 
711  if (get_bits_left(gbc) < width) {
712  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
713  "%s: bitstream ended.\n", name);
714  return AVERROR_INVALIDDATA;
715  }
716 
717  value = get_sbits_long(gbc, width);
718 
720 
721  if (value < range_min || value > range_max) {
722  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
723  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
724  name, value, range_min, range_max);
725  return AVERROR_INVALIDDATA;
726  }
727 
728  *write_to = value;
729  return 0;
730 }
731 #endif
732 
733 #if CBS_WRITE
735  int width, const char *name,
736  const int *subscripts, int32_t value,
737  int32_t range_min, int32_t range_max)
738 {
740 
741  av_assert0(width > 0 && width <= 32);
742 
743  if (value < range_min || value > range_max) {
744  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
745  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
746  name, value, range_min, range_max);
747  return AVERROR_INVALIDDATA;
748  }
749 
750  if (put_bits_left(pbc) < width)
751  return AVERROR(ENOSPC);
752 
754 
756 
757  return 0;
758 }
759 #endif
760 
761 
763  int position)
764 {
765  CodedBitstreamUnit *units;
766 
767  if (frag->nb_units < frag->nb_units_allocated) {
768  units = frag->units;
769 
770  if (position < frag->nb_units)
771  memmove(units + position + 1, units + position,
772  (frag->nb_units - position) * sizeof(*units));
773  } else {
774  units = av_malloc_array(frag->nb_units*2 + 1, sizeof(*units));
775  if (!units)
776  return AVERROR(ENOMEM);
777 
778  frag->nb_units_allocated = 2*frag->nb_units_allocated + 1;
779 
780  if (position > 0)
781  memcpy(units, frag->units, position * sizeof(*units));
782 
783  if (position < frag->nb_units)
784  memcpy(units + position + 1, frag->units + position,
785  (frag->nb_units - position) * sizeof(*units));
786  }
787 
788  memset(units + position, 0, sizeof(*units));
789 
790  if (units != frag->units) {
791  av_free(frag->units);
792  frag->units = units;
793  }
794 
795  ++frag->nb_units;
796 
797  return 0;
798 }
799 
801  int position,
803  void *content,
804  void *content_ref)
805 {
806  CodedBitstreamUnit *unit;
807  int err;
808 
809  if (position == -1)
810  position = frag->nb_units;
811  av_assert0(position >= 0 && position <= frag->nb_units);
812 
813  err = cbs_insert_unit(frag, position);
814  if (err < 0)
815  return err;
816 
817  if (content_ref) {
818  // Create our own reference out of the user-supplied one.
819  content_ref = av_refstruct_ref(content_ref);
820  }
821 
822  unit = &frag->units[position];
823  unit->type = type;
824  unit->content = content;
825  unit->content_ref = content_ref;
826 
827  return 0;
828 }
829 
832  uint8_t *data, size_t data_size,
833  AVBufferRef *data_buf,
834  int position)
835 {
836  CodedBitstreamUnit *unit;
837  AVBufferRef *data_ref;
838  int err;
839 
840  av_assert0(position >= 0 && position <= frag->nb_units);
841 
842  if (data_buf)
843  data_ref = av_buffer_ref(data_buf);
844  else
845  data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
846  if (!data_ref) {
847  if (!data_buf)
848  av_free(data);
849  return AVERROR(ENOMEM);
850  }
851 
852  err = cbs_insert_unit(frag, position);
853  if (err < 0) {
854  av_buffer_unref(&data_ref);
855  return err;
856  }
857 
858  unit = &frag->units[position];
859  unit->type = type;
860  unit->data = data;
861  unit->data_size = data_size;
862  unit->data_ref = data_ref;
863 
864  return 0;
865 }
866 
869  uint8_t *data, size_t data_size,
870  AVBufferRef *data_buf)
871 {
872  return cbs_insert_unit_data(frag, type,
873  data, data_size, data_buf,
874  frag->nb_units);
875 }
876 
878  int position)
879 {
880  av_assert0(0 <= position && position < frag->nb_units
881  && "Unit to be deleted not in fragment.");
882 
883  cbs_unit_uninit(&frag->units[position]);
884 
885  --frag->nb_units;
886 
887  if (frag->nb_units > 0)
888  memmove(frag->units + position,
889  frag->units + position + 1,
890  (frag->nb_units - position) * sizeof(*frag->units));
891 }
892 
893 static void cbs_default_free_unit_content(AVRefStructOpaque opaque, void *content)
894 {
895  const CodedBitstreamUnitTypeDescriptor *desc = opaque.c;
896 
897  for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
898  void **ptr = (void**)((char*)content + desc->type.ref.offsets[i]);
899  av_buffer_unref((AVBufferRef**)(ptr + 1));
900  }
901 }
902 
905  CodedBitstreamUnit *unit)
906 {
908  int i, j;
909 
910  if (!ctx->codec->unit_types)
911  return NULL;
912 
913  for (i = 0;; i++) {
914  desc = &ctx->codec->unit_types[i];
915  if (desc->nb_unit_types == 0)
916  break;
917  if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
918  if (unit->type >= desc->unit_type.range.start &&
919  unit->type <= desc->unit_type.range.end)
920  return desc;
921  } else {
922  for (j = 0; j < desc->nb_unit_types; j++) {
923  if (desc->unit_type.list[j] == unit->type)
924  return desc;
925  }
926  }
927  }
928  return NULL;
929 }
930 
932 {
933  return av_refstruct_alloc_ext_c(desc->content_size, 0,
934  (AVRefStructOpaque){ .c = desc },
935  desc->content_type == CBS_CONTENT_TYPE_COMPLEX
936  ? desc->type.complex.content_free
938 }
939 
941  CodedBitstreamUnit *unit)
942 {
944 
945  av_assert0(!unit->content && !unit->content_ref);
946 
948  if (!desc)
949  return AVERROR(ENOSYS);
950 
951  unit->content_ref = cbs_alloc_content(desc);
952  if (!unit->content_ref)
953  return AVERROR(ENOMEM);
954  unit->content = unit->content_ref;
955 
956  return 0;
957 }
958 
959 static int cbs_clone_noncomplex_unit_content(void **clonep,
960  const CodedBitstreamUnit *unit,
962 {
963  const uint8_t *src;
964  uint8_t *copy;
965  int err, i;
966 
967  av_assert0(unit->content);
968  src = unit->content;
969 
971  if (!copy)
972  return AVERROR(ENOMEM);
973  memcpy(copy, src, desc->content_size);
974  for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
975  void **ptr = (void**)(copy + desc->type.ref.offsets[i]);
976  /* Zero all the AVBufferRefs as they are owned by src. */
977  *(ptr + 1) = NULL;
978  }
979 
980  for (i = 0; i < desc->type.ref.nb_offsets; i++) {
981  const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->type.ref.offsets[i]);
982  const AVBufferRef *src_buf = *(AVBufferRef**)(src_ptr + 1);
983  uint8_t **copy_ptr = (uint8_t**)(copy + desc->type.ref.offsets[i]);
984  AVBufferRef **copy_buf = (AVBufferRef**)(copy_ptr + 1);
985 
986  if (!*src_ptr) {
987  av_assert0(!src_buf);
988  continue;
989  }
990  if (!src_buf) {
991  // We can't handle a non-refcounted pointer here - we don't
992  // have enough information to handle whatever structure lies
993  // at the other end of it.
994  err = AVERROR(EINVAL);
995  goto fail;
996  }
997 
998  *copy_buf = av_buffer_ref(src_buf);
999  if (!*copy_buf) {
1000  err = AVERROR(ENOMEM);
1001  goto fail;
1002  }
1003  }
1004  *clonep = copy;
1005 
1006  return 0;
1007 
1008 fail:
1010  return err;
1011 }
1012 
1013 /*
1014  * On success, unit->content and unit->content_ref are updated with
1015  * the new content; unit is untouched on failure.
1016  * Any old content_ref is simply overwritten and not freed.
1017  */
1019  CodedBitstreamUnit *unit)
1020 {
1022  void *new_content;
1023  int err;
1024 
1025  desc = cbs_find_unit_type_desc(ctx, unit);
1026  if (!desc)
1027  return AVERROR(ENOSYS);
1028 
1029  switch (desc->content_type) {
1031  err = cbs_clone_noncomplex_unit_content(&new_content, unit, desc);
1032  break;
1033 
1035  if (!desc->type.complex.content_clone)
1036  return AVERROR_PATCHWELCOME;
1037  err = desc->type.complex.content_clone(&new_content, unit);
1038  break;
1039 
1040  default:
1041  av_assert0(0 && "Invalid content type.");
1042  }
1043 
1044  if (err < 0)
1045  return err;
1046 
1047  unit->content_ref = new_content;
1048  unit->content = new_content;
1049  return 0;
1050 }
1051 
1053  CodedBitstreamUnit *unit)
1054 {
1055  av_assert0(unit->content);
1056  if (unit->content_ref)
1057  return 0;
1058  return cbs_clone_unit_content(ctx, unit);
1059 }
1060 
1062  CodedBitstreamUnit *unit)
1063 {
1064  void *ref = unit->content_ref;
1065  int err;
1066 
1067  av_assert0(unit->content);
1068  if (ref && av_refstruct_exclusive(ref))
1069  return 0;
1070 
1071  err = cbs_clone_unit_content(ctx, unit);
1072  if (err < 0)
1073  return err;
1075  return 0;
1076 }
1077 
1079  CodedBitstreamFragment *frag,
1080  enum AVDiscard skip,
1081  int flags)
1082 {
1083  if (!ctx->codec->discarded_unit)
1084  return;
1085 
1086  for (int i = frag->nb_units - 1; i >= 0; i--) {
1087  if (ctx->codec->discarded_unit(ctx, &frag->units[i], skip)) {
1088  // discard all units
1089  if (!(flags & DISCARD_FLAG_KEEP_NON_VCL)) {
1090  CBS_FUNC(fragment_free)(frag);
1091  return;
1092  }
1093 
1094  CBS_FUNC(delete_unit)(frag, i);
1095  }
1096  }
1097 }
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:1061
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:877
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:656
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:867
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:519
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:1078
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:665
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:691
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:612
fail
#define fail()
Definition: checkasm.h:196
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:931
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:940
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:800
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:830
bits
uint8_t bits
Definition: vp3data.h:128
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:647
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:904
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:482
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
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:959
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:346
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:417
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:1052
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:508
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:762
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:363
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:579
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:734
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:893
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:1018
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:515
read
int CBS_FUNC() read(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVBufferRef *buf, 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
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:700
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:453
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:89
AVDiscard
AVDiscard
Definition: defs.h:220
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_read_data
static int cbs_read_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVBufferRef *buf, const uint8_t *data, size_t size, int header)
Definition: cbs.c:262
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