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