Mercurial > mplayer.hg
annotate demux_avi.c @ 1414:68e8cd978708
-fsmode range extended
author | arpi |
---|---|
date | Sun, 29 Jul 2001 16:31:37 +0000 |
parents | 65058a94df3b |
children | ea0a0b9e6fbc |
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 | |
1409 | 71 if(ds==demux->video){ |
1 | 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!!! |
1368 | 85 #if 1 |
86 // printf("ds=0x%X\n",ds); | |
87 // printf("packno=%d\n",ds->pack_no); | |
1409 | 88 // printf("### pack_no=%d\n",demux->video->pack_no+demux->video->packs); |
89 avi_video_pts = (demux->video->pack_no+demux->video->packs) * | |
1368 | 90 (float)((sh_video_t*)demux->video->sh)->video.dwScale / |
91 (float)((sh_video_t*)demux->video->sh)->video.dwRate; | |
92 #else | |
291 | 93 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
|
94 // avi_video_pts+=avi_video_ftime; |
1368 | 95 #endif |
1 | 96 avi_audio_pts=avi_video_pts; |
97 } | |
98 | |
99 // len=stream_read_dword_le(demux->stream); | |
100 skip=(len+1)&(~1); // total bytes in this chunk | |
101 | |
102 if(ds){ | |
103 if(verbose>=2) printf("DEMUX_AVI: Read %d data bytes from packet %04X\n",len,id); | |
979 | 104 ds_read_packet(ds,demux->stream,len,pts,idxpos,flags); |
1 | 105 skip-=len; |
106 } | |
107 if(skip){ | |
108 if(verbose>=2) printf("DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id); | |
109 stream_skip(demux->stream,skip); | |
110 } | |
111 return ds?1:0; | |
112 } | |
113 | |
114 //static int num_elementary_packets100=0; | |
115 //static int num_elementary_packets101=0; | |
116 | |
117 // return value: | |
118 // 0 = EOF or no stream found | |
119 // 1 = successfully read a packet | |
120 int demux_avi_fill_buffer(demuxer_t *demux){ | |
121 unsigned int id=0; | |
122 unsigned int len; | |
123 int max_packs=128; | |
124 int ret=0; | |
125 | |
126 do{ | |
979 | 127 int flags=0; |
1 | 128 AVIINDEXENTRY *idx=NULL; |
129 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
|
130 if(demux->filepos>=demux->movi_end){ |
1 | 131 demux->stream->eof=1; |
132 return 0; | |
133 } | |
134 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
|
135 if(demux->idx_size>0 && demux->idx_pos<demux->idx_size){ |
1 | 136 unsigned int pos; |
137 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
138 //if(demux->idx_pos<0) printf("Fatal! idx_pos=%d\n",demux->idx_pos); |
1 | 139 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
140 idx=&((AVIINDEXENTRY *)demux->idx)[demux->idx_pos++]; |
1 | 141 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
142 //printf("[%d]",demux->idx_pos);fflush(stdout); |
1 | 143 |
144 //stream_seek(demux->stream,idx.dwChunkOffset); | |
145 //printf("IDX pos=%X idx.pos=%X idx.size=%X idx.flags=%X\n",demux->filepos, | |
146 // pos-4,idx->dwChunkLength,idx->dwFlags); | |
147 if(idx->dwFlags&AVIIF_LIST){ | |
148 // LIST | |
149 continue; | |
150 } | |
151 if(!demux_avi_select_stream(demux,idx->ckid)){ | |
600 | 152 if(verbose>2) printf("Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid); |
1 | 153 continue; // skip this chunk |
154 } | |
155 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
156 pos=idx->dwChunkOffset+demux->idx_offset; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
157 if(pos<demux->movi_start || pos>=demux->movi_end){ |
1 | 158 printf("ChunkOffset out of range! current=0x%X idx=0x%X \n",demux->filepos,pos); |
159 continue; | |
160 } | |
161 #if 0 | |
162 if(pos!=demux->filepos){ | |
163 printf("Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos); | |
164 } | |
165 #endif | |
166 stream_seek(demux->stream,pos); | |
167 id=stream_read_dword_le(demux->stream); | |
168 if(id!=idx->ckid){ | |
600 | 169 printf("ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid); |
1 | 170 continue; |
171 } | |
172 len=stream_read_dword_le(demux->stream); | |
173 // if((len&(~1))!=(idx->dwChunkLength&(~1))){ | |
174 // if((len)!=(idx->dwChunkLength)){ | |
175 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){ | |
600 | 176 printf("ChunkSize mismatch! raw=%d idx=%ld \n",len,idx->dwChunkLength); |
1 | 177 continue; |
178 } | |
979 | 179 if(idx->dwFlags&AVIIF_KEYFRAME) flags=1; |
1 | 180 } else { |
181 id=stream_read_dword_le(demux->stream); | |
182 len=stream_read_dword_le(demux->stream); | |
183 if(id==mmioFOURCC('L','I','S','T')){ | |
184 id=stream_read_dword_le(demux->stream); // list type | |
185 continue; | |
186 } | |
187 } | |
979 | 188 ret=demux_avi_read_packet(demux,id,len,demux->idx_pos-1,flags); |
1 | 189 if(!ret && skip_video_frames<=0) |
190 if(--max_packs==0){ | |
191 demux->stream->eof=1; | |
192 printf("demux: file doesn't contain the selected audio or video stream\n"); | |
193 return 0; | |
194 } | |
195 } while(ret!=1); | |
196 return 1; | |
197 } | |
198 | |
199 | |
200 // return value: | |
201 // 0 = EOF or no stream found | |
202 // 1 = successfully read a packet | |
203 int demux_avi_fill_buffer_ni(demuxer_t *demux,demux_stream_t* ds){ | |
204 unsigned int id=0; | |
205 unsigned int len; | |
206 int max_packs=128; | |
207 int ret=0; | |
208 | |
209 do{ | |
979 | 210 int flags=0; |
1 | 211 AVIINDEXENTRY *idx=NULL; |
212 int idx_pos=0; | |
213 demux->filepos=stream_tell(demux->stream); | |
214 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
215 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
|
216 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
|
217 idx_pos=demux->idx_pos++; |
1 | 218 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
219 if(demux->idx_size>0 && idx_pos<demux->idx_size){ |
1 | 220 unsigned int pos; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
221 idx=&((AVIINDEXENTRY *)demux->idx)[idx_pos]; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
222 // idx=&demux->idx[idx_pos]; |
1 | 223 |
224 if(idx->dwFlags&AVIIF_LIST){ | |
225 // LIST | |
226 continue; | |
227 } | |
228 if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){ | |
600 | 229 if(verbose>2) printf("Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid); |
1 | 230 continue; // skip this chunk |
231 } | |
232 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
233 pos=idx->dwChunkOffset+demux->idx_offset; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
234 if(pos<demux->movi_start || pos>=demux->movi_end){ |
1 | 235 printf("ChunkOffset out of range! current=0x%X idx=0x%X \n",demux->filepos,pos); |
236 continue; | |
237 } | |
238 #if 0 | |
239 if(pos!=demux->filepos){ | |
240 printf("Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos); | |
241 } | |
242 #endif | |
243 stream_seek(demux->stream,pos); | |
244 | |
245 id=stream_read_dword_le(demux->stream); | |
246 | |
247 if(stream_eof(demux->stream)) return 0; | |
248 | |
249 if(id!=idx->ckid){ | |
600 | 250 printf("ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid); |
1 | 251 continue; |
252 } | |
253 len=stream_read_dword_le(demux->stream); | |
254 // if((len&(~1))!=(idx->dwChunkLength&(~1))){ | |
255 // if((len)!=(idx->dwChunkLength)){ | |
256 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){ | |
600 | 257 printf("ChunkSize mismatch! raw=%d idx=%ld \n",len,idx->dwChunkLength); |
1 | 258 continue; |
259 } | |
979 | 260 if(idx->dwFlags&AVIIF_KEYFRAME) flags=1; |
1 | 261 } else return 0; |
979 | 262 ret=demux_avi_read_packet(demux,id,len,idx_pos,flags); |
1 | 263 if(!ret && skip_video_frames<=0) |
264 if(--max_packs==0){ | |
265 demux->stream->eof=1; | |
266 printf("demux: file doesn't contain the selected audio or video stream\n"); | |
267 return 0; | |
268 } | |
269 } while(ret!=1); | |
270 return 1; | |
271 } | |
272 | |
273 | |
274 // return value: | |
275 // 0 = EOF or no stream found | |
276 // 1 = successfully read a packet | |
277 int demux_avi_fill_buffer_nini(demuxer_t *demux,demux_stream_t* ds){ | |
278 unsigned int id=0; | |
279 unsigned int len; | |
280 int ret=0; | |
281 int *fpos=NULL; | |
282 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
283 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
|
284 if(ds==demux->audio) fpos=&demux->idx_pos_v; else |
1 | 285 return 0; |
286 | |
287 stream_seek(demux->stream,fpos[0]); | |
288 | |
289 do{ | |
290 | |
291 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
|
292 if(demux->filepos>=demux->movi_end){ |
1 | 293 demux->stream->eof=1; |
294 return 0; | |
295 } | |
296 if(stream_eof(demux->stream)) return 0; | |
297 | |
298 id=stream_read_dword_le(demux->stream); | |
299 len=stream_read_dword_le(demux->stream); | |
300 if(id==mmioFOURCC('L','I','S','T')){ | |
301 id=stream_read_dword_le(demux->stream); // list type | |
302 continue; | |
303 } | |
304 | |
305 if(ds==demux_avi_select_stream(demux,id)){ | |
306 // read it! | |
979 | 307 ret=demux_avi_read_packet(demux,id,len,demux->idx_pos-1,0); |
1 | 308 } else { |
309 // skip it! | |
310 int skip=(len+1)&(~1); // total bytes in this chunk | |
311 stream_skip(demux->stream,skip); | |
312 } | |
313 | |
314 } while(ret!=1); | |
315 fpos[0]=stream_tell(demux->stream); | |
316 return 1; | |
317 } | |
318 | |
319 |