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;
84 static const char * captureStateString[] = {
91 /***************************************************************************
92 * DirectSoundCaptureCreate [DSOUND.6]
94 * Create and initialize a DirectSoundCapture interface.
97 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
98 * lplpDSC [O] Address of a variable to receive the interface pointer.
99 * pUnkOuter [I] Must be NULL.
103 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
107 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
108 * or NULL for the default device or DSDEVID_DefaultCapture or
109 * DSDEVID_DefaultVoiceCapture.
111 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
114 DirectSoundCaptureCreate8(
116 LPDIRECTSOUNDCAPTURE* lplpDSC,
117 LPUNKNOWN pUnkOuter )
119 IDirectSoundCaptureImpl** ippDSC=(IDirectSoundCaptureImpl**)lplpDSC;
120 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), lplpDSC, pUnkOuter);
123 WARN("invalid parameter: pUnkOuter != NULL\n");
124 return DSERR_NOAGGREGATION;
128 WARN("invalid parameter: lplpDSC == NULL\n");
129 return DSERR_INVALIDPARAM;
132 /* Default device? */
133 if ( !lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL) )
134 lpcGUID = &DSDEVID_DefaultCapture;
136 *ippDSC = (IDirectSoundCaptureImpl*)HeapAlloc(GetProcessHeap(),
137 HEAP_ZERO_MEMORY, sizeof(IDirectSoundCaptureImpl));
139 if (*ippDSC == NULL) {
140 WARN("out of memory\n");
141 return DSERR_OUTOFMEMORY;
143 ICOM_THIS(IDirectSoundCaptureImpl, *ippDSC);
146 This->state = STATE_STOPPED;
148 InitializeCriticalSection( &(This->lock) );
150 This->lpVtbl = &dscvt;
151 dsound_capture = This;
153 if (GetDeviceID(lpcGUID, &This->guid) == DS_OK) {
155 hres = IDirectSoundCaptureImpl_Initialize( (LPDIRECTSOUNDCAPTURE)This, &This->guid);
157 WARN("IDirectSoundCaptureImpl_Initialize failed\n");
161 WARN("invalid GUID: %s\n", debugstr_guid(lpcGUID));
162 return DSERR_INVALIDPARAM;
165 /***************************************************************************
166 * DirectSoundCaptureEnumerateA [DSOUND.7]
168 * Enumerate all DirectSound drivers installed in the system.
171 * lpDSEnumCallback [I] Address of callback function.
172 * lpContext [I] Address of user defined context passed to callback function.
176 * Failure: DSERR_INVALIDPARAM
179 DirectSoundCaptureEnumerateA(
180 LPDSENUMCALLBACKA lpDSEnumCallback,
188 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
190 if (lpDSEnumCallback == NULL) {
191 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
192 return DSERR_INVALIDPARAM;
195 devs = waveInGetNumDevs();
197 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
199 for (wid = 0; wid < devs; ++wid) {
200 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
202 if (IsEqualGUID( &guid, &temp ) ) {
203 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
205 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
206 "Primary Sound Capture Driver",desc.szDrvName,lpContext);
207 if (lpDSEnumCallback(NULL, "Primary Sound Capture Driver", desc.szDrvName, lpContext) == FALSE)
216 for (wid = 0; wid < devs; ++wid) {
217 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
219 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
221 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
222 debugstr_guid(&guid),desc.szDesc,desc.szDrvName,lpContext);
223 if (lpDSEnumCallback(&guid, desc.szDesc, desc.szDrvName, lpContext) == FALSE)
232 /***************************************************************************
233 * DirectSoundCaptureEnumerateW [DSOUND.8]
235 * Enumerate all DirectSound drivers installed in the system.
238 * lpDSEnumCallback [I] Address of callback function.
239 * lpContext [I] Address of user defined context passed to callback function.
243 * Failure: DSERR_INVALIDPARAM
246 DirectSoundCaptureEnumerateW(
247 LPDSENUMCALLBACKW lpDSEnumCallback,
254 WCHAR wDesc[MAXPNAMELEN];
255 WCHAR wName[MAXPNAMELEN];
257 TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
259 if (lpDSEnumCallback == NULL) {
260 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
261 return DSERR_INVALIDPARAM;
264 devs = waveInGetNumDevs();
266 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
268 for (wid = 0; wid < devs; ++wid) {
269 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
271 if (IsEqualGUID( &guid, &temp ) ) {
272 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
274 TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n",
275 "Primary Sound Capture Driver",desc.szDrvName,lpContext);
276 MultiByteToWideChar( CP_ACP, 0, "Primary Sound Capture Driver", -1,
277 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
278 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
279 wName, sizeof(wName)/sizeof(WCHAR) );
280 if (lpDSEnumCallback(NULL, wDesc, wName, lpContext) == FALSE)
289 for (wid = 0; wid < devs; ++wid) {
290 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
292 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
294 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
295 debugstr_guid(&DSDEVID_DefaultCapture),desc.szDesc,desc.szDrvName,lpContext);
296 MultiByteToWideChar( CP_ACP, 0, desc.szDesc, -1,
297 wDesc, sizeof(wDesc)/sizeof(WCHAR) );
298 MultiByteToWideChar( CP_ACP, 0, desc.szDrvName, -1,
299 wName, sizeof(wName)/sizeof(WCHAR) );
300 if (lpDSEnumCallback((LPGUID)&DSDEVID_DefaultCapture, wDesc, wName, lpContext) == FALSE)
310 DSOUND_capture_callback(
317 IDirectSoundCaptureImpl* This = (IDirectSoundCaptureImpl*)dwUser;
318 TRACE("(%p,%08x(%s),%08lx,%08lx,%08lx) entering at %ld\n",hwi,msg,
319 msg == MM_WIM_OPEN ? "MM_WIM_OPEN" : msg == MM_WIM_CLOSE ? "MM_WIM_CLOSE" :
320 msg == MM_WIM_DATA ? "MM_WIM_DATA" : "UNKNOWN",dwUser,dw1,dw2,GetTickCount());
322 if (msg == MM_WIM_DATA) {
323 LPWAVEHDR pHdr = (LPWAVEHDR)dw1;
324 EnterCriticalSection( &(This->lock) );
325 TRACE("DirectSoundCapture msg=MM_WIM_DATA, old This->state=%s, old This->index=%d\n",
326 captureStateString[This->state],This->index);
327 if (This->state != STATE_STOPPED) {
328 int index = This->index;
329 if (This->state == STATE_STARTING) {
330 This->read_position = pHdr->dwBytesRecorded;
331 This->state = STATE_CAPTURING;
333 waveInUnprepareHeader(hwi,&(This->pwave[This->index]),sizeof(WAVEHDR));
334 if (This->capture_buffer->nrofnotifies)
335 SetEvent(This->capture_buffer->notifies[This->index].hEventNotify);
336 This->index = (This->index + 1) % This->nrofpwaves;
337 if ( (This->index == 0) && !(This->capture_buffer->flags & DSCBSTART_LOOPING) ) {
338 TRACE("end of buffer\n");
339 This->state = STATE_STOPPED;
341 if (This->state == STATE_CAPTURING) {
342 waveInPrepareHeader(hwi,&(This->pwave[index]),sizeof(WAVEHDR));
343 waveInAddBuffer(hwi, &(This->pwave[index]), sizeof(WAVEHDR));
344 } else if (This->state == STATE_STOPPING) {
346 This->state = STATE_STOPPED;
350 TRACE("DirectSoundCapture new This->state=%s, new This->index=%d\n",
351 captureStateString[This->state],This->index);
352 LeaveCriticalSection( &(This->lock) );
355 TRACE("completed\n");
358 static HRESULT WINAPI
359 IDirectSoundCaptureImpl_QueryInterface(
360 LPDIRECTSOUNDCAPTURE iface,
364 ICOM_THIS(IDirectSoundCaptureImpl,iface);
365 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
368 WARN("invalid parameter\n");
376 hres = IDsCaptureDriver_QueryInterface(This->driver, riid, ppobj);
378 WARN("IDsCaptureDriver_QueryInterface failed\n");
382 WARN("unsupported riid: %s\n", debugstr_guid(riid));
387 IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface )
390 ICOM_THIS(IDirectSoundCaptureImpl,iface);
391 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
393 EnterCriticalSection( &(This->lock) );
394 uRef = ++(This->ref);
397 IDsCaptureDriver_AddRef(This->driver);
399 LeaveCriticalSection( &(This->lock) );
405 IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface )
408 ICOM_THIS(IDirectSoundCaptureImpl,iface);
409 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
411 EnterCriticalSection( &(This->lock) );
413 uRef = --(This->ref);
415 LeaveCriticalSection( &(This->lock) );
418 TRACE("deleting object\n");
420 IDsCaptureDriver_Close(This->driver);
421 IDsCaptureDriver_Release(This->driver);
424 if (This->capture_buffer)
425 IDirectSoundCaptureBufferImpl_Release(
426 (LPDIRECTSOUNDCAPTUREBUFFER8) This->capture_buffer);
429 HeapFree(GetProcessHeap(), 0, This->pwfx);
431 DeleteCriticalSection( &(This->lock) );
432 HeapFree( GetProcessHeap(), 0, This );
433 dsound_capture = NULL;
434 TRACE("(%p) released\n",This);
440 static HRESULT WINAPI
441 IDirectSoundCaptureImpl_CreateCaptureBuffer(
442 LPDIRECTSOUNDCAPTURE iface,
443 LPCDSCBUFFERDESC lpcDSCBufferDesc,
444 LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
448 ICOM_THIS(IDirectSoundCaptureImpl,iface);
450 TRACE( "(%p,%p,%p,%p)\n",This,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk );
453 WARN("invalid parameter: This == NULL\n");
454 return DSERR_INVALIDPARAM;
457 if (lpcDSCBufferDesc == NULL) {
458 WARN("invalid parameter: lpcDSCBufferDesc == NULL)\n");
459 return DSERR_INVALIDPARAM;
462 if (lplpDSCaptureBuffer == NULL) {
463 WARN("invalid parameter: lplpDSCaptureBuffer == NULL\n");
464 return DSERR_INVALIDPARAM;
468 WARN("invalid parameter: pUnk != NULL\n");
469 return DSERR_INVALIDPARAM;
472 /* FIXME: We can only have one buffer so what do we do here? */
473 if (This->capture_buffer) {
474 WARN("lnvalid parameter: already has buffer\n");
475 return DSERR_INVALIDPARAM; /* DSERR_GENERIC ? */
478 hr = DSOUND_CreateDirectSoundCaptureBuffer( This, lpcDSCBufferDesc,
479 (LPVOID*)lplpDSCaptureBuffer );
482 WARN("DSOUND_CreateDirectSoundCaptureBuffer failed\n");
487 static HRESULT WINAPI
488 IDirectSoundCaptureImpl_GetCaps(
489 LPDIRECTSOUNDCAPTURE iface,
490 LPDSCCAPS lpDSCCaps )
492 ICOM_THIS(IDirectSoundCaptureImpl,iface);
493 TRACE("(%p,%p)\n",This,lpDSCCaps);
495 if (lpDSCCaps== NULL) {
496 WARN("invalid parameter: lpDSCCaps== NULL\n");
497 return DSERR_INVALIDPARAM;
500 if (lpDSCCaps->dwSize < sizeof(*lpDSCCaps)) {
501 WARN("invalid parameter: lpDSCCaps->dwSize = %ld < %d\n",
502 lpDSCCaps->dwSize, sizeof(*lpDSCCaps));
503 return DSERR_INVALIDPARAM;
506 if ( !(This->initialized) ) {
507 WARN("not initialized\n");
508 return DSERR_UNINITIALIZED;
511 lpDSCCaps->dwFlags = This->drvcaps.dwFlags;
512 lpDSCCaps->dwFormats = This->drvcaps.dwFormats;
513 lpDSCCaps->dwChannels = This->drvcaps.dwChannels;
515 TRACE("(flags=0x%08lx,format=0x%08lx,channels=%ld)\n",lpDSCCaps->dwFlags,
516 lpDSCCaps->dwFormats, lpDSCCaps->dwChannels);
521 static HRESULT WINAPI
522 IDirectSoundCaptureImpl_Initialize(
523 LPDIRECTSOUNDCAPTURE iface,
526 HRESULT err = DSERR_INVALIDPARAM;
528 ICOM_THIS(IDirectSoundCaptureImpl,iface);
529 TRACE("(%p)\n", This);
532 WARN("invalid parameter: This == NULL\n");
533 return DSERR_INVALIDPARAM;
536 if (This->initialized) {
537 WARN("already initialized\n");
538 return DSERR_ALREADYINITIALIZED;
541 widn = waveInGetNumDevs();
544 WARN("no audio devices found\n");
545 return DSERR_NODRIVER;
548 /* Get dsound configuration */
549 setup_dsound_options();
551 /* enumerate WINMM audio devices and find the one we want */
552 for (wid=0; wid<widn; wid++) {
554 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)(&guid),0));
556 WARN("waveInMessage failed; err=%lx\n",err);
559 if (IsEqualGUID( lpcGUID, &guid) ) {
566 WARN("invalid parameter\n");
567 return DSERR_INVALIDPARAM;
570 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD)&(This->driver),0));
571 if ( (err != DS_OK) && (err != DSERR_UNSUPPORTED) ) {
572 WARN("waveInMessage failed; err=%lx\n",err);
577 /* Disable the direct sound driver to force emulation if requested. */
578 if (ds_hw_accel == DS_HW_ACCEL_EMULATION)
581 /* Get driver description */
583 TRACE("using DirectSound driver\n");
584 err = IDsCaptureDriver_GetDriverDesc(This->driver, &(This->drvdesc));
586 WARN("IDsCaptureDriver_GetDriverDesc failed\n");
590 TRACE("using WINMM\n");
591 /* if no DirectSound interface available, use WINMM API instead */
592 This->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN |
593 DSDDESC_DOMMSYSTEMSETFORMAT;
596 This->drvdesc.dnDevNode = wid;
598 /* open the DirectSound driver if available */
599 if (This->driver && (err == DS_OK))
600 err = IDsCaptureDriver_Open(This->driver);
603 This->initialized = TRUE;
605 /* the driver is now open, so it's now allowed to call GetCaps */
607 This->drvcaps.dwSize = sizeof(This->drvcaps);
608 err = IDsCaptureDriver_GetCaps(This->driver,&(This->drvcaps));
610 WARN("IDsCaptureDriver_GetCaps failed\n");
613 } else /*if (This->hwi)*/ {
615 err = mmErr(waveInGetDevCapsA((UINT)This->drvdesc.dnDevNode, &wic, sizeof(wic)));
618 This->drvcaps.dwFlags = 0;
619 strncpy(This->drvdesc.szDrvName, wic.szPname,
620 sizeof(This->drvdesc.szDrvName));
622 This->drvcaps.dwFlags |= DSCCAPS_EMULDRIVER;
623 This->drvcaps.dwFormats = wic.dwFormats;
624 This->drvcaps.dwChannels = wic.wChannels;
632 static ICOM_VTABLE(IDirectSoundCapture) dscvt =
634 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
635 /* IUnknown methods */
636 IDirectSoundCaptureImpl_QueryInterface,
637 IDirectSoundCaptureImpl_AddRef,
638 IDirectSoundCaptureImpl_Release,
640 /* IDirectSoundCapture methods */
641 IDirectSoundCaptureImpl_CreateCaptureBuffer,
642 IDirectSoundCaptureImpl_GetCaps,
643 IDirectSoundCaptureImpl_Initialize
647 DSOUND_CreateDirectSoundCaptureBuffer(
648 IDirectSoundCaptureImpl *ipDSC,
649 LPCDSCBUFFERDESC lpcDSCBufferDesc,
653 TRACE( "(%p,%p)\n", lpcDSCBufferDesc, ppobj );
656 WARN("invalid parameter: ipDSC == NULL\n");
657 return DSERR_INVALIDPARAM;
660 if (lpcDSCBufferDesc == NULL) {
661 WARN("invalid parameter: lpcDSCBufferDesc == NULL\n");
662 return DSERR_INVALIDPARAM;
666 WARN("invalid parameter: ppobj == NULL\n");
667 return DSERR_INVALIDPARAM;
670 if ( (lpcDSCBufferDesc->dwSize < sizeof(DSCBUFFERDESC)) ||
671 (lpcDSCBufferDesc->dwBufferBytes == 0) ||
672 (lpcDSCBufferDesc->lpwfxFormat == NULL) ) {
673 WARN("invalid lpcDSCBufferDesc\n");
675 return DSERR_INVALIDPARAM;
678 if ( !ipDSC->initialized ) {
679 WARN("not initialized\n");
681 return DSERR_UNINITIALIZED;
684 wfex = lpcDSCBufferDesc->lpwfxFormat;
687 TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
688 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
689 wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
690 wfex->nAvgBytesPerSec, wfex->nBlockAlign,
691 wfex->wBitsPerSample, wfex->cbSize);
693 if (wfex->wFormatTag == WAVE_FORMAT_PCM) {
694 ipDSC->pwfx = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEFORMATEX));
695 memcpy(ipDSC->pwfx, wfex, sizeof(WAVEFORMATEX));
696 ipDSC->pwfx->cbSize = 0;
698 ipDSC->pwfx = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEFORMATEX)+wfex->cbSize);
699 memcpy(ipDSC->pwfx, wfex, sizeof(WAVEFORMATEX)+wfex->cbSize);
702 WARN("lpcDSCBufferDesc->lpwfxFormat == 0\n");
704 return DSERR_INVALIDPARAM; /* FIXME: DSERR_BADFORMAT ? */
707 *ppobj = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
708 sizeof(IDirectSoundCaptureBufferImpl));
710 if ( *ppobj == NULL ) {
711 WARN("out of memory\n");
713 return DSERR_OUTOFMEMORY;
716 ICOM_THIS(IDirectSoundCaptureBufferImpl,*ppobj);
719 This->dsound = ipDSC;
720 This->dsound->capture_buffer = This;
722 This->nrofnotifies = 0;
723 This->hwnotify = NULL;
725 This->pdscbd = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
726 lpcDSCBufferDesc->dwSize);
728 memcpy(This->pdscbd, lpcDSCBufferDesc, lpcDSCBufferDesc->dwSize);
731 This->dsound->capture_buffer = 0;
732 HeapFree( GetProcessHeap(), 0, This );
734 return DSERR_OUTOFMEMORY;
737 This->lpVtbl = &dscbvt;
740 err = IDsCaptureDriver_CreateCaptureBuffer(ipDSC->driver,
741 ipDSC->pwfx,0,0,&(ipDSC->buflen),&(ipDSC->buffer),(LPVOID*)&(ipDSC->hwbuf));
743 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
744 This->dsound->capture_buffer = 0;
745 HeapFree( GetProcessHeap(), 0, This );
752 DWORD flags = CALLBACK_FUNCTION;
753 if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
754 flags |= WAVE_DIRECTSOUND;
755 err = mmErr(waveInOpen(&(ipDSC->hwi),
756 ipDSC->drvdesc.dnDevNode, ipDSC->pwfx,
757 (DWORD)DSOUND_capture_callback, (DWORD)ipDSC, flags));
759 WARN("waveInOpen failed\n");
760 This->dsound->capture_buffer = 0;
761 HeapFree( GetProcessHeap(), 0, This );
766 buflen = lpcDSCBufferDesc->dwBufferBytes;
767 TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->buffer);
769 newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,ipDSC->buffer,buflen);
771 newbuf = (LPBYTE)HeapAlloc(GetProcessHeap(),0,buflen);
772 if (newbuf == NULL) {
773 WARN("failed to allocate capture buffer\n");
774 err = DSERR_OUTOFMEMORY;
775 /* but the old buffer might still exist and must be re-prepared */
777 ipDSC->buffer = newbuf;
778 ipDSC->buflen = buflen;
783 TRACE("returning DS_OK\n");
787 /*******************************************************************************
788 * IDirectSoundCaptureNotify
790 static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_QueryInterface(
791 LPDIRECTSOUNDNOTIFY iface,
795 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
796 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
798 if (This->dscb == NULL) {
799 WARN("invalid parameter\n");
803 return IDirectSoundCaptureBuffer_QueryInterface((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb, riid, ppobj);
806 static ULONG WINAPI IDirectSoundCaptureNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
808 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
811 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
813 ref = InterlockedIncrement(&(This->ref));
817 static ULONG WINAPI IDirectSoundCaptureNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
819 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
822 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
824 ref = InterlockedDecrement(&(This->ref));
826 This->dscb->notify=NULL;
827 IDirectSoundCaptureBuffer_Release((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb);
828 HeapFree(GetProcessHeap(),0,This);
829 TRACE("(%p) released\n",This);
834 static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_SetNotificationPositions(
835 LPDIRECTSOUNDNOTIFY iface,
837 LPCDSBPOSITIONNOTIFY notify)
839 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
840 TRACE("(%p,0x%08lx,%p)\n",This,howmuch,notify);
842 if (notify == NULL) {
843 WARN("invalid parameter: notify == NULL\n");
844 return DSERR_INVALIDPARAM;
847 if (TRACE_ON(dsound)) {
849 for (i=0;i<howmuch;i++)
850 TRACE("notify at %ld to 0x%08lx\n",
851 notify[i].dwOffset,(DWORD)notify[i].hEventNotify);
854 if (This->dscb->hwnotify) {
856 hres = IDsDriverNotify_SetNotificationPositions(This->dscb->hwnotify, howmuch, notify);
858 WARN("IDsDriverNotify_SetNotificationPositions failed\n");
861 /* Make an internal copy of the caller-supplied array.
862 * Replace the existing copy if one is already present. */
863 if (This->dscb->notifies)
864 This->dscb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
865 This->dscb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
867 This->dscb->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
868 howmuch * sizeof(DSBPOSITIONNOTIFY));
870 if (This->dscb->notifies == NULL) {
871 WARN("out of memory\n");
872 return DSERR_OUTOFMEMORY;
874 memcpy(This->dscb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
875 This->dscb->nrofnotifies = howmuch;
881 ICOM_VTABLE(IDirectSoundNotify) dscnvt =
883 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
884 IDirectSoundCaptureNotifyImpl_QueryInterface,
885 IDirectSoundCaptureNotifyImpl_AddRef,
886 IDirectSoundCaptureNotifyImpl_Release,
887 IDirectSoundCaptureNotifyImpl_SetNotificationPositions,
890 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
891 IDirectSoundCaptureBufferImpl *dscb,
892 IDirectSoundCaptureNotifyImpl **pdscn)
894 IDirectSoundCaptureNotifyImpl * dscn;
895 TRACE("(%p,%p)\n",dscb,pdscn);
897 dscn = (IDirectSoundCaptureNotifyImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dscn));
900 WARN("out of memory\n");
901 return DSERR_OUTOFMEMORY;
905 dscn->lpVtbl = &dscnvt;
908 IDirectSoundCaptureBuffer_AddRef((LPDIRECTSOUNDCAPTUREBUFFER)dscb);
914 /*******************************************************************************
915 * IDirectSoundCaptureBuffer
917 static HRESULT WINAPI
918 IDirectSoundCaptureBufferImpl_QueryInterface(
919 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
923 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
925 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
928 WARN("invalid parameter\n");
934 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ||
935 IsEqualGUID( &IID_IDirectSoundNotify8, riid ) ) {
937 hres = IDirectSoundCaptureNotifyImpl_Create(This, &This->notify);
939 if (This->dsound->hwbuf) {
940 hres = IDsCaptureDriverBuffer_QueryInterface(This->dsound->hwbuf,
941 &IID_IDsDriverNotify, (LPVOID*)&(This->hwnotify));
943 WARN("IDsCaptureDriverBuffer_QueryInterface failed\n");
949 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
950 *ppobj = (LPVOID)This->notify;
954 WARN("IID_IDirectSoundNotify\n");
958 if ( IsEqualGUID( &IID_IDirectSoundCaptureBuffer, riid ) ||
959 IsEqualGUID( &IID_IDirectSoundCaptureBuffer8, riid ) ) {
960 IDirectSoundCaptureBuffer8_AddRef(iface);
965 FIXME("(%p,%s,%p) unsupported GUID\n", This, debugstr_guid(riid), ppobj);
966 return E_NOINTERFACE;
970 IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
973 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
974 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
976 assert(This->dsound);
978 EnterCriticalSection( &(This->dsound->lock) );
980 uRef = ++(This->ref);
982 LeaveCriticalSection( &(This->dsound->lock) );
988 IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
991 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
992 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
994 assert(This->dsound);
996 EnterCriticalSection( &(This->dsound->lock) );
998 uRef = --(This->ref);
1000 LeaveCriticalSection( &(This->dsound->lock) );
1003 TRACE("deleting object\n");
1005 HeapFree(GetProcessHeap(),0, This->pdscbd);
1007 if (This->dsound->hwi) {
1008 waveInReset(This->dsound->hwi);
1009 waveInClose(This->dsound->hwi);
1010 if (This->dsound->pwave) {
1011 HeapFree(GetProcessHeap(),0, This->dsound->pwave);
1012 This->dsound->pwave = 0;
1014 This->dsound->hwi = 0;
1017 if (This->dsound->hwbuf)
1018 IDsCaptureDriverBuffer_Release(This->dsound->hwbuf);
1020 /* remove from IDirectSoundCaptureImpl */
1022 This->dsound->capture_buffer = NULL;
1024 ERR("does not reference dsound\n");
1027 IDirectSoundNotify_Release((LPDIRECTSOUNDNOTIFY)This->notify);
1029 if (This->notifies != NULL)
1030 HeapFree(GetProcessHeap(), 0, This->notifies);
1032 HeapFree( GetProcessHeap(), 0, This );
1033 TRACE("(%p) released\n",This);
1039 static HRESULT WINAPI
1040 IDirectSoundCaptureBufferImpl_GetCaps(
1041 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1042 LPDSCBCAPS lpDSCBCaps )
1044 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1045 TRACE( "(%p,%p)\n", This, lpDSCBCaps );
1048 WARN("invalid parameter: This == NULL\n");
1049 return DSERR_INVALIDPARAM;
1052 if (lpDSCBCaps == NULL) {
1053 WARN("invalid parameter: lpDSCBCaps == NULL\n");
1054 return DSERR_INVALIDPARAM;
1057 if (lpDSCBCaps->dwSize < sizeof(DSCBCAPS)) {
1058 WARN("invalid parameter: lpDSCBCaps->dwSize = %ld < %d\n",
1059 lpDSCBCaps->dwSize, sizeof(DSCBCAPS));
1060 return DSERR_INVALIDPARAM;
1063 if (This->dsound == NULL) {
1064 WARN("invalid parameter: This->dsound == NULL\n");
1065 return DSERR_INVALIDPARAM;
1068 lpDSCBCaps->dwSize = sizeof(DSCBCAPS);
1069 lpDSCBCaps->dwFlags = This->flags;
1070 lpDSCBCaps->dwBufferBytes = This->pdscbd->dwBufferBytes;
1071 lpDSCBCaps->dwReserved = 0;
1073 TRACE("returning DS_OK\n");
1077 static HRESULT WINAPI
1078 IDirectSoundCaptureBufferImpl_GetCurrentPosition(
1079 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1080 LPDWORD lpdwCapturePosition,
1081 LPDWORD lpdwReadPosition )
1083 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1084 TRACE( "(%p,%p,%p)\n", This, lpdwCapturePosition, lpdwReadPosition );
1087 WARN("invalid parameter: This == NULL\n");
1088 return DSERR_INVALIDPARAM;
1091 if (This->dsound == NULL) {
1092 WARN("invalid parameter: This->dsound == NULL\n");
1093 return DSERR_INVALIDPARAM;
1096 if (This->dsound->driver) {
1098 hres = IDsCaptureDriverBuffer_GetPosition(This->dsound->hwbuf, lpdwCapturePosition, lpdwReadPosition );
1099 if (hres != DS_OK) {
1100 WARN("IDsCaptureDriverBuffer_GetPosition failed\n");
1103 } else if (This->dsound->hwi) {
1104 EnterCriticalSection(&(This->dsound->lock));
1105 TRACE("old This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1106 if (lpdwCapturePosition) {
1108 mtime.wType = TIME_BYTES;
1109 waveInGetPosition(This->dsound->hwi, &mtime, sizeof(mtime));
1110 TRACE("mtime.u.cb=%ld,This->dsound->buflen=%ld\n", mtime.u.cb,
1111 This->dsound->buflen);
1112 mtime.u.cb = mtime.u.cb % This->dsound->buflen;
1113 *lpdwCapturePosition = mtime.u.cb;
1116 if (lpdwReadPosition) {
1117 if (This->dsound->state == STATE_STARTING) {
1118 if (lpdwCapturePosition)
1119 This->dsound->read_position = *lpdwCapturePosition;
1120 This->dsound->state = STATE_CAPTURING;
1122 *lpdwReadPosition = This->dsound->read_position;
1124 TRACE("new This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1125 LeaveCriticalSection(&(This->dsound->lock));
1126 if (lpdwCapturePosition) TRACE("*lpdwCapturePosition=%ld\n",*lpdwCapturePosition);
1127 if (lpdwReadPosition) TRACE("*lpdwReadPosition=%ld\n",*lpdwReadPosition);
1129 WARN("no driver\n");
1130 return DSERR_NODRIVER;
1133 TRACE("returning DS_OK\n");
1137 static HRESULT WINAPI
1138 IDirectSoundCaptureBufferImpl_GetFormat(
1139 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1140 LPWAVEFORMATEX lpwfxFormat,
1141 DWORD dwSizeAllocated,
1142 LPDWORD lpdwSizeWritten )
1144 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1145 TRACE( "(%p,%p,0x%08lx,%p)\n", This, lpwfxFormat, dwSizeAllocated,
1149 WARN("invalid parameter: This == NULL\n");
1150 return DSERR_INVALIDPARAM;
1153 if (This->dsound == NULL) {
1154 WARN("invalid parameter: This->dsound == NULL\n");
1155 return DSERR_INVALIDPARAM;
1158 if (dwSizeAllocated > (sizeof(WAVEFORMATEX) + This->dsound->pwfx->cbSize))
1159 dwSizeAllocated = sizeof(WAVEFORMATEX) + This->dsound->pwfx->cbSize;
1161 if (lpwfxFormat) { /* NULL is valid (just want size) */
1162 memcpy(lpwfxFormat, This->dsound->pwfx, dwSizeAllocated);
1163 if (lpdwSizeWritten)
1164 *lpdwSizeWritten = dwSizeAllocated;
1166 if (lpdwSizeWritten)
1167 *lpdwSizeWritten = sizeof(WAVEFORMATEX) + This->dsound->pwfx->cbSize;
1169 TRACE("invalid parameter: lpdwSizeWritten = NULL\n");
1170 return DSERR_INVALIDPARAM;
1174 TRACE("returning DS_OK\n");
1178 static HRESULT WINAPI
1179 IDirectSoundCaptureBufferImpl_GetStatus(
1180 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1181 LPDWORD lpdwStatus )
1183 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1184 TRACE( "(%p, %p), thread is %04lx\n", This, lpdwStatus, GetCurrentThreadId() );
1187 WARN("invalid parameter: This == NULL\n");
1188 return DSERR_INVALIDPARAM;
1191 if (This->dsound == NULL) {
1192 WARN("invalid parameter: This->dsound == NULL\n");
1193 return DSERR_INVALIDPARAM;
1196 if (lpdwStatus == NULL) {
1197 WARN("invalid parameter: lpdwStatus == NULL\n");
1198 return DSERR_INVALIDPARAM;
1202 EnterCriticalSection(&(This->dsound->lock));
1204 TRACE("old This->dsound->state=%s, old lpdwStatus=%08lx\n",
1205 captureStateString[This->dsound->state],*lpdwStatus);
1206 if ((This->dsound->state == STATE_STARTING) ||
1207 (This->dsound->state == STATE_CAPTURING)) {
1208 *lpdwStatus |= DSCBSTATUS_CAPTURING;
1209 if (This->flags & DSCBSTART_LOOPING)
1210 *lpdwStatus |= DSCBSTATUS_LOOPING;
1212 TRACE("new This->dsound->state=%s, new lpdwStatus=%08lx\n",
1213 captureStateString[This->dsound->state],*lpdwStatus);
1214 LeaveCriticalSection(&(This->dsound->lock));
1216 TRACE("status=%lx\n", *lpdwStatus);
1217 TRACE("returning DS_OK\n");
1221 static HRESULT WINAPI
1222 IDirectSoundCaptureBufferImpl_Initialize(
1223 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1224 LPDIRECTSOUNDCAPTURE lpDSC,
1225 LPCDSCBUFFERDESC lpcDSCBDesc )
1227 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1229 FIXME( "(%p,%p,%p): stub\n", This, lpDSC, lpcDSCBDesc );
1234 static HRESULT WINAPI
1235 IDirectSoundCaptureBufferImpl_Lock(
1236 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1239 LPVOID* lplpvAudioPtr1,
1240 LPDWORD lpdwAudioBytes1,
1241 LPVOID* lplpvAudioPtr2,
1242 LPDWORD lpdwAudioBytes2,
1245 HRESULT err = DS_OK;
1246 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1247 TRACE( "(%p,%08lu,%08lu,%p,%p,%p,%p,0x%08lx) at %ld\n", This, dwReadCusor,
1248 dwReadBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2,
1249 lpdwAudioBytes2, dwFlags, GetTickCount() );
1252 WARN("invalid parameter: This == NULL\n");
1253 return DSERR_INVALIDPARAM;
1256 if (This->dsound == NULL) {
1257 WARN("invalid parameter: This->dsound == NULL\n");
1258 return DSERR_INVALIDPARAM;
1261 if (lplpvAudioPtr1 == NULL) {
1262 WARN("invalid parameter: lplpvAudioPtr1 == NULL\n");
1263 return DSERR_INVALIDPARAM;
1266 if (lpdwAudioBytes1 == NULL) {
1267 WARN("invalid parameter: lpdwAudioBytes1 == NULL\n");
1268 return DSERR_INVALIDPARAM;
1271 EnterCriticalSection(&(This->dsound->lock));
1273 if (This->dsound->driver) {
1274 err = IDsCaptureDriverBuffer_Lock(This->dsound->hwbuf, lplpvAudioPtr1,
1275 lpdwAudioBytes1, lplpvAudioPtr2, lpdwAudioBytes2,
1276 dwReadCusor, dwReadBytes, dwFlags);
1278 WARN("IDsCaptureDriverBuffer_Lock failed\n");
1279 } else if (This->dsound->hwi) {
1280 *lplpvAudioPtr1 = This->dsound->buffer + dwReadCusor;
1281 if ( (dwReadCusor + dwReadBytes) > This->dsound->buflen) {
1282 *lpdwAudioBytes1 = This->dsound->buflen - dwReadCusor;
1284 *lplpvAudioPtr2 = This->dsound->buffer;
1285 if (lpdwAudioBytes2)
1286 *lpdwAudioBytes2 = dwReadBytes - *lpdwAudioBytes1;
1288 *lpdwAudioBytes1 = dwReadBytes;
1290 *lplpvAudioPtr2 = 0;
1291 if (lpdwAudioBytes2)
1292 *lpdwAudioBytes2 = 0;
1295 TRACE("invalid call\n");
1296 err = DSERR_INVALIDCALL; /* DSERR_NODRIVER ? */
1299 LeaveCriticalSection(&(This->dsound->lock));
1304 static HRESULT WINAPI
1305 IDirectSoundCaptureBufferImpl_Start(
1306 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1309 HRESULT err = DS_OK;
1310 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1311 TRACE( "(%p,0x%08lx)\n", This, dwFlags );
1314 WARN("invalid parameter: This == NULL\n");
1315 return DSERR_INVALIDPARAM;
1318 if (This->dsound == NULL) {
1319 WARN("invalid parameter: This->dsound == NULL\n");
1320 return DSERR_INVALIDPARAM;
1323 if ( (This->dsound->driver == 0) && (This->dsound->hwi == 0) ) {
1324 WARN("no driver\n");
1325 return DSERR_NODRIVER;
1328 EnterCriticalSection(&(This->dsound->lock));
1330 This->flags = dwFlags;
1331 TRACE("old This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1332 if (This->dsound->state == STATE_STOPPED)
1333 This->dsound->state = STATE_STARTING;
1334 else if (This->dsound->state == STATE_STOPPING)
1335 This->dsound->state = STATE_CAPTURING;
1336 TRACE("new This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1338 LeaveCriticalSection(&(This->dsound->lock));
1340 if (This->dsound->driver) {
1341 err = IDsCaptureDriverBuffer_Start(This->dsound->hwbuf, dwFlags);
1343 WARN("IDsCaptureDriverBuffer_Start failed\n");
1346 IDirectSoundCaptureImpl* ipDSC = This->dsound;
1348 if (ipDSC->buffer) {
1349 if (This->nrofnotifies) {
1352 ipDSC->nrofpwaves = This->nrofnotifies;
1353 TRACE("nrofnotifies=%d\n", This->nrofnotifies);
1355 /* prepare headers */
1357 ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,
1358 ipDSC->nrofpwaves*sizeof(WAVEHDR));
1360 ipDSC->pwave = HeapAlloc(GetProcessHeap(),0,
1361 ipDSC->nrofpwaves*sizeof(WAVEHDR));
1363 for (c = 0; c < ipDSC->nrofpwaves; c++) {
1365 ipDSC->pwave[0].lpData = ipDSC->buffer;
1366 ipDSC->pwave[0].dwBufferLength =
1367 This->notifies[0].dwOffset + 1;
1369 ipDSC->pwave[c].lpData = ipDSC->buffer +
1370 This->notifies[c-1].dwOffset + 1;
1371 ipDSC->pwave[c].dwBufferLength =
1372 This->notifies[c].dwOffset -
1373 This->notifies[c-1].dwOffset;
1375 ipDSC->pwave[c].dwBytesRecorded = 0;
1376 ipDSC->pwave[c].dwUser = (DWORD)ipDSC;
1377 ipDSC->pwave[c].dwFlags = 0;
1378 ipDSC->pwave[c].dwLoops = 0;
1379 err = mmErr(waveInPrepareHeader(ipDSC->hwi,
1380 &(ipDSC->pwave[c]),sizeof(WAVEHDR)));
1383 waveInUnprepareHeader(ipDSC->hwi,
1384 &(ipDSC->pwave[c]),sizeof(WAVEHDR));
1388 err = mmErr(waveInAddBuffer(ipDSC->hwi,
1389 &(ipDSC->pwave[c]), sizeof(WAVEHDR)));
1392 waveInUnprepareHeader(ipDSC->hwi,
1393 &(ipDSC->pwave[c]),sizeof(WAVEHDR));
1398 memset(ipDSC->buffer,
1399 (ipDSC->pwfx->wBitsPerSample == 8) ? 128 : 0, ipDSC->buflen);
1401 TRACE("no notifiers specified\n");
1402 /* no notifiers specified so just create a single default header */
1403 ipDSC->nrofpwaves = 1;
1405 ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,sizeof(WAVEHDR));
1407 ipDSC->pwave = HeapAlloc(GetProcessHeap(),0,sizeof(WAVEHDR));
1409 ipDSC->pwave[0].lpData = ipDSC->buffer;
1410 ipDSC->pwave[0].dwBufferLength = ipDSC->buflen;
1411 ipDSC->pwave[0].dwBytesRecorded = 0;
1412 ipDSC->pwave[0].dwUser = (DWORD)ipDSC;
1413 ipDSC->pwave[0].dwFlags = 0;
1414 ipDSC->pwave[0].dwLoops = 0;
1416 err = mmErr(waveInPrepareHeader(ipDSC->hwi,
1417 &(ipDSC->pwave[0]),sizeof(WAVEHDR)));
1419 WARN("waveInPrepareHeader failed\n");
1420 waveInUnprepareHeader(ipDSC->hwi,
1421 &(ipDSC->pwave[0]),sizeof(WAVEHDR));
1423 err = mmErr(waveInAddBuffer(ipDSC->hwi,
1424 &(ipDSC->pwave[0]), sizeof(WAVEHDR)));
1426 waveInUnprepareHeader(ipDSC->hwi,
1427 &(ipDSC->pwave[0]),sizeof(WAVEHDR));
1433 ipDSC->read_position = 0;
1436 /* start filling the first buffer */
1437 err = mmErr(waveInStart(ipDSC->hwi));
1442 WARN("calling waveInClose because of error\n");
1443 waveInClose(This->dsound->hwi);
1444 This->dsound->hwi = 0;
1447 TRACE("returning %ld\n", err);
1451 static HRESULT WINAPI
1452 IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
1454 HRESULT err = DS_OK;
1455 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1456 TRACE( "(%p)\n", This );
1459 WARN("invalid parameter: This == NULL\n");
1460 return DSERR_INVALIDPARAM;
1463 if (This->dsound == NULL) {
1464 WARN("invalid parameter: This->dsound == NULL\n");
1465 return DSERR_INVALIDPARAM;
1468 EnterCriticalSection(&(This->dsound->lock));
1470 TRACE("old This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1471 if (This->dsound->state == STATE_CAPTURING)
1472 This->dsound->state = STATE_STOPPING;
1473 else if (This->dsound->state == STATE_STARTING)
1474 This->dsound->state = STATE_STOPPED;
1475 TRACE("new This->dsound->state=%s\n",captureStateString[This->dsound->state]);
1477 LeaveCriticalSection(&(This->dsound->lock));
1479 if (This->dsound->driver) {
1480 err = IDsCaptureDriverBuffer_Stop(This->dsound->hwbuf);
1481 if (err == DSERR_BUFFERLOST) {
1482 /* Wine-only: the driver wants us to reopen the device */
1483 IDsCaptureDriverBuffer_Release(This->dsound->hwbuf);
1484 err = IDsCaptureDriver_CreateCaptureBuffer(This->dsound->driver,
1485 This->dsound->pwfx,0,0,&(This->dsound->buflen),&(This->dsound->buffer),
1486 (LPVOID*)&(This->dsound->hwbuf));
1488 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
1489 This->dsound->hwbuf = 0;
1491 } else if (err != DS_OK)
1492 WARN("IDsCaptureDriverBuffer_Stop failed\n");
1493 } else if (This->dsound->hwi) {
1494 err = waveInStop(This->dsound->hwi);
1496 WARN("no driver\n");
1497 err = DSERR_NODRIVER;
1500 TRACE( "(%p) returning 0x%08lx\n", This,err);
1504 static HRESULT WINAPI
1505 IDirectSoundCaptureBufferImpl_Unlock(
1506 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1507 LPVOID lpvAudioPtr1,
1508 DWORD dwAudioBytes1,
1509 LPVOID lpvAudioPtr2,
1510 DWORD dwAudioBytes2 )
1512 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1513 TRACE( "(%p,%p,%08lu,%p,%08lu)\n", This, lpvAudioPtr1, dwAudioBytes1,
1514 lpvAudioPtr2, dwAudioBytes2 );
1517 WARN("invalid parameter: This == NULL\n");
1518 return DSERR_INVALIDPARAM;
1521 if (lpvAudioPtr1 == NULL) {
1522 WARN("invalid parameter: lpvAudioPtr1 == NULL\n");
1523 return DSERR_INVALIDPARAM;
1526 if (This->dsound->driver) {
1528 hres = IDsCaptureDriverBuffer_Unlock(This->dsound->hwbuf, lpvAudioPtr1,
1529 dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1531 WARN("IDsCaptureDriverBuffer_Unlock failed\n");
1533 } else if (This->dsound->hwi) {
1534 This->dsound->read_position = (This->dsound->read_position +
1535 (dwAudioBytes1 + dwAudioBytes2)) % This->dsound->buflen;
1537 WARN("invalid call\n");
1538 return DSERR_INVALIDCALL;
1544 static HRESULT WINAPI
1545 IDirectSoundCaptureBufferImpl_GetObjectInPath(
1546 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1547 REFGUID rguidObject,
1549 REFGUID rguidInterface,
1552 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1554 FIXME( "(%p,%s,%lu,%s,%p): stub\n", This, debugstr_guid(rguidObject),
1555 dwIndex, debugstr_guid(rguidInterface), ppObject );
1560 static HRESULT WINAPI
1561 IDirectSoundCaptureBufferImpl_GetFXStatus(
1562 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1564 LPDWORD pdwFXStatus )
1566 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1568 FIXME( "(%p,%lu,%p): stub\n", This, dwFXCount, pdwFXStatus );
1573 static ICOM_VTABLE(IDirectSoundCaptureBuffer8) dscbvt =
1575 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1576 /* IUnknown methods */
1577 IDirectSoundCaptureBufferImpl_QueryInterface,
1578 IDirectSoundCaptureBufferImpl_AddRef,
1579 IDirectSoundCaptureBufferImpl_Release,
1581 /* IDirectSoundCaptureBuffer methods */
1582 IDirectSoundCaptureBufferImpl_GetCaps,
1583 IDirectSoundCaptureBufferImpl_GetCurrentPosition,
1584 IDirectSoundCaptureBufferImpl_GetFormat,
1585 IDirectSoundCaptureBufferImpl_GetStatus,
1586 IDirectSoundCaptureBufferImpl_Initialize,
1587 IDirectSoundCaptureBufferImpl_Lock,
1588 IDirectSoundCaptureBufferImpl_Start,
1589 IDirectSoundCaptureBufferImpl_Stop,
1590 IDirectSoundCaptureBufferImpl_Unlock,
1592 /* IDirectSoundCaptureBuffer methods */
1593 IDirectSoundCaptureBufferImpl_GetObjectInPath,
1594 IDirectSoundCaptureBufferImpl_GetFXStatus
1597 /*******************************************************************************
1598 * DirectSoundCapture ClassFactory
1601 static HRESULT WINAPI
1602 DSCCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1604 ICOM_THIS(IClassFactoryImpl,iface);
1606 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1607 return E_NOINTERFACE;
1611 DSCCF_AddRef(LPCLASSFACTORY iface)
1613 ICOM_THIS(IClassFactoryImpl,iface);
1614 TRACE("(%p) ref was %ld\n", This, This->ref);
1615 return ++(This->ref);
1619 DSCCF_Release(LPCLASSFACTORY iface)
1621 ICOM_THIS(IClassFactoryImpl,iface);
1622 /* static class, won't be freed */
1623 TRACE("(%p) ref was %ld\n", This, This->ref);
1624 return --(This->ref);
1627 static HRESULT WINAPI
1628 DSCCF_CreateInstance(
1629 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj )
1631 ICOM_THIS(IClassFactoryImpl,iface);
1632 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1634 if (ppobj == NULL) {
1635 WARN("invalid parameter\n");
1636 return E_INVALIDARG;
1641 if ( IsEqualGUID( &IID_IDirectSoundCapture, riid ) ||
1642 IsEqualGUID( &IID_IDirectSoundCapture8, riid ) ) {
1643 return DirectSoundCaptureCreate8(0,(LPDIRECTSOUNDCAPTURE8*)ppobj,pOuter);
1646 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
1647 return E_NOINTERFACE;
1650 static HRESULT WINAPI
1651 DSCCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1653 ICOM_THIS(IClassFactoryImpl,iface);
1654 FIXME("(%p)->(%d),stub!\n",This,dolock);
1658 static ICOM_VTABLE(IClassFactory) DSCCF_Vtbl =
1660 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1661 DSCCF_QueryInterface,
1664 DSCCF_CreateInstance,
1668 IClassFactoryImpl DSOUND_CAPTURE_CF = { &DSCCF_Vtbl, 1 };
1670 /***************************************************************************
1671 * DirectSoundFullDuplexCreate8 [DSOUND.10]
1673 * Create and initialize a DirectSoundFullDuplex interface.
1676 * pcGuidCaptureDevice [I] Address of sound capture device GUID.
1677 * pcGuidRenderDevice [I] Address of sound render device GUID.
1678 * pcDSCBufferDesc [I] Address of capture buffer description.
1679 * pcDSBufferDesc [I] Address of render buffer description.
1680 * hWnd [I] Handle to application window.
1681 * dwLevel [I] Cooperative level.
1682 * ppDSFD [O] Address where full duplex interface returned.
1683 * ppDSCBuffer8 [0] Address where capture buffer interface returned.
1684 * ppDSBuffer8 [0] Address where render buffer interface returned.
1685 * pUnkOuter [I] Must be NULL.
1689 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
1690 * DSERR_OUTOFMEMORY DSERR_INVALIDCALL DSERR_NODRIVER
1693 DirectSoundFullDuplexCreate8(
1694 LPCGUID pcGuidCaptureDevice,
1695 LPCGUID pcGuidRenderDevice,
1696 LPCDSCBUFFERDESC pcDSCBufferDesc,
1697 LPCDSBUFFERDESC pcDSBufferDesc,
1700 LPDIRECTSOUNDFULLDUPLEX *ppDSFD,
1701 LPDIRECTSOUNDCAPTUREBUFFER8 *ppDSCBuffer8,
1702 LPDIRECTSOUNDBUFFER8 *ppDSBuffer8,
1703 LPUNKNOWN pUnkOuter)
1705 IDirectSoundFullDuplexImpl** ippDSFD=(IDirectSoundFullDuplexImpl**)ppDSFD;
1706 TRACE("(%s,%s,%p,%p,%lx,%lx,%p,%p,%p,%p)\n", debugstr_guid(pcGuidCaptureDevice),
1707 debugstr_guid(pcGuidRenderDevice), pcDSCBufferDesc, pcDSBufferDesc,
1708 (DWORD)hWnd, dwLevel, ppDSFD, ppDSCBuffer8, ppDSBuffer8, pUnkOuter);
1711 WARN("pUnkOuter != 0\n");
1712 return DSERR_NOAGGREGATION;
1715 *ippDSFD = (IDirectSoundFullDuplexImpl*)HeapAlloc(GetProcessHeap(),
1716 HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
1718 if (*ippDSFD == NULL) {
1719 WARN("out of memory\n");
1720 return DSERR_OUTOFMEMORY;
1723 ICOM_THIS(IDirectSoundFullDuplexImpl, *ippDSFD);
1726 This->lpVtbl = &dsfdvt;
1728 InitializeCriticalSection( &(This->lock) );
1730 hres = IDirectSoundFullDuplexImpl_Initialize( (LPDIRECTSOUNDFULLDUPLEX)This,
1731 pcGuidCaptureDevice, pcGuidRenderDevice,
1732 pcDSCBufferDesc, pcDSBufferDesc,
1733 hWnd, dwLevel, ppDSCBuffer8, ppDSBuffer8);
1735 WARN("IDirectSoundFullDuplexImpl_Initialize failed\n");
1739 return DSERR_GENERIC;
1742 static HRESULT WINAPI
1743 IDirectSoundFullDuplexImpl_QueryInterface(
1744 LPDIRECTSOUNDFULLDUPLEX iface,
1748 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1749 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
1751 if (ppobj == NULL) {
1752 WARN("invalid parameter\n");
1753 return E_INVALIDARG;
1757 return E_NOINTERFACE;
1761 IDirectSoundFullDuplexImpl_AddRef( LPDIRECTSOUNDFULLDUPLEX iface )
1764 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1765 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1767 EnterCriticalSection( &(This->lock) );
1769 uRef = ++(This->ref);
1771 LeaveCriticalSection( &(This->lock) );
1777 IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface )
1780 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1781 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1783 EnterCriticalSection( &(This->lock) );
1785 uRef = --(This->ref);
1787 LeaveCriticalSection( &(This->lock) );
1790 DeleteCriticalSection( &(This->lock) );
1791 HeapFree( GetProcessHeap(), 0, This );
1792 TRACE("(%p) released\n",This);
1798 static HRESULT WINAPI
1799 IDirectSoundFullDuplexImpl_Initialize(
1800 LPDIRECTSOUNDFULLDUPLEX iface,
1801 LPCGUID pCaptureGuid,
1802 LPCGUID pRendererGuid,
1803 LPCDSCBUFFERDESC lpDscBufferDesc,
1804 LPCDSBUFFERDESC lpDsBufferDesc,
1807 LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8,
1808 LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 )
1810 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1811 IDirectSoundCaptureBufferImpl** ippdscb=(IDirectSoundCaptureBufferImpl**)lplpDirectSoundCaptureBuffer8;
1812 IDirectSoundBufferImpl** ippdsc=(IDirectSoundBufferImpl**)lplpDirectSoundBuffer8;
1814 FIXME( "(%p,%s,%s,%p,%p,%lx,%lx,%p,%p) stub!\n", This, debugstr_guid(pCaptureGuid),
1815 debugstr_guid(pRendererGuid), lpDscBufferDesc, lpDsBufferDesc, (DWORD)hWnd, dwLevel,
1821 static ICOM_VTABLE(IDirectSoundFullDuplex) dsfdvt =
1823 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1824 /* IUnknown methods */
1825 IDirectSoundFullDuplexImpl_QueryInterface,
1826 IDirectSoundFullDuplexImpl_AddRef,
1827 IDirectSoundFullDuplexImpl_Release,
1829 /* IDirectSoundFullDuplex methods */
1830 IDirectSoundFullDuplexImpl_Initialize
1833 /*******************************************************************************
1834 * DirectSoundFullDuplex ClassFactory
1837 static HRESULT WINAPI
1838 DSFDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1840 ICOM_THIS(IClassFactoryImpl,iface);
1842 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1843 return E_NOINTERFACE;
1847 DSFDCF_AddRef(LPCLASSFACTORY iface)
1849 ICOM_THIS(IClassFactoryImpl,iface);
1850 TRACE("(%p) ref was %ld\n", This, This->ref);
1851 return ++(This->ref);
1855 DSFDCF_Release(LPCLASSFACTORY iface)
1857 ICOM_THIS(IClassFactoryImpl,iface);
1858 /* static class, won't be freed */
1859 TRACE("(%p) ref was %ld\n", This, This->ref);
1860 return --(This->ref);
1863 static HRESULT WINAPI
1864 DSFDCF_CreateInstance(
1865 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj )
1867 ICOM_THIS(IClassFactoryImpl,iface);
1869 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1871 if (ppobj == NULL) {
1872 WARN("invalid parameter\n");
1873 return E_INVALIDARG;
1878 if ( IsEqualGUID( &IID_IDirectSoundFullDuplex, riid ) ) {
1879 /* FIXME: how do we do this one ? */
1880 FIXME("not implemented\n");
1881 return E_NOINTERFACE;
1884 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
1885 return E_NOINTERFACE;
1888 static HRESULT WINAPI
1889 DSFDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1891 ICOM_THIS(IClassFactoryImpl,iface);
1892 FIXME("(%p)->(%d),stub!\n",This,dolock);
1896 static ICOM_VTABLE(IClassFactory) DSFDCF_Vtbl =
1898 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1899 DSFDCF_QueryInterface,
1902 DSFDCF_CreateInstance,
1906 IClassFactoryImpl DSOUND_FULLDUPLEX_CF = { &DSFDCF_Vtbl, 1 };