sipxmedialib  Version 3.3
Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Friends | List of all members
MpAlsa Class Reference

Wrapper for ALSA device that use file descriptor to communicate. More...

#include <MpAlsa.h>

Inheritance diagram for MpAlsa:
Inheritance graph
[legend]
Collaboration diagram for MpAlsa:
Collaboration graph
[legend]

Public Member Functions

Creators
 MpAlsa ()
 Constructor. More...
 
 ~MpAlsa ()
 Destructor. More...
 
Manipulators
OsStatus setInputDevice (MpidAlsa *pIDD)
 Connect MpidAlsa class driver. More...
 
OsStatus setOutputDevice (MpodAlsa *pODD)
 Connect MpodAlsa class driver. More...
 
OsStatus freeInputDevice ()
 Disconnect Input driver. More...
 
OsStatus freeOutputDevice ()
 Disconnect Output driver. More...
 
OsStatus attachReader ()
 Enable input device. More...
 
OsStatus attachWriter ()
 Enable output device. More...
 
OsStatus detachReader ()
 Disable input device. More...
 
OsStatus detachWriter ()
 Disable output device. More...
 
Inquiry
Parameters
deviceNamesoutput - list of device names
captureinput - true - get input device names false - get output device names
Returns
count of device names
UtlBoolean isDeviceValid ()
 Inquire if the device is valid. More...
 
UtlBoolean isReaderAttached ()
 Inquire if the input device is connected. More...
 
UtlBoolean isWriterAttached ()
 Inquire if the output device is connected. More...
 
UtlBoolean isDevCapBatch ()
 
UtlBoolean isDevCapDuplex ()
 
UtlBoolean isDevCapMmap ()
 
UtlBoolean isDevCapTrigger ()
 
UtlBoolean isNotUsed ()
 Inquire if ALSA device is free, i.e. neither input nor output is connected. More...
 

Static Public Member Functions

Accessors
static int getDeviceNames (UtlContainer &deviceNames, bool capture)
 get list of available input or output Alsa device names More...
 

Protected Member Functions

OsStatus initDevice (const char *devname, int samplesPerSecond)
 Pre initializations for ALSA device. More...
 
OsStatus initDeviceFinal (unsigned samplesPerSec, unsigned samplerPerFrame)
 Final initializations for ALSA device. More...
 
OsStatus setSampleRate (unsigned samplesPerSec, unsigned samplerPerFrame)
 Because ALSA device works in duplex mode we must ensure that input and output driver use one sample rate and perfrom final init. More...
 
OsStatus doInput (char *buffer, int size)
 Perform input operation of ALSA device. More...
 
OsStatus doOutput (const char *buffer, int size)
 Perform output operation of ALSA device. More...
 
OsStatus doInputRs (MpAudioSample *buffer, unsigned size)
 Perform input operation of ALSA device with siutable resampler. More...
 
OsStatus doOutputRs (const MpAudioSample *buffer, unsigned size)
 Perform output operation of ALSA device with siutable resampler. More...
 
void noMoreNeeded ()
 Deinitialization and freeing sequences. More...
 
void soundIoThread ()
 Thread subroutine. More...
 

Protected Attributes

UtlBoolean mbReadCap
 Device is able to play audio. More...
 
UtlBoolean mbWriteCap
 Device is able to capture audio. More...
 
MpidAlsamReader
 Input driver. More...
 
MpodAlsamWriter
 Output driver. More...
 
int mDeviceCap
 Device capabilities. More...
 
volatile UtlBoolean mStReader
 Input device is enabled. More...
 
volatile UtlBoolean mStWriter
 Output device is enabled. More...
 
volatile UtlBoolean mStShutdown
 Thread exit flag. More...
 
volatile UtlBoolean mModeChanged
 IO settings has changed. More...
 
unsigned mUsedSamplesPerSec
 Used samples rate either for IO. More...
 
unsigned mUsedSamplesPerFrame
 Used frame size for IO. More...
 
MpAudioSamplemResamplerBuffer
 Buffer for conversions. More...
 
UtlBoolean mStereoOps
 Use stereo output. More...
 
pthread_t mIoThread
 Internal IO thread. More...
 
sem_t mSleepSem
 Control IO thread sleeping. More...
 
sem_t mSignalSem
 Use for parameters synchronization. More...
 
snd_pcm_t * pPcmOut
 
snd_pcm_t * pPcmIn
 
int writeBufSize
 
int readBufSize
 

Private Member Functions

void threadIoStatusChanged ()
 
void threadWakeUp ()
 
void threadKill ()
 
UtlBoolean alsaSetTrigger (bool turnOn)
 
UtlBoolean alsaReset ()
 
int alsaSetupPcmDevice (const char *devname, bool capture, unsigned &suggestedRate)
 
