sipxmedialib  Version 3.3
MpResource.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2013 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2007 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 _MpResource_h_
15 #define _MpResource_h_
16 
17 // SYSTEM INCLUDES
18 // APPLICATION INCLUDES
19 #include "os/OsDefs.h"
20 #include "os/OsRWMutex.h"
21 #include "os/OsStatus.h"
22 #include "os/OsMsgQ.h"
23 #include "utl/UtlContainable.h"
24 #include "utl/UtlString.h"
25 #include "mp/MpBuf.h"
27 
28 // DEFINES
29 // MACROS
30 // EXTERNAL FUNCTIONS
31 // EXTERNAL VARIABLES
32 // CONSTANTS
33 // STRUCTS
34 // TYPEDEFS
35 // FORWARD DECLARATIONS
36 class MpFlowGraphBase;
37 class MpFlowGraphMsg;
38 class MpResourceMsg;
39 
41 
56 class MpResource : public UtlString
57 {
58 /* //////////////////////////// PUBLIC //////////////////////////////////// */
59 public:
60 
61  friend class MpFlowGraphBase;
62 
65  typedef enum
66  {
70  } VisitState;
71 
72  enum
73  {
76  };
77 
78 static const UtlContainableType TYPE;
79 
80 /* ============================ CREATORS ================================== */
82 
83 
85  MpResource(const UtlString& rName, int minInputs, int maxInputs,
86  int minOutputs, int maxOutputs);
87 
89  virtual ~MpResource();
90 
92 
93 /* ============================ MANIPULATORS ============================== */
95 
96 
98  virtual UtlBoolean disable();
115  static OsStatus disable(const UtlString& namedResource,
117  OsMsgQ& fgQ);
136  virtual UtlBoolean enable();
155  static OsStatus enable(const UtlString& namedResource,
157  OsMsgQ& fgQ);
176  virtual void reset();
178 
181  static OsStatus setNotificationsEnabled(UtlBoolean enable,
182  const UtlString& namedResource,
183  OsMsgQ& fgQ);
203  UtlBoolean handleMessages(OsMsgQ& msgQ);
221  virtual UtlBoolean processFrame() = 0;
234  void setVisitState(int newState);
249  OsStatus sendNotification(MpResNotificationMsg& msg);
258  virtual void setConnectionId(MpConnectionID connectionId);
264  virtual void setStreamId(int streamId);
270  virtual int getStreamId(void);
272 
274  virtual OsStatus pushBuffer(int inputPort, MpBufPtr& inputBuffer);
275 
277  virtual void reassignSSRC(void);
278 
280 
281 /* ============================ ACCESSORS ================================= */
283 
284 
286  static void resourceInfo(MpResource* pResource, int index);
287 
289  MpFlowGraphBase* getFlowGraph() const;
295  void getInputInfo(int inPortIdx, MpResource*& rpUpstreamResource,
297  int& rUpstreamPortIdx);
308  const UtlString &getName() const;
310 
312  void getOutputInfo(int outPortIdx, MpResource*& rpDownstreamResource,
313  int& rDownstreamPortIdx);
324  int getVisitState();
331  int maxInputs() const;
333 
335  int maxOutputs() const;
336 
338  int minInputs() const;
339 
341  int minOutputs() const;
342 
344  int numInputs() const;
345 
347  int numOutputs() const;
348 
350  virtual MpConnectionID getConnectionId(void) const;
351 
374  UtlContainableType getContainableType() const;
376 
378  virtual OsStatus getCurrentLatency(int &latency, int input=0, int output=0) const;
406 
407 /* ============================ INQUIRY =================================== */
409 
410 
412  UtlBoolean isEnabled() const;
413 
415  UtlBoolean isInputConnected(int portIdx);
421  UtlBoolean isInputUnconnected(int portIdx);
428  UtlBoolean isOutputConnected(int portIdx);
435  UtlBoolean isOutputUnconnected(int portIdx);
442  UtlBoolean areNotificationsEnabled() const;
449  virtual UtlBoolean isAsynchInput(int inputIndex);
451 
453 
454 /* //////////////////////////// PROTECTED ///////////////////////////////// */
455 protected:
456 
457  // Conn is a local class definition
458 
460  struct Conn
461  {
463  int portIndex;
464  UtlBoolean reserved;
465  };
466 
469  int mStreamId;
470  UtlBoolean mIsEnabled;
472 
473  OsRWMutex mRWMutex;
474 
487  OsBSem mLock;
488 
489  static const OsTime sOperationQueueTimeout;
491 
493  virtual UtlBoolean handleMessage(MpFlowGraphMsg& fgMsg);
496  virtual UtlBoolean handleMessage(MpResourceMsg& rMsg);
500  virtual UtlBoolean handleEnable();
502 
504  virtual UtlBoolean handleDisable();
505 
508  void setInputBuffer(int inPortIdx, const MpBufPtr &pBuf);
509 
511  OsStatus postMessage(MpFlowGraphMsg& rMsg);
525  OsStatus postMessage(MpResourceMsg& rMsg);
531  UtlBoolean pushBufferDownsream(int outPortIdx, const MpBufPtr &pBuf);
539  virtual OsStatus setFlowGraph(MpFlowGraphBase* pFlowGraph);
547  virtual OsStatus setNotificationsEnabled(UtlBoolean enable);
556  virtual UtlBoolean connectInput(MpResource& rFrom, int fromPortIdx, int toPortIdx);
566  virtual UtlBoolean connectOutput(MpResource& rTo, int toPortIdx, int fromPortIdx);
576  virtual UtlBoolean disconnectInput(int inPortIdx);
586  virtual UtlBoolean disconnectOutput(int outPortIdx);
596  void setName(const UtlString& rName);
598 
599 /* //////////////////////////// PRIVATE /////////////////////////////////// */
600 private:
601 
603  MpResource(const MpResource& rMpResource);
604 
606  MpResource& operator=(const MpResource& rhs);
607 
608 };
609 
610 /* ============================ INLINE METHODS ============================ */
611 
612 #endif // _MpResource_h_
UtlBoolean isInputConnected(int portIdx)
Returns TRUE if portIdx is valid and the indicated input is connected, FALSE otherwise.
Definition: MpResource.cpp:447
VisitState
Graph traversal states that are used when running a topological sort to order resources within a flow...
Definition: MpResource.h:65
Message object used to communicate with the media processing task.
Definition: MpFlowGraphMsg.h:33
OsRWMutex mRWMutex
reader/writer lock for synchronization
Definition: MpResource.h:473
Message object used to communicate with the media processing task.
Definition: MpResourceMsg.h:30
UtlBoolean isOutputConnected(int portIdx)
Returns TRUE if portIdx is valid and the indicated output is connected, FALSE otherwise.
Definition: MpResource.cpp:471
int minInputs() const
Returns the minimum number of inputs required by this resource.
Definition: MpResource.cpp:363
MpFlowGraphBase * mpFlowGraph
flow graph this resource belongs to
Definition: MpResource.h:467
int minOutputs() const
Returns the minimum number of outputs required by this resource.
Definition: MpResource.cpp:369
UtlBoolean areNotificationsEnabled() const
Returns TRUE if notification sending is enabled on this resource.
Definition: MpResource.cpp:493
MpBufPtr * mpInBufs
input buffers for this resource
Definition: MpResource.h:475
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...
Definition: MpResource.cpp:635
void getInputInfo(int inPortIdx, MpResource *&rpUpstreamResource, int &rUpstreamPortIdx)
Returns information about the upstream end of a connection.
Definition: MpResource.cpp:301
The Conn object maintains information about the "far end" of a connection.
Definition: MpResource.h:460
MpFlowGraphBase * getFlowGraph() const
Returns parent flowgraph.
Definition: MpResource.cpp:293
int reserveFirstUnconnectedInput()
Find the first unconnected input port and reserve it.
Definition: MpResource.cpp:386
Flow graph for coordinating the execution of media processing resources.
Definition: MpFlowGraphBase.h:91
void getOutputInfo(int outPortIdx, MpResource *&rpDownstreamResource, int &rDownstreamPortIdx)
Returns information about the downstream end of a connection.
Definition: MpResource.cpp:326
int mMinInputs
number of required inputs
Definition: MpResource.h:481
UtlBoolean isOutputUnconnected(int portIdx)
Returns TRUE if portIdx is valid and the indicated output is not connected, FALSE otherwise...
Definition: MpResource.cpp:483
virtual int getStreamId(void)
Get the ID of a stream within the connection this resource belongs to.
Definition: MpResource.cpp:224
MpConnectionID mConnectionId
The ID of connection this resource belongs to.
Definition: MpResource.h:468
UtlBoolean handleMessages(OsMsgQ &msgQ)
Handles a queue full of incoming messages for this media processing object.
Definition: MpResource.cpp:561
UtlBoolean pushBufferDownsream(int outPortIdx, const MpBufPtr &pBuf)
Makes pBuf available to resource connected to the outPortIdx output port of this resource.
Definition: MpResource.cpp:650
UtlBoolean mNotificationsEnabled
Whether we should send notifications or not.
Definition: MpResource.h:486
Get input or output latency, associated with a resource.
Definition: MpResource.h:74
void setName(const UtlString &rName)
Sets the name that is associated with this resource.
Definition: MpResource.cpp:813
Conn * mpInConns
input connections for this resource
Definition: MpResource.h:477
UtlBoolean reserved
this port is reserved to be used
Definition: MpResource.h:464
virtual OsStatus getCurrentLatency(int &latency, int input=0, int output=0) const
Get current input to output latency (in samples)
Definition: MpResource.cpp:425
virtual OsStatus setFlowGraph(MpFlowGraphBase *pFlowGraph)
Associates this resource with the indicated flow graph.
Definition: MpResource.cpp:796
virtual void setStreamId(int streamId)
Set the ID of a stream inside of the connection this resource belongs to.
Definition: MpResource.cpp:219
int portIndex
Port number on the other end of the connection.
Definition: MpResource.h:463
UtlBoolean isInputUnconnected(int portIdx)
Returns TRUE if portIdx is valid and the indicated input is not connected, FALSE otherwise.
Definition: MpResource.cpp:459
int mMaxInputs
maximum number of inputs
Definition: MpResource.h:479
virtual UtlBoolean isAsynchInput(int inputIndex)
Takes asynchronous input (pushBuffer).
Definition: MpResource.cpp:499
virtual void reassignSSRC(void)
Broadcast announcement that we are changing our SSRC.
Definition: MpResource.cpp:234
Conn * mpOutConns
output connections for this resource
Definition: MpResource.h:478
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 resour...
Definition: MpResource.cpp:715
int mMinOutputs
number of required outputs
Definition: MpResource.h:482
static void resourceInfo(MpResource *pResource, int index)
Displays information on the console about the specified resource.
Definition: MpResource.cpp:240
static const OsTime sOperationQueueTimeout
The timeout for message operations for all resources when posting to the flowgraph queue...
Definition: MpResource.h:489
virtual UtlBoolean disable()
Disable this resource.
Definition: MpResource.cpp:121
int numInputs() const
Returns the number of resource inputs that are currently connected.
Definition: MpResource.cpp:375
virtual ~MpResource()
Destructor.
Definition: MpResource.cpp:91
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...
Definition: MpResource.cpp:736
MpResource * pResource
Other end of the connection.
Definition: MpResource.h:462
int mMaxOutputs
maximum number of outputs
Definition: MpResource.h:480
Infinite latency, i.e. data from the input is not sent to the output.
Definition: MpResource.h:75
virtual UtlBoolean disconnectInput(int inPortIdx)
Removes the connection to the inPortIdx input port of this resource.
Definition: MpResource.cpp:756
MpBufPtr * mpOutBufs
output buffers for this resource
Definition: MpResource.h:476
int getVisitState()
Returns the current visit state for this resource.
Definition: MpResource.cpp:345
Definition: MpResource.h:68
const UtlString & getName() const
Returns the name associated with this resource.
Definition: MpResource.cpp:318
static OsStatus setNotificationsEnabled(UtlBoolean enable, const UtlString &namedResource, OsMsgQ &fgQ)
Post a message to enable or disable resource notifications on the named resource. ...
Definition: MpResource.cpp:165
Definition: MpResource.h:69
Definition: MpResNotificationMsg.h:31
UtlContainableType getContainableType() const
Get the ContainableType for a UtlContainable derived class.
Definition: MpResource.cpp:420
MpResource & operator=(const MpResource &rhs)
Assignment operator (not implemented for this class)
MpResource(const UtlString &rName, int minInputs, int maxInputs, int minOutputs, int maxOutputs)
Constructor.
Definition: MpResource.cpp:39
int mVisitState
(used by flow graph topological sort alg.)
Definition: MpResource.h:485
int reserveFirstUnconnectedOutput()
Find the first unconnected output port and reserve it.
Definition: MpResource.cpp:403
virtual UtlBoolean handleEnable()
perform the enable operation on the resource
Definition: MpResource.cpp:611
virtual UtlBoolean enable()
Enable this resource.
Definition: MpResource.cpp:145
Smart pointer to MpBuf.
Definition: MpBuf.h:160
int maxOutputs() const
Returns the maximum number of outputs supported by this resource.
Definition: MpResource.cpp:357
virtual UtlBoolean disconnectOutput(int outPortIdx)
Removes the connection to the outPortIdx output port of this resource.
Definition: MpResource.cpp:776
int mNumActualInputs
actual number of connected inputs
Definition: MpResource.h:483
int MpConnectionID
Flowgraph connection ID.
Definition: MpTypes.h:56
OsBSem mLock
used mainly to make safe changes to ports
Definition: MpResource.h:487
int maxInputs() const
Returns the maximum number of inputs supported by this resource.
Definition: MpResource.cpp:351
virtual OsStatus pushBuffer(int inputPort, MpBufPtr &inputBuffer)
Receive buffer asynchronously from resource at given input port.
Definition: MpResource.cpp:229
virtual void reset()
This method is invoked for resources that care about stream discontinuities.
Definition: MpResource.cpp:161
RNMsgType
Phone set message types.
Definition: MpResNotificationMsg.h:37
int mStreamId
Definition: MpResource.h:469
void setVisitState(int newState)
Sets the visit state for this resource.
Definition: MpResource.cpp:178
Definition: MpResource.h:67
int numOutputs() const
Returns the number of resource outputs that are currently connected.
Definition: MpResource.cpp:381
int mNumActualOutputs
actual number of connected outputs
Definition: MpResource.h:484
Abstract base class for all media processing objects.
Definition: MpResource.h:56
virtual UtlBoolean handleDisable()
perform the disable operation on the resource
Definition: MpResource.cpp:622
OsStatus sendNotification(MpResNotificationMsg::RNMsgType msgType)
Send a notification with the given message type if notifications are enabled.
Definition: MpResource.cpp:186
static const UtlContainableType TYPE
Class name, used for run-time checks.
Definition: MpResource.h:78
virtual void setConnectionId(MpConnectionID connectionId)
Set the ID of a connection this resource belongs to.
Definition: MpResource.cpp:209
UtlBoolean mIsEnabled
TRUE if resource is enabled, FALSE otherwise.
Definition: MpResource.h:471
virtual MpConnectionID getConnectionId(void) const
Get the ID of a connection this resource belongs to.
Definition: MpResource.cpp:214
virtual UtlBoolean processFrame()=0
This method is called in every flowgraph processing cycle.
OsStatus postMessage(MpFlowGraphMsg &rMsg)
Post a message from this resource.
Definition: MpResource.cpp:678
UtlBoolean isEnabled() const
Returns TRUE is this resource is currently enabled, FALSE otherwise.
Definition: MpResource.cpp:440
virtual UtlBoolean handleMessage(MpFlowGraphMsg &fgMsg)
Handles an incoming flowgraph message for this media processing object.
Definition: MpResource.cpp:508