sipxmedialib  Version 3.3
Classes | Public Types | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
MprDecode Class Reference

The "Decode" media processing resource. More...

#include <MprDecode.h>

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

Classes

struct  StreamState
 

Public Types

enum  AddlResMsgTypes { MPRM_SET_PLC = MpResourceMsg::MPRM_EXTERNAL_MESSAGE_START, MPRM_DESELCT_CODECS, MPRM_RESET, MPRM_SET_VAD_PARAM }
 
- Public Types inherited from MpResource
enum  VisitState { NOT_VISITED, IN_PROGRESS, FINISHED }
 Graph traversal states that are used when running a topological sort to order resources within a flow graph. More...
 
enum  { ASSOCIATED_LATENCY =-1, INF_LATENCY =-1 }
 

Public Member Functions

Creators
 MprDecode (const UtlString &rName, const UtlString &plcName="")
 Constructor. More...
 
virtual ~MprDecode ()
 Destructor. More...
 
Accessors
UtlContainableType getContainableType () const
 
virtual OsStatus getCurrentLatency (int &latency, int input=0, int output=0) const
 Get current input to output latency (in samples) More...
 
- Public Member Functions inherited from MpAudioResource
 MpAudioResource (const UtlString &rName, int minInputs, int maxInputs, int minOutputs, int maxOutputs)
 Constructor. More...
 
virtual ~MpAudioResource ()
 Destructor. More...
 
virtual UtlBoolean processFrame (void)
 Wrapper around doProcessFrame(). More...
 
- Public Member Functions inherited from MpResource
 MpResource (const UtlString &rName, int minInputs, int maxInputs, int minOutputs, int maxOutputs)
 Constructor. More...
 
virtual ~MpResource ()
 Destructor. More...
 
virtual UtlBoolean disable ()
 Disable this resource. More...
 
virtual UtlBoolean enable ()
 Enable this resource. More...
 
UtlBoolean handleMessages (OsMsgQ &msgQ)
 Handles a queue full of incoming messages for this media processing object. More...
 
void setVisitState (int newState)
 Sets the visit state for this resource. More...
 
OsStatus sendNotification (MpResNotificationMsg::RNMsgType msgType)
 Send a notification with the given message type if notifications are enabled. More...
 
OsStatus sendNotification (MpResNotificationMsg &msg)
 Send the given notification message if notifications are enabled. More...
 
virtual int getStreamId (void)
 Get the ID of a stream within the connection this resource belongs to. More...
 
virtual void reassignSSRC (void)
 Broadcast announcement that we are changing our SSRC. More...
 
MpFlowGraphBasegetFlowGraph () const
 Returns parent flowgraph. More...
 
void getInputInfo (int inPortIdx, MpResource *&rpUpstreamResource, int &rUpstreamPortIdx)
 Returns information about the upstream end of a connection. More...
 
const UtlString & getName () const
 Returns the name associated with this resource. More...
 
void getOutputInfo (int outPortIdx, MpResource *&rpDownstreamResource, int &rDownstreamPortIdx)
 Returns information about the downstream end of a connection. More...
 
int getVisitState ()
 Returns the current visit state for this resource. More...
 
int maxInputs () const
 Returns the maximum number of inputs supported by this resource. More...
 
int maxOutputs () const
 Returns the maximum number of outputs supported by this resource. More...
 
int minInputs () const
 Returns the minimum number of inputs required by this resource. More...
 
int minOutputs () const
 Returns the minimum number of outputs required by this resource. More...
 
int numInputs () const
 Returns the number of resource inputs that are currently connected. More...
 
int numOutputs () const
 Returns the number of resource outputs that are currently connected. More...
 
virtual MpConnectionID getConnectionId (void) const
 Get the ID of a connection this resource belongs to. More...
 
int reserveFirstUnconnectedInput ()
 Find the first unconnected input port and reserve it. More...
 
int reserveFirstUnconnectedOutput ()
 Find the first unconnected output port and reserve it. More...
 
UtlContainableType getContainableType () const
 Get the ContainableType for a UtlContainable derived class. More...
 
UtlBoolean isEnabled () const
 Returns TRUE is this resource is currently enabled, FALSE otherwise. More...
 
UtlBoolean isInputConnected (int portIdx)
 Returns TRUE if portIdx is valid and the indicated input is connected, FALSE otherwise. More...
 
UtlBoolean isInputUnconnected (int portIdx)
 Returns TRUE if portIdx is valid and the indicated input is not connected, FALSE otherwise. More...
 
