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';
75 magnitude = sign ? -value :
value;
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);
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__) 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",
463 if (pos + index_size != frag->
data_size) {
498 err = cbs_vp9_read_frame(ctx, &gbc, frame);
528 err = cbs_vp9_write_frame(ctx, pbc, frame);
576 "make superframe: %d.\n", frag->
nb_units);
581 for (i = 0; i < frag->
nb_units; i++)
582 if (max < frag->units[i].data_size)
588 size_len =
av_log2(max) / 8 + 1;
596 for (i = 0; i < frag->
nb_units; i++) {
608 for (i = 0; i < frag->
nb_units; i++) {
618 err = cbs_vp9_write_superframe_index(ctx, &pbc, &sfi);
621 "superframe index.\n");
641 memset(vp9->
ref, 0,
sizeof(vp9->
ref));
654 .unit_types = cbs_vp9_unit_types,
int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
static void cbs_vp9_flush(CodedBitstreamContext *ctx)
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...
ptrdiff_t const GLvoid * data
static void flush(AVCodecContext *avctx)
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)
static const CodedBitstreamUnitTypeDescriptor cbs_vp9_unit_types[]
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.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int trace_enable
Enable trace output during read/write operations.
GLsizei GLboolean const GLfloat * value
static int cbs_vp9_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int get_bits_count(const GetBitContext *s)
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
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_allocated.
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)
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 AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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_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)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
VP9ReferenceFrameState ref[VP9_NUM_REF_FRAMES]
uint32_t frame_sizes[VP9_MAX_FRAMES_IN_SUPERFRAME]
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
uint8_t * data
Pointer to the bitstream form of this fragment.
#define CBS_UNIT_TYPE_END_OF_LIST
static int cbs_vp9_write_le(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, uint32_t value)
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)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
AVBufferRef * data_ref
A reference to the buffer containing data.
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)