sipxmedialib  Version 3.3
MpMediaTask.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2021 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2004-2006 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 #ifndef _MpMediaTask_h_
14 #define _MpMediaTask_h_
15 
16 // SYSTEM INCLUDES
17 
18 // APPLICATION INCLUDES
19 #include "utl/UtlHistogram.h"
20 #include "os/OsDefs.h"
21 #include "os/OsRWMutex.h"
22 #include "os/OsServerTask.h"
23 #include "os/OsMsgPool.h"
24 #include "os/OsCallback.h"
25 #include "mp/MpMediaTaskMsg.h"
26 
27 // DEFINES
28 
29 //#define _PROFILE
30 
31 // MACROS
32 // EXTERNAL FUNCTIONS
33 // EXTERNAL VARIABLES
34 // CONSTANTS
35 // STRUCTS
36 // TYPEDEFS
37 
38 // FORWARD DECLARATIONS
39 class MpFlowGraphBase;
40 class OsNotification;
41 
96 class MpMediaTask : public OsServerTask
97 {
98 /* //////////////////////////// PUBLIC //////////////////////////////////// */
99 public:
100  enum {
104  };
105 
106 
107 /* ============================ CREATORS ================================== */
109 
110 
112  static MpMediaTask* createMediaTask(int maxFlowGraph,
113  UtlBoolean enableLocalAudio = true);
114 
116  static MpMediaTask* getMediaTask();
117 
119  virtual
120  ~MpMediaTask();
121 
123 
124 /* ============================ MANIPULATORS ============================== */
126 
127 
130  OsStatus manageFlowGraph(MpFlowGraphBase& rFlowGraph);
142  OsStatus unmanageFlowGraph(MpFlowGraphBase& rFlowGraph);
154  OsStatus setDebug(UtlBoolean enableFlag);
161  OsStatus setFocus(MpFlowGraphBase* pFlowGraph);
172  OsStatus setTimeLimit(int usecs);
182  OsStatus setWaitTimeout(int msecs);
192  OsStatus startFlowGraph(MpFlowGraphBase& rFlowGraph);
201  OsStatus stopFlowGraph(MpFlowGraphBase& rFlowGraph);
210  static OsStatus signalFrameStart(const OsTime &timeout = OsTime::OS_INFINITY);
218  OsStatus sendToAllFlowgraphs(OsMsgQ& queuedMessages);
226 
227 /* ============================ ACCESSORS ================================= */
229 
230 
232  int numHandledMsgErrs();
233 
235  UtlBoolean getDebugMode(void) const;
236 
239  MpFlowGraphBase* getFocus(void) const;
240 
243  int getLimitExceededCnt(void) const;
244 
247  OsStatus getManagedFlowGraphs(MpFlowGraphBase* flowGraphs[], const int size,
248  int& numItems);
255  int getTimeLimit(void) const;
258 
261  int getWaitTimeout(void) const;
266  int getWaitTimeoutCnt(void) const;
269 
272  int numManagedFlowGraphs(void) const;
273 
276  int numProcessedFrames(void) const;
282  int numStartedFlowGraphs(void) const;
289  OsMsgPool* getBufferMsgPool(void) const;
291 
294  inline OsNotification *getTickerNotification();
302  static MpFlowGraphBase* mediaInfo(void);
304 
307  static int maxNumManagedFlowGraphs(void);
308 
310 
311 /* ============================ INQUIRY =================================== */
313 
314 
316  UtlBoolean isManagedFlowGraph(MpFlowGraphBase* pFlowGraph);
323  void getQueueUsage(int& numMsgs, int& softLimit,
325  int& hardLimit);
326 
328 
329 /* //////////////////////////// PROTECTED ///////////////////////////////// */
330 protected:
331 
333  MpMediaTask(int maxFlowGraph, UtlBoolean enableLocalAudio);
334 
335 /* //////////////////////////// PRIVATE /////////////////////////////////// */
336 private:
337 
338  OsMutex mMutex;
339  UtlBoolean mDebugEnabled;
340 
342  unsigned mProcessedCnt;
345  OsTime mSemTimeout;
347  UtlBoolean mWaitForSignal;
351  static int mMaxFlowGraph;
354  OsMsgPool* mpBufferMsgPool;
356  OsMsgPool* mpSignalMsgPool;
357  static const OsTime smOperationQueueTimeout;
358  OsCallback mFlowgraphTicker;
360  UtlBoolean mIsLocalAudioEnabled;
361  static UtlBoolean mIsBlockingReported;
362 
364  // Static data members used to enforce Singleton behavior
365  static MpMediaTask* volatile spInstance;
366  static OsBSem sLock;
368 
370 #ifdef _PROFILE /* [ */
371  long long mStartTicks;
374  long long mStopTicks;
376  unsigned long long mLimitTicks;
377 
380  UtlHistogram mStartToEndTime;
382  UtlHistogram mStartToStartTime;
384  UtlHistogram mEndToStartTime;
386  UtlHistogram mSignalTime;
388  UtlHistogram mSignalToStartTime;
390  UtlHistogram mOtherMessages;
391 #endif /* _PROFILE ] */
392 
394  int run(void* pArg);
395 
397  UtlBoolean handleMessage(OsMsg& rMsg);
403  UtlBoolean handleManage(MpFlowGraphBase* pFlowGraph);
410  UtlBoolean handleSetFocus(MpFlowGraphBase* pFlowGraph);
417  UtlBoolean handleStart(MpFlowGraphBase* pFlowGraph);
424  UtlBoolean handleStop(MpFlowGraphBase* pFlowGraph);
431  UtlBoolean handleUnmanage(MpFlowGraphBase* pFlowGraph);
438  UtlBoolean handleWaitForSignal(MpMediaTaskMsg*);
445  static
447  void flowgraphTickerCallback(const intptr_t userData, const intptr_t eventData);
453  MpMediaTask(const MpMediaTask& rMpMediaTask);
455 
457  MpMediaTask& operator=(const MpMediaTask& rhs);
458 
459 };
460 
461 /* ============================ INLINE METHODS ============================ */
462 
464 {
465  return &mFlowgraphTicker;
466 }
467 
468 #endif // _MpMediaTask_h_
OsStatus setWaitTimeout(int msecs)
Sets the maximum time (in milliseconds) that the media processing task will wait for a "frame start" ...
Definition: MpMediaTask.cpp:224
int getWaitTimeoutCnt(void) const
Returns the number of times that the wait timeout associated with "frame start" signal has been excee...
Definition: MpMediaTask.cpp:451
OsStatus sendToAllFlowgraphs(OsMsgQ &queuedMessages)
Queue the given messages to each of the managed flowgraphs.
Definition: MpMediaTask.cpp:335
int mManagedCnt
Number of flow graphs presently managed.
Definition: MpMediaTask.h:343
int numHandledMsgErrs()
Debug aid for tracking state. See MpMediaTaskTest.
Definition: MpMediaTask.cpp:383
UtlBoolean handleUnmanage(MpFlowGraphBase *pFlowGraph)
Handles the UNMANAGE message.
Definition: MpMediaTask.cpp:857
int numManagedFlowGraphs(void) const
Returns the number of flow graphs currently being managed by the media processing task...
Definition: MpMediaTask.cpp:510
static MpMediaTask *volatile spInstance
pointer to the single instance
Definition: MpMediaTask.h:365
static int mMaxFlowGraph
Definition: MpMediaTask.h:351
void getQueueUsage(int &numMsgs, int &softLimit, int &hardLimit)
Return usage information on the Media Task's message queue.
Definition: MpMediaTask.cpp:550
int mTimeLimitCnt
Number of frames where time limit was exceeded.
Definition: MpMediaTask.h:341
OsStatus getManagedFlowGraphs(MpFlowGraphBase *flowGraphs[], const int size, int &numItems)
Returns an array of MpFlowGraphBase pointers that are presently managed by the media processing task...
Definition: MpMediaTask.cpp:416
MpFlowGraphBase ** mManagedFGs
The set of flow graphs presently managed.
Definition: MpMediaTask.h:350
UtlBoolean mDebugEnabled
TRUE if debug mode is enabled, FALSE otherwise.
Definition: MpMediaTask.h:339
UtlBoolean mWaitForSignal
If TRUE, then don't handle any incoming msgs until a FrameStart signal has been received.
Definition: MpMediaTask.h:347
int getTimeLimit(void) const
Returns the amount of time (in microseconds) allotted to the media processing task for processing a f...
Definition: MpMediaTask.cpp:433
int mHandleMsgErrs
Number of message handling problems during the last frame processing interval.
Definition: MpMediaTask.h:353
MpMediaTask & operator=(const MpMediaTask &rhs)
Assignment operator (not implemented for this task)
UtlBoolean handleMessage(OsMsg &rMsg)
Handle an incoming message.
Definition: MpMediaTask.cpp:677
Flow graph for coordinating the execution of media processing resources.
Definition: MpFlowGraphBase.h:91
static OsBSem sLock
semaphore used to ensure that there is only one instance of this class
Definition: MpMediaTask.h:367
OsMsgPool * getBufferMsgPool(void) const
Returns pointer to pool of reusable buffer messages.
Definition: MpMediaTask.cpp:542
static MpMediaTask * createMediaTask(int maxFlowGraph, UtlBoolean enableLocalAudio=true)
Create the media processing task.
Definition: MpMediaTask.cpp:74
int getLimitExceededCnt(void) const
Returns the number of times that the frame processing time limit has been exceeded.
Definition: MpMediaTask.cpp:406
int numStartedFlowGraphs(void) const
Returns the number of flow graphs that have been started by the media processing task.
Definition: MpMediaTask.cpp:536
int mSemTimeoutCnt
Number of times the mSemTimeOut was exceeded.
Definition: MpMediaTask.h:346
OsStatus setFocus(MpFlowGraphBase *pFlowGraph)
Changes the focus to the indicated flow graph.
Definition: MpMediaTask.cpp:188
OsStatus setDebug(UtlBoolean enableFlag)
When "debug" mode is enabled, the "time limit" checking is disabled and the wait for "frame start" ti...
Definition: MpMediaTask.cpp:173
OsStatus startFlowGraph(MpFlowGraphBase &rFlowGraph)
Directs the media processing task to start the specified flow graph.
Definition: MpMediaTask.cpp:300
static MpFlowGraphBase * mediaInfo(void)
Displays information on the console about the media processing task.
Definition: MpMediaTask.cpp:458
static const OsTime smOperationQueueTimeout
to the flowgraph queue.
Definition: MpMediaTask.h:357
UtlBoolean handleManage(MpFlowGraphBase *pFlowGraph)
Handles the MANAGE message.
Definition: MpMediaTask.cpp:748
UtlBoolean getDebugMode(void) const
Returns TRUE if debug mode is enabled, FALSE otherwise.
Definition: MpMediaTask.cpp:392
OsStatus unmanageFlowGraph(MpFlowGraphBase &rFlowGraph)
Directs the media processing task to remove the flow graph from its set of managed flow graphs...
Definition: MpMediaTask.cpp:159
Message object used to communicate with the media processing task.
Definition: MpMediaTaskMsg.h:32
MpFlowGraphBase * mpFocus
FlowGraph that has the focus (may be NULL)
Definition: MpMediaTask.h:349
OsTime mSemTimeout
Timeout value for acquiring the start semaphore.
Definition: MpMediaTask.h:345
OsNotification * getTickerNotification()
Get OsNotification to signal for the next frame processing interval start.
Definition: MpMediaTask.h:463
int mLimitUsecs
Frame processing time limit (in usecs)
Definition: MpMediaTask.h:352
int mStartedCnt
Number of flow graphs presently started.
Definition: MpMediaTask.h:344
UtlBoolean handleWaitForSignal(MpMediaTaskMsg *)
Handles the WAIT_FOR_SIGNAL message.
Definition: MpMediaTask.cpp:909
Object responsible for coordinating the execution of media processing flow graphs.
Definition: MpMediaTask.h:96
int run(void *pArg)
Definition: MpMediaTask.cpp:649
static int maxNumManagedFlowGraphs(void)
Returns the maximum number of flow graphs that can be managed by the media processing task...
Definition: MpMediaTask.cpp:517
processing limit = 6 msecs
Definition: MpMediaTask.h:101
unsigned mProcessedCnt
Number of frames that have been processed.
Definition: MpMediaTask.h:342
UtlBoolean handleStop(MpFlowGraphBase *pFlowGraph)
Handles the STOP message.
Definition: MpMediaTask.cpp:835
static MpMediaTask * getMediaTask()
Return a pointer to the media processing task if exists.
Definition: MpMediaTask.cpp:96
UtlBoolean handleSetFocus(MpFlowGraphBase *pFlowGraph)
Handles the SET_FOCUS message.
Definition: MpMediaTask.cpp:773
OsMsgPool * mpBufferMsgPool
Pool of reusable buffer messages.
Definition: MpMediaTask.h:355
media task execution priority
Definition: MpMediaTask.h:103
int getWaitTimeout(void) const
Returns the maximum time (in milliseconds) that the media processing task will wait for the "frame st...
Definition: MpMediaTask.cpp:441
OsStatus setTimeLimit(int usecs)
Sets the amount of time (in microseconds) allotted to the media processing task for processing a fram...
Definition: MpMediaTask.cpp:208
static UtlBoolean mIsBlockingReported
for too long already reported?
Definition: MpMediaTask.h:361
virtual ~MpMediaTask()
Destructor.
Definition: MpMediaTask.cpp:110
MpFlowGraphBase * getFocus(void) const
Returns the flow graph that currently has focus (access to the audio apparatus) or NULL if there is n...
Definition: MpMediaTask.cpp:399
static void flowgraphTickerCallback(const intptr_t userData, const intptr_t eventData)
Callback for flowgraph ticker.
Definition: MpMediaTask.cpp:1110
MpMediaTask(int maxFlowGraph, UtlBoolean enableLocalAudio)
Default constructor.
Definition: MpMediaTask.cpp:564
UtlBoolean handleStart(MpFlowGraphBase *pFlowGraph)
Handles the START message.
Definition: MpMediaTask.cpp:816
int numProcessedFrames(void) const
Returns the number of frames that the media processing task has processed. This count is maintained a...
Definition: MpMediaTask.cpp:528
semaphore timeout = 0.5 secs
Definition: MpMediaTask.h:102
OsCallback mFlowgraphTicker
OsNotification to call flowgraphTickerCallback()
Definition: MpMediaTask.h:359
OsStatus manageFlowGraph(MpFlowGraphBase &rFlowGraph)
Directs the media processing task to add the flow graph to its set of managed flow graphs...
Definition: MpMediaTask.cpp:135
UtlBoolean isManagedFlowGraph(MpFlowGraphBase *pFlowGraph)
Is flow graph managed by the media processing task?
Definition: MpMediaTask.cpp:1095
OsMsgPool * mpSignalMsgPool
Pool of reusable frame signal messages.
Definition: MpMediaTask.h:356
OsStatus stopFlowGraph(MpFlowGraphBase &rFlowGraph)
Directs the media processing task to stop the specified flow graph.
Definition: MpMediaTask.cpp:324
UtlBoolean mIsLocalAudioEnabled
Affects setFocus().
Definition: MpMediaTask.h:360
static OsStatus signalFrameStart(const OsTime &timeout=OsTime::OS_INFINITY)
Signal the media processing task that it should begin processing the next frame.
Definition: MpMediaTask.cpp:243
OsMutex mMutex
lock for synchronization
Definition: MpMediaTask.h:338