UtlBoolean isOutputConnected (int portIdx)
 Returns TRUE if portIdx is valid and the indicated output is connected, FALSE otherwise. More...
 
UtlBoolean isOutputUnconnected (int portIdx)
 Returns TRUE if portIdx is valid and the indicated output is not connected, FALSE otherwise. More...
 
UtlBoolean areNotificationsEnabled () const
 Returns TRUE if notification sending is enabled on this resource. More...
 
virtual UtlBoolean isAsynchInput (int inputIndex)
 Takes asynchronous input (pushBuffer). More...
 

Static Public Attributes

static const UtlContainableType TYPE = "MprDecode"
 Class name, used for run-time checks. More...
 
- Static Public Attributes inherited from MpResource
static const UtlContainableType TYPE = "MpResource"
 Class name, used for run-time checks. More...
 

Private Member Functions

virtual UtlBoolean doProcessFrame (MpBufPtr inBufs[], MpBufPtr outBufs[], int inBufsSize, int outBufsSize, UtlBoolean isEnabled, int samplesPerFrame, int samplesPerSecond)
 This method does the real work for the media processing resource and must be defined in each class derived from this one. More...
 
UtlBoolean tryDecodeAsSignalling (const MpRtpBufPtr &rtp)
 Decode RTP packet if it belongs to signaling codec. More...
 
OsStatus setFlowGraph (MpFlowGraphBase *pFlowGraph)
 Associates this resource with the indicated flow graph. More...
 
virtual UtlBoolean handleMessage (MpResourceMsg &rMsg)
 Handle new style messages for this resource. More...
 
UtlBoolean handleSelectCodecs (SdpCodec *pCodecs[], int numCodecs)
 Replace mpCurrentCodecs with pCodecs. More...
 
UtlBoolean handleDeselectCodecs (UtlBoolean shouldLock=TRUE)
 Remove all codecs from mpCurrentCodecs, transferring them to mpPrevCodecs. More...
 
UtlBoolean handleDeselectCodec (MpDecoderBase *pDecoder)
 Remove one codec from mpConnection's payload type decoder table. More...
 
UtlBoolean handleSetPlc (const UtlString &plcName)
 Change PLC algorithm to one provided. More...
 
UtlBoolean handleReset ()
 Handle MPRM_RESET message. More...
 
UtlBoolean handleDisable ()
 perform the disable operation on the resource More...
 
UtlBoolean handleSetVadParam (UtlSerialized &serialData)
 Handle message to set VAD parameter. More...
 
void deletePriorCodecs ()
 Delete the array of previously used codecs. More...
 
 MprDecode (const MprDecode &rMprDecode)
 Copy constructor (not implemented for this class) More...
 
MprDecodeoperator= (const MprDecode &rhs)
 Assignment operator (not implemented for this class) More...
 

Private Attributes

MpJitterBuffermpJB
 Pointer to JitterBuffer instance. More...
 
UtlBoolean mIsJBInitialized
 Is JB initialized or not? More...
 
MprDejittermpMyDJ
 Dejitter instance, used by this decoder. More...
 
UtlBoolean mOwnDJ
 Is dejitter owned by this decoder? More...
 
UtlBoolean mIsStreamInitialized
 Have we received at least one packet? More...
 
struct MprDecode::StreamState mStreamState
 
RtpSeq mLastPulledSeq
 Sequence number of last pulled packet. More...
 
MpJitterBufferEstimationmpJbEstimationState
 State of JB delay estimation. More...
 
MpDecoderBase ** mpCurrentCodecs
 List of the codecs to be used to decode media. More...
 
int mNumCurrentCodecs
 Length of mpCurrentCodecs array. More...
 
UtlBoolean mEnableG722Hack
 
int mG722HackPayloadType
 
MpDecoderBase ** mpPrevCodecs
 Similar list of all codecs that have ever been listed on mpCurrentCodecs. More...
 
int mNumPrevCodecs
 Length of mpPrevCodecs array. More...
 
MpDecoderPayloadMap mDecoderMap
 Mapping of payload types to decoder instances. More...
 

Manipulators

virtual void reset ()
 Reset decoder to the initial state to be able process new stream. More...
 
void setMyDejitter (MprDejitter *newDJ, UtlBoolean ownDj)
 Pair this decode resource with the dejitter resource. More...
 
virtual OsStatus pushBuffer (int inputPort, MpBufPtr &inputBuffer)
 MpResource::pushBuffer More...
 