int alsaSetupWarning (const char *devname, int err, bool cap, const char *pLogString)
 

Static Private Member Functions

static void * soundCardIoWrapper (void *arg)
 Thread subroutine. More...
 

Friends

class MpidAlsa
 
class MpodAlsa
 

Detailed Description

Wrapper for ALSA device that use file descriptor to communicate.

Constructor & Destructor Documentation

MpAlsa ( )

Constructor.

~MpAlsa ( )

Destructor.

Member Function Documentation

OsStatus setInputDevice ( MpidAlsa pIDD)

Connect MpidAlsa class driver.

OsStatus setOutputDevice ( MpodAlsa pODD)

Connect MpodAlsa class driver.

OsStatus freeInputDevice ( )

Disconnect Input driver.

OsStatus freeOutputDevice ( )

Disconnect Output driver.

OsStatus attachReader ( )

Enable input device.

OsStatus attachWriter ( )

Enable output device.

OsStatus detachReader ( )

Disable input device.

OsStatus detachWriter ( )

Disable output device.

static int getDeviceNames ( UtlContainer &  deviceNames,
bool  capture 
)
static

get list of available input or output Alsa device names

UtlBoolean isDeviceValid ( )
inline

Inquire if the device is valid.

UtlBoolean isReaderAttached ( )
inline

Inquire if the input device is connected.

UtlBoolean isWriterAttached ( )
inline

Inquire if the output device is connected.

UtlBoolean isDevCapBatch ( )
inline
UtlBoolean isDevCapDuplex ( )
inline
UtlBoolean isDevCapMmap ( )
inline
UtlBoolean isDevCapTrigger ( )
inline
UtlBoolean isNotUsed ( )
inline

Inquire if ALSA device is free, i.e. neither input nor output is connected.

OsStatus initDevice ( const char *  devname,
int  samplesPerSecond 
)
protected

Pre initializations for ALSA device.

OsStatus initDeviceFinal ( unsigned  samplesPerSec,
unsigned  samplerPerFrame 
)
protected

Final initializations for ALSA device.

OsStatus setSampleRate ( unsigned  samplesPerSec,
unsigned  samplerPerFrame 
)
protected

Because ALSA device works in duplex mode we must ensure that input and output driver use one sample rate and perfrom final init.

OsStatus doInput ( char *  buffer,
int  size 
)
protected

Perform input operation of ALSA device.

OsStatus doOutput ( const char *  buffer,
int  size 
)
protected

Perform output operation of ALSA device.

OsStatus doInputRs ( MpAudioSample buffer,
unsigned  size 
)
protected

Perform input operation of ALSA device with siutable resampler.

OsStatus doOutputRs ( const MpAudioSample buffer,
unsigned  size 
)
protected

Perform output operation of ALSA device with siutable resampler.

void noMoreNeeded ( )
protected

Deinitialization and freeing sequences.

void soundIoThread ( )
protected

Thread subroutine.

void threadIoStatusChanged ( )
private
void threadWakeUp ( )
private
void threadKill ( )
private
UtlBoolean alsaSetTrigger ( bool  turnOn)
private
UtlBoolean alsaReset ( )
private
static void* soundCardIoWrapper ( void *  arg)
staticprivate

Thread subroutine.

int alsaSetupPcmDevice ( const char *  devname,
bool  capture,
unsigned &  suggestedRate 
)
private
int alsaSetupWarning ( const char *  devname,
int  err,
bool  cap,
const char *  pLogString 
)
private

Friends And Related Function Documentation

friend class MpidAlsa
friend
friend class MpodAlsa
friend

Member Data Documentation

UtlBoolean mbReadCap
protected

Device is able to play audio.

UtlBoolean mbWriteCap
protected

Device is able to capture audio.

MpidAlsa* mReader
protected

Input driver.

MpodAlsa* mWriter
protected

Output driver.

int mDeviceCap
protected

Device capabilities.

volatile UtlBoolean mStReader
protected

Input device is enabled.

volatile UtlBoolean mStWriter
protected

Output device is enabled.

volatile UtlBoolean mStShutdown
protected

Thread exit flag.

volatile UtlBoolean mModeChanged
protected

IO settings has changed.

unsigned mUsedSamplesPerSec
protected

Used samples rate either for IO.

unsigned mUsedSamplesPerFrame
protected

Used frame size for IO.

MpAudioSample* mResamplerBuffer
protected

Buffer for conversions.

UtlBoolean mStereoOps
protected

Use stereo output.

pthread_t mIoThread
protected

Internal IO thread.

sem_t mSleepSem
protected

Control IO thread sleeping.

sem_t mSignalSem
protected

Use for parameters synchronization.

snd_pcm_t* pPcmOut
protected
snd_pcm_t* pPcmIn
protected
int writeBufSize
protected
int readBufSize
protected