sipxmedialib  Version 3.3
MpidCoreAudio.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2007 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // $$
10 
11 // Author: Sergey Kostanbaev <Sergey DOT Kostanbaev AT sipez DOT com>
12 
13 #ifndef _MpidCoreAudio_h_
14 #define _MpidCoreAudio_h_
15 
16 // SYSTEM INCLUDES
17 #include <pthread.h>
18 #include <semaphore.h>
19 
20 
21 // APPLICATION INCLUDES
22 #include "mp/MpInputDeviceDriver.h"
23 #include "mp/MpCoreAudioHardware.h"
24 
25 // DEFINES
26 // MACROS
27 // EXTERNAL FUNCTIONS
28 // EXTERNAL VARIABLES
29 // CONSTANTS
30 // STRUCTS
31 // TYPEDEFS
32 // FORWARD DECLARATIONS
34 
39 {
40 /* //////////////////////////// PUBLIC //////////////////////////////////// */
41 public:
42 
43 /* ============================ CREATORS ================================== */
45 
46 
48  MpidCoreAudio(const UtlString& name,
49  MpInputDeviceManager& deviceManager);
59 
61 
62 /* ============================ MANIPULATORS ============================== */
64 
65 
67  OsStatus enableDevice(unsigned samplesPerFrame,
68  unsigned samplesPerSec,
69  MpFrameTime currentFrameTime);
70 
72  OsStatus disableDevice();
73 
75 
76 /* ============================ ACCESSORS ================================= */
78 
79 
81 
82 /* ============================ INQUIRY =================================== */
84 
85 
87  UtlBoolean isDeviceValid();
88 
90 
91 /* //////////////////////////// PROTECTED ///////////////////////////////// */
92 protected:
93  AudioUnit mInputUnit;
94  AudioConverterRef mConverter;
96 
99 
100  void* mTempBuffer;
103  unsigned mInputFrameSize;
104 
106  void pushFrame();
107 
109  void skipFrame();
110 
111  bool setAudioUnitFormat(const AudioStreamBasicDescription& ds);
112 
113  bool initResempler(const AudioStreamBasicDescription& ds);
114 
115  bool setBuffers();
116 
117  static
118  void propertyListener(void * inRefCon,
119  AudioUnit ci,
120  AudioUnitPropertyID inID,
121  AudioUnitScope inScope,
122  AudioUnitElement inElement);
123 
124  static
125  OSStatus renderProc(void * inRefCon,
126  AudioUnitRenderActionFlags* inActionFlags,
127  const AudioTimeStamp * inTimeStamp,
128  UInt32 inBusNumber,
129  UInt32 inNumFrames,
130  AudioBufferList * ioData);
131 
132  static
133  OSStatus ACproc(AudioConverterRef inAudioConverter,
134  UInt32 * ioDataPackets,
135  AudioBufferList* ioData,
136  AudioStreamPacketDescription ** inUserData,
137  void *inUData);
138 
139 /* //////////////////////////// PRIVATE /////////////////////////////////// */
140 private:
141 
143  MpidCoreAudio(const MpidCoreAudio& rMpInputDeviceDriver);
144 
147 
148 };
149 
150 /* ============================ INLINE METHODS ============================ */
151 
152 #endif // _MpidCoreAudio_h_
void * mTempBufferHalf
Pointer to the center of the temp buffer.
Definition: MpidCoreAudio.h:101
OsStatus disableDevice()
Uninitialize device driver.
Definition: MpidCoreAudio.cpp:292
void * mTempBuffer
Buffer for temporary storage.
Definition: MpidCoreAudio.h:100
unsigned mInputFrameSize
Device input frame size.
Definition: MpidCoreAudio.h:103
bool setBuffers()
Definition: MpidCoreAudio.cpp:426
int samplesPerFrame
uint32_t MpFrameTime
Definition: MpTypes.h:53
bool initResempler(const AudioStreamBasicDescription &ds)
Definition: MpidCoreAudio.cpp:404
unsigned mTempBufferHalfSize
Half size of buffer.
Definition: MpidCoreAudio.h:102
UtlBoolean isDeviceValid()
Inquire if the device is valid.
Definition: MpidCoreAudio.cpp:324
MpAudioSample * mAudioFrame
Wave buffer for silence.
Definition: MpidCoreAudio.h:98
CoreAudioHardware mDevice
CoreAudio hardware device handle.
Definition: MpidCoreAudio.h:95
OsStatus enableDevice(unsigned samplesPerFrame, unsigned samplesPerSec, MpFrameTime currentFrameTime)
Initialize device driver and state.
Definition: MpidCoreAudio.cpp:66
int16_t MpAudioSample
Definition: MpTypes.h:44
Container of input devices for input drivers and resources.
Definition: MpInputDeviceManager.h:79
AudioConverterRef mConverter
Sample rate converter.
Definition: MpidCoreAudio.h:94
static void propertyListener(void *inRefCon, AudioUnit ci, AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement)
Definition: MpidCoreAudio.cpp:473
MpidCoreAudio & operator=(const MpidCoreAudio &rhs)
Assignment operator (not implemented for this class).
static OSStatus ACproc(AudioConverterRef inAudioConverter, UInt32 *ioDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription **inUserData, void *inUData)
Definition: MpidCoreAudio.cpp:596
bool setAudioUnitFormat(const AudioStreamBasicDescription &ds)
Definition: MpidCoreAudio.cpp:346
double mInputSampleRate
Device smaple rate.
Definition: MpidCoreAudio.h:97
void skipFrame()
Add frame time to mCurrentFrameTime.
Definition: MpidCoreAudio.cpp:341
void pushFrame()
Push audio frame to InputDeviceManager.
Definition: MpidCoreAudio.cpp:330
Container for device specific input driver.
Definition: MpInputDeviceDriver.h:58
Container for CoreAudio hardware device specific.
Definition: MpCoreAudioHardware.h:40
static OSStatus renderProc(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
Definition: MpidCoreAudio.cpp:541
Container for device specific input CoreAudio driver.
Definition: MpidCoreAudio.h:38
MpidCoreAudio(const UtlString &name, MpInputDeviceManager &deviceManager)
Default constructor.
Definition: MpidCoreAudio.cpp:49
AudioUnit mInputUnit
AudioUnit input handle.
Definition: MpidCoreAudio.h:93
~MpidCoreAudio()
Destructor.
Definition: MpidCoreAudio.cpp:58