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