Removed non-standard header includes.
[wine/multimedia.git] / dlls / dsound / capture.c
blob6b5707a2894b050a65d9a9742f60e3c0af910235
1 /* DirectSoundCapture
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
22 * TODO:
23 * Implement DirectSoundFullDuplex support.
24 * Implement FX support.
27 #include "config.h"
28 #include <assert.h>
29 #include <stdio.h>
30 #include <sys/types.h>
31 #include <sys/fcntl.h>
32 #ifdef HAVE_UNISTD_H
33 # include <unistd.h>
34 #endif
35 #include <stdlib.h>
36 #include <string.h>
38 #include "windef.h"
39 #include "winbase.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "winerror.h"
43 #include "mmsystem.h"
44 #include "mmddk.h"
45 #include "winternl.h"
46 #include "winnls.h"
47 #include "wine/debug.h"
48 #include "dsound.h"
49 #include "dsdriver.h"
50 #include "dsound_private.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
54 static HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(
55 LPDIRECTSOUNDCAPTURE iface,
56 LPCGUID lpcGUID );
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,
64 LPVOID* ppobj );
65 static HRESULT WINAPI IDirectSoundFullDuplexImpl_Initialize(
66 LPDIRECTSOUNDFULLDUPLEX iface,
67 LPCGUID pCaptureGuid,
68 LPCGUID pRendererGuid,
69 LPCDSCBUFFERDESC lpDscBufferDesc,
70 LPCDSBUFFERDESC lpDsBufferDesc,
71 HWND hWnd,
72 DWORD dwLevel,
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.
87 * PARAMS
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.
92 * RETURNS
93 * Success: DS_OK
94 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
95 * DSERR_OUTOFMEMORY
97 * NOTES
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.
104 HRESULT WINAPI
105 DirectSoundCaptureCreate8(
106 LPCGUID lpcGUID,
107 LPDIRECTSOUNDCAPTURE* lplpDSC,
108 LPUNKNOWN pUnkOuter )
110 IDirectSoundCaptureImpl** ippDSC=(IDirectSoundCaptureImpl**)lplpDSC;
111 TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), lplpDSC, pUnkOuter);
113 if ( pUnkOuter ) {
114 WARN("invalid parameter: pUnkOuter != NULL\n");
115 return DSERR_NOAGGREGATION;
118 if ( !lplpDSC ) {
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;
133 } else {
134 ICOM_THIS(IDirectSoundCaptureImpl, *ippDSC);
136 This->ref = 1;
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) {
145 HRESULT hres;
146 hres = IDirectSoundCaptureImpl_Initialize( (LPDIRECTSOUNDCAPTURE)This, &This->guid);
147 if (hres != DS_OK)
148 WARN("IDirectSoundCaptureImpl_Initialize failed\n");
149 return hres;
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.
161 * PARAMS
162 * lpDSEnumCallback [I] Address of callback function.
163 * lpContext [I] Address of user defined context passed to callback function.
165 * RETURNS
166 * Success: DS_OK
167 * Failure: DSERR_INVALIDPARAM
169 HRESULT WINAPI
170 DirectSoundCaptureEnumerateA(
171 LPDSENUMCALLBACKA lpDSEnumCallback,
172 LPVOID lpContext)
174 unsigned devs, wid;
175 DSDRIVERDESC desc;
176 GUID guid;
177 int err;
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();
187 if (devs > 0) {
188 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
189 GUID temp;
190 for (wid = 0; wid < devs; ++wid) {
191 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
192 if (err == DS_OK) {
193 if (IsEqualGUID( &guid, &temp ) ) {
194 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
195 if (err == DS_OK) {
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)
199 return DS_OK;
207 for (wid = 0; wid < devs; ++wid) {
208 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
209 if (err == DS_OK) {
210 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
211 if (err == DS_OK) {
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)
215 return DS_OK;
220 return DS_OK;
223 /***************************************************************************
224 * DirectSoundCaptureEnumerateW [DSOUND.8]
226 * Enumerate all DirectSound drivers installed in the system.
228 * PARAMS
229 * lpDSEnumCallback [I] Address of callback function.
230 * lpContext [I] Address of user defined context passed to callback function.
232 * RETURNS
233 * Success: DS_OK
234 * Failure: DSERR_INVALIDPARAM
236 HRESULT WINAPI
237 DirectSoundCaptureEnumerateW(
238 LPDSENUMCALLBACKW lpDSEnumCallback,
239 LPVOID lpContext)
241 unsigned devs, wid;
242 DSDRIVERDESC desc;
243 GUID guid;
244 int err;
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();
256 if (devs > 0) {
257 if (GetDeviceID(&DSDEVID_DefaultCapture, &guid) == DS_OK) {
258 GUID temp;
259 for (wid = 0; wid < devs; ++wid) {
260 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&temp,0));
261 if (err == DS_OK) {
262 if (IsEqualGUID( &guid, &temp ) ) {
263 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
264 if (err == DS_OK) {
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)
272 return DS_OK;
280 for (wid = 0; wid < devs; ++wid) {
281 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDDESC,(DWORD)&desc,0));
282 if (err == DS_OK) {
283 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)&guid,0));
284 if (err == DS_OK) {
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)
292 return DS_OK;
297 return DS_OK;
300 static void CALLBACK
301 DSOUND_capture_callback(
302 HWAVEIN hwi,
303 UINT msg,
304 DWORD dwUser,
305 DWORD dw1,
306 DWORD dw2 )
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) {
318 MMTIME mtime;
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->nrofnotifies)
329 SetEvent(This->capture_buffer->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;
333 } else {
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,
350 REFIID riid,
351 LPVOID* ppobj )
353 ICOM_THIS(IDirectSoundCaptureImpl,iface);
354 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
356 if (ppobj == NULL) {
357 WARN("invalid parameter\n");
358 return E_INVALIDARG;
361 *ppobj = NULL;
363 if (This->driver) {
364 HRESULT hres;
365 hres = IDsCaptureDriver_QueryInterface(This->driver, riid, ppobj);
366 if (hres != DS_OK)
367 WARN("IDsCaptureDriver_QueryInterface failed\n");
368 return hres;
371 WARN("unsupported riid: %s\n", debugstr_guid(riid));
372 return E_FAIL;
375 static ULONG WINAPI
376 IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface )
378 ULONG uRef;
379 ICOM_THIS(IDirectSoundCaptureImpl,iface);
380 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
382 EnterCriticalSection( &(This->lock) );
383 uRef = ++(This->ref);
385 if (This->driver)
386 IDsCaptureDriver_AddRef(This->driver);
388 LeaveCriticalSection( &(This->lock) );
390 return uRef;
393 static ULONG WINAPI
394 IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface )
396 ULONG uRef;
397 ICOM_THIS(IDirectSoundCaptureImpl,iface);
398 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
400 EnterCriticalSection( &(This->lock) );
402 uRef = --(This->ref);
404 LeaveCriticalSection( &(This->lock) );
406 if ( uRef == 0 ) {
407 TRACE("deleting object\n");
408 if (This->capture_buffer)
409 IDirectSoundCaptureBufferImpl_Release(
410 (LPDIRECTSOUNDCAPTUREBUFFER8) This->capture_buffer);
412 if (This->driver) {
413 IDsCaptureDriver_Close(This->driver);
414 IDsCaptureDriver_Release(This->driver);
417 DeleteCriticalSection( &(This->lock) );
418 HeapFree( GetProcessHeap(), 0, This );
419 dsound_capture = NULL;
420 TRACE("(%p) released\n",This);
423 return uRef;
426 static HRESULT WINAPI
427 IDirectSoundCaptureImpl_CreateCaptureBuffer(
428 LPDIRECTSOUNDCAPTURE iface,
429 LPCDSCBUFFERDESC lpcDSCBufferDesc,
430 LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
431 LPUNKNOWN pUnk )
433 HRESULT hr;
434 ICOM_THIS(IDirectSoundCaptureImpl,iface);
436 TRACE( "(%p,%p,%p,%p)\n",This,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk );
438 if (This == NULL) {
439 WARN("invalid parameter: This == NULL\n");
440 return DSERR_INVALIDPARAM;
443 if (lpcDSCBufferDesc == NULL) {
444 WARN("invalid parameter: lpcDSCBufferDesc == NULL)\n");
445 return DSERR_INVALIDPARAM;
448 if (lplpDSCaptureBuffer == NULL) {
449 WARN("invalid parameter: lplpDSCaptureBuffer == NULL\n");
450 return DSERR_INVALIDPARAM;
453 if (pUnk != NULL) {
454 WARN("invalid parameter: pUnk != NULL\n");
455 return DSERR_INVALIDPARAM;
458 /* FIXME: We can only have one buffer so what do we do here? */
459 if (This->capture_buffer) {
460 WARN("lnvalid parameter: already has buffer\n");
461 return DSERR_INVALIDPARAM; /* DSERR_GENERIC ? */
464 hr = DSOUND_CreateDirectSoundCaptureBuffer( This, lpcDSCBufferDesc,
465 (LPVOID*)lplpDSCaptureBuffer );
467 if (hr != DS_OK)
468 WARN("DSOUND_CreateDirectSoundCaptureBuffer failed\n");
470 return hr;
473 static HRESULT WINAPI
474 IDirectSoundCaptureImpl_GetCaps(
475 LPDIRECTSOUNDCAPTURE iface,
476 LPDSCCAPS lpDSCCaps )
478 ICOM_THIS(IDirectSoundCaptureImpl,iface);
479 TRACE("(%p,%p)\n",This,lpDSCCaps);
481 if (lpDSCCaps== NULL) {
482 WARN("invalid parameter: lpDSCCaps== NULL\n");
483 return DSERR_INVALIDPARAM;
486 if (lpDSCCaps->dwSize < sizeof(*lpDSCCaps)) {
487 WARN("invalid parameter: lpDSCCaps->dwSize = %ld < %d\n",
488 lpDSCCaps->dwSize, sizeof(*lpDSCCaps));
489 return DSERR_INVALIDPARAM;
492 if ( !(This->initialized) ) {
493 WARN("not initialized\n");
494 return DSERR_UNINITIALIZED;
497 lpDSCCaps->dwFlags = This->drvcaps.dwFlags;
498 lpDSCCaps->dwFormats = This->drvcaps.dwFormats;
499 lpDSCCaps->dwChannels = This->drvcaps.dwChannels;
501 TRACE("(flags=0x%08lx,format=0x%08lx,channels=%ld)\n",lpDSCCaps->dwFlags,
502 lpDSCCaps->dwFormats, lpDSCCaps->dwChannels);
504 return DS_OK;
507 static HRESULT WINAPI
508 IDirectSoundCaptureImpl_Initialize(
509 LPDIRECTSOUNDCAPTURE iface,
510 LPCGUID lpcGUID )
512 HRESULT err = DSERR_INVALIDPARAM;
513 unsigned wid, widn;
514 ICOM_THIS(IDirectSoundCaptureImpl,iface);
515 TRACE("(%p)\n", This);
517 if (!This) {
518 WARN("invalid parameter: This == NULL\n");
519 return DSERR_INVALIDPARAM;
522 if (This->initialized) {
523 WARN("already initialized\n");
524 return DSERR_ALREADYINITIALIZED;
527 widn = waveInGetNumDevs();
529 if (!widn) {
530 WARN("no audio devices found\n");
531 return DSERR_NODRIVER;
534 /* Get dsound configuration */
535 setup_dsound_options();
537 /* enumerate WINMM audio devices and find the one we want */
538 for (wid=0; wid<widn; wid++) {
539 GUID guid;
540 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDGUID,(DWORD)(&guid),0));
541 if (err != DS_OK) {
542 WARN("waveInMessage failed; err=%lx\n",err);
543 return err;
545 if (IsEqualGUID( lpcGUID, &guid) ) {
546 err = DS_OK;
547 break;
551 if (err != DS_OK) {
552 WARN("invalid parameter\n");
553 return DSERR_INVALIDPARAM;
556 err = mmErr(waveInMessage((HWAVEIN)wid,DRV_QUERYDSOUNDIFACE,(DWORD)&(This->driver),0));
557 if ( (err != DS_OK) && (err != DSERR_UNSUPPORTED) ) {
558 WARN("waveInMessage failed; err=%lx\n",err);
559 return err;
561 err = DS_OK;
563 /* Disable the direct sound driver to force emulation if requested. */
564 if (ds_hw_accel == DS_HW_ACCEL_EMULATION)
565 This->driver = NULL;
567 /* Get driver description */
568 if (This->driver) {
569 TRACE("using DirectSound driver\n");
570 err = IDsCaptureDriver_GetDriverDesc(This->driver, &(This->drvdesc));
571 if (err != DS_OK) {
572 WARN("IDsCaptureDriver_GetDriverDesc failed\n");
573 return err;
575 } else {
576 TRACE("using WINMM\n");
577 /* if no DirectSound interface available, use WINMM API instead */
578 This->drvdesc.dwFlags = DSDDESC_DOMMSYSTEMOPEN |
579 DSDDESC_DOMMSYSTEMSETFORMAT;
582 This->drvdesc.dnDevNode = wid;
584 /* open the DirectSound driver if available */
585 if (This->driver && (err == DS_OK))
586 err = IDsCaptureDriver_Open(This->driver);
588 if (err == DS_OK) {
589 This->initialized = TRUE;
591 /* the driver is now open, so it's now allowed to call GetCaps */
592 if (This->driver) {
593 This->drvcaps.dwSize = sizeof(This->drvcaps);
594 err = IDsCaptureDriver_GetCaps(This->driver,&(This->drvcaps));
595 if (err != DS_OK) {
596 WARN("IDsCaptureDriver_GetCaps failed\n");
597 return err;
599 } else /*if (This->hwi)*/ {
600 WAVEINCAPSA wic;
601 err = mmErr(waveInGetDevCapsA((UINT)This->drvdesc.dnDevNode, &wic, sizeof(wic)));
603 if (err == DS_OK) {
604 This->drvcaps.dwFlags = 0;
605 strncpy(This->drvdesc.szDrvName, wic.szPname,
606 sizeof(This->drvdesc.szDrvName));
608 This->drvcaps.dwFlags |= DSCCAPS_EMULDRIVER;
609 This->drvcaps.dwFormats = wic.dwFormats;
610 This->drvcaps.dwChannels = wic.wChannels;
615 return err;
618 static ICOM_VTABLE(IDirectSoundCapture) dscvt =
620 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
621 /* IUnknown methods */
622 IDirectSoundCaptureImpl_QueryInterface,
623 IDirectSoundCaptureImpl_AddRef,
624 IDirectSoundCaptureImpl_Release,
626 /* IDirectSoundCapture methods */
627 IDirectSoundCaptureImpl_CreateCaptureBuffer,
628 IDirectSoundCaptureImpl_GetCaps,
629 IDirectSoundCaptureImpl_Initialize
632 static HRESULT
633 DSOUND_CreateDirectSoundCaptureBuffer(
634 IDirectSoundCaptureImpl *ipDSC,
635 LPCDSCBUFFERDESC lpcDSCBufferDesc,
636 LPVOID* ppobj )
638 LPWAVEFORMATEX wfex;
639 TRACE( "(%p,%p)\n", lpcDSCBufferDesc, ppobj );
641 if (ipDSC == NULL) {
642 WARN("invalid parameter: ipDSC == NULL\n");
643 return DSERR_INVALIDPARAM;
646 if (lpcDSCBufferDesc == NULL) {
647 WARN("invalid parameter: lpcDSCBufferDesc == NULL\n");
648 return DSERR_INVALIDPARAM;
651 if (ppobj == NULL) {
652 WARN("invalid parameter: ppobj == NULL\n");
653 return DSERR_INVALIDPARAM;
656 if ( (lpcDSCBufferDesc->dwSize < sizeof(DSCBUFFERDESC)) ||
657 (lpcDSCBufferDesc->dwBufferBytes == 0) ||
658 (lpcDSCBufferDesc->lpwfxFormat == NULL) ) {
659 WARN("invalid lpcDSCBufferDesc\n");
660 *ppobj = NULL;
661 return DSERR_INVALIDPARAM;
664 if ( !ipDSC->initialized ) {
665 WARN("not initialized\n");
666 *ppobj = NULL;
667 return DSERR_UNINITIALIZED;
670 wfex = lpcDSCBufferDesc->lpwfxFormat;
672 if (wfex) {
673 TRACE("(formattag=0x%04x,chans=%d,samplerate=%ld,"
674 "bytespersec=%ld,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
675 wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
676 wfex->nAvgBytesPerSec, wfex->nBlockAlign,
677 wfex->wBitsPerSample, wfex->cbSize);
679 if (wfex->wFormatTag == WAVE_FORMAT_PCM)
680 memcpy(&(ipDSC->wfx), wfex, sizeof(WAVEFORMATEX));
681 else {
682 WARN("non PCM formats not supported\n");
683 *ppobj = NULL;
684 return DSERR_BADFORMAT;
686 } else {
687 WARN("lpcDSCBufferDesc->lpwfxFormat == 0\n");
688 *ppobj = NULL;
689 return DSERR_INVALIDPARAM; /* FIXME: DSERR_BADFORMAT ? */
692 *ppobj = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
693 sizeof(IDirectSoundCaptureBufferImpl));
695 if ( *ppobj == NULL ) {
696 WARN("out of memory\n");
697 *ppobj = NULL;
698 return DSERR_OUTOFMEMORY;
699 } else {
700 HRESULT err = DS_OK;
701 ICOM_THIS(IDirectSoundCaptureBufferImpl,*ppobj);
703 This->ref = 1;
704 This->dsound = ipDSC;
705 This->dsound->capture_buffer = This;
706 This->notify = NULL;
707 This->nrofnotifies = 0;
708 This->hwnotify = NULL;
710 This->pdscbd = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
711 lpcDSCBufferDesc->dwSize);
712 if (This->pdscbd)
713 memcpy(This->pdscbd, lpcDSCBufferDesc, lpcDSCBufferDesc->dwSize);
714 else {
715 WARN("no memory\n");
716 This->dsound->capture_buffer = 0;
717 HeapFree( GetProcessHeap(), 0, This );
718 *ppobj = NULL;
719 return DSERR_OUTOFMEMORY;
722 This->lpVtbl = &dscbvt;
724 if (ipDSC->driver) {
725 err = IDsCaptureDriver_CreateCaptureBuffer(ipDSC->driver,
726 &(ipDSC->wfx),0,0,&(ipDSC->buflen),&(ipDSC->buffer),(LPVOID*)&(ipDSC->hwbuf));
727 if (err != DS_OK) {
728 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
729 This->dsound->capture_buffer = 0;
730 HeapFree( GetProcessHeap(), 0, This );
731 *ppobj = NULL;
732 return err;
734 } else {
735 LPBYTE newbuf;
736 DWORD buflen;
737 DWORD flags = CALLBACK_FUNCTION;
738 if (ds_hw_accel != DS_HW_ACCEL_EMULATION)
739 flags |= WAVE_DIRECTSOUND;
740 err = mmErr(waveInOpen(&(ipDSC->hwi),
741 ipDSC->drvdesc.dnDevNode, &(ipDSC->wfx),
742 (DWORD)DSOUND_capture_callback, (DWORD)ipDSC, flags));
743 if (err != DS_OK) {
744 WARN("waveInOpen failed\n");
745 This->dsound->capture_buffer = 0;
746 HeapFree( GetProcessHeap(), 0, This );
747 *ppobj = NULL;
748 return err;
751 buflen = lpcDSCBufferDesc->dwBufferBytes;
752 TRACE("desired buflen=%ld, old buffer=%p\n", buflen, ipDSC->buffer);
753 newbuf = (LPBYTE)HeapReAlloc(GetProcessHeap(),0,ipDSC->buffer,buflen);
755 if (newbuf == NULL) {
756 WARN("failed to allocate capture buffer\n");
757 err = DSERR_OUTOFMEMORY;
758 /* but the old buffer might still exist and must be re-prepared */
759 } else {
760 ipDSC->buffer = newbuf;
761 ipDSC->buflen = buflen;
766 TRACE("returning DS_OK\n");
767 return DS_OK;
770 /*******************************************************************************
771 * IDirectSoundCaptureNotify
773 static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_QueryInterface(
774 LPDIRECTSOUNDNOTIFY iface,
775 REFIID riid,
776 LPVOID *ppobj)
778 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
779 TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
781 if (This->dscb == NULL) {
782 WARN("invalid parameter\n");
783 return E_INVALIDARG;
786 return IDirectSoundCaptureBuffer_QueryInterface((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb, riid, ppobj);
789 static ULONG WINAPI IDirectSoundCaptureNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
791 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
792 DWORD ref;
794 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
796 ref = InterlockedIncrement(&(This->ref));
797 return ref;
800 static ULONG WINAPI IDirectSoundCaptureNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
802 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
803 DWORD ref;
805 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
807 ref = InterlockedDecrement(&(This->ref));
808 if (ref == 0) {
809 This->dscb->notify=NULL;
810 IDirectSoundCaptureBuffer_Release((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb);
811 HeapFree(GetProcessHeap(),0,This);
812 TRACE("(%p) released\n",This);
814 return ref;
817 static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_SetNotificationPositions(
818 LPDIRECTSOUNDNOTIFY iface,
819 DWORD howmuch,
820 LPCDSBPOSITIONNOTIFY notify)
822 ICOM_THIS(IDirectSoundCaptureNotifyImpl,iface);
823 TRACE("(%p,0x%08lx,%p)\n",This,howmuch,notify);
825 if (notify == NULL) {
826 WARN("invalid parameter: notify == NULL\n");
827 return DSERR_INVALIDPARAM;
830 if (TRACE_ON(dsound)) {
831 int i;
832 for (i=0;i<howmuch;i++)
833 TRACE("notify at %ld to 0x%08lx\n",
834 notify[i].dwOffset,(DWORD)notify[i].hEventNotify);
837 if (This->dscb->hwnotify) {
838 HRESULT hres;
839 hres = IDsDriverNotify_SetNotificationPositions(This->dscb->hwnotify, howmuch, notify);
840 if (hres != DS_OK)
841 WARN("IDsDriverNotify_SetNotificationPositions failed\n");
842 return hres;
843 } else {
844 /* Make an internal copy of the caller-supplied array.
845 * Replace the existing copy if one is already present. */
846 This->dscb->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
847 This->dscb->notifies, howmuch * sizeof(DSBPOSITIONNOTIFY));
848 if (This->dscb->notifies == NULL) {
849 WARN("out of memory\n");
850 return DSERR_OUTOFMEMORY;
852 memcpy(This->dscb->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
853 This->dscb->nrofnotifies = howmuch;
856 return S_OK;
859 ICOM_VTABLE(IDirectSoundNotify) dscnvt =
861 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
862 IDirectSoundCaptureNotifyImpl_QueryInterface,
863 IDirectSoundCaptureNotifyImpl_AddRef,
864 IDirectSoundCaptureNotifyImpl_Release,
865 IDirectSoundCaptureNotifyImpl_SetNotificationPositions,
868 HRESULT WINAPI IDirectSoundCaptureNotifyImpl_Create(
869 IDirectSoundCaptureBufferImpl *dscb,
870 IDirectSoundCaptureNotifyImpl **pdscn)
872 IDirectSoundCaptureNotifyImpl * dscn;
873 TRACE("(%p,%p)\n",dscb,pdscn);
875 dscn = (IDirectSoundCaptureNotifyImpl*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dscn));
877 if (dscn == NULL) {
878 WARN("out of memory\n");
879 return DSERR_OUTOFMEMORY;
882 dscn->ref = 0;
883 dscn->lpVtbl = &dscnvt;
884 dscn->dscb = dscb;
885 dscb->notify = dscn;
886 IDirectSoundCaptureBuffer_AddRef((LPDIRECTSOUNDCAPTUREBUFFER)dscb);
888 *pdscn = dscn;
889 return DS_OK;
892 /*******************************************************************************
893 * IDirectSoundCaptureBuffer
895 static HRESULT WINAPI
896 IDirectSoundCaptureBufferImpl_QueryInterface(
897 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
898 REFIID riid,
899 LPVOID* ppobj )
901 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
902 HRESULT hres;
903 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
905 if (ppobj == NULL) {
906 WARN("invalid parameter\n");
907 return E_INVALIDARG;
910 *ppobj = NULL;
912 if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ||
913 IsEqualGUID( &IID_IDirectSoundNotify8, riid ) ) {
914 if (!This->notify)
915 hres = IDirectSoundCaptureNotifyImpl_Create(This, &This->notify);
916 if (This->notify) {
917 if (This->dsound->hwbuf) {
918 hres = IDsCaptureDriverBuffer_QueryInterface(This->dsound->hwbuf,
919 &IID_IDsDriverNotify, (LPVOID*)&(This->hwnotify));
920 if (hres != DS_OK) {
921 WARN("IDsCaptureDriverBuffer_QueryInterface failed\n");
922 *ppobj = 0;
923 return hres;
927 IDirectSoundNotify_AddRef((LPDIRECTSOUNDNOTIFY)This->notify);
928 *ppobj = (LPVOID)This->notify;
929 return DS_OK;
932 WARN("IID_IDirectSoundNotify\n");
933 return E_FAIL;
936 if ( IsEqualGUID( &IID_IDirectSoundCaptureBuffer, riid ) ||
937 IsEqualGUID( &IID_IDirectSoundCaptureBuffer8, riid ) ) {
938 IDirectSoundCaptureBuffer8_AddRef(iface);
939 *ppobj = This;
940 return NO_ERROR;
943 FIXME("(%p,%s,%p) unsupported GUID\n", This, debugstr_guid(riid), ppobj);
944 return E_NOINTERFACE;
947 static ULONG WINAPI
948 IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
950 ULONG uRef;
951 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
952 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
954 assert(This->dsound);
956 EnterCriticalSection( &(This->dsound->lock) );
958 uRef = ++(This->ref);
960 LeaveCriticalSection( &(This->dsound->lock) );
962 return uRef;
965 static ULONG WINAPI
966 IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
968 ULONG uRef;
969 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
970 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
972 assert(This->dsound);
974 EnterCriticalSection( &(This->dsound->lock) );
976 uRef = --(This->ref);
978 LeaveCriticalSection( &(This->dsound->lock) );
980 if ( uRef == 0 ) {
981 TRACE("deleting object\n");
982 if (This->pdscbd)
983 HeapFree(GetProcessHeap(),0, This->pdscbd);
985 if (This->dsound->hwi) {
986 waveInReset(This->dsound->hwi);
987 waveInClose(This->dsound->hwi);
988 if (This->dsound->pwave) {
989 HeapFree(GetProcessHeap(),0, This->dsound->pwave);
990 This->dsound->pwave = 0;
992 This->dsound->hwi = 0;
995 if (This->dsound->hwbuf)
996 IDsCaptureDriverBuffer_Release(This->dsound->hwbuf);
998 /* remove from IDirectSoundCaptureImpl */
999 if (This->dsound)
1000 This->dsound->capture_buffer = NULL;
1001 else
1002 ERR("does not reference dsound\n");
1004 if (This->notify)
1005 IDirectSoundNotify_Release((LPDIRECTSOUNDNOTIFY)This->notify);
1007 if (This->notifies != NULL)
1008 HeapFree(GetProcessHeap(), 0, This->notifies);
1010 HeapFree( GetProcessHeap(), 0, This );
1011 TRACE("(%p) released\n",This);
1014 return uRef;
1017 static HRESULT WINAPI
1018 IDirectSoundCaptureBufferImpl_GetCaps(
1019 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1020 LPDSCBCAPS lpDSCBCaps )
1022 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1023 TRACE( "(%p,%p)\n", This, lpDSCBCaps );
1025 if (This == NULL) {
1026 WARN("invalid parameter: This == NULL\n");
1027 return DSERR_INVALIDPARAM;
1030 if (lpDSCBCaps == NULL) {
1031 WARN("invalid parameter: lpDSCBCaps == NULL\n");
1032 return DSERR_INVALIDPARAM;
1035 if (lpDSCBCaps->dwSize < sizeof(DSCBCAPS)) {
1036 WARN("invalid parameter: lpDSCBCaps->dwSize = %ld < %d\n",
1037 lpDSCBCaps->dwSize, sizeof(DSCBCAPS));
1038 return DSERR_INVALIDPARAM;
1041 if (This->dsound == NULL) {
1042 WARN("invalid parameter: This->dsound == NULL\n");
1043 return DSERR_INVALIDPARAM;
1046 lpDSCBCaps->dwSize = sizeof(DSCBCAPS);
1047 lpDSCBCaps->dwFlags = This->flags;
1048 lpDSCBCaps->dwBufferBytes = This->pdscbd->dwBufferBytes;
1049 lpDSCBCaps->dwReserved = 0;
1051 TRACE("returning DS_OK\n");
1052 return DS_OK;
1055 static HRESULT WINAPI
1056 IDirectSoundCaptureBufferImpl_GetCurrentPosition(
1057 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1058 LPDWORD lpdwCapturePosition,
1059 LPDWORD lpdwReadPosition )
1061 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1062 TRACE( "(%p,%p,%p)\n", This, lpdwCapturePosition, lpdwReadPosition );
1064 if (This == NULL) {
1065 WARN("invalid parameter: This == NULL\n");
1066 return DSERR_INVALIDPARAM;
1069 if (This->dsound == NULL) {
1070 WARN("invalid parameter: This->dsound == NULL\n");
1071 return DSERR_INVALIDPARAM;
1074 if (This->dsound->driver) {
1075 HRESULT hres;
1076 hres = IDsCaptureDriverBuffer_GetPosition(This->dsound->hwbuf, lpdwCapturePosition, lpdwReadPosition );
1077 if (hres != DS_OK) {
1078 WARN("IDsCaptureDriverBuffer_GetPosition failed\n");
1079 return hres;
1081 } else if (This->dsound->hwi) {
1082 EnterCriticalSection(&(This->dsound->lock));
1083 TRACE("old This->dsound->state=%ld\n",This->dsound->state);
1084 if (lpdwCapturePosition) {
1085 MMTIME mtime;
1086 mtime.wType = TIME_BYTES;
1087 waveInGetPosition(This->dsound->hwi, &mtime, sizeof(mtime));
1088 TRACE("mtime.u.cb=%ld,This->dsound->buflen=%ld\n", mtime.u.cb,
1089 This->dsound->buflen);
1090 mtime.u.cb = mtime.u.cb % This->dsound->buflen;
1091 *lpdwCapturePosition = mtime.u.cb;
1094 if (lpdwReadPosition) {
1095 if (This->dsound->state == STATE_STARTING) {
1096 if (lpdwCapturePosition)
1097 This->dsound->read_position = *lpdwCapturePosition;
1098 This->dsound->state = STATE_CAPTURING;
1100 *lpdwReadPosition = This->dsound->read_position;
1102 TRACE("new This->dsound->state=%ld\n",This->dsound->state);
1103 LeaveCriticalSection(&(This->dsound->lock));
1104 if (lpdwCapturePosition) TRACE("*lpdwCapturePosition=%ld\n",*lpdwCapturePosition);
1105 if (lpdwReadPosition) TRACE("*lpdwReadPosition=%ld\n",*lpdwReadPosition);
1106 } else {
1107 WARN("no driver\n");
1108 return DSERR_NODRIVER;
1111 TRACE("returning DS_OK\n");
1112 return DS_OK;
1115 static HRESULT WINAPI
1116 IDirectSoundCaptureBufferImpl_GetFormat(
1117 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1118 LPWAVEFORMATEX lpwfxFormat,
1119 DWORD dwSizeAllocated,
1120 LPDWORD lpdwSizeWritten )
1122 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1123 TRACE( "(%p,%p,0x%08lx,%p)\n", This, lpwfxFormat, dwSizeAllocated,
1124 lpdwSizeWritten );
1126 if (This == NULL) {
1127 WARN("invalid parameter: This == NULL\n");
1128 return DSERR_INVALIDPARAM;
1131 if (This->dsound == NULL) {
1132 WARN("invalid parameter: This->dsound == NULL\n");
1133 return DSERR_INVALIDPARAM;
1136 /* FIXME: use real size for extended formats someday */
1137 if (dwSizeAllocated > sizeof(This->dsound->wfx))
1138 dwSizeAllocated = sizeof(This->dsound->wfx);
1139 if (lpwfxFormat) { /* NULL is valid (just want size) */
1140 memcpy(lpwfxFormat,&(This->dsound->wfx),dwSizeAllocated);
1141 if (lpdwSizeWritten)
1142 *lpdwSizeWritten = dwSizeAllocated;
1143 } else {
1144 if (lpdwSizeWritten)
1145 *lpdwSizeWritten = sizeof(This->dsound->wfx);
1146 else {
1147 TRACE("invalid parameter: lpdwSizeWritten = NULL\n");
1148 return DSERR_INVALIDPARAM;
1152 TRACE("returning DS_OK\n");
1153 return DS_OK;
1156 static HRESULT WINAPI
1157 IDirectSoundCaptureBufferImpl_GetStatus(
1158 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1159 LPDWORD lpdwStatus )
1161 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1162 TRACE( "(%p, %p), thread is %04lx\n", This, lpdwStatus, GetCurrentThreadId() );
1164 if (This == NULL) {
1165 WARN("invalid parameter: This == NULL\n");
1166 return DSERR_INVALIDPARAM;
1169 if (This->dsound == NULL) {
1170 WARN("invalid parameter: This->dsound == NULL\n");
1171 return DSERR_INVALIDPARAM;
1174 if (lpdwStatus == NULL) {
1175 WARN("invalid parameter: lpdwStatus == NULL\n");
1176 return DSERR_INVALIDPARAM;
1179 *lpdwStatus = 0;
1180 EnterCriticalSection(&(This->dsound->lock));
1182 TRACE("old This->dsound->state=%ld, old lpdwStatus=%08lx\n",This->dsound->state,*lpdwStatus);
1183 if ((This->dsound->state == STATE_STARTING) ||
1184 (This->dsound->state == STATE_CAPTURING)) {
1185 *lpdwStatus |= DSCBSTATUS_CAPTURING;
1186 if (This->flags & DSCBSTART_LOOPING)
1187 *lpdwStatus |= DSCBSTATUS_LOOPING;
1189 TRACE("new This->dsound->state=%ld, new lpdwStatus=%08lx\n",This->dsound->state,*lpdwStatus);
1190 LeaveCriticalSection(&(This->dsound->lock));
1192 TRACE("status=%lx\n", *lpdwStatus);
1193 TRACE("returning DS_OK\n");
1194 return DS_OK;
1197 static HRESULT WINAPI
1198 IDirectSoundCaptureBufferImpl_Initialize(
1199 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1200 LPDIRECTSOUNDCAPTURE lpDSC,
1201 LPCDSCBUFFERDESC lpcDSCBDesc )
1203 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1205 FIXME( "(%p,%p,%p): stub\n", This, lpDSC, lpcDSCBDesc );
1207 return DS_OK;
1210 static HRESULT WINAPI
1211 IDirectSoundCaptureBufferImpl_Lock(
1212 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1213 DWORD dwReadCusor,
1214 DWORD dwReadBytes,
1215 LPVOID* lplpvAudioPtr1,
1216 LPDWORD lpdwAudioBytes1,
1217 LPVOID* lplpvAudioPtr2,
1218 LPDWORD lpdwAudioBytes2,
1219 DWORD dwFlags )
1221 HRESULT err = DS_OK;
1222 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1223 TRACE( "(%p,%08lu,%08lu,%p,%p,%p,%p,0x%08lx) at %ld\n", This, dwReadCusor,
1224 dwReadBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2,
1225 lpdwAudioBytes2, dwFlags, GetTickCount() );
1227 if (This == NULL) {
1228 WARN("invalid parameter: This == NULL\n");
1229 return DSERR_INVALIDPARAM;
1232 if (This->dsound == NULL) {
1233 WARN("invalid parameter: This->dsound == NULL\n");
1234 return DSERR_INVALIDPARAM;
1237 if (lplpvAudioPtr1 == NULL) {
1238 WARN("invalid parameter: lplpvAudioPtr1 == NULL\n");
1239 return DSERR_INVALIDPARAM;
1242 if (lpdwAudioBytes1 == NULL) {
1243 WARN("invalid parameter: lpdwAudioBytes1 == NULL\n");
1244 return DSERR_INVALIDPARAM;
1247 EnterCriticalSection(&(This->dsound->lock));
1249 if (This->dsound->driver) {
1250 err = IDsCaptureDriverBuffer_Lock(This->dsound->hwbuf, lplpvAudioPtr1,
1251 lpdwAudioBytes1, lplpvAudioPtr2, lpdwAudioBytes2,
1252 dwReadCusor, dwReadBytes, dwFlags);
1253 if (err != DS_OK)
1254 WARN("IDsCaptureDriverBuffer_Lock failed\n");
1255 } else if (This->dsound->hwi) {
1256 *lplpvAudioPtr1 = This->dsound->buffer + dwReadCusor;
1257 if ( (dwReadCusor + dwReadBytes) > This->dsound->buflen) {
1258 *lpdwAudioBytes1 = This->dsound->buflen - dwReadCusor;
1259 if (lplpvAudioPtr2)
1260 *lplpvAudioPtr2 = This->dsound->buffer;
1261 if (lpdwAudioBytes2)
1262 *lpdwAudioBytes2 = dwReadBytes - *lpdwAudioBytes1;
1263 } else {
1264 *lpdwAudioBytes1 = dwReadBytes;
1265 if (lplpvAudioPtr2)
1266 *lplpvAudioPtr2 = 0;
1267 if (lpdwAudioBytes2)
1268 *lpdwAudioBytes2 = 0;
1270 } else {
1271 TRACE("invalid call\n");
1272 err = DSERR_INVALIDCALL; /* DSERR_NODRIVER ? */
1275 LeaveCriticalSection(&(This->dsound->lock));
1277 return err;
1280 static HRESULT WINAPI
1281 IDirectSoundCaptureBufferImpl_Start(
1282 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1283 DWORD dwFlags )
1285 HRESULT err = DS_OK;
1286 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1287 TRACE( "(%p,0x%08lx)\n", This, dwFlags );
1289 if (This == NULL) {
1290 WARN("invalid parameter: This == NULL\n");
1291 return DSERR_INVALIDPARAM;
1294 if (This->dsound == NULL) {
1295 WARN("invalid parameter: This->dsound == NULL\n");
1296 return DSERR_INVALIDPARAM;
1299 if ( (This->dsound->driver == 0) && (This->dsound->hwi == 0) ) {
1300 WARN("no driver\n");
1301 return DSERR_NODRIVER;
1304 EnterCriticalSection(&(This->dsound->lock));
1306 This->flags = dwFlags;
1307 TRACE("old This->dsound->state=%ld\n",This->dsound->state);
1308 if (This->dsound->state == STATE_STOPPED)
1309 This->dsound->state = STATE_STARTING;
1310 else if (This->dsound->state == STATE_STOPPING)
1311 This->dsound->state = STATE_CAPTURING;
1312 TRACE("new This->dsound->state=%ld\n",This->dsound->state);
1314 LeaveCriticalSection(&(This->dsound->lock));
1316 if (This->dsound->driver) {
1317 err = IDsCaptureDriverBuffer_Start(This->dsound->hwbuf, dwFlags);
1318 if (err != DS_OK)
1319 WARN("IDsCaptureDriverBuffer_Start failed\n");
1320 return err;
1321 } else {
1322 IDirectSoundCaptureImpl* ipDSC = This->dsound;
1324 if (ipDSC->buffer) {
1325 if (This->nrofnotifies) {
1326 unsigned c;
1328 ipDSC->nrofpwaves = This->nrofnotifies;
1330 /* prepare headers */
1331 ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,
1332 ipDSC->nrofpwaves*sizeof(WAVEHDR));
1334 for (c = 0; c < ipDSC->nrofpwaves; c++) {
1335 if (c == 0) {
1336 ipDSC->pwave[0].lpData = ipDSC->buffer;
1337 ipDSC->pwave[0].dwBufferLength =
1338 This->notifies[0].dwOffset + 1;
1339 } else {
1340 ipDSC->pwave[c].lpData = ipDSC->buffer +
1341 This->notifies[c-1].dwOffset + 1;
1342 ipDSC->pwave[c].dwBufferLength =
1343 This->notifies[c].dwOffset -
1344 This->notifies[c-1].dwOffset;
1346 ipDSC->pwave[c].dwUser = (DWORD)ipDSC;
1347 ipDSC->pwave[c].dwFlags = 0;
1348 ipDSC->pwave[c].dwLoops = 0;
1349 err = mmErr(waveInPrepareHeader(ipDSC->hwi,
1350 &(ipDSC->pwave[c]),sizeof(WAVEHDR)));
1351 if (err != DS_OK) {
1352 while (c--)
1353 waveInUnprepareHeader(ipDSC->hwi,
1354 &(ipDSC->pwave[c]),sizeof(WAVEHDR));
1355 break;
1359 memset(ipDSC->buffer,
1360 (ipDSC->wfx.wBitsPerSample == 16) ? 0 : 128, ipDSC->buflen);
1361 } else {
1362 TRACE("no notifiers specified\n");
1363 /* no notifiers specified so just create a single default header */
1364 ipDSC->nrofpwaves = 1;
1365 ipDSC->pwave = HeapReAlloc(GetProcessHeap(),0,ipDSC->pwave,sizeof(WAVEHDR));
1366 ipDSC->pwave[0].lpData = ipDSC->buffer;
1367 ipDSC->pwave[0].dwBufferLength = ipDSC->buflen;
1368 ipDSC->pwave[0].dwUser = (DWORD)ipDSC;
1369 ipDSC->pwave[0].dwFlags = 0;
1370 ipDSC->pwave[0].dwLoops = 0;
1372 err = mmErr(waveInPrepareHeader(ipDSC->hwi,
1373 &(ipDSC->pwave[0]),sizeof(WAVEHDR)));
1374 if (err != DS_OK) {
1375 WARN("waveInPrepareHeader failed\n");
1376 waveInUnprepareHeader(ipDSC->hwi,
1377 &(ipDSC->pwave[0]),sizeof(WAVEHDR));
1382 ipDSC->index = 0;
1383 ipDSC->read_position = 0;
1385 if (err == DS_OK) {
1386 err = mmErr(waveInReset(ipDSC->hwi));
1387 if (err == DS_OK) {
1388 /* add the first buffer to the queue */
1389 err = mmErr(waveInAddBuffer(ipDSC->hwi, &(ipDSC->pwave[0]), sizeof(WAVEHDR)));
1390 if (err == DS_OK) {
1391 /* start filling the first buffer */
1392 err = mmErr(waveInStart(ipDSC->hwi));
1393 } else
1394 WARN("waveInAddBuffer failed\n");
1395 } else
1396 WARN("waveInReset failed\n");
1400 if (err != DS_OK) {
1401 WARN("calling waveInClose because of error\n");
1402 waveInClose(This->dsound->hwi);
1403 This->dsound->hwi = 0;
1406 TRACE("returning %ld\n", err);
1407 return err;
1410 static HRESULT WINAPI
1411 IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
1413 HRESULT err = DS_OK;
1414 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1415 TRACE( "(%p)\n", This );
1417 if (This == NULL) {
1418 WARN("invalid parameter: This == NULL\n");
1419 return DSERR_INVALIDPARAM;
1422 if (This->dsound == NULL) {
1423 WARN("invalid parameter: This->dsound == NULL\n");
1424 return DSERR_INVALIDPARAM;
1427 EnterCriticalSection(&(This->dsound->lock));
1429 TRACE("old This->dsound->state=%ld\n",This->dsound->state);
1430 if (This->dsound->state == STATE_CAPTURING)
1431 This->dsound->state = STATE_STOPPING;
1432 else if (This->dsound->state == STATE_STARTING)
1433 This->dsound->state = STATE_STOPPED;
1434 TRACE("new This->dsound->state=%ld\n",This->dsound->state);
1436 LeaveCriticalSection(&(This->dsound->lock));
1438 if (This->dsound->driver) {
1439 err = IDsCaptureDriverBuffer_Stop(This->dsound->hwbuf);
1440 if (err == DSERR_BUFFERLOST) {
1441 /* Wine-only: the driver wants us to reopen the device */
1442 IDsCaptureDriverBuffer_Release(This->dsound->hwbuf);
1443 err = IDsCaptureDriver_CreateCaptureBuffer(This->dsound->driver,
1444 &(This->dsound->wfx),0,0,&(This->dsound->buflen),&(This->dsound->buffer),
1445 (LPVOID*)&(This->dsound->hwbuf));
1446 if (err != DS_OK) {
1447 WARN("IDsCaptureDriver_CreateCaptureBuffer failed\n");
1448 This->dsound->hwbuf = 0;
1450 } else if (err != DS_OK)
1451 WARN("IDsCaptureDriverBuffer_Stop failed\n");
1452 } else if (This->dsound->hwi) {
1453 err = waveInStop(This->dsound->hwi);
1454 } else {
1455 WARN("no driver\n");
1456 err = DSERR_NODRIVER;
1459 TRACE( "(%p) returning 0x%08lx\n", This,err);
1460 return err;
1463 static HRESULT WINAPI
1464 IDirectSoundCaptureBufferImpl_Unlock(
1465 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1466 LPVOID lpvAudioPtr1,
1467 DWORD dwAudioBytes1,
1468 LPVOID lpvAudioPtr2,
1469 DWORD dwAudioBytes2 )
1471 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1472 TRACE( "(%p,%p,%08lu,%p,%08lu)\n", This, lpvAudioPtr1, dwAudioBytes1,
1473 lpvAudioPtr2, dwAudioBytes2 );
1475 if (This == NULL) {
1476 WARN("invalid parameter: This == NULL\n");
1477 return DSERR_INVALIDPARAM;
1480 if (lpvAudioPtr1 == NULL) {
1481 WARN("invalid parameter: lpvAudioPtr1 == NULL\n");
1482 return DSERR_INVALIDPARAM;
1485 if (This->dsound->driver) {
1486 HRESULT hres;
1487 hres = IDsCaptureDriverBuffer_Unlock(This->dsound->hwbuf, lpvAudioPtr1,
1488 dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2);
1489 if (hres != DS_OK)
1490 WARN("IDsCaptureDriverBuffer_Unlock failed\n");
1491 return hres;
1492 } else if (This->dsound->hwi) {
1493 This->dsound->read_position = (This->dsound->read_position +
1494 (dwAudioBytes1 + dwAudioBytes2)) % This->dsound->buflen;
1495 } else {
1496 WARN("invalid call\n");
1497 return DSERR_INVALIDCALL;
1500 return DS_OK;
1503 static HRESULT WINAPI
1504 IDirectSoundCaptureBufferImpl_GetObjectInPath(
1505 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1506 REFGUID rguidObject,
1507 DWORD dwIndex,
1508 REFGUID rguidInterface,
1509 LPVOID* ppObject )
1511 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1513 FIXME( "(%p,%s,%lu,%s,%p): stub\n", This, debugstr_guid(rguidObject),
1514 dwIndex, debugstr_guid(rguidInterface), ppObject );
1516 return DS_OK;
1519 static HRESULT WINAPI
1520 IDirectSoundCaptureBufferImpl_GetFXStatus(
1521 LPDIRECTSOUNDCAPTUREBUFFER8 iface,
1522 DWORD dwFXCount,
1523 LPDWORD pdwFXStatus )
1525 ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
1527 FIXME( "(%p,%lu,%p): stub\n", This, dwFXCount, pdwFXStatus );
1529 return DS_OK;
1532 static ICOM_VTABLE(IDirectSoundCaptureBuffer8) dscbvt =
1534 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1535 /* IUnknown methods */
1536 IDirectSoundCaptureBufferImpl_QueryInterface,
1537 IDirectSoundCaptureBufferImpl_AddRef,
1538 IDirectSoundCaptureBufferImpl_Release,
1540 /* IDirectSoundCaptureBuffer methods */
1541 IDirectSoundCaptureBufferImpl_GetCaps,
1542 IDirectSoundCaptureBufferImpl_GetCurrentPosition,
1543 IDirectSoundCaptureBufferImpl_GetFormat,
1544 IDirectSoundCaptureBufferImpl_GetStatus,
1545 IDirectSoundCaptureBufferImpl_Initialize,
1546 IDirectSoundCaptureBufferImpl_Lock,
1547 IDirectSoundCaptureBufferImpl_Start,
1548 IDirectSoundCaptureBufferImpl_Stop,
1549 IDirectSoundCaptureBufferImpl_Unlock,
1551 /* IDirectSoundCaptureBuffer methods */
1552 IDirectSoundCaptureBufferImpl_GetObjectInPath,
1553 IDirectSoundCaptureBufferImpl_GetFXStatus
1556 /*******************************************************************************
1557 * DirectSoundCapture ClassFactory
1560 static HRESULT WINAPI
1561 DSCCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1563 ICOM_THIS(IClassFactoryImpl,iface);
1565 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1566 return E_NOINTERFACE;
1569 static ULONG WINAPI
1570 DSCCF_AddRef(LPCLASSFACTORY iface)
1572 ICOM_THIS(IClassFactoryImpl,iface);
1573 TRACE("(%p) ref was %ld\n", This, This->ref);
1574 return ++(This->ref);
1577 static ULONG WINAPI
1578 DSCCF_Release(LPCLASSFACTORY iface)
1580 ICOM_THIS(IClassFactoryImpl,iface);
1581 /* static class, won't be freed */
1582 TRACE("(%p) ref was %ld\n", This, This->ref);
1583 return --(This->ref);
1586 static HRESULT WINAPI
1587 DSCCF_CreateInstance(
1588 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj )
1590 ICOM_THIS(IClassFactoryImpl,iface);
1591 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1593 if (ppobj == NULL) {
1594 WARN("invalid parameter\n");
1595 return E_INVALIDARG;
1598 *ppobj = NULL;
1600 if ( IsEqualGUID( &IID_IDirectSoundCapture, riid ) ||
1601 IsEqualGUID( &IID_IDirectSoundCapture8, riid ) ) {
1602 return DirectSoundCaptureCreate8(0,(LPDIRECTSOUNDCAPTURE8*)ppobj,pOuter);
1605 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
1606 return E_NOINTERFACE;
1609 static HRESULT WINAPI
1610 DSCCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1612 ICOM_THIS(IClassFactoryImpl,iface);
1613 FIXME("(%p)->(%d),stub!\n",This,dolock);
1614 return S_OK;
1617 static ICOM_VTABLE(IClassFactory) DSCCF_Vtbl =
1619 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1620 DSCCF_QueryInterface,
1621 DSCCF_AddRef,
1622 DSCCF_Release,
1623 DSCCF_CreateInstance,
1624 DSCCF_LockServer
1627 IClassFactoryImpl DSOUND_CAPTURE_CF = { &DSCCF_Vtbl, 1 };
1629 /***************************************************************************
1630 * DirectSoundFullDuplexCreate8 [DSOUND.10]
1632 * Create and initialize a DirectSoundFullDuplex interface.
1634 * PARAMS
1635 * pcGuidCaptureDevice [I] Address of sound capture device GUID.
1636 * pcGuidRenderDevice [I] Address of sound render device GUID.
1637 * pcDSCBufferDesc [I] Address of capture buffer description.
1638 * pcDSBufferDesc [I] Address of render buffer description.
1639 * hWnd [I] Handle to application window.
1640 * dwLevel [I] Cooperative level.
1641 * ppDSFD [O] Address where full duplex interface returned.
1642 * ppDSCBuffer8 [0] Address where capture buffer interface returned.
1643 * ppDSBuffer8 [0] Address where render buffer interface returned.
1644 * pUnkOuter [I] Must be NULL.
1646 * RETURNS
1647 * Success: DS_OK
1648 * Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
1649 * DSERR_OUTOFMEMORY DSERR_INVALIDCALL DSERR_NODRIVER
1651 HRESULT WINAPI
1652 DirectSoundFullDuplexCreate8(
1653 LPCGUID pcGuidCaptureDevice,
1654 LPCGUID pcGuidRenderDevice,
1655 LPCDSCBUFFERDESC pcDSCBufferDesc,
1656 LPCDSBUFFERDESC pcDSBufferDesc,
1657 HWND hWnd,
1658 DWORD dwLevel,
1659 LPDIRECTSOUNDFULLDUPLEX *ppDSFD,
1660 LPDIRECTSOUNDCAPTUREBUFFER8 *ppDSCBuffer8,
1661 LPDIRECTSOUNDBUFFER8 *ppDSBuffer8,
1662 LPUNKNOWN pUnkOuter)
1664 IDirectSoundFullDuplexImpl** ippDSFD=(IDirectSoundFullDuplexImpl**)ppDSFD;
1665 TRACE("(%s,%s,%p,%p,%lx,%lx,%p,%p,%p,%p)\n", debugstr_guid(pcGuidCaptureDevice),
1666 debugstr_guid(pcGuidRenderDevice), pcDSCBufferDesc, pcDSBufferDesc,
1667 (DWORD)hWnd, dwLevel, ppDSFD, ppDSCBuffer8, ppDSBuffer8, pUnkOuter);
1669 if ( pUnkOuter ) {
1670 WARN("pUnkOuter != 0\n");
1671 return DSERR_NOAGGREGATION;
1674 *ippDSFD = (IDirectSoundFullDuplexImpl*)HeapAlloc(GetProcessHeap(),
1675 HEAP_ZERO_MEMORY, sizeof(IDirectSoundFullDuplexImpl));
1677 if (*ippDSFD == NULL) {
1678 WARN("out of memory\n");
1679 return DSERR_OUTOFMEMORY;
1680 } else {
1681 HRESULT hres;
1682 ICOM_THIS(IDirectSoundFullDuplexImpl, *ippDSFD);
1684 This->ref = 1;
1685 This->lpVtbl = &dsfdvt;
1687 InitializeCriticalSection( &(This->lock) );
1689 hres = IDirectSoundFullDuplexImpl_Initialize( (LPDIRECTSOUNDFULLDUPLEX)This,
1690 pcGuidCaptureDevice, pcGuidRenderDevice,
1691 pcDSCBufferDesc, pcDSBufferDesc,
1692 hWnd, dwLevel, ppDSCBuffer8, ppDSBuffer8);
1693 if (hres != DS_OK)
1694 WARN("IDirectSoundFullDuplexImpl_Initialize failed\n");
1695 return hres;
1698 return DSERR_GENERIC;
1701 static HRESULT WINAPI
1702 IDirectSoundFullDuplexImpl_QueryInterface(
1703 LPDIRECTSOUNDFULLDUPLEX iface,
1704 REFIID riid,
1705 LPVOID* ppobj )
1707 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1708 TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
1710 if (ppobj == NULL) {
1711 WARN("invalid parameter\n");
1712 return E_INVALIDARG;
1715 *ppobj = NULL;
1716 return E_NOINTERFACE;
1719 static ULONG WINAPI
1720 IDirectSoundFullDuplexImpl_AddRef( LPDIRECTSOUNDFULLDUPLEX iface )
1722 ULONG uRef;
1723 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1724 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1726 EnterCriticalSection( &(This->lock) );
1728 uRef = ++(This->ref);
1730 LeaveCriticalSection( &(This->lock) );
1732 return uRef;
1735 static ULONG WINAPI
1736 IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface )
1738 ULONG uRef;
1739 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1740 TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
1742 EnterCriticalSection( &(This->lock) );
1744 uRef = --(This->ref);
1746 LeaveCriticalSection( &(This->lock) );
1748 if ( uRef == 0 ) {
1749 DeleteCriticalSection( &(This->lock) );
1750 HeapFree( GetProcessHeap(), 0, This );
1751 TRACE("(%p) released\n",This);
1754 return uRef;
1757 static HRESULT WINAPI
1758 IDirectSoundFullDuplexImpl_Initialize(
1759 LPDIRECTSOUNDFULLDUPLEX iface,
1760 LPCGUID pCaptureGuid,
1761 LPCGUID pRendererGuid,
1762 LPCDSCBUFFERDESC lpDscBufferDesc,
1763 LPCDSBUFFERDESC lpDsBufferDesc,
1764 HWND hWnd,
1765 DWORD dwLevel,
1766 LPLPDIRECTSOUNDCAPTUREBUFFER8 lplpDirectSoundCaptureBuffer8,
1767 LPLPDIRECTSOUNDBUFFER8 lplpDirectSoundBuffer8 )
1769 ICOM_THIS(IDirectSoundFullDuplexImpl,iface);
1770 IDirectSoundCaptureBufferImpl** ippdscb=(IDirectSoundCaptureBufferImpl**)lplpDirectSoundCaptureBuffer8;
1771 IDirectSoundBufferImpl** ippdsc=(IDirectSoundBufferImpl**)lplpDirectSoundBuffer8;
1773 FIXME( "(%p,%s,%s,%p,%p,%lx,%lx,%p,%p) stub!\n", This, debugstr_guid(pCaptureGuid),
1774 debugstr_guid(pRendererGuid), lpDscBufferDesc, lpDsBufferDesc, (DWORD)hWnd, dwLevel,
1775 ippdscb, ippdsc);
1777 return E_FAIL;
1780 static ICOM_VTABLE(IDirectSoundFullDuplex) dsfdvt =
1782 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1783 /* IUnknown methods */
1784 IDirectSoundFullDuplexImpl_QueryInterface,
1785 IDirectSoundFullDuplexImpl_AddRef,
1786 IDirectSoundFullDuplexImpl_Release,
1788 /* IDirectSoundFullDuplex methods */
1789 IDirectSoundFullDuplexImpl_Initialize
1792 /*******************************************************************************
1793 * DirectSoundFullDuplex ClassFactory
1796 static HRESULT WINAPI
1797 DSFDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
1799 ICOM_THIS(IClassFactoryImpl,iface);
1801 FIXME("(%p)->(%s,%p),stub!\n",This,debugstr_guid(riid),ppobj);
1802 return E_NOINTERFACE;
1805 static ULONG WINAPI
1806 DSFDCF_AddRef(LPCLASSFACTORY iface)
1808 ICOM_THIS(IClassFactoryImpl,iface);
1809 TRACE("(%p) ref was %ld\n", This, This->ref);
1810 return ++(This->ref);
1813 static ULONG WINAPI
1814 DSFDCF_Release(LPCLASSFACTORY iface)
1816 ICOM_THIS(IClassFactoryImpl,iface);
1817 /* static class, won't be freed */
1818 TRACE("(%p) ref was %ld\n", This, This->ref);
1819 return --(This->ref);
1822 static HRESULT WINAPI
1823 DSFDCF_CreateInstance(
1824 LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj )
1826 ICOM_THIS(IClassFactoryImpl,iface);
1828 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
1830 if (ppobj == NULL) {
1831 WARN("invalid parameter\n");
1832 return E_INVALIDARG;
1835 *ppobj = NULL;
1837 if ( IsEqualGUID( &IID_IDirectSoundFullDuplex, riid ) ) {
1838 /* FIXME: how do we do this one ? */
1839 FIXME("not implemented\n");
1840 return E_NOINTERFACE;
1843 WARN("(%p,%p,%s,%p) Interface not found!\n",This,pOuter,debugstr_guid(riid),ppobj);
1844 return E_NOINTERFACE;
1847 static HRESULT WINAPI
1848 DSFDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
1850 ICOM_THIS(IClassFactoryImpl,iface);
1851 FIXME("(%p)->(%d),stub!\n",This,dolock);
1852 return S_OK;
1855 static ICOM_VTABLE(IClassFactory) DSFDCF_Vtbl =
1857 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1858 DSFDCF_QueryInterface,
1859 DSFDCF_AddRef,
1860 DSFDCF_Release,
1861 DSFDCF_CreateInstance,
1862 DSFDCF_LockServer
1865 IClassFactoryImpl DSOUND_FULLDUPLEX_CF = { &DSFDCF_Vtbl, 1 };