sipxmedialib  Version 3.3
Protected Member Functions | Private Member Functions | Private Attributes | List of all members
MpTopologyGraph Class Reference

Flowgraph with resources wired as defined in given topology and factory. More...

#include <MpTopologyGraph.h>

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

Public Member Functions

Creators
 MpTopologyGraph (int samplesPerFrame, int samplesPerSec, MpResourceTopology &initialResourceTopology, MpResourceFactory &resourceFactory, OsMsgDispatcher *pNotifDispatcher=NULL)
 Constructor. More...
 
virtual ~MpTopologyGraph ()
 Destructor. More...
 
Manipulators
OsStatus addResources (MpResourceTopology &incrementalTopology, MpResourceFactory *resourceFactory, int resourceInstanceId)
 Add resource to the existing flowgraph as defined by given topology and optional factory. More...
 
OsStatus destroyResources (MpResourceTopology &resourceTopology, int resourceInstanceId)
 Delete resources from existing flowgraph as defined by given topology. More...
 
virtual OsStatus processNextFrame ()
 Extended processNextFrame() for diagnostic reasons. More...
 
virtual OsStatus gainFocus ()
 Informs the flow graph that it now has the MpMediaTask focus. More...
 
virtual OsStatus loseFocus ()
 Informs the flow graph that it has lost the MpMediaTask focus. More...
 
Accessors
MpFlowGraphBase::FlowGraphType getType ()
 
OsStatus lookupVirtualInput (const UtlString &virtualName, int virtualPortIdx, MpResource *&rpResource, int &portIdx)
 Lookup real input port corresponding to given virtual one. More...
 
OsStatus lookupVirtualOutput (const UtlString &virtualName, int virtualPortIdx, MpResource *&rpResource, int &portIdx)
 Lookup real output port corresponding to given virtual one. More...
 
OsStatus lookupInput (const UtlString &resourceName, int portIdx, MpResource *&pFoundResource, int &foundPortIdx)
 Lookup real or virtual input port. More...
 
OsStatus lookupOutput (const UtlString &resourceName, int portIdx, MpResource *&pFoundResource, int &foundPortIdx)
 Lookup real or virtual output port. More...
 
- Public Member Functions inherited from MpFlowGraphBase
void synchronize (const char *tag=NULL, int val=0)
 Sends a message to self, and waits for reply. More...
 
 MpFlowGraphBase (int samplesPerFrame=0, int samplesPerSec=0, OsMsgDispatcher *pNotifDispatcher=NULL)
 Constructor. More...
 
virtual ~MpFlowGraphBase ()
 Destructor. More...
 
OsStatus addLink (MpResource &rFrom, int outPortIdx, MpResource &rTo, int inPortIdx)
 Creates a link between resources. More...
 
OsMsgDispatcher * setNotificationDispatcher (OsMsgDispatcher *notifyDispatcher)
 Adds a dispatcher for notifications to the flowgraph. More...
 
OsStatus addResource (MpResource &rResource, UtlBoolean makeNameUnique=TRUE)
 Adds the indicated media processing object to the flow graph. More...
 
OsStatus destroyResources (void)
 Stops the flow graph, removes all of the resources in the flow graph and destroys them. More...
 
OsStatus disable (void)
 Invokes the disable() method for each resource in the flow graph. More...
 
OsStatus enable (void)
 Invokes the enable() method for each resource in the flow graph. More...
 
OsStatus insertResourceAfter (MpResource &rResource, MpResource &rUpstreamResource, int outPortIdx)
 Inserts rResource into the flow graph downstream of the designated rUpstreamResource resource. More...
 
OsStatus insertResourceBefore (MpResource &rResource, MpResource &rDownstreamResource, int inPortIdx)
 
virtual OsStatus postNotification (const MpResNotificationMsg &msg)
 posts a resource notification message to the Notification dispatcher. More...
 
OsStatus removeLink (MpResource &rFrom, int outPortIdx)
 Removes the link between the outPortIdx port of the rFrom resource and its downstream counterpart. More...
 
OsStatus removeResource (MpResource &rResource)
 Removes the indicated media processing object from the flow graph. More...
 
OsStatus destroyResource (const UtlString &resourceName)
 Removes the indicated media processing object from the flowgraph and destroys it. More...
 
OsStatus setNotificationsEnabled (bool enabled, const UtlString &resourceName=NULL)
 
OsStatus start (void)
 Start this flow graph. More...
 
OsStatus stop (void)
 Stop this flow graph. More...
 
