2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVCODEC_CBS_INTERNAL_H
20 #define AVCODEC_CBS_INTERNAL_H
28 typedef struct CodedBitstreamType {
29 enum AVCodecID codec_id;
31 size_t priv_data_size;
33 // Split frag->data into coded bitstream units, creating the
34 // frag->units array. Fill data but not content on each unit.
35 // The header argument should be set if the fragment came from
36 // a header block, which may require different parsing for some
37 // codecs (e.g. the AVCC header in H.264).
38 int (*split_fragment)(CodedBitstreamContext *ctx,
39 CodedBitstreamFragment *frag,
42 // Read the unit->data bitstream and decompose it, creating
44 int (*read_unit)(CodedBitstreamContext *ctx,
45 CodedBitstreamUnit *unit);
47 // Write the data bitstream from unit->content into pbc.
48 // Return value AVERROR(ENOSPC) indicates that pbc was too small.
49 int (*write_unit)(CodedBitstreamContext *ctx,
50 CodedBitstreamUnit *unit,
53 // Read the data from all of frag->units and assemble it into
54 // a bitstream for the whole fragment.
55 int (*assemble_fragment)(CodedBitstreamContext *ctx,
56 CodedBitstreamFragment *frag);
58 // Free the codec internal state.
59 void (*close)(CodedBitstreamContext *ctx);
63 // Helper functions for trace output.
65 void ff_cbs_trace_header(CodedBitstreamContext *ctx,
68 void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
69 const char *name, const int *subscripts,
70 const char *bitstring, int64_t value);
73 // Helper functions for read/write of common bitstream elements, including
74 // generation of trace output.
76 int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
77 int width, const char *name,
78 const int *subscripts, uint32_t *write_to,
79 uint32_t range_min, uint32_t range_max);
81 int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
82 int width, const char *name,
83 const int *subscripts, uint32_t value,
84 uint32_t range_min, uint32_t range_max);
86 int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
87 int width, const char *name,
88 const int *subscripts, int32_t *write_to,
89 int32_t range_min, int32_t range_max);
91 int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
92 int width, const char *name,
93 const int *subscripts, int32_t value,
94 int32_t range_min, int32_t range_max);
96 // The largest unsigned value representable in N bits, suitable for use as
97 // range_max in the above functions.
98 #define MAX_UINT_BITS(length) ((UINT64_C(1) << (length)) - 1)
100 // The largest signed value representable in N bits, suitable for use as
101 // range_max in the above functions.
102 #define MAX_INT_BITS(length) ((INT64_C(1) << ((length) - 1)) - 1)
104 // The smallest signed value representable in N bits, suitable for use as
105 // range_min in the above functions.
106 #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1)))
109 extern const CodedBitstreamType ff_cbs_type_av1;
110 extern const CodedBitstreamType ff_cbs_type_h264;
111 extern const CodedBitstreamType ff_cbs_type_h265;
112 extern const CodedBitstreamType ff_cbs_type_jpeg;
113 extern const CodedBitstreamType ff_cbs_type_mpeg2;
114 extern const CodedBitstreamType ff_cbs_type_vp9;
117 #endif /* AVCODEC_CBS_INTERNAL_H */