33 unsigned int ctb_log2_size_y =
sps->log2_min_luma_coding_block_size_minus3 + 3 +
34 sps->log2_diff_max_min_luma_coding_block_size;
39#define HEADER(name) do { \
40 ff_cbs_trace_header(ctx, name); \
43#define CHECK(call) do { \
49#define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
50#define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
51#define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name)
52#define FUNC_NAME2_EXPORT(rw, codec, name) ff_cbs_ ## codec ## _ ## rw ## _ ## name
53#define FUNC_NAME1_EXPORT(rw, codec, name) FUNC_NAME2_EXPORT(rw, codec, name)
54#define FUNC_SEI(name) FUNC_NAME1_EXPORT(READWRITE, sei, name)
56#define SEI_FUNC(name, args) \
57static int FUNC_H265(name) args; \
58static int FUNC_H265(name ## _internal)(CodedBitstreamContext *ctx, \
59 RWContext *rw, void *cur, \
60 SEIMessageState *state) \
62 return FUNC_H265(name)(ctx, rw, cur, state); \
64static int FUNC_H265(name) args
66#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
68#define u(width, name, range_min, range_max) \
69 xu(width, name, current->name, range_min, range_max, 0, )
70#define flag(name) ub(1, name)
71#define ue(name, range_min, range_max) \
72 xue(name, current->name, range_min, range_max, 0, )
73#define i(width, name, range_min, range_max) \
74 xi(width, name, current->name, range_min, range_max, 0, )
75#define ib(width, name) \
76 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, )
77#define se(name, range_min, range_max) \
78 xse(name, current->name, range_min, range_max, 0, )
80#define us(width, name, range_min, range_max, subs, ...) \
81 xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
82#define ubs(width, name, subs, ...) \
83 xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
84#define flags(name, subs, ...) \
85 xu(1, name, current->name, 0, 1, subs, __VA_ARGS__)
86#define ues(name, range_min, range_max, subs, ...) \
87 xue(name, current->name, range_min, range_max, subs, __VA_ARGS__)
88#define is(width, name, range_min, range_max, subs, ...) \
89 xi(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
90#define ibs(width, name, subs, ...) \
91 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), subs, __VA_ARGS__)
92#define ses(name, range_min, range_max, subs, ...) \
93 xse(name, current->name, range_min, range_max, subs, __VA_ARGS__)
95#define fixed(width, name, value) do { \
96 av_unused uint32_t fixed_value = value; \
97 xu(width, name, fixed_value, value, value, 0, ); \
102#define READWRITE read
103#define RWContext GetBitContext
105#define ub(width, name) do { \
107 CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
109 current->name = value; \
111#define xu(width, name, var, range_min, range_max, subs, ...) do { \
113 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
114 SUBSCRIPTS(subs, __VA_ARGS__), \
115 &value, range_min, range_max)); \
118#define xue(name, var, range_min, range_max, subs, ...) do { \
120 CHECK(ff_cbs_read_ue_golomb(ctx, rw, #name, \
121 SUBSCRIPTS(subs, __VA_ARGS__), \
122 &value, range_min, range_max)); \
125#define xi(width, name, var, range_min, range_max, subs, ...) do { \
127 CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
128 SUBSCRIPTS(subs, __VA_ARGS__), \
129 &value, range_min, range_max)); \
132#define xse(name, var, range_min, range_max, subs, ...) do { \
134 CHECK(ff_cbs_read_se_golomb(ctx, rw, #name, \
135 SUBSCRIPTS(subs, __VA_ARGS__), \
136 &value, range_min, range_max)); \
141#define infer(name, value) do { \
142 current->name = value; \
145#define more_rbsp_data(var) ((var) = ff_cbs_h2645_read_more_rbsp_data(rw))
147#define bit_position(rw) (get_bits_count(rw))
148#define byte_alignment(rw) (get_bits_count(rw) % 8)
150#define allocate(name, size) do { \
151 name ## _ref = av_buffer_allocz(size + \
152 AV_INPUT_BUFFER_PADDING_SIZE); \
154 return AVERROR(ENOMEM); \
155 name = (void *)name ## _ref->data; \
158#define FUNC(name) FUNC_H265(name)
176#undef allocate_struct
180#define READWRITE write
181#define RWContext PutBitContext
183#define ub(width, name) do { \
184 uint32_t value = current->name; \
185 CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
188#define xu(width, name, var, range_min, range_max, subs, ...) do { \
189 uint32_t value = var; \
190 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
191 SUBSCRIPTS(subs, __VA_ARGS__), \
192 value, range_min, range_max)); \
194#define xue(name, var, range_min, range_max, subs, ...) do { \
195 uint32_t value = var; \
196 CHECK(ff_cbs_write_ue_golomb(ctx, rw, #name, \
197 SUBSCRIPTS(subs, __VA_ARGS__), \
198 value, range_min, range_max)); \
200#define xi(width, name, var, range_min, range_max, subs, ...) do { \
201 int32_t value = var; \
202 CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
203 SUBSCRIPTS(subs, __VA_ARGS__), \
204 value, range_min, range_max)); \
206#define xse(name, var, range_min, range_max, subs, ...) do { \
207 int32_t value = var; \
208 CHECK(ff_cbs_write_se_golomb(ctx, rw, #name, \
209 SUBSCRIPTS(subs, __VA_ARGS__), \
210 value, range_min, range_max)); \
213#define infer(name, value) do { \
214 if (current->name != (value)) { \
215 av_log(ctx->log_ctx, AV_LOG_ERROR, \
216 "%s does not match inferred value: " \
217 "%"PRId64", but should be %"PRId64".\n", \
218 #name, (int64_t)current->name, (int64_t)(value)); \
219 return AVERROR_INVALIDDATA; \
223#define more_rbsp_data(var) (var)
225#define bit_position(rw) (put_bits_count(rw))
226#define byte_alignment(rw) (put_bits_count(rw) % 8)
228#define allocate(name, size) do { \
230 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s must be set " \
231 "for writing.\n", #name); \
232 return AVERROR_INVALIDDATA; \
236#define FUNC(name) FUNC_H265(name)
277 size_t size, start, end;
278 int i, j, nb_arrays, nal_unit_type, nb_nals,
version;
287 version = bytestream2_get_byte(&gbc);
297 nb_arrays = bytestream2_get_byte(&gbc);
298 for (
i = 0;
i < nb_arrays;
i++) {
299 nal_unit_type = bytestream2_get_byte(&gbc) & 0x3f;
300 nb_nals = bytestream2_get_be16(&gbc);
303 for (j = 0; j < nb_nals; j++) {
306 size = bytestream2_get_be16(&gbc);
314 frag->
data + start, end - start,
319 "HVCC array %d (%d NAL units of type %d).\n",
320 i, nb_nals, nal_unit_type);
347#define cbs_h2645_replace_ps(ps_name, ps_var, id_element) \
348static int cbs_h265_replace_ ## ps_var(CodedBitstreamContext *ctx, \
349 CodedBitstreamUnit *unit) \
351 CodedBitstreamH265Context *priv = ctx->priv_data; \
352 H265Raw## ps_name *ps_var = unit->content; \
353 unsigned int id = ps_var->id_element; \
354 int err = ff_cbs_make_unit_refcounted(ctx, unit); \
357 if (priv->ps_var[id] == priv->active_ ## ps_var) \
358 priv->active_ ## ps_var = NULL ; \
359 av_assert0(unit->content_ref); \
360 av_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
378 err = ff_cbs_alloc_unit_content(
ctx, unit);
382 switch (unit->
type) {
387 err = cbs_h265_read_vps(
ctx, &gbc,
vps);
391 err = cbs_h265_replace_vps(
ctx, unit);
400 err = cbs_h265_read_sps(
ctx, &gbc,
sps);
404 err = cbs_h265_replace_sps(
ctx, unit);
414 err = cbs_h265_read_pps(
ctx, &gbc,
pps);
418 err = cbs_h265_replace_pps(
ctx, unit);
444 err = cbs_h265_read_slice_segment_header(
ctx, &gbc, &slice->
header);
465 err = cbs_h265_read_aud(
ctx, &gbc, unit->
content);
473 err = cbs_h265_read_filler(
ctx, &gbc, unit->
content);
482 err = cbs_h265_read_sei(
ctx, &gbc, unit->
content,
503 switch (unit->
type) {
508 err = cbs_h265_write_vps(
ctx, pbc,
vps);
512 err = cbs_h265_replace_vps(
ctx, unit);
522 err = cbs_h265_write_sps(
ctx, pbc,
sps);
526 err = cbs_h265_replace_sps(
ctx, unit);
536 err = cbs_h265_write_pps(
ctx, pbc,
pps);
540 err = cbs_h265_replace_pps(
ctx, unit);
565 err = cbs_h265_write_slice_segment_header(
ctx, pbc, &slice->
header);
583 err = cbs_h265_write_aud(
ctx, pbc, unit->
content);
591 err = cbs_h265_write_filler(
ctx, pbc, unit->
content);
600 err = cbs_h265_write_sei(
ctx, pbc, unit->
content,
610 "NAL unit type %"PRIu32
".\n", unit->
type);
626 switch (unit->
type) {
661 "h265 slice header is null, missing decompose?\n");
671 switch (unit->
type) {
760#define SEI_MESSAGE_RW(codec, name) \
761 .read = cbs_ ## codec ## _read_ ## name ## _internal, \
762 .write = cbs_ ## codec ## _write_ ## name ## _internal
842 .read_unit = &cbs_h265_read_nal_unit,
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_tell(const GetByteContext *g)
int ff_cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const H2645Packet *packet)
int ff_cbs_h2645_write_slice_data(CodedBitstreamContext *ctx, PutBitContext *pbc, const uint8_t *data, size_t data_size, int data_bit_start)
int ff_cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
int ff_cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H264RawHRD *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
#define SEI_MESSAGE_RW(codec, name)
static av_cold void cbs_h265_flush(CodedBitstreamContext *ctx)
static CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[]
static av_cold void cbs_h265_close(CodedBitstreamContext *ctx)
const CodedBitstreamType ff_cbs_type_h265
const SEIMessageTypeDescriptor ff_cbs_sei_h265_types[]
static void cbs_h265_pic_size_in_ctbs(const H265RawSPS *sps, unsigned int *width, unsigned int *height)
static int cbs_h265_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
static int cbs_h265_discarded_nal_unit(CodedBitstreamContext *ctx, const CodedBitstreamUnit *unit, enum AVDiscard skip)
static void cbs_h265_free_sei(AVRefStructOpaque unused, void *content)
#define cbs_h2645_replace_ps(ps_name, ps_var, id_element)
static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
static int FUNC vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static int FUNC extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *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 CBS_UNIT_TYPES_COMPLEX(types, structure, free_func)
#define CBS_UNIT_RANGE_INTERNAL_REF(range_start, range_end, structure, ref_field)
void ff_cbs_sei_free_message_list(SEIRawMessageList *list)
Free all SEI messages in a message list.
#define SEI_MESSAGE_TYPE_END
#define AV_CEIL_RSHIFT(a, b)
void(* flush)(AVBSFContext *ctx)
bitstream reader API header.
static int get_bits_count(const GetBitContext *s)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AVDISCARD_ALL
discard all
@ AVDISCARD_NONKEY
discard all frames except keyframes
@ AVDISCARD_BIDIR
discard all bidirectional frames
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
@ AVDISCARD_NONINTRA
discard all non intra frames
@ AVDISCARD_NONREF
discard all non reference
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ H2645_FLAG_SMALL_PADDING
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
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.
Memory handling functions.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
static const uint8_t header[24]
@ SEI_TYPE_ALPHA_CHANNEL_INFO
@ SEI_TYPE_DECODED_PICTURE_HASH
@ SEI_TYPE_RECOVERY_POINT
@ SEI_TYPE_ACTIVE_PARAMETER_SETS
@ SEI_TYPE_DISPLAY_ORIENTATION
@ SEI_TYPE_THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO
@ SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
@ SEI_TYPE_BUFFERING_PERIOD
#define FF_ARRAY_ELEMS(a)
Context structure for coded bitstream operations.
Coded bitstream fragment structure, combining one or more units.
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.
const H265RawVPS * active_vps
const H265RawSPS * active_sps
H265RawVPS * vps[HEVC_MAX_VPS_COUNT]
RefStruct references.
CodedBitstreamH2645Context common
H265RawSPS * sps[HEVC_MAX_SPS_COUNT]
RefStruct references.
const H265RawPPS * active_pps
H265RawPPS * pps[HEVC_MAX_PPS_COUNT]
RefStruct references.
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.
H265RawSliceHeader header
RefStruct is an API for creating reference-counted objects with minimal overhead.