int getSamplesPerFrame (void) const
 Returns the number of samples expected per frame. More...
 
int getSamplesPerSec (void) const
 Returns the number of samples expected per second. More...
 
int getState (void) const
 Returns the current state of flow graph. More...
 
OsMsgDispatcher * getNotificationDispatcher () const
 Returns the current notification dispatcher, if any. If none, returns NULL. More...
 
OsStatus lookupResource (const UtlString &name, MpResource *&rpResource)
 Sets rpResource to point to the resource that corresponds to name or to NULL if no matching resource is found. More...
 
int numLinks (void) const
 Returns the number of links in the flow graph. More...
 
int numFramesProcessed (void) const
 Returns the number of frames this flow graph has processed. More...
 
int numResources (void) const
 Returns the number of resources in the flow graph. More...
 
OsMsgQ * getMsgQ (void)
 Returns the message queue used by the flow graph. More...
 
int getFlowgraphNum () const
 Get flowgraph's sequence number (use for debug purposes only!) More...
 
UtlString getFlowgraphName () const
 Get flowgraph's name based on its sequence number (use for debug purposes only!) More...
 
OsStatus getLatencyForPath (MpResource *pStartResource, int startResourceInput, const UtlString &endResourceName, int endResourceOutput, UtlBoolean includeEndResourceLatency, int &latency)
 Get latency for main path from one resource to another in forward direction. More...
 
OsStatus getLatencyForPathReverse (MpResource *pStartResource, int startResourceOutput, const UtlString &endResourceName, int endResourceInput, UtlBoolean includeEndResourceLatency, int &latency)
 Get latency for main path from one resource to another in reverse direction. More...
 
UtlBoolean isStarted (void) const
 Is flow graph in STARTED state. More...
 

Protected Member Functions

virtual OsStatus postMessage (const MpFlowGraphMsg &message, const OsTime &waitTime=OsTime::OS_INFINITY)
 Post a message to be handled by this flowgraph. More...
 
virtual UtlBoolean handleMessage (OsMsg &message)
 Handle a message for this flowgraph. More...
 
- Protected Member Functions inherited from MpFlowGraphBase
UtlBoolean handleRemoveLink (MpResource *pFrom, int outPortIdx)
 Handle the FLOWGRAPH_REMOVE_LINK message. More...
 
UtlBoolean handleRemoveResource (MpResource *pResource)
 Handle the FLOWGRAPH_REMOVE_RESOURCE message. More...
 
UtlBoolean handleDestroyResource (const UtlString &name)
 Handle the FLOWGRAPH_DESTROY_RESOURCE message. More...
 
UtlBoolean handleSynchronize (MpFlowGraphMsg &rMsg)
 Handle the FLOWGRAPH_SYNCHRONIZE message. More...
 

Private Member Functions

int addTopologyResources (MpResourceTopology &resourceTopology, MpResourceFactory &resourceFactory, UtlHashBag &newResources, UtlBoolean replaceNumInName=FALSE, int resourceNum=-1)
 Adds all new resources defined in a topology. More...
 
int addVirtualInputs (MpResourceTopology &resourceTopology, UtlHashBag &newResources, UtlBoolean replaceNumInName=FALSE, int resourceNum=-1)
 Adds all virtual inputs defined in a topology. More...
 
int removeVirtualInputs (MpResourceTopology &resourceTopology, UtlBoolean replaceNumInName, int resourceNum)
 Remove all virtual inputs defined in a topology from the flowgraph. More...
 
int addVirtualOutputs (MpResourceTopology &resourceTopology, UtlHashBag &newResources, UtlBoolean replaceNumInName=FALSE, int resourceNum=-1)
 Adds all virtual outputs defined in a topology. More...
 
int removeVirtualOutputs (MpResourceTopology &resourceTopology, UtlBoolean replaceNumInName, int resourceNum)
 Remove all virtual outputs defined in a topology from the flowgraph. More...
 
int linkTopologyResources (MpResourceTopology &resourceTopology, UtlHashBag &newResources, UtlBoolean replaceNumInName=FALSE, int resourceNum=-1)
 Adds links defined for resources in resource topology. More...
 
 MpTopologyGraph (const MpTopologyGraph &rMpTopologyGraph)
 Disabled copy constructor. More...
 
MpTopologyGraphoperator= (const MpTopologyGraph &rhs)
 Disable assignment operator. More...
 

Private Attributes

MpResourceFactorympResourceFactory
 Factory for resources. More...
 
