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

Audio input driver for Android OS. More...

#include <MpidAndroid.h>

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

Protected Types

enum  DriverState {
  DRIVER_IDLE, DRIVER_INIT, DRIVER_STARTING, DRIVER_RECORDING,
  DRIVER_STOPPING, DRIVER_STOPPED
}
 

Protected Member Functions

bool initAudioRecord ()
 Prepare AudioRecord stream for recording. More...
 
bool probeSampleRate (int targetRate, int targetFrameSize, const int *ratesList, int ratesListLen, bool probeDefault=true)
 Call initAudioRecord() with frequencies listed until we find working one. More...
 

Static Protected Member Functions

static void audioCallback (int event, void *user, void *info)
 Callback function to be called by OS. More...
 

Protected Attributes

audio_source mStreamSource
 Source of a stream we're recording. More...
 
DriverState mState
 Driver internal state. More...
 
MpAndroidAudioRecordmpAudioRecord
 Pointer to audio track used for record. More...
 
int mSamplesPerSecInternal
 Sample rate of AudioRecord. More...
 
int mSamplesPerFrameInternal
 Number of sample per frame we use with AudioRecord. More...
 
MpAudioSamplempBufInternal
 full buffer. Have mSamplesPerFrameInternal size. More...
 
int mBufInternalSamples
 Number of samples currently stored in mpBufInternal. More...
 
Mutex mLock
 
Condition mWaitCbkCond
 
MpResamplerBasempResampler
 to output samplerate. More...
 
MpAudioSamplempResampleBuf
 resampler. More...
 
- Protected Attributes inherited from MpInputDeviceDriver
MpInputDeviceManagermpInputDeviceManager
 this device driver. More...
 
UtlBoolean mIsEnabled
 Whether this device driver is enabled or not. More...
 
MpInputDeviceHandle mDeviceId
 this device, as supplied by the InputDeviceManager. More...
 
unsigned mSamplesPerFrame
 number of samples. More...
 
unsigned mSamplesPerSec
 of samples per second. More...
 
MpFrameTime mCurrentFrameTime
 pushed to input device manager. More...
 

Static Protected Attributes

static const int mpSampleRatesList []
 AudioRecord initialization. More...
 
static const int mSampleRatesListLen
 Number of entries in mpSampleRatesList. More...
 

Private Member Functions

 MpidAndroid (const MpidAndroid &rMpidAndroid)
 Copy constructor (not implemented for this class) More...
 
MpidAndroidoperator= (const MpidAndroid &rhs)
 Assignment operator (not implemented for this class) More...
 

Creators

enum  audio_source {
  AUDIO_SOURCE_DEFAULT = 0, AUDIO_SOURCE_MIC = 1, AUDIO_SOURCE_VOICE_UPLINK = 2, AUDIO_SOURCE_VOICE_DOWNLINK = 3,
  AUDIO_SOURCE_VOICE_CALL = 4, AUDIO_SOURCE_CAMCORDER = 5, AUDIO_SOURCE_VOICE_RECOGNITION = 6, AUDIO_SOURCE_MAX = AUDIO_SOURCE_VOICE_RECOGNITION,
  AUDIO_SOURCE_LIST_END
}
 Audio input source. Refer to Android OS sources. More...
 
 MpidAndroid (audio_source source, MpInputDeviceManager &deviceManager)
 Default constructor. More...
 
virtual ~MpidAndroid ()
 Destructor. More...
 

Manipulators

virtual OsStatus enableDevice (unsigned samplesPerFrame, unsigned samplesPerSec, MpFrameTime currentFrameTime=0)
 Initialize device driver and state. More...
 
virtual OsStatus disableDevice ()
 Uninitialize device driver. More...
 

Inquiry

virtual UtlBoolean isDeviceValid ()
 Inquire if the device is valid. More...
 

Additional Inherited Members

- Public Member Functions inherited from MpInputDeviceDriver
 MpInputDeviceDriver (const UtlString &name, MpInputDeviceManager &deviceManager)
 Default constructor. More...
 
virtual ~MpInputDeviceDriver ()
 Destructor. More...
 
virtual OsStatus setDeviceId (MpInputDeviceHandle deviceId)
 Set device ID associated with this device in parent input device manager. More...
 
virtual OsStatus clearDeviceId ()
 Clear the device ID associated with this device. More...
 
virtual MpInputDeviceHandle getDeviceId () const
 Get device ID associated with this device in parent input device manager. More...
 
uint32_t getSamplesPerSec () const
 Get the sample rate of this device driver, if enabled. More...
 
uint32_t getSamplesPerFrame () const
 Get the samples per frame of this device driver, if enabled. More...
 
MpFrameTime getFramePeriod ()
 Calculate the number of milliseconds that a frame occupies in time. More...
 
MpFrameTime getCurrentFrameTime () const
 Get timestamp for the next frame to be pushed to input device manager. More...
 
