29 const int *subscripts,
int32_t *write_to)
35 if (
ctx->trace_enable)
40 "%s: bitstream ended.\n",
name);
48 if (
ctx->trace_enable) {
52 bits[
i] = magnitude >> (
width -
i - 1) & 1 ?
'1' :
'0';
53 bits[
i] = sign ?
'1' :
'0';
77 if (
ctx->trace_enable) {
81 bits[
i] = magnitude >> (
width -
i - 1) & 1 ?
'1' :
'0';
82 bits[
i] = sign ?
'1' :
'0';
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);
104 if (
ctx->trace_enable)
107 for (
i = 0,
value = range_min;
value < range_max;) {
110 "%s: bitstream ended.\n",
name);
122 if (
ctx->trace_enable) {
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",
145 if (
value == range_max)
146 len = range_max - range_min;
152 if (
ctx->trace_enable) {
155 for (
i = 0;
i <
len;
i++) {
156 if (range_min +
i ==
value)
174 const int *subscripts, uint32_t *write_to)
181 if (
ctx->trace_enable)
186 "%s: bitstream ended.\n",
name);
194 if (
ctx->trace_enable) {
198 for (
i = 0;
i < 8;
i++)
212 const int *subscripts, uint32_t
value)
221 if (
ctx->trace_enable) {
225 for (
i = 0;
i < 8;
i++)
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__)
265 #define READWRITE read
266 #define RWContext GetBitContext
268 #define xf(width, name, var, subs, ...) do { \
270 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
271 SUBSCRIPTS(subs, __VA_ARGS__), \
272 &value, 0, (1 << width) - 1)); \
275 #define xs(width, name, var, subs, ...) do { \
277 CHECK(cbs_vp9_read_s(ctx, rw, width, #name, \
278 SUBSCRIPTS(subs, __VA_ARGS__), &value)); \
283 #define increment(name, min, max) do { \
285 CHECK(cbs_vp9_read_increment(ctx, rw, min, max, #name, &value)); \
286 current->name = value; \
289 #define fle(width, name, subs, ...) do { \
290 CHECK(cbs_vp9_read_le(ctx, rw, width, #name, \
291 SUBSCRIPTS(subs, __VA_ARGS__), ¤t->name)); \
294 #define delta_q(name) do { \
295 uint8_t delta_coded; \
297 xf(1, name.delta_coded, delta_coded, 0, ); \
299 xs(4, name.delta_q, delta_q, 0, ); \
302 current->name = delta_q; \
305 #define prob(name, subs, ...) do { \
306 uint8_t prob_coded; \
308 xf(1, name.prob_coded, prob_coded, subs, __VA_ARGS__); \
310 xf(8, name.prob, prob, subs, __VA_ARGS__); \
313 current->name = prob; \
316 #define fixed(width, name, value) do { \
317 av_unused uint32_t fixed_value; \
318 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
319 0, &fixed_value, value, value)); \
322 #define infer(name, value) do { \
323 current->name = value; \
326 #define byte_alignment(rw) (get_bits_count(rw) % 8)
341 #undef byte_alignment
345 #define READWRITE write
346 #define RWContext PutBitContext
348 #define xf(width, name, var, subs, ...) do { \
349 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
350 SUBSCRIPTS(subs, __VA_ARGS__), \
351 var, 0, (1 << width) - 1)); \
353 #define xs(width, name, var, subs, ...) do { \
354 CHECK(cbs_vp9_write_s(ctx, rw, width, #name, \
355 SUBSCRIPTS(subs, __VA_ARGS__), var)); \
358 #define increment(name, min, max) do { \
359 CHECK(cbs_vp9_write_increment(ctx, rw, min, max, #name, current->name)); \
362 #define fle(width, name, subs, ...) do { \
363 CHECK(cbs_vp9_write_le(ctx, rw, width, #name, \
364 SUBSCRIPTS(subs, __VA_ARGS__), current->name)); \
367 #define delta_q(name) do { \
368 xf(1, name.delta_coded, !!current->name, 0, ); \
370 xs(4, name.delta_q, current->name, 0, ); \
373 #define prob(name, subs, ...) do { \
374 xf(1, name.prob_coded, current->name != 255, subs, __VA_ARGS__); \
375 if (current->name != 255) \
376 xf(8, name.prob, current->name, subs, __VA_ARGS__); \
379 #define fixed(width, name, value) do { \
380 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
381 0, value, value, value)); \
384 #define infer(name, value) do { \
385 if (current->name != (value)) { \
386 av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \
387 "%s does not match inferred value: " \
388 "%"PRId64", but should be %"PRId64".\n", \
389 #name, (int64_t)current->name, (int64_t)(value)); \
393 #define byte_alignment(rw) (put_bits_count(rw) % 8)
408 #undef byte_alignment
424 if ((superframe_header & 0xe0) == 0xc0) {
427 size_t index_size,
pos;
430 index_size = 2 + (((superframe_header & 0x18) >> 3) + 1) *
431 ((superframe_header & 0x07) + 1);
441 err = cbs_vp9_read_superframe_index(
ctx, &gbc, &sfi);
449 "in superframe: %"PRIu32
" bytes.\n",
498 err = cbs_vp9_read_frame(
ctx, &gbc,
frame);
511 if (!
frame->data_ref)
528 err = cbs_vp9_write_frame(
ctx, pbc,
frame);
576 "make superframe: %d.\n", frag->
nb_units);
582 if (max < frag->units[
i].data_size)
618 err = cbs_vp9_write_superframe_index(
ctx, &pbc, &sfi);
621 "superframe index.\n");
641 memset(vp9->
ref, 0,
sizeof(vp9->
ref));
static void flush(AVCodecContext *avctx)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_cbs_insert_unit_data(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.
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *str, const int *subscripts, const char *bits, int64_t value)
int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
#define CBS_UNIT_TYPE_END_OF_LIST
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
static int cbs_vp9_read_s(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, int32_t *write_to)
static int cbs_vp9_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *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)
static int cbs_vp9_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
static const CodedBitstreamUnitTypeDescriptor cbs_vp9_unit_types[]
static void cbs_vp9_flush(CodedBitstreamContext *ctx)
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)
const CodedBitstreamType ff_cbs_type_vp9
static int cbs_vp9_read_le(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, uint32_t *write_to)
static int cbs_vp9_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, uint32_t value)
static int cbs_vp9_write_s(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, int32_t value)
static int cbs_vp9_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_alloc(buffer_size_t size)
Allocate an AVBuffer of the given size using av_malloc().
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
common internal API header
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int put_bits_count(PutBitContext *s)
static int put_bits_left(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
static const uint8_t header[24]
A reference to a data buffer.
void * priv_data
Format private data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Context structure for coded bitstream operations.
Coded bitstream fragment structure, combining one or more units.
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
int nb_units
Number of units in this fragment.
size_t data_size
The number of bytes in the bitstream.
uint8_t * data
Pointer to the bitstream form of this fragment.
AVBufferRef * data_ref
A reference to the buffer containing data.
Coded bitstream unit structure.
void * content
Pointer to the decomposed form of this unit.
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
AVBufferRef * data_ref
A reference to the buffer containing data.
VP9ReferenceFrameState ref[VP9_NUM_REF_FRAMES]
uint8_t superframe_marker
uint8_t bytes_per_framesize_minus_1
uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME]
uint8_t frames_in_superframe_minus_1
static int ref[MAX_W *MAX_W]