UtlHashMap mVirtualInputs
 Virtual inputs mapping to real inputs. More...
 
UtlHashMap mVirtualOutputs
 Virtual outputs mapping to real outputs. More...
 

Additional Inherited Members

- Public Types inherited from MpFlowGraphBase
enum  FlowGraphState { STARTED, STOPPED }
 
enum  FlowGraphType { BASE_FLOWGRAPH = 0, CALL_FLOWGRAPH = 1, TOPOLOGY_FLOWGRAPH = 2 }
 
- Static Public Member Functions inherited from MpFlowGraphBase
static void flowGraphInfo (MpFlowGraphBase *pFlowGraph)
 Displays information on the console about the specified flow graph. More...
 
- Protected Attributes inherited from MpFlowGraphBase
OsRWMutex mRWMutex
 

Detailed Description

Flowgraph with resources wired as defined in given topology and factory.

The MpTopologyGraph is a MpFlowGraphBase which is constructed with resources connected as defined by the given MpResourceTopology. The resources are constructed using the given MpResourceFactory. This allows for a flexible construction of flowgraphs containing different resources, connected in a custom (as opposed to hardcoded) graph topology.

To keep this flowgraph independent of specific resources and topologies all operations on existing resources must be performed via message passing (the message queue is obtained via getMsgQ). The messages are either handled by the flowgraph or dispatched to the resource named in the message. See the specific resource for the types of messages and operations that can be performed on the resource. See MpResource for more information on the message format and performing operations on resources using message passing.

Constructor & Destructor Documentation

MpTopologyGraph ( int  samplesPerFrame,
int  samplesPerSec,
MpResourceTopology initialResourceTopology,
MpResourceFactory resourceFactory,
OsMsgDispatcher *  pNotifDispatcher = NULL 
)

Constructor.

~MpTopologyGraph ( )
virtual

Destructor.

MpTopologyGraph ( const MpTopologyGraph rMpTopologyGraph)
private

Disabled copy constructor.

Member Function Documentation

OsStatus addResources ( MpResourceTopology incrementalTopology,
MpResourceFactory resourceFactory,
int  resourceInstanceId 
)

Add resource to the existing flowgraph as defined by given topology and optional factory.

If the resourceFactory is NULL, the factory provided when constructing this flowgraph is used as the default factory.

Parameters
[in]incrementalTopology- defines the resources to be added to the flowgraph and the order in which they are connected.
[in]resourceFactory- factory to construct the resources added named in the incrementalTopology
[in]resourceInstanceId- instance ID to be used to make resource names unique in the flowgraph.
Returns
OS_SUCCESS always.
OsStatus destroyResources ( MpResourceTopology resourceTopology,
int  resourceInstanceId 
)

Delete resources from existing flowgraph as defined by given topology.

Warning
At the moment resourceTopology must not contain "paired" resources, that is resource, whose constructor returns two or more resource instances.
Parameters
[in]incrementalTopology- defines the resources to be deleted from the flowgraph.
[in]resourceInstanceId- instance ID used to make resource names unique in the flowgraph.
Returns
OS_SUCCESS always.
OsStatus processNextFrame ( void  )
virtual

Extended processNextFrame() for diagnostic reasons.

Reimplemented from MpFlowGraphBase.

OsStatus gainFocus ( void  )
virtual

Informs the flow graph that it now has the MpMediaTask focus.

Only the flow graph that has the focus is permitted to access the audio hardware. This may only be called if this flow graph is managed and started. Also this call is meaningful only if local audio is enabled for this flowgraph.

Return values
OS_SUCCESSon success
OS_FAILEDif flowgraph does not support setting focus.

Reimplemented from MpFlowGraphBase.

OsStatus loseFocus ( void  )
virtual

Informs the flow graph that it has lost the MpMediaTask focus.

Only the flow graph that has the focus is permitted to access the audio hardware. This may only be called if this flow graph is managed and started. Also this call is meaningful only if local audio is enabled for this flowgraph.

Return values
OS_SUCCESSon success
OS_FAILEDif flowgraph does not support setting focus.

Reimplemented from MpFlowGraphBase.

MpFlowGraphBase::FlowGraphType getType ( )
virtual

Reimplemented from MpFlowGraphBase.

OsStatus lookupVirtualInput ( const UtlString &  virtualName,
int  virtualPortIdx,
MpResource *&  rpResource,
int &  portIdx 
)

Lookup real input port corresponding to given virtual one.

