msado15: Implement Dispatch functions in Fields.
[wine.git] / dlls / dsound / buffer.c
blobfafa6fc60150862d12c4484b2be13e87cdb45ee6
1 /* DirectSound
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 <stdarg.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "mmsystem.h"
30 #include "vfwmsgs.h"
31 #include "wine/debug.h"
32 #include "dsound.h"
33 #include "dsound_private.h"
34 #include "dsconf.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
38 /*******************************************************************************
39 * IDirectSoundNotify
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,
48 void **ppobj)
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);
64 if(ref == 1)
65 InterlockedIncrement(&This->numIfaces);
67 return ref;
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);
80 return ref;
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)
91 return -1;
92 }else if(right->dwOffset == DSBPN_OFFSETSTOP)
93 return 1;
95 if(left->dwOffset == right->dwOffset)
96 return 0;
98 if(left->dwOffset < right->dwOffset)
99 return -1;
101 return 1;
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)) {
117 unsigned int i;
118 for (i=0;i<howmuch;i++)
119 TRACE("notify at %d to %p\n",
120 notify[i].dwOffset,notify[i].hEventNotify);
123 if (howmuch > 0) {
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);
137 } else {
138 HeapFree(GetProcessHeap(), 0, This->notifies);
139 This->notifies = NULL;
140 This->nrofnotifies = 0;
143 return S_OK;
146 static const IDirectSoundNotifyVtbl dsnvt =
148 IDirectSoundNotifyImpl_QueryInterface,
149 IDirectSoundNotifyImpl_AddRef,
150 IDirectSoundNotifyImpl_Release,
151 IDirectSoundNotifyImpl_SetNotificationPositions,
154 /*******************************************************************************
155 * IDirectSoundBuffer
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);
177 else {
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);
186 LONG oldVol;
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;
207 if (vol != oldVol)
208 /* recalc 3d volume, which in turn recalcs the pans */
209 DSOUND_Calc3DBuffer(This);
210 } else {
211 oldVol = This->volpan.lVolume;
212 This->volpan.lVolume = vol;
213 if (vol != oldVol)
214 DSOUND_RecalcVolPan(&(This->volpan));
217 ReleaseSRWLockExclusive(&This->lock);
219 return hres;
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;
233 if (vol == NULL) {
234 WARN("invalid parameter: vol == NULL\n");
235 return DSERR_INVALIDPARAM;
238 *vol = This->volpan.lVolume;
240 return DS_OK;
243 static HRESULT WINAPI IDirectSoundBufferImpl_SetFrequency(IDirectSoundBuffer8 *iface, DWORD freq)
245 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
246 DWORD oldFreq;
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;
271 This->freq = 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);
281 return DS_OK;
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;
289 int i;
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) {
297 This->leadin = TRUE;
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);
308 return hres;
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);
330 return hres;
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);
340 if(ref == 1)
341 InterlockedIncrement(&This->numIfaces);
343 return ref;
346 static ULONG WINAPI IDirectSoundBufferImpl_Release(IDirectSoundBuffer8 *iface)
348 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
349 ULONG ref;
351 if (is_primary_buffer(This)){
352 ref = capped_refcount_dec(&This->ref);
353 if(!ref)
354 capped_refcount_dec(&This->numIfaces);
355 TRACE("(%p) ref %d\n", This, ref);
356 return ref;
359 ref = InterlockedDecrement(&This->ref);
360 if (!ref && !InterlockedDecrement(&This->numIfaces))
361 secondarybuffer_destroy(This);
363 TRACE("(%p) ref %d\n", This, ref);
365 return ref;
368 static HRESULT WINAPI IDirectSoundBufferImpl_GetCurrentPosition(IDirectSoundBuffer8 *iface,
369 DWORD *playpos, DWORD *writepos)
371 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
372 DWORD pos;
374 TRACE("(%p,%p,%p)\n",This,playpos,writepos);
376 AcquireSRWLockShared(&This->lock);
378 pos = This->sec_mixpos;
380 /* sanity */
381 if (pos >= This->buflen){
382 FIXME("Bad play position. playpos: %d, buflen: %d\n", pos, This->buflen);
383 pos %= This->buflen;
386 if (playpos)
387 *playpos = pos;
388 if (writepos)
389 *writepos = pos;
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());
402 return DS_OK;
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;
416 *status = 0;
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 if (This->dsbd.dwFlags & DSBCAPS_LOCDEFER)
424 *status |= DSBSTATUS_LOCSOFTWARE;
425 ReleaseSRWLockShared(&This->lock);
427 TRACE("status=%x\n", *status);
428 return DS_OK;
432 static HRESULT WINAPI IDirectSoundBufferImpl_GetFormat(IDirectSoundBuffer8 *iface,
433 LPWAVEFORMATEX lpwf, DWORD wfsize, DWORD *wfwritten)
435 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
436 DWORD size;
438 TRACE("(%p,%p,%d,%p)\n",This,lpwf,wfsize,wfwritten);
440 size = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
442 if (lpwf) { /* NULL is valid */
443 if (wfsize >= size) {
444 CopyMemory(lpwf,This->pwfx,size);
445 if (wfwritten)
446 *wfwritten = size;
447 } else {
448 WARN("invalid parameter: wfsize too small\n");
449 CopyMemory(lpwf,This->pwfx,wfsize);
450 if (wfwritten)
451 *wfwritten = wfsize;
452 return DSERR_INVALIDPARAM;
454 } else {
455 if (wfwritten)
456 *wfwritten = sizeof(WAVEFORMATEX) + This->pwfx->cbSize;
457 else {
458 WARN("invalid parameter: wfwritten == NULL\n");
459 return DSERR_INVALIDPARAM;
463 return DS_OK;
466 static HRESULT WINAPI IDirectSoundBufferImpl_Lock(IDirectSoundBuffer8 *iface, DWORD writecursor,
467 DWORD writebytes, void **lplpaudioptr1, DWORD *audiobytes1, void **lplpaudioptr2,
468 DWORD *audiobytes2, DWORD flags)
470 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
471 HRESULT hres = DS_OK;
473 TRACE("(%p,%d,%d,%p,%p,%p,%p,0x%08x) at %d\n", This, writecursor, writebytes, lplpaudioptr1,
474 audiobytes1, lplpaudioptr2, audiobytes2, flags, GetTickCount());
476 if (!audiobytes1)
477 return DSERR_INVALIDPARAM;
479 /* when this flag is set, writecursor is meaningless and must be calculated */
480 if (flags & DSBLOCK_FROMWRITECURSOR) {
481 /* GetCurrentPosition does too much magic to duplicate here */
482 hres = IDirectSoundBufferImpl_GetCurrentPosition(iface, NULL, &writecursor);
483 if (hres != DS_OK) {
484 WARN("IDirectSoundBufferImpl_GetCurrentPosition failed\n");
485 return hres;
489 /* when this flag is set, writebytes is meaningless and must be set */
490 if (flags & DSBLOCK_ENTIREBUFFER)
491 writebytes = This->buflen;
493 if (writecursor >= This->buflen) {
494 WARN("Invalid parameter, writecursor: %u >= buflen: %u\n",
495 writecursor, This->buflen);
496 return DSERR_INVALIDPARAM;
499 if (writebytes > This->buflen) {
500 WARN("Invalid parameter, writebytes: %u > buflen: %u\n",
501 writebytes, This->buflen);
502 return DSERR_INVALIDPARAM;
505 AcquireSRWLockShared(&This->lock);
507 if (writecursor+writebytes <= This->buflen) {
508 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
509 if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)
510 WARN("Overwriting mixing position, case 1\n");
511 *audiobytes1 = writebytes;
512 if (lplpaudioptr2)
513 *(LPBYTE*)lplpaudioptr2 = NULL;
514 if (audiobytes2)
515 *audiobytes2 = 0;
516 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n",
517 *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
518 TRACE("->%d.0\n",writebytes);
519 This->buffer->lockedbytes += writebytes;
520 } else {
521 DWORD remainder = writebytes + writecursor - This->buflen;
522 *(LPBYTE*)lplpaudioptr1 = This->buffer->memory+writecursor;
523 *audiobytes1 = This->buflen-writecursor;
524 This->buffer->lockedbytes += *audiobytes1;
525 if (This->sec_mixpos >= writecursor && This->sec_mixpos < writecursor + writebytes && This->state == STATE_PLAYING)
526 WARN("Overwriting mixing position, case 2\n");
527 if (lplpaudioptr2)
528 *(LPBYTE*)lplpaudioptr2 = This->buffer->memory;
529 if (audiobytes2) {
530 *audiobytes2 = writebytes-(This->buflen-writecursor);
531 This->buffer->lockedbytes += *audiobytes2;
533 if (audiobytes2 && This->sec_mixpos < remainder && This->state == STATE_PLAYING)
534 WARN("Overwriting mixing position, case 3\n");
535 TRACE("Locked %p(%i bytes) and %p(%i bytes) writecursor=%d\n", *(LPBYTE*)lplpaudioptr1, *audiobytes1, lplpaudioptr2 ? *(LPBYTE*)lplpaudioptr2 : NULL, audiobytes2 ? *audiobytes2: 0, writecursor);
538 ReleaseSRWLockShared(&This->lock);
540 return DS_OK;
543 static HRESULT WINAPI IDirectSoundBufferImpl_SetCurrentPosition(IDirectSoundBuffer8 *iface,
544 DWORD newpos)
546 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
547 HRESULT hres = DS_OK;
549 TRACE("(%p,%d)\n",This,newpos);
551 AcquireSRWLockExclusive(&This->lock);
553 /* start mixing from this new location instead */
554 newpos %= This->buflen;
555 newpos -= newpos%This->pwfx->nBlockAlign;
556 This->sec_mixpos = newpos;
558 /* at this point, do not attempt to reset buffers, mess with primary mix position,
559 or anything like that to reduce latency. The data already prebuffered cannot be changed */
561 ReleaseSRWLockExclusive(&This->lock);
563 return hres;
566 static HRESULT WINAPI IDirectSoundBufferImpl_SetPan(IDirectSoundBuffer8 *iface, LONG pan)
568 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
569 HRESULT hres = DS_OK;
571 TRACE("(%p,%d)\n",This,pan);
573 if ((pan > DSBPAN_RIGHT) || (pan < DSBPAN_LEFT)) {
574 WARN("invalid parameter: pan = %d\n", pan);
575 return DSERR_INVALIDPARAM;
578 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
579 WARN("control unavailable\n");
580 return DSERR_CONTROLUNAVAIL;
583 AcquireSRWLockExclusive(&This->lock);
585 if (This->volpan.lPan != pan) {
586 This->volpan.lPan = pan;
587 DSOUND_RecalcVolPan(&(This->volpan));
590 ReleaseSRWLockExclusive(&This->lock);
592 return hres;
595 static HRESULT WINAPI IDirectSoundBufferImpl_GetPan(IDirectSoundBuffer8 *iface, LONG *pan)
597 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
599 TRACE("(%p,%p)\n",This,pan);
601 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLPAN)) {
602 WARN("control unavailable\n");
603 return DSERR_CONTROLUNAVAIL;
606 if (pan == NULL) {
607 WARN("invalid parameter: pan = NULL\n");
608 return DSERR_INVALIDPARAM;
611 *pan = This->volpan.lPan;
613 return DS_OK;
616 static HRESULT WINAPI IDirectSoundBufferImpl_Unlock(IDirectSoundBuffer8 *iface, void *p1, DWORD x1,
617 void *p2, DWORD x2)
619 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface), *iter;
620 HRESULT hres = DS_OK;
622 TRACE("(%p,%p,%d,%p,%d)\n", This,p1,x1,p2,x2);
624 if (!p2)
625 x2 = 0;
627 if((p1 && ((BYTE*)p1 < This->buffer->memory || (BYTE*)p1 >= This->buffer->memory + This->buflen)) ||
628 (p2 && ((BYTE*)p2 < This->buffer->memory || (BYTE*)p2 >= This->buffer->memory + This->buflen)))
629 return DSERR_INVALIDPARAM;
631 if (x1 || x2)
633 AcquireSRWLockShared(&This->device->buffer_list_lock);
634 LIST_FOR_EACH_ENTRY(iter, &This->buffer->buffers, IDirectSoundBufferImpl, entry )
636 AcquireSRWLockShared(&iter->lock);
637 if (x1)
639 if(x1 + (DWORD_PTR)p1 - (DWORD_PTR)iter->buffer->memory > iter->buflen)
640 hres = DSERR_INVALIDPARAM;
641 else
642 iter->buffer->lockedbytes -= x1;
645 if (x2)
647 if(x2 + (DWORD_PTR)p2 - (DWORD_PTR)iter->buffer->memory > iter->buflen)
648 hres = DSERR_INVALIDPARAM;
649 else
650 iter->buffer->lockedbytes -= x2;
652 ReleaseSRWLockShared(&iter->lock);
654 ReleaseSRWLockShared(&This->device->buffer_list_lock);
657 return hres;
660 static HRESULT WINAPI IDirectSoundBufferImpl_Restore(IDirectSoundBuffer8 *iface)
662 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
664 FIXME("(%p):stub\n",This);
665 return DS_OK;
668 static HRESULT WINAPI IDirectSoundBufferImpl_GetFrequency(IDirectSoundBuffer8 *iface, DWORD *freq)
670 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
672 TRACE("(%p,%p)\n",This,freq);
674 if (freq == NULL) {
675 WARN("invalid parameter: freq = NULL\n");
676 return DSERR_INVALIDPARAM;
679 *freq = This->freq;
680 TRACE("-> %d\n", *freq);
682 return DS_OK;
685 static const char* dump_DSFX_guid(const DSEFFECTDESC *desc)
687 #define FE(guid) if (IsEqualGUID(&guid, &desc->guidDSFXClass)) return #guid
688 FE(GUID_DSFX_STANDARD_GARGLE);
689 FE(GUID_DSFX_STANDARD_CHORUS);
690 FE(GUID_DSFX_STANDARD_FLANGER);
691 FE(GUID_DSFX_STANDARD_ECHO);
692 FE(GUID_DSFX_STANDARD_DISTORTION);
693 FE(GUID_DSFX_STANDARD_COMPRESSOR);
694 FE(GUID_DSFX_STANDARD_PARAMEQ);
695 FE(GUID_DSFX_STANDARD_I3DL2REVERB);
696 FE(GUID_DSFX_WAVES_REVERB);
697 #undef FE
699 return debugstr_guid(&desc->guidDSFXClass);
702 static HRESULT WINAPI IDirectSoundBufferImpl_SetFX(IDirectSoundBuffer8 *iface, DWORD dwEffectsCount,
703 LPDSEFFECTDESC pDSFXDesc, DWORD *pdwResultCodes)
705 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
706 DWORD u;
707 DSFilter *filters;
708 HRESULT hr, hr2;
709 DMO_MEDIA_TYPE dmt;
710 WAVEFORMATEX wfx;
712 TRACE("(%p,%u,%p,%p)\n", This, dwEffectsCount, pDSFXDesc, pdwResultCodes);
714 if (pdwResultCodes)
715 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
717 if ((dwEffectsCount > 0 && !pDSFXDesc) ||
718 (dwEffectsCount == 0 && (pDSFXDesc || pdwResultCodes))
720 return E_INVALIDARG;
722 if (!(This->dsbd.dwFlags & DSBCAPS_CTRLFX)) {
723 WARN("attempted to call SetFX on buffer without DSBCAPS_CTRLFX\n");
724 return DSERR_CONTROLUNAVAIL;
727 if (This->state != STATE_STOPPED)
728 return DSERR_INVALIDCALL;
730 if (This->buffer->lockedbytes > 0)
731 return DSERR_INVALIDCALL;
733 if (dwEffectsCount == 0) {
734 if (This->num_filters > 0) {
735 for (u = 0; u < This->num_filters; u++) {
736 IMediaObject_Release(This->filters[u].obj);
738 HeapFree(GetProcessHeap(), 0, This->filters);
740 This->filters = NULL;
741 This->num_filters = 0;
744 return DS_OK;
747 filters = HeapAlloc(GetProcessHeap(), 0, dwEffectsCount * sizeof(DSFilter));
748 if (!filters) {
749 WARN("out of memory\n");
750 return DSERR_OUTOFMEMORY;
753 hr = DS_OK;
755 wfx.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
756 wfx.nChannels = This->pwfx->nChannels;
757 wfx.nSamplesPerSec = This->pwfx->nSamplesPerSec;
758 wfx.wBitsPerSample = sizeof(float) * 8;
759 wfx.nBlockAlign = (wfx.nChannels * wfx.wBitsPerSample)/8;
760 wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
761 wfx.cbSize = sizeof(wfx);
763 dmt.majortype = KSDATAFORMAT_TYPE_AUDIO;
764 dmt.subtype = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
765 dmt.bFixedSizeSamples = TRUE;
766 dmt.bTemporalCompression = FALSE;
767 dmt.lSampleSize = sizeof(float) * This->pwfx->nChannels / 8;
768 dmt.formattype = FORMAT_WaveFormatEx;
769 dmt.pUnk = NULL;
770 dmt.cbFormat = sizeof(WAVEFORMATEX);
771 dmt.pbFormat = (BYTE*)&wfx;
773 for (u = 0; u < dwEffectsCount; u++) {
774 TRACE("%d: 0x%08x, %s\n", u, pDSFXDesc[u].dwFlags, dump_DSFX_guid(&pDSFXDesc[u]));
776 hr2 = CoCreateInstance(&pDSFXDesc[u].guidDSFXClass, NULL, CLSCTX_INPROC_SERVER, &IID_IMediaObject, (LPVOID*)&filters[u].obj);
778 if (SUCCEEDED(hr2)) {
779 hr2 = IMediaObject_SetInputType(filters[u].obj, 0, &dmt, 0);
780 if (FAILED(hr2))
781 WARN("Could not set DMO input type\n");
784 if (SUCCEEDED(hr2)) {
785 hr2 = IMediaObject_SetOutputType(filters[u].obj, 0, &dmt, 0);
786 if (FAILED(hr2))
787 WARN("Could not set DMO output type\n");
790 if (FAILED(hr2)) {
791 if (hr == DS_OK)
792 hr = hr2;
794 if (pdwResultCodes)
795 pdwResultCodes[u] = (hr2 == REGDB_E_CLASSNOTREG) ? DSFXR_UNKNOWN : DSFXR_FAILED;
796 } else {
797 if (pdwResultCodes)
798 pdwResultCodes[u] = DSFXR_LOCSOFTWARE;
802 if (FAILED(hr)) {
803 for (u = 0; u < dwEffectsCount; u++) {
804 if (pdwResultCodes)
805 pdwResultCodes[u] = (pdwResultCodes[u] != DSFXR_UNKNOWN) ? DSFXR_PRESENT : DSFXR_UNKNOWN;
807 if (filters[u].obj)
808 IMediaObject_Release(filters[u].obj);
811 HeapFree(GetProcessHeap(), 0, filters);
812 } else {
813 if (This->num_filters > 0) {
814 for (u = 0; u < This->num_filters; u++) {
815 IMediaObject_Release(This->filters[u].obj);
816 if (This->filters[u].inplace) IMediaObjectInPlace_Release(This->filters[u].inplace);
818 HeapFree(GetProcessHeap(), 0, This->filters);
821 for (u = 0; u < dwEffectsCount; u++) {
822 memcpy(&filters[u].guid, &pDSFXDesc[u].guidDSFXClass, sizeof(GUID));
823 if (FAILED(IMediaObject_QueryInterface(filters[u].obj, &IID_IMediaObjectInPlace, (void*)&filters[u].inplace)))
824 filters[u].inplace = NULL;
827 This->filters = filters;
828 This->num_filters = dwEffectsCount;
831 return hr;
834 static HRESULT WINAPI IDirectSoundBufferImpl_AcquireResources(IDirectSoundBuffer8 *iface,
835 DWORD dwFlags, DWORD dwEffectsCount, DWORD *pdwResultCodes)
837 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
838 DWORD u;
840 FIXME("(%p,%08u,%u,%p): stub, faking success\n",This,dwFlags,dwEffectsCount,pdwResultCodes);
842 if (pdwResultCodes)
843 for (u=0; u<dwEffectsCount; u++) pdwResultCodes[u] = DSFXR_UNKNOWN;
845 WARN("control unavailable\n");
846 return DS_OK;
849 static HRESULT WINAPI IDirectSoundBufferImpl_GetObjectInPath(IDirectSoundBuffer8 *iface,
850 REFGUID clsid, DWORD index, REFGUID iid, void **out)
852 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
853 DWORD i, count = 0;
855 TRACE("(%p,%s,%u,%s,%p)\n", This, debugstr_guid(clsid), index, debugstr_guid(iid), out);
857 if (!out)
858 return E_INVALIDARG;
860 for (i = 0; i < This->num_filters; i++)
862 if (IsEqualGUID(clsid, &This->filters[i].guid) || IsEqualGUID(clsid, &GUID_All_Objects))
864 if (count++ == index)
865 return IMediaObject_QueryInterface(This->filters[i].obj, iid, out);
868 return DSERR_OBJECTNOTFOUND;
871 static HRESULT WINAPI IDirectSoundBufferImpl_Initialize(IDirectSoundBuffer8 *iface,
872 IDirectSound *dsound, LPCDSBUFFERDESC dbsd)
874 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
876 WARN("(%p) already initialized\n", This);
877 return DSERR_ALREADYINITIALIZED;
880 static HRESULT WINAPI IDirectSoundBufferImpl_GetCaps(IDirectSoundBuffer8 *iface, LPDSBCAPS caps)
882 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
884 TRACE("(%p)->(%p)\n",This,caps);
886 if (caps == NULL) {
887 WARN("invalid parameter: caps == NULL\n");
888 return DSERR_INVALIDPARAM;
891 if (caps->dwSize < sizeof(*caps)) {
892 WARN("invalid parameter: caps->dwSize = %d\n",caps->dwSize);
893 return DSERR_INVALIDPARAM;
896 caps->dwFlags = This->dsbd.dwFlags;
897 caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
899 caps->dwBufferBytes = This->buflen;
901 /* According to windows, this is zero*/
902 caps->dwUnlockTransferRate = 0;
903 caps->dwPlayCpuOverhead = 0;
905 return DS_OK;
908 static HRESULT WINAPI IDirectSoundBufferImpl_QueryInterface(IDirectSoundBuffer8 *iface, REFIID riid,
909 void **ppobj)
911 IDirectSoundBufferImpl *This = impl_from_IDirectSoundBuffer8(iface);
913 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
915 if (ppobj == NULL) {
916 WARN("invalid parameter\n");
917 return E_INVALIDARG;
920 *ppobj = NULL; /* assume failure */
922 if ( IsEqualGUID(riid, &IID_IUnknown) ||
923 IsEqualGUID(riid, &IID_IDirectSoundBuffer) ||
924 IsEqualGUID(riid, &IID_IDirectSoundBuffer8) ) {
925 IDirectSoundBuffer8_AddRef(iface);
926 *ppobj = iface;
927 return S_OK;
930 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
931 if(This->dsbd.dwFlags & DSBCAPS_CTRLPOSITIONNOTIFY) {
932 IDirectSoundNotify_AddRef(&This->IDirectSoundNotify_iface);
933 *ppobj = &This->IDirectSoundNotify_iface;
934 return S_OK;
937 TRACE( "App requested IDirectSoundNotify without DSBCAPS_CTRLPOSITIONNOTIFY flag.\n");
938 return E_NOINTERFACE;
941 if ( IsEqualGUID( &IID_IDirectSound3DBuffer, riid ) ) {
942 if(This->dsbd.dwFlags & DSBCAPS_CTRL3D){
943 IDirectSound3DBuffer_AddRef(&This->IDirectSound3DBuffer_iface);
944 *ppobj = &This->IDirectSound3DBuffer_iface;
945 return S_OK;
947 TRACE("app requested IDirectSound3DBuffer on non-3D secondary buffer\n");
948 return E_NOINTERFACE;
951 if ( IsEqualGUID( &IID_IDirectSound3DListener, riid ) ) {
952 ERR("app requested IDirectSound3DListener on secondary buffer\n");
953 return E_NOINTERFACE;
956 if ( IsEqualGUID( &IID_IKsPropertySet, riid ) ) {
957 IKsPropertySet_AddRef(&This->IKsPropertySet_iface);
958 *ppobj = &This->IKsPropertySet_iface;
959 return S_OK;
962 FIXME( "Unknown IID %s\n", debugstr_guid( riid ) );
964 return E_NOINTERFACE;
967 static const IDirectSoundBuffer8Vtbl dsbvt =
969 IDirectSoundBufferImpl_QueryInterface,
970 IDirectSoundBufferImpl_AddRef,
971 IDirectSoundBufferImpl_Release,
972 IDirectSoundBufferImpl_GetCaps,
973 IDirectSoundBufferImpl_GetCurrentPosition,
974 IDirectSoundBufferImpl_GetFormat,
975 IDirectSoundBufferImpl_GetVolume,
976 IDirectSoundBufferImpl_GetPan,
977 IDirectSoundBufferImpl_GetFrequency,
978 IDirectSoundBufferImpl_GetStatus,
979 IDirectSoundBufferImpl_Initialize,
980 IDirectSoundBufferImpl_Lock,
981 IDirectSoundBufferImpl_Play,
982 IDirectSoundBufferImpl_SetCurrentPosition,
983 IDirectSoundBufferImpl_SetFormat,
984 IDirectSoundBufferImpl_SetVolume,
985 IDirectSoundBufferImpl_SetPan,
986 IDirectSoundBufferImpl_SetFrequency,
987 IDirectSoundBufferImpl_Stop,
988 IDirectSoundBufferImpl_Unlock,
989 IDirectSoundBufferImpl_Restore,
990 IDirectSoundBufferImpl_SetFX,
991 IDirectSoundBufferImpl_AcquireResources,
992 IDirectSoundBufferImpl_GetObjectInPath
995 HRESULT secondarybuffer_create(DirectSoundDevice *device, const DSBUFFERDESC *dsbd,
996 IDirectSoundBuffer **buffer)
998 IDirectSoundBufferImpl *dsb;
999 LPWAVEFORMATEX wfex = dsbd->lpwfxFormat;
1000 HRESULT err = DS_OK;
1001 DWORD capf = 0;
1002 size_t bufsize;
1004 TRACE("(%p,%p,%p)\n", device, dsbd, buffer);
1006 if (dsbd->dwBufferBytes < DSBSIZE_MIN || dsbd->dwBufferBytes > DSBSIZE_MAX) {
1007 WARN("invalid parameter: dsbd->dwBufferBytes = %d\n", dsbd->dwBufferBytes);
1008 return DSERR_INVALIDPARAM; /* FIXME: which error? */
1011 dsb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(*dsb));
1013 if (!dsb)
1014 return DSERR_OUTOFMEMORY;
1016 TRACE("Created buffer at %p\n", dsb);
1018 dsb->ref = 1;
1019 dsb->refn = 0;
1020 dsb->ref3D = 0;
1021 dsb->refiks = 0;
1022 dsb->numIfaces = 1;
1023 dsb->device = device;
1024 dsb->IDirectSoundBuffer8_iface.lpVtbl = &dsbvt;
1025 dsb->IDirectSoundNotify_iface.lpVtbl = &dsnvt;
1026 dsb->IDirectSound3DBuffer_iface.lpVtbl = &ds3dbvt;
1027 dsb->IKsPropertySet_iface.lpVtbl = &iksbvt;
1029 /* size depends on version */
1030 CopyMemory(&dsb->dsbd, dsbd, dsbd->dwSize);
1032 dsb->pwfx = DSOUND_CopyFormat(wfex);
1033 if (!dsb->pwfx) {
1034 IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
1035 return DSERR_OUTOFMEMORY;
1038 if (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign)
1039 dsb->buflen = dsbd->dwBufferBytes +
1040 (dsbd->lpwfxFormat->nBlockAlign -
1041 (dsbd->dwBufferBytes % dsbd->lpwfxFormat->nBlockAlign));
1042 else
1043 dsb->buflen = dsbd->dwBufferBytes;
1045 dsb->freq = dsbd->lpwfxFormat->nSamplesPerSec;
1046 dsb->notifies = NULL;
1047 dsb->nrofnotifies = 0;
1049 /* Check necessary hardware mixing capabilities */
1050 if (wfex->nChannels==2) capf |= DSCAPS_SECONDARYSTEREO;
1051 else capf |= DSCAPS_SECONDARYMONO;
1052 if (wfex->wBitsPerSample==16) capf |= DSCAPS_SECONDARY16BIT;
1053 else capf |= DSCAPS_SECONDARY8BIT;
1055 TRACE("capf = 0x%08x, device->drvcaps.dwFlags = 0x%08x\n", capf, device->drvcaps.dwFlags);
1057 /* Allocate an empty buffer */
1058 bufsize = (sizeof(*(dsb->buffer)) + sizeof(void *) - 1) & ~(sizeof(void *) - 1);
1059 dsb->buffer = HeapAlloc(GetProcessHeap(),0,bufsize + dsb->buflen);
1060 if (!dsb->buffer) {
1061 IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
1062 return DSERR_OUTOFMEMORY;
1065 /* Allocate system memory for buffer */
1066 dsb->buffer->memory = (BYTE *)dsb->buffer + bufsize;
1068 dsb->buffer->ref = 1;
1069 dsb->buffer->lockedbytes = 0;
1070 list_init(&dsb->buffer->buffers);
1071 list_add_head(&dsb->buffer->buffers, &dsb->entry);
1072 FillMemory(dsb->buffer->memory, dsb->buflen, dsbd->lpwfxFormat->wBitsPerSample == 8 ? 128 : 0);
1074 /* It's not necessary to initialize values to zero since */
1075 /* we allocated this structure with HEAP_ZERO_MEMORY... */
1076 dsb->sec_mixpos = 0;
1077 dsb->state = STATE_STOPPED;
1079 dsb->freqAdjustNum = dsb->freq;
1080 dsb->freqAdjustDen = device->pwfx->nSamplesPerSec;
1081 dsb->nAvgBytesPerSec = dsb->freq *
1082 dsbd->lpwfxFormat->nBlockAlign;
1084 /* calculate fragment size and write lead */
1085 DSOUND_RecalcFormat(dsb);
1087 if (dsb->dsbd.dwFlags & DSBCAPS_CTRL3D) {
1088 dsb->ds3db_ds3db.dwSize = sizeof(DS3DBUFFER);
1089 dsb->ds3db_ds3db.vPosition.x = 0.0;
1090 dsb->ds3db_ds3db.vPosition.y = 0.0;
1091 dsb->ds3db_ds3db.vPosition.z = 0.0;
1092 dsb->ds3db_ds3db.vVelocity.x = 0.0;
1093 dsb->ds3db_ds3db.vVelocity.y = 0.0;
1094 dsb->ds3db_ds3db.vVelocity.z = 0.0;
1095 dsb->ds3db_ds3db.dwInsideConeAngle = DS3D_DEFAULTCONEANGLE;
1096 dsb->ds3db_ds3db.dwOutsideConeAngle = DS3D_DEFAULTCONEANGLE;
1097 dsb->ds3db_ds3db.vConeOrientation.x = 0.0;
1098 dsb->ds3db_ds3db.vConeOrientation.y = 0.0;
1099 dsb->ds3db_ds3db.vConeOrientation.z = 0.0;
1100 dsb->ds3db_ds3db.lConeOutsideVolume = DS3D_DEFAULTCONEOUTSIDEVOLUME;
1101 dsb->ds3db_ds3db.flMinDistance = DS3D_DEFAULTMINDISTANCE;
1102 dsb->ds3db_ds3db.flMaxDistance = DS3D_DEFAULTMAXDISTANCE;
1103 dsb->ds3db_ds3db.dwMode = DS3DMODE_NORMAL;
1105 dsb->ds3db_need_recalc = FALSE;
1106 DSOUND_Calc3DBuffer(dsb);
1107 } else
1108 DSOUND_RecalcVolPan(&(dsb->volpan));
1110 InitializeSRWLock(&dsb->lock);
1112 /* register buffer */
1113 err = DirectSoundDevice_AddBuffer(device, dsb);
1114 if (err == DS_OK)
1115 *buffer = (IDirectSoundBuffer*)&dsb->IDirectSoundBuffer8_iface;
1116 else
1117 IDirectSoundBuffer8_Release(&dsb->IDirectSoundBuffer8_iface);
1119 return err;
1122 void secondarybuffer_destroy(IDirectSoundBufferImpl *This)
1124 ULONG ref = InterlockedIncrement(&This->numIfaces);
1126 if (ref > 1)
1127 WARN("Destroying buffer with %u in use interfaces\n", ref - 1);
1129 if (This->dsbd.dwFlags & DSBCAPS_LOCHARDWARE)
1130 This->device->drvcaps.dwFreeHwMixingAllBuffers++;
1132 DirectSoundDevice_RemoveBuffer(This->device, This);
1134 This->buffer->ref--;
1135 list_remove(&This->entry);
1136 if (This->buffer->ref == 0)
1137 HeapFree(GetProcessHeap(), 0, This->buffer);
1139 HeapFree(GetProcessHeap(), 0, This->notifies);
1140 HeapFree(GetProcessHeap(), 0, This->pwfx);
1142 if (This->filters) {
1143 int i;
1144 for (i = 0; i < This->num_filters; i++) {
1145 IMediaObject_Release(This->filters[i].obj);
1146 if (This->filters[i].inplace) IMediaObjectInPlace_Release(This->filters[i].inplace);
1148 HeapFree(GetProcessHeap(), 0, This->filters);
1151 HeapFree(GetProcessHeap(), 0, This);
1153 TRACE("(%p) released\n", This);
1156 HRESULT IDirectSoundBufferImpl_Duplicate(
1157 DirectSoundDevice *device,
1158 IDirectSoundBufferImpl **ppdsb,
1159 IDirectSoundBufferImpl *pdsb)
1161 IDirectSoundBufferImpl *dsb;
1162 HRESULT hres = DS_OK;
1163 TRACE("(%p,%p,%p)\n", device, ppdsb, pdsb);
1165 dsb = HeapAlloc(GetProcessHeap(),0,sizeof(*dsb));
1166 if (dsb == NULL) {
1167 WARN("out of memory\n");
1168 *ppdsb = NULL;
1169 return DSERR_OUTOFMEMORY;
1172 AcquireSRWLockShared(&pdsb->lock);
1174 CopyMemory(dsb, pdsb, sizeof(*dsb));
1176 dsb->pwfx = DSOUND_CopyFormat(pdsb->pwfx);
1178 ReleaseSRWLockShared(&pdsb->lock);
1180 if (dsb->pwfx == NULL) {
1181 HeapFree(GetProcessHeap(),0,dsb);
1182 *ppdsb = NULL;
1183 return DSERR_OUTOFMEMORY;
1186 dsb->buffer->ref++;
1187 list_add_head(&dsb->buffer->buffers, &dsb->entry);
1188 dsb->ref = 0;
1189 dsb->refn = 0;
1190 dsb->ref3D = 0;
1191 dsb->refiks = 0;
1192 dsb->numIfaces = 0;
1193 dsb->state = STATE_STOPPED;
1194 dsb->sec_mixpos = 0;
1195 dsb->notifies = NULL;
1196 dsb->nrofnotifies = 0;
1197 dsb->device = device;
1198 DSOUND_RecalcFormat(dsb);
1200 InitializeSRWLock(&dsb->lock);
1202 /* register buffer */
1203 hres = DirectSoundDevice_AddBuffer(device, dsb);
1204 if (hres != DS_OK) {
1205 list_remove(&dsb->entry);
1206 dsb->buffer->ref--;
1207 HeapFree(GetProcessHeap(),0,dsb->pwfx);
1208 HeapFree(GetProcessHeap(),0,dsb);
1209 dsb = NULL;
1210 }else
1211 IDirectSoundBuffer8_AddRef(&dsb->IDirectSoundBuffer8_iface);
1213 *ppdsb = dsb;
1214 return hres;
1217 /*******************************************************************************
1218 * IKsPropertySet
1221 static inline IDirectSoundBufferImpl *impl_from_IKsPropertySet(IKsPropertySet *iface)
1223 return CONTAINING_RECORD(iface, IDirectSoundBufferImpl, IKsPropertySet_iface);
1226 /* IUnknown methods */
1227 static HRESULT WINAPI IKsPropertySetImpl_QueryInterface(IKsPropertySet *iface, REFIID riid,
1228 void **ppobj)
1230 IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
1232 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
1234 return IDirectSoundBuffer8_QueryInterface(&This->IDirectSoundBuffer8_iface, riid, ppobj);
1237 static ULONG WINAPI IKsPropertySetImpl_AddRef(IKsPropertySet *iface)
1239 IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
1240 ULONG ref = InterlockedIncrement(&This->refiks);
1242 TRACE("(%p) ref %d\n", This, ref);
1244 if(ref == 1)
1245 InterlockedIncrement(&This->numIfaces);
1247 return ref;
1250 static ULONG WINAPI IKsPropertySetImpl_Release(IKsPropertySet *iface)
1252 IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
1253 ULONG ref;
1255 if (is_primary_buffer(This)){
1256 ref = capped_refcount_dec(&This->refiks);
1257 if(!ref)
1258 capped_refcount_dec(&This->numIfaces);
1259 TRACE("(%p) ref %d\n", This, ref);
1260 return ref;
1263 ref = InterlockedDecrement(&This->refiks);
1264 if (!ref && !InterlockedDecrement(&This->numIfaces))
1265 secondarybuffer_destroy(This);
1267 TRACE("(%p) ref %d\n", This, ref);
1269 return ref;
1272 static HRESULT WINAPI IKsPropertySetImpl_Get(IKsPropertySet *iface, REFGUID guidPropSet,
1273 ULONG dwPropID, void *pInstanceData, ULONG cbInstanceData, void *pPropData,
1274 ULONG cbPropData, ULONG *pcbReturned)
1276 IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
1278 TRACE("(iface=%p,guidPropSet=%s,dwPropID=%d,pInstanceData=%p,cbInstanceData=%d,pPropData=%p,cbPropData=%d,pcbReturned=%p)\n",
1279 This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData,pcbReturned);
1281 return E_PROP_ID_UNSUPPORTED;
1284 static HRESULT WINAPI IKsPropertySetImpl_Set(IKsPropertySet *iface, REFGUID guidPropSet,
1285 ULONG dwPropID, void *pInstanceData, ULONG cbInstanceData, void *pPropData,
1286 ULONG cbPropData)
1288 IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
1290 TRACE("(%p,%s,%d,%p,%d,%p,%d)\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData);
1292 return E_PROP_ID_UNSUPPORTED;
1295 static HRESULT WINAPI IKsPropertySetImpl_QuerySupport(IKsPropertySet *iface, REFGUID guidPropSet,
1296 ULONG dwPropID, ULONG *pTypeSupport)
1298 IDirectSoundBufferImpl *This = impl_from_IKsPropertySet(iface);
1300 TRACE("(%p,%s,%d,%p)\n",This,debugstr_guid(guidPropSet),dwPropID,pTypeSupport);
1302 return E_PROP_ID_UNSUPPORTED;
1305 const IKsPropertySetVtbl iksbvt = {
1306 IKsPropertySetImpl_QueryInterface,
1307 IKsPropertySetImpl_AddRef,
1308 IKsPropertySetImpl_Release,
1309 IKsPropertySetImpl_Get,
1310 IKsPropertySetImpl_Set,
1311 IKsPropertySetImpl_QuerySupport