OsStatus pushPacket (MpRtpBufPtr &pRtp)
 Add incoming RTP packet to the decoding queue. More...
 
void setConnectionId (MpConnectionID connectionId)
 Set the ID of a connection this resource belongs to. More...
 
void setStreamId (int connectionId)
 Set the ID of a stream inside of the connection this resource belongs to. More...
 
static OsStatus reset (const UtlString &namedResource, OsMsgQ &fgQ)
 Reset decoder to the initial state to be able process new stream. More...
 
static OsStatus selectCodecs (const UtlString &namedResource, OsMsgQ &fgQ, SdpCodec *codecs[], int numCodecs)
 Provide set of codecs this decode resource will be able to decode. More...
 
static OsStatus deselectCodecs (const UtlString &namedResource, OsMsgQ &fgQ)
 Clear set of codecs this resource is able to decode. More...
 
static OsStatus setPlc (const UtlString &namedResource, OsMsgQ &fgQ, const UtlString &plcName="")
 Change PLC algorithm to one with given name. THIS METHOD DOES NOT WORK! More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MpResource
static OsStatus disable (const UtlString &namedResource, OsMsgQ &fgQ)
 Post a message to disable the resource named. More...
 
static OsStatus enable (const UtlString &namedResource, OsMsgQ &fgQ)
 Post a message to enable the resource named. More...
 
static OsStatus setNotificationsEnabled (UtlBoolean enable, const UtlString &namedResource, OsMsgQ &fgQ)
 Post a message to enable or disable resource notifications on the named resource. More...
 
static void resourceInfo (MpResource *pResource, int index)
 Displays information on the console about the specified resource. More...
 
- Protected Member Functions inherited from MpResource
virtual UtlBoolean handleMessage (MpFlowGraphMsg &fgMsg)
 Handles an incoming flowgraph message for this media processing object. More...
 
virtual UtlBoolean handleEnable ()
 perform the enable operation on the resource More...
 
void setInputBuffer (int inPortIdx, const MpBufPtr &pBuf)
 If there already is a buffer stored for this input port, delete it. Then store pBuf for the indicated input port. More...
 
OsStatus postMessage (MpFlowGraphMsg &rMsg)
 Post a message from this resource. More...
 
OsStatus postMessage (MpResourceMsg &rMsg)
 Post a message for this resource. More...
 
UtlBoolean pushBufferDownsream (int outPortIdx, const MpBufPtr &pBuf)
 Makes pBuf available to resource connected to the outPortIdx output port of this resource. More...
 
virtual OsStatus setNotificationsEnabled (UtlBoolean enable)
 Sets whether or not this resource should send notifications. More...
 
virtual UtlBoolean connectInput (MpResource &rFrom, int fromPortIdx, int toPortIdx)
 Connects the toPortIdx input port on this resource to the fromPortIdx output port of the rFrom resource. More...
 
virtual UtlBoolean connectOutput (MpResource &rTo, int toPortIdx, int fromPortIdx)
 Connects the fromPortIdx output port on this resource to the toPortIdx input port of the rTo resource. More...
 
virtual UtlBoolean disconnectInput (int inPortIdx)
 Removes the connection to the inPortIdx input port of this resource. More...
 
virtual UtlBoolean disconnectOutput (int outPortIdx)
 Removes the connection to the outPortIdx output port of this resource. More...
 
void setName (const UtlString &rName)
 Sets the name that is associated with this resource. More...
 
- Protected Attributes inherited from MpResource
MpFlowGraphBasempFlowGraph
 flow graph this resource belongs to More...
 
MpConnectionID mConnectionId
 The ID of connection this resource belongs to. More...
 
int mStreamId
 
UtlBoolean mIsEnabled
 TRUE if resource is enabled, FALSE otherwise. More...
 
OsRWMutex mRWMutex
 reader/writer lock for synchronization More...
 
MpBufPtrmpInBufs
 input buffers for this resource More...
 
MpBufPtrmpOutBufs
 output buffers for this resource More...
 
ConnmpInConns
 input connections for this resource More...
 
ConnmpOutConns
 output connections for this resource More...
 
int mMaxInputs
 maximum number of inputs More...
 
int mMaxOutputs
 maximum number of outputs More...
 
int mMinInputs
 number of required inputs More...
 
int mMinOutputs
 number of required outputs More...
 
int mNumActualInputs
 actual number of connected inputs More...
 
int mNumActualOutputs
 actual number of connected outputs More...
 
int mVisitState
 (used by flow graph topological sort alg.) More...
 
