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
;
24 CDirectSoundCapture_fnQueryInterface(
25 LPDIRECTSOUNDCAPTURE8 iface
,
30 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
32 /* check if the interface is supported */
33 if (IsEqualIID(riid
, &IID_IUnknown
) ||
34 IsEqualIID(riid
, &IID_IDirectSoundCapture
))
36 *ppobj
= (LPVOID
)&This
->lpVtbl
;
37 InterlockedIncrement(&This
->ref
);
41 /* unsupported interface */
42 if (SUCCEEDED(StringFromIID(riid
, &pStr
)))
44 DPRINT("No Interface for class %s\n", pStr
);
52 CDirectSoundCapture_fnAddRef(
53 LPDIRECTSOUNDCAPTURE8 iface
)
56 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
58 /* increment reference count */
59 ref
= InterlockedIncrement(&This
->ref
);
66 CDirectSoundCapture_fnRelease(
67 LPDIRECTSOUNDCAPTURE8 iface
)
70 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
72 /* release reference count */
73 ref
= InterlockedDecrement(&(This
->ref
));
77 HeapFree(GetProcessHeap(), 0, This
);
86 CDirectSoundCapture_fnCreateCaptureBuffer(
87 LPDIRECTSOUNDCAPTURE8 iface
,
88 LPCDSCBUFFERDESC lpcDSBufferDesc
,
89 LPDIRECTSOUNDCAPTUREBUFFER
*ppDSCBuffer
,
93 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
95 if (!This
->bInitialized
)
97 /* object not yet initialized */
98 return DSERR_UNINITIALIZED
;
101 if (!lpcDSBufferDesc
|| !ppDSCBuffer
|| pUnkOuter
!= NULL
)
103 DPRINT("Invalid parameter %p %p %p\n", lpcDSBufferDesc
, ppDSCBuffer
, pUnkOuter
);
104 return DSERR_INVALIDPARAM
;
107 /* check buffer description */
108 if ((lpcDSBufferDesc
->dwSize
!= sizeof(DSCBUFFERDESC
) && lpcDSBufferDesc
->dwSize
!= sizeof(DSCBUFFERDESC1
)) || lpcDSBufferDesc
->dwReserved
!= 0)
110 DPRINT("Invalid buffer description size %u expected %u or %u dwReserved %u\n", lpcDSBufferDesc
->dwSize
, sizeof(DSBUFFERDESC1
), sizeof(DSBUFFERDESC
), lpcDSBufferDesc
->dwReserved
);
111 return DSERR_INVALIDPARAM
;
115 ASSERT(lpcDSBufferDesc
->lpwfxFormat
);
117 if (lpcDSBufferDesc
->lpwfxFormat
)
119 DPRINT("This %p wFormatTag %x nChannels %u nSamplesPerSec %u nAvgBytesPerSec %u NBlockAlign %u wBitsPerSample %u cbSize %u\n",
120 This
, lpcDSBufferDesc
->lpwfxFormat
->wFormatTag
, lpcDSBufferDesc
->lpwfxFormat
->nChannels
, lpcDSBufferDesc
->lpwfxFormat
->nSamplesPerSec
, lpcDSBufferDesc
->lpwfxFormat
->nAvgBytesPerSec
, lpcDSBufferDesc
->lpwfxFormat
->nBlockAlign
, lpcDSBufferDesc
->lpwfxFormat
->wBitsPerSample
, lpcDSBufferDesc
->lpwfxFormat
->cbSize
);
123 hResult
= NewDirectSoundCaptureBuffer((LPDIRECTSOUNDCAPTUREBUFFER8
*)ppDSCBuffer
, This
->Filter
, lpcDSBufferDesc
);
130 CDirectSoundCapture_fnGetCaps(
131 LPDIRECTSOUNDCAPTURE8 iface
,
136 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
138 if (!This
->bInitialized
)
140 /* object not yet initialized */
141 return DSERR_UNINITIALIZED
;
147 return DSERR_INVALIDPARAM
;
150 if (pDSCCaps
->dwSize
!= sizeof(DSCCAPS
))
153 return DSERR_INVALIDPARAM
;
157 /* We are certified ;) */
158 pDSCCaps
->dwFlags
= DSCCAPS_CERTIFIED
;
160 ASSERT(This
->Filter
);
162 Result
= waveInGetDevCapsW(This
->Filter
->MappedId
[0], &Caps
, sizeof(WAVEINCAPSW
));
163 if (Result
!= MMSYSERR_NOERROR
)
166 DPRINT("waveInGetDevCapsW for device %u failed with %x\n", This
->Filter
->MappedId
[0], Result
);
167 return DSERR_UNSUPPORTED
;
170 pDSCCaps
->dwFormats
= Caps
.dwFormats
;
171 pDSCCaps
->dwChannels
= Caps
.wChannels
;
179 CDirectSoundCapture_fnInitialize(
180 LPDIRECTSOUNDCAPTURE8 iface
,
181 LPCGUID pcGuidDevice
)
185 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
190 if (This
->bInitialized
)
192 /* object has already been initialized */
193 return DSERR_ALREADYINITIALIZED
;
196 /* fixme mutual exlucsion */
198 if (pcGuidDevice
== NULL
|| IsEqualGUID(pcGuidDevice
, &GUID_NULL
))
200 /* use default playback device id */
201 pcGuidDevice
= &DSDEVID_DefaultCapture
;
204 if (IsEqualIID(pcGuidDevice
, &DSDEVID_DefaultVoicePlayback
) || IsEqualIID(pcGuidDevice
, &DSDEVID_DefaultPlayback
))
206 /* this has to be a winetest */
207 return DSERR_NODRIVER
;
210 /* now verify the guid */
211 if (GetDeviceID(pcGuidDevice
, &DeviceGuid
) != DS_OK
)
213 if (SUCCEEDED(StringFromIID(pcGuidDevice
, &pGuidStr
)))
215 DPRINT("IDirectSound8_fnInitialize: Unknown GUID %ws\n", pGuidStr
);
216 CoTaskMemFree(pGuidStr
);
218 return DSERR_INVALIDPARAM
;
221 if (FindDeviceByGuid(&DeviceGuid
, &This
->Filter
))
223 This
->bInitialized
= TRUE
;
227 DPRINT("Failed to find device\n");
228 return DSERR_INVALIDPARAM
;
231 static IDirectSoundCaptureVtbl vt_DirectSoundCapture
=
233 /* IUnknown methods */
234 CDirectSoundCapture_fnQueryInterface
,
235 CDirectSoundCapture_fnAddRef
,
236 CDirectSoundCapture_fnRelease
,
237 CDirectSoundCapture_fnCreateCaptureBuffer
,
238 CDirectSoundCapture_fnGetCaps
,
239 CDirectSoundCapture_fnInitialize
243 InternalDirectSoundCaptureCreate(
245 LPDIRECTSOUNDCAPTURE8
*ppDS
,
248 LPCDirectSoundCaptureImpl This
;
251 if (!ppDS
|| pUnkOuter
!= NULL
)
253 /* invalid parameter passed */
254 return DSERR_INVALIDPARAM
;
257 /* allocate CDirectSoundCaptureImpl struct */
258 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CDirectSoundCaptureImpl
));
261 /* not enough memory */
262 return DSERR_OUTOFMEMORY
;
265 /* initialize IDirectSoundCapture object */
267 This
->lpVtbl
= &vt_DirectSoundCapture
;
270 /* initialize direct sound interface */
271 hr
= IDirectSoundCapture_Initialize((LPDIRECTSOUNDCAPTURE8
)&This
->lpVtbl
, lpcGUID
);
273 /* check for success */
277 DPRINT("Failed to initialize DirectSoundCapture object with %x\n", hr
);
278 IDirectSoundCapture_Release((LPDIRECTSOUND8
)&This
->lpVtbl
);
283 *ppDS
= (LPDIRECTSOUNDCAPTURE8
)&This
->lpVtbl
;
284 DPRINT("DirectSoundCapture object %p\n", *ppDS
);
290 NewDirectSoundCapture(
296 LPCDirectSoundCaptureImpl This
;
298 /* check requested interface */
299 if (!IsEqualIID(riid
, &IID_IUnknown
) && !IsEqualIID(riid
, &IID_IDirectSoundCapture
) && !IsEqualIID(riid
, &IID_IDirectSoundCapture8
))
302 StringFromIID(riid
, &pStr
);
303 DPRINT("NewDirectSoundCapture does not support Interface %ws\n", pStr
);
305 return E_NOINTERFACE
;
308 /* allocate CDirectSoundCaptureImpl struct */
309 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CDirectSoundCaptureImpl
));
312 /* not enough memory */
313 return DSERR_OUTOFMEMORY
;
316 /* initialize object */
318 This
->lpVtbl
= &vt_DirectSoundCapture
;
319 This
->bInitialized
= FALSE
;
320 *ppvObject
= (LPVOID
)&This
->lpVtbl
;
328 DirectSoundCaptureCreate(
330 LPDIRECTSOUNDCAPTURE
*ppDSC
,
333 return InternalDirectSoundCaptureCreate(lpcGUID
, (LPDIRECTSOUNDCAPTURE8
*)ppDSC
, pUnkOuter
);
338 DirectSoundCaptureCreate8(
340 LPDIRECTSOUNDCAPTURE8
*ppDSC8
,
343 return InternalDirectSoundCaptureCreate(lpcGUID
, ppDSC8
, pUnkOuter
);