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 <stdint.h>
23 
24 #include "libavutil/buffer.h"
25 #include "libavutil/log.h"
26 
27 #include "cbs.h"
28 #include "codec_id.h"
29 #include "get_bits.h"
30 #include "put_bits.h"
31 
32 
34  // Unit content is a simple structure.
36  // Unit content contains some references to other structures, but all
37  // managed via buffer reference counting. The descriptor defines the
38  // structure offsets of every buffer reference.
40  // Unit content is something more complex. The descriptor defines
41  // special functions to manage the content.
43 };
44 
45 enum {
46  // Maximum number of unit types described by the same unit type
47  // descriptor.
49  // Maximum number of reference buffer offsets in any one unit.
51  // Special value used in a unit type descriptor to indicate that it
52  // applies to a large range of types rather than a set of discrete
53  // values.
55 };
56 
57 typedef const struct CodedBitstreamUnitTypeDescriptor {
58  // Number of entries in the unit_types array, or the special value
59  // CBS_UNIT_TYPE_RANGE to indicate that the range fields should be
60  // used instead.
62 
63  // Array of unit types that this entry describes.
65 
66  // Start and end of unit type range, used if nb_unit_types is
67  // CBS_UNIT_TYPE_RANGE.
70 
71  // The type of content described.
73  // The size of the structure which should be allocated to contain
74  // the decomposed content of this type of unit.
75  size_t content_size;
76 
77  // Number of entries in the ref_offsets array. Only used if the
78  // content_type is CBS_CONTENT_TYPE_INTERNAL_REFS.
80  // The structure must contain two adjacent elements:
81  // type *field;
82  // AVBufferRef *field_ref;
83  // where field points to something in the buffer referred to by
84  // field_ref. This offset is then set to offsetof(struct, field).
86 
87  void (*content_free)(void *opaque, uint8_t *data);
90 
91 typedef struct CodedBitstreamType {
93 
94  // A class for the private data, used to declare private AVOptions.
95  // This field is NULL for types that do not declare any options.
96  // If this field is non-NULL, the first member of the filter private data
97  // must be a pointer to AVClass.
99 
101 
102  // List of unit type descriptors for this codec.
103  // Terminated by a descriptor with nb_unit_types equal to zero.
105 
106  // Split frag->data into coded bitstream units, creating the
107  // frag->units array. Fill data but not content on each unit.
108  // The header argument should be set if the fragment came from
109  // a header block, which may require different parsing for some
110  // codecs (e.g. the AVCC header in H.264).
113  int header);
114 
115  // Read the unit->data bitstream and decompose it, creating
116  // unit->content.
118  CodedBitstreamUnit *unit);
119 
120  // Write the data bitstream from unit->content into pbc.
121  // Return value AVERROR(ENOSPC) indicates that pbc was too small.
123  CodedBitstreamUnit *unit,
124  PutBitContext *pbc);
125 
126  // Read the data from all of frag->units and assemble it into
127  // a bitstream for the whole fragment.
129  CodedBitstreamFragment *frag);
130 
131  // Reset the codec internal state.
133 
134  // Free the codec internal state.
137 
138 
139 // Helper functions for trace output.
140 
142  const char *name);
143 
145  const char *name, const int *subscripts,
146  const char *bitstring, int64_t value);
147 
148 
149 // Helper functions for read/write of common bitstream elements, including
150 // generation of trace output.
151 
153  int width, const char *name,
154  const int *subscripts, uint32_t *write_to,
155  uint32_t range_min, uint32_t range_max);
156 
158  int width, const char *name,
159  const int *subscripts, uint32_t value,
160  uint32_t range_min, uint32_t range_max);
161 
163  int width, const char *name,
164  const int *subscripts, int32_t *write_to,
165  int32_t range_min, int32_t range_max);
166 
168  int width, const char *name,
169  const int *subscripts, int32_t value,
170  int32_t range_min, int32_t range_max);
171 
172 // The largest unsigned value representable in N bits, suitable for use as
173 // range_max in the above functions.
174 #define MAX_UINT_BITS(length) ((UINT64_C(1) << (length)) - 1)
175 
176 // The largest signed value representable in N bits, suitable for use as
177 // range_max in the above functions.
178 #define MAX_INT_BITS(length) ((INT64_C(1) << ((length) - 1)) - 1)
179 
180 // The smallest signed value representable in N bits, suitable for use as
181 // range_min in the above functions.
182 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
183 
184 
185 #define CBS_UNIT_TYPE_POD(type, structure) { \
186  .nb_unit_types = 1, \
187  .unit_types = { type }, \
188  .content_type = CBS_CONTENT_TYPE_POD, \
189  .content_size = sizeof(structure), \
190  }
191 #define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) { \
192  .nb_unit_types = 1, \
193  .unit_types = { type }, \
194  .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
195  .content_size = sizeof(structure), \
196  .nb_ref_offsets = 1, \
197  .ref_offsets = { offsetof(structure, ref_field) }, \
198  }
199 #define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) { \
200  .nb_unit_types = 1, \
201  .unit_types = { type }, \
202  .content_type = CBS_CONTENT_TYPE_COMPLEX, \
203  .content_size = sizeof(structure), \
204  .content_free = free_func, \
205  }
206 #define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
207 
208 
215 
216 
217 #endif /* AVCODEC_CBS_INTERNAL_H */
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
CodedBitstreamUnitTypeDescriptor::unit_type_range_start
const CodedBitstreamUnitType unit_type_range_start
Definition: cbs_internal.h:68
CodedBitstreamType::close
void(* close)(CodedBitstreamContext *ctx)
Definition: cbs_internal.h:135
CBS_CONTENT_TYPE_POD
@ CBS_CONTENT_TYPE_POD
Definition: cbs_internal.h:35
CodedBitstreamType::priv_class
const AVClass * priv_class
Definition: cbs_internal.h:98
CodedBitstreamUnitTypeDescriptor::content_type
enum CBSContentType content_type
Definition: cbs_internal.h:72
ff_cbs_type_vp9
const CodedBitstreamType ff_cbs_type_vp9
Definition: cbs_vp9.c:649
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:173
data
const char data[16]
Definition: mxf.c:143
cbs.h
CodedBitstreamUnitTypeDescriptor::content_free
void(* content_free)(void *opaque, uint8_t *data)
Definition: cbs_internal.h:87
ff_cbs_read_signed
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:618
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:69
CodedBitstreamUnitTypeDescriptor::ref_offsets
size_t ref_offsets[CBS_MAX_REF_OFFSETS]
Definition: cbs_internal.h:85
ff_cbs_write_unsigned
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:582
GetBitContext
Definition: get_bits.h:62
CBS_CONTENT_TYPE_INTERNAL_REFS
@ CBS_CONTENT_TYPE_INTERNAL_REFS
Definition: cbs_internal.h:39
ff_cbs_trace_syntax_element
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:489
CodedBitstreamUnitTypeDescriptor
Definition: cbs_internal.h:57
ff_cbs_type_mpeg2
const CodedBitstreamType ff_cbs_type_mpeg2
Definition: cbs_mpeg2.c:421
codec_id.h
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:121
width
#define width
CodedBitstreamUnitTypeDescriptor::nb_unit_types
int nb_unit_types
Definition: cbs_internal.h:61
ff_cbs_read_unsigned
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:539
ctx
AVFormatContext * ctx
Definition: movenc.c:48
get_bits.h
CodedBitstreamType::codec_id
enum AVCodecID codec_id
Definition: cbs_internal.h:92
PutBitContext
Definition: put_bits.h:49
CodedBitstreamType::read_unit
int(* read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_internal.h:117
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
CodedBitstreamUnitTypeDescriptor::content_clone
int(* content_clone)(AVBufferRef **ref, CodedBitstreamUnit *unit)
Definition: cbs_internal.h:88
CodedBitstreamUnitTypeDescriptor::unit_types
const CodedBitstreamUnitType unit_types[CBS_MAX_UNIT_TYPES]
Definition: cbs_internal.h:64
ff_cbs_trace_header
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
Definition: cbs.c:480
CBSContentType
CBSContentType
Definition: cbs_internal.h:33
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
ff_cbs_type_jpeg
const CodedBitstreamType ff_cbs_type_jpeg
Definition: cbs_jpeg.c:461
CodedBitstreamType::unit_types
const CodedBitstreamUnitTypeDescriptor * unit_types
Definition: cbs_internal.h:104
CBS_CONTENT_TYPE_COMPLEX
@ CBS_CONTENT_TYPE_COMPLEX
Definition: cbs_internal.h:42
header
static const uint8_t header[24]
Definition: sdr2.c:67
buffer.h
CodedBitstreamType
Definition: cbs_internal.h:91
CodedBitstreamUnitTypeDescriptor::nb_ref_offsets
int nb_ref_offsets
Definition: cbs_internal.h:79
ff_cbs_type_av1
const CodedBitstreamType ff_cbs_type_av1
Definition: cbs_av1.c:1321
CodedBitstreamType::priv_data_size
size_t priv_data_size
Definition: cbs_internal.h:100
CodedBitstreamUnitTypeDescriptor::unit_type_range_end
const CodedBitstreamUnitType unit_type_range_end
Definition: cbs_internal.h:69
CBS_UNIT_TYPE_RANGE
@ CBS_UNIT_TYPE_RANGE
Definition: cbs_internal.h:54
log.h
CodedBitstreamType::write_unit
int(* write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition: cbs_internal.h:122
CBS_MAX_UNIT_TYPES
@ CBS_MAX_UNIT_TYPES
Definition: cbs_internal.h:48
ff_cbs_write_signed
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:661
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
CBS_MAX_REF_OFFSETS
@ CBS_MAX_REF_OFFSETS
Definition: cbs_internal.h:50
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:46
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
ff_cbs_type_h265
const CodedBitstreamType ff_cbs_type_h265
Definition: cbs_h2645.c:1492
CodedBitstreamType::flush
void(* flush)(CodedBitstreamContext *ctx)
Definition: cbs_internal.h:132
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
CodedBitstreamUnitTypeDescriptor::content_size
size_t content_size
Definition: cbs_internal.h:75
int32_t
int32_t
Definition: audioconvert.c:56
CodedBitstreamType::assemble_fragment
int(* assemble_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs_internal.h:128
CodedBitstreamType::split_fragment
int(* split_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition: cbs_internal.h:111
int
int
Definition: ffmpeg_filter.c:156
put_bits.h
ff_cbs_type_h264
const CodedBitstreamType ff_cbs_type_h264
Definition: cbs_h2645.c:1476