annotate demux_mov.c @ 1531:31df4b3fc37a

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