sipxmedialib  Version 3.3
MpResourceTopology.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2015 SIPez LLC. All rights reserved.
3 //
4 // $$
6 
7 // Author: Dan Petrie <dpetrie AT SIPez DOT com>
8 
9 #ifndef _MpResourceTopology_h_
10 #define _MpResourceTopology_h_
11 
12 // SYSTEM INCLUDES
13 #include <mp/MpTypes.h>
14 #include <os/OsStatus.h>
15 #include <utl/UtlString.h>
16 #include <utl/UtlDList.h>
17 #include <utl/UtlHashMap.h>
18 
19 // APPLICATION INCLUDES
20 // DEFINES
21 #define DEFAULT_FROM_FILE_RESOURCE_NAME "FromFile1"
22 #define DEFAULT_FROM_INPUT_DEVICE_RESOURCE_NAME "FromMic1"
23 #define DEFAULT_BRIDGE_RESOURCE_NAME "Bridge1"
24 #define DEFAULT_VIDEO_MIXER_RESOURCE_NAME "VideoMixer1"
25 #define DEFAULT_SPEAKER_SELECTOR_RESOURCE_NAME "SpeakerSelector1"
26 #define DEFAULT_TONE_GEN_RESOURCE_NAME "ToneGen1"
27 #define DEFAULT_TONE_DETECT_RESOURCE_NAME "ToneDetect"
28 #define DEFAULT_TO_OUTPUT_DEVICE_RESOURCE_NAME "ToSpeaker1"
29 #define DEFAULT_SPEEX_PREPROCESS_RESOURCE_NAME "SpeexPreprocess"
30 #define DEFAULT_NULL_RESOURCE_NAME "Null1"
31 #define DEFAULT_RTP_INPUT_RESOURCE_NAME "InRtp-%d"
32 #define DEFAULT_VIDEO_RTP_INPUT_RESOURCE_NAME "InVideoRtp-%d"
33 #define DEFAULT_DECODE_RESOURCE_NAME "Decode-%d"
34 #define DEFAULT_RTP_OUTPUT_RESOURCE_NAME "OutRtp-%d"
35 #define DEFAULT_VIDEO_RTP_OUTPUT_RESOURCE_NAME "OutVideoRtp-%d"
36 #define DEFAULT_ENCODE_RESOURCE_NAME "Encode-%d"
37 #define DEFAULT_RECORDER_RESOURCE_NAME "CallRecorder"
38 #define DEFAULT_TO_OUTPUT_SPLITTER_RESOURCE_NAME "ToOutputSplitter1"
39 #define DEFAULT_VAD_RESOURCE_NAME "Vad"
40 #define DEFAULT_VOICE_ACTIVITY_NOTIFIER_RESOURCE_NAME "VoiceActivityNotifier"
41 #define DEFAULT_DELAY_RESOURCE_NAME "Delay"
42 #define DEFAULT_NOTCH_FILTER_RESOURCE_NAME "NotchFilter"
43 
44 #define CONNECTION_NAME_SUFFIX "-%d"
45 #define STREAM_NAME_SUFFIX "-%d"
46 #define MIC_NAME_SUFFIX "-Mic"
47 #define SPEAKER_NAME_SUFFIX "-Spkr"
48 #define AEC_OUTPUT_BUFFER_RESOURCE_NAME_SUFFIX "-outBuffer"
49 #define AEC_NAME_SUFFIX "-AEC"
50 #define DIRECTION_IN_SUFFIX "-In"
51 #define DIRECTION_OUT_SUFFIX "-Out"
52 
57 #define VIRTUAL_NAME_LOCAL_STREAM_OUTPUT "StreamOutput" MIC_NAME_SUFFIX
58 
63 #define VIRTUAL_NAME_LOCAL_STREAM_INPUT "StreamInput" SPEAKER_NAME_SUFFIX
64 
72 #define VIRTUAL_NAME_RTP_STREAM_OUTPUT "StreamOutput" CONNECTION_NAME_SUFFIX
73 
83 #define VIRTUAL_NAME_CONNECTION_PORTS "ConnectionPorts"
84 
85 // MACROS
86 // EXTERNAL FUNCTIONS
87 // EXTERNAL VARIABLES
88 // CONSTANTS
89 // STRUCTS
90 // TYPEDEFS
91 // FORWARD DECLARATIONS
92 class MpResourceFactory;
93 class UtlHashMapIterator;
94 
124 {
125 /* //////////////////////////// PUBLIC //////////////////////////////////// */
126 public:
127 
129  {
131  };
132 
133  typedef UtlHashMapIterator* VirtualPortIterator;
134 
136  struct ResourceDef
137  {
138 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
139  // Visual Studio 6.0 is broken when it comes to statically initializing
140  // an array of structs containing object references, so in this case
141  // just store const char* -- Note: this means reduced functionality
142  // under VS6 -- only static names and types can be used here.
143  const char* resourceType;
144  const char* resourceName;
145 #else
146  const UtlString resourceType;
147  const UtlString resourceName;
148 #endif
149 
151  int streamId;
152  };
155  {
156 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
157  // See above notice about VS6 being broken
158  const char* outputResourceName;
159 #else
160  const UtlString outputResourceName;
161 #endif
162 
164 
165 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
166  // See above notice about VS6 being broken
167  const char* inputResourceName;
168 #else
169  const UtlString inputResourceName;
170 #endif
171 
173  };
174 
175 /* ============================ CREATORS ================================== */
176 
179 
181  virtual ~MpResourceTopology();
182 
183 /* ============================ MANIPULATORS ============================== */
184 
186  OsStatus addResource(const UtlString& resourceType,
187  const UtlString& resourceName,
189  int streamId = -1);
202  OsStatus addResources(const ResourceDef *defines, int numDefines);
210  OsStatus addConnection(const UtlString& outputResourceName,
212  int outputPortIndex,
213  const UtlString& inputResourceName,
214  int inputPortIndex);
215 
217  OsStatus addConnections(const ConnectionDef *defines, int numDefines);
231  OsStatus addVirtualInput(const UtlString& realResourceName,
233  int realPortIndex,
234  const UtlString& virtualResourceName,
235  int virtualPortIndex);
241  OsStatus addVirtualOutput(const UtlString& realResourceName,
243  int realPortIndex,
244  const UtlString& virtualResourceName,
245  int virtualPortIndex);
252  OsStatus validateConnections(UtlString& firstUnconnectedResourceName,
254  UtlString& firstDanglingResourceName,
255  UtlBoolean allowExternalResources = FALSE) const;
274  OsStatus validateResourceTypes(MpResourceFactory& resourceFactory,
276  int& firstInvalidResourceIndex) const;
283  static void replaceNumInName(UtlString& resourceName,
285  int resourceNum);
286 
287 /* ============================ ACCESSORS ================================= */
288 
290  OsStatus getResource(int resourceIndex,
291  UtlString& resourceType,
292  UtlString& resourceName,
294  int& streamId) const;
295 
297  OsStatus getResource(int resourceIndex,
298  UtlString& resourceName) const;
299 
301  OsStatus getInputVirtualResource(const UtlString &virtualName,
302  int virtualPort,
303  UtlString& resourceName,
304  int &resourcePort) const;
305 
307  OsStatus getOutputVirtualResource(const UtlString &virtualName,
308  int virtualPort,
309  UtlString& resourceName,
310  int &resourcePort) const;
311 
313  OsStatus getConnection(int connectionIndex,
314  UtlString& outputResourceName,
315  int& outputPortIndex,
316  UtlString& inputResourceName,
317  int& inputPortIndex);
318 
327  void initVirtualInputIterator(VirtualPortIterator &portIter);
329 
331  void freeVirtualInputIterator(VirtualPortIterator &portIter);
332 
334  OsStatus getNextVirtualInput(VirtualPortIterator &portIter,
335  UtlString& realResourceName,
336  int &realPortIndex,
337  UtlString& virtualResourceName,
338  int &virtualPortIndex);
351  void initVirtualOutputIterator(VirtualPortIterator &portIter);
353 
355  void freeVirtualOutputIterator(VirtualPortIterator &portIter);
356 
358  OsStatus getNextVirtualOutput(VirtualPortIterator &portIter,
359  UtlString& realResourceName,
360  int &realPortIndex,
361  UtlString& virtualResourceName,
362  int &virtualPortIndex);
375  int dumpResources(UtlString& dumpString);
377 
379  int dumpConnections(UtlString& dumpString);
380 
381 /* ============================ INQUIRY =================================== */
382 
383 /* //////////////////////////// PROTECTED ///////////////////////////////// */
384 protected:
385 
387  UtlDList mResources;
388  UtlDList mConnections;
389  UtlHashMap mVirtualInputs;
390  UtlHashMap mVirtualOutputs;
391 
392  int findResourceConnections(const UtlString& resourceName,
393  UtlContainer& connectionsToTraverse) const;
394 
395 /* //////////////////////////// PRIVATE /////////////////////////////////// */
396 private:
397 
399  MpResourceTopology(const MpResourceTopology& rMpResourceTopology);
400 
403 };
404 
405 /* ============================ INLINE METHODS ============================ */
406 
407 #endif // _MpResourceTopology_h_
int getNextLogicalPortNumber()
Get the next logical port, used when the same port number ???
Definition: MpResourceTopology.cpp:632
int findResourceConnections(const UtlString &resourceName, UtlContainer &connectionsToTraverse) const
Definition: MpResourceTopology.cpp:739
void freeVirtualInputIterator(VirtualPortIterator &portIter)
Destroy virtual input ports iterator.
Definition: MpResourceTopology.cpp:642
OsStatus addResource(const UtlString &resourceType, const UtlString &resourceName, MpConnectionID connectionId=MP_INVALID_CONNECTION_ID, int streamId=-1)
Add a new resource definition to the topology.
Definition: MpResourceTopology.cpp:105
MpResourceTopology()
Constructor.
Definition: MpResourceTopology.cpp:90
void initVirtualInputIterator(VirtualPortIterator &portIter)
Initialize virtual input ports iterator.
Definition: MpResourceTopology.cpp:637
int streamId
Definition: MpResourceTopology.h:151
A connection type for use with addConnections().
Definition: MpResourceTopology.h:154
OsStatus addConnection(const UtlString &outputResourceName, int outputPortIndex, const UtlString &inputResourceName, int inputPortIndex)
Add a new connection definition to the topology.
Definition: MpResourceTopology.cpp:141
OsStatus getInputVirtualResource(const UtlString &virtualName, int virtualPort, UtlString &resourceName, int &resourcePort) const
Get the resource name and port index by the virtual input name and port index.
Definition: MpResourceTopology.cpp:525
MpLogicalPortTypes
Definition: MpResourceTopology.h:128
virtual ~MpResourceTopology()
Destructor.
Definition: MpResourceTopology.cpp:96
void initVirtualOutputIterator(VirtualPortIterator &portIter)
Initialize virtual output ports iterator.
Definition: MpResourceTopology.cpp:669
OsStatus getResource(int resourceIndex, UtlString &resourceType, UtlString &resourceName, MpConnectionID &connectionId, int &streamId) const
Get the resource definition indicated by the resourceIndex.
Definition: MpResourceTopology.cpp:482
UtlHashMap mVirtualInputs
Mapping between virtual and real inputs.
Definition: MpResourceTopology.h:389
static void replaceNumInName(UtlString &resourceName, int resourceNum)
Utility to replace "%d" in resource name with an integer.
Definition: MpResourceTopology.cpp:468
const UtlString inputResourceName
Definition: MpResourceTopology.h:169
const UtlString outputResourceName
Definition: MpResourceTopology.h:160
MpConnectionID connectionId
Definition: MpResourceTopology.h:150
Definition: MpResourceTopology.h:130
OsStatus addConnections(const ConnectionDef *defines, int numDefines)
Add resources from an array.
Definition: MpResourceTopology.cpp:153
UtlDList mConnections
Definition: MpResourceTopology.h:388
OsStatus getConnection(int connectionIndex, UtlString &outputResourceName, int &outputPortIndex, UtlString &inputResourceName, int &inputPortIndex)
Get the connection definition indicated by the connectionIndex.
Definition: MpResourceTopology.cpp:607
A resource type for use with addResources().
Definition: MpResourceTopology.h:136
OsStatus getNextVirtualOutput(VirtualPortIterator &portIter, UtlString &realResourceName, int &realPortIndex, UtlString &virtualResourceName, int &virtualPortIndex)
Get virtual output data from an iterator.
Definition: MpResourceTopology.cpp:681
int mPriorLogicalPort
Definition: MpResourceTopology.h:386
const UtlString resourceName
Definition: MpResourceTopology.h:147
OsStatus validateConnections(UtlString &firstUnconnectedResourceName, UtlString &firstDanglingResourceName, UtlBoolean allowExternalResources=FALSE) const
Validate that the connections are connect the resources.
Definition: MpResourceTopology.cpp:299
void freeVirtualOutputIterator(VirtualPortIterator &portIter)
Destroy virtual output ports iterator.
Definition: MpResourceTopology.cpp:674
MpResourceFactory is used to construct resources by type name.
Definition: MpResourceFactory.h:61
MpResourceTopology & operator=(const MpResourceTopology &rhs)
Disabled assignment operator.
OsStatus validateResourceTypes(MpResourceFactory &resourceFactory, int &firstInvalidResourceIndex) const
Validate that all the resource types in this topology have a constructor in the factory.
Definition: MpResourceTopology.cpp:447
UtlDList mResources
Definition: MpResourceTopology.h:387
int dumpConnections(UtlString &dumpString)
Dump connections to debug string.
Definition: MpResourceTopology.cpp:714
OsStatus addResources(const ResourceDef *defines, int numDefines)
Add resources from an array.
Definition: MpResourceTopology.cpp:125
int dumpResources(UtlString &dumpString)
Dump resources to debug string.
Definition: MpResourceTopology.cpp:693
OsStatus getOutputVirtualResource(const UtlString &virtualName, int virtualPort, UtlString &resourceName, int &resourcePort) const
Get the resource name and port index by the virtual output name and port index.
Definition: MpResourceTopology.cpp:566
const UtlString resourceType
Definition: MpResourceTopology.h:146
OsStatus addVirtualOutput(const UtlString &realResourceName, int realPortIndex, const UtlString &virtualResourceName, int virtualPortIndex)
Add a new virtual output definition to the topology.
Definition: MpResourceTopology.cpp:247
int MpConnectionID
Flowgraph connection ID.
Definition: MpTypes.h:56
UtlHashMap mVirtualOutputs
Mapping between virtual and real outputs.
Definition: MpResourceTopology.h:390
MpResourceTopology is used to define a set of resources and how they are to be connected in a flowgra...
Definition: MpResourceTopology.h:123
UtlHashMapIterator * VirtualPortIterator
Definition: MpResourceTopology.h:133
#define MP_INVALID_CONNECTION_ID
Definition: MpTypes.h:57
#define FALSE
Definition: PlgDefsV1.h:37
int outputPortIndex
Definition: MpResourceTopology.h:163
int inputPortIndex
Definition: MpResourceTopology.h:172
OsStatus addVirtualInput(const UtlString &realResourceName, int realPortIndex, const UtlString &virtualResourceName, int virtualPortIndex)
Add a new virtual input definition to the topology.
Definition: MpResourceTopology.cpp:195
OsStatus getNextVirtualInput(VirtualPortIterator &portIter, UtlString &realResourceName, int &realPortIndex, UtlString &virtualResourceName, int &virtualPortIndex)
Get virtual input data from an iterator.
Definition: MpResourceTopology.cpp:648