sipxmedialib  Version 3.3
Protected Attributes | Private Member Functions | List of all members
MpOutputDeviceDriver Class Referenceabstract

Container for device specific output driver. More...

#include <MpOutputDeviceDriver.h>

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

Protected Attributes

OsAtomicLightBool mIsEnabled
 Whether this device driver is enabled or not. More...
 
OsAtomicLightUInt mSamplesPerFrame
 number of samples. More...
 
OsAtomicLightUInt mSamplesPerSec
 of samples per second. More...
 
OsCallback * mpTickerNotification
 is ready to accept more data. See enableDevice() for details. More...
 

Private Member Functions

 MpOutputDeviceDriver (const MpOutputDeviceDriver &rMpOutputDeviceDriver)
 Copy constructor (not implemented for this class) More...
 
MpOutputDeviceDriveroperator= (const MpOutputDeviceDriver &rhs)
 Assignment operator (not implemented for this class) More...
 

Creators

 MpOutputDeviceDriver (const UtlString &name)
 Default constructor. More...
 
virtual ~MpOutputDeviceDriver ()
 Destructor. More...
 

Manipulators

virtual OsStatus enableDevice (unsigned samplesPerFrame, unsigned samplesPerSec, MpFrameTime currentFrameTime, OsCallback &frameTicker)=0
 Initialize device driver and state. More...
 
virtual OsStatus disableDevice ()=0
 Uninitialize device driver. More...
 
virtual OsStatus pushFrame (unsigned int numSamples, const MpAudioSample *samples, MpFrameTime frameTime)=0
 Send data to output device. More...
 

Accessors

MpFrameTime getFramePeriod () const
 Calculate the number of milliseconds that a frame occupies in time. More...
 
unsigned getSamplesPerFrame () const
 Get number of samples in a frame. More...
 
unsigned getSamplesPerSec () const
 Get number of samples per second. More...
 
const UtlString & getDeviceName () const
 Get device name. More...
 
static MpFrameTime getFramePeriod (unsigned samplesPerFrame, unsigned samplesPerSec)
 Calculate the number of milliseconds that a frame occupies in time. More...
 

Inquiry

virtual OsStatus canEnable ()
 Check if this device can connect. More...
 
virtual UtlBoolean isEnabled () const
 Inquire if this driver is enabled. More...
 

Detailed Description

Container for device specific output driver.

The MpOutputDeviceDriver is the abstract base class for the implementations of output media drivers. An instance of MpOutputDeviceDriver is created for every physical or logical input device (e.g. speaker). A driver is instantiated and then added to the MpOutputDeviceManager. The driver must be enabled via the MpOutputDeviceManager to begin consuming frames.

Each audio output driver should notify its MpAudioOutputConnection when the device is ready to accept the next frame of data with provided OsNotification. See enableDevice() for more information.

MpOutputDeviceDriver has a text name which is defined upon construction. This name will typically be the same as the OS defined name for the input device. The name of the MpOutputDeviceDriver is accessed via the data() method inherited from UtlString. This allows MpOutputDeviceDriver to be contained and accessed by name.

Constructor & Destructor Documentation

MpOutputDeviceDriver ( const UtlString &  name)
explicit

Default constructor.

Parameters
name- (in) unique device driver name (e.g. "/dev/dsp", "YAMAHA AC-XG WDM Audio", etc.)
~MpOutputDeviceDriver ( )
virtual

Destructor.

MpOutputDeviceDriver ( const MpOutputDeviceDriver rMpOutputDeviceDriver)
private

Copy constructor (not implemented for this class)

Member Function Documentation

virtual OsStatus enableDevice ( unsigned  samplesPerFrame,
unsigned  samplesPerSec,
MpFrameTime  currentFrameTime,
OsCallback &  frameTicker 
)
pure 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
[in]samplesPerFrame- the number of samples in a frame of media
[in]samplesPerSec- sample rate for media frame in samples per second
[in]currentFrameTime- time in milliseconds for beginning of frame relative to the MpOutputDeviceManager reference time
[in]frameTicker- notification to signal when device become ready. Device driver MUST signal this notification as soon as it become ready to receive next portion of data to play back. Note, it is a callback which in turn calls pushFrame() method of this device driver. Also notification may be used to signal begin of frame interval for one or several flowgraphs, so it should be as uniform as possible, i.e. it should not burst or hold over, driver should signal this notification after equal intervals of time.
Returns
OS_INVALID_STATE if device already enabled.

This method is supposed to be used from MpAudioOutputConnection only. If you want enable device, use MpOutputDeviceManager or MpAudioOutputConnection methods.

Implemented in MpodWinMM, MpodAlsa, MpodOss, MpodAndroid, and MpodBufferRecorder.

virtual OsStatus disableDevice ( )
pure 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.

This method is supposed to be used from MpAudioOutputConnection only. If you want disable device, use MpOutputDeviceManager or MpAudioOutputConnection methods.

Implemented in MpodWinMM, MpodAlsa, MpodOss, MpodAndroid, MpodBufferRecorder, and MpodCoreAudio.

virtual OsStatus pushFrame ( unsigned int  numSamples,
const MpAudioSample samples,
MpFrameTime  frameTime 
)
pure virtual

Send data to output device.

This method is called from a callback which is called when we fire ticker notification. See enableDevice() for details.

Parameters
[in]numSamples- Number of samples in samples array.
[in]samples- Array of samples to push to device.
[in]frameTime- Time of pushed frame. Device may consider does it want it or not internally. If frame come too late driver should return OS_SUCCESS and throw out it silently. Common problem is when MediaTask queue is jammed - no frames are processed for some time and then they are processed bursty. Using given frameTime driver may keep its internal queue short. It is guaranteed that frame time would increase monotonically.
Returns
OS_LIMIT_REACHED if mixer buffer is full, i.e. frame come too early.
OS_FAILED for other errors.
OS_SUCCESS if frame sent correctly.
See also
enableDevice() for documentation when this is being called.

Implemented in MpodWinMM, MpodAlsa, MpodBufferRecorder, MpodOss, MpodAndroid, and MpodCoreAudio.

MpFrameTime getFramePeriod ( ) const
inline

Calculate the number of milliseconds that a frame occupies in time.

unsigned getSamplesPerFrame ( void  ) const
inline

Get number of samples in a frame.

unsigned getSamplesPerSec ( void  ) const
inline

Get number of samples per second.

MpFrameTime getFramePeriod ( unsigned  samplesPerFrame,
unsigned  samplesPerSec 
)
inlinestatic

Calculate the number of milliseconds that a frame occupies in time.

const UtlString & getDeviceName ( ) const
inline

Get device name.

virtual OsStatus canEnable ( )
inlinevirtual

Check if this device can connect.

Reimplemented in MpodAlsa, and MpodOss.

UtlBoolean isEnabled ( ) const
virtual

Inquire if this driver is enabled.

Returns
- OS_SUCCESS if the device can be enabled OS_NOT_FOUND if the named device does not exist OS_NOT_OWNER if the user does not have permission to connect OS_BUSY if the device is already in use and cannot be shared
MpOutputDeviceDriver& operator= ( const MpOutputDeviceDriver rhs)
private

Assignment operator (not implemented for this class)

Member Data Documentation

OsAtomicLightBool mIsEnabled
protected

Whether this device driver is enabled or not.

OsAtomicLightUInt mSamplesPerFrame
protected

number of samples.

Device produce audio frame with this

OsAtomicLightUInt mSamplesPerSec
protected

of samples per second.

Device produce audio with this number

OsCallback* mpTickerNotification
protected

is ready to accept more data. See enableDevice() for details.

Callback to be called when device