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