Go to the documentation of this file.
29 #define HEADER(name) do { \
30 ff_cbs_trace_header(ctx, name); \
33 #define CHECK(call) do { \
39 #define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
40 #define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
41 #define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name)
42 #define FUNC_NAME2_EXPORT(rw, codec, name) ff_cbs_ ## codec ## _ ## rw ## _ ## name
43 #define FUNC_NAME1_EXPORT(rw, codec, name) FUNC_NAME2_EXPORT(rw, codec, name)
44 #define FUNC_SEI(name) FUNC_NAME1_EXPORT(READWRITE, sei, name)
46 #define SEI_FUNC(name, args) \
47 static int FUNC_H265(name) args; \
48 static int FUNC_H265(name ## _internal)(CodedBitstreamContext *ctx, \
49 RWContext *rw, void *cur, \
50 SEIMessageState *state) \
52 return FUNC_H265(name)(ctx, rw, cur, state); \
54 static int FUNC_H265(name) args
56 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
58 #define u(width, name, range_min, range_max) \
59 xu(width, name, current->name, range_min, range_max, 0, )
60 #define flag(name) ub(1, name)
61 #define ue(name, range_min, range_max) \
62 xue(name, current->name, range_min, range_max, 0, )
63 #define i(width, name, range_min, range_max) \
64 xi(width, name, current->name, range_min, range_max, 0, )
65 #define ib(width, name) \
66 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, )
67 #define se(name, range_min, range_max) \
68 xse(name, current->name, range_min, range_max, 0, )
70 #define us(width, name, range_min, range_max, subs, ...) \
71 xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
72 #define ubs(width, name, subs, ...) \
73 xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
74 #define flags(name, subs, ...) \
75 xu(1, name, current->name, 0, 1, subs, __VA_ARGS__)
76 #define ues(name, range_min, range_max, subs, ...) \
77 xue(name, current->name, range_min, range_max, subs, __VA_ARGS__)
78 #define is(width, name, range_min, range_max, subs, ...) \
79 xi(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
80 #define ibs(width, name, subs, ...) \
81 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), subs, __VA_ARGS__)
82 #define ses(name, range_min, range_max, subs, ...) \
83 xse(name, current->name, range_min, range_max, subs, __VA_ARGS__)
85 #define fixed(width, name, value) do { \
86 av_unused uint32_t fixed_value = value; \
87 xu(width, name, fixed_value, value, value, 0, ); \
92 #define READWRITE read
93 #define RWContext GetBitContext
95 #define ub(width, name) do { \
97 CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
99 current->name = value; \
101 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
103 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
104 SUBSCRIPTS(subs, __VA_ARGS__), \
105 &value, range_min, range_max)); \
108 #define xue(name, var, range_min, range_max, subs, ...) do { \
110 CHECK(ff_cbs_read_ue_golomb(ctx, rw, #name, \
111 SUBSCRIPTS(subs, __VA_ARGS__), \
112 &value, range_min, range_max)); \
115 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
117 CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
118 SUBSCRIPTS(subs, __VA_ARGS__), \
119 &value, range_min, range_max)); \
122 #define xse(name, var, range_min, range_max, subs, ...) do { \
124 CHECK(ff_cbs_read_se_golomb(ctx, rw, #name, \
125 SUBSCRIPTS(subs, __VA_ARGS__), \
126 &value, range_min, range_max)); \
131 #define infer(name, value) do { \
132 current->name = value; \
135 #define more_rbsp_data(var) ((var) = ff_cbs_h2645_read_more_rbsp_data(rw))
137 #define bit_position(rw) (get_bits_count(rw))
138 #define byte_alignment(rw) (get_bits_count(rw) % 8)
140 #define allocate(name, size) do { \
141 name ## _ref = av_buffer_allocz(size + \
142 AV_INPUT_BUFFER_PADDING_SIZE); \
144 return AVERROR(ENOMEM); \
145 name = name ## _ref->data; \
148 #define FUNC(name) FUNC_H265(name)
162 #undef more_rbsp_data
164 #undef byte_alignment
166 #undef allocate_struct
170 #define READWRITE write
171 #define RWContext PutBitContext
173 #define ub(width, name) do { \
174 uint32_t value = current->name; \
175 CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
178 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
179 uint32_t value = var; \
180 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
181 SUBSCRIPTS(subs, __VA_ARGS__), \
182 value, range_min, range_max)); \
184 #define xue(name, var, range_min, range_max, subs, ...) do { \
185 uint32_t value = var; \
186 CHECK(ff_cbs_write_ue_golomb(ctx, rw, #name, \
187 SUBSCRIPTS(subs, __VA_ARGS__), \
188 value, range_min, range_max)); \
190 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
191 int32_t value = var; \
192 CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
193 SUBSCRIPTS(subs, __VA_ARGS__), \
194 value, range_min, range_max)); \
196 #define xse(name, var, range_min, range_max, subs, ...) do { \
197 int32_t value = var; \
198 CHECK(ff_cbs_write_se_golomb(ctx, rw, #name, \
199 SUBSCRIPTS(subs, __VA_ARGS__), \
200 value, range_min, range_max)); \
203 #define infer(name, value) do { \
204 if (current->name != (value)) { \
205 av_log(ctx->log_ctx, AV_LOG_ERROR, \
206 "%s does not match inferred value: " \
207 "%"PRId64", but should be %"PRId64".\n", \
208 #name, (int64_t)current->name, (int64_t)(value)); \
209 return AVERROR_INVALIDDATA; \
213 #define more_rbsp_data(var) (var)
215 #define bit_position(rw) (put_bits_count(rw))
216 #define byte_alignment(rw) (put_bits_count(rw) % 8)
218 #define allocate(name, size) do { \
220 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s must be set " \
221 "for writing.\n", #name); \
222 return AVERROR_INVALIDDATA; \
226 #define FUNC(name) FUNC_H265(name)
244 #undef more_rbsp_data
246 #undef byte_alignment
267 size_t size, start, end;
268 int i, j, nb_arrays, nal_unit_type, nb_nals,
version;
277 version = bytestream2_get_byte(&gbc);
287 nb_arrays = bytestream2_get_byte(&gbc);
288 for (
i = 0;
i < nb_arrays;
i++) {
289 nal_unit_type = bytestream2_get_byte(&gbc) & 0x3f;
290 nb_nals = bytestream2_get_be16(&gbc);
293 for (j = 0; j < nb_nals; j++) {
296 size = bytestream2_get_be16(&gbc);
304 frag->
data + start, end - start,
309 "HVCC array %d (%d NAL units of type %d).\n",
310 i, nb_nals, nal_unit_type);
337 #define cbs_h2645_replace_ps(ps_name, ps_var, id_element) \
338 static int cbs_h265_replace_ ## ps_var(CodedBitstreamContext *ctx, \
339 CodedBitstreamUnit *unit) \
341 CodedBitstreamH265Context *priv = ctx->priv_data; \
342 H265Raw## ps_name *ps_var = unit->content; \
343 unsigned int id = ps_var->id_element; \
344 int err = ff_cbs_make_unit_refcounted(ctx, unit); \
347 if (priv->ps_var[id] == priv->active_ ## ps_var) \
348 priv->active_ ## ps_var = NULL ; \
349 av_assert0(unit->content_ref); \
350 av_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
368 err = ff_cbs_alloc_unit_content(
ctx, unit);
372 switch (unit->
type) {
377 err = cbs_h265_read_vps(
ctx, &gbc,
vps);
381 err = cbs_h265_replace_vps(
ctx, unit);
390 err = cbs_h265_read_sps(
ctx, &gbc,
sps);
394 err = cbs_h265_replace_sps(
ctx, unit);
404 err = cbs_h265_read_pps(
ctx, &gbc,
pps);
408 err = cbs_h265_replace_pps(
ctx, unit);
434 err = cbs_h265_read_slice_segment_header(
ctx, &gbc, &slice->
header);
455 err = cbs_h265_read_aud(
ctx, &gbc, unit->
content);
463 err = cbs_h265_read_filler(
ctx, &gbc, unit->
content);
472 err = cbs_h265_read_sei(
ctx, &gbc, unit->
content,
493 switch (unit->
type) {
498 err = cbs_h265_write_vps(
ctx, pbc,
vps);
502 err = cbs_h265_replace_vps(
ctx, unit);
512 err = cbs_h265_write_sps(
ctx, pbc,
sps);
516 err = cbs_h265_replace_sps(
ctx, unit);
526 err = cbs_h265_write_pps(
ctx, pbc,
pps);
530 err = cbs_h265_replace_pps(
ctx, unit);
555 err = cbs_h265_write_slice_segment_header(
ctx, pbc, &slice->
header);
573 err = cbs_h265_write_aud(
ctx, pbc, unit->
content);
581 err = cbs_h265_write_filler(
ctx, pbc, unit->
content);
590 err = cbs_h265_write_sei(
ctx, pbc, unit->
content,
600 "NAL unit type %"PRIu32
".\n", unit->
type);
616 switch (unit->
type) {
651 "h265 slice header is null, missing decompose?\n");
661 switch (unit->
type) {
739 #define SEI_MESSAGE_RW(codec, name) \
740 .read = cbs_ ## codec ## _read_ ## name ## _internal, \
741 .write = cbs_ ## codec ## _write_ ## name ## _internal
821 .read_unit = &cbs_h265_read_nal_unit,
@ SEI_TYPE_ALPHA_CHANNEL_INFO
H265RawVPS * vps[HEVC_MAX_VPS_COUNT]
RefStruct references.
#define AV_LOG_WARNING
Something somehow does not look correct.
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
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
RefStruct is an API for creating reference-counted objects with minimal overhead.
void * content
Pointer to the decomposed form of this unit.
H265RawSliceHeader header
static int get_bits_count(const GetBitContext *s)
int ff_cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
H265RawSPS * sps[HEVC_MAX_SPS_COUNT]
RefStruct references.
Context structure for coded bitstream operations.
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
int ff_cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const H2645Packet *packet)
CodedBitstreamUnitType type
Codec-specific type of this unit.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
CodedBitstreamH2645Context common
static av_cold void cbs_h265_close(CodedBitstreamContext *ctx)
@ SEI_TYPE_THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Coded bitstream unit structure.
int ff_cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
static av_cold void close(AVCodecParserContext *s)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static int cbs_h265_discarded_nal_unit(CodedBitstreamContext *ctx, const CodedBitstreamUnit *unit, enum AVDiscard skip)
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
const SEIMessageTypeDescriptor ff_cbs_sei_h265_types[]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int FUNC() extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *current)
#define FF_ARRAY_ELEMS(a)
Coded bitstream fragment structure, combining one or more units.
static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
size_t data_size
The number of bytes in the bitstream.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static AVFormatContext * ctx
#define SEI_MESSAGE_TYPE_END
@ AVDISCARD_BIDIR
discard all bidirectional frames
const CodedBitstreamType ff_cbs_type_h265
@ AVDISCARD_ALL
discard all
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[]
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
void(* flush)(AVBSFContext *ctx)
#define CBS_UNIT_RANGE_INTERNAL_REF(range_start, range_end, structure, ref_field)
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
uint8_t * data
Pointer to the bitstream form of this fragment.
static const uint8_t header[24]
#define CBS_UNIT_TYPE_POD(type_, structure)
static void cbs_h265_free_sei(AVRefStructOpaque unused, void *content)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
#define SEI_MESSAGE_RW(codec, name)
@ H2645_FLAG_SMALL_PADDING
@ AVDISCARD_NONINTRA
discard all non intra frames
AVBufferRef * data_ref
A reference to the buffer containing data.
#define CBS_UNIT_TYPES_COMPLEX(types, structure, free_func)
#define flags(name, subs,...)
@ SEI_TYPE_DISPLAY_ORIENTATION
#define cbs_h2645_replace_ps(ps_name, ps_var, id_element)
const H265RawSPS * active_sps
#define CBS_UNIT_TYPE_END_OF_LIST
H265RawPPS * pps[HEVC_MAX_PPS_COUNT]
RefStruct references.
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int cbs_h265_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
int ff_cbs_h2645_write_slice_data(CodedBitstreamContext *ctx, PutBitContext *pbc, const uint8_t *data, size_t data_size, int data_bit_start)
const H265RawPPS * active_pps
@ SEI_TYPE_BUFFERING_PERIOD
const H265RawVPS * active_vps
@ SEI_TYPE_RECOVERY_POINT
@ SEI_TYPE_DECODED_PICTURE_HASH
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define i(width, name, range_min, range_max)
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int nal_length_size, enum AVCodecID codec_id, int flags)
Split an input packet into NAL units.
void ff_cbs_sei_free_message_list(SEIRawMessageList *list)
Free all SEI messages in a message list.
@ AVDISCARD_NONREF
discard all non reference
@ SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
@ SEI_TYPE_ACTIVE_PARAMETER_SETS
void * priv_data
Format private data.
static av_cold void cbs_h265_flush(CodedBitstreamContext *ctx)
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
int nb_units
Number of units in this fragment.