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(DSBUFFERDESC
) && lpcDSBufferDesc
->dwSize
!= sizeof(DSBUFFERDESC1
)) || lpcDSBufferDesc
->dwReserved
!= 0)
110 DPRINT("Invalid buffer description size %u expected %u dwReserved %u\n", lpcDSBufferDesc
->dwSize
, sizeof(DSBUFFERDESC1
), 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
;
144 if (!pDSCCaps
|| pDSCCaps
->dwSize
!= sizeof(DSCCAPS
))
147 return DSERR_INVALIDPARAM
;
150 /* We are certified ;) */
151 pDSCCaps
->dwFlags
= DSCCAPS_CERTIFIED
;
153 Result
= waveInGetDevCapsW(This
->Filter
->MappedId
[0], &Caps
, sizeof(WAVEINCAPSW
));
154 if (Result
!= MMSYSERR_NOERROR
)
157 DPRINT("waveInGetDevCapsW for device %u failed with %x\n", This
->Filter
->MappedId
[0], Result
);
158 return DSERR_UNSUPPORTED
;
161 pDSCCaps
->dwFormats
= Caps
.dwFormats
;
162 pDSCCaps
->dwChannels
= Caps
.wChannels
;
170 CDirectSoundCapture_fnInitialize(
171 LPDIRECTSOUNDCAPTURE8 iface
,
172 LPCGUID pcGuidDevice
)
177 LPCDirectSoundCaptureImpl This
= (LPCDirectSoundCaptureImpl
)CONTAINING_RECORD(iface
, CDirectSoundCaptureImpl
, lpVtbl
);
182 if (This
->bInitialized
)
184 /* object has already been initialized */
185 return DSERR_ALREADYINITIALIZED
;
188 /* fixme mutual exlucsion */
190 if (pcGuidDevice
== NULL
|| IsEqualGUID(pcGuidDevice
, &GUID_NULL
))
192 /* use default playback device id */
193 pcGuidDevice
= &DSDEVID_DefaultCapture
;
196 /* now verify the guid */
197 if (GetDeviceID(pcGuidDevice
, &DeviceGuid
) != DS_OK
)
199 if (SUCCEEDED(StringFromIID(pcGuidDevice
, &pGuidStr
)))
201 DPRINT("IDirectSound8_fnInitialize: Unknown GUID %ws\n", pGuidStr
);
202 CoTaskMemFree(pGuidStr
);
204 return DSERR_INVALIDPARAM
;
207 hr
= FindDeviceByGuid(&DeviceGuid
, &This
->Filter
);
211 This
->bInitialized
= TRUE
;
215 DPRINT("Failed to find device\n");
216 return DSERR_INVALIDPARAM
;
219 static IDirectSoundCaptureVtbl vt_DirectSoundCapture
=
221 /* IUnknown methods */
222 CDirectSoundCapture_fnQueryInterface
,
223 CDirectSoundCapture_fnAddRef
,
224 CDirectSoundCapture_fnRelease
,
225 CDirectSoundCapture_fnCreateCaptureBuffer
,
226 CDirectSoundCapture_fnGetCaps
,
227 CDirectSoundCapture_fnInitialize
231 InternalDirectSoundCaptureCreate(
233 LPDIRECTSOUNDCAPTURE8
*ppDS
,
236 LPCDirectSoundCaptureImpl This
;
239 if (!ppDS
|| pUnkOuter
!= NULL
)
241 /* invalid parameter passed */
242 return DSERR_INVALIDPARAM
;
245 /* allocate CDirectSoundCaptureImpl struct */
246 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CDirectSoundCaptureImpl
));
249 /* not enough memory */
250 return DSERR_OUTOFMEMORY
;
253 /* initialize IDirectSoundCapture object */
255 This
->lpVtbl
= &vt_DirectSoundCapture
;
258 /* initialize direct sound interface */
259 hr
= IDirectSoundCapture_Initialize((LPDIRECTSOUNDCAPTURE8
)&This
->lpVtbl
, lpcGUID
);
261 /* check for success */
265 DPRINT("Failed to initialize DirectSoundCapture object with %x\n", hr
);
266 IDirectSoundCapture_Release((LPDIRECTSOUND8
)&This
->lpVtbl
);
271 *ppDS
= (LPDIRECTSOUNDCAPTURE8
)&This
->lpVtbl
;
272 DPRINT("DirectSoundCapture object %p\n", *ppDS
);
280 DirectSoundCaptureCreate(
282 LPDIRECTSOUNDCAPTURE
*ppDSC
,
285 return InternalDirectSoundCaptureCreate(lpcGUID
, (LPDIRECTSOUNDCAPTURE8
*)ppDSC
, pUnkOuter
);
290 DirectSoundCaptureCreate8(
292 LPDIRECTSOUNDCAPTURE8
*ppDSC8
,
295 return InternalDirectSoundCaptureCreate(lpcGUID
, ppDSC8
, pUnkOuter
);