@ -162,15 +162,13 @@ If the input device has no more subscriptions, it will be closed.
@@ -162,15 +162,13 @@ If the input device has no more subscriptions, it will be closed.
void Audio : : unsubscribeInput ( )
{
qDebug ( ) < < " unsubscribing input " < < inputSubscriptions ;
QMutexLocker locker ( & audioInLock ) ;
if ( inputSubscriptions > 0 )
inputSubscriptions - - ;
else if ( inputSubscriptions < 0 )
inputSubscriptions = 0 ;
if ( ! inputSubscriptions ) {
closeOutput ( ) ;
closeInput ( ) ;
}
cleanupInput ( ) ;
}
/**
@ -180,14 +178,7 @@ void Audio::openInput(const QString& inDevDescr)
@@ -180,14 +178,7 @@ void Audio::openInput(const QString& inDevDescr)
{
QMutexLocker lock ( & audioInLock ) ;
if ( alInDev ) {
# if (!FIX_SND_PCM_PREPARE_BUG)
qDebug ( ) < < " stopping capture " ;
alcCaptureStop ( alInDev ) ;
# endif
alcCaptureCloseDevice ( alInDev ) ;
}
alInDev = nullptr ;
cleanupInput ( ) ;
if ( inDevDescr = = " none " )
return ;
@ -251,8 +242,8 @@ bool Audio::openOutput(const QString &outDevDescr)
@@ -251,8 +242,8 @@ bool Audio::openOutput(const QString &outDevDescr)
qDebug ( ) < < " Opening audio output " + outDevDescr ;
QMutexLocker lock ( & audioOutLock ) ;
auto * tmp = alOutDev ;
alOutDev = nullptr ;
cleanupOutput ( ) ;
if ( outDevDescr ! = " none " )
{
@ -285,12 +276,6 @@ bool Audio::openOutput(const QString &outDevDescr)
@@ -285,12 +276,6 @@ bool Audio::openOutput(const QString &outDevDescr)
if ( alOutDev )
{
if ( alContext & & alcMakeContextCurrent ( nullptr ) = = ALC_TRUE )
alcDestroyContext ( alContext ) ;
if ( tmp )
alcCloseDevice ( tmp ) ;
alContext = alcCreateContext ( alOutDev , nullptr ) ;
if ( alcMakeContextCurrent ( alContext ) )
{
@ -328,23 +313,7 @@ void Audio::closeInput()
@@ -328,23 +313,7 @@ void Audio::closeInput()
{
qDebug ( ) < < " Closing input " ;
QMutexLocker locker ( & audioInLock ) ;
if ( alInDev )
{
# if (!FIX_SND_PCM_PREPARE_BUG)
qDebug ( ) < < " stopping capture " ;
alcCaptureStop ( alInDev ) ;
# endif
if ( alcCaptureCloseDevice ( alInDev ) = = ALC_TRUE )
{
alInDev = nullptr ;
inputSubscriptions = 0 ;
}
else
{
qWarning ( ) < < " Failed to close input " ;
}
}
cleanupInput ( ) ;
}
/**
@ -354,20 +323,7 @@ void Audio::closeOutput()
@@ -354,20 +323,7 @@ void Audio::closeOutput()
{
qDebug ( ) < < " Closing output " ;
QMutexLocker locker ( & audioOutLock ) ;
if ( alContext & & alcMakeContextCurrent ( nullptr ) = = ALC_TRUE )
{
alcDestroyContext ( alContext ) ;
alContext = nullptr ;
}
if ( alOutDev )
{
if ( alcCloseDevice ( alOutDev ) = = ALC_TRUE )
alOutDev = nullptr ;
else
qWarning ( ) < < " Failed to close output " ;
}
cleanupOutput ( ) ;
}
/**
@ -429,8 +385,6 @@ void Audio::playGroupAudioQueued(void*,int group, int peer, const int16_t* data,
@@ -429,8 +385,6 @@ void Audio::playGroupAudioQueued(void*,int group, int peer, const int16_t* data,
emit static_cast < Core * > ( core ) - > groupPeerAudioPlaying ( group , peer ) ;
}
/**
Must be called from the audio thread , plays a group call ' s received audio
*/
@ -503,6 +457,49 @@ void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, u
@@ -503,6 +457,49 @@ void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, u
alSourcePlay ( alSource ) ;
}
void Audio : : cleanupInput ( )
{
if ( alInDev )
{
# if (!FIX_SND_PCM_PREPARE_BUG)
qDebug ( ) < < " stopping capture " ;
alcCaptureStop ( alInDev ) ;
# endif
if ( alcCaptureCloseDevice ( alInDev ) )
{
alInDev = nullptr ;
inputSubscriptions = 0 ;
}
else
{
qWarning ( ) < < " Failed to close input " ;
}
}
}
void Audio : : cleanupOutput ( )
{
if ( inputSubscriptions )
cleanupInput ( ) ;
if ( alOutDev ) {
alSourcei ( alMainSource , AL_LOOPING , AL_FALSE ) ;
alSourceStop ( alMainSource ) ;
alDeleteSources ( 1 , & alMainSource ) ;
ALCdevice * device = alcGetContextsDevice ( alContext ) ;
if ( ! alcMakeContextCurrent ( nullptr ) )
qWarning ( " Failed to clear current audio context. " ) ;
alcDestroyContext ( alContext ) ;
alContext = nullptr ;
if ( ! alcCloseDevice ( device ) )
qWarning ( " Failed to close output. " ) ;
}
}
/**
Returns true if the input device is open and suscribed to
*/