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, MAX_UINT_BITS(width), 0, ) 45 #define uir(width, name) \ 46 xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0, ) 47 #define uis(width, name, subs, ...) \ 48 xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__) 49 #define uirs(width, name, subs, ...) \ 50 xui(width, name, current->name, 1, MAX_UINT_BITS(width), subs, __VA_ARGS__) 51 #define xui(width, name, var, range_min, range_max, subs, ...) \ 52 xuia(width, #name, var, range_min, range_max, subs, __VA_ARGS__) 53 #define sis(width, name, subs, ...) \ 54 xsi(width, name, current->name, subs, __VA_ARGS__) 56 #define marker_bit() \ 58 #define bit(string, value) do { \ 59 av_unused uint32_t bit = value; \ 60 xuia(1, string, bit, value, value, 0, ); \ 65 #define READWRITE read 66 #define RWContext GetBitContext 68 #define xuia(width, string, var, range_min, range_max, subs, ...) do { \ 70 CHECK(ff_cbs_read_unsigned(ctx, rw, width, string, \ 71 SUBSCRIPTS(subs, __VA_ARGS__), \ 72 &value, range_min, range_max)); \ 76 #define xsi(width, name, var, subs, ...) do { \ 78 CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \ 79 SUBSCRIPTS(subs, __VA_ARGS__), &value, \ 80 MIN_INT_BITS(width), \ 81 MAX_INT_BITS(width))); \ 85 #define nextbits(width, compare, var) \ 86 (get_bits_left(rw) >= width && \ 87 (var = show_bits(rw, width)) == (compare)) 89 #define infer(name, value) do { \ 90 current->name = value; \ 105 #define READWRITE write 106 #define RWContext PutBitContext 108 #define xuia(width, string, var, range_min, range_max, subs, ...) do { \ 109 CHECK(ff_cbs_write_unsigned(ctx, rw, width, string, \ 110 SUBSCRIPTS(subs, __VA_ARGS__), \ 111 var, range_min, range_max)); \ 114 #define xsi(width, name, var, subs, ...) do { \ 115 CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \ 116 SUBSCRIPTS(subs, __VA_ARGS__), var, \ 117 MIN_INT_BITS(width), \ 118 MAX_INT_BITS(width))); \ 121 #define nextbits(width, compare, var) (var) 123 #define infer(name, value) do { \ 124 if (current->name != (value)) { \ 125 av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \ 126 "%s does not match inferred value: " \ 127 "%"PRId64", but should be %"PRId64".\n", \ 128 #name, (int64_t)current->name, (int64_t)(value)); \ 173 int err,
i,
final = 0;
177 if (start_code >> 8 != 0x000001) {
183 unit_type = start_code & 0xff;
200 if (start_code >> 8 == 0x000001) {
203 unit_size = (end - 4) - start;
206 unit_size = end - start;
244 err = cbs_mpeg2_read_slice_header(ctx, &gbc, &slice->
header);
263 switch (unit->
type) {
264 #define START(start_code, type, read_func, free_func) \ 268 err = ff_cbs_alloc_unit_content(ctx, unit, \ 269 sizeof(*header), free_func); \ 272 header = unit->content; \ 273 err = cbs_mpeg2_read_ ## read_func(ctx, &gbc, header); \ 305 switch (unit->
type) {
306 #define START(start_code, type, func) \ 308 err = cbs_mpeg2_write_ ## func(ctx, pbc, unit->content); \ 320 "code %02"PRIx32
".\n", unit->
type);
334 err = cbs_mpeg2_write_slice_header(ctx, pbc, &slice->
header);
362 for (; rest > 3; rest -= 4, pos += 4)
365 for (; rest; rest--, pos++)
394 for (i = 0; i < frag->
nb_units; i++)
403 for (i = 0; i < frag->
nb_units; i++) {
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
int nb_units
Number of units in this fragment.
static void cbs_mpeg2_free_slice(void *opaque, uint8_t *content)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static void cbs_mpeg2_free_picture_header(void *opaque, uint8_t *content)
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
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_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)
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
#define MAX_UINT_BITS(length)
static av_cold int end(AVCodecContext *avctx)
static int get_bits_count(const GetBitContext *s)
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_allocated.
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)
static int FUNC() extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *current)
#define i(width, name, range_min, range_max)
#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)
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.
static void cbs_mpeg2_free_user_data(void *opaque, uint8_t *content)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
#define START(start_code, type, read_func, free_func)
static int FUNC() user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
static int FUNC() sequence_end(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceEnd *current)
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
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().
static int cbs_mpeg2_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
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
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
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)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
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).