Parameters
[in]virtualName- resource name of the virtual input port.
[in]virtualPortIdx- port index of the virtual input port.
[out]rpResource- pointer to a resource, corresponding to the virtual port. Value is undefined if virtual port is not found.
[out]portIdx- input port index on rpResource corresponding to the virtual port. Value is undefined if virtual port is not found.
Return values
OS_SUCCESSif virtual port is found.
OS_NOT_FOUNDif virtual resource is not found.
OsStatus lookupVirtualOutput ( const UtlString &  virtualName,
int  virtualPortIdx,
MpResource *&  rpResource,
int &  portIdx 
)

Lookup real output port corresponding to given virtual one.

Parameters
[in]virtualName- resource name of the virtual output port.
[in]virtualPortIdx- port index of the virtual output port.
[out]rpResource- pointer to a resource, corresponding to the virtual port. Value is undefined if virtual port is not found.
[out]portIdx- output port index on rpResource corresponding to the virtual port. Value is undefined if virtual port is not found.
Return values
OS_SUCCESSif virtual port is found.
OS_NOT_FOUNDif virtual resource is not found.
OsStatus lookupInput ( const UtlString &  resourceName,
int  portIdx,
MpResource *&  pFoundResource,
int &  foundPortIdx 
)

Lookup real or virtual input port.

This method tries to search for real resource with given name. If real resource is not found it then tries to search for virtual port with given name/portIdx pair.

Parameters
[in]resourceName- resource name to look for.
[in]portIdx- input port index to look for.
[out]pFoundResource- found resource. Value is undefined if port is not found.
[out]foundPortIdx- found port index. Value is undefined if port is not found.
Return values
OS_SUCCESSif port is found.
OS_NOT_FOUNDif port is not found.
OsStatus lookupOutput ( const UtlString &  resourceName,
int  portIdx,
MpResource *&  pFoundResource,
int &  foundPortIdx 
)

Lookup real or virtual output port.

This method tries to search for real resource with given name. If real resource is not found it then tries to search for virtual port with given name/portIdx pair.

Parameters
[in]resourceName- resource name to look for.
[in]portIdx- output port index to look for.
[out]pFoundResource- found resource. Value is undefined if port is not found.
[out]foundPortIdx- found port index. Value is undefined if port is not found.
Return values
OS_SUCCESSif port is found.
OS_NOT_FOUNDif port is not found.
OsStatus postMessage ( const MpFlowGraphMsg message,
const OsTime &  waitTime = OsTime::OS_INFINITY 
)
protectedvirtual

Post a message to be handled by this flowgraph.

Reimplemented from MpFlowGraphBase.

UtlBoolean handleMessage ( OsMsg &  message)
protectedvirtual

Handle a message for this flowgraph.

Reimplemented from MpFlowGraphBase.

int addTopologyResources ( MpResourceTopology resourceTopology,
MpResourceFactory resourceFactory,
UtlHashBag &  newResources,
UtlBoolean  replaceNumInName = FALSE,
int  resourceNum = -1 
)
private

Adds all new resources defined in a topology.

int addVirtualInputs ( MpResourceTopology resourceTopology,
UtlHashBag &  newResources,
UtlBoolean  replaceNumInName = FALSE,
int  resourceNum = -1 
)
private

Adds all virtual inputs defined in a topology.

int removeVirtualInputs ( MpResourceTopology resourceTopology,
UtlBoolean  replaceNumInName,
int  resourceNum 
)
private

Remove all virtual inputs defined in a topology from the flowgraph.

int addVirtualOutputs ( MpResourceTopology resourceTopology,
UtlHashBag &  newResources,
UtlBoolean  replaceNumInName = FALSE,
int  resourceNum = -1 
)
private

Adds all virtual outputs defined in a topology.

int removeVirtualOutputs ( MpResourceTopology resourceTopology,
UtlBoolean  replaceNumInName,
int  resourceNum 
)
private

Remove all virtual outputs defined in a topology from the flowgraph.

int linkTopologyResources ( MpResourceTopology resourceTopology,
UtlHashBag &  newResources,
UtlBoolean  replaceNumInName = FALSE,
int  resourceNum = -1 
)
private

Adds links defined for resources in resource topology.

MpTopologyGraph& operator= ( const MpTopologyGraph rhs)
private

Disable assignment operator.

Member Data Documentation

MpResourceFactory* mpResourceFactory
private

Factory for resources.

UtlHashMap mVirtualInputs
private

Virtual inputs mapping to real inputs.

UtlHashMap mVirtualOutputs
private

Virtual outputs mapping to real outputs.