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