FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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 "config.h"
22 
23 #include "libavutil/avassert.h"
24 #include "libavutil/buffer.h"
25 #include "libavutil/common.h"
26 
27 #include "cbs.h"
28 #include "cbs_internal.h"
29 
30 
32 #if CONFIG_CBS_AV1
34 #endif
35 #if CONFIG_CBS_H264
37 #endif
38 #if CONFIG_CBS_H265
40 #endif
41 #if CONFIG_CBS_JPEG
43 #endif
44 #if CONFIG_CBS_MPEG2
46 #endif
47 #if CONFIG_CBS_VP9
49 #endif
50 };
51 
53 #if CONFIG_CBS_AV1
55 #endif
56 #if CONFIG_CBS_H264
58 #endif
59 #if CONFIG_CBS_H265
61 #endif
62 #if CONFIG_CBS_JPEG
64 #endif
65 #if CONFIG_CBS_MPEG2
67 #endif
68 #if CONFIG_CBS_VP9
70 #endif
72 };
73 
75  enum AVCodecID codec_id, void *log_ctx)
76 {
78  const CodedBitstreamType *type;
79  int i;
80 
81  type = NULL;
82  for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
83  if (cbs_type_table[i]->codec_id == codec_id) {
84  type = cbs_type_table[i];
85  break;
86  }
87  }
88  if (!type)
89  return AVERROR(EINVAL);
90 
91  ctx = av_mallocz(sizeof(*ctx));
92  if (!ctx)
93  return AVERROR(ENOMEM);
94 
95  ctx->log_ctx = log_ctx;
96  ctx->codec = type;
97 
99  if (!ctx->priv_data) {
100  av_freep(&ctx);
101  return AVERROR(ENOMEM);
102  }
103 
104  ctx->decompose_unit_types = NULL;
105 
106  ctx->trace_enable = 0;
107  ctx->trace_level = AV_LOG_TRACE;
108 
109  *ctx_ptr = ctx;
110  return 0;
111 }
112 
114 {
115  CodedBitstreamContext *ctx = *ctx_ptr;
116 
117  if (!ctx)
118  return;
119 
120  if (ctx->codec && ctx->codec->close)
121  ctx->codec->close(ctx);
122 
123  av_freep(&ctx->priv_data);
124  av_freep(ctx_ptr);
125 }
126 
128  CodedBitstreamUnit *unit)
129 {
131  unit->content = NULL;
132 
133  av_buffer_unref(&unit->data_ref);
134  unit->data = NULL;
135  unit->data_size = 0;
136  unit->data_bit_padding = 0;
137 }
138 
141 {
142  int i;
143 
144  for (i = 0; i < frag->nb_units; i++)
145  cbs_unit_uninit(ctx, &frag->units[i]);
146  av_freep(&frag->units);
147  frag->nb_units = 0;
148 
149  av_buffer_unref(&frag->data_ref);
150  frag->data = NULL;
151  frag->data_size = 0;
152  frag->data_bit_padding = 0;
153 }
154 
157 {
158  int err, i, j;
159 
160  for (i = 0; i < frag->nb_units; i++) {
161  CodedBitstreamUnit *unit = &frag->units[i];
162 
163  if (ctx->decompose_unit_types) {
164  for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
165  if (ctx->decompose_unit_types[j] == unit->type)
166  break;
167  }
168  if (j >= ctx->nb_decompose_unit_types)
169  continue;
170  }
171 
173  unit->content = NULL;
174 
175  av_assert0(unit->data && unit->data_ref);
176 
177  err = ctx->codec->read_unit(ctx, unit);
178  if (err == AVERROR(ENOSYS)) {
180  "Decomposition unimplemented for unit %d "
181  "(type %"PRIu32").\n", i, unit->type);
182  } else if (err < 0) {
183  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
184  "(type %"PRIu32").\n", i, unit->type);
185  return err;
186  }
187  }
188 
189  return 0;
190 }
191 
194  const uint8_t *data, size_t size)
195 {
196  av_assert0(!frag->data && !frag->data_ref);
197 
198  frag->data_ref =
200  if (!frag->data_ref)
201  return AVERROR(ENOMEM);
202 
203  frag->data = frag->data_ref->data;
204  frag->data_size = size;
205 
206  memcpy(frag->data, data, size);
207  memset(frag->data + size, 0,
209 
210  return 0;
211 }
212 
215  const AVCodecParameters *par)
216 {
217  int err;
218 
219  memset(frag, 0, sizeof(*frag));
220 
221  err = cbs_fill_fragment_data(ctx, frag, par->extradata,
222  par->extradata_size);
223  if (err < 0)
224  return err;
225 
226  err = ctx->codec->split_fragment(ctx, frag, 1);
227  if (err < 0)
228  return err;
229 
230  return cbs_read_fragment_content(ctx, frag);
231 }
232 
235  const AVPacket *pkt)
236 {
237  int err;
238 
239  memset(frag, 0, sizeof(*frag));
240 
241  if (pkt->buf) {
242  frag->data_ref = av_buffer_ref(pkt->buf);
243  if (!frag->data_ref)
244  return AVERROR(ENOMEM);
245 
246  frag->data = pkt->data;
247  frag->data_size = pkt->size;
248 
249  } else {
250  err = cbs_fill_fragment_data(ctx, frag, pkt->data, pkt->size);
251  if (err < 0)
252  return err;
253  }
254 
255  err = ctx->codec->split_fragment(ctx, frag, 0);
256  if (err < 0)
257  return err;
258 
259  return cbs_read_fragment_content(ctx, frag);
260 }
261 
264  const uint8_t *data, size_t size)
265 {
266  int err;
267 
268  memset(frag, 0, sizeof(*frag));
269 
270  err = cbs_fill_fragment_data(ctx, frag, data, size);
271  if (err < 0)
272  return err;
273 
274  err = ctx->codec->split_fragment(ctx, frag, 0);
275  if (err < 0)
276  return err;
277 
278  return cbs_read_fragment_content(ctx, frag);
279 }
280 
281 
284 {
285  int err, i;
286 
287  for (i = 0; i < frag->nb_units; i++) {
288  CodedBitstreamUnit *unit = &frag->units[i];
289 
290  if (!unit->content)
291  continue;
292 
293  av_buffer_unref(&unit->data_ref);
294  unit->data = NULL;
295 
296  err = ctx->codec->write_unit(ctx, unit);
297  if (err < 0) {
298  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
299  "(type %"PRIu32").\n", i, unit->type);
300  return err;
301  }
302  av_assert0(unit->data && unit->data_ref);
303  }
304 
305  av_buffer_unref(&frag->data_ref);
306  frag->data = NULL;
307 
308  err = ctx->codec->assemble_fragment(ctx, frag);
309  if (err < 0) {
310  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
311  return err;
312  }
313  av_assert0(frag->data && frag->data_ref);
314 
315  return 0;
316 }
317 
319  AVCodecParameters *par,
321 {
322  int err;
323 
324  err = ff_cbs_write_fragment_data(ctx, frag);
325  if (err < 0)
326  return err;
327 
328  av_freep(&par->extradata);
329 
330  par->extradata = av_malloc(frag->data_size +
332  if (!par->extradata)
333  return AVERROR(ENOMEM);
334 
335  memcpy(par->extradata, frag->data, frag->data_size);
336  memset(par->extradata + frag->data_size, 0,
338  par->extradata_size = frag->data_size;
339 
340  return 0;
341 }
342 
344  AVPacket *pkt,
346 {
347  AVBufferRef *buf;
348  int err;
349 
350  err = ff_cbs_write_fragment_data(ctx, frag);
351  if (err < 0)
352  return err;
353 
354  buf = av_buffer_ref(frag->data_ref);
355  if (!buf)
356  return AVERROR(ENOMEM);
357 
358  av_init_packet(pkt);
359  pkt->buf = buf;
360  pkt->data = frag->data;
361  pkt->size = frag->data_size;
362 
363  return 0;
364 }
365 
366 
368  const char *name)
369 {
370  if (!ctx->trace_enable)
371  return;
372 
373  av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
374 }
375 
377  const char *str, const int *subscripts,
378  const char *bits, int64_t value)
379 {
380  char name[256];
381  size_t name_len, bits_len;
382  int pad, subs, i, j, k, n;
383 
384  if (!ctx->trace_enable)
385  return;
386 
387  av_assert0(value >= INT_MIN && value <= UINT32_MAX);
388 
389  subs = subscripts ? subscripts[0] : 0;
390  n = 0;
391  for (i = j = 0; str[i];) {
392  if (str[i] == '[') {
393  if (n < subs) {
394  ++n;
395  k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
396  av_assert0(k > 0 && j + k < sizeof(name));
397  j += k;
398  for (++i; str[i] && str[i] != ']'; i++);
399  av_assert0(str[i] == ']');
400  } else {
401  while (str[i] && str[i] != ']')
402  name[j++] = str[i++];
403  av_assert0(str[i] == ']');
404  }
405  } else {
406  av_assert0(j + 1 < sizeof(name));
407  name[j++] = str[i++];
408  }
409  }
410  av_assert0(j + 1 < sizeof(name));
411  name[j] = 0;
412  av_assert0(n == subs);
413 
414  name_len = strlen(name);
415  bits_len = strlen(bits);
416 
417  if (name_len + bits_len > 60)
418  pad = bits_len + 2;
419  else
420  pad = 61 - name_len;
421 
422  av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
423  position, name, pad, bits, value);
424 }
425 
427  int width, const char *name,
428  const int *subscripts, uint32_t *write_to,
429  uint32_t range_min, uint32_t range_max)
430 {
431  uint32_t value;
432  int position;
433 
434  av_assert0(width > 0 && width <= 32);
435 
436  if (get_bits_left(gbc) < width) {
437  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
438  "%s: bitstream ended.\n", name);
439  return AVERROR_INVALIDDATA;
440  }
441 
442  if (ctx->trace_enable)
443  position = get_bits_count(gbc);
444 
445  value = get_bits_long(gbc, width);
446 
447  if (ctx->trace_enable) {
448  char bits[33];
449  int i;
450  for (i = 0; i < width; i++)
451  bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
452  bits[i] = 0;
453 
454  ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
455  bits, value);
456  }
457 
458  if (value < range_min || value > range_max) {
459  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
460  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
461  name, value, range_min, range_max);
462  return AVERROR_INVALIDDATA;
463  }
464 
465  *write_to = value;
466  return 0;
467 }
468 
470  int width, const char *name,
471  const int *subscripts, uint32_t value,
472  uint32_t range_min, uint32_t range_max)
473 {
474  av_assert0(width > 0 && width <= 32);
475 
476  if (value < range_min || value > range_max) {
477  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
478  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
479  name, value, range_min, range_max);
480  return AVERROR_INVALIDDATA;
481  }
482 
483  if (put_bits_left(pbc) < width)
484  return AVERROR(ENOSPC);
485 
486  if (ctx->trace_enable) {
487  char bits[33];
488  int i;
489  for (i = 0; i < width; i++)
490  bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
491  bits[i] = 0;
492 
494  name, subscripts, bits, value);
495  }
496 
497  if (width < 32)
498  put_bits(pbc, width, value);
499  else
500  put_bits32(pbc, value);
501 
502  return 0;
503 }
504 
505 
507  CodedBitstreamUnit *unit,
508  size_t size,
509  void (*free)(void *opaque, uint8_t *data))
510 {
511  av_assert0(!unit->content && !unit->content_ref);
512 
513  unit->content = av_mallocz(size);
514  if (!unit->content)
515  return AVERROR(ENOMEM);
516 
517  unit->content_ref = av_buffer_create(unit->content, size,
518  free, ctx, 0);
519  if (!unit->content_ref) {
520  av_freep(&unit->content);
521  return AVERROR(ENOMEM);
522  }
523 
524  return 0;
525 }
526 
528  CodedBitstreamUnit *unit,
529  size_t size)
530 {
531  av_assert0(!unit->data && !unit->data_ref);
532 
534  if (!unit->data_ref)
535  return AVERROR(ENOMEM);
536 
537  unit->data = unit->data_ref->data;
538  unit->data_size = size;
539 
540  memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
541 
542  return 0;
543 }
544 
547  int position)
548 {
549  CodedBitstreamUnit *units;
550 
551  units = av_malloc_array(frag->nb_units + 1, sizeof(*units));
552  if (!units)
553  return AVERROR(ENOMEM);
554 
555  if (position > 0)
556  memcpy(units, frag->units, position * sizeof(*units));
557  if (position < frag->nb_units)
558  memcpy(units + position + 1, frag->units + position,
559  (frag->nb_units - position) * sizeof(*units));
560 
561  memset(units + position, 0, sizeof(*units));
562 
563  av_freep(&frag->units);
564  frag->units = units;
565  ++frag->nb_units;
566 
567  return 0;
568 }
569 
572  int position,
574  void *content,
575  AVBufferRef *content_buf)
576 {
577  CodedBitstreamUnit *unit;
578  AVBufferRef *content_ref;
579  int err;
580 
581  if (position == -1)
582  position = frag->nb_units;
583  av_assert0(position >= 0 && position <= frag->nb_units);
584 
585  if (content_buf) {
586  content_ref = av_buffer_ref(content_buf);
587  if (!content_ref)
588  return AVERROR(ENOMEM);
589  } else {
590  content_ref = NULL;
591  }
592 
593  err = cbs_insert_unit(ctx, frag, position);
594  if (err < 0) {
595  av_buffer_unref(&content_ref);
596  return err;
597  }
598 
599  unit = &frag->units[position];
600  unit->type = type;
601  unit->content = content;
602  unit->content_ref = content_ref;
603 
604  return 0;
605 }
606 
609  int position,
611  uint8_t *data, size_t data_size,
612  AVBufferRef *data_buf)
613 {
614  CodedBitstreamUnit *unit;
615  AVBufferRef *data_ref;
616  int err;
617 
618  if (position == -1)
619  position = frag->nb_units;
620  av_assert0(position >= 0 && position <= frag->nb_units);
621 
622  if (data_buf)
623  data_ref = av_buffer_ref(data_buf);
624  else
625  data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
626  if (!data_ref)
627  return AVERROR(ENOMEM);
628 
629  err = cbs_insert_unit(ctx, frag, position);
630  if (err < 0) {
631  av_buffer_unref(&data_ref);
632  return err;
633  }
634 
635  unit = &frag->units[position];
636  unit->type = type;
637  unit->data = data;
638  unit->data_size = data_size;
639  unit->data_ref = data_ref;
640 
641  return 0;
642 }
643 
646  int position)
647 {
648  if (position < 0 || position >= frag->nb_units)
649  return AVERROR(EINVAL);
650 
651  cbs_unit_uninit(ctx, &frag->units[position]);
652 
653  --frag->nb_units;
654 
655  if (frag->nb_units == 0) {
656  av_freep(&frag->units);
657 
658  } else {
659  memmove(frag->units + position,
660  frag->units + position + 1,
661  (frag->nb_units - position) * sizeof(*frag->units));
662 
663  // Don't bother reallocating the unit array.
664  }
665 
666  return 0;
667 }
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:250
#define NULL
Definition: coverity.c:32
int nb_units
Number of units in this fragment.
Definition: cbs.h:147
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
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:125
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:208
int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag)
Write the bitstream of a fragment to a packet.
Definition: cbs.c:343
static void cbs_unit_uninit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:127
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:74
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:68
int size
Definition: avcodec.h:1446
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
Definition: cbs.c:506
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, 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:570
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
Definition: cbs.c:367
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
static AVPacket pkt
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3892
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:469
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int trace_enable
Enable trace output during read/write operations.
Definition: cbs.h:197
uint8_t
#define av_malloc(s)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:202
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:43
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:426
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:86
static const CodedBitstreamType * cbs_type_table[]
Definition: cbs.c:31
void(* close)(CodedBitstreamContext *ctx)
Definition: cbs_internal.h:57
static int cbs_read_fragment_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs.c:155
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:233
uint8_t * data
Definition: avcodec.h:1445
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
int ff_cbs_alloc_unit_data(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size)
Allocate a new internal data buffer of the given size in the unit.
Definition: cbs.c:527
Coded bitstream unit structure.
Definition: cbs.h:64
ptrdiff_t size
Definition: opengl_enc.c:101
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:101
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units.
Definition: cbs.h:153
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:75
int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Insert a new unit into a fragment with the given data bitstream.
Definition: cbs.c:607
#define av_log(a,...)
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:129
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:814
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
Definition: cbs.c:139
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:93
#define AVERROR(e)
Definition: error.h:43
int(* split_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition: cbs_internal.h:38
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1428
simple assert() macros that are a bit more flexible than ISO C assert().
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:28
int(* read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_internal.h:44
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:133
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
int extradata_size
Size of the extradata content in bytes.
Definition: avcodec.h:3918
const CodedBitstreamType ff_cbs_type_mpeg2
Definition: cbs_mpeg2.c:395
void * log_ctx
Logging context to be passed to all av_log() calls associated with this context.
Definition: cbs.h:164
const CodedBitstreamType ff_cbs_type_h264
Definition: cbs_h2645.c:1498
const CodedBitstreamType ff_cbs_type_av1
Definition: cbs_av1.c:1317
int(* assemble_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs_internal.h:53
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:318
#define width
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
AVFormatContext * ctx
Definition: movenc.c:48
int ff_cbs_delete_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position)
Delete a unit from a fragment and free all memory it uses.
Definition: cbs.c:644
int n
Definition: avisynth_c.h:684
enum AVCodecID codec_id
Definition: vaapi_decode.c:364
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:122
#define FF_ARRAY_ELEMS(a)
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:282
int nb_decompose_unit_types
Length of the decompose_unit_types array.
Definition: cbs.h:192
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:67
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:116
const CodedBitstreamType ff_cbs_type_jpeg
Definition: cbs_jpeg.c:509
uint8_t * data
The data buffer.
Definition: buffer.h:89
int trace_level
Log level to use for trace output.
Definition: cbs.h:203
void * buf
Definition: avisynth_c.h:690
GLint GLenum type
Definition: opengl_enc.c:105
static int cbs_fill_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const uint8_t *data, size_t size)
Definition: cbs.c:192
Context structure for coded bitstream operations.
Definition: cbs.h:159
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
Definition: cbs.h:106
refcounted data buffer API
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:113
#define snprintf
Definition: snprintf.h:34
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:531
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:213
void * priv_data
Internal codec-specific data.
Definition: cbs.h:180
A reference to a data buffer.
Definition: buffer.h:81
common internal and external API header
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:92
static int cbs_insert_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position)
Definition: cbs.c:545
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
CodedBitstreamUnitType * decompose_unit_types
Array of unit types which should be decomposed when reading.
Definition: cbs.h:188
const CodedBitstreamType ff_cbs_type_h265
Definition: cbs_h2645.c:1511
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
enum AVCodecID ff_cbs_all_codec_ids[]
Table of all supported codec IDs.
Definition: cbs.c:52
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:782
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3914
#define av_freep(p)
#define AV_CODEC_ID_H265
Definition: avcodec.h:393
const struct CodedBitstreamType * codec
Internal codec-specific hooks.
Definition: cbs.h:169
#define av_malloc_array(a, b)
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:262
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:139
const CodedBitstreamType ff_cbs_type_vp9
Definition: cbs_vp9.c:681
This structure stores compressed data.
Definition: avcodec.h:1422
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *str, const int *subscripts, const char *bits, int64_t value)
Definition: cbs.c:376
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition: cbs.h:80
const char * name
Definition: opengl_enc.c:103
int(* write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_internal.h:48