sipxmedialib  Version 3.3
MpOutputDeviceDriver.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007-2017 SIPez LLC. All rights reserved.
3 //
4 //
5 // $$
7 
8 // Author: Alexander Chemeris <Alexander DOT Chemeris AT SIPez DOT com>
9 
10 #ifndef _MpOutputDeviceDriver_h_
11 #define _MpOutputDeviceDriver_h_
12 
13 // SYSTEM INCLUDES
14 //#include <utl/UtlDefs.h>
15 #include <os/OsStatus.h>
16 #include <os/OsAtomics.h>
17 #include <utl/UtlString.h>
18 
19 // APPLICATION INCLUDES
20 #include "mp/MpTypes.h"
21 
22 // DEFINES
23 // MACROS
24 // EXTERNAL FUNCTIONS
25 // EXTERNAL VARIABLES
26 // CONSTANTS
27 // STRUCTS
28 // TYPEDEFS
29 // FORWARD DECLARATIONS
30 class OsCallback;
31 
53 class MpOutputDeviceDriver : public UtlString
54 {
55 /* //////////////////////////// PUBLIC //////////////////////////////////// */
56 public:
57 
58 /* ============================ CREATORS ================================== */
60 
61 
63  explicit
64  MpOutputDeviceDriver(const UtlString& name);
70  virtual
73 
75 
76 /* ============================ MANIPULATORS ============================== */
78 
79 
81  virtual OsStatus enableDevice(unsigned samplesPerFrame,
82  unsigned samplesPerSec,
83  MpFrameTime currentFrameTime,
84  OsCallback &frameTicker) = 0;
111  virtual OsStatus disableDevice() = 0;
125  virtual
127  OsStatus pushFrame(unsigned int numSamples,
128  const MpAudioSample* samples,
129  MpFrameTime frameTime) = 0;
152 
153 /* ============================ ACCESSORS ================================= */
155 
156 
158  inline
159  MpFrameTime getFramePeriod() const;
160 
162  inline
163  unsigned getSamplesPerFrame() const;
164 
166  inline
167  unsigned getSamplesPerSec() const;
168 
170  static inline
171  MpFrameTime getFramePeriod(unsigned samplesPerFrame,
172  unsigned samplesPerSec);
173 
175  inline
176  const UtlString &getDeviceName() const;
177 
179 
180 /* ============================ INQUIRY =================================== */
182 
183  virtual OsStatus canEnable() {return(OS_SUCCESS);};
193  virtual UtlBoolean isEnabled() const;
195 
197 
198 /* //////////////////////////// PROTECTED ///////////////////////////////// */
199 protected:
200 
201  OsAtomicLightBool mIsEnabled;
202  OsAtomicLightUInt mSamplesPerFrame;
203  OsAtomicLightUInt mSamplesPerSec;
205  OsCallback *mpTickerNotification;
207 
209 /* //////////////////////////// PRIVATE /////////////////////////////////// */
210 private:
211 
213  MpOutputDeviceDriver(const MpOutputDeviceDriver& rMpOutputDeviceDriver);
214 
217 };
218 
219 
220 /* ============================ INLINE METHODS ============================ */
221 
223 {
225 }
226 
228  unsigned samplesPerSec)
229 {
230  assert(samplesPerSec);
231  return(samplesPerSec ? ((1000*samplesPerFrame)/samplesPerSec) : 0);
232 }
233 
235 {
236  return mSamplesPerFrame;
237 }
238 
240 {
241  return mSamplesPerSec;
242 }
243 
244 const UtlString &MpOutputDeviceDriver::getDeviceName() const
245 {
246  return *this;
247 }
248 
249 #endif // _MpOutputDeviceDriver_h_
virtual OsStatus enableDevice(unsigned samplesPerFrame, unsigned samplesPerSec, MpFrameTime currentFrameTime, OsCallback &frameTicker)=0
Initialize device driver and state.
int samplesPerFrame
OsAtomicLightUInt mSamplesPerSec
of samples per second.
Definition: MpOutputDeviceDriver.h:204
virtual UtlBoolean isEnabled() const
Inquire if this driver is enabled.
Definition: MpOutputDeviceDriver.cpp:48
virtual OsStatus disableDevice()=0
Uninitialize device driver.
uint32_t MpFrameTime
Definition: MpTypes.h:53
OsAtomicLightUInt mSamplesPerFrame
number of samples.
Definition: MpOutputDeviceDriver.h:202
const UtlString & getDeviceName() const
Get device name.
Definition: MpOutputDeviceDriver.h:244
unsigned getSamplesPerSec() const
Get number of samples per second.
Definition: MpOutputDeviceDriver.h:239
OsAtomicLightBool mIsEnabled
Whether this device driver is enabled or not.
Definition: MpOutputDeviceDriver.h:201
int16_t MpAudioSample
Definition: MpTypes.h:44
MpFrameTime getFramePeriod() const
Calculate the number of milliseconds that a frame occupies in time.
Definition: MpOutputDeviceDriver.h:222
virtual OsStatus pushFrame(unsigned int numSamples, const MpAudioSample *samples, MpFrameTime frameTime)=0
Send data to output device.
unsigned getSamplesPerFrame() const
Get number of samples in a frame.
Definition: MpOutputDeviceDriver.h:234
virtual OsStatus canEnable()
Check if this device can connect.
Definition: MpOutputDeviceDriver.h:184
OsCallback * mpTickerNotification
is ready to accept more data. See enableDevice() for details.
Definition: MpOutputDeviceDriver.h:206
virtual ~MpOutputDeviceDriver()
Destructor.
Definition: MpOutputDeviceDriver.cpp:37
MpOutputDeviceDriver & operator=(const MpOutputDeviceDriver &rhs)
Assignment operator (not implemented for this class)
MpOutputDeviceDriver(const UtlString &name)
Default constructor.
Definition: MpOutputDeviceDriver.cpp:28
Container for device specific output driver.
Definition: MpOutputDeviceDriver.h:53