sipxmedialib  Version 3.3
MpidWinMM.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007-2021 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: Keith Kyzivat <kkyzivat AT SIPez DOT com>
12 
13 #ifndef _MpidWinMM_h_
14 #define _MpidWinMM_h_
15 
16 // SYSTEM INCLUDES
17 #define WIN32_LEAN_AND_MEAN
18 //#include <Windows.h>
19 #include <MMSystem.h>
20 
21 // APPLICATION INCLUDES
22 #include "mp/MpInputDeviceDriver.h"
23 
24 // DEFINES
25 #define DEFAULT_N_INPUT_BUFS 32
26 
27 // MACROS
28 // EXTERNAL FUNCTIONS
29 // EXTERNAL VARIABLES
30 // CONSTANTS
31 // STRUCTS
32 // TYPEDEFS
33 // FORWARD DECLARATIONS
35 struct IMMDeviceEnumerator;
36 struct IMMNotificationClient;
37 
47 {
48  friend class MpodWinMM;
49 
50 /* //////////////////////////// PUBLIC //////////////////////////////////// */
51 public:
52 
53 /* ============================ CREATORS ================================== */
55 
56 
58  MpidWinMM(const UtlString& name,
59  MpInputDeviceManager& deviceManager,
60  unsigned nInputBuffers = DEFAULT_N_INPUT_BUFS);
71  virtual
73  ~MpidWinMM();
74 
76 
77 /* ============================ MANIPULATORS ============================== */
79 
80 
82  OsStatus enableDevice(unsigned samplesPerFrame,
83  unsigned samplesPerSec,
84  MpFrameTime currentFrameTime);
99  OsStatus disableDevice();
110 
111 /* ============================ ACCESSORS ================================= */
113 
114 
116  static UtlString getDefaultDeviceName();
117 
119 
120 /* ============================ INQUIRY =================================== */
122 
123 
125  inline UtlBoolean isDeviceValid();
126 
128 
129 /* //////////////////////////// PROTECTED ///////////////////////////////// */
130 protected:
131 
133  WAVEHDR* initWaveHeader(int n);
141  void processAudioInput(HWAVEIN hwi,
143  UINT uMsg,
144  void* dwParam1);
151  static void CALLBACK waveInCallbackStatic(HWAVEIN hwi,
153  UINT uMsg,
154  void* dwInstance,
155  void* dwParam1,
156  void* dwParam2);
163  static bool nameIsSame(const UtlString& a, const UtlString& b);
164 
165  // Windows device accessors
167  static IMMDeviceEnumerator* getWinDeviceEnumerator();
168  static void registerDeviceEnumerator(IMMDeviceEnumerator* deviceEnumeratorPtr, IMMNotificationClient* winAudioDeviceChangeCallback);
169  static void unregisterDeviceEnumerator(IMMDeviceEnumerator* deviceEnumeratorPtr, IMMNotificationClient* winAudioDeviceChangeCallback);
170  static void getWinNameForDevice(IMMDeviceEnumerator* deviceEnumeratorPtr, const LPCWSTR winDeviceId, UtlString& deviceName);
171 
172 /* //////////////////////////// PRIVATE /////////////////////////////////// */
173 private:
174 
176  HWAVEIN mDevHandle;
178  unsigned mNumInBuffers;
179  unsigned mWaveBufSize;
181  WAVEHDR* mpWaveHeaders;
183  LPSTR* mpWaveBuffers;
184  UtlBoolean mIsOpen;
186  IMMNotificationClient* mWinAudioDeviceChangeCallback;
188  IMMDeviceEnumerator* mDeviceEnumeratorPtr;
190 
192  MpidWinMM(const MpInputDeviceDriver& rMpInputDeviceDriver);
193 
196 };
197 
198 /* ============================ INLINE METHODS ============================ */
199 
201 {
202  return (mWinMMDeviceId >= 0);
203 }
204 
205 
206 #endif // _MpidWinMM_h_
unsigned mNumInBuffers
Definition: MpidWinMM.h:178
static void registerDeviceEnumerator(IMMDeviceEnumerator *deviceEnumeratorPtr, IMMNotificationClient *winAudioDeviceChangeCallback)
Definition: MpidWinMM.cpp:806
HWAVEIN mDevHandle
The Microsoft handle for this audio input device.
Definition: MpidWinMM.h:177
virtual ~MpidWinMM()
Destructor.
Definition: MpidWinMM.cpp:367
void processAudioInput(HWAVEIN hwi, UINT uMsg, void *dwParam1)
Processes incoming audio data.
Definition: MpidWinMM.cpp:667
static UtlString getDefaultDeviceName()
get the windows name of the default wave input device.
Definition: MpidWinMM.cpp:606
unsigned mWaveBufSize
Definition: MpidWinMM.h:180
int samplesPerFrame
UtlBoolean isDeviceValid()
Inquire if the windows device is valid.
Definition: MpidWinMM.h:200
uint32_t MpFrameTime
Definition: MpTypes.h:53
static IMMDeviceEnumerator * getWinDeviceEnumerator()
Definition: MpidWinMM.cpp:778
UtlBoolean mIsOpen
Boolean indicating waveInOpen() completed.
Definition: MpidWinMM.h:184
LPSTR * mpWaveBuffers
Array of nNumInBuffers wave buffers.
Definition: MpidWinMM.h:183
static void getWinNameForDevice(IMMDeviceEnumerator *deviceEnumeratorPtr, const LPCWSTR winDeviceId, UtlString &deviceName)
Definition: MpidWinMM.cpp:864
IMMDeviceEnumerator * mDeviceEnumeratorPtr
Definition: MpidWinMM.h:189
Definition: MpidWinMM.cpp:41
IMMNotificationClient * mWinAudioDeviceChangeCallback
device state changes.
Definition: MpidWinMM.h:187
Container for the Microsoft Windows Multimedia specific input driver.
Definition: MpidWinMM.h:46
MpidWinMM & operator=(const MpInputDeviceDriver &rhs)
Assignment operator (not implemented for this class)
Container of input devices for input drivers and resources.
Definition: MpInputDeviceManager.h:79
WAVEHDR * mpWaveHeaders
Array of nNumInBuffers wave headers.
Definition: MpidWinMM.h:182
int mWinMMDeviceId
Definition: MpidWinMM.h:175
WAVEHDR * initWaveHeader(int n)
Zero out a wave header, so it is ready to be filled in by windows.
Definition: MpidWinMM.cpp:645
OsStatus enableDevice(unsigned samplesPerFrame, unsigned samplesPerSec, MpFrameTime currentFrameTime)
Initialize device driver and state.
Definition: MpidWinMM.cpp:404
Container for Microsoft Windows device specific output driver.
Definition: MpodWinMM.h:69
static bool nameIsSame(const UtlString &a, const UtlString &b)
Definition: MpidWinMM.cpp:921
static void unregisterDeviceEnumerator(IMMDeviceEnumerator *deviceEnumeratorPtr, IMMNotificationClient *winAudioDeviceChangeCallback)
Definition: MpidWinMM.cpp:831
Container for device specific input driver.
Definition: MpInputDeviceDriver.h:58
static void CALLBACK waveInCallbackStatic(HWAVEIN hwi, UINT uMsg, void *dwInstance, void *dwParam1, void *dwParam2)
Callback function for receiving data from windows audio.
Definition: MpidWinMM.cpp:764
OsStatus disableDevice()
Uninitialize device driver.
Definition: MpidWinMM.cpp:532
MpidWinMM(const UtlString &name, MpInputDeviceManager &deviceManager, unsigned nInputBuffers=DEFAULT_N_INPUT_BUFS)
Default constructor.
Definition: MpidWinMM.cpp:240
unsigned mnAddBufferFailures
within the callback has failed since last enabled.
Definition: MpidWinMM.h:185
#define DEFAULT_N_INPUT_BUFS
Definition: MpidWinMM.h:25