sipxmedialib  Version 3.3
MpOutputDeviceManager.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007-2021 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2007-2008 SIPfoundry Inc.
5 // Licensed by SIPfoundry under the LGPL license.
6 //
7 // $$
9 
10 // Author: Alexander Chemeris <Alexander DOT Chemeris AT SIPez DOT com>
11 
12 #ifndef _MpOutputDeviceManager_h_
13 #define _MpOutputDeviceManager_h_
14 
15 // SYSTEM INCLUDES
16 
17 // APPLICATION INCLUDES
18 #include <os/OsRWMutex.h>
19 #include <utl/UtlHashMap.h>
20 #include <utl/UtlHashBag.h>
21 #include <utl/UtlSList.h>
22 #include "mp/MpTypes.h"
23 
24 // DEFINES
25 // MACROS
26 // EXTERNAL FUNCTIONS
27 // EXTERNAL VARIABLES
28 // CONSTANTS
29 // STRUCTS
30 // TYPEDEFS
31 // FORWARD DECLARATIONS
34 class UtlString;
35 class MpBufPtr;
36 class OsNotification;
37 class OsMsgDispatcher;
39 
67 {
68 /* //////////////////////////// PUBLIC //////////////////////////////////// */
69 public:
70 
71 /* ============================ CREATORS ================================== */
73 
74 
76  MpOutputDeviceManager(unsigned defaultSamplesPerFrame,
77  unsigned defaultSamplesPerSecond,
78  MpFrameTime defaultMixerBufferLength);
92  virtual
102 
103 /* ============================ MANIPULATORS ============================== */
105 
106 
135  int removeAllDevices();
141  OsStatus enableDevice(MpOutputDeviceHandle deviceId,
143  MpFrameTime mixerBufferLength = 0,
144  uint32_t samplesPerFrame = 0,
145  uint32_t samplesPerSec = 0);
173  OsStatus disableDevice(MpOutputDeviceHandle deviceId);
189  OsStatus disableAllDevicesExcept(int exceptCount = 0, MpOutputDeviceHandle exceptIdArray[] = NULL);
200  OsStatus pushFrameFirst(MpOutputDeviceHandle deviceId,
202  MpFrameTime &frameTime,
203  const MpBufPtr& frame,
204  UtlBoolean initFrameTime = FALSE);
238  OsStatus pushFrame(MpOutputDeviceHandle deviceId,
240  MpFrameTime frameTime,
241  const MpBufPtr& frame);
253  OsNotification *pFlowgraphTicker);
278 
279 /* ============================ ACCESSORS ================================= */
281 
282 
284  OsStatus getDeviceName(MpOutputDeviceHandle deviceId, UtlString& deviceName) const;
299  OsStatus getDeviceId(const UtlString& deviceName, MpOutputDeviceHandle &deviceId) const;
316  OsStatus getMixerBufferLength(MpOutputDeviceHandle deviceId, MpFrameTime &length) const;
336  OsStatus getDeviceSamplesPerSec(MpOutputDeviceHandle deviceId,
338  uint32_t& samplesPerSec) const;
351  uint32_t& samplesPerFrame) const;
361  OsMsgDispatcher* getNotificationDispatcher();
367  OsStatus addNotificationDispatcher(OsMsgDispatcher* notifyDispatcher); // , connectionId, streamId);
373  OsStatus removeNotificationDispatcher(OsMsgDispatcher* notifyDispatcher); // , connectionId, streamId);
379  OsStatus postNotification(const MpResNotificationMsg& msg);// resourceName);
386 
387 /* ============================ INQUIRY =================================== */
389 
390 
392  UtlBoolean isDeviceEnabled(MpOutputDeviceHandle deviceId) const;
400 
401 /* //////////////////////////// PROTECTED ///////////////////////////////// */
402 protected:
403 
405  int tries=10) const;
406  // Try 10 times (this is a blind guess).
407  // Checking every 10ms over 100ms seems reasonable.
408 
409 
410 /* //////////////////////////// PRIVATE /////////////////////////////////// */
411 private:
412 
413  mutable OsRWMutex mRwMutex;
422  OsTime mTimeZero;
424  UtlSList mNotifiers;
425 
427  MpOutputDeviceManager(const MpOutputDeviceManager& rMpOutputDeviceManager);
428 
431 
432 };
433 
434 /* ============================ INLINE METHODS ============================ */
435 
436 #endif // _MpOutputDeviceManager_h_
UtlSList mNotifiers
Definition: MpOutputDeviceManager.h:424
int samplesPerFrame
MpFrameTime getCurrentFrameTime(MpOutputDeviceHandle deviceId) const
Get current frame timestamp.
Definition: MpOutputDeviceManager.cpp:543
uint32_t MpFrameTime
Definition: MpTypes.h:53
OsStatus removeNotificationDispatcher(OsMsgDispatcher *notifyDispatcher)
remove given notifier to disable posting of notification messages to the notifier ...
Definition: MpOutputDeviceManager.cpp:637
MpOutputDeviceHandle mLastDeviceId
Definition: MpOutputDeviceManager.h:416
int removeAllDevices()
Definition: MpOutputDeviceManager.cpp:148
MpOutputDeviceHandle addDevice(MpOutputDeviceDriver *newDevice)
Add a new input device for use.
Definition: MpOutputDeviceManager.cpp:78
virtual ~MpOutputDeviceManager()
Destructor.
Definition: MpOutputDeviceManager.cpp:65
OsStatus setFlowgraphTickerSource(MpOutputDeviceHandle deviceId, OsNotification *pFlowgraphTicker)
Set device that will be used to send frame start message to media task.
Definition: MpOutputDeviceManager.cpp:397
OsRWMutex mRwMutex
Definition: MpOutputDeviceManager.h:413
OsStatus getDeviceSamplesPerSec(MpOutputDeviceHandle deviceId, uint32_t &samplesPerSec) const
Get the sample rate that a particular device is running at.
Definition: MpOutputDeviceManager.cpp:562
MpOutputDeviceHandle mCurrentTickerDevice
Definition: MpOutputDeviceManager.h:423
MpOutputDeviceManager(unsigned defaultSamplesPerFrame, unsigned defaultSamplesPerSecond, MpFrameTime defaultMixerBufferLength)
Default constructor.
Definition: MpOutputDeviceManager.cpp:46
MpOutputDeviceDriver * removeDevice(MpOutputDeviceHandle deviceId)
Remove an existing input device.
Definition: MpOutputDeviceManager.cpp:105
OsStatus addNotificationDispatcher(OsMsgDispatcher *notifyDispatcher)
Add notifier to enable posting of notification messages.
Definition: MpOutputDeviceManager.cpp:621
OsStatus getDeviceSamplesPerFrame(MpOutputDeviceHandle deviceId, uint32_t &samplesPerFrame) const
Get the number of samples per frame that a particular device is running at.
Definition: MpOutputDeviceManager.cpp:589
OsStatus getDeviceId(const UtlString &deviceName, MpOutputDeviceHandle &deviceId) const
Get the device id for the given device driver name.
Definition: MpOutputDeviceManager.cpp:495
MpAudioOutputConnection * findConnectionBlocking(MpOutputDeviceHandle deviceId, int tries=10) const
Definition: MpOutputDeviceManager.cpp:696
int MpOutputDeviceHandle
Definition: MpTypes.h:50
OsTime mTimeZero
Definition: MpOutputDeviceManager.h:422
unsigned mDefaultSamplesPerSecond
Definition: MpOutputDeviceManager.h:418
UtlHashMap mConnectionsByDeviceName
Definition: MpOutputDeviceManager.h:420
Definition: MpResNotificationMsg.h:31
OsStatus getDeviceName(MpOutputDeviceHandle deviceId, UtlString &deviceName) const
Get the device driver name for the given device ID.
Definition: MpOutputDeviceManager.cpp:467
OsStatus getMixerBufferLength(MpOutputDeviceHandle deviceId, MpFrameTime &length) const
Get mixer buffer length (in milliseconds) for given device.
Definition: MpOutputDeviceManager.cpp:517
MpOutputDeviceManager & operator=(const MpOutputDeviceManager &rhs)
Assignment operator (not implemented for this class)
UtlBoolean isDeviceEnabled(MpOutputDeviceHandle deviceId) const
Inquire if device is enabled (e.g. consuming media data).
Definition: MpOutputDeviceManager.cpp:670
Smart pointer to MpBuf.
Definition: MpBuf.h:160
OsMsgDispatcher * getNotificationDispatcher()
Get notifier to enable posting of notification messages.
Definition: MpOutputDeviceManager.cpp:608
Container of output devices.
Definition: MpOutputDeviceManager.h:66
UtlHashBag mConnectionsByDeviceId
Definition: MpOutputDeviceManager.h:421
OsStatus disableAllDevicesExcept(int exceptCount=0, MpOutputDeviceHandle exceptIdArray[]=NULL)
Helper to disable all device drivers except the optional list of devices.
Definition: MpOutputDeviceManager.cpp:287
OsStatus pushFrame(MpOutputDeviceHandle deviceId, MpFrameTime frameTime, const MpBufPtr &frame)
Method for sending frame of data to output device with initialized frame time.
Definition: MpOutputDeviceManager.cpp:390
OsStatus pushFrameFirst(MpOutputDeviceHandle deviceId, MpFrameTime &frameTime, const MpBufPtr &frame, UtlBoolean initFrameTime=FALSE)
Method for sending frame of data to output device.
Definition: MpOutputDeviceManager.cpp:331
unsigned mDefaultSamplesPerFrame
Definition: MpOutputDeviceManager.h:417
MpFrameTime mDefaultBufferLength
Definition: MpOutputDeviceManager.h:419
#define FALSE
Definition: PlgDefsV1.h:37
OsStatus enableDevice(MpOutputDeviceHandle deviceId, MpFrameTime mixerBufferLength=0, uint32_t samplesPerFrame=0, uint32_t samplesPerSec=0)
Helper to enable device driver.
Definition: MpOutputDeviceManager.cpp:194
OsStatus disableDevice(MpOutputDeviceHandle deviceId)
Helper to disable device driver.
Definition: MpOutputDeviceManager.cpp:233
OsStatus postNotification(const MpResNotificationMsg &msg)
Most a message to the notifer to interested parties.
Definition: MpOutputDeviceManager.cpp:657
Container for device specific output driver.
Definition: MpOutputDeviceDriver.h:53
Private container class for MpOutputDeviceDriver pointer and mixer buffer.
Definition: MpAudioOutputConnection.h:49