ReactOS 0.4.15-dev-7712-gbbbcd8e
capture.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Configuration of network devices
4 * FILE: dll/directx/dsound_new/capture.c
5 * PURPOSE: Implement IDirectSoundCapture
6 *
7 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8 */
9
10#include "precomp.h"
11
12typedef struct
13{
14 IDirectSoundCaptureVtbl *lpVtbl;
20
26 LPVOID * ppobj)
27{
28 LPOLESTR pStr;
30
31 /* check if the interface is supported */
33 IsEqualIID(riid, &IID_IDirectSoundCapture))
34 {
35 *ppobj = (LPVOID)&This->lpVtbl;
37 return S_OK;
38 }
39
40 /* unsupported interface */
41 if (SUCCEEDED(StringFromIID(riid, &pStr)))
42 {
43 DPRINT("No Interface for class %s\n", pStr);
44 CoTaskMemFree(pStr);
45 }
46 return E_NOINTERFACE;
47}
48
53{
54 ULONG ref;
56
57 /* increment reference count */
59
60 return ref;
61}
62
67{
68 ULONG ref;
70
71 /* release reference count */
72 ref = InterlockedDecrement(&(This->ref));
73
74 if (!ref)
75 {
77 }
78
79 return ref;
80}
81
82
87 LPCDSCBUFFERDESC lpcDSBufferDesc,
88 LPDIRECTSOUNDCAPTUREBUFFER *ppDSCBuffer,
89 LPUNKNOWN pUnkOuter)
90{
91 HRESULT hResult;
93
94 if (!This->bInitialized)
95 {
96 /* object not yet initialized */
98 }
99
100 if (!lpcDSBufferDesc || !ppDSCBuffer || pUnkOuter != NULL)
101 {
102 /* invalid param */
103 return DSERR_INVALIDPARAM;
104 }
105
106 /* check buffer description */
107 if ((lpcDSBufferDesc->dwSize != sizeof(DSCBUFFERDESC) && lpcDSBufferDesc->dwSize != sizeof(DSCBUFFERDESC1)) ||
108 lpcDSBufferDesc->dwReserved != 0 || lpcDSBufferDesc->dwBufferBytes == 0 || lpcDSBufferDesc->lpwfxFormat == NULL)
109 {
110 /* invalid buffer description */
111 return DSERR_INVALIDPARAM;
112 }
113
114 DPRINT("This %p wFormatTag %x nChannels %u nSamplesPerSec %u nAvgBytesPerSec %u NBlockAlign %u wBitsPerSample %u cbSize %u\n",
115 This, lpcDSBufferDesc->lpwfxFormat->wFormatTag, lpcDSBufferDesc->lpwfxFormat->nChannels, lpcDSBufferDesc->lpwfxFormat->nSamplesPerSec, lpcDSBufferDesc->lpwfxFormat->nAvgBytesPerSec, lpcDSBufferDesc->lpwfxFormat->nBlockAlign, lpcDSBufferDesc->lpwfxFormat->wBitsPerSample, lpcDSBufferDesc->lpwfxFormat->cbSize);
116
117 hResult = NewDirectSoundCaptureBuffer((LPDIRECTSOUNDCAPTUREBUFFER8*)ppDSCBuffer, This->Filter, lpcDSBufferDesc);
118 return hResult;
119}
120
121
123WINAPI
126 LPDSCCAPS pDSCCaps)
127{
128 WAVEINCAPSW Caps;
131
132 if (!This->bInitialized)
133 {
134 /* object not yet initialized */
135 return DSERR_UNINITIALIZED;
136 }
137
138 if (!pDSCCaps)
139 {
140 /* invalid param */
141 return DSERR_INVALIDPARAM;
142 }
143
144 if (pDSCCaps->dwSize != sizeof(DSCCAPS))
145 {
146 /* invalid param */
147 return DSERR_INVALIDPARAM;
148 }
149
150
151 /* We are certified ;) */
152 pDSCCaps->dwFlags = DSCCAPS_CERTIFIED;
153
154 ASSERT(This->Filter);
155
156 Result = waveInGetDevCapsW(This->Filter->MappedId[0], &Caps, sizeof(WAVEINCAPSW));
158 {
159 /* failed */
160 DPRINT("waveInGetDevCapsW for device %u failed with %x\n", This->Filter->MappedId[0], Result);
161 return DSERR_UNSUPPORTED;
162 }
163
164 pDSCCaps->dwFormats = Caps.dwFormats;
165 pDSCCaps->dwChannels = Caps.wChannels;
166
167 return DS_OK;
168}
169
170
172WINAPI
175 LPCGUID pcGuidDevice)
176{
177 GUID DeviceGuid;
178 LPOLESTR pGuidStr;
180
181 /* sanity check */
183
184 if (This->bInitialized)
185 {
186 /* object has already been initialized */
188 }
189
190 /* fixme mutual exclusion */
191
192 if (pcGuidDevice == NULL || IsEqualGUID(pcGuidDevice, &GUID_NULL))
193 {
194 /* use default playback device id */
195 pcGuidDevice = &DSDEVID_DefaultCapture;
196 }
197
198 if (IsEqualIID(pcGuidDevice, &DSDEVID_DefaultVoicePlayback) || IsEqualIID(pcGuidDevice, &DSDEVID_DefaultPlayback))
199 {
200 /* this has to be a winetest */
201 return DSERR_NODRIVER;
202 }
203
204 /* now verify the guid */
205 if (GetDeviceID(pcGuidDevice, &DeviceGuid) != DS_OK)
206 {
207 if (SUCCEEDED(StringFromIID(pcGuidDevice, &pGuidStr)))
208 {
209 DPRINT("IDirectSound8_fnInitialize: Unknown GUID %ws\n", pGuidStr);
210 CoTaskMemFree(pGuidStr);
211 }
212 return DSERR_INVALIDPARAM;
213 }
214
215 if (FindDeviceByGuid(&DeviceGuid, &This->Filter))
216 {
217 This->bInitialized = TRUE;
218 return DS_OK;
219 }
220
221 DPRINT("Failed to find device\n");
222 return DSERR_INVALIDPARAM;
223}
224
225static IDirectSoundCaptureVtbl vt_DirectSoundCapture =
226{
227 /* IUnknown methods */
234};
235
238 LPCGUID lpcGUID,
240 IUnknown *pUnkOuter)
241{
243 HRESULT hr;
244
245 if (!ppDS || pUnkOuter != NULL)
246 {
247 /* invalid parameter passed */
248 return DSERR_INVALIDPARAM;
249 }
250
251 /* allocate CDirectSoundCaptureImpl struct */
253 if (!This)
254 {
255 /* not enough memory */
256 return DSERR_OUTOFMEMORY;
257 }
258
259 /* initialize IDirectSoundCapture object */
260 This->ref = 1;
261 This->lpVtbl = &vt_DirectSoundCapture;
262
263
264 /* initialize direct sound interface */
266
267 /* check for success */
268 if (!SUCCEEDED(hr))
269 {
270 /* failed */
271 DPRINT("Failed to initialize DirectSoundCapture object with %x\n", hr);
273 return hr;
274 }
275
276 /* store result */
277 *ppDS = (LPDIRECTSOUNDCAPTURE8)&This->lpVtbl;
278 DPRINT("DirectSoundCapture object %p\n", *ppDS);
279 return DS_OK;
280}
281
285 IUnknown* pUnkOuter,
286 REFIID riid,
288{
289 LPOLESTR pStr;
291
292 /* check requested interface */
293 if (!IsEqualIID(riid, &IID_IUnknown) && !IsEqualIID(riid, &IID_IDirectSoundCapture) && !IsEqualIID(riid, &IID_IDirectSoundCapture8))
294 {
295 *ppvObject = 0;
296 StringFromIID(riid, &pStr);
297 DPRINT("NewDirectSoundCapture does not support Interface %ws\n", pStr);
298 CoTaskMemFree(pStr);
299 return E_NOINTERFACE;
300 }
301
302 /* allocate CDirectSoundCaptureImpl struct */
304 if (!This)
305 {
306 /* not enough memory */
307 return DSERR_OUTOFMEMORY;
308 }
309
310 /* initialize object */
311 This->ref = 1;
312 This->lpVtbl = &vt_DirectSoundCapture;
313 This->bInitialized = FALSE;
314 *ppvObject = (LPVOID)&This->lpVtbl;
315
316 return S_OK;
317}
318
319
321WINAPI
323 LPCGUID lpcGUID,
325 LPUNKNOWN pUnkOuter)
326{
327 return InternalDirectSoundCaptureCreate(lpcGUID, (LPDIRECTSOUNDCAPTURE8*)ppDSC, pUnkOuter);
328}
329
331WINAPI
333 LPCGUID lpcGUID,
334 LPDIRECTSOUNDCAPTURE8 *ppDSC8,
335 LPUNKNOWN pUnkOuter)
336{
337 return InternalDirectSoundCaptureCreate(lpcGUID, ppDSC8, pUnkOuter);
338}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
const GUID IID_IUnknown
HRESULT NewDirectSoundCaptureBuffer(LPDIRECTSOUNDCAPTUREBUFFER8 *OutBuffer, LPFILTERINFO Filter, LPCDSCBUFFERDESC lpcDSBufferDesc)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HRESULT WINAPI CDirectSoundCapture_fnGetCaps(LPDIRECTSOUNDCAPTURE8 iface, LPDSCCAPS pDSCCaps)
Definition: capture.c:124
HRESULT WINAPI DirectSoundCaptureCreate8(LPCGUID lpcGUID, LPDIRECTSOUNDCAPTURE8 *ppDSC8, LPUNKNOWN pUnkOuter)
Definition: capture.c:332
HRESULT InternalDirectSoundCaptureCreate(LPCGUID lpcGUID, LPDIRECTSOUNDCAPTURE8 *ppDS, IUnknown *pUnkOuter)
Definition: capture.c:237
HRESULT WINAPI CDirectSoundCapture_fnQueryInterface(LPDIRECTSOUNDCAPTURE8 iface, REFIID riid, LPVOID *ppobj)
Definition: capture.c:23
HRESULT WINAPI CDirectSoundCapture_fnInitialize(LPDIRECTSOUNDCAPTURE8 iface, LPCGUID pcGuidDevice)
Definition: capture.c:173
HRESULT CALLBACK NewDirectSoundCapture(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppvObject)
Definition: capture.c:284
ULONG WINAPI CDirectSoundCapture_fnAddRef(LPDIRECTSOUNDCAPTURE8 iface)
Definition: capture.c:51
ULONG WINAPI CDirectSoundCapture_fnRelease(LPDIRECTSOUNDCAPTURE8 iface)
Definition: capture.c:65
static IDirectSoundCaptureVtbl vt_DirectSoundCapture
Definition: capture.c:225
struct CDirectSoundCaptureImpl * LPCDirectSoundCaptureImpl
HRESULT WINAPI DirectSoundCaptureCreate(LPCGUID lpcGUID, LPDIRECTSOUNDCAPTURE *ppDSC, LPUNKNOWN pUnkOuter)
Definition: capture.c:322
HRESULT WINAPI CDirectSoundCapture_fnCreateCaptureBuffer(LPDIRECTSOUNDCAPTURE8 iface, LPCDSCBUFFERDESC lpcDSBufferDesc, LPDIRECTSOUNDCAPTUREBUFFER *ppDSCBuffer, LPUNKNOWN pUnkOuter)
Definition: capture.c:85
BOOL FindDeviceByGuid(LPCGUID pGuidSrc, LPFILTERINFO *Filter)
Definition: devicelist.c:470
LPFILTERINFO RootInfo
Definition: dsound.c:13
HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
Definition: dsound.c:53
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define DSERR_UNINITIALIZED
Definition: dsound.h:133
#define IID_IDirectSoundCapture8
Definition: dsound.h:93
#define DSERR_ALREADYINITIALIZED
Definition: dsound.h:129
struct IDirectSoundCapture * LPDIRECTSOUNDCAPTURE
Definition: dsound.h:92
struct IDirectSoundCaptureBuffer * LPDIRECTSOUNDCAPTUREBUFFER
Definition: dsound.h:97
#define IDirectSoundCapture_Release(p)
Definition: dsound.h:736
struct IDirectSoundCaptureBuffer8 * LPDIRECTSOUNDCAPTUREBUFFER8
Definition: dsound.h:100
#define DSERR_UNSUPPORTED
Definition: dsound.h:127
#define IDirectSoundCapture_Initialize(p, a)
Definition: dsound.h:740
#define DSERR_OUTOFMEMORY
Definition: dsound.h:125
#define DS_OK
Definition: dsound.h:116
#define DSERR_INVALIDPARAM
Definition: dsound.h:121
struct IDirectSound8 * LPDIRECTSOUND8
Definition: dsound.h:73
#define DSCCAPS_CERTIFIED
Definition: dsound.h:386
struct IDirectSoundCapture * LPDIRECTSOUNDCAPTURE8
Definition: dsound.h:94
#define DSERR_NODRIVER
Definition: dsound.h:128
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define GUID_NULL
Definition: ks.h:106
UINT MMRESULT
Definition: mmsystem.h:962
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define ASSERT(a)
Definition: mode.c:44
static LPOLESTR
Definition: stg_prop.c:27
static LPUNKNOWN
Definition: ndr_ole.c:49
#define LPVOID
Definition: nt_native.h:45
_Check_return_ HRESULT WINAPI StringFromIID(_In_ REFIID rclsid, _Outptr_ LPOLESTR *lplpsz)
long LONG
Definition: pedump.c:60
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
HRESULT hr
Definition: shlfolder.c:183
#define DPRINT
Definition: sndvol32.h:71
IDirectSoundCaptureVtbl * lpVtbl
Definition: capture.c:14
LPFILTERINFO Filter
Definition: capture.c:18
DWORD dwBufferBytes
Definition: dsound.h:359
LPWAVEFORMATEX lpwfxFormat
Definition: dsound.h:361
DWORD dwReserved
Definition: dsound.h:360
DWORD dwSize
Definition: dsound.h:357
DWORD dwChannels
Definition: dsound.h:372
DWORD dwSize
Definition: dsound.h:369
DWORD dwFormats
Definition: dsound.h:371
DWORD dwFlags
Definition: dsound.h:370
WORD nBlockAlign
Definition: mmreg.h:82
WORD cbSize
Definition: mmreg.h:84
DWORD nAvgBytesPerSec
Definition: mmreg.h:81
DWORD nSamplesPerSec
Definition: mmreg.h:80
WORD nChannels
Definition: mmreg.h:79
WORD wFormatTag
Definition: mmreg.h:78
WORD wBitsPerSample
Definition: mmreg.h:83
Definition: send.c:48
DWORD dwFormats
Definition: mmsystem.h:1061
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
_In_ void _In_ PCCERT_CONTEXT _In_opt_ LPFILETIME _In_ DWORD _In_ DWORD _Outptr_opt_ void ** ppvObject
Definition: wincrypt.h:6082
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:2364
UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
Definition: winmm.c:2573
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409