Mercurial > mplayer.hg
annotate libmpdemux/demux_avi.c @ 31666:796b778e2411
Enable robust resync for mpg123 decoder.
This prevents the decoder from giving up give after long pieces of invalid
data, for example during transmission errors with DVB-T and similar.
patch by Thomas Orgis, thomas-forum orgis org
author | diego |
---|---|
date | Tue, 13 Jul 2010 15:11:34 +0000 |
parents | f87bfe2885f2 |
children | 7b02012e9581 |
rev | line source |
---|---|
29238
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
1 /* |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
2 * AVI file parser for DEMUXER v2.9 |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
3 * Copyright (c) 2001 A'rpi/ESP-team |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
4 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
5 * This file is part of MPlayer. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
6 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
7 * MPlayer is free software; you can redistribute it and/or modify |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
10 * (at your option) any later version. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
11 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
12 * MPlayer is distributed in the hope that it will be useful, |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
15 * GNU General Public License for more details. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
16 * |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
18 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
d643e4643313
Add standard license header to all files in libmpdemux.
diego
parents:
28189
diff
changeset
|
20 */ |
1 | 21 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
22 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
23 #include <stdlib.h> |
1430 | 24 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
25 |
1567 | 26 #include "config.h" |
27 #include "mp_msg.h" | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1737
diff
changeset
|
28 #include "help_mp.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
29 |
22605
4d81dbdf46b9
Add explicit location for headers from the stream/ directory.
diego
parents:
22148
diff
changeset
|
30 #include "stream/stream.h" |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
31 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
32 #include "stheader.h" |
30585
2ed1972eb23b
Add header for demux_ogg_open, init_avi_with_ogg; avoids forward declarations.
diego
parents:
30581
diff
changeset
|
33 #include "demux_ogg.h" |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
34 #include "aviheader.h" |
1 | 35 |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25200
diff
changeset
|
36 extern const demuxer_desc_t demuxer_desc_avi_ni; |
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25200
diff
changeset
|
37 extern const demuxer_desc_t demuxer_desc_avi_nini; |
16211
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
38 |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
39 // PTS: 0=interleaved 1=BPS-based |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
40 int pts_from_bps=1; |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
41 |
1 | 42 // Select ds from ID |
30570
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
43 static demux_stream_t *demux_avi_select_stream(demuxer_t *demux, |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
44 unsigned int id) |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
45 { |
1 | 46 int stream_id=avi_stream_id(id); |
426 | 47 |
48 | |
49 if(demux->video->id==-1) | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
50 if(demux->v_streams[stream_id]) |
426 | 51 demux->video->id=stream_id; |
52 | |
53 if(demux->audio->id==-1) | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
54 if(demux->a_streams[stream_id]) |
426 | 55 demux->audio->id=stream_id; |
56 | |
57 if(stream_id==demux->audio->id){ | |
58 if(!demux->audio->sh){ | |
7785
ffe8bfaa2851
fix & workaround possible sig8/sig11 in blocksize calculation
arpi
parents:
7501
diff
changeset
|
59 sh_audio_t* sh; |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
60 avi_priv_t *priv=demux->priv; |
7785
ffe8bfaa2851
fix & workaround possible sig8/sig11 in blocksize calculation
arpi
parents:
7501
diff
changeset
|
61 sh=demux->audio->sh=demux->a_streams[stream_id]; |
1567 | 62 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
|
63 if(sh->wf){ |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
64 priv->audio_block_size=sh->wf->nBlockAlign; |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
65 if(!priv->audio_block_size){ |
7785
ffe8bfaa2851
fix & workaround possible sig8/sig11 in blocksize calculation
arpi
parents:
7501
diff
changeset
|
66 // 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
|
67 if(sh->format==1) |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
68 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
|
69 else |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
70 priv->audio_block_size=1; // hope the best... |
8059 | 71 } else { |
72 // workaround old mencoder's bug: | |
73 if(sh->audio.dwSampleSize==1 && sh->audio.dwScale==1 && | |
74 (sh->wf->nBlockAlign==1152 || sh->wf->nBlockAlign==576)){ | |
20700 | 75 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_WorkAroundBlockAlignHeaderBug); |
8059 | 76 priv->audio_block_size=1; |
77 } | |
7785
ffe8bfaa2851
fix & workaround possible sig8/sig11 in blocksize calculation
arpi
parents:
7501
diff
changeset
|
78 } |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
79 } else { |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
80 priv->audio_block_size=sh->audio.dwSampleSize; |
7785
ffe8bfaa2851
fix & workaround possible sig8/sig11 in blocksize calculation
arpi
parents:
7501
diff
changeset
|
81 } |
426 | 82 } |
83 return demux->audio; | |
84 } | |
85 if(stream_id==demux->video->id){ | |
86 if(!demux->video->sh){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
426
diff
changeset
|
87 demux->video->sh=demux->v_streams[stream_id]; |
1567 | 88 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected AVI video ID = %d\n",demux->video->id); |
426 | 89 } |
90 return demux->video; | |
91 } | |
1 | 92 if(id!=mmioFOURCC('J','U','N','K')){ |
93 // unknown | |
1998 | 94 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
|
95 //abort(); |
1 | 96 } |
97 return NULL; | |
98 } | |
99 | |
2438 | 100 static int valid_fourcc(unsigned int id){ |
20400
f4518826ea84
Allow lowercase letters in AVI stream id, fixes bug #277
reimar
parents:
20337
diff
changeset
|
101 static const char valid[] = "0123456789abcdefghijklmnopqrstuvwxyz" |
f4518826ea84
Allow lowercase letters in AVI stream id, fixes bug #277
reimar
parents:
20337
diff
changeset
|
102 "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; |
2438 | 103 unsigned char* fcc=(unsigned char*)(&id); |
20400
f4518826ea84
Allow lowercase letters in AVI stream id, fixes bug #277
reimar
parents:
20337
diff
changeset
|
104 return strchr(valid, fcc[0]) && strchr(valid, fcc[1]) && |
f4518826ea84
Allow lowercase letters in AVI stream id, fixes bug #277
reimar
parents:
20337
diff
changeset
|
105 strchr(valid, fcc[2]) && strchr(valid, fcc[3]); |
2438 | 106 } |
107 | |
29871 | 108 static int valid_stream_id(unsigned int id) { |
109 unsigned char* fcc=(unsigned char*)(&id); | |
110 return fcc[0] >= '0' && fcc[0] <= '9' && fcc[1] >= '0' && fcc[1] <= '9' && | |
111 ((fcc[2] == 'w' && fcc[3] == 'b') || (fcc[2] == 'd' && fcc[3] == 'c')); | |
112 } | |
113 | |
2438 | 114 static int choose_chunk_len(unsigned int len1,unsigned int len2){ |
115 // len1 has a bit more priority than len2. len1!=len2 | |
116 // Note: this is a first-idea-logic, may be wrong. comments welcomed. | |
117 | |
118 // prefer small frames rather than 0 | |
119 if(!len1) return (len2>0x80000) ? len1 : len2; | |
120 if(!len2) return (len1>0x100000) ? len2 : len1; | |
121 | |
122 // choose the smaller value: | |
123 return (len1<len2)? len1 : len2; | |
124 } | |
125 | |
6884
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
126 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
|
127 avi_priv_t *priv=demux->priv; |
1 | 128 int skip; |
129 float pts=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
130 |
1567 | 131 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_avi.read_packet: %X\n",id); |
1 | 132 |
133 if(ds==demux->audio){ | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
134 if(priv->pts_corrected==0){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
135 if(priv->pts_has_video){ |
1455 | 136 // we have video pts now |
2826 | 137 float delay=0; |
138 if(((sh_audio_t*)(ds->sh))->wf->nAvgBytesPerSec) | |
139 delay=(float)priv->pts_corr_bytes/((sh_audio_t*)(ds->sh))->wf->nAvgBytesPerSec; | |
1567 | 140 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
|
141 //priv->pts_correction=-priv->avi_audio_pts+delay; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
142 priv->pts_correction=delay-priv->avi_audio_pts; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
143 priv->avi_audio_pts+=priv->pts_correction; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
144 priv->pts_corrected=1; |
1455 | 145 } else |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
146 priv->pts_corr_bytes+=len; |
1455 | 147 } |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
148 if(pts_from_bps){ |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
149 pts = priv->audio_block_no * |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
150 (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
|
151 (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
|
152 } else |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
153 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
|
154 priv->avi_audio_pts=0; |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
155 // update blockcount: |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
156 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
|
157 ((len+priv->audio_block_size-1)/priv->audio_block_size) : 1; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
158 } else |
1409 | 159 if(ds==demux->video){ |
1 | 160 // video |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
161 if(priv->skip_video_frames>0){ |
1 | 162 // drop frame (seeking) |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
163 --priv->skip_video_frames; |
1 | 164 ds=NULL; |
165 } | |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
166 |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
167 pts = priv->avi_video_pts = priv->video_pack_no * |
1368 | 168 (float)((sh_video_t*)demux->video->sh)->video.dwScale / |
169 (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
|
170 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
171 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
|
172 priv->pts_has_video=1; |
1455 | 173 |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
174 if(ds) ++priv->video_pack_no; |
1498 | 175 |
1 | 176 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
177 |
1 | 178 skip=(len+1)&(~1); // total bytes in this chunk |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
179 |
1 | 180 if(ds){ |
1567 | 181 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_AVI: Read %d data bytes from packet %04X\n",len,id); |
979 | 182 ds_read_packet(ds,demux->stream,len,pts,idxpos,flags); |
1 | 183 skip-=len; |
184 } | |
28189
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
185 skip = FFMAX(skip, 0); |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
186 if (avi_stream_id(id) > 99 && id != mmioFOURCC('J','U','N','K')) |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
187 skip = FFMIN(skip, 65536); |
1 | 188 if(skip){ |
1567 | 189 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id); |
1 | 190 stream_skip(demux->stream,skip); |
191 } | |
192 return ds?1:0; | |
193 } | |
194 | |
28189
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
195 static uint32_t avi_find_id(stream_t *stream) { |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
196 uint32_t id = stream_read_dword_le(stream); |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
197 if (!id) { |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
198 mp_msg(MSGT_DEMUX, MSGL_WARN, "Incomplete stream? Trying resync.\n"); |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
199 do { |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
200 id = stream_read_dword_le(stream); |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
201 if (stream_eof(stream)) return 0; |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
202 } while (avi_stream_id(id) > 99); |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
203 } |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
204 return id; |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
205 } |
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
206 |
1 | 207 // return value: |
208 // 0 = EOF or no stream found | |
209 // 1 = successfully read a packet | |
16175 | 210 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
|
211 avi_priv_t *priv=demux->priv; |
1 | 212 unsigned int id=0; |
213 unsigned int len; | |
214 int ret=0; | |
6884
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
215 demux_stream_t *ds; |
1 | 216 |
217 do{ | |
9228 | 218 int flags=1; |
1 | 219 AVIINDEXENTRY *idx=NULL; |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
220 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
|
221 off_t pos; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
222 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
223 idx=&((AVIINDEXENTRY *)priv->idx)[priv->idx_pos++]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
224 |
1 | 225 if(idx->dwFlags&AVIIF_LIST){ |
29871 | 226 if (!valid_stream_id(idx->ckid)) |
1 | 227 // LIST |
228 continue; | |
29871 | 229 if (!priv->warned_unaligned) |
230 mp_msg(MSGT_DEMUX, MSGL_WARN, "Looks like unaligned chunk in index, broken AVI file!\n"); | |
231 priv->warned_unaligned = 1; | |
1 | 232 } |
233 if(!demux_avi_select_stream(demux,idx->ckid)){ | |
1567 | 234 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid); |
1 | 235 continue; // skip this chunk |
236 } | |
237 | |
12036 | 238 pos = (off_t)priv->idx_offset+AVI_IDX_OFFSET(idx); |
29920
4f740437ed2b
Finally rename the STREAM_SEEK define to MP_STREAM_SEEK, there are just too many
reimar
parents:
29872
diff
changeset
|
239 if((pos<demux->movi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start) && (demux->stream->flags & MP_STREAM_SEEK)){ |
17366 | 240 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkOffset out of range! idx=0x%"PRIX64" \n",(int64_t)pos); |
1 | 241 continue; |
242 } | |
243 stream_seek(demux->stream,pos); | |
1421 | 244 demux->filepos=stream_tell(demux->stream); |
1 | 245 id=stream_read_dword_le(demux->stream); |
1421 | 246 if(stream_eof(demux->stream)) return 0; // EOF! |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
247 |
1 | 248 if(id!=idx->ckid){ |
1567 | 249 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid); |
2438 | 250 if(valid_fourcc(idx->ckid)) |
251 id=idx->ckid; // use index if valid | |
252 else | |
253 if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad | |
1 | 254 } |
255 len=stream_read_dword_le(demux->stream); | |
256 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){ | |
17366 | 257 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%d \n",len,idx->dwChunkLength); |
2438 | 258 if(len>0x200000 && idx->dwChunkLength>0x200000) continue; // both values bad :( |
259 len=choose_chunk_len(idx->dwChunkLength,len); | |
1 | 260 } |
9228 | 261 if(!(idx->dwFlags&AVIIF_KEYFRAME)) flags=0; |
1 | 262 } else { |
1421 | 263 demux->filepos=stream_tell(demux->stream); |
29920
4f740437ed2b
Finally rename the STREAM_SEEK define to MP_STREAM_SEEK, there are just too many
reimar
parents:
29872
diff
changeset
|
264 if(demux->filepos>=demux->movi_end && demux->movi_end>demux->movi_start && (demux->stream->flags & MP_STREAM_SEEK)){ |
1421 | 265 demux->stream->eof=1; |
266 return 0; | |
267 } | |
28189
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
268 id=avi_find_id(demux->stream); |
1 | 269 len=stream_read_dword_le(demux->stream); |
1421 | 270 if(stream_eof(demux->stream)) return 0; // EOF! |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
271 |
6056
f980563afdbc
big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents:
4665
diff
changeset
|
272 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
|
273 id=stream_read_dword_le(demux->stream); // list or RIFF type |
1 | 274 continue; |
275 } | |
276 } | |
6884
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
277 |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
278 ds=demux_avi_select_stream(demux,id); |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
279 if(ds) |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
280 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
|
281 // 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
|
282 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
|
283 if(priv->idx_size>0){ |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
284 // has index |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
285 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
|
286 demux->desc=&demuxer_desc_avi_ni; |
6884
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
287 --priv->idx_pos; // hack |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
288 } else { |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
289 // no index |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
290 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
|
291 demux->desc=&demuxer_desc_avi_nini; |
6884
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
292 priv->idx_pos=demux->filepos; // hack |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
293 } |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
294 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
|
295 // 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
|
296 return -1; |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
297 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
298 |
6884
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
299 ret=demux_avi_read_packet(demux,ds,id,len,priv->idx_pos-1,flags); |
1 | 300 } while(ret!=1); |
301 return 1; | |
302 } | |
303 | |
304 | |
305 // return value: | |
306 // 0 = EOF or no stream found | |
307 // 1 = successfully read a packet | |
30570
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
308 static int demux_avi_fill_buffer_ni(demuxer_t *demux, demux_stream_t *ds) |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
309 { |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
310 avi_priv_t *priv=demux->priv; |
1 | 311 unsigned int id=0; |
312 unsigned int len; | |
313 int ret=0; | |
314 | |
315 do{ | |
9228 | 316 int flags=1; |
1 | 317 AVIINDEXENTRY *idx=NULL; |
318 int idx_pos=0; | |
319 demux->filepos=stream_tell(demux->stream); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
320 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
321 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
|
322 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
|
323 idx_pos=priv->idx_pos++; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
324 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
325 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
|
326 off_t pos; |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
327 idx=&((AVIINDEXENTRY *)priv->idx)[idx_pos]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
328 |
1 | 329 if(idx->dwFlags&AVIIF_LIST){ |
29871 | 330 if (!valid_stream_id(idx->ckid)) |
1 | 331 // LIST |
332 continue; | |
29871 | 333 if (!priv->warned_unaligned) |
334 mp_msg(MSGT_DEMUX, MSGL_WARN, "Looks like unaligned chunk in index, broken AVI file!\n"); | |
335 priv->warned_unaligned = 1; | |
1 | 336 } |
337 if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){ | |
1567 | 338 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid); |
1 | 339 continue; // skip this chunk |
340 } | |
341 | |
12036 | 342 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
|
343 if((pos<demux->movi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start)){ |
17366 | 344 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 | 345 continue; |
346 } | |
347 stream_seek(demux->stream,pos); | |
348 | |
349 id=stream_read_dword_le(demux->stream); | |
350 | |
351 if(stream_eof(demux->stream)) return 0; | |
352 | |
353 if(id!=idx->ckid){ | |
1567 | 354 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid); |
2438 | 355 if(valid_fourcc(idx->ckid)) |
356 id=idx->ckid; // use index if valid | |
357 else | |
358 if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad | |
1 | 359 } |
360 len=stream_read_dword_le(demux->stream); | |
361 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){ | |
17366 | 362 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%d \n",len,idx->dwChunkLength); |
2438 | 363 if(len>0x200000 && idx->dwChunkLength>0x200000) continue; // both values bad :( |
364 len=choose_chunk_len(idx->dwChunkLength,len); | |
1 | 365 } |
9228 | 366 if(!(idx->dwFlags&AVIIF_KEYFRAME)) flags=0; |
1 | 367 } else return 0; |
6884
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
368 ret=demux_avi_read_packet(demux,demux_avi_select_stream(demux,id),id,len,idx_pos,flags); |
1 | 369 } while(ret!=1); |
370 return 1; | |
371 } | |
372 | |
373 | |
374 // return value: | |
375 // 0 = EOF or no stream found | |
376 // 1 = successfully read a packet | |
30570
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
377 static int demux_avi_fill_buffer_nini(demuxer_t *demux, demux_stream_t *ds) |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
378 { |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
379 avi_priv_t *priv=demux->priv; |
1 | 380 unsigned int id=0; |
381 unsigned int len; | |
382 int ret=0; | |
6056
f980563afdbc
big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents:
4665
diff
changeset
|
383 off_t *fpos=NULL; |
1 | 384 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
385 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
|
386 if(ds==demux->audio) fpos=&priv->idx_pos_a; else |
1 | 387 return 0; |
388 | |
389 stream_seek(demux->stream,fpos[0]); | |
390 | |
391 do{ | |
392 | |
393 demux->filepos=stream_tell(demux->stream); | |
2439
022a7e7fec2d
while_encoding.avi (ffmpeg) fix (ignoring movi_ check if end<=start)
arpi
parents:
2438
diff
changeset
|
394 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
|
395 ds->eof=1; |
1 | 396 return 0; |
397 } | |
398 | |
28189
dd53119e77c8
Make AVI demuxer more resilient against broken or incomplete files.
reimar
parents:
28051
diff
changeset
|
399 id=avi_find_id(demux->stream); |
1 | 400 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
|
401 |
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
402 if(stream_eof(demux->stream)) return 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
403 |
1 | 404 if(id==mmioFOURCC('L','I','S','T')){ |
405 id=stream_read_dword_le(demux->stream); // list type | |
406 continue; | |
407 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
408 |
6056
f980563afdbc
big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents:
4665
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 continue; |
f980563afdbc
big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents:
4665
diff
changeset
|
413 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
414 |
1 | 415 if(ds==demux_avi_select_stream(demux,id)){ |
416 // read it! | |
6884
37946a0a155a
detection of badly interleaved avi files and auto-switch to -ni
arpi
parents:
6871
diff
changeset
|
417 ret=demux_avi_read_packet(demux,ds,id,len,priv->idx_pos-1,0); |
1 | 418 } else { |
419 // skip it! | |
420 int skip=(len+1)&(~1); // total bytes in this chunk | |
421 stream_skip(demux->stream,skip); | |
422 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
423 |
1 | 424 } while(ret!=1); |
425 fpos[0]=stream_tell(demux->stream); | |
426 return 1; | |
427 } | |
428 | |
2314 | 429 // AVI demuxer parameters: |
25932 | 430 int index_mode=-1; // -1=untouched 0=don't use index 1=use (generate) index |
11234
9767665d49e0
Saving and loading external index file. Patch by Jason Tackaberry <tack@auc.ca>
alex
parents:
10709
diff
changeset
|
431 char *index_file_save = NULL, *index_file_load = NULL; |
2314 | 432 int force_ni=0; // force non-interleaved AVI parsing |
433 | |
16175 | 434 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
|
435 demux_stream_t *d_audio=demuxer->audio; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
436 demux_stream_t *d_video=demuxer->video; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
437 sh_audio_t *sh_audio=NULL; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
438 sh_video_t *sh_video=NULL; |
29872
76e81f47bce2
Use calloc instead of initializing each struct member individually to 0.
reimar
parents:
29871
diff
changeset
|
439 avi_priv_t* priv=calloc(1, sizeof(avi_priv_t)); |
12036 | 440 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
441 demuxer->priv=(void*)priv; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
442 |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
443 //---- AVI header: |
29920
4f740437ed2b
Finally rename the STREAM_SEEK define to MP_STREAM_SEEK, there are just too many
reimar
parents:
29872
diff
changeset
|
444 read_avi_header(demuxer,(demuxer->stream->flags & MP_STREAM_SEEK_BW)?index_mode:-2); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
445 |
7501 | 446 if(demuxer->audio->id>=0 && !demuxer->a_streams[demuxer->audio->id]){ |
20695 | 447 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_InvalidAudioStreamNosound,demuxer->audio->id); |
7501 | 448 demuxer->audio->id=-2; // disabled |
449 } | |
450 if(demuxer->video->id>=0 && !demuxer->v_streams[demuxer->video->id]){ | |
20695 | 451 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_InvalidAudioStreamUsingDefault,demuxer->video->id); |
7501 | 452 demuxer->video->id=-1; // autodetect |
453 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
454 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
455 stream_reset(demuxer->stream); |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
456 stream_seek(demuxer->stream,demuxer->movi_start); |
4665 | 457 if(priv->idx_size>1){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
458 // decide index format: |
4665 | 459 #if 1 |
12036 | 460 if((AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[0])<demuxer->movi_start || |
461 AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[1])<demuxer->movi_start )&& !priv->isodml) | |
4665 | 462 priv->idx_offset=demuxer->movi_start-4; |
463 #else | |
12036 | 464 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
|
465 priv->idx_offset=demuxer->movi_start-4; |
4665 | 466 #endif |
467 mp_msg(MSGT_DEMUX,MSGL_V,"AVI index offset: 0x%X (movi=0x%X idx0=0x%X idx1=0x%X)\n", | |
468 (int)priv->idx_offset,(int)demuxer->movi_start, | |
469 (int)((AVIINDEXENTRY *)priv->idx)[0].dwChunkOffset, | |
470 (int)((AVIINDEXENTRY *)priv->idx)[1].dwChunkOffset); | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
471 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
472 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
473 if(priv->idx_size>0){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
474 // check that file is non-interleaved: |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
475 int i; |
6056
f980563afdbc
big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents:
4665
diff
changeset
|
476 off_t a_pos=-1; |
f980563afdbc
big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents:
4665
diff
changeset
|
477 off_t v_pos=-1; |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
478 for(i=0;i<priv->idx_size;i++){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
479 AVIINDEXENTRY* idx=&((AVIINDEXENTRY *)priv->idx)[i]; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
480 demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid); |
12036 | 481 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
|
482 if(a_pos==-1 && ds==demuxer->audio){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
483 a_pos=pos; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
484 if(v_pos!=-1) break; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
485 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
486 if(v_pos==-1 && ds==demuxer->video){ |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
487 v_pos=pos; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
488 if(a_pos!=-1) break; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
489 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
490 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
491 if(v_pos==-1){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1737
diff
changeset
|
492 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
|
493 return NULL; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
494 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
495 if(a_pos==-1){ |
20337
fccb66884d60
Avoid crash after "AVI: No audio stream found -> no sound." message,
reimar
parents:
20246
diff
changeset
|
496 d_audio->sh=sh_audio=NULL; |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
497 } else { |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 demuxer->desc=&demuxer_desc_avi_ni; // HACK!!!! |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
502 pts_from_bps=1; // force BPS sync! |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
503 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
504 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
505 } else { |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
506 // no index |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
507 if(force_ni){ |
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_INFO,MSGTR_UsingNINI); |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
509 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
|
510 demuxer->desc=&demuxer_desc_avi_nini; // HACK!!!! |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
511 priv->idx_pos_a= |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
512 priv->idx_pos_v=demuxer->movi_start; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
513 pts_from_bps=1; // force BPS sync! |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
514 } |
1623
5908dd344067
added demuxer->seekable flag to generalize seeking ability test
arpi
parents:
1567
diff
changeset
|
515 demuxer->seekable=0; |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
516 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
517 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
|
518 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
|
519 return NULL; |
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 sh_video=d_video->sh;sh_video->ds=d_video; |
1496 | 522 if(d_audio->id!=-2){ |
1567 | 523 mp_msg(MSGT_DEMUX,MSGL_V,"AVI: Searching for audio stream (id:%d)\n",d_audio->id); |
2330 | 524 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
|
525 mp_msg(MSGT_DEMUX,MSGL_INFO,"AVI: " MSGTR_MissingAudioStream); |
20337
fccb66884d60
Avoid crash after "AVI: No audio stream found -> no sound." message,
reimar
parents:
20246
diff
changeset
|
526 d_audio->sh=sh_audio=NULL; |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
527 } else { |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
528 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
|
529 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
530 } |
8516
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 // calculating audio/video bitrate: |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
533 if(priv->idx_size>0){ |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
534 // we have index, let's count 'em! |
30538 | 535 AVIINDEXENTRY *idx = priv->idx; |
18393
09b64c87b29a
Fix calculation of stream sizes when they are too big for a 32-bit variable
pacman
parents:
17643
diff
changeset
|
536 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
|
537 int64_t asize=0; |
8516
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
538 size_t vsamples=0; |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
539 size_t asamples=0; |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
540 int i; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
541 for(i=0;i<priv->idx_size;i++){ |
30538 | 542 int id=avi_stream_id(idx[i].ckid); |
30542
4995c42045c9
Make len unsigned. More correct anyway and avoids sign extension to 64 bit
reimar
parents:
30538
diff
changeset
|
543 unsigned len=idx[i].dwChunkLength; |
8516
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
544 if(sh_video->ds->id == id) { |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
545 vsize+=len; |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
546 ++vsamples; |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
547 } |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
548 else if(sh_audio && sh_audio->ds->id == id) { |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
549 asize+=len; |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
550 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
|
551 } |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
552 } |
18393
09b64c87b29a
Fix calculation of stream sizes when they are too big for a 32-bit variable
pacman
parents:
17643
diff
changeset
|
553 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
|
554 priv->numberofframes=vsamples; |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
555 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
|
556 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
|
557 } else { |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
558 // 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
|
559 int64_t vsize; |
09b64c87b29a
Fix calculation of stream sizes when they are too big for a 32-bit variable
pacman
parents:
17643
diff
changeset
|
560 int64_t asize=0; |
8516
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
561 |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
562 if((priv->numberofframes=sh_video->video.dwLength)<=1) |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
563 // bad video header, try to get number of frames from audio |
8646 | 564 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
|
565 if(priv->numberofframes<=1){ |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
566 mp_msg(MSGT_SEEK,MSGL_WARN,MSGTR_CouldntDetFNo); |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
567 priv->numberofframes=0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
568 } |
8516
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 if(sh_audio){ |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
571 if(sh_audio->wf->nAvgBytesPerSec && sh_audio->audio.dwSampleSize!=1){ |
8646 | 572 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
|
573 } else { |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
574 asize=sh_audio->audio.dwLength; |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
575 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
|
576 } |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
577 } |
71e2ba5d6cdc
accurate bitrate calculation using index, and more accurate guessing
arpi
parents:
8254
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 } |
17643 | 582 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
583 return demuxer; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
584 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
585 } |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
586 |
1 | 587 |
30570
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
588 static void demux_seek_avi(demuxer_t *demuxer, float rel_seek_secs, |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
589 float audio_delay, int flags) |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
590 { |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
591 avi_priv_t *priv=demuxer->priv; |
1466 | 592 demux_stream_t *d_audio=demuxer->audio; |
593 demux_stream_t *d_video=demuxer->video; | |
594 sh_audio_t *sh_audio=d_audio->sh; | |
595 sh_video_t *sh_video=d_video->sh; | |
596 float skip_audio_secs=0; | |
597 | |
598 //FIXME: OFF_T - Didn't check AVI case yet (avi files can't be >2G anyway?) | |
599 //================= seek in AVI ========================== | |
600 int rel_seek_frames=rel_seek_secs*sh_video->fps; | |
601 int video_chunk_pos=d_video->pos; | |
602 int i; | |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1623
diff
changeset
|
603 |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
604 if(flags&SEEK_ABSOLUTE){ |
1628
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1623
diff
changeset
|
605 // seek absolute |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1623
diff
changeset
|
606 video_chunk_pos=0; |
bd1ef18cdf33
seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents:
1623
diff
changeset
|
607 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
608 |
25883
baf32110d3fc
Use defines to give names to the different seek flags.
reimar
parents:
25707
diff
changeset
|
609 if(flags&SEEK_FACTOR){ |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
610 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
|
611 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
612 |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
613 priv->skip_video_frames=0; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
614 priv->avi_audio_pts=0; |
1466 | 615 |
1481 | 616 // ------------ STEP 1: find nearest video keyframe chunk ------------ |
1466 | 617 // find nearest video keyframe chunk pos: |
618 if(rel_seek_frames>0){ | |
619 // seek forward | |
7002
518faaa2aee4
corrects an off-by-one error when trying to seek beyond the end of file.
arpi
parents:
6884
diff
changeset
|
620 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
|
621 int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid; |
1466 | 622 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
|
623 if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break; |
1466 | 624 } |
625 ++video_chunk_pos; | |
626 } | |
627 } else { | |
628 // seek backward | |
1498 | 629 while(video_chunk_pos>0){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
630 int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid; |
1466 | 631 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
|
632 if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break; |
1466 | 633 } |
634 --video_chunk_pos; | |
635 } | |
636 } | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
637 priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=video_chunk_pos; |
1466 | 638 |
639 // re-calc video pts: | |
640 d_video->pack_no=0; | |
641 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
|
642 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; |
1466 | 643 if(avi_stream_id(id)==d_video->id) ++d_video->pack_no; |
644 } | |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
645 priv->video_pack_no= |
1546 | 646 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
|
647 priv->avi_video_pts=d_video->pack_no*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate; |
1481 | 648 d_video->pos=video_chunk_pos; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
649 |
1567 | 650 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 | 651 |
652 // ------------ STEP 2: seek audio, find the right chunk & pos ------------ | |
653 | |
654 d_audio->pack_no=0; | |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
655 priv->audio_block_no=0; |
1481 | 656 d_audio->dpos=0; |
1466 | 657 |
658 if(sh_audio){ | |
659 int i; | |
660 int len=0; | |
661 int skip_audio_bytes=0; | |
1481 | 662 int curr_audio_pos=-1; |
663 int audio_chunk_pos=-1; | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
664 int chunk_max=(demuxer->type==DEMUXER_TYPE_AVI)?video_chunk_pos:priv->idx_size; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
665 |
1481 | 666 if(sh_audio->audio.dwSampleSize){ |
667 // constant rate audio stream | |
17636 | 668 /* immediate seeking to audio position, including when streams are delayed */ |
669 curr_audio_pos=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; | |
1481 | 670 curr_audio_pos*=sh_audio->audio.dwSampleSize; |
1466 | 671 |
672 // find audio chunk pos: | |
1481 | 673 for(i=0;i<chunk_max;i++){ |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
674 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; |
1466 | 675 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
|
676 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength; |
1481 | 677 if(d_audio->dpos<=curr_audio_pos && curr_audio_pos<(d_audio->dpos+len)){ |
1466 | 678 break; |
679 } | |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
680 ++d_audio->pack_no; |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
681 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
|
682 ((len+priv->audio_block_size-1)/priv->audio_block_size) : 1; |
1481 | 683 d_audio->dpos+=len; |
1466 | 684 } |
685 } | |
6640
2d3d4c628ece
hopefully fixed last A-V sync bug, and also fixed largefile bug in debug printf
arpi
parents:
6056
diff
changeset
|
686 audio_chunk_pos=i; |
1481 | 687 skip_audio_bytes=curr_audio_pos-d_audio->dpos; |
1466 | 688 |
6640
2d3d4c628ece
hopefully fixed last A-V sync bug, and also fixed largefile bug in debug printf
arpi
parents:
6056
diff
changeset
|
689 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
|
690 i,chunk_max,(int)d_audio->dpos,curr_audio_pos); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
691 |
1481 | 692 } else { |
693 // VBR audio | |
17636 | 694 /* immediate seeking to audio position, including when streams are delayed */ |
695 int chunks=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; | |
1481 | 696 audio_chunk_pos=0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
697 |
1481 | 698 // find audio chunk pos: |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
699 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
|
700 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; |
1481 | 701 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
|
702 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength; |
1481 | 703 if(i>chunk_max){ |
704 skip_audio_bytes+=len; | |
705 } else { | |
706 ++d_audio->pack_no; | |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
707 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
|
708 ((len+priv->audio_block_size-1)/priv->audio_block_size) : 1; |
1481 | 709 d_audio->dpos+=len; |
710 audio_chunk_pos=i; | |
711 } | |
8030
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
712 if(priv->audio_block_size) |
2b39ff3860b7
cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents:
7785
diff
changeset
|
713 chunks-=(len+priv->audio_block_size-1)/priv->audio_block_size; |
1481 | 714 } |
715 } | |
716 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
717 |
1481 | 718 // Now we have: |
719 // audio_chunk_pos = chunk no in index table (it's <=chunk_max) | |
720 // skip_audio_bytes = bytes to be skipped after chunk seek | |
721 // d-audio->pack_no = chunk_no in stream at audio_chunk_pos | |
722 // d_audio->dpos = bytepos in stream at audio_chunk_pos | |
723 // let's seek! | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
724 |
1466 | 725 // update stream position: |
726 d_audio->pos=audio_chunk_pos; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29238
diff
changeset
|
727 |
1481 | 728 if(demuxer->type==DEMUXER_TYPE_AVI){ |
729 // interleaved stream: | |
730 if(audio_chunk_pos<video_chunk_pos){ | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
731 // calc priv->skip_video_frames & adjust video pts counter: |
1481 | 732 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
|
733 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
734 if(avi_stream_id(id)==d_video->id) ++priv->skip_video_frames; |
1481 | 735 } |
736 // requires for correct audio pts calculation (demuxer): | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
737 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
|
738 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
|
739 // set index position: |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
740 priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=audio_chunk_pos; |
1481 | 741 } |
742 } else { | |
743 // non-interleaved stream: | |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
744 priv->idx_pos_a=audio_chunk_pos; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
745 priv->idx_pos_v=video_chunk_pos; |
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1481
diff
changeset
|
746 priv->idx_pos=(audio_chunk_pos<video_chunk_pos)?audio_chunk_pos:video_chunk_pos; |
1481 | 747 } |
1466 | 748 |
1567 | 749 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
|
750 (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
|
751 (int)priv->skip_video_frames,skip_audio_bytes,skip_audio_secs); |
1466 | 752 |
753 if(skip_audio_bytes){ | |
754 demux_read_data(d_audio,NULL,skip_audio_bytes); | |
755 } | |
756 | |
757 } | |
1508
6e752419c7e8
update pts to obtain OSD time display change while rewinding/forwarding
atlka
parents:
1498
diff
changeset
|
758 d_video->pts=priv->avi_video_pts; // OSD |
1466 | 759 |
760 } | |
761 | |
762 | |
30570
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
763 static void demux_close_avi(demuxer_t *demuxer) |
98dc6ae7ede2
libmpdemux: Mark functions not used outside of their files as static.
diego
parents:
30542
diff
changeset
|
764 { |
6816 | 765 avi_priv_t* priv=demuxer->priv; |
1466 | 766 |
6816 | 767 if(!priv) |
768 return; | |
769 | |
770 if(priv->idx_size > 0) | |
771 free(priv->idx); | |
772 free(priv); | |
773 } | |
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 |
16199
acb7885f916d
demux_avi_control() missing in avi's demuxer struct.
ods15
parents:
16175
diff
changeset
|
776 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
|
777 avi_priv_t *priv=demuxer->priv; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
778 demux_stream_t *d_video=demuxer->video; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
779 sh_video_t *sh_video=d_video->sh; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
780 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
781 switch(cmd) { |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
782 case DEMUXER_CTRL_GET_TIME_LENGTH: |
17342 | 783 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
|
784 *((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
|
785 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
|
786 return DEMUXER_CTRL_OK; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
787 |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
788 case DEMUXER_CTRL_GET_PERCENT_POS: |
17342 | 789 if (!priv->numberofframes || !sh_video) { |
14502
8769fa370f83
Move generic length and percent pos calculation to demuxer.c
reimar
parents:
12036
diff
changeset
|
790 return DEMUXER_CTRL_DONTKNOW; |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
791 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
792 *((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
|
793 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
|
794 return DEMUXER_CTRL_OK; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
795 |
21403 | 796 case DEMUXER_CTRL_SWITCH_AUDIO: |
797 case DEMUXER_CTRL_SWITCH_VIDEO: { | |
798 int audio = (cmd == DEMUXER_CTRL_SWITCH_AUDIO); | |
799 demux_stream_t *ds = audio ? demuxer->audio : demuxer->video; | |
800 void **streams = audio ? demuxer->a_streams : demuxer->v_streams; | |
21406 | 801 int maxid = FFMIN(100, audio ? MAX_A_STREAMS : MAX_V_STREAMS); |
21403 | 802 int chunkid; |
803 if (ds->id < -1) | |
30937
f87bfe2885f2
Make audio switching with AVI demuxer chose the first audio stream
reimar
parents:
30585
diff
changeset
|
804 ds->id = -1; |
21403 | 805 |
806 if (*(int *)arg >= 0) | |
807 ds->id = *(int *)arg; | |
808 else { | |
21405
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
809 int i; |
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
810 for (i = 0; i < maxid; i++) { |
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
811 if (++ds->id >= maxid) ds->id = 0; |
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
812 if (streams[ds->id]) break; |
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
813 } |
21403 | 814 } |
815 | |
816 chunkid = (ds->id / 10 + '0') | (ds->id % 10 + '0') << 8; | |
817 ds->sh = NULL; | |
21405
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
818 if (!streams[ds->id]) // stream not available |
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
819 ds->id = -1; |
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
820 else |
a120cda87e3e
Proper fix for last demux_avi commit, stream switching now really should
reimar
parents:
21404
diff
changeset
|
821 demux_avi_select_stream(demuxer, chunkid); |
21403 | 822 *(int *)arg = ds->id; |
823 return DEMUXER_CTRL_OK; | |
824 } | |
825 | |
8208
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
826 default: |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
827 return DEMUXER_CTRL_NOTIMPL; |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
828 } |
ae5a2ae1c349
demuxer_control(), percent position and time length query implemented in
arpi
parents:
8123
diff
changeset
|
829 } |
16175 | 830 |
831 | |
832 static int avi_check_file(demuxer_t *demuxer) | |
833 { | |
834 int id=stream_read_dword_le(demuxer->stream); // "RIFF" | |
835 | |
836 if((id==mmioFOURCC('R','I','F','F')) || (id==mmioFOURCC('O','N','2',' '))) { | |
837 stream_read_dword_le(demuxer->stream); //filesize | |
838 id=stream_read_dword_le(demuxer->stream); // "AVI " | |
839 if(id==formtypeAVI) | |
840 return DEMUXER_TYPE_AVI; | |
22148 | 841 // "Samsung Digimax i6 PMP" crap according to bug 742 |
842 if(id==mmioFOURCC('A','V','I',0x19)) | |
843 return DEMUXER_TYPE_AVI; | |
16175 | 844 if(id==mmioFOURCC('O','N','2','f')){ |
20695 | 845 mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_ON2AviFormat); |
16175 | 846 return DEMUXER_TYPE_AVI; |
847 } | |
848 } | |
849 | |
850 return 0; | |
851 } | |
852 | |
853 | |
854 static demuxer_t* demux_open_hack_avi(demuxer_t *demuxer) | |
855 { | |
856 sh_audio_t* sh_a; | |
857 | |
25200 | 858 demuxer = demux_open_avi(demuxer); |
16175 | 859 if(!demuxer) return NULL; // failed to open |
25200 | 860 sh_a = demuxer->audio->sh; |
16175 | 861 if(demuxer->audio->id != -2 && sh_a) { |
27363
40057010b1fa
Change a bunch of codec-specific preprocessor directives from a HAVE_
diego
parents:
25932
diff
changeset
|
862 #ifdef CONFIG_OGGVORBIS |
16175 | 863 // support for Ogg-in-AVI: |
864 if(sh_a->format == 0xFFFE) | |
865 demuxer = init_avi_with_ogg(demuxer); | |
866 else if(sh_a->format == 0x674F) { | |
867 stream_t* s; | |
868 demuxer_t *od; | |
869 s = new_ds_stream(demuxer->audio); | |
870 od = new_demuxer(s,DEMUXER_TYPE_OGG,-1,-2,-2,NULL); | |
871 if(!demux_ogg_open(od)) { | |
872 mp_msg( MSGT_DEMUXER,MSGL_ERR,MSGTR_ErrorOpeningOGGDemuxer); | |
873 free_stream(s); | |
874 demuxer->audio->id = -2; | |
875 } else | |
876 demuxer = new_demuxers_demuxer(demuxer,od,demuxer); | |
877 } | |
878 #endif | |
879 } | |
880 | |
881 return demuxer; | |
882 } | |
883 | |
884 | |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25200
diff
changeset
|
885 const demuxer_desc_t demuxer_desc_avi = { |
16175 | 886 "AVI demuxer", |
887 "avi", | |
888 "AVI", | |
889 "Arpi?", | |
890 "AVI files, including non interleaved files", | |
891 DEMUXER_TYPE_AVI, | |
892 1, // safe autodetect | |
893 avi_check_file, | |
894 demux_avi_fill_buffer, | |
895 demux_open_hack_avi, | |
896 demux_close_avi, | |
897 demux_seek_avi, | |
16199
acb7885f916d
demux_avi_control() missing in avi's demuxer struct.
ods15
parents:
16175
diff
changeset
|
898 demux_avi_control |
16175 | 899 }; |
16211
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
900 |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25200
diff
changeset
|
901 const demuxer_desc_t demuxer_desc_avi_ni = { |
16211
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
902 "AVI demuxer, non-interleaved", |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
903 "avini", |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
904 "AVI", |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
905 "Arpi?", |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
906 "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
|
907 DEMUXER_TYPE_AVI, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
908 1, // safe autodetect |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
909 avi_check_file, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
910 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
|
911 demux_open_hack_avi, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
912 demux_close_avi, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
913 demux_seek_avi, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
914 demux_avi_control |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
915 }; |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
916 |
25707
d4fe6e23283e
Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents:
25200
diff
changeset
|
917 const demuxer_desc_t demuxer_desc_avi_nini = { |
16211
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
918 "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
|
919 "avinini", |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
920 "AVI", |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
921 "Arpi?", |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
922 "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
|
923 DEMUXER_TYPE_AVI, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
924 1, // safe autodetect |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
925 avi_check_file, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
926 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
|
927 demux_open_hack_avi, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
928 demux_close_avi, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
929 demux_seek_avi, |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
930 demux_avi_control |
391b89e20a56
100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents:
16199
diff
changeset
|
931 }; |