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 "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"): %s.\n",
235  i, unit->type, av_err2str(err));
236  return err;
237  }
238  }
239 
240  return 0;
241 }
242 
244  const uint8_t *data, size_t size)
245 {
246  av_assert0(!frag->data && !frag->data_ref);
247 
248  frag->data_ref =
250  if (!frag->data_ref)
251  return AVERROR(ENOMEM);
252 
253  frag->data = frag->data_ref->data;
254  frag->data_size = size;
255 
256  memcpy(frag->data, data, size);
257  memset(frag->data + size, 0,
259 
260  return 0;
261 }
262 
265  const AVBufferRef *buf,
266  const uint8_t *data, size_t size,
267  int header)
268 {
269  int err;
270 
271  if (buf) {
272  frag->data_ref = av_buffer_ref(buf);
273  if (!frag->data_ref)
274  return AVERROR(ENOMEM);
275 
276  frag->data = (uint8_t *)data;
277  frag->data_size = size;
278 
279  } else {
280  err = cbs_fill_fragment_data(frag, data, size);
281  if (err < 0)
282  return err;
283  }
284 
285  err = ctx->codec->split_fragment(ctx, frag, header);
286  if (err < 0)
287  return err;
288 
289  return cbs_read_fragment_content(ctx, frag);
290 }
291 
294  const AVCodecParameters *par)
295 {
296  return cbs_read_data(ctx, frag, NULL,
297  par->extradata,
298  par->extradata_size, 1);
299 }
300 
303  const AVCodecContext *avctx)
304 {
305  return cbs_read_data(ctx, frag, NULL,
306  avctx->extradata,
307  avctx->extradata_size, 1);
308 }
309 
312  const AVPacket *pkt)
313 {
314  return cbs_read_data(ctx, frag, pkt->buf,
315  pkt->data, pkt->size, 0);
316 }
317 
320  const AVPacket *pkt)
321 {
322  size_t side_data_size;
323  const uint8_t *side_data =
325  &side_data_size);
326 
327  return cbs_read_data(ctx, frag, NULL,
328  side_data, side_data_size, 1);
329 }
330 
333  const AVBufferRef *buf,
334  const uint8_t *data, size_t size)
335 {
336  return cbs_read_data(ctx, frag, buf,
337  data, size, 0);
338 }
339 #endif
340 
341 #if CBS_WRITE
342 /**
343  * Allocate a new internal data buffer of the given size in the unit.
344  *
345  * The data buffer will have input padding.
346  */
348  size_t size)
349 {
350  av_assert0(!unit->data && !unit->data_ref);
351 
353  if (!unit->data_ref)
354  return AVERROR(ENOMEM);
355 
356  unit->data = unit->data_ref->data;
357  unit->data_size = size;
358 
359  memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
360 
361  return 0;
362 }
363 
365  CodedBitstreamUnit *unit)
366 {
367  PutBitContext pbc;
368  int ret;
369 
370  if (!ctx->write_buffer) {
371  // Initial write buffer size is 1MB.
372  ctx->write_buffer_size = 1024 * 1024;
373 
374  reallocate_and_try_again:
375  ret = av_reallocp(&ctx->write_buffer, ctx->write_buffer_size);
376  if (ret < 0) {
377  av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
378  "sufficiently large write buffer (last attempt "
379  "%"SIZE_SPECIFIER" bytes).\n", ctx->write_buffer_size);
380  return ret;
381  }
382  }
383 
384  init_put_bits(&pbc, ctx->write_buffer, ctx->write_buffer_size);
385 
386  ret = ctx->codec->write_unit(ctx, unit, &pbc);
387  if (ret < 0) {
388  if (ret == AVERROR(ENOSPC)) {
389  // Overflow.
390  if (ctx->write_buffer_size == INT_MAX / 8)
391  return AVERROR(ENOMEM);
392  ctx->write_buffer_size = FFMIN(2 * ctx->write_buffer_size, INT_MAX / 8);
393  goto reallocate_and_try_again;
394  }
395  // Write failed for some other reason.
396  return ret;
397  }
398 
399  // Overflow but we didn't notice.
400  av_assert0(put_bits_count(&pbc) <= 8 * ctx->write_buffer_size);
401 
402  if (put_bits_count(&pbc) % 8)
403  unit->data_bit_padding = 8 - put_bits_count(&pbc) % 8;
404  else
405  unit->data_bit_padding = 0;
406 
407  flush_put_bits(&pbc);
408 
410  if (ret < 0)
411  return ret;
412 
413  memcpy(unit->data, ctx->write_buffer, unit->data_size);
414 
415  return 0;
416 }
417 
420 {
421  int err, i;
422 
423  for (i = 0; i < frag->nb_units; i++) {
424  CodedBitstreamUnit *unit = &frag->units[i];
425 
426  if (!unit->content)
427  continue;
428 
429  av_buffer_unref(&unit->data_ref);
430  unit->data = NULL;
431 
432  err = cbs_write_unit_data(ctx, unit);
433  if (err < 0) {
434  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
435  "(type %"PRIu32").\n", i, unit->type);
436  return err;
437  }
438  av_assert0(unit->data && unit->data_ref);
439  }
440 
441  av_buffer_unref(&frag->data_ref);
442  frag->data = NULL;
443 
444  err = ctx->codec->assemble_fragment(ctx, frag);
445  if (err < 0) {
446  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
447  return err;
448  }
449  av_assert0(frag->data && frag->data_ref);
450 
451  return 0;
452 }
453 
455  AVCodecParameters *par,
457 {
458  int err;
459 
460  err = CBS_FUNC(write_fragment_data)(ctx, frag);
461  if (err < 0)
462  return err;
463 
464  av_freep(&par->extradata);
465  par->extradata_size = 0;
466 
467  if (!frag->data_size)
468  return 0;
469 
470  par->extradata = av_malloc(frag->data_size +
472  if (!par->extradata)
473  return AVERROR(ENOMEM);
474 
475  memcpy(par->extradata, frag->data, frag->data_size);
476  memset(par->extradata + frag->data_size, 0,
478  par->extradata_size = frag->data_size;
479 
480  return 0;
481 }
482 
484  AVPacket *pkt,
486 {
487  AVBufferRef *buf;
488  int err;
489 
490  err = CBS_FUNC(write_fragment_data)(ctx, frag);
491  if (err < 0)
492  return err;
493 
494  buf = av_buffer_ref(frag->data_ref);
495  if (!buf)
496  return AVERROR(ENOMEM);
497 
499 
500  pkt->buf = buf;
501  pkt->data = frag->data;
502  pkt->size = frag->data_size;
503 
504  return 0;
505 }
506 #endif
507 
508 
510  const char *name)
511 {
512 #if CBS_TRACE
513  if (!ctx->trace_enable)
514  return;
515 
516  av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
517 #endif
518 }
519 
520 void CBS_FUNC(trace_read_log)(void *trace_context,
521  GetBitContext *gbc, int length,
522  const char *str, const int *subscripts,
523  int64_t value)
524 {
525 #if CBS_TRACE
526  CodedBitstreamContext *ctx = trace_context;
527  char name[256];
528  char bits[256];
529  size_t name_len, bits_len;
530  int pad, subs, i, j, k, n;
531  int position;
532 
533  av_assert0(value >= INT_MIN && value <= UINT32_MAX);
534 
535  position = get_bits_count(gbc);
536 
537  av_assert0(length < 256);
538  for (i = 0; i < length; i++)
539  bits[i] = get_bits1(gbc) ? '1' : '0';
540  bits[length] = 0;
541 
542  subs = subscripts ? subscripts[0] : 0;
543  n = 0;
544  for (i = j = 0; str[i];) {
545  if (str[i] == '[') {
546  if (n < subs) {
547  ++n;
548  k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
549  av_assert0(k > 0 && j + k < sizeof(name));
550  j += k;
551  for (++i; str[i] && str[i] != ']'; i++);
552  av_assert0(str[i] == ']');
553  } else {
554  while (str[i] && str[i] != ']')
555  name[j++] = str[i++];
556  av_assert0(str[i] == ']');
557  }
558  } else {
559  av_assert0(j + 1 < sizeof(name));
560  name[j++] = str[i++];
561  }
562  }
563  av_assert0(j + 1 < sizeof(name));
564  name[j] = 0;
565  av_assert0(n == subs);
566 
567  name_len = strlen(name);
568  bits_len = length;
569 
570  if (name_len + bits_len > 60)
571  pad = bits_len + 2;
572  else
573  pad = 61 - name_len;
574 
575  av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
576  position, name, pad, bits, value);
577 #endif
578 }
579 
580 void CBS_FUNC(trace_write_log)(void *trace_context,
581  PutBitContext *pbc, int length,
582  const char *str, const int *subscripts,
583  int64_t value)
584 {
585 #if CBS_TRACE
586  CodedBitstreamContext *ctx = trace_context;
587 
588  // Ensure that the syntax element is written to the output buffer,
589  // make a GetBitContext pointed at the start position, then call the
590  // read log function which can read the bits back to log them.
591 
592  GetBitContext gbc;
593  int position;
594 
595  if (length > 0) {
597  flush = *pbc;
599  }
600 
601  position = put_bits_count(pbc);
602  av_assert0(position >= length);
603 
604  init_get_bits(&gbc, pbc->buf, position);
605 
606  skip_bits_long(&gbc, position - length);
607 
608  CBS_FUNC(trace_read_log)(ctx, &gbc, length, str, subscripts, value);
609 #endif
610 }
611 
612 #if CBS_READ
614  GetBitContext *gbc,
615  int width, const char *name,
616  const int *subscripts,
617  uint32_t *write_to,
618  uint32_t range_min,
619  uint32_t range_max)
620 {
621  uint32_t value;
622 
624 
625  av_assert0(width > 0 && width <= 32);
626 
627  if (get_bits_left(gbc) < width) {
628  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
629  "%s: bitstream ended.\n", name);
630  return AVERROR_INVALIDDATA;
631  }
632 
633  value = get_bits_long(gbc, width);
634 
636 
637  if (value < range_min || value > range_max) {
638  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
639  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
640  name, value, range_min, range_max);
641  return AVERROR_INVALIDDATA;
642  }
643 
644  *write_to = value;
645  return 0;
646 }
647 
649  int width, const char *name,
650  const int *subscripts, uint32_t *write_to,
651  uint32_t range_min, uint32_t range_max)
652 {
653  return cbs_read_unsigned(ctx, gbc, width, name, subscripts,
654  write_to, range_min, range_max);
655 }
656 
658  int width, const char *name, uint32_t *write_to)
659 {
660  return cbs_read_unsigned(ctx, gbc, width, name, NULL,
661  write_to, 0, UINT32_MAX);
662 }
663 #endif
664 
665 #if CBS_WRITE
667  int width, const char *name,
668  const int *subscripts, uint32_t value,
669  uint32_t range_min, uint32_t range_max)
670 {
672 
673  av_assert0(width > 0 && width <= 32);
674 
675  if (value < range_min || value > range_max) {
676  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
677  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
678  name, value, range_min, range_max);
679  return AVERROR_INVALIDDATA;
680  }
681 
682  if (put_bits_left(pbc) < width)
683  return AVERROR(ENOSPC);
684 
685  put_bits63(pbc, width, value);
686 
688 
689  return 0;
690 }
691 
693  int width, const char *name, uint32_t value)
694 {
695  return CBS_FUNC(write_unsigned)(ctx, pbc, width, name, NULL,
696  value, 0, MAX_UINT_BITS(width));
697 }
698 #endif
699 
700 #if CBS_READ
702  int width, const char *name,
703  const int *subscripts, int32_t *write_to,
704  int32_t range_min, int32_t range_max)
705 {
706  int32_t value;
707 
709 
710  av_assert0(width > 0 && width <= 32);
711 
712  if (get_bits_left(gbc) < width) {
713  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
714  "%s: bitstream ended.\n", name);
715  return AVERROR_INVALIDDATA;
716  }
717 
718  value = get_sbits_long(gbc, width);
719 
721 
722  if (value < range_min || value > range_max) {
723  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
724  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
725  name, value, range_min, range_max);
726  return AVERROR_INVALIDDATA;
727  }
728 
729  *write_to = value;
730  return 0;
731 }
732 #endif
733 
734 #if CBS_WRITE
736  int width, const char *name,
737  const int *subscripts, int32_t value,
738  int32_t range_min, int32_t range_max)
739 {
741 
742  av_assert0(width > 0 && width <= 32);
743 
744  if (value < range_min || value > range_max) {
745  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
746  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
747  name, value, range_min, range_max);
748  return AVERROR_INVALIDDATA;
749  }
750 
751  if (put_bits_left(pbc) < width)
752  return AVERROR(ENOSPC);
753 
755 
757 
758  return 0;
759 }
760 #endif
761 
762 
764  int position)
765 {
766  CodedBitstreamUnit *units;
767 
768  if (frag->nb_units < frag->nb_units_allocated) {
769  units = frag->units;
770 
771  if (position < frag->nb_units)
772  memmove(units + position + 1, units + position,
773  (frag->nb_units - position) * sizeof(*units));
774  } else {
775  units = av_malloc_array(frag->nb_units*2 + 1, sizeof(*units));
776  if (!units)
777  return AVERROR(ENOMEM);
778 
779  frag->nb_units_allocated = 2*frag->nb_units_allocated + 1;
780 
781  if (position > 0)
782  memcpy(units, frag->units, position * sizeof(*units));
783 
784  if (position < frag->nb_units)
785  memcpy(units + position + 1, frag->units + position,
786  (frag->nb_units - position) * sizeof(*units));
787 
788  av_free(frag->units);
789  frag->units = units;
790  }
791 
792  memset(units + position, 0, sizeof(*units));
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:276
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:292
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:689
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:99
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:318
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:419
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:250
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:657
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:558
cbs_fill_fragment_data
static int cbs_fill_fragment_data(CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Definition: cbs.c:243
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:520
data
const char data[16]
Definition: mxf.c:149
zero_extend
static av_const unsigned zero_extend(unsigned val, unsigned bits)
Definition: mathops.h:150
discard_units
void CBS_FUNC() discard_units(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, enum AVDiscard skip, int flags)
Discard units according 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:512
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:666
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:692
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:613
fail
#define fail()
Definition: checkasm.h:200
GetBitContext
Definition: get_bits.h:109
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:135
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
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
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:648
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:344
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:541
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:483
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:386
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: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:301
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:347
AVPacket::size
int size
Definition: packet.h:559
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:418
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
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:509
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:763
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:364
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:90
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:310
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:580
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:735
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: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:331
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:701
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:153
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:535
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:454
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:223
get_sbits_long
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition: get_bits.h:469
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:1292
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:383
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:263
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