FFmpeg
cbs_internal.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVCODEC_CBS_INTERNAL_H
20 #define AVCODEC_CBS_INTERNAL_H
21 
22 #include "avcodec.h"
23 #include "cbs.h"
24 #include "get_bits.h"
25 #include "put_bits.h"
26 
27 
29  // Unit content is a simple structure.
31  // Unit content contains some references to other structures, but all
32  // managed via buffer reference counting. The descriptor defines the
33  // structure offsets of every buffer reference.
35  // Unit content is something more complex. The descriptor defines
36  // special functions to manage the content.
38 };
39 
40 enum {
41  // Maximum number of unit types described by the same unit type
42  // descriptor.
44  // Maximum number of reference buffer offsets in any one unit.
46  // Special value used in a unit type descriptor to indicate that it
47  // applies to a large range of types rather than a set of discrete
48  // values.
50 };
51 
52 typedef const struct CodedBitstreamUnitTypeDescriptor {
53  // Number of entries in the unit_types array, or the special value
54  // CBS_UNIT_TYPE_RANGE to indicate that the range fields should be
55  // used instead.
57 
58  // Array of unit types that this entry describes.
60 
61  // Start and end of unit type range, used if nb_unit_types is
62  // CBS_UNIT_TYPE_RANGE.
65 
66  // The type of content described.
68  // The size of the structure which should be allocated to contain
69  // the decomposed content of this type of unit.
70  size_t content_size;
71 
72  // Number of entries in the ref_offsets array. Only used if the
73  // content_type is CBS_CONTENT_TYPE_INTERNAL_REFS.
75  // The structure must contain two adjacent elements:
76  // type *field;
77  // AVBufferRef *field_ref;
78  // where field points to something in the buffer referred to by
79  // field_ref. This offset is then set to offsetof(struct, field).
81 
82  void (*content_free)(void *opaque, uint8_t *data);
85 
86 typedef struct CodedBitstreamType {
88 
90 
91  // List of unit type descriptors for this codec.
92  // Terminated by a descriptor with nb_unit_types equal to zero.
94 
95  // Split frag->data into coded bitstream units, creating the
96  // frag->units array. Fill data but not content on each unit.
97  // The header argument should be set if the fragment came from
98  // a header block, which may require different parsing for some
99  // codecs (e.g. the AVCC header in H.264).
100  int (*split_fragment)(CodedBitstreamContext *ctx,
102  int header);
103 
104  // Read the unit->data bitstream and decompose it, creating
105  // unit->content.
107  CodedBitstreamUnit *unit);
108 
109  // Write the data bitstream from unit->content into pbc.
110  // Return value AVERROR(ENOSPC) indicates that pbc was too small.
111  int (*write_unit)(CodedBitstreamContext *ctx,
112  CodedBitstreamUnit *unit,
113  PutBitContext *pbc);
114 
115  // Read the data from all of frag->units and assemble it into
116  // a bitstream for the whole fragment.
117  int (*assemble_fragment)(CodedBitstreamContext *ctx,
118  CodedBitstreamFragment *frag);
119 
120  // Reset the codec internal state.
122 
123  // Free the codec internal state.
126 
127 
128 // Helper functions for trace output.
129 
131  const char *name);
132 
134  const char *name, const int *subscripts,
135  const char *bitstring, int64_t value);
136 
137 
138 // Helper functions for read/write of common bitstream elements, including
139 // generation of trace output.
140 
142  int width, const char *name,
143  const int *subscripts, uint32_t *write_to,
144  uint32_t range_min, uint32_t range_max);
145 
147  int width, const char *name,
148  const int *subscripts, uint32_t value,
149  uint32_t range_min, uint32_t range_max);
150 
152  int width, const char *name,
153  const int *subscripts, int32_t *write_to,
154  int32_t range_min, int32_t range_max);
155 
157  int width, const char *name,
158  const int *subscripts, int32_t value,
159  int32_t range_min, int32_t range_max);
160 
161 // The largest unsigned value representable in N bits, suitable for use as
162 // range_max in the above functions.
163 #define MAX_UINT_BITS(length) ((UINT64_C(1) << (length)) - 1)
164 
165 // The largest signed value representable in N bits, suitable for use as
166 // range_max in the above functions.
167 #define MAX_INT_BITS(length) ((INT64_C(1) << ((length) - 1)) - 1)
168 
169 // The smallest signed value representable in N bits, suitable for use as
170 // range_min in the above functions.
171 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
172 
173 
174 #define CBS_UNIT_TYPE_POD(type, structure) { \
175  .nb_unit_types = 1, \
176  .unit_types = { type }, \
177  .content_type = CBS_CONTENT_TYPE_POD, \
178  .content_size = sizeof(structure), \
179  }
180 #define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) { \
181  .nb_unit_types = 1, \
182  .unit_types = { type }, \
183  .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
184  .content_size = sizeof(structure), \
185  .nb_ref_offsets = 1, \
186  .ref_offsets = { offsetof(structure, ref_field) }, \
187  }
188 #define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) { \
189  .nb_unit_types = 1, \
190  .unit_types = { type }, \
191  .content_type = CBS_CONTENT_TYPE_COMPLEX, \
192  .content_size = sizeof(structure), \
193  .content_free = free_func, \
194  }
195 #define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
196 
197 
204 
205 
206 #endif /* AVCODEC_CBS_INTERNAL_H */
const CodedBitstreamUnitType unit_types[CBS_MAX_UNIT_TYPES]
Definition: cbs_internal.h:59
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
static void flush(AVCodecContext *avctx)
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *name, const int *subscripts, const char *bitstring, int64_t value)
Definition: cbs.c:437
uint8_t
int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, int32_t *write_to, int32_t range_min, int32_t range_max)
Definition: cbs.c:566
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:43
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:108
const CodedBitstreamUnitTypeDescriptor * unit_types
Definition: cbs_internal.h:93
bitstream reader API header.
Coded bitstream unit structure.
Definition: cbs.h:66
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
Definition: cbs.c:428
static const uint8_t header[24]
Definition: sdr2.c:67
int(* content_clone)(AVBufferRef **ref, CodedBitstreamUnit *unit)
Definition: cbs_internal.h:83
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:46
int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, uint32_t value, uint32_t range_min, uint32_t range_max)
Definition: cbs.c:530
const CodedBitstreamUnitType unit_type_range_end
Definition: cbs_internal.h:64
const CodedBitstreamType ff_cbs_type_mpeg2
Definition: cbs_mpeg2.c:421
size_t ref_offsets[CBS_MAX_REF_OFFSETS]
Definition: cbs_internal.h:80
const CodedBitstreamType ff_cbs_type_av1
Definition: cbs_av1.c:1255
int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, const int *subscripts, uint32_t *write_to, uint32_t range_min, uint32_t range_max)
Definition: cbs.c:487
#define width
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
Libavcodec external API header.
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:118
const CodedBitstreamType ff_cbs_type_jpeg
Definition: cbs_jpeg.c:461
CBSContentType
Definition: cbs_internal.h:28
Context structure for coded bitstream operations.
Definition: cbs.h:170
const CodedBitstreamType ff_cbs_type_h265
Definition: cbs_h2645.c:1527
A reference to a data buffer.
Definition: buffer.h:81
enum CBSContentType content_type
Definition: cbs_internal.h:67
int
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, const int *subscripts, int32_t value, int32_t range_min, int32_t range_max)
Definition: cbs.c:609
const CodedBitstreamUnitType unit_type_range_start
Definition: cbs_internal.h:63
void(* content_free)(void *opaque, uint8_t *data)
Definition: cbs_internal.h:82
const CodedBitstreamType ff_cbs_type_h264
Definition: cbs_h2645.c:1511
const CodedBitstreamType ff_cbs_type_vp9
Definition: cbs_vp9.c:649
const char * name
Definition: opengl_enc.c:102
bitstream writer API