2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Configuration of network devices
4 * FILE: dll/directx/dsound_new/directsound.c
5 * PURPOSE: Handles IDirectSound interface
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
14 IDirectSound8Vtbl
*lpVtbl
;
20 LPDIRECTSOUNDBUFFER8 PrimaryBuffer
;
23 }CDirectSoundImpl
, *LPCDirectSoundImpl
;
27 IDirectSound8_fnQueryInterface(
33 LPCDirectSoundImpl This
= (LPCDirectSoundImpl
)CONTAINING_RECORD(iface
, CDirectSoundImpl
, lpVtbl
);
36 if (IsEqualIID(riid
, &IID_IUnknown
) ||
37 IsEqualIID(riid
, &IID_IDirectSound
) ||
38 IsEqualIID(riid
, &IID_IDirectSound8
))
40 *ppobj
= (LPVOID
)&This
->lpVtbl
;
41 InterlockedIncrement(&This
->ref
);
45 if (SUCCEEDED(StringFromIID(riid
, &pStr
)))
47 DPRINT("No Interface for class %s\n", pStr
);
55 IDirectSound8_fnAddRef(
59 LPCDirectSoundImpl This
= (LPCDirectSoundImpl
)CONTAINING_RECORD(iface
, CDirectSoundImpl
, lpVtbl
);
61 ref
= InterlockedIncrement(&This
->ref
);
68 IDirectSound8_fnRelease(
72 LPCDirectSoundImpl This
= (LPCDirectSoundImpl
)CONTAINING_RECORD(iface
, CDirectSoundImpl
, lpVtbl
);
74 ref
= InterlockedDecrement(&(This
->ref
));
78 HeapFree(GetProcessHeap(), 0, This
);
86 IDirectSound8_fnCreateSoundBuffer(
88 LPCDSBUFFERDESC lpcDSBufferDesc
,
89 LPLPDIRECTSOUNDBUFFER lplpDirectSoundBuffer
,
90 IUnknown FAR
* pUnkOuter
)
93 LPCDirectSoundImpl This
= (LPCDirectSoundImpl
)CONTAINING_RECORD(iface
, CDirectSoundImpl
, lpVtbl
);
95 if (!This
->bInitialized
)
97 /* object not yet initialized */
98 return DSERR_UNINITIALIZED
;
101 if (!lpcDSBufferDesc
|| !lplpDirectSoundBuffer
|| pUnkOuter
!= NULL
)
103 DPRINT("Invalid parameter %p %p %p\n", lpcDSBufferDesc
, lplpDirectSoundBuffer
, 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
;
114 DPRINT("This %p dwFlags %x dwBufferBytes %u lpwfxFormat %p dwSize %u\n", This
, lpcDSBufferDesc
->dwFlags
, lpcDSBufferDesc
->dwBufferBytes
, lpcDSBufferDesc
->lpwfxFormat
, lpcDSBufferDesc
->dwSize
);
116 if (lpcDSBufferDesc
->dwFlags
& DSBCAPS_PRIMARYBUFFER
)
118 if (lpcDSBufferDesc
->lpwfxFormat
!= NULL
)
120 /* format must be null for primary sound buffer */
121 return DSERR_INVALIDPARAM
;
124 if (This
->PrimaryBuffer
)
126 /* primary buffer already exists */
127 IDirectSoundBuffer8_AddRef(This
->PrimaryBuffer
);
128 *lplpDirectSoundBuffer
= (LPDIRECTSOUNDBUFFER
)This
->PrimaryBuffer
;
132 hResult
= NewPrimarySoundBuffer((LPLPDIRECTSOUNDBUFFER8
)lplpDirectSoundBuffer
, This
->Filter
, This
->dwLevel
);
133 if (SUCCEEDED(hResult
))
135 /* store primary buffer */
136 This
->PrimaryBuffer
= (LPDIRECTSOUNDBUFFER8
)*lplpDirectSoundBuffer
;
142 if (lpcDSBufferDesc
->lpwfxFormat
== NULL
)
144 /* format must not be null */
145 return DSERR_INVALIDPARAM
;
148 if (!This
->PrimaryBuffer
)
150 hResult
= NewPrimarySoundBuffer((LPLPDIRECTSOUNDBUFFER8
)lplpDirectSoundBuffer
, This
->Filter
, This
->dwLevel
);
151 if (SUCCEEDED(hResult
))
153 /* store primary buffer */
154 This
->PrimaryBuffer
= (LPDIRECTSOUNDBUFFER8
)*lplpDirectSoundBuffer
;
158 DPRINT("Failed to create primary buffer with %x\n", hResult
);
164 ASSERT(This
->PrimaryBuffer
);
166 DPRINT("This %p wFormatTag %x nChannels %u nSamplesPerSec %u nAvgBytesPerSec %u NBlockAlign %u wBitsPerSample %u cbSize %u\n",
167 This
, lpcDSBufferDesc
->lpwfxFormat
->wFormatTag
, lpcDSBufferDesc
->lpwfxFormat
->nChannels
, lpcDSBufferDesc
->lpwfxFormat
->nSamplesPerSec
, lpcDSBufferDesc
->lpwfxFormat
->nAvgBytesPerSec
, lpcDSBufferDesc
->lpwfxFormat
->nBlockAlign
, lpcDSBufferDesc
->lpwfxFormat
->wBitsPerSample
, lpcDSBufferDesc
->lpwfxFormat
->cbSize
);
169 hResult
= NewSecondarySoundBuffer((LPLPDIRECTSOUNDBUFFER8
)lplpDirectSoundBuffer
, This
->Filter
, This
->dwLevel
, lpcDSBufferDesc
, This
->PrimaryBuffer
);
176 IDirectSound8_fnGetCaps(
177 LPDIRECTSOUND8 iface
,
181 return DSERR_GENERIC
;
186 IDirectSound8_fnDuplicateSoundBuffer(
187 LPDIRECTSOUND8 iface
,
188 LPDIRECTSOUNDBUFFER lpDsbOriginal
,
189 LPLPDIRECTSOUNDBUFFER lplpDsbDuplicate
)
192 return DSERR_OUTOFMEMORY
;
197 IDirectSound8_fnSetCooperativeLevel(
198 LPDIRECTSOUND8 iface
,
202 LPCDirectSoundImpl This
= (LPCDirectSoundImpl
)CONTAINING_RECORD(iface
, CDirectSoundImpl
, lpVtbl
);
204 if (!This
->bInitialized
)
206 /* object not yet initialized */
207 return DSERR_UNINITIALIZED
;
210 /* store cooperation level */
211 This
->dwLevel
= dwLevel
;
217 IDirectSound8_fnCompact(
218 LPDIRECTSOUND8 iface
)
221 return DSERR_INVALIDPARAM
;
226 IDirectSound8_fnGetSpeakerConfig(
227 LPDIRECTSOUND8 iface
,
228 LPDWORD pdwSpeakerConfig
)
231 return DSERR_INVALIDPARAM
;
236 IDirectSound8_fnSetSpeakerConfig(
237 LPDIRECTSOUND8 iface
,
238 DWORD dwSpeakerConfig
)
241 return DSERR_INVALIDPARAM
;
247 IDirectSound8_fnInitialize(
248 LPDIRECTSOUND8 iface
,
249 LPCGUID pcGuidDevice
)
254 LPCDirectSoundImpl This
= (LPCDirectSoundImpl
)CONTAINING_RECORD(iface
, CDirectSoundImpl
, lpVtbl
);
258 EnumAudioDeviceInterfaces(&RootInfo
);
264 if (This
->bInitialized
)
266 /* object has already been initialized */
267 return DSERR_ALREADYINITIALIZED
;
270 /* fixme mutual exlucsion */
272 if (pcGuidDevice
== NULL
|| IsEqualGUID(pcGuidDevice
, &GUID_NULL
))
274 /* use default playback device id */
275 pcGuidDevice
= &DSDEVID_DefaultPlayback
;
278 /* now verify the guid */
279 if (GetDeviceID(pcGuidDevice
, &DeviceGuid
) != DS_OK
)
281 if (SUCCEEDED(StringFromIID(pcGuidDevice
, &pGuidStr
)))
283 DPRINT("IDirectSound8_fnInitialize: Unknown GUID %ws\n", pGuidStr
);
284 CoTaskMemFree(pGuidStr
);
286 return DSERR_INVALIDPARAM
;
289 hr
= FindDeviceByGuid(&DeviceGuid
, &This
->Filter
);
293 This
->bInitialized
= TRUE
;
297 DPRINT("Failed to find device\n");
298 return DSERR_INVALIDPARAM
;
303 IDirectSound8_fnVerifyCertification(
304 LPDIRECTSOUND8 iface
,
305 LPDWORD pdwCertified
)
311 static IDirectSound8Vtbl vt_DirectSound8
=
313 /* IUnknown methods */
314 IDirectSound8_fnQueryInterface
,
315 IDirectSound8_fnAddRef
,
316 IDirectSound8_fnRelease
,
317 /* IDirectSound methods */
318 IDirectSound8_fnCreateSoundBuffer
,
319 IDirectSound8_fnGetCaps
,
320 IDirectSound8_fnDuplicateSoundBuffer
,
321 IDirectSound8_fnSetCooperativeLevel
,
322 IDirectSound8_fnCompact
,
323 IDirectSound8_fnGetSpeakerConfig
,
324 IDirectSound8_fnSetSpeakerConfig
,
325 IDirectSound8_fnInitialize
,
326 /* IDirectSound8 methods */
327 IDirectSound8_fnVerifyCertification
331 InternalDirectSoundCreate(
333 LPDIRECTSOUND8
*ppDS
,
336 LPCDirectSoundImpl This
;
339 if (!ppDS
|| pUnkOuter
!= NULL
)
341 /* invalid parameter passed */
342 return DSERR_INVALIDPARAM
;
345 /* allocate CDirectSoundImpl struct */
346 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CDirectSoundImpl
));
349 /* not enough memory */
350 return DSERR_OUTOFMEMORY
;
353 /* initialize IDirectSound object */
355 This
->lpVtbl
= &vt_DirectSound8
;
358 /* initialize direct sound interface */
359 hr
= IDirectSound8_Initialize((LPDIRECTSOUND8
)&This
->lpVtbl
, lpcGUID
);
361 /* check for success */
365 DPRINT("Failed to initialize DirectSound object with %x\n", hr
);
366 IDirectSound8_Release((LPDIRECTSOUND8
)&This
->lpVtbl
);
371 *ppDS
= (LPDIRECTSOUND8
)&This
->lpVtbl
;
372 DPRINT("DirectSound object %p\n", *ppDS
);
383 return InternalDirectSoundCreate(lpcGUID
, (LPDIRECTSOUND8
*)ppDS
, pUnkOuter
);
390 LPDIRECTSOUND8
*ppDS
,
393 return InternalDirectSoundCreate(lpcGUID
, ppDS
, pUnkOuter
);