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