1 /*
2 * AVS2-P2/IEEE1857.4 video parser.
3 * Copyright (c) 2018 Huiwen Ren <hwrenx@gmail.com>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
26
28 {
31 int cur = 0;
32
33 if (!pic_found) {
34 for (; cur < buf_size; ++cur) {
37 cur++;
38 pic_found = 1;
39 break;
40 }
41 }
42 }
43
44 if (pic_found) {
45 if (!buf_size)
47 for (; cur < buf_size; cur++) {
52 return cur - 3;
53 }
54 }
55 }
56
59
61 }
62
65 {
69 int chroma, sample_precision, encoding_precision = 1;
70 // sample_precision and encoding_precision is 3 bits
71 static const uint8_t precision[8] = { 0, 8, 10 };
72 unsigned aspect_ratio;
73 unsigned frame_rate_code;
74 int low_delay;
76 // update buf_size_min if parse more deeper
77 const int buf_size_min = 15;
78
79 if (buf_size < buf_size_min)
80 return;
81
84
87
90
91 // progressive_sequence u(1)
92 // field_coded_sequence u(1)
94
97
101 encoding_precision =
get_bits(&gb, 3);
102
105
106 // bit_rate_lower u(18)
107 // marker_bit f(1)
108 // bit_rate_upper u(12)
110
112
122
124 "AVS2 parse seq HDR: profile %x, level %x, "
125 "width %d, height %d, "
126 "chroma %d, sample_precision %d bits, encoding_precision %d bits, "
127 "aspect_ratio 0x%x, framerate %d/%d, low_delay %d\n",
130 chroma, precision[sample_precision], precision[encoding_precision],
132 }
133
136 {
137 if (buf_size < 5)
138 return;
139
140 if (!(buf[0] == 0x0 && buf[1] == 0x0 && buf[2] == 0x1))
141 return;
142
143 switch (buf[3]) {
146 return;
150 return;
153 if (buf_size > 9) {
154 int pic_code_type = buf[8] & 0x3;
155 if (pic_code_type == 1)
157 else if (pic_code_type == 3)
159 else
161 }
162 return;
163 }
164 }
165
167 const uint8_t **poutbuf, int *poutbuf_size,
168 const uint8_t *buf, int buf_size)
169 {
171 int next;
172
174 next = buf_size;
175 } else {
179 *poutbuf_size = 0;
180 return buf_size;
181 }
182 }
183
185
186 *poutbuf = buf;
187 *poutbuf_size = buf_size;
188
189 return next;
190 }
191
197 };