Mercurial > mplayer.hg
annotate libmpdemux/demux_viv.c @ 4088:4435dc3b8bef
Add DVD subtitles to menoder
author | kmkaplan |
---|---|
date | Fri, 11 Jan 2002 16:06:45 +0000 |
parents | 8dcc18663e60 |
children | 760481d8421c |
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); |
3612 | 194 priv->title = strdup(param); |
2784 | 195 } |
196 if (!strcmp(opt, "Author")) | |
197 { | |
3068 | 198 demux_info_add(demux, "author", param); |
3612 | 199 priv->author = strdup(param); |
2784 | 200 } |
201 if (!strcmp(opt, "Copyright")) | |
202 { | |
3068 | 203 demux_info_add(demux, "copyright", param); |
3612 | 204 priv->copyright = strdup(param); |
2784 | 205 } |
206 if (!strcmp(opt, "Producer")) | |
207 { | |
3069 | 208 demux_info_add(demux, "encoder", param); |
3612 | 209 priv->producer = strdup(param); |
2784 | 210 } |
211 | |
212 /* get next token */ | |
213 token = strtok(NULL, (char *)&("\x0d\x0a")); | |
214 } | |
2788 | 215 |
216 if (buf) | |
217 free(buf); | |
218 if (opt) | |
219 free(opt); | |
220 if (param) | |
221 free(param); | |
2784 | 222 } |
223 | |
2687 | 224 int vivo_check_file(demuxer_t* demuxer){ |
225 int flags=0; | |
226 int i=0; | |
227 int len; | |
228 int len2; | |
229 int c; | |
230 unsigned char buf[2048+256]; | |
231 vivo_priv_t* priv; | |
2784 | 232 int orig_pos = stream_tell(demuxer->stream); |
2687 | 233 |
234 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for VIVO\n"); | |
235 | |
236 c=stream_read_char(demuxer->stream); | |
2792 | 237 if(c==-256) return 0; |
2687 | 238 len=0; |
239 while((c=stream_read_char(demuxer->stream))>=0x80){ | |
240 len+=0x80*(c-0x80); | |
241 if(len>1024) return 0; | |
242 } | |
243 len+=c; | |
244 printf("header block 1 size: %d\n",len); | |
245 //stream_skip(demuxer->stream,len); | |
2928 | 246 |
247 priv=malloc(sizeof(vivo_priv_t)); | |
248 memset(priv,0,sizeof(vivo_priv_t)); | |
249 demuxer->priv=priv; | |
2784 | 250 |
2805 | 251 #if 0 |
2785 | 252 vivo_parse_text_header(demuxer, len); |
2784 | 253 if (priv->supported == 0) |
254 return 0; | |
255 #else | |
2928 | 256 /* this is enought for check (for now) */ |
257 stream_read(demuxer->stream,buf,len); | |
258 buf[len]=0; | |
259 // printf("VIVO header: '%s'\n",buf); | |
260 | |
2687 | 261 // parse header: |
262 i=0; | |
263 while(i<len && buf[i]==0x0D && buf[i+1]==0x0A) i+=2; // skip empty lines | |
2695 | 264 if(strncmp(buf+i,"Version:Vivo/",13)) return 0; // bad version/type! |
2784 | 265 #endif |
2687 | 266 |
2695 | 267 #if 0 |
2687 | 268 c=stream_read_char(demuxer->stream); |
269 if(c) return 0; | |
270 len2=0; | |
271 while((c=stream_read_char(demuxer->stream))>=0x80){ | |
272 len2+=0x80*(c-0x80); | |
273 if(len+len2>2048) return 0; | |
274 } | |
275 len2+=c; | |
276 printf("header block 2 size: %d\n",len2); | |
277 stream_skip(demuxer->stream,len2); | |
278 // stream_read(demuxer->stream,buf+len,len2); | |
2695 | 279 #endif |
2687 | 280 |
281 // c=stream_read_char(demuxer->stream); | |
282 // printf("first packet: %02X\n",c); | |
283 | |
2784 | 284 stream_seek(demuxer->stream, orig_pos); |
285 | |
2687 | 286 return 1; |
287 } | |
288 | |
3733 | 289 static int audio_pos=0; |
290 static int audio_rate=0; | |
3526 | 291 |
2687 | 292 // return value: |
293 // 0 = EOF or no stream found | |
294 // 1 = successfully read a packet | |
295 int demux_vivo_fill_buffer(demuxer_t *demux){ | |
296 demux_stream_t *ds=NULL; | |
297 int c; | |
298 int len=0; | |
299 int seq; | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
300 int prefix=0; |
2687 | 301 demux->filepos=stream_tell(demux->stream); |
302 | |
303 c=stream_read_char(demux->stream); | |
2792 | 304 if (c == -256) /* EOF */ |
305 return 0; | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
306 // printf("c=%x,%02X\n",c,c&0xf0); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
307 if (c == 0x82) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
308 { |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
309 /* 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
|
310 #warning "Calculate PTS from picture header!" |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
311 prefix = 1; |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
312 c = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
313 printf("packet 0x82(pos=%lu) chunk=%x\n", |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
314 stream_tell(demux->stream), c); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
315 } |
2687 | 316 switch(c&0xF0){ |
2695 | 317 case 0x00: // header - skip it! |
2784 | 318 { |
2687 | 319 len=stream_read_char(demux->stream); |
2695 | 320 if(len>=0x80) len=0x80*(len-0x80)+stream_read_char(demux->stream); |
321 printf("vivo extra header: %d bytes\n",len); | |
2784 | 322 #ifdef TEXTPARSE_ALL |
323 { | |
324 int pos; | |
325 /* also try to parse all headers */ | |
326 pos = stream_tell(demux->stream); | |
327 vivo_parse_text_header(demux, len); | |
328 stream_seek(demux->stream, pos); | |
329 } | |
330 #endif | |
2687 | 331 break; |
2784 | 332 } |
2687 | 333 case 0x10: // video 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=128; |
2687 | 338 ds=demux->video; |
339 break; | |
340 case 0x20: // video packet | |
341 len=stream_read_char(demux->stream); | |
342 ds=demux->video; | |
343 break; | |
3068 | 344 case 0x30: // audio packet |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
345 if (prefix == 1) |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
346 len = stream_read_char(demux->stream); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
347 else |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
348 len=40; /* 40kbps */ |
2695 | 349 ds=demux->audio; |
3526 | 350 audio_pos+=len; |
2695 | 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; |
3526 | 358 audio_pos+=len; |
2687 | 359 break; |
360 default: | |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
361 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
|
362 c, stream_tell(demux->stream)); |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
363 return 0; |
2687 | 364 } |
3245
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
365 |
1e2a87b7cae8
added support for packet 0x82 (from vivodump.c by arpi)
alex
parents:
3113
diff
changeset
|
366 // printf("chunk=%x, len=%d\n", c, len); |
2687 | 367 |
2695 | 368 if(!ds || ds->id<-1){ |
2687 | 369 if(len) stream_skip(demux->stream,len); |
370 return 1; | |
371 } | |
372 | |
373 seq=c&0x0F; | |
374 | |
375 if(ds->asf_packet){ | |
376 if(ds->asf_seq!=seq){ | |
377 // closed segment, finalize packet: | |
378 ds_add_packet(ds,ds->asf_packet); | |
379 ds->asf_packet=NULL; | |
2695 | 380 // printf("packet!\n"); |
2687 | 381 } else { |
382 // append data to it! | |
383 demux_packet_t* dp=ds->asf_packet; | |
384 dp->buffer=realloc(dp->buffer,dp->len+len); | |
385 //memcpy(dp->buffer+dp->len,data,len); | |
386 stream_read(demux->stream,dp->buffer+dp->len,len); | |
387 mp_dbg(MSGT_DEMUX,MSGL_DBG4,"data appended! %d+%d\n",dp->len,len); | |
388 dp->len+=len; | |
389 // we are ready now. | |
2695 | 390 if((c&0xF0)==0x20) --ds->asf_seq; // hack! |
2687 | 391 return 1; |
392 } | |
393 } | |
394 // create new packet: | |
395 { demux_packet_t* dp; | |
396 dp=new_demux_packet(len); | |
397 //memcpy(dp->buffer,data,len); | |
398 stream_read(demux->stream,dp->buffer,len); | |
3526 | 399 dp->pts=audio_rate?((float)audio_pos/(float)audio_rate):0; |
2687 | 400 // dp->flags=keyframe; |
401 // if(ds==demux->video) printf("ASF time: %8d dur: %5d \n",time,dur); | |
402 dp->pos=demux->filepos; | |
403 ds->asf_packet=dp; | |
404 ds->asf_seq=seq; | |
405 // we are ready now. | |
406 return 1; | |
407 } | |
408 | |
409 } | |
410 | |
411 static const short h263_format[8][2] = { | |
412 { 0, 0 }, | |
413 { 128, 96 }, | |
414 { 176, 144 }, | |
415 { 352, 288 }, | |
416 { 704, 576 }, | |
417 { 1408, 1152 }, | |
2784 | 418 { 320, 240 } // ??????? or 240x180 (found in vivo2) ? |
2687 | 419 }; |
420 | |
421 static unsigned char* buffer; | |
422 static int bufptr=0; | |
423 static int bitcnt=0; | |
424 static unsigned char buf=0; | |
425 static int format, width, height; | |
426 | |
427 static unsigned int x_get_bits(int n){ | |
428 unsigned int x=0; | |
429 while(n-->0){ | |
430 if(!bitcnt){ | |
431 // fill buff | |
432 buf=buffer[bufptr++]; | |
433 bitcnt=8; | |
434 } | |
435 //x=(x<<1)|(buf&1);buf>>=1; | |
436 x=(x<<1)|(buf>>7);buf<<=1; | |
437 --bitcnt; | |
438 } | |
439 return x; | |
440 } | |
441 | |
442 #define get_bits(xxx,n) x_get_bits(n) | |
443 #define get_bits1(xxx) x_get_bits(1) | |
444 #define skip_bits(xxx,n) x_get_bits(n) | |
445 #define skip_bits1(xxx) x_get_bits(1) | |
446 | |
447 /* most is hardcoded. should extend to handle all h263 streams */ | |
448 static int h263_decode_picture_header(unsigned char *b_ptr) | |
449 { | |
2928 | 450 // int i; |
2695 | 451 |
452 // for(i=0;i<16;i++) printf(" %02X",b_ptr[i]); printf("\n"); | |
2687 | 453 |
454 buffer=b_ptr; | |
455 bufptr=bitcnt=buf=0; | |
456 | |
457 /* picture header */ | |
2695 | 458 if (get_bits(&s->gb, 22) != 0x20){ |
459 printf("bad picture header\n"); | |
2687 | 460 return -1; |
2695 | 461 } |
2687 | 462 skip_bits(&s->gb, 8); /* picture timestamp */ |
463 | |
2695 | 464 if (get_bits1(&s->gb) != 1){ |
465 printf("bad marker\n"); | |
2687 | 466 return -1; /* marker */ |
2695 | 467 } |
468 if (get_bits1(&s->gb) != 0){ | |
469 printf("bad h263 id\n"); | |
2687 | 470 return -1; /* h263 id */ |
2695 | 471 } |
2687 | 472 skip_bits1(&s->gb); /* split screen off */ |
473 skip_bits1(&s->gb); /* camera off */ | |
474 skip_bits1(&s->gb); /* freeze picture release off */ | |
475 | |
476 format = get_bits(&s->gb, 3); | |
477 | |
478 if (format != 7) { | |
479 printf("h263_plus = 0 format = %d\n",format); | |
480 /* H.263v1 */ | |
481 width = h263_format[format][0]; | |
482 height = h263_format[format][1]; | |
483 printf("%d x %d\n",width,height); | |
2695 | 484 // if (!width) return -1; |
2687 | 485 |
486 printf("pict_type=%d\n",get_bits1(&s->gb)); | |
487 printf("unrestricted_mv=%d\n",get_bits1(&s->gb)); | |
488 #if 1 | |
489 printf("SAC: %d\n",get_bits1(&s->gb)); | |
490 printf("advanced prediction mode: %d\n",get_bits1(&s->gb)); | |
491 printf("PB frame: %d\n",get_bits1(&s->gb)); | |
492 #else | |
493 if (get_bits1(&s->gb) != 0) | |
494 return -1; /* SAC: off */ | |
495 if (get_bits1(&s->gb) != 0) | |
496 return -1; /* advanced prediction mode: off */ | |
497 if (get_bits1(&s->gb) != 0) | |
498 return -1; /* not PB frame */ | |
499 #endif | |
500 printf("qscale=%d\n",get_bits(&s->gb, 5)); | |
501 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ | |
502 } else { | |
503 printf("h263_plus = 1\n"); | |
504 /* H.263v2 */ | |
2695 | 505 if (get_bits(&s->gb, 3) != 1){ |
506 printf("H.263v2 A error\n"); | |
2687 | 507 return -1; |
2695 | 508 } |
509 if (get_bits(&s->gb, 3) != 6){ /* custom source format */ | |
510 printf("custom source format\n"); | |
2687 | 511 return -1; |
2695 | 512 } |
2687 | 513 skip_bits(&s->gb, 12); |
514 skip_bits(&s->gb, 3); | |
515 printf("pict_type=%d\n",get_bits(&s->gb, 3) + 1); | |
516 // if (s->pict_type != I_TYPE && | |
517 // s->pict_type != P_TYPE) | |
518 // return -1; | |
519 skip_bits(&s->gb, 7); | |
520 skip_bits(&s->gb, 4); /* aspect ratio */ | |
521 width = (get_bits(&s->gb, 9) + 1) * 4; | |
522 skip_bits1(&s->gb); | |
523 height = get_bits(&s->gb, 9) * 4; | |
524 printf("%d x %d\n",width,height); | |
2695 | 525 //if (height == 0) |
526 // return -1; | |
2687 | 527 printf("qscale=%d\n",get_bits(&s->gb, 5)); |
528 } | |
529 | |
530 /* PEI */ | |
531 while (get_bits1(&s->gb) != 0) { | |
532 skip_bits(&s->gb, 8); | |
533 } | |
534 // s->f_code = 1; | |
535 // s->width = width; | |
536 // s->height = height; | |
537 return 0; | |
538 } | |
539 | |
540 | |
2695 | 541 |
2687 | 542 void demux_open_vivo(demuxer_t* demuxer){ |
543 vivo_priv_t* priv=demuxer->priv; | |
544 | |
545 if(!ds_fill_buffer(demuxer->video)){ | |
546 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingVideoStreamBug); | |
547 return; | |
548 } | |
3526 | 549 |
550 audio_pos=0; | |
2687 | 551 |
552 h263_decode_picture_header(demuxer->video->buffer); | |
553 | |
3503 | 554 if (vivo_param_version != -1) |
555 priv->version = '0' + vivo_param_version; | |
2687 | 556 |
557 { 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
|
558 |
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
559 /* viv1, viv2 (for better codecs.conf) */ |
c0e6a39d2ab7
changed to generate fourcc's like: viv<version> -> viv1,viv2
alex
parents:
3069
diff
changeset
|
560 sh->format = mmioFOURCC('v', 'i', 'v', priv->version); |
2784 | 561 if(!sh->fps) |
2928 | 562 { |
2784 | 563 if (priv->fps) |
564 sh->fps=priv->fps; | |
565 else | |
566 sh->fps=15.0f; | |
2928 | 567 } |
2687 | 568 sh->frametime=1.0f/sh->fps; |
2805 | 569 |
3502 | 570 /* XXX: FIXME: can't scale image. */ |
571 /* hotfix to disable: */ | |
2805 | 572 priv->disp_width = priv->width; |
573 priv->disp_height = priv->height; | |
574 | |
3502 | 575 if (vivo_param_width != -1) |
576 priv->disp_width = priv->width = vivo_param_width; | |
577 | |
578 if (vivo_param_height != -1) | |
579 priv->disp_height = priv->height = vivo_param_height; | |
580 | |
581 if (vivo_param_vformat != -1) | |
582 { | |
583 priv->disp_width = priv->width = h263_format[vivo_param_vformat][0]; | |
584 priv->disp_height = priv->height = h263_format[vivo_param_vformat][1]; | |
585 } | |
586 | |
2784 | 587 if (priv->disp_width) |
588 sh->disp_w = priv->disp_width; | |
589 else | |
590 sh->disp_w = width; | |
591 if (priv->disp_height) | |
592 sh->disp_h = priv->disp_height; | |
593 else | |
594 sh->disp_h = height; | |
2687 | 595 |
596 // emulate BITMAPINFOHEADER: | |
597 sh->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
598 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); | |
599 sh->bih->biSize=40; | |
2784 | 600 if (priv->width) |
601 sh->bih->biWidth = priv->width; | |
602 else | |
603 sh->bih->biWidth = width; | |
604 if (priv->height) | |
605 sh->bih->biHeight = priv->height; | |
606 else | |
607 sh->bih->biHeight = height; | |
2687 | 608 sh->bih->biPlanes=1; |
609 sh->bih->biBitCount=24; | |
610 sh->bih->biCompression=sh->format; | |
611 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight*3; | |
3502 | 612 |
613 /* insert as stream */ | |
614 demuxer->video->sh=sh; | |
615 sh->ds=demuxer->video; | |
2687 | 616 demuxer->video->id=0; |
2928 | 617 |
3502 | 618 /* disable seeking */ |
2928 | 619 demuxer->seekable = 0; |
2788 | 620 |
2928 | 621 printf("VIVO Video stream %d size: display: %dx%d, codec: %lux%lu\n", |
2788 | 622 demuxer->video->id, sh->disp_w, sh->disp_h, sh->bih->biWidth, |
623 sh->bih->biHeight); | |
2687 | 624 } |
625 | |
3502 | 626 /* AUDIO init */ |
627 if (demuxer->audio->id >= -1){ | |
2687 | 628 if(!ds_fill_buffer(demuxer->audio)){ |
629 mp_msg(MSGT_DEMUX,MSGL_ERR,"VIVO: " MSGTR_MissingAudioStream); | |
630 } else | |
631 { sh_audio_t* sh=new_sh_audio(demuxer,1); | |
2788 | 632 |
3502 | 633 /* Select audio codec */ |
3471 | 634 if (priv->audio_codec == 0) |
635 { | |
636 if (priv->version == '2') | |
637 priv->audio_codec = VIVO_AUDIO_SIREN; | |
638 else | |
639 priv->audio_codec = VIVO_AUDIO_G723; | |
640 } | |
3502 | 641 if (vivo_param_acodec != NULL) |
642 { | |
643 if (!strcasecmp(vivo_param_acodec, "g723")) | |
644 priv->audio_codec = VIVO_AUDIO_G723; | |
645 if (!strcasecmp(vivo_param_acodec, "siren")) | |
646 priv->audio_codec = VIVO_AUDIO_SIREN; | |
647 } | |
3471 | 648 |
3502 | 649 sh->format = -1; |
650 if (priv->audio_codec == VIVO_AUDIO_G723) | |
651 sh->format = 0x111; | |
3471 | 652 if (priv->audio_codec == VIVO_AUDIO_SIREN) |
3502 | 653 sh->format = 0x112; |
654 if (sh->format == -1) | |
655 { | |
656 mp_msg(MSGT_DEMUX, MSGL_ERR, "VIVO: Not support audio codec (%d)\n", | |
657 priv->audio_codec); | |
658 goto nosound; | |
659 } | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
660 |
2687 | 661 // Emulate WAVEFORMATEX struct: |
662 sh->wf=malloc(sizeof(WAVEFORMATEX)); | |
663 memset(sh->wf,0,sizeof(WAVEFORMATEX)); | |
3439
192449c155c7
fixed Waveformatheader emu and added vivo1/2 audio detection
alex
parents:
3245
diff
changeset
|
664 sh->wf->wFormatTag=sh->format; |
3502 | 665 sh->wf->nChannels=1; /* 1 channels for both Siren and G.723 */ |
666 | |
667 /* Set bits per sample */ | |
3471 | 668 if (priv->audio_codec == VIVO_AUDIO_SIREN) |
3502 | 669 sh->wf->wBitsPerSample = 16; |
3471 | 670 else |
3502 | 671 if (priv->audio_codec == VIVO_AUDIO_G723) |
672 sh->wf->wBitsPerSample = 8; | |
673 | |
674 /* Set sampling rate */ | |
675 if (priv->audio_samplerate) /* got from header */ | |
676 sh->wf->nSamplesPerSec = priv->audio_samplerate; | |
3471 | 677 else |
678 { | |
679 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
3502 | 680 sh->wf->nSamplesPerSec = 16000; |
681 if (priv->audio_codec == VIVO_AUDIO_G723) | |
682 sh->wf->nSamplesPerSec = 8000; | |
3471 | 683 } |
3502 | 684 if (vivo_param_samplerate != -1) |
685 sh->wf->nSamplesPerSec = vivo_param_samplerate; | |
686 | |
687 /* Set audio bitrate */ | |
688 if (priv->audio_bitrate) /* got from header */ | |
689 sh->wf->nAvgBytesPerSec = priv->audio_bitrate; | |
2784 | 690 else |
3471 | 691 { |
692 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
693 sh->wf->nAvgBytesPerSec = 2000; | |
3502 | 694 if (priv->audio_codec == VIVO_AUDIO_G723) |
3471 | 695 sh->wf->nAvgBytesPerSec = 800; |
696 } | |
3502 | 697 if (vivo_param_abitrate != -1) |
698 sh->wf->nAvgBytesPerSec = vivo_param_abitrate; | |
3526 | 699 audio_rate=sh->wf->nAvgBytesPerSec; |
3502 | 700 |
3471 | 701 if (!priv->audio_bytesperblock) |
702 { | |
703 if (priv->audio_codec == VIVO_AUDIO_SIREN) | |
3502 | 704 sh->wf->nBlockAlign = 40; |
705 if (priv->audio_codec == VIVO_AUDIO_G723) | |
706 sh->wf->nBlockAlign = 24; | |
3471 | 707 } |
708 else | |
3502 | 709 sh->wf->nBlockAlign = priv->audio_bytesperblock; |
710 if (vivo_param_bytesperblock != -1) | |
711 sh->wf->nBlockAlign = vivo_param_bytesperblock; | |
712 | |
713 sound_ok: | |
714 /* insert as stream */ | |
715 demuxer->audio->sh=sh; | |
716 sh->ds=demuxer->audio; | |
2687 | 717 demuxer->audio->id=1; |
3502 | 718 nosound: |
2687 | 719 } |
2695 | 720 } |
2687 | 721 |
722 } | |
723 | |
2788 | 724 void demux_close_vivo(demuxer_t *demuxer) |
725 { | |
726 vivo_priv_t* priv=demuxer->priv; | |
2809 | 727 |
728 if (priv) { | |
729 if (priv->title) | |
730 free(priv->title); | |
731 if (priv->author) | |
732 free(priv->author); | |
733 if (priv->copyright) | |
734 free(priv->copyright); | |
735 if (priv->producer) | |
736 free(priv->producer); | |
2788 | 737 free(priv); |
2809 | 738 } |
2788 | 739 return; |
740 } |