Mercurial > mplayer.hg
annotate demux_avi.c @ 1537:7bdf6a585b67
All aalib options can be passed to aalib (-aaXXX), also -aahelp is new
author | folke |
---|---|
date | Wed, 15 Aug 2001 19:27:57 +0000 |
parents | 6e752419c7e8 |
children | d4cd08b06665 |
rev | line source |
---|---|
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
1 // AVI file parser for DEMUXER v2.9 by A'rpi/ESP-team |
1 | 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> |
1430 | 5 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
6 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
7 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
|
8 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
9 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
10 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
11 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
12 #include "wine/mmreg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
13 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
14 #include "wine/vfw.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
15 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
16 #include "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
17 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
18 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
19 #include "aviheader.h" |
1 | 20 |
21 // Select ds from ID | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
22 demux_stream_t* demux_avi_select_stream(demuxer_t *demux,unsigned int id){ |
1 | 23 int stream_id=avi_stream_id(id); |
426 | 24 |
25 // printf("demux_avi_select_stream(%d) {a:%d/v:%d}\n",stream_id, | |
26 // demux->audio->id,demux->video->id); | |
27 | |
28 if(demux->video->id==-1) | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
29 if(demux->v_streams[stream_id]) |
426 | 30 demux->video->id=stream_id; |
31 | |
32 if(demux->audio->id==-1) | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
33 if(demux->a_streams[stream_id]) |
426 | 34 demux->audio->id=stream_id; |
35 | |
36 if(stream_id==demux->audio->id){ | |
37 if(!demux->audio->sh){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
38 demux->audio->sh=demux->a_streams[stream_id]; |
426 | 39 if(verbose) printf("Auto-selected AVI audio ID = %d\n",demux->audio->id); |
40 } | |
41 return demux->audio; | |
42 } | |
43 if(stream_id==demux->video->id){ | |
44 if(!demux->video->sh){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
45 demux->video->sh=demux->v_streams[stream_id]; |
426 | 46 if(verbose) printf("Auto-selected AVI video ID = %d\n",demux->video->id); |
47 } | |
48 return demux->video; | |
49 } | |
1 | 50 if(id!=mmioFOURCC('J','U','N','K')){ |
51 // unknown | |
600 | 52 if(verbose>=2) printf("Unknown chunk: %.4s (%X)\n",(char *) &id,id); |
1 | 53 } |
54 return NULL; | |
55 } | |
56 | |
979 | 57 static int demux_avi_read_packet(demuxer_t *demux,unsigned int id,unsigned int len,int idxpos,int flags){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
58 avi_priv_t *priv=demux->priv; |
1 | 59 int skip; |
60 float pts=0; | |
61 demux_stream_t *ds=demux_avi_select_stream(demux,id); | |
62 | |
63 if(verbose>=3) printf("demux_avi.read_packet: %X\n",id); | |
64 | |
65 if(ds==demux->audio){ | |
1455 | 66 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
67 if(priv->pts_corrected==0){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
68 // printf("\rYYY-A A: %5.3f V: %5.3f \n",priv->avi_audio_pts,priv->avi_video_pts); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
69 if(priv->pts_has_video){ |
1455 | 70 // we have video pts now |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
71 float delay=(float)priv->pts_corr_bytes/((sh_audio_t*)(ds->sh))->wf->nAvgBytesPerSec; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
72 printf("XXX initial v_pts=%5.3f a_pos=%d (%5.3f) \n",priv->avi_audio_pts,priv->pts_corr_bytes,delay); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
73 //priv->pts_correction=-priv->avi_audio_pts+delay; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
74 priv->pts_correction=delay-priv->avi_audio_pts; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
75 priv->avi_audio_pts+=priv->pts_correction; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
76 priv->pts_corrected=1; |
1455 | 77 } else |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
78 priv->pts_corr_bytes+=len; |
1455 | 79 } |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
80 pts=priv->avi_audio_pts; //+priv->pts_correction; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
81 priv->avi_audio_pts=0; |
1 | 82 } else |
1409 | 83 if(ds==demux->video){ |
1 | 84 // video |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
85 if(priv->skip_video_frames>0){ |
1 | 86 // drop frame (seeking) |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
87 --priv->skip_video_frames; |
1 | 88 ds=NULL; |
1498 | 89 // } else { |
90 // pts=priv->avi_video_pts; | |
1 | 91 } |
92 // ezt a 2 sort lehet hogy fell kell majd cserelni: | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
93 //priv->avi_video_pts+=avi_pts_frametime; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
94 //priv->avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
95 //priv->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
|
96 // FIXME!!! |
1368 | 97 #if 1 |
98 // printf("ds=0x%X\n",ds); | |
99 // printf("packno=%d\n",ds->pack_no); | |
1409 | 100 // printf("### pack_no=%d\n",demux->video->pack_no+demux->video->packs); |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
101 priv->avi_video_pts = (demux->video->pack_no+demux->video->packs) * |
1368 | 102 (float)((sh_video_t*)demux->video->sh)->video.dwScale / |
103 (float)((sh_video_t*)demux->video->sh)->video.dwRate; | |
104 #else | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
105 priv->avi_video_pts+=(float)((sh_video_t*)(demux->video->sh))->video.dwScale/(float)((sh_video_t*)(demux->video->sh))->video.dwRate; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
106 // priv->avi_video_pts+=avi_video_ftime; |
1368 | 107 #endif |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
108 // printf("\rYYY-V A: %5.3f V: %5.3f \n",priv->avi_audio_pts,priv->avi_video_pts); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
109 priv->avi_audio_pts=priv->avi_video_pts+priv->pts_correction; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
110 priv->pts_has_video=1; |
1455 | 111 |
1498 | 112 pts=priv->avi_video_pts; |
113 | |
114 //printf("read pack_no: %d pts %5.3f \n",demux->video->pack_no+demux->video->packs,pts); | |
115 | |
1 | 116 } |
117 | |
118 // len=stream_read_dword_le(demux->stream); | |
119 skip=(len+1)&(~1); // total bytes in this chunk | |
120 | |
121 if(ds){ | |
122 if(verbose>=2) printf("DEMUX_AVI: Read %d data bytes from packet %04X\n",len,id); | |
979 | 123 ds_read_packet(ds,demux->stream,len,pts,idxpos,flags); |
1 | 124 skip-=len; |
125 } | |
126 if(skip){ | |
127 if(verbose>=2) printf("DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id); | |
128 stream_skip(demux->stream,skip); | |
129 } | |
130 return ds?1:0; | |
131 } | |
132 | |
133 // return value: | |
134 // 0 = EOF or no stream found | |
135 // 1 = successfully read a packet | |
136 int demux_avi_fill_buffer(demuxer_t *demux){ | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
137 avi_priv_t *priv=demux->priv; |
1 | 138 unsigned int id=0; |
139 unsigned int len; | |
140 int max_packs=128; | |
141 int ret=0; | |
142 | |
143 do{ | |
979 | 144 int flags=0; |
1 | 145 AVIINDEXENTRY *idx=NULL; |
1421 | 146 #if 0 |
1 | 147 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
|
148 if(demux->filepos>=demux->movi_end){ |
1 | 149 demux->stream->eof=1; |
150 return 0; | |
151 } | |
152 if(stream_eof(demux->stream)) return 0; | |
1421 | 153 #endif |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
154 if(priv->idx_size>0 && priv->idx_pos<priv->idx_size){ |
1 | 155 unsigned int pos; |
156 | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
157 //if(priv->idx_pos<0) printf("Fatal! idx_pos=%d\n",priv->idx_pos); |
1 | 158 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
159 idx=&((AVIINDEXENTRY *)priv->idx)[priv->idx_pos++]; |
1 | 160 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
161 //printf("[%d]",priv->idx_pos);fflush(stdout); |
1 | 162 |
163 //stream_seek(demux->stream,idx.dwChunkOffset); | |
164 //printf("IDX pos=%X idx.pos=%X idx.size=%X idx.flags=%X\n",demux->filepos, | |
165 // pos-4,idx->dwChunkLength,idx->dwFlags); | |
166 if(idx->dwFlags&AVIIF_LIST){ | |
167 // LIST | |
168 continue; | |
169 } | |
170 if(!demux_avi_select_stream(demux,idx->ckid)){ | |
600 | 171 if(verbose>2) printf("Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid); |
1 | 172 continue; // skip this chunk |
173 } | |
174 | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
175 pos=idx->dwChunkOffset+priv->idx_offset; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
176 if(pos<demux->movi_start || pos>=demux->movi_end){ |
1421 | 177 printf("ChunkOffset out of range! idx=0x%X \n",pos); |
1 | 178 continue; |
179 } | |
180 #if 0 | |
181 if(pos!=demux->filepos){ | |
182 printf("Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos); | |
183 } | |
184 #endif | |
185 stream_seek(demux->stream,pos); | |
1421 | 186 demux->filepos=stream_tell(demux->stream); |
1 | 187 id=stream_read_dword_le(demux->stream); |
1421 | 188 if(stream_eof(demux->stream)) return 0; // EOF! |
189 | |
1 | 190 if(id!=idx->ckid){ |
1464 | 191 if(verbose) printf("ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid); |
192 id=idx->ckid; | |
193 // continue; | |
1 | 194 } |
195 len=stream_read_dword_le(demux->stream); | |
196 // if((len&(~1))!=(idx->dwChunkLength&(~1))){ | |
197 // if((len)!=(idx->dwChunkLength)){ | |
198 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){ | |
1464 | 199 if(verbose) printf("ChunkSize mismatch! raw=%d idx=%ld \n",len,idx->dwChunkLength); |
200 len=idx->dwChunkLength; | |
201 // continue; | |
1 | 202 } |
979 | 203 if(idx->dwFlags&AVIIF_KEYFRAME) flags=1; |
1 | 204 } else { |
1421 | 205 demux->filepos=stream_tell(demux->stream); |
206 if(demux->filepos>=demux->movi_end){ | |
207 demux->stream->eof=1; | |
208 return 0; | |
209 } | |
1 | 210 id=stream_read_dword_le(demux->stream); |
211 len=stream_read_dword_le(demux->stream); | |
1421 | 212 if(stream_eof(demux->stream)) return 0; // EOF! |
213 | |
1 | 214 if(id==mmioFOURCC('L','I','S','T')){ |
215 id=stream_read_dword_le(demux->stream); // list type | |
216 continue; | |
217 } | |
218 } | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
219 ret=demux_avi_read_packet(demux,id,len,priv->idx_pos-1,flags); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
220 if(!ret && priv->skip_video_frames<=0) |
1 | 221 if(--max_packs==0){ |
222 demux->stream->eof=1; | |
223 printf("demux: file doesn't contain the selected audio or video stream\n"); | |
224 return 0; | |
225 } | |
226 } while(ret!=1); | |
227 return 1; | |
228 } | |
229 | |
230 | |
231 // return value: | |
232 // 0 = EOF or no stream found | |
233 // 1 = successfully read a packet | |
234 int demux_avi_fill_buffer_ni(demuxer_t *demux,demux_stream_t* ds){ | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
235 avi_priv_t *priv=demux->priv; |
1 | 236 unsigned int id=0; |
237 unsigned int len; | |
238 int max_packs=128; | |
239 int ret=0; | |
240 | |
241 do{ | |
979 | 242 int flags=0; |
1 | 243 AVIINDEXENTRY *idx=NULL; |
244 int idx_pos=0; | |
245 demux->filepos=stream_tell(demux->stream); | |
246 | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
247 if(ds==demux->video) idx_pos=priv->idx_pos_v++; else |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
248 if(ds==demux->audio) idx_pos=priv->idx_pos_a++; else |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
249 idx_pos=priv->idx_pos++; |
1 | 250 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
251 if(priv->idx_size>0 && idx_pos<priv->idx_size){ |
1 | 252 unsigned int pos; |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
253 idx=&((AVIINDEXENTRY *)priv->idx)[idx_pos]; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
254 // idx=&priv->idx[idx_pos]; |
1 | 255 |
256 if(idx->dwFlags&AVIIF_LIST){ | |
257 // LIST | |
258 continue; | |
259 } | |
260 if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){ | |
600 | 261 if(verbose>2) printf("Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid); |
1 | 262 continue; // skip this chunk |
263 } | |
264 | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
265 pos=idx->dwChunkOffset+priv->idx_offset; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
266 if(pos<demux->movi_start || pos>=demux->movi_end){ |
1 | 267 printf("ChunkOffset out of range! current=0x%X idx=0x%X \n",demux->filepos,pos); |
268 continue; | |
269 } | |
270 #if 0 | |
271 if(pos!=demux->filepos){ | |
272 printf("Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos); | |
273 } | |
274 #endif | |
275 stream_seek(demux->stream,pos); | |
276 | |
277 id=stream_read_dword_le(demux->stream); | |
278 | |
279 if(stream_eof(demux->stream)) return 0; | |
280 | |
281 if(id!=idx->ckid){ | |
1464 | 282 if(verbose) printf("ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid); |
283 id=idx->ckid; | |
284 // continue; | |
1 | 285 } |
286 len=stream_read_dword_le(demux->stream); | |
287 // if((len&(~1))!=(idx->dwChunkLength&(~1))){ | |
288 // if((len)!=(idx->dwChunkLength)){ | |
289 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){ | |
1464 | 290 if(verbose) printf("ChunkSize mismatch! raw=%d idx=%ld \n",len,idx->dwChunkLength); |
291 len=idx->dwChunkLength; | |
292 // continue; | |
1 | 293 } |
979 | 294 if(idx->dwFlags&AVIIF_KEYFRAME) flags=1; |
1 | 295 } else return 0; |
979 | 296 ret=demux_avi_read_packet(demux,id,len,idx_pos,flags); |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
297 if(!ret && priv->skip_video_frames<=0) |
1 | 298 if(--max_packs==0){ |
299 demux->stream->eof=1; | |
300 printf("demux: file doesn't contain the selected audio or video stream\n"); | |
301 return 0; | |
302 } | |
303 } while(ret!=1); | |
304 return 1; | |
305 } | |
306 | |
307 | |
308 // return value: | |
309 // 0 = EOF or no stream found | |
310 // 1 = successfully read a packet | |
311 int demux_avi_fill_buffer_nini(demuxer_t *demux,demux_stream_t* ds){ | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
312 avi_priv_t *priv=demux->priv; |
1 | 313 unsigned int id=0; |
314 unsigned int len; | |
315 int ret=0; | |
316 int *fpos=NULL; | |
317 | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
318 if(ds==demux->video) fpos=&priv->idx_pos_v; else |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
319 if(ds==demux->audio) fpos=&priv->idx_pos_a; else |
1 | 320 return 0; |
321 | |
322 stream_seek(demux->stream,fpos[0]); | |
323 | |
324 do{ | |
325 | |
326 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
|
327 if(demux->filepos>=demux->movi_end){ |
1 | 328 demux->stream->eof=1; |
329 return 0; | |
330 } | |
331 if(stream_eof(demux->stream)) return 0; | |
332 | |
333 id=stream_read_dword_le(demux->stream); | |
334 len=stream_read_dword_le(demux->stream); | |
335 if(id==mmioFOURCC('L','I','S','T')){ | |
336 id=stream_read_dword_le(demux->stream); // list type | |
337 continue; | |
338 } | |
339 | |
340 if(ds==demux_avi_select_stream(demux,id)){ | |
341 // read it! | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
342 ret=demux_avi_read_packet(demux,id,len,priv->idx_pos-1,0); |
1 | 343 } else { |
344 // skip it! | |
345 int skip=(len+1)&(~1); // total bytes in this chunk | |
346 stream_skip(demux->stream,skip); | |
347 } | |
348 | |
349 } while(ret!=1); | |
350 fpos[0]=stream_tell(demux->stream); | |
351 return 1; | |
352 } | |
353 | |
1496 | 354 //extern int audio_id; |
355 //extern int video_id; | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
356 extern int index_mode; // -1=untouched 0=don't use index 1=use (geneate) index |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
357 extern int force_ni; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
358 extern int pts_from_bps; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
359 |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
360 demuxer_t* demux_open_avi(demuxer_t* demuxer){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
361 demux_stream_t *d_audio=demuxer->audio; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
362 demux_stream_t *d_video=demuxer->video; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
363 sh_audio_t *sh_audio=NULL; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
364 sh_video_t *sh_video=NULL; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
365 avi_priv_t* priv=malloc(sizeof(avi_priv_t)); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
366 |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
367 // priv struct: |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
368 priv->avi_audio_pts=priv->avi_video_pts=0.0f; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
369 priv->pts_correction=0.0f; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
370 priv->skip_video_frames=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
371 priv->pts_corr_bytes=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
372 priv->pts_has_video=priv->pts_corrected=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
373 demuxer->priv=(void*)priv; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
374 |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
375 //---- AVI header: |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
376 read_avi_header(demuxer,(demuxer->stream->type!=STREAMTYPE_STREAM)?index_mode:-2); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
377 stream_reset(demuxer->stream); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
378 stream_seek(demuxer->stream,demuxer->movi_start); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
379 priv->idx_pos=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
380 priv->idx_pos_a=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
381 priv->idx_pos_v=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
382 if(priv->idx_size>0){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
383 // decide index format: |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
384 if(((AVIINDEXENTRY *)priv->idx)[0].dwChunkOffset<demuxer->movi_start) |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
385 priv->idx_offset=demuxer->movi_start-4; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
386 else |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
387 priv->idx_offset=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
388 if(verbose) printf("AVI index offset: %d\n",priv->idx_offset); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
389 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
390 // demuxer->endpos=avi_header.movi_end; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
391 |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
392 if(priv->idx_size>0){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
393 // check that file is non-interleaved: |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
394 int i; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
395 int a_pos=-1; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
396 int v_pos=-1; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
397 for(i=0;i<priv->idx_size;i++){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
398 AVIINDEXENTRY* idx=&((AVIINDEXENTRY *)priv->idx)[i]; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
399 demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
400 int pos=idx->dwChunkOffset+priv->idx_offset; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
401 if(a_pos==-1 && ds==demuxer->audio){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
402 a_pos=pos; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
403 if(v_pos!=-1) break; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
404 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
405 if(v_pos==-1 && ds==demuxer->video){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
406 v_pos=pos; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
407 if(a_pos!=-1) break; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
408 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
409 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
410 if(v_pos==-1){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
411 fprintf(stderr,"AVI_NI: missing video stream!? contact the author, it may be a bug :(\n"); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
412 return NULL; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
413 // GUI_MSG( mplErrorAVINI ) |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
414 // exit(1); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
415 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
416 if(a_pos==-1){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
417 printf("AVI_NI: No audio stream found -> nosound\n"); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
418 sh_audio=NULL; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
419 } else { |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
420 if(force_ni || abs(a_pos-v_pos)>0x100000){ // distance > 1MB |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
421 printf("%s NON-INTERLEAVED AVI file-format!\n",force_ni?"Forced":"Detected"); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
422 demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!! |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
423 pts_from_bps=1; // force BPS sync! |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
424 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
425 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
426 } else { |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
427 // no index |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
428 if(force_ni){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
429 printf("Using NON-INTERLEAVED Broken AVI file-format!\n"); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
430 demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!! |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
431 priv->idx_pos_a= |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
432 priv->idx_pos_v=demuxer->movi_start; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
433 pts_from_bps=1; // force BPS sync! |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
434 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
435 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
436 if(!ds_fill_buffer(d_video)){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
437 fprintf(stderr,"AVI: missing video stream!? contact the author, it may be a bug :(\n"); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
438 return NULL; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
439 // GUI_MSG( mplAVIErrorMissingVideoStream ) |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
440 // exit(1); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
441 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
442 sh_video=d_video->sh;sh_video->ds=d_video; |
1496 | 443 if(d_audio->id!=-2){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
444 if(verbose) printf("AVI: Searching for audio stream (id:%d)\n",d_audio->id); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
445 if(!ds_fill_buffer(d_audio)){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
446 printf("AVI: No Audio stream found... ->nosound\n"); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
447 sh_audio=NULL; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
448 } else { |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
449 sh_audio=d_audio->sh;sh_audio->ds=d_audio; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
450 sh_audio->format=sh_audio->wf->wFormatTag; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
451 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
452 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
453 // calc. FPS: |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
454 sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
455 sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
456 // calculating video bitrate: |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
457 sh_video->i_bps=demuxer->movi_end-demuxer->movi_start-priv->idx_size*8; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
458 if(sh_audio) sh_video->i_bps-=sh_audio->audio.dwLength; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
459 if(verbose) printf("AVI video length=%d\n",sh_video->i_bps); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
460 sh_video->i_bps=((float)sh_video->i_bps/(float)sh_video->video.dwLength)*sh_video->fps; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
461 printf("VIDEO: [%.4s] %ldx%ld %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n", |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
462 (char *)&sh_video->bih->biCompression, |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
463 sh_video->bih->biWidth, |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
464 sh_video->bih->biHeight, |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
465 sh_video->bih->biBitCount, |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
466 sh_video->fps, |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
467 sh_video->i_bps*0.008f, |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
468 sh_video->i_bps/1024.0f ); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
469 |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
470 return demuxer; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
471 |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
472 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
473 |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
474 //extern float initial_pts_delay; |
1 | 475 |
1466 | 476 void demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
477 avi_priv_t *priv=demuxer->priv; |
1466 | 478 demux_stream_t *d_audio=demuxer->audio; |
479 demux_stream_t *d_video=demuxer->video; | |
480 sh_audio_t *sh_audio=d_audio->sh; | |
481 sh_video_t *sh_video=d_video->sh; | |
482 float skip_audio_secs=0; | |
483 | |
484 //FIXME: OFF_T - Didn't check AVI case yet (avi files can't be >2G anyway?) | |
485 //================= seek in AVI ========================== | |
486 int rel_seek_frames=rel_seek_secs*sh_video->fps; | |
487 int video_chunk_pos=d_video->pos; | |
488 int i; | |
489 | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
490 priv->skip_video_frames=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
491 priv->avi_audio_pts=0; |
1466 | 492 |
1481 | 493 // ------------ STEP 1: find nearest video keyframe chunk ------------ |
1466 | 494 // find nearest video keyframe chunk pos: |
495 if(rel_seek_frames>0){ | |
496 // seek forward | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
497 while(video_chunk_pos<priv->idx_size){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
498 int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid; |
1466 | 499 if(avi_stream_id(id)==d_video->id){ // video frame |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
500 if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break; |
1466 | 501 } |
502 ++video_chunk_pos; | |
503 } | |
504 } else { | |
505 // seek backward | |
1498 | 506 while(video_chunk_pos>0){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
507 int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid; |
1466 | 508 if(avi_stream_id(id)==d_video->id){ // video frame |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
509 if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break; |
1466 | 510 } |
511 --video_chunk_pos; | |
512 } | |
513 } | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
514 priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=video_chunk_pos; |
1466 | 515 |
516 // re-calc video pts: | |
517 d_video->pack_no=0; | |
518 for(i=0;i<video_chunk_pos;i++){ | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
519 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; |
1466 | 520 if(avi_stream_id(id)==d_video->id) ++d_video->pack_no; |
521 } | |
522 sh_video->num_frames=d_video->pack_no; | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
523 priv->avi_video_pts=d_video->pack_no*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
1481 | 524 d_video->pos=video_chunk_pos; |
1498 | 525 |
526 printf("V_SEEK: pack=%d pts=%5.3f chunk=%d \n",d_video->pack_no,priv->avi_video_pts,video_chunk_pos); | |
1481 | 527 |
528 // ------------ STEP 2: seek audio, find the right chunk & pos ------------ | |
529 | |
530 d_audio->pack_no=0; | |
531 d_audio->dpos=0; | |
1466 | 532 |
533 if(sh_audio){ | |
534 int i; | |
1481 | 535 // int apos=0; |
1466 | 536 int last=0; |
537 int len=0; | |
538 int skip_audio_bytes=0; | |
1481 | 539 int curr_audio_pos=-1; |
540 int audio_chunk_pos=-1; | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
541 int chunk_max=(demuxer->type==DEMUXER_TYPE_AVI)?video_chunk_pos:priv->idx_size; |
1481 | 542 |
543 if(sh_audio->audio.dwSampleSize){ | |
544 // constant rate audio stream | |
545 #if 0 | |
546 int align; | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
547 curr_audio_pos=(priv->avi_video_pts) * sh_audio->wf->nAvgBytesPerSec; |
1481 | 548 if(curr_audio_pos<0)curr_audio_pos=0; |
549 align=sh_audio->audio.dwSampleSize; | |
550 if(sh_audio->wf->nBlockAlign>align) align=sh_audio->wf->nBlockAlign; | |
551 curr_audio_pos/=align; | |
552 curr_audio_pos*=align; | |
1466 | 553 #else |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
554 curr_audio_pos=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; |
1481 | 555 curr_audio_pos*=sh_audio->audio.dwSampleSize; |
1466 | 556 #endif |
557 | |
558 // find audio chunk pos: | |
1481 | 559 for(i=0;i<chunk_max;i++){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
560 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; |
1466 | 561 if(avi_stream_id(id)==d_audio->id){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
562 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength; |
1481 | 563 audio_chunk_pos=i; ++d_audio->pack_no; |
564 if(d_audio->dpos<=curr_audio_pos && curr_audio_pos<(d_audio->dpos+len)){ | |
565 //if(verbose)printf("break;\n"); | |
1466 | 566 break; |
567 } | |
1481 | 568 d_audio->dpos+=len; |
1466 | 569 } |
570 } | |
1481 | 571 skip_audio_bytes=curr_audio_pos-d_audio->dpos; |
1466 | 572 |
1481 | 573 } else { |
574 // VBR audio | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
575 int chunks=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; |
1481 | 576 audio_chunk_pos=0; |
577 | |
578 // find audio chunk pos: | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
579 for(i=0;i<priv->idx_size && chunks>0;i++){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
580 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; |
1481 | 581 if(avi_stream_id(id)==d_audio->id){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
582 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength; |
1481 | 583 if(i>chunk_max){ |
584 skip_audio_bytes+=len; | |
585 } else { | |
586 ++d_audio->pack_no; | |
587 d_audio->dpos+=len; | |
588 audio_chunk_pos=i; | |
589 } | |
590 --chunks; | |
591 } | |
592 } | |
593 //if(audio_chunk_pos>chunk_max) audio_chunk_pos=chunk_max; | |
594 | |
595 // printf("VBR seek: %5.3f -> chunk_no %d -> chunk_idx %d + skip %d \n", | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
596 // priv->avi_video_pts, audio_chunk_pos, ); |
1481 | 597 |
598 } | |
599 | |
600 // Now we have: | |
601 // audio_chunk_pos = chunk no in index table (it's <=chunk_max) | |
602 // skip_audio_bytes = bytes to be skipped after chunk seek | |
603 // d-audio->pack_no = chunk_no in stream at audio_chunk_pos | |
604 // d_audio->dpos = bytepos in stream at audio_chunk_pos | |
605 // let's seek! | |
606 | |
1466 | 607 // update stream position: |
608 d_audio->pos=audio_chunk_pos; | |
1481 | 609 // d_audio->dpos=apos; |
610 // d_audio->pts=initial_pts_delay+(float)apos/(float)sh_audio->wf->nAvgBytesPerSec; | |
611 | |
612 if(demuxer->type==DEMUXER_TYPE_AVI){ | |
613 // interleaved stream: | |
614 if(audio_chunk_pos<video_chunk_pos){ | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
615 // calc priv->skip_video_frames & adjust video pts counter: |
1481 | 616 for(i=audio_chunk_pos;i<video_chunk_pos;i++){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
617 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
618 if(avi_stream_id(id)==d_video->id) ++priv->skip_video_frames; |
1481 | 619 } |
620 // requires for correct audio pts calculation (demuxer): | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
621 priv->avi_video_pts-=priv->skip_video_frames*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
622 priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=audio_chunk_pos; |
1481 | 623 } |
624 } else { | |
625 // non-interleaved stream: | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
626 priv->idx_pos_a=audio_chunk_pos; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
627 priv->idx_pos_v=video_chunk_pos; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
628 priv->idx_pos=(audio_chunk_pos<video_chunk_pos)?audio_chunk_pos:video_chunk_pos; |
1481 | 629 } |
1498 | 630 |
1508
6e752419c7e8
update pts to obtain OSD time display change while rewinding/forwarding
atlka
parents:
1498
diff
changeset
|
631 |
1466 | 632 |
633 if(verbose) printf("SEEK: idx=%d (a:%d v:%d) v.skip=%d a.skip=%d/%4.3f \n", | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
634 priv->idx_pos,audio_chunk_pos,video_chunk_pos, |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
635 priv->skip_video_frames,skip_audio_bytes,skip_audio_secs); |
1466 | 636 |
637 if(skip_audio_bytes){ | |
638 demux_read_data(d_audio,NULL,skip_audio_bytes); | |
639 //d_audio->pts=0; // PTS is outdated because of the raw data skipping | |
640 } | |
641 resync_audio_stream(sh_audio); | |
642 | |
1481 | 643 // sh_audio->timer=-skip_audio_secs; |
1466 | 644 |
645 } | |
1508
6e752419c7e8
update pts to obtain OSD time display change while rewinding/forwarding
atlka
parents:
1498
diff
changeset
|
646 d_video->pts=priv->avi_video_pts; // OSD |
1466 | 647 |
648 } | |
649 | |
650 | |
651 |