FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cbs_vp9.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 "libavutil/avassert.h"
20 
21 #include "cbs.h"
22 #include "cbs_internal.h"
23 #include "cbs_vp9.h"
24 #include "internal.h"
25 
26 
28  int width, const char *name,
29  const int *subscripts, int32_t *write_to)
30 {
31  uint32_t magnitude;
32  int position, sign;
33  int32_t value;
34 
35  if (ctx->trace_enable)
36  position = get_bits_count(gbc);
37 
38  if (get_bits_left(gbc) < width + 1) {
39  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid signed value at "
40  "%s: bitstream ended.\n", name);
41  return AVERROR_INVALIDDATA;
42  }
43 
44  magnitude = get_bits(gbc, width);
45  sign = get_bits1(gbc);
46  value = sign ? -(int32_t)magnitude : magnitude;
47 
48  if (ctx->trace_enable) {
49  char bits[33];
50  int i;
51  for (i = 0; i < width; i++)
52  bits[i] = magnitude >> (width - i - 1) & 1 ? '1' : '0';
53  bits[i] = sign ? '1' : '0';
54  bits[i + 1] = 0;
55 
56  ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
57  bits, value);
58  }
59 
60  *write_to = value;
61  return 0;
62 }
63 
65  int width, const char *name,
66  const int *subscripts, int32_t value)
67 {
68  uint32_t magnitude;
69  int sign;
70 
71  if (put_bits_left(pbc) < width + 1)
72  return AVERROR(ENOSPC);
73 
74  sign = value < 0;
75  magnitude = sign ? -value : value;
76 
77  if (ctx->trace_enable) {
78  char bits[33];
79  int i;
80  for (i = 0; i < width; i++)
81  bits[i] = magnitude >> (width - i - 1) & 1 ? '1' : '0';
82  bits[i] = sign ? '1' : '0';
83  bits[i + 1] = 0;
84 
86  name, subscripts, bits, value);
87  }
88 
89  put_bits(pbc, width, magnitude);
90  put_bits(pbc, 1, sign);
91 
92  return 0;
93 }
94 
96  uint32_t range_min, uint32_t range_max,
97  const char *name, uint32_t *write_to)
98 {
99  uint32_t value;
100  int position, i;
101  char bits[8];
102 
103  av_assert0(range_min <= range_max && range_max - range_min < sizeof(bits) - 1);
104  if (ctx->trace_enable)
105  position = get_bits_count(gbc);
106 
107  for (i = 0, value = range_min; value < range_max;) {
108  if (get_bits_left(gbc) < 1) {
109  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid increment value at "
110  "%s: bitstream ended.\n", name);
111  return AVERROR_INVALIDDATA;
112  }
113  if (get_bits1(gbc)) {
114  bits[i++] = '1';
115  ++value;
116  } else {
117  bits[i++] = '0';
118  break;
119  }
120  }
121 
122  if (ctx->trace_enable) {
123  bits[i] = 0;
124  ff_cbs_trace_syntax_element(ctx, position, name, NULL, bits, value);
125  }
126 
127  *write_to = value;
128  return 0;
129 }
130 
132  uint32_t range_min, uint32_t range_max,
133  const char *name, uint32_t value)
134 {
135  int len;
136 
137  av_assert0(range_min <= range_max && range_max - range_min < 8);
138  if (value < range_min || value > range_max) {
139  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
140  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
141  name, value, range_min, range_max);
142  return AVERROR_INVALIDDATA;
143  }
144 
145  if (value == range_max)
146  len = range_max - range_min;
147  else
148  len = value - range_min + 1;
149  if (put_bits_left(pbc) < len)
150  return AVERROR(ENOSPC);
151 
152  if (ctx->trace_enable) {
153  char bits[8];
154  int i;
155  for (i = 0; i < len; i++) {
156  if (range_min + i == value)
157  bits[i] = '0';
158  else
159  bits[i] = '1';
160  }
161  bits[i] = 0;
163  name, NULL, bits, value);
164  }
165 
166  if (len > 0)
167  put_bits(pbc, len, (1 << len) - 1 - (value != range_max));
168 
169  return 0;
170 }
171 
173  int width, const char *name,
174  const int *subscripts, uint32_t *write_to)
175 {
176  uint32_t value;
177  int position, b;
178 
179  av_assert0(width % 8 == 0);
180 
181  if (ctx->trace_enable)
182  position = get_bits_count(gbc);
183 
184  if (get_bits_left(gbc) < width) {
185  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid le value at "
186  "%s: bitstream ended.\n", name);
187  return AVERROR_INVALIDDATA;
188  }
189 
190  value = 0;
191  for (b = 0; b < width; b += 8)
192  value |= get_bits(gbc, 8) << b;
193 
194  if (ctx->trace_enable) {
195  char bits[33];
196  int i;
197  for (b = 0; b < width; b += 8)
198  for (i = 0; i < 8; i++)
199  bits[b + i] = value >> (b + i) & 1 ? '1' : '0';
200  bits[b] = 0;
201 
202  ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
203  bits, value);
204  }
205 
206  *write_to = value;
207  return 0;
208 }
209 
211  int width, const char *name,
212  const int *subscripts, uint32_t value)
213 {
214  int b;
215 
216  av_assert0(width % 8 == 0);
217 
218  if (put_bits_left(pbc) < width)
219  return AVERROR(ENOSPC);
220 
221  if (ctx->trace_enable) {
222  char bits[33];
223  int i;
224  for (b = 0; b < width; b += 8)
225  for (i = 0; i < 8; i++)
226  bits[b + i] = value >> (b + i) & 1 ? '1' : '0';
227  bits[b] = 0;
228 
230  name, subscripts, bits, value);
231  }
232 
233  for (b = 0; b < width; b += 8)
234  put_bits(pbc, 8, value >> b & 0xff);
235 
236  return 0;
237 }
238 
239 #define HEADER(name) do { \
240  ff_cbs_trace_header(ctx, name); \
241  } while (0)
242 
243 #define CHECK(call) do { \
244  err = (call); \
245  if (err < 0) \
246  return err; \
247  } while (0)
248 
249 #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
250 #define FUNC_VP9(rw, name) FUNC_NAME(rw, vp9, name)
251 #define FUNC(name) FUNC_VP9(READWRITE, name)
252 
253 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
254 
255 #define f(width, name) \
256  xf(width, name, current->name, 0)
257 #define s(width, name) \
258  xs(width, name, current->name, 0)
259 #define fs(width, name, subs, ...) \
260  xf(width, name, current->name, subs, __VA_ARGS__)
261 #define ss(width, name, subs, ...) \
262  xs(width, name, current->name, subs, __VA_ARGS__)
263 
264 
265 #define READ
266 #define READWRITE read
267 #define RWContext GetBitContext
268 
269 #define xf(width, name, var, subs, ...) do { \
270  uint32_t value = 0; \
271  CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
272  SUBSCRIPTS(subs, __VA_ARGS__), \
273  &value, 0, (1 << width) - 1)); \
274  var = value; \
275  } while (0)
276 #define xs(width, name, var, subs, ...) do { \
277  int32_t value = 0; \
278  CHECK(cbs_vp9_read_s(ctx, rw, width, #name, \
279  SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
280  var = value; \
281  } while (0)
282 
283 
284 #define increment(name, min, max) do { \
285  uint32_t value = 0; \
286  CHECK(cbs_vp9_read_increment(ctx, rw, min, max, #name, &value)); \
287  current->name = value; \
288  } while (0)
289 
290 #define fle(width, name, subs, ...) do { \
291  CHECK(cbs_vp9_read_le(ctx, rw, width, #name, \
292  SUBSCRIPTS(subs, __VA_ARGS__), &current->name)); \
293  } while (0)
294 
295 #define delta_q(name) do { \
296  uint8_t delta_coded; \
297  int8_t delta_q; \
298  xf(1, name.delta_coded, delta_coded, 0); \
299  if (delta_coded) \
300  xs(4, name.delta_q, delta_q, 0); \
301  else \
302  delta_q = 0; \
303  current->name = delta_q; \
304  } while (0)
305 
306 #define prob(name, subs, ...) do { \
307  uint8_t prob_coded; \
308  int8_t prob; \
309  xf(1, name.prob_coded, prob_coded, subs, __VA_ARGS__); \
310  if (prob_coded) \
311  xf(8, name.prob, prob, subs, __VA_ARGS__); \
312  else \
313  prob = 255; \
314  current->name = prob; \
315  } while (0)
316 
317 #define infer(name, value) do { \
318  current->name = value; \
319  } while (0)
320 
321 #define byte_alignment(rw) (get_bits_count(rw) % 8)
322 
323 #include "cbs_vp9_syntax_template.c"
324 
325 #undef READ
326 #undef READWRITE
327 #undef RWContext
328 #undef xf
329 #undef xs
330 #undef increment
331 #undef fle
332 #undef delta_q
333 #undef prob
334 #undef infer
335 #undef byte_alignment
336 
337 
338 #define WRITE
339 #define READWRITE write
340 #define RWContext PutBitContext
341 
342 #define xf(width, name, var, subs, ...) do { \
343  CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
344  SUBSCRIPTS(subs, __VA_ARGS__), \
345  var, 0, (1 << width) - 1)); \
346  } while (0)
347 #define xs(width, name, var, subs, ...) do { \
348  CHECK(cbs_vp9_write_s(ctx, rw, width, #name, \
349  SUBSCRIPTS(subs, __VA_ARGS__), var)); \
350  } while (0)
351 
352 #define increment(name, min, max) do { \
353  CHECK(cbs_vp9_write_increment(ctx, rw, min, max, #name, current->name)); \
354  } while (0)
355 
356 #define fle(width, name, subs, ...) do { \
357  CHECK(cbs_vp9_write_le(ctx, rw, width, #name, \
358  SUBSCRIPTS(subs, __VA_ARGS__), current->name)); \
359  } while (0)
360 
361 #define delta_q(name) do { \
362  xf(1, name.delta_coded, !!current->name, 0); \
363  if (current->name) \
364  xs(4, name.delta_q, current->name, 0); \
365  } while (0)
366 
367 #define prob(name, subs, ...) do { \
368  xf(1, name.prob_coded, current->name != 255, subs, __VA_ARGS__); \
369  if (current->name != 255) \
370  xf(8, name.prob, current->name, subs, __VA_ARGS__); \
371  } while (0)
372 
373 #define infer(name, value) do { \
374  if (current->name != (value)) { \
375  av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \
376  "%s does not match inferred value: " \
377  "%"PRId64", but should be %"PRId64".\n", \
378  #name, (int64_t)current->name, (int64_t)(value)); \
379  } \
380  } while (0)
381 
382 #define byte_alignment(rw) (put_bits_count(rw) % 8)
383 
384 #include "cbs_vp9_syntax_template.c"
385 
386 #undef READ
387 #undef READWRITE
388 #undef RWContext
389 #undef xf
390 #undef xs
391 #undef increment
392 #undef fle
393 #undef delta_q
394 #undef prob
395 #undef infer
396 #undef byte_alignment
397 
398 
401  int header)
402 {
403  uint8_t superframe_header;
404  int err;
405 
406  // Last byte in the packet.
407  superframe_header = frag->data[frag->data_size - 1];
408 
409  if ((superframe_header & 0xe0) == 0xc0) {
411  GetBitContext gbc;
412  size_t index_size, pos;
413  int i;
414 
415  index_size = 2 + (((superframe_header & 0x18) >> 3) + 1) *
416  ((superframe_header & 0x07) + 1);
417 
418  err = init_get_bits(&gbc, frag->data + frag->data_size - index_size,
419  8 * index_size);
420  if (err < 0)
421  return err;
422 
423  err = cbs_vp9_read_superframe_index(ctx, &gbc, &sfi);
424  if (err < 0)
425  return err;
426 
427  pos = 0;
428  for (i = 0; i <= sfi.frames_in_superframe_minus_1; i++) {
429  if (pos + sfi.frame_sizes[i] + index_size > frag->data_size) {
430  av_log(ctx->log_ctx, AV_LOG_ERROR, "Frame %d too large "
431  "in superframe: %"PRIu32" bytes.\n",
432  i, sfi.frame_sizes[i]);
433  return AVERROR_INVALIDDATA;
434  }
435 
436  err = ff_cbs_insert_unit_data(ctx, frag, -1, 0,
437  frag->data + pos,
438  sfi.frame_sizes[i],
439  frag->data_ref);
440  if (err < 0)
441  return err;
442 
443  pos += sfi.frame_sizes[i];
444  }
445  if (pos + index_size != frag->data_size) {
446  av_log(ctx->log_ctx, AV_LOG_WARNING, "Extra padding at "
447  "end of superframe: %zu bytes.\n",
448  frag->data_size - (pos + index_size));
449  }
450 
451  return 0;
452 
453  } else {
454  err = ff_cbs_insert_unit_data(ctx, frag, -1, 0,
455  frag->data, frag->data_size,
456  frag->data_ref);
457  if (err < 0)
458  return err;
459  }
460 
461  return 0;
462 }
463 
464 static void cbs_vp9_free_frame(void *unit, uint8_t *content)
465 {
466  VP9RawFrame *frame = (VP9RawFrame*)content;
467  av_buffer_unref(&frame->data_ref);
468  av_freep(&frame);
469 }
470 
472  CodedBitstreamUnit *unit)
473 {
475  GetBitContext gbc;
476  int err, pos;
477 
478  err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
479  if (err < 0)
480  return err;
481 
482  err = ff_cbs_alloc_unit_content(ctx, unit, sizeof(*frame),
484  if (err < 0)
485  return err;
486  frame = unit->content;
487 
488  err = cbs_vp9_read_frame(ctx, &gbc, frame);
489  if (err < 0)
490  return err;
491 
492  pos = get_bits_count(&gbc);
493  av_assert0(pos % 8 == 0);
494  pos /= 8;
495  av_assert0(pos <= unit->data_size);
496 
497  if (pos == unit->data_size) {
498  // No data (e.g. a show-existing-frame frame).
499  } else {
500  frame->data_ref = av_buffer_ref(unit->data_ref);
501  if (!frame->data_ref)
502  return AVERROR(ENOMEM);
503 
504  frame->data = unit->data + pos;
505  frame->data_size = unit->data_size - pos;
506  }
507 
508  return 0;
509 }
510 
512  CodedBitstreamUnit *unit)
513 {
514  CodedBitstreamVP9Context *priv = ctx->priv_data;
515  VP9RawFrame *frame = unit->content;
516  PutBitContext pbc;
517  int err;
518 
519  if (!priv->write_buffer) {
520  // Initial write buffer size is 1MB.
521  priv->write_buffer_size = 1024 * 1024;
522 
523  reallocate_and_try_again:
524  err = av_reallocp(&priv->write_buffer, priv->write_buffer_size);
525  if (err < 0) {
526  av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
527  "sufficiently large write buffer (last attempt "
528  "%zu bytes).\n", priv->write_buffer_size);
529  return err;
530  }
531  }
532 
533  init_put_bits(&pbc, priv->write_buffer, priv->write_buffer_size);
534 
535  err = cbs_vp9_write_frame(ctx, &pbc, frame);
536  if (err == AVERROR(ENOSPC)) {
537  priv->write_buffer_size *= 2;
538  goto reallocate_and_try_again;
539  }
540  if (err < 0)
541  return err;
542 
543  // Frame must be byte-aligned.
544  av_assert0(put_bits_count(&pbc) % 8 == 0);
545 
546  unit->data_size = put_bits_count(&pbc) / 8;
547  unit->data_bit_padding = 0;
548  flush_put_bits(&pbc);
549 
550  if (frame->data) {
551  if (unit->data_size + frame->data_size >
552  priv->write_buffer_size) {
553  priv->write_buffer_size *= 2;
554  goto reallocate_and_try_again;
555  }
556 
557  memcpy(priv->write_buffer + unit->data_size,
558  frame->data, frame->data_size);
559  unit->data_size += frame->data_size;
560  }
561 
562  err = ff_cbs_alloc_unit_data(ctx, unit, unit->data_size);
563  if (err < 0)
564  return err;
565 
566  memcpy(unit->data, priv->write_buffer, unit->data_size);
567 
568  return 0;
569 }
570 
573 {
574  int err;
575 
576  if (frag->nb_units == 1) {
577  // Output is just the content of the single frame.
578 
579  CodedBitstreamUnit *frame = &frag->units[0];
580 
581  frag->data_ref = av_buffer_ref(frame->data_ref);
582  if (!frag->data_ref)
583  return AVERROR(ENOMEM);
584 
585  frag->data = frame->data;
586  frag->data_size = frame->data_size;
587 
588  } else {
589  // Build superframe out of frames.
590 
592  PutBitContext pbc;
593  AVBufferRef *ref;
594  uint8_t *data;
595  size_t size, max, pos;
596  int i, size_len;
597 
598  if (frag->nb_units > 8) {
599  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many frames to "
600  "make superframe: %d.\n", frag->nb_units);
601  return AVERROR(EINVAL);
602  }
603 
604  max = 0;
605  for (i = 0; i < frag->nb_units; i++)
606  if (max < frag->units[i].data_size)
607  max = frag->units[i].data_size;
608 
609  if (max < 2)
610  size_len = 1;
611  else
612  size_len = av_log2(max) / 8 + 1;
613  av_assert0(size_len <= 4);
614 
616  sfi.bytes_per_framesize_minus_1 = size_len - 1;
617  sfi.frames_in_superframe_minus_1 = frag->nb_units - 1;
618 
619  size = 2;
620  for (i = 0; i < frag->nb_units; i++) {
621  size += size_len + frag->units[i].data_size;
622  sfi.frame_sizes[i] = frag->units[i].data_size;
623  }
624 
626  if (!ref)
627  return AVERROR(ENOMEM);
628  data = ref->data;
629  memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
630 
631  pos = 0;
632  for (i = 0; i < frag->nb_units; i++) {
633  av_assert0(size - pos > frag->units[i].data_size);
634  memcpy(data + pos, frag->units[i].data,
635  frag->units[i].data_size);
636  pos += frag->units[i].data_size;
637  }
638  av_assert0(size - pos == 2 + frag->nb_units * size_len);
639 
640  init_put_bits(&pbc, data + pos, size - pos);
641 
642  err = cbs_vp9_write_superframe_index(ctx, &pbc, &sfi);
643  if (err < 0) {
644  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write "
645  "superframe index.\n");
646  av_buffer_unref(&ref);
647  return err;
648  }
649 
650  av_assert0(put_bits_left(&pbc) == 0);
651  flush_put_bits(&pbc);
652 
653  frag->data_ref = ref;
654  frag->data = data;
655  frag->data_size = size;
656  }
657 
658  return 0;
659 }
660 
662 {
663  CodedBitstreamVP9Context *priv = ctx->priv_data;
664 
665  av_freep(&priv->write_buffer);
666 }
667 
670 
671  .priv_data_size = sizeof(CodedBitstreamVP9Context),
672 
673  .split_fragment = &cbs_vp9_split_fragment,
674  .read_unit = &cbs_vp9_read_unit,
675  .write_unit = &cbs_vp9_write_unit,
676  .assemble_fragment = &cbs_vp9_assemble_fragment,
677 
678  .close = &cbs_vp9_close,
679 };
#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
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:269
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static int cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs_vp9.c:571
const char * b
Definition: vf_curves.c:113
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
Definition: cbs.c:494
AVBufferRef * data_ref
Definition: cbs_vp9.h:171
int av_log2(unsigned v)
Definition: intmath.c:26
static void cbs_vp9_close(CodedBitstreamContext *ctx)
Definition: cbs_vp9.c:661
#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
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:86
static AVFrame * frame
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:200
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
static int cbs_vp9_read_le(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, uint32_t *write_to)
Definition: cbs_vp9.c:172
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:101
static const uint8_t header[24]
Definition: sdr2.c:67
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
static int cbs_vp9_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t range_min, uint32_t range_max, const char *name, uint32_t value)
Definition: cbs_vp9.c:131
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 cbs_vp9_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition: cbs_vp9.c:399
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:596
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:93
#define AVERROR(e)
Definition: error.h:43
uint16_t width
Definition: gdv.c:47
simple assert() macros that are a bit more flexible than ISO C assert().
static int cbs_vp9_write_s(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, int32_t value)
Definition: cbs_vp9.c:64
uint8_t superframe_marker
Definition: cbs_vp9.h:175
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
uint8_t bytes_per_framesize_minus_1
Definition: cbs_vp9.h:176
void * log_ctx
Logging context to be passed to all av_log() calls associated with this context.
Definition: cbs.h:164
static int cbs_vp9_read_s(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, int32_t *write_to)
Definition: cbs_vp9.c:27
uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME]
Definition: cbs_vp9.h:178
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
size_t data_size
Definition: cbs_vp9.h:170
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:122
static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, uint32_t value)
Definition: cbs_vp9.c:210
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:163
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
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:321
Context structure for coded bitstream operations.
Definition: cbs.h:159
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:433
uint8_t * write_buffer
Definition: cbs_vp9.h:196
enum AVCodecID codec_id
Definition: cbs_internal.h:29
const CodedBitstreamType ff_cbs_type_vp9
Definition: cbs_vp9.c:668
uint8_t * data
Definition: cbs_vp9.h:169
uint8_t frames_in_superframe_minus_1
Definition: cbs_vp9.h:177
void * priv_data
Internal codec-specific data.
Definition: cbs.h:180
A reference to a data buffer.
Definition: buffer.h:81
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:101
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:92
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:48
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:776
int len
#define av_freep(p)
static int cbs_vp9_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_vp9.c:471
static int cbs_vp9_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_vp9.c:511
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:139
static void cbs_vp9_free_frame(void *unit, uint8_t *content)
Definition: cbs_vp9.c:464
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
static int cbs_vp9_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc, uint32_t range_min, uint32_t range_max, const char *name, uint32_t *write_to)
Definition: cbs_vp9.c:95