sipxmedialib  Version 3.3
MpFlowGraphBase.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2013 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2008 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
8 // Licensed to SIPfoundry under a Contributor Agreement.
9 //
10 // $$
12 
13 
14 #ifndef _MpFlowGraphBase_h_
15 #define _MpFlowGraphBase_h_
16 
17 // SYSTEM INCLUDES
18 
19 #include "rtcp/RtcpConfig.h"
20 
21 // APPLICATION INCLUDES
22 #include <utl/UtlHashMap.h>
23 
24 #include "utl/UtlString.h"
25 #include "os/OsDefs.h"
26 #include "os/OsMsgQ.h"
27 #include "os/OsStatus.h"
28 #include "os/OsRWMutex.h"
29 #include "os/OsTime.h"
30 #include "mp/MpResource.h"
31 #include "os/OsMsgDispatcher.h"
33 #ifdef INCLUDE_RTCP /* [ */
34 #include "rtcp/RTCManager.h"
35 #endif /* INCLUDE_RTCP ] */
36 
37 // DEFINES
38 // MACROS
39 // EXTERNAL FUNCTIONS
40 // EXTERNAL VARIABLES
41 // CONSTANTS
42 // STRUCTS
43 // TYPEDEFS
44 
45 // FORWARD DECLARATIONS
46 class MpFlowGraphMsg;
47 class OsMsg;
48 
92 #ifdef INCLUDE_RTCP /* [ */
93  : public CBaseClass,
94  public IRTCPNotify
95 #endif /* INCLUDE_RTCP ] */
96 {
97 /* //////////////////////////// PUBLIC //////////////////////////////////// */
98 public:
99  friend OsStatus MpResource::postMessage(MpFlowGraphMsg& rMsg);
100 
101  typedef enum
102  {
105  } FlowGraphState;
106 
107  typedef enum
108  {
112  } FlowGraphType;
113  //: FlowGraph Types
114 
115 /* ============================ CREATORS ================================== */
117 
118 
121  int samplesPerSec = 0,
122  OsMsgDispatcher *pNotifDispatcher = NULL);
123 
125  virtual
127 
129 
130 /* ============================ MANIPULATORS ============================== */
132 
133  OsStatus addLink(MpResource& rFrom, int outPortIdx,
135  MpResource& rTo, int inPortIdx);
150  OsMsgDispatcher*
152  setNotificationDispatcher(OsMsgDispatcher* notifyDispatcher);
165  OsStatus addResource(MpResource& rResource, UtlBoolean makeNameUnique=TRUE);
181  OsStatus destroyResources(void);
192  OsStatus disable(void);
206  OsStatus enable(void);
220  virtual OsStatus gainFocus(void);
232  OsStatus insertResourceAfter(MpResource& rResource,
235  MpResource& rUpstreamResource,
236  int outPortIdx);
249  OsStatus insertResourceBefore(MpResource& rResource,
252  MpResource& rDownstreamResource,
253  int inPortIdx);
266  virtual OsStatus loseFocus(void);
278  virtual OsStatus postNotification(const MpResNotificationMsg& msg);
300  virtual OsStatus processNextFrame(void);
306  OsStatus removeLink(MpResource& rFrom, int outPortIdx);
318  OsStatus removeResource(MpResource& rResource);
329  OsStatus destroyResource(const UtlString& resourceName);
341  OsStatus setNotificationsEnabled(bool enabled,
343  const UtlString& resourceName = NULL);
344 
346  OsStatus start(void);
354  OsStatus stop(void);
364 
366  void synchronize(const char* tag=NULL, int val=0);
367 
368 /* ============================ ACCESSORS ================================= */
369 
371  static void flowGraphInfo(MpFlowGraphBase* pFlowGraph);
372 
374 
375  virtual FlowGraphType getType();
377 
379  inline int getSamplesPerFrame(void) const;
380 
382  inline int getSamplesPerSec(void) const;
383 
385  inline int getState(void) const;
386 
388  inline OsMsgDispatcher* getNotificationDispatcher() const;
389 
392  OsStatus lookupResource(const UtlString& name,
393  MpResource*& rpResource);
403  inline int numLinks(void) const;
405 
407  inline int numFramesProcessed(void) const;
408 
410  inline int numResources(void) const;
411 
413  inline OsMsgQ* getMsgQ(void) ;
414 
416  inline int getFlowgraphNum() const;
417 
419  inline UtlString getFlowgraphName() const;
420 
422  OsStatus getLatencyForPath(MpResource *pStartResource,
423  int startResourceInput,
424  const UtlString &endResourceName,
425  int endResourceOutput,
426  UtlBoolean includeEndResourceLatency,
427  int &latency);
451  OsStatus getLatencyForPathReverse(MpResource *pStartResource,
453  int startResourceOutput,
454  const UtlString &endResourceName,
455  int endResourceInput,
456  UtlBoolean includeEndResourceLatency,
457  int &latency);
465 #ifdef INCLUDE_RTCP /* [ */
466  IRTCPSession* getRTCPSessionPtr(void);
468 
469  IRTCPConnection* getRTCPConnectionPtr(MpConnectionID connId, int mediaType, int streamId);
470 
471 #endif /* INCLUDE_RTCP ] */
472 
473 
474 
476 
477 /* ============================ INQUIRY =================================== */
479 
480 
482  UtlBoolean isStarted(void) const;
489 
490 /* ============================ CALLBACKS ================================= */
491 #ifdef INCLUDE_RTCP /* [ */
492 
511  unsigned long GetEventInterest(void);
512 
534  void LocalSSRCCollision(IRTCPConnection *piRTCPConnection,
535  IRTCPSession *piRTCPSession);
536 
537 
559  void RemoteSSRCCollision(IRTCPConnection *piRTCPConnection,
560  IRTCPSession *piRTCPSession);
561 
562 
582 #endif /* INCLUDE_RTCP ] */
583 /* //////////////////////////// PROTECTED ///////////////////////////////// */
584 protected:
585  OsRWMutex mRWMutex; // reader/writer lock for synchronization
586 
588  virtual OsStatus postMessage(const MpFlowGraphMsg& rMsg,
589  const OsTime& rTimeout=OsTime::OS_INFINITY);
594  virtual UtlBoolean handleMessage(OsMsg& rMsg);
601  UtlBoolean handleRemoveLink(MpResource* pFrom, int outPortIdx);
608  UtlBoolean handleRemoveResource(MpResource* pResource);
615  UtlBoolean handleDestroyResource(const UtlString &name);
622  UtlBoolean handleSynchronize(MpFlowGraphMsg& rMsg);
629 /* //////////////////////////// PRIVATE /////////////////////////////////// */
630 private:
631 
632  enum { MAX_FLOWGRAPH_MESSAGES = 150};
634 
635  static int gFgMaxNumber;
636  int mFgNumber;
638 
640  UtlHashMap mResourceDict;
643  int mCurState;
644  OsMsgQ mMessages;
645  OsMsgDispatcher* mNotifyDispatcher;
647  int mLinkCnt;
649  UtlBoolean mRecomputeOrder;
653  static const OsTime smProcessMessagesTimeout;
655 
657 #ifdef INCLUDE_RTCP /* [ */
658  int hashRtcpConnection(MpConnectionID connId, int mediaType, int streamId);
659  UtlBoolean createRtcpConnection(MpConnectionID connId, int mediaType, int streamId);
660  UtlBoolean deleteRtcpConnection(MpConnectionID connId, int mediaType, int streamId);
661 
662  IRTCPSession* mpiRTCPSession;
664  unsigned long mulEventInterest;
665  OsMutex mRtcpConnMutex;
666  UtlHashMap mRtcpConnMap;
667 #endif /* INCLUDE_RTCP ] */
668 
669 
672  OsStatus computeOrder(void);
678  int getExecOrderIndex(const MpResource* resource) const;
685  UtlBoolean disconnectAllInputs(MpResource* pResource);
693  UtlBoolean disconnectAllOutputs(MpResource* pResource);
701  UtlBoolean handleAddLink(MpResource* pFrom, int outPortIdx,
703  MpResource* pTo, int inPortIdx);
709  UtlBoolean handleAddResource(MpResource* pResource,
711  UtlBoolean makeNameUnique);
717  UtlBoolean handleDestroyResources(void);
724  UtlBoolean handleDisable(void);
731  UtlBoolean handleEnable(void);
738  UtlBoolean handleStart(void);
745  UtlBoolean handleStop(void);
752  OsStatus handleGetLatencyForPath(MpResource *pStartResource,
754  int startResourceInput,
755  const UtlString &endResourceName,
756  int endResourceOutput,
757  UtlBoolean includeEndResourceLatency,
758  int &latency);
759 
761  OsStatus handleGetLatencyForPathReverse(MpResource *pStartResource,
762  int startResourceOutput,
763  const UtlString &endResourceName,
764  int endResourceInput,
765  UtlBoolean includeEndResourceLatency,
766  int &latency);
767 
770  OsStatus lookupResourcePrivate(const UtlString& name,
771  MpResource*& rpResource);
787  OsStatus processMessages(void);
793  MpFlowGraphBase(const MpFlowGraphBase& rMpFlowGraph);
795 
798 
799 };
800 
801 /* ============================ INLINE METHODS ============================ */
802 
804 {
805  return mSamplesPerFrame;
806 }
807 
809 {
810  return mSamplesPerSec;
811 }
812 
814 {
815  return mCurState;
816 }
817 
818 OsMsgDispatcher* MpFlowGraphBase::getNotificationDispatcher(void) const
819 {
820  return mNotifyDispatcher;
821 }
822 
824 {
825  return mLinkCnt;
826 }
827 
829 {
830  return mPeriodCnt;
831 }
832 
834 {
835  return mResourceCnt;
836 }
837 
839 {
840  return &mMessages ;
841 }
842 
844 {
845  return mFgNumber;
846 }
847 
849 {
850  char tmpStr[10];
851  snprintf(tmpStr, sizeof(tmpStr), "FG%d", getFlowgraphNum());
852  return tmpStr;
853 }
854 
855 #ifdef INCLUDE_RTCP /* [ */
856 inline IRTCPSession *MpFlowGraphBase::getRTCPSessionPtr(void)
857 {
858  return(mpiRTCPSession);
859 }
860 
861 
862 
881 inline unsigned long MpFlowGraphBase::GetEventInterest(void)
882 {
883 
884  return(mulEventInterest);
885 }
886 #endif /* INCLUDE_RTCP ] */
887 
888 #endif // _MpFlowGraphBase_h_
UtlBoolean handleSynchronize(MpFlowGraphMsg &rMsg)
Handle the FLOWGRAPH_SYNCHRONIZE message.
Definition: MpFlowGraphBase.cpp:1304
Message object used to communicate with the media processing task.
Definition: MpFlowGraphMsg.h:33
UtlBoolean handleDestroyResource(const UtlString &name)
Handle the FLOWGRAPH_DESTROY_RESOURCE message.
Definition: MpFlowGraphBase.cpp:1672
UtlString getFlowgraphName() const
Get flowgraph&#39;s name based on its sequence number (use for debug purposes only!)
Definition: MpFlowGraphBase.h:848
int mPeriodCnt
number of frames processed by this flow graph
Definition: MpFlowGraphBase.h:646
Definition: MpFlowGraphBase.h:110
int mCurState
current flow graph state
Definition: MpFlowGraphBase.h:643
UtlBoolean disconnectAllInputs(MpResource *pResource)
Disconnects all inputs (and the corresponding upstream outputs) for the indicated resource...
Definition: MpFlowGraphBase.cpp:1114
virtual OsStatus postMessage(const MpFlowGraphMsg &rMsg, const OsTime &rTimeout=OsTime::OS_INFINITY)
Posts a message to this flow graph.
Definition: MpFlowGraphBase.cpp:1846
virtual OsStatus loseFocus(void)
Informs the flow graph that it has lost the MpMediaTask focus.
Definition: MpFlowGraphBase.cpp:473
UtlBoolean handleDestroyResources(void)
Handle the FLOWGRAPH_DESTROY_RESOURCES message.
Definition: MpFlowGraphBase.cpp:1435
int samplesPerFrame
Definition: MpFlowGraphBase.h:111
MpFlowGraphBase & operator=(const MpFlowGraphBase &rhs)
Assignment operator (not implemented for this task)
MpResource * mExecOrder[MAX_FLOWGRAPH_RESOURCES]
resource execution order
Definition: MpFlowGraphBase.h:641
OsStatus computeOrder(void)
Computes the execution order for the flow graph by performing a topological sort on the resource grap...
Definition: MpFlowGraphBase.cpp:1083
virtual UtlBoolean handleMessage(OsMsg &rMsg)
Handles an incoming message for the flow graph.
Definition: MpFlowGraphBase.cpp:1165
virtual OsStatus postNotification(const MpResNotificationMsg &msg)
posts a resource notification message to the Notification dispatcher.
Definition: MpFlowGraphBase.cpp:480
int mSamplesPerSec
number of samples per second
Definition: MpFlowGraphBase.h:651
int getExecOrderIndex(const MpResource *resource) const
Find the index of the given resource in the compute order array.
Definition: MpFlowGraphBase.cpp:1097
Definition: MpFlowGraphBase.h:632
UtlHashMap mResourceDict
resource dictionary
Definition: MpFlowGraphBase.h:640
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.
Definition: MpFlowGraphBase.cpp:959
OsStatus destroyResource(const UtlString &resourceName)
Removes the indicated media processing object from the flowgraph and destroys it. ...
Definition: MpFlowGraphBase.cpp:632
OsMsgQ mMessages
message queue for this flow graph
Definition: MpFlowGraphBase.h:644
FlowGraphState
Definition: MpFlowGraphBase.h:101
int getState(void) const
Returns the current state of flow graph.
Definition: MpFlowGraphBase.h:813
virtual ~MpFlowGraphBase()
Destructor.
Definition: MpFlowGraphBase.cpp:110
Flow graph for coordinating the execution of media processing resources.
Definition: MpFlowGraphBase.h:91
OsStatus disable(void)
Invokes the disable() method for each resource in the flow graph.
Definition: MpFlowGraphBase.cpp:294
int getFlowgraphNum() const
Get flowgraph&#39;s sequence number (use for debug purposes only!)
Definition: MpFlowGraphBase.h:843
int numResources(void) const
Returns the number of resources in the flow graph.
Definition: MpFlowGraphBase.h:833
flow graph has been started (is processing media streams)
Definition: MpFlowGraphBase.h:103
UtlBoolean isStarted(void) const
Is flow graph in STARTED state.
Definition: MpFlowGraphBase.cpp:1070
OsStatus setNotificationsEnabled(bool enabled, const UtlString &resourceName=NULL)
Definition: MpFlowGraphBase.cpp:650
int numFramesProcessed(void) const
Returns the number of frames this flow graph has processed.
Definition: MpFlowGraphBase.h:828
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 ...
Definition: MpFlowGraphBase.cpp:935
OsStatus destroyResources(void)
Stops the flow graph, removes all of the resources in the flow graph and destroys them...
Definition: MpFlowGraphBase.cpp:270
UtlBoolean handleRemoveLink(MpResource *pFrom, int outPortIdx)
Handle the FLOWGRAPH_REMOVE_LINK message.
Definition: MpFlowGraphBase.cpp:1540
UtlBoolean handleEnable(void)
Handle the FLOWGRAPH_ENABLE message.
Definition: MpFlowGraphBase.cpp:1513
Definition: MpFlowGraphBase.h:633
OsStatus addResource(MpResource &rResource, UtlBoolean makeNameUnique=TRUE)
Adds the indicated media processing object to the flow graph.
Definition: MpFlowGraphBase.cpp:234
Definition: MpFlowGraphBase.h:109
UtlBoolean handleRemoveResource(MpResource *pResource)
Handle the FLOWGRAPH_REMOVE_RESOURCE message.
Definition: MpFlowGraphBase.cpp:1583
int mSamplesPerFrame
number of samples per frame
Definition: MpFlowGraphBase.h:650
int getSamplesPerFrame(void) const
Returns the number of samples expected per frame.
Definition: MpFlowGraphBase.h:803
UtlBoolean handleAddLink(MpResource *pFrom, int outPortIdx, MpResource *pTo, int inPortIdx)
Handle the FLOWGRAPH_ADD_LINK message.
Definition: MpFlowGraphBase.cpp:1333
OsStatus handleGetLatencyForPathReverse(MpResource *pStartResource, int startResourceOutput, const UtlString &endResourceName, int endResourceInput, UtlBoolean includeEndResourceLatency, int &latency)
Do the real work for getLatencyForPathReverse()
Definition: MpFlowGraphBase.cpp:1778
int getSamplesPerSec(void) const
Returns the number of samples expected per second.
Definition: MpFlowGraphBase.h:808
virtual void RemoteSSRCCollision(IRTCPConnection *piRTCPConnection=NULL, IRTCPSession *piRTCPSession=NULL)
Definition: IRTCPNotify.h:401
OsStatus start(void)
Start this flow graph.
Definition: MpFlowGraphBase.cpp:683
UtlBoolean handleAddResource(MpResource *pResource, UtlBoolean makeNameUnique)
Handle the FLOWGRAPH_ADD_RESOURCE message.
Definition: MpFlowGraphBase.cpp:1388
OsStatus stop(void)
Stop this flow graph.
Definition: MpFlowGraphBase.cpp:701
OsStatus insertResourceBefore(MpResource &rResource, MpResource &rDownstreamResource, int inPortIdx)
Definition: MpFlowGraphBase.cpp:416
virtual OsStatus processNextFrame(void)
Processes the next frame interval&#39;s worth of media for the flow graph.
Definition: MpFlowGraphBase.cpp:496
FlowGraphType
Definition: MpFlowGraphBase.h:107
static int gFgMaxNumber
mFgNumber (for debug purposes only!)
Definition: MpFlowGraphBase.h:635
MpFlowGraphBase(int samplesPerFrame=0, int samplesPerSec=0, OsMsgDispatcher *pNotifDispatcher=NULL)
Constructor.
Definition: MpFlowGraphBase.cpp:54
MpResource * mpResourceInProcess
For debugging, keep track of what.
Definition: MpFlowGraphBase.h:652
virtual OsStatus gainFocus(void)
Informs the flow graph that it now has the MpMediaTask focus.
Definition: MpFlowGraphBase.cpp:337
OsStatus processMessages(void)
Processes all of the messages currently queued for this flow graph.
Definition: MpFlowGraphBase.cpp:1857
UtlBoolean mRecomputeOrder
TRUE ==> the execution order needs computing.
Definition: MpFlowGraphBase.h:649
OsStatus enable(void)
Invokes the enable() method for each resource in the flow graph.
Definition: MpFlowGraphBase.cpp:318
flow graph is stopped (not processing media streams)
Definition: MpFlowGraphBase.h:104
MpResource * mUnsorted[MAX_FLOWGRAPH_RESOURCES]
unsorted resources
Definition: MpFlowGraphBase.h:642
Definition: MpResNotificationMsg.h:31
int mFgNumber
Definition: MpFlowGraphBase.h:637
#define DECLARE_IBASE_M
Definition: BaseClass.h:368
int mLinkCnt
number of links in this flow graph
Definition: MpFlowGraphBase.h:647
int numLinks(void) const
Returns the number of links in the flow graph.
Definition: MpFlowGraphBase.h:823
OsMsgDispatcher * mNotifyDispatcher
Dispatcher for notification messages.
Definition: MpFlowGraphBase.h:645
static const OsTime smProcessMessagesTimeout
from the flowgraph queue.
Definition: MpFlowGraphBase.h:654
OsMsgDispatcher * getNotificationDispatcher() const
Returns the current notification dispatcher, if any. If none, returns NULL.
Definition: MpFlowGraphBase.h:818
void synchronize(const char *tag=NULL, int val=0)
Sends a message to self, and waits for reply.
Definition: MpFlowGraphBase.cpp:711
UtlBoolean handleStop(void)
Handle the FLOWGRAPH_STOP message.
Definition: MpFlowGraphBase.cpp:1704
Definition: BaseClass.h:118
OsStatus removeLink(MpResource &rFrom, int outPortIdx)
Removes the link between the outPortIdx port of the rFrom resource and its downstream counterpart...
Definition: MpFlowGraphBase.cpp:587
OsStatus lookupResourcePrivate(const UtlString &name, MpResource *&rpResource)
Sets rpResource to point to the resource that corresponds to name or to NULL if no matching resource ...
Definition: MpFlowGraphBase.cpp:945
#define INCLUDE_RTCP
Definition: RtcpConfig.h:55
virtual void LocalSSRCCollision(IRTCPConnection *piRTCPConnection=NULL, IRTCPSession *piRTCPSession=NULL)
Definition: IRTCPNotify.h:376
int MpConnectionID
Flowgraph connection ID.
Definition: MpTypes.h:56
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.
Definition: MpFlowGraphBase.cpp:1013
OsStatus insertResourceAfter(MpResource &rResource, MpResource &rUpstreamResource, int outPortIdx)
Inserts rResource into the flow graph downstream of the designated rUpstreamResource resource...
Definition: MpFlowGraphBase.cpp:352
UtlBoolean handleStart(void)
Handle the FLOWGRAPH_START message.
Definition: MpFlowGraphBase.cpp:1695
OsRWMutex mRWMutex
Definition: MpFlowGraphBase.h:585
OsMsgDispatcher * setNotificationDispatcher(OsMsgDispatcher *notifyDispatcher)
Adds a dispatcher for notifications to the flowgraph.
Definition: MpFlowGraphBase.cpp:218
int mResourceCnt
number of resources in this flow graph
Definition: MpFlowGraphBase.h:648
Abstract base class for all media processing objects.
Definition: MpResource.h:56
OsStatus handleGetLatencyForPath(MpResource *pStartResource, int startResourceInput, const UtlString &endResourceName, int endResourceOutput, UtlBoolean includeEndResourceLatency, int &latency)
Do the real work for getLatencyForPath()
Definition: MpFlowGraphBase.cpp:1712
UtlBoolean disconnectAllOutputs(MpResource *pResource)
Disconnects all outputs (and the corresponding downstream inputs) for the indicated resource...
Definition: MpFlowGraphBase.cpp:1141
virtual FlowGraphType getType()
Returns the type of this flow graph.
Definition: MpFlowGraphBase.cpp:879
#define TRUE
Definition: PlgDefsV1.h:41
OsStatus removeResource(MpResource &rResource)
Removes the indicated media processing object from the flow graph.
Definition: MpFlowGraphBase.cpp:614
OsMsgQ * getMsgQ(void)
Returns the message queue used by the flow graph.
Definition: MpFlowGraphBase.h:838
OsStatus postMessage(MpFlowGraphMsg &rMsg)
Post a message from this resource.
Definition: MpResource.cpp:678
UtlBoolean handleDisable(void)
Handle the FLOWGRAPH_DISABLE message.
Definition: MpFlowGraphBase.cpp:1486
OsStatus addLink(MpResource &rFrom, int outPortIdx, MpResource &rTo, int inPortIdx)
Creates a link between resources.
Definition: MpFlowGraphBase.cpp:182
static void flowGraphInfo(MpFlowGraphBase *pFlowGraph)
Displays information on the console about the specified flow graph.
Definition: MpFlowGraphBase.cpp:886