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_H264
34 #endif
35 #if CONFIG_CBS_H265
37 #endif
38 #if CONFIG_CBS_MPEG2
40 #endif
41 #if CONFIG_CBS_VP9
43 #endif
44 };
45 
47 #if CONFIG_CBS_H264
49 #endif
50 #if CONFIG_CBS_H265
52 #endif
53 #if CONFIG_CBS_MPEG2
55 #endif
56 #if CONFIG_CBS_VP9
58 #endif
60 };
61 
63  enum AVCodecID codec_id, void *log_ctx)
64 {
66  const CodedBitstreamType *type;
67  int i;
68 
69  type = NULL;
70  for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
71  if (cbs_type_table[i]->codec_id == codec_id) {
72  type = cbs_type_table[i];
73  break;
74  }
75  }
76  if (!type)
77  return AVERROR(EINVAL);
78 
79  ctx = av_mallocz(sizeof(*ctx));
80  if (!ctx)
81  return AVERROR(ENOMEM);
82 
83  ctx->log_ctx = log_ctx;
84  ctx->codec = type;
85 
87  if (!ctx->priv_data) {
88  av_freep(&ctx);
89  return AVERROR(ENOMEM);
90  }
91 
93 
94  ctx->trace_enable = 0;
96 
97  *ctx_ptr = ctx;
98  return 0;
99 }
100 
102 {
103  CodedBitstreamContext *ctx = *ctx_ptr;
104 
105  if (!ctx)
106  return;
107 
108  if (ctx->codec && ctx->codec->close)
109  ctx->codec->close(ctx);
110 
111  av_freep(&ctx->priv_data);
112  av_freep(ctx_ptr);
113 }
114 
116  CodedBitstreamUnit *unit)
117 {
119  unit->content = NULL;
120 
121  av_buffer_unref(&unit->data_ref);
122  unit->data = NULL;
123  unit->data_size = 0;
124  unit->data_bit_padding = 0;
125 }
126 
129 {
130  int i;
131 
132  for (i = 0; i < frag->nb_units; i++)
133  cbs_unit_uninit(ctx, &frag->units[i]);
134  av_freep(&frag->units);
135  frag->nb_units = 0;
136 
137  av_buffer_unref(&frag->data_ref);
138  frag->data = NULL;
139  frag->data_size = 0;
140  frag->data_bit_padding = 0;
141 }
142 
145 {
146  int err, i, j;
147 
148  for (i = 0; i < frag->nb_units; i++) {
149  CodedBitstreamUnit *unit = &frag->units[i];
150 
151  if (ctx->decompose_unit_types) {
152  for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
153  if (ctx->decompose_unit_types[j] == unit->type)
154  break;
155  }
156  if (j >= ctx->nb_decompose_unit_types)
157  continue;
158  }
159 
161  unit->content = NULL;
162 
163  av_assert0(unit->data && unit->data_ref);
164 
165  err = ctx->codec->read_unit(ctx, unit);
166  if (err == AVERROR(ENOSYS)) {
168  "Decomposition unimplemented for unit %d "
169  "(type %"PRIu32").\n", i, unit->type);
170  } else if (err < 0) {
171  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
172  "(type %"PRIu32").\n", i, unit->type);
173  return err;
174  }
175  }
176 
177  return 0;
178 }
179 
182  const uint8_t *data, size_t size)
183 {
184  av_assert0(!frag->data && !frag->data_ref);
185 
186  frag->data_ref =
188  if (!frag->data_ref)
189  return AVERROR(ENOMEM);
190 
191  frag->data = frag->data_ref->data;
192  frag->data_size = size;
193 
194  memcpy(frag->data, data, size);
195  memset(frag->data + size, 0,
197 
198  return 0;
199 }
200 
203  const AVCodecParameters *par)
204 {
205  int err;
206 
207  memset(frag, 0, sizeof(*frag));
208 
209  err = cbs_fill_fragment_data(ctx, frag, par->extradata,
210  par->extradata_size);
211  if (err < 0)
212  return err;
213 
214  err = ctx->codec->split_fragment(ctx, frag, 1);
215  if (err < 0)
216  return err;
217 
218  return cbs_read_fragment_content(ctx, frag);
219 }
220 
223  const AVPacket *pkt)
224 {
225  int err;
226 
227  memset(frag, 0, sizeof(*frag));
228 
229  if (pkt->buf) {
230  frag->data_ref = av_buffer_ref(pkt->buf);
231  if (!frag->data_ref)
232  return AVERROR(ENOMEM);
233 
234  frag->data = pkt->data;
235  frag->data_size = pkt->size;
236 
237  } else {
238  err = cbs_fill_fragment_data(ctx, frag, pkt->data, pkt->size);
239  if (err < 0)
240  return err;
241  }
242 
243  err = ctx->codec->split_fragment(ctx, frag, 0);
244  if (err < 0)
245  return err;
246 
247  return cbs_read_fragment_content(ctx, frag);
248 }
249 
252  const uint8_t *data, size_t size)
253 {
254  int err;
255 
256  memset(frag, 0, sizeof(*frag));
257 
258  err = cbs_fill_fragment_data(ctx, frag, data, size);
259  if (err < 0)
260  return err;
261 
262  err = ctx->codec->split_fragment(ctx, frag, 0);
263  if (err < 0)
264  return err;
265 
266  return cbs_read_fragment_content(ctx, frag);
267 }
268 
269 
272 {
273  int err, i;
274 
275  for (i = 0; i < frag->nb_units; i++) {
276  CodedBitstreamUnit *unit = &frag->units[i];
277 
278  if (!unit->content)
279  continue;
280 
281  av_buffer_unref(&unit->data_ref);
282  unit->data = NULL;
283 
284  err = ctx->codec->write_unit(ctx, unit);
285  if (err < 0) {
286  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
287  "(type %"PRIu32").\n", i, unit->type);
288  return err;
289  }
290  av_assert0(unit->data && unit->data_ref);
291  }
292 
293  av_buffer_unref(&frag->data_ref);
294  frag->data = NULL;
295 
296  err = ctx->codec->assemble_fragment(ctx, frag);
297  if (err < 0) {
298  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
299  return err;
300  }
301  av_assert0(frag->data && frag->data_ref);
302 
303  return 0;
304 }
305 
307  AVCodecParameters *par,
309 {
310  int err;
311 
312  err = ff_cbs_write_fragment_data(ctx, frag);
313  if (err < 0)
314  return err;
315 
316  av_freep(&par->extradata);
317 
318  par->extradata = av_malloc(frag->data_size +
320  if (!par->extradata)
321  return AVERROR(ENOMEM);
322 
323  memcpy(par->extradata, frag->data, frag->data_size);
324  memset(par->extradata + frag->data_size, 0,
326  par->extradata_size = frag->data_size;
327 
328  return 0;
329 }
330 
332  AVPacket *pkt,
334 {
335  AVBufferRef *buf;
336  int err;
337 
338  err = ff_cbs_write_fragment_data(ctx, frag);
339  if (err < 0)
340  return err;
341 
342  buf = av_buffer_ref(frag->data_ref);
343  if (!buf)
344  return AVERROR(ENOMEM);
345 
346  av_init_packet(pkt);
347  pkt->buf = buf;
348  pkt->data = frag->data;
349  pkt->size = frag->data_size;
350 
351  return 0;
352 }
353 
354 
356  const char *name)
357 {
358  if (!ctx->trace_enable)
359  return;
360 
361  av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
362 }
363 
365  const char *str, const int *subscripts,
366  const char *bits, int64_t value)
367 {
368  char name[256];
369  size_t name_len, bits_len;
370  int pad, subs, i, j, k, n;
371 
372  if (!ctx->trace_enable)
373  return;
374 
375  av_assert0(value >= INT_MIN && value <= UINT32_MAX);
376 
377  subs = subscripts ? subscripts[0] : 0;
378  n = 0;
379  for (i = j = 0; str[i];) {
380  if (str[i] == '[') {
381  if (n < subs) {
382  ++n;
383  k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
384  av_assert0(k > 0 && j + k < sizeof(name));
385  j += k;
386  for (++i; str[i] && str[i] != ']'; i++);
387  av_assert0(str[i] == ']');
388  } else {
389  while (str[i] && str[i] != ']')
390  name[j++] = str[i++];
391  av_assert0(str[i] == ']');
392  }
393  } else {
394  av_assert0(j + 1 < sizeof(name));
395  name[j++] = str[i++];
396  }
397  }
398  av_assert0(j + 1 < sizeof(name));
399  name[j] = 0;
400  av_assert0(n == subs);
401 
402  name_len = strlen(name);
403  bits_len = strlen(bits);
404 
405  if (name_len + bits_len > 60)
406  pad = bits_len + 2;
407  else
408  pad = 61 - name_len;
409 
410  av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
411  position, name, pad, bits, value);
412 }
413 
415  int width, const char *name,
416  const int *subscripts, uint32_t *write_to,
417  uint32_t range_min, uint32_t range_max)
418 {
419  uint32_t value;
420  int position;
421 
422  av_assert0(width > 0 && width <= 32);
423 
424  if (get_bits_left(gbc) < width) {
425  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
426  "%s: bitstream ended.\n", name);
427  return AVERROR_INVALIDDATA;
428  }
429 
430  if (ctx->trace_enable)
431  position = get_bits_count(gbc);
432 
433  value = get_bits_long(gbc, width);
434 
435  if (ctx->trace_enable) {
436  char bits[33];
437  int i;
438  for (i = 0; i < width; i++)
439  bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
440  bits[i] = 0;
441 
442  ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
443  bits, value);
444  }
445 
446  if (value < range_min || value > range_max) {
447  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
448  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
449  name, value, range_min, range_max);
450  return AVERROR_INVALIDDATA;
451  }
452 
453  *write_to = value;
454  return 0;
455 }
456 
458  int width, const char *name,
459  const int *subscripts, uint32_t value,
460  uint32_t range_min, uint32_t range_max)
461 {
462  av_assert0(width > 0 && width <= 32);
463 
464  if (value < range_min || value > range_max) {
465  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
466  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
467  name, value, range_min, range_max);
468  return AVERROR_INVALIDDATA;
469  }
470 
471  if (put_bits_left(pbc) < width)
472  return AVERROR(ENOSPC);
473 
474  if (ctx->trace_enable) {
475  char bits[33];
476  int i;
477  for (i = 0; i < width; i++)
478  bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
479  bits[i] = 0;
480 
482  name, subscripts, bits, value);
483  }
484 
485  if (width < 32)
486  put_bits(pbc, width, value);
487  else
488  put_bits32(pbc, value);
489 
490  return 0;
491 }
492 
493 
495  CodedBitstreamUnit *unit,
496  size_t size,
497  void (*free)(void *opaque, uint8_t *data))
498 {
499  av_assert0(!unit->content && !unit->content_ref);
500 
501  unit->content = av_mallocz(size);
502  if (!unit->content)
503  return AVERROR(ENOMEM);
504 
505  unit->content_ref = av_buffer_create(unit->content, size,
506  free, ctx, 0);
507  if (!unit->content_ref) {
508  av_freep(&unit->content);
509  return AVERROR(ENOMEM);
510  }
511 
512  return 0;
513 }
514 
516  CodedBitstreamUnit *unit,
517  size_t size)
518 {
519  av_assert0(!unit->data && !unit->data_ref);
520 
522  if (!unit->data_ref)
523  return AVERROR(ENOMEM);
524 
525  unit->data = unit->data_ref->data;
526  unit->data_size = size;
527 
528  memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
529 
530  return 0;
531 }
532 
535  int position)
536 {
537  CodedBitstreamUnit *units;
538 
539  units = av_malloc_array(frag->nb_units + 1, sizeof(*units));
540  if (!units)
541  return AVERROR(ENOMEM);
542 
543  if (position > 0)
544  memcpy(units, frag->units, position * sizeof(*units));
545  if (position < frag->nb_units)
546  memcpy(units + position + 1, frag->units + position,
547  (frag->nb_units - position) * sizeof(*units));
548 
549  memset(units + position, 0, sizeof(*units));
550 
551  av_freep(&frag->units);
552  frag->units = units;
553  ++frag->nb_units;
554 
555  return 0;
556 }
557 
560  int position,
562  void *content,
563  AVBufferRef *content_buf)
564 {
565  CodedBitstreamUnit *unit;
566  AVBufferRef *content_ref;
567  int err;
568 
569  if (position == -1)
570  position = frag->nb_units;
571  av_assert0(position >= 0 && position <= frag->nb_units);
572 
573  if (content_buf) {
574  content_ref = av_buffer_ref(content_buf);
575  if (!content_ref)
576  return AVERROR(ENOMEM);
577  } else {
578  content_ref = NULL;
579  }
580 
581  err = cbs_insert_unit(ctx, frag, position);
582  if (err < 0) {
583  av_buffer_unref(&content_ref);
584  return err;
585  }
586 
587  unit = &frag->units[position];
588  unit->type = type;
589  unit->content = content;
590  unit->content_ref = content_ref;
591 
592  return 0;
593 }
594 
597  int position,
599  uint8_t *data, size_t data_size,
600  AVBufferRef *data_buf)
601 {
602  CodedBitstreamUnit *unit;
603  AVBufferRef *data_ref;
604  int err;
605 
606  if (position == -1)
607  position = frag->nb_units;
608  av_assert0(position >= 0 && position <= frag->nb_units);
609 
610  if (data_buf)
611  data_ref = av_buffer_ref(data_buf);
612  else
613  data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
614  if (!data_ref)
615  return AVERROR(ENOMEM);
616 
617  err = cbs_insert_unit(ctx, frag, position);
618  if (err < 0) {
619  av_buffer_unref(&data_ref);
620  return err;
621  }
622 
623  unit = &frag->units[position];
624  unit->type = type;
625  unit->data = data;
626  unit->data_size = data_size;
627  unit->data_ref = data_ref;
628 
629  return 0;
630 }
631 
634  int position)
635 {
636  if (position < 0 || position >= frag->nb_units)
637  return AVERROR(EINVAL);
638 
639  cbs_unit_uninit(ctx, &frag->units[position]);
640 
641  --frag->nb_units;
642 
643  if (frag->nb_units == 0) {
644  av_freep(&frag->units);
645 
646  } else {
647  memmove(frag->units + position,
648  frag->units + position + 1,
649  (frag->nb_units - position) * sizeof(*frag->units));
650 
651  // Don't bother reallocating the unit array.
652  }
653 
654  return 0;
655 }
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:331
static void cbs_unit_uninit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs.c:115
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:62
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:68
int size
Definition: avcodec.h:1432
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
Definition: cbs.c:494
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:558
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
Definition: cbs.c:355
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:3877
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:457
#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:414
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:143
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:221
uint8_t * data
Definition: avcodec.h:1431
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:200
#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:515
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:595
#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:596
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:127
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:1414
uint16_t width
Definition: gdv.c:47
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:3903
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:1464
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:306
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:632
int n
Definition: avisynth_c.h:684
enum AVCodecID codec_id
Definition: vaapi_decode.c:362
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:270
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
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:180
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:101
#define snprintf
Definition: snprintf.h:34
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:354
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:201
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:533
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:1477
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:46
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:774
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: avcodec.h:3899
#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:250
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:139
const CodedBitstreamType ff_cbs_type_vp9
Definition: cbs_vp9.c:668
This structure stores compressed data.
Definition: avcodec.h:1408
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:364
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