29 const int *subscripts,
int32_t *write_to)
40 "%s: bitstream ended.\n", name);
46 value = sign ? -(
int32_t)magnitude : magnitude;
51 for (i = 0; i <
width; i++)
52 bits[i] = magnitude >> (width - i - 1) & 1 ?
'1' :
'0';
53 bits[
i] = sign ?
'1' :
'0';
80 for (i = 0; i <
width; i++)
81 bits[i] = magnitude >> (width - i - 1) & 1 ?
'1' :
'0';
82 bits[
i] = sign ?
'1' :
'0';
86 name, subscripts, bits, value);
96 uint32_t range_min, uint32_t range_max,
97 const char *
name, uint32_t *write_to)
103 av_assert0(range_min <= range_max && range_max - range_min <
sizeof(bits) - 1);
107 for (i = 0, value = range_min; value < range_max;) {
110 "%s: bitstream ended.\n", name);
132 uint32_t range_min, uint32_t range_max,
137 av_assert0(range_min <= range_max && range_max - range_min < 8);
138 if (value < range_min || value > range_max) {
140 "%"PRIu32
", but must be in [%"PRIu32
",%"PRIu32
"].\n",
141 name, value, range_min, range_max);
145 if (value == range_max)
146 len = range_max - range_min;
148 len = value - range_min + 1;
155 for (i = 0; i <
len; i++) {
156 if (range_min + i == value)
163 name,
NULL, bits, value);
167 put_bits(pbc, len, (1 << len) - 1 - (value != range_max));
174 const int *subscripts, uint32_t *write_to)
186 "%s: bitstream ended.\n", name);
191 for (b = 0; b <
width; b += 8)
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';
212 const int *subscripts, uint32_t
value)
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';
230 name, subscripts, bits, value);
233 for (b = 0; b <
width; b += 8)
234 put_bits(pbc, 8, value >> b & 0xff);
239 #define HEADER(name) do { \ 240 ff_cbs_trace_header(ctx, name); \ 243 #define CHECK(call) do { \ 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) 253 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) 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__) 266 #define READWRITE read 267 #define RWContext GetBitContext 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)); \ 276 #define xs(width, name, var, subs, ...) do { \ 278 CHECK(cbs_vp9_read_s(ctx, rw, width, #name, \ 279 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \ 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; \ 290 #define fle(width, name, subs, ...) do { \ 291 CHECK(cbs_vp9_read_le(ctx, rw, width, #name, \ 292 SUBSCRIPTS(subs, __VA_ARGS__), ¤t->name)); \ 295 #define delta_q(name) do { \ 296 uint8_t delta_coded; \ 298 xf(1, name.delta_coded, delta_coded, 0); \ 300 xs(4, name.delta_q, delta_q, 0); \ 303 current->name = delta_q; \ 306 #define prob(name, subs, ...) do { \ 307 uint8_t prob_coded; \ 309 xf(1, name.prob_coded, prob_coded, subs, __VA_ARGS__); \ 311 xf(8, name.prob, prob, subs, __VA_ARGS__); \ 314 current->name = prob; \ 317 #define fixed(width, name, value) do { \ 318 av_unused uint32_t fixed_value = value; \ 319 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \ 320 0, &fixed_value, value, value)); \ 323 #define infer(name, value) do { \ 324 current->name = value; \ 327 #define byte_alignment(rw) (get_bits_count(rw) % 8) 342 #undef byte_alignment 346 #define READWRITE write 347 #define RWContext PutBitContext 349 #define xf(width, name, var, subs, ...) do { \ 350 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \ 351 SUBSCRIPTS(subs, __VA_ARGS__), \ 352 var, 0, (1 << width) - 1)); \ 354 #define xs(width, name, var, subs, ...) do { \ 355 CHECK(cbs_vp9_write_s(ctx, rw, width, #name, \ 356 SUBSCRIPTS(subs, __VA_ARGS__), var)); \ 359 #define increment(name, min, max) do { \ 360 CHECK(cbs_vp9_write_increment(ctx, rw, min, max, #name, current->name)); \ 363 #define fle(width, name, subs, ...) do { \ 364 CHECK(cbs_vp9_write_le(ctx, rw, width, #name, \ 365 SUBSCRIPTS(subs, __VA_ARGS__), current->name)); \ 368 #define delta_q(name) do { \ 369 xf(1, name.delta_coded, !!current->name, 0); \ 371 xs(4, name.delta_q, current->name, 0); \ 374 #define prob(name, subs, ...) do { \ 375 xf(1, name.prob_coded, current->name != 255, subs, __VA_ARGS__); \ 376 if (current->name != 255) \ 377 xf(8, name.prob, current->name, subs, __VA_ARGS__); \ 380 #define fixed(width, name, value) do { \ 381 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \ 382 0, value, value, value)); \ 385 #define infer(name, value) do { \ 386 if (current->name != (value)) { \ 387 av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \ 388 "%s does not match inferred value: " \ 389 "%"PRId64", but should be %"PRId64".\n", \ 390 #name, (int64_t)current->name, (int64_t)(value)); \ 394 #define byte_alignment(rw) (put_bits_count(rw) % 8) 409 #undef byte_alignment 425 if ((superframe_header & 0xe0) == 0xc0) {
428 size_t index_size, pos;
431 index_size = 2 + (((superframe_header & 0x18) >> 3) + 1) *
432 ((superframe_header & 0x07) + 1);
442 err = cbs_vp9_read_superframe_index(ctx, &gbc, &sfi);
450 "in superframe: %"PRIu32
" bytes.\n",
464 if (pos + index_size != frag->
data_size) {
507 err = cbs_vp9_read_frame(ctx, &gbc, frame);
542 reallocate_and_try_again:
546 "sufficiently large write buffer (last attempt " 554 err = cbs_vp9_write_frame(ctx, &pbc, frame);
557 goto reallocate_and_try_again;
573 goto reallocate_and_try_again;
614 size_t size, max, pos;
619 "make superframe: %d.\n", frag->
nb_units);
624 for (i = 0; i < frag->
nb_units; i++)
625 if (max < frag->units[i].data_size)
631 size_len =
av_log2(max) / 8 + 1;
639 for (i = 0; i < frag->
nb_units; i++) {
651 for (i = 0; i < frag->
nb_units; i++) {
661 err = cbs_vp9_write_superframe_index(ctx, &pbc, &sfi);
664 "superframe index.\n");
int nb_units
Number of units in this fragment.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
static void cbs_vp9_close(CodedBitstreamContext *ctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int trace_enable
Enable trace output during read/write operations.
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
static int get_bits_count(const GetBitContext *s)
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.
Coded bitstream unit structure.
static int cbs_vp9_read_le(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, uint32_t *write_to)
void * content
Pointer to the decomposed form of this unit.
static const uint8_t header[24]
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units.
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
static int cbs_vp9_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t range_min, uint32_t range_max, const char *name, uint32_t value)
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.
size_t data_size
The number of bytes in the bitstream.
static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
static int get_bits_left(GetBitContext *gb)
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int put_bits_left(PutBitContext *s)
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)
uint8_t superframe_marker
static int put_bits_count(PutBitContext *s)
uint8_t bytes_per_framesize_minus_1
void * log_ctx
Logging context to be passed to all av_log() calls associated with this context.
static int cbs_vp9_read_s(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, int32_t *write_to)
uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME]
uint8_t * data
Pointer to the bitstream form of this fragment.
static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, uint32_t value)
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Coded bitstream fragment structure, combining one or more units.
uint8_t * data
The data buffer.
static unsigned int get_bits1(GetBitContext *s)
Context structure for coded bitstream operations.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
const CodedBitstreamType ff_cbs_type_vp9
uint8_t frames_in_superframe_minus_1
void * priv_data
Internal codec-specific data.
A reference to a data buffer.
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static int ref[MAX_W *MAX_W]
AVBufferRef * data_ref
A reference to the buffer containing data.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static int cbs_vp9_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
static int cbs_vp9_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
AVBufferRef * data_ref
A reference to the buffer containing data.
static void cbs_vp9_free_frame(void *unit, uint8_t *content)
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *str, const int *subscripts, const char *bits, int64_t value)
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
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)