Mercurial > mplayer.hg
annotate libmpdemux/demux_audio.c @ 10368:6fb8a6a4a071
removing my (nonworking) email address
author | alex |
---|---|
date | Thu, 03 Jul 2003 20:22:51 +0000 |
parents | a084597140af |
children | e46e5a6c53b8 |
rev | line source |
---|---|
4694 | 1 |
2 #include "config.h" | |
4712 | 3 #include "../mp_msg.h" |
4694 | 4 |
5 #include <stdlib.h> | |
6 #include <stdio.h> | |
7 #include "stream.h" | |
8 #include "demuxer.h" | |
9 #include "stheader.h" | |
10 #include "genres.h" | |
6763 | 11 #include "mp3_hdr.h" |
4694 | 12 |
13 #include <string.h> | |
14 #ifdef MP_DEBUG | |
15 #include <assert.h> | |
16 #endif | |
17 | |
18 #define MP3 1 | |
19 #define WAV 2 | |
20 | |
21 | |
22 #define HDR_SIZE 4 | |
23 | |
24 typedef struct da_priv { | |
25 int frmt; | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
26 float last_pts; |
4694 | 27 } da_priv_t; |
28 | |
29 extern void free_sh_audio(sh_audio_t* sh); | |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
30 extern void resync_audio_stream(sh_audio_t *sh_audio); |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8116
diff
changeset
|
31 extern void print_wave_header(WAVEFORMATEX *h); |
4694 | 32 |
7867 | 33 int hr_mp3_seek = 0; |
4694 | 34 |
35 int demux_audio_open(demuxer_t* demuxer) { | |
36 stream_t *s; | |
37 sh_audio_t* sh_audio; | |
38 uint8_t hdr[HDR_SIZE]; | |
6763 | 39 int st_pos = 0,frmt = 0, n = 0, pos = 0, step, mp3_freq,mp3_chans; |
4694 | 40 da_priv_t* priv; |
41 #ifdef MP_DEBUG | |
42 assert(demuxer != NULL); | |
43 assert(demuxer->stream != NULL); | |
44 #endif | |
45 | |
46 s = demuxer->stream; | |
47 | |
48 while(n < 5 && ! s->eof) { | |
49 st_pos = stream_tell(s); | |
50 step = 1; | |
51 if(pos < HDR_SIZE) { | |
52 stream_read(s,&hdr[pos],HDR_SIZE-pos); | |
53 pos = HDR_SIZE; | |
54 } | |
55 | |
56 if( hdr[0] == 'R' && hdr[1] == 'I' && hdr[2] == 'F' && hdr[3] == 'F' ) { | |
57 stream_skip(s,4); | |
58 if(s->eof) | |
59 break; | |
60 stream_read(s,hdr,4); | |
61 if(s->eof) | |
62 break; | |
63 if(hdr[0] != 'W' || hdr[1] != 'A' || hdr[2] != 'V' || hdr[3] != 'E' ) | |
64 stream_skip(s,-8); | |
65 else | |
66 // We found wav header. Now we can have 'fmt ' or a mp3 header | |
67 // empty the buffer | |
68 step = 4; | |
8116 | 69 } else if( hdr[0] == 'I' && hdr[1] == 'D' && hdr[2] == '3' && (hdr[3] >= 2)) { |
70 int len; | |
71 stream_skip(s,2); | |
72 stream_read(s,hdr,4); | |
73 len = (hdr[0]<<21) | (hdr[1]<<14) | (hdr[2]<<7) | hdr[3]; | |
74 stream_skip(s,len); | |
75 step = 4; | |
4694 | 76 } else if( hdr[0] == 'f' && hdr[1] == 'm' && hdr[2] == 't' && hdr[3] == ' ' ) { |
77 frmt = WAV; | |
78 break; | |
6763 | 79 } else if((n = mp_get_mp3_header(hdr,&mp3_chans,&mp3_freq)) > 0) { |
4694 | 80 frmt = MP3; |
81 break; | |
82 } | |
83 // Add here some other audio format detection | |
84 if(step < HDR_SIZE) | |
85 memmove(hdr,&hdr[step],HDR_SIZE-step); | |
86 pos -= step; | |
87 } | |
88 | |
89 if(!frmt) | |
90 return 0; | |
91 | |
92 sh_audio = new_sh_audio(demuxer,0); | |
93 | |
94 switch(frmt) { | |
95 case MP3: | |
96 sh_audio->format = 0x55; | |
4717
b7054dadd2c0
We should skip exactly the first frame on mp3 files.
albeu
parents:
4712
diff
changeset
|
97 demuxer->movi_start = st_pos-HDR_SIZE+n; |
6763 | 98 sh_audio->audio.dwSampleSize= 0; |
99 sh_audio->audio.dwScale = 1152; | |
100 sh_audio->audio.dwRate = mp3_freq; | |
101 sh_audio->wf = malloc(sizeof(WAVEFORMATEX)); | |
102 sh_audio->wf->wFormatTag = sh_audio->format; | |
103 sh_audio->wf->nChannels = mp3_chans; | |
104 sh_audio->wf->nSamplesPerSec = mp3_freq; | |
8110 | 105 sh_audio->wf->nBlockAlign = 1152; |
6763 | 106 sh_audio->wf->wBitsPerSample = 16; |
107 sh_audio->wf->cbSize = 0; | |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
108 for(n = 0; n < 5 ; n++) { |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
109 pos = mp_decode_mp3_header(hdr); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
110 if(pos < 0) |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
111 return 0; |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
112 stream_skip(s,pos-4); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
113 if(s->eof) |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
114 return 0; |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
115 stream_read(s,hdr,4); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
116 if(s->eof) |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
117 return 0; |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
118 } |
4694 | 119 if(s->end_pos) { |
120 char tag[4]; | |
121 stream_seek(s,s->end_pos-128); | |
122 stream_read(s,tag,3); | |
123 tag[3] = '\0'; | |
124 if(strcmp(tag,"TAG")) | |
125 demuxer->movi_end = s->end_pos; | |
126 else { | |
127 char buf[31]; | |
128 uint8_t g; | |
129 demuxer->movi_end = stream_tell(s)-3; | |
130 stream_read(s,buf,30); | |
131 buf[30] = '\0'; | |
132 demux_info_add(demuxer,"Title",buf); | |
133 stream_read(s,buf,30); | |
134 buf[30] = '\0'; | |
135 demux_info_add(demuxer,"Artist",buf); | |
136 stream_read(s,buf,30); | |
137 buf[30] = '\0'; | |
138 demux_info_add(demuxer,"Album",buf); | |
139 stream_read(s,buf,4); | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
140 buf[4] = '\0'; |
4694 | 141 demux_info_add(demuxer,"Year",buf); |
142 stream_read(s,buf,30); | |
143 buf[30] = '\0'; | |
144 demux_info_add(demuxer,"Comment",buf); | |
145 if(buf[28] == 0 && buf[29] != 0) { | |
146 uint8_t trk = (uint8_t)buf[29]; | |
147 sprintf(buf,"%d",trk); | |
148 demux_info_add(demuxer,"Track",buf); | |
149 } | |
150 g = stream_read_char(s); | |
151 demux_info_add(demuxer,"Genre",genres[g]); | |
152 } | |
153 } | |
154 break; | |
155 case WAV: { | |
4720
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
156 unsigned int chunk_type; |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
157 unsigned int chunk_size; |
4694 | 158 WAVEFORMATEX* w; |
159 int l; | |
160 l = stream_read_dword_le(s); | |
9596 | 161 if(l < 16) { |
9591
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
162 mp_msg(MSGT_DEMUX,MSGL_ERR,"[demux_audio] Bad wav header length: too short (%d)!!!\n",l); |
4694 | 163 free_sh_audio(sh_audio); |
164 return 0; | |
165 } | |
9591
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
166 sh_audio->wf = w = (WAVEFORMATEX*)malloc(l); |
4694 | 167 w->wFormatTag = sh_audio->format = stream_read_word_le(s); |
168 w->nChannels = sh_audio->channels = stream_read_word_le(s); | |
169 w->nSamplesPerSec = sh_audio->samplerate = stream_read_dword_le(s); | |
170 w->nAvgBytesPerSec = stream_read_dword_le(s); | |
171 w->nBlockAlign = stream_read_word_le(s); | |
172 w->wBitsPerSample = sh_audio->samplesize = stream_read_word_le(s); | |
9616
a6bbab17a87f
10l cbSize not inited for l=16.\n Could give problem in print_wave_header
rtognimp
parents:
9596
diff
changeset
|
173 w->cbSize = 0; |
9596 | 174 l -= 16; |
175 if (l > 0) { | |
9591
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
176 w->cbSize = stream_read_word_le(s); |
9596 | 177 l -= 2; |
9655 | 178 if (w->cbSize > 0) { |
9591
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
179 if (l < w->cbSize) { |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
180 mp_msg(MSGT_DEMUX,MSGL_ERR,"[demux_audio] truncated extradata (%d < %d)\n", |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
181 l,w->cbSize); |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
182 stream_read(s,(char*)((char*)(w)+sizeof(WAVEFORMATEX)),l); |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
183 l = 0; |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
184 } else { |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
185 stream_read(s,(char*)((char*)(w)+sizeof(WAVEFORMATEX)),w->cbSize); |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
186 l -= w->cbSize; |
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
187 } |
9655 | 188 } |
9596 | 189 } |
9591
3904b95fce8f
Read extradata for wav files, based on patch by <dimakar(at)yahoo.com>. Required for truespeech files.
rtognimp
parents:
8359
diff
changeset
|
190 |
7847 | 191 if(verbose>0) print_wave_header(w); |
4694 | 192 if(l) |
193 stream_skip(s,l); | |
4720
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
194 do |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
195 { |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
196 chunk_type = stream_read_fourcc(demuxer->stream); |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
197 chunk_size = stream_read_dword_le(demuxer->stream); |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
198 if (chunk_type != mmioFOURCC('d', 'a', 't', 'a')) |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
199 stream_skip(demuxer->stream, chunk_size); |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
200 } while (chunk_type != mmioFOURCC('d', 'a', 't', 'a')); |
4694 | 201 demuxer->movi_start = stream_tell(s); |
202 demuxer->movi_end = s->end_pos; | |
7847 | 203 // printf("wav: %X .. %X\n",(int)demuxer->movi_start,(int)demuxer->movi_end); |
4694 | 204 } break; |
205 } | |
206 | |
207 priv = (da_priv_t*)malloc(sizeof(da_priv_t)); | |
208 priv->frmt = frmt; | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
209 priv->last_pts = -1; |
4694 | 210 demuxer->priv = priv; |
211 demuxer->audio->id = 0; | |
212 demuxer->audio->sh = sh_audio; | |
213 sh_audio->ds = demuxer->audio; | |
10244
a084597140af
don't set audio pts to infinity after seeking in mp3 files :)
rfelker
parents:
9655
diff
changeset
|
214 sh_audio->samplerate = sh_audio->audio.dwRate; |
4694 | 215 |
216 if(stream_tell(s) != demuxer->movi_start) | |
217 stream_seek(s,demuxer->movi_start); | |
218 | |
4712 | 219 mp_msg(MSGT_DEMUX,MSGL_V,"demux_audio: audio data 0x%X - 0x%X \n",demuxer->movi_start,demuxer->movi_end); |
220 | |
4694 | 221 return 1; |
222 } | |
223 | |
224 | |
225 int demux_audio_fill_buffer(demux_stream_t *ds) { | |
226 sh_audio_t* sh_audio; | |
227 demuxer_t* demux; | |
228 da_priv_t* priv; | |
229 stream_t* s; | |
230 #ifdef MP_DEBUG | |
231 assert(ds != NULL); | |
232 assert(ds->sh != NULL); | |
233 assert(ds->demuxer != NULL); | |
234 #endif | |
235 sh_audio = ds->sh; | |
236 demux = ds->demuxer; | |
237 priv = demux->priv; | |
238 s = demux->stream; | |
239 | |
240 if(s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) | |
241 return 0; | |
242 | |
243 switch(priv->frmt) { | |
244 case MP3 : | |
245 while(! s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) { | |
246 uint8_t hdr[4]; | |
247 int len; | |
248 stream_read(s,hdr,4); | |
249 len = mp_decode_mp3_header(hdr); | |
250 if(len < 0) { | |
251 stream_skip(s,-3); | |
252 } else { | |
253 demux_packet_t* dp; | |
254 if(s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) | |
255 return 0; | |
256 dp = new_demux_packet(len); | |
257 memcpy(dp->buffer,hdr,4); | |
258 stream_read(s,dp->buffer + 4,len-4); | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
259 priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + 1152/(float)sh_audio->samplerate; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
260 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4694 | 261 ds_add_packet(ds,dp); |
262 return 1; | |
263 } | |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
264 } break; |
4694 | 265 case WAV : { |
266 int l = sh_audio->wf->nAvgBytesPerSec; | |
267 demux_packet_t* dp = new_demux_packet(l); | |
268 stream_read(s,dp->buffer,l); | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
269 priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + l/(float)sh_audio->i_bps; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
270 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4694 | 271 ds_add_packet(ds,dp); |
272 return 1; | |
273 } | |
274 default: | |
4720
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
275 printf("Audio demuxer : unknown format %d\n",priv->frmt); |
4694 | 276 } |
277 | |
278 | |
279 return 0; | |
280 } | |
281 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
282 static void high_res_mp3_seek(demuxer_t *demuxer,float time) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
283 uint8_t hdr[4]; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
284 int len,nf; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
285 da_priv_t* priv = demuxer->priv; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
286 sh_audio_t* sh = (sh_audio_t*)demuxer->audio->sh; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
287 |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
288 nf = time*sh->samplerate/1152; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
289 while(nf > 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
290 stream_read(demuxer->stream,hdr,4); |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
291 len = mp_decode_mp3_header(hdr); |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
292 if(len < 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
293 stream_skip(demuxer->stream,-3); |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
294 continue; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
295 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
296 stream_skip(demuxer->stream,len-4); |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
297 priv->last_pts += 1152/(float)sh->samplerate; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
298 nf--; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
299 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
300 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
301 |
4694 | 302 void demux_audio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
303 sh_audio_t* sh_audio; | |
304 stream_t* s; | |
305 int base,pos; | |
306 float len; | |
307 da_priv_t* priv; | |
308 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
309 if(!(sh_audio = demuxer->audio->sh)) |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
310 return; |
4694 | 311 s = demuxer->stream; |
312 priv = demuxer->priv; | |
313 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
314 if(priv->frmt == MP3 && hr_mp3_seek && !(flags & 2)) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
315 len = (flags & 1) ? rel_seek_secs - priv->last_pts : rel_seek_secs; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
316 if(len < 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
317 stream_seek(s,demuxer->movi_start); |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
318 len = priv->last_pts + len; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
319 priv->last_pts = 0; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
320 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
321 if(len > 0) |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
322 high_res_mp3_seek(demuxer,len); |
8056
324b6e5387be
A-V sync cleanup: sh_audio->timer replaced by sh_audio->delay, it contains
arpi
parents:
7867
diff
changeset
|
323 sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
324 resync_audio_stream(sh_audio); |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
325 return; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
326 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
327 |
5796 | 328 base = flags&1 ? demuxer->movi_start : stream_tell(s); |
329 if(flags&2) | |
330 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); | |
331 else | |
332 pos = base + (rel_seek_secs*sh_audio->i_bps); | |
4694 | 333 |
334 if(demuxer->movi_end && pos >= demuxer->movi_end) { | |
8359 | 335 pos = demuxer->movi_end; |
336 //sh_audio->delay = (stream_tell(s) - demuxer->movi_start)/(float)sh_audio->i_bps; | |
337 //return; | |
4694 | 338 } else if(pos < demuxer->movi_start) |
339 pos = demuxer->movi_start; | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
340 |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
341 priv->last_pts = (pos-demuxer->movi_start)/(float)sh_audio->i_bps; |
8056
324b6e5387be
A-V sync cleanup: sh_audio->timer replaced by sh_audio->delay, it contains
arpi
parents:
7867
diff
changeset
|
342 sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4694 | 343 |
344 switch(priv->frmt) { | |
345 case WAV: | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
346 pos -= (pos % (sh_audio->channels * sh_audio->samplesize) ); |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
347 // We need to decrease the pts by one step to make it the "last one" |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
348 priv->last_pts -= sh_audio->wf->nAvgBytesPerSec/(float)sh_audio->i_bps; |
4694 | 349 break; |
350 } | |
351 | |
352 stream_seek(s,pos); | |
353 | |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
354 resync_audio_stream(sh_audio); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
355 |
4694 | 356 } |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
357 |
5812 | 358 void demux_close_audio(demuxer_t* demuxer) { |
359 da_priv_t* priv = demuxer->priv; | |
360 | |
361 if(!priv) | |
362 return; | |
363 free(priv); | |
364 } | |
365 |