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