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
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
14 IDirectSoundCaptureVtbl
*lpVtbl
;
19 }CDirectSoundCaptureImpl
, *LPCDirectSoundCaptureImpl
;
23 CDirectSoundCapture_fnQueryInterface(
24 LPDIRECTSOUNDCAPTURE8 iface
,
29 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
31 /* check if the interface is supported */
32 if (IsEqualIID(riid
, &IID_IUnknown
) ||
33 IsEqualIID(riid
, &IID_IDirectSoundCapture
))
35 *ppobj
= (LPVOID
)&This
->lpVtbl
;
36 InterlockedIncrement(&This
->ref
);
40 /* unsupported interface */
41 if (SUCCEEDED(StringFromIID(riid
, &pStr
)))
43 DPRINT("No Interface for class %s\n", pStr
);
51 CDirectSoundCapture_fnAddRef(
52 LPDIRECTSOUNDCAPTURE8 iface
)
55 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
57 /* increment reference count */
58 ref
= InterlockedIncrement(&This
->ref
);
65 CDirectSoundCapture_fnRelease(
66 LPDIRECTSOUNDCAPTURE8 iface
)
69 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
71 /* release reference count */
72 ref
= InterlockedDecrement(&(This
->ref
));
76 HeapFree(GetProcessHeap(), 0, This
);
85 CDirectSoundCapture_fnCreateCaptureBuffer(
86 LPDIRECTSOUNDCAPTURE8 iface
,
87 LPCDSCBUFFERDESC lpcDSBufferDesc
,
88 LPDIRECTSOUNDCAPTUREBUFFER
*ppDSCBuffer
,
92 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
94 if (!This
->bInitialized
)
96 /* object not yet initialized */
97 return DSERR_UNINITIALIZED
;
100 if (!lpcDSBufferDesc
|| !ppDSCBuffer
|| pUnkOuter
!= NULL
)
103 return DSERR_INVALIDPARAM
;
106 /* check buffer description */
107 if ((lpcDSBufferDesc
->dwSize
!= sizeof(DSCBUFFERDESC
) && lpcDSBufferDesc
->dwSize
!= sizeof(DSCBUFFERDESC1
)) ||
108 lpcDSBufferDesc
->dwReserved
!= 0 || lpcDSBufferDesc
->dwBufferBytes
== 0 || lpcDSBufferDesc
->lpwfxFormat
== NULL
)
110 /* invalid buffer description */
111 return DSERR_INVALIDPARAM
;
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
);
117 hResult
= NewDirectSoundCaptureBuffer((LPDIRECTSOUNDCAPTUREBUFFER8
*)ppDSCBuffer
, This
->Filter
, lpcDSBufferDesc
);
124 CDirectSoundCapture_fnGetCaps(
125 LPDIRECTSOUNDCAPTURE8 iface
,
130 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
132 if (!This
->bInitialized
)
134 /* object not yet initialized */
135 return DSERR_UNINITIALIZED
;
141 return DSERR_INVALIDPARAM
;
144 if (pDSCCaps
->dwSize
!= sizeof(DSCCAPS
))
147 return DSERR_INVALIDPARAM
;
151 /* We are certified ;) */
152 pDSCCaps
->dwFlags
= DSCCAPS_CERTIFIED
;
154 ASSERT(This
->Filter
);
156 Result
= waveInGetDevCapsW(This
->Filter
->MappedId
[0], &Caps
, sizeof(WAVEINCAPSW
));
157 if (Result
!= MMSYSERR_NOERROR
)
160 DPRINT("waveInGetDevCapsW for device %u failed with %x\n", This
->Filter
->MappedId
[0], Result
);
161 return DSERR_UNSUPPORTED
;
164 pDSCCaps
->dwFormats
= Caps
.dwFormats
;
165 pDSCCaps
->dwChannels
= Caps
.wChannels
;
173 CDirectSoundCapture_fnInitialize(
174 LPDIRECTSOUNDCAPTURE8 iface
,
175 LPCGUID pcGuidDevice
)
179 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
184 if (This
->bInitialized
)
186 /* object has already been initialized */
187 return DSERR_ALREADYINITIALIZED
;
190 /* fixme mutual exlucsion */
192 if (pcGuidDevice
== NULL
|| IsEqualGUID(pcGuidDevice
, &GUID_NULL
))
194 /* use default playback device id */
195 pcGuidDevice
= &DSDEVID_DefaultCapture
;
198 if (IsEqualIID(pcGuidDevice
, &DSDEVID_DefaultVoicePlayback
) || IsEqualIID(pcGuidDevice
, &DSDEVID_DefaultPlayback
))
200 /* this has to be a winetest */
201 return DSERR_NODRIVER
;
204 /* now verify the guid */
205 if (GetDeviceID(pcGuidDevice
, &DeviceGuid
) != DS_OK
)
207 if (SUCCEEDED(StringFromIID(pcGuidDevice
, &pGuidStr
)))
209 DPRINT("IDirectSound8_fnInitialize: Unknown GUID %ws\n", pGuidStr
);
210 CoTaskMemFree(pGuidStr
);
212 return DSERR_INVALIDPARAM
;
215 if (FindDeviceByGuid(&DeviceGuid
, &This
->Filter
))
217 This
->bInitialized
= TRUE
;
221 DPRINT("Failed to find device\n");
222 return DSERR_INVALIDPARAM
;
225 static IDirectSoundCaptureVtbl vt_DirectSoundCapture
=
227 /* IUnknown methods */
228 CDirectSoundCapture_fnQueryInterface
,
229 CDirectSoundCapture_fnAddRef
,
230 CDirectSoundCapture_fnRelease
,
231 CDirectSoundCapture_fnCreateCaptureBuffer
,
232 CDirectSoundCapture_fnGetCaps
,
233 CDirectSoundCapture_fnInitialize
237 InternalDirectSoundCaptureCreate(
239 LPDIRECTSOUNDCAPTURE8
*ppDS
,
242 LPCDirectSoundCaptureImpl This
;
245 if (!ppDS
|| pUnkOuter
!= NULL
)
247 /* invalid parameter passed */
248 return DSERR_INVALIDPARAM
;
251 /* allocate CDirectSoundCaptureImpl struct */
252 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CDirectSoundCaptureImpl
));
255 /* not enough memory */
256 return DSERR_OUTOFMEMORY
;
259 /* initialize IDirectSoundCapture object */
261 This
->lpVtbl
= &vt_DirectSoundCapture
;
264 /* initialize direct sound interface */
265 hr
= IDirectSoundCapture_Initialize((LPDIRECTSOUNDCAPTURE8
)&This
->lpVtbl
, lpcGUID
);
267 /* check for success */
271 DPRINT("Failed to initialize DirectSoundCapture object with %x\n", hr
);
272 IDirectSoundCapture_Release((LPDIRECTSOUND8
)&This
->lpVtbl
);
277 *ppDS
= (LPDIRECTSOUNDCAPTURE8
)&This
->lpVtbl
;
278 DPRINT("DirectSoundCapture object %p\n", *ppDS
);
284 NewDirectSoundCapture(
290 LPCDirectSoundCaptureImpl This
;
292 /* check requested interface */
293 if (!IsEqualIID(riid
, &IID_IUnknown
) && !IsEqualIID(riid
, &IID_IDirectSoundCapture
) && !IsEqualIID(riid
, &IID_IDirectSoundCapture8
))
296 StringFromIID(riid
, &pStr
);
297 DPRINT("NewDirectSoundCapture does not support Interface %ws\n", pStr
);
299 return E_NOINTERFACE
;
302 /* allocate CDirectSoundCaptureImpl struct */
303 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CDirectSoundCaptureImpl
));
306 /* not enough memory */
307 return DSERR_OUTOFMEMORY
;
310 /* initialize object */
312 This
->lpVtbl
= &vt_DirectSoundCapture
;
313 This
->bInitialized
= FALSE
;
314 *ppvObject
= (LPVOID
)&This
->lpVtbl
;
322 DirectSoundCaptureCreate(
324 LPDIRECTSOUNDCAPTURE
*ppDSC
,
327 return InternalDirectSoundCaptureCreate(lpcGUID
, (LPDIRECTSOUNDCAPTURE8
*)ppDSC
, pUnkOuter
);
332 DirectSoundCaptureCreate8(
334 LPDIRECTSOUNDCAPTURE8
*ppDSC8
,
337 return InternalDirectSoundCaptureCreate(lpcGUID
, ppDSC8
, pUnkOuter
);