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