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
31 #include "wine/debug.h"
33 #include "dsound_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
38 /*******************************************************************************
42 static inline struct IDirectSoundBufferImpl
*impl_from_IDirectSoundNotify(IDirectSoundNotify
*iface
)
44 return CONTAINING_RECORD(iface
, struct IDirectSoundBufferImpl
, IDirectSoundNotify_iface
);
47 static HRESULT WINAPI
IDirectSoundNotifyImpl_QueryInterface(IDirectSoundNotify
*iface
, REFIID riid
,
50 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
52 TRACE("(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
54 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
57 static ULONG WINAPI
IDirectSoundNotifyImpl_AddRef(IDirectSoundNotify
*iface
)
59 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
60 ULONG ref
= InterlockedIncrement(&This
->refn
);
62 TRACE("(%p) ref %d\n", This
, ref
);
65 InterlockedIncrement(&This
->numIfaces
);
70 static ULONG WINAPI
IDirectSoundNotifyImpl_Release(IDirectSoundNotify
*iface
)
72 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
73 ULONG ref
= InterlockedDecrement(&This
->refn
);
75 TRACE("(%p) ref %d\n", This
, ref
);
77 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
78 secondarybuffer_destroy(This
);
83 static int __cdecl
notify_compar(const void *l
, const void *r
)
85 const DSBPOSITIONNOTIFY
*left
= l
;
86 const DSBPOSITIONNOTIFY
*right
= r
;
88 /* place DSBPN_OFFSETSTOP at the start of the sorted array */
89 if(left
->dwOffset
== DSBPN_OFFSETSTOP
){
90 if(right
->dwOffset
!= DSBPN_OFFSETSTOP
)
92 }else if(right
->dwOffset
== DSBPN_OFFSETSTOP
)
95 if(left
->dwOffset
== right
->dwOffset
)
98 if(left
->dwOffset
< right
->dwOffset
)
104 static HRESULT WINAPI
IDirectSoundNotifyImpl_SetNotificationPositions(IDirectSoundNotify
*iface
,
105 DWORD howmuch
, const DSBPOSITIONNOTIFY
*notify
)
107 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
109 TRACE("(%p,0x%08x,%p)\n",This
,howmuch
,notify
);
111 if (howmuch
> 0 && notify
== NULL
) {
112 WARN("invalid parameter: notify == NULL\n");
113 return DSERR_INVALIDPARAM
;
116 if (TRACE_ON(dsound
)) {
118 for (i
=0;i
<howmuch
;i
++)
119 TRACE("notify at %d to %p\n",
120 notify
[i
].dwOffset
,notify
[i
].hEventNotify
);
124 /* Make an internal copy of the caller-supplied array.
125 * Replace the existing copy if one is already present. */
126 HeapFree(GetProcessHeap(), 0, This
->notifies
);
127 This
->notifies
= HeapAlloc(GetProcessHeap(), 0,
128 howmuch
* sizeof(DSBPOSITIONNOTIFY
));
130 if (This
->notifies
== NULL
) {
131 WARN("out of memory\n");
132 return DSERR_OUTOFMEMORY
;
134 CopyMemory(This
->notifies
, notify
, howmuch
* sizeof(DSBPOSITIONNOTIFY
));
135 This
->nrofnotifies
= howmuch
;
136 qsort(This
->notifies
, howmuch
, sizeof(DSBPOSITIONNOTIFY
), notify_compar
);
138 HeapFree(GetProcessHeap(), 0, This
->notifies
);
139 This
->notifies
= NULL
;
140 This
->nrofnotifies
= 0;
146 static const IDirectSoundNotifyVtbl dsnvt
=
148 IDirectSoundNotifyImpl_QueryInterface
,
149 IDirectSoundNotifyImpl_AddRef
,
150 IDirectSoundNotifyImpl_Release
,
151 IDirectSoundNotifyImpl_SetNotificationPositions
,
154 /*******************************************************************************
158 static inline IDirectSoundBufferImpl
*impl_from_IDirectSoundBuffer8(IDirectSoundBuffer8
*iface
)
160 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSoundBuffer8_iface
);
163 static inline BOOL
is_primary_buffer(IDirectSoundBufferImpl
*This
)
165 return (This
->dsbd
.dwFlags
& DSBCAPS_PRIMARYBUFFER
) != 0;
168 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFormat(IDirectSoundBuffer8
*iface
,
169 LPCWAVEFORMATEX wfex
)
171 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
173 TRACE("(%p,%p)\n", iface
, wfex
);
175 if (is_primary_buffer(This
))
176 return primarybuffer_SetFormat(This
->device
, wfex
);
178 WARN("not available for secondary buffers.\n");
179 return DSERR_INVALIDCALL
;
183 static HRESULT WINAPI
IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8
*iface
, LONG vol
)
185 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
188 HRESULT hres
= DS_OK
;
190 TRACE("(%p,%d)\n",This
,vol
);
192 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
193 WARN("control unavailable: This->dsbd.dwFlags = 0x%08x\n", This
->dsbd
.dwFlags
);
194 return DSERR_CONTROLUNAVAIL
;
197 if ((vol
> DSBVOLUME_MAX
) || (vol
< DSBVOLUME_MIN
)) {
198 WARN("invalid parameter: vol = %d\n", vol
);
199 return DSERR_INVALIDPARAM
;
202 AcquireSRWLockExclusive(&This
->lock
);
204 if (This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
205 oldVol
= This
->ds3db_lVolume
;
206 This
->ds3db_lVolume
= vol
;
208 /* recalc 3d volume, which in turn recalcs the pans */
209 DSOUND_Calc3DBuffer(This
);
211 oldVol
= This
->volpan
.lVolume
;
212 This
->volpan
.lVolume
= vol
;
214 DSOUND_RecalcVolPan(&(This
->volpan
));
217 ReleaseSRWLockExclusive(&This
->lock
);
222 static HRESULT WINAPI
IDirectSoundBufferImpl_GetVolume(IDirectSoundBuffer8
*iface
, LONG
*vol
)
224 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
226 TRACE("(%p,%p)\n",This
,vol
);
228 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
229 WARN("control unavailable\n");
230 return DSERR_CONTROLUNAVAIL
;
234 WARN("invalid parameter: vol == NULL\n");
235 return DSERR_INVALIDPARAM
;
238 *vol
= This
->volpan
.lVolume
;
243 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8
*iface
, DWORD freq
)
245 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
248 TRACE("(%p,%d)\n",This
,freq
);
250 if (is_primary_buffer(This
)) {
251 WARN("not available for primary buffers.\n");
252 return DSERR_CONTROLUNAVAIL
;
255 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFREQUENCY
)) {
256 WARN("control unavailable\n");
257 return DSERR_CONTROLUNAVAIL
;
260 if (freq
== DSBFREQUENCY_ORIGINAL
)
261 freq
= This
->pwfx
->nSamplesPerSec
;
263 if ((freq
< DSBFREQUENCY_MIN
) || (freq
> DSBFREQUENCY_MAX
)) {
264 WARN("invalid parameter: freq = %d\n", freq
);
265 return DSERR_INVALIDPARAM
;
268 AcquireSRWLockExclusive(&This
->lock
);
270 oldFreq
= This
->freq
;
272 if (freq
!= oldFreq
) {
273 This
->freqAdjustNum
= This
->freq
;
274 This
->freqAdjustDen
= This
->device
->pwfx
->nSamplesPerSec
;
275 This
->nAvgBytesPerSec
= freq
* This
->pwfx
->nBlockAlign
;
276 DSOUND_RecalcFormat(This
);
279 ReleaseSRWLockExclusive(&This
->lock
);
284 static HRESULT WINAPI
IDirectSoundBufferImpl_Play(IDirectSoundBuffer8
*iface
, DWORD reserved1
,
285 DWORD reserved2
, DWORD flags
)
287 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
288 HRESULT hres
= DS_OK
;
291 TRACE("(%p,%08x,%08x,%08x)\n",This
,reserved1
,reserved2
,flags
);
293 AcquireSRWLockExclusive(&This
->lock
);
295 This
->playflags
= flags
;
296 if (This
->state
== STATE_STOPPED
) {
298 This
->state
= STATE_STARTING
;
299 } else if (This
->state
== STATE_STOPPING
)
300 This
->state
= STATE_PLAYING
;
302 for (i
= 0; i
< This
->num_filters
; i
++) {
303 IMediaObject_Discontinuity(This
->filters
[i
].obj
, 0);
306 ReleaseSRWLockExclusive(&This
->lock
);
311 static HRESULT WINAPI
IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8
*iface
)
313 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
314 HRESULT hres
= DS_OK
;
316 TRACE("(%p)\n",This
);
318 AcquireSRWLockExclusive(&This
->lock
);
320 if (This
->state
== STATE_PLAYING
)
321 This
->state
= STATE_STOPPING
;
322 else if (This
->state
== STATE_STARTING
)
324 This
->state
= STATE_STOPPED
;
325 DSOUND_CheckEvent(This
, 0, 0);
328 ReleaseSRWLockExclusive(&This
->lock
);
333 static ULONG WINAPI
IDirectSoundBufferImpl_AddRef(IDirectSoundBuffer8
*iface
)
335 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
336 ULONG ref
= InterlockedIncrement(&This
->ref
);
338 TRACE("(%p) ref %d\n", This
, ref
);
341 InterlockedIncrement(&This
->numIfaces
);
346 static ULONG WINAPI
IDirectSoundBufferImpl_Release(IDirectSoundBuffer8
*iface
)
348 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
351 if (is_primary_buffer(This
)){
352 ref
= capped_refcount_dec(&This
->ref
);
354 capped_refcount_dec(&This
->numIfaces
);
355 TRACE("(%p) ref %d\n", This
, ref
);
359 ref
= InterlockedDecrement(&This
->ref
);
360 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
361 secondarybuffer_destroy(This
);
363 TRACE("(%p) ref %d\n", This
, ref
);
368 static HRESULT WINAPI
IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuffer8
*iface
,
369 DWORD
*playpos
, DWORD
*writepos
)
371 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
374 TRACE("(%p,%p,%p)\n",This
,playpos
,writepos
);
376 AcquireSRWLockShared(&This
->lock
);
378 pos
= This
->sec_mixpos
;
381 if (pos
>= This
->buflen
){
382 FIXME("Bad play position. playpos: %d, buflen: %d\n", pos
, This
->buflen
);
391 if (writepos
&& This
->state
!= STATE_STOPPED
) {
392 /* apply the documented 10ms lead to writepos */
393 *writepos
+= This
->writelead
;
394 *writepos
%= This
->buflen
;
397 ReleaseSRWLockShared(&This
->lock
);
399 TRACE("playpos = %d, writepos = %d, buflen=%d (%p, time=%d)\n",
400 playpos
?*playpos
:-1, writepos
?*writepos
:-1, This
->buflen
, This
, GetTickCount());
405 static HRESULT WINAPI
IDirectSoundBufferImpl_GetStatus(IDirectSoundBuffer8
*iface
, DWORD
*status
)
407 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
409 TRACE("(%p,%p)\n",This
,status
);
411 if (status
== NULL
) {
412 WARN("invalid parameter: status = NULL\n");
413 return DSERR_INVALIDPARAM
;
417 AcquireSRWLockShared(&This
->lock
);
418 if ((This
->state
== STATE_STARTING
) || (This
->state
== STATE_PLAYING
)) {
419 *status
|= DSBSTATUS_PLAYING
;
420 if (This
->playflags
& DSBPLAY_LOOPING
)
421 *status
|= DSBSTATUS_LOOPING
;
423 ReleaseSRWLockShared(&This
->lock
);
425 TRACE("status=%x\n", *status
);
430 static HRESULT WINAPI
IDirectSoundBufferImpl_GetFormat(IDirectSoundBuffer8
*iface
,
431 LPWAVEFORMATEX lpwf
, DWORD wfsize
, DWORD
*wfwritten
)
433 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
436 TRACE("(%p,%p,%d,%p)\n",This
,lpwf
,wfsize
,wfwritten
);
438 size
= sizeof(WAVEFORMATEX
) + This
->pwfx
->cbSize
;
440 if (lpwf
) { /* NULL is valid */
441 if (wfsize
>= size
) {
442 CopyMemory(lpwf
,This
->pwfx
,size
);
446 WARN("invalid parameter: wfsize too small\n");
447 CopyMemory(lpwf
,This
->pwfx
,wfsize
);
450 return DSERR_INVALIDPARAM
;
454 *wfwritten
= sizeof(WAVEFORMATEX
) + This
->pwfx
->cbSize
;
456 WARN("invalid parameter: wfwritten == NULL\n");
457 return DSERR_INVALIDPARAM
;
464 static HRESULT WINAPI
IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8
*iface
, DWORD writecursor
,
465 DWORD writebytes
, void **lplpaudioptr1
, DWORD
*audiobytes1
, void **lplpaudioptr2
,
466 DWORD
*audiobytes2
, DWORD flags
)
468 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
469 HRESULT hres
= DS_OK
;
471 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n", This
, writecursor
, writebytes
, lplpaudioptr1
,
472 audiobytes1
, lplpaudioptr2
, audiobytes2
, flags
, GetTickCount());
475 return DSERR_INVALIDPARAM
;
477 /* when this flag is set, writecursor is meaningless and must be calculated */
478 if (flags
& DSBLOCK_FROMWRITECURSOR
) {
479 /* GetCurrentPosition does too much magic to duplicate here */
480 hres
= IDirectSoundBufferImpl_GetCurrentPosition(iface
, NULL
, &writecursor
);
482 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
487 /* when this flag is set, writebytes is meaningless and must be set */
488 if (flags
& DSBLOCK_ENTIREBUFFER
)
489 writebytes
= This
->buflen
;
491 if (writecursor
>= This
->buflen
) {
492 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
493 writecursor
, This
->buflen
);
494 return DSERR_INVALIDPARAM
;
497 if (writebytes
> This
->buflen
) {
498 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
499 writebytes
, This
->buflen
);
500 return DSERR_INVALIDPARAM
;
503 AcquireSRWLockShared(&This
->lock
);
505 if (writecursor
+writebytes
<= This
->buflen
) {
506 *(LPBYTE
*)lplpaudioptr1
= This
->buffer
->memory
+writecursor
;
507 if (This
->sec_mixpos
>= writecursor
&& This
->sec_mixpos
< writecursor
+ writebytes
&& This
->state
== STATE_PLAYING
)
508 WARN("Overwriting mixing position, case 1\n");
509 *audiobytes1
= writebytes
;
511 *(LPBYTE
*)lplpaudioptr2
= NULL
;
514 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n",
515 *(LPBYTE
*)lplpaudioptr1
, *audiobytes1
, lplpaudioptr2
? *(LPBYTE
*)lplpaudioptr2
: NULL
, audiobytes2
? *audiobytes2
: 0, writecursor
);
516 TRACE("->%d.0\n",writebytes
);
517 This
->buffer
->lockedbytes
+= writebytes
;
519 DWORD remainder
= writebytes
+ writecursor
- This
->buflen
;
520 *(LPBYTE
*)lplpaudioptr1
= This
->buffer
->memory
+writecursor
;
521 *audiobytes1
= This
->buflen
-writecursor
;
522 This
->buffer
->lockedbytes
+= *audiobytes1
;
523 if (This
->sec_mixpos
>= writecursor
&& This
->sec_mixpos
< writecursor
+ writebytes
&& This
->state
== STATE_PLAYING
)
524 WARN("Overwriting mixing position, case 2\n");
526 *(LPBYTE
*)lplpaudioptr2
= This
->buffer
->memory
;
528 *audiobytes2
= writebytes
-(This
->buflen
-writecursor
);
529 This
->buffer
->lockedbytes
+= *audiobytes2
;
531 if (audiobytes2
&& This
->sec_mixpos
< remainder
&& This
->state
== STATE_PLAYING
)
532 WARN("Overwriting mixing position, case 3\n");
533 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE
*)lplpaudioptr1
, *audiobytes1
, lplpaudioptr2
? *(LPBYTE
*)lplpaudioptr2
: NULL
, audiobytes2
? *audiobytes2
: 0, writecursor
);
536 ReleaseSRWLockShared(&This
->lock
);
541 static HRESULT WINAPI
IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuffer8
*iface
,
544 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
545 HRESULT hres
= DS_OK
;
547 TRACE("(%p,%d)\n",This
,newpos
);
549 AcquireSRWLockExclusive(&This
->lock
);
551 /* start mixing from this new location instead */
552 newpos
%= This
->buflen
;
553 newpos
-= newpos
%This
->pwfx
->nBlockAlign
;
554 This
->sec_mixpos
= newpos
;
556 /* at this point, do not attempt to reset buffers, mess with primary mix position,
557 or anything like that to reduce latency. The data already prebuffered cannot be changed */
559 ReleaseSRWLockExclusive(&This
->lock
);
564 static HRESULT WINAPI
IDirectSoundBufferImpl_SetPan(IDirectSoundBuffer8
*iface
, LONG pan
)
566 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
567 HRESULT hres
= DS_OK
;
569 TRACE("(%p,%d)\n",This
,pan
);
571 if ((pan
> DSBPAN_RIGHT
) || (pan
< DSBPAN_LEFT
)) {
572 WARN("invalid parameter: pan = %d\n", pan
);
573 return DSERR_INVALIDPARAM
;
576 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
577 WARN("control unavailable\n");
578 return DSERR_CONTROLUNAVAIL
;
581 AcquireSRWLockExclusive(&This
->lock
);
583 if (This
->volpan
.lPan
!= pan
) {
584 This
->volpan
.lPan
= pan
;
585 DSOUND_RecalcVolPan(&(This
->volpan
));
588 ReleaseSRWLockExclusive(&This
->lock
);
593 static HRESULT WINAPI
IDirectSoundBufferImpl_GetPan(IDirectSoundBuffer8
*iface
, LONG
*pan
)
595 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
597 TRACE("(%p,%p)\n",This
,pan
);
599 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
600 WARN("control unavailable\n");
601 return DSERR_CONTROLUNAVAIL
;
605 WARN("invalid parameter: pan = NULL\n");
606 return DSERR_INVALIDPARAM
;
609 *pan
= This
->volpan
.lPan
;
614 static HRESULT WINAPI
IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8
*iface
, void *p1
, DWORD x1
,
617 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
), *iter
;
618 HRESULT hres
= DS_OK
;
620 TRACE("(%p,%p,%d,%p,%d)\n", This
,p1
,x1
,p2
,x2
);
625 if((p1
&& ((BYTE
*)p1
< This
->buffer
->memory
|| (BYTE
*)p1
>= This
->buffer
->memory
+ This
->buflen
)) ||
626 (p2
&& ((BYTE
*)p2
< This
->buffer
->memory
|| (BYTE
*)p2
>= This
->buffer
->memory
+ This
->buflen
)))
627 return DSERR_INVALIDPARAM
;
631 AcquireSRWLockShared(&This
->device
->buffer_list_lock
);
632 LIST_FOR_EACH_ENTRY(iter
, &This
->buffer
->buffers
, IDirectSoundBufferImpl
, entry
)
634 AcquireSRWLockShared(&iter
->lock
);
637 if(x1
+ (DWORD_PTR
)p1
- (DWORD_PTR
)iter
->buffer
->memory
> iter
->buflen
)
638 hres
= DSERR_INVALIDPARAM
;
640 iter
->buffer
->lockedbytes
-= x1
;
645 if(x2
+ (DWORD_PTR
)p2
- (DWORD_PTR
)iter
->buffer
->memory
> iter
->buflen
)
646 hres
= DSERR_INVALIDPARAM
;
648 iter
->buffer
->lockedbytes
-= x2
;
650 ReleaseSRWLockShared(&iter
->lock
);
652 ReleaseSRWLockShared(&This
->device
->buffer_list_lock
);
658 static HRESULT WINAPI
IDirectSoundBufferImpl_Restore(IDirectSoundBuffer8
*iface
)
660 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
662 FIXME("(%p):stub\n",This
);
666 static HRESULT WINAPI
IDirectSoundBufferImpl_GetFrequency(IDirectSoundBuffer8
*iface
, DWORD
*freq
)
668 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
670 TRACE("(%p,%p)\n",This
,freq
);
673 WARN("invalid parameter: freq = NULL\n");
674 return DSERR_INVALIDPARAM
;
678 TRACE("-> %d\n", *freq
);
683 static const char* dump_DSFX_guid(const DSEFFECTDESC
*desc
)
685 #define FE(guid) if (IsEqualGUID(&guid, &desc->guidDSFXClass)) return #guid
686 FE(GUID_DSFX_STANDARD_GARGLE
);
687 FE(GUID_DSFX_STANDARD_CHORUS
);
688 FE(GUID_DSFX_STANDARD_FLANGER
);
689 FE(GUID_DSFX_STANDARD_ECHO
);
690 FE(GUID_DSFX_STANDARD_DISTORTION
);
691 FE(GUID_DSFX_STANDARD_COMPRESSOR
);
692 FE(GUID_DSFX_STANDARD_PARAMEQ
);
693 FE(GUID_DSFX_STANDARD_I3DL2REVERB
);
694 FE(GUID_DSFX_WAVES_REVERB
);
697 return debugstr_guid(&desc
->guidDSFXClass
);
700 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFX(IDirectSoundBuffer8
*iface
, DWORD dwEffectsCount
,
701 LPDSEFFECTDESC pDSFXDesc
, DWORD
*pdwResultCodes
)
703 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
710 TRACE("(%p,%u,%p,%p)\n", This
, dwEffectsCount
, pDSFXDesc
, pdwResultCodes
);
713 for (u
=0; u
<dwEffectsCount
; u
++) pdwResultCodes
[u
] = DSFXR_UNKNOWN
;
715 if ((dwEffectsCount
> 0 && !pDSFXDesc
) ||
716 (dwEffectsCount
== 0 && (pDSFXDesc
|| pdwResultCodes
))
720 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFX
)) {
721 WARN("attempted to call SetFX on buffer without DSBCAPS_CTRLFX\n");
722 return DSERR_CONTROLUNAVAIL
;
725 if (This
->state
!= STATE_STOPPED
)
726 return DSERR_INVALIDCALL
;
728 if (This
->buffer
->lockedbytes
> 0)
729 return DSERR_INVALIDCALL
;
731 if (dwEffectsCount
== 0) {
732 if (This
->num_filters
> 0) {
733 for (u
= 0; u
< This
->num_filters
; u
++) {
734 IMediaObject_Release(This
->filters
[u
].obj
);
736 HeapFree(GetProcessHeap(), 0, This
->filters
);
738 This
->filters
= NULL
;
739 This
->num_filters
= 0;
745 filters
= HeapAlloc(GetProcessHeap(), 0, dwEffectsCount
* sizeof(DSFilter
));
747 WARN("out of memory\n");
748 return DSERR_OUTOFMEMORY
;
753 wfx
.wFormatTag
= WAVE_FORMAT_IEEE_FLOAT
;
754 wfx
.nChannels
= This
->pwfx
->nChannels
;
755 wfx
.nSamplesPerSec
= This
->pwfx
->nSamplesPerSec
;
756 wfx
.wBitsPerSample
= sizeof(float) * 8;
757 wfx
.nBlockAlign
= (wfx
.nChannels
* wfx
.wBitsPerSample
)/8;
758 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
759 wfx
.cbSize
= sizeof(wfx
);
761 dmt
.majortype
= KSDATAFORMAT_TYPE_AUDIO
;
762 dmt
.subtype
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
763 dmt
.bFixedSizeSamples
= TRUE
;
764 dmt
.bTemporalCompression
= FALSE
;
765 dmt
.lSampleSize
= sizeof(float) * This
->pwfx
->nChannels
/ 8;
766 dmt
.formattype
= FORMAT_WaveFormatEx
;
768 dmt
.cbFormat
= sizeof(WAVEFORMATEX
);
769 dmt
.pbFormat
= (BYTE
*)&wfx
;
771 for (u
= 0; u
< dwEffectsCount
; u
++) {
772 TRACE("%d: 0x%08x, %s\n", u
, pDSFXDesc
[u
].dwFlags
, dump_DSFX_guid(&pDSFXDesc
[u
]));
774 hr2
= CoCreateInstance(&pDSFXDesc
[u
].guidDSFXClass
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMediaObject
, (LPVOID
*)&filters
[u
].obj
);
776 if (SUCCEEDED(hr2
)) {
777 hr2
= IMediaObject_SetInputType(filters
[u
].obj
, 0, &dmt
, 0);
779 WARN("Could not set DMO input type\n");
782 if (SUCCEEDED(hr2
)) {
783 hr2
= IMediaObject_SetOutputType(filters
[u
].obj
, 0, &dmt
, 0);
785 WARN("Could not set DMO output type\n");
793 pdwResultCodes
[u
] = (hr2
== REGDB_E_CLASSNOTREG
) ? DSFXR_UNKNOWN
: DSFXR_FAILED
;
796 pdwResultCodes
[u
] = DSFXR_LOCSOFTWARE
;
801 for (u
= 0; u
< dwEffectsCount
; u
++) {
803 pdwResultCodes
[u
] = (pdwResultCodes
[u
] != DSFXR_UNKNOWN
) ? DSFXR_PRESENT
: DSFXR_UNKNOWN
;
806 IMediaObject_Release(filters
[u
].obj
);
809 HeapFree(GetProcessHeap(), 0, filters
);
811 if (This
->num_filters
> 0) {
812 for (u
= 0; u
< This
->num_filters
; u
++) {
813 IMediaObject_Release(This
->filters
[u
].obj
);
814 if (This
->filters
[u
].inplace
) IMediaObjectInPlace_Release(This
->filters
[u
].inplace
);
816 HeapFree(GetProcessHeap(), 0, This
->filters
);
819 for (u
= 0; u
< dwEffectsCount
; u
++) {
820 memcpy(&filters
[u
].guid
, &pDSFXDesc
[u
].guidDSFXClass
, sizeof(GUID
));
821 if (FAILED(IMediaObject_QueryInterface(filters
[u
].obj
, &IID_IMediaObjectInPlace
, (void*)&filters
[u
].inplace
)))
822 filters
[u
].inplace
= NULL
;
825 This
->filters
= filters
;
826 This
->num_filters
= dwEffectsCount
;
832 static HRESULT WINAPI
IDirectSoundBufferImpl_AcquireResources(IDirectSoundBuffer8
*iface
,
833 DWORD dwFlags
, DWORD dwEffectsCount
, DWORD
*pdwResultCodes
)
835 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
838 FIXME("(%p,%08u,%u,%p): stub, faking success\n",This
,dwFlags
,dwEffectsCount
,pdwResultCodes
);
841 for (u
=0; u
<dwEffectsCount
; u
++) pdwResultCodes
[u
] = DSFXR_UNKNOWN
;
843 WARN("control unavailable\n");
847 static HRESULT WINAPI
IDirectSoundBufferImpl_GetObjectInPath(IDirectSoundBuffer8
*iface
,
848 REFGUID clsid
, DWORD index
, REFGUID iid
, void **out
)
850 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
853 TRACE("(%p,%s,%u,%s,%p)\n", This
, debugstr_guid(clsid
), index
, debugstr_guid(iid
), out
);
858 for (i
= 0; i
< This
->num_filters
; i
++)
860 if (IsEqualGUID(clsid
, &This
->filters
[i
].guid
) || IsEqualGUID(clsid
, &GUID_All_Objects
))
862 if (count
++ == index
)
863 return IMediaObject_QueryInterface(This
->filters
[i
].obj
, iid
, out
);
866 return DSERR_OBJECTNOTFOUND
;
869 static HRESULT WINAPI
IDirectSoundBufferImpl_Initialize(IDirectSoundBuffer8
*iface
,
870 IDirectSound
*dsound
, LPCDSBUFFERDESC dbsd
)
872 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
874 WARN("(%p) already initialized\n", This
);
875 return DSERR_ALREADYINITIALIZED
;
878 static HRESULT WINAPI
IDirectSoundBufferImpl_GetCaps(IDirectSoundBuffer8
*iface
, LPDSBCAPS caps
)
880 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
882 TRACE("(%p)->(%p)\n",This
,caps
);
885 WARN("invalid parameter: caps == NULL\n");
886 return DSERR_INVALIDPARAM
;
889 if (caps
->dwSize
< sizeof(*caps
)) {
890 WARN("invalid parameter: caps->dwSize = %d\n",caps
->dwSize
);
891 return DSERR_INVALIDPARAM
;
894 caps
->dwFlags
= This
->dsbd
.dwFlags
;
895 caps
->dwFlags
|= DSBCAPS_LOCSOFTWARE
;
897 caps
->dwBufferBytes
= This
->buflen
;
899 /* According to windows, this is zero*/
900 caps
->dwUnlockTransferRate
= 0;
901 caps
->dwPlayCpuOverhead
= 0;
906 static HRESULT WINAPI
IDirectSoundBufferImpl_QueryInterface(IDirectSoundBuffer8
*iface
, REFIID riid
,
909 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
911 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
914 WARN("invalid parameter\n");
918 *ppobj
= NULL
; /* assume failure */
920 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
921 IsEqualGUID(riid
, &IID_IDirectSoundBuffer
) ||
922 IsEqualGUID(riid
, &IID_IDirectSoundBuffer8
) ) {
923 IDirectSoundBuffer8_AddRef(iface
);
928 if ( IsEqualGUID( &IID_IDirectSoundNotify
, riid
) ) {
929 if(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPOSITIONNOTIFY
) {
930 IDirectSoundNotify_AddRef(&This
->IDirectSoundNotify_iface
);
931 *ppobj
= &This
->IDirectSoundNotify_iface
;
935 TRACE( "App requested IDirectSoundNotify without DSBCAPS_CTRLPOSITIONNOTIFY flag.\n");
936 return E_NOINTERFACE
;
939 if ( IsEqualGUID( &IID_IDirectSound3DBuffer
, riid
) ) {
940 if(This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
){
941 IDirectSound3DBuffer_AddRef(&This
->IDirectSound3DBuffer_iface
);
942 *ppobj
= &This
->IDirectSound3DBuffer_iface
;
945 TRACE("app requested IDirectSound3DBuffer on non-3D secondary buffer\n");
946 return E_NOINTERFACE
;
949 if ( IsEqualGUID( &IID_IDirectSound3DListener
, riid
) ) {
950 ERR("app requested IDirectSound3DListener on secondary buffer\n");
951 return E_NOINTERFACE
;
954 if ( IsEqualGUID( &IID_IKsPropertySet
, riid
) ) {
955 IKsPropertySet_AddRef(&This
->IKsPropertySet_iface
);
956 *ppobj
= &This
->IKsPropertySet_iface
;
960 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
962 return E_NOINTERFACE
;
965 static const IDirectSoundBuffer8Vtbl dsbvt
=
967 IDirectSoundBufferImpl_QueryInterface
,
968 IDirectSoundBufferImpl_AddRef
,
969 IDirectSoundBufferImpl_Release
,
970 IDirectSoundBufferImpl_GetCaps
,
971 IDirectSoundBufferImpl_GetCurrentPosition
,
972 IDirectSoundBufferImpl_GetFormat
,
973 IDirectSoundBufferImpl_GetVolume
,
974 IDirectSoundBufferImpl_GetPan
,
975 IDirectSoundBufferImpl_GetFrequency
,
976 IDirectSoundBufferImpl_GetStatus
,
977 IDirectSoundBufferImpl_Initialize
,
978 IDirectSoundBufferImpl_Lock
,
979 IDirectSoundBufferImpl_Play
,
980 IDirectSoundBufferImpl_SetCurrentPosition
,
981 IDirectSoundBufferImpl_SetFormat
,
982 IDirectSoundBufferImpl_SetVolume
,
983 IDirectSoundBufferImpl_SetPan
,
984 IDirectSoundBufferImpl_SetFrequency
,
985 IDirectSoundBufferImpl_Stop
,
986 IDirectSoundBufferImpl_Unlock
,
987 IDirectSoundBufferImpl_Restore
,
988 IDirectSoundBufferImpl_SetFX
,
989 IDirectSoundBufferImpl_AcquireResources
,
990 IDirectSoundBufferImpl_GetObjectInPath
993 HRESULT
secondarybuffer_create(DirectSoundDevice
*device
, const DSBUFFERDESC
*dsbd
,
994 IDirectSoundBuffer
**buffer
)
996 IDirectSoundBufferImpl
*dsb
;
997 LPWAVEFORMATEX wfex
= dsbd
->lpwfxFormat
;
1002 TRACE("(%p,%p,%p)\n", device
, dsbd
, buffer
);
1004 if (dsbd
->dwBufferBytes
< DSBSIZE_MIN
|| dsbd
->dwBufferBytes
> DSBSIZE_MAX
) {
1005 WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd
->dwBufferBytes
);
1006 return DSERR_INVALIDPARAM
; /* FIXME: which error? */
1009 dsb
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(*dsb
));
1012 return DSERR_OUTOFMEMORY
;
1014 TRACE("Created buffer at %p\n", dsb
);
1021 dsb
->device
= device
;
1022 dsb
->IDirectSoundBuffer8_iface
.lpVtbl
= &dsbvt
;
1023 dsb
->IDirectSoundNotify_iface
.lpVtbl
= &dsnvt
;
1024 dsb
->IDirectSound3DBuffer_iface
.lpVtbl
= &ds3dbvt
;
1025 dsb
->IKsPropertySet_iface
.lpVtbl
= &iksbvt
;
1027 /* size depends on version */
1028 CopyMemory(&dsb
->dsbd
, dsbd
, dsbd
->dwSize
);
1030 dsb
->pwfx
= DSOUND_CopyFormat(wfex
);
1032 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1033 return DSERR_OUTOFMEMORY
;
1036 if (dsbd
->dwBufferBytes
% dsbd
->lpwfxFormat
->nBlockAlign
)
1037 dsb
->buflen
= dsbd
->dwBufferBytes
+
1038 (dsbd
->lpwfxFormat
->nBlockAlign
-
1039 (dsbd
->dwBufferBytes
% dsbd
->lpwfxFormat
->nBlockAlign
));
1041 dsb
->buflen
= dsbd
->dwBufferBytes
;
1043 dsb
->freq
= dsbd
->lpwfxFormat
->nSamplesPerSec
;
1044 dsb
->notifies
= NULL
;
1045 dsb
->nrofnotifies
= 0;
1047 /* Check necessary hardware mixing capabilities */
1048 if (wfex
->nChannels
==2) capf
|= DSCAPS_SECONDARYSTEREO
;
1049 else capf
|= DSCAPS_SECONDARYMONO
;
1050 if (wfex
->wBitsPerSample
==16) capf
|= DSCAPS_SECONDARY16BIT
;
1051 else capf
|= DSCAPS_SECONDARY8BIT
;
1053 TRACE("capf = 0x%08x, device->drvcaps.dwFlags = 0x%08x\n", capf
, device
->drvcaps
.dwFlags
);
1055 /* Allocate an empty buffer */
1056 bufsize
= (sizeof(*(dsb
->buffer
)) + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
1057 dsb
->buffer
= HeapAlloc(GetProcessHeap(),0,bufsize
+ dsb
->buflen
);
1059 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1060 return DSERR_OUTOFMEMORY
;
1063 /* Allocate system memory for buffer */
1064 dsb
->buffer
->memory
= (BYTE
*)dsb
->buffer
+ bufsize
;
1066 dsb
->buffer
->ref
= 1;
1067 dsb
->buffer
->lockedbytes
= 0;
1068 list_init(&dsb
->buffer
->buffers
);
1069 list_add_head(&dsb
->buffer
->buffers
, &dsb
->entry
);
1070 FillMemory(dsb
->buffer
->memory
, dsb
->buflen
, dsbd
->lpwfxFormat
->wBitsPerSample
== 8 ? 128 : 0);
1072 /* It's not necessary to initialize values to zero since */
1073 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1074 dsb
->sec_mixpos
= 0;
1075 dsb
->state
= STATE_STOPPED
;
1077 dsb
->freqAdjustNum
= dsb
->freq
;
1078 dsb
->freqAdjustDen
= device
->pwfx
->nSamplesPerSec
;
1079 dsb
->nAvgBytesPerSec
= dsb
->freq
*
1080 dsbd
->lpwfxFormat
->nBlockAlign
;
1082 /* calculate fragment size and write lead */
1083 DSOUND_RecalcFormat(dsb
);
1085 if (dsb
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
1086 dsb
->ds3db_ds3db
.dwSize
= sizeof(DS3DBUFFER
);
1087 dsb
->ds3db_ds3db
.vPosition
.x
= 0.0;
1088 dsb
->ds3db_ds3db
.vPosition
.y
= 0.0;
1089 dsb
->ds3db_ds3db
.vPosition
.z
= 0.0;
1090 dsb
->ds3db_ds3db
.vVelocity
.x
= 0.0;
1091 dsb
->ds3db_ds3db
.vVelocity
.y
= 0.0;
1092 dsb
->ds3db_ds3db
.vVelocity
.z
= 0.0;
1093 dsb
->ds3db_ds3db
.dwInsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1094 dsb
->ds3db_ds3db
.dwOutsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1095 dsb
->ds3db_ds3db
.vConeOrientation
.x
= 0.0;
1096 dsb
->ds3db_ds3db
.vConeOrientation
.y
= 0.0;
1097 dsb
->ds3db_ds3db
.vConeOrientation
.z
= 0.0;
1098 dsb
->ds3db_ds3db
.lConeOutsideVolume
= DS3D_DEFAULTCONEOUTSIDEVOLUME
;
1099 dsb
->ds3db_ds3db
.flMinDistance
= DS3D_DEFAULTMINDISTANCE
;
1100 dsb
->ds3db_ds3db
.flMaxDistance
= DS3D_DEFAULTMAXDISTANCE
;
1101 dsb
->ds3db_ds3db
.dwMode
= DS3DMODE_NORMAL
;
1103 dsb
->ds3db_need_recalc
= FALSE
;
1104 DSOUND_Calc3DBuffer(dsb
);
1106 DSOUND_RecalcVolPan(&(dsb
->volpan
));
1108 InitializeSRWLock(&dsb
->lock
);
1110 /* register buffer */
1111 err
= DirectSoundDevice_AddBuffer(device
, dsb
);
1113 *buffer
= (IDirectSoundBuffer
*)&dsb
->IDirectSoundBuffer8_iface
;
1115 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1120 void secondarybuffer_destroy(IDirectSoundBufferImpl
*This
)
1122 ULONG ref
= InterlockedIncrement(&This
->numIfaces
);
1125 WARN("Destroying buffer with %u in use interfaces\n", ref
- 1);
1127 if (This
->dsbd
.dwFlags
& DSBCAPS_LOCHARDWARE
)
1128 This
->device
->drvcaps
.dwFreeHwMixingAllBuffers
++;
1130 DirectSoundDevice_RemoveBuffer(This
->device
, This
);
1132 This
->buffer
->ref
--;
1133 list_remove(&This
->entry
);
1134 if (This
->buffer
->ref
== 0)
1135 HeapFree(GetProcessHeap(), 0, This
->buffer
);
1137 HeapFree(GetProcessHeap(), 0, This
->notifies
);
1138 HeapFree(GetProcessHeap(), 0, This
->pwfx
);
1140 if (This
->filters
) {
1142 for (i
= 0; i
< This
->num_filters
; i
++) {
1143 IMediaObject_Release(This
->filters
[i
].obj
);
1144 if (This
->filters
[i
].inplace
) IMediaObjectInPlace_Release(This
->filters
[i
].inplace
);
1146 HeapFree(GetProcessHeap(), 0, This
->filters
);
1149 HeapFree(GetProcessHeap(), 0, This
);
1151 TRACE("(%p) released\n", This
);
1154 HRESULT
IDirectSoundBufferImpl_Duplicate(
1155 DirectSoundDevice
*device
,
1156 IDirectSoundBufferImpl
**ppdsb
,
1157 IDirectSoundBufferImpl
*pdsb
)
1159 IDirectSoundBufferImpl
*dsb
;
1160 HRESULT hres
= DS_OK
;
1161 TRACE("(%p,%p,%p)\n", device
, ppdsb
, pdsb
);
1163 dsb
= HeapAlloc(GetProcessHeap(),0,sizeof(*dsb
));
1165 WARN("out of memory\n");
1167 return DSERR_OUTOFMEMORY
;
1170 AcquireSRWLockShared(&pdsb
->lock
);
1172 CopyMemory(dsb
, pdsb
, sizeof(*dsb
));
1174 dsb
->pwfx
= DSOUND_CopyFormat(pdsb
->pwfx
);
1176 ReleaseSRWLockShared(&pdsb
->lock
);
1178 if (dsb
->pwfx
== NULL
) {
1179 HeapFree(GetProcessHeap(),0,dsb
);
1181 return DSERR_OUTOFMEMORY
;
1185 list_add_head(&dsb
->buffer
->buffers
, &dsb
->entry
);
1191 dsb
->state
= STATE_STOPPED
;
1192 dsb
->sec_mixpos
= 0;
1193 dsb
->notifies
= NULL
;
1194 dsb
->nrofnotifies
= 0;
1195 dsb
->device
= device
;
1196 DSOUND_RecalcFormat(dsb
);
1198 InitializeSRWLock(&dsb
->lock
);
1200 /* register buffer */
1201 hres
= DirectSoundDevice_AddBuffer(device
, dsb
);
1202 if (hres
!= DS_OK
) {
1203 list_remove(&dsb
->entry
);
1205 HeapFree(GetProcessHeap(),0,dsb
->pwfx
);
1206 HeapFree(GetProcessHeap(),0,dsb
);
1209 IDirectSoundBuffer8_AddRef(&dsb
->IDirectSoundBuffer8_iface
);
1215 /*******************************************************************************
1219 static inline IDirectSoundBufferImpl
*impl_from_IKsPropertySet(IKsPropertySet
*iface
)
1221 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IKsPropertySet_iface
);
1224 /* IUnknown methods */
1225 static HRESULT WINAPI
IKsPropertySetImpl_QueryInterface(IKsPropertySet
*iface
, REFIID riid
,
1228 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1230 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
1232 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
1235 static ULONG WINAPI
IKsPropertySetImpl_AddRef(IKsPropertySet
*iface
)
1237 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1238 ULONG ref
= InterlockedIncrement(&This
->refiks
);
1240 TRACE("(%p) ref %d\n", This
, ref
);
1243 InterlockedIncrement(&This
->numIfaces
);
1248 static ULONG WINAPI
IKsPropertySetImpl_Release(IKsPropertySet
*iface
)
1250 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1253 if (is_primary_buffer(This
)){
1254 ref
= capped_refcount_dec(&This
->refiks
);
1256 capped_refcount_dec(&This
->numIfaces
);
1257 TRACE("(%p) ref %d\n", This
, ref
);
1261 ref
= InterlockedDecrement(&This
->refiks
);
1262 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
1263 secondarybuffer_destroy(This
);
1265 TRACE("(%p) ref %d\n", This
, ref
);
1270 static HRESULT WINAPI
IKsPropertySetImpl_Get(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1271 ULONG dwPropID
, void *pInstanceData
, ULONG cbInstanceData
, void *pPropData
,
1272 ULONG cbPropData
, ULONG
*pcbReturned
)
1274 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1276 TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
1277 This
,debugstr_guid(guidPropSet
),dwPropID
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
,pcbReturned
);
1279 return E_PROP_ID_UNSUPPORTED
;
1282 static HRESULT WINAPI
IKsPropertySetImpl_Set(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1283 ULONG dwPropID
, void *pInstanceData
, ULONG cbInstanceData
, void *pPropData
,
1286 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1288 TRACE("(%p,%s,%d,%p,%d,%p,%d)\n",This
,debugstr_guid(guidPropSet
),dwPropID
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
);
1290 return E_PROP_ID_UNSUPPORTED
;
1293 static HRESULT WINAPI
IKsPropertySetImpl_QuerySupport(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1294 ULONG dwPropID
, ULONG
*pTypeSupport
)
1296 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1298 TRACE("(%p,%s,%d,%p)\n",This
,debugstr_guid(guidPropSet
),dwPropID
,pTypeSupport
);
1300 return E_PROP_ID_UNSUPPORTED
;
1303 const IKsPropertySetVtbl iksbvt
= {
1304 IKsPropertySetImpl_QueryInterface
,
1305 IKsPropertySetImpl_AddRef
,
1306 IKsPropertySetImpl_Release
,
1307 IKsPropertySetImpl_Get
,
1308 IKsPropertySetImpl_Set
,
1309 IKsPropertySetImpl_QuerySupport