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 
89  // A class for the private data, used to declare private AVOptions.
90  // This field is NULL for types that do not declare any options.
91  // If this field is non-NULL, the first member of the filter private data
92  // must be a pointer to AVClass.
94 
96 
97  // List of unit type descriptors for this codec.
98  // Terminated by a descriptor with nb_unit_types equal to zero.
100 
101  // Split frag->data into coded bitstream units, creating the
102  // frag->units array. Fill data but not content on each unit.
103  // The header argument should be set if the fragment came from
104  // a header block, which may require different parsing for some
105  // codecs (e.g. the AVCC header in H.264).
108  int header);
109 
110  // Read the unit->data bitstream and decompose it, creating
111  // unit->content.
113  CodedBitstreamUnit *unit);
114 
115  // Write the data bitstream from unit->content into pbc.
116  // Return value AVERROR(ENOSPC) indicates that pbc was too small.
118  CodedBitstreamUnit *unit,
119  PutBitContext *pbc);
120 
121  // Read the data from all of frag->units and assemble it into
122  // a bitstream for the whole fragment.
124  CodedBitstreamFragment *frag);
125 
126  // Reset the codec internal state.
128 
129  // Free the codec internal state.
132 
133 
134 // Helper functions for trace output.
135 
137  const char *name);
138 
140  const char *name, const int *subscripts,
141  const char *bitstring, int64_t value);
142 
143 
144 // Helper functions for read/write of common bitstream elements, including
145 // generation of trace output.
146 
148  int width, const char *name,
149  const int *subscripts, uint32_t *write_to,
150  uint32_t range_min, uint32_t range_max);
151 
153  int width, const char *name,
154  const int *subscripts, uint32_t value,
155  uint32_t range_min, uint32_t range_max);
156 
158  int width, const char *name,
159  const int *subscripts, int32_t *write_to,
160  int32_t range_min, int32_t range_max);
161 
163  int width, const char *name,
164  const int *subscripts, int32_t value,
165  int32_t range_min, int32_t range_max);
166 
167 // The largest unsigned value representable in N bits, suitable for use as
168 // range_max in the above functions.
169 #define MAX_UINT_BITS(length) ((UINT64_C(1) << (length)) - 1)
170 
171 // The largest signed value representable in N bits, suitable for use as
172 // range_max in the above functions.
173 #define MAX_INT_BITS(length) ((INT64_C(1) << ((length) - 1)) - 1)
174 
175 // The smallest signed value representable in N bits, suitable for use as
176 // range_min in the above functions.
177 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
178 
179 
180 #define CBS_UNIT_TYPE_POD(type, structure) { \
181  .nb_unit_types = 1, \
182  .unit_types = { type }, \
183  .content_type = CBS_CONTENT_TYPE_POD, \
184  .content_size = sizeof(structure), \
185  }
186 #define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field) { \
187  .nb_unit_types = 1, \
188  .unit_types = { type }, \
189  .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS, \
190  .content_size = sizeof(structure), \
191  .nb_ref_offsets = 1, \
192  .ref_offsets = { offsetof(structure, ref_field) }, \
193  }
194 #define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func) { \
195  .nb_unit_types = 1, \
196  .unit_types = { type }, \
197  .content_type = CBS_CONTENT_TYPE_COMPLEX, \
198  .content_size = sizeof(structure), \
199  .content_free = free_func, \
200  }
201 #define CBS_UNIT_TYPE_END_OF_LIST { .nb_unit_types = 0 }
202 
203 
210 
211 
212 #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:63
CodedBitstreamType::close
void(* close)(CodedBitstreamContext *ctx)
Definition: cbs_internal.h:130
CBS_CONTENT_TYPE_POD
@ CBS_CONTENT_TYPE_POD
Definition: cbs_internal.h:30
CodedBitstreamType::priv_class
const AVClass * priv_class
Definition: cbs_internal.h:93
CodedBitstreamUnitTypeDescriptor::content_type
enum CBSContentType content_type
Definition: cbs_internal.h:67
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:170
data
const char data[16]
Definition: mxf.c:142
cbs.h
CodedBitstreamUnitTypeDescriptor::content_free
void(* content_free)(void *opaque, uint8_t *data)
Definition: cbs_internal.h:82
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:582
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:66
CodedBitstreamUnitTypeDescriptor::ref_offsets
size_t ref_offsets[CBS_MAX_REF_OFFSETS]
Definition: cbs_internal.h:80
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:546
GetBitContext
Definition: get_bits.h:61
CBS_CONTENT_TYPE_INTERNAL_REFS
@ CBS_CONTENT_TYPE_INTERNAL_REFS
Definition: cbs_internal.h:34
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:453
CodedBitstreamUnitTypeDescriptor
Definition: cbs_internal.h:52
ff_cbs_type_mpeg2
const CodedBitstreamType ff_cbs_type_mpeg2
Definition: cbs_mpeg2.c:421
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:118
width
#define width
CodedBitstreamUnitTypeDescriptor::nb_unit_types
int nb_unit_types
Definition: cbs_internal.h:56
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:503
ctx
AVFormatContext * ctx
Definition: movenc.c:48
get_bits.h
CodedBitstreamType::codec_id
enum AVCodecID codec_id
Definition: cbs_internal.h:87
PutBitContext
Definition: put_bits.h:44
int32_t
int32_t
Definition: audio_convert.c:194
CodedBitstreamType::read_unit
int(* read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_internal.h:112
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
CodedBitstreamUnitTypeDescriptor::content_clone
int(* content_clone)(AVBufferRef **ref, CodedBitstreamUnit *unit)
Definition: cbs_internal.h:83
CodedBitstreamUnitTypeDescriptor::unit_types
const CodedBitstreamUnitType unit_types[CBS_MAX_UNIT_TYPES]
Definition: cbs_internal.h:59
ff_cbs_trace_header
void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name)
Definition: cbs.c:444
CBSContentType
CBSContentType
Definition: cbs_internal.h:28
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:46
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:99
CBS_CONTENT_TYPE_COMPLEX
@ CBS_CONTENT_TYPE_COMPLEX
Definition: cbs_internal.h:37
header
static const uint8_t header[24]
Definition: sdr2.c:67
CodedBitstreamType
Definition: cbs_internal.h:86
CodedBitstreamUnitTypeDescriptor::nb_ref_offsets
int nb_ref_offsets
Definition: cbs_internal.h:74
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:95
CodedBitstreamUnitTypeDescriptor::unit_type_range_end
const CodedBitstreamUnitType unit_type_range_end
Definition: cbs_internal.h:64
CBS_UNIT_TYPE_RANGE
@ CBS_UNIT_TYPE_RANGE
Definition: cbs_internal.h:49
CodedBitstreamType::write_unit
int(* write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition: cbs_internal.h:117
CBS_MAX_UNIT_TYPES
@ CBS_MAX_UNIT_TYPES
Definition: cbs_internal.h:43
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:625
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
uint8_t
uint8_t
Definition: audio_convert.c:194
avcodec.h
CBS_MAX_REF_OFFSETS
@ CBS_MAX_REF_OFFSETS
Definition: cbs_internal.h:45
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:43
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:127
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:84
CodedBitstreamUnitTypeDescriptor::content_size
size_t content_size
Definition: cbs_internal.h:70
CodedBitstreamType::assemble_fragment
int(* assemble_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs_internal.h:123
CodedBitstreamType::split_fragment
int(* split_fragment)(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition: cbs_internal.h:106
int
int
Definition: ffmpeg_filter.c:170
put_bits.h
ff_cbs_type_h264
const CodedBitstreamType ff_cbs_type_h264
Definition: cbs_h2645.c:1476