Mercurial > mplayer.hg
annotate demux_avi.c @ 1197:80ca716ce5e9
Made surface locks switchable via preprocessor.
author | atmosfear |
---|---|
date | Sat, 23 Jun 2001 10:18:23 +0000 |
parents | 3bcc435cd5a2 |
children | faee296c7c9a |
rev | line source |
---|---|
1 | 1 // AVI file parser for DEMUXER v2.6 by A'rpi/ESP-team |
2 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
3 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
4 #include <stdlib.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
5 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
6 extern int verbose; // defined in mplayer.c |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
7 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
8 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
9 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
10 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
11 #include "wine/mmreg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
12 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
13 #include "wine/vfw.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
14 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
15 #include "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
16 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
17 |
1 | 18 //static float avi_pts_frametime=1.0f/25.0f; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
19 float avi_audio_pts=0; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
20 float avi_video_pts=0; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
21 //float avi_video_ftime=0.04; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
22 int skip_video_frames=0; |
1 | 23 |
24 // Select ds from ID | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
25 demux_stream_t* demux_avi_select_stream(demuxer_t *demux,unsigned int id){ |
1 | 26 int stream_id=avi_stream_id(id); |
426 | 27 |
28 // printf("demux_avi_select_stream(%d) {a:%d/v:%d}\n",stream_id, | |
29 // demux->audio->id,demux->video->id); | |
30 | |
31 if(demux->video->id==-1) | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
32 if(demux->v_streams[stream_id]) |
426 | 33 demux->video->id=stream_id; |
34 | |
35 if(demux->audio->id==-1) | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
36 if(demux->a_streams[stream_id]) |
426 | 37 demux->audio->id=stream_id; |
38 | |
39 if(stream_id==demux->audio->id){ | |
40 if(!demux->audio->sh){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
41 demux->audio->sh=demux->a_streams[stream_id]; |
426 | 42 if(verbose) printf("Auto-selected AVI audio ID = %d\n",demux->audio->id); |
43 } | |
44 return demux->audio; | |
45 } | |
46 if(stream_id==demux->video->id){ | |
47 if(!demux->video->sh){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
48 demux->video->sh=demux->v_streams[stream_id]; |
426 | 49 if(verbose) printf("Auto-selected AVI video ID = %d\n",demux->video->id); |
50 } | |
51 return demux->video; | |
52 } | |
1 | 53 if(id!=mmioFOURCC('J','U','N','K')){ |
54 // unknown | |
600 | 55 if(verbose>=2) printf("Unknown chunk: %.4s (%X)\n",(char *) &id,id); |
1 | 56 } |
57 return NULL; | |
58 } | |
59 | |
979 | 60 static int demux_avi_read_packet(demuxer_t *demux,unsigned int id,unsigned int len,int idxpos,int flags){ |
1 | 61 int skip; |
62 float pts=0; | |
63 demux_stream_t *ds=demux_avi_select_stream(demux,id); | |
64 | |
65 if(verbose>=3) printf("demux_avi.read_packet: %X\n",id); | |
66 | |
67 if(ds==demux->audio){ | |
68 pts=avi_audio_pts; | |
69 avi_audio_pts=0; | |
70 } else | |
71 if(ds==demux->video){ | |
72 // video | |
73 if(skip_video_frames>0){ | |
74 // drop frame (seeking) | |
75 --skip_video_frames; | |
76 ds=NULL; | |
77 } else { | |
78 pts=avi_video_pts; | |
79 } | |
80 // ezt a 2 sort lehet hogy fell kell majd cserelni: | |
81 //avi_video_pts+=avi_pts_frametime; | |
291 | 82 //avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate; |
83 //avi_video_pts+=((sh_video_t*)ds->sh)->frametime; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
84 // FIXME!!! |
291 | 85 avi_video_pts+=(float)((sh_video_t*)(demux->video->sh))->video.dwScale/(float)((sh_video_t*)(demux->video->sh))->video.dwRate; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
86 // avi_video_pts+=avi_video_ftime; |
1 | 87 avi_audio_pts=avi_video_pts; |
88 } | |
89 | |
90 // len=stream_read_dword_le(demux->stream); | |
91 skip=(len+1)&(~1); // total bytes in this chunk | |
92 | |
93 if(ds){ | |
94 if(verbose>=2) printf("DEMUX_AVI: Read %d data bytes from packet %04X\n",len,id); | |
979 | 95 ds_read_packet(ds,demux->stream,len,pts,idxpos,flags); |
1 | 96 skip-=len; |
97 } | |
98 if(skip){ | |
99 if(verbose>=2) printf("DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id); | |
100 stream_skip(demux->stream,skip); | |
101 } | |
102 return ds?1:0; | |
103 } | |
104 | |
105 //static int num_elementary_packets100=0; | |
106 //static int num_elementary_packets101=0; | |
107 | |
108 // return value: | |
109 // 0 = EOF or no stream found | |
110 // 1 = successfully read a packet | |
111 int demux_avi_fill_buffer(demuxer_t *demux){ | |
112 unsigned int id=0; | |
113 unsigned int len; | |
114 int max_packs=128; | |
115 int ret=0; | |
116 | |
117 do{ | |
979 | 118 int flags=0; |
1 | 119 AVIINDEXENTRY *idx=NULL; |
120 demux->filepos=stream_tell(demux->stream); | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
121 if(demux->filepos>=demux->movi_end){ |
1 | 122 demux->stream->eof=1; |
123 return 0; | |
124 } | |
125 if(stream_eof(demux->stream)) return 0; | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
126 if(demux->idx_size>0 && demux->idx_pos<demux->idx_size){ |
1 | 127 unsigned int pos; |
128 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
129 //if(demux->idx_pos<0) printf("Fatal! idx_pos=%d\n",demux->idx_pos); |
1 | 130 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
131 idx=&((AVIINDEXENTRY *)demux->idx)[demux->idx_pos++]; |
1 | 132 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
133 //printf("[%d]",demux->idx_pos);fflush(stdout); |
1 | 134 |
135 //stream_seek(demux->stream,idx.dwChunkOffset); | |
136 //printf("IDX pos=%X idx.pos=%X idx.size=%X idx.flags=%X\n",demux->filepos, | |
137 // pos-4,idx->dwChunkLength,idx->dwFlags); | |
138 if(idx->dwFlags&AVIIF_LIST){ | |
139 // LIST | |
140 continue; | |
141 } | |
142 if(!demux_avi_select_stream(demux,idx->ckid)){ | |
600 | 143 if(verbose>2) printf("Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid); |
1 | 144 continue; // skip this chunk |
145 } | |
146 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
147 pos=idx->dwChunkOffset+demux->idx_offset; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
148 if(pos<demux->movi_start || pos>=demux->movi_end){ |
1 | 149 printf("ChunkOffset out of range! current=0x%X idx=0x%X \n",demux->filepos,pos); |
150 continue; | |
151 } | |
152 #if 0 | |
153 if(pos!=demux->filepos){ | |
154 printf("Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos); | |
155 } | |
156 #endif | |
157 stream_seek(demux->stream,pos); | |
158 id=stream_read_dword_le(demux->stream); | |
159 if(id!=idx->ckid){ | |
600 | 160 printf("ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid); |
1 | 161 continue; |
162 } | |
163 len=stream_read_dword_le(demux->stream); | |
164 // if((len&(~1))!=(idx->dwChunkLength&(~1))){ | |
165 // if((len)!=(idx->dwChunkLength)){ | |
166 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){ | |
600 | 167 printf("ChunkSize mismatch! raw=%d idx=%ld \n",len,idx->dwChunkLength); |
1 | 168 continue; |
169 } | |
979 | 170 if(idx->dwFlags&AVIIF_KEYFRAME) flags=1; |
1 | 171 } else { |
172 id=stream_read_dword_le(demux->stream); | |
173 len=stream_read_dword_le(demux->stream); | |
174 if(id==mmioFOURCC('L','I','S','T')){ | |
175 id=stream_read_dword_le(demux->stream); // list type | |
176 continue; | |
177 } | |
178 } | |
979 | 179 ret=demux_avi_read_packet(demux,id,len,demux->idx_pos-1,flags); |
1 | 180 if(!ret && skip_video_frames<=0) |
181 if(--max_packs==0){ | |
182 demux->stream->eof=1; | |
183 printf("demux: file doesn't contain the selected audio or video stream\n"); | |
184 return 0; | |
185 } | |
186 } while(ret!=1); | |
187 return 1; | |
188 } | |
189 | |
190 | |
191 // return value: | |
192 // 0 = EOF or no stream found | |
193 // 1 = successfully read a packet | |
194 int demux_avi_fill_buffer_ni(demuxer_t *demux,demux_stream_t* ds){ | |
195 unsigned int id=0; | |
196 unsigned int len; | |
197 int max_packs=128; | |
198 int ret=0; | |
199 | |
200 do{ | |
979 | 201 int flags=0; |
1 | 202 AVIINDEXENTRY *idx=NULL; |
203 int idx_pos=0; | |
204 demux->filepos=stream_tell(demux->stream); | |
205 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
206 if(ds==demux->video) idx_pos=demux->idx_pos_a++; else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
207 if(ds==demux->audio) idx_pos=demux->idx_pos_v++; else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
208 idx_pos=demux->idx_pos++; |
1 | 209 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
210 if(demux->idx_size>0 && idx_pos<demux->idx_size){ |
1 | 211 unsigned int pos; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
212 idx=&((AVIINDEXENTRY *)demux->idx)[idx_pos]; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
213 // idx=&demux->idx[idx_pos]; |
1 | 214 |
215 if(idx->dwFlags&AVIIF_LIST){ | |
216 // LIST | |
217 continue; | |
218 } | |
219 if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){ | |
600 | 220 if(verbose>2) printf("Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid); |
1 | 221 continue; // skip this chunk |
222 } | |
223 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
224 pos=idx->dwChunkOffset+demux->idx_offset; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
225 if(pos<demux->movi_start || pos>=demux->movi_end){ |
1 | 226 printf("ChunkOffset out of range! current=0x%X idx=0x%X \n",demux->filepos,pos); |
227 continue; | |
228 } | |
229 #if 0 | |
230 if(pos!=demux->filepos){ | |
231 printf("Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos); | |
232 } | |
233 #endif | |
234 stream_seek(demux->stream,pos); | |
235 | |
236 id=stream_read_dword_le(demux->stream); | |
237 | |
238 if(stream_eof(demux->stream)) return 0; | |
239 | |
240 if(id!=idx->ckid){ | |
600 | 241 printf("ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid); |
1 | 242 continue; |
243 } | |
244 len=stream_read_dword_le(demux->stream); | |
245 // if((len&(~1))!=(idx->dwChunkLength&(~1))){ | |
246 // if((len)!=(idx->dwChunkLength)){ | |
247 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){ | |
600 | 248 printf("ChunkSize mismatch! raw=%d idx=%ld \n",len,idx->dwChunkLength); |
1 | 249 continue; |
250 } | |
979 | 251 if(idx->dwFlags&AVIIF_KEYFRAME) flags=1; |
1 | 252 } else return 0; |
979 | 253 ret=demux_avi_read_packet(demux,id,len,idx_pos,flags); |
1 | 254 if(!ret && skip_video_frames<=0) |
255 if(--max_packs==0){ | |
256 demux->stream->eof=1; | |
257 printf("demux: file doesn't contain the selected audio or video stream\n"); | |
258 return 0; | |
259 } | |
260 } while(ret!=1); | |
261 return 1; | |
262 } | |
263 | |
264 | |
265 // return value: | |
266 // 0 = EOF or no stream found | |
267 // 1 = successfully read a packet | |
268 int demux_avi_fill_buffer_nini(demuxer_t *demux,demux_stream_t* ds){ | |
269 unsigned int id=0; | |
270 unsigned int len; | |
271 int ret=0; | |
272 int *fpos=NULL; | |
273 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
274 if(ds==demux->video) fpos=&demux->idx_pos_a; else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
275 if(ds==demux->audio) fpos=&demux->idx_pos_v; else |
1 | 276 return 0; |
277 | |
278 stream_seek(demux->stream,fpos[0]); | |
279 | |
280 do{ | |
281 | |
282 demux->filepos=stream_tell(demux->stream); | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
283 if(demux->filepos>=demux->movi_end){ |
1 | 284 demux->stream->eof=1; |
285 return 0; | |
286 } | |
287 if(stream_eof(demux->stream)) return 0; | |
288 | |
289 id=stream_read_dword_le(demux->stream); | |
290 len=stream_read_dword_le(demux->stream); | |
291 if(id==mmioFOURCC('L','I','S','T')){ | |
292 id=stream_read_dword_le(demux->stream); // list type | |
293 continue; | |
294 } | |
295 | |
296 if(ds==demux_avi_select_stream(demux,id)){ | |
297 // read it! | |
979 | 298 ret=demux_avi_read_packet(demux,id,len,demux->idx_pos-1,0); |
1 | 299 } else { |
300 // skip it! | |
301 int skip=(len+1)&(~1); // total bytes in this chunk | |
302 stream_skip(demux->stream,skip); | |
303 } | |
304 | |
305 } while(ret!=1); | |
306 fpos[0]=stream_tell(demux->stream); | |
307 return 1; | |
308 } | |
309 | |
310 |