sipxmedialib  Version 3.3
MpInputDeviceManager.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: Dan Petrie <dpetrie AT SIPez DOT com>
11 
12 #ifndef _MpInputDeviceManager_h_
13 #define _MpInputDeviceManager_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 #define MP_INVALID_INPUT_DEVICE_HANDLE -1
26 
27 // MACROS
28 // EXTERNAL FUNCTIONS
29 // EXTERNAL VARIABLES
30 // CONSTANTS
31 // STRUCTS
32 // TYPEDEFS
33 // FORWARD DECLARATIONS
35 class UtlString;
36 class MpBufPtr;
37 class MpBufPool;
38 class OsMsgDispatcher;
40 
80 {
81 /* //////////////////////////// PUBLIC //////////////////////////////////// */
82 public:
83 
84 /* ============================ CREATORS ================================== */
86 
87 
89  MpInputDeviceManager(unsigned defaultSamplesPerFrame,
90  unsigned defaultSamplesPerSecond,
91  unsigned defaultNumBufferedFrames,
92  MpBufPool& bufferPool);
107  virtual
117 
118 /* ============================ MANIPULATORS ============================== */
120 
121 
148  int removeAllDevices();
154  OsStatus setupDevice(MpInputDeviceHandle deviceId,
156  uint32_t samplesPerFrame = 0,
157  uint32_t samplesPerSec = 0);
178  OsStatus enableDevice(MpInputDeviceHandle deviceId);
193  OsStatus disableDevice(MpInputDeviceHandle deviceId);
208  OsStatus disableAllDevicesExcept(int exceptCount = 0, MpInputDeviceHandle exceptIdArray[] = NULL);
218  OsStatus pushFrame(MpInputDeviceHandle deviceId,
220  unsigned numSamples,
221  MpAudioSample *samples,
222  MpFrameTime frameTime);
242  OsStatus getFrame(MpInputDeviceHandle deviceId,
244  MpFrameTime &frameTime,
245  MpBufPtr& buffer,
246  unsigned& numFramesBefore,
247  unsigned& numFramesAfter);
276 
277 /* ============================ ACCESSORS ================================= */
279 
280 
282  OsStatus getDeviceName(MpInputDeviceHandle deviceId, UtlString& deviceName) const;
296  OsStatus getDeviceId(const UtlString& deviceName,
298  MpInputDeviceHandle& deviceId) const;
329  OsStatus getDeviceSamplesPerSec(MpInputDeviceHandle deviceId,
331  uint32_t& samplesPerSec) const;
344  uint32_t& samplesPerFrame) const;
355  OsStatus getTimeDerivatives(MpInputDeviceHandle deviceId,
358  unsigned& nDerivatives,
359  double*& derivativeBuf) const;
380  OsMsgDispatcher* getNotificationDispatcher();
386  OsStatus addNotificationDispatcher(OsMsgDispatcher* notifyDispatcher); // , connectionId, streamId);
392  OsStatus removeNotificationDispatcher(OsMsgDispatcher* notifyDispatcher); // , connectionId, streamId);
398  OsStatus postNotification(const MpResNotificationMsg& msg);// resourceName);
405 
406 /* ============================ INQUIRY =================================== */
408 
409 
411  UtlBoolean isDeviceEnabled(MpInputDeviceHandle deviceId) const;
419 
420 /* //////////////////////////// PROTECTED ///////////////////////////////// */
421 protected:
422 
423 
424 /* //////////////////////////// PRIVATE /////////////////////////////////// */
425 private:
426 
427  mutable OsRWMutex mRwMutex;
433  UtlSList mNotifiers;
436  OsTime mTimeZero;
437 
439  MpInputDeviceManager(const MpInputDeviceManager& rMpInputDeviceManager);
440 
443 
444 };
445 
446 /* ============================ INLINE METHODS ============================ */
447 
448 #endif // _MpInputDeviceManager_h_
OsStatus setupDevice(MpInputDeviceHandle deviceId, uint32_t samplesPerFrame=0, uint32_t samplesPerSec=0)
Set device parameters before enabling it.
Definition: MpInputDeviceManager.cpp:684
OsStatus getDeviceId(const UtlString &deviceName, MpInputDeviceHandle &deviceId) const
Get the device id for the given device driver name.
Definition: MpInputDeviceManager.cpp:951
int samplesPerFrame
MpInputDeviceHandle mLastDeviceId
Definition: MpInputDeviceManager.h:428
OsStatus getDeviceSamplesPerSec(MpInputDeviceHandle deviceId, uint32_t &samplesPerSec) const
Get the sample rate that a particular device is running at.
Definition: MpInputDeviceManager.cpp:994
MpInputDeviceHandle addDevice(MpInputDeviceDriver &newDevice)
Add a new input device for use.
Definition: MpInputDeviceManager.cpp:517
uint32_t MpFrameTime
Definition: MpTypes.h:53
MpInputDeviceManager & operator=(const MpInputDeviceManager &rhs)
Assignment operator (not implemented for this class)
OsStatus getTimeDerivatives(MpInputDeviceHandle deviceId, unsigned &nDerivatives, double *&derivativeBuf) const
Method for obtaining the time derivatives for sequential frames.
Definition: MpInputDeviceManager.cpp:1036
OsStatus enableDevice(MpInputDeviceHandle deviceId)
Helper to enable device driver.
Definition: MpInputDeviceManager.cpp:704
unsigned mDefaultNumBufferedFrames
Definition: MpInputDeviceManager.h:431
OsMsgDispatcher * getNotificationDispatcher()
Get notifier to enable posting of notification messages.
Definition: MpInputDeviceManager.cpp:1063
OsStatus getDeviceSamplesPerFrame(MpInputDeviceHandle deviceId, uint32_t &samplesPerFrame) const
Get the number of samples per frame that a particular device is running at.
Definition: MpInputDeviceManager.cpp:1018
OsRWMutex mRwMutex
Definition: MpInputDeviceManager.h:427
MpInputDeviceDriver * removeDevice(MpInputDeviceHandle deviceId)
Remove an existing input device.
Definition: MpInputDeviceManager.cpp:561
int16_t MpAudioSample
Definition: MpTypes.h:44
MpFrameTime getCurrentFrameTime(MpInputDeviceHandle deviceId) const
Get current frame timestamp.
Definition: MpInputDeviceManager.cpp:975
UtlHashMap mConnectionsByDeviceName
Definition: MpInputDeviceManager.h:434
OsStatus disableDevice(MpInputDeviceHandle deviceId)
Helper to disable device driver.
Definition: MpInputDeviceManager.cpp:733
Container of input devices for input drivers and resources.
Definition: MpInputDeviceManager.h:79
UtlSList mNotifiers
Definition: MpInputDeviceManager.h:433
unsigned mDefaultSamplesPerFrame
Definition: MpInputDeviceManager.h:429
UtlHashBag mConnectionsByDeviceId
Definition: MpInputDeviceManager.h:435
OsStatus pushFrame(MpInputDeviceHandle deviceId, unsigned numSamples, MpAudioSample *samples, MpFrameTime frameTime)
Method for MpInputDeviceDriver to push a frame of media for a given time.
Definition: MpInputDeviceManager.cpp:852
Definition: MpResNotificationMsg.h:31
OsStatus getDeviceName(MpInputDeviceHandle deviceId, UtlString &deviceName) const
Get the device driver name for the given device ID.
Definition: MpInputDeviceManager.cpp:918
int removeAllDevices()
Definition: MpInputDeviceManager.cpp:638
OsTime mTimeZero
Definition: MpInputDeviceManager.h:436
OsStatus postNotification(const MpResNotificationMsg &msg)
Most a message to the notifer to interested parties.
Definition: MpInputDeviceManager.cpp:1112
MpBufPool * mpBufferPool
Definition: MpInputDeviceManager.h:432
UtlBoolean isDeviceEnabled(MpInputDeviceHandle deviceId) const
Inquire if device is enabled (e.g. generating media data).
Definition: MpInputDeviceManager.cpp:1125
Smart pointer to MpBuf.
Definition: MpBuf.h:160
Container for device specific input driver.
Definition: MpInputDeviceDriver.h:58
int MpInputDeviceHandle
Definition: MpTypes.h:48
virtual ~MpInputDeviceManager()
Destructor.
Definition: MpInputDeviceManager.cpp:504
OsStatus addNotificationDispatcher(OsMsgDispatcher *notifyDispatcher)
Add a notifier to enable posting of notification messages.
Definition: MpInputDeviceManager.cpp:1076
OsStatus removeNotificationDispatcher(OsMsgDispatcher *notifyDispatcher)
remove given notifier to disable posting of notification messages to the notifier ...
Definition: MpInputDeviceManager.cpp:1092
MpInputDeviceManager(unsigned defaultSamplesPerFrame, unsigned defaultSamplesPerSecond, unsigned defaultNumBufferedFrames, MpBufPool &bufferPool)
Default constructor.
Definition: MpInputDeviceManager.cpp:484
OsStatus disableAllDevicesExcept(int exceptCount=0, MpInputDeviceHandle exceptIdArray[]=NULL)
Helper to disable all device drivers except the optional list of devices.
Definition: MpInputDeviceManager.cpp:808
Pool of buffers.
Definition: MpBufPool.h:32
unsigned mDefaultSamplesPerSecond
Definition: MpInputDeviceManager.h:430
OsStatus getFrame(MpInputDeviceHandle deviceId, MpFrameTime &frameTime, MpBufPtr &buffer, unsigned &numFramesBefore, unsigned &numFramesAfter)
Method for obtaining the buffer for a given frame and device ID.
Definition: MpInputDeviceManager.cpp:879