1 /*
2 * AV1 common parsing code
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef AVCODEC_AV1_PARSE_H
22 #define AVCODEC_AV1_PARSE_H
23
25 #include <stdint.h>
26
30
33
34 // OBU header fields + max leb128 length
35 #define MAX_OBU_HEADER_SIZE (2 + 8)
36
38 /** Size of payload */
41
42 /**
43 * Size, in bits, of just the data, excluding the trailing_one_bit and
44 * any trailing padding.
45 */
47
48 /** Size of entire OBU, including header */
51
52 /** GetBitContext initialized to the start of the payload */
54
56
60
61 /** An input packet split into OBUs */
68
69 /**
70 * Extract an OBU from a raw bitstream.
71 *
72 * @note This function does not copy or store any bitstream data. All
73 * the pointers in the AV1OBU structure will be valid as long
74 * as the input buffer also is.
75 */
77 void *logctx);
78
79 /**
80 * Split an input packet into OBUs.
81 *
82 * @note This function does not copy or store any bitstream data. All
83 * the pointers in the AV1Packet structure will be valid as
84 * long as the input buffer also is.
85 */
87 void *logctx);
88
89 /**
90 * Free all the allocated memory in the packet.
91 */
93
97
98 for (
i = 0;
i < 8;
i++) {
100 ret |= (int64_t)(
byte & 0x7f) << (
i * 7);
101 if (!(byte & 0x80))
102 break;
103 }
105 }
106
108 int64_t *obu_size,
int *start_pos,
int *
type,
109 int *temporal_id, int *spatial_id)
110 {
112 int ret, extension_flag, has_size_flag;
114
118
119 if (
get_bits1(&gb) != 0)
// obu_forbidden_bit
121
126
127 if (extension_flag) {
130 skip_bits(&gb, 3);
// extension_header_reserved_3bits
131 } else {
132 *temporal_id = *spatial_id = 0;
133 }
134
135 *obu_size = has_size_flag ?
leb128(&gb)
136 : buf_size - 1 - extension_flag;
137
140
142
143 size = *obu_size + *start_pos;
144
147
149 }
150
152 {
153 int v;
154
155 /* There are no trailing bits on these */
159 if (
size > INT_MAX / 8)
161 else
163 }
164
165 while (
size > 0 && buf[
size - 1] == 0)
167
169 return 0;
170
172
173 if (
size > INT_MAX / 8)
176
177 /* Remove the trailing_one_bit and following trailing zeros */
178 if (v)
180
182 }
183
184 #endif /* AVCODEC_AV1_PARSE_H */