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 %ld\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 %ld\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 void commit_next_chunk(IDirectSoundBufferImpl
*dsb
)
106 void *dstbuff
= dsb
->committedbuff
, *srcbuff
= dsb
->buffer
->memory
;
107 DWORD srcoff
= dsb
->sec_mixpos
, srcsize
= dsb
->buflen
, cpysize
= dsb
->writelead
;
109 if(dsb
->state
!= STATE_PLAYING
)
112 if(cpysize
> srcsize
- srcoff
) {
113 DWORD overflow
= cpysize
- (srcsize
- srcoff
);
114 memcpy(dstbuff
, (BYTE
*)srcbuff
+ srcoff
, srcsize
- srcoff
);
115 memcpy((BYTE
*)dstbuff
+ (srcsize
- srcoff
), srcbuff
, overflow
);
117 memcpy(dstbuff
, (BYTE
*)srcbuff
+ srcoff
, cpysize
);
120 dsb
->use_committed
= TRUE
;
121 dsb
->committed_mixpos
= 0;
122 TRACE("committing %lu bytes from offset %lu\n", dsb
->writelead
, dsb
->sec_mixpos
);
125 static HRESULT WINAPI
IDirectSoundNotifyImpl_SetNotificationPositions(IDirectSoundNotify
*iface
,
126 DWORD howmuch
, const DSBPOSITIONNOTIFY
*notify
)
128 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundNotify(iface
);
130 TRACE("(%p,0x%08lx,%p)\n",This
,howmuch
,notify
);
132 if (howmuch
> 0 && notify
== NULL
) {
133 WARN("invalid parameter: notify == NULL\n");
134 return DSERR_INVALIDPARAM
;
137 if (TRACE_ON(dsound
)) {
139 for (i
=0;i
<howmuch
;i
++)
140 TRACE("notify at %ld to %p\n",
141 notify
[i
].dwOffset
,notify
[i
].hEventNotify
);
145 /* Make an internal copy of the caller-supplied array.
146 * Replace the existing copy if one is already present. */
147 free(This
->notifies
);
148 This
->notifies
= malloc(howmuch
* sizeof(DSBPOSITIONNOTIFY
));
150 if (This
->notifies
== NULL
) {
151 WARN("out of memory\n");
152 return DSERR_OUTOFMEMORY
;
154 CopyMemory(This
->notifies
, notify
, howmuch
* sizeof(DSBPOSITIONNOTIFY
));
155 This
->nrofnotifies
= howmuch
;
156 qsort(This
->notifies
, howmuch
, sizeof(DSBPOSITIONNOTIFY
), notify_compar
);
158 free(This
->notifies
);
159 This
->notifies
= NULL
;
160 This
->nrofnotifies
= 0;
166 static const IDirectSoundNotifyVtbl dsnvt
=
168 IDirectSoundNotifyImpl_QueryInterface
,
169 IDirectSoundNotifyImpl_AddRef
,
170 IDirectSoundNotifyImpl_Release
,
171 IDirectSoundNotifyImpl_SetNotificationPositions
,
174 /*******************************************************************************
178 static inline IDirectSoundBufferImpl
*impl_from_IDirectSoundBuffer8(IDirectSoundBuffer8
*iface
)
180 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IDirectSoundBuffer8_iface
);
183 static inline BOOL
is_primary_buffer(IDirectSoundBufferImpl
*This
)
185 return (This
->dsbd
.dwFlags
& DSBCAPS_PRIMARYBUFFER
) != 0;
188 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFormat(IDirectSoundBuffer8
*iface
,
189 LPCWAVEFORMATEX wfex
)
191 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
193 TRACE("(%p,%p)\n", iface
, wfex
);
195 if (is_primary_buffer(This
))
196 return primarybuffer_SetFormat(This
->device
, wfex
);
198 WARN("not available for secondary buffers.\n");
199 return DSERR_INVALIDCALL
;
203 static HRESULT WINAPI
IDirectSoundBufferImpl_SetVolume(IDirectSoundBuffer8
*iface
, LONG vol
)
205 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
208 HRESULT hres
= DS_OK
;
210 TRACE("(%p,%ld)\n",This
,vol
);
212 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
213 WARN("control unavailable: This->dsbd.dwFlags = 0x%08lx\n", This
->dsbd
.dwFlags
);
214 return DSERR_CONTROLUNAVAIL
;
217 if ((vol
> DSBVOLUME_MAX
) || (vol
< DSBVOLUME_MIN
)) {
218 WARN("invalid parameter: vol = %ld\n", vol
);
219 return DSERR_INVALIDPARAM
;
222 AcquireSRWLockExclusive(&This
->lock
);
224 if (This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
225 oldVol
= This
->ds3db_lVolume
;
226 This
->ds3db_lVolume
= vol
;
228 /* recalc 3d volume, which in turn recalcs the pans */
229 DSOUND_Calc3DBuffer(This
);
231 oldVol
= This
->volpan
.lVolume
;
232 This
->volpan
.lVolume
= vol
;
234 DSOUND_RecalcVolPan(&(This
->volpan
));
237 ReleaseSRWLockExclusive(&This
->lock
);
242 static HRESULT WINAPI
IDirectSoundBufferImpl_GetVolume(IDirectSoundBuffer8
*iface
, LONG
*vol
)
244 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
246 TRACE("(%p,%p)\n",This
,vol
);
248 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLVOLUME
)) {
249 WARN("control unavailable\n");
250 return DSERR_CONTROLUNAVAIL
;
254 WARN("invalid parameter: vol == NULL\n");
255 return DSERR_INVALIDPARAM
;
258 *vol
= This
->volpan
.lVolume
;
263 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8
*iface
, DWORD freq
)
265 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
268 TRACE("(%p,%ld)\n",This
,freq
);
270 if (is_primary_buffer(This
)) {
271 WARN("not available for primary buffers.\n");
272 return DSERR_CONTROLUNAVAIL
;
275 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFREQUENCY
)) {
276 WARN("control unavailable\n");
277 return DSERR_CONTROLUNAVAIL
;
280 if (freq
== DSBFREQUENCY_ORIGINAL
)
281 freq
= This
->pwfx
->nSamplesPerSec
;
283 if ((freq
< DSBFREQUENCY_MIN
) || (freq
> DSBFREQUENCY_MAX
)) {
284 WARN("invalid parameter: freq = %ld\n", freq
);
285 return DSERR_INVALIDPARAM
;
288 AcquireSRWLockExclusive(&This
->lock
);
290 oldFreq
= This
->freq
;
293 DSOUND_RecalcFormat(This
);
295 ReleaseSRWLockExclusive(&This
->lock
);
300 static HRESULT WINAPI
IDirectSoundBufferImpl_Play(IDirectSoundBuffer8
*iface
, DWORD reserved1
,
301 DWORD reserved2
, DWORD flags
)
303 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
304 HRESULT hres
= DS_OK
;
307 TRACE("(%p,%08lx,%08lx,%08lx)\n",This
,reserved1
,reserved2
,flags
);
309 AcquireSRWLockExclusive(&This
->lock
);
311 This
->playflags
= flags
;
312 if (This
->state
== STATE_STOPPED
) {
314 This
->state
= STATE_STARTING
;
317 for (i
= 0; i
< This
->num_filters
; i
++) {
318 IMediaObject_Discontinuity(This
->filters
[i
].obj
, 0);
321 ReleaseSRWLockExclusive(&This
->lock
);
326 static HRESULT WINAPI
IDirectSoundBufferImpl_Stop(IDirectSoundBuffer8
*iface
)
328 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
329 HRESULT hres
= DS_OK
;
331 TRACE("(%p)\n",This
);
333 AcquireSRWLockExclusive(&This
->lock
);
335 if (This
->state
== STATE_PLAYING
|| This
->state
== STATE_STARTING
)
337 This
->state
= STATE_STOPPED
;
338 This
->use_committed
= FALSE
;
339 This
->committed_mixpos
= 0;
340 DSOUND_CheckEvent(This
, 0, 0);
343 ReleaseSRWLockExclusive(&This
->lock
);
348 static ULONG WINAPI
IDirectSoundBufferImpl_AddRef(IDirectSoundBuffer8
*iface
)
350 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
351 ULONG ref
= InterlockedIncrement(&This
->ref
);
353 TRACE("(%p) ref %ld\n", This
, ref
);
356 InterlockedIncrement(&This
->numIfaces
);
361 static ULONG WINAPI
IDirectSoundBufferImpl_Release(IDirectSoundBuffer8
*iface
)
363 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
366 if (is_primary_buffer(This
)){
367 ref
= capped_refcount_dec(&This
->ref
);
369 capped_refcount_dec(&This
->numIfaces
);
370 TRACE("(%p) ref %ld\n", This
, ref
);
374 ref
= InterlockedDecrement(&This
->ref
);
375 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
376 secondarybuffer_destroy(This
);
378 TRACE("(%p) ref %ld\n", This
, ref
);
383 static HRESULT WINAPI
IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuffer8
*iface
,
384 DWORD
*playpos
, DWORD
*writepos
)
386 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
389 TRACE("(%p,%p,%p)\n",This
,playpos
,writepos
);
391 AcquireSRWLockShared(&This
->lock
);
393 pos
= This
->sec_mixpos
;
396 if (pos
>= This
->buflen
){
397 FIXME("Bad play position. playpos: %ld, buflen: %ld\n", pos
, This
->buflen
);
406 if (writepos
&& This
->state
!= STATE_STOPPED
) {
407 /* apply the documented 10ms lead to writepos */
408 *writepos
+= This
->writelead
;
409 *writepos
%= This
->buflen
;
412 ReleaseSRWLockShared(&This
->lock
);
414 TRACE("playpos = %ld, writepos = %ld, buflen=%ld (%p, time=%ld)\n",
415 playpos
?*playpos
:-1, writepos
?*writepos
:-1, This
->buflen
, This
, GetTickCount());
420 static HRESULT WINAPI
IDirectSoundBufferImpl_GetStatus(IDirectSoundBuffer8
*iface
, DWORD
*status
)
422 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
424 TRACE("(%p,%p)\n",This
,status
);
426 if (status
== NULL
) {
427 WARN("invalid parameter: status = NULL\n");
428 return DSERR_INVALIDPARAM
;
432 AcquireSRWLockShared(&This
->lock
);
433 if ((This
->state
== STATE_STARTING
) || (This
->state
== STATE_PLAYING
)) {
434 *status
|= DSBSTATUS_PLAYING
;
435 if (This
->playflags
& DSBPLAY_LOOPING
)
436 *status
|= DSBSTATUS_LOOPING
;
438 if (This
->dsbd
.dwFlags
& DSBCAPS_LOCDEFER
)
439 *status
|= DSBSTATUS_LOCSOFTWARE
;
440 ReleaseSRWLockShared(&This
->lock
);
442 TRACE("status=%lx\n", *status
);
447 static HRESULT WINAPI
IDirectSoundBufferImpl_GetFormat(IDirectSoundBuffer8
*iface
,
448 LPWAVEFORMATEX lpwf
, DWORD wfsize
, DWORD
*wfwritten
)
450 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
453 TRACE("(%p,%p,%ld,%p)\n",This
,lpwf
,wfsize
,wfwritten
);
455 size
= sizeof(WAVEFORMATEX
) + This
->pwfx
->cbSize
;
457 if (lpwf
) { /* NULL is valid */
458 if (wfsize
>= size
) {
459 CopyMemory(lpwf
,This
->pwfx
,size
);
463 WARN("invalid parameter: wfsize too small\n");
464 CopyMemory(lpwf
,This
->pwfx
,wfsize
);
467 return DSERR_INVALIDPARAM
;
471 *wfwritten
= sizeof(WAVEFORMATEX
) + This
->pwfx
->cbSize
;
473 WARN("invalid parameter: wfwritten == NULL\n");
474 return DSERR_INVALIDPARAM
;
481 static HRESULT WINAPI
IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8
*iface
, DWORD writecursor
,
482 DWORD writebytes
, void **lplpaudioptr1
, DWORD
*audiobytes1
, void **lplpaudioptr2
,
483 DWORD
*audiobytes2
, DWORD flags
)
485 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
486 HRESULT hres
= DS_OK
;
488 TRACE("(%p,%ld,%ld,%p,%p,%p,%p,0x%08lx) at %ld\n", This
, writecursor
, writebytes
, lplpaudioptr1
,
489 audiobytes1
, lplpaudioptr2
, audiobytes2
, flags
, GetTickCount());
492 return DSERR_INVALIDPARAM
;
494 /* when this flag is set, writecursor is meaningless and must be calculated */
495 if (flags
& DSBLOCK_FROMWRITECURSOR
) {
496 /* GetCurrentPosition does too much magic to duplicate here */
497 hres
= IDirectSoundBufferImpl_GetCurrentPosition(iface
, NULL
, &writecursor
);
499 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
504 /* when this flag is set, writebytes is meaningless and must be set */
505 if (flags
& DSBLOCK_ENTIREBUFFER
)
506 writebytes
= This
->buflen
;
508 if (writecursor
>= This
->buflen
) {
509 WARN("Invalid parameter, writecursor: %lu >= buflen: %lu\n",
510 writecursor
, This
->buflen
);
511 return DSERR_INVALIDPARAM
;
514 if (writebytes
> This
->buflen
) {
515 WARN("Invalid parameter, writebytes: %lu > buflen: %lu\n",
516 writebytes
, This
->buflen
);
517 return DSERR_INVALIDPARAM
;
520 AcquireSRWLockShared(&This
->lock
);
522 if (writecursor
+writebytes
<= This
->buflen
) {
523 *(LPBYTE
*)lplpaudioptr1
= This
->buffer
->memory
+writecursor
;
524 if (This
->sec_mixpos
>= writecursor
&& This
->sec_mixpos
< writecursor
+ writebytes
&& This
->state
== STATE_PLAYING
) {
525 WARN("Overwriting mixing position, case 1\n");
526 commit_next_chunk(This
);
528 *audiobytes1
= writebytes
;
530 *(LPBYTE
*)lplpaudioptr2
= NULL
;
533 TRACE("Locked %p(%li bytes) and %p(%li bytes) writecursor=%ld\n",
534 *(LPBYTE
*)lplpaudioptr1
, *audiobytes1
, lplpaudioptr2
? *(LPBYTE
*)lplpaudioptr2
: NULL
, audiobytes2
? *audiobytes2
: 0, writecursor
);
535 TRACE("->%ld.0\n",writebytes
);
536 This
->buffer
->lockedbytes
+= writebytes
;
538 DWORD remainder
= writebytes
+ writecursor
- This
->buflen
;
539 *(LPBYTE
*)lplpaudioptr1
= This
->buffer
->memory
+writecursor
;
540 *audiobytes1
= This
->buflen
-writecursor
;
541 This
->buffer
->lockedbytes
+= *audiobytes1
;
542 if (This
->sec_mixpos
>= writecursor
&& This
->sec_mixpos
< writecursor
+ writebytes
&& This
->state
== STATE_PLAYING
) {
543 WARN("Overwriting mixing position, case 2\n");
544 commit_next_chunk(This
);
547 *(LPBYTE
*)lplpaudioptr2
= This
->buffer
->memory
;
549 *audiobytes2
= writebytes
-(This
->buflen
-writecursor
);
550 This
->buffer
->lockedbytes
+= *audiobytes2
;
552 if (audiobytes2
&& This
->sec_mixpos
< remainder
&& This
->state
== STATE_PLAYING
) {
553 WARN("Overwriting mixing position, case 3\n");
554 commit_next_chunk(This
);
556 TRACE("Locked %p(%li bytes) and %p(%li bytes) writecursor=%ld\n", *(LPBYTE
*)lplpaudioptr1
, *audiobytes1
, lplpaudioptr2
? *(LPBYTE
*)lplpaudioptr2
: NULL
, audiobytes2
? *audiobytes2
: 0, writecursor
);
559 ReleaseSRWLockShared(&This
->lock
);
564 static HRESULT WINAPI
IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuffer8
*iface
,
567 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
568 HRESULT hres
= DS_OK
;
570 TRACE("(%p,%ld)\n",This
,newpos
);
572 AcquireSRWLockExclusive(&This
->lock
);
574 /* start mixing from this new location instead */
575 newpos
%= This
->buflen
;
576 newpos
-= newpos
%This
->pwfx
->nBlockAlign
;
577 This
->sec_mixpos
= newpos
;
579 This
->use_committed
= FALSE
;
580 This
->committed_mixpos
= 0;
582 /* at this point, do not attempt to reset buffers, mess with primary mix position,
583 or anything like that to reduce latency. The data already prebuffered cannot be changed */
585 ReleaseSRWLockExclusive(&This
->lock
);
590 static HRESULT WINAPI
IDirectSoundBufferImpl_SetPan(IDirectSoundBuffer8
*iface
, LONG pan
)
592 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
593 HRESULT hres
= DS_OK
;
595 TRACE("(%p,%ld)\n",This
,pan
);
597 if ((pan
> DSBPAN_RIGHT
) || (pan
< DSBPAN_LEFT
)) {
598 WARN("invalid parameter: pan = %ld\n", pan
);
599 return DSERR_INVALIDPARAM
;
602 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
603 WARN("control unavailable\n");
604 return DSERR_CONTROLUNAVAIL
;
607 AcquireSRWLockExclusive(&This
->lock
);
609 if (This
->volpan
.lPan
!= pan
) {
610 This
->volpan
.lPan
= pan
;
611 DSOUND_RecalcVolPan(&(This
->volpan
));
614 ReleaseSRWLockExclusive(&This
->lock
);
619 static HRESULT WINAPI
IDirectSoundBufferImpl_GetPan(IDirectSoundBuffer8
*iface
, LONG
*pan
)
621 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
623 TRACE("(%p,%p)\n",This
,pan
);
625 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPAN
)) {
626 WARN("control unavailable\n");
627 return DSERR_CONTROLUNAVAIL
;
631 WARN("invalid parameter: pan = NULL\n");
632 return DSERR_INVALIDPARAM
;
635 *pan
= This
->volpan
.lPan
;
640 static HRESULT WINAPI
IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8
*iface
, void *p1
, DWORD x1
,
643 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
), *iter
;
644 HRESULT hres
= DS_OK
;
646 TRACE("(%p,%p,%ld,%p,%ld)\n", This
,p1
,x1
,p2
,x2
);
651 if((p1
&& ((BYTE
*)p1
< This
->buffer
->memory
|| (BYTE
*)p1
>= This
->buffer
->memory
+ This
->buflen
)) ||
652 (p2
&& ((BYTE
*)p2
< This
->buffer
->memory
|| (BYTE
*)p2
>= This
->buffer
->memory
+ This
->buflen
)))
653 return DSERR_INVALIDPARAM
;
657 AcquireSRWLockShared(&This
->device
->buffer_list_lock
);
658 LIST_FOR_EACH_ENTRY(iter
, &This
->buffer
->buffers
, IDirectSoundBufferImpl
, entry
)
660 AcquireSRWLockShared(&iter
->lock
);
663 if(x1
+ (DWORD_PTR
)p1
- (DWORD_PTR
)iter
->buffer
->memory
> iter
->buflen
)
664 hres
= DSERR_INVALIDPARAM
;
666 iter
->buffer
->lockedbytes
-= x1
;
671 if(x2
+ (DWORD_PTR
)p2
- (DWORD_PTR
)iter
->buffer
->memory
> iter
->buflen
)
672 hres
= DSERR_INVALIDPARAM
;
674 iter
->buffer
->lockedbytes
-= x2
;
676 ReleaseSRWLockShared(&iter
->lock
);
678 ReleaseSRWLockShared(&This
->device
->buffer_list_lock
);
684 static HRESULT WINAPI
IDirectSoundBufferImpl_Restore(IDirectSoundBuffer8
*iface
)
686 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
688 FIXME("(%p):stub\n",This
);
692 static HRESULT WINAPI
IDirectSoundBufferImpl_GetFrequency(IDirectSoundBuffer8
*iface
, DWORD
*freq
)
694 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
696 TRACE("(%p,%p)\n",This
,freq
);
699 WARN("invalid parameter: freq = NULL\n");
700 return DSERR_INVALIDPARAM
;
704 TRACE("-> %ld\n", *freq
);
709 static const char* dump_DSFX_guid(const DSEFFECTDESC
*desc
)
711 #define FE(guid) if (IsEqualGUID(&guid, &desc->guidDSFXClass)) return #guid
712 FE(GUID_DSFX_STANDARD_GARGLE
);
713 FE(GUID_DSFX_STANDARD_CHORUS
);
714 FE(GUID_DSFX_STANDARD_FLANGER
);
715 FE(GUID_DSFX_STANDARD_ECHO
);
716 FE(GUID_DSFX_STANDARD_DISTORTION
);
717 FE(GUID_DSFX_STANDARD_COMPRESSOR
);
718 FE(GUID_DSFX_STANDARD_PARAMEQ
);
719 FE(GUID_DSFX_STANDARD_I3DL2REVERB
);
720 FE(GUID_DSFX_WAVES_REVERB
);
723 return debugstr_guid(&desc
->guidDSFXClass
);
726 static HRESULT WINAPI
IDirectSoundBufferImpl_SetFX(IDirectSoundBuffer8
*iface
, DWORD dwEffectsCount
,
727 LPDSEFFECTDESC pDSFXDesc
, DWORD
*pdwResultCodes
)
729 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
736 TRACE("(%p,%lu,%p,%p)\n", This
, dwEffectsCount
, pDSFXDesc
, pdwResultCodes
);
739 for (u
=0; u
<dwEffectsCount
; u
++) pdwResultCodes
[u
] = DSFXR_UNKNOWN
;
741 if ((dwEffectsCount
> 0 && !pDSFXDesc
) ||
742 (dwEffectsCount
== 0 && (pDSFXDesc
|| pdwResultCodes
))
746 if (!(This
->dsbd
.dwFlags
& DSBCAPS_CTRLFX
)) {
747 WARN("attempted to call SetFX on buffer without DSBCAPS_CTRLFX\n");
748 return DSERR_CONTROLUNAVAIL
;
751 if (This
->state
!= STATE_STOPPED
)
752 return DSERR_INVALIDCALL
;
754 if (This
->buffer
->lockedbytes
> 0)
755 return DSERR_INVALIDCALL
;
757 if (dwEffectsCount
== 0) {
758 if (This
->num_filters
> 0) {
759 for (u
= 0; u
< This
->num_filters
; u
++) {
760 IMediaObject_Release(This
->filters
[u
].obj
);
764 This
->filters
= NULL
;
765 This
->num_filters
= 0;
771 filters
= malloc(dwEffectsCount
* sizeof(DSFilter
));
773 WARN("out of memory\n");
774 return DSERR_OUTOFMEMORY
;
779 wfx
.wFormatTag
= WAVE_FORMAT_IEEE_FLOAT
;
780 wfx
.nChannels
= This
->pwfx
->nChannels
;
781 wfx
.nSamplesPerSec
= This
->pwfx
->nSamplesPerSec
;
782 wfx
.wBitsPerSample
= sizeof(float) * 8;
783 wfx
.nBlockAlign
= (wfx
.nChannels
* wfx
.wBitsPerSample
)/8;
784 wfx
.nAvgBytesPerSec
= wfx
.nSamplesPerSec
* wfx
.nBlockAlign
;
785 wfx
.cbSize
= sizeof(wfx
);
787 dmt
.majortype
= KSDATAFORMAT_TYPE_AUDIO
;
788 dmt
.subtype
= KSDATAFORMAT_SUBTYPE_IEEE_FLOAT
;
789 dmt
.bFixedSizeSamples
= TRUE
;
790 dmt
.bTemporalCompression
= FALSE
;
791 dmt
.lSampleSize
= sizeof(float) * This
->pwfx
->nChannels
/ 8;
792 dmt
.formattype
= FORMAT_WaveFormatEx
;
794 dmt
.cbFormat
= sizeof(WAVEFORMATEX
);
795 dmt
.pbFormat
= (BYTE
*)&wfx
;
797 for (u
= 0; u
< dwEffectsCount
; u
++) {
798 TRACE("%ld: 0x%08lx, %s\n", u
, pDSFXDesc
[u
].dwFlags
, dump_DSFX_guid(&pDSFXDesc
[u
]));
800 hr2
= CoCreateInstance(&pDSFXDesc
[u
].guidDSFXClass
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IMediaObject
, (LPVOID
*)&filters
[u
].obj
);
802 if (SUCCEEDED(hr2
)) {
803 hr2
= IMediaObject_SetInputType(filters
[u
].obj
, 0, &dmt
, 0);
805 WARN("Could not set DMO input type\n");
808 if (SUCCEEDED(hr2
)) {
809 hr2
= IMediaObject_SetOutputType(filters
[u
].obj
, 0, &dmt
, 0);
811 WARN("Could not set DMO output type\n");
819 pdwResultCodes
[u
] = (hr2
== REGDB_E_CLASSNOTREG
) ? DSFXR_UNKNOWN
: DSFXR_FAILED
;
822 pdwResultCodes
[u
] = DSFXR_LOCSOFTWARE
;
827 for (u
= 0; u
< dwEffectsCount
; u
++) {
829 pdwResultCodes
[u
] = (pdwResultCodes
[u
] != DSFXR_UNKNOWN
) ? DSFXR_PRESENT
: DSFXR_UNKNOWN
;
832 IMediaObject_Release(filters
[u
].obj
);
837 if (This
->num_filters
> 0) {
838 for (u
= 0; u
< This
->num_filters
; u
++) {
839 IMediaObject_Release(This
->filters
[u
].obj
);
840 if (This
->filters
[u
].inplace
) IMediaObjectInPlace_Release(This
->filters
[u
].inplace
);
845 for (u
= 0; u
< dwEffectsCount
; u
++) {
846 memcpy(&filters
[u
].guid
, &pDSFXDesc
[u
].guidDSFXClass
, sizeof(GUID
));
847 if (FAILED(IMediaObject_QueryInterface(filters
[u
].obj
, &IID_IMediaObjectInPlace
, (void*)&filters
[u
].inplace
)))
848 filters
[u
].inplace
= NULL
;
851 This
->filters
= filters
;
852 This
->num_filters
= dwEffectsCount
;
858 static HRESULT WINAPI
IDirectSoundBufferImpl_AcquireResources(IDirectSoundBuffer8
*iface
,
859 DWORD dwFlags
, DWORD dwEffectsCount
, DWORD
*pdwResultCodes
)
861 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
864 FIXME("(%p,%08lu,%lu,%p): stub, faking success\n",This
,dwFlags
,dwEffectsCount
,pdwResultCodes
);
867 for (u
=0; u
<dwEffectsCount
; u
++) pdwResultCodes
[u
] = DSFXR_UNKNOWN
;
869 WARN("control unavailable\n");
873 static HRESULT WINAPI
IDirectSoundBufferImpl_GetObjectInPath(IDirectSoundBuffer8
*iface
,
874 REFGUID clsid
, DWORD index
, REFGUID iid
, void **out
)
876 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
879 TRACE("(%p,%s,%lu,%s,%p)\n", This
, debugstr_guid(clsid
), index
, debugstr_guid(iid
), out
);
884 for (i
= 0; i
< This
->num_filters
; i
++)
886 if (IsEqualGUID(clsid
, &This
->filters
[i
].guid
) || IsEqualGUID(clsid
, &GUID_All_Objects
))
888 if (count
++ == index
)
889 return IMediaObject_QueryInterface(This
->filters
[i
].obj
, iid
, out
);
892 return DSERR_OBJECTNOTFOUND
;
895 static HRESULT WINAPI
IDirectSoundBufferImpl_Initialize(IDirectSoundBuffer8
*iface
,
896 IDirectSound
*dsound
, LPCDSBUFFERDESC dbsd
)
898 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
900 WARN("(%p) already initialized\n", This
);
901 return DSERR_ALREADYINITIALIZED
;
904 static HRESULT WINAPI
IDirectSoundBufferImpl_GetCaps(IDirectSoundBuffer8
*iface
, LPDSBCAPS caps
)
906 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
908 TRACE("(%p)->(%p)\n",This
,caps
);
911 WARN("invalid parameter: caps == NULL\n");
912 return DSERR_INVALIDPARAM
;
915 if (caps
->dwSize
< sizeof(*caps
)) {
916 WARN("invalid parameter: caps->dwSize = %ld\n",caps
->dwSize
);
917 return DSERR_INVALIDPARAM
;
920 caps
->dwFlags
= This
->dsbd
.dwFlags
;
921 caps
->dwFlags
|= DSBCAPS_LOCSOFTWARE
;
923 caps
->dwBufferBytes
= This
->buflen
;
925 /* According to windows, this is zero*/
926 caps
->dwUnlockTransferRate
= 0;
927 caps
->dwPlayCpuOverhead
= 0;
932 static HRESULT WINAPI
IDirectSoundBufferImpl_QueryInterface(IDirectSoundBuffer8
*iface
, REFIID riid
,
935 IDirectSoundBufferImpl
*This
= impl_from_IDirectSoundBuffer8(iface
);
937 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
940 WARN("invalid parameter\n");
944 *ppobj
= NULL
; /* assume failure */
946 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
947 IsEqualGUID(riid
, &IID_IDirectSoundBuffer
) ||
948 IsEqualGUID(riid
, &IID_IDirectSoundBuffer8
) ) {
949 IDirectSoundBuffer8_AddRef(iface
);
954 if ( IsEqualGUID( &IID_IDirectSoundNotify
, riid
) ) {
955 if(This
->dsbd
.dwFlags
& DSBCAPS_CTRLPOSITIONNOTIFY
) {
956 IDirectSoundNotify_AddRef(&This
->IDirectSoundNotify_iface
);
957 *ppobj
= &This
->IDirectSoundNotify_iface
;
961 TRACE( "App requested IDirectSoundNotify without DSBCAPS_CTRLPOSITIONNOTIFY flag.\n");
962 return E_NOINTERFACE
;
965 if ( IsEqualGUID( &IID_IDirectSound3DBuffer
, riid
) ) {
966 if(This
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
){
967 IDirectSound3DBuffer_AddRef(&This
->IDirectSound3DBuffer_iface
);
968 *ppobj
= &This
->IDirectSound3DBuffer_iface
;
971 TRACE("app requested IDirectSound3DBuffer on non-3D secondary buffer\n");
972 return E_NOINTERFACE
;
975 if ( IsEqualGUID( &IID_IDirectSound3DListener
, riid
) ) {
976 ERR("app requested IDirectSound3DListener on secondary buffer\n");
977 return E_NOINTERFACE
;
980 if ( IsEqualGUID( &IID_IKsPropertySet
, riid
) ) {
981 IKsPropertySet_AddRef(&This
->IKsPropertySet_iface
);
982 *ppobj
= &This
->IKsPropertySet_iface
;
986 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
988 return E_NOINTERFACE
;
991 static const IDirectSoundBuffer8Vtbl dsbvt
=
993 IDirectSoundBufferImpl_QueryInterface
,
994 IDirectSoundBufferImpl_AddRef
,
995 IDirectSoundBufferImpl_Release
,
996 IDirectSoundBufferImpl_GetCaps
,
997 IDirectSoundBufferImpl_GetCurrentPosition
,
998 IDirectSoundBufferImpl_GetFormat
,
999 IDirectSoundBufferImpl_GetVolume
,
1000 IDirectSoundBufferImpl_GetPan
,
1001 IDirectSoundBufferImpl_GetFrequency
,
1002 IDirectSoundBufferImpl_GetStatus
,
1003 IDirectSoundBufferImpl_Initialize
,
1004 IDirectSoundBufferImpl_Lock
,
1005 IDirectSoundBufferImpl_Play
,
1006 IDirectSoundBufferImpl_SetCurrentPosition
,
1007 IDirectSoundBufferImpl_SetFormat
,
1008 IDirectSoundBufferImpl_SetVolume
,
1009 IDirectSoundBufferImpl_SetPan
,
1010 IDirectSoundBufferImpl_SetFrequency
,
1011 IDirectSoundBufferImpl_Stop
,
1012 IDirectSoundBufferImpl_Unlock
,
1013 IDirectSoundBufferImpl_Restore
,
1014 IDirectSoundBufferImpl_SetFX
,
1015 IDirectSoundBufferImpl_AcquireResources
,
1016 IDirectSoundBufferImpl_GetObjectInPath
1019 HRESULT
secondarybuffer_create(DirectSoundDevice
*device
, const DSBUFFERDESC
*dsbd
,
1020 IDirectSoundBuffer
**buffer
)
1022 IDirectSoundBufferImpl
*dsb
;
1023 LPWAVEFORMATEX wfex
= dsbd
->lpwfxFormat
;
1024 HRESULT err
= DS_OK
;
1028 TRACE("(%p,%p,%p)\n", device
, dsbd
, buffer
);
1030 if (dsbd
->dwBufferBytes
< DSBSIZE_MIN
|| dsbd
->dwBufferBytes
> DSBSIZE_MAX
) {
1031 WARN("invalid parameter: dsbd->dwBufferBytes = %ld\n", dsbd
->dwBufferBytes
);
1032 return DSERR_INVALIDPARAM
; /* FIXME: which error? */
1035 dsb
= calloc(1, sizeof(*dsb
));
1038 return DSERR_OUTOFMEMORY
;
1040 TRACE("Created buffer at %p\n", dsb
);
1047 dsb
->device
= device
;
1048 dsb
->IDirectSoundBuffer8_iface
.lpVtbl
= &dsbvt
;
1049 dsb
->IDirectSoundNotify_iface
.lpVtbl
= &dsnvt
;
1050 dsb
->IDirectSound3DBuffer_iface
.lpVtbl
= &ds3dbvt
;
1051 dsb
->IKsPropertySet_iface
.lpVtbl
= &iksbvt
;
1053 /* size depends on version */
1054 CopyMemory(&dsb
->dsbd
, dsbd
, dsbd
->dwSize
);
1056 dsb
->pwfx
= DSOUND_CopyFormat(wfex
);
1058 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1059 return DSERR_OUTOFMEMORY
;
1062 if (dsbd
->dwBufferBytes
% dsbd
->lpwfxFormat
->nBlockAlign
)
1063 dsb
->buflen
= dsbd
->dwBufferBytes
+
1064 (dsbd
->lpwfxFormat
->nBlockAlign
-
1065 (dsbd
->dwBufferBytes
% dsbd
->lpwfxFormat
->nBlockAlign
));
1067 dsb
->buflen
= dsbd
->dwBufferBytes
;
1069 dsb
->freq
= dsbd
->lpwfxFormat
->nSamplesPerSec
;
1070 dsb
->notifies
= NULL
;
1071 dsb
->nrofnotifies
= 0;
1073 /* Check necessary hardware mixing capabilities */
1074 if (wfex
->nChannels
==2) capf
|= DSCAPS_SECONDARYSTEREO
;
1075 else capf
|= DSCAPS_SECONDARYMONO
;
1076 if (wfex
->wBitsPerSample
==16) capf
|= DSCAPS_SECONDARY16BIT
;
1077 else capf
|= DSCAPS_SECONDARY8BIT
;
1079 TRACE("capf = 0x%08lx, device->drvcaps.dwFlags = 0x%08lx\n", capf
, device
->drvcaps
.dwFlags
);
1081 /* Allocate an empty buffer */
1082 bufsize
= (sizeof(*(dsb
->buffer
)) + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
1083 dsb
->buffer
= malloc(bufsize
+ dsb
->buflen
);
1085 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1086 return DSERR_OUTOFMEMORY
;
1089 /* Allocate system memory for buffer */
1090 dsb
->buffer
->memory
= (BYTE
*)dsb
->buffer
+ bufsize
;
1092 dsb
->buffer
->ref
= 1;
1093 dsb
->buffer
->lockedbytes
= 0;
1094 list_init(&dsb
->buffer
->buffers
);
1095 list_add_head(&dsb
->buffer
->buffers
, &dsb
->entry
);
1096 FillMemory(dsb
->buffer
->memory
, dsb
->buflen
, dsbd
->lpwfxFormat
->wBitsPerSample
== 8 ? 128 : 0);
1098 /* It's not necessary to initialize values to zero since */
1099 /* we allocated this structure with calloc... */
1100 dsb
->sec_mixpos
= 0;
1101 dsb
->state
= STATE_STOPPED
;
1103 /* calculate fragment size and write lead */
1104 DSOUND_RecalcFormat(dsb
);
1106 dsb
->committedbuff
= malloc(dsb
->maxwritelead
);
1107 if(!dsb
->committedbuff
) {
1108 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1109 return DSERR_OUTOFMEMORY
;
1112 if (dsb
->dsbd
.dwFlags
& DSBCAPS_CTRL3D
) {
1113 dsb
->ds3db_ds3db
.dwSize
= sizeof(DS3DBUFFER
);
1114 dsb
->ds3db_ds3db
.vPosition
.x
= 0.0;
1115 dsb
->ds3db_ds3db
.vPosition
.y
= 0.0;
1116 dsb
->ds3db_ds3db
.vPosition
.z
= 0.0;
1117 dsb
->ds3db_ds3db
.vVelocity
.x
= 0.0;
1118 dsb
->ds3db_ds3db
.vVelocity
.y
= 0.0;
1119 dsb
->ds3db_ds3db
.vVelocity
.z
= 0.0;
1120 dsb
->ds3db_ds3db
.dwInsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1121 dsb
->ds3db_ds3db
.dwOutsideConeAngle
= DS3D_DEFAULTCONEANGLE
;
1122 dsb
->ds3db_ds3db
.vConeOrientation
.x
= 0.0;
1123 dsb
->ds3db_ds3db
.vConeOrientation
.y
= 0.0;
1124 dsb
->ds3db_ds3db
.vConeOrientation
.z
= 0.0;
1125 dsb
->ds3db_ds3db
.lConeOutsideVolume
= DS3D_DEFAULTCONEOUTSIDEVOLUME
;
1126 dsb
->ds3db_ds3db
.flMinDistance
= DS3D_DEFAULTMINDISTANCE
;
1127 dsb
->ds3db_ds3db
.flMaxDistance
= DS3D_DEFAULTMAXDISTANCE
;
1128 dsb
->ds3db_ds3db
.dwMode
= DS3DMODE_NORMAL
;
1130 dsb
->ds3db_need_recalc
= FALSE
;
1131 DSOUND_Calc3DBuffer(dsb
);
1133 DSOUND_RecalcVolPan(&(dsb
->volpan
));
1135 InitializeSRWLock(&dsb
->lock
);
1137 /* register buffer */
1138 err
= DirectSoundDevice_AddBuffer(device
, dsb
);
1140 *buffer
= (IDirectSoundBuffer
*)&dsb
->IDirectSoundBuffer8_iface
;
1142 IDirectSoundBuffer8_Release(&dsb
->IDirectSoundBuffer8_iface
);
1147 void secondarybuffer_destroy(IDirectSoundBufferImpl
*This
)
1149 ULONG ref
= InterlockedIncrement(&This
->numIfaces
);
1152 WARN("Destroying buffer with %lu in use interfaces\n", ref
- 1);
1154 if (This
->dsbd
.dwFlags
& DSBCAPS_LOCHARDWARE
)
1155 This
->device
->drvcaps
.dwFreeHwMixingAllBuffers
++;
1157 DirectSoundDevice_RemoveBuffer(This
->device
, This
);
1159 This
->buffer
->ref
--;
1160 list_remove(&This
->entry
);
1161 if (This
->buffer
->ref
== 0)
1164 free(This
->notifies
);
1166 free(This
->committedbuff
);
1168 if (This
->filters
) {
1170 for (i
= 0; i
< This
->num_filters
; i
++) {
1171 IMediaObject_Release(This
->filters
[i
].obj
);
1172 if (This
->filters
[i
].inplace
) IMediaObjectInPlace_Release(This
->filters
[i
].inplace
);
1174 free(This
->filters
);
1177 TRACE("(%p) released\n", This
);
1182 BOOL
secondarybuffer_is_audible(IDirectSoundBufferImpl
*This
)
1185 for (i
= 0; i
< This
->device
->pwfx
->nChannels
; i
++) {
1186 if (This
->volpan
.dwTotalAmpFactor
[i
] != 0)
1193 HRESULT
IDirectSoundBufferImpl_Duplicate(
1194 DirectSoundDevice
*device
,
1195 IDirectSoundBufferImpl
**ppdsb
,
1196 IDirectSoundBufferImpl
*pdsb
)
1198 IDirectSoundBufferImpl
*dsb
;
1199 HRESULT hres
= DS_OK
;
1200 VOID
*committedbuff
;
1201 TRACE("(%p,%p,%p)\n", device
, ppdsb
, pdsb
);
1203 dsb
= malloc(sizeof(*dsb
));
1205 WARN("out of memory\n");
1207 return DSERR_OUTOFMEMORY
;
1210 committedbuff
= malloc(pdsb
->maxwritelead
);
1211 if (committedbuff
== NULL
) {
1214 return DSERR_OUTOFMEMORY
;
1217 AcquireSRWLockShared(&pdsb
->lock
);
1219 CopyMemory(dsb
, pdsb
, sizeof(*dsb
));
1221 dsb
->pwfx
= DSOUND_CopyFormat(pdsb
->pwfx
);
1223 ReleaseSRWLockShared(&pdsb
->lock
);
1225 if (dsb
->pwfx
== NULL
) {
1226 free(committedbuff
);
1229 return DSERR_OUTOFMEMORY
;
1233 list_add_head(&dsb
->buffer
->buffers
, &dsb
->entry
);
1239 dsb
->state
= STATE_STOPPED
;
1240 dsb
->sec_mixpos
= 0;
1241 dsb
->notifies
= NULL
;
1242 dsb
->nrofnotifies
= 0;
1243 dsb
->device
= device
;
1244 dsb
->committedbuff
= committedbuff
;
1245 dsb
->use_committed
= FALSE
;
1246 dsb
->committed_mixpos
= 0;
1247 DSOUND_RecalcFormat(dsb
);
1249 InitializeSRWLock(&dsb
->lock
);
1251 /* register buffer */
1252 hres
= DirectSoundDevice_AddBuffer(device
, dsb
);
1253 if (hres
!= DS_OK
) {
1254 list_remove(&dsb
->entry
);
1257 free(dsb
->committedbuff
);
1261 IDirectSoundBuffer8_AddRef(&dsb
->IDirectSoundBuffer8_iface
);
1267 /*******************************************************************************
1271 static inline IDirectSoundBufferImpl
*impl_from_IKsPropertySet(IKsPropertySet
*iface
)
1273 return CONTAINING_RECORD(iface
, IDirectSoundBufferImpl
, IKsPropertySet_iface
);
1276 /* IUnknown methods */
1277 static HRESULT WINAPI
IKsPropertySetImpl_QueryInterface(IKsPropertySet
*iface
, REFIID riid
,
1280 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1282 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
1284 return IDirectSoundBuffer8_QueryInterface(&This
->IDirectSoundBuffer8_iface
, riid
, ppobj
);
1287 static ULONG WINAPI
IKsPropertySetImpl_AddRef(IKsPropertySet
*iface
)
1289 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1290 ULONG ref
= InterlockedIncrement(&This
->refiks
);
1292 TRACE("(%p) ref %ld\n", This
, ref
);
1295 InterlockedIncrement(&This
->numIfaces
);
1300 static ULONG WINAPI
IKsPropertySetImpl_Release(IKsPropertySet
*iface
)
1302 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1305 if (is_primary_buffer(This
)){
1306 ref
= capped_refcount_dec(&This
->refiks
);
1308 capped_refcount_dec(&This
->numIfaces
);
1309 TRACE("(%p) ref %ld\n", This
, ref
);
1313 ref
= InterlockedDecrement(&This
->refiks
);
1314 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
1315 secondarybuffer_destroy(This
);
1317 TRACE("(%p) ref %ld\n", This
, ref
);
1322 static HRESULT WINAPI
IKsPropertySetImpl_Get(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1323 ULONG dwPropID
, void *pInstanceData
, ULONG cbInstanceData
, void *pPropData
,
1324 ULONG cbPropData
, ULONG
*pcbReturned
)
1326 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1328 TRACE("(iface=%p,guidPropSet=%s,dwPropID=%ld,pInstanceData=%p,cbInstanceData=%ld,pPropData=%p,cbPropData=%ld,pcbReturned=%p)\n",
1329 This
,debugstr_guid(guidPropSet
),dwPropID
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
,pcbReturned
);
1331 return E_PROP_ID_UNSUPPORTED
;
1334 static HRESULT WINAPI
IKsPropertySetImpl_Set(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1335 ULONG dwPropID
, void *pInstanceData
, ULONG cbInstanceData
, void *pPropData
,
1338 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1340 TRACE("(%p,%s,%ld,%p,%ld,%p,%ld)\n",This
,debugstr_guid(guidPropSet
),dwPropID
,pInstanceData
,cbInstanceData
,pPropData
,cbPropData
);
1342 return E_PROP_ID_UNSUPPORTED
;
1345 static HRESULT WINAPI
IKsPropertySetImpl_QuerySupport(IKsPropertySet
*iface
, REFGUID guidPropSet
,
1346 ULONG dwPropID
, ULONG
*pTypeSupport
)
1348 IDirectSoundBufferImpl
*This
= impl_from_IKsPropertySet(iface
);
1350 TRACE("(%p,%s,%ld,%p)\n",This
,debugstr_guid(guidPropSet
),dwPropID
,pTypeSupport
);
1352 return E_PROP_ID_UNSUPPORTED
;
1355 const IKsPropertySetVtbl iksbvt
= {
1356 IKsPropertySetImpl_QueryInterface
,
1357 IKsPropertySetImpl_AddRef
,
1358 IKsPropertySetImpl_Release
,
1359 IKsPropertySetImpl_Get
,
1360 IKsPropertySetImpl_Set
,
1361 IKsPropertySetImpl_QuerySupport