Mercurial > mplayer.hg
annotate libmpdemux/demux_viv.c @ 29510:8ba4a5ee1480
Adjust documentation about filtering out whitespace changes from 'svn diff'.
'svn diff' now has builtin whitespace ignore options.
author | diego |
---|---|
date | Wed, 26 Aug 2009 17:35:40 +0000 |
parents | 4a1c217a844b |
children | 0f5751eb7126 |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
2 * VIVO file parser |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
3 * copyright (c) 2001 A'rpi |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
4 * VIVO text header parser and audio support by alex |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
5 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
6 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
7 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
11 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
12 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
16 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
17 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
27282
diff
changeset
|
21 */ |
2687 | 22 |
23 #include <stdio.h> | |
24 #include <stdlib.h> | |
25 #include <unistd.h> | |
2928 | 26 #include <string.h> /* strtok */ |
2687 | 27 |
28 #include "config.h" | |
29 #include "mp_msg.h" | |
30 #include "help_mp.h" | |
31 | |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
22283
diff
changeset
|
32 #include "stream/stream.h" |
2687 | 33 #include "demuxer.h" |
34 #include "stheader.h" | |
35 | |
3502 | 36 /* parameters ! */ |
3503 | 37 int vivo_param_version = -1; |
3502 | 38 char *vivo_param_acodec = NULL; |
39 int vivo_param_abitrate = -1; | |
40 int vivo_param_samplerate = -1; | |
41 int vivo_param_bytesperblock = -1; | |
42 int vivo_param_width = -1; | |
43 int vivo_param_height = -1; | |
44 int vivo_param_vformat = -1; | |
45 | |
3471 | 46 /* VIVO audio standards from vivog723.acm: |
47 | |
48 G.723: | |
49 FormatTag = 0x111 | |
50 Channels = 1 - mono | |
51 SamplesPerSec = 8000 - 8khz | |
52 AvgBytesPerSec = 800 | |
53 BlockAlign (bytes per block) = 24 | |
54 BitsPerSample = 8 | |
55 | |
56 Siren: | |
57 FormatTag = 0x112 | |
58 Channels = 1 - mono | |
59 SamplesPerSec = 16000 - 16khz | |
60 AvgBytesPerSec = 2000 | |
61 BlockAlign (bytes per block) = 40 | |
62 BitsPerSample = 8 | |
63 */ | |
64 | |
3502 | 65 //enum { VIVO_AUDIO_G723, VIVO_AUDIO_SIREN }; |
66 | |
3471 | 67 #define VIVO_AUDIO_G723 1 |
68 #define VIVO_AUDIO_SIREN 2 | |
2687 | 69 |
70 typedef struct { | |
2784 | 71 /* generic */ |
3113
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
72 char version; |
2784 | 73 int supported; |
74 /* info */ | |
75 char *title; | |
76 char *author; | |
77 char *copyright; | |
78 char *producer; | |
79 /* video */ | |
80 float fps; | |
81 int width; | |
82 int height; | |
83 int disp_width; | |
84 int disp_height; | |
85 /* audio */ | |
3471 | 86 int audio_codec; |
87 int audio_bitrate; | |
88 int audio_samplerate; | |
89 int audio_bytesperblock; | |
2687 | 90 } vivo_priv_t; |
91 | |
2784 | 92 /* parse all possible extra headers */ |
22283
bc9e95184521
cosmetics: Fix some common typos, sepErate --> sepArate, deciSSion --> deciSion.
diego
parents:
21421
diff
changeset
|
93 /* (audio headers are separate - mostly with recordtype=3 or 4) */ |
2784 | 94 #define TEXTPARSE_ALL 1 |
95 | |
96 static void vivo_parse_text_header(demuxer_t *demux, int header_len) | |
97 { | |
98 vivo_priv_t* priv = demux->priv; | |
99 char *buf; | |
100 int i; | |
101 char *token; | |
102 char *opt, *param; | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
103 int parser_in_audio_block = 0; |
2784 | 104 |
105 if (!demux->priv) | |
106 { | |
107 priv = malloc(sizeof(vivo_priv_t)); | |
108 memset(priv, 0, sizeof(vivo_priv_t)); | |
109 demux->priv = priv; | |
110 priv->supported = 0; | |
111 } | |
112 | |
113 buf = malloc(header_len); | |
114 opt = malloc(header_len); | |
115 param = malloc(header_len); | |
116 stream_read(demux->stream, buf, header_len); | |
117 i=0; | |
118 while(i<header_len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
119 |
2784 | 120 token = strtok(buf, (char *)&("\x0d\x0a")); |
121 while (token && (header_len>2)) | |
122 { | |
123 header_len -= strlen(token)+2; | |
124 if (sscanf(token, "%[^:]:%[^\n]", opt, param) != 2) | |
125 { | |
17366 | 126 mp_msg(MSGT_DEMUX, MSGL_V, "viv_text_header_parser: bad line: '%s' at ~%#"PRIx64"\n", |
127 token, (int64_t)stream_tell(demux->stream)); | |
2784 | 128 break; |
129 } | |
3471 | 130 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%d bytes/%d bytes left)\n", |
2784 | 131 token, strlen(token), header_len); |
3471 | 132 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token => o: '%s', p: '%s'\n", |
2784 | 133 opt, param); |
134 | |
135 /* checking versions: only v1 or v2 is suitable (or known?:) */ | |
136 if (!strcmp(opt, "Version")) | |
137 { | |
138 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Version: %s\n", param); | |
2928 | 139 if (!strncmp(param, "Vivo/1", 6) || !strncmp(param, "Vivo/2", 6)) |
3113
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
140 { |
2784 | 141 priv->supported = 1; |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
142 /* save major version for fourcc */ |
3113
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
143 priv->version = param[5]; |
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
144 } |
2784 | 145 } |
146 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
147 /* video specific */ |
2784 | 148 if (!strcmp(opt, "FPS")) |
149 { | |
150 mp_msg(MSGT_DEMUX, MSGL_DBG2, "FPS: %f\n", atof(param)); | |
151 priv->fps = atof(param); | |
152 } | |
153 if (!strcmp(opt, "Width")) | |
154 { | |
155 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Width: %d\n", atoi(param)); | |
156 priv->width = atoi(param); | |
157 } | |
158 if (!strcmp(opt, "Height")) | |
159 { | |
160 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Height: %d\n", atoi(param)); | |
161 priv->height = atoi(param); | |
162 } | |
163 if (!strcmp(opt, "DisplayWidth")) | |
164 { | |
165 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Width: %d\n", atoi(param)); | |
166 priv->disp_width = atoi(param); | |
167 } | |
168 if (!strcmp(opt, "DisplayHeight")) | |
169 { | |
170 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Height: %d\n", atoi(param)); | |
171 priv->disp_height = atoi(param); | |
172 } | |
173 | |
174 /* audio specific */ | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
175 if (!strcmp(opt, "RecordType")) |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
176 { |
3471 | 177 /* no audio recordblock by Vivo/1.00, 3 and 4 by Vivo/2.00 */ |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
178 if ((atoi(param) == 3) || (atoi(param) == 4)) |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
179 parser_in_audio_block = 1; |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
180 else |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
181 parser_in_audio_block = 0; |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
182 } |
2784 | 183 if (!strcmp(opt, "NominalBitrate")) |
184 { | |
3471 | 185 priv->audio_bitrate = atoi(param); |
186 if (priv->audio_bitrate == 2000) | |
187 priv->audio_codec = VIVO_AUDIO_SIREN; | |
188 if (priv->audio_bitrate == 800) | |
189 priv->audio_codec = VIVO_AUDIO_G723; | |
2784 | 190 } |
191 if (!strcmp(opt, "SamplingFrequency")) | |
192 { | |
3471 | 193 priv->audio_samplerate = atoi(param); |
194 if (priv->audio_samplerate == 16000) | |
195 priv->audio_codec = VIVO_AUDIO_SIREN; | |
196 if (priv->audio_samplerate == 8000) | |
197 priv->audio_codec = VIVO_AUDIO_G723; | |
2784 | 198 } |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
199 if (!strcmp(opt, "Length") && (parser_in_audio_block == 1)) |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
200 { |
3471 | 201 priv->audio_bytesperblock = atoi(param); /* 24 or 40 kbps */ |
202 if (priv->audio_bytesperblock == 40) | |
203 priv->audio_codec = VIVO_AUDIO_SIREN; | |
204 if (priv->audio_bytesperblock == 24) | |
205 priv->audio_codec = VIVO_AUDIO_G723; | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
206 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
207 |
2784 | 208 /* only for displaying some informations about movie*/ |
209 if (!strcmp(opt, "Title")) | |
210 { | |
29288
4a1c217a844b
In all demux_info_add calls change "name" to "title".
reimar
parents:
29263
diff
changeset
|
211 demux_info_add(demux, "title", param); |
3612 | 212 priv->title = strdup(param); |
2784 | 213 } |
214 if (!strcmp(opt, "Author")) | |
215 { | |
3068 | 216 demux_info_add(demux, "author", param); |
3612 | 217 priv->author = strdup(param); |
2784 | 218 } |
219 if (!strcmp(opt, "Copyright")) | |
220 { | |
3068 | 221 demux_info_add(demux, "copyright", param); |
3612 | 222 priv->copyright = strdup(param); |
2784 | 223 } |
224 if (!strcmp(opt, "Producer")) | |
225 { | |
3069 | 226 demux_info_add(demux, "encoder", param); |
3612 | 227 priv->producer = strdup(param); |
2784 | 228 } |
229 | |
230 /* get next token */ | |
231 token = strtok(NULL, (char *)&("\x0d\x0a")); | |
232 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
233 |
2788 | 234 if (buf) |
235 free(buf); | |
236 if (opt) | |
237 free(opt); | |
238 if (param) | |
239 free(param); | |
2784 | 240 } |
241 | |
16175 | 242 static int vivo_check_file(demuxer_t* demuxer){ |
2687 | 243 int i=0; |
244 int len; | |
245 int c; | |
246 unsigned char buf[2048+256]; | |
247 vivo_priv_t* priv; | |
2784 | 248 int orig_pos = stream_tell(demuxer->stream); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
249 |
2687 | 250 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
251 |
2687 | 252 c=stream_read_char(demuxer->stream); |
2792 | 253 if(c==-256) return 0; |
2687 | 254 len=0; |
255 while((c=stream_read_char(demuxer->stream))>=0x80){ | |
256 len+=0x80*(c-0x80); | |
257 if(len>1024) return 0; | |
258 } | |
259 len+=c; | |
6139
3898967fcc96
some more output cosmetics, especially for vivo and mov demuxers
arpi
parents:
4407
diff
changeset
|
260 mp_msg(MSGT_DEMUX,MSGL_V,"header block 1 size: %d\n",len); |
2687 | 261 //stream_skip(demuxer->stream,len); |
2928 | 262 |
263 priv=malloc(sizeof(vivo_priv_t)); | |
264 memset(priv,0,sizeof(vivo_priv_t)); | |
265 demuxer->priv=priv; | |
2784 | 266 |
2805 | 267 #if 0 |
2785 | 268 vivo_parse_text_header(demuxer, len); |
2784 | 269 if (priv->supported == 0) |
270 return 0; | |
271 #else | |
2928 | 272 /* this is enought for check (for now) */ |
273 stream_read(demuxer->stream,buf,len); | |
274 buf[len]=0; | |
275 // printf("VIVO header: '%s'\n",buf); | |
276 | |
2687 | 277 // parse header: |
278 i=0; | |
279 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines | |
2695 | 280 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type! |
2784 | 281 #endif |
2687 | 282 |
2695 | 283 #if 0 |
2687 | 284 c=stream_read_char(demuxer->stream); |
285 if(c) return 0; | |
286 len2=0; | |
287 while((c=stream_read_char(demuxer->stream))>=0x80){ | |
288 len2+=0x80*(c-0x80); | |
289 if(len+len2>2048) return 0; | |
290 } | |
291 len2+=c; | |
6139
3898967fcc96
some more output cosmetics, especially for vivo and mov demuxers
arpi
parents:
4407
diff
changeset
|
292 mp_msg(MSGT_DEMUX,MSGL_V,"header block 2 size: %d\n",len2); |
2687 | 293 stream_skip(demuxer->stream,len2); |
294 // stream_read(demuxer->stream,buf+len,len2); | |
2695 | 295 #endif |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
296 |
2687 | 297 // c=stream_read_char(demuxer->stream); |
298 // printf("first packet: %02X\n",c); | |
299 | |
2784 | 300 stream_seek(demuxer->stream, orig_pos); |
301 | |
16175 | 302 return DEMUXER_TYPE_VIVO; |
2687 | 303 } |
304 | |
3733 | 305 static int audio_pos=0; |
306 static int audio_rate=0; | |
3526 | 307 |
2687 | 308 // return value: |
309 // 0 = EOF or no stream found | |
310 // 1 = successfully read a packet | |
16175 | 311 static int demux_vivo_fill_buffer(demuxer_t *demux, demux_stream_t *dsds){ |
2687 | 312 demux_stream_t *ds=NULL; |
313 int c; | |
314 int len=0; | |
315 int seq; | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
316 int prefix=0; |
2687 | 317 demux->filepos=stream_tell(demux->stream); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
318 |
2687 | 319 c=stream_read_char(demux->stream); |
2792 | 320 if (c == -256) /* EOF */ |
321 return 0; | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
322 // printf("c=%x,%02X\n",c,c&0xf0); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
323 if (c == 0x82) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
324 { |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
325 /* ok, this works, but pts calculating from header is required! */ |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
326 #warning "Calculate PTS from picture header!" |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
327 prefix = 1; |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
328 c = stream_read_char(demux->stream); |
19075 | 329 mp_msg(MSGT_DEMUX, MSGL_V, "packet 0x82(pos=%u) chunk=%x\n", |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
6139
diff
changeset
|
330 (int)stream_tell(demux->stream), c); |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
331 } |
2687 | 332 switch(c&0xF0){ |
2695 | 333 case 0x00: // header - skip it! |
2784 | 334 { |
2687 | 335 len=stream_read_char(demux->stream); |
2695 | 336 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream); |
19075 | 337 mp_msg(MSGT_DEMUX, MSGL_V, "vivo extra header: %d bytes\n",len); |
2784 | 338 #ifdef TEXTPARSE_ALL |
339 { | |
340 int pos; | |
341 /* also try to parse all headers */ | |
342 pos = stream_tell(demux->stream); | |
343 vivo_parse_text_header(demux, len); | |
344 stream_seek(demux->stream, pos); | |
345 } | |
346 #endif | |
2687 | 347 break; |
2784 | 348 } |
2687 | 349 case 0x10: // video packet |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
350 if (prefix == 1) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
351 len = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
352 else |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
353 len=128; |
2687 | 354 ds=demux->video; |
355 break; | |
356 case 0x20: // video packet | |
357 len=stream_read_char(demux->stream); | |
358 ds=demux->video; | |
359 break; | |
3068 | 360 case 0x30: // audio packet |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
361 if (prefix == 1) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
362 len = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
363 else |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
364 len=40; /* 40kbps */ |
2695 | 365 ds=demux->audio; |
3526 | 366 audio_pos+=len; |
2695 | 367 break; |
2687 | 368 case 0x40: // audio packet |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
369 if (prefix == 1) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
370 len = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
371 else |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
372 len=24; /* 24kbps */ |
2687 | 373 ds=demux->audio; |
3526 | 374 audio_pos+=len; |
2687 | 375 break; |
376 default: | |
17366 | 377 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X at pos %"PRIu64" contact author!\n", |
378 c, (int64_t)stream_tell(demux->stream)); | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
379 return 0; |
2687 | 380 } |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
381 |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
382 // printf("chunk=%x, len=%d\n", c, len); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
383 |
2695 | 384 if(!ds || ds->id<-1){ |
2687 | 385 if(len) stream_skip(demux->stream,len); |
386 return 1; | |
387 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
388 |
2687 | 389 seq=c&0x0F; |
390 | |
391 if(ds->asf_packet){ | |
392 if(ds->asf_seq!=seq){ | |
393 // closed segment, finalize packet: | |
394 ds_add_packet(ds,ds->asf_packet); | |
395 ds->asf_packet=NULL; | |
2695 | 396 // printf("packet!\n"); |
2687 | 397 } else { |
398 // append data to it! | |
399 demux_packet_t* dp=ds->asf_packet; | |
27282
16beae919ff1
Avoid including avcodec.h in demuxer.h (and thus many other files) just to get
reimar
parents:
27269
diff
changeset
|
400 if(dp->len + len + MP_INPUT_BUFFER_PADDING_SIZE < 0) |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
17366
diff
changeset
|
401 return 0; |
27282
16beae919ff1
Avoid including avcodec.h in demuxer.h (and thus many other files) just to get
reimar
parents:
27269
diff
changeset
|
402 dp->buffer=realloc(dp->buffer,dp->len+len+MP_INPUT_BUFFER_PADDING_SIZE); |
16beae919ff1
Avoid including avcodec.h in demuxer.h (and thus many other files) just to get
reimar
parents:
27269
diff
changeset
|
403 memset(dp->buffer+dp->len+len, 0, MP_INPUT_BUFFER_PADDING_SIZE); |
2687 | 404 //memcpy(dp->buffer+dp->len,data,len); |
405 stream_read(demux->stream,dp->buffer+dp->len,len); | |
406 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len); | |
407 dp->len+=len; | |
408 // we are ready now. | |
2695 | 409 if((c&0xF0)==0x20) --ds->asf_seq; // hack! |
2687 | 410 return 1; |
411 } | |
412 } | |
413 // create new packet: | |
414 { demux_packet_t* dp; | |
415 dp=new_demux_packet(len); | |
416 //memcpy(dp->buffer,data,len); | |
417 stream_read(demux->stream,dp->buffer,len); | |
3526 | 418 dp->pts=audio_rate?((float)audio_pos/(float)audio_rate):0; |
2687 | 419 // dp->flags=keyframe; |
420 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur); | |
421 dp->pos=demux->filepos; | |
422 ds->asf_packet=dp; | |
423 ds->asf_seq=seq; | |
424 // we are ready now. | |
425 return 1; | |
426 } | |
427 | |
428 } | |
429 | |
430 static const short h263_format[8][2] = { | |
431 { 0, 0 }, | |
432 { 128, 96 }, | |
433 { 176, 144 }, | |
434 { 352, 288 }, | |
435 { 704, 576 }, | |
436 { 1408, 1152 }, | |
2784 | 437 { 320, 240 } // ??????? or 240x180 (found in vivo2) ? |
2687 | 438 }; |
439 | |
440 static unsigned char* buffer; | |
441 static int bufptr=0; | |
442 static int bitcnt=0; | |
443 static unsigned char buf=0; | |
444 static int format, width, height; | |
445 | |
446 static unsigned int x_get_bits(int n){ | |
447 unsigned int x=0; | |
448 while(n-->0){ | |
449 if(!bitcnt){ | |
450 // fill buff | |
451 buf=buffer[bufptr++]; | |
452 bitcnt=8; | |
453 } | |
454 //x=(x<<1)|(buf&1);buf>>=1; | |
455 x=(x<<1)|(buf>>7);buf<<=1; | |
456 --bitcnt; | |
457 } | |
458 return x; | |
459 } | |
460 | |
461 #define get_bits(xxx,n) x_get_bits(n) | |
462 #define get_bits1(xxx) x_get_bits(1) | |
463 #define skip_bits(xxx,n) x_get_bits(n) | |
464 #define skip_bits1(xxx) x_get_bits(1) | |
465 | |
466 /* most is hardcoded. should extend to handle all h263 streams */ | |
467 static int h263_decode_picture_header(unsigned char *b_ptr) | |
468 { | |
2928 | 469 // int i; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
470 |
2695 | 471 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n"); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
472 |
2687 | 473 buffer=b_ptr; |
474 bufptr=bitcnt=buf=0; | |
475 | |
476 /* picture header */ | |
2695 | 477 if (get_bits(&s->gb, 22) != 0x20){ |
19075 | 478 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad picture header\n"); |
2687 | 479 return -1; |
2695 | 480 } |
2687 | 481 skip_bits(&s->gb, 8); /* picture timestamp */ |
482 | |
2695 | 483 if (get_bits1(&s->gb) != 1){ |
19075 | 484 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad marker\n"); |
2687 | 485 return -1; /* marker */ |
2695 | 486 } |
487 if (get_bits1(&s->gb) != 0){ | |
19075 | 488 mp_msg(MSGT_DEMUX, MSGL_FATAL, "bad h263 id\n"); |
2687 | 489 return -1; /* h263 id */ |
2695 | 490 } |
2687 | 491 skip_bits1(&s->gb); /* split screen off */ |
492 skip_bits1(&s->gb); /* camera off */ | |
493 skip_bits1(&s->gb); /* freeze picture release off */ | |
494 | |
495 format = get_bits(&s->gb, 3); | |
496 | |
497 if (format != 7) { | |
19075 | 498 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 0 format = %d\n", format); |
2687 | 499 /* H.263v1 */ |
500 width = h263_format[format][0]; | |
501 height = h263_format[format][1]; | |
19075 | 502 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height); |
2695 | 503 // if (!width) return -1; |
2687 | 504 |
19075 | 505 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits1(&s->gb)); |
506 mp_msg(MSGT_DEMUX, MSGL_V, "unrestricted_mv=%d\n", get_bits1(&s->gb)); | |
2687 | 507 #if 1 |
19075 | 508 mp_msg(MSGT_DEMUX, MSGL_V, "SAC: %d\n", get_bits1(&s->gb)); |
509 mp_msg(MSGT_DEMUX, MSGL_V, "advanced prediction mode: %d\n", get_bits1(&s->gb)); | |
510 mp_msg(MSGT_DEMUX, MSGL_V, "PB frame: %d\n", get_bits1(&s->gb)); | |
2687 | 511 #else |
512 if (get_bits1(&s->gb) != 0) | |
513 return -1; /* SAC: off */ | |
514 if (get_bits1(&s->gb) != 0) | |
515 return -1; /* advanced prediction mode: off */ | |
516 if (get_bits1(&s->gb) != 0) | |
517 return -1; /* not PB frame */ | |
518 #endif | |
19075 | 519 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5)); |
2687 | 520 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
521 } else { | |
19075 | 522 mp_msg(MSGT_DEMUX, MSGL_V, "h263_plus = 1\n"); |
2687 | 523 /* H.263v2 */ |
2695 | 524 if (get_bits(&s->gb, 3) != 1){ |
19075 | 525 mp_msg(MSGT_DEMUX, MSGL_FATAL, "H.263v2 A error\n"); |
2687 | 526 return -1; |
2695 | 527 } |
528 if (get_bits(&s->gb, 3) != 6){ /* custom source format */ | |
19075 | 529 mp_msg(MSGT_DEMUX, MSGL_FATAL, "custom source format\n"); |
2687 | 530 return -1; |
2695 | 531 } |
2687 | 532 skip_bits(&s->gb, 12); |
533 skip_bits(&s->gb, 3); | |
19075 | 534 mp_msg(MSGT_DEMUX, MSGL_V, "pict_type=%d\n", get_bits(&s->gb, 3) + 1); |
2687 | 535 // if (s->pict_type != I_TYPE && |
536 // s->pict_type != P_TYPE) | |
537 // return -1; | |
538 skip_bits(&s->gb, 7); | |
539 skip_bits(&s->gb, 4); /* aspect ratio */ | |
540 width = (get_bits(&s->gb, 9) + 1) * 4; | |
541 skip_bits1(&s->gb); | |
542 height = get_bits(&s->gb, 9) * 4; | |
19075 | 543 mp_msg(MSGT_DEMUX, MSGL_V, "%d x %d\n", width, height); |
2695 | 544 //if (height == 0) |
545 // return -1; | |
19075 | 546 mp_msg(MSGT_DEMUX, MSGL_V, "qscale=%d\n", get_bits(&s->gb, 5)); |
2687 | 547 } |
548 | |
549 /* PEI */ | |
550 while (get_bits1(&s->gb) != 0) { | |
551 skip_bits(&s->gb, 8); | |
552 } | |
553 // s->f_code = 1; | |
554 // s->width = width; | |
555 // s->height = height; | |
556 return 0; | |
557 } | |
558 | |
559 | |
2695 | 560 |
16175 | 561 static demuxer_t* demux_open_vivo(demuxer_t* demuxer){ |
2687 | 562 vivo_priv_t* priv=demuxer->priv; |
563 | |
564 if(!ds_fill_buffer(demuxer->video)){ | |
565 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingVideoStreamBug); | |
16175 | 566 return NULL; |
2687 | 567 } |
3526 | 568 |
569 audio_pos=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
570 |
2687 | 571 h263_decode_picture_header(demuxer->video->buffer); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
572 |
3503 | 573 if (vivo_param_version != -1) |
574 priv->version = '0' + vivo_param_version; | |
2687 | 575 |
576 { sh_video_t* sh=new_sh_video(demuxer,0); | |
3113
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
577 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
578 /* viv1, viv2 (for better codecs.conf) */ |
3113
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
579 sh->format = mmioFOURCC('v', 'i', 'v', priv->version); |
2784 | 580 if(!sh->fps) |
2928 | 581 { |
2784 | 582 if (priv->fps) |
583 sh->fps=priv->fps; | |
584 else | |
585 sh->fps=15.0f; | |
2928 | 586 } |
2687 | 587 sh->frametime=1.0f/sh->fps; |
2805 | 588 |
3502 | 589 /* XXX: FIXME: can't scale image. */ |
590 /* hotfix to disable: */ | |
2805 | 591 priv->disp_width = priv->width; |
592 priv->disp_height = priv->height; | |
593 | |
3502 | 594 if (vivo_param_width != -1) |
595 priv->disp_width = priv->width = vivo_param_width; | |
596 | |
597 if (vivo_param_height != -1) | |
598 priv->disp_height = priv->height = vivo_param_height; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
599 |
3502 | 600 if (vivo_param_vformat != -1) |
601 { | |
602 priv->disp_width = priv->width = h263_format[vivo_param_vformat][0]; | |
603 priv->disp_height = priv->height = h263_format[vivo_param_vformat][1]; | |
604 } | |
605 | |
2784 | 606 if (priv->disp_width) |
607 sh->disp_w = priv->disp_width; | |
608 else | |
609 sh->disp_w = width; | |
610 if (priv->disp_height) | |
611 sh->disp_h = priv->disp_height; | |
612 else | |
613 sh->disp_h = height; | |
2687 | 614 |
615 // emulate BITMAPINFOHEADER: | |
616 sh->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
617 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); | |
618 sh->bih->biSize=40; | |
2784 | 619 if (priv->width) |
620 sh->bih->biWidth = priv->width; | |
621 else | |
622 sh->bih->biWidth = width; | |
623 if (priv->height) | |
624 sh->bih->biHeight = priv->height; | |
625 else | |
626 sh->bih->biHeight = height; | |
2687 | 627 sh->bih->biPlanes=1; |
628 sh->bih->biBitCount=24; | |
629 sh->bih->biCompression=sh->format; | |
630 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3; | |
3502 | 631 |
632 /* insert as stream */ | |
633 demuxer->video->sh=sh; | |
634 sh->ds=demuxer->video; | |
2687 | 635 demuxer->video->id=0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
636 |
3502 | 637 /* disable seeking */ |
2928 | 638 demuxer->seekable = 0; |
2788 | 639 |
19075 | 640 mp_msg(MSGT_DEMUX,MSGL_V,"VIVO Video stream %d size: display: %dx%d, codec: %ux%u\n", |
2788 | 641 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth, |
642 sh->bih->biHeight); | |
2687 | 643 } |
644 | |
3502 | 645 /* AUDIO init */ |
646 if (demuxer->audio->id >= -1){ | |
2687 | 647 if(!ds_fill_buffer(demuxer->audio)){ |
648 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream); | |
649 } else | |
650 { sh_audio_t* sh=new_sh_audio(demuxer,1); | |
2788 | 651 |
3502 | 652 /* Select audio codec */ |
3471 | 653 if (priv->audio_codec == 0) |
654 { | |
655 if (priv->version == '2') | |
656 priv->audio_codec = VIVO_AUDIO_SIREN; | |
657 else | |
658 priv->audio_codec = VIVO_AUDIO_G723; | |
659 } | |
3502 | 660 if (vivo_param_acodec != NULL) |
661 { | |
662 if (!strcasecmp(vivo_param_acodec, "g723")) | |
663 priv->audio_codec = VIVO_AUDIO_G723; | |
664 if (!strcasecmp(vivo_param_acodec, "siren")) | |
665 priv->audio_codec = VIVO_AUDIO_SIREN; | |
666 } | |
3471 | 667 |
3502 | 668 if (priv->audio_codec == VIVO_AUDIO_G723) |
669 sh->format = 0x111; | |
9955
d6be831a5f9a
fixed 2 10l-s (bug found in the spring cleanup patch by Raindel Shachar
alex
parents:
8254
diff
changeset
|
670 else if (priv->audio_codec == VIVO_AUDIO_SIREN) |
3502 | 671 sh->format = 0x112; |
9955
d6be831a5f9a
fixed 2 10l-s (bug found in the spring cleanup patch by Raindel Shachar
alex
parents:
8254
diff
changeset
|
672 else |
3502 | 673 { |
674 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: Not support audio codec (%d)\n", | |
675 priv->audio_codec); | |
18708
9e2b300db17b
Change free_sh_audio() to take demuxer and stream id as parameters
uau
parents:
18558
diff
changeset
|
676 free_sh_audio(demuxer, 1); |
3502 | 677 goto nosound; |
678 } | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
679 |
2687 | 680 // Emulate WAVEFORMATEX struct: |
681 sh->wf=malloc(sizeof(WAVEFORMATEX)); | |
682 memset(sh->wf,0,sizeof(WAVEFORMATEX)); | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
683 sh->wf->wFormatTag=sh->format; |
3502 | 684 sh->wf->nChannels=1; /* 1 channels for both Siren and G.723 */ |
685 | |
686 /* Set bits per sample */ | |
3471 | 687 if (priv->audio_codec == VIVO_AUDIO_SIREN) |
3502 | 688 sh->wf->wBitsPerSample = 16; |
3471 | 689 else |
3502 | 690 if (priv->audio_codec == VIVO_AUDIO_G723) |
691 sh->wf->wBitsPerSample = 8; | |
692 | |
693 /* Set sampling rate */ | |
694 if (priv->audio_samplerate) /* got from header */ | |
695 sh->wf->nSamplesPerSec = priv->audio_samplerate; | |
3471 | 696 else |
697 { | |
698 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
3502 | 699 sh->wf->nSamplesPerSec = 16000; |
700 if (priv->audio_codec == VIVO_AUDIO_G723) | |
701 sh->wf->nSamplesPerSec = 8000; | |
3471 | 702 } |
3502 | 703 if (vivo_param_samplerate != -1) |
704 sh->wf->nSamplesPerSec = vivo_param_samplerate; | |
705 | |
706 /* Set audio bitrate */ | |
707 if (priv->audio_bitrate) /* got from header */ | |
708 sh->wf->nAvgBytesPerSec = priv->audio_bitrate; | |
2784 | 709 else |
3471 | 710 { |
711 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
712 sh->wf->nAvgBytesPerSec = 2000; | |
3502 | 713 if (priv->audio_codec == VIVO_AUDIO_G723) |
3471 | 714 sh->wf->nAvgBytesPerSec = 800; |
715 } | |
3502 | 716 if (vivo_param_abitrate != -1) |
717 sh->wf->nAvgBytesPerSec = vivo_param_abitrate; | |
3526 | 718 audio_rate=sh->wf->nAvgBytesPerSec; |
3502 | 719 |
3471 | 720 if (!priv->audio_bytesperblock) |
721 { | |
722 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
3502 | 723 sh->wf->nBlockAlign = 40; |
724 if (priv->audio_codec == VIVO_AUDIO_G723) | |
725 sh->wf->nBlockAlign = 24; | |
3471 | 726 } |
727 else | |
3502 | 728 sh->wf->nBlockAlign = priv->audio_bytesperblock; |
729 if (vivo_param_bytesperblock != -1) | |
730 sh->wf->nBlockAlign = vivo_param_bytesperblock; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
731 |
8254
772d6d27fd66
warning patch by (Dominik Mierzejewski <dominik at rangers dot eu dot org>)
michael
parents:
7472
diff
changeset
|
732 /*sound_ok:*/ |
3502 | 733 /* insert as stream */ |
734 demuxer->audio->sh=sh; | |
735 sh->ds=demuxer->audio; | |
2687 | 736 demuxer->audio->id=1; |
3502 | 737 nosound: |
16175 | 738 return demuxer; |
2687 | 739 } |
2695 | 740 } |
16175 | 741 return demuxer; |
742 } | |
2687 | 743 |
16175 | 744 static void demux_close_vivo(demuxer_t *demuxer) |
2788 | 745 { |
746 vivo_priv_t* priv=demuxer->priv; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
747 |
2809 | 748 if (priv) { |
749 if (priv->title) | |
750 free(priv->title); | |
751 if (priv->author) | |
752 free(priv->author); | |
753 if (priv->copyright) | |
754 free(priv->copyright); | |
755 if (priv->producer) | |
756 free(priv->producer); | |
2788 | 757 free(priv); |
2809 | 758 } |
2788 | 759 return; |
760 } | |
16175 | 761 |
762 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
22605
diff
changeset
|
763 const demuxer_desc_t demuxer_desc_vivo = { |
16175 | 764 "Vivo demuxer", |
765 "vivo", | |
766 "VIVO", | |
767 "A'rpi, Alex Beregszasi", | |
768 "", | |
769 DEMUXER_TYPE_VIVO, | |
770 0, // unsafe autodetect | |
771 vivo_check_file, | |
772 demux_vivo_fill_buffer, | |
773 demux_open_vivo, | |
774 demux_close_vivo, | |
775 NULL, | |
776 NULL | |
777 }; |