UtlBoolean mNotificationsEnabled
 Whether we should send notifications or not. More...
 
OsBSem mLock
 used mainly to make safe changes to ports More...
 
- Static Protected Attributes inherited from MpResource
static const OsTime sOperationQueueTimeout = OsTime::OS_INFINITY
 The timeout for message operations for all resources when posting to the flowgraph queue. More...
 

Detailed Description

The "Decode" media processing resource.

Member Enumeration Documentation

Enumerator
MPRM_SET_PLC 
MPRM_DESELCT_CODECS 
MPRM_RESET 
MPRM_SET_VAD_PARAM 

Constructor & Destructor Documentation

MprDecode ( const UtlString &  rName,
const UtlString &  plcName = "" 
)

Constructor.

~MprDecode ( )
virtual

Destructor.

MprDecode ( const MprDecode rMprDecode)
private

Copy constructor (not implemented for this class)

Member Function Documentation

OsStatus reset ( const UtlString &  namedResource,
OsMsgQ &  fgQ 
)
static

Reset decoder to the initial state to be able process new stream.

void reset ( )
virtual

Reset decoder to the initial state to be able process new stream.

Reimplemented from MpResource.

OsStatus selectCodecs ( const UtlString &  namedResource,
OsMsgQ &  fgQ,
SdpCodec *  codecs[],
int  numCodecs 
)
static

Provide set of codecs this decode resource will be able to decode.

OsStatus deselectCodecs ( const UtlString &  namedResource,
OsMsgQ &  fgQ 
)
static

Clear set of codecs this resource is able to decode.

OsStatus setPlc ( const UtlString &  namedResource,
OsMsgQ &  fgQ,
const UtlString &  plcName = "" 
)
static

Change PLC algorithm to one with given name. THIS METHOD DOES NOT WORK!

Sends an MPRM_SET_PLC message to the named MprDecode resource within the flowgraph who's queue is supplied. When the message is received, the above resource will change PLC algorithm to chosen one.

Parameters
[in]namedResource- the name of the resource to send a message to.
[in]fgQ- the queue of the flowgraph containing the resource which the message is to be received by.
[in]plcName- name of PLC algorithm to use. See MpJitterBuffer::setPlc() for more details.
Returns
the result of attempting to queue the message to this resource.
void setMyDejitter ( MprDejitter newDJ,
UtlBoolean  ownDj 
)

Pair this decode resource with the dejitter resource.

If ownDj is TRUE, then dejitter instance will be freed in the destructor of this decoder.

OsStatus pushBuffer ( int  inputPort,
MpBufPtr inputBuffer 
)
virtual

MpResource::pushBuffer

Reimplemented from MpResource.

OsStatus pushPacket ( MpRtpBufPtr pRtp)

Add incoming RTP packet to the decoding queue.

Warning
This method swaps pRtp with some other packet in the dejitter buffer. So you should dispose pRtp pointer asap after calling this method.
Returns
OS_SUCCESS on success
OS_LIMIT_REACHED if too many codecs used in incoming RTP packets
void setConnectionId ( MpConnectionID  connectionId)
virtual

Set the ID of a connection this resource belongs to.

Warning
This method directly modifies resource structure.

Reimplemented from MpResource.

void setStreamId ( int  connectionId)
virtual

Set the ID of a stream inside of the connection this resource belongs to.

Warning
This method directly modifies resource structure.

Reimplemented from MpResource.

UtlContainableType getContainableType ( ) const

OsStatus getCurrentLatency ( int &  latency,
int  input = 0,
int  output = 0 
) const
virtual

Get current input to output latency (in samples)

Get given input to given output latency in samples.

This method is called from media processing loop and thus should not block.

Note
Resource may cache latency from the last processed frame interval or retrieve/calculate it at every call to this method. I think this freedom shouldn't affect precision in a considerable way. But it is not recommended to return average latency here.
Parameters
[out]latency- value of latency returned. Set to INF_LATENCY if this input does not send data to this output currently.
[in]input- input for data to return latency for. If set to ASSOCIATED_LATENCY, then input latency, associated with this resource to be returned. E.g. driver latency to be returned for MprFromInputDevice.
[in]output- output for data to return latency for. If set to ASSOCIATED_LATENCY, then output latency, associated with this resource to be returned. E.g. driver latency to be returned for MprToOutputDevice.
Return values
OS_SUCCESSif latency has been returned successfully.
OS_NOT_FOUNDif input or output are not connected.

Reimplemented from MpResource.

