27 #define HEADER(name) do { \
28 ff_cbs_trace_header(ctx, name); \
31 #define CHECK(call) do { \
37 #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
38 #define FUNC_MPEG2(rw, name) FUNC_NAME(rw, mpeg2, name)
39 #define FUNC(name) FUNC_MPEG2(READWRITE, name)
43 #define READWRITE read
44 #define RWContext GetBitContext
46 #define xui(width, name, var) do { \
48 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
49 &value, 0, (1 << width) - 1)); \
53 #define ui(width, name) \
54 xui(width, name, current->name)
56 #define marker_bit() do { \
57 av_unused uint32_t one; \
58 CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", &one, 1, 1)); \
61 #define nextbits(width, compare, var) \
62 (get_bits_left(rw) >= width && \
63 (var = show_bits(rw, width)) == (compare))
77 #define READWRITE write
78 #define RWContext PutBitContext
80 #define xui(width, name, var) do { \
81 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
82 var, 0, (1 << width) - 1)); \
85 #define ui(width, name) \
86 xui(width, name, current->name)
88 #define marker_bit() do { \
89 CHECK(ff_cbs_write_unsigned(ctx, rw, 1, "marker_bit", 1, 1, 1)); \
92 #define nextbits(width, compare, var) (var)
126 uint32_t
start_code = -1, next_start_code = -1;
128 int err, i, unit_type;
136 unit_type = start_code & 0xff;
142 unit_size = end - (start - 1);
146 unit_size = (end - 4) - (start - 1);
152 memcpy(unit_data, start - 1, unit_size);
156 unit_data, unit_size,
NULL);
165 start_code = next_start_code;
192 err = cbs_mpeg2_read_slice_header(ctx, &gbc, &slice->
header);
213 switch (unit->
type) {
214 #define START(start_code, type, read_func, free_func) \
218 err = ff_cbs_alloc_unit_content(ctx, unit, \
219 sizeof(*header), free_func); \
222 header = unit->content; \
223 err = cbs_mpeg2_read_ ## read_func(ctx, &gbc, header); \
252 switch (unit->
type) {
253 #define START(start_code, type, func) \
255 err = cbs_mpeg2_write_ ## func(ctx, pbc, unit->content); \
265 "code %02"PRIx32
".\n", unit->
type);
281 err = cbs_mpeg2_write_slice_header(ctx, pbc, &slice->
header);
317 reallocate_and_try_again:
321 "sufficiently large write buffer (last attempt "
329 if (unit->
type >= 0x01 && unit->
type <= 0xaf)
337 goto reallocate_and_try_again;
369 for (i = 0; i < frag->
nb_units; i++)
378 for (i = 0; i < frag->
nb_units; i++) {
386 data[dp++] = unit->
data[sp];
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 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.
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
CodedBitstreamUnitType type
Codec-specific type of this unit.
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, size_t size, void(*free)(void *opaque, uint8_t *data))
static int cbs_mpeg2_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
static void cbs_mpeg2_free_user_data(void *unit, uint8_t *content)
static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
static int FUNC() extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawPSExtensionData *current)
static av_cold int end(AVCodecContext *avctx)
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.
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.
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.
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
size_t data_size
The number of bytes in the bitstream.
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int put_bits_left(PutBitContext *s)
AVS_Value void * user_data
AVBufferRef * user_data_ref
simple assert() macros that are a bit more flexible than ISO C assert().
static int put_bits_count(PutBitContext *s)
static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
static int FUNC() picture_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawPictureHeader *current)
void * log_ctx
Logging context to be passed to all av_log() calls associated with this context.
#define START(start_code, type, read_func, free_func)
preferred ID for MPEG-1/2 video decoding
uint8_t * data
Pointer to the bitstream form of this fragment.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
const CodedBitstreamType ff_cbs_type_mpeg2
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
static int FUNC() sequence_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current)
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.
#define MPEG2_START_IS_SLICE(type)
uint8_t * data
The data buffer.
Context structure for coded bitstream operations.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static int cbs_mpeg2_write_slice(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
MPEG2RawSliceHeader header
void * priv_data
Internal codec-specific data.
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void cbs_mpeg2_close(CodedBitstreamContext *ctx)
static int FUNC() group_of_pictures_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawGroupOfPicturesHeader *current)
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 void cbs_mpeg2_free_slice(void *unit, uint8_t *content)
static int cbs_mpeg2_write_header(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
AVBufferRef * data_ref
If data is reference counted, a reference to the buffer containing data.
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).