sipxmedialib  Version 3.3
MpAudioOutputConnection.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007-2013 SIPez LLC. All rights reserved.
3 //
4 // Copyright (C) 2007 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 _MpAudioOutputConnection_h_
13 #define _MpAudioOutputConnection_h_
14 
15 // SYSTEM INCLUDES
16 
17 // APPLICATION INCLUDES
18 #include <mp/MpTypes.h>
20 #include <utl/UtlInt.h>
21 #include <os/OsMutex.h>
22 #include <os/OsCallback.h>
23 
24 // DEFINES
25 // MACROS
26 // EXTERNAL FUNCTIONS
27 // EXTERNAL VARIABLES
28 // CONSTANTS
29 // STRUCTS
30 // TYPEDEFS
31 // FORWARD DECLARATIONS
32 
49 class MpAudioOutputConnection : public UtlInt
50 {
51 /* //////////////////////////// PUBLIC //////////////////////////////////// */
52 public:
53 
54 /* ============================ CREATORS ================================== */
56 
57 
60  MpOutputDeviceDriver *deviceDriver);
66  virtual
69 
71 
72 /* ============================ MANIPULATORS ============================== */
74 
75 
77  OsStatus enableDevice(unsigned samplesPerFrame,
78  unsigned samplesPerSec,
79  MpFrameTime currentFrameTime,
80  MpFrameTime mixerBufferLength);
99  OsStatus disableDevice();
108  OsStatus enableFlowgraphTicker(OsNotification *pFlowgraphTicker);
118  OsStatus disableFlowgraphTicker();
125  OsStatus pushFrameBeginning(unsigned int numSamples,
127  const MpAudioSample* samples,
128  MpFrameTime &frameTime);
143  OsStatus pushFrame(unsigned int numSamples,
145  const MpAudioSample* samples,
146  MpFrameTime frameTime);
163  inline
165  unsigned increaseUseCount();
181  inline
183  unsigned decreaseUseCount();
194 
195 /* ============================ ACCESSORS ================================= */
197 
198 
200  inline
202 
204  inline
206 
208  inline
209  unsigned getUseCount() const;
219  inline
221  unsigned getSamplesPerFrame() const;
222 
224 
226 
227 /* ============================ INQUIRY =================================== */
229 
230 
232 
233 /* //////////////////////////// PROTECTED ///////////////////////////////// */
234 protected:
235 
237 
238 
240  OsStatus initMixerBuffer(unsigned mixerBufferLength);
249  OsStatus freeMixerBuffer();
258  OsStatus mixFrame(unsigned frameOffset,
260  const MpAudioSample* samples,
261  unsigned numSamples);
274  inline OsStatus isLateToMix(unsigned frameOffset,
276  unsigned numSamples) const;
290  OsStatus advanceMixerBuffer(unsigned numSamples);
302  static
304  void readyForDataCallback(const intptr_t userData, const intptr_t eventData);
311 
312 /* //////////////////////////// PRIVATE /////////////////////////////////// */
313 private:
314 
315  mutable OsMutex mMutex;
316  int mUseCount;
317 
321 
324  unsigned mMixerBufferBegin;
326 
328  OsNotification *mpFlowgraphTicker;
331 
333 
335  MpAudioOutputConnection(const MpAudioOutputConnection& rMpAudioOutputConnection);
336 
339 
340 };
341 
342 /* ============================ INLINE METHODS ============================ */
343 
345 {
346  return ++mUseCount;
347 }
348 
350 {
351  return --mUseCount;
352 }
353 
355 {
356  return mpDeviceDriver;
357 };
358 
360 {
362 }
363 
365 {
366  return mUseCount;
367 }
368 
370 {
372 }
373 
374 OsStatus MpAudioOutputConnection::isLateToMix(unsigned frameOffset,
375  unsigned numSamples) const
376 {
377 
378  // Whole frame should fit into buffer to be accepted.
379  if (frameOffset+numSamples > mMixerBufferLength)
380  {
381  return OS_LIMIT_REACHED;
382  }
383  return OS_SUCCESS;
384 }
385 
386 #endif // _MpAudioOutputConnection_h_
MpFrameTime getCurrentFrameTime() const
Definition: MpAudioOutputConnection.cpp:329
int samplesPerFrame
unsigned getUseCount() const
Return number of external entities, referring to this connection.
Definition: MpAudioOutputConnection.h:364
unsigned mMixerBufferBegin
Index of first available sample in mixer buffer.
Definition: MpAudioOutputConnection.h:325
virtual ~MpAudioOutputConnection()
Destructor.
Definition: MpAudioOutputConnection.cpp:93
MpAudioOutputConnection & operator=(const MpAudioOutputConnection &rhs)
Assignment operator (not implemented for this class)
uint32_t MpFrameTime
Definition: MpTypes.h:53
OsStatus freeMixerBuffer()
Free mixer buffer and set all related member variables to zero.
Definition: MpAudioOutputConnection.cpp:368
unsigned mMixerBufferLength
Length of mixer buffer (in samples).
Definition: MpAudioOutputConnection.h:322
MpAudioOutputConnection(MpOutputDeviceHandle deviceId, MpOutputDeviceDriver *deviceDriver)
Default constructor.
Definition: MpAudioOutputConnection.cpp:77
unsigned increaseUseCount()
Add one more reference to this connection.
Definition: MpAudioOutputConnection.h:344
unsigned decreaseUseCount()
Remove one reference to this connection.
Definition: MpAudioOutputConnection.h:349
OsStatus advanceMixerBuffer(unsigned numSamples)
Pull frame from mixer buffer.
Definition: MpAudioOutputConnection.cpp:431
MpFrameTime getMixerBufferLength() const
Return length of mixer buffer in milliseconds.
Definition: MpAudioOutputConnection.h:359
int mUseCount
Use counter, used to implement safe delete.
Definition: MpAudioOutputConnection.h:316
unsigned getSamplesPerSec() const
Get number of samples per second.
Definition: MpOutputDeviceDriver.h:239
OsStatus initMixerBuffer(unsigned mixerBufferLength)
Allocate mixer buffer and initialize all related member variables.
Definition: MpAudioOutputConnection.cpp:345
OsMutex mMutex
Mutex to synchronize access to connection.
Definition: MpAudioOutputConnection.h:315
int16_t MpAudioSample
Definition: MpTypes.h:44
MpOutputDeviceDriver * mpDeviceDriver
connection.
Definition: MpAudioOutputConnection.h:318
unsigned getSamplesPerFrame() const
Return number of samples per frame, this driver expect from flowgraph.
Definition: MpAudioOutputConnection.h:369
OsStatus pushFrame(unsigned int numSamples, const MpAudioSample *samples, MpFrameTime frameTime)
Send data frame to output device.
Definition: MpAudioOutputConnection.cpp:254
int MpOutputDeviceHandle
Definition: MpTypes.h:50
OsStatus enableFlowgraphTicker(OsNotification *pFlowgraphTicker)
Use this device to signal frame processing interval start.
Definition: MpAudioOutputConnection.cpp:181
OsStatus disableDevice()
Uninitialize device driver.
Definition: MpAudioOutputConnection.cpp:157
OsStatus disableFlowgraphTicker()
Stop using this device to signal frame processing interval start.
Definition: MpAudioOutputConnection.cpp:200
unsigned getSamplesPerFrame() const
Get number of samples in a frame.
Definition: MpOutputDeviceDriver.h:234
OsStatus enableDevice(unsigned samplesPerFrame, unsigned samplesPerSec, MpFrameTime currentFrameTime, MpFrameTime mixerBufferLength)
Initialize device driver and mixer buffer.
Definition: MpAudioOutputConnection.cpp:99
OsNotification * mpFlowgraphTicker
when it should process next frame.
Definition: MpAudioOutputConnection.h:330
MpOutputDeviceDriver * getDeviceDriver() const
Return device driver contained in this connection.
Definition: MpAudioOutputConnection.h:354
OsStatus isLateToMix(unsigned frameOffset, unsigned numSamples) const
Check whether it&#39;s too late to mix this frame in or not (does not check for too early).
Definition: MpAudioOutputConnection.h:374
MpFrameTime mCurrentFrameTime
Frame time of the mixer buffer begin.
Definition: MpAudioOutputConnection.h:320
static void readyForDataCallback(const intptr_t userData, const intptr_t eventData)
Call this when driver become ready for the next frame.
Definition: MpAudioOutputConnection.cpp:469
OsCallback readyForDataCallbackNotf
Definition: MpAudioOutputConnection.h:327
OsStatus mixFrame(unsigned frameOffset, const MpAudioSample *samples, unsigned numSamples)
Mix frame to mixer buffer.
Definition: MpAudioOutputConnection.cpp:381
OsStatus pushFrameBeginning(unsigned int numSamples, const MpAudioSample *samples, MpFrameTime &frameTime)
Send data frame to the beginning of mixer buffer and return frame time.
Definition: MpAudioOutputConnection.cpp:219
MpAudioSample * mpMixerBuffer
several media streams.
Definition: MpAudioOutputConnection.h:323
Container for device specific output driver.
Definition: MpOutputDeviceDriver.h:53
Private container class for MpOutputDeviceDriver pointer and mixer buffer.
Definition: MpAudioOutputConnection.h:49