UtlBoolean doProcessFrame ( MpBufPtr  inBufs[],
MpBufPtr  outBufs[],
int  inBufsSize,
int  outBufsSize,
UtlBoolean  isEnabled,
int  samplesPerFrame,
int  samplesPerSecond 
)
privatevirtual

This method does the real work for the media processing resource and must be defined in each class derived from this one.

Parameters
inBufs(in) array of pointers to input buffers for the resource
outBufs(out) array of pointers to output buffers produce by the resource
inBufsSize(in) size of the inBufs array
outBufsSize(in) size of the outBufs array
isEnabled(in) indicates whether this resource has been enabled
samplesPerFrame(in) samples to produce per frame processing interval
samplesPerSecond(in) samples to produce per second
Returns
TRUE if successful, FALSE otherwise.

Implements MpAudioResource.

UtlBoolean tryDecodeAsSignalling ( const MpRtpBufPtr rtp)
private

Decode RTP packet if it belongs to signaling codec.

Return values
TRUE- packet was decoded as signaling
FALSE- packet is not signaling
OsStatus setFlowGraph ( MpFlowGraphBase pFlowGraph)
privatevirtual

Associates this resource with the indicated flow graph.

Parameters
[in]pFlowGraph- pointer to a flowgraph owning this resource.
Return values
OS_SUCCESS- for now, this method always returns success

Reimplemented from MpResource.

UtlBoolean handleMessage ( MpResourceMsg rMsg)
privatevirtual

Handle new style messages for this resource.

Reimplemented from MpResource.

UtlBoolean handleSelectCodecs ( SdpCodec *  pCodecs[],
int  numCodecs 
)
private

Replace mpCurrentCodecs with pCodecs.

Copy the codecs in mpCurrentCodecs onto mpPrevCodecs and deletes pCodecs.

UtlBoolean handleDeselectCodecs ( UtlBoolean  shouldLock = TRUE)
private

Remove all codecs from mpCurrentCodecs, transferring them to mpPrevCodecs.

UtlBoolean handleDeselectCodec ( MpDecoderBase pDecoder)
private

Remove one codec from mpConnection's payload type decoder table.

Note
Caller must hold mLock.
UtlBoolean handleSetPlc ( const UtlString &  plcName)
private

Change PLC algorithm to one provided.

UtlBoolean handleReset ( )
private

Handle MPRM_RESET message.

UtlBoolean handleDisable ( void  )
privatevirtual

perform the disable operation on the resource

Reimplemented from MpResource.

UtlBoolean handleSetVadParam ( UtlSerialized &  serialData)
private

Handle message to set VAD parameter.

void deletePriorCodecs ( )
private

Delete the array of previously used codecs.

MprDecode& operator= ( const MprDecode rhs)
private

Assignment operator (not implemented for this class)

Member Data Documentation

const UtlContainableType TYPE = "MprDecode"
static

Class name, used for run-time checks.

MpJitterBuffer* mpJB
private

Pointer to JitterBuffer instance.

UtlBoolean mIsJBInitialized
private

Is JB initialized or not?

MprDejitter* mpMyDJ
private

Dejitter instance, used by this decoder.

UtlBoolean mOwnDJ
private

Is dejitter owned by this decoder?

UtlBoolean mIsStreamInitialized
private

Have we received at least one packet?

struct MprDecode::StreamState mStreamState
private
RtpSeq mLastPulledSeq
private

Sequence number of last pulled packet.

MpJitterBufferEstimation* mpJbEstimationState
private

State of JB delay estimation.

MpDecoderBase** mpCurrentCodecs
private

List of the codecs to be used to decode media.

Pointer to array of length mNumCurrentCodecs of MpDecoderBase*'s which represent the codecs, or NULL if mNumCurrentCodecs == 0.

int mNumCurrentCodecs
private

Length of mpCurrentCodecs array.

UtlBoolean mEnableG722Hack
private

Should we cheat with RTP clock rate in case G.722 is selected. According to section 4.5.2 of RFC 3551 we should use 8K RTP clock rate instead of 16K for G.722 because of historical error in RFC 1890.

int mG722HackPayloadType
private

RTP payload type to which we should apply G.722 RTP clock rate workaround. Set to -1 if workaround is not enabled. See mEnableG722Hack for better description.

MpDecoderBase** mpPrevCodecs
private

Similar list of all codecs that have ever been listed on mpCurrentCodecs.

int mNumPrevCodecs
private

Length of mpPrevCodecs array.

MpDecoderPayloadMap mDecoderMap
private

Mapping of payload types to decoder instances.