Mercurial > mplayer.hg
annotate libmpdemux/demux_viv.c @ 3492:24b0fad7fccc
Use $AUDIODEV environment variable as the default audio device on solaris, if
available.
author | jkeil |
---|---|
date | Fri, 14 Dec 2001 20:13:17 +0000 |
parents | e5aae38e6a09 |
children | 1ff0ff94ac91 |
rev | line source |
---|---|
2687 | 1 // VIVO file parser by A'rpi |
3471 | 2 // VIVO text header parser and audio support by alex |
2687 | 3 |
4 #include <stdio.h> | |
5 #include <stdlib.h> | |
6 #include <unistd.h> | |
2928 | 7 #include <string.h> /* strtok */ |
2687 | 8 |
9 #include "config.h" | |
10 #include "mp_msg.h" | |
11 #include "help_mp.h" | |
12 | |
13 #include "stream.h" | |
14 #include "demuxer.h" | |
15 #include "stheader.h" | |
3471 | 16 #include "bswap.h" |
2687 | 17 |
3471 | 18 /* VIVO audio standards from vivog723.acm: |
19 | |
20 G.723: | |
21 FormatTag = 0x111 | |
22 Channels = 1 - mono | |
23 SamplesPerSec = 8000 - 8khz | |
24 AvgBytesPerSec = 800 | |
25 BlockAlign (bytes per block) = 24 | |
26 BitsPerSample = 8 | |
27 | |
28 Siren: | |
29 FormatTag = 0x112 | |
30 Channels = 1 - mono | |
31 SamplesPerSec = 16000 - 16khz | |
32 AvgBytesPerSec = 2000 | |
33 BlockAlign (bytes per block) = 40 | |
34 BitsPerSample = 8 | |
35 */ | |
36 | |
37 #define VIVO_AUDIO_G723 1 | |
38 #define VIVO_AUDIO_SIREN 2 | |
2687 | 39 |
40 typedef struct { | |
2784 | 41 /* generic */ |
3113
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
42 char version; |
2784 | 43 int supported; |
44 /* info */ | |
45 char *title; | |
46 char *author; | |
47 char *copyright; | |
48 char *producer; | |
49 /* video */ | |
50 float fps; | |
51 int width; | |
52 int height; | |
53 int disp_width; | |
54 int disp_height; | |
55 /* audio */ | |
3471 | 56 int audio_codec; |
57 int audio_bitrate; | |
58 int audio_samplerate; | |
59 int audio_bytesperblock; | |
2687 | 60 } vivo_priv_t; |
61 | |
2784 | 62 /* parse all possible extra headers */ |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
63 /* (audio headers are seperate - mostly with recordtype=3 or 4) */ |
2784 | 64 #define TEXTPARSE_ALL 1 |
65 | |
66 static void vivo_parse_text_header(demuxer_t *demux, int header_len) | |
67 { | |
68 vivo_priv_t* priv = demux->priv; | |
69 char *buf; | |
70 int i; | |
71 char *token; | |
72 char *opt, *param; | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
73 int parser_in_audio_block = 0; |
2784 | 74 |
75 if (!demux->priv) | |
76 { | |
77 priv = malloc(sizeof(vivo_priv_t)); | |
78 memset(priv, 0, sizeof(vivo_priv_t)); | |
79 demux->priv = priv; | |
80 priv->supported = 0; | |
81 } | |
82 | |
83 buf = malloc(header_len); | |
84 opt = malloc(header_len); | |
85 param = malloc(header_len); | |
86 stream_read(demux->stream, buf, header_len); | |
87 i=0; | |
88 while(i<header_len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines | |
89 | |
90 token = strtok(buf, (char *)&("\x0d\x0a")); | |
91 while (token && (header_len>2)) | |
92 { | |
93 header_len -= strlen(token)+2; | |
94 if (sscanf(token, "%[^:]:%[^\n]", opt, param) != 2) | |
95 { | |
96 mp_msg(MSGT_DEMUX, MSGL_V, "viv_text_header_parser: bad line: '%s' at ~%p\n", | |
97 token, stream_tell(demux->stream)); | |
98 break; | |
99 } | |
3471 | 100 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token: '%s' (%d bytes/%d bytes left)\n", |
2784 | 101 token, strlen(token), header_len); |
3471 | 102 mp_dbg(MSGT_DEMUX, MSGL_DBG3, "token => o: '%s', p: '%s'\n", |
2784 | 103 opt, param); |
104 | |
105 /* checking versions: only v1 or v2 is suitable (or known?:) */ | |
106 if (!strcmp(opt, "Version")) | |
107 { | |
108 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Version: %s\n", param); | |
2928 | 109 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
|
110 { |
2784 | 111 priv->supported = 1; |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
112 /* save major version for fourcc */ |
3113
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
113 priv->version = param[5]; |
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
114 } |
2784 | 115 } |
116 | |
117 /* video specific */ | |
118 if (!strcmp(opt, "FPS")) | |
119 { | |
120 mp_msg(MSGT_DEMUX, MSGL_DBG2, "FPS: %f\n", atof(param)); | |
121 priv->fps = atof(param); | |
122 } | |
123 if (!strcmp(opt, "Width")) | |
124 { | |
125 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Width: %d\n", atoi(param)); | |
126 priv->width = atoi(param); | |
127 } | |
128 if (!strcmp(opt, "Height")) | |
129 { | |
130 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Height: %d\n", atoi(param)); | |
131 priv->height = atoi(param); | |
132 } | |
133 if (!strcmp(opt, "DisplayWidth")) | |
134 { | |
135 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Width: %d\n", atoi(param)); | |
136 priv->disp_width = atoi(param); | |
137 } | |
138 if (!strcmp(opt, "DisplayHeight")) | |
139 { | |
140 mp_msg(MSGT_DEMUX, MSGL_DBG2, "Display Height: %d\n", atoi(param)); | |
141 priv->disp_height = atoi(param); | |
142 } | |
143 | |
144 /* audio specific */ | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
145 if (!strcmp(opt, "RecordType")) |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
146 { |
3471 | 147 /* 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
|
148 if ((atoi(param) == 3) || (atoi(param) == 4)) |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
149 parser_in_audio_block = 1; |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
150 else |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
151 parser_in_audio_block = 0; |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
152 } |
2784 | 153 if (!strcmp(opt, "NominalBitrate")) |
154 { | |
3471 | 155 priv->audio_bitrate = atoi(param); |
156 if (priv->audio_bitrate == 2000) | |
157 priv->audio_codec = VIVO_AUDIO_SIREN; | |
158 if (priv->audio_bitrate == 800) | |
159 priv->audio_codec = VIVO_AUDIO_G723; | |
2784 | 160 } |
161 if (!strcmp(opt, "SamplingFrequency")) | |
162 { | |
3471 | 163 priv->audio_samplerate = atoi(param); |
164 if (priv->audio_samplerate == 16000) | |
165 priv->audio_codec = VIVO_AUDIO_SIREN; | |
166 if (priv->audio_samplerate == 8000) | |
167 priv->audio_codec = VIVO_AUDIO_G723; | |
2784 | 168 } |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
169 if (!strcmp(opt, "Length") && (parser_in_audio_block == 1)) |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
170 { |
3471 | 171 priv->audio_bytesperblock = atoi(param); /* 24 or 40 kbps */ |
172 if (priv->audio_bytesperblock == 40) | |
173 priv->audio_codec = VIVO_AUDIO_SIREN; | |
174 if (priv->audio_bytesperblock == 24) | |
175 priv->audio_codec = VIVO_AUDIO_G723; | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
176 } |
2784 | 177 |
178 /* only for displaying some informations about movie*/ | |
179 if (!strcmp(opt, "Title")) | |
180 { | |
3068 | 181 demux_info_add(demux, "name", param); |
2784 | 182 priv->title = malloc(strlen(param)); |
183 strcpy(priv->title, param); | |
184 } | |
185 if (!strcmp(opt, "Author")) | |
186 { | |
3068 | 187 demux_info_add(demux, "author", param); |
2784 | 188 priv->author = malloc(strlen(param)); |
189 strcpy(priv->author, param); | |
190 } | |
191 if (!strcmp(opt, "Copyright")) | |
192 { | |
3068 | 193 demux_info_add(demux, "copyright", param); |
2784 | 194 priv->copyright = malloc(strlen(param)); |
195 strcpy(priv->copyright, param); | |
196 } | |
197 if (!strcmp(opt, "Producer")) | |
198 { | |
3069 | 199 demux_info_add(demux, "encoder", param); |
2784 | 200 priv->producer = malloc(strlen(param)); |
201 strcpy(priv->producer, param); | |
202 } | |
203 | |
204 /* get next token */ | |
205 token = strtok(NULL, (char *)&("\x0d\x0a")); | |
206 } | |
2788 | 207 |
208 if (buf) | |
209 free(buf); | |
210 if (opt) | |
211 free(opt); | |
212 if (param) | |
213 free(param); | |
2784 | 214 } |
215 | |
2687 | 216 int vivo_check_file(demuxer_t* demuxer){ |
217 int flags=0; | |
218 int i=0; | |
219 int len; | |
220 int len2; | |
221 int c; | |
222 unsigned char buf[2048+256]; | |
223 vivo_priv_t* priv; | |
2784 | 224 int orig_pos = stream_tell(demuxer->stream); |
2687 | 225 |
226 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n"); | |
227 | |
228 c=stream_read_char(demuxer->stream); | |
2792 | 229 if(c==-256) return 0; |
2687 | 230 len=0; |
231 while((c=stream_read_char(demuxer->stream))>=0x80){ | |
232 len+=0x80*(c-0x80); | |
233 if(len>1024) return 0; | |
234 } | |
235 len+=c; | |
236 printf("header block 1 size: %d\n",len); | |
237 //stream_skip(demuxer->stream,len); | |
2928 | 238 |
239 priv=malloc(sizeof(vivo_priv_t)); | |
240 memset(priv,0,sizeof(vivo_priv_t)); | |
241 demuxer->priv=priv; | |
2784 | 242 |
2805 | 243 #if 0 |
2785 | 244 vivo_parse_text_header(demuxer, len); |
2784 | 245 if (priv->supported == 0) |
246 return 0; | |
247 #else | |
2928 | 248 /* this is enought for check (for now) */ |
249 stream_read(demuxer->stream,buf,len); | |
250 buf[len]=0; | |
251 // printf("VIVO header: '%s'\n",buf); | |
252 | |
2687 | 253 // parse header: |
254 i=0; | |
255 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines | |
2695 | 256 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type! |
2784 | 257 #endif |
2687 | 258 |
2695 | 259 #if 0 |
2687 | 260 c=stream_read_char(demuxer->stream); |
261 if(c) return 0; | |
262 len2=0; | |
263 while((c=stream_read_char(demuxer->stream))>=0x80){ | |
264 len2+=0x80*(c-0x80); | |
265 if(len+len2>2048) return 0; | |
266 } | |
267 len2+=c; | |
268 printf("header block 2 size: %d\n",len2); | |
269 stream_skip(demuxer->stream,len2); | |
270 // stream_read(demuxer->stream,buf+len,len2); | |
2695 | 271 #endif |
2687 | 272 |
273 // c=stream_read_char(demuxer->stream); | |
274 // printf("first packet: %02X\n",c); | |
275 | |
2784 | 276 stream_seek(demuxer->stream, orig_pos); |
277 | |
2687 | 278 return 1; |
279 } | |
280 | |
281 // return value: | |
282 // 0 = EOF or no stream found | |
283 // 1 = successfully read a packet | |
284 int demux_vivo_fill_buffer(demuxer_t *demux){ | |
285 demux_stream_t *ds=NULL; | |
286 int c; | |
287 int len=0; | |
288 int seq; | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
289 int prefix=0; |
2687 | 290 demux->filepos=stream_tell(demux->stream); |
291 | |
292 c=stream_read_char(demux->stream); | |
2792 | 293 if (c == -256) /* EOF */ |
294 return 0; | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
295 // printf("c=%x,%02X\n",c,c&0xf0); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
296 if (c == 0x82) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
297 { |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
298 /* 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
|
299 #warning "Calculate PTS from picture header!" |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
300 prefix = 1; |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
301 c = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
302 printf("packet 0x82(pos=%lu) chunk=%x\n", |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
303 stream_tell(demux->stream), c); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
304 } |
2687 | 305 switch(c&0xF0){ |
2695 | 306 case 0x00: // header - skip it! |
2784 | 307 { |
2687 | 308 len=stream_read_char(demux->stream); |
2695 | 309 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream); |
310 printf("vivo extra header: %d bytes\n",len); | |
2784 | 311 #ifdef TEXTPARSE_ALL |
312 { | |
313 int pos; | |
314 /* also try to parse all headers */ | |
315 pos = stream_tell(demux->stream); | |
316 vivo_parse_text_header(demux, len); | |
317 stream_seek(demux->stream, pos); | |
318 } | |
319 #endif | |
2687 | 320 break; |
2784 | 321 } |
2687 | 322 case 0x10: // video packet |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
323 if (prefix == 1) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
324 len = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
325 else |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
326 len=128; |
2687 | 327 ds=demux->video; |
328 break; | |
329 case 0x20: // video packet | |
330 len=stream_read_char(demux->stream); | |
331 ds=demux->video; | |
332 break; | |
3068 | 333 case 0x30: // audio packet |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
334 if (prefix == 1) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
335 len = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
336 else |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
337 len=40; /* 40kbps */ |
2695 | 338 ds=demux->audio; |
339 break; | |
2687 | 340 case 0x40: // audio packet |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
341 if (prefix == 1) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
342 len = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
343 else |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
344 len=24; /* 24kbps */ |
2687 | 345 ds=demux->audio; |
346 break; | |
347 default: | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
348 mp_msg(MSGT_DEMUX,MSGL_WARN,"VIVO - unknown ID found: %02X at pos %lu contact author!\n", |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
349 c, stream_tell(demux->stream)); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
350 return 0; |
2687 | 351 } |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
352 |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
353 // printf("chunk=%x, len=%d\n", c, len); |
2687 | 354 |
2695 | 355 if(!ds || ds->id<-1){ |
2687 | 356 if(len) stream_skip(demux->stream,len); |
357 return 1; | |
358 } | |
359 | |
360 seq=c&0x0F; | |
361 | |
362 if(ds->asf_packet){ | |
363 if(ds->asf_seq!=seq){ | |
364 // closed segment, finalize packet: | |
365 ds_add_packet(ds,ds->asf_packet); | |
366 ds->asf_packet=NULL; | |
2695 | 367 // printf("packet!\n"); |
2687 | 368 } else { |
369 // append data to it! | |
370 demux_packet_t* dp=ds->asf_packet; | |
371 dp->buffer=realloc(dp->buffer,dp->len+len); | |
372 //memcpy(dp->buffer+dp->len,data,len); | |
373 stream_read(demux->stream,dp->buffer+dp->len,len); | |
374 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len); | |
375 dp->len+=len; | |
376 // we are ready now. | |
2695 | 377 if((c&0xF0)==0x20) --ds->asf_seq; // hack! |
2687 | 378 return 1; |
379 } | |
380 } | |
381 // create new packet: | |
382 { demux_packet_t* dp; | |
383 dp=new_demux_packet(len); | |
384 //memcpy(dp->buffer,data,len); | |
385 stream_read(demux->stream,dp->buffer,len); | |
386 // dp->pts=time*0.001f; | |
387 // dp->flags=keyframe; | |
388 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur); | |
389 dp->pos=demux->filepos; | |
390 ds->asf_packet=dp; | |
391 ds->asf_seq=seq; | |
392 // we are ready now. | |
393 return 1; | |
394 } | |
395 | |
396 } | |
397 | |
398 static const short h263_format[8][2] = { | |
399 { 0, 0 }, | |
400 { 128, 96 }, | |
401 { 176, 144 }, | |
402 { 352, 288 }, | |
403 { 704, 576 }, | |
404 { 1408, 1152 }, | |
2784 | 405 { 320, 240 } // ??????? or 240x180 (found in vivo2) ? |
2687 | 406 }; |
407 | |
408 static unsigned char* buffer; | |
409 static int bufptr=0; | |
410 static int bitcnt=0; | |
411 static unsigned char buf=0; | |
412 static int format, width, height; | |
413 | |
414 static unsigned int x_get_bits(int n){ | |
415 unsigned int x=0; | |
416 while(n-->0){ | |
417 if(!bitcnt){ | |
418 // fill buff | |
419 buf=buffer[bufptr++]; | |
420 bitcnt=8; | |
421 } | |
422 //x=(x<<1)|(buf&1);buf>>=1; | |
423 x=(x<<1)|(buf>>7);buf<<=1; | |
424 --bitcnt; | |
425 } | |
426 return x; | |
427 } | |
428 | |
429 #define get_bits(xxx,n) x_get_bits(n) | |
430 #define get_bits1(xxx) x_get_bits(1) | |
431 #define skip_bits(xxx,n) x_get_bits(n) | |
432 #define skip_bits1(xxx) x_get_bits(1) | |
433 | |
434 /* most is hardcoded. should extend to handle all h263 streams */ | |
435 static int h263_decode_picture_header(unsigned char *b_ptr) | |
436 { | |
2928 | 437 // int i; |
2695 | 438 |
439 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n"); | |
2687 | 440 |
441 buffer=b_ptr; | |
442 bufptr=bitcnt=buf=0; | |
443 | |
444 /* picture header */ | |
2695 | 445 if (get_bits(&s->gb, 22) != 0x20){ |
446 printf("bad picture header\n"); | |
2687 | 447 return -1; |
2695 | 448 } |
2687 | 449 skip_bits(&s->gb, 8); /* picture timestamp */ |
450 | |
2695 | 451 if (get_bits1(&s->gb) != 1){ |
452 printf("bad marker\n"); | |
2687 | 453 return -1; /* marker */ |
2695 | 454 } |
455 if (get_bits1(&s->gb) != 0){ | |
456 printf("bad h263 id\n"); | |
2687 | 457 return -1; /* h263 id */ |
2695 | 458 } |
2687 | 459 skip_bits1(&s->gb); /* split screen off */ |
460 skip_bits1(&s->gb); /* camera off */ | |
461 skip_bits1(&s->gb); /* freeze picture release off */ | |
462 | |
463 format = get_bits(&s->gb, 3); | |
464 | |
465 if (format != 7) { | |
466 printf("h263_plus = 0 format = %d\n",format); | |
467 /* H.263v1 */ | |
468 width = h263_format[format][0]; | |
469 height = h263_format[format][1]; | |
470 printf("%d x %d\n",width,height); | |
2695 | 471 // if (!width) return -1; |
2687 | 472 |
473 printf("pict_type=%d\n",get_bits1(&s->gb)); | |
474 printf("unrestricted_mv=%d\n",get_bits1(&s->gb)); | |
475 #if 1 | |
476 printf("SAC: %d\n",get_bits1(&s->gb)); | |
477 printf("advanced prediction mode: %d\n",get_bits1(&s->gb)); | |
478 printf("PB frame: %d\n",get_bits1(&s->gb)); | |
479 #else | |
480 if (get_bits1(&s->gb) != 0) | |
481 return -1; /* SAC: off */ | |
482 if (get_bits1(&s->gb) != 0) | |
483 return -1; /* advanced prediction mode: off */ | |
484 if (get_bits1(&s->gb) != 0) | |
485 return -1; /* not PB frame */ | |
486 #endif | |
487 printf("qscale=%d\n",get_bits(&s->gb, 5)); | |
488 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | |
489 } else { | |
490 printf("h263_plus = 1\n"); | |
491 /* H.263v2 */ | |
2695 | 492 if (get_bits(&s->gb, 3) != 1){ |
493 printf("H.263v2 A error\n"); | |
2687 | 494 return -1; |
2695 | 495 } |
496 if (get_bits(&s->gb, 3) != 6){ /* custom source format */ | |
497 printf("custom source format\n"); | |
2687 | 498 return -1; |
2695 | 499 } |
2687 | 500 skip_bits(&s->gb, 12); |
501 skip_bits(&s->gb, 3); | |
502 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1); | |
503 // if (s->pict_type != I_TYPE && | |
504 // s->pict_type != P_TYPE) | |
505 // return -1; | |
506 skip_bits(&s->gb, 7); | |
507 skip_bits(&s->gb, 4); /* aspect ratio */ | |
508 width = (get_bits(&s->gb, 9) + 1) * 4; | |
509 skip_bits1(&s->gb); | |
510 height = get_bits(&s->gb, 9) * 4; | |
511 printf("%d x %d\n",width,height); | |
2695 | 512 //if (height == 0) |
513 // return -1; | |
2687 | 514 printf("qscale=%d\n",get_bits(&s->gb, 5)); |
515 } | |
516 | |
517 /* PEI */ | |
518 while (get_bits1(&s->gb) != 0) { | |
519 skip_bits(&s->gb, 8); | |
520 } | |
521 // s->f_code = 1; | |
522 // s->width = width; | |
523 // s->height = height; | |
524 return 0; | |
525 } | |
526 | |
527 | |
2695 | 528 |
2687 | 529 void demux_open_vivo(demuxer_t* demuxer){ |
530 vivo_priv_t* priv=demuxer->priv; | |
531 | |
532 if(!ds_fill_buffer(demuxer->video)){ | |
533 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingVideoStreamBug); | |
534 return; | |
535 } | |
536 | |
537 h263_decode_picture_header(demuxer->video->buffer); | |
538 | |
539 | |
540 { 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
|
541 |
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
542 /* viv1, viv2 (for better codecs.conf) */ |
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
543 sh->format = mmioFOURCC('v', 'i', 'v', priv->version); |
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
544 // sh->format=0x6f766976; // "vivo" |
2784 | 545 if(!sh->fps) |
2928 | 546 { |
2784 | 547 if (priv->fps) |
548 sh->fps=priv->fps; | |
549 else | |
550 sh->fps=15.0f; | |
2928 | 551 } |
2687 | 552 sh->frametime=1.0f/sh->fps; |
2805 | 553 |
554 #warning "FIXME! we can't scale" | |
555 priv->disp_width = priv->width; | |
556 priv->disp_height = priv->height; | |
557 | |
2784 | 558 if (priv->disp_width) |
559 sh->disp_w = priv->disp_width; | |
560 else | |
561 sh->disp_w = width; | |
562 if (priv->disp_height) | |
563 sh->disp_h = priv->disp_height; | |
564 else | |
565 sh->disp_h = height; | |
2687 | 566 |
567 // emulate BITMAPINFOHEADER: | |
568 sh->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
569 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); | |
570 sh->bih->biSize=40; | |
2784 | 571 if (priv->width) |
572 sh->bih->biWidth = priv->width; | |
573 else | |
574 sh->bih->biWidth = width; | |
575 if (priv->height) | |
576 sh->bih->biHeight = priv->height; | |
577 else | |
578 sh->bih->biHeight = height; | |
2687 | 579 sh->bih->biPlanes=1; |
580 sh->bih->biBitCount=24; | |
581 sh->bih->biCompression=sh->format; | |
582 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3; | |
583 demuxer->video->sh=sh; sh->ds=demuxer->video; | |
584 demuxer->video->id=0; | |
2928 | 585 |
586 demuxer->seekable = 0; | |
2788 | 587 |
2928 | 588 printf("VIVO Video stream %d size: display: %dx%d, codec: %lux%lu\n", |
2788 | 589 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth, |
590 sh->bih->biHeight); | |
2687 | 591 } |
592 | |
2695 | 593 if(demuxer->audio->id>=-1){ |
2687 | 594 if(!ds_fill_buffer(demuxer->audio)){ |
595 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream); | |
596 } else | |
597 { sh_audio_t* sh=new_sh_audio(demuxer,1); | |
2788 | 598 |
3471 | 599 if (priv->audio_codec == 0) |
600 { | |
601 if (priv->version == '2') | |
602 priv->audio_codec = VIVO_AUDIO_SIREN; | |
603 else | |
604 priv->audio_codec = VIVO_AUDIO_G723; | |
605 } | |
606 | |
607 // if (priv->version == '2') | |
608 // if (priv->audio_bytesperblock == 40) | |
609 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
610 sh->format=0x112; /* Vivo Siren */ |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
611 else |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
612 // if (priv->version == '1') |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
613 sh->format=0x111; /* Vivo G.723 */ |
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
614 |
2687 | 615 // Emulate WAVEFORMATEX struct: |
616 sh->wf=malloc(sizeof(WAVEFORMATEX)); | |
617 memset(sh->wf,0,sizeof(WAVEFORMATEX)); | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
618 sh->wf->wFormatTag=sh->format; |
2687 | 619 sh->wf->nChannels=1; |
3471 | 620 /* FIXME bits, samplerate, avgbytes, and blockalign */ |
621 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
622 // if (priv->audio_len == 40) | |
623 sh->wf->wBitsPerSample=16; /* siren */ | |
624 else | |
625 sh->wf->wBitsPerSample=8; | |
626 if (priv->audio_samplerate) | |
627 sh->wf->nSamplesPerSec=priv->audio_samplerate; | |
628 else | |
629 { | |
630 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
631 sh->wf->nSamplesPerSec=16000; | |
632 else | |
633 sh->wf->nSamplesPerSec=8000; | |
634 } | |
635 if (priv->audio_bitrate) | |
636 sh->wf->nAvgBytesPerSec=priv->audio_bitrate; | |
2784 | 637 else |
3471 | 638 { |
639 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
640 // if (priv->version == '2') | |
641 sh->wf->nAvgBytesPerSec = 2000; | |
642 else | |
643 sh->wf->nAvgBytesPerSec = 800; | |
644 } | |
645 // sh->wf->nAvgBytesPerSec=sh->wf->nChannels*sh->wf->wBitsPerSample*sh->wf->nSamplesPerSec/8; | |
646 // sh->wf->nBlockAlign=2*sh->wf->nChannels; | |
647 if (!priv->audio_bytesperblock) | |
648 { | |
649 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
650 // if (priv->version == '2') | |
651 sh->wf->nBlockAlign=40; /* siren */ | |
652 else | |
653 sh->wf->nBlockAlign=24; | |
654 } | |
655 else | |
656 sh->wf->nBlockAlign=priv->audio_bytesperblock; | |
2687 | 657 demuxer->audio->sh=sh; sh->ds=demuxer->audio; |
658 demuxer->audio->id=1; | |
659 } | |
2695 | 660 } |
2687 | 661 |
662 } | |
663 | |
2788 | 664 void demux_close_vivo(demuxer_t *demuxer) |
665 { | |
666 vivo_priv_t* priv=demuxer->priv; | |
2809 | 667 |
668 if (priv) { | |
669 if (priv->title) | |
670 free(priv->title); | |
671 if (priv->author) | |
672 free(priv->author); | |
673 if (priv->copyright) | |
674 free(priv->copyright); | |
675 if (priv->producer) | |
676 free(priv->producer); | |
2788 | 677 free(priv); |
2809 | 678 } |
2788 | 679 return; |
680 } |