Mercurial > mplayer.hg
annotate libmpdemux/demux_audio.c @ 8078:26a2ae540b04
bugfixes :
- It seems the CONF_TYPE_SUBCONFIG array for the "mode" option eats
all other -xvidencopts parameters. With it it wasn't possible to set
the bitrate or in fact any other parameter beside "mode".
- xvidencopts_conf wasn't properly initialised for some of the
lines. Probably didn't cause bugs but at least this shaves a few gcc
warnings.
- Rewrote initialisation code & defaults according to
xvidcore/docs/xvid-encoder.txt in XViD CVS tree. Some of the defaults
where bad. Done with the help of Markus Liebl < lieblm at web dot de >
modified features:
- Changed "debug" default to 0. Use the "debug" flag to enable it.
- Changed the interpretation of "br" to be consistent with lavc (now
in kbits/s if <16000, else bits/s). Should be backward compatible.
- Now use "-xvidopts pass=(1|2)" instead of "-xvidopts mode=2pass-(1|2)".
- Use the "-passtmpfile" global option instead of a hardwired name.
- Use the same motion presets as XViD's vfw CVS code (which is the
source of the windows codec I assume).
coding style etc...:
- Use static variables instead of a big struct for individual options,
easier to initialize.
- [f]printf() ->> mp_msg()
added features:
- Added "lumi_mask", "mpeg_quant", "hintedme" and "hintfile" options,
all off by default.
author | rguyom |
---|---|
date | Sun, 03 Nov 2002 12:43:30 +0000 |
parents | 324b6e5387be |
children | 884d233c25d5 |
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; | |
68 } else if( hdr[0] == 'f' && hdr[1] == 'm' && hdr[2] == 't' && hdr[3] == ' ' ) { | |
69 frmt = WAV; | |
70 break; | |
6763 | 71 } else if((n = mp_get_mp3_header(hdr,&mp3_chans,&mp3_freq)) > 0) { |
4694 | 72 frmt = MP3; |
73 break; | |
74 } | |
75 // Add here some other audio format detection | |
76 if(step < HDR_SIZE) | |
77 memmove(hdr,&hdr[step],HDR_SIZE-step); | |
78 pos -= step; | |
79 } | |
80 | |
81 if(!frmt) | |
82 return 0; | |
83 | |
84 sh_audio = new_sh_audio(demuxer,0); | |
85 | |
86 switch(frmt) { | |
87 case MP3: | |
88 sh_audio->format = 0x55; | |
4717
b7054dadd2c0
We should skip exactly the first frame on mp3 files.
albeu
parents:
4712
diff
changeset
|
89 demuxer->movi_start = st_pos-HDR_SIZE+n; |
6763 | 90 sh_audio->audio.dwSampleSize= 0; |
91 sh_audio->audio.dwScale = 1152; | |
92 sh_audio->audio.dwRate = mp3_freq; | |
93 sh_audio->wf = malloc(sizeof(WAVEFORMATEX)); | |
94 sh_audio->wf->wFormatTag = sh_audio->format; | |
95 sh_audio->wf->nChannels = mp3_chans; | |
96 sh_audio->wf->nSamplesPerSec = mp3_freq; | |
97 sh_audio->wf->nBlockAlign = 1; | |
98 sh_audio->wf->wBitsPerSample = 16; | |
99 sh_audio->wf->cbSize = 0; | |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
100 for(n = 0; n < 5 ; n++) { |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
101 pos = mp_decode_mp3_header(hdr); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
102 if(pos < 0) |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
103 return 0; |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
104 stream_skip(s,pos-4); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
105 if(s->eof) |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
106 return 0; |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
107 stream_read(s,hdr,4); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
108 if(s->eof) |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
109 return 0; |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
110 } |
4694 | 111 if(s->end_pos) { |
112 char tag[4]; | |
113 stream_seek(s,s->end_pos-128); | |
114 stream_read(s,tag,3); | |
115 tag[3] = '\0'; | |
116 if(strcmp(tag,"TAG")) | |
117 demuxer->movi_end = s->end_pos; | |
118 else { | |
119 char buf[31]; | |
120 uint8_t g; | |
121 demuxer->movi_end = stream_tell(s)-3; | |
122 stream_read(s,buf,30); | |
123 buf[30] = '\0'; | |
124 demux_info_add(demuxer,"Title",buf); | |
125 stream_read(s,buf,30); | |
126 buf[30] = '\0'; | |
127 demux_info_add(demuxer,"Artist",buf); | |
128 stream_read(s,buf,30); | |
129 buf[30] = '\0'; | |
130 demux_info_add(demuxer,"Album",buf); | |
131 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
|
132 buf[4] = '\0'; |
4694 | 133 demux_info_add(demuxer,"Year",buf); |
134 stream_read(s,buf,30); | |
135 buf[30] = '\0'; | |
136 demux_info_add(demuxer,"Comment",buf); | |
137 if(buf[28] == 0 && buf[29] != 0) { | |
138 uint8_t trk = (uint8_t)buf[29]; | |
139 sprintf(buf,"%d",trk); | |
140 demux_info_add(demuxer,"Track",buf); | |
141 } | |
142 g = stream_read_char(s); | |
143 demux_info_add(demuxer,"Genre",genres[g]); | |
144 } | |
145 } | |
146 break; | |
147 case WAV: { | |
4720
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
148 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
|
149 unsigned int chunk_size; |
4694 | 150 WAVEFORMATEX* w; |
151 int l; | |
152 sh_audio->wf = w = (WAVEFORMATEX*)malloc(sizeof(WAVEFORMATEX)); | |
153 l = stream_read_dword_le(s); | |
154 if(l < 16) { | |
155 printf("Bad wav header length : too short !!!\n"); | |
156 free_sh_audio(sh_audio); | |
157 return 0; | |
158 } | |
159 w->wFormatTag = sh_audio->format = stream_read_word_le(s); | |
160 w->nChannels = sh_audio->channels = stream_read_word_le(s); | |
161 w->nSamplesPerSec = sh_audio->samplerate = stream_read_dword_le(s); | |
162 w->nAvgBytesPerSec = stream_read_dword_le(s); | |
163 w->nBlockAlign = stream_read_word_le(s); | |
164 w->wBitsPerSample = sh_audio->samplesize = stream_read_word_le(s); | |
165 w->cbSize = 0; | |
166 l -= 16; | |
7847 | 167 if(verbose>0) print_wave_header(w); |
4694 | 168 if(l) |
169 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
|
170 do |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
171 { |
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
172 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
|
173 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
|
174 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
|
175 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
|
176 } while (chunk_type != mmioFOURCC('d', 'a', 't', 'a')); |
4694 | 177 demuxer->movi_start = stream_tell(s); |
178 demuxer->movi_end = s->end_pos; | |
7847 | 179 // printf("wav: %X .. %X\n",(int)demuxer->movi_start,(int)demuxer->movi_end); |
4694 | 180 } break; |
181 } | |
182 | |
183 priv = (da_priv_t*)malloc(sizeof(da_priv_t)); | |
184 priv->frmt = frmt; | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
185 priv->last_pts = -1; |
4694 | 186 demuxer->priv = priv; |
187 demuxer->audio->id = 0; | |
188 demuxer->audio->sh = sh_audio; | |
189 sh_audio->ds = demuxer->audio; | |
190 | |
191 if(stream_tell(s) != demuxer->movi_start) | |
192 stream_seek(s,demuxer->movi_start); | |
193 | |
4712 | 194 mp_msg(MSGT_DEMUX,MSGL_V,"demux_audio: audio data 0x%X - 0x%X \n",demuxer->movi_start,demuxer->movi_end); |
195 | |
4694 | 196 return 1; |
197 } | |
198 | |
199 | |
200 int demux_audio_fill_buffer(demux_stream_t *ds) { | |
201 sh_audio_t* sh_audio; | |
202 demuxer_t* demux; | |
203 da_priv_t* priv; | |
204 stream_t* s; | |
205 #ifdef MP_DEBUG | |
206 assert(ds != NULL); | |
207 assert(ds->sh != NULL); | |
208 assert(ds->demuxer != NULL); | |
209 #endif | |
210 sh_audio = ds->sh; | |
211 demux = ds->demuxer; | |
212 priv = demux->priv; | |
213 s = demux->stream; | |
214 | |
215 if(s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) | |
216 return 0; | |
217 | |
218 switch(priv->frmt) { | |
219 case MP3 : | |
220 while(! s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) { | |
221 uint8_t hdr[4]; | |
222 int len; | |
223 stream_read(s,hdr,4); | |
224 len = mp_decode_mp3_header(hdr); | |
225 if(len < 0) { | |
226 stream_skip(s,-3); | |
227 } else { | |
228 demux_packet_t* dp; | |
229 if(s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) | |
230 return 0; | |
231 dp = new_demux_packet(len); | |
232 memcpy(dp->buffer,hdr,4); | |
233 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
|
234 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
|
235 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4694 | 236 ds_add_packet(ds,dp); |
237 return 1; | |
238 } | |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
239 } break; |
4694 | 240 case WAV : { |
241 int l = sh_audio->wf->nAvgBytesPerSec; | |
242 demux_packet_t* dp = new_demux_packet(l); | |
243 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
|
244 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
|
245 ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4694 | 246 ds_add_packet(ds,dp); |
247 return 1; | |
248 } | |
249 default: | |
4720
10ad330c1733
fixed WAV demuxer so that it skips to the actual start of the audio data
melanson
parents:
4717
diff
changeset
|
250 printf("Audio demuxer : unknown format %d\n",priv->frmt); |
4694 | 251 } |
252 | |
253 | |
254 return 0; | |
255 } | |
256 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
257 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
|
258 uint8_t hdr[4]; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
259 int len,nf; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
260 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
|
261 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
|
262 |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
263 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
|
264 while(nf > 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
265 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
|
266 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
|
267 if(len < 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
268 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
|
269 continue; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
270 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
271 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
|
272 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
|
273 nf--; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
274 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
275 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
276 |
4694 | 277 void demux_audio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ |
278 sh_audio_t* sh_audio; | |
279 stream_t* s; | |
280 int base,pos; | |
281 float len; | |
282 da_priv_t* priv; | |
283 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
284 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
|
285 return; |
4694 | 286 s = demuxer->stream; |
287 priv = demuxer->priv; | |
288 | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
289 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
|
290 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
|
291 if(len < 0) { |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
292 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
|
293 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
|
294 priv->last_pts = 0; |
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 if(len > 0) |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
297 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
|
298 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
|
299 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
|
300 return; |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
301 } |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
302 |
5796 | 303 base = flags&1 ? demuxer->movi_start : stream_tell(s); |
304 if(flags&2) | |
305 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); | |
306 else | |
307 pos = base + (rel_seek_secs*sh_audio->i_bps); | |
4694 | 308 |
309 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
|
310 sh_audio->delay = (stream_tell(s) - demuxer->movi_start)/(float)sh_audio->i_bps; |
4694 | 311 return; |
312 } else if(pos < demuxer->movi_start) | |
313 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
|
314 |
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
315 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
|
316 sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; |
4694 | 317 |
318 switch(priv->frmt) { | |
319 case WAV: | |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
320 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
|
321 // 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
|
322 priv->last_pts -= sh_audio->wf->nAvgBytesPerSec/(float)sh_audio->i_bps; |
4694 | 323 break; |
324 } | |
325 | |
326 stream_seek(s,pos); | |
327 | |
4700
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
328 resync_audio_stream(sh_audio); |
30131db5dfbb
Improved mp3 detection (don't detect mpeg1/2 as mp3 anymore)
albeu
parents:
4694
diff
changeset
|
329 |
4694 | 330 } |
4764
9579496a91db
Added pts for mp3 and wav. And perfect seeking for mp3, unless flags & 2
albeu
parents:
4720
diff
changeset
|
331 |
5812 | 332 void demux_close_audio(demuxer_t* demuxer) { |
333 da_priv_t* priv = demuxer->priv; | |
334 | |
335 if(!priv) | |
336 return; | |
337 free(priv); | |
338 } | |
339 |