summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/loopcontrol.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index 93a6e3f..6dfd057 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -219,40 +219,40 @@ void LoopControl::startAudio() {
219 audioMutex->lock(); 219 audioMutex->lock();
220 220
221 if ( moreAudio ) { 221 if ( moreAudio ) {
222 222
223 if ( !isMuted && mediaPlayerState->curDecoder() ) { 223 if ( !isMuted && mediaPlayerState->curDecoder() ) {
224 224
225 currentSample = audioSampleCounter + 1; 225 currentSample = audioSampleCounter + 1;
226 226
227 if ( currentSample != audioSampleCounter + 1 ) 227 if ( currentSample != audioSampleCounter + 1 )
228 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 228 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
229 229
230 long samplesRead = 0; 230 long samplesRead = 0;
231 mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 231 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
232 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 232 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
233 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 233 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
234 234
235 if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 235 if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
236 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 236 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
237 } else if ( sampleWaitTime <= -5000 ) { 237 } else if ( sampleWaitTime <= -5000 ) {
238 qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 238 qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
239 //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 239 //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
240 currentSample = sampleWeShouldBeAt; 240 currentSample = sampleWeShouldBeAt;
241 } 241 }
242 242
243 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 243 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
244 audioSampleCounter = currentSample + samplesRead - 1; 244 audioSampleCounter = currentSample + samplesRead - 1;
245 245
246 moreAudio = audioSampleCounter <= total_audio_samples; 246 moreAudio = readOk && (audioSampleCounter <= total_audio_samples);
247 247
248 } else { 248 } else {
249 249
250 moreAudio = FALSE; 250 moreAudio = FALSE;
251 251
252 } 252 }
253 253
254 } 254 }
255 255
256 audioMutex->unlock(); 256 audioMutex->unlock();
257} 257}
258 258