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