diff options
| author | Michal Szwaj <michal.szwaj@o2.pl> | 2019-08-17 16:25:56 +0200 |
|---|---|---|
| committer | Michal Szwaj <michal.szwaj@o2.pl> | 2019-08-17 16:49:32 +0200 |
| commit | 2d9b95f9992659150fc7dabf92e161327c56a099 (patch) | |
| tree | 55427e4f92261582053b09e672a76f14f6f1d0c6 | |
| parent | 241e666f546364dbc471d7ff2aa381f32d1d9885 (diff) | |
Fix high CPU usage by PulseAudio backend when stream is stopped
| -rw-r--r-- | RtAudio.cpp | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/RtAudio.cpp b/RtAudio.cpp index e0713a0..1df152b 100644 --- a/RtAudio.cpp +++ b/RtAudio.cpp @@ -8679,15 +8679,18 @@ void RtApiPulse::stopStream( void ) stream_.state = STREAM_STOPPED; MUTEX_LOCK( &stream_.mutex ); - if ( pah && pah->s_play ) { - int pa_error; - if ( pa_simple_drain( pah->s_play, &pa_error ) < 0 ) { - errorStream_ << "RtApiPulse::stopStream: error draining output device, " << - pa_strerror( pa_error ) << "."; - errorText_ = errorStream_.str(); - MUTEX_UNLOCK( &stream_.mutex ); - error( RtAudioError::SYSTEM_ERROR ); - return; + if ( pah ) { + pah->runnable = false; + if ( pah->s_play ) { + int pa_error; + if ( pa_simple_drain( pah->s_play, &pa_error ) < 0 ) { + errorStream_ << "RtApiPulse::stopStream: error draining output device, " << + pa_strerror( pa_error ) << "."; + errorText_ = errorStream_.str(); + MUTEX_UNLOCK( &stream_.mutex ); + error( RtAudioError::SYSTEM_ERROR ); + return; + } } } @@ -8713,15 +8716,18 @@ void RtApiPulse::abortStream( void ) stream_.state = STREAM_STOPPED; MUTEX_LOCK( &stream_.mutex ); - if ( pah && pah->s_play ) { - int pa_error; - if ( pa_simple_flush( pah->s_play, &pa_error ) < 0 ) { - errorStream_ << "RtApiPulse::abortStream: error flushing output device, " << - pa_strerror( pa_error ) << "."; - errorText_ = errorStream_.str(); - MUTEX_UNLOCK( &stream_.mutex ); - error( RtAudioError::SYSTEM_ERROR ); - return; + if ( pah ) { + pah->runnable = false; + if ( pah->s_play ) { + int pa_error; + if ( pa_simple_flush( pah->s_play, &pa_error ) < 0 ) { + errorStream_ << "RtApiPulse::abortStream: error flushing output device, " << + pa_strerror( pa_error ) << "."; + errorText_ = errorStream_.str(); + MUTEX_UNLOCK( &stream_.mutex ); + error( RtAudioError::SYSTEM_ERROR ); + return; + } } } |
