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