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