1490
|
1 // QuickTime MOV file parser
|
|
2 // based on TOOLS/movinfo.c by A'rpi & Al3x
|
|
3
|
|
4 #include <stdio.h>
|
|
5 #include <stdlib.h>
|
|
6 #include <unistd.h>
|
|
7
|
|
8 extern int verbose; // defined in mplayer.c
|
|
9
|
|
10 #include "stream.h"
|
|
11 #include "demuxer.h"
|
|
12
|
|
13 #include "wine/mmreg.h"
|
|
14 #include "wine/avifmt.h"
|
|
15 #include "wine/vfw.h"
|
|
16
|
|
17 #include "codec-cfg.h"
|
|
18 #include "stheader.h"
|
|
19
|
|
20 typedef struct {
|
|
21 int id;
|
|
22 int type;
|
|
23 int timescale;
|
|
24 int width,height; // for video
|
|
25 unsigned int fourcc;
|
|
26 int data_len;
|
|
27 unsigned char* data;
|
|
28 } mov_track_t;
|
|
29
|
|
30 #define MOV_MAX_TRACKS 256
|
|
31
|
|
32 #define MOV_TRAK_UNKNOWN 0
|
|
33 #define MOV_TRAK_VIDEO 1
|
|
34 #define MOV_TRAK_AUDIO 2
|
|
35
|
|
36 typedef struct {
|
|
37 off_t moov_start;
|
|
38 off_t moov_end;
|
|
39 off_t mdat_start;
|
|
40 off_t mdat_end;
|
|
41 int track_db;
|
|
42 mov_track_t* tracks[MOV_MAX_TRACKS];
|
|
43 } mov_priv_t;
|
|
44
|
|
45 #define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d))
|
|
46
|
|
47 int mov_check_file(demuxer_t* demuxer){
|
|
48 int flags=0;
|
|
49 mov_priv_t* priv=malloc(sizeof(mov_priv_t));
|
|
50
|
|
51 printf("Checking for MOV\n");
|
|
52
|
|
53 memset(priv,0,sizeof(mov_priv_t));
|
|
54 demuxer->priv=priv;
|
|
55
|
|
56 while(1){
|
|
57 off_t len=stream_read_dword(demuxer->stream);
|
|
58 unsigned int id=stream_read_dword(demuxer->stream);
|
|
59 if(stream_eof(demuxer->stream)) break; // EOF
|
|
60 if(len<8) break; // invalid chunk
|
|
61 switch(id){
|
|
62 case MOV_FOURCC('m','o','o','v'):
|
|
63 if(verbose)printf("MOV: Movie header found!\n");
|
|
64 priv->moov_start=stream_tell(demuxer->stream);
|
|
65 priv->moov_end=priv->moov_start+len-8;
|
|
66 flags|=1;
|
|
67 break;
|
|
68 case MOV_FOURCC('m','d','a','t'):
|
|
69 if(verbose)printf("MOV: Movie DATA found!\n");
|
|
70 priv->mdat_start=stream_tell(demuxer->stream);
|
|
71 priv->mdat_end=priv->mdat_start+len-8;
|
|
72 flags|=2;
|
|
73 break;
|
|
74 default:
|
|
75 if(verbose) printf("MOV: unknown chunk: %.4s %d\n",&id,(int)len);
|
|
76 }
|
|
77 if(!stream_skip(demuxer->stream,len-8)) break;
|
|
78 }
|
|
79
|
|
80 return (flags==3);
|
|
81 }
|
|
82
|
|
83 static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak){
|
|
84 mov_priv_t* priv=demuxer->priv;
|
|
85 while(1){
|
|
86 off_t pos;
|
|
87 off_t len;
|
|
88 unsigned int id;
|
|
89 //
|
|
90 pos=stream_tell(demuxer->stream);
|
|
91 if(pos>=endpos) return; // END
|
|
92 len=stream_read_dword(demuxer->stream);
|
|
93 if(len<8) return; // error
|
|
94 len-=8;
|
|
95 id=stream_read_dword(demuxer->stream);
|
|
96 //
|
|
97 if(verbose>1)printf("lschunks %.4s %d\n",&id,(int)len);
|
|
98 //
|
|
99 if(trak){
|
|
100 switch(id){
|
|
101 case MOV_FOURCC('t','k','h','d'): {
|
|
102 if(verbose)printf("MOV: %*sTrack header!\n",level,"");
|
|
103 // read width x height
|
|
104 break;
|
|
105 }
|
|
106 case MOV_FOURCC('m','d','h','d'): {
|
|
107 if(verbose)printf("MOV: %*sMedia header!\n",level,"");
|
|
108 // read timescale
|
|
109 break;
|
|
110 }
|
|
111 case MOV_FOURCC('v','m','h','d'): {
|
|
112 if(verbose)printf("MOV: %*sVideo header!\n",level,"");
|
|
113 trak->type=MOV_TRAK_VIDEO;
|
|
114 // read video data
|
|
115 break;
|
|
116 }
|
|
117 case MOV_FOURCC('s','m','h','d'): {
|
|
118 if(verbose)printf("MOV: %*sSound header!\n",level,"");
|
|
119 trak->type=MOV_TRAK_AUDIO;
|
|
120 // read audio data
|
|
121 break;
|
|
122 }
|
|
123 case MOV_FOURCC('s','t','s','d'): {
|
|
124 int i=stream_read_dword(demuxer->stream); // temp!
|
|
125 int count=stream_read_dword(demuxer->stream);
|
|
126 if(verbose)printf("MOV: %*sDescription list! (cnt:%d)\n",level,"",count);
|
|
127 for(i=0;i<count;i++){
|
|
128 off_t pos=stream_tell(demuxer->stream);
|
|
129 off_t len=stream_read_dword(demuxer->stream);
|
|
130 unsigned int fourcc=stream_read_dword_le(demuxer->stream);
|
|
131 if(len<8) break; // error
|
|
132 if(verbose)printf("MOV: %*s desc #%d: %.4s",level,"",i,&fourcc);
|
|
133 if(!i){
|
|
134 trak->fourcc=fourcc;
|
|
135 // read codec data
|
|
136 trak->data_len=len-8;
|
|
137 trak->data=malloc(trak->data_len);
|
|
138 stream_read(demuxer->stream,trak->data,trak->data_len);
|
|
139 if(trak->type==MOV_TRAK_VIDEO && trak->data_len>43){
|
|
140 printf(" '%.*s'",trak->data_len-43,trak->data+43);
|
|
141 }
|
|
142 }
|
|
143 if(verbose) printf("\n");
|
|
144 if(fourcc!=trak->fourcc && i)
|
|
145 printf("MOV: Warning! variable FOURCC detected!?\n");
|
|
146 if(!stream_seek(demuxer->stream,pos+len)) break;
|
|
147 }
|
|
148 break;
|
|
149 }
|
|
150 case MOV_FOURCC('m','d','i','a'): {
|
|
151 if(verbose)printf("MOV: %*sMedia stream!\n",level,"");
|
|
152 lschunks(demuxer,level+1,pos+len,trak);
|
|
153 break;
|
|
154 }
|
|
155 case MOV_FOURCC('m','i','n','f'): {
|
|
156 if(verbose)printf("MOV: %*sMedia info!\n",level,"");
|
|
157 lschunks(demuxer,level+1,pos+len,trak);
|
|
158 break;
|
|
159 }
|
|
160 case MOV_FOURCC('s','t','b','l'): {
|
|
161 if(verbose)printf("MOV: %*sSample info!\n",level,"");
|
|
162 lschunks(demuxer,level+1,pos+len,trak);
|
|
163 break;
|
|
164 }
|
|
165 }//switch(id)
|
|
166 } else
|
|
167 if(id==MOV_FOURCC('t','r','a','k')){
|
|
168 // if(trak) printf("MOV: Warning! trak in trak?\n");
|
|
169 if(priv->track_db>=MOV_MAX_TRACKS){
|
|
170 printf("MOV: Warning! too many tracks!");
|
|
171 return;
|
|
172 }
|
|
173 trak=malloc(sizeof(mov_track_t));
|
|
174 memset(trak,0,sizeof(mov_track_t));
|
|
175 if(verbose)printf("MOV: Track #%d:\n",priv->track_db);
|
|
176 trak->id=priv->track_db;
|
|
177 priv->tracks[priv->track_db++]=trak;
|
|
178 lschunks(demuxer,level+1,pos+len,trak);
|
|
179 trak=NULL;
|
|
180 } else
|
|
181 if(id==MOV_FOURCC('c','m','o','v')){
|
|
182 printf("MOV: Compressed headers not (yet) supported!\n");
|
|
183 return;
|
|
184 }
|
|
185
|
|
186 pos+=len+8;
|
|
187 if(pos>=endpos) break;
|
|
188 if(!stream_seek(demuxer->stream,pos)) break;
|
|
189 }
|
|
190 }
|
|
191
|
|
192 int mov_read_header(demuxer_t* demuxer){
|
|
193 mov_priv_t* priv=demuxer->priv;
|
|
194
|
|
195 // printf("mov_read_header!\n");
|
|
196
|
|
197 // Parse header:
|
|
198 if(!stream_seek(demuxer->stream,priv->moov_start)) return 0; // ???
|
|
199 lschunks(demuxer, 0, priv->moov_end, NULL);
|
|
200
|
|
201 // Build tables:
|
|
202 // ...
|
|
203
|
|
204 printf("\n****** Quicktime MOV format not yet supported!!!!!!! *******\n");
|
|
205
|
|
206 return 1;
|
|
207 }
|