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