1 /*
2 * Dirac parser
3 *
4 * Copyright (c) 2007-2008 Marco Gerards <marco@gnu.org>
5 * Copyright (c) 2008 BBC, Anuradha Suraparaju <asuraparaju@gmail.com>
6 *
7 * This file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 /**
25 * @file
26 * Dirac Parser
27 * @author Marco Gerards <marco@gnu.org>
28 */
29
30 #include <string.h>
31
34
36
37 #define DIRAC_PARSE_INFO_PREFIX 0x42424344
38
39 /**
40 * Find the end of the current frame in the bitstream.
41 * @return the position of the first byte of the next frame or -1
42 */
55
58 {
60 int i = 0;
61
63 for (i = 0; i < buf_size; i++) {
64 state = (state << 8) | buf[i];
66 state = -1;
70 break;
71 }
72 }
73 }
74
77 for (; i < buf_size; i++) {
82 } else {
84 break;
85 }
86 } else
87 state = (state << 8) | buf[i];
88 }
89 }
91 return -1;
92 }
93
99
102 {
105 if (start < pc->
buffer || (start + 13 > end))
106 return 0;
108
111
114
115 return 1;
116 }
117
120 {
124
130 if (*buf_size == 0 && pc->
buffer[4] == 0x10) {
132 *buf_size = pc->
index;
133 return 0;
134 }
135 }
136
137 if (next == -1) {
138 /* Found a possible frame start but not a frame end */
139 void *new_buffer =
146 return -1;
147 } else {
148 /* Found a possible frame start and a possible frame end */
155
156 /* Need to check if we have a valid Parse Unit. We can't go by the
157 * sync pattern 'BBCD' alone because arithmetic coding of the residual
158 * and motion data can cause the pattern triggering a false start of
159 * frame. So check if the previous parse offset of the next parse unit
160 * is equal to the next parse offset of the current parse unit then
161 * we can be pretty sure that we have a valid parse unit */
166 ) {
168 *buf_size = next - 9;
170 return -1;
171 }
172
173 /* All non-frame data must be accompanied by frame data. This is to
174 * ensure that pts is set correctly. So if the current parse unit is
175 * not frame data, wait for frame data to come along */
176
179
181
182 if ((pu.
pu_type & 0x08) != 0x08) {
184 *buf_size = next;
185 return -1;
186 }
187
188 /* Get the picture number to set the pts and dts*/
189 if (parse_timing_info) {
192 int pts =
AV_RB32(cur_pu + 13);
195 else
200 }
203
204 /* Finally have a complete Dirac data unit */
207
211 }
212 return next;
213 }
214
216 const uint8_t **poutbuf,
int *poutbuf_size,
218 {
220 int next;
221
222 *poutbuf = NULL;
223 *poutbuf_size = 0;
224
226 next = buf_size;
228 *poutbuf_size = buf_size;
229 /* Assume that data has been packetized into an encapsulation unit. */
230 } else {
233 /* No frame start found yet. So throw away the entire buffer. */
234 return buf_size;
235
237 return buf_size;
238 }
239
241 *poutbuf_size = buf_size;
242 return next;
243 }
244
246 {
248
251 }
252
258 };