Mercurial > mplayer.hg
annotate demux_mov.c @ 2175:1deee7703f33
just version update
author | eyck |
---|---|
date | Fri, 12 Oct 2001 11:56:02 +0000 |
parents | 0c6cef85d507 |
children | 10b279d72a8f |
rev | line source |
---|---|
2148 | 1 // QuickTime MOV file parser by A'rpi |
2 // based on TOOLS/movinfo.c by me & Al3x | |
3 // compressed header support from moov.c of the openquicktime lib. | |
1490 | 4 |
5 #include <stdio.h> | |
6 #include <stdlib.h> | |
7 #include <unistd.h> | |
8 | |
1567 | 9 #include "config.h" |
2148 | 10 |
11 #ifdef HAVE_PNG | |
12 // should be detected by ./configure... | |
13 #define HAVE_ZLIB | |
14 #endif | |
15 | |
1567 | 16 #include "mp_msg.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
17 #include "help_mp.h" |
1490 | 18 |
19 #include "stream.h" | |
20 #include "demuxer.h" | |
21 | |
22 #include "wine/mmreg.h" | |
23 #include "wine/avifmt.h" | |
24 #include "wine/vfw.h" | |
25 | |
26 #include "codec-cfg.h" | |
27 #include "stheader.h" | |
28 | |
2148 | 29 #ifdef HAVE_ZLIB |
30 #include <zlib.h> | |
31 #endif | |
32 | |
1490 | 33 typedef struct { |
2100 | 34 unsigned int pts; // duration |
35 unsigned int size; | |
36 off_t pos; | |
37 } mov_sample_t; | |
38 | |
39 typedef struct { | |
2115 | 40 unsigned int sample; // number of the first sample in teh chunk |
41 unsigned int size; // number of samples in the chunk | |
42 int desc; // for multiple codecs mode - not used | |
2100 | 43 off_t pos; |
44 } mov_chunk_t; | |
45 | |
46 typedef struct { | |
47 unsigned int first; | |
48 unsigned int spc; | |
49 unsigned int sdid; | |
50 } mov_chunkmap_t; | |
51 | |
52 typedef struct { | |
2115 | 53 unsigned int num; |
54 unsigned int dur; | |
55 } mov_durmap_t; | |
56 | |
57 typedef struct { | |
1490 | 58 int id; |
59 int type; | |
2101 | 60 int pos; |
61 // | |
1490 | 62 int timescale; |
2100 | 63 unsigned int length; |
2115 | 64 int samplesize; // 0 = variable |
65 int duration; // 0 = variable | |
1490 | 66 int width,height; // for video |
67 unsigned int fourcc; | |
2115 | 68 // |
2101 | 69 int tkdata_len; // track data |
70 unsigned char* tkdata; | |
71 int stdata_len; // stream data | |
72 unsigned char* stdata; | |
2100 | 73 int samples_size; |
74 mov_sample_t* samples; | |
75 int chunks_size; | |
76 mov_chunk_t* chunks; | |
77 int chunkmap_size; | |
78 mov_chunkmap_t* chunkmap; | |
2115 | 79 int durmap_size; |
80 mov_durmap_t* durmap; | |
1490 | 81 } mov_track_t; |
82 | |
2100 | 83 void mov_build_index(mov_track_t* trak){ |
84 int i,j,s; | |
85 int last=trak->chunks_size; | |
2115 | 86 unsigned int pts=0; |
2100 | 87 printf("MOV track: %d chunks, %d samples\n",trak->chunks_size,trak->samples_size); |
88 printf("pts=%d scale=%d time=%5.3f\n",trak->length,trak->timescale,(float)trak->length/(float)trak->timescale); | |
89 // process chunkmap: | |
90 i=trak->chunkmap_size; | |
91 while(i>0){ | |
92 --i; | |
93 for(j=trak->chunkmap[i].first;j<last;j++){ | |
94 trak->chunks[j].desc=trak->chunkmap[i].sdid; | |
95 trak->chunks[j].size=trak->chunkmap[i].spc; | |
96 } | |
97 last=trak->chunkmap[i].first; | |
98 } | |
2115 | 99 |
100 // calc pts of chunks: | |
101 s=0; | |
102 for(j=0;j<trak->chunks_size;j++){ | |
103 trak->chunks[j].sample=s; | |
104 s+=trak->chunks[j].size; | |
105 } | |
106 | |
107 if(!trak->samples_size){ | |
108 // constant sampesize | |
109 if(trak->durmap_size==1 || (trak->durmap_size==2 && trak->durmap[1].num==1)){ | |
110 } else printf("*** constant samplesize & variable duration not yet supported! ***\nContact the author if you have such sample file!\n"); | |
111 return; | |
112 } | |
113 | |
114 // calc pts: | |
115 s=0; | |
116 for(j=0;j<trak->durmap_size;j++){ | |
117 for(i=0;i<trak->durmap[j].num;i++){ | |
118 trak->samples[s].pts=pts; | |
119 ++s; | |
120 pts+=trak->durmap[j].dur; | |
121 } | |
122 } | |
2100 | 123 |
124 // calc sample offsets | |
125 s=0; | |
126 for(j=0;j<trak->chunks_size;j++){ | |
127 off_t pos=trak->chunks[j].pos; | |
128 for(i=0;i<trak->chunks[j].size;i++){ | |
129 trak->samples[s].pos=pos; | |
130 #if 0 | |
131 printf("Sample %5d: pts=%8d off=0x%08X size=%d\n",s, | |
132 trak->samples[s].pts, | |
133 (int)trak->samples[s].pos, | |
134 trak->samples[s].size); | |
135 #endif | |
136 pos+=trak->samples[s].size; | |
137 ++s; | |
138 } | |
139 } | |
140 | |
141 } | |
142 | |
1490 | 143 #define MOV_MAX_TRACKS 256 |
144 | |
145 #define MOV_TRAK_UNKNOWN 0 | |
146 #define MOV_TRAK_VIDEO 1 | |
147 #define MOV_TRAK_AUDIO 2 | |
148 | |
149 typedef struct { | |
150 off_t moov_start; | |
151 off_t moov_end; | |
152 off_t mdat_start; | |
153 off_t mdat_end; | |
154 int track_db; | |
155 mov_track_t* tracks[MOV_MAX_TRACKS]; | |
156 } mov_priv_t; | |
157 | |
158 #define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d)) | |
159 | |
160 int mov_check_file(demuxer_t* demuxer){ | |
161 int flags=0; | |
162 mov_priv_t* priv=malloc(sizeof(mov_priv_t)); | |
163 | |
1567 | 164 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for MOV\n"); |
1490 | 165 |
166 memset(priv,0,sizeof(mov_priv_t)); | |
167 demuxer->priv=priv; | |
168 | |
169 while(1){ | |
170 off_t len=stream_read_dword(demuxer->stream); | |
171 unsigned int id=stream_read_dword(demuxer->stream); | |
172 if(stream_eof(demuxer->stream)) break; // EOF | |
173 if(len<8) break; // invalid chunk | |
174 switch(id){ | |
175 case MOV_FOURCC('m','o','o','v'): | |
1567 | 176 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n"); |
1490 | 177 priv->moov_start=stream_tell(demuxer->stream); |
178 priv->moov_end=priv->moov_start+len-8; | |
179 flags|=1; | |
180 break; | |
181 case MOV_FOURCC('m','d','a','t'): | |
1567 | 182 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie DATA found!\n"); |
1490 | 183 priv->mdat_start=stream_tell(demuxer->stream); |
184 priv->mdat_end=priv->mdat_start+len-8; | |
185 flags|=2; | |
186 break; | |
187 default: | |
1567 | 188 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); |
1490 | 189 } |
190 if(!stream_skip(demuxer->stream,len-8)) break; | |
191 } | |
2148 | 192 |
193 if(flags==1) | |
194 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing data (mdat) chunk! Maybe broken file...\n"); | |
195 else if(flags==2) | |
196 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing header (moov/cmov) chunk! Maybe broken file...\n"); | |
1490 | 197 |
198 return (flags==3); | |
199 } | |
200 | |
201 static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak){ | |
202 mov_priv_t* priv=demuxer->priv; | |
203 while(1){ | |
204 off_t pos; | |
205 off_t len; | |
206 unsigned int id; | |
207 // | |
208 pos=stream_tell(demuxer->stream); | |
2148 | 209 // printf("stream_tell==%d\n",pos); |
1490 | 210 if(pos>=endpos) return; // END |
211 len=stream_read_dword(demuxer->stream); | |
2148 | 212 // printf("len==%d\n",len); |
1490 | 213 if(len<8) return; // error |
214 len-=8; | |
215 id=stream_read_dword(demuxer->stream); | |
216 // | |
1567 | 217 mp_msg(MSGT_DEMUX,MSGL_DBG2,"lschunks %.4s %d\n",&id,(int)len); |
1490 | 218 // |
219 if(trak){ | |
220 switch(id){ | |
221 case MOV_FOURCC('t','k','h','d'): { | |
1567 | 222 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sTrack header!\n",level,""); |
2101 | 223 // read codec data |
224 trak->tkdata_len=len; | |
225 trak->tkdata=malloc(trak->tkdata_len); | |
226 stream_read(demuxer->stream,trak->tkdata,trak->tkdata_len); | |
1490 | 227 break; |
228 } | |
229 case MOV_FOURCC('m','d','h','d'): { | |
2100 | 230 unsigned int tmp; |
1567 | 231 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia header!\n",level,""); |
2100 | 232 #if 0 |
233 tmp=stream_read_dword(demuxer->stream); | |
234 printf("dword1: 0x%08X (%d)\n",tmp,tmp); | |
235 tmp=stream_read_dword(demuxer->stream); | |
236 printf("dword2: 0x%08X (%d)\n",tmp,tmp); | |
237 tmp=stream_read_dword(demuxer->stream); | |
238 printf("dword3: 0x%08X (%d)\n",tmp,tmp); | |
239 tmp=stream_read_dword(demuxer->stream); | |
240 printf("dword4: 0x%08X (%d)\n",tmp,tmp); | |
241 tmp=stream_read_dword(demuxer->stream); | |
242 printf("dword5: 0x%08X (%d)\n",tmp,tmp); | |
243 tmp=stream_read_dword(demuxer->stream); | |
244 printf("dword6: 0x%08X (%d)\n",tmp,tmp); | |
245 #endif | |
246 stream_skip(demuxer->stream,12); | |
1490 | 247 // read timescale |
2100 | 248 trak->timescale=stream_read_dword(demuxer->stream); |
249 // read length | |
250 trak->length=stream_read_dword(demuxer->stream); | |
1490 | 251 break; |
252 } | |
253 case MOV_FOURCC('v','m','h','d'): { | |
1567 | 254 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sVideo header!\n",level,""); |
1490 | 255 trak->type=MOV_TRAK_VIDEO; |
256 // read video data | |
257 break; | |
258 } | |
259 case MOV_FOURCC('s','m','h','d'): { | |
1567 | 260 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSound header!\n",level,""); |
1490 | 261 trak->type=MOV_TRAK_AUDIO; |
262 // read audio data | |
263 break; | |
264 } | |
265 case MOV_FOURCC('s','t','s','d'): { | |
266 int i=stream_read_dword(demuxer->stream); // temp! | |
267 int count=stream_read_dword(demuxer->stream); | |
1567 | 268 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sDescription list! (cnt:%d)\n",level,"",count); |
1490 | 269 for(i=0;i<count;i++){ |
270 off_t pos=stream_tell(demuxer->stream); | |
271 off_t len=stream_read_dword(demuxer->stream); | |
272 unsigned int fourcc=stream_read_dword_le(demuxer->stream); | |
273 if(len<8) break; // error | |
1567 | 274 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s desc #%d: %.4s",level,"",i,&fourcc); |
1490 | 275 if(!i){ |
276 trak->fourcc=fourcc; | |
277 // read codec data | |
2101 | 278 trak->stdata_len=len-8; |
279 trak->stdata=malloc(trak->stdata_len); | |
280 stream_read(demuxer->stream,trak->stdata,trak->stdata_len); | |
281 if(trak->type==MOV_TRAK_VIDEO && trak->stdata_len>43){ | |
282 mp_msg(MSGT_DEMUX,MSGL_V," '%.*s'",trak->stdata_len-43,trak->stdata+43); | |
1490 | 283 } |
284 } | |
1567 | 285 mp_msg(MSGT_DEMUX,MSGL_V,"\n"); |
1490 | 286 if(fourcc!=trak->fourcc && i) |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
287 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC); |
1490 | 288 if(!stream_seek(demuxer->stream,pos+len)) break; |
289 } | |
290 break; | |
291 } | |
2100 | 292 case MOV_FOURCC('s','t','t','s'): { |
293 int temp=stream_read_dword(demuxer->stream); | |
294 int len=stream_read_dword(demuxer->stream); | |
295 int i; | |
296 int x=0; | |
297 unsigned int pts=0; | |
298 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample duration table! (%d blocks)\n",level,"",len); | |
2115 | 299 trak->durmap=malloc(sizeof(mov_durmap_t)*len); |
300 memset(trak->durmap,0,sizeof(mov_durmap_t)*len); | |
301 trak->durmap_size=len; | |
2100 | 302 for(i=0;i<len;i++){ |
2115 | 303 trak->durmap[i].num=stream_read_dword(demuxer->stream); |
304 trak->durmap[i].dur=stream_read_dword(demuxer->stream); | |
305 pts+=trak->durmap[i].num*trak->durmap[i].dur; | |
2100 | 306 } |
307 if(trak->length!=pts) printf("Warning! pts=%d length=%d\n",pts,trak->length); | |
308 break; | |
309 } | |
310 case MOV_FOURCC('s','t','s','c'): { | |
311 int temp=stream_read_dword(demuxer->stream); | |
312 int len=stream_read_dword(demuxer->stream); | |
313 int i; | |
314 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample->Chunk mapping table! (%d blocks)\n",level,"",len); | |
315 // read data: | |
316 trak->chunkmap_size=len; | |
317 trak->chunkmap=malloc(sizeof(mov_chunkmap_t)*len); | |
318 for(i=0;i<len;i++){ | |
2103 | 319 trak->chunkmap[i].first=stream_read_dword(demuxer->stream)-1; |
2100 | 320 trak->chunkmap[i].spc=stream_read_dword(demuxer->stream); |
321 trak->chunkmap[i].sdid=stream_read_dword(demuxer->stream); | |
322 } | |
323 break; | |
324 } | |
325 case MOV_FOURCC('s','t','s','z'): { | |
326 int temp=stream_read_dword(demuxer->stream); | |
327 int ss=stream_read_dword(demuxer->stream); | |
328 int len=stream_read_dword(demuxer->stream); | |
329 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample size table! len=%d ss=%d\n",level,"",len,ss); | |
2115 | 330 trak->samplesize=ss; |
331 if(!ss){ | |
332 // variable samplesize | |
333 int i; | |
2100 | 334 trak->samples=realloc(trak->samples,sizeof(mov_sample_t)*len); |
335 trak->samples_size=len; | |
2115 | 336 for(i=0;i<len;i++) |
337 trak->samples[i].size=stream_read_dword(demuxer->stream); | |
2100 | 338 } |
339 break; | |
340 } | |
341 case MOV_FOURCC('s','t','c','o'): { | |
342 int temp=stream_read_dword(demuxer->stream); | |
343 int len=stream_read_dword(demuxer->stream); | |
344 int i; | |
345 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sChunk offset table! (%d chunks)\n",level,"",len); | |
346 // extend array if needed: | |
347 if(len>trak->chunks_size){ | |
348 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len); | |
349 trak->chunks_size=len; | |
350 } | |
351 // read elements: | |
352 for(i=0;i<len;i++) trak->chunks[i].pos=stream_read_dword(demuxer->stream); | |
353 break; | |
354 } | |
1490 | 355 case MOV_FOURCC('m','d','i','a'): { |
1567 | 356 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia stream!\n",level,""); |
1490 | 357 lschunks(demuxer,level+1,pos+len,trak); |
358 break; | |
359 } | |
360 case MOV_FOURCC('m','i','n','f'): { | |
1567 | 361 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia info!\n",level,""); |
1490 | 362 lschunks(demuxer,level+1,pos+len,trak); |
363 break; | |
364 } | |
365 case MOV_FOURCC('s','t','b','l'): { | |
1567 | 366 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample info!\n",level,""); |
1490 | 367 lschunks(demuxer,level+1,pos+len,trak); |
368 break; | |
369 } | |
370 }//switch(id) | |
371 } else | |
372 if(id==MOV_FOURCC('t','r','a','k')){ | |
373 // if(trak) printf("MOV: Warning! trak in trak?\n"); | |
374 if(priv->track_db>=MOV_MAX_TRACKS){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
375 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVtooManyTrk); |
1490 | 376 return; |
377 } | |
378 trak=malloc(sizeof(mov_track_t)); | |
379 memset(trak,0,sizeof(mov_track_t)); | |
1567 | 380 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Track #%d:\n",priv->track_db); |
1490 | 381 trak->id=priv->track_db; |
2100 | 382 priv->tracks[priv->track_db]=trak; |
1490 | 383 lschunks(demuxer,level+1,pos+len,trak); |
2100 | 384 mov_build_index(trak); |
385 switch(trak->type){ | |
386 case MOV_TRAK_AUDIO: { | |
387 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db); | |
388 sh->format=trak->fourcc; | |
2101 | 389 printf("!!! audio bits: %d chans: %d\n",trak->stdata[19],trak->stdata[17]); |
2115 | 390 printf("Fourcc: %.4s\n",&trak->fourcc); |
2101 | 391 // Emulate WAVEFORMATEX struct: |
392 sh->wf=malloc(sizeof(WAVEFORMATEX)); | |
393 memset(sh->wf,0,sizeof(WAVEFORMATEX)); | |
394 sh->wf->nChannels=trak->stdata[17]; | |
395 sh->wf->wBitsPerSample=trak->stdata[19]; | |
396 sh->wf->nSamplesPerSec=trak->timescale; | |
397 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*((sh->wf->wBitsPerSample+7)/8)*sh->wf->nSamplesPerSec; | |
398 // Selection: | |
399 if(demuxer->audio->id==-1 || demuxer->audio->id==priv->track_db){ | |
400 // (auto)selected audio track: | |
401 demuxer->audio->id=priv->track_db; | |
402 demuxer->audio->sh=sh; sh->ds=demuxer->audio; | |
403 } | |
2100 | 404 break; |
405 } | |
406 case MOV_TRAK_VIDEO: { | |
407 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); | |
408 sh->format=trak->fourcc; | |
409 sh->fps=trak->timescale; | |
410 sh->frametime=1.0f/sh->fps; | |
2101 | 411 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8); |
412 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); | |
413 | |
414 // emulate BITMAPINFOHEADER: | |
415 sh->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
416 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); | |
417 sh->bih->biSize=40; | |
418 sh->bih->biWidth=sh->disp_w; | |
419 sh->bih->biHeight=sh->disp_h; | |
420 sh->bih->biPlanes=0; | |
421 sh->bih->biBitCount=16; | |
422 sh->bih->biCompression=trak->fourcc; | |
423 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight; | |
424 | |
425 printf("Image size: %d x %d\n",sh->disp_w,sh->disp_h); | |
2115 | 426 printf("Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43); |
427 | |
2101 | 428 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){ |
429 // (auto)selected video track: | |
430 demuxer->video->id=priv->track_db; | |
431 demuxer->video->sh=sh; sh->ds=demuxer->video; | |
432 } | |
2100 | 433 break; |
434 } | |
435 } | |
436 printf("--------------\n"); | |
437 priv->track_db++; | |
1490 | 438 trak=NULL; |
439 } else | |
2148 | 440 #ifndef HAVE_ZLIB |
1490 | 441 if(id==MOV_FOURCC('c','m','o','v')){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
442 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); |
1490 | 443 return; |
444 } | |
2148 | 445 #else |
446 if(id==MOV_FOURCC('c','m','o','v')){ | |
447 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); | |
448 lschunks(demuxer,level+1,pos+len,NULL); | |
449 } else | |
450 if(id==MOV_FOURCC('d','c','o','m')){ | |
451 // int temp=stream_read_dword(demuxer->stream); | |
452 unsigned int len=stream_read_dword(demuxer->stream); | |
453 printf("Compressed header uses %.4s algo!\n",&len); | |
454 } else | |
455 if(id==MOV_FOURCC('c','m','v','d')){ | |
456 // int temp=stream_read_dword(demuxer->stream); | |
457 unsigned int moov_sz=stream_read_dword(demuxer->stream); | |
458 unsigned int cmov_sz=len-4; | |
459 unsigned char* cmov_buf=malloc(cmov_sz); | |
460 unsigned char* moov_buf=malloc(moov_sz+16); | |
461 int zret; | |
462 z_stream zstrm; | |
463 stream_t* backup; | |
464 | |
465 printf("Compressed header size: %d / %d\n",cmov_sz,moov_sz); | |
466 | |
467 stream_read(demuxer->stream,cmov_buf,cmov_sz); | |
468 | |
469 zstrm.zalloc = (alloc_func)0; | |
470 zstrm.zfree = (free_func)0; | |
471 zstrm.opaque = (voidpf)0; | |
472 zstrm.next_in = cmov_buf; | |
473 zstrm.avail_in = cmov_sz; | |
474 zstrm.next_out = moov_buf; | |
475 zstrm.avail_out = moov_sz; | |
476 | |
477 zret = inflateInit(&zstrm); | |
478 if (zret != Z_OK) | |
479 { fprintf(stderr,"QT cmov: inflateInit err %d\n",zret); | |
480 return; | |
481 } | |
482 zret = inflate(&zstrm, Z_NO_FLUSH); | |
483 if ((zret != Z_OK) && (zret != Z_STREAM_END)) | |
484 { fprintf(stderr,"QT cmov inflate: ERR %d\n",zret); | |
485 return; | |
486 } | |
487 #if 0 | |
488 else { | |
489 FILE *DecOut; | |
490 DecOut = fopen("Out.bin", "w"); | |
491 fwrite(moov_buf, 1, moov_sz, DecOut); | |
492 fclose(DecOut); | |
493 } | |
494 #endif | |
495 if(moov_sz != zstrm.total_out) printf("Warning! moov size differs cmov: %d zlib: %d\n",moov_sz,zstrm.total_out); | |
496 zret = inflateEnd(&zstrm); | |
497 | |
498 backup=demuxer->stream; | |
499 demuxer->stream=new_memory_stream(moov_buf,moov_sz); | |
500 stream_skip(demuxer->stream,8); | |
501 lschunks(demuxer,level+1,moov_sz,NULL); // parse uncompr. 'moov' | |
502 //free_stream(demuxer->stream); | |
503 demuxer->stream=backup; | |
504 | |
505 } | |
506 #endif | |
1490 | 507 |
508 pos+=len+8; | |
509 if(pos>=endpos) break; | |
510 if(!stream_seek(demuxer->stream,pos)) break; | |
511 } | |
512 } | |
513 | |
514 int mov_read_header(demuxer_t* demuxer){ | |
515 mov_priv_t* priv=demuxer->priv; | |
516 | |
2100 | 517 printf("mov_read_header!\n"); |
1490 | 518 |
519 // Parse header: | |
2100 | 520 stream_reset(demuxer->stream); |
1490 | 521 if(!stream_seek(demuxer->stream,priv->moov_start)) return 0; // ??? |
522 lschunks(demuxer, 0, priv->moov_end, NULL); | |
523 | |
2127 | 524 #if 1 |
525 return 1; | |
526 #else | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
527 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVnotyetsupp); |
2127 | 528 return 0; |
529 #endif | |
1490 | 530 } |
2101 | 531 |
532 // return value: | |
533 // 0 = EOF or no stream found | |
534 // 1 = successfully read a packet | |
535 int demux_mov_fill_buffer(demuxer_t *demuxer,demux_stream_t* ds){ | |
536 mov_priv_t* priv=demuxer->priv; | |
537 mov_track_t* trak=NULL; | |
538 float pts; | |
539 | |
540 if(ds->id<0 || ds->id>=priv->track_db) return 0; | |
541 trak=priv->tracks[ds->id]; | |
542 | |
2115 | 543 if(trak->samplesize){ |
544 // read chunk: | |
545 if(trak->pos>=trak->chunks_size) return 0; // EOF | |
546 stream_seek(demuxer->stream,trak->chunks[trak->pos].pos); | |
547 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
548 ds_read_packet(ds,demuxer->stream,trak->chunks[trak->pos].size*trak->samplesize,pts,trak->chunks[trak->pos].pos,0); | |
549 } else { | |
2101 | 550 // read sample: |
551 if(trak->pos>=trak->samples_size) return 0; // EOF | |
552 stream_seek(demuxer->stream,trak->samples[trak->pos].pos); | |
553 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; | |
554 ds_read_packet(ds,demuxer->stream,trak->samples[trak->pos].size,pts,trak->samples[trak->pos].pos,0); | |
2115 | 555 } |
2101 | 556 ++trak->pos; |
2115 | 557 |
2101 | 558 return 1; |
559 | |
560 } |