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.
31 #include <sys/types.h>
32 #include <sys/fcntl.h>
49 #include "wine/debug.h"
52 #include "dsound_private.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
56 static HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
57 LPDIRECTSOUNDCAPTURE iface,
59 static ULONG WINAPI IDirectSoundCaptureImpl_Release(
60 LPDIRECTSOUNDCAPTURE iface );
61 static ULONG WINAPI IDirectSoundCaptureBufferImpl_Release(
62 LPDIRECTSOUNDCAPTUREBUFFER8 iface );
63 static HRESULT DSOUND_CreateDirectSoundCaptureBuffer(
64 IDirectSoundCaptureImpl *ipDSC,
65 LPCDSCBUFFERDESC lpcDSCBufferDesc,
67 static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize(
68 LPDIRECTSOUNDFULLDUPLEX iface,
70 LPCGUID pRendererGuid,
71 LPCDSCBUFFERDESC lpDscBufferDesc,
72 LPCDSBUFFERDESC lpDsBufferDesc,
75 LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8,
76 LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 );
78 static ICOM_VTABLE(IDirectSoundCapture) dscvt;
79 static ICOM_VTABLE(IDirectSoundCaptureBuffer8) dscbvt;
80 static ICOM_VTABLE(IDirectSoundFullDuplex) dsfdvt;
82 static IDirectSoundCaptureImpl* dsound_capture = NULL;
83 static GUID capture_guids[MAXWAVEDRIVERS];
85 static const char * captureStateString[] = {
92 /***************************************************************************
93 * DirectSoundCaptureCreate [DSOUND.6]
95 * Create and initialize a DirectSoundCapture interface.
98 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
99 * lplpDSC [O] Address of a variable to receive the interface pointer.
100 * pUnkOuter [I] Must be NULL.
104 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
108 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
109 * or NULL for the default device or DSDEVID_DefaultCapture or
110 * DSDEVID_DefaultVoiceCapture.
112 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
115 DirectSoundCaptureCreate8(
117 LPDIRECTSOUNDCAPTURE* lplpDSC,
118 LPUNKNOWN pUnkOuter )
120 IDirectSoundCaptureImpl** ippDSC=(IDirectSoundCaptureImpl**)lplpDSC;
121 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), lplpDSC, pUnkOuter);
124 WARN("invalid parameter: pUnkOuter != NULL\n");
125 return DSERR_NOAGGREGATION;
129 WARN("invalid parameter: lplpDSC == NULL\n");
130 return DSERR_INVALIDPARAM;
133 /* Default device? */
134 if ( !lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL) )
135 lpcGUID = &DSDEVID_DefaultCapture;
137 *ippDSC = (IDirectSoundCaptureImpl*)HeapAlloc(GetProcessHeap(),
138 HEAP_ZERO_MEMORY, sizeof(IDirectSoundCaptureImpl));
140 if (*ippDSC == NULL) {
141 WARN("out of memory\n");
142 return DSERR_OUTOFMEMORY;
144 ICOM_THIS(IDirectSoundCaptureImpl, *ippDSC);
147 This->state = STATE_STOPPED;
149 InitializeCriticalSection( &(This->lock) );
150 This->lock.DebugInfo->Spare[1] = (DWORD)"DSCAPTURE_lock";
152 This->lpVtbl = &dscvt;
153 dsound_capture = This;
155 if (GetDeviceID(lpcGUID, &This->guid) == DS_OK) {
157 hres = IDirectSoundCaptureImpl_Initialize( (LPDIRECTSOUNDCAPTURE)This, &This->guid);
159 WARN("IDirectSoundCaptureImpl_Initialize failed\n");
163 WARN("invalid GUID: %s\n", debugstr_guid(lpcGUID));
164 return DSERR_INVALIDPARAM;
167 /***************************************************************************
168 * DirectSoundCaptureEnumerateA [DSOUND.7]
170 * Enumerate all DirectSound drivers installed in the system.
173 * lpDSEnumCallback [I] Address of callback function.
174 * lpContext [I] Address of user defined context passed to callback function.
178 * Failure: DSERR_INVALIDPARAM
181 DirectSoundCaptureEnumerateA(
182 LPDSENUMCALLBACKA lpDSEnumCallback,
190 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
192 if (lpDSEnumCallback == NULL) {
193 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
194 return DSERR_INVALIDPARAM;
197 devs = waveInGetNumDevs();
199 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
201 for (wid = 0; wid < devs; ++wid) {
202 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
204 if (IsEqualGUID( &guid, &temp ) ) {
205 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
207 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
208 "Primary Sound Capture Driver",desc.szDrvName,lpContext);
209 if (lpDSEnumCallback(NULL, "Primary Sound Capture Driver", desc.szDrvName, lpContext) == FALSE)
218 for (wid = 0; wid < devs; ++wid) {
219 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
221 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&capture_guids[wid],0));
223 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
224 debugstr_guid(&capture_guids[wid]),desc.szDesc,desc.szDrvName,lpContext);
225 if (lpDSEnumCallback(&capture_guids[wid], desc.szDesc, desc.szDrvName, lpContext) == FALSE)
234 /***************************************************************************
235 * DirectSoundCaptureEnumerateW [DSOUND.8]
237 * Enumerate all DirectSound drivers installed in the system.
240 * lpDSEnumCallback [I] Address of callback function.
241 * lpContext [I] Address of user defined context passed to callback function.
245 * Failure: DSERR_INVALIDPARAM
248 DirectSoundCaptureEnumerateW(
249 LPDSENUMCALLBACKW lpDSEnumCallback,
256 WCHAR wDesc[MAXPNAMELEN];
257 WCHAR wName[MAXPNAMELEN];
259 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
261 if (lpDSEnumCallback == NULL) {
262 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
263 return DSERR_INVALIDPARAM;
266 devs = waveInGetNumDevs();
268 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
270 for (wid = 0; wid < devs; ++wid) {
271 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
273 if (IsEqualGUID( &guid, &temp ) ) {
274 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
276 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
277 "Primary Sound Capture Driver",desc.szDrvName,lpContext);
278 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Capture Driver", -1,
279 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
280 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
281 wName, sizeof(wName)/sizeof(WCHAR) );
282 if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
291 for (wid = 0; wid < devs; ++wid) {
292 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
294 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&capture_guids[wid],0));
296 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
297 debugstr_guid(&capture_guids[wid]),desc.szDesc,desc.szDrvName,lpContext);
298 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
299 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
300 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
301 wName, sizeof(wName)/sizeof(WCHAR) );
302 if (lpDSEnumCallback((LPGUID)&capture_guids[wid], wDesc, wName, lpContext) == FALSE)
312 DSOUND_capture_callback(
319 IDirectSoundCaptureImpl* This = (IDirectSoundCaptureImpl*)dwUser;
320 TRACE("(%p,%08x(%s),%08lx,%08lx,%08lx) entering at %ld\n",hwi,msg,
321 msg == MM_WIM_OPEN ? "MM_WIM_OPEN" : msg == MM_WIM_CLOSE ? "MM_WIM_CLOSE" :
322 msg == MM_WIM_DATA ? "MM_WIM_DATA" : "UNKNOWN",dwUser,dw1,dw2,GetTickCount());
324 if (msg == MM_WIM_DATA) {
325 LPWAVEHDR pHdr = (LPWAVEHDR)dw1;
326 EnterCriticalSection( &(This->lock) );
327 TRACE("DirectSoundCapture msg=MM_WIM_DATA, old This->state=%s, old This->index=%d\n",
328 captureStateString[This->state],This->index);
329 if (This->state != STATE_STOPPED) {
330 int index = This->index;
331 if (This->state == STATE_STARTING) {
332 This->read_position = pHdr->dwBytesRecorded;
333 This->state = STATE_CAPTURING;
335 waveInUnprepareHeader(hwi,&(This->pwave[This->index]),sizeof(WAVEHDR));
336 if (This->capture_buffer->nrofnotifies)
337 SetEvent(This->capture_buffer->notifies[This->index].hEventNotify);
338 This->index = (This->index + 1) % This->nrofpwaves;
339 if ( (This->index == 0) && !(This->capture_buffer->flags & DSCBSTART_LOOPING) ) {
340 TRACE("end of buffer\n");
341 This->state = STATE_STOPPED;
343 if (This->state == STATE_CAPTURING) {
344 waveInPrepareHeader(hwi,&(This->pwave[index]),sizeof(WAVEHDR));
345 waveInAddBuffer(hwi, &(This->pwave[index]), sizeof(WAVEHDR));
346 } else if (This->state == STATE_STOPPING) {
348 This->state = STATE_STOPPED;
352 TRACE("DirectSoundCapture new This->state=%s, new This->index=%d\n",
353 captureStateString[This->state],This->index);
354 LeaveCriticalSection( &(This->lock) );
357 TRACE("completed\n");
360 static HRESULT WINAPI
361 IDirectSoundCaptureImpl_QueryInterface(
362 LPDIRECTSOUNDCAPTURE iface,
366 ICOM_THIS(IDirectSoundCaptureImpl,iface);
367 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
370 WARN("invalid parameter\n");
378 hres = IDsCaptureDriver_QueryInterface(This->driver, riid, ppobj);
380 WARN("IDsCaptureDriver_QueryInterface failed\n");
384 WARN("unsupported riid: %s\n", debugstr_guid(riid));
389 IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface )
392 ICOM_THIS(IDirectSoundCaptureImpl,iface);
393 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
395 EnterCriticalSection( &(This->lock) );
396 uRef = ++(This->ref);
399 IDsCaptureDriver_AddRef(This->driver);
401 LeaveCriticalSection( &(This->lock) );
407 IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface )
410 ICOM_THIS(IDirectSoundCaptureImpl,iface);
411 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
413 EnterCriticalSection( &(This->lock) );
415 uRef = --(This->ref);
417 LeaveCriticalSection( &(This->lock) );
420 TRACE("deleting object\n");
422 IDsCaptureDriver_Close(This->driver);
423 IDsCaptureDriver_Release(This->driver);
426 if (This->capture_buffer)
427 IDirectSoundCaptureBufferImpl_Release(
428 (LPDIRECTSOUNDCAPTUREBUFFER8) This->capture_buffer);
431 HeapFree(GetProcessHeap(), 0, This->pwfx);
433 DeleteCriticalSection( &(This->lock) );
434 HeapFree( GetProcessHeap(), 0, This );
435 dsound_capture = NULL;
436 TRACE("(%p) released\n",This);
442 static HRESULT WINAPI
443 IDirectSoundCaptureImpl_CreateCaptureBuffer(
444 LPDIRECTSOUNDCAPTURE iface,
445 LPCDSCBUFFERDESC lpcDSCBufferDesc,
446 LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
450 ICOM_THIS(IDirectSoundCaptureImpl,iface);
452 TRACE( "(%p,%p,%p,%p)\n",This,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk );
455 WARN("invalid parameter: This == NULL\n");
456 return DSERR_INVALIDPARAM;
459 if (lpcDSCBufferDesc == NULL) {
460 WARN("invalid parameter: lpcDSCBufferDesc == NULL)\n");
461 return DSERR_INVALIDPARAM;
464 if (lplpDSCaptureBuffer == NULL) {
465 WARN("invalid parameter: lplpDSCaptureBuffer == NULL\n");
466 return DSERR_INVALIDPARAM;
470 WARN("invalid parameter: pUnk != NULL\n");
471 return DSERR_INVALIDPARAM;
474 /* FIXME: We can only have one buffer so what do we do here? */
475 if (This->capture_buffer) {
476 WARN("lnvalid parameter: already has buffer\n");
477 return DSERR_INVALIDPARAM; /* DSERR_GENERIC ? */
480 hr = DSOUND_CreateDirectSoundCaptureBuffer( This, lpcDSCBufferDesc,
481 (LPVOID*)lplpDSCaptureBuffer );
484 WARN("DSOUND_CreateDirectSoundCaptureBuffer failed\n");
489 static HRESULT WINAPI
490 IDirectSoundCaptureImpl_GetCaps(
491 LPDIRECTSOUNDCAPTURE iface,
492 LPDSCCAPS lpDSCCaps )
494 ICOM_THIS(IDirectSoundCaptureImpl,iface);
495 TRACE("(%p,%p)\n",This,lpDSCCaps);
497 if (lpDSCCaps== NULL) {
498 WARN("invalid parameter: lpDSCCaps== NULL\n");
499 return DSERR_INVALIDPARAM;
502 if (lpDSCCaps->dwSize < sizeof(*lpDSCCaps)) {
503 WARN("invalid parameter: lpDSCCaps->dwSize = %ld < %d\n",
504 lpDSCCaps->dwSize, sizeof(*lpDSCCaps));
505 return DSERR_INVALIDPARAM;
508 if ( !(This->initialized) ) {
509 WARN("not initialized\n");
510 return DSERR_UNINITIALIZED;
513 lpDSCCaps->dwFlags = This->drvcaps.dwFlags;
514 lpDSCCaps->dwFormats = This->drvcaps.dwFormats;
515 lpDSCCaps->dwChannels = This->drvcaps.dwChannels;
517 TRACE("(flags=0x%08lx,format=0x%08lx,channels=%ld)\n",lpDSCCaps->dwFlags,
518 lpDSCCaps->dwFormats, lpDSCCaps->dwChannels);
523 static HRESULT WINAPI
524 IDirectSoundCaptureImpl_Initialize(
525 LPDIRECTSOUNDCAPTURE iface,
528 HRESULT err = DSERR_INVALIDPARAM;
530 ICOM_THIS(IDirectSoundCaptureImpl,iface);
531 TRACE("(%p)\n", This);
534 WARN("invalid parameter: This == NULL\n");
535 return DSERR_INVALIDPARAM;
538 if (This->initialized) {
539 WARN("already initialized\n");
540 return DSERR_ALREADYINITIALIZED;
543 widn = waveInGetNumDevs();
546 WARN("no audio devices found\n");
547 return DSERR_NODRIVER;
550 /* Get dsound configuration */
551 setup_dsound_options();
553 /* enumerate WINMM audio devices and find the one we want */
554 for (wid=0; wid<widn; wid++) {
556 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)(&guid),0));
558 WARN("waveInMessage failed; err=%lx\n",err);
561 if (IsEqualGUID( lpcGUID, &guid) ) {
568 WARN("invalid parameter\n");
569 return DSERR_INVALIDPARAM;
572 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD)&(This->driver),0));
573 if ( (err != DS_OK) && (err != DSERR_UNSUPPORTED) ) {
574 WARN("waveInMessage failed; err=%lx\n",err);
579 /* Disable the direct sound driver to force emulation if requested. */
580 if (ds_hw_accel == DS_HW_ACCEL_EMULATION)
583 /* Get driver description */
585 TRACE("using DirectSound driver\n");
586 err = IDsCaptureDriver_GetDriverDesc(This->driver, &(This->drvdesc));
588 WARN("IDsCaptureDriver_GetDriverDesc failed\n");
592 TRACE("using WINMM\n");
593 /* if no DirectSound interface available, use WINMM API instead */
594 This->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN |
595 DSDDESC_DOMMSYSTEMSETFORMAT;
598 This->drvdesc.dnDevNode = wid;
600 /* open the DirectSound driver if available */
601 if (This->driver && (err == DS_OK))
602 err = IDsCaptureDriver_Open(This->driver);
605 This->initialized = TRUE;
607 /* the driver is now open, so it's now allowed to call GetCaps */
609 This->drvcaps.dwSize = sizeof(This->drvcaps);
610 err = IDsCaptureDriver_GetCaps(This->driver,&(This->drvcaps));
612 WARN("IDsCaptureDriver_GetCaps failed\n");
615 } else /*if (This->hwi)*/ {
617 err = mmErr(waveInGetDevCapsA((UINT)This->drvdesc.dnDevNode, &wic, sizeof(wic)));
620 This->drvcaps.dwFlags = 0;
621 strncpy(This->drvdesc.szDrvName, wic.szPname,
622 sizeof(This->drvdesc.szDrvName));
624 This->drvcaps.dwFlags |= DSCCAPS_EMULDRIVER;
625 This->drvcaps.dwFormats = wic.dwFormats;
626 This->drvcaps.dwChannels = wic.wChannels;
634 static ICOM_VTABLE(IDirectSoundCapture) dscvt =
636 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
637 /* IUnknown methods */
638 IDirectSoundCaptureImpl_QueryInterface,
639 IDirectSoundCaptureImpl_AddRef,
640 IDirectSoundCaptureImpl_Release,
642 /* IDirectSoundCapture methods */
643 IDirectSoundCaptureImpl_CreateCaptureBuffer,
644 IDirectSoundCaptureImpl_GetCaps,
645 IDirectSoundCaptureImpl_Initialize
649 DSOUND_CreateDirectSoundCaptureBuffer(
650 IDirectSoundCaptureImpl *ipDSC,
651 LPCDSCBUFFERDESC lpcDSCBufferDesc,
655 TRACE( "(%p,%p)\n", lpcDSCBufferDesc, ppobj );
658 WARN("invalid parameter: ipDSC == NULL\n");
659 return DSERR_INVALIDPARAM;
662 if (lpcDSCBufferDesc == NULL) {
663 WARN("invalid parameter: lpcDSCBufferDesc == NULL\n");
664 return DSERR_INVALIDPARAM;
668 WARN("invalid parameter: ppobj == NULL\n");
669 return DSERR_INVALIDPARAM;
672 if ( ((lpcDSCBufferDesc->dwSize != sizeof(DSCBUFFERDESC)) &&
673 (lpcDSCBufferDesc->dwSize != sizeof(DSCBUFFERDESC1))) ||
674 (lpcDSCBufferDesc->dwBufferBytes == 0) ||
675 (lpcDSCBufferDesc->lpwfxFormat == NULL) ) {
676 WARN("invalid lpcDSCBufferDesc\n");
678 return DSERR_INVALIDPARAM;
681 if ( !ipDSC->initialized ) {
682 WARN("not initialized\n");
684 return DSERR_UNINITIALIZED;
687 wfex = lpcDSCBufferDesc->lpwfxFormat;
690 TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
691 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
692 wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
693 wfex->nAvgBytesPerSec, wfex->nBlockAlign,
694 wfex->wBitsPerSample, wfex->cbSize);
696 if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
697 ipDSC->pwfx = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEFORMATEX));
698 memcpy(ipDSC->pwfx, wfex, sizeof(WAVEFORMATEX));
699 ipDSC->pwfx->cbSize = 0;
701 ipDSC->pwfx = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEFORMATEX)+wfex->cbSize);
702 memcpy(ipDSC->pwfx, wfex, sizeof(WAVEFORMATEX)+wfex->cbSize);
705 WARN("lpcDSCBufferDesc->lpwfxFormat == 0\n");
707 return DSERR_INVALIDPARAM; /* FIXME: DSERR_BADFORMAT ? */
710 *ppobj = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
711 sizeof(IDirectSoundCaptureBufferImpl));
713 if ( *ppobj == NULL ) {
714 WARN("out of memory\n");
716 return DSERR_OUTOFMEMORY;
719 ICOM_THIS(IDirectSoundCaptureBufferImpl,*ppobj);
722 This->dsound = ipDSC;
723 This->dsound->capture_buffer = This;
725 This->nrofnotifies = 0;
726 This->hwnotify = NULL;
728 This->pdscbd = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
729 lpcDSCBufferDesc->dwSize);
731 memcpy(This->pdscbd, lpcDSCBufferDesc, lpcDSCBufferDesc->dwSize);
734 This->dsound->capture_buffer = 0;
735 HeapFree( GetProcessHeap(), 0, This );
737 return DSERR_OUTOFMEMORY;
740 This->lpVtbl = &dscbvt;
743 err = IDsCaptureDriver_CreateCaptureBuffer(ipDSC->driver,
744 ipDSC->pwfx,0,0,&(ipDSC->buflen),&(ipDSC->buffer),(LPVOID*)&(ipDSC->hwbuf));
746 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
747 This->dsound->capture_buffer = 0;
748 HeapFree( GetProcessHeap(), 0, This );
755 DWORD flags = CALLBACK_FUNCTION;
756 if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
757 flags |= WAVE_DIRECTSOUND;
758 err = mmErr(waveInOpen(&(ipDSC->hwi),
759 ipDSC->drvdesc.dnDevNode, ipDSC->pwfx,
760 (DWORD)DSOUND_capture_callback, (DWORD)ipDSC, flags));
762 WARN("waveInOpen failed\n");
763 This->dsound->capture_buffer = 0;
764 HeapFree( GetProcessHeap(), 0, This );
769 buflen = lpcDSCBufferDesc->dwBufferBytes;
770 TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->buffer);
772 newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,ipDSC->buffer,buflen);
774 newbuf = (LPBYTE)HeapAlloc(GetProcessHeap(),0,buflen);
775 if (newbuf == NULL) {
776 WARN("failed to allocate capture buffer\n");
777 err = DSERR_OUTOFMEMORY;
778 /* but the old buffer might still exist and must be re-prepared */
780 ipDSC->buffer = newbuf;
781 ipDSC->buflen = buflen;
786 TRACE("returning DS_OK\n");
790 /*******************************************************************************
791 * IDirectSoundCaptureNotify
793 static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_QueryInterface(
794 LPDIRECTSOUNDNOTIFY iface,
798 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
799 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
801 if (This->dscb == NULL) {
802 WARN("invalid parameter\n");
806 return IDirectSoundCaptureBuffer_QueryInterface((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb, riid, ppobj);
809 static ULONG WINAPI IDirectSoundCaptureNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
811 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
814 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
816 ref = InterlockedIncrement(&(This->ref));
820 static ULONG WINAPI IDirectSoundCaptureNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
822 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
825 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
827 ref = InterlockedDecrement(&(This->ref));
829 if (This->dscb->hwnotify)
830 IDsDriverNotify_Release(This->dscb->hwnotify);
831 This->dscb->notify=NULL;
832 IDirectSoundCaptureBuffer_Release((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb);
833 HeapFree(GetProcessHeap(),0,This);
834 TRACE("(%p) released\n",This);
839 static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_SetNotificationPositions(
840 LPDIRECTSOUNDNOTIFY iface,
842 LPCDSBPOSITIONNOTIFY notify)
844 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
845 TRACE("(%p,0x%08lx,%p)\n",This,howmuch,notify);
847 if (howmuch > 0 && notify == NULL) {
848 WARN("invalid parameter: notify == NULL\n");
849 return DSERR_INVALIDPARAM;
852 if (TRACE_ON(dsound)) {
854 for (i=0;i<howmuch;i++)
855 TRACE("notify at %ld to 0x%08lx\n",
856 notify[i].dwOffset,(DWORD)notify[i].hEventNotify);
859 if (This->dscb->hwnotify) {
861 hres = IDsDriverNotify_SetNotificationPositions(This->dscb->hwnotify, howmuch, notify);
863 WARN("IDsDriverNotify_SetNotificationPositions failed\n");
865 } else if (howmuch > 0) {
866 /* Make an internal copy of the caller-supplied array.
867 * Replace the existing copy if one is already present. */
868 if (This->dscb->notifies)
869 This->dscb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
870 This->dscb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
872 This->dscb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
873 howmuch * sizeof(DSBPOSITIONNOTIFY));
875 if (This->dscb->notifies == NULL) {
876 WARN("out of memory\n");
877 return DSERR_OUTOFMEMORY;
879 memcpy(This->dscb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
880 This->dscb->nrofnotifies = howmuch;
882 if (This->dscb->notifies) {
883 HeapFree(GetProcessHeap(), 0, This->dscb->notifies);
884 This->dscb->notifies = NULL;
886 This->dscb->nrofnotifies = 0;
892 ICOM_VTABLE(IDirectSoundNotify) dscnvt =
894 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
895 IDirectSoundCaptureNotifyImpl_QueryInterface,
896 IDirectSoundCaptureNotifyImpl_AddRef,
897 IDirectSoundCaptureNotifyImpl_Release,
898 IDirectSoundCaptureNotifyImpl_SetNotificationPositions,
901 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
902 IDirectSoundCaptureBufferImpl *dscb,
903 IDirectSoundCaptureNotifyImpl **pdscn)
905 IDirectSoundCaptureNotifyImpl * dscn;
906 TRACE("(%p,%p)\n",dscb,pdscn);
908 dscn = (IDirectSoundCaptureNotifyImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dscn));
911 WARN("out of memory\n");
912 return DSERR_OUTOFMEMORY;
916 dscn->lpVtbl = &dscnvt;
919 IDirectSoundCaptureBuffer_AddRef((LPDIRECTSOUNDCAPTUREBUFFER)dscb);
925 /*******************************************************************************
926 * IDirectSoundCaptureBuffer
928 static HRESULT WINAPI
929 IDirectSoundCaptureBufferImpl_QueryInterface(
930 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
934 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
936 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
939 WARN("invalid parameter\n");
945 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ||
946 IsEqualGUID( &IID_IDirectSoundNotify8, riid ) ) {
948 hres = IDirectSoundCaptureNotifyImpl_Create(This, &This->notify);
950 if (This->dsound->hwbuf) {
951 hres = IDsCaptureDriverBuffer_QueryInterface(This->dsound->hwbuf,
952 &IID_IDsDriverNotify, (LPVOID*)&(This->hwnotify));
954 WARN("IDsCaptureDriverBuffer_QueryInterface failed\n");
960 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
961 *ppobj = (LPVOID)This->notify;
965 WARN("IID_IDirectSoundNotify\n");
969 if ( IsEqualGUID( &IID_IDirectSoundCaptureBuffer, riid ) ||
970 IsEqualGUID( &IID_IDirectSoundCaptureBuffer8, riid ) ) {
971 IDirectSoundCaptureBuffer8_AddRef(iface);
976 FIXME("(%p,%s,%p) unsupported GUID\n", This, debugstr_guid(riid), ppobj);
977 return E_NOINTERFACE;
981 IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
984 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
985 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
987 assert(This->dsound);
989 EnterCriticalSection( &(This->dsound->lock) );
991 uRef = ++(This->ref);
993 LeaveCriticalSection( &(This->dsound->lock) );
999 IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
1002 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1003 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1005 assert(This->dsound);
1007 EnterCriticalSection( &(This->dsound->lock) );
1009 uRef = --(This->ref);
1011 LeaveCriticalSection( &(This->dsound->lock) );
1014 TRACE("deleting object\n");
1016 HeapFree(GetProcessHeap(),0, This->pdscbd);
1018 if (This->dsound->hwi) {
1019 waveInReset(This->dsound->hwi);
1020 waveInClose(This->dsound->hwi);
1021 if (This->dsound->pwave) {
1022 HeapFree(GetProcessHeap(),0, This->dsound->pwave);
1023 This->dsound->pwave = 0;
1025 This->dsound->hwi = 0;
1028 if (This->dsound->hwbuf)
1029 IDsCaptureDriverBuffer_Release(This->dsound->hwbuf);
1031 /* remove from IDirectSoundCaptureImpl */
1033 This->dsound->capture_buffer = NULL;
1035 ERR("does not reference dsound\n");
1038 IDirectSoundNotify_Release((LPDIRECTSOUNDNOTIFY)This->notify);
1040 if (This->notifies != NULL)
1041 HeapFree(GetProcessHeap(), 0, This->notifies);
1043 HeapFree( GetProcessHeap(), 0, This );
1044 TRACE("(%p) released\n",This);
1050 static HRESULT WINAPI
1051 IDirectSoundCaptureBufferImpl_GetCaps(
1052 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1053 LPDSCBCAPS lpDSCBCaps )
1055 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1056 TRACE( "(%p,%p)\n", This, lpDSCBCaps );
1059 WARN("invalid parameter: This == NULL\n");
1060 return DSERR_INVALIDPARAM;
1063 if (lpDSCBCaps == NULL) {
1064 WARN("invalid parameter: lpDSCBCaps == NULL\n");
1065 return DSERR_INVALIDPARAM;
1068 if (lpDSCBCaps->dwSize < sizeof(DSCBCAPS)) {
1069 WARN("invalid parameter: lpDSCBCaps->dwSize = %ld < %d\n",
1070 lpDSCBCaps->dwSize, sizeof(DSCBCAPS));
1071 return DSERR_INVALIDPARAM;
1074 if (This->dsound == NULL) {
1075 WARN("invalid parameter: This->dsound == NULL\n");
1076 return DSERR_INVALIDPARAM;
1079 lpDSCBCaps->dwSize = sizeof(DSCBCAPS);
1080 lpDSCBCaps->dwFlags = This->flags;
1081 lpDSCBCaps->dwBufferBytes = This->pdscbd->dwBufferBytes;
1082 lpDSCBCaps->dwReserved = 0;
1084 TRACE("returning DS_OK\n");
1088 static HRESULT WINAPI
1089 IDirectSoundCaptureBufferImpl_GetCurrentPosition(
1090 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1091 LPDWORD lpdwCapturePosition,
1092 LPDWORD lpdwReadPosition )
1094 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1095 TRACE( "(%p,%p,%p)\n", This, lpdwCapturePosition, lpdwReadPosition );
1098 WARN("invalid parameter: This == NULL\n");
1099 return DSERR_INVALIDPARAM;
1102 if (This->dsound == NULL) {
1103 WARN("invalid parameter: This->dsound == NULL\n");
1104 return DSERR_INVALIDPARAM;
1107 if (This->dsound->driver) {
1109 hres = IDsCaptureDriverBuffer_GetPosition(This->dsound->hwbuf, lpdwCapturePosition, lpdwReadPosition );
1110 if (hres != DS_OK) {
1111 WARN("IDsCaptureDriverBuffer_GetPosition failed\n");
1114 } else if (This->dsound->hwi) {
1115 EnterCriticalSection(&(This->dsound->lock));
1116 TRACE("old This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1117 if (lpdwCapturePosition) {
1119 mtime.wType = TIME_BYTES;
1120 waveInGetPosition(This->dsound->hwi, &mtime, sizeof(mtime));
1121 TRACE("mtime.u.cb=%ld,This->dsound->buflen=%ld\n", mtime.u.cb,
1122 This->dsound->buflen);
1123 mtime.u.cb = mtime.u.cb % This->dsound->buflen;
1124 *lpdwCapturePosition = mtime.u.cb;
1127 if (lpdwReadPosition) {
1128 if (This->dsound->state == STATE_STARTING) {
1129 if (lpdwCapturePosition)
1130 This->dsound->read_position = *lpdwCapturePosition;
1131 This->dsound->state = STATE_CAPTURING;
1133 *lpdwReadPosition = This->dsound->read_position;
1135 TRACE("new This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1136 LeaveCriticalSection(&(This->dsound->lock));
1137 if (lpdwCapturePosition) TRACE("*lpdwCapturePosition=%ld\n",*lpdwCapturePosition);
1138 if (lpdwReadPosition) TRACE("*lpdwReadPosition=%ld\n",*lpdwReadPosition);
1140 WARN("no driver\n");
1141 return DSERR_NODRIVER;
1144 TRACE("returning DS_OK\n");
1148 static HRESULT WINAPI
1149 IDirectSoundCaptureBufferImpl_GetFormat(
1150 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1151 LPWAVEFORMATEX lpwfxFormat,
1152 DWORD dwSizeAllocated,
1153 LPDWORD lpdwSizeWritten )
1155 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1156 TRACE( "(%p,%p,0x%08lx,%p)\n", This, lpwfxFormat, dwSizeAllocated,
1160 WARN("invalid parameter: This == NULL\n");
1161 return DSERR_INVALIDPARAM;
1164 if (This->dsound == NULL) {
1165 WARN("invalid parameter: This->dsound == NULL\n");
1166 return DSERR_INVALIDPARAM;
1169 if (dwSizeAllocated > (sizeof(WAVEFORMATEX) + This->dsound->pwfx->cbSize))
1170 dwSizeAllocated = sizeof(WAVEFORMATEX) + This->dsound->pwfx->cbSize;
1172 if (lpwfxFormat) { /* NULL is valid (just want size) */
1173 memcpy(lpwfxFormat, This->dsound->pwfx, dwSizeAllocated);
1174 if (lpdwSizeWritten)
1175 *lpdwSizeWritten = dwSizeAllocated;
1177 if (lpdwSizeWritten)
1178 *lpdwSizeWritten = sizeof(WAVEFORMATEX) + This->dsound->pwfx->cbSize;
1180 TRACE("invalid parameter: lpdwSizeWritten = NULL\n");
1181 return DSERR_INVALIDPARAM;
1185 TRACE("returning DS_OK\n");
1189 static HRESULT WINAPI
1190 IDirectSoundCaptureBufferImpl_GetStatus(
1191 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1192 LPDWORD lpdwStatus )
1194 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1195 TRACE( "(%p, %p), thread is %04lx\n", This, lpdwStatus, GetCurrentThreadId() );
1198 WARN("invalid parameter: This == NULL\n");
1199 return DSERR_INVALIDPARAM;
1202 if (This->dsound == NULL) {
1203 WARN("invalid parameter: This->dsound == NULL\n");
1204 return DSERR_INVALIDPARAM;
1207 if (lpdwStatus == NULL) {
1208 WARN("invalid parameter: lpdwStatus == NULL\n");
1209 return DSERR_INVALIDPARAM;
1213 EnterCriticalSection(&(This->dsound->lock));
1215 TRACE("old This->dsound->state=%s, old lpdwStatus=%08lx\n",
1216 captureStateString[This->dsound->state],*lpdwStatus);
1217 if ((This->dsound->state == STATE_STARTING) ||
1218 (This->dsound->state == STATE_CAPTURING)) {
1219 *lpdwStatus |= DSCBSTATUS_CAPTURING;
1220 if (This->flags & DSCBSTART_LOOPING)
1221 *lpdwStatus |= DSCBSTATUS_LOOPING;
1223 TRACE("new This->dsound->state=%s, new lpdwStatus=%08lx\n",
1224 captureStateString[This->dsound->state],*lpdwStatus);
1225 LeaveCriticalSection(&(This->dsound->lock));
1227 TRACE("status=%lx\n", *lpdwStatus);
1228 TRACE("returning DS_OK\n");
1232 static HRESULT WINAPI
1233 IDirectSoundCaptureBufferImpl_Initialize(
1234 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1235 LPDIRECTSOUNDCAPTURE lpDSC,
1236 LPCDSCBUFFERDESC lpcDSCBDesc )
1238 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1240 FIXME( "(%p,%p,%p): stub\n", This, lpDSC, lpcDSCBDesc );
1245 static HRESULT WINAPI
1246 IDirectSoundCaptureBufferImpl_Lock(
1247 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1250 LPVOID* lplpvAudioPtr1,
1251 LPDWORD lpdwAudioBytes1,
1252 LPVOID* lplpvAudioPtr2,
1253 LPDWORD lpdwAudioBytes2,
1256 HRESULT err = DS_OK;
1257 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1258 TRACE( "(%p,%08lu,%08lu,%p,%p,%p,%p,0x%08lx) at %ld\n", This, dwReadCusor,
1259 dwReadBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2,
1260 lpdwAudioBytes2, dwFlags, GetTickCount() );
1263 WARN("invalid parameter: This == NULL\n");
1264 return DSERR_INVALIDPARAM;
1267 if (This->dsound == NULL) {
1268 WARN("invalid parameter: This->dsound == NULL\n");
1269 return DSERR_INVALIDPARAM;
1272 if (lplpvAudioPtr1 == NULL) {
1273 WARN("invalid parameter: lplpvAudioPtr1 == NULL\n");
1274 return DSERR_INVALIDPARAM;
1277 if (lpdwAudioBytes1 == NULL) {
1278 WARN("invalid parameter: lpdwAudioBytes1 == NULL\n");
1279 return DSERR_INVALIDPARAM;
1282 EnterCriticalSection(&(This->dsound->lock));
1284 if (This->dsound->driver) {
1285 err = IDsCaptureDriverBuffer_Lock(This->dsound->hwbuf, lplpvAudioPtr1,
1286 lpdwAudioBytes1, lplpvAudioPtr2, lpdwAudioBytes2,
1287 dwReadCusor, dwReadBytes, dwFlags);
1289 WARN("IDsCaptureDriverBuffer_Lock failed\n");
1290 } else if (This->dsound->hwi) {
1291 *lplpvAudioPtr1 = This->dsound->buffer + dwReadCusor;
1292 if ( (dwReadCusor + dwReadBytes) > This->dsound->buflen) {
1293 *lpdwAudioBytes1 = This->dsound->buflen - dwReadCusor;
1295 *lplpvAudioPtr2 = This->dsound->buffer;
1296 if (lpdwAudioBytes2)
1297 *lpdwAudioBytes2 = dwReadBytes - *lpdwAudioBytes1;
1299 *lpdwAudioBytes1 = dwReadBytes;
1301 *lplpvAudioPtr2 = 0;
1302 if (lpdwAudioBytes2)
1303 *lpdwAudioBytes2 = 0;
1306 TRACE("invalid call\n");
1307 err = DSERR_INVALIDCALL; /* DSERR_NODRIVER ? */
1310 LeaveCriticalSection(&(This->dsound->lock));
1315 static HRESULT WINAPI
1316 IDirectSoundCaptureBufferImpl_Start(
1317 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1320 HRESULT err = DS_OK;
1321 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1322 TRACE( "(%p,0x%08lx)\n", This, dwFlags );
1325 WARN("invalid parameter: This == NULL\n");
1326 return DSERR_INVALIDPARAM;
1329 if (This->dsound == NULL) {
1330 WARN("invalid parameter: This->dsound == NULL\n");
1331 return DSERR_INVALIDPARAM;
1334 if ( (This->dsound->driver == 0) && (This->dsound->hwi == 0) ) {
1335 WARN("no driver\n");
1336 return DSERR_NODRIVER;
1339 EnterCriticalSection(&(This->dsound->lock));
1341 This->flags = dwFlags;
1342 TRACE("old This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1343 if (This->dsound->state == STATE_STOPPED)
1344 This->dsound->state = STATE_STARTING;
1345 else if (This->dsound->state == STATE_STOPPING)
1346 This->dsound->state = STATE_CAPTURING;
1347 TRACE("new This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1349 LeaveCriticalSection(&(This->dsound->lock));
1351 if (This->dsound->driver) {
1352 err = IDsCaptureDriverBuffer_Start(This->dsound->hwbuf, dwFlags);
1354 WARN("IDsCaptureDriverBuffer_Start failed\n");
1357 IDirectSoundCaptureImpl* ipDSC = This->dsound;
1359 if (ipDSC->buffer) {
1360 if (This->nrofnotifies) {
1363 ipDSC->nrofpwaves = This->nrofnotifies;
1364 TRACE("nrofnotifies=%d\n", This->nrofnotifies);
1366 /* prepare headers */
1368 ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,
1369 ipDSC->nrofpwaves*sizeof(WAVEHDR));
1371 ipDSC->pwave = HeapAlloc(GetProcessHeap(),0,
1372 ipDSC->nrofpwaves*sizeof(WAVEHDR));
1374 for (c = 0; c < ipDSC->nrofpwaves; c++) {
1375 if (This->notifies[c].dwOffset == DSBPN_OFFSETSTOP) {
1376 TRACE("got DSBPN_OFFSETSTOP\n");
1377 ipDSC->nrofpwaves = c;
1381 ipDSC->pwave[0].lpData = ipDSC->buffer;
1382 ipDSC->pwave[0].dwBufferLength =
1383 This->notifies[0].dwOffset + 1;
1385 ipDSC->pwave[c].lpData = ipDSC->buffer +
1386 This->notifies[c-1].dwOffset + 1;
1387 ipDSC->pwave[c].dwBufferLength =
1388 This->notifies[c].dwOffset -
1389 This->notifies[c-1].dwOffset;
1391 ipDSC->pwave[c].dwBytesRecorded = 0;
1392 ipDSC->pwave[c].dwUser = (DWORD)ipDSC;
1393 ipDSC->pwave[c].dwFlags = 0;
1394 ipDSC->pwave[c].dwLoops = 0;
1395 err = mmErr(waveInPrepareHeader(ipDSC->hwi,
1396 &(ipDSC->pwave[c]),sizeof(WAVEHDR)));
1398 WARN("waveInPrepareHeader failed\n");
1400 waveInUnprepareHeader(ipDSC->hwi,
1401 &(ipDSC->pwave[c]),sizeof(WAVEHDR));
1405 err = mmErr(waveInAddBuffer(ipDSC->hwi,
1406 &(ipDSC->pwave[c]), sizeof(WAVEHDR)));
1408 WARN("waveInAddBuffer failed\n");
1410 waveInUnprepareHeader(ipDSC->hwi,
1411 &(ipDSC->pwave[c]),sizeof(WAVEHDR));
1416 memset(ipDSC->buffer,
1417 (ipDSC->pwfx->wBitsPerSample == 8) ? 128 : 0, ipDSC->buflen);
1419 TRACE("no notifiers specified\n");
1420 /* no notifiers specified so just create a single default header */
1421 ipDSC->nrofpwaves = 1;
1423 ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,sizeof(WAVEHDR));
1425 ipDSC->pwave = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEHDR));
1427 ipDSC->pwave[0].lpData = ipDSC->buffer;
1428 ipDSC->pwave[0].dwBufferLength = ipDSC->buflen;
1429 ipDSC->pwave[0].dwBytesRecorded = 0;
1430 ipDSC->pwave[0].dwUser = (DWORD)ipDSC;
1431 ipDSC->pwave[0].dwFlags = 0;
1432 ipDSC->pwave[0].dwLoops = 0;
1434 err = mmErr(waveInPrepareHeader(ipDSC->hwi,
1435 &(ipDSC->pwave[0]),sizeof(WAVEHDR)));
1437 WARN("waveInPrepareHeader failed\n");
1438 waveInUnprepareHeader(ipDSC->hwi,
1439 &(ipDSC->pwave[0]),sizeof(WAVEHDR));
1441 err = mmErr(waveInAddBuffer(ipDSC->hwi,
1442 &(ipDSC->pwave[0]), sizeof(WAVEHDR)));
1444 WARN("waveInAddBuffer failed\n");
1445 waveInUnprepareHeader(ipDSC->hwi,
1446 &(ipDSC->pwave[0]),sizeof(WAVEHDR));
1452 ipDSC->read_position = 0;
1455 /* start filling the first buffer */
1456 err = mmErr(waveInStart(ipDSC->hwi));
1458 WARN("waveInStart failed\n");
1463 WARN("calling waveInClose because of error\n");
1464 waveInClose(This->dsound->hwi);
1465 This->dsound->hwi = 0;
1468 TRACE("returning %ld\n", err);
1472 static HRESULT WINAPI
1473 IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
1475 HRESULT err = DS_OK;
1476 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1477 TRACE( "(%p)\n", This );
1480 WARN("invalid parameter: This == NULL\n");
1481 return DSERR_INVALIDPARAM;
1484 if (This->dsound == NULL) {
1485 WARN("invalid parameter: This->dsound == NULL\n");
1486 return DSERR_INVALIDPARAM;
1489 EnterCriticalSection(&(This->dsound->lock));
1491 TRACE("old This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1492 if (This->dsound->state == STATE_CAPTURING)
1493 This->dsound->state = STATE_STOPPING;
1494 else if (This->dsound->state == STATE_STARTING)
1495 This->dsound->state = STATE_STOPPED;
1496 TRACE("new This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1498 LeaveCriticalSection(&(This->dsound->lock));
1500 if (This->dsound->driver) {
1501 err = IDsCaptureDriverBuffer_Stop(This->dsound->hwbuf);
1502 if (err == DSERR_BUFFERLOST) {
1503 /* Wine-only: the driver wants us to reopen the device */
1504 IDsCaptureDriverBuffer_Release(This->dsound->hwbuf);
1505 err = IDsCaptureDriver_CreateCaptureBuffer(This->dsound->driver,
1506 This->dsound->pwfx,0,0,&(This->dsound->buflen),&(This->dsound->buffer),
1507 (LPVOID*)&(This->dsound->hwbuf));
1509 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
1510 This->dsound->hwbuf = 0;
1512 } else if (err != DS_OK)
1513 WARN("IDsCaptureDriverBuffer_Stop failed\n");
1514 } else if (This->dsound->hwi) {
1515 err = waveInStop(This->dsound->hwi);
1517 WARN("no driver\n");
1518 err = DSERR_NODRIVER;
1521 TRACE( "(%p) returning 0x%08lx\n", This,err);
1525 static HRESULT WINAPI
1526 IDirectSoundCaptureBufferImpl_Unlock(
1527 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1528 LPVOID lpvAudioPtr1,
1529 DWORD dwAudioBytes1,
1530 LPVOID lpvAudioPtr2,
1531 DWORD dwAudioBytes2 )
1533 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1534 TRACE( "(%p,%p,%08lu,%p,%08lu)\n", This, lpvAudioPtr1, dwAudioBytes1,
1535 lpvAudioPtr2, dwAudioBytes2 );
1538 WARN("invalid parameter: This == NULL\n");
1539 return DSERR_INVALIDPARAM;
1542 if (lpvAudioPtr1 == NULL) {
1543 WARN("invalid parameter: lpvAudioPtr1 == NULL\n");
1544 return DSERR_INVALIDPARAM;
1547 if (This->dsound->driver) {
1549 hres = IDsCaptureDriverBuffer_Unlock(This->dsound->hwbuf, lpvAudioPtr1,
1550 dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1552 WARN("IDsCaptureDriverBuffer_Unlock failed\n");
1554 } else if (This->dsound->hwi) {
1555 This->dsound->read_position = (This->dsound->read_position +
1556 (dwAudioBytes1 + dwAudioBytes2)) % This->dsound->buflen;
1558 WARN("invalid call\n");
1559 return DSERR_INVALIDCALL;
1565 static HRESULT WINAPI
1566 IDirectSoundCaptureBufferImpl_GetObjectInPath(
1567 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1568 REFGUID rguidObject,
1570 REFGUID rguidInterface,
1573 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1575 FIXME( "(%p,%s,%lu,%s,%p): stub\n", This, debugstr_guid(rguidObject),
1576 dwIndex, debugstr_guid(rguidInterface), ppObject );
1581 static HRESULT WINAPI
1582 IDirectSoundCaptureBufferImpl_GetFXStatus(
1583 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1585 LPDWORD pdwFXStatus )
1587 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1589 FIXME( "(%p,%lu,%p): stub\n", This, dwFXCount, pdwFXStatus );
1594 static ICOM_VTABLE(IDirectSoundCaptureBuffer8) dscbvt =
1596 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1597 /* IUnknown methods */
1598 IDirectSoundCaptureBufferImpl_QueryInterface,
1599 IDirectSoundCaptureBufferImpl_AddRef,
1600 IDirectSoundCaptureBufferImpl_Release,
1602 /* IDirectSoundCaptureBuffer methods */
1603 IDirectSoundCaptureBufferImpl_GetCaps,
1604 IDirectSoundCaptureBufferImpl_GetCurrentPosition,
1605 IDirectSoundCaptureBufferImpl_GetFormat,
1606 IDirectSoundCaptureBufferImpl_GetStatus,
1607 IDirectSoundCaptureBufferImpl_Initialize,
1608 IDirectSoundCaptureBufferImpl_Lock,
1609 IDirectSoundCaptureBufferImpl_Start,
1610 IDirectSoundCaptureBufferImpl_Stop,
1611 IDirectSoundCaptureBufferImpl_Unlock,
1613 /* IDirectSoundCaptureBuffer methods */
1614 IDirectSoundCaptureBufferImpl_GetObjectInPath,
1615 IDirectSoundCaptureBufferImpl_GetFXStatus
1618 /*******************************************************************************
1619 * DirectSoundCapture ClassFactory
1622 static HRESULT WINAPI
1623 DSCCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1625 ICOM_THIS(IClassFactoryImpl,iface);
1627 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1628 return E_NOINTERFACE;
1632 DSCCF_AddRef(LPCLASSFACTORY iface)
1634 ICOM_THIS(IClassFactoryImpl,iface);
1635 TRACE("(%p) ref was %ld\n", This, This->ref);
1636 return ++(This->ref);
1640 DSCCF_Release(LPCLASSFACTORY iface)
1642 ICOM_THIS(IClassFactoryImpl,iface);
1643 /* static class, won't be freed */
1644 TRACE("(%p) ref was %ld\n", This, This->ref);
1645 return --(This->ref);
1648 static HRESULT WINAPI
1649 DSCCF_CreateInstance(
1650 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj )
1652 ICOM_THIS(IClassFactoryImpl,iface);
1653 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1655 if (ppobj == NULL) {
1656 WARN("invalid parameter\n");
1657 return E_INVALIDARG;
1662 if ( IsEqualGUID( &IID_IDirectSoundCapture, riid ) ||
1663 IsEqualGUID( &IID_IDirectSoundCapture8, riid ) ) {
1664 return DirectSoundCaptureCreate8(0,(LPDIRECTSOUNDCAPTURE8*)ppobj,pOuter);
1667 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
1668 return E_NOINTERFACE;
1671 static HRESULT WINAPI
1672 DSCCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1674 ICOM_THIS(IClassFactoryImpl,iface);
1675 FIXME("(%p)->(%d),stub!\n",This,dolock);
1679 static ICOM_VTABLE(IClassFactory) DSCCF_Vtbl =
1681 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1682 DSCCF_QueryInterface,
1685 DSCCF_CreateInstance,
1689 IClassFactoryImpl DSOUND_CAPTURE_CF = { &DSCCF_Vtbl, 1 };
1691 /***************************************************************************
1692 * DirectSoundFullDuplexCreate [DSOUND.10]
1694 * Create and initialize a DirectSoundFullDuplex interface.
1697 * pcGuidCaptureDevice [I] Address of sound capture device GUID.
1698 * pcGuidRenderDevice [I] Address of sound render device GUID.
1699 * pcDSCBufferDesc [I] Address of capture buffer description.
1700 * pcDSBufferDesc [I] Address of render buffer description.
1701 * hWnd [I] Handle to application window.
1702 * dwLevel [I] Cooperative level.
1703 * ppDSFD [O] Address where full duplex interface returned.
1704 * ppDSCBuffer8 [0] Address where capture buffer interface returned.
1705 * ppDSBuffer8 [0] Address where render buffer interface returned.
1706 * pUnkOuter [I] Must be NULL.
1710 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
1711 * DSERR_OUTOFMEMORY DSERR_INVALIDCALL DSERR_NODRIVER
1714 DirectSoundFullDuplexCreate(
1715 LPCGUID pcGuidCaptureDevice,
1716 LPCGUID pcGuidRenderDevice,
1717 LPCDSCBUFFERDESC pcDSCBufferDesc,
1718 LPCDSBUFFERDESC pcDSBufferDesc,
1721 LPDIRECTSOUNDFULLDUPLEX *ppDSFD,
1722 LPDIRECTSOUNDCAPTUREBUFFER8 *ppDSCBuffer8,
1723 LPDIRECTSOUNDBUFFER8 *ppDSBuffer8,
1724 LPUNKNOWN pUnkOuter)
1726 IDirectSoundFullDuplexImpl** ippDSFD=(IDirectSoundFullDuplexImpl**)ppDSFD;
1727 TRACE("(%s,%s,%p,%p,%lx,%lx,%p,%p,%p,%p)\n", debugstr_guid(pcGuidCaptureDevice),
1728 debugstr_guid(pcGuidRenderDevice), pcDSCBufferDesc, pcDSBufferDesc,
1729 (DWORD)hWnd, dwLevel, ppDSFD, ppDSCBuffer8, ppDSBuffer8, pUnkOuter);
1732 WARN("pUnkOuter != 0\n");
1733 return DSERR_NOAGGREGATION;
1736 *ippDSFD = (IDirectSoundFullDuplexImpl*)HeapAlloc(GetProcessHeap(),
1737 HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
1739 if (*ippDSFD == NULL) {
1740 WARN("out of memory\n");
1741 return DSERR_OUTOFMEMORY;
1744 ICOM_THIS(IDirectSoundFullDuplexImpl, *ippDSFD);
1747 This->lpVtbl = &dsfdvt;
1749 InitializeCriticalSection( &(This->lock) );
1750 This->lock.DebugInfo->Spare[1] = (DWORD)"DSDUPLEX_lock";
1752 hres = IDirectSoundFullDuplexImpl_Initialize( (LPDIRECTSOUNDFULLDUPLEX)This,
1753 pcGuidCaptureDevice, pcGuidRenderDevice,
1754 pcDSCBufferDesc, pcDSBufferDesc,
1755 hWnd, dwLevel, ppDSCBuffer8, ppDSBuffer8);
1757 WARN("IDirectSoundFullDuplexImpl_Initialize failed\n");
1761 return DSERR_GENERIC;
1764 static HRESULT WINAPI
1765 IDirectSoundFullDuplexImpl_QueryInterface(
1766 LPDIRECTSOUNDFULLDUPLEX iface,
1770 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1771 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
1773 if (ppobj == NULL) {
1774 WARN("invalid parameter\n");
1775 return E_INVALIDARG;
1779 return E_NOINTERFACE;
1783 IDirectSoundFullDuplexImpl_AddRef( LPDIRECTSOUNDFULLDUPLEX iface )
1786 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1787 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1789 EnterCriticalSection( &(This->lock) );
1791 uRef = ++(This->ref);
1793 LeaveCriticalSection( &(This->lock) );
1799 IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface )
1802 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1803 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1805 EnterCriticalSection( &(This->lock) );
1807 uRef = --(This->ref);
1809 LeaveCriticalSection( &(This->lock) );
1812 DeleteCriticalSection( &(This->lock) );
1813 HeapFree( GetProcessHeap(), 0, This );
1814 TRACE("(%p) released\n",This);
1820 static HRESULT WINAPI
1821 IDirectSoundFullDuplexImpl_Initialize(
1822 LPDIRECTSOUNDFULLDUPLEX iface,
1823 LPCGUID pCaptureGuid,
1824 LPCGUID pRendererGuid,
1825 LPCDSCBUFFERDESC lpDscBufferDesc,
1826 LPCDSBUFFERDESC lpDsBufferDesc,
1829 LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8,
1830 LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 )
1832 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1833 IDirectSoundCaptureBufferImpl** ippdscb=(IDirectSoundCaptureBufferImpl**)lplpDirectSoundCaptureBuffer8;
1834 IDirectSoundBufferImpl** ippdsc=(IDirectSoundBufferImpl**)lplpDirectSoundBuffer8;
1836 FIXME( "(%p,%s,%s,%p,%p,%lx,%lx,%p,%p) stub!\n", This, debugstr_guid(pCaptureGuid),
1837 debugstr_guid(pRendererGuid), lpDscBufferDesc, lpDsBufferDesc, (DWORD)hWnd, dwLevel,
1843 static ICOM_VTABLE(IDirectSoundFullDuplex) dsfdvt =
1845 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1846 /* IUnknown methods */
1847 IDirectSoundFullDuplexImpl_QueryInterface,
1848 IDirectSoundFullDuplexImpl_AddRef,
1849 IDirectSoundFullDuplexImpl_Release,
1851 /* IDirectSoundFullDuplex methods */
1852 IDirectSoundFullDuplexImpl_Initialize
1855 /*******************************************************************************
1856 * DirectSoundFullDuplex ClassFactory
1859 static HRESULT WINAPI
1860 DSFDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1862 ICOM_THIS(IClassFactoryImpl,iface);
1864 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1865 return E_NOINTERFACE;
1869 DSFDCF_AddRef(LPCLASSFACTORY iface)
1871 ICOM_THIS(IClassFactoryImpl,iface);
1872 TRACE("(%p) ref was %ld\n", This, This->ref);
1873 return ++(This->ref);
1877 DSFDCF_Release(LPCLASSFACTORY iface)
1879 ICOM_THIS(IClassFactoryImpl,iface);
1880 /* static class, won't be freed */
1881 TRACE("(%p) ref was %ld\n", This, This->ref);
1882 return --(This->ref);
1885 static HRESULT WINAPI
1886 DSFDCF_CreateInstance(
1887 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj )
1889 ICOM_THIS(IClassFactoryImpl,iface);
1891 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1893 if (ppobj == NULL) {
1894 WARN("invalid parameter\n");
1895 return E_INVALIDARG;
1900 if ( IsEqualGUID( &IID_IDirectSoundFullDuplex, riid ) ) {
1901 /* FIXME: how do we do this one ? */
1902 FIXME("not implemented\n");
1903 return E_NOINTERFACE;
1906 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
1907 return E_NOINTERFACE;
1910 static HRESULT WINAPI
1911 DSFDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1913 ICOM_THIS(IClassFactoryImpl,iface);
1914 FIXME("(%p)->(%d),stub!\n",This,dolock);
1918 static ICOM_VTABLE(IClassFactory) DSFDCF_Vtbl =
1920 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1921 DSFDCF_QueryInterface,
1924 DSFDCF_CreateInstance,
1928 IClassFactoryImpl DSOUND_FULLDUPLEX_CF = { &DSFDCF_Vtbl, 1 };