1 /*
2 * Vivo stream demuxer
3 * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
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
22 /**
23 * @file
24 * @brief Vivo stream demuxer
25 * @author Daniel Verkamp <daniel at drv.nu>
26 * @sa http://wiki.multimedia.cx/index.php?title=Vivo
27 */
28
32
35
39
42
44 {
45 const unsigned char *
buf = p->
buf;
47
48 // stream must start with packet of type 0 and sequence number 0
49 if (*buf++ != 0)
50 return 0;
51
52 // read at most 2 bytes of coded length
53 c = *buf++;
54 length = c & 0x7F;
55 if (c & 0x80) {
56 c = *buf++;
57 length = (length << 7) | (c & 0x7F);
58 }
59 if (c & 0x80 || length > 1024 || length < 21)
60 return 0;
61
62 if (memcmp(buf, "\r\nVersion:Vivo/", 15))
63 return 0;
64 buf += 15;
65
66 if (*buf < '0' && *buf > '2')
67 return 0;
68
70 }
71
73 {
76 unsigned c, get_length = 0;
77
80
82 if (c == 0x82) {
83 get_length = 1;
85 }
86
89
91 case 0: get_length = 1; break;
92 case 1: vivo->
length = 128;
break;
93 case 2: get_length = 1; break;
94 case 3: vivo->
length = 40;
break;
95 case 4: vivo->
length = 24;
break;
96 default:
99 }
100
101 if (get_length) {
104 if (c & 0x80) {
107
108 if (c & 0x80) {
111 }
112 }
113 }
114
115 return 0;
116 }
117
119 {
123 unsigned char *
line, *line_end, *key, *
value;
124 long value_int;
127 char *end_value;
128
131 if (!ast || !vst)
133
135
136 while (1) {
139
140 // done reading all text header packets?
142 break;
143
144 if (vivo->
length <= 1024) {
147 } else {
150 continue;
151 }
152
154 while (*line) {
155 line_end = strstr(line, "\r\n");
156 if (!line_end)
157 break;
158
159 *line_end = 0;
160 key = line;
161 line = line_end + 2; // skip \r\n
162
163 if (line_end == key) // skip blank lines
164 continue;
165
166 value = strchr(key, ':');
167 if (!value) {
169 value);
170 continue;
171 }
172
173 *value++ = 0;
174
176
177 value_int = strtol(value, &end_value, 10);
178 value_used = 0;
179 if (*end_value == 0) { // valid integer
181 value_used = 1;
182 if (!strcmp(key, "Duration")) {
183 duration = value_int;
184 } else if (!strcmp(key, "Width")) {
186 } else if (!strcmp(key, "Height")) {
188 } else if (!strcmp(key, "TimeUnitNumerator")) {
189 fps.
num = value_int / 1000;
190 } else if (!strcmp(key, "TimeUnitDenominator")) {
192 } else if (!strcmp(key, "SamplingFrequency")) {
194 } else if (!strcmp(key, "NominalBitrate")) {
195 } else if (!strcmp(key, "Length")) {
196 // size of file
197 } else {
198 value_used = 0;
199 }
200 }
201
202 if (!strcmp(key, "Version")) {
203 if (sscanf(value,
"Vivo/%d.", &vivo->
version) != 1)
205 value_used = 1;
206 } else if (!strcmp(key, "FPS")) {
208
209 value_used = 1;
212 }
213
214 if (!value_used)
216 }
217 }
218
221 if (duration)
223
227
234 }
235
240
241 return 0;
242 }
243
245 {
248 unsigned old_sequence = vivo->
sequence, old_type = vivo->
type;
249 int stream_index,
ret = 0;
250
251 restart:
252
255
256 switch (vivo->
type) {
257 case 0:
261 goto restart;
262 case 1:
263 case 2: // video
264 stream_index = 0;
265 break;
266 case 3:
267 case 4: // audio
268 stream_index = 1;
269 break;
270 default:
273 }
274
276 goto fail;
277
278 // get next packet header
280 goto fail;
281
282 while (vivo->
sequence == old_sequence &&
283 (((vivo->
type - 1) >> 1) == ((old_type - 1) >> 1))) {
286 break;
287 }
288
290 break;
291
292 // get next packet header
294 break;
295 }
296
298
299 fail:
300 if (ret < 0)
303 }
304
312 .extensions = "viv",
313 };