3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998 Rob Riggs
5 * Copyright 2000-2001 TransGaming Technologies, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Implement DirectSoundFullDuplex support.
24 * Implement FX support.
30 #include <sys/types.h>
31 #include <sys/fcntl.h>
47 #include "wine/debug.h"
50 #include "dsound_private.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(dsound
);
54 static HRESULT WINAPI
IDirectSoundCaptureImpl_Initialize(
55 LPDIRECTSOUNDCAPTURE iface
,
57 static ULONG WINAPI
IDirectSoundCaptureImpl_Release(
58 LPDIRECTSOUNDCAPTURE iface
);
59 static ULONG WINAPI
IDirectSoundCaptureBufferImpl_Release(
60 LPDIRECTSOUNDCAPTUREBUFFER8 iface
);
61 static HRESULT
DSOUND_CreateDirectSoundCaptureBuffer(
62 IDirectSoundCaptureImpl
*ipDSC
,
63 LPCDSCBUFFERDESC lpcDSCBufferDesc
,
65 static HRESULT WINAPI
IDirectSoundFullDuplexImpl_Initialize(
66 LPDIRECTSOUNDFULLDUPLEX iface
,
68 LPCGUID pRendererGuid
,
69 LPCDSCBUFFERDESC lpDscBufferDesc
,
70 LPCDSBUFFERDESC lpDsBufferDesc
,
73 LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8
,
74 LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8
);
76 static ICOM_VTABLE(IDirectSoundCapture
) dscvt
;
77 static ICOM_VTABLE(IDirectSoundCaptureBuffer8
) dscbvt
;
78 static ICOM_VTABLE(IDirectSoundFullDuplex
) dsfdvt
;
80 IDirectSoundCaptureImpl
* dsound_capture
= NULL
;
82 /***************************************************************************
83 * DirectSoundCaptureCreate [DSOUND.6]
85 * Create and initialize a DirectSoundCapture interface.
88 * lpcGUID [I] Address of the GUID that identifies the sound capture device.
89 * lplpDSC [O] Address of a variable to receive the interface pointer.
90 * pUnkOuter [I] Must be NULL.
94 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
98 * lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
99 * or NULL for the default device or DSDEVID_DefaultCapture or
100 * DSDEVID_DefaultVoiceCapture.
102 * DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
105 DirectSoundCaptureCreate8(
107 LPDIRECTSOUNDCAPTURE
* lplpDSC
,
108 LPUNKNOWN pUnkOuter
)
110 IDirectSoundCaptureImpl
** ippDSC
=(IDirectSoundCaptureImpl
**)lplpDSC
;
111 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID
), lplpDSC
, pUnkOuter
);
114 WARN("invalid parameter: pUnkOuter != NULL\n");
115 return DSERR_NOAGGREGATION
;
119 WARN("invalid parameter: lplpDSC == NULL\n");
120 return DSERR_INVALIDPARAM
;
123 /* Default device? */
124 if ( !lpcGUID
|| IsEqualGUID(lpcGUID
, &GUID_NULL
) )
125 lpcGUID
= &DSDEVID_DefaultCapture
;
127 *ippDSC
= (IDirectSoundCaptureImpl
*)HeapAlloc(GetProcessHeap(),
128 HEAP_ZERO_MEMORY
, sizeof(IDirectSoundCaptureImpl
));
130 if (*ippDSC
== NULL
) {
131 WARN("out of memory\n");
132 return DSERR_OUTOFMEMORY
;
134 ICOM_THIS(IDirectSoundCaptureImpl
, *ippDSC
);
137 This
->state
= STATE_STOPPED
;
139 InitializeCriticalSection( &(This
->lock
) );
141 This
->lpVtbl
= &dscvt
;
142 dsound_capture
= This
;
144 if (GetDeviceID(lpcGUID
, &This
->guid
) == DS_OK
) {
146 hres
= IDirectSoundCaptureImpl_Initialize( (LPDIRECTSOUNDCAPTURE
)This
, &This
->guid
);
148 WARN("IDirectSoundCaptureImpl_Initialize failed\n");
152 WARN("invalid GUID: %s\n", debugstr_guid(lpcGUID
));
153 return DSERR_INVALIDPARAM
;
156 /***************************************************************************
157 * DirectSoundCaptureEnumerateA [DSOUND.7]
159 * Enumerate all DirectSound drivers installed in the system.
162 * lpDSEnumCallback [I] Address of callback function.
163 * lpContext [I] Address of user defined context passed to callback function.
167 * Failure: DSERR_INVALIDPARAM
170 DirectSoundCaptureEnumerateA(
171 LPDSENUMCALLBACKA lpDSEnumCallback
,
179 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
181 if (lpDSEnumCallback
== NULL
) {
182 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
183 return DSERR_INVALIDPARAM
;
186 devs
= waveInGetNumDevs();
188 if (GetDeviceID(&DSDEVID_DefaultCapture
, &guid
) == DS_OK
) {
190 for (wid
= 0; wid
< devs
; ++wid
) {
191 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDGUID
,(DWORD
)&temp
,0));
193 if (IsEqualGUID( &guid
, &temp
) ) {
194 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDDESC
,(DWORD
)&desc
,0));
196 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
197 debugstr_guid(&DSDEVID_DefaultCapture
),"Primary Sound Capture Driver",desc
.szDrvName
,lpContext
);
198 if (lpDSEnumCallback((LPGUID
)&DSDEVID_DefaultCapture
, "Primary Sound Capture Driver", desc
.szDrvName
, lpContext
) == FALSE
)
207 for (wid
= 0; wid
< devs
; ++wid
) {
208 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDDESC
,(DWORD
)&desc
,0));
210 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDGUID
,(DWORD
)&guid
,0));
212 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
213 debugstr_guid(&guid
),desc
.szDesc
,desc
.szDrvName
,lpContext
);
214 if (lpDSEnumCallback(&guid
, desc
.szDesc
, desc
.szDrvName
, lpContext
) == FALSE
)
223 /***************************************************************************
224 * DirectSoundCaptureEnumerateW [DSOUND.8]
226 * Enumerate all DirectSound drivers installed in the system.
229 * lpDSEnumCallback [I] Address of callback function.
230 * lpContext [I] Address of user defined context passed to callback function.
234 * Failure: DSERR_INVALIDPARAM
237 DirectSoundCaptureEnumerateW(
238 LPDSENUMCALLBACKW lpDSEnumCallback
,
245 WCHAR wDesc
[MAXPNAMELEN
];
246 WCHAR wName
[MAXPNAMELEN
];
248 TRACE("(%p,%p)\n", lpDSEnumCallback
, lpContext
);
250 if (lpDSEnumCallback
== NULL
) {
251 WARN("invalid parameter: lpDSEnumCallback == NULL\n");
252 return DSERR_INVALIDPARAM
;
255 devs
= waveInGetNumDevs();
257 if (GetDeviceID(&DSDEVID_DefaultCapture
, &guid
) == DS_OK
) {
259 for (wid
= 0; wid
< devs
; ++wid
) {
260 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDGUID
,(DWORD
)&temp
,0));
262 if (IsEqualGUID( &guid
, &temp
) ) {
263 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDDESC
,(DWORD
)&desc
,0));
265 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
266 debugstr_guid(&DSDEVID_DefaultCapture
),"Primary Sound Capture Driver",desc
.szDrvName
,lpContext
);
267 MultiByteToWideChar( CP_ACP
, 0, "Primary Sound Capture Driver", -1,
268 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
) );
269 MultiByteToWideChar( CP_ACP
, 0, desc
.szDrvName
, -1,
270 wName
, sizeof(wName
)/sizeof(WCHAR
) );
271 if (lpDSEnumCallback((LPGUID
)&DSDEVID_DefaultCapture
, wDesc
, wName
, lpContext
) == FALSE
)
280 for (wid
= 0; wid
< devs
; ++wid
) {
281 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDDESC
,(DWORD
)&desc
,0));
283 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDGUID
,(DWORD
)&guid
,0));
285 TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n",
286 debugstr_guid(&DSDEVID_DefaultCapture
),desc
.szDesc
,desc
.szDrvName
,lpContext
);
287 MultiByteToWideChar( CP_ACP
, 0, desc
.szDesc
, -1,
288 wDesc
, sizeof(wDesc
)/sizeof(WCHAR
) );
289 MultiByteToWideChar( CP_ACP
, 0, desc
.szDrvName
, -1,
290 wName
, sizeof(wName
)/sizeof(WCHAR
) );
291 if (lpDSEnumCallback((LPGUID
)&DSDEVID_DefaultCapture
, wDesc
, wName
, lpContext
) == FALSE
)
301 DSOUND_capture_callback(
308 IDirectSoundCaptureImpl
* This
= (IDirectSoundCaptureImpl
*)dwUser
;
309 TRACE("(%p,%08x(%s),%08lx,%08lx,%08lx) entering at %ld\n",hwi
,msg
,
310 msg
== MM_WIM_OPEN
? "MM_WIM_OPEN" : msg
== MM_WIM_CLOSE
? "MM_WIM_CLOSE" :
311 msg
== MM_WIM_DATA
? "MM_WIM_DATA" : "UNKNOWN",dwUser
,dw1
,dw2
,GetTickCount());
313 if (msg
== MM_WIM_DATA
) {
314 EnterCriticalSection( &(This
->lock
) );
315 TRACE("DirectSoundCapture msg=MM_WIM_DATA, old This->state=%ld, old This->index=%d\n",This
->state
,This
->index
);
316 if (This
->state
!= STATE_STOPPED
) {
317 if (This
->state
== STATE_STARTING
) {
319 mtime
.wType
= TIME_BYTES
;
320 waveInGetPosition(This
->hwi
, &mtime
, sizeof(mtime
));
321 TRACE("mtime.u.cb=%ld,This->buflen=%ld\n", mtime
.u
.cb
, This
->buflen
);
322 mtime
.u
.cb
= mtime
.u
.cb
% This
->buflen
;
323 This
->read_position
= mtime
.u
.cb
;
324 This
->state
= STATE_CAPTURING
;
326 This
->index
= (This
->index
+ 1) % This
->nrofpwaves
;
327 waveInUnprepareHeader(hwi
,&(This
->pwave
[This
->index
]),sizeof(WAVEHDR
));
328 if (This
->capture_buffer
->notify
&& This
->capture_buffer
->notify
->nrofnotifies
)
329 SetEvent(This
->capture_buffer
->notify
->notifies
[This
->index
].hEventNotify
);
330 if ( (This
->index
== 0) && !(This
->capture_buffer
->flags
& DSCBSTART_LOOPING
) ) {
331 TRACE("end of buffer\n");
332 This
->state
= STATE_STOPPED
;
334 if (This
->state
== STATE_CAPTURING
) {
335 waveInPrepareHeader(hwi
,&(This
->pwave
[This
->index
]),sizeof(WAVEHDR
));
336 waveInAddBuffer(hwi
, &(This
->pwave
[This
->index
]), sizeof(WAVEHDR
));
340 TRACE("DirectSoundCapture new This->state=%ld, new This->index=%d\n",This
->state
,This
->index
);
341 LeaveCriticalSection( &(This
->lock
) );
344 TRACE("completed\n");
347 static HRESULT WINAPI
348 IDirectSoundCaptureImpl_QueryInterface(
349 LPDIRECTSOUNDCAPTURE iface
,
353 ICOM_THIS(IDirectSoundCaptureImpl
,iface
);
354 TRACE( "(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
357 WARN("invalid parameter\n");
365 hres
= IDsCaptureDriver_QueryInterface(This
->driver
, riid
, ppobj
);
367 WARN("IDsCaptureDriver_QueryInterface failed\n");
371 WARN("unsupported riid: %s\n", debugstr_guid(riid
));
376 IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface
)
379 ICOM_THIS(IDirectSoundCaptureImpl
,iface
);
381 EnterCriticalSection( &(This
->lock
) );
383 TRACE( "(%p) was 0x%08lx\n", This
, This
->ref
);
384 uRef
= ++(This
->ref
);
387 IDsCaptureDriver_AddRef(This
->driver
);
389 LeaveCriticalSection( &(This
->lock
) );
395 IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface
)
398 ICOM_THIS(IDirectSoundCaptureImpl
,iface
);
400 EnterCriticalSection( &(This
->lock
) );
402 TRACE( "(%p) was 0x%08lx\n", This
, This
->ref
);
403 uRef
= --(This
->ref
);
405 LeaveCriticalSection( &(This
->lock
) );
408 TRACE("deleting object\n");
409 if (This
->capture_buffer
)
410 IDirectSoundCaptureBufferImpl_Release(
411 (LPDIRECTSOUNDCAPTUREBUFFER8
) This
->capture_buffer
);
414 IDsCaptureDriver_Close(This
->driver
);
415 IDsCaptureDriver_Release(This
->driver
);
418 DeleteCriticalSection( &(This
->lock
) );
419 HeapFree( GetProcessHeap(), 0, This
);
420 dsound_capture
= NULL
;
423 TRACE( "returning 0x%08lx\n", uRef
);
427 static HRESULT WINAPI
428 IDirectSoundCaptureImpl_CreateCaptureBuffer(
429 LPDIRECTSOUNDCAPTURE iface
,
430 LPCDSCBUFFERDESC lpcDSCBufferDesc
,
431 LPDIRECTSOUNDCAPTUREBUFFER
* lplpDSCaptureBuffer
,
435 ICOM_THIS(IDirectSoundCaptureImpl
,iface
);
437 TRACE( "(%p,%p,%p,%p)\n",This
,lpcDSCBufferDesc
,lplpDSCaptureBuffer
,pUnk
);
440 WARN("invalid parameter: This == NULL\n");
441 return DSERR_INVALIDPARAM
;
444 if (lpcDSCBufferDesc
== NULL
) {
445 WARN("invalid parameter: lpcDSCBufferDesc == NULL)\n");
446 return DSERR_INVALIDPARAM
;
449 if (lplpDSCaptureBuffer
== NULL
) {
450 WARN("invalid parameter: lplpDSCaptureBuffer == NULL\n");
451 return DSERR_INVALIDPARAM
;
455 WARN("invalid parameter: pUnk != NULL\n");
456 return DSERR_INVALIDPARAM
;
459 /* FIXME: We can only have one buffer so what do we do here? */
460 if (This
->capture_buffer
) {
461 WARN("lnvalid parameter: already has buffer\n");
462 return DSERR_INVALIDPARAM
; /* DSERR_GENERIC ? */
465 hr
= DSOUND_CreateDirectSoundCaptureBuffer( This
, lpcDSCBufferDesc
,
466 (LPVOID
*)lplpDSCaptureBuffer
);
469 WARN("DSOUND_CreateDirectSoundCaptureBuffer failed\n");
474 static HRESULT WINAPI
475 IDirectSoundCaptureImpl_GetCaps(
476 LPDIRECTSOUNDCAPTURE iface
,
477 LPDSCCAPS lpDSCCaps
)
479 ICOM_THIS(IDirectSoundCaptureImpl
,iface
);
480 TRACE("(%p,%p)\n",This
,lpDSCCaps
);
482 if (lpDSCCaps
== NULL
) {
483 WARN("invalid parameter: lpDSCCaps== NULL\n");
484 return DSERR_INVALIDPARAM
;
487 if (lpDSCCaps
->dwSize
< sizeof(*lpDSCCaps
)) {
488 WARN("invalid parameter: lpDSCCaps->dwSize = %ld < %d\n",
489 lpDSCCaps
->dwSize
, sizeof(*lpDSCCaps
));
490 return DSERR_INVALIDPARAM
;
493 if ( !(This
->initialized
) ) {
494 WARN("not initialized\n");
495 return DSERR_UNINITIALIZED
;
498 lpDSCCaps
->dwFlags
= This
->drvcaps
.dwFlags
;
499 lpDSCCaps
->dwFormats
= This
->drvcaps
.dwFormats
;
500 lpDSCCaps
->dwChannels
= This
->drvcaps
.dwChannels
;
502 TRACE("(flags=0x%08lx,format=0x%08lx,channels=%ld)\n",lpDSCCaps
->dwFlags
,
503 lpDSCCaps
->dwFormats
, lpDSCCaps
->dwChannels
);
508 static HRESULT WINAPI
509 IDirectSoundCaptureImpl_Initialize(
510 LPDIRECTSOUNDCAPTURE iface
,
513 HRESULT err
= DSERR_INVALIDPARAM
;
515 ICOM_THIS(IDirectSoundCaptureImpl
,iface
);
516 TRACE("(%p)\n", This
);
519 WARN("invalid parameter: This == NULL\n");
520 return DSERR_INVALIDPARAM
;
523 if (This
->initialized
) {
524 WARN("already initialized\n");
525 return DSERR_ALREADYINITIALIZED
;
528 widn
= waveInGetNumDevs();
531 WARN("no audio devices found\n");
532 return DSERR_NODRIVER
;
535 /* Get dsound configuration */
536 setup_dsound_options();
538 /* enumerate WINMM audio devices and find the one we want */
539 for (wid
=0; wid
<widn
; wid
++) {
541 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDGUID
,(DWORD
)(&guid
),0));
543 WARN("waveInMessage failed; err=%lx\n",err
);
546 if (IsEqualGUID( lpcGUID
, &guid
) ) {
553 WARN("invalid parameter\n");
554 return DSERR_INVALIDPARAM
;
557 err
= mmErr(waveInMessage((HWAVEIN
)wid
,DRV_QUERYDSOUNDIFACE
,(DWORD
)&(This
->driver
),0));
558 if ( (err
!= DS_OK
) && (err
!= DSERR_UNSUPPORTED
) ) {
559 WARN("waveInMessage failed; err=%lx\n",err
);
564 /* Disable the direct sound driver to force emulation if requested. */
565 if (ds_hw_accel
== DS_HW_ACCEL_EMULATION
)
568 /* Get driver description */
570 TRACE("using DirectSound driver\n");
571 err
= IDsCaptureDriver_GetDriverDesc(This
->driver
, &(This
->drvdesc
));
573 WARN("IDsCaptureDriver_GetDriverDesc failed\n");
577 TRACE("using WINMM\n");
578 /* if no DirectSound interface available, use WINMM API instead */
579 This
->drvdesc
.dwFlags
= DSDDESC_DOMMSYSTEMOPEN
|
580 DSDDESC_DOMMSYSTEMSETFORMAT
;
583 This
->drvdesc
.dnDevNode
= wid
;
585 /* open the DirectSound driver if available */
586 if (This
->driver
&& (err
== DS_OK
))
587 err
= IDsCaptureDriver_Open(This
->driver
);
590 This
->initialized
= TRUE
;
592 /* the driver is now open, so it's now allowed to call GetCaps */
594 This
->drvcaps
.dwSize
= sizeof(This
->drvcaps
);
595 err
= IDsCaptureDriver_GetCaps(This
->driver
,&(This
->drvcaps
));
597 WARN("IDsCaptureDriver_GetCaps failed\n");
600 } else /*if (This->hwi)*/ {
602 err
= mmErr(waveInGetDevCapsA((UINT
)This
->drvdesc
.dnDevNode
, &wic
, sizeof(wic
)));
605 This
->drvcaps
.dwFlags
= 0;
606 strncpy(This
->drvdesc
.szDrvName
, wic
.szPname
,
607 sizeof(This
->drvdesc
.szDrvName
));
609 This
->drvcaps
.dwFlags
|= DSCCAPS_EMULDRIVER
;
610 This
->drvcaps
.dwFormats
= wic
.dwFormats
;
611 This
->drvcaps
.dwChannels
= wic
.wChannels
;
619 static ICOM_VTABLE(IDirectSoundCapture
) dscvt
=
621 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
622 /* IUnknown methods */
623 IDirectSoundCaptureImpl_QueryInterface
,
624 IDirectSoundCaptureImpl_AddRef
,
625 IDirectSoundCaptureImpl_Release
,
627 /* IDirectSoundCapture methods */
628 IDirectSoundCaptureImpl_CreateCaptureBuffer
,
629 IDirectSoundCaptureImpl_GetCaps
,
630 IDirectSoundCaptureImpl_Initialize
634 DSOUND_CreateDirectSoundCaptureBuffer(
635 IDirectSoundCaptureImpl
*ipDSC
,
636 LPCDSCBUFFERDESC lpcDSCBufferDesc
,
640 TRACE( "(%p,%p)\n", lpcDSCBufferDesc
, ppobj
);
643 WARN("invalid parameter: ipDSC == NULL\n");
644 return DSERR_INVALIDPARAM
;
647 if (lpcDSCBufferDesc
== NULL
) {
648 WARN("invalid parameter: lpcDSCBufferDesc == NULL\n");
649 return DSERR_INVALIDPARAM
;
653 WARN("invalid parameter: ppobj == NULL\n");
654 return DSERR_INVALIDPARAM
;
657 if ( (lpcDSCBufferDesc
->dwSize
< sizeof(DSCBUFFERDESC
)) ||
658 (lpcDSCBufferDesc
->dwBufferBytes
== 0) ||
659 (lpcDSCBufferDesc
->lpwfxFormat
== NULL
) ) {
660 WARN("invalid lpcDSCBufferDesc\n");
662 return DSERR_INVALIDPARAM
;
665 if ( !ipDSC
->initialized
) {
666 WARN("not initialized\n");
668 return DSERR_UNINITIALIZED
;
671 wfex
= lpcDSCBufferDesc
->lpwfxFormat
;
674 TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
675 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
676 wfex
->wFormatTag
, wfex
->nChannels
, wfex
->nSamplesPerSec
,
677 wfex
->nAvgBytesPerSec
, wfex
->nBlockAlign
,
678 wfex
->wBitsPerSample
, wfex
->cbSize
);
680 if (wfex
->wFormatTag
== WAVE_FORMAT_PCM
)
681 memcpy(&(ipDSC
->wfx
), wfex
, sizeof(WAVEFORMATEX
));
683 WARN("non PCM formats not supported\n");
685 return DSERR_BADFORMAT
;
688 WARN("lpcDSCBufferDesc->lpwfxFormat == 0\n");
690 return DSERR_INVALIDPARAM
; /* FIXME: DSERR_BADFORMAT ? */
693 *ppobj
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,
694 sizeof(IDirectSoundCaptureBufferImpl
));
696 if ( *ppobj
== NULL
) {
697 WARN("out of memory\n");
699 return DSERR_OUTOFMEMORY
;
702 ICOM_THIS(IDirectSoundCaptureBufferImpl
,*ppobj
);
705 This
->dsound
= ipDSC
;
706 This
->dsound
->capture_buffer
= This
;
708 This
->pdscbd
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,
709 lpcDSCBufferDesc
->dwSize
);
711 memcpy(This
->pdscbd
, lpcDSCBufferDesc
, lpcDSCBufferDesc
->dwSize
);
714 This
->dsound
->capture_buffer
= 0;
715 HeapFree( GetProcessHeap(), 0, This
);
717 return DSERR_OUTOFMEMORY
;
720 This
->lpVtbl
= &dscbvt
;
723 err
= IDsCaptureDriver_CreateCaptureBuffer(ipDSC
->driver
,
724 &(ipDSC
->wfx
),0,0,&(ipDSC
->buflen
),&(ipDSC
->buffer
),(LPVOID
*)&(ipDSC
->hwbuf
));
726 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
727 This
->dsound
->capture_buffer
= 0;
728 HeapFree( GetProcessHeap(), 0, This
);
735 DWORD flags
= CALLBACK_FUNCTION
;
736 if (ds_hw_accel
!= DS_HW_ACCEL_EMULATION
)
737 flags
|= WAVE_DIRECTSOUND
;
738 err
= mmErr(waveInOpen(&(ipDSC
->hwi
),
739 ipDSC
->drvdesc
.dnDevNode
, &(ipDSC
->wfx
),
740 (DWORD
)DSOUND_capture_callback
, (DWORD
)ipDSC
, flags
));
742 WARN("waveInOpen failed\n");
743 This
->dsound
->capture_buffer
= 0;
744 HeapFree( GetProcessHeap(), 0, This
);
749 buflen
= lpcDSCBufferDesc
->dwBufferBytes
;
750 TRACE("desired buflen=%ld, old buffer=%p\n", buflen
, ipDSC
->buffer
);
751 newbuf
= (LPBYTE
)HeapReAlloc(GetProcessHeap(),0,ipDSC
->buffer
,buflen
);
753 if (newbuf
== NULL
) {
754 WARN("failed to allocate capture buffer\n");
755 err
= DSERR_OUTOFMEMORY
;
756 /* but the old buffer might still exist and must be re-prepared */
758 ipDSC
->buffer
= newbuf
;
759 ipDSC
->buflen
= buflen
;
764 TRACE("returning DS_OK\n");
768 static HRESULT WINAPI
769 IDirectSoundCaptureBufferImpl_QueryInterface(
770 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
774 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
775 TRACE( "(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
778 WARN("invalid parameter\n");
784 if ( IsEqualGUID( &IID_IDirectSoundNotify
, riid
) ||
785 IsEqualGUID( &IID_IDirectSoundNotify8
, riid
) ) {
787 This
->notify
= (IDirectSoundNotifyImpl
*)HeapAlloc(GetProcessHeap(),
788 HEAP_ZERO_MEMORY
, sizeof(*This
->notify
));
790 This
->notify
->ref
= 0; /* release when ref = -1 */
791 This
->notify
->lpVtbl
= &dsnvt
;
795 if (This
->dsound
->hwbuf
) {
798 err
= IDsCaptureDriverBuffer_QueryInterface(This
->dsound
->hwbuf
,
799 &IID_IDsDriverNotify
, (LPVOID
*)&(This
->notify
->hwnotify
));
801 WARN("IDsCaptureDriverBuffer_QueryInterface failed\n");
807 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY
)This
->notify
);
808 *ppobj
= (LPVOID
)This
->notify
;
813 WARN("IID_IDirectSoundNotify\n");
817 if ( IsEqualGUID( &IID_IDirectSoundCaptureBuffer
, riid
) ||
818 IsEqualGUID( &IID_IDirectSoundCaptureBuffer8
, riid
) ) {
819 IDirectSoundCaptureBuffer8_AddRef(iface
);
824 FIXME("(%p,%s,%p) unsupported GUID\n", This
, debugstr_guid(riid
), ppobj
);
828 return E_NOINTERFACE
;
832 IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface
)
835 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
836 TRACE( "(%p)\n", This
);
838 assert(This
->dsound
);
840 EnterCriticalSection( &(This
->dsound
->lock
) );
842 TRACE( "(%p) was 0x%08lx\n", This
, This
->ref
);
843 uRef
= ++(This
->ref
);
845 LeaveCriticalSection( &(This
->dsound
->lock
) );
851 IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface
)
854 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
855 TRACE( "(%p)\n", This
);
857 assert(This
->dsound
);
859 EnterCriticalSection( &(This
->dsound
->lock
) );
861 TRACE( "(%p) was 0x%08lx\n", This
, This
->ref
);
862 uRef
= --(This
->ref
);
864 LeaveCriticalSection( &(This
->dsound
->lock
) );
867 TRACE("deleting object\n");
869 HeapFree(GetProcessHeap(),0, This
->pdscbd
);
871 if (This
->dsound
->hwi
) {
872 waveInReset(This
->dsound
->hwi
);
873 waveInClose(This
->dsound
->hwi
);
874 if (This
->dsound
->pwave
) {
875 HeapFree(GetProcessHeap(),0, This
->dsound
->pwave
);
876 This
->dsound
->pwave
= 0;
878 This
->dsound
->hwi
= 0;
881 if (This
->dsound
->hwbuf
)
882 IDsCaptureDriverBuffer_Release(This
->dsound
->hwbuf
);
884 /* remove from IDirectSoundCaptureImpl */
886 This
->dsound
->capture_buffer
= NULL
;
888 ERR("does not reference dsound\n");
891 IDirectSoundNotify_Release((LPDIRECTSOUNDNOTIFY
)This
->notify
);
893 HeapFree( GetProcessHeap(), 0, This
);
896 TRACE( "returning 0x%08lx\n", uRef
);
900 static HRESULT WINAPI
901 IDirectSoundCaptureBufferImpl_GetCaps(
902 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
903 LPDSCBCAPS lpDSCBCaps
)
905 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
906 TRACE( "(%p,%p)\n", This
, lpDSCBCaps
);
909 WARN("invalid parameter: This == NULL\n");
910 return DSERR_INVALIDPARAM
;
913 if (lpDSCBCaps
== NULL
) {
914 WARN("invalid parameter: lpDSCBCaps == NULL\n");
915 return DSERR_INVALIDPARAM
;
918 if (lpDSCBCaps
->dwSize
< sizeof(DSCBCAPS
)) {
919 WARN("invalid parameter: lpDSCBCaps->dwSize = %ld < %d\n",
920 lpDSCBCaps
->dwSize
, sizeof(DSCBCAPS
));
921 return DSERR_INVALIDPARAM
;
924 if (This
->dsound
== NULL
) {
925 WARN("invalid parameter: This->dsound == NULL\n");
926 return DSERR_INVALIDPARAM
;
929 lpDSCBCaps
->dwSize
= sizeof(DSCBCAPS
);
930 lpDSCBCaps
->dwFlags
= This
->flags
;
931 lpDSCBCaps
->dwBufferBytes
= This
->pdscbd
->dwBufferBytes
;
932 lpDSCBCaps
->dwReserved
= 0;
934 TRACE("returning DS_OK\n");
938 static HRESULT WINAPI
939 IDirectSoundCaptureBufferImpl_GetCurrentPosition(
940 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
941 LPDWORD lpdwCapturePosition
,
942 LPDWORD lpdwReadPosition
)
944 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
945 TRACE( "(%p,%p,%p)\n", This
, lpdwCapturePosition
, lpdwReadPosition
);
948 WARN("invalid parameter: This == NULL\n");
949 return DSERR_INVALIDPARAM
;
952 if (This
->dsound
== NULL
) {
953 WARN("invalid parameter: This->dsound == NULL\n");
954 return DSERR_INVALIDPARAM
;
957 if (This
->dsound
->driver
) {
959 hres
= IDsCaptureDriverBuffer_GetPosition(This
->dsound
->hwbuf
, lpdwCapturePosition
, lpdwReadPosition
);
961 WARN("IDsCaptureDriverBuffer_GetPosition failed\n");
964 } else if (This
->dsound
->hwi
) {
965 EnterCriticalSection(&(This
->dsound
->lock
));
966 TRACE("old This->dsound->state=%ld\n",This
->dsound
->state
);
967 if (lpdwCapturePosition
) {
969 mtime
.wType
= TIME_BYTES
;
970 waveInGetPosition(This
->dsound
->hwi
, &mtime
, sizeof(mtime
));
971 TRACE("mtime.u.cb=%ld,This->dsound->buflen=%ld\n", mtime
.u
.cb
,
972 This
->dsound
->buflen
);
973 mtime
.u
.cb
= mtime
.u
.cb
% This
->dsound
->buflen
;
974 *lpdwCapturePosition
= mtime
.u
.cb
;
977 if (lpdwReadPosition
) {
978 if (This
->dsound
->state
== STATE_STARTING
) {
979 if (lpdwCapturePosition
)
980 This
->dsound
->read_position
= *lpdwCapturePosition
;
981 This
->dsound
->state
= STATE_CAPTURING
;
983 *lpdwReadPosition
= This
->dsound
->read_position
;
985 TRACE("new This->dsound->state=%ld\n",This
->dsound
->state
);
986 LeaveCriticalSection(&(This
->dsound
->lock
));
987 if (lpdwCapturePosition
) TRACE("*lpdwCapturePosition=%ld\n",*lpdwCapturePosition
);
988 if (lpdwReadPosition
) TRACE("*lpdwReadPosition=%ld\n",*lpdwReadPosition
);
991 return DSERR_NODRIVER
;
994 TRACE("returning DS_OK\n");
998 static HRESULT WINAPI
999 IDirectSoundCaptureBufferImpl_GetFormat(
1000 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
1001 LPWAVEFORMATEX lpwfxFormat
,
1002 DWORD dwSizeAllocated
,
1003 LPDWORD lpdwSizeWritten
)
1005 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1006 TRACE( "(%p,%p,0x%08lx,%p)\n", This
, lpwfxFormat
, dwSizeAllocated
,
1010 WARN("invalid parameter: This == NULL\n");
1011 return DSERR_INVALIDPARAM
;
1014 if (This
->dsound
== NULL
) {
1015 WARN("invalid parameter: This->dsound == NULL\n");
1016 return DSERR_INVALIDPARAM
;
1019 /* FIXME: use real size for extended formats someday */
1020 if (dwSizeAllocated
> sizeof(This
->dsound
->wfx
))
1021 dwSizeAllocated
= sizeof(This
->dsound
->wfx
);
1022 if (lpwfxFormat
) { /* NULL is valid (just want size) */
1023 memcpy(lpwfxFormat
,&(This
->dsound
->wfx
),dwSizeAllocated
);
1024 if (lpdwSizeWritten
)
1025 *lpdwSizeWritten
= dwSizeAllocated
;
1027 if (lpdwSizeWritten
)
1028 *lpdwSizeWritten
= sizeof(This
->dsound
->wfx
);
1030 TRACE("invalid parameter: lpdwSizeWritten = NULL\n");
1031 return DSERR_INVALIDPARAM
;
1035 TRACE("returning DS_OK\n");
1039 static HRESULT WINAPI
1040 IDirectSoundCaptureBufferImpl_GetStatus(
1041 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
1042 LPDWORD lpdwStatus
)
1044 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1045 TRACE( "(%p, %p), thread is %04lx\n", This
, lpdwStatus
, GetCurrentThreadId() );
1048 WARN("invalid parameter: This == NULL\n");
1049 return DSERR_INVALIDPARAM
;
1052 if (This
->dsound
== NULL
) {
1053 WARN("invalid parameter: This->dsound == NULL\n");
1054 return DSERR_INVALIDPARAM
;
1057 if (lpdwStatus
== NULL
) {
1058 WARN("invalid parameter: lpdwStatus == NULL\n");
1059 return DSERR_INVALIDPARAM
;
1063 EnterCriticalSection(&(This
->dsound
->lock
));
1065 TRACE("old This->dsound->state=%ld, old lpdwStatus=%08lx\n",This
->dsound
->state
,*lpdwStatus
);
1066 if ((This
->dsound
->state
== STATE_STARTING
) ||
1067 (This
->dsound
->state
== STATE_CAPTURING
)) {
1068 *lpdwStatus
|= DSCBSTATUS_CAPTURING
;
1069 if (This
->flags
& DSCBSTART_LOOPING
)
1070 *lpdwStatus
|= DSCBSTATUS_LOOPING
;
1072 TRACE("new This->dsound->state=%ld, new lpdwStatus=%08lx\n",This
->dsound
->state
,*lpdwStatus
);
1073 LeaveCriticalSection(&(This
->dsound
->lock
));
1075 TRACE("status=%lx\n", *lpdwStatus
);
1076 TRACE("returning DS_OK\n");
1080 static HRESULT WINAPI
1081 IDirectSoundCaptureBufferImpl_Initialize(
1082 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
1083 LPDIRECTSOUNDCAPTURE lpDSC
,
1084 LPCDSCBUFFERDESC lpcDSCBDesc
)
1086 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1088 FIXME( "(%p,%p,%p): stub\n", This
, lpDSC
, lpcDSCBDesc
);
1093 static HRESULT WINAPI
1094 IDirectSoundCaptureBufferImpl_Lock(
1095 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
1098 LPVOID
* lplpvAudioPtr1
,
1099 LPDWORD lpdwAudioBytes1
,
1100 LPVOID
* lplpvAudioPtr2
,
1101 LPDWORD lpdwAudioBytes2
,
1104 HRESULT err
= DS_OK
;
1105 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1106 TRACE( "(%p,%08lu,%08lu,%p,%p,%p,%p,0x%08lx) at %ld\n", This
, dwReadCusor
,
1107 dwReadBytes
, lplpvAudioPtr1
, lpdwAudioBytes1
, lplpvAudioPtr2
,
1108 lpdwAudioBytes2
, dwFlags
, GetTickCount() );
1111 WARN("invalid parameter: This == NULL\n");
1112 return DSERR_INVALIDPARAM
;
1115 if (This
->dsound
== NULL
) {
1116 WARN("invalid parameter: This->dsound == NULL\n");
1117 return DSERR_INVALIDPARAM
;
1120 if (lplpvAudioPtr1
== NULL
) {
1121 WARN("invalid parameter: lplpvAudioPtr1 == NULL\n");
1122 return DSERR_INVALIDPARAM
;
1125 if (lpdwAudioBytes1
== NULL
) {
1126 WARN("invalid parameter: lpdwAudioBytes1 == NULL\n");
1127 return DSERR_INVALIDPARAM
;
1130 EnterCriticalSection(&(This
->dsound
->lock
));
1132 if (This
->dsound
->driver
) {
1133 err
= IDsCaptureDriverBuffer_Lock(This
->dsound
->hwbuf
, lplpvAudioPtr1
,
1134 lpdwAudioBytes1
, lplpvAudioPtr2
, lpdwAudioBytes2
,
1135 dwReadCusor
, dwReadBytes
, dwFlags
);
1137 WARN("IDsCaptureDriverBuffer_Lock failed\n");
1138 } else if (This
->dsound
->hwi
) {
1139 *lplpvAudioPtr1
= This
->dsound
->buffer
+ dwReadCusor
;
1140 if ( (dwReadCusor
+ dwReadBytes
) > This
->dsound
->buflen
) {
1141 *lpdwAudioBytes1
= This
->dsound
->buflen
- dwReadCusor
;
1143 *lplpvAudioPtr2
= This
->dsound
->buffer
;
1144 if (lpdwAudioBytes2
)
1145 *lpdwAudioBytes2
= dwReadBytes
- *lpdwAudioBytes1
;
1147 *lpdwAudioBytes1
= dwReadBytes
;
1149 *lplpvAudioPtr2
= 0;
1150 if (lpdwAudioBytes2
)
1151 *lpdwAudioBytes2
= 0;
1154 TRACE("invalid call\n");
1155 err
= DSERR_INVALIDCALL
; /* DSERR_NODRIVER ? */
1158 LeaveCriticalSection(&(This
->dsound
->lock
));
1163 static HRESULT WINAPI
1164 IDirectSoundCaptureBufferImpl_Start(
1165 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
1168 HRESULT err
= DS_OK
;
1169 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1170 TRACE( "(%p,0x%08lx)\n", This
, dwFlags
);
1173 WARN("invalid parameter: This == NULL\n");
1174 return DSERR_INVALIDPARAM
;
1177 if (This
->dsound
== NULL
) {
1178 WARN("invalid parameter: This->dsound == NULL\n");
1179 return DSERR_INVALIDPARAM
;
1182 if ( (This
->dsound
->driver
== 0) && (This
->dsound
->hwi
== 0) ) {
1183 WARN("no driver\n");
1184 return DSERR_NODRIVER
;
1187 EnterCriticalSection(&(This
->dsound
->lock
));
1189 This
->flags
= dwFlags
;
1190 TRACE("old This->dsound->state=%ld\n",This
->dsound
->state
);
1191 if (This
->dsound
->state
== STATE_STOPPED
)
1192 This
->dsound
->state
= STATE_STARTING
;
1193 else if (This
->dsound
->state
== STATE_STOPPING
)
1194 This
->dsound
->state
= STATE_CAPTURING
;
1195 TRACE("new This->dsound->state=%ld\n",This
->dsound
->state
);
1197 LeaveCriticalSection(&(This
->dsound
->lock
));
1199 if (This
->dsound
->driver
) {
1200 err
= IDsCaptureDriverBuffer_Start(This
->dsound
->hwbuf
, dwFlags
);
1202 WARN("IDsCaptureDriverBuffer_Start failed\n");
1205 IDirectSoundCaptureImpl
* ipDSC
= This
->dsound
;
1207 if (ipDSC
->buffer
) {
1208 if (This
->notify
&& This
->notify
->nrofnotifies
) {
1211 ipDSC
->nrofpwaves
= This
->notify
->nrofnotifies
;
1213 /* prepare headers */
1214 ipDSC
->pwave
= HeapReAlloc(GetProcessHeap(),0,ipDSC
->pwave
,
1215 ipDSC
->nrofpwaves
*sizeof(WAVEHDR
));
1217 for (c
= 0; c
< ipDSC
->nrofpwaves
; c
++) {
1219 ipDSC
->pwave
[0].lpData
= ipDSC
->buffer
;
1220 ipDSC
->pwave
[0].dwBufferLength
=
1221 This
->notify
->notifies
[0].dwOffset
+ 1;
1223 ipDSC
->pwave
[c
].lpData
= ipDSC
->buffer
+
1224 This
->notify
->notifies
[c
-1].dwOffset
+ 1;
1225 ipDSC
->pwave
[c
].dwBufferLength
=
1226 This
->notify
->notifies
[c
].dwOffset
-
1227 This
->notify
->notifies
[c
-1].dwOffset
;
1229 ipDSC
->pwave
[c
].dwUser
= (DWORD
)ipDSC
;
1230 ipDSC
->pwave
[c
].dwFlags
= 0;
1231 ipDSC
->pwave
[c
].dwLoops
= 0;
1232 err
= mmErr(waveInPrepareHeader(ipDSC
->hwi
,
1233 &(ipDSC
->pwave
[c
]),sizeof(WAVEHDR
)));
1236 waveInUnprepareHeader(ipDSC
->hwi
,
1237 &(ipDSC
->pwave
[c
]),sizeof(WAVEHDR
));
1242 memset(ipDSC
->buffer
,
1243 (ipDSC
->wfx
.wBitsPerSample
== 16) ? 0 : 128, ipDSC
->buflen
);
1245 TRACE("no notifiers specified\n");
1246 /* no notifiers specified so just create a single default header */
1247 ipDSC
->nrofpwaves
= 1;
1248 ipDSC
->pwave
= HeapReAlloc(GetProcessHeap(),0,ipDSC
->pwave
,sizeof(WAVEHDR
));
1249 ipDSC
->pwave
[0].lpData
= ipDSC
->buffer
;
1250 ipDSC
->pwave
[0].dwBufferLength
= ipDSC
->buflen
;
1251 ipDSC
->pwave
[0].dwUser
= (DWORD
)ipDSC
;
1252 ipDSC
->pwave
[0].dwFlags
= 0;
1253 ipDSC
->pwave
[0].dwLoops
= 0;
1255 err
= mmErr(waveInPrepareHeader(ipDSC
->hwi
,
1256 &(ipDSC
->pwave
[0]),sizeof(WAVEHDR
)));
1258 WARN("waveInPrepareHeader failed\n");
1259 waveInUnprepareHeader(ipDSC
->hwi
,
1260 &(ipDSC
->pwave
[0]),sizeof(WAVEHDR
));
1266 ipDSC
->read_position
= 0;
1269 err
= mmErr(waveInReset(ipDSC
->hwi
));
1271 /* add the first buffer to the queue */
1272 err
= mmErr(waveInAddBuffer(ipDSC
->hwi
, &(ipDSC
->pwave
[0]), sizeof(WAVEHDR
)));
1274 /* start filling the first buffer */
1275 err
= mmErr(waveInStart(ipDSC
->hwi
));
1277 WARN("waveInAddBuffer failed\n");
1279 WARN("waveInReset failed\n");
1284 WARN("calling waveInClose because of error\n");
1285 waveInClose(This
->dsound
->hwi
);
1286 This
->dsound
->hwi
= 0;
1289 TRACE("returning %ld\n", err
);
1293 static HRESULT WINAPI
1294 IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface
)
1296 HRESULT err
= DS_OK
;
1297 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1298 TRACE( "(%p)\n", This
);
1301 WARN("invalid parameter: This == NULL\n");
1302 return DSERR_INVALIDPARAM
;
1305 if (This
->dsound
== NULL
) {
1306 WARN("invalid parameter: This->dsound == NULL\n");
1307 return DSERR_INVALIDPARAM
;
1310 EnterCriticalSection(&(This
->dsound
->lock
));
1312 TRACE("old This->dsound->state=%ld\n",This
->dsound
->state
);
1313 if (This
->dsound
->state
== STATE_CAPTURING
)
1314 This
->dsound
->state
= STATE_STOPPING
;
1315 else if (This
->dsound
->state
== STATE_STARTING
)
1316 This
->dsound
->state
= STATE_STOPPED
;
1317 TRACE("new This->dsound->state=%ld\n",This
->dsound
->state
);
1319 LeaveCriticalSection(&(This
->dsound
->lock
));
1321 if (This
->dsound
->driver
) {
1322 err
= IDsCaptureDriverBuffer_Stop(This
->dsound
->hwbuf
);
1323 if (err
== DSERR_BUFFERLOST
) {
1324 /* Wine-only: the driver wants us to reopen the device */
1325 IDsCaptureDriverBuffer_Release(This
->dsound
->hwbuf
);
1326 err
= IDsCaptureDriver_CreateCaptureBuffer(This
->dsound
->driver
,
1327 &(This
->dsound
->wfx
),0,0,&(This
->dsound
->buflen
),&(This
->dsound
->buffer
),
1328 (LPVOID
*)&(This
->dsound
->hwbuf
));
1330 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
1331 This
->dsound
->hwbuf
= 0;
1333 } else if (err
!= DS_OK
)
1334 WARN("IDsCaptureDriverBuffer_Stop failed\n");
1335 } else if (This
->dsound
->hwi
) {
1336 err
= waveInStop(This
->dsound
->hwi
);
1338 WARN("no driver\n");
1339 err
= DSERR_NODRIVER
;
1342 TRACE( "(%p) returning 0x%08lx\n", This
,err
);
1346 static HRESULT WINAPI
1347 IDirectSoundCaptureBufferImpl_Unlock(
1348 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
1349 LPVOID lpvAudioPtr1
,
1350 DWORD dwAudioBytes1
,
1351 LPVOID lpvAudioPtr2
,
1352 DWORD dwAudioBytes2
)
1354 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1355 TRACE( "(%p,%p,%08lu,%p,%08lu)\n", This
, lpvAudioPtr1
, dwAudioBytes1
,
1356 lpvAudioPtr2
, dwAudioBytes2
);
1359 WARN("invalid parameter: This == NULL\n");
1360 return DSERR_INVALIDPARAM
;
1363 if (lpvAudioPtr1
== NULL
) {
1364 WARN("invalid parameter: lpvAudioPtr1 == NULL\n");
1365 return DSERR_INVALIDPARAM
;
1368 if (This
->dsound
->driver
) {
1370 hres
= IDsCaptureDriverBuffer_Unlock(This
->dsound
->hwbuf
, lpvAudioPtr1
,
1371 dwAudioBytes1
, lpvAudioPtr2
, dwAudioBytes2
);
1373 WARN("IDsCaptureDriverBuffer_Unlock failed\n");
1375 } else if (This
->dsound
->hwi
) {
1376 This
->dsound
->read_position
= (This
->dsound
->read_position
+
1377 (dwAudioBytes1
+ dwAudioBytes2
)) % This
->dsound
->buflen
;
1379 WARN("invalid call\n");
1380 return DSERR_INVALIDCALL
;
1386 static HRESULT WINAPI
1387 IDirectSoundCaptureBufferImpl_GetObjectInPath(
1388 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
1389 REFGUID rguidObject
,
1391 REFGUID rguidInterface
,
1394 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1396 FIXME( "(%p,%s,%lu,%s,%p): stub\n", This
, debugstr_guid(rguidObject
),
1397 dwIndex
, debugstr_guid(rguidInterface
), ppObject
);
1402 static HRESULT WINAPI
1403 IDirectSoundCaptureBufferImpl_GetFXStatus(
1404 LPDIRECTSOUNDCAPTUREBUFFER8 iface
,
1406 LPDWORD pdwFXStatus
)
1408 ICOM_THIS(IDirectSoundCaptureBufferImpl
,iface
);
1410 FIXME( "(%p,%lu,%p): stub\n", This
, dwFXCount
, pdwFXStatus
);
1415 static ICOM_VTABLE(IDirectSoundCaptureBuffer8
) dscbvt
=
1417 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1418 /* IUnknown methods */
1419 IDirectSoundCaptureBufferImpl_QueryInterface
,
1420 IDirectSoundCaptureBufferImpl_AddRef
,
1421 IDirectSoundCaptureBufferImpl_Release
,
1423 /* IDirectSoundCaptureBuffer methods */
1424 IDirectSoundCaptureBufferImpl_GetCaps
,
1425 IDirectSoundCaptureBufferImpl_GetCurrentPosition
,
1426 IDirectSoundCaptureBufferImpl_GetFormat
,
1427 IDirectSoundCaptureBufferImpl_GetStatus
,
1428 IDirectSoundCaptureBufferImpl_Initialize
,
1429 IDirectSoundCaptureBufferImpl_Lock
,
1430 IDirectSoundCaptureBufferImpl_Start
,
1431 IDirectSoundCaptureBufferImpl_Stop
,
1432 IDirectSoundCaptureBufferImpl_Unlock
,
1434 /* IDirectSoundCaptureBuffer methods */
1435 IDirectSoundCaptureBufferImpl_GetObjectInPath
,
1436 IDirectSoundCaptureBufferImpl_GetFXStatus
1439 /*******************************************************************************
1440 * DirectSoundCapture ClassFactory
1443 static HRESULT WINAPI
1444 DSCCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
)
1446 ICOM_THIS(IClassFactoryImpl
,iface
);
1448 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
1449 return E_NOINTERFACE
;
1453 DSCCF_AddRef(LPCLASSFACTORY iface
)
1455 ICOM_THIS(IClassFactoryImpl
,iface
);
1456 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
1457 return ++(This
->ref
);
1461 DSCCF_Release(LPCLASSFACTORY iface
)
1463 ICOM_THIS(IClassFactoryImpl
,iface
);
1464 /* static class, won't be freed */
1465 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
1466 return --(This
->ref
);
1469 static HRESULT WINAPI
1470 DSCCF_CreateInstance(
1471 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
)
1473 ICOM_THIS(IClassFactoryImpl
,iface
);
1474 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1476 if (ppobj
== NULL
) {
1477 WARN("invalid parameter\n");
1478 return E_INVALIDARG
;
1483 if ( IsEqualGUID( &IID_IDirectSoundCapture
, riid
) ||
1484 IsEqualGUID( &IID_IDirectSoundCapture8
, riid
) ) {
1485 return DirectSoundCaptureCreate8(0,(LPDIRECTSOUNDCAPTURE8
*)ppobj
,pOuter
);
1488 WARN("(%p,%p,%s,%p) Interface not found!\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1489 return E_NOINTERFACE
;
1492 static HRESULT WINAPI
1493 DSCCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
)
1495 ICOM_THIS(IClassFactoryImpl
,iface
);
1496 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
1500 static ICOM_VTABLE(IClassFactory
) DSCCF_Vtbl
=
1502 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1503 DSCCF_QueryInterface
,
1506 DSCCF_CreateInstance
,
1510 IClassFactoryImpl DSOUND_CAPTURE_CF
= { &DSCCF_Vtbl
, 1 };
1512 /***************************************************************************
1513 * DirectSoundFullDuplexCreate8 [DSOUND.10]
1515 * Create and initialize a DirectSoundFullDuplex interface.
1518 * pcGuidCaptureDevice [I] Address of sound capture device GUID.
1519 * pcGuidRenderDevice [I] Address of sound render device GUID.
1520 * pcDSCBufferDesc [I] Address of capture buffer description.
1521 * pcDSBufferDesc [I] Address of render buffer description.
1522 * hWnd [I] Handle to application window.
1523 * dwLevel [I] Cooperative level.
1524 * ppDSFD [O] Address where full duplex interface returned.
1525 * ppDSCBuffer8 [0] Address where capture buffer interface returned.
1526 * ppDSBuffer8 [0] Address where render buffer interface returned.
1527 * pUnkOuter [I] Must be NULL.
1531 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
1532 * DSERR_OUTOFMEMORY DSERR_INVALIDCALL DSERR_NODRIVER
1535 DirectSoundFullDuplexCreate8(
1536 LPCGUID pcGuidCaptureDevice
,
1537 LPCGUID pcGuidRenderDevice
,
1538 LPCDSCBUFFERDESC pcDSCBufferDesc
,
1539 LPCDSBUFFERDESC pcDSBufferDesc
,
1542 LPDIRECTSOUNDFULLDUPLEX
*ppDSFD
,
1543 LPDIRECTSOUNDCAPTUREBUFFER8
*ppDSCBuffer8
,
1544 LPDIRECTSOUNDBUFFER8
*ppDSBuffer8
,
1545 LPUNKNOWN pUnkOuter
)
1547 IDirectSoundFullDuplexImpl
** ippDSFD
=(IDirectSoundFullDuplexImpl
**)ppDSFD
;
1548 TRACE("(%s,%s,%p,%p,%lx,%lx,%p,%p,%p,%p)\n", debugstr_guid(pcGuidCaptureDevice
),
1549 debugstr_guid(pcGuidRenderDevice
), pcDSCBufferDesc
, pcDSBufferDesc
,
1550 (DWORD
)hWnd
, dwLevel
, ppDSFD
, ppDSCBuffer8
, ppDSBuffer8
, pUnkOuter
);
1553 WARN("pUnkOuter != 0\n");
1554 return DSERR_NOAGGREGATION
;
1557 *ippDSFD
= (IDirectSoundFullDuplexImpl
*)HeapAlloc(GetProcessHeap(),
1558 HEAP_ZERO_MEMORY
, sizeof(IDirectSoundFullDuplexImpl
));
1560 if (*ippDSFD
== NULL
) {
1561 WARN("out of memory\n");
1562 return DSERR_OUTOFMEMORY
;
1565 ICOM_THIS(IDirectSoundFullDuplexImpl
, *ippDSFD
);
1568 This
->lpVtbl
= &dsfdvt
;
1570 InitializeCriticalSection( &(This
->lock
) );
1572 hres
= IDirectSoundFullDuplexImpl_Initialize( (LPDIRECTSOUNDFULLDUPLEX
)This
,
1573 pcGuidCaptureDevice
, pcGuidRenderDevice
,
1574 pcDSCBufferDesc
, pcDSBufferDesc
,
1575 hWnd
, dwLevel
, ppDSCBuffer8
, ppDSBuffer8
);
1577 WARN("IDirectSoundFullDuplexImpl_Initialize failed\n");
1581 return DSERR_GENERIC
;
1584 static HRESULT WINAPI
1585 IDirectSoundFullDuplexImpl_QueryInterface(
1586 LPDIRECTSOUNDFULLDUPLEX iface
,
1590 ICOM_THIS(IDirectSoundFullDuplexImpl
,iface
);
1591 TRACE( "(%p,%s,%p)\n", This
, debugstr_guid(riid
), ppobj
);
1593 if (ppobj
== NULL
) {
1594 WARN("invalid parameter\n");
1595 return E_INVALIDARG
;
1599 return E_NOINTERFACE
;
1603 IDirectSoundFullDuplexImpl_AddRef( LPDIRECTSOUNDFULLDUPLEX iface
)
1606 ICOM_THIS(IDirectSoundFullDuplexImpl
,iface
);
1608 EnterCriticalSection( &(This
->lock
) );
1610 TRACE( "(%p) was 0x%08lx\n", This
, This
->ref
);
1611 uRef
= ++(This
->ref
);
1613 LeaveCriticalSection( &(This
->lock
) );
1619 IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface
)
1622 ICOM_THIS(IDirectSoundFullDuplexImpl
,iface
);
1624 EnterCriticalSection( &(This
->lock
) );
1626 TRACE( "(%p) was 0x%08lx\n", This
, This
->ref
);
1627 uRef
= --(This
->ref
);
1629 LeaveCriticalSection( &(This
->lock
) );
1632 TRACE("deleting object\n");
1633 DeleteCriticalSection( &(This
->lock
) );
1634 HeapFree( GetProcessHeap(), 0, This
);
1640 static HRESULT WINAPI
1641 IDirectSoundFullDuplexImpl_Initialize(
1642 LPDIRECTSOUNDFULLDUPLEX iface
,
1643 LPCGUID pCaptureGuid
,
1644 LPCGUID pRendererGuid
,
1645 LPCDSCBUFFERDESC lpDscBufferDesc
,
1646 LPCDSBUFFERDESC lpDsBufferDesc
,
1649 LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8
,
1650 LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8
)
1652 ICOM_THIS(IDirectSoundFullDuplexImpl
,iface
);
1653 IDirectSoundCaptureBufferImpl
** ippdscb
=(IDirectSoundCaptureBufferImpl
**)lplpDirectSoundCaptureBuffer8
;
1654 IDirectSoundBufferImpl
** ippdsc
=(IDirectSoundBufferImpl
**)lplpDirectSoundBuffer8
;
1656 FIXME( "(%p,%s,%s,%p,%p,%lx,%lx,%p,%p) stub!\n", This
, debugstr_guid(pCaptureGuid
),
1657 debugstr_guid(pRendererGuid
), lpDscBufferDesc
, lpDsBufferDesc
, (DWORD
)hWnd
, dwLevel
,
1663 static ICOM_VTABLE(IDirectSoundFullDuplex
) dsfdvt
=
1665 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1666 /* IUnknown methods */
1667 IDirectSoundFullDuplexImpl_QueryInterface
,
1668 IDirectSoundFullDuplexImpl_AddRef
,
1669 IDirectSoundFullDuplexImpl_Release
,
1671 /* IDirectSoundFullDuplex methods */
1672 IDirectSoundFullDuplexImpl_Initialize
1675 /*******************************************************************************
1676 * DirectSoundFullDuplex ClassFactory
1679 static HRESULT WINAPI
1680 DSFDCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
,LPVOID
*ppobj
)
1682 ICOM_THIS(IClassFactoryImpl
,iface
);
1684 FIXME("(%p)->(%s,%p),stub!\n",This
,debugstr_guid(riid
),ppobj
);
1685 return E_NOINTERFACE
;
1689 DSFDCF_AddRef(LPCLASSFACTORY iface
)
1691 ICOM_THIS(IClassFactoryImpl
,iface
);
1692 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
1693 return ++(This
->ref
);
1697 DSFDCF_Release(LPCLASSFACTORY iface
)
1699 ICOM_THIS(IClassFactoryImpl
,iface
);
1700 /* static class, won't be freed */
1701 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
1702 return --(This
->ref
);
1705 static HRESULT WINAPI
1706 DSFDCF_CreateInstance(
1707 LPCLASSFACTORY iface
,LPUNKNOWN pOuter
,REFIID riid
,LPVOID
*ppobj
)
1709 ICOM_THIS(IClassFactoryImpl
,iface
);
1711 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1713 if (ppobj
== NULL
) {
1714 WARN("invalid parameter\n");
1715 return E_INVALIDARG
;
1720 if ( IsEqualGUID( &IID_IDirectSoundFullDuplex
, riid
) ) {
1721 /* FIXME: how do we do this one ? */
1722 FIXME("not implemented\n");
1723 return E_NOINTERFACE
;
1726 WARN("(%p,%p,%s,%p) Interface not found!\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
1727 return E_NOINTERFACE
;
1730 static HRESULT WINAPI
1731 DSFDCF_LockServer(LPCLASSFACTORY iface
,BOOL dolock
)
1733 ICOM_THIS(IClassFactoryImpl
,iface
);
1734 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
1738 static ICOM_VTABLE(IClassFactory
) DSFDCF_Vtbl
=
1740 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1741 DSFDCF_QueryInterface
,
1744 DSFDCF_CreateInstance
,
1748 IClassFactoryImpl DSOUND_FULLDUPLEX_CF
= { &DSFDCF_Vtbl
, 1 };