Skip to content
Snippets Groups Projects
Commit 38e8d709 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

remove async_pcm_handler; replaced by an extra thread

parent d7195d17
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,11 @@
#include "alsalayer.h"
void* ringtoneThreadEntry( void *ptr);
static pthread_t ringtone_thread;
bool ringtone_thread_is_running;
// Constructor
AlsaLayer::AlsaLayer( ManagerImpl* manager )
: AudioLayer( manager , ALSA )
......@@ -35,6 +40,9 @@
, IDSoundCards()
{
_debug(" Constructor of AlsaLayer called\n");
// The flag to stop the ringtone thread loop
ringtone_thread_is_running = false;
}
// Destructor
......@@ -44,6 +52,9 @@ AlsaLayer::~AlsaLayer (void)
closeCaptureStream();
closePlaybackStream();
deviceClosed = true;
ringtone_thread_is_running = false;
pthread_join(ringtone_thread, NULL);
}
void
......@@ -53,6 +64,8 @@ AlsaLayer::closeLayer()
closeCaptureStream();
closePlaybackStream();
deviceClosed = true;
ringtone_thread_is_running = false;
}
bool
......@@ -132,11 +145,18 @@ AlsaLayer::stopStream(void)
}
}
void AlsaLayer::AlsaCallBack( snd_async_handler_t* pcm_callback )
void* ringtoneThreadEntry( void *ptr )
{
while( ringtone_thread_is_running )
{
( ( AlsaLayer *)snd_async_handler_get_callback_private( pcm_callback )) -> playTones();
( ( AlsaLayer *) ptr) -> playTones();
}
return 0;
}
void
AlsaLayer::fillHWBuffer( void)
{
......@@ -248,6 +268,7 @@ void AlsaLayer::restorePulseAppsVolume( void ){}
void
AlsaLayer::playTones( void )
{
int frames = _periodSize ;
int maxBytes = frames * sizeof(SFLDataFormat) ;
SFLDataFormat* out = (SFLDataFormat*)malloc(maxBytes * sizeof(SFLDataFormat));
......@@ -268,6 +289,7 @@ AlsaLayer::playTones( void )
free( out ); out = 0;
}
bool
AlsaLayer::isPlaybackActive(void) {
ost::MutexLock guard( _mutex );
......@@ -383,10 +405,21 @@ bool AlsaLayer::alsa_set_params( snd_pcm_t *pcm_handle, int type, int rate ){
return false;
}
if( type == 1 ){
if( (err = snd_async_add_pcm_handler( &_AsyncHandler, pcm_handle , AlsaCallBack, this ) < 0)){
/*if( (err = snd_async_add_pcm_handler( &_AsyncHandler, pcm_handle , AlsaCallBack, this ) < 0)){
_debugAlsa(" Unable to install the async callback handler (%s)\n", snd_strerror(err));
return false;
}*/
// So the loop could start when the ringtone thread entry function is reached
ringtone_thread_is_running = true;
if( pthread_create(&ringtone_thread, NULL, ringtoneThreadEntry, this) != 0 )
{
_debug("Unable to start the ringtone posix thread\n");
return false;
}
}
snd_pcm_sw_params_free( swparams );
......
......@@ -22,6 +22,8 @@
#include "audiolayer.h"
#include <pthread.h>
class RingBuffer;
class ManagerImpl;
......@@ -202,6 +204,15 @@ class AlsaLayer : public AudioLayer {
*/
void setPlaybackVolume( double volume );
/**
* Callback used for asynchronous playback.
* Write tones buffer to the alsa internal ring buffer.
*/
void playTones( void );
private:
// Copy Constructor
......@@ -232,13 +243,7 @@ class AlsaLayer : public AudioLayer {
* Called when a certain amount of data is written ot the device
* @param pcm_callback The callback pointer
*/
static void AlsaCallBack( snd_async_handler_t* pcm_callback);
/**
* Callback used for asynchronous playback.
* Write tones buffer to the alsa internal ring buffer.
*/
void playTones( void );
//static void AlsaCallBack( snd_async_handler_t* pcm_callback);
/**
* Open the specified device.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment