3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2002 TransGaming Technologies, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "dsound_private.h"
24 /*******************************************************************************
28 struct IDirectSoundNotifyImpl
31 const IDirectSoundNotifyVtbl
*lpVtbl
;
33 IDirectSoundBufferImpl
* dsb
;
36 static HRESULT
IDirectSoundNotifyImpl_Create(IDirectSoundBufferImpl
*dsb
,
37 IDirectSoundNotifyImpl
**pdsn
);
38 static HRESULT
IDirectSoundNotifyImpl_Destroy(IDirectSoundNotifyImpl
*pdsn
);
40 static HRESULT WINAPI
IDirectSoundNotifyImpl_QueryInterface(
41 LPDIRECTSOUNDNOTIFY iface
,REFIID riid
,LPVOID
*ppobj
43 IDirectSoundNotifyImpl
*This
= (IDirectSoundNotifyImpl
*)iface
;
44 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
46 if (This
->dsb
== NULL
) {
47 WARN("invalid parameter\n");
51 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER
)This
->dsb
, riid
, ppobj
);
54 static ULONG WINAPI
IDirectSoundNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface
)
56 IDirectSoundNotifyImpl
*This
= (IDirectSoundNotifyImpl
*)iface
;
57 ULONG ref
= InterlockedIncrement(&(This
->ref
));
58 TRACE("(%p) ref was %d\n", This
, ref
- 1);
62 static ULONG WINAPI
IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface
)
64 IDirectSoundNotifyImpl
*This
= (IDirectSoundNotifyImpl
*)iface
;
65 ULONG ref
= InterlockedDecrement(&(This
->ref
));
66 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
69 This
->dsb
->notify
= NULL
;
70 IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER
)This
->dsb
);
71 HeapFree(GetProcessHeap(), 0, This
);
72 TRACE("(%p) released\n", This
);
77 static HRESULT WINAPI
IDirectSoundNotifyImpl_SetNotificationPositions(
78 LPDIRECTSOUNDNOTIFY iface
,DWORD howmuch
,LPCDSBPOSITIONNOTIFY notify
80 IDirectSoundNotifyImpl
*This
= (IDirectSoundNotifyImpl
*)iface
;
81 TRACE("(%p,0x%08x,%p)\n",This
,howmuch
,notify
);
83 if (howmuch
> 0 && notify
== NULL
) {
84 WARN("invalid parameter: notify == NULL\n");
85 return DSERR_INVALIDPARAM
;
88 if (TRACE_ON(dsound
)) {
90 for (i
=0;i
<howmuch
;i
++)
91 TRACE("notify at %d to %p\n",
92 notify
[i
].dwOffset
,notify
[i
].hEventNotify
);
95 if (This
->dsb
->hwnotify
) {
97 hres
= IDsDriverNotify_SetNotificationPositions(This
->dsb
->hwnotify
, howmuch
, notify
);
99 WARN("IDsDriverNotify_SetNotificationPositions failed\n");
101 } else if (howmuch
> 0) {
102 /* Make an internal copy of the caller-supplied array.
103 * Replace the existing copy if one is already present. */
104 HeapFree(GetProcessHeap(), 0, This
->dsb
->notifies
);
105 This
->dsb
->notifies
= HeapAlloc(GetProcessHeap(), 0,
106 howmuch
* sizeof(DSBPOSITIONNOTIFY
));
108 if (This
->dsb
->notifies
== NULL
) {
109 WARN("out of memory\n");
110 return DSERR_OUTOFMEMORY
;
112 CopyMemory(This
->dsb
->notifies
, notify
, howmuch
* sizeof(DSBPOSITIONNOTIFY
));
113 This
->dsb
->nrofnotifies
= howmuch
;
115 HeapFree(GetProcessHeap(), 0, This
->dsb
->notifies
);
116 This
->dsb
->notifies
= NULL
;
117 This
->dsb
->nrofnotifies
= 0;
123 static const IDirectSoundNotifyVtbl dsnvt
=
125 IDirectSoundNotifyImpl_QueryInterface
,
126 IDirectSoundNotifyImpl_AddRef
,
127 IDirectSoundNotifyImpl_Release
,
128 IDirectSoundNotifyImpl_SetNotificationPositions
,
131 static HRESULT
IDirectSoundNotifyImpl_Create(
132 IDirectSoundBufferImpl
* dsb
,
133 IDirectSoundNotifyImpl
**pdsn
)
135 IDirectSoundNotifyImpl
* dsn
;
136 TRACE("(%p,%p)\n",dsb
,pdsn
);
138 dsn
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dsn
));
141 WARN("out of memory\n");
142 return DSERR_OUTOFMEMORY
;
146 dsn
->lpVtbl
= &dsnvt
;
149 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER
)dsb
);
155 static HRESULT
IDirectSoundNotifyImpl_Destroy(
156 IDirectSoundNotifyImpl
*pdsn
)
158 TRACE("(%p)\n",pdsn
);
160 while (IDirectSoundNotifyImpl_Release((LPDIRECTSOUNDNOTIFY
)pdsn
) > 0);
165 /*******************************************************************************
169 static inline IDirectSoundBufferImpl
*impl_from_IDirectSoundBuffer8(IDirectSoundBuffer8
*iface
)
171 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSoundBuffer8_iface
);
174 static inline BOOL
is_primary_buffer(IDirectSoundBufferImpl
*This
)
176 return This
->dsbd
.dwFlags
& DSBCAPS_PRIMARYBUFFER
? TRUE
: FALSE
;
179 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFormat(IDirectSoundBuffer8
*iface
,
180 LPCWAVEFORMATEX wfex
)
182 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
184 TRACE("(%p,%p)\n", iface
, wfex
);
186 if (is_primary_buffer(This
))
187 return primarybuffer_SetFormat(This
->device
, wfex
);
189 WARN("not available for secondary buffers.\n");
190 return DSERR_INVALIDCALL
;
194 static HRESULT WINAPI
IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8
*iface
, LONG vol
)
196 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
199 HRESULT hres
= DS_OK
;
201 TRACE("(%p,%d)\n",This
,vol
);
203 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
204 WARN("control unavailable: This->dsbd.dwFlags = 0x%08x\n", This
->dsbd
.dwFlags
);
205 return DSERR_CONTROLUNAVAIL
;
208 if ((vol
> DSBVOLUME_MAX
) || (vol
< DSBVOLUME_MIN
)) {
209 WARN("invalid parameter: vol = %d\n", vol
);
210 return DSERR_INVALIDPARAM
;
214 RtlAcquireResourceExclusive(&This
->lock
, TRUE
);
216 if (This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
217 oldVol
= This
->ds3db_lVolume
;
218 This
->ds3db_lVolume
= vol
;
220 /* recalc 3d volume, which in turn recalcs the pans */
221 DSOUND_Calc3DBuffer(This
);
223 oldVol
= This
->volpan
.lVolume
;
224 This
->volpan
.lVolume
= vol
;
226 DSOUND_RecalcVolPan(&(This
->volpan
));
231 hres
= IDsDriverBuffer_SetVolumePan(This
->hwbuf
, &(This
->volpan
));
233 WARN("IDsDriverBuffer_SetVolumePan failed\n");
237 RtlReleaseResource(&This
->lock
);
243 static HRESULT WINAPI
IDirectSoundBufferImpl_GetVolume(IDirectSoundBuffer8
*iface
, LONG
*vol
)
245 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
247 TRACE("(%p,%p)\n",This
,vol
);
249 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
250 WARN("control unavailable\n");
251 return DSERR_CONTROLUNAVAIL
;
255 WARN("invalid parameter: vol == NULL\n");
256 return DSERR_INVALIDPARAM
;
259 *vol
= This
->volpan
.lVolume
;
264 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8
*iface
, DWORD freq
)
266 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
269 TRACE("(%p,%d)\n",This
,freq
);
271 if (is_primary_buffer(This
)) {
272 WARN("not available for primary buffers.\n");
273 return DSERR_CONTROLUNAVAIL
;
276 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFREQUENCY
)) {
277 WARN("control unavailable\n");
278 return DSERR_CONTROLUNAVAIL
;
281 if (freq
== DSBFREQUENCY_ORIGINAL
)
282 freq
= This
->pwfx
->nSamplesPerSec
;
284 if ((freq
< DSBFREQUENCY_MIN
) || (freq
> DSBFREQUENCY_MAX
)) {
285 WARN("invalid parameter: freq = %d\n", freq
);
286 return DSERR_INVALIDPARAM
;
290 RtlAcquireResourceExclusive(&This
->lock
, TRUE
);
292 oldFreq
= This
->freq
;
294 if (freq
!= oldFreq
) {
295 This
->freqAdjust
= ((DWORD64
)This
->freq
<< DSOUND_FREQSHIFT
) / This
->device
->pwfx
->nSamplesPerSec
;
296 This
->nAvgBytesPerSec
= freq
* This
->pwfx
->nBlockAlign
;
297 DSOUND_RecalcFormat(This
);
298 DSOUND_MixToTemporary(This
, 0, This
->buflen
, FALSE
);
301 RtlReleaseResource(&This
->lock
);
307 static HRESULT WINAPI
IDirectSoundBufferImpl_Play(IDirectSoundBuffer8
*iface
, DWORD reserved1
,
308 DWORD reserved2
, DWORD flags
)
310 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
311 HRESULT hres
= DS_OK
;
313 TRACE("(%p,%08x,%08x,%08x)\n",This
,reserved1
,reserved2
,flags
);
316 RtlAcquireResourceExclusive(&This
->lock
, TRUE
);
318 This
->playflags
= flags
;
319 if (This
->state
== STATE_STOPPED
&& !This
->hwbuf
) {
321 This
->state
= STATE_STARTING
;
322 } else if (This
->state
== STATE_STOPPING
)
323 This
->state
= STATE_PLAYING
;
325 hres
= IDsDriverBuffer_Play(This
->hwbuf
, 0, 0, This
->playflags
);
327 WARN("IDsDriverBuffer_Play failed\n");
329 This
->state
= STATE_PLAYING
;
332 RtlReleaseResource(&This
->lock
);
338 static HRESULT WINAPI
IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8
*iface
)
340 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
341 HRESULT hres
= DS_OK
;
343 TRACE("(%p)\n",This
);
346 RtlAcquireResourceExclusive(&This
->lock
, TRUE
);
348 if (This
->state
== STATE_PLAYING
)
349 This
->state
= STATE_STOPPING
;
350 else if (This
->state
== STATE_STARTING
)
352 This
->state
= STATE_STOPPED
;
353 DSOUND_CheckEvent(This
, 0, 0);
356 hres
= IDsDriverBuffer_Stop(This
->hwbuf
);
358 WARN("IDsDriverBuffer_Stop failed\n");
360 This
->state
= STATE_STOPPED
;
363 RtlReleaseResource(&This
->lock
);
369 static ULONG WINAPI
IDirectSoundBufferImpl_AddRef(IDirectSoundBuffer8
*iface
)
371 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
372 ULONG ref
= InterlockedIncrement(&This
->ref
);
374 TRACE("(%p) ref was %d\n", This
, ref
- 1);
377 InterlockedIncrement(&This
->numIfaces
);
382 static ULONG WINAPI
IDirectSoundBufferImpl_Release(IDirectSoundBuffer8
*iface
)
384 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
385 ULONG ref
= InterlockedDecrement(&This
->ref
);
387 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
389 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
)) {
390 if (is_primary_buffer(This
))
391 primarybuffer_destroy(This
);
393 secondarybuffer_destroy(This
);
398 static HRESULT WINAPI
IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuffer8
*iface
,
399 DWORD
*playpos
, DWORD
*writepos
)
401 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
404 TRACE("(%p,%p,%p)\n",This
,playpos
,writepos
);
406 RtlAcquireResourceShared(&This
->lock
, TRUE
);
408 hres
=IDsDriverBuffer_GetPosition(This
->hwbuf
,playpos
,writepos
);
410 WARN("IDsDriverBuffer_GetPosition failed\n");
414 DWORD pos
= This
->sec_mixpos
;
417 if (pos
>= This
->buflen
){
418 FIXME("Bad play position. playpos: %d, buflen: %d\n", pos
, This
->buflen
);
427 if (writepos
&& This
->state
!= STATE_STOPPED
&& (!This
->hwbuf
|| !(This
->device
->drvdesc
.dwFlags
& DSDDESC_DONTNEEDWRITELEAD
))) {
428 /* apply the documented 10ms lead to writepos */
429 *writepos
+= This
->writelead
;
430 *writepos
%= This
->buflen
;
432 RtlReleaseResource(&This
->lock
);
434 TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",
435 playpos
?*playpos
:-1, writepos
?*writepos
:-1, This
->buflen
, This
, GetTickCount());
440 static HRESULT WINAPI
IDirectSoundBufferImpl_GetStatus(IDirectSoundBuffer8
*iface
, DWORD
*status
)
442 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
444 TRACE("(%p,%p), thread is %04x\n",This
,status
,GetCurrentThreadId());
446 if (status
== NULL
) {
447 WARN("invalid parameter: status = NULL\n");
448 return DSERR_INVALIDPARAM
;
452 RtlAcquireResourceShared(&This
->lock
, TRUE
);
453 if ((This
->state
== STATE_STARTING
) || (This
->state
== STATE_PLAYING
)) {
454 *status
|= DSBSTATUS_PLAYING
;
455 if (This
->playflags
& DSBPLAY_LOOPING
)
456 *status
|= DSBSTATUS_LOOPING
;
458 RtlReleaseResource(&This
->lock
);
460 TRACE("status=%x\n", *status
);
465 static HRESULT WINAPI
IDirectSoundBufferImpl_GetFormat(IDirectSoundBuffer8
*iface
,
466 LPWAVEFORMATEX lpwf
, DWORD wfsize
, DWORD
*wfwritten
)
468 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
471 TRACE("(%p,%p,%d,%p)\n",This
,lpwf
,wfsize
,wfwritten
);
473 size
= sizeof(WAVEFORMATEX
) + This
->pwfx
->cbSize
;
475 if (lpwf
) { /* NULL is valid */
476 if (wfsize
>= size
) {
477 CopyMemory(lpwf
,This
->pwfx
,size
);
481 WARN("invalid parameter: wfsize too small\n");
482 CopyMemory(lpwf
,This
->pwfx
,wfsize
);
485 return DSERR_INVALIDPARAM
;
489 *wfwritten
= sizeof(WAVEFORMATEX
) + This
->pwfx
->cbSize
;
491 WARN("invalid parameter: wfwritten == NULL\n");
492 return DSERR_INVALIDPARAM
;
499 static HRESULT WINAPI
IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8
*iface
, DWORD writecursor
,
500 DWORD writebytes
, void **lplpaudioptr1
, DWORD
*audiobytes1
, void **lplpaudioptr2
,
501 DWORD
*audiobytes2
, DWORD flags
)
503 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
504 HRESULT hres
= DS_OK
;
506 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n", This
, writecursor
, writebytes
, lplpaudioptr1
,
507 audiobytes1
, lplpaudioptr2
, audiobytes2
, flags
, GetTickCount());
510 return DSERR_INVALIDPARAM
;
512 /* when this flag is set, writecursor is meaningless and must be calculated */
513 if (flags
& DSBLOCK_FROMWRITECURSOR
) {
514 /* GetCurrentPosition does too much magic to duplicate here */
515 hres
= IDirectSoundBufferImpl_GetCurrentPosition(iface
, NULL
, &writecursor
);
517 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
522 /* when this flag is set, writebytes is meaningless and must be set */
523 if (flags
& DSBLOCK_ENTIREBUFFER
)
524 writebytes
= This
->buflen
;
526 if (writecursor
>= This
->buflen
) {
527 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
528 writecursor
, This
->buflen
);
529 return DSERR_INVALIDPARAM
;
532 if (writebytes
> This
->buflen
) {
533 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
534 writebytes
, This
->buflen
);
535 return DSERR_INVALIDPARAM
;
539 RtlAcquireResourceShared(&This
->lock
, TRUE
);
541 if (!(This
->device
->drvdesc
.dwFlags
& DSDDESC_DONTNEEDSECONDARYLOCK
) && This
->hwbuf
) {
542 hres
= IDsDriverBuffer_Lock(This
->hwbuf
,
543 lplpaudioptr1
, audiobytes1
,
544 lplpaudioptr2
, audiobytes2
,
545 writecursor
, writebytes
,
548 WARN("IDsDriverBuffer_Lock failed\n");
549 RtlReleaseResource(&This
->lock
);
553 if (writecursor
+writebytes
<= This
->buflen
) {
554 *(LPBYTE
*)lplpaudioptr1
= This
->buffer
->memory
+writecursor
;
555 if (This
->sec_mixpos
>= writecursor
&& This
->sec_mixpos
< writecursor
+ writebytes
&& This
->state
== STATE_PLAYING
)
556 WARN("Overwriting mixing position, case 1\n");
557 *audiobytes1
= writebytes
;
559 *(LPBYTE
*)lplpaudioptr2
= NULL
;
562 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n",
563 *(LPBYTE
*)lplpaudioptr1
, *audiobytes1
, lplpaudioptr2
? *(LPBYTE
*)lplpaudioptr2
: NULL
, audiobytes2
? *audiobytes2
: 0, writecursor
);
564 TRACE("->%d.0\n",writebytes
);
566 DWORD remainder
= writebytes
+ writecursor
- This
->buflen
;
567 *(LPBYTE
*)lplpaudioptr1
= This
->buffer
->memory
+writecursor
;
568 *audiobytes1
= This
->buflen
-writecursor
;
569 if (This
->sec_mixpos
>= writecursor
&& This
->sec_mixpos
< writecursor
+ writebytes
&& This
->state
== STATE_PLAYING
)
570 WARN("Overwriting mixing position, case 2\n");
572 *(LPBYTE
*)lplpaudioptr2
= This
->buffer
->memory
;
574 *audiobytes2
= writebytes
-(This
->buflen
-writecursor
);
575 if (audiobytes2
&& This
->sec_mixpos
< remainder
&& This
->state
== STATE_PLAYING
)
576 WARN("Overwriting mixing position, case 3\n");
577 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE
*)lplpaudioptr1
, *audiobytes1
, lplpaudioptr2
? *(LPBYTE
*)lplpaudioptr2
: NULL
, audiobytes2
? *audiobytes2
: 0, writecursor
);
581 RtlReleaseResource(&This
->lock
);
587 static HRESULT WINAPI
IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuffer8
*iface
,
590 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
591 HRESULT hres
= DS_OK
;
594 TRACE("(%p,%d)\n",This
,newpos
);
597 RtlAcquireResourceExclusive(&This
->lock
, TRUE
);
599 oldpos
= This
->sec_mixpos
;
601 /* start mixing from this new location instead */
602 newpos
%= This
->buflen
;
603 newpos
-= newpos
%This
->pwfx
->nBlockAlign
;
604 This
->sec_mixpos
= newpos
;
606 /* at this point, do not attempt to reset buffers, mess with primary mix position,
607 or anything like that to reduce latency. The data already prebuffered cannot be changed */
609 /* position HW buffer if applicable, else just start mixing from new location instead */
611 hres
= IDsDriverBuffer_SetPosition(This
->hwbuf
, This
->buf_mixpos
);
613 WARN("IDsDriverBuffer_SetPosition failed\n");
615 else if (oldpos
!= newpos
)
616 /* FIXME: Perhaps add a call to DSOUND_MixToTemporary here? Not sure it's needed */
617 This
->buf_mixpos
= DSOUND_secpos_to_bufpos(This
, newpos
, 0, NULL
);
619 RtlReleaseResource(&This
->lock
);
625 static HRESULT WINAPI
IDirectSoundBufferImpl_SetPan(IDirectSoundBuffer8
*iface
, LONG pan
)
627 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
628 HRESULT hres
= DS_OK
;
630 TRACE("(%p,%d)\n",This
,pan
);
632 if ((pan
> DSBPAN_RIGHT
) || (pan
< DSBPAN_LEFT
)) {
633 WARN("invalid parameter: pan = %d\n", pan
);
634 return DSERR_INVALIDPARAM
;
637 /* You cannot use both pan and 3D controls */
638 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
) ||
639 (This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
)) {
640 WARN("control unavailable\n");
641 return DSERR_CONTROLUNAVAIL
;
645 RtlAcquireResourceExclusive(&This
->lock
, TRUE
);
647 if (This
->volpan
.lPan
!= pan
) {
648 This
->volpan
.lPan
= pan
;
649 DSOUND_RecalcVolPan(&(This
->volpan
));
652 hres
= IDsDriverBuffer_SetVolumePan(This
->hwbuf
, &(This
->volpan
));
654 WARN("IDsDriverBuffer_SetVolumePan failed\n");
658 RtlReleaseResource(&This
->lock
);
664 static HRESULT WINAPI
IDirectSoundBufferImpl_GetPan(IDirectSoundBuffer8
*iface
, LONG
*pan
)
666 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
668 TRACE("(%p,%p)\n",This
,pan
);
670 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
671 WARN("control unavailable\n");
672 return DSERR_CONTROLUNAVAIL
;
676 WARN("invalid parameter: pan = NULL\n");
677 return DSERR_INVALIDPARAM
;
680 *pan
= This
->volpan
.lPan
;
685 static HRESULT WINAPI
IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8
*iface
, void *p1
, DWORD x1
,
688 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
), *iter
;
689 HRESULT hres
= DS_OK
;
691 TRACE("(%p,%p,%d,%p,%d)\n", This
,p1
,x1
,p2
,x2
);
694 RtlAcquireResourceShared(&This
->lock
, TRUE
);
696 if (!(This
->device
->drvdesc
.dwFlags
& DSDDESC_DONTNEEDSECONDARYLOCK
) && This
->hwbuf
) {
697 hres
= IDsDriverBuffer_Unlock(This
->hwbuf
, p1
, x1
, p2
, x2
);
699 WARN("IDsDriverBuffer_Unlock failed\n");
702 RtlReleaseResource(&This
->lock
);
708 if (!This
->hwbuf
&& (x1
|| x2
))
710 RtlAcquireResourceShared(&This
->device
->buffer_list_lock
, TRUE
);
711 LIST_FOR_EACH_ENTRY(iter
, &This
->buffer
->buffers
, IDirectSoundBufferImpl
, entry
)
713 RtlAcquireResourceShared(&iter
->lock
, TRUE
);
716 if(x1
+ (DWORD_PTR
)p1
- (DWORD_PTR
)iter
->buffer
->memory
> iter
->buflen
)
717 hres
= DSERR_INVALIDPARAM
;
719 DSOUND_MixToTemporary(iter
, (DWORD_PTR
)p1
- (DWORD_PTR
)iter
->buffer
->memory
, x1
, FALSE
);
722 DSOUND_MixToTemporary(iter
, 0, x2
, FALSE
);
723 RtlReleaseResource(&iter
->lock
);
725 RtlReleaseResource(&This
->device
->buffer_list_lock
);
731 static HRESULT WINAPI
IDirectSoundBufferImpl_Restore(IDirectSoundBuffer8
*iface
)
733 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
735 FIXME("(%p):stub\n",This
);
739 static HRESULT WINAPI
IDirectSoundBufferImpl_GetFrequency(IDirectSoundBuffer8
*iface
, DWORD
*freq
)
741 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
743 TRACE("(%p,%p)\n",This
,freq
);
746 WARN("invalid parameter: freq = NULL\n");
747 return DSERR_INVALIDPARAM
;
751 TRACE("-> %d\n", *freq
);
756 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFX(IDirectSoundBuffer8
*iface
, DWORD dwEffectsCount
,
757 LPDSEFFECTDESC pDSFXDesc
, DWORD
*pdwResultCodes
)
759 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
762 FIXME("(%p,%u,%p,%p): stub\n",This
,dwEffectsCount
,pDSFXDesc
,pdwResultCodes
);
765 for (u
=0; u
<dwEffectsCount
; u
++) pdwResultCodes
[u
] = DSFXR_UNKNOWN
;
767 WARN("control unavailable\n");
768 return DSERR_CONTROLUNAVAIL
;
771 static HRESULT WINAPI
IDirectSoundBufferImpl_AcquireResources(IDirectSoundBuffer8
*iface
,
772 DWORD dwFlags
, DWORD dwEffectsCount
, DWORD
*pdwResultCodes
)
774 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
777 FIXME("(%p,%08u,%u,%p): stub, faking success\n",This
,dwFlags
,dwEffectsCount
,pdwResultCodes
);
780 for (u
=0; u
<dwEffectsCount
; u
++) pdwResultCodes
[u
] = DSFXR_UNKNOWN
;
782 WARN("control unavailable\n");
786 static HRESULT WINAPI
IDirectSoundBufferImpl_GetObjectInPath(IDirectSoundBuffer8
*iface
,
787 REFGUID rguidObject
, DWORD dwIndex
, REFGUID rguidInterface
, void **ppObject
)
789 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
791 FIXME("(%p,%s,%u,%s,%p): stub\n",This
,debugstr_guid(rguidObject
),dwIndex
,debugstr_guid(rguidInterface
),ppObject
);
793 WARN("control unavailable\n");
794 return DSERR_CONTROLUNAVAIL
;
797 static HRESULT WINAPI
IDirectSoundBufferImpl_Initialize(IDirectSoundBuffer8
*iface
,
798 IDirectSound
*dsound
, LPCDSBUFFERDESC dbsd
)
800 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
802 WARN("(%p) already initialized\n", This
);
803 return DSERR_ALREADYINITIALIZED
;
806 static HRESULT WINAPI
IDirectSoundBufferImpl_GetCaps(IDirectSoundBuffer8
*iface
, LPDSBCAPS caps
)
808 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
810 TRACE("(%p)->(%p)\n",This
,caps
);
813 WARN("invalid parameter: caps == NULL\n");
814 return DSERR_INVALIDPARAM
;
817 if (caps
->dwSize
< sizeof(*caps
)) {
818 WARN("invalid parameter: caps->dwSize = %d\n",caps
->dwSize
);
819 return DSERR_INVALIDPARAM
;
822 caps
->dwFlags
= This
->dsbd
.dwFlags
;
823 if (This
->hwbuf
) caps
->dwFlags
|= DSBCAPS_LOCHARDWARE
;
824 else caps
->dwFlags
|= DSBCAPS_LOCSOFTWARE
;
826 caps
->dwBufferBytes
= This
->buflen
;
828 /* According to windows, this is zero*/
829 caps
->dwUnlockTransferRate
= 0;
830 caps
->dwPlayCpuOverhead
= 0;
835 static HRESULT WINAPI
IDirectSoundBufferImpl_QueryInterface(IDirectSoundBuffer8
*iface
, REFIID riid
,
838 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
840 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
843 WARN("invalid parameter\n");
847 *ppobj
= NULL
; /* assume failure */
849 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
850 IsEqualGUID(riid
, &IID_IDirectSoundBuffer
) ||
851 IsEqualGUID(riid
, &IID_IDirectSoundBuffer8
) ) {
852 IDirectSoundBuffer8_AddRef(iface
);
857 if ( IsEqualGUID( &IID_IDirectSoundNotify
, riid
) ) {
859 IDirectSoundNotifyImpl_Create(This
, &(This
->notify
));
861 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY
)This
->notify
);
862 *ppobj
= This
->notify
;
865 WARN("IID_IDirectSoundNotify\n");
866 return E_NOINTERFACE
;
869 if ( IsEqualGUID( &IID_IDirectSound3DBuffer
, riid
) ) {
871 IDirectSound3DBufferImpl_Create(This
, &(This
->ds3db
));
873 IDirectSound3DBuffer_AddRef((LPDIRECTSOUND3DBUFFER
)This
->ds3db
);
874 *ppobj
= This
->ds3db
;
877 WARN("IID_IDirectSound3DBuffer\n");
878 return E_NOINTERFACE
;
881 if ( IsEqualGUID( &IID_IDirectSound3DListener
, riid
) ) {
882 ERR("app requested IDirectSound3DListener on secondary buffer\n");
883 return E_NOINTERFACE
;
886 if ( IsEqualGUID( &IID_IKsPropertySet
, riid
) ) {
888 IKsBufferPropertySetImpl_Create(This
, &(This
->iks
));
890 IKsPropertySet_AddRef((LPKSPROPERTYSET
)This
->iks
);
894 WARN("IID_IKsPropertySet\n");
895 return E_NOINTERFACE
;
898 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
900 return E_NOINTERFACE
;
903 static const IDirectSoundBuffer8Vtbl dsbvt
=
905 IDirectSoundBufferImpl_QueryInterface
,
906 IDirectSoundBufferImpl_AddRef
,
907 IDirectSoundBufferImpl_Release
,
908 IDirectSoundBufferImpl_GetCaps
,
909 IDirectSoundBufferImpl_GetCurrentPosition
,
910 IDirectSoundBufferImpl_GetFormat
,
911 IDirectSoundBufferImpl_GetVolume
,
912 IDirectSoundBufferImpl_GetPan
,
913 IDirectSoundBufferImpl_GetFrequency
,
914 IDirectSoundBufferImpl_GetStatus
,
915 IDirectSoundBufferImpl_Initialize
,
916 IDirectSoundBufferImpl_Lock
,
917 IDirectSoundBufferImpl_Play
,
918 IDirectSoundBufferImpl_SetCurrentPosition
,
919 IDirectSoundBufferImpl_SetFormat
,
920 IDirectSoundBufferImpl_SetVolume
,
921 IDirectSoundBufferImpl_SetPan
,
922 IDirectSoundBufferImpl_SetFrequency
,
923 IDirectSoundBufferImpl_Stop
,
924 IDirectSoundBufferImpl_Unlock
,
925 IDirectSoundBufferImpl_Restore
,
926 IDirectSoundBufferImpl_SetFX
,
927 IDirectSoundBufferImpl_AcquireResources
,
928 IDirectSoundBufferImpl_GetObjectInPath
931 HRESULT
IDirectSoundBufferImpl_Create(
932 DirectSoundDevice
* device
,
933 IDirectSoundBufferImpl
**pdsb
,
934 LPCDSBUFFERDESC dsbd
)
936 IDirectSoundBufferImpl
*dsb
;
937 LPWAVEFORMATEX wfex
= dsbd
->lpwfxFormat
;
941 TRACE("(%p,%p,%p)\n",device
,pdsb
,dsbd
);
943 if (dsbd
->dwBufferBytes
< DSBSIZE_MIN
|| dsbd
->dwBufferBytes
> DSBSIZE_MAX
) {
944 WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd
->dwBufferBytes
);
946 return DSERR_INVALIDPARAM
; /* FIXME: which error? */
949 dsb
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(*dsb
));
952 WARN("out of memory\n");
954 return DSERR_OUTOFMEMORY
;
957 TRACE("Created buffer at %p\n", dsb
);
961 dsb
->device
= device
;
962 dsb
->IDirectSoundBuffer8_iface
.lpVtbl
= &dsbvt
;
965 /* size depends on version */
966 CopyMemory(&dsb
->dsbd
, dsbd
, dsbd
->dwSize
);
968 dsb
->pwfx
= DSOUND_CopyFormat(wfex
);
969 if (dsb
->pwfx
== NULL
) {
970 HeapFree(GetProcessHeap(),0,dsb
);
972 return DSERR_OUTOFMEMORY
;
975 if (dsbd
->dwBufferBytes
% dsbd
->lpwfxFormat
->nBlockAlign
)
976 dsb
->buflen
= dsbd
->dwBufferBytes
+
977 (dsbd
->lpwfxFormat
->nBlockAlign
-
978 (dsbd
->dwBufferBytes
% dsbd
->lpwfxFormat
->nBlockAlign
));
980 dsb
->buflen
= dsbd
->dwBufferBytes
;
982 dsb
->freq
= dsbd
->lpwfxFormat
->nSamplesPerSec
;
984 dsb
->notifies
= NULL
;
985 dsb
->nrofnotifies
= 0;
988 /* Check necessary hardware mixing capabilities */
989 if (wfex
->nChannels
==2) capf
|= DSCAPS_SECONDARYSTEREO
;
990 else capf
|= DSCAPS_SECONDARYMONO
;
991 if (wfex
->wBitsPerSample
==16) capf
|= DSCAPS_SECONDARY16BIT
;
992 else capf
|= DSCAPS_SECONDARY8BIT
;
994 use_hw
= !!(dsbd
->dwFlags
& DSBCAPS_LOCHARDWARE
);
995 TRACE("use_hw = %d, capf = 0x%08x, device->drvcaps.dwFlags = 0x%08x\n", use_hw
, capf
, device
->drvcaps
.dwFlags
);
996 if (use_hw
&& ((device
->drvcaps
.dwFlags
& capf
) != capf
|| !device
->driver
))
999 WARN("Format not supported for hardware buffer\n");
1000 HeapFree(GetProcessHeap(),0,dsb
->pwfx
);
1001 HeapFree(GetProcessHeap(),0,dsb
);
1003 if ((device
->drvcaps
.dwFlags
& capf
) != capf
)
1004 return DSERR_BADFORMAT
;
1005 return DSERR_GENERIC
;
1008 /* FIXME: check hardware sample rate mixing capabilities */
1009 /* FIXME: check app hints for software/hardware buffer (STATIC, LOCHARDWARE, etc) */
1010 /* FIXME: check whether any hardware buffers are left */
1011 /* FIXME: handle DSDHEAP_CREATEHEAP for hardware buffers */
1013 /* Allocate an empty buffer */
1014 dsb
->buffer
= HeapAlloc(GetProcessHeap(),0,sizeof(*(dsb
->buffer
)));
1015 if (dsb
->buffer
== NULL
) {
1016 WARN("out of memory\n");
1017 HeapFree(GetProcessHeap(),0,dsb
->pwfx
);
1018 HeapFree(GetProcessHeap(),0,dsb
);
1020 return DSERR_OUTOFMEMORY
;
1023 /* Allocate system memory for buffer if applicable */
1024 if ((device
->drvdesc
.dwFlags
& DSDDESC_USESYSTEMMEMORY
) || !use_hw
) {
1025 dsb
->buffer
->memory
= HeapAlloc(GetProcessHeap(),0,dsb
->buflen
);
1026 if (dsb
->buffer
->memory
== NULL
) {
1027 WARN("out of memory\n");
1028 HeapFree(GetProcessHeap(),0,dsb
->pwfx
);
1029 HeapFree(GetProcessHeap(),0,dsb
->buffer
);
1030 HeapFree(GetProcessHeap(),0,dsb
);
1032 return DSERR_OUTOFMEMORY
;
1036 /* Allocate the hardware buffer */
1038 err
= IDsDriver_CreateSoundBuffer(device
->driver
,wfex
,dsbd
->dwFlags
,0,
1039 &(dsb
->buflen
),&(dsb
->buffer
->memory
),
1040 (LPVOID
*)&(dsb
->hwbuf
));
1043 WARN("Failed to create hardware secondary buffer: %08x\n", err
);
1044 if (device
->drvdesc
.dwFlags
& DSDDESC_USESYSTEMMEMORY
)
1045 HeapFree(GetProcessHeap(),0,dsb
->buffer
->memory
);
1046 HeapFree(GetProcessHeap(),0,dsb
->buffer
);
1047 HeapFree(GetProcessHeap(),0,dsb
->pwfx
);
1048 HeapFree(GetProcessHeap(),0,dsb
);
1050 return DSERR_GENERIC
;
1054 dsb
->buffer
->ref
= 1;
1055 list_init(&dsb
->buffer
->buffers
);
1056 list_add_head(&dsb
->buffer
->buffers
, &dsb
->entry
);
1057 FillMemory(dsb
->buffer
->memory
, dsb
->buflen
, dsbd
->lpwfxFormat
->wBitsPerSample
== 8 ? 128 : 0);
1059 /* It's not necessary to initialize values to zero since */
1060 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1061 dsb
->buf_mixpos
= dsb
->sec_mixpos
= 0;
1062 dsb
->state
= STATE_STOPPED
;
1064 dsb
->freqAdjust
= ((DWORD64
)dsb
->freq
<< DSOUND_FREQSHIFT
) / device
->pwfx
->nSamplesPerSec
;
1065 dsb
->nAvgBytesPerSec
= dsb
->freq
*
1066 dsbd
->lpwfxFormat
->nBlockAlign
;
1068 /* calculate fragment size and write lead */
1069 DSOUND_RecalcFormat(dsb
);
1071 if (dsb
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
1072 dsb
->ds3db_ds3db
.dwSize
= sizeof(DS3DBUFFER
);
1073 dsb
->ds3db_ds3db
.vPosition
.x
= 0.0;
1074 dsb
->ds3db_ds3db
.vPosition
.y
= 0.0;
1075 dsb
->ds3db_ds3db
.vPosition
.z
= 0.0;
1076 dsb
->ds3db_ds3db
.vVelocity
.x
= 0.0;
1077 dsb
->ds3db_ds3db
.vVelocity
.y
= 0.0;
1078 dsb
->ds3db_ds3db
.vVelocity
.z
= 0.0;
1079 dsb
->ds3db_ds3db
.dwInsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1080 dsb
->ds3db_ds3db
.dwOutsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1081 dsb
->ds3db_ds3db
.vConeOrientation
.x
= 0.0;
1082 dsb
->ds3db_ds3db
.vConeOrientation
.y
= 0.0;
1083 dsb
->ds3db_ds3db
.vConeOrientation
.z
= 0.0;
1084 dsb
->ds3db_ds3db
.lConeOutsideVolume
= DS3D_DEFAULTCONEOUTSIDEVOLUME
;
1085 dsb
->ds3db_ds3db
.flMinDistance
= DS3D_DEFAULTMINDISTANCE
;
1086 dsb
->ds3db_ds3db
.flMaxDistance
= DS3D_DEFAULTMAXDISTANCE
;
1087 dsb
->ds3db_ds3db
.dwMode
= DS3DMODE_NORMAL
;
1089 dsb
->ds3db_need_recalc
= FALSE
;
1090 DSOUND_Calc3DBuffer(dsb
);
1092 DSOUND_RecalcVolPan(&(dsb
->volpan
));
1094 RtlInitializeResource(&dsb
->lock
);
1096 /* register buffer if not primary */
1097 if (!(dsbd
->dwFlags
& DSBCAPS_PRIMARYBUFFER
)) {
1098 err
= DirectSoundDevice_AddBuffer(device
, dsb
);
1100 HeapFree(GetProcessHeap(),0,dsb
->buffer
->memory
);
1101 HeapFree(GetProcessHeap(),0,dsb
->buffer
);
1102 RtlDeleteResource(&dsb
->lock
);
1103 HeapFree(GetProcessHeap(),0,dsb
->pwfx
);
1104 HeapFree(GetProcessHeap(),0,dsb
);
1113 void secondarybuffer_destroy(IDirectSoundBufferImpl
*This
)
1115 DirectSoundDevice_RemoveBuffer(This
->device
, This
);
1116 RtlDeleteResource(&This
->lock
);
1119 IDsDriverBuffer_Release(This
->hwbuf
);
1120 if (!This
->hwbuf
|| (This
->device
->drvdesc
.dwFlags
& DSDDESC_USESYSTEMMEMORY
)) {
1121 This
->buffer
->ref
--;
1122 list_remove(&This
->entry
);
1123 if (This
->buffer
->ref
== 0) {
1124 HeapFree(GetProcessHeap(), 0, This
->buffer
->memory
);
1125 HeapFree(GetProcessHeap(), 0, This
->buffer
);
1129 HeapFree(GetProcessHeap(), 0, This
->tmp_buffer
);
1130 HeapFree(GetProcessHeap(), 0, This
->notifies
);
1131 HeapFree(GetProcessHeap(), 0, This
->pwfx
);
1132 HeapFree(GetProcessHeap(), 0, This
);
1134 TRACE("(%p) released\n", This
);
1137 HRESULT
IDirectSoundBufferImpl_Destroy(
1138 IDirectSoundBufferImpl
*pdsb
)
1140 TRACE("(%p)\n",pdsb
);
1142 /* This keeps the *_Destroy functions from possibly deleting
1143 * this object until it is ready to be deleted */
1144 InterlockedIncrement(&pdsb
->numIfaces
);
1147 WARN("iks not NULL\n");
1148 IKsBufferPropertySetImpl_Destroy(pdsb
->iks
);
1153 WARN("ds3db not NULL\n");
1154 IDirectSound3DBufferImpl_Destroy(pdsb
->ds3db
);
1159 WARN("notify not NULL\n");
1160 IDirectSoundNotifyImpl_Destroy(pdsb
->notify
);
1161 pdsb
->notify
= NULL
;
1164 secondarybuffer_destroy(pdsb
);
1169 HRESULT
IDirectSoundBufferImpl_Duplicate(
1170 DirectSoundDevice
*device
,
1171 IDirectSoundBufferImpl
**ppdsb
,
1172 IDirectSoundBufferImpl
*pdsb
)
1174 IDirectSoundBufferImpl
*dsb
;
1175 HRESULT hres
= DS_OK
;
1176 TRACE("(%p,%p,%p)\n", device
, ppdsb
, pdsb
);
1178 dsb
= HeapAlloc(GetProcessHeap(),0,sizeof(*dsb
));
1180 WARN("out of memory\n");
1182 return DSERR_OUTOFMEMORY
;
1184 CopyMemory(dsb
, pdsb
, sizeof(*dsb
));
1186 dsb
->pwfx
= DSOUND_CopyFormat(pdsb
->pwfx
);
1187 if (dsb
->pwfx
== NULL
) {
1188 HeapFree(GetProcessHeap(),0,dsb
);
1190 return DSERR_OUTOFMEMORY
;
1194 TRACE("duplicating hardware buffer\n");
1196 hres
= IDsDriver_DuplicateSoundBuffer(device
->driver
, pdsb
->hwbuf
,
1197 (LPVOID
*)&dsb
->hwbuf
);
1199 WARN("IDsDriver_DuplicateSoundBuffer failed (%08x)\n", hres
);
1200 HeapFree(GetProcessHeap(),0,dsb
->pwfx
);
1201 HeapFree(GetProcessHeap(),0,dsb
);
1208 list_add_head(&dsb
->buffer
->buffers
, &dsb
->entry
);
1211 dsb
->state
= STATE_STOPPED
;
1212 dsb
->buf_mixpos
= dsb
->sec_mixpos
= 0;
1214 dsb
->notifies
= NULL
;
1215 dsb
->nrofnotifies
= 0;
1216 dsb
->device
= device
;
1218 dsb
->iks
= NULL
; /* FIXME? */
1219 dsb
->tmp_buffer
= NULL
;
1220 DSOUND_RecalcFormat(dsb
);
1221 DSOUND_MixToTemporary(dsb
, 0, dsb
->buflen
, FALSE
);
1223 RtlInitializeResource(&dsb
->lock
);
1225 /* register buffer */
1226 hres
= DirectSoundDevice_AddBuffer(device
, dsb
);
1227 if (hres
!= DS_OK
) {
1228 RtlDeleteResource(&dsb
->lock
);
1229 HeapFree(GetProcessHeap(),0,dsb
->tmp_buffer
);
1230 list_remove(&dsb
->entry
);
1232 HeapFree(GetProcessHeap(),0,dsb
->pwfx
);
1233 HeapFree(GetProcessHeap(),0,dsb
);
1241 /*******************************************************************************
1242 * IKsBufferPropertySet
1245 /* IUnknown methods */
1246 static HRESULT WINAPI
IKsBufferPropertySetImpl_QueryInterface(
1247 LPKSPROPERTYSET iface
,
1251 IKsBufferPropertySetImpl
*This
= (IKsBufferPropertySetImpl
*)iface
;
1252 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
1254 return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8
)This
->dsb
, riid
, ppobj
);
1257 static ULONG WINAPI
IKsBufferPropertySetImpl_AddRef(LPKSPROPERTYSET iface
)
1259 IKsBufferPropertySetImpl
*This
= (IKsBufferPropertySetImpl
*)iface
;
1260 ULONG ref
= InterlockedIncrement(&(This
->ref
));
1261 TRACE("(%p) ref was %d\n", This
, ref
- 1);
1265 static ULONG WINAPI
IKsBufferPropertySetImpl_Release(LPKSPROPERTYSET iface
)
1267 IKsBufferPropertySetImpl
*This
= (IKsBufferPropertySetImpl
*)iface
;
1268 ULONG ref
= InterlockedDecrement(&(This
->ref
));
1269 TRACE("(%p) ref was %d\n", This
, ref
+ 1);
1273 IDirectSoundBuffer_Release((LPDIRECTSOUND3DBUFFER
)This
->dsb
);
1274 HeapFree(GetProcessHeap(), 0, This
);
1275 TRACE("(%p) released\n", This
);
1280 static HRESULT WINAPI
IKsBufferPropertySetImpl_Get(
1281 LPKSPROPERTYSET iface
,
1282 REFGUID guidPropSet
,
1284 LPVOID pInstanceData
,
1285 ULONG cbInstanceData
,
1288 PULONG pcbReturned
)
1290 IKsBufferPropertySetImpl
*This
= (IKsBufferPropertySetImpl
*)iface
;
1291 PIDSDRIVERPROPERTYSET ps
;
1292 TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
1293 This
,debugstr_guid(guidPropSet
),dwPropID
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
,pcbReturned
);
1295 if (This
->dsb
->hwbuf
) {
1296 IDsDriver_QueryInterface(This
->dsb
->hwbuf
, &IID_IDsDriverPropertySet
, (void **)&ps
);
1302 prop
.s
.Set
= *guidPropSet
;
1303 prop
.s
.Id
= dwPropID
;
1304 prop
.s
.Flags
= 0; /* unused */
1305 prop
.s
.InstanceId
= (ULONG
)This
->dsb
->device
;
1308 hres
= IDsDriverPropertySet_Get(ps
, &prop
, pInstanceData
, cbInstanceData
, pPropData
, cbPropData
, pcbReturned
);
1310 IDsDriverPropertySet_Release(ps
);
1316 return E_PROP_ID_UNSUPPORTED
;
1319 static HRESULT WINAPI
IKsBufferPropertySetImpl_Set(
1320 LPKSPROPERTYSET iface
,
1321 REFGUID guidPropSet
,
1323 LPVOID pInstanceData
,
1324 ULONG cbInstanceData
,
1328 IKsBufferPropertySetImpl
*This
= (IKsBufferPropertySetImpl
*)iface
;
1329 PIDSDRIVERPROPERTYSET ps
;
1330 TRACE("(%p,%s,%d,%p,%d,%p,%d)\n",This
,debugstr_guid(guidPropSet
),dwPropID
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
);
1332 if (This
->dsb
->hwbuf
) {
1333 IDsDriver_QueryInterface(This
->dsb
->hwbuf
, &IID_IDsDriverPropertySet
, (void **)&ps
);
1339 prop
.s
.Set
= *guidPropSet
;
1340 prop
.s
.Id
= dwPropID
;
1341 prop
.s
.Flags
= 0; /* unused */
1342 prop
.s
.InstanceId
= (ULONG
)This
->dsb
->device
;
1343 hres
= IDsDriverPropertySet_Set(ps
,&prop
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
);
1345 IDsDriverPropertySet_Release(ps
);
1351 return E_PROP_ID_UNSUPPORTED
;
1354 static HRESULT WINAPI
IKsBufferPropertySetImpl_QuerySupport(
1355 LPKSPROPERTYSET iface
,
1356 REFGUID guidPropSet
,
1358 PULONG pTypeSupport
)
1360 IKsBufferPropertySetImpl
*This
= (IKsBufferPropertySetImpl
*)iface
;
1361 PIDSDRIVERPROPERTYSET ps
;
1362 TRACE("(%p,%s,%d,%p)\n",This
,debugstr_guid(guidPropSet
),dwPropID
,pTypeSupport
);
1364 if (This
->dsb
->hwbuf
) {
1365 IDsDriver_QueryInterface(This
->dsb
->hwbuf
, &IID_IDsDriverPropertySet
, (void **)&ps
);
1370 hres
= IDsDriverPropertySet_QuerySupport(ps
,guidPropSet
, dwPropID
,pTypeSupport
);
1372 IDsDriverPropertySet_Release(ps
);
1378 return E_PROP_ID_UNSUPPORTED
;
1381 static const IKsPropertySetVtbl iksbvt
= {
1382 IKsBufferPropertySetImpl_QueryInterface
,
1383 IKsBufferPropertySetImpl_AddRef
,
1384 IKsBufferPropertySetImpl_Release
,
1385 IKsBufferPropertySetImpl_Get
,
1386 IKsBufferPropertySetImpl_Set
,
1387 IKsBufferPropertySetImpl_QuerySupport
1390 HRESULT
IKsBufferPropertySetImpl_Create(
1391 IDirectSoundBufferImpl
*dsb
,
1392 IKsBufferPropertySetImpl
**piks
)
1394 IKsBufferPropertySetImpl
*iks
;
1395 TRACE("(%p,%p)\n",dsb
,piks
);
1398 iks
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(*iks
));
1400 WARN("out of memory\n");
1402 return DSERR_OUTOFMEMORY
;
1408 iks
->lpVtbl
= &iksbvt
;
1410 IDirectSoundBuffer_AddRef((LPDIRECTSOUNDBUFFER
)dsb
);
1416 HRESULT
IKsBufferPropertySetImpl_Destroy(
1417 IKsBufferPropertySetImpl
*piks
)
1419 TRACE("(%p)\n",piks
);
1421 while (IKsBufferPropertySetImpl_Release((LPKSPROPERTYSET
)piks
) > 0);