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)
41 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
43 #define ui(width, name) \
44 xui(width, name, current->name, 0)
45 #define uis(width, name, subs, ...) \
46 xui(width, name, current->name, subs, __VA_ARGS__)
50 #define READWRITE read
51 #define RWContext GetBitContext
53 #define xui(width, name, var, subs, ...) do { \
55 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
56 SUBSCRIPTS(subs, __VA_ARGS__), \
57 &value, 0, (1 << width) - 1)); \
61 #define marker_bit() do { \
62 av_unused uint32_t one; \
63 CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", NULL, &one, 1, 1)); \
66 #define nextbits(width, compare, var) \
67 (get_bits_left(rw) >= width && \
68 (var = show_bits(rw, width)) == (compare))
81 #define READWRITE write
82 #define RWContext PutBitContext
84 #define xui(width, name, var, subs, ...) do { \
85 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
86 SUBSCRIPTS(subs, __VA_ARGS__), \
87 var, 0, (1 << width) - 1)); \
90 #define marker_bit() do { \
91 CHECK(ff_cbs_write_unsigned(ctx, rw, 1, "marker_bit", NULL, 1, 1, 1)); \
94 #define nextbits(width, compare, var) (var)
127 uint32_t
start_code = -1, next_start_code = -1;
129 int err, i, unit_type;
137 unit_type = start_code & 0xff;
143 unit_size = end - (start - 1);
147 unit_size = (end - 4) - (start - 1);
150 unit_data = (
uint8_t *)start - 1;
153 unit_data, unit_size, frag->
data_ref);
160 start_code = next_start_code;
187 err = cbs_mpeg2_read_slice_header(ctx, &gbc, &slice->
header);
203 switch (unit->
type) {
204 #define START(start_code, type, read_func, free_func) \
208 err = ff_cbs_alloc_unit_content(ctx, unit, \
209 sizeof(*header), free_func); \
212 header = unit->content; \
213 err = cbs_mpeg2_read_ ## read_func(ctx, &gbc, header); \
242 switch (unit->
type) {
243 #define START(start_code, type, func) \
245 err = cbs_mpeg2_write_ ## func(ctx, pbc, unit->content); \
255 "code %02"PRIx32
".\n", unit->
type);
271 err = cbs_mpeg2_write_slice_header(ctx, pbc, &slice->
header);
307 reallocate_and_try_again:
311 "sufficiently large write buffer (last attempt "
319 if (unit->
type >= 0x01 && unit->
type <= 0xaf)
327 goto reallocate_and_try_again;
359 for (i = 0; i < frag->
nb_units; i++)
368 for (i = 0; i < frag->
nb_units; i++) {
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)
AVBufferRef * data_ref
A reference to the buffer containing data.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
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
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).