mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
[#1314] Add mutex to pulse layer audio streams
This commit is contained in:
@ -34,33 +34,46 @@ AudioStream::AudioStream( pa_context* context, int type, std::string desc, doubl
|
||||
|
||||
_context = context;
|
||||
|
||||
connect();
|
||||
connectStream();
|
||||
}
|
||||
|
||||
AudioStream::~AudioStream()
|
||||
{
|
||||
_debug("Destroy audio streams\n");
|
||||
pa_stream_disconnect( pulseStream() );
|
||||
pa_stream_unref( pulseStream() );
|
||||
disconnectStream();
|
||||
}
|
||||
|
||||
void
|
||||
AudioStream::connect()
|
||||
AudioStream::connectStream()
|
||||
{
|
||||
_audiostream = createStream( _context );
|
||||
ost::MutexLock guard(_mutex);
|
||||
|
||||
if(!_audiostream)
|
||||
_audiostream = createStream( _context );
|
||||
else {
|
||||
disconnectStream();
|
||||
_audiostream = createStream( _context );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AudioStream::disconnect( void )
|
||||
AudioStream::disconnectStream( void )
|
||||
{
|
||||
ost::MutexLock guard(_mutex);
|
||||
|
||||
_debug("Destroy audio streams\n");
|
||||
pa_stream_disconnect( pulseStream() );
|
||||
pa_stream_unref( pulseStream() );
|
||||
pa_stream_disconnect( _audiostream );
|
||||
pa_stream_unref( _audiostream );
|
||||
|
||||
_audiostream = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED )
|
||||
{
|
||||
|
||||
|
||||
_debug("AudioStream::stream_state_callback :: The state of the stream changed\n");
|
||||
assert(s);
|
||||
switch(pa_stream_get_state(s)){
|
||||
@ -89,6 +102,8 @@ AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED )
|
||||
|
||||
pa_stream_state_t
|
||||
AudioStream::getStreamState(void) {
|
||||
|
||||
ost::MutexLock guard(_mutex);
|
||||
return pa_stream_get_state(_audiostream);
|
||||
}
|
||||
|
||||
@ -97,6 +112,8 @@ AudioStream::getStreamState(void) {
|
||||
pa_stream*
|
||||
AudioStream::createStream( pa_context* c )
|
||||
{
|
||||
ost::MutexLock guard(_mutex);
|
||||
|
||||
pa_stream* s;
|
||||
//pa_cvolume cv;
|
||||
|
||||
|
@ -27,6 +27,8 @@
|
||||
#include "ringbuffer.h"
|
||||
#include "audioloop.h"
|
||||
|
||||
#include <cc++/thread.h>
|
||||
|
||||
/**
|
||||
* This data structure contains the different king of audio streams available
|
||||
*/
|
||||
@ -71,12 +73,12 @@ class AudioStream {
|
||||
/**
|
||||
* Connect the pulse audio stream
|
||||
*/
|
||||
void connect();
|
||||
void connectStream();
|
||||
|
||||
/**
|
||||
* Disconnect the pulseaudio stream
|
||||
*/
|
||||
void disconnect();
|
||||
void disconnectStream();
|
||||
|
||||
/**
|
||||
* Accessor: Get the pulseaudio stream object
|
||||
@ -105,6 +107,8 @@ class AudioStream {
|
||||
*/
|
||||
pa_stream_state_t getStreamState(void);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Copy Constructor
|
||||
@ -162,6 +166,8 @@ class AudioStream {
|
||||
pa_sample_spec sample_spec ;
|
||||
pa_cvolume _volume;
|
||||
|
||||
ost::Mutex _mutex;
|
||||
|
||||
};
|
||||
|
||||
#endif // _AUDIO_STREAM_H
|
||||
|
@ -57,8 +57,8 @@ PulseLayer::closeLayer( void )
|
||||
{
|
||||
_debug("PulseLayer::closeLayer :: Destroy pulselayer\n");
|
||||
|
||||
playback->disconnect();
|
||||
record->disconnect();
|
||||
playback->disconnectStream();
|
||||
record->disconnectStream();
|
||||
|
||||
while(PulseLayer::streamState != 2);
|
||||
PulseLayer::streamState = 0;
|
||||
@ -131,13 +131,14 @@ bool PulseLayer::disconnectPulseAudioServer( void )
|
||||
{
|
||||
_debug(" PulseLayer::disconnectPulseAudioServer( void ) \n");
|
||||
|
||||
if( playback )
|
||||
playback->disconnect();
|
||||
if( playback ){
|
||||
playback->disconnectStream();
|
||||
delete playback; playback=NULL;
|
||||
|
||||
if( record )
|
||||
}
|
||||
if( record ){
|
||||
record->disconnectStream();
|
||||
delete record; record=NULL;
|
||||
|
||||
}
|
||||
if (!playback && !record)
|
||||
return true;
|
||||
else
|
||||
|
Reference in New Issue
Block a user