annotate libmpdemux/demux_avi.c @ 2612:60b9c03744d3

SSE update on FreeBSD
author eyck
date Thu, 01 Nov 2001 21:42:37 +0000
parents 022a7e7fec2d
children 17f46b2330e9
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
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
11 #include "stream.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
12 #include "demuxer.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
13 #include "stheader.h"
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
14
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
15 #include "aviheader.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 // Select ds from ID
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
18 demux_stream_t* demux_avi_select_stream(demuxer_t *demux,unsigned int id){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 int stream_id=avi_stream_id(id);
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
20
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
21 // printf("demux_avi_select_stream(%d) {a:%d/v:%d}\n",stream_id,
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
22 // demux->audio->id,demux->video->id);
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
23
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
24 if(demux->video->id==-1)
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
25 if(demux->v_streams[stream_id])
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
26 demux->video->id=stream_id;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
27
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
28 if(demux->audio->id==-1)
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
29 if(demux->a_streams[stream_id])
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
30 demux->audio->id=stream_id;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
31
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
32 if(stream_id==demux->audio->id){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
33 if(!demux->audio->sh){
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
34 demux->audio->sh=demux->a_streams[stream_id];
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
35 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected AVI audio ID = %d\n",demux->audio->id);
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
36 }
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
37 return demux->audio;
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->video->id){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
40 if(!demux->video->sh){
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
41 demux->video->sh=demux->v_streams[stream_id];
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
42 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
43 }
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
44 return demux->video;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
45 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 if(id!=mmioFOURCC('J','U','N','K')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 // unknown
1998
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
48 mp_msg(MSGT_DEMUX,MSGL_DBG2,"Unknown chunk: %.4s (%X)\n",(char *) &id,id);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
53 static int valid_fourcc(unsigned int id){
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
54 unsigned char* fcc=(unsigned char*)(&id);
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
55 #define FCC_CHR_CHECK(x) (x<48 || x>=96)
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
56 if(FCC_CHR_CHECK(fcc[0])) return 0;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
57 if(FCC_CHR_CHECK(fcc[1])) return 0;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
58 if(FCC_CHR_CHECK(fcc[2])) return 0;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
59 if(FCC_CHR_CHECK(fcc[3])) return 0;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
60 return 1;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
61 #undef FCC_CHR_CHECK
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
62 }
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
63
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
64 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
65 // 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
66 // 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
67
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
68 // prefer small frames rather than 0
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
69 if(!len1) return (len2>0x80000) ? len1 : len2;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
70 if(!len2) return (len1>0x100000) ? len2 : len1;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
71
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
72 // choose the smaller value:
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
73 return (len1<len2)? len1 : len2;
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
74 }
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
75
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 600
diff changeset
76 static int demux_avi_read_packet(demuxer_t *demux,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
77 avi_priv_t *priv=demux->priv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 int skip;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 float pts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 demux_stream_t *ds=demux_avi_select_stream(demux,id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
82 mp_dbg(MSGT_DEMUX,MSGL_DBG3,"demux_avi.read_packet: %X\n",id);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 if(ds==demux->audio){
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
85
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
86 if(priv->pts_corrected==0){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
87 // printf("\rYYY-A A: %5.3f V: %5.3f \n",priv->avi_audio_pts,priv->avi_video_pts);
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
88 if(priv->pts_has_video){
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
89 // we have video pts now
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
90 float 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
91 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
92 //priv->pts_correction=-priv->avi_audio_pts+delay;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
93 priv->pts_correction=delay-priv->avi_audio_pts;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
94 priv->avi_audio_pts+=priv->pts_correction;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
95 priv->pts_corrected=1;
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
96 } else
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
97 priv->pts_corr_bytes+=len;
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
98 }
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
99 pts=priv->avi_audio_pts; //+priv->pts_correction;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
100 priv->avi_audio_pts=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 } else
1409
65058a94df3b video pts calculation fixed (Desperado-trailer.avi)
arpi
parents: 1368
diff changeset
102 if(ds==demux->video){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 // video
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
104 if(priv->skip_video_frames>0){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 // drop frame (seeking)
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
106 --priv->skip_video_frames;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 ds=NULL;
1498
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
108 // } else {
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
109 // pts=priv->avi_video_pts;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 // ezt a 2 sort lehet hogy fell kell majd cserelni:
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
112 //priv->avi_video_pts+=avi_pts_frametime;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
113 //priv->avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
114 //priv->avi_video_pts+=((sh_video_t*)ds->sh)->frametime;
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
115 // FIXME!!!
1368
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
116 #if 1
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
117 // printf("ds=0x%X\n",ds);
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
118 // printf("packno=%d\n",ds->pack_no);
1409
65058a94df3b video pts calculation fixed (Desperado-trailer.avi)
arpi
parents: 1368
diff changeset
119 // printf("### pack_no=%d\n",demux->video->pack_no+demux->video->packs);
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
120 priv->avi_video_pts = (demux->video->pack_no+demux->video->packs) *
1368
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
121 (float)((sh_video_t*)demux->video->sh)->video.dwScale /
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
122 (float)((sh_video_t*)demux->video->sh)->video.dwRate;
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
123 #else
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
124 priv->avi_video_pts+=(float)((sh_video_t*)(demux->video->sh))->video.dwScale/(float)((sh_video_t*)(demux->video->sh))->video.dwRate;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
125 // priv->avi_video_pts+=avi_video_ftime;
1368
faee296c7c9a video pts calculation precision fixed
arpi
parents: 979
diff changeset
126 #endif
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
127 // printf("\rYYY-V A: %5.3f V: %5.3f \n",priv->avi_audio_pts,priv->avi_video_pts);
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
128 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
129 priv->pts_has_video=1;
1455
b2f3962d0e0e interleaved AVI: audio preload PTS compensation
arpi
parents: 1430
diff changeset
130
1498
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
131 pts=priv->avi_video_pts;
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
132
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
133 //printf("read pack_no: %d pts %5.3f \n",demux->video->pack_no+demux->video->packs,pts);
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
134
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 // len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 skip=(len+1)&(~1); // total bytes in this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 if(ds){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
141 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
142 ds_read_packet(ds,demux->stream,len,pts,idxpos,flags);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 skip-=len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 if(skip){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
146 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
147 stream_skip(demux->stream,skip);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 return ds?1:0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 // 1 = successfully read a packet
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 int demux_avi_fill_buffer(demuxer_t *demux){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
156 avi_priv_t *priv=demux->priv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 int max_packs=128;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 do{
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 600
diff changeset
163 int flags=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 AVIINDEXENTRY *idx=NULL;
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
165 #if 0
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 demux->filepos=stream_tell(demux->stream);
587
8511095c5283 stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents: 426
diff changeset
167 if(demux->filepos>=demux->movi_end){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 if(stream_eof(demux->stream)) return 0;
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
172 #endif
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
173 if(priv->idx_size>0 && priv->idx_pos<priv->idx_size){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 unsigned int pos;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
176 //if(priv->idx_pos<0) printf("Fatal! idx_pos=%d\n",priv->idx_pos);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
178 idx=&((AVIINDEXENTRY *)priv->idx)[priv->idx_pos++];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
180 //printf("[%d]",priv->idx_pos);fflush(stdout);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 //stream_seek(demux->stream,idx.dwChunkOffset);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 //printf("IDX pos=%X idx.pos=%X idx.size=%X idx.flags=%X\n",demux->filepos,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 // pos-4,idx->dwChunkLength,idx->dwFlags);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 if(idx->dwFlags&AVIIF_LIST){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 // LIST
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 if(!demux_avi_select_stream(demux,idx->ckid)){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
190 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
191 continue; // skip this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
194 pos=idx->dwChunkOffset+priv->idx_offset;
2439
022a7e7fec2d while_encoding.avi (ffmpeg) fix (ignoring movi_ check if end<=start)
arpi
parents: 2438
diff changeset
195 if((pos<demux->movi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start)){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
196 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkOffset out of range! idx=0x%X \n",pos);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 if(pos!=demux->filepos){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
201 mp_msg(MSGT_DEMUX,MSGL_V,"Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 stream_seek(demux->stream,pos);
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
205 demux->filepos=stream_tell(demux->stream);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 id=stream_read_dword_le(demux->stream);
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
207 if(stream_eof(demux->stream)) return 0; // EOF!
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
208
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 if(id!=idx->ckid){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
210 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
211 if(valid_fourcc(idx->ckid))
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
212 id=idx->ckid; // use index if valid
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
213 else
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
214 if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 // if((len&(~1))!=(idx->dwChunkLength&(~1))){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 // if((len)!=(idx->dwChunkLength)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
220 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%ld \n",len,idx->dwChunkLength);
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
221 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
222 len=choose_chunk_len(idx->dwChunkLength,len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 }
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 600
diff changeset
224 if(idx->dwFlags&AVIIF_KEYFRAME) flags=1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 } else {
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
226 demux->filepos=stream_tell(demux->stream);
2439
022a7e7fec2d while_encoding.avi (ffmpeg) fix (ignoring movi_ check if end<=start)
arpi
parents: 2438
diff changeset
227 if(demux->filepos>=demux->movi_end && demux->movi_end>demux->movi_start){
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
228 demux->stream->eof=1;
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
229 return 0;
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
230 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 len=stream_read_dword_le(demux->stream);
1421
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
233 if(stream_eof(demux->stream)) return 0; // EOF!
ea0a0b9e6fbc nosound avi seeking fixed
arpi
parents: 1409
diff changeset
234
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 if(id==mmioFOURCC('L','I','S','T')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 id=stream_read_dword_le(demux->stream); // list type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 }
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
240 ret=demux_avi_read_packet(demux,id,len,priv->idx_pos-1,flags);
1998
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
241 // if(!ret && priv->skip_video_frames<=0)
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
242 // if(--max_packs==0){
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
243 // demux->stream->eof=1;
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
244 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_DoesntContainSelectedStream);
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
245 // return 0;
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
246 // }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 // 1 = successfully read a packet
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 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
256 avi_priv_t *priv=demux->priv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 int max_packs=128;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 do{
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 600
diff changeset
263 int flags=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 AVIINDEXENTRY *idx=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265 int idx_pos=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 demux->filepos=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
268 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
269 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
270 idx_pos=priv->idx_pos++;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
272 if(priv->idx_size>0 && idx_pos<priv->idx_size){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 unsigned int pos;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
274 idx=&((AVIINDEXENTRY *)priv->idx)[idx_pos];
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
275 // idx=&priv->idx[idx_pos];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 if(idx->dwFlags&AVIIF_LIST){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 // LIST
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
282 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
283 continue; // skip this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
286 pos=idx->dwChunkOffset+priv->idx_offset;
2439
022a7e7fec2d while_encoding.avi (ffmpeg) fix (ignoring movi_ check if end<=start)
arpi
parents: 2438
diff changeset
287 if((pos<demux->movi_start || pos>=demux->movi_end) && (demux->movi_end>demux->movi_start)){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
288 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkOffset out of range! current=0x%X idx=0x%X \n",demux->filepos,pos);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 if(pos!=demux->filepos){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
293 mp_msg(MSGT_DEMUX,MSGL_V,"Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 stream_seek(demux->stream,pos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
298 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
299
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 if(stream_eof(demux->stream)) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302 if(id!=idx->ckid){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
303 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
304 if(valid_fourcc(idx->ckid))
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
305 id=idx->ckid; // use index if valid
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
306 else
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
307 if(!valid_fourcc(id)) continue; // drop chunk if both id and idx bad
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
308 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 // if((len&(~1))!=(idx->dwChunkLength&(~1))){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 // if((len)!=(idx->dwChunkLength)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
313 mp_msg(MSGT_DEMUX,MSGL_V,"ChunkSize mismatch! raw=%d idx=%ld \n",len,idx->dwChunkLength);
2438
561a7b13220a better logic to choose valid info at broken index
arpi
parents: 2338
diff changeset
314 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
315 len=choose_chunk_len(idx->dwChunkLength,len);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 }
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 600
diff changeset
317 if(idx->dwFlags&AVIIF_KEYFRAME) flags=1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 } else return 0;
979
3bcc435cd5a2 keyframe flag added
arpi_esp
parents: 600
diff changeset
319 ret=demux_avi_read_packet(demux,id,len,idx_pos,flags);
1998
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
320 // if(!ret && priv->skip_video_frames<=0)
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
321 // if(--max_packs==0){
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
322 // demux->stream->eof=1;
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
323 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_DoesntContainSelectedStream);
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
324 // return 0;
d3378988a98e disabled packet limit
arpi
parents: 1973
diff changeset
325 // }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
326 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
327 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 // 1 = successfully read a packet
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334 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
335 avi_priv_t *priv=demux->priv;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
339 int *fpos=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
341 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
342 if(ds==demux->audio) fpos=&priv->idx_pos_a; else
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
343 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
344
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
345 stream_seek(demux->stream,fpos[0]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347 do{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
348
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 demux->filepos=stream_tell(demux->stream);
2439
022a7e7fec2d while_encoding.avi (ffmpeg) fix (ignoring movi_ check if end<=start)
arpi
parents: 2438
diff changeset
350 if(demux->filepos>=demux->movi_end && (demux->movi_end>demux->movi_start)){
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 if(stream_eof(demux->stream)) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
355
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
358 if(id==mmioFOURCC('L','I','S','T')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
359 id=stream_read_dword_le(demux->stream); // list type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
360 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
361 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
363 if(ds==demux_avi_select_stream(demux,id)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 // read it!
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
365 ret=demux_avi_read_packet(demux,id,len,priv->idx_pos-1,0);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
366 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
367 // skip it!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
368 int skip=(len+1)&(~1); // total bytes in this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
369 stream_skip(demux->stream,skip);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
370 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
372 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
373 fpos[0]=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376
1496
8c3e93ef116d cleanup...
arpi
parents: 1485
diff changeset
377 //extern int audio_id;
8c3e93ef116d cleanup...
arpi
parents: 1485
diff changeset
378 //extern int video_id;
2314
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
379 //extern int index_mode; // -1=untouched 0=don't use index 1=use (geneate) index
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
380 //extern int force_ni;
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
381 //extern int pts_from_bps;
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
382
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
383 // AVI demuxer parameters:
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
384 int index_mode=-1; // -1=untouched 0=don't use index 1=use (geneate) index
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
385 int force_ni=0; // force non-interleaved AVI parsing
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
386
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
387 // PTS: 0=interleaved 1=BPS-based
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
388 #ifdef AVI_SYNC_BPS
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
389 int pts_from_bps=1;
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
390 #else
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
391 int pts_from_bps=0;
d0e1c32ad432 libdemux cleanup part 1
arpi
parents: 2310
diff changeset
392 #endif
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
393
2050
18f4dd5d568f -Wall warnings fixed
arpi
parents: 1998
diff changeset
394 void read_avi_header(demuxer_t *demuxer,int index_mode);
18f4dd5d568f -Wall warnings fixed
arpi
parents: 1998
diff changeset
395
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
396 demuxer_t* demux_open_avi(demuxer_t* demuxer){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
397 demux_stream_t *d_audio=demuxer->audio;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
398 demux_stream_t *d_video=demuxer->video;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
399 sh_audio_t *sh_audio=NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
400 sh_video_t *sh_video=NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
401 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
402
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
403 // priv struct:
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
404 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
405 priv->pts_correction=0.0f;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
406 priv->skip_video_frames=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
407 priv->pts_corr_bytes=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
408 priv->pts_has_video=priv->pts_corrected=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
409 demuxer->priv=(void*)priv;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
410
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
411 //---- AVI header:
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
412 read_avi_header(demuxer,(demuxer->stream->type!=STREAMTYPE_STREAM)?index_mode:-2);
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
413 stream_reset(demuxer->stream);
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
414 stream_seek(demuxer->stream,demuxer->movi_start);
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
415 priv->idx_pos=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
416 priv->idx_pos_a=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
417 priv->idx_pos_v=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
418 if(priv->idx_size>0){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
419 // decide index format:
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
420 if(((AVIINDEXENTRY *)priv->idx)[0].dwChunkOffset<demuxer->movi_start)
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
421 priv->idx_offset=demuxer->movi_start-4;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
422 else
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
423 priv->idx_offset=0;
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
424 mp_msg(MSGT_DEMUX,MSGL_V,"AVI index offset: %d\n",priv->idx_offset);
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
425 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
426 // demuxer->endpos=avi_header.movi_end;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
427
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
428 if(priv->idx_size>0){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
429 // check that file is non-interleaved:
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
430 int i;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
431 int a_pos=-1;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
432 int v_pos=-1;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
433 for(i=0;i<priv->idx_size;i++){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
434 AVIINDEXENTRY* idx=&((AVIINDEXENTRY *)priv->idx)[i];
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
435 demux_stream_t* ds=demux_avi_select_stream(demuxer,idx->ckid);
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
436 int pos=idx->dwChunkOffset+priv->idx_offset;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
437 if(a_pos==-1 && ds==demuxer->audio){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
438 a_pos=pos;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
439 if(v_pos!=-1) break;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
440 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
441 if(v_pos==-1 && ds==demuxer->video){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
442 v_pos=pos;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
443 if(a_pos!=-1) break;
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(v_pos==-1){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1737
diff changeset
447 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
448 return NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
449 // GUI_MSG( mplErrorAVINI )
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
450 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
451 if(a_pos==-1){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1737
diff changeset
452 mp_msg(MSGT_DEMUX,MSGL_INFO,"AVI_NI: " MSGTR_MissingAudioStream);
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
453 sh_audio=NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
454 } else {
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
455 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
456 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
457 demuxer->type=DEMUXER_TYPE_AVI_NI; // HACK!!!!
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
458 pts_from_bps=1; // force BPS sync!
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
459 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
460 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
461 } else {
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
462 // no index
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
463 if(force_ni){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1737
diff changeset
464 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
465 demuxer->type=DEMUXER_TYPE_AVI_NINI; // HACK!!!!
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
466 priv->idx_pos_a=
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
467 priv->idx_pos_v=demuxer->movi_start;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
468 pts_from_bps=1; // force BPS sync!
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
469 }
1623
5908dd344067 added demuxer->seekable flag to generalize seeking ability test
arpi
parents: 1567
diff changeset
470 demuxer->seekable=0;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
471 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
472 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
473 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
474 return NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
475 // GUI_MSG( mplAVIErrorMissingVideoStream )
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 sh_video=d_video->sh;sh_video->ds=d_video;
1496
8c3e93ef116d cleanup...
arpi
parents: 1485
diff changeset
478 if(d_audio->id!=-2){
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
479 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
480 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
481 mp_msg(MSGT_DEMUX,MSGL_INFO,"AVI: " MSGTR_MissingAudioStream);
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
482 sh_audio=NULL;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
483 } else {
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
484 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
485 sh_audio->format=sh_audio->wf->wFormatTag;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
486 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
487 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
488 // calc. FPS:
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
489 sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
490 sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
491 // calculating video bitrate:
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
492 sh_video->i_bps=demuxer->movi_end-demuxer->movi_start-priv->idx_size*8;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
493 if(sh_audio) sh_video->i_bps-=sh_audio->audio.dwLength;
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
494 mp_msg(MSGT_DEMUX,MSGL_V,"AVI video length=%d\n",sh_video->i_bps);
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
495 sh_video->i_bps=((float)sh_video->i_bps/(float)sh_video->video.dwLength)*sh_video->fps;
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
496 mp_msg(MSGT_DEMUX,MSGL_INFO,"VIDEO: [%.4s] %ldx%ld %dbpp %4.2f fps %5.1f kbps (%4.1f kbyte/s)\n",
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
497 (char *)&sh_video->bih->biCompression,
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
498 sh_video->bih->biWidth,
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
499 sh_video->bih->biHeight,
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
500 sh_video->bih->biBitCount,
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
501 sh_video->fps,
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
502 sh_video->i_bps*0.008f,
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
503 sh_video->i_bps/1024.0f );
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
504
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
505 return demuxer;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
506
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
507 }
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
508
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
509 //extern float initial_pts_delay;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
510
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
511 void demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,int flags){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
512 avi_priv_t *priv=demuxer->priv;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
513 demux_stream_t *d_audio=demuxer->audio;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
514 demux_stream_t *d_video=demuxer->video;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
515 sh_audio_t *sh_audio=d_audio->sh;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
516 sh_video_t *sh_video=d_video->sh;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
517 float skip_audio_secs=0;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
518
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
519 //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
520 //================= seek in AVI ==========================
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
521 int rel_seek_frames=rel_seek_secs*sh_video->fps;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
522 int video_chunk_pos=d_video->pos;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
523 int i;
1628
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
524
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
525 if(flags&1){
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
526 // seek absolute
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
527 video_chunk_pos=0;
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
528 }
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
529
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
530 if(flags&2){
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
531 // float 0..1
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
532 int total=sh_video->video.dwLength;
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
533 if(total<=1){
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
534 // bad video header, try to get it from audio
1737
00505a8fa2b4 sig11 for abs seek in bad avi file fixed
arpi
parents: 1631
diff changeset
535 if(sh_audio) total=sh_video->fps*sh_audio->audio.dwLength/sh_audio->wf->nAvgBytesPerSec;
00505a8fa2b4 sig11 for abs seek in bad avi file fixed
arpi
parents: 1631
diff changeset
536 if(total<=1){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1737
diff changeset
537 mp_msg(MSGT_SEEK,MSGL_WARN,MSGTR_CouldntDetFNo);
1628
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
538 total=0;
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
539 }
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
540 }
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
541 rel_seek_frames=rel_seek_secs*total;
bd1ef18cdf33 seeking flags implemented: 0x1=rel/abs and 0x2=time/percent
arpi
parents: 1623
diff changeset
542 }
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
543
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
544 priv->skip_video_frames=0;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
545 priv->avi_audio_pts=0;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
546
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
547 // ------------ STEP 1: find nearest video keyframe chunk ------------
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
548 // find nearest video keyframe chunk pos:
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
549 if(rel_seek_frames>0){
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
550 // seek forward
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
551 while(video_chunk_pos<priv->idx_size){
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
552 int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
553 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
554 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
555 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
556 ++video_chunk_pos;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
557 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
558 } else {
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
559 // seek backward
1498
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
560 while(video_chunk_pos>0){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
561 int id=((AVIINDEXENTRY *)priv->idx)[video_chunk_pos].ckid;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
562 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
563 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
564 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
565 --video_chunk_pos;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
566 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
567 }
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
568 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
569
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
570 // re-calc video pts:
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
571 d_video->pack_no=0;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
572 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
573 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
574 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
575 }
1546
d4cd08b06665 display number of decoded frames (for progr. mpeg2)
arpi
parents: 1508
diff changeset
576 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
577 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
578 d_video->pos=video_chunk_pos;
1498
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
579
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
580 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
581
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
582 // ------------ STEP 2: seek audio, find the right chunk & pos ------------
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
583
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
584 d_audio->pack_no=0;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
585 d_audio->dpos=0;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
586
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
587 if(sh_audio){
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
588 int i;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
589 // int apos=0;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
590 int last=0;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
591 int len=0;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
592 int skip_audio_bytes=0;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
593 int curr_audio_pos=-1;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
594 int audio_chunk_pos=-1;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
595 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
596
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
597 if(sh_audio->audio.dwSampleSize){
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
598 // constant rate audio stream
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
599 #if 0
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
600 int align;
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
601 curr_audio_pos=(priv->avi_video_pts) * sh_audio->wf->nAvgBytesPerSec;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
602 if(curr_audio_pos<0)curr_audio_pos=0;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
603 align=sh_audio->audio.dwSampleSize;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
604 if(sh_audio->wf->nBlockAlign>align) align=sh_audio->wf->nBlockAlign;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
605 curr_audio_pos/=align;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
606 curr_audio_pos*=align;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
607 #else
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
608 curr_audio_pos=(priv->avi_video_pts)*(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
609 curr_audio_pos*=sh_audio->audio.dwSampleSize;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
610 #endif
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
611
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
612 // find audio chunk pos:
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
613 for(i=0;i<chunk_max;i++){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
614 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
615 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
616 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
617 audio_chunk_pos=i; ++d_audio->pack_no;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
618 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
619 break;
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
620 }
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
621 d_audio->dpos+=len;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
622 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
623 }
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
624 skip_audio_bytes=curr_audio_pos-d_audio->dpos;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
625
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
626 } else {
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
627 // VBR audio
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
628 int chunks=(priv->avi_video_pts)*(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
629 audio_chunk_pos=0;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
630
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
631 // find audio chunk pos:
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
632 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
633 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
634 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
635 len=((AVIINDEXENTRY *)priv->idx)[i].dwChunkLength;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
636 if(i>chunk_max){
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
637 skip_audio_bytes+=len;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
638 } else {
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
639 ++d_audio->pack_no;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
640 d_audio->dpos+=len;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
641 audio_chunk_pos=i;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
642 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
643 --chunks;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
644 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
645 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
646 //if(audio_chunk_pos>chunk_max) audio_chunk_pos=chunk_max;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
647
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
648 // printf("VBR seek: %5.3f -> chunk_no %d -> chunk_idx %d + skip %d \n",
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
649 // priv->avi_video_pts, audio_chunk_pos, );
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
650
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
651 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
652
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
653 // Now we have:
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
654 // 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
655 // 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
656 // 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
657 // 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
658 // let's seek!
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
659
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
660 // update stream position:
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
661 d_audio->pos=audio_chunk_pos;
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
662 // d_audio->dpos=apos;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
663 // d_audio->pts=initial_pts_delay+(float)apos/(float)sh_audio->wf->nAvgBytesPerSec;
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
664
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
665 if(demuxer->type==DEMUXER_TYPE_AVI){
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
666 // interleaved stream:
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
667 if(audio_chunk_pos<video_chunk_pos){
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
668 // 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
669 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
670 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
671 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
672 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
673 // requires for correct audio pts calculation (demuxer):
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
674 priv->avi_video_pts-=priv->skip_video_frames*(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
675 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
676 }
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
677 } else {
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
678 // non-interleaved stream:
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
679 priv->idx_pos_a=audio_chunk_pos;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
680 priv->idx_pos_v=video_chunk_pos;
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
681 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
682 }
1498
6174b815b5f4 PTS calc updates, fixes, cleanups, mess...
arpi
parents: 1496
diff changeset
683
1508
6e752419c7e8 update pts to obtain OSD time display change while rewinding/forwarding
atlka
parents: 1498
diff changeset
684
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
685
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1546
diff changeset
686 mp_msg(MSGT_SEEK,MSGL_V,"SEEK: idx=%d (a:%d v:%d) v.skip=%d a.skip=%d/%4.3f \n",
1485
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
687 priv->idx_pos,audio_chunk_pos,video_chunk_pos,
b895f95e7657 AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents: 1481
diff changeset
688 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
689
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
690 if(skip_audio_bytes){
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
691 demux_read_data(d_audio,NULL,skip_audio_bytes);
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
692 //d_audio->pts=0; // PTS is outdated because of the raw data skipping
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
693 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
694 resync_audio_stream(sh_audio);
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
695
1481
db2a6ae7e296 AVI pts/seek fixes, VBR support, faster NI seek
arpi
parents: 1477
diff changeset
696 // sh_audio->timer=-skip_audio_secs;
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
697
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
698 }
1508
6e752419c7e8 update pts to obtain OSD time display change while rewinding/forwarding
atlka
parents: 1498
diff changeset
699 d_video->pts=priv->avi_video_pts; // OSD
1466
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
700
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
701 }
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
702
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
703
7845f6d7c4ba format-specific seeking code moved to demuxer_ stuff
arpi
parents: 1464
diff changeset
704