]> git.sesse.net Git - ffmpeg/blob - libavcodec/cbs_internal.h
Merge commit '662558f985f50834eebe82d6b6854c66f33ab320'
[ffmpeg] / libavcodec / cbs_internal.h
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
28 typedef struct CodedBitstreamType {
29     enum AVCodecID codec_id;
30
31     size_t priv_data_size;
32
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,
40                           int header);
41
42     // Read the unit->data bitstream and decompose it, creating
43     // unit->content.
44     int (*read_unit)(CodedBitstreamContext *ctx,
45                      CodedBitstreamUnit *unit);
46
47     // Write the unit->data bitstream from unit->content.
48     int (*write_unit)(CodedBitstreamContext *ctx,
49                       CodedBitstreamUnit *unit);
50
51     // Read the data from all of frag->units and assemble it into
52     // a bitstream for the whole fragment.
53     int (*assemble_fragment)(CodedBitstreamContext *ctx,
54                              CodedBitstreamFragment *frag);
55
56     // Free the codec internal state.
57     void (*close)(CodedBitstreamContext *ctx);
58 } CodedBitstreamType;
59
60
61 // Helper functions for trace output.
62
63 void ff_cbs_trace_header(CodedBitstreamContext *ctx,
64                          const char *name);
65
66 void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
67                                  const char *name, const int *subscripts,
68                                  const char *bitstring, int64_t value);
69
70
71 // Helper functions for read/write of common bitstream elements, including
72 // generation of trace output.
73
74 int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
75                          int width, const char *name,
76                          const int *subscripts, uint32_t *write_to,
77                          uint32_t range_min, uint32_t range_max);
78
79 int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
80                           int width, const char *name,
81                           const int *subscripts, uint32_t value,
82                           uint32_t range_min, uint32_t range_max);
83
84 // The largest value representable in N bits, suitable for use as
85 // range_max in the above functions.
86 #define MAX_UINT_BITS(length) ((UINT64_C(1) << (length)) - 1)
87
88
89 extern const CodedBitstreamType ff_cbs_type_h264;
90 extern const CodedBitstreamType ff_cbs_type_h265;
91 extern const CodedBitstreamType ff_cbs_type_mpeg2;
92 extern const CodedBitstreamType ff_cbs_type_vp9;
93
94
95 #endif /* AVCODEC_CBS_INTERNAL_H */