Mercurial > mplayer.hg
annotate libmpdemux/demux_mov.c @ 2481:0e9a5504a246
libdl checking added
author | alex |
---|---|
date | Fri, 26 Oct 2001 13:39:15 +0000 |
parents | 8d00b25169af |
children | 22bfa362af42 |
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. | |
2386 | 4 // References: http://openquicktime.sf.net/, http://www.heroinewarrior.com/ |
1490 | 5 |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <unistd.h> | |
9 | |
1567 | 10 #include "config.h" |
2148 | 11 |
12 #ifdef HAVE_PNG | |
13 // should be detected by ./configure... | |
14 #define HAVE_ZLIB | |
15 #endif | |
16 | |
1567 | 17 #include "mp_msg.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
18 #include "help_mp.h" |
1490 | 19 |
20 #include "stream.h" | |
21 #include "demuxer.h" | |
22 #include "stheader.h" | |
23 | |
2386 | 24 #include "bswap.h" |
25 | |
2148 | 26 #ifdef HAVE_ZLIB |
27 #include <zlib.h> | |
28 #endif | |
29 | |
1490 | 30 typedef struct { |
2100 | 31 unsigned int pts; // duration |
32 unsigned int size; | |
33 off_t pos; | |
34 } mov_sample_t; | |
35 | |
36 typedef struct { | |
2115 | 37 unsigned int sample; // number of the first sample in teh chunk |
38 unsigned int size; // number of samples in the chunk | |
39 int desc; // for multiple codecs mode - not used | |
2100 | 40 off_t pos; |
41 } mov_chunk_t; | |
42 | |
43 typedef struct { | |
44 unsigned int first; | |
45 unsigned int spc; | |
46 unsigned int sdid; | |
47 } mov_chunkmap_t; | |
48 | |
49 typedef struct { | |
2115 | 50 unsigned int num; |
51 unsigned int dur; | |
52 } mov_durmap_t; | |
53 | |
54 typedef struct { | |
1490 | 55 int id; |
56 int type; | |
2101 | 57 int pos; |
58 // | |
1490 | 59 int timescale; |
2100 | 60 unsigned int length; |
2115 | 61 int samplesize; // 0 = variable |
62 int duration; // 0 = variable | |
1490 | 63 int width,height; // for video |
64 unsigned int fourcc; | |
2115 | 65 // |
2101 | 66 int tkdata_len; // track data |
67 unsigned char* tkdata; | |
68 int stdata_len; // stream data | |
69 unsigned char* stdata; | |
2100 | 70 int samples_size; |
71 mov_sample_t* samples; | |
72 int chunks_size; | |
73 mov_chunk_t* chunks; | |
74 int chunkmap_size; | |
75 mov_chunkmap_t* chunkmap; | |
2115 | 76 int durmap_size; |
77 mov_durmap_t* durmap; | |
1490 | 78 } mov_track_t; |
79 | |
2100 | 80 void mov_build_index(mov_track_t* trak){ |
81 int i,j,s; | |
82 int last=trak->chunks_size; | |
2115 | 83 unsigned int pts=0; |
2100 | 84 printf("MOV track: %d chunks, %d samples\n",trak->chunks_size,trak->samples_size); |
85 printf("pts=%d scale=%d time=%5.3f\n",trak->length,trak->timescale,(float)trak->length/(float)trak->timescale); | |
86 // process chunkmap: | |
87 i=trak->chunkmap_size; | |
88 while(i>0){ | |
89 --i; | |
90 for(j=trak->chunkmap[i].first;j<last;j++){ | |
91 trak->chunks[j].desc=trak->chunkmap[i].sdid; | |
92 trak->chunks[j].size=trak->chunkmap[i].spc; | |
93 } | |
94 last=trak->chunkmap[i].first; | |
95 } | |
2115 | 96 |
97 // calc pts of chunks: | |
98 s=0; | |
99 for(j=0;j<trak->chunks_size;j++){ | |
100 trak->chunks[j].sample=s; | |
101 s+=trak->chunks[j].size; | |
102 } | |
103 | |
104 if(!trak->samples_size){ | |
105 // constant sampesize | |
106 if(trak->durmap_size==1 || (trak->durmap_size==2 && trak->durmap[1].num==1)){ | |
2227 | 107 trak->duration=trak->durmap[0].dur; |
2115 | 108 } else printf("*** constant samplesize & variable duration not yet supported! ***\nContact the author if you have such sample file!\n"); |
109 return; | |
110 } | |
111 | |
112 // calc pts: | |
113 s=0; | |
114 for(j=0;j<trak->durmap_size;j++){ | |
115 for(i=0;i<trak->durmap[j].num;i++){ | |
116 trak->samples[s].pts=pts; | |
117 ++s; | |
118 pts+=trak->durmap[j].dur; | |
119 } | |
120 } | |
2100 | 121 |
122 // calc sample offsets | |
123 s=0; | |
124 for(j=0;j<trak->chunks_size;j++){ | |
125 off_t pos=trak->chunks[j].pos; | |
126 for(i=0;i<trak->chunks[j].size;i++){ | |
127 trak->samples[s].pos=pos; | |
128 #if 0 | |
129 printf("Sample %5d: pts=%8d off=0x%08X size=%d\n",s, | |
130 trak->samples[s].pts, | |
131 (int)trak->samples[s].pos, | |
132 trak->samples[s].size); | |
133 #endif | |
134 pos+=trak->samples[s].size; | |
135 ++s; | |
136 } | |
137 } | |
138 | |
139 } | |
140 | |
1490 | 141 #define MOV_MAX_TRACKS 256 |
142 | |
143 #define MOV_TRAK_UNKNOWN 0 | |
144 #define MOV_TRAK_VIDEO 1 | |
145 #define MOV_TRAK_AUDIO 2 | |
146 | |
147 typedef struct { | |
148 off_t moov_start; | |
149 off_t moov_end; | |
150 off_t mdat_start; | |
151 off_t mdat_end; | |
152 int track_db; | |
153 mov_track_t* tracks[MOV_MAX_TRACKS]; | |
154 } mov_priv_t; | |
155 | |
156 #define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d)) | |
157 | |
158 int mov_check_file(demuxer_t* demuxer){ | |
159 int flags=0; | |
160 mov_priv_t* priv=malloc(sizeof(mov_priv_t)); | |
161 | |
1567 | 162 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for MOV\n"); |
1490 | 163 |
164 memset(priv,0,sizeof(mov_priv_t)); | |
165 demuxer->priv=priv; | |
166 | |
167 while(1){ | |
168 off_t len=stream_read_dword(demuxer->stream); | |
169 unsigned int id=stream_read_dword(demuxer->stream); | |
170 if(stream_eof(demuxer->stream)) break; // EOF | |
171 if(len<8) break; // invalid chunk | |
172 switch(id){ | |
173 case MOV_FOURCC('m','o','o','v'): | |
1567 | 174 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n"); |
1490 | 175 priv->moov_start=stream_tell(demuxer->stream); |
176 priv->moov_end=priv->moov_start+len-8; | |
177 flags|=1; | |
178 break; | |
179 case MOV_FOURCC('m','d','a','t'): | |
1567 | 180 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie DATA found!\n"); |
1490 | 181 priv->mdat_start=stream_tell(demuxer->stream); |
182 priv->mdat_end=priv->mdat_start+len-8; | |
183 flags|=2; | |
184 break; | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
185 case MOV_FOURCC('f','r','e','e'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
186 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
187 case MOV_FOURCC('w','i','d','e'): |
1490 | 188 default: |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
189 id = bswap_32(id); |
1567 | 190 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len); |
1490 | 191 } |
192 if(!stream_skip(demuxer->stream,len-8)) break; | |
193 } | |
2148 | 194 |
195 if(flags==1) | |
196 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing data (mdat) chunk! Maybe broken file...\n"); | |
197 else if(flags==2) | |
198 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing header (moov/cmov) chunk! Maybe broken file...\n"); | |
1490 | 199 |
200 return (flags==3); | |
201 } | |
202 | |
203 static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak){ | |
204 mov_priv_t* priv=demuxer->priv; | |
205 while(1){ | |
206 off_t pos; | |
207 off_t len; | |
208 unsigned int id; | |
209 // | |
210 pos=stream_tell(demuxer->stream); | |
2148 | 211 // printf("stream_tell==%d\n",pos); |
1490 | 212 if(pos>=endpos) return; // END |
213 len=stream_read_dword(demuxer->stream); | |
2148 | 214 // printf("len==%d\n",len); |
1490 | 215 if(len<8) return; // error |
216 len-=8; | |
217 id=stream_read_dword(demuxer->stream); | |
218 // | |
1567 | 219 mp_msg(MSGT_DEMUX,MSGL_DBG2,"lschunks %.4s %d\n",&id,(int)len); |
1490 | 220 // |
221 if(trak){ | |
222 switch(id){ | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
223 case MOV_FOURCC('u','d','t','a'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
224 /* here not supported :p */ |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
225 break; |
1490 | 226 case MOV_FOURCC('t','k','h','d'): { |
1567 | 227 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sTrack header!\n",level,""); |
2101 | 228 // read codec data |
229 trak->tkdata_len=len; | |
230 trak->tkdata=malloc(trak->tkdata_len); | |
231 stream_read(demuxer->stream,trak->tkdata,trak->tkdata_len); | |
1490 | 232 break; |
233 } | |
234 case MOV_FOURCC('m','d','h','d'): { | |
2100 | 235 unsigned int tmp; |
1567 | 236 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia header!\n",level,""); |
2100 | 237 #if 0 |
238 tmp=stream_read_dword(demuxer->stream); | |
239 printf("dword1: 0x%08X (%d)\n",tmp,tmp); | |
240 tmp=stream_read_dword(demuxer->stream); | |
241 printf("dword2: 0x%08X (%d)\n",tmp,tmp); | |
242 tmp=stream_read_dword(demuxer->stream); | |
243 printf("dword3: 0x%08X (%d)\n",tmp,tmp); | |
244 tmp=stream_read_dword(demuxer->stream); | |
245 printf("dword4: 0x%08X (%d)\n",tmp,tmp); | |
246 tmp=stream_read_dword(demuxer->stream); | |
247 printf("dword5: 0x%08X (%d)\n",tmp,tmp); | |
248 tmp=stream_read_dword(demuxer->stream); | |
249 printf("dword6: 0x%08X (%d)\n",tmp,tmp); | |
250 #endif | |
251 stream_skip(demuxer->stream,12); | |
1490 | 252 // read timescale |
2100 | 253 trak->timescale=stream_read_dword(demuxer->stream); |
254 // read length | |
255 trak->length=stream_read_dword(demuxer->stream); | |
1490 | 256 break; |
257 } | |
258 case MOV_FOURCC('v','m','h','d'): { | |
1567 | 259 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sVideo header!\n",level,""); |
1490 | 260 trak->type=MOV_TRAK_VIDEO; |
261 // read video data | |
262 break; | |
263 } | |
264 case MOV_FOURCC('s','m','h','d'): { | |
1567 | 265 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSound header!\n",level,""); |
1490 | 266 trak->type=MOV_TRAK_AUDIO; |
267 // read audio data | |
268 break; | |
269 } | |
270 case MOV_FOURCC('s','t','s','d'): { | |
271 int i=stream_read_dword(demuxer->stream); // temp! | |
272 int count=stream_read_dword(demuxer->stream); | |
1567 | 273 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sDescription list! (cnt:%d)\n",level,"",count); |
1490 | 274 for(i=0;i<count;i++){ |
275 off_t pos=stream_tell(demuxer->stream); | |
276 off_t len=stream_read_dword(demuxer->stream); | |
277 unsigned int fourcc=stream_read_dword_le(demuxer->stream); | |
278 if(len<8) break; // error | |
1567 | 279 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s desc #%d: %.4s",level,"",i,&fourcc); |
1490 | 280 if(!i){ |
281 trak->fourcc=fourcc; | |
282 // read codec data | |
2101 | 283 trak->stdata_len=len-8; |
284 trak->stdata=malloc(trak->stdata_len); | |
285 stream_read(demuxer->stream,trak->stdata,trak->stdata_len); | |
286 if(trak->type==MOV_TRAK_VIDEO && trak->stdata_len>43){ | |
287 mp_msg(MSGT_DEMUX,MSGL_V," '%.*s'",trak->stdata_len-43,trak->stdata+43); | |
1490 | 288 } |
289 } | |
1567 | 290 mp_msg(MSGT_DEMUX,MSGL_V,"\n"); |
1490 | 291 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
|
292 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC); |
1490 | 293 if(!stream_seek(demuxer->stream,pos+len)) break; |
294 } | |
295 break; | |
296 } | |
2100 | 297 case MOV_FOURCC('s','t','t','s'): { |
298 int temp=stream_read_dword(demuxer->stream); | |
299 int len=stream_read_dword(demuxer->stream); | |
300 int i; | |
301 int x=0; | |
302 unsigned int pts=0; | |
303 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample duration table! (%d blocks)\n",level,"",len); | |
2115 | 304 trak->durmap=malloc(sizeof(mov_durmap_t)*len); |
305 memset(trak->durmap,0,sizeof(mov_durmap_t)*len); | |
306 trak->durmap_size=len; | |
2100 | 307 for(i=0;i<len;i++){ |
2115 | 308 trak->durmap[i].num=stream_read_dword(demuxer->stream); |
309 trak->durmap[i].dur=stream_read_dword(demuxer->stream); | |
310 pts+=trak->durmap[i].num*trak->durmap[i].dur; | |
2386 | 311 |
312 if(i==0) | |
313 { | |
314 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); | |
315 if (!sh->fps) | |
316 sh->fps = trak->timescale/trak->durmap[i].dur; | |
317 /* initial fps */ | |
318 } | |
2100 | 319 } |
320 if(trak->length!=pts) printf("Warning! pts=%d length=%d\n",pts,trak->length); | |
321 break; | |
322 } | |
323 case MOV_FOURCC('s','t','s','c'): { | |
324 int temp=stream_read_dword(demuxer->stream); | |
325 int len=stream_read_dword(demuxer->stream); | |
326 int i; | |
327 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample->Chunk mapping table! (%d blocks)\n",level,"",len); | |
328 // read data: | |
329 trak->chunkmap_size=len; | |
330 trak->chunkmap=malloc(sizeof(mov_chunkmap_t)*len); | |
331 for(i=0;i<len;i++){ | |
2103 | 332 trak->chunkmap[i].first=stream_read_dword(demuxer->stream)-1; |
2100 | 333 trak->chunkmap[i].spc=stream_read_dword(demuxer->stream); |
334 trak->chunkmap[i].sdid=stream_read_dword(demuxer->stream); | |
335 } | |
336 break; | |
337 } | |
338 case MOV_FOURCC('s','t','s','z'): { | |
339 int temp=stream_read_dword(demuxer->stream); | |
340 int ss=stream_read_dword(demuxer->stream); | |
341 int len=stream_read_dword(demuxer->stream); | |
342 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample size table! len=%d ss=%d\n",level,"",len,ss); | |
2115 | 343 trak->samplesize=ss; |
344 if(!ss){ | |
345 // variable samplesize | |
346 int i; | |
2100 | 347 trak->samples=realloc(trak->samples,sizeof(mov_sample_t)*len); |
348 trak->samples_size=len; | |
2115 | 349 for(i=0;i<len;i++) |
350 trak->samples[i].size=stream_read_dword(demuxer->stream); | |
2100 | 351 } |
352 break; | |
353 } | |
354 case MOV_FOURCC('s','t','c','o'): { | |
355 int temp=stream_read_dword(demuxer->stream); | |
356 int len=stream_read_dword(demuxer->stream); | |
357 int i; | |
358 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sChunk offset table! (%d chunks)\n",level,"",len); | |
359 // extend array if needed: | |
360 if(len>trak->chunks_size){ | |
361 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len); | |
362 trak->chunks_size=len; | |
363 } | |
364 // read elements: | |
365 for(i=0;i<len;i++) trak->chunks[i].pos=stream_read_dword(demuxer->stream); | |
366 break; | |
367 } | |
1490 | 368 case MOV_FOURCC('m','d','i','a'): { |
1567 | 369 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia stream!\n",level,""); |
1490 | 370 lschunks(demuxer,level+1,pos+len,trak); |
371 break; | |
372 } | |
373 case MOV_FOURCC('m','i','n','f'): { | |
1567 | 374 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia info!\n",level,""); |
1490 | 375 lschunks(demuxer,level+1,pos+len,trak); |
376 break; | |
377 } | |
378 case MOV_FOURCC('s','t','b','l'): { | |
1567 | 379 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample info!\n",level,""); |
1490 | 380 lschunks(demuxer,level+1,pos+len,trak); |
381 break; | |
382 } | |
383 }//switch(id) | |
384 } else | |
385 if(id==MOV_FOURCC('t','r','a','k')){ | |
386 // if(trak) printf("MOV: Warning! trak in trak?\n"); | |
387 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
|
388 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVtooManyTrk); |
1490 | 389 return; |
390 } | |
391 trak=malloc(sizeof(mov_track_t)); | |
392 memset(trak,0,sizeof(mov_track_t)); | |
1567 | 393 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Track #%d:\n",priv->track_db); |
1490 | 394 trak->id=priv->track_db; |
2100 | 395 priv->tracks[priv->track_db]=trak; |
1490 | 396 lschunks(demuxer,level+1,pos+len,trak); |
2100 | 397 mov_build_index(trak); |
398 switch(trak->type){ | |
399 case MOV_TRAK_AUDIO: { | |
400 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db); | |
401 sh->format=trak->fourcc; | |
2101 | 402 printf("!!! audio bits: %d chans: %d\n",trak->stdata[19],trak->stdata[17]); |
2115 | 403 printf("Fourcc: %.4s\n",&trak->fourcc); |
2101 | 404 // Emulate WAVEFORMATEX struct: |
405 sh->wf=malloc(sizeof(WAVEFORMATEX)); | |
406 memset(sh->wf,0,sizeof(WAVEFORMATEX)); | |
407 sh->wf->nChannels=trak->stdata[17]; | |
408 sh->wf->wBitsPerSample=trak->stdata[19]; | |
409 sh->wf->nSamplesPerSec=trak->timescale; | |
410 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*((sh->wf->wBitsPerSample+7)/8)*sh->wf->nSamplesPerSec; | |
411 // Selection: | |
412 if(demuxer->audio->id==-1 || demuxer->audio->id==priv->track_db){ | |
413 // (auto)selected audio track: | |
414 demuxer->audio->id=priv->track_db; | |
415 demuxer->audio->sh=sh; sh->ds=demuxer->audio; | |
416 } | |
2100 | 417 break; |
418 } | |
419 case MOV_TRAK_VIDEO: { | |
420 sh_video_t* sh=new_sh_video(demuxer,priv->track_db); | |
421 sh->format=trak->fourcc; | |
2386 | 422 if(!sh->fps) sh->fps=trak->timescale; |
2100 | 423 sh->frametime=1.0f/sh->fps; |
2101 | 424 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8); |
425 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8); | |
426 | |
427 // emulate BITMAPINFOHEADER: | |
428 sh->bih=malloc(sizeof(BITMAPINFOHEADER)); | |
429 memset(sh->bih,0,sizeof(BITMAPINFOHEADER)); | |
430 sh->bih->biSize=40; | |
431 sh->bih->biWidth=sh->disp_w; | |
432 sh->bih->biHeight=sh->disp_h; | |
433 sh->bih->biPlanes=0; | |
434 sh->bih->biBitCount=16; | |
435 sh->bih->biCompression=trak->fourcc; | |
436 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight; | |
437 | |
438 printf("Image size: %d x %d\n",sh->disp_w,sh->disp_h); | |
2115 | 439 printf("Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43); |
440 | |
2101 | 441 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){ |
442 // (auto)selected video track: | |
443 demuxer->video->id=priv->track_db; | |
444 demuxer->video->sh=sh; sh->ds=demuxer->video; | |
445 } | |
2100 | 446 break; |
447 } | |
448 } | |
449 printf("--------------\n"); | |
450 priv->track_db++; | |
1490 | 451 trak=NULL; |
452 } else | |
2148 | 453 #ifndef HAVE_ZLIB |
1490 | 454 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
|
455 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); |
1490 | 456 return; |
457 } | |
2148 | 458 #else |
459 if(id==MOV_FOURCC('c','m','o','v')){ | |
460 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr); | |
461 lschunks(demuxer,level+1,pos+len,NULL); | |
462 } else | |
463 if(id==MOV_FOURCC('d','c','o','m')){ | |
464 // int temp=stream_read_dword(demuxer->stream); | |
2386 | 465 unsigned int len=bswap_32(stream_read_dword(demuxer->stream)); |
2148 | 466 printf("Compressed header uses %.4s algo!\n",&len); |
467 } else | |
468 if(id==MOV_FOURCC('c','m','v','d')){ | |
469 // int temp=stream_read_dword(demuxer->stream); | |
470 unsigned int moov_sz=stream_read_dword(demuxer->stream); | |
471 unsigned int cmov_sz=len-4; | |
472 unsigned char* cmov_buf=malloc(cmov_sz); | |
473 unsigned char* moov_buf=malloc(moov_sz+16); | |
474 int zret; | |
475 z_stream zstrm; | |
476 stream_t* backup; | |
477 | |
478 printf("Compressed header size: %d / %d\n",cmov_sz,moov_sz); | |
479 | |
480 stream_read(demuxer->stream,cmov_buf,cmov_sz); | |
481 | |
482 zstrm.zalloc = (alloc_func)0; | |
483 zstrm.zfree = (free_func)0; | |
484 zstrm.opaque = (voidpf)0; | |
485 zstrm.next_in = cmov_buf; | |
486 zstrm.avail_in = cmov_sz; | |
487 zstrm.next_out = moov_buf; | |
488 zstrm.avail_out = moov_sz; | |
489 | |
490 zret = inflateInit(&zstrm); | |
491 if (zret != Z_OK) | |
492 { fprintf(stderr,"QT cmov: inflateInit err %d\n",zret); | |
493 return; | |
494 } | |
495 zret = inflate(&zstrm, Z_NO_FLUSH); | |
496 if ((zret != Z_OK) && (zret != Z_STREAM_END)) | |
497 { fprintf(stderr,"QT cmov inflate: ERR %d\n",zret); | |
498 return; | |
499 } | |
500 #if 0 | |
501 else { | |
502 FILE *DecOut; | |
503 DecOut = fopen("Out.bin", "w"); | |
504 fwrite(moov_buf, 1, moov_sz, DecOut); | |
505 fclose(DecOut); | |
506 } | |
507 #endif | |
508 if(moov_sz != zstrm.total_out) printf("Warning! moov size differs cmov: %d zlib: %d\n",moov_sz,zstrm.total_out); | |
509 zret = inflateEnd(&zstrm); | |
510 | |
511 backup=demuxer->stream; | |
512 demuxer->stream=new_memory_stream(moov_buf,moov_sz); | |
513 stream_skip(demuxer->stream,8); | |
514 lschunks(demuxer,level+1,moov_sz,NULL); // parse uncompr. 'moov' | |
515 //free_stream(demuxer->stream); | |
516 demuxer->stream=backup; | |
517 | |
518 } | |
519 #endif | |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
520 else if (id==MOV_FOURCC('u','d','t','a')) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
521 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
522 unsigned int udta_id; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
523 off_t udta_len; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
524 off_t udta_size = len; |
1490 | 525 |
2429
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
526 mp_msg(MSGT_DEMUX, MSGL_DBG2, "mov: user data record found\n"); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
527 mp_msg(MSGT_DEMUX, MSGL_INFO, "Quicktime Clip Info:\n"); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
528 |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
529 while((len > 8) && (udta_size > 8)) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
530 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
531 udta_len = stream_read_dword(demuxer->stream); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
532 udta_id = stream_read_dword(demuxer->stream); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
533 udta_size -= 8; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
534 mp_msg(MSGT_DEMUX, MSGL_DBG2, "udta_id: %.4s (len: %d)\n", &udta_id, udta_len); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
535 switch (udta_id) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
536 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
537 case MOV_FOURCC(0xa9,'c','p','y'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
538 case MOV_FOURCC(0xa9,'i','n','f'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
539 case MOV_FOURCC(0xa9,'n','a','m'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
540 case MOV_FOURCC(0xa9,'A','R','T'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
541 case MOV_FOURCC(0xa9,'d','i','r'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
542 case MOV_FOURCC(0xa9,'c','m','t'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
543 case MOV_FOURCC(0xa9,'r','e','q'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
544 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
545 off_t text_len = stream_read_word(demuxer->stream); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
546 char text[text_len+2+1]; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
547 stream_read(demuxer->stream, (char *)&text, text_len+2); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
548 text[text_len+2] = 0x0; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
549 switch(udta_id) |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
550 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
551 case MOV_FOURCC(0xa9,'c','p','y'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
552 mp_msg(MSGT_DEMUX, MSGL_INFO, " Copyright: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
553 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
554 case MOV_FOURCC(0xa9,'i','n','f'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
555 mp_msg(MSGT_DEMUX, MSGL_INFO, " Info: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
556 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
557 case MOV_FOURCC(0xa9,'n','a','m'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
558 mp_msg(MSGT_DEMUX, MSGL_INFO, " Name: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
559 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
560 case MOV_FOURCC(0xa9,'A','R','T'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
561 mp_msg(MSGT_DEMUX, MSGL_INFO, " Artist: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
562 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
563 case MOV_FOURCC(0xa9,'d','i','r'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
564 mp_msg(MSGT_DEMUX, MSGL_INFO, " Director: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
565 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
566 case MOV_FOURCC(0xa9,'c','m','t'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
567 mp_msg(MSGT_DEMUX, MSGL_INFO, " Comment: %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
568 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
569 case MOV_FOURCC(0xa9,'r','e','q'): |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
570 mp_msg(MSGT_DEMUX, MSGL_INFO, " Requests(codec): %s\n", &text[2]); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
571 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
572 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
573 udta_size -= 4+text_len; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
574 break; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
575 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
576 default: |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
577 { |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
578 char dump[udta_len-4]; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
579 stream_read(demuxer->stream, (char *)&dump, udta_len-4-4); |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
580 udta_size -= udta_len; |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
581 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
582 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
583 } |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
584 } /* eof udta */ |
8d00b25169af
handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents:
2419
diff
changeset
|
585 |
1490 | 586 pos+=len+8; |
587 if(pos>=endpos) break; | |
588 if(!stream_seek(demuxer->stream,pos)) break; | |
589 } | |
590 } | |
591 | |
592 int mov_read_header(demuxer_t* demuxer){ | |
593 mov_priv_t* priv=demuxer->priv; | |
594 | |
2100 | 595 printf("mov_read_header!\n"); |
1490 | 596 |
597 // Parse header: | |
2100 | 598 stream_reset(demuxer->stream); |
1490 | 599 if(!stream_seek(demuxer->stream,priv->moov_start)) return 0; // ??? |
600 lschunks(demuxer, 0, priv->moov_end, NULL); | |
601 | |
2127 | 602 #if 1 |
603 return 1; | |
604 #else | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1567
diff
changeset
|
605 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVnotyetsupp); |
2127 | 606 return 0; |
607 #endif | |
1490 | 608 } |
2101 | 609 |
610 // return value: | |
611 // 0 = EOF or no stream found | |
612 // 1 = successfully read a packet | |
613 int demux_mov_fill_buffer(demuxer_t *demuxer,demux_stream_t* ds){ | |
614 mov_priv_t* priv=demuxer->priv; | |
615 mov_track_t* trak=NULL; | |
616 float pts; | |
617 | |
618 if(ds->id<0 || ds->id>=priv->track_db) return 0; | |
619 trak=priv->tracks[ds->id]; | |
620 | |
2115 | 621 if(trak->samplesize){ |
622 // read chunk: | |
2419 | 623 int x; |
2115 | 624 if(trak->pos>=trak->chunks_size) return 0; // EOF |
625 stream_seek(demuxer->stream,trak->chunks[trak->pos].pos); | |
626 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
2419 | 627 x=trak->chunks[trak->pos].size*trak->samplesize; |
628 x/=ds->ss_div; x*=ds->ss_mul; // compression ratio fix | |
629 ds_read_packet(ds,demuxer->stream,x,pts,trak->chunks[trak->pos].pos,0); | |
630 if(ds==demuxer->audio) printf("sample %d bytes pts %5.3f\n",trak->chunks[trak->pos].size*trak->samplesize,pts); | |
2115 | 631 } else { |
2101 | 632 // read sample: |
633 if(trak->pos>=trak->samples_size) return 0; // EOF | |
634 stream_seek(demuxer->stream,trak->samples[trak->pos].pos); | |
635 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; | |
636 ds_read_packet(ds,demuxer->stream,trak->samples[trak->pos].size,pts,trak->samples[trak->pos].pos,0); | |
2115 | 637 } |
2101 | 638 ++trak->pos; |
2115 | 639 |
2101 | 640 return 1; |
641 | |
642 } | |
2227 | 643 |
644 static float mov_seek_track(mov_track_t* trak,float pts,int flags){ | |
645 | |
646 // printf("MOV track seek called %5.3f \n",pts); | |
647 if(flags&2) pts*=trak->length; else pts*=(float)trak->timescale; | |
648 | |
649 if(trak->samplesize){ | |
650 int sample=pts/trak->duration; | |
651 // printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration); | |
652 if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative | |
653 trak->pos=0; | |
654 while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos; | |
655 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale; | |
656 } else { | |
657 unsigned int ipts=pts; | |
658 // printf("MOV track seek - sample: %d \n",ipts); | |
659 if(!(flags&1)) ipts+=trak->samples[trak->pos].pts; | |
660 trak->pos=0; | |
661 while(trak->pos<trak->samples_size && trak->samples[trak->pos].pts<ipts) ++trak->pos; | |
662 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale; | |
663 } | |
664 | |
665 // printf("MOV track seek done: %5.3f \n",pts); | |
666 | |
667 return pts; | |
668 } | |
669 | |
670 void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){ | |
671 mov_priv_t* priv=demuxer->priv; | |
672 demux_stream_t* ds; | |
673 | |
674 // printf("MOV seek called %5.3f flag=%d \n",pts,flags); | |
675 | |
676 ds=demuxer->video; | |
677 if(ds && ds->id>=0 && ds->id<priv->track_db){ | |
678 mov_track_t* trak=priv->tracks[ds->id]; | |
679 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; | |
680 //if(!(flags&1)) pts+=ds->pts; | |
681 pts=ds->pts=mov_seek_track(trak,pts,flags); | |
682 flags=1; // absolute seconds | |
683 } | |
684 | |
685 ds=demuxer->audio; | |
686 if(ds && ds->id>=0 && ds->id<priv->track_db){ | |
687 mov_track_t* trak=priv->tracks[ds->id]; | |
688 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale; | |
689 //if(!(flags&1)) pts+=ds->pts; | |
690 ds->pts=mov_seek_track(trak,pts,flags); | |
691 } | |
692 | |
693 } | |
694 |