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
);
259 if (This
->bInitialized
)
261 /* object has already been initialized */
262 return DSERR_ALREADYINITIALIZED
;
265 /* fixme mutual exlucsion */
267 if (pcGuidDevice
== NULL
|| IsEqualGUID(pcGuidDevice
, &GUID_NULL
))
269 /* use default playback device id */
270 pcGuidDevice
= &DSDEVID_DefaultPlayback
;
273 /* now verify the guid */
274 if (GetDeviceID(pcGuidDevice
, &DeviceGuid
) != DS_OK
)
276 if (SUCCEEDED(StringFromIID(pcGuidDevice
, &pGuidStr
)))
278 DPRINT("IDirectSound8_fnInitialize: Unknown GUID %ws\n", pGuidStr
);
279 CoTaskMemFree(pGuidStr
);
281 return DSERR_INVALIDPARAM
;
284 hr
= FindDeviceByGuid(&DeviceGuid
, &This
->Filter
);
288 This
->bInitialized
= TRUE
;
292 DPRINT("Failed to find device\n");
293 return DSERR_INVALIDPARAM
;
298 IDirectSound8_fnVerifyCertification(
299 LPDIRECTSOUND8 iface
,
300 LPDWORD pdwCertified
)
306 static IDirectSound8Vtbl vt_DirectSound8
=
308 /* IUnknown methods */
309 IDirectSound8_fnQueryInterface
,
310 IDirectSound8_fnAddRef
,
311 IDirectSound8_fnRelease
,
312 /* IDirectSound methods */
313 IDirectSound8_fnCreateSoundBuffer
,
314 IDirectSound8_fnGetCaps
,
315 IDirectSound8_fnDuplicateSoundBuffer
,
316 IDirectSound8_fnSetCooperativeLevel
,
317 IDirectSound8_fnCompact
,
318 IDirectSound8_fnGetSpeakerConfig
,
319 IDirectSound8_fnSetSpeakerConfig
,
320 IDirectSound8_fnInitialize
,
321 /* IDirectSound8 methods */
322 IDirectSound8_fnVerifyCertification
326 InternalDirectSoundCreate(
328 LPDIRECTSOUND8
*ppDS
,
331 LPCDirectSoundImpl This
;
334 if (!ppDS
|| pUnkOuter
!= NULL
)
336 /* invalid parameter passed */
337 return DSERR_INVALIDPARAM
;
340 /* allocate CDirectSoundImpl struct */
341 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CDirectSoundImpl
));
344 /* not enough memory */
345 return DSERR_OUTOFMEMORY
;
348 /* initialize IDirectSound object */
350 This
->lpVtbl
= &vt_DirectSound8
;
353 /* initialize direct sound interface */
354 hr
= IDirectSound8_Initialize((LPDIRECTSOUND8
)&This
->lpVtbl
, lpcGUID
);
356 /* check for success */
360 DPRINT("Failed to initialize DirectSound object with %x\n", hr
);
361 IDirectSound8_Release((LPDIRECTSOUND8
)&This
->lpVtbl
);
366 *ppDS
= (LPDIRECTSOUND8
)&This
->lpVtbl
;
367 DPRINT("DirectSound object %p\n", *ppDS
);
378 return InternalDirectSoundCreate(lpcGUID
, (LPDIRECTSOUND8
*)ppDS
, pUnkOuter
);
385 LPDIRECTSOUND8
*ppDS
,
388 return InternalDirectSoundCreate(lpcGUID
, ppDS
, pUnkOuter
);