Mercurial > mplayer.hg
annotate demux_mov.c @ 2264:7851375ea156
increased precission of s_xinc s_xinc2 (needed for the mmx2 bugfix)
moved mmx variables to top to avoid alignment issues
mmx2 code should work fine now if and only if the input width is %16=0 and the output width is %32=0
reordered some code (5% faster with a simply -benchmark)
first line bug fixed (i hope i didnt introduce any new bugs with that ...)
changed a lot of the vertical scale setup code, i hope i fixed something and didnt mess it up :)
a few known bugs left (rightmost line is wrong)
MMX2 code will only be used for upscaling & acceptable widthˇs
16bit dithering can be disabled
author | michael |
---|---|
date | Thu, 18 Oct 2001 22:27:13 +0000 |
parents | 10b279d72a8f |
children |
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)){ | |
2227 | 110 trak->duration=trak->durmap[0].dur; |
2115 | 111 } else printf("*** constant samplesize & variable duration not yet supported! ***\nContact the author if you have such sample file!\n"); |
112 return; | |
113 } | |
114 | |
115 // calc pts: | |
116 s=0; | |
117 for(j=0;j<trak->durmap_size;j++){ | |
118 for(i=0;i<trak->durmap[j].num;i++){ | |
119 trak->samples[s].pts=pts; | |
120 ++s; | |
121 pts+=trak->durmap[j].dur; | |
122 } | |
123 } | |
2100 | 124 |
125 // calc sample offsets | |
126 s=0; | |
127 for(j=0;j<trak->chunks_size;j++){ | |
128 off_t pos=trak->chunks[j].pos; | |
129 for(i=0;i<trak->chunks[j].size;i++){ | |
130 trak->samples[s].pos=pos; | |
131 #if 0 | |
132 printf("Sample %5d: pts=%8d off=0x%08X size=%d\n",s, | |
133 trak->samples[s].pts, | |
134 (int)trak->samples[s].pos, | |
135 trak->samples[s].size); | |
136 #endif | |
137 pos+=trak->samples[s].size; | |
138 ++s; | |
139 } | |
140 } | |
141 | |
142 } | |
143 | |
1490 | 144 #define MOV_MAX_TRACKS 256 |
145 | |
146 #define MOV_TRAK_UNKNOWN 0 | |
147 #define MOV_TRAK_VIDEO 1 | |
148 #define MOV_TRAK_AUDIO 2 | |
149 | |
150 typedef struct { | |
151 off_t moov_start; | |
152 off_t moov_end; | |
153 off_t mdat_start; | |
154 off_t mdat_end; | |
155 int track_db; | |
156 mov_track_t* tracks[MOV_MAX_TRACKS]; | |
157 } mov_priv_t; | |
158 | |
159 #define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d)) | |
160 | |
161 int mov_check_file(demuxer_t* demuxer){ | |
162 int flags=0; | |
163 mov_priv_t* priv=malloc(sizeof(mov_priv_t)); | |
164 | |
1567 | 165 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for MOV\n"); |
1490 | 166 |
167 memset(priv,0,sizeof(mov_priv_t)); | |
168 demuxer->priv=priv; | |
169 | |
170 while(1){ | |
171 off_t len=stream_read_dword(demuxer->stream); | |
172 unsigned int id=stream_read_dword(demuxer->stream); | |
173 if(stream_eof(demuxer->stream)) break; // EOF | |
174 if(len<8) break; // invalid chunk | |
175 switch(id){ | |
176 case MOV_FOURCC('m','o','o','v'): | |
1567 | 177 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n"); |
1490 | 178 priv->moov_start=stream_tell(demuxer->stream); |
179 priv->moov_end=priv->moov_start+len-8; | |
180 flags|=1; | |
181 break; | |
182 case MOV_FOURCC('m','d','a','t'): | |
1567 | 183 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie DATA found!\n"); |
1490 | 184 priv->mdat_start=stream_tell(demuxer->stream); |
185 priv->mdat_end=priv->mdat_start+len-8; | |
186 flags|=2; | |
187 break; | |
188 default: | |
1567 | 189 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); |
1490 | 190 } |
191 if(!stream_skip(demuxer->stream,len-8)) break; | |
192 } | |
2148 | 193 |
194 if(flags==1) | |
195 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing data (mdat) chunk! Maybe broken file...\n"); | |
196 else if(flags==2) | |
197 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing header (moov/cmov) chunk! Maybe broken file...\n"); | |
1490 | 198 |
199 return (flags==3); | |
200 } | |
201 | |
202 static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak){ | |
203 mov_priv_t* priv=demuxer->priv; | |
204 while(1){ | |
205 off_t pos; | |
206 off_t len; | |
207 unsigned int id; | |
208 // | |
209 pos=stream_tell(demuxer->stream); | |
2148 | 210 // printf("stream_tell==%d\n",pos); |
1490 | 211 if(pos>=endpos) return; // END |
212 len=stream_read_dword(demuxer->stream); | |
2148 | 213 // printf("len==%d\n",len); |
1490 | 214 if(len<8) return; // error |
215 len-=8; | |
216 id=stream_read_dword(demuxer->stream); | |
217 // | |
1567 | 218 mp_msg(MSGT_DEMUX,MSGL_DBG2,"lschunks %.4s %d\n",&id,(int)len); |
1490 | 219 // |
220 if(trak){ | |
221 switch(id){ | |
222 case MOV_FOURCC('t','k','h','d'): { | |
1567 | 223 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sTrack header!\n",level,""); |
2101 | 224 // read codec data |
225 trak->tkdata_len=len; | |
226 trak->tkdata=malloc(trak->tkdata_len); | |
227 stream_read(demuxer->stream,trak->tkdata,trak->tkdata_len); | |
1490 | 228 break; |
229 } | |
230 case MOV_FOURCC('m','d','h','d'): { | |
2100 | 231 unsigned int tmp; |
1567 | 232 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia header!\n",level,""); |
2100 | 233 #if 0 |
234 tmp=stream_read_dword(demuxer->stream); | |
235 printf("dword1: 0x%08X (%d)\n",tmp,tmp); | |
236 tmp=stream_read_dword(demuxer->stream); | |
237 printf("dword2: 0x%08X (%d)\n",tmp,tmp); | |
238 tmp=stream_read_dword(demuxer->stream); | |
239 printf("dword3: 0x%08X (%d)\n",tmp,tmp); | |
240 tmp=stream_read_dword(demuxer->stream); | |
241 printf("dword4: 0x%08X (%d)\n",tmp,tmp); | |
242 tmp=stream_read_dword(demuxer->stream); | |
243 printf("dword5: 0x%08X (%d)\n",tmp,tmp); | |
244 tmp=stream_read_dword(demuxer->stream); | |
245 printf("dword6: 0x%08X (%d)\n",tmp,tmp); | |
246 #endif | |
247 stream_skip(demuxer->stream,12); | |
1490 | 248 // read timescale |
2100 | 249 trak->timescale=stream_read_dword(demuxer->stream); |
250 // read length | |
251 trak->length=stream_read_dword(demuxer->stream); | |
1490 | 252 break; |
253 } | |
254 case MOV_FOURCC('v','m','h','d'): { | |
1567 | 255 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sVideo header!\n",level,""); |
1490 | 256 trak->type=MOV_TRAK_VIDEO; |
257 // read video data | |
258 break; | |
259 } | |
260 case MOV_FOURCC('s','m','h','d'): { | |
1567 | 261 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSound header!\n",level,""); |
1490 | 262 trak->type=MOV_TRAK_AUDIO; |
263 // read audio data | |
264 break; | |
265 } | |
266 case MOV_FOURCC('s','t','s','d'): { | |
267 int i=stream_read_dword(demuxer->stream); // temp! | |
268 int count=stream_read_dword(demuxer->stream); | |
1567 | 269 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sDescription list! (cnt:%d)\n",level,"",count); |
1490 | 270 for(i=0;i<count;i++){ |
271 off_t pos=stream_tell(demuxer->stream); | |
272 off_t len=stream_read_dword(demuxer->stream); | |
273 unsigned int fourcc=stream_read_dword_le(demuxer->stream); | |
274 if(len<8) break; // error | |
1567 | 275 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s desc #%d: %.4s",level,"",i,&fourcc); |
1490 | 276 if(!i){ |
277 trak->fourcc=fourcc; | |
278 // read codec data | |
2101 | 279 trak->stdata_len=len-8; |
280 trak->stdata=malloc(trak->stdata_len); | |
281 stream_read(demuxer->stream,trak->stdata,trak->stdata_len); | |
282 if(trak->type==MOV_TRAK_VIDEO && trak->stdata_len>43){ | |
283 mp_msg(MSGT_DEMUX,MSGL_V," '%.*s'",trak->stdata_len-43,trak->stdata+43); | |
1490 | 284 } |
285 } | |
1567 | 286 mp_msg(MSGT_DEMUX,MSGL_V,"\n"); |
1490 | 287 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
|
288 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC); |
1490 | 289 if(!stream_seek(demuxer->stream,pos+len)) break; |
290 } | |
291 break; | |
292 } | |
2100 | 293 case MOV_FOURCC('s','t','t','s'): { |
294 int temp=stream_read_dword(demuxer->stream); | |
295 int len=stream_read_dword(demuxer->stream); | |
296 int i; | |
297 int x=0; | |
298 unsigned int pts=0; | |
299 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample duration table! (%d blocks)\n",level,"",len); | |
2115 | 300 trak->durmap=malloc(sizeof(mov_durmap_t)*len); |
301 memset(trak->durmap,0,sizeof(mov_durmap_t)*len); | |
302 trak->durmap_size=len; | |
2100 | 303 for(i=0;i<len;i++){ |
2115 | 304 trak->durmap[i].num=stream_read_dword(demuxer->stream); |
305 trak->durmap[i].dur=stream_read_dword(demuxer->stream); | |
306 pts+=trak->durmap[i].num*trak->durmap[i].dur; | |
2100 | 307 } |
308 if(trak->length!=pts) printf("Warning! pts=%d length=%d\n",pts,trak->length); | |
309 break; | |
310 } | |
311 case MOV_FOURCC('s','t','s','c'): { | |
312 int temp=stream_read_dword(demuxer->stream); | |
313 int len=stream_read_dword(demuxer->stream); | |
314 int i; | |
315 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample->Chunk mapping table! (%d blocks)\n",level,"",len); | |
316 // read data: | |
317 trak->chunkmap_size=len; | |
318 trak->chunkmap=malloc(sizeof(mov_chunkmap_t)*len); | |
319 for(i=0;i<len;i++){ | |
2103 | 320 trak->chunkmap[i].first=stream_read_dword(demuxer->stream)-1; |
2100 | 321 trak->chunkmap[i].spc=stream_read_dword(demuxer->stream); |
322 trak->chunkmap[i].sdid=stream_read_dword(demuxer->stream); | |
323 } | |
324 break; | |
325 } | |
326 case MOV_FOURCC('s','t','s','z'): { | |
327 int temp=stream_read_dword(demuxer->stream); | |
328 int ss=stream_read_dword(demuxer->stream); | |
329 int len=stream_read_dword(demuxer->stream); | |
330 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample size table! len=%d ss=%d\n",level,"",len,ss); | |
2115 | 331 trak->samplesize=ss; |
332 if(!ss){ | |
333 // variable samplesize | |
334 int i; | |
2100 | 335 trak->samples=realloc(trak->samples,sizeof(mov_sample_t)*len); |
336 trak->samples_size=len; | |
2115 | 337 for(i=0;i<len;i++) |
338 trak->samples[i].size=stream_read_dword(demuxer->stream); | |
2100 | 339 } |
340 break; | |
341 } | |
342 case MOV_FOURCC('s','t','c','o'): { | |
343 int temp=stream_read_dword(demuxer->stream); | |
344 int len=stream_read_dword(demuxer->stream); | |
345 int i; | |
346 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sChunk offset table! (%d chunks)\n",level,"",len); | |
347 // extend array if needed: | |
348 if(len>trak->chunks_size){ | |
349 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len); | |
350 trak->chunks_size=len; | |
351 } | |
352 // read elements: | |
353 for(i=0;i<len;i++) trak->chunks[i].pos=stream_read_dword(demuxer->stream); | |
354 break; | |
355 } | |
1490 | 356 case MOV_FOURCC('m','d','i','a'): { |
1567 | 357 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia stream!\n",level,""); |
1490 | 358 lschunks(demuxer,level+1,pos+len,trak); |
359 break; | |
360 } | |
361 case MOV_FOURCC('m','i','n','f'): { | |
1567 | 362 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia info!\n",level,""); |
1490 | 363 lschunks(demuxer,level+1,pos+len,trak); |
364 break; | |
365 } | |
366 case MOV_FOURCC('s','t','b','l'): { | |
1567 | 367 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample info!\n",level,""); |
1490 | 368 lschunks(demuxer,level+1,pos+len,trak); |
369 break; | |
370 } | |
371 }//switch(id) | |
372 } else | |
373 if(id==MOV_FOURCC('t','r','a','k')){ | |
374 // if(trak) printf("MOV: Warning! trak in trak?\n"); | |
375 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
|
376 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVtooManyTrk); |
1490 | 377 return; |
378 } | |
379 trak=malloc(sizeof(mov_track_t)); | |
380 memset(trak,0,sizeof(mov_track_t)); | |
1567 | 381 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Track #%d:\n",priv->track_db); |
1490 | 382 trak->id=priv->track_db; |
2100 | 383 priv->tracks[priv->track_db]=trak; |
1490 | 384 lschunks(demuxer,level+1,pos+len,trak); |
2100 | 385 mov_build_index(trak); |
386 switch(trak->type){ | |
387 case MOV_TRAK_AUDIO: { | |
388 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db); | |
389 sh->format=trak->fourcc; | |
2101 | 390 printf("!!! audio bits: %d chans: %d\n",trak->stdata[19],trak->stdata[17]); |
2115 | 391 printf("Fourcc: %.4s\n",&trak->fourcc); |
2101 | 392 // Emulate WAVEFORMATEX struct: |
393 sh->wf=malloc(sizeof(WAVEFORMATEX)); | |
394 memset(sh->wf,0,sizeof(WAVEFORMATEX)); | |
395 sh->wf->nChannels=trak->stdata[17]; | |
396 sh->wf->wBitsPerSample=trak->stdata[19]; | |
397 sh->wf->nSamplesPerSec=trak->timescale; | |
398 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*((sh->wf->wBitsPerSample+7)/8)*sh->wf->nSamplesPerSec; | |
399 // Selection: | |
400 if(demuxer->audio->id==-1 || demuxer->audio->id==priv->track_db){ | |
401 // (auto)selected audio track: | |
402 demuxer->audio->id=priv->track_db; | |
403 demuxer->audio->sh=sh; sh->ds=demuxer->audio; | |
404 } | |
2100 | 405 break; |
406 } | |
407 case MOV_TRAK_VIDEO: { | |
408 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); | |
409 sh->format=trak->fourcc; | |
410 sh->fps=trak->timescale; | |
411 sh->frametime=1.0f/sh->fps; | |
2101 | 412 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8); |
413 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); | |
414 | |
415 // emulate BITMAPINFOHEADER: | |
416 sh->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
417 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); | |
418 sh->bih->biSize=40; | |
419 sh->bih->biWidth=sh->disp_w; | |
420 sh->bih->biHeight=sh->disp_h; | |
421 sh->bih->biPlanes=0; | |
422 sh->bih->biBitCount=16; | |
423 sh->bih->biCompression=trak->fourcc; | |
424 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight; | |
425 | |
426 printf("Image size: %d x %d\n",sh->disp_w,sh->disp_h); | |
2115 | 427 printf("Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43); |
428 | |
2101 | 429 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){ |
430 // (auto)selected video track: | |
431 demuxer->video->id=priv->track_db; | |
432 demuxer->video->sh=sh; sh->ds=demuxer->video; | |
433 } | |
2100 | 434 break; |
435 } | |
436 } | |
437 printf("--------------\n"); | |
438 priv->track_db++; | |
1490 | 439 trak=NULL; |
440 } else | |
2148 | 441 #ifndef HAVE_ZLIB |
1490 | 442 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
|
443 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); |
1490 | 444 return; |
445 } | |
2148 | 446 #else |
447 if(id==MOV_FOURCC('c','m','o','v')){ | |
448 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); | |
449 lschunks(demuxer,level+1,pos+len,NULL); | |
450 } else | |
451 if(id==MOV_FOURCC('d','c','o','m')){ | |
452 // int temp=stream_read_dword(demuxer->stream); | |
453 unsigned int len=stream_read_dword(demuxer->stream); | |
454 printf("Compressed header uses %.4s algo!\n",&len); | |
455 } else | |
456 if(id==MOV_FOURCC('c','m','v','d')){ | |
457 // int temp=stream_read_dword(demuxer->stream); | |
458 unsigned int moov_sz=stream_read_dword(demuxer->stream); | |
459 unsigned int cmov_sz=len-4; | |
460 unsigned char* cmov_buf=malloc(cmov_sz); | |
461 unsigned char* moov_buf=malloc(moov_sz+16); | |
462 int zret; | |
463 z_stream zstrm; | |
464 stream_t* backup; | |
465 | |
466 printf("Compressed header size: %d / %d\n",cmov_sz,moov_sz); | |
467 | |
468 stream_read(demuxer->stream,cmov_buf,cmov_sz); | |
469 | |
470 zstrm.zalloc = (alloc_func)0; | |
471 zstrm.zfree = (free_func)0; | |
472 zstrm.opaque = (voidpf)0; | |
473 zstrm.next_in = cmov_buf; | |
474 zstrm.avail_in = cmov_sz; | |
475 zstrm.next_out = moov_buf; | |
476 zstrm.avail_out = moov_sz; | |
477 | |
478 zret = inflateInit(&zstrm); | |
479 if (zret != Z_OK) | |
480 { fprintf(stderr,"QT cmov: inflateInit err %d\n",zret); | |
481 return; | |
482 } | |
483 zret = inflate(&zstrm, Z_NO_FLUSH); | |
484 if ((zret != Z_OK) && (zret != Z_STREAM_END)) | |
485 { fprintf(stderr,"QT cmov inflate: ERR %d\n",zret); | |
486 return; | |
487 } | |
488 #if 0 | |
489 else { | |
490 FILE *DecOut; | |
491 DecOut = fopen("Out.bin", "w"); | |
492 fwrite(moov_buf, 1, moov_sz, DecOut); | |
493 fclose(DecOut); | |
494 } | |
495 #endif | |
496 if(moov_sz != zstrm.total_out) printf("Warning! moov size differs cmov: %d zlib: %d\n",moov_sz,zstrm.total_out); | |
497 zret = inflateEnd(&zstrm); | |
498 | |
499 backup=demuxer->stream; | |
500 demuxer->stream=new_memory_stream(moov_buf,moov_sz); | |
501 stream_skip(demuxer->stream,8); | |
502 lschunks(demuxer,level+1,moov_sz,NULL); // parse uncompr. 'moov' | |
503 //free_stream(demuxer->stream); | |
504 demuxer->stream=backup; | |
505 | |
506 } | |
507 #endif | |
1490 | 508 |
509 pos+=len+8; | |
510 if(pos>=endpos) break; | |
511 if(!stream_seek(demuxer->stream,pos)) break; | |
512 } | |
513 } | |
514 | |
515 int mov_read_header(demuxer_t* demuxer){ | |
516 mov_priv_t* priv=demuxer->priv; | |
517 | |
2100 | 518 printf("mov_read_header!\n"); |
1490 | 519 |
520 // Parse header: | |
2100 | 521 stream_reset(demuxer->stream); |
1490 | 522 if(!stream_seek(demuxer->stream,priv->moov_start)) return 0; // ??? |
523 lschunks(demuxer, 0, priv->moov_end, NULL); | |
524 | |
2127 | 525 #if 1 |
526 return 1; | |
527 #else | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
528 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVnotyetsupp); |
2127 | 529 return 0; |
530 #endif | |
1490 | 531 } |
2101 | 532 |
533 // return value: | |
534 // 0 = EOF or no stream found | |
535 // 1 = successfully read a packet | |
536 int demux_mov_fill_buffer(demuxer_t *demuxer,demux_stream_t* ds){ | |
537 mov_priv_t* priv=demuxer->priv; | |
538 mov_track_t* trak=NULL; | |
539 float pts; | |
540 | |
541 if(ds->id<0 || ds->id>=priv->track_db) return 0; | |
542 trak=priv->tracks[ds->id]; | |
543 | |
2115 | 544 if(trak->samplesize){ |
545 // read chunk: | |
546 if(trak->pos>=trak->chunks_size) return 0; // EOF | |
547 stream_seek(demuxer->stream,trak->chunks[trak->pos].pos); | |
548 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
549 ds_read_packet(ds,demuxer->stream,trak->chunks[trak->pos].size*trak->samplesize,pts,trak->chunks[trak->pos].pos,0); | |
550 } else { | |
2101 | 551 // read sample: |
552 if(trak->pos>=trak->samples_size) return 0; // EOF | |
553 stream_seek(demuxer->stream,trak->samples[trak->pos].pos); | |
554 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; | |
555 ds_read_packet(ds,demuxer->stream,trak->samples[trak->pos].size,pts,trak->samples[trak->pos].pos,0); | |
2115 | 556 } |
2101 | 557 ++trak->pos; |
2115 | 558 |
2101 | 559 return 1; |
560 | |
561 } | |
2227 | 562 |
563 static float mov_seek_track(mov_track_t* trak,float pts,int flags){ | |
564 | |
565 // printf("MOV track seek called %5.3f \n",pts); | |
566 if(flags&2) pts*=trak->length; else pts*=(float)trak->timescale; | |
567 | |
568 if(trak->samplesize){ | |
569 int sample=pts/trak->duration; | |
570 // printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration); | |
571 if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative | |
572 trak->pos=0; | |
573 while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos; | |
574 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
575 } else { | |
576 unsigned int ipts=pts; | |
577 // printf("MOV track seek - sample: %d \n",ipts); | |
578 if(!(flags&1)) ipts+=trak->samples[trak->pos].pts; | |
579 trak->pos=0; | |
580 while(trak->pos<trak->samples_size && trak->samples[trak->pos].pts<ipts) ++trak->pos; | |
581 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; | |
582 } | |
583 | |
584 // printf("MOV track seek done: %5.3f \n",pts); | |
585 | |
586 return pts; | |
587 } | |
588 | |
589 void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){ | |
590 mov_priv_t* priv=demuxer->priv; | |
591 demux_stream_t* ds; | |
592 | |
593 // printf("MOV seek called %5.3f flag=%d \n",pts,flags); | |
594 | |
595 ds=demuxer->video; | |
596 if(ds && ds->id>=0 && ds->id<priv->track_db){ | |
597 mov_track_t* trak=priv->tracks[ds->id]; | |
598 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; | |
599 //if(!(flags&1)) pts+=ds->pts; | |
600 pts=ds->pts=mov_seek_track(trak,pts,flags); | |
601 flags=1; // absolute seconds | |
602 } | |
603 | |
604 ds=demuxer->audio; | |
605 if(ds && ds->id>=0 && ds->id<priv->track_db){ | |
606 mov_track_t* trak=priv->tracks[ds->id]; | |
607 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; | |
608 //if(!(flags&1)) pts+=ds->pts; | |
609 ds->pts=mov_seek_track(trak,pts,flags); | |
610 } | |
611 | |
612 } | |
613 |