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 uir(width, name) \
44 xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0, )
45#define uis(width, name, subs, ...) \
46 xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
47#define uirs(width, name, subs, ...) \
48 xui(width, name, current->name, 1, MAX_UINT_BITS(width), subs, __VA_ARGS__)
49#define xui(width, name, var, range_min, range_max, subs, ...) \
50 xuia(width, #name, var, range_min, range_max, subs, __VA_ARGS__)
51#define sis(width, name, subs, ...) \
52 xsi(width, name, current->name, subs, __VA_ARGS__)
56#define bit(string, value) do { \
57 av_unused uint32_t bit = value; \
58 xuia(1, string, bit, value, value, 0, ); \
64#define RWContext GetBitContext
66#define ui(width, name) do { \
68 CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
70 current->name = value; \
72#define xuia(width, string, var, range_min, range_max, subs, ...) do { \
74 CHECK(ff_cbs_read_unsigned(ctx, rw, width, string, \
75 SUBSCRIPTS(subs, __VA_ARGS__), \
76 &value, range_min, range_max)); \
80#define xsi(width, name, var, subs, ...) do { \
82 CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
83 SUBSCRIPTS(subs, __VA_ARGS__), &value, \
84 MIN_INT_BITS(width), \
85 MAX_INT_BITS(width))); \
89#define nextbits(width, compare, var) \
90 (get_bits_left(rw) >= width && \
91 (var = show_bits(rw, width)) == (compare))
93#define infer(name, value) do { \
94 current->name = value; \
110#define READWRITE write
111#define RWContext PutBitContext
113#define ui(width, name) do { \
114 CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
118#define xuia(width, string, var, range_min, range_max, subs, ...) do { \
119 CHECK(ff_cbs_write_unsigned(ctx, rw, width, string, \
120 SUBSCRIPTS(subs, __VA_ARGS__), \
121 var, range_min, range_max)); \
124#define xsi(width, name, var, subs, ...) do { \
125 CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
126 SUBSCRIPTS(subs, __VA_ARGS__), var, \
127 MIN_INT_BITS(width), \
128 MAX_INT_BITS(width))); \
131#define nextbits(width, compare, var) (var)
133#define infer(name, value) do { \
134 if (current->name != (value)) { \
135 av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \
136 "%s does not match inferred value: " \
137 "%"PRId64", but should be %"PRId64".\n", \
138 #name, (int64_t)current->name, (int64_t)(value)); \
158 const uint8_t *start;
189 unit_size = (end - 4) - start;
192 unit_size = end - start;
195 err = ff_cbs_append_unit_data(frag, unit_type, (uint8_t*)start,
218 err = ff_cbs_alloc_unit_content(
ctx, unit);
226 err = cbs_mpeg2_read_slice_header(
ctx, &gbc, &slice->
header);
245 switch (unit->
type) {
246#define START(start_code, type, read_func, free_func) \
249 type *header = unit->content; \
250 err = cbs_mpeg2_read_ ## read_func(ctx, &gbc, header); \
282 switch (unit->
type) {
283#define START(start_code, type, func) \
285 err = cbs_mpeg2_write_ ## func(ctx, pbc, unit->content); \
297 "code %02"PRIx32
".\n", unit->
type);
311 err = cbs_mpeg2_write_slice_header(
ctx, pbc, &slice->
header);
339 for (; rest > 3; rest -= 4,
pos += 4)
342 for (; rest; rest--,
pos++)
402 extra_information_picture.extra_information),
406 .unit_type.range.start = 0x01,
407 .unit_type.range.end = 0xaf,
411 .
type.ref = { .nb_offsets = 2,
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define i(width, name, range_min, range_max)
static int FUNC extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *current)
static int FUNC picture_header(CodedBitstreamContext *ctx, RWContext *rw, H266RawPictureHeader *current)
#define CBS_UNIT_TYPE_POD(type_, structure)
#define CBS_UNIT_TYPE_END_OF_LIST
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
@ CBS_CONTENT_TYPE_INTERNAL_REFS
#define MAX_UINT_BITS(length)
static int cbs_mpeg2_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
const CodedBitstreamType ff_cbs_type_mpeg2
#define START(start_code, type, read_func, free_func)
static int cbs_mpeg2_write_slice(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int cbs_mpeg2_write_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static CodedBitstreamUnitTypeDescriptor cbs_mpeg2_unit_types[]
static int cbs_mpeg2_write_header(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int cbs_mpeg2_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
static int cbs_mpeg2_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
#define MPEG2_START_IS_SLICE(type)
@ MPEG2_START_SEQUENCE_HEADER
@ MPEG2_START_SEQUENCE_END
static int FUNC user_data(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawUserData *current)
static int FUNC sequence_end(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceEnd *current)
static int FUNC group_of_pictures_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawGroupOfPicturesHeader *current)
static int FUNC sequence_header(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawSequenceHeader *current)
static int get_bits_left(GetBitContext *gb)
static int get_bits_count(const GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#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
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
static int put_bits_count(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_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 av_unused void put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
static const uint8_t header[24]
Accelerated start code search function for start codes common to MPEG-1/2/4 video,...
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
uint8_t * data
The data buffer.
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.
CodedBitstreamUnitType type
Codec-specific type 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.
MPEG2RawSliceHeader header
static AVFormatContext * ctx