3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2001 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Implement DirectSoundFullDuplex support.
24 * Implement FX support.
30 #include <sys/types.h>
31 #include <sys/fcntl.h>
47 #include "wine/debug.h"
50 #include "dsound_private.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
54 static HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
55 LPDIRECTSOUNDCAPTURE iface,
57 static ULONG WINAPI IDirectSoundCaptureImpl_Release(
58 LPDIRECTSOUNDCAPTURE iface );
59 static ULONG WINAPI IDirectSoundCaptureBufferImpl_Release(
60 LPDIRECTSOUNDCAPTUREBUFFER8 iface );
61 static HRESULT DSOUND_CreateDirectSoundCaptureBuffer(
62 IDirectSoundCaptureImpl *ipDSC,
63 LPCDSCBUFFERDESC lpcDSCBufferDesc,
65 static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize(
66 LPDIRECTSOUNDFULLDUPLEX iface,
68 LPCGUID pRendererGuid,
69 LPCDSCBUFFERDESC lpDscBufferDesc,
70 LPCDSBUFFERDESC lpDsBufferDesc,
73 LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8,
74 LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 );
76 static ICOM_VTABLE(IDirectSoundCapture) dscvt;
77 static ICOM_VTABLE(IDirectSoundCaptureBuffer8) dscbvt;
78 static ICOM_VTABLE(IDirectSoundFullDuplex) dsfdvt;
80 IDirectSoundCaptureImpl* dsound_capture = NULL;
82 /***************************************************************************
83 * DirectSoundCaptureCreate [DSOUND.6]
85 * Create and initialize a DirectSoundCapture interface.
88 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
89 * lplpDSC [O] Address of a variable to receive the interface pointer.
90 * pUnkOuter [I] Must be NULL.
94 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
98 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
99 * or NULL for the default device or DSDEVID_DefaultCapture or
100 * DSDEVID_DefaultVoiceCapture.
102 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
105 DirectSoundCaptureCreate8(
107 LPDIRECTSOUNDCAPTURE* lplpDSC,
108 LPUNKNOWN pUnkOuter )
110 IDirectSoundCaptureImpl** ippDSC=(IDirectSoundCaptureImpl**)lplpDSC;
111 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), lplpDSC, pUnkOuter);
114 WARN("invalid parameter: pUnkOuter != NULL\n");
115 return DSERR_NOAGGREGATION;
119 WARN("invalid parameter: lplpDSC == NULL\n");
120 return DSERR_INVALIDPARAM;
123 /* Default device? */
124 if ( !lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL) )
125 lpcGUID = &DSDEVID_DefaultCapture;
127 *ippDSC = (IDirectSoundCaptureImpl*)HeapAlloc(GetProcessHeap(),
128 HEAP_ZERO_MEMORY, sizeof(IDirectSoundCaptureImpl));
130 if (*ippDSC == NULL) {
131 TRACE("couldn't allocate memory\n");
132 return DSERR_OUTOFMEMORY;
136 ICOM_THIS(IDirectSoundCaptureImpl, *ippDSC);
139 This->state = STATE_STOPPED;
141 InitializeCriticalSection( &(This->lock) );
143 This->lpVtbl = &dscvt;
144 dsound_capture = This;
146 if (GetDeviceID(lpcGUID, &This->guid) == DS_OK)
147 return IDirectSoundCaptureImpl_Initialize( (LPDIRECTSOUNDCAPTURE)This, &This->guid);
149 WARN("invalid GUID\n");
150 return DSERR_INVALIDPARAM;
153 /***************************************************************************
154 * DirectSoundCaptureEnumerateA [DSOUND.7]
156 * Enumerate all DirectSound drivers installed in the system.
159 * lpDSEnumCallback [I] Address of callback function.
160 * lpContext [I] Address of user defined context passed to callback function.
164 * Failure: DSERR_INVALIDPARAM
167 DirectSoundCaptureEnumerateA(
168 LPDSENUMCALLBACKA lpDSEnumCallback,
176 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
178 if (lpDSEnumCallback == NULL) {
179 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
180 return DSERR_INVALIDPARAM;
183 devs = waveInGetNumDevs();
185 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
187 for (wid = 0; wid < devs; ++wid) {
188 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
190 if (IsEqualGUID( &guid, &temp ) ) {
191 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
193 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
194 debugstr_guid(&DSDEVID_DefaultCapture),"Primary Sound Capture Driver",desc.szDrvName,lpContext);
195 if (lpDSEnumCallback((LPGUID)&DSDEVID_DefaultCapture, "Primary Sound Capture Driver", desc.szDrvName, lpContext) == FALSE)
204 for (wid = 0; wid < devs; ++wid) {
205 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
207 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
209 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
210 debugstr_guid(&guid),desc.szDesc,desc.szDrvName,lpContext);
211 if (lpDSEnumCallback(&guid, desc.szDesc, desc.szDrvName, lpContext) == FALSE)
220 /***************************************************************************
221 * DirectSoundCaptureEnumerateW [DSOUND.8]
223 * Enumerate all DirectSound drivers installed in the system.
226 * lpDSEnumCallback [I] Address of callback function.
227 * lpContext [I] Address of user defined context passed to callback function.
231 * Failure: DSERR_INVALIDPARAM
234 DirectSoundCaptureEnumerateW(
235 LPDSENUMCALLBACKW lpDSEnumCallback,
242 WCHAR wDesc[MAXPNAMELEN];
243 WCHAR wName[MAXPNAMELEN];
245 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
247 if (lpDSEnumCallback == NULL) {
248 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
249 return DSERR_INVALIDPARAM;
252 devs = waveInGetNumDevs();
254 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
256 for (wid = 0; wid < devs; ++wid) {
257 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
259 if (IsEqualGUID( &guid, &temp ) ) {
260 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
262 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
263 debugstr_guid(&DSDEVID_DefaultCapture),"Primary Sound Capture Driver",desc.szDrvName,lpContext);
264 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Capture Driver", -1,
265 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
266 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
267 wName, sizeof(wName)/sizeof(WCHAR) );
268 if (lpDSEnumCallback((LPGUID)&DSDEVID_DefaultCapture, wDesc, wName, lpContext) == FALSE)
277 for (wid = 0; wid < devs; ++wid) {
278 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
280 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
282 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
283 debugstr_guid(&DSDEVID_DefaultCapture),desc.szDesc,desc.szDrvName,lpContext);
284 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
285 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
286 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
287 wName, sizeof(wName)/sizeof(WCHAR) );
288 if (lpDSEnumCallback((LPGUID)&DSDEVID_DefaultCapture, wDesc, wName, lpContext) == FALSE)
298 DSOUND_capture_callback(
305 IDirectSoundCaptureImpl* This = (IDirectSoundCaptureImpl*)dwUser;
306 TRACE("(%p,%08x(%s),%08lx,%08lx,%08lx) entering at %ld\n",hwi,msg,
307 msg == MM_WIM_OPEN ? "MM_WIM_OPEN" : msg == MM_WIM_CLOSE ? "MM_WIM_CLOSE" :
308 msg == MM_WIM_DATA ? "MM_WIM_DATA" : "UNKNOWN",dwUser,dw1,dw2,GetTickCount());
310 if (msg == MM_WIM_DATA) {
311 EnterCriticalSection( &(This->lock) );
312 TRACE("DirectSoundCapture msg=MM_WIM_DATA, old This->state=%ld, old This->index=%d\n",This->state,This->index);
313 if (This->state != STATE_STOPPED) {
314 if (This->state == STATE_STARTING) {
316 mtime.wType = TIME_BYTES;
317 waveInGetPosition(This->hwi, &mtime, sizeof(mtime));
318 TRACE("mtime.u.cb=%ld,This->buflen=%ld\n", mtime.u.cb, This->buflen);
319 mtime.u.cb = mtime.u.cb % This->buflen;
320 This->read_position = mtime.u.cb;
321 This->state = STATE_CAPTURING;
323 This->index = (This->index + 1) % This->nrofpwaves;
324 waveInUnprepareHeader(hwi,&(This->pwave[This->index]),sizeof(WAVEHDR));
325 if (This->capture_buffer->notify && This->capture_buffer->notify->nrofnotifies)
326 SetEvent(This->capture_buffer->notify->notifies[This->index].hEventNotify);
327 if ( (This->index == 0) && !(This->capture_buffer->flags & DSCBSTART_LOOPING) ) {
328 TRACE("end of buffer\n");
329 This->state = STATE_STOPPED;
331 if (This->state == STATE_CAPTURING) {
332 waveInPrepareHeader(hwi,&(This->pwave[This->index]),sizeof(WAVEHDR));
333 waveInAddBuffer(hwi, &(This->pwave[This->index]), sizeof(WAVEHDR));
337 TRACE("DirectSoundCapture new This->state=%ld, new This->index=%d\n",This->state,This->index);
338 LeaveCriticalSection( &(This->lock) );
341 TRACE("completed\n");
344 static HRESULT WINAPI
345 IDirectSoundCaptureImpl_QueryInterface(
346 LPDIRECTSOUNDCAPTURE iface,
350 ICOM_THIS(IDirectSoundCaptureImpl,iface);
351 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
354 return IDsCaptureDriver_QueryInterface(This->driver, riid, ppobj);
360 IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface )
363 ICOM_THIS(IDirectSoundCaptureImpl,iface);
365 EnterCriticalSection( &(This->lock) );
367 TRACE( "(%p) was 0x%08lx\n", This, This->ref );
368 uRef = ++(This->ref);
371 IDsCaptureDriver_AddRef(This->driver);
373 LeaveCriticalSection( &(This->lock) );
379 IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface )
382 ICOM_THIS(IDirectSoundCaptureImpl,iface);
384 EnterCriticalSection( &(This->lock) );
386 TRACE( "(%p) was 0x%08lx\n", This, This->ref );
387 uRef = --(This->ref);
389 LeaveCriticalSection( &(This->lock) );
392 TRACE("deleting object\n");
393 if (This->capture_buffer)
394 IDirectSoundCaptureBufferImpl_Release(
395 (LPDIRECTSOUNDCAPTUREBUFFER8) This->capture_buffer);
398 IDsCaptureDriver_Close(This->driver);
399 IDsCaptureDriver_Release(This->driver);
402 DeleteCriticalSection( &(This->lock) );
403 HeapFree( GetProcessHeap(), 0, This );
404 dsound_capture = NULL;
407 TRACE( "returning 0x%08lx\n", uRef );
411 static HRESULT WINAPI
412 IDirectSoundCaptureImpl_CreateCaptureBuffer(
413 LPDIRECTSOUNDCAPTURE iface,
414 LPCDSCBUFFERDESC lpcDSCBufferDesc,
415 LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
419 ICOM_THIS(IDirectSoundCaptureImpl,iface);
421 TRACE( "(%p,%p,%p,%p)\n",This,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk );
423 if ( (This == NULL) || (lpcDSCBufferDesc== NULL) ||
424 (lplpDSCaptureBuffer == NULL) || pUnk ) {
425 WARN("invalid parameters\n");
426 return DSERR_INVALIDPARAM;
429 /* FIXME: We can only have one buffer so what do we do here? */
430 if (This->capture_buffer) {
431 WARN("already has buffer\n");
432 return DSERR_INVALIDPARAM; /* DSERR_GENERIC ? */
435 hr = DSOUND_CreateDirectSoundCaptureBuffer( This, lpcDSCBufferDesc,
436 (LPVOID*)lplpDSCaptureBuffer );
441 static HRESULT WINAPI
442 IDirectSoundCaptureImpl_GetCaps(
443 LPDIRECTSOUNDCAPTURE iface,
444 LPDSCCAPS lpDSCCaps )
446 ICOM_THIS(IDirectSoundCaptureImpl,iface);
447 TRACE("(%p,%p)\n",This,lpDSCCaps);
449 if ( (lpDSCCaps== NULL) || (lpDSCCaps->dwSize != sizeof(*lpDSCCaps)) ) {
450 WARN("invalid parameters\n");
451 return DSERR_INVALIDPARAM;
454 if ( !(This->initialized) ) {
455 WARN("not initialized\n");
456 return DSERR_UNINITIALIZED;
459 lpDSCCaps->dwFlags = This->drvcaps.dwFlags;
460 lpDSCCaps->dwFormats = This->drvcaps.dwFormats;
461 lpDSCCaps->dwChannels = This->drvcaps.dwChannels;
463 TRACE("(flags=0x%08lx,format=0x%08lx,channels=%ld)\n",lpDSCCaps->dwFlags,
464 lpDSCCaps->dwFormats, lpDSCCaps->dwChannels);
469 static HRESULT WINAPI
470 IDirectSoundCaptureImpl_Initialize(
471 LPDIRECTSOUNDCAPTURE iface,
474 HRESULT err = DSERR_INVALIDPARAM;
476 ICOM_THIS(IDirectSoundCaptureImpl,iface);
477 TRACE("(%p)\n", This);
480 WARN("invalid parameter\n");
481 return DSERR_INVALIDPARAM;
484 if (This->initialized) {
485 WARN("already initialized\n");
486 return DSERR_ALREADYINITIALIZED;
489 widn = waveInGetNumDevs();
492 WARN("no audio devices found\n");
493 return DSERR_NODRIVER;
496 /* Get dsound configuration */
497 setup_dsound_options();
499 /* enumerate WINMM audio devices and find the one we want */
500 for (wid=0; wid<widn; wid++) {
502 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)(&guid),0));
504 WARN("waveInMessage failed; err=%lx\n",err);
507 if (IsEqualGUID( lpcGUID, &guid) ) {
514 WARN("invalid parameter\n");
515 return DSERR_INVALIDPARAM;
518 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD)&(This->driver),0));
519 if ( (err != DS_OK) && (err != DSERR_UNSUPPORTED) ) {
520 WARN("waveInMessage failed; err=%lx\n",err);
525 /* Disable the direct sound driver to force emulation if requested. */
526 if (ds_hw_accel == DS_HW_ACCEL_EMULATION)
529 /* Get driver description */
531 TRACE("using DirectSound driver\n");
532 err = IDsCaptureDriver_GetDriverDesc(This->driver, &(This->drvdesc));
534 WARN("IDsCaptureDriver_GetDriverDesc failed\n");
538 TRACE("using WINMM\n");
539 /* if no DirectSound interface available, use WINMM API instead */
540 This->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN |
541 DSDDESC_DOMMSYSTEMSETFORMAT;
544 This->drvdesc.dnDevNode = wid;
546 /* open the DirectSound driver if available */
547 if (This->driver && (err == DS_OK))
548 err = IDsCaptureDriver_Open(This->driver);
551 This->initialized = TRUE;
553 /* the driver is now open, so it's now allowed to call GetCaps */
555 This->drvcaps.dwSize = sizeof(This->drvcaps);
556 err = IDsCaptureDriver_GetCaps(This->driver,&(This->drvcaps));
558 WARN("IDsCaptureDriver_GetCaps failed\n");
561 } else /*if (This->hwi)*/ {
563 err = mmErr(waveInGetDevCapsA((UINT)This->drvdesc.dnDevNode, &wic, sizeof(wic)));
566 This->drvcaps.dwFlags = 0;
567 strncpy(This->drvdesc.szDrvName, wic.szPname,
568 sizeof(This->drvdesc.szDrvName));
570 This->drvcaps.dwFlags |= DSCCAPS_EMULDRIVER;
571 This->drvcaps.dwFormats = wic.dwFormats;
572 This->drvcaps.dwChannels = wic.wChannels;
580 static ICOM_VTABLE(IDirectSoundCapture) dscvt =
582 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
583 /* IUnknown methods */
584 IDirectSoundCaptureImpl_QueryInterface,
585 IDirectSoundCaptureImpl_AddRef,
586 IDirectSoundCaptureImpl_Release,
588 /* IDirectSoundCapture methods */
589 IDirectSoundCaptureImpl_CreateCaptureBuffer,
590 IDirectSoundCaptureImpl_GetCaps,
591 IDirectSoundCaptureImpl_Initialize
595 DSOUND_CreateDirectSoundCaptureBuffer(
596 IDirectSoundCaptureImpl *ipDSC,
597 LPCDSCBUFFERDESC lpcDSCBufferDesc,
601 TRACE( "(%p,%p)\n", lpcDSCBufferDesc, ppobj );
603 if ( (ipDSC == NULL) || (lpcDSCBufferDesc == NULL) || (ppobj == NULL) ) {
604 WARN("invalid parameters\n");
605 return DSERR_INVALIDPARAM;
608 if ( (lpcDSCBufferDesc->dwSize < sizeof(DSCBUFFERDESC)) ||
609 (lpcDSCBufferDesc->dwBufferBytes == 0) ||
610 (lpcDSCBufferDesc->lpwfxFormat == NULL) ) {
611 WARN("invalid lpcDSCBufferDesc\n");
612 return DSERR_INVALIDPARAM;
615 if ( !ipDSC->initialized ) {
616 WARN("not initialized\n");
617 return DSERR_UNINITIALIZED;
620 wfex = lpcDSCBufferDesc->lpwfxFormat;
623 TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
624 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
625 wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
626 wfex->nAvgBytesPerSec, wfex->nBlockAlign,
627 wfex->wBitsPerSample, wfex->cbSize);
629 if (wfex->wFormatTag == WAVE_FORMAT_PCM)
630 memcpy(&(ipDSC->wfx), wfex, sizeof(WAVEFORMATEX));
632 WARN("non PCM formats not supported\n");
633 return DSERR_BADFORMAT;
636 WARN("lpcDSCBufferDesc->lpwfxFormat == 0\n");
637 return DSERR_INVALIDPARAM; /* FIXME: DSERR_BADFORMAT ? */
640 *ppobj = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
641 sizeof(IDirectSoundCaptureBufferImpl));
643 if ( *ppobj == NULL ) {
644 WARN("out of memory\n");
645 return DSERR_OUTOFMEMORY;
648 ICOM_THIS(IDirectSoundCaptureBufferImpl,*ppobj);
651 This->dsound = ipDSC;
652 This->dsound->capture_buffer = This;
654 This->pdscbd = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
655 lpcDSCBufferDesc->dwSize);
657 memcpy(This->pdscbd, lpcDSCBufferDesc, lpcDSCBufferDesc->dwSize);
660 This->dsound->capture_buffer = 0;
661 HeapFree( GetProcessHeap(), 0, This );
663 return DSERR_OUTOFMEMORY;
666 This->lpVtbl = &dscbvt;
669 err = IDsCaptureDriver_CreateCaptureBuffer(ipDSC->driver,
670 &(ipDSC->wfx),0,0,&(ipDSC->buflen),&(ipDSC->buffer),(LPVOID*)&(ipDSC->hwbuf));
672 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
673 This->dsound->capture_buffer = 0;
674 HeapFree( GetProcessHeap(), 0, This );
681 DWORD flags = CALLBACK_FUNCTION;
682 if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
683 flags |= WAVE_DIRECTSOUND;
684 err = mmErr(waveInOpen(&(ipDSC->hwi),
685 ipDSC->drvdesc.dnDevNode, &(ipDSC->wfx),
686 (DWORD)DSOUND_capture_callback, (DWORD)ipDSC, flags));
688 WARN("waveInOpen failed\n");
689 This->dsound->capture_buffer = 0;
690 HeapFree( GetProcessHeap(), 0, This );
695 buflen = lpcDSCBufferDesc->dwBufferBytes;
696 TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->buffer);
697 newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,ipDSC->buffer,buflen);
699 if (newbuf == NULL) {
700 WARN("failed to allocate capture buffer\n");
701 err = DSERR_OUTOFMEMORY;
702 /* but the old buffer might still exist and must be re-prepared */
704 ipDSC->buffer = newbuf;
705 ipDSC->buflen = buflen;
710 TRACE("returning DS_OK\n");
714 static HRESULT WINAPI
715 IDirectSoundCaptureBufferImpl_QueryInterface(
716 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
720 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
721 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
723 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ||
724 IsEqualGUID( &IID_IDirectSoundNotify8, riid ) ) {
726 This->notify = (IDirectSoundNotifyImpl*)HeapAlloc(GetProcessHeap(),
727 HEAP_ZERO_MEMORY, sizeof(*This->notify));
729 This->notify->ref = 0; /* release when ref = -1 */
730 This->notify->lpVtbl = &dsnvt;
734 if (This->dsound->hwbuf) {
737 err = IDsCaptureDriverBuffer_QueryInterface(This->dsound->hwbuf,
738 &IID_IDsDriverNotify, (LPVOID*)&(This->notify->hwnotify));
740 WARN("IDsCaptureDriverBuffer_QueryInterface failed\n");
746 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
747 *ppobj = (LPVOID)This->notify;
755 if ( IsEqualGUID( &IID_IDirectSoundCaptureBuffer, riid ) ||
756 IsEqualGUID( &IID_IDirectSoundCaptureBuffer8, riid ) ) {
757 IDirectSoundCaptureBuffer8_AddRef(iface);
762 FIXME("(%p,%s,%p) unsupported GUID\n", This, debugstr_guid(riid), ppobj);
766 return E_NOINTERFACE;
770 IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
773 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
774 TRACE( "(%p)\n", This );
776 assert(This->dsound);
778 EnterCriticalSection( &(This->dsound->lock) );
780 TRACE( "(%p) was 0x%08lx\n", This, This->ref );
781 uRef = ++(This->ref);
783 LeaveCriticalSection( &(This->dsound->lock) );
789 IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
792 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
793 TRACE( "(%p)\n", This );
795 assert(This->dsound);
797 EnterCriticalSection( &(This->dsound->lock) );
799 TRACE( "(%p) was 0x%08lx\n", This, This->ref );
800 uRef = --(This->ref);
802 LeaveCriticalSection( &(This->dsound->lock) );
805 TRACE("deleting object\n");
807 HeapFree(GetProcessHeap(),0, This->pdscbd);
809 if (This->dsound->hwi) {
810 waveInReset(This->dsound->hwi);
811 waveInClose(This->dsound->hwi);
812 if (This->dsound->pwave) {
813 HeapFree(GetProcessHeap(),0, This->dsound->pwave);
814 This->dsound->pwave = 0;
816 This->dsound->hwi = 0;
819 if (This->dsound->hwbuf)
820 IDsCaptureDriverBuffer_Release(This->dsound->hwbuf);
822 /* remove from IDirectSoundCaptureImpl */
824 This->dsound->capture_buffer = NULL;
826 ERR("does not reference dsound\n");
829 IDirectSoundNotify_Release((LPDIRECTSOUNDNOTIFY)This->notify);
831 HeapFree( GetProcessHeap(), 0, This );
834 TRACE( "returning 0x%08lx\n", uRef );
838 static HRESULT WINAPI
839 IDirectSoundCaptureBufferImpl_GetCaps(
840 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
841 LPDSCBCAPS lpDSCBCaps )
843 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
844 TRACE( "(%p,%p)\n", This, lpDSCBCaps );
846 if ( (This == NULL) || (lpDSCBCaps == NULL) ) {
847 WARN("invalid parameters\n");
848 return DSERR_INVALIDPARAM;
851 if ( (lpDSCBCaps->dwSize < sizeof(DSCBCAPS)) || (This->dsound == NULL) ) {
852 WARN("invalid parameters\n");
853 return DSERR_INVALIDPARAM;
856 lpDSCBCaps->dwSize = sizeof(DSCBCAPS);
857 lpDSCBCaps->dwFlags = This->flags;
858 lpDSCBCaps->dwBufferBytes = This->pdscbd->dwBufferBytes;
859 lpDSCBCaps->dwReserved = 0;
861 TRACE("returning DS_OK\n");
865 static HRESULT WINAPI
866 IDirectSoundCaptureBufferImpl_GetCurrentPosition(
867 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
868 LPDWORD lpdwCapturePosition,
869 LPDWORD lpdwReadPosition )
871 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
872 TRACE( "(%p,%p,%p)\n", This, lpdwCapturePosition, lpdwReadPosition );
874 if ( (This == NULL) || (This->dsound == NULL) ) {
875 WARN("invalid parameter\n");
876 return DSERR_INVALIDPARAM;
879 if (This->dsound->driver) {
880 return IDsCaptureDriverBuffer_GetPosition(This->dsound->hwbuf, lpdwCapturePosition, lpdwReadPosition );
881 } else if (This->dsound->hwi) {
882 EnterCriticalSection(&(This->dsound->lock));
883 TRACE("old This->dsound->state=%ld\n",This->dsound->state);
884 if (lpdwCapturePosition) {
886 mtime.wType = TIME_BYTES;
887 waveInGetPosition(This->dsound->hwi, &mtime, sizeof(mtime));
888 TRACE("mtime.u.cb=%ld,This->dsound->buflen=%ld\n", mtime.u.cb,
889 This->dsound->buflen);
890 mtime.u.cb = mtime.u.cb % This->dsound->buflen;
891 *lpdwCapturePosition = mtime.u.cb;
894 if (lpdwReadPosition) {
895 if (This->dsound->state == STATE_STARTING) {
896 if (lpdwCapturePosition)
897 This->dsound->read_position = *lpdwCapturePosition;
898 This->dsound->state = STATE_CAPTURING;
900 *lpdwReadPosition = This->dsound->read_position;
902 TRACE("new This->dsound->state=%ld\n",This->dsound->state);
903 LeaveCriticalSection(&(This->dsound->lock));
904 if (lpdwCapturePosition) TRACE("*lpdwCapturePosition=%ld\n",*lpdwCapturePosition);
905 if (lpdwReadPosition) TRACE("*lpdwReadPosition=%ld\n",*lpdwReadPosition);
908 return DSERR_NODRIVER;
911 TRACE("returning DS_OK\n");
915 static HRESULT WINAPI
916 IDirectSoundCaptureBufferImpl_GetFormat(
917 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
918 LPWAVEFORMATEX lpwfxFormat,
919 DWORD dwSizeAllocated,
920 LPDWORD lpdwSizeWritten )
922 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
923 TRACE( "(%p,%p,0x%08lx,%p)\n", This, lpwfxFormat, dwSizeAllocated,
926 if ( (This == NULL) || (This->dsound == NULL) ) {
927 WARN("invalid parameter\n");
928 return DSERR_INVALIDPARAM;
931 /* FIXME: use real size for extended formats someday */
932 if (dwSizeAllocated > sizeof(This->dsound->wfx))
933 dwSizeAllocated = sizeof(This->dsound->wfx);
934 if (lpwfxFormat) { /* NULL is valid (just want size) */
935 memcpy(lpwfxFormat,&(This->dsound->wfx),dwSizeAllocated);
937 *lpdwSizeWritten = dwSizeAllocated;
940 *lpdwSizeWritten = sizeof(This->dsound->wfx);
942 TRACE("invalid parameter\n");
943 return DSERR_INVALIDPARAM;
947 TRACE("returning DS_OK\n");
951 static HRESULT WINAPI
952 IDirectSoundCaptureBufferImpl_GetStatus(
953 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
956 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
957 TRACE( "(%p, %p), thread is %04lx\n", This, lpdwStatus, GetCurrentThreadId() );
959 if ( (This == NULL ) || (This->dsound == NULL) || (lpdwStatus == NULL) ) {
960 WARN("invalid parameter\n");
961 return DSERR_INVALIDPARAM;
965 EnterCriticalSection(&(This->dsound->lock));
967 TRACE("old This->dsound->state=%ld, old lpdwStatus=%08lx\n",This->dsound->state,*lpdwStatus);
968 if ((This->dsound->state == STATE_STARTING) ||
969 (This->dsound->state == STATE_CAPTURING)) {
970 *lpdwStatus |= DSCBSTATUS_CAPTURING;
971 if (This->flags & DSCBSTART_LOOPING)
972 *lpdwStatus |= DSCBSTATUS_LOOPING;
974 TRACE("new This->dsound->state=%ld, new lpdwStatus=%08lx\n",This->dsound->state,*lpdwStatus);
975 LeaveCriticalSection(&(This->dsound->lock));
977 TRACE("status=%lx\n", *lpdwStatus);
978 TRACE("returning DS_OK\n");
982 static HRESULT WINAPI
983 IDirectSoundCaptureBufferImpl_Initialize(
984 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
985 LPDIRECTSOUNDCAPTURE lpDSC,
986 LPCDSCBUFFERDESC lpcDSCBDesc )
988 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
990 FIXME( "(%p,%p,%p): stub\n", This, lpDSC, lpcDSCBDesc );
995 static HRESULT WINAPI
996 IDirectSoundCaptureBufferImpl_Lock(
997 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1000 LPVOID* lplpvAudioPtr1,
1001 LPDWORD lpdwAudioBytes1,
1002 LPVOID* lplpvAudioPtr2,
1003 LPDWORD lpdwAudioBytes2,
1006 HRESULT err = DS_OK;
1007 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1008 TRACE( "(%p,%08lu,%08lu,%p,%p,%p,%p,0x%08lx) at %ld\n", This, dwReadCusor,
1009 dwReadBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2,
1010 lpdwAudioBytes2, dwFlags, GetTickCount() );
1012 if ( (This == NULL) || (This->dsound == NULL) || (lplpvAudioPtr1 == NULL) ||
1013 (lpdwAudioBytes1 == NULL) ) {
1014 WARN("invalid parameter\n");
1015 return DSERR_INVALIDPARAM;
1018 EnterCriticalSection(&(This->dsound->lock));
1020 if (This->dsound->driver) {
1021 err = IDsCaptureDriverBuffer_Lock(This->dsound->hwbuf, lplpvAudioPtr1,
1022 lpdwAudioBytes1, lplpvAudioPtr2, lpdwAudioBytes2,
1023 dwReadCusor, dwReadBytes, dwFlags);
1024 } else if (This->dsound->hwi) {
1025 *lplpvAudioPtr1 = This->dsound->buffer + dwReadCusor;
1026 if ( (dwReadCusor + dwReadBytes) > This->dsound->buflen) {
1027 *lpdwAudioBytes1 = This->dsound->buflen - dwReadCusor;
1029 *lplpvAudioPtr2 = This->dsound->buffer;
1030 if (lpdwAudioBytes2)
1031 *lpdwAudioBytes2 = dwReadBytes - *lpdwAudioBytes1;
1033 *lpdwAudioBytes1 = dwReadBytes;
1035 *lplpvAudioPtr2 = 0;
1036 if (lpdwAudioBytes2)
1037 *lpdwAudioBytes2 = 0;
1040 TRACE("invalid call\n");
1041 err = DSERR_INVALIDCALL; /* DSERR_NODRIVER ? */
1044 LeaveCriticalSection(&(This->dsound->lock));
1049 static HRESULT WINAPI
1050 IDirectSoundCaptureBufferImpl_Start(
1051 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1054 HRESULT err = DS_OK;
1055 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1056 TRACE( "(%p,0x%08lx)\n", This, dwFlags );
1058 if ( (This == NULL) || (This->dsound == NULL) ) {
1059 WARN("invalid parameter\n");
1060 return DSERR_INVALIDPARAM;
1063 if ( (This->dsound->driver == 0) && (This->dsound->hwi == 0) ) {
1064 WARN("no driver\n");
1065 return DSERR_NODRIVER;
1068 EnterCriticalSection(&(This->dsound->lock));
1070 This->flags = dwFlags;
1071 TRACE("old This->dsound->state=%ld\n",This->dsound->state);
1072 if (This->dsound->state == STATE_STOPPED)
1073 This->dsound->state = STATE_STARTING;
1074 else if (This->dsound->state == STATE_STOPPING)
1075 This->dsound->state = STATE_CAPTURING;
1076 TRACE("new This->dsound->state=%ld\n",This->dsound->state);
1078 LeaveCriticalSection(&(This->dsound->lock));
1080 if (This->dsound->driver) {
1081 err = IDsCaptureDriverBuffer_Start(This->dsound->hwbuf, dwFlags);
1084 IDirectSoundCaptureImpl* ipDSC = This->dsound;
1086 if (ipDSC->buffer) {
1087 if (This->notify && This->notify->nrofnotifies) {
1090 ipDSC->nrofpwaves = This->notify->nrofnotifies;
1092 /* prepare headers */
1093 ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,
1094 ipDSC->nrofpwaves*sizeof(WAVEHDR));
1096 for (c = 0; c < ipDSC->nrofpwaves; c++) {
1098 ipDSC->pwave[0].lpData = ipDSC->buffer;
1099 ipDSC->pwave[0].dwBufferLength =
1100 This->notify->notifies[0].dwOffset + 1;
1102 ipDSC->pwave[c].lpData = ipDSC->buffer +
1103 This->notify->notifies[c-1].dwOffset + 1;
1104 ipDSC->pwave[c].dwBufferLength =
1105 This->notify->notifies[c].dwOffset -
1106 This->notify->notifies[c-1].dwOffset;
1108 ipDSC->pwave[c].dwUser = (DWORD)ipDSC;
1109 ipDSC->pwave[c].dwFlags = 0;
1110 ipDSC->pwave[c].dwLoops = 0;
1111 err = mmErr(waveInPrepareHeader(ipDSC->hwi,
1112 &(ipDSC->pwave[c]),sizeof(WAVEHDR)));
1115 waveInUnprepareHeader(ipDSC->hwi,
1116 &(ipDSC->pwave[c]),sizeof(WAVEHDR));
1121 memset(ipDSC->buffer,
1122 (ipDSC->wfx.wBitsPerSample == 16) ? 0 : 128, ipDSC->buflen);
1124 TRACE("no notifiers specified\n");
1125 /* no notifiers specified so just create a single default header */
1126 ipDSC->nrofpwaves = 1;
1127 ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,sizeof(WAVEHDR));
1128 ipDSC->pwave[0].lpData = ipDSC->buffer;
1129 ipDSC->pwave[0].dwBufferLength = ipDSC->buflen;
1130 ipDSC->pwave[0].dwUser = (DWORD)ipDSC;
1131 ipDSC->pwave[0].dwFlags = 0;
1132 ipDSC->pwave[0].dwLoops = 0;
1134 err = mmErr(waveInPrepareHeader(ipDSC->hwi,
1135 &(ipDSC->pwave[0]),sizeof(WAVEHDR)));
1137 waveInUnprepareHeader(ipDSC->hwi,
1138 &(ipDSC->pwave[0]),sizeof(WAVEHDR));
1144 ipDSC->read_position = 0;
1147 err = mmErr(waveInReset(ipDSC->hwi));
1149 /* add the first buffer to the queue */
1150 err = mmErr(waveInAddBuffer(ipDSC->hwi, &(ipDSC->pwave[0]), sizeof(WAVEHDR)));
1152 /* start filling the first buffer */
1153 err = mmErr(waveInStart(ipDSC->hwi));
1160 WARN("calling waveInClose because of error\n");
1161 waveInClose(This->dsound->hwi);
1162 This->dsound->hwi = 0;
1165 TRACE("returning %ld\n", err);
1169 static HRESULT WINAPI
1170 IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
1172 HRESULT err = DS_OK;
1173 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1174 TRACE( "(%p)\n", This );
1176 if ( (This == NULL) || (This->dsound == NULL) ) {
1177 WARN("invalid parameter\n");
1178 return DSERR_INVALIDPARAM;
1181 EnterCriticalSection(&(This->dsound->lock));
1183 TRACE("old This->dsound->state=%ld\n",This->dsound->state);
1184 if (This->dsound->state == STATE_CAPTURING)
1185 This->dsound->state = STATE_STOPPING;
1186 else if (This->dsound->state == STATE_STARTING)
1187 This->dsound->state = STATE_STOPPED;
1188 TRACE("new This->dsound->state=%ld\n",This->dsound->state);
1190 LeaveCriticalSection(&(This->dsound->lock));
1192 if (This->dsound->driver) {
1193 err = IDsCaptureDriverBuffer_Stop(This->dsound->hwbuf);
1194 if (err == DSERR_BUFFERLOST) {
1195 /* Wine-only: the driver wants us to reopen the device */
1196 IDsCaptureDriverBuffer_Release(This->dsound->hwbuf);
1197 err = IDsCaptureDriver_CreateCaptureBuffer(This->dsound->driver,
1198 &(This->dsound->wfx),0,0,&(This->dsound->buflen),&(This->dsound->buffer),
1199 (LPVOID*)&(This->dsound->hwbuf));
1201 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
1202 This->dsound->hwbuf = 0;
1205 } else if (This->dsound->hwi) {
1206 err = waveInStop(This->dsound->hwi);
1208 WARN("no driver\n");
1209 err = DSERR_NODRIVER;
1212 TRACE( "(%p) returning 0x%08lx\n", This,err);
1216 static HRESULT WINAPI
1217 IDirectSoundCaptureBufferImpl_Unlock(
1218 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1219 LPVOID lpvAudioPtr1,
1220 DWORD dwAudioBytes1,
1221 LPVOID lpvAudioPtr2,
1222 DWORD dwAudioBytes2 )
1224 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1225 TRACE( "(%p,%p,%08lu,%p,%08lu)\n", This, lpvAudioPtr1, dwAudioBytes1,
1226 lpvAudioPtr2, dwAudioBytes2 );
1228 if ( (This == NULL) || (lpvAudioPtr1 == NULL) ) {
1229 WARN("invalid parameters\n");
1230 return DSERR_INVALIDPARAM;
1233 if (This->dsound->driver) {
1234 return IDsCaptureDriverBuffer_Unlock(This->dsound->hwbuf, lpvAudioPtr1,
1235 dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1236 } else if (This->dsound->hwi) {
1237 This->dsound->read_position = (This->dsound->read_position +
1238 (dwAudioBytes1 + dwAudioBytes2)) % This->dsound->buflen;
1240 WARN("invalid call\n");
1241 return DSERR_INVALIDCALL;
1247 static HRESULT WINAPI
1248 IDirectSoundCaptureBufferImpl_GetObjectInPath(
1249 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1250 REFGUID rguidObject,
1252 REFGUID rguidInterface,
1255 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1257 FIXME( "(%p,%s,%lu,%s,%p): stub\n", This, debugstr_guid(rguidObject),
1258 dwIndex, debugstr_guid(rguidInterface), ppObject );
1263 static HRESULT WINAPI
1264 IDirectSoundCaptureBufferImpl_GetFXStatus(
1265 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1267 LPDWORD pdwFXStatus )
1269 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1271 FIXME( "(%p,%lu,%p): stub\n", This, dwFXCount, pdwFXStatus );
1276 static ICOM_VTABLE(IDirectSoundCaptureBuffer8) dscbvt =
1278 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1279 /* IUnknown methods */
1280 IDirectSoundCaptureBufferImpl_QueryInterface,
1281 IDirectSoundCaptureBufferImpl_AddRef,
1282 IDirectSoundCaptureBufferImpl_Release,
1284 /* IDirectSoundCaptureBuffer methods */
1285 IDirectSoundCaptureBufferImpl_GetCaps,
1286 IDirectSoundCaptureBufferImpl_GetCurrentPosition,
1287 IDirectSoundCaptureBufferImpl_GetFormat,
1288 IDirectSoundCaptureBufferImpl_GetStatus,
1289 IDirectSoundCaptureBufferImpl_Initialize,
1290 IDirectSoundCaptureBufferImpl_Lock,
1291 IDirectSoundCaptureBufferImpl_Start,
1292 IDirectSoundCaptureBufferImpl_Stop,
1293 IDirectSoundCaptureBufferImpl_Unlock,
1295 /* IDirectSoundCaptureBuffer methods */
1296 IDirectSoundCaptureBufferImpl_GetObjectInPath,
1297 IDirectSoundCaptureBufferImpl_GetFXStatus
1300 /***************************************************************************
1301 * DirectSoundFullDuplexCreate8 [DSOUND.10]
1303 * Create and initialize a DirectSoundFullDuplex interface.
1306 * pcGuidCaptureDevice [I] Address of sound capture device GUID.
1307 * pcGuidRenderDevice [I] Address of sound render device GUID.
1308 * pcDSCBufferDesc [I] Address of capture buffer description.
1309 * pcDSBufferDesc [I] Address of render buffer description.
1310 * hWnd [I] Handle to application window.
1311 * dwLevel [I] Cooperative level.
1312 * ppDSFD [O] Address where full duplex interface returned.
1313 * ppDSCBuffer8 [0] Address where capture buffer interface returned.
1314 * ppDSBuffer8 [0] Address where render buffer interface returned.
1315 * pUnkOuter [I] Must be NULL.
1319 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
1320 * DSERR_OUTOFMEMORY DSERR_INVALIDCALL DSERR_NODRIVER
1323 DirectSoundFullDuplexCreate8(
1324 LPCGUID pcGuidCaptureDevice,
1325 LPCGUID pcGuidRenderDevice,
1326 LPCDSCBUFFERDESC pcDSCBufferDesc,
1327 LPCDSBUFFERDESC pcDSBufferDesc,
1330 LPDIRECTSOUNDFULLDUPLEX *ppDSFD,
1331 LPDIRECTSOUNDCAPTUREBUFFER8 *ppDSCBuffer8,
1332 LPDIRECTSOUNDBUFFER8 *ppDSBuffer8,
1333 LPUNKNOWN pUnkOuter)
1335 IDirectSoundFullDuplexImpl** ippDSFD=(IDirectSoundFullDuplexImpl**)ppDSFD;
1336 TRACE("(%s,%s,%p,%p,%lx,%lx,%p,%p,%p,%p)\n", debugstr_guid(pcGuidCaptureDevice),
1337 debugstr_guid(pcGuidRenderDevice), pcDSCBufferDesc, pcDSBufferDesc,
1338 (DWORD)hWnd, dwLevel, ppDSFD, ppDSCBuffer8, ppDSBuffer8, pUnkOuter);
1341 WARN("pUnkOuter != 0\n");
1342 return DSERR_NOAGGREGATION;
1345 *ippDSFD = (IDirectSoundFullDuplexImpl*)HeapAlloc(GetProcessHeap(),
1346 HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
1348 if (*ippDSFD == NULL) {
1349 TRACE("couldn't allocate memory\n");
1350 return DSERR_OUTOFMEMORY;
1354 ICOM_THIS(IDirectSoundFullDuplexImpl, *ippDSFD);
1357 This->lpVtbl = &dsfdvt;
1359 InitializeCriticalSection( &(This->lock) );
1361 return IDirectSoundFullDuplexImpl_Initialize( (LPDIRECTSOUNDFULLDUPLEX)This,
1362 pcGuidCaptureDevice, pcGuidRenderDevice,
1363 pcDSCBufferDesc, pcDSBufferDesc,
1364 hWnd, dwLevel, ppDSCBuffer8, ppDSBuffer8);
1368 static HRESULT WINAPI
1369 IDirectSoundFullDuplexImpl_QueryInterface(
1370 LPDIRECTSOUNDFULLDUPLEX iface,
1374 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1375 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
1381 IDirectSoundFullDuplexImpl_AddRef( LPDIRECTSOUNDFULLDUPLEX iface )
1384 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1386 EnterCriticalSection( &(This->lock) );
1388 TRACE( "(%p) was 0x%08lx\n", This, This->ref );
1389 uRef = ++(This->ref);
1391 LeaveCriticalSection( &(This->lock) );
1397 IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface )
1400 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1402 EnterCriticalSection( &(This->lock) );
1404 TRACE( "(%p) was 0x%08lx\n", This, This->ref );
1405 uRef = --(This->ref);
1407 LeaveCriticalSection( &(This->lock) );
1410 TRACE("deleting object\n");
1411 DeleteCriticalSection( &(This->lock) );
1412 HeapFree( GetProcessHeap(), 0, This );
1418 static HRESULT WINAPI
1419 IDirectSoundFullDuplexImpl_Initialize(
1420 LPDIRECTSOUNDFULLDUPLEX iface,
1421 LPCGUID pCaptureGuid,
1422 LPCGUID pRendererGuid,
1423 LPCDSCBUFFERDESC lpDscBufferDesc,
1424 LPCDSBUFFERDESC lpDsBufferDesc,
1427 LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8,
1428 LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 )
1430 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1431 IDirectSoundCaptureBufferImpl** ippdscb=(IDirectSoundCaptureBufferImpl**)lplpDirectSoundCaptureBuffer8;
1432 IDirectSoundBufferImpl** ippdsc=(IDirectSoundBufferImpl**)lplpDirectSoundBuffer8;
1434 TRACE( "(%p,%s,%s,%p,%p,%lx,%lx,%p,%p)\n", This, debugstr_guid(pCaptureGuid),
1435 debugstr_guid(pRendererGuid), lpDscBufferDesc, lpDsBufferDesc, (DWORD)hWnd, dwLevel,
1441 static ICOM_VTABLE(IDirectSoundFullDuplex) dsfdvt =
1443 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1444 /* IUnknown methods */
1445 IDirectSoundFullDuplexImpl_QueryInterface,
1446 IDirectSoundFullDuplexImpl_AddRef,
1447 IDirectSoundFullDuplexImpl_Release,
1449 /* IDirectSoundFullDuplex methods */
1450 IDirectSoundFullDuplexImpl_Initialize