summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-04-21 16:13:30 (UTC)
committer llornkcor <llornkcor>2002-04-21 16:13:30 (UTC)
commit392eb0350465565e2a849ada60e6734be025787b (patch) (unidiff)
tree44727c201e6ef8e4d61d6011180d41b46c8f4ea4
parentd7ff40e1530a1aab578a3d3c3126c4367cf3e898 (diff)
downloadopie-392eb0350465565e2a849ada60e6734be025787b.zip
opie-392eb0350465565e2a849ada60e6734be025787b.tar.gz
opie-392eb0350465565e2a849ada60e6734be025787b.tar.bz2
fix unfixed stream stop
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/audiodevice.cpp1
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp2
2 files changed, 2 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/audiodevice.cpp b/core/multimedia/opieplayer/audiodevice.cpp
index 2087c7f..ad44abb 100644
--- a/core/multimedia/opieplayer/audiodevice.cpp
+++ b/core/multimedia/opieplayer/audiodevice.cpp
@@ -219,64 +219,65 @@ AudioDevice::AudioDevice( unsigned int f, unsigned int chs, unsigned int bps ) {
219 219
220 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1) 220 if(ioctl( d->handle, SNDCTL_DSP_GETCAPS, &capabilities )==-1)
221 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")"); 221 perror("ioctl(\"SNDCTL_DSP_GETCAPS\")");
222 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1) 222 if(ioctl( d->handle, SNDCTL_DSP_SETFRAGMENT, &fragments )==-1)
223 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")"); 223 perror("ioctl(\"SNDCTL_DSP_SETFRAGMENT\")");
224 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1) 224 if(ioctl( d->handle, SNDCTL_DSP_SETFMT, & format )==-1)
225 perror("ioctl(\"SNDCTL_DSP_SETFMT\")"); 225 perror("ioctl(\"SNDCTL_DSP_SETFMT\")");
226 qDebug("freq %d", d->frequency); 226 qDebug("freq %d", d->frequency);
227 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1) 227 if(ioctl( d->handle, SNDCTL_DSP_SPEED, &d->frequency )==-1)
228 perror("ioctl(\"SNDCTL_DSP_SPEED\")"); 228 perror("ioctl(\"SNDCTL_DSP_SPEED\")");
229 qDebug("channels %d",d->channels); 229 qDebug("channels %d",d->channels);
230 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) { 230 if ( ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels ) == -1 ) {
231 d->channels = ( d->channels == 1 ) ? 2 : d->channels; 231 d->channels = ( d->channels == 1 ) ? 2 : d->channels;
232 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1) 232 if(ioctl( d->handle, SNDCTL_DSP_CHANNELS, &d->channels )==-1)
233 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")"); 233 perror("ioctl(\"SNDCTL_DSP_CHANNELS\")");
234 } 234 }
235 235
236 d->bufferSize = sound_fragment_bytes; 236 d->bufferSize = sound_fragment_bytes;
237 d->unwrittenBuffer = new char[d->bufferSize]; 237 d->unwrittenBuffer = new char[d->bufferSize];
238 d->unwritten = 0; 238 d->unwritten = 0;
239 d->can_GETOSPACE = TRUE; // until we find otherwise 239 d->can_GETOSPACE = TRUE; // until we find otherwise
240 240
241 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels ); 241 //if ( chs != d->channels ) qDebug( "Wanted %d, got %d channels", chs, d->channels );
242 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency ); 242 //if ( f != d->frequency ) qDebug( "wanted %dHz, got %dHz", f, d->frequency );
243 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" ); 243 //if ( capabilities & DSP_CAP_BATCH ) qDebug( "Sound card has local buffer" );
244 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" ); 244 //if ( capabilities & DSP_CAP_REALTIME )qDebug( "Sound card has realtime sync" );
245 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" ); 245 //if ( capabilities & DSP_CAP_TRIGGER ) qDebug( "Sound card has precise trigger" );
246 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" ); 246 //if ( capabilities & DSP_CAP_MMAP ) qDebug( "Sound card can mmap" );
247} 247}
248 248
249 249
250AudioDevice::~AudioDevice() { 250AudioDevice::~AudioDevice() {
251 qDebug("destryo audiodevice");
251#ifdef Q_OS_WIN32 252#ifdef Q_OS_WIN32
252 waveOutClose( (HWAVEOUT)d->handle ); 253 waveOutClose( (HWAVEOUT)d->handle );
253#else 254#else
254# ifndef KEEP_DEVICE_OPEN 255# ifndef KEEP_DEVICE_OPEN
255 close( d->handle ); // Now it should be safe to shut the handle 256 close( d->handle ); // Now it should be safe to shut the handle
256# endif 257# endif
257 delete d->unwrittenBuffer; 258 delete d->unwrittenBuffer;
258 delete d; 259 delete d;
259#endif 260#endif
260} 261}
261 262
262 263
263void AudioDevice::volumeChanged( bool muted ) 264void AudioDevice::volumeChanged( bool muted )
264{ 265{
265 AudioDevicePrivate::muted = muted; 266 AudioDevicePrivate::muted = muted;
266} 267}
267 268
268 269
269void AudioDevice::write( char *buffer, unsigned int length ) 270void AudioDevice::write( char *buffer, unsigned int length )
270{ 271{
271#ifdef Q_OS_WIN32 272#ifdef Q_OS_WIN32
272 // returns immediately and (to be implemented) emits completedIO() when finished writing 273 // returns immediately and (to be implemented) emits completedIO() when finished writing
273 WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) ); 274 WAVEHDR *lpWaveHdr = (WAVEHDR *)malloc( sizeof(WAVEHDR) );
274 // maybe the buffer should be copied so that this fool proof, but its a performance hit 275 // maybe the buffer should be copied so that this fool proof, but its a performance hit
275 lpWaveHdr->lpData = buffer; 276 lpWaveHdr->lpData = buffer;
276 lpWaveHdr->dwBufferLength = length; 277 lpWaveHdr->dwBufferLength = length;
277 lpWaveHdr->dwFlags = 0L; 278 lpWaveHdr->dwFlags = 0L;
278 lpWaveHdr->dwLoops = 0L; 279 lpWaveHdr->dwLoops = 0L;
279 waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ); 280 waveOutPrepareHeader( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) );
280 // waveOutWrite returns immediately. the data is sent in the background. 281 // waveOutWrite returns immediately. the data is sent in the background.
281 if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) ) 282 if ( waveOutWrite( (HWAVEOUT)d->handle, lpWaveHdr, sizeof(WAVEHDR) ) )
282 qDebug( "failed to write block to audio device" ); 283 qDebug( "failed to write block to audio device" );
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index 01596a0..7005886 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -219,65 +219,65 @@ void LoopControl::startVideo() {
219 219
220 220
221void LoopControl::startAudio() { 221void LoopControl::startAudio() {
222 222
223//qDebug("start audio"); 223//qDebug("start audio");
224 audioMutex->lock(); 224 audioMutex->lock();
225 if ( moreAudio ) { 225 if ( moreAudio ) {
226 226
227 if ( !isMuted && mediaPlayerState->curDecoder() ) { 227 if ( !isMuted && mediaPlayerState->curDecoder() ) {
228 228
229 currentSample = audioSampleCounter + 1; 229 currentSample = audioSampleCounter + 1;
230 230
231 if ( currentSample != audioSampleCounter + 1 ) 231 if ( currentSample != audioSampleCounter + 1 )
232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
233 233
234 long samplesRead = 0; 234 long samplesRead = 0;
235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
237 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 237 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
238 238
239// this causes drop outs not sure why its even here 239// this causes drop outs not sure why its even here
240// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 240// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
241// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 241// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
242// } 242// }
243// else if ( sampleWaitTime <= -5000 ) { 243// else if ( sampleWaitTime <= -5000 ) {
244// qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 244// qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
245// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 245// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
246// currentSample = sampleWeShouldBeAt; 246// currentSample = sampleWeShouldBeAt;
247// } 247// }
248 248
249 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 249 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
250 250
251// if( mediaPlayerState->isStreaming == FALSE) 251 if( mediaPlayerState->isStreaming == FALSE)
252 audioSampleCounter = currentSample + samplesRead - 1; 252 audioSampleCounter = currentSample + samplesRead - 1;
253 253
254 moreAudio = readOk && (audioSampleCounter <= total_audio_samples); 254 moreAudio = readOk && (audioSampleCounter <= total_audio_samples);
255 255
256 } else { 256 } else {
257 257
258 moreAudio = FALSE; 258 moreAudio = FALSE;
259 259
260 } 260 }
261 261
262 } 262 }
263 263
264 audioMutex->unlock(); 264 audioMutex->unlock();
265} 265}
266 266
267 267
268void LoopControl::killTimers() { 268void LoopControl::killTimers() {
269 269
270 audioMutex->lock(); 270 audioMutex->lock();
271 271
272 if ( hasVideoChannel ) 272 if ( hasVideoChannel )
273 killTimer( videoId ); 273 killTimer( videoId );
274 killTimer( sliderId ); 274 killTimer( sliderId );
275 threadOkToGo = FALSE; 275 threadOkToGo = FALSE;
276 276
277 audioMutex->unlock(); 277 audioMutex->unlock();
278} 278}
279 279
280 280
281void LoopControl::startTimers() { 281void LoopControl::startTimers() {
282 282
283 audioMutex->lock(); 283 audioMutex->lock();