const UtlString & getDeviceName () const
 Get device name. More...
 
virtual UtlBoolean isEnabled ()
 Inquire if this driver is enabled. More...
 
- Static Public Member Functions inherited from MpInputDeviceDriver
static MpFrameTime getFramePeriod (unsigned samplesPerFrame, unsigned samplesPerSec)
 Calculate the number of milliseconds that a frame occupies in time. More...
 

Detailed Description

Audio input driver for Android OS.

See also
MpInputDeviceDriver

Member Enumeration Documentation

Audio input source. Refer to Android OS sources.

Enumerator
AUDIO_SOURCE_DEFAULT 
AUDIO_SOURCE_MIC 
AUDIO_SOURCE_VOICE_UPLINK 
AUDIO_SOURCE_VOICE_DOWNLINK 
AUDIO_SOURCE_VOICE_CALL 
AUDIO_SOURCE_CAMCORDER 
AUDIO_SOURCE_VOICE_RECOGNITION 
AUDIO_SOURCE_MAX 
AUDIO_SOURCE_LIST_END 
enum DriverState
protected
Enumerator
DRIVER_IDLE 

Driver is being initialized or initialization failed.

DRIVER_INIT 

Driver has been successfully initialized and is not playing.

DRIVER_STARTING 

Driver is starting playing.

DRIVER_RECORDING 

Driver is playing.

DRIVER_STOPPING 

Driver is stopping.

DRIVER_STOPPED 

Driver is stopped: the AudioRecord will be stopped.

Constructor & Destructor Documentation

MpidAndroid ( audio_source  source,
MpInputDeviceManager deviceManager 
)

Default constructor.

Parameters
[in]source- what audio source to record.
[in]deviceManager- MpInputDeviceManager this device is to push frames to via pushFrame method
~MpidAndroid ( )
virtual

Destructor.

MpidAndroid ( const MpidAndroid rMpidAndroid)
private

Copy constructor (not implemented for this class)

Member Function Documentation

OsStatus enableDevice ( unsigned  samplesPerFrame,
unsigned  samplesPerSec,
MpFrameTime  currentFrameTime = 0 
)
virtual

Initialize device driver and state.

This method enables the device driver.

this SHOULD NOT be used to mute/unmute a device. Disabling and enabling a device results in state and buffer queues being cleared.

Parameters
samplesPerFrame- the number of samples in a frame of media
samplesPerSec- sample rate for media frame in samples per second
currentFrameTime- time in milliseconds for beginning of frame relative to the MpInputDeviceManager reference time

Implements MpInputDeviceDriver.

OsStatus disableDevice ( )
virtual

Uninitialize device driver.

This method disables the device driver and should release any platform device resources so that the device might be used else where.

this SHOULD NOT be used to mute/unmute a device. Disabling and enabling a device results in state and buffer queues being cleared.

Implements MpInputDeviceDriver.

UtlBoolean isDeviceValid ( )
virtual

Inquire if the device is valid.

Implements MpInputDeviceDriver.

bool initAudioRecord ( )
protected

Prepare AudioRecord stream for recording.

bool probeSampleRate ( int  targetRate,
int  targetFrameSize,
const int *  ratesList,
int  ratesListLen,
bool  probeDefault = true 
)
protected

Call initAudioRecord() with frequencies listed until we find working one.

void audioCallback ( int  event,
void *  user,
void *  info 
)
staticprotected

Callback function to be called by OS.

MpidAndroid& operator= ( const MpidAndroid rhs)
private

Assignment operator (not implemented for this class)

Member Data Documentation

audio_source mStreamSource
protected

Source of a stream we're recording.

DriverState mState
protected

Driver internal state.

MpAndroidAudioRecord* mpAudioRecord
protected

Pointer to audio track used for record.

int mSamplesPerSecInternal
protected

Sample rate of AudioRecord.

int mSamplesPerFrameInternal
protected

Number of sample per frame we use with AudioRecord.

MpAudioSample* mpBufInternal
protected

full buffer. Have mSamplesPerFrameInternal size.

Temporary audio buffer to save data if don't receive

int mBufInternalSamples
protected

Number of samples currently stored in mpBufInternal.

Mutex mLock
protected

Mutex to control concurrent access to driver object from audio callback and application API

Condition mWaitCbkCond
protected

condition enabling interface to wait for audio callback completion after a change is requested

MpResamplerBase* mpResampler
protected

to output samplerate.

Resampler used to resample from hardware samplerate

MpAudioSample* mpResampleBuf
protected

resampler.

Buffer of size mSamplesPerFrameInternal used by

const int mpSampleRatesList
staticprotected
Initial value:
=
{8000, 16000, 24000, 32000, 48000, 96000, 11025, 22050, 44100}

AudioRecord initialization.

List of sampling rates to probe during

const int mSampleRatesListLen
staticprotected
Initial value:

Number of entries in mpSampleRatesList.