annotate libmpdemux/demux_avi.c @ 26637:e3fd577a9573

cosmetics: alphabetical order
author diego
date Sun, 04 May 2008 18:28:24 +0000
parents f85dc2a992c3
children 40057010b1fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
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
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1421
diff changeset
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
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
7 #include "config.h"
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
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
22605
4d81dbdf46b9 Add explicit location for headers from the stream/ directory.
diego
parents: 22148
diff changeset
11 #include "stream/stream.h"
587
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
17 extern demuxer_t* init_avi_with_ogg(demuxer_t* demuxer);
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
18 extern int demux_ogg_open(demuxer_t* demuxer);
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
19
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 25200
diff changeset
20 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
21 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
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 int stream_id=avi_stream_id(id);
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
29
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
30
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
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
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
33 demux->video->id=stream_id;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
34
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
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
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
37 demux->audio->id=stream_id;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
38
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
39 if(stream_id==demux->audio->id){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
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
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
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
e64ff1e1593c workaround old mencoder's cbr-mp3 header bug
arpi
parents: 8030
diff changeset
53 } else {
e64ff1e1593c workaround old mencoder's cbr-mp3 header bug
arpi
parents: 8030
diff changeset
54 // workaround old mencoder's bug:
e64ff1e1593c workaround old mencoder's cbr-mp3 header bug
arpi
parents: 8030
diff changeset
55 if(sh->audio.dwSampleSize==1 && sh->audio.dwScale==1 &&
e64ff1e1593c workaround old mencoder's cbr-mp3 header bug
arpi
parents: 8030
diff changeset
56 (sh->wf->nBlockAlign==1152 || sh->wf->nBlockAlign==576)){
20700
45086015c50d Fix an obvious typo.
eugeni
parents: 20696
diff changeset
57 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_WorkAroundBlockAlignHeaderBug);
8059
e64ff1e1593c workaround old mencoder's cbr-mp3 header bug
arpi
parents: 8030
diff changeset
58 priv->audio_block_size=1;
e64ff1e1593c workaround old mencoder's cbr-mp3 header bug
arpi
parents: 8030
diff changeset
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
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
64 }
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
65 return demux->audio;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
66 }
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
67 if(stream_id==demux->video->id){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
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
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
70 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected AVI video ID = %d\n",demux->video->id);
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
71 }
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
72 return demux->video;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
73 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 if(id!=mmioFOURCC('J','U','N','K')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 // unknown
1998
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
82 static int valid_fourcc(unsigned int id){
20400
f4518826ea84 Allow lowercase letters in AVI stream id, fixes bug #277
reimar
parents: 20337
diff changeset
83 static const char valid[] = "0123456789abcdefghijklmnopqrstuvwxyz"
f4518826ea84 Allow lowercase letters in AVI stream id, fixes bug #277
reimar
parents: 20337
diff changeset
84 "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
85 unsigned char* fcc=(unsigned char*)(&id);
20400
f4518826ea84 Allow lowercase letters in AVI stream id, fixes bug #277
reimar
parents: 20337
diff changeset
86 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
87 strchr(valid, fcc[2]) && strchr(valid, fcc[3]);
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
88 }
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
89
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
90 static int choose_chunk_len(unsigned int len1,unsigned int len2){
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
91 // len1 has a bit more priority than len2. len1!=len2
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
92 // Note: this is a first-idea-logic, may be wrong. comments welcomed.
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
93
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
94 // prefer small frames rather than 0
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
95 if(!len1) return (len2>0x80000) ? len1 : len2;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
96 if(!len2) return (len1>0x100000) ? len2 : len1;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
97
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
98 // choose the smaller value:
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
99 return (len1<len2)? len1 : len2;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
100 }
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
101
6884
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
102 static int demux_avi_read_packet(demuxer_t *demux,demux_stream_t *ds,unsigned int id,unsigned int len,int idxpos,int flags){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
103 avi_priv_t *priv=demux->priv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 int skip;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 float pts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
107 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_avi.read_packet: %X\n",id);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 if(ds==demux->audio){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
110 if(priv->pts_corrected==0){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
111 if(priv->pts_has_video){
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
112 // we have video pts now
2826
17f46b2330e9 -nobps NaN fixed
arpi
parents: 2439
diff changeset
113 float delay=0;
17f46b2330e9 -nobps NaN fixed
arpi
parents: 2439
diff changeset
114 if(((sh_audio_t*)(ds->sh))->wf->nAvgBytesPerSec)
17f46b2330e9 -nobps NaN fixed
arpi
parents: 2439
diff changeset
115 delay=(float)priv->pts_corr_bytes/((sh_audio_t*)(ds->sh))->wf->nAvgBytesPerSec;
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
116 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
117 //priv->pts_correction=-priv->avi_audio_pts+delay;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
118 priv->pts_correction=delay-priv->avi_audio_pts;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
119 priv->avi_audio_pts+=priv->pts_correction;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
120 priv->pts_corrected=1;
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
121 } else
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
122 priv->pts_corr_bytes+=len;
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
123 }
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
124 if(pts_from_bps){
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
125 pts = priv->audio_block_no *
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
126 (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
127 (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
128 } else
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
129 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
130 priv->avi_audio_pts=0;
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
131 // update blockcount:
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
132 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
133 ((len+priv->audio_block_size-1)/priv->audio_block_size) : 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 } else
1409
65058a94df3b video pts calculation fixed (Desperado-trailer.avi)
arpi
parents: 1368
diff changeset
135 if(ds==demux->video){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 // video
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
137 if(priv->skip_video_frames>0){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 // drop frame (seeking)
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
139 --priv->skip_video_frames;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 ds=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 }
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
142
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
143 pts = priv->avi_video_pts = priv->video_pack_no *
1368
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
144 (float)((sh_video_t*)demux->video->sh)->video.dwScale /
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
145 (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
146
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
147 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
148 priv->pts_has_video=1;
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
149
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
150 if(ds) ++priv->video_pack_no;
1498
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
151
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 skip=(len+1)&(~1); // total bytes in this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 if(ds){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
157 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_AVI: Read %d data bytes from packet %04X\n",len,id);
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 600
diff changeset
158 ds_read_packet(ds,demux->stream,len,pts,idxpos,flags);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 skip-=len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 if(skip){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
162 mp_dbg(MSGT_DEMUX,MSGL_DBG2,"DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 stream_skip(demux->stream,skip);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 return ds?1:0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 // 1 = successfully read a packet
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
171 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
172 avi_priv_t *priv=demux->priv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 int ret=0;
6884
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
176 demux_stream_t *ds;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 do{
9228
5ef5179188ca - ignore movi_end if reading from stdin
arpi
parents: 8926
diff changeset
179 int flags=1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 AVIINDEXENTRY *idx=NULL;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
181 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
182 off_t pos;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
184 idx=&((AVIINDEXENTRY *)priv->idx)[priv->idx_pos++];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 if(idx->dwFlags&AVIIF_LIST){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 // LIST
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 if(!demux_avi_select_stream(demux,idx->ckid)){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
191 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 continue; // skip this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194
12036
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
195 pos = (off_t)priv->idx_offset+AVI_IDX_OFFSET(idx);
11965
3d75bcc28231 enable seeking in http streams
attila
parents: 11234
diff changeset
196 if((pos<demux->movi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start) && (demux->stream->flags & STREAM_SEEK)){
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17342
diff changeset
197 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkOffset out of range! idx=0x%"PRIX64" \n",(int64_t)pos);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 stream_seek(demux->stream,pos);
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
201 demux->filepos=stream_tell(demux->stream);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 id=stream_read_dword_le(demux->stream);
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
203 if(stream_eof(demux->stream)) return 0; // EOF!
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
204
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 if(id!=idx->ckid){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
206 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid);
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
207 if(valid_fourcc(idx->ckid))
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
208 id=idx->ckid; // use index if valid
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
209 else
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
210 if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17342
diff changeset
214 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%d \n",len,idx->dwChunkLength);
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
215 if(len>0x200000 && idx->dwChunkLength>0x200000) continue; // both values bad :(
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
216 len=choose_chunk_len(idx->dwChunkLength,len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 }
9228
5ef5179188ca - ignore movi_end if reading from stdin
arpi
parents: 8926
diff changeset
218 if(!(idx->dwFlags&AVIIF_KEYFRAME)) flags=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 } else {
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
220 demux->filepos=stream_tell(demux->stream);
11965
3d75bcc28231 enable seeking in http streams
attila
parents: 11234
diff changeset
221 if(demux->filepos>=demux->movi_end && demux->movi_end>demux->movi_start && (demux->stream->flags & STREAM_SEEK)){
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
222 demux->stream->eof=1;
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
223 return 0;
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
224 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 len=stream_read_dword_le(demux->stream);
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
227 if(stream_eof(demux->stream)) return 0; // EOF!
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
228
6056
f980563afdbc big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents: 4665
diff changeset
229 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
230 id=stream_read_dword_le(demux->stream); // list or RIFF type
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 }
6884
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
234
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
235 ds=demux_avi_select_stream(demux,id);
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
236 if(ds)
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
237 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
238 // 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
239 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
240 if(priv->idx_size>0){
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
241 // has index
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
242 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
243 demux->desc=&demuxer_desc_avi_ni;
6884
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
244 --priv->idx_pos; // hack
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
245 } else {
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
246 // no index
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
247 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
248 demux->desc=&demuxer_desc_avi_nini;
6884
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
249 priv->idx_pos=demux->filepos; // hack
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
250 }
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
251 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
252 // 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
253 return -1;
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
254 }
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
255
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
256 ret=demux_avi_read_packet(demux,ds,id,len,priv->idx_pos-1,flags);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 // 1 = successfully read a packet
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 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
266 avi_priv_t *priv=demux->priv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 do{
9228
5ef5179188ca - ignore movi_end if reading from stdin
arpi
parents: 8926
diff changeset
272 int flags=1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 AVIINDEXENTRY *idx=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 int idx_pos=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 demux->filepos=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
277 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
278 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
279 idx_pos=priv->idx_pos++;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
281 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
282 off_t pos;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
283 idx=&((AVIINDEXENTRY *)priv->idx)[idx_pos];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 if(idx->dwFlags&AVIIF_LIST){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 // LIST
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
290 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"Skip chunk %.4s (0x%X) \n",(char *)&idx->ckid,(unsigned int)idx->ckid);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 continue; // skip this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293
12036
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
294 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
295 if((pos<demux->movi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start)){
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17342
diff changeset
296 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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299 stream_seek(demux->stream,pos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 if(stream_eof(demux->stream)) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 if(id!=idx->ckid){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
306 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkID mismatch! raw=%.4s idx=%.4s \n",(char *)&id,(char *)&idx->ckid);
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
307 if(valid_fourcc(idx->ckid))
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
308 id=idx->ckid; // use index if valid
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
309 else
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
310 if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
17366
934380353fd6 massive attack: mp_msg printf format fixes
rathann
parents: 17342
diff changeset
314 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%d \n",len,idx->dwChunkLength);
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
315 if(len>0x200000 && idx->dwChunkLength>0x200000) continue; // both values bad :(
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
316 len=choose_chunk_len(idx->dwChunkLength,len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
317 }
9228
5ef5179188ca - ignore movi_end if reading from stdin
arpi
parents: 8926
diff changeset
318 if(!(idx->dwFlags&AVIIF_KEYFRAME)) flags=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 } else return 0;
6884
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
320 ret=demux_avi_read_packet(demux,demux_avi_select_stream(demux,id),id,len,idx_pos,flags);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 // 1 = successfully read a packet
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 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
330 avi_priv_t *priv=demux->priv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 int ret=0;
6056
f980563afdbc big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents: 4665
diff changeset
334 off_t *fpos=NULL;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
335
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
336 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
337 if(ds==demux->audio) fpos=&priv->idx_pos_a; else
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340 stream_seek(demux->stream,fpos[0]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
341
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
342 do{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344 demux->filepos=stream_tell(demux->stream);
2439
022a7e7fec2d while_encoding.avi (ffmpeg) fix (ignoring movi_ check if end<=start)
arpi
parents: 2438
diff changeset
345 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
346 ds->eof=1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 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
352
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
353 if(stream_eof(demux->stream)) return 0;
37946a0a155a detection of badly interleaved avi files and auto-switch to -ni
arpi
parents: 6871
diff changeset
354
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355 if(id==mmioFOURCC('L','I','S','T')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 id=stream_read_dword_le(demux->stream); // list type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359
6056
f980563afdbc big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents: 4665
diff changeset
360 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
361 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
362 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
363 continue;
f980563afdbc big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents: 4665
diff changeset
364 }
f980563afdbc big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents: 4665
diff changeset
365
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 if(ds==demux_avi_select_stream(demux,id)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 // read it!
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,ds,id,len,priv->idx_pos-1,0);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 // skip it!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 int skip=(len+1)&(~1); // total bytes in this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372 stream_skip(demux->stream,skip);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 fpos[0]=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379
2314
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
380 // AVI demuxer parameters:
25932
f85dc2a992c3 cosmetic typo fix, geneate > generate
compn
parents: 25883
diff changeset
381 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
382 char *index_file_save = NULL, *index_file_load = NULL;
2314
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
383 int force_ni=0; // force non-interleaved AVI parsing
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
384
2050
18f4dd5d568f -Wall warnings fixed
arpi
parents: 1998
diff changeset
385 void read_avi_header(demuxer_t *demuxer,int index_mode);
18f4dd5d568f -Wall warnings fixed
arpi
parents: 1998
diff changeset
386
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
387 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
388 demux_stream_t *d_audio=demuxer->audio;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
389 demux_stream_t *d_video=demuxer->video;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
390 sh_audio_t *sh_audio=NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
391 sh_video_t *sh_video=NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
392 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
393
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
394 // priv struct:
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
395 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
396 priv->pts_correction=0.0f;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
397 priv->skip_video_frames=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
398 priv->pts_corr_bytes=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
399 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
400 priv->video_pack_no=0;
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
401 priv->audio_block_no=0;
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
402 priv->audio_block_size=0;
12036
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
403 priv->isodml = 0;
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
404 priv->suidx_size = 0;
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
405 priv->suidx = NULL;
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
406
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
407 demuxer->priv=(void*)priv;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
408
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
409 //---- AVI header:
12018
2c2fb4457982 Seek in HTTP streams and stdin seek fixes
rtognimp
parents: 11965
diff changeset
410 read_avi_header(demuxer,(demuxer->stream->flags & STREAM_SEEK_BW)?index_mode:-2);
7501
20910550332f fixed invalid -aid/-vid segfault
arpi
parents: 7472
diff changeset
411
20910550332f fixed invalid -aid/-vid segfault
arpi
parents: 7472
diff changeset
412 if(demuxer->audio->id>=0 && !demuxer->a_streams[demuxer->audio->id]){
20695
c44d7b2316e6 MSGTRs for demux_avi.c
kraymer
parents: 20400
diff changeset
413 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_InvalidAudioStreamNosound,demuxer->audio->id);
7501
20910550332f fixed invalid -aid/-vid segfault
arpi
parents: 7472
diff changeset
414 demuxer->audio->id=-2; // disabled
20910550332f fixed invalid -aid/-vid segfault
arpi
parents: 7472
diff changeset
415 }
20910550332f fixed invalid -aid/-vid segfault
arpi
parents: 7472
diff changeset
416 if(demuxer->video->id>=0 && !demuxer->v_streams[demuxer->video->id]){
20695
c44d7b2316e6 MSGTRs for demux_avi.c
kraymer
parents: 20400
diff changeset
417 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_InvalidAudioStreamUsingDefault,demuxer->video->id);
7501
20910550332f fixed invalid -aid/-vid segfault
arpi
parents: 7472
diff changeset
418 demuxer->video->id=-1; // autodetect
20910550332f fixed invalid -aid/-vid segfault
arpi
parents: 7472
diff changeset
419 }
20910550332f fixed invalid -aid/-vid segfault
arpi
parents: 7472
diff changeset
420
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
421 stream_reset(demuxer->stream);
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
422 stream_seek(demuxer->stream,demuxer->movi_start);
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
423 priv->idx_pos=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
424 priv->idx_pos_a=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
425 priv->idx_pos_v=0;
4665
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
426 if(priv->idx_size>1){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
427 // decide index format:
4665
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
428 #if 1
12036
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
429 if((AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[0])<demuxer->movi_start ||
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
430 AVI_IDX_OFFSET(&((AVIINDEXENTRY *)priv->idx)[1])<demuxer->movi_start )&& !priv->isodml)
4665
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
431 priv->idx_offset=demuxer->movi_start-4;
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
432 else
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
433 priv->idx_offset=0;
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
434 #else
12036
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
435 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
436 priv->idx_offset=demuxer->movi_start-4;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
437 else
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
438 priv->idx_offset=0;
4665
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
439 #endif
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
440 mp_msg(MSGT_DEMUX,MSGL_V,"AVI index offset: 0x%X (movi=0x%X idx0=0x%X idx1=0x%X)\n",
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
441 (int)priv->idx_offset,(int)demuxer->movi_start,
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
442 (int)((AVIINDEXENTRY *)priv->idx)[0].dwChunkOffset,
80256840ff29 ehh. forgot to commit this one...
arpi
parents: 3302
diff changeset
443 (int)((AVIINDEXENTRY *)priv->idx)[1].dwChunkOffset);
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
444 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
445
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
446 if(priv->idx_size>0){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
447 // check that file is non-interleaved:
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
448 int i;
6056
f980563afdbc big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents: 4665
diff changeset
449 off_t a_pos=-1;
f980563afdbc big (>2GB) AVI files support - patch by Wolfram Gloger <wg@malloc.de>
arpi
parents: 4665
diff changeset
450 off_t v_pos=-1;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
451 for(i=0;i<priv->idx_size;i++){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
452 AVIINDEXENTRY* idx=&((AVIINDEXENTRY *)priv->idx)[i];
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
453 demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid);
12036
846ed866f86c OpenDML read/write support
ranma
parents: 12018
diff changeset
454 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
455 if(a_pos==-1 && ds==demuxer->audio){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
456 a_pos=pos;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
457 if(v_pos!=-1) break;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
458 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
459 if(v_pos==-1 && ds==demuxer->video){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
460 v_pos=pos;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
461 if(a_pos!=-1) break;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
462 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
463 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
464 if(v_pos==-1){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1737
diff changeset
465 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
466 return NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
467 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
468 if(a_pos==-1){
20337
fccb66884d60 Avoid crash after "AVI: No audio stream found -> no sound." message,
reimar
parents: 20246
diff changeset
469 d_audio->sh=sh_audio=NULL;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
470 } else {
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
471 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
472 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
473 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
474 demuxer->desc=&demuxer_desc_avi_ni; // HACK!!!!
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
475 pts_from_bps=1; // force BPS sync!
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
476 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
477 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
478 } else {
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
479 // no index
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
480 if(force_ni){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1737
diff changeset
481 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
482 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
483 demuxer->desc=&demuxer_desc_avi_nini; // HACK!!!!
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
484 priv->idx_pos_a=
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
485 priv->idx_pos_v=demuxer->movi_start;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
486 pts_from_bps=1; // force BPS sync!
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
487 }
1623
5908dd344067 added demuxer->seekable flag to generalize seeking ability test
arpi
parents: 1567
diff changeset
488 demuxer->seekable=0;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
489 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
490 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
491 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
492 return NULL;
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 sh_video=d_video->sh;sh_video->ds=d_video;
1496
8c3e93ef116d cleanup...
arpi
parents: 1485
diff changeset
495 if(d_audio->id!=-2){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
496 mp_msg(MSGT_DEMUX,MSGL_V,"AVI: Searching for audio stream (id:%d)\n",d_audio->id);
2330
8f0861360325 AVI - no audio stream fix
arpi
parents: 2314
diff changeset
497 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
498 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
499 d_audio->sh=sh_audio=NULL;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
500 } else {
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
501 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
502 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
503 }
8516
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
504
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
505 // calculating audio/video bitrate:
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
506 if(priv->idx_size>0){
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
507 // 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
508 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
509 int64_t asize=0;
8516
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
510 size_t vsamples=0;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
511 size_t asamples=0;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
512 int i;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
513 for(i=0;i<priv->idx_size;i++){
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
514 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
515 int len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
516 if(sh_video->ds->id == id) {
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
517 vsize+=len;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
518 ++vsamples;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
519 }
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
520 else if(sh_audio && sh_audio->ds->id == id) {
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
521 asize+=len;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
522 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
523 }
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
524 }
18393
09b64c87b29a Fix calculation of stream sizes when they are too big for a 32-bit variable
pacman
parents: 17643
diff changeset
525 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
526 priv->numberofframes=vsamples;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
527 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
528 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
529 } else {
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
530 // 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
531 int64_t vsize;
09b64c87b29a Fix calculation of stream sizes when they are too big for a 32-bit variable
pacman
parents: 17643
diff changeset
532 int64_t asize=0;
8516
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
533
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
534 if((priv->numberofframes=sh_video->video.dwLength)<=1)
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
535 // bad video header, try to get number of frames from audio
8646
b4c85f36e8fc fixed these:
arpi
parents: 8516
diff changeset
536 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
537 if(priv->numberofframes<=1){
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
538 mp_msg(MSGT_SEEK,MSGL_WARN,MSGTR_CouldntDetFNo);
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
539 priv->numberofframes=0;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
540 }
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(sh_audio){
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
543 if(sh_audio->wf->nAvgBytesPerSec && sh_audio->audio.dwSampleSize!=1){
8646
b4c85f36e8fc fixed these:
arpi
parents: 8516
diff changeset
544 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
545 } else {
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
546 asize=sh_audio->audio.dwLength;
71e2ba5d6cdc accurate bitrate calculation using index, and more accurate guessing
arpi
parents: 8254
diff changeset
547 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
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 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
551 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
552 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
553 }
17643
cea08919336b dwStart support for mplayer.
corey
parents: 17636
diff changeset
554
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
555 return demuxer;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
556
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
557 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
558
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
559
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
560 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
561 avi_priv_t *priv=demuxer->priv;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
562 demux_stream_t *d_audio=demuxer->audio;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
563 demux_stream_t *d_video=demuxer->video;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
564 sh_audio_t *sh_audio=d_audio->sh;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
565 sh_video_t *sh_video=d_video->sh;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
566 float skip_audio_secs=0;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
567
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
568 //FIXME: OFF_T - Didn't check AVI case yet (avi files can't be >2G anyway?)
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
569 //================= seek in AVI ==========================
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
570 int rel_seek_frames=rel_seek_secs*sh_video->fps;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
571 int video_chunk_pos=d_video->pos;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
572 int i;
1628
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
573
25883
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
574 if(flags&SEEK_ABSOLUTE){
1628
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
575 // seek absolute
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
576 video_chunk_pos=0;
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
577 }
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
578
25883
baf32110d3fc Use defines to give names to the different seek flags.
reimar
parents: 25707
diff changeset
579 if(flags&SEEK_FACTOR){
8208
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
580 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
581 }
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
582
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
583 priv->skip_video_frames=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
584 priv->avi_audio_pts=0;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
585
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
586 // ------------ STEP 1: find nearest video keyframe chunk ------------
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
587 // find nearest video keyframe chunk pos:
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
588 if(rel_seek_frames>0){
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
589 // seek forward
7002
518faaa2aee4 corrects an off-by-one error when trying to seek beyond the end of file.
arpi
parents: 6884
diff changeset
590 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
591 int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
592 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
593 if((--rel_seek_frames)<0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
594 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
595 ++video_chunk_pos;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
596 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
597 } else {
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
598 // seek backward
1498
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
599 while(video_chunk_pos>0){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
600 int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
601 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
602 if((++rel_seek_frames)>0 && ((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].dwFlags&AVIIF_KEYFRAME) break;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
603 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
604 --video_chunk_pos;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
605 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
606 }
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
607 priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=video_chunk_pos;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
608
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
609 // re-calc video pts:
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
610 d_video->pack_no=0;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
611 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
612 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
613 if(avi_stream_id(id)==d_video->id) ++d_video->pack_no;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
614 }
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
615 priv->video_pack_no=
1546
d4cd08b06665 display number of decoded frames (for progr. mpeg2)
arpi
parents: 1508
diff changeset
616 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
617 priv->avi_video_pts=d_video->pack_no*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
618 d_video->pos=video_chunk_pos;
1498
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
619
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
620 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
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
621
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
622 // ------------ STEP 2: seek audio, find the right chunk & pos ------------
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
623
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
624 d_audio->pack_no=0;
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
625 priv->audio_block_no=0;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
626 d_audio->dpos=0;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
627
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
628 if(sh_audio){
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
629 int i;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
630 int len=0;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
631 int skip_audio_bytes=0;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
632 int curr_audio_pos=-1;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
633 int audio_chunk_pos=-1;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
634 int chunk_max=(demuxer->type==DEMUXER_TYPE_AVI)?video_chunk_pos:priv->idx_size;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
635
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
636 if(sh_audio->audio.dwSampleSize){
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
637 // constant rate audio stream
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
638 /* immediate seeking to audio position, including when streams are delayed */
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
639 curr_audio_pos=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
640 curr_audio_pos*=sh_audio->audio.dwSampleSize;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
641
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
642 // find audio chunk pos:
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
643 for(i=0;i<chunk_max;i++){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
644 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
645 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
646 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
647 if(d_audio->dpos<=curr_audio_pos && curr_audio_pos<(d_audio->dpos+len)){
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
648 break;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
649 }
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
650 ++d_audio->pack_no;
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
651 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
652 ((len+priv->audio_block_size-1)/priv->audio_block_size) : 1;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
653 d_audio->dpos+=len;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
654 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
655 }
6640
2d3d4c628ece hopefully fixed last A-V sync bug, and also fixed largefile bug in debug printf
arpi
parents: 6056
diff changeset
656 audio_chunk_pos=i;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
657 skip_audio_bytes=curr_audio_pos-d_audio->dpos;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
658
6640
2d3d4c628ece hopefully fixed last A-V sync bug, and also fixed largefile bug in debug printf
arpi
parents: 6056
diff changeset
659 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
660 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
661
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
662 } else {
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
663 // VBR audio
17636
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
664 /* immediate seeking to audio position, including when streams are delayed */
b849a99cdc3c Second-try commit of this patch.
corey
parents: 17569
diff changeset
665 int chunks=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
666 audio_chunk_pos=0;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
667
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
668 // find audio chunk pos:
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
669 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
670 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
671 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
672 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
673 if(i>chunk_max){
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
674 skip_audio_bytes+=len;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
675 } else {
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
676 ++d_audio->pack_no;
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
677 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
678 ((len+priv->audio_block_size-1)/priv->audio_block_size) : 1;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
679 d_audio->dpos+=len;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
680 audio_chunk_pos=i;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
681 }
8030
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
682 if(priv->audio_block_size)
2b39ff3860b7 cleanup of .AVI timestamp calculation (ugly hack from mplayer.c removed,
arpi
parents: 7785
diff changeset
683 chunks-=(len+priv->audio_block_size-1)/priv->audio_block_size;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
684 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
685 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
686 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
687
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
688 // Now we have:
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
689 // audio_chunk_pos = chunk no in index table (it's <=chunk_max)
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
690 // skip_audio_bytes = bytes to be skipped after chunk seek
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
691 // d-audio->pack_no = chunk_no in stream at audio_chunk_pos
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
692 // d_audio->dpos = bytepos in stream at audio_chunk_pos
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
693 // let's seek!
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
694
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
695 // update stream position:
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
696 d_audio->pos=audio_chunk_pos;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
697
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
698 if(demuxer->type==DEMUXER_TYPE_AVI){
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
699 // interleaved stream:
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
700 if(audio_chunk_pos<video_chunk_pos){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
701 // calc priv->skip_video_frames & adjust video pts counter:
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
702 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
703 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
704 if(avi_stream_id(id)==d_video->id) ++priv->skip_video_frames;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
705 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
706 // requires for correct audio pts calculation (demuxer):
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
707 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
708 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
709 // set index position:
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
710 priv->idx_pos_a=priv->idx_pos_v=priv->idx_pos=audio_chunk_pos;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
711 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
712 } else {
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
713 // non-interleaved stream:
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
714 priv->idx_pos_a=audio_chunk_pos;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
715 priv->idx_pos_v=video_chunk_pos;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
716 priv->idx_pos=(audio_chunk_pos<video_chunk_pos)?audio_chunk_pos:video_chunk_pos;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
717 }
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
718
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
719 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
720 (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
721 (int)priv->skip_video_frames,skip_audio_bytes,skip_audio_secs);
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
722
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
723 if(skip_audio_bytes){
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
724 demux_read_data(d_audio,NULL,skip_audio_bytes);
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
725 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
726
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
727 }
1508
6e752419c7e8 update pts to obtain OSD time display change while rewinding/forwarding
atlka
parents: 1498
diff changeset
728 d_video->pts=priv->avi_video_pts; // OSD
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
729
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
730 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
731
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
732
6816
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
733 void demux_close_avi(demuxer_t *demuxer) {
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
734 avi_priv_t* priv=demuxer->priv;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
735
6816
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
736 if(!priv)
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
737 return;
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
738
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
739 if(priv->idx_size > 0)
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
740 free(priv->idx);
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
741 free(priv);
f01e5cefb828 Add uninit to the avi demuxer
albeu
parents: 6640
diff changeset
742 }
8208
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
743
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
744
16199
acb7885f916d demux_avi_control() missing in avi's demuxer struct.
ods15
parents: 16175
diff changeset
745 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
746 avi_priv_t *priv=demuxer->priv;
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
747 demux_stream_t *d_video=demuxer->video;
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
748 sh_video_t *sh_video=d_video->sh;
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
749
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
750 switch(cmd) {
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
751 case DEMUXER_CTRL_GET_TIME_LENGTH:
17342
adb64d908347 fix crash if no video codec available
reimar
parents: 16877
diff changeset
752 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
753 *((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
754 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
755 return DEMUXER_CTRL_OK;
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
756
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
757 case DEMUXER_CTRL_GET_PERCENT_POS:
17342
adb64d908347 fix crash if no video codec available
reimar
parents: 16877
diff changeset
758 if (!priv->numberofframes || !sh_video) {
14502
8769fa370f83 Move generic length and percent pos calculation to demuxer.c
reimar
parents: 12036
diff changeset
759 return DEMUXER_CTRL_DONTKNOW;
8208
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
760 }
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
761 *((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
762 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
763 return DEMUXER_CTRL_OK;
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
764
21403
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
765 case DEMUXER_CTRL_SWITCH_AUDIO:
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
766 case DEMUXER_CTRL_SWITCH_VIDEO: {
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
767 int audio = (cmd == DEMUXER_CTRL_SWITCH_AUDIO);
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
768 demux_stream_t *ds = audio ? demuxer->audio : demuxer->video;
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
769 void **streams = audio ? demuxer->a_streams : demuxer->v_streams;
21406
3acff79cdd9f 100l confused FFMIN/FFMAX
reimar
parents: 21405
diff changeset
770 int maxid = FFMIN(100, audio ? MAX_A_STREAMS : MAX_V_STREAMS);
21403
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
771 int chunkid;
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
772 if (ds->id < -1)
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
773 return DEMUXER_CTRL_NOTIMPL;
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
774
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
775 if (*(int *)arg >= 0)
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
776 ds->id = *(int *)arg;
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
777 else {
21405
a120cda87e3e Proper fix for last demux_avi commit, stream switching now really should
reimar
parents: 21404
diff changeset
778 int i;
a120cda87e3e Proper fix for last demux_avi commit, stream switching now really should
reimar
parents: 21404
diff changeset
779 for (i = 0; i < maxid; i++) {
a120cda87e3e Proper fix for last demux_avi commit, stream switching now really should
reimar
parents: 21404
diff changeset
780 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
781 if (streams[ds->id]) break;
a120cda87e3e Proper fix for last demux_avi commit, stream switching now really should
reimar
parents: 21404
diff changeset
782 }
21403
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
783 }
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
784
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
785 chunkid = (ds->id / 10 + '0') | (ds->id % 10 + '0') << 8;
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
786 ds->sh = NULL;
21405
a120cda87e3e Proper fix for last demux_avi commit, stream switching now really should
reimar
parents: 21404
diff changeset
787 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
788 ds->id = -1;
a120cda87e3e Proper fix for last demux_avi commit, stream switching now really should
reimar
parents: 21404
diff changeset
789 else
a120cda87e3e Proper fix for last demux_avi commit, stream switching now really should
reimar
parents: 21404
diff changeset
790 demux_avi_select_stream(demuxer, chunkid);
21403
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
791 *(int *)arg = ds->id;
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
792 return DEMUXER_CTRL_OK;
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
793 }
c91294804a0b Implement stream switching for AVI demuxer.
reimar
parents: 21387
diff changeset
794
8208
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
795 default:
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
796 return DEMUXER_CTRL_NOTIMPL;
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
797 }
ae5a2ae1c349 demuxer_control(), percent position and time length query implemented in
arpi
parents: 8123
diff changeset
798 }
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
799
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
800
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
801 static int avi_check_file(demuxer_t *demuxer)
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
802 {
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
803 int id=stream_read_dword_le(demuxer->stream); // "RIFF"
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
804
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
805 if((id==mmioFOURCC('R','I','F','F')) || (id==mmioFOURCC('O','N','2',' '))) {
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
806 stream_read_dword_le(demuxer->stream); //filesize
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
807 id=stream_read_dword_le(demuxer->stream); // "AVI "
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
808 if(id==formtypeAVI)
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
809 return DEMUXER_TYPE_AVI;
22148
19bfd17ba231 Support some weird AVI header, fixes bug 742
reimar
parents: 21406
diff changeset
810 // "Samsung Digimax i6 PMP" crap according to bug 742
19bfd17ba231 Support some weird AVI header, fixes bug 742
reimar
parents: 21406
diff changeset
811 if(id==mmioFOURCC('A','V','I',0x19))
19bfd17ba231 Support some weird AVI header, fixes bug 742
reimar
parents: 21406
diff changeset
812 return DEMUXER_TYPE_AVI;
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
813 if(id==mmioFOURCC('O','N','2','f')){
20695
c44d7b2316e6 MSGTRs for demux_avi.c
kraymer
parents: 20400
diff changeset
814 mp_msg(MSGT_DEMUXER,MSGL_INFO,MSGTR_ON2AviFormat);
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
815 return DEMUXER_TYPE_AVI;
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
816 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
817 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
818
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
819 return 0;
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
820 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
821
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
822
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
823 static demuxer_t* demux_open_hack_avi(demuxer_t *demuxer)
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
824 {
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
825 sh_audio_t* sh_a;
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
826
25200
3f59c69ec31c Remove some pointless casts
reimar
parents: 22605
diff changeset
827 demuxer = demux_open_avi(demuxer);
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
828 if(!demuxer) return NULL; // failed to open
25200
3f59c69ec31c Remove some pointless casts
reimar
parents: 22605
diff changeset
829 sh_a = demuxer->audio->sh;
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
830 if(demuxer->audio->id != -2 && sh_a) {
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
831 #ifdef HAVE_OGGVORBIS
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
832 // support for Ogg-in-AVI:
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
833 if(sh_a->format == 0xFFFE)
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
834 demuxer = init_avi_with_ogg(demuxer);
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
835 else if(sh_a->format == 0x674F) {
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
836 stream_t* s;
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
837 demuxer_t *od;
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
838 s = new_ds_stream(demuxer->audio);
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
839 od = new_demuxer(s,DEMUXER_TYPE_OGG,-1,-2,-2,NULL);
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
840 if(!demux_ogg_open(od)) {
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
841 mp_msg( MSGT_DEMUXER,MSGL_ERR,MSGTR_ErrorOpeningOGGDemuxer);
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
842 free_stream(s);
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
843 demuxer->audio->id = -2;
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
844 } else
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
845 demuxer = new_demuxers_demuxer(demuxer,od,demuxer);
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
846 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
847 #endif
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
848 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
849
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
850 return demuxer;
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
851 }
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
852
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
853
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 25200
diff changeset
854 const demuxer_desc_t demuxer_desc_avi = {
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
855 "AVI demuxer",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
856 "avi",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
857 "AVI",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
858 "Arpi?",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
859 "AVI files, including non interleaved files",
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
860 DEMUXER_TYPE_AVI,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
861 1, // safe autodetect
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
862 avi_check_file,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
863 demux_avi_fill_buffer,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
864 demux_open_hack_avi,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
865 demux_close_avi,
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
866 demux_seek_avi,
16199
acb7885f916d demux_avi_control() missing in avi's demuxer struct.
ods15
parents: 16175
diff changeset
867 demux_avi_control
16175
6b86089c2edd Demuxer modularization
rtognimp
parents: 14502
diff changeset
868 };
16211
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
869
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 25200
diff changeset
870 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
871 "AVI demuxer, non-interleaved",
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
872 "avini",
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
873 "AVI",
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
874 "Arpi?",
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
875 "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
876 DEMUXER_TYPE_AVI,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
877 1, // safe autodetect
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
878 avi_check_file,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
879 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
880 demux_open_hack_avi,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
881 demux_close_avi,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
882 demux_seek_avi,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
883 demux_avi_control
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
884 };
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
885
25707
d4fe6e23283e Make all demuxer_desc_t const, thus moving them to .rodata
reimar
parents: 25200
diff changeset
886 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
887 "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
888 "avinini",
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
889 "AVI",
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
890 "Arpi?",
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
891 "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
892 DEMUXER_TYPE_AVI,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
893 1, // safe autodetect
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
894 avi_check_file,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
895 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
896 demux_open_hack_avi,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
897 demux_close_avi,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
898 demux_seek_avi,
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
899 demux_avi_control
391b89e20a56 100l: fix avi demuxing for ni and nini cases, allow forcing ni and nini
rtognimp
parents: 16199
diff changeset
900 };