2003-02-15 01:01:17 +01:00
|
|
|
/* DirectSoundCapture
|
2002-06-13 21:15:06 +02:00
|
|
|
*
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1998 Rob Riggs
|
|
|
|
* Copyright 2000-2001 TransGaming Technologies, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-06-13 21:15:06 +02:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* TODO:
|
2003-03-04 03:12:34 +01:00
|
|
|
* Implement FX support.
|
2005-06-04 11:38:14 +02:00
|
|
|
* Implement both IDirectSoundCaptureBuffer and IDirectSoundCaptureBuffer8
|
|
|
|
* Make DirectSoundCaptureCreate and DirectSoundCaptureCreate8 behave differently
|
2002-06-13 21:15:06 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
#define COBJMACROS
|
2015-03-11 11:30:29 +01:00
|
|
|
|
2002-06-13 21:15:06 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2005-10-17 11:24:50 +02:00
|
|
|
#include "winuser.h"
|
2002-06-13 21:15:06 +02:00
|
|
|
#include "mmsystem.h"
|
2003-02-15 01:01:17 +01:00
|
|
|
#include "mmddk.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "winnls.h"
|
2002-06-13 21:15:06 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "dsound.h"
|
2003-02-15 01:01:17 +01:00
|
|
|
#include "dsound_private.h"
|
2002-06-13 21:15:06 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dsound);
|
|
|
|
|
2012-08-30 23:48:27 +02:00
|
|
|
typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice;
|
|
|
|
|
|
|
|
/* IDirectSoundCaptureBuffer implementation structure */
|
|
|
|
typedef struct IDirectSoundCaptureBufferImpl
|
|
|
|
{
|
|
|
|
IDirectSoundCaptureBuffer8 IDirectSoundCaptureBuffer8_iface;
|
|
|
|
IDirectSoundNotify IDirectSoundNotify_iface;
|
|
|
|
LONG numIfaces; /* "in use interfaces" refcount */
|
2016-05-16 16:55:43 +02:00
|
|
|
LONG ref, refn, has_dsc8;
|
2012-08-30 23:48:27 +02:00
|
|
|
/* IDirectSoundCaptureBuffer fields */
|
|
|
|
DirectSoundCaptureDevice *device;
|
|
|
|
DSCBUFFERDESC *pdscbd;
|
|
|
|
DWORD flags;
|
|
|
|
/* IDirectSoundNotify fields */
|
|
|
|
DSBPOSITIONNOTIFY *notifies;
|
|
|
|
int nrofnotifies;
|
2013-08-21 17:16:08 +02:00
|
|
|
HANDLE thread;
|
|
|
|
HANDLE sleepev;
|
2012-08-30 23:48:27 +02:00
|
|
|
} IDirectSoundCaptureBufferImpl;
|
|
|
|
|
|
|
|
/* DirectSoundCaptureDevice implementation structure */
|
|
|
|
struct DirectSoundCaptureDevice
|
|
|
|
{
|
|
|
|
GUID guid;
|
|
|
|
LONG ref;
|
|
|
|
DSCCAPS drvcaps;
|
|
|
|
BYTE *buffer;
|
|
|
|
DWORD buflen, write_pos_bytes;
|
|
|
|
WAVEFORMATEX *pwfx;
|
|
|
|
IDirectSoundCaptureBufferImpl *capture_buffer;
|
|
|
|
DWORD state;
|
|
|
|
CRITICAL_SECTION lock;
|
|
|
|
IMMDevice *mmdevice;
|
|
|
|
IAudioClient *client;
|
|
|
|
IAudioCaptureClient *capture;
|
|
|
|
struct list entry;
|
|
|
|
};
|
|
|
|
|
2013-08-21 17:16:08 +02:00
|
|
|
static DWORD WINAPI DSOUND_capture_thread(void *user);
|
2006-08-02 13:26:14 +02:00
|
|
|
|
2012-01-12 00:11:20 +01:00
|
|
|
static void capturebuffer_destroy(IDirectSoundCaptureBufferImpl *This)
|
|
|
|
{
|
|
|
|
if (This->device->state == STATE_CAPTURING)
|
|
|
|
This->device->state = STATE_STOPPING;
|
|
|
|
|
2013-08-21 17:16:08 +02:00
|
|
|
if(This->thread){
|
|
|
|
SetEvent(This->sleepev);
|
|
|
|
WaitForSingleObject(This->thread, INFINITE);
|
|
|
|
CloseHandle(This->thread);
|
|
|
|
}
|
|
|
|
CloseHandle(This->sleepev);
|
|
|
|
|
2012-01-12 00:11:20 +01:00
|
|
|
HeapFree(GetProcessHeap(),0, This->pdscbd);
|
|
|
|
|
|
|
|
if (This->device->client) {
|
|
|
|
IAudioClient_Release(This->device->client);
|
|
|
|
This->device->client = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->device->capture) {
|
|
|
|
IAudioCaptureClient_Release(This->device->capture);
|
|
|
|
This->device->capture = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove from DirectSoundCaptureDevice */
|
|
|
|
This->device->capture_buffer = NULL;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->notifies);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
TRACE("(%p) released\n", This);
|
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
/*******************************************************************************
|
2012-01-12 00:09:01 +01:00
|
|
|
* IDirectSoundNotify
|
2009-12-02 12:12:37 +01:00
|
|
|
*/
|
2012-01-12 00:19:48 +01:00
|
|
|
static inline struct IDirectSoundCaptureBufferImpl *impl_from_IDirectSoundNotify(IDirectSoundNotify *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectSoundCaptureBufferImpl, IDirectSoundNotify_iface);
|
|
|
|
}
|
|
|
|
|
2012-01-12 00:09:01 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundNotifyImpl_QueryInterface(IDirectSoundNotify *iface, REFIID riid,
|
|
|
|
void **ppobj)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2012-01-12 00:19:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundNotify(iface);
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2012-01-12 00:19:48 +01:00
|
|
|
TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj);
|
2006-08-02 13:26:14 +02:00
|
|
|
|
2018-03-30 06:04:48 +02:00
|
|
|
return IDirectSoundCaptureBuffer8_QueryInterface(&This->IDirectSoundCaptureBuffer8_iface, riid, ppobj);
|
2009-12-02 12:12:37 +01:00
|
|
|
}
|
2006-08-02 13:26:14 +02:00
|
|
|
|
2012-01-12 00:09:01 +01:00
|
|
|
static ULONG WINAPI IDirectSoundNotifyImpl_AddRef(IDirectSoundNotify *iface)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2012-01-12 00:19:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundNotify(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->refn);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("(%p) ref was %d\n", This, ref - 1);
|
2012-01-12 00:19:48 +01:00
|
|
|
|
|
|
|
if(ref == 1)
|
|
|
|
InterlockedIncrement(&This->numIfaces);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
return ref;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2012-01-12 00:09:01 +01:00
|
|
|
static ULONG WINAPI IDirectSoundNotifyImpl_Release(IDirectSoundNotify *iface)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2012-01-12 00:19:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundNotify(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->refn);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("(%p) ref was %d\n", This, ref + 1);
|
2006-06-10 11:57:48 +02:00
|
|
|
|
2012-01-12 00:19:48 +01:00
|
|
|
if (!ref && !InterlockedDecrement(&This->numIfaces))
|
|
|
|
capturebuffer_destroy(This);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
return ref;
|
|
|
|
}
|
2003-11-14 22:03:24 +01:00
|
|
|
|
2012-01-12 00:09:01 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(IDirectSoundNotify *iface,
|
|
|
|
DWORD howmuch, const DSBPOSITIONNOTIFY *notify)
|
2005-06-04 11:38:14 +02:00
|
|
|
{
|
2012-01-12 00:19:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundNotify(iface);
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("(%p,0x%08x,%p)\n",This,howmuch,notify);
|
2006-08-18 07:13:31 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (howmuch > 0 && notify == NULL) {
|
|
|
|
WARN("invalid parameter: notify == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2006-08-18 07:13:31 +02:00
|
|
|
}
|
2005-06-04 11:38:14 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (TRACE_ON(dsound)) {
|
|
|
|
unsigned int i;
|
|
|
|
for (i=0;i<howmuch;i++)
|
|
|
|
TRACE("notify at %d to %p\n",
|
|
|
|
notify[i].dwOffset,notify[i].hEventNotify);
|
|
|
|
}
|
2005-06-04 11:38:14 +02:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
if (howmuch > 0) {
|
2009-12-02 12:12:37 +01:00
|
|
|
/* Make an internal copy of the caller-supplied array.
|
|
|
|
* Replace the existing copy if one is already present. */
|
2012-01-12 00:19:48 +01:00
|
|
|
if (This->notifies)
|
|
|
|
This->notifies = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->notifies,
|
|
|
|
howmuch * sizeof(DSBPOSITIONNOTIFY));
|
2009-12-02 12:12:37 +01:00
|
|
|
else
|
2012-01-12 00:19:48 +01:00
|
|
|
This->notifies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
howmuch * sizeof(DSBPOSITIONNOTIFY));
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2012-01-12 00:19:48 +01:00
|
|
|
if (!This->notifies) {
|
2009-12-02 12:12:37 +01:00
|
|
|
WARN("out of memory\n");
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
}
|
2012-01-12 00:19:48 +01:00
|
|
|
CopyMemory(This->notifies, notify, howmuch * sizeof(DSBPOSITIONNOTIFY));
|
|
|
|
This->nrofnotifies = howmuch;
|
2005-06-04 11:38:14 +02:00
|
|
|
} else {
|
2012-01-12 00:19:48 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->notifies);
|
|
|
|
This->notifies = NULL;
|
|
|
|
This->nrofnotifies = 0;
|
2005-06-04 11:38:14 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
return S_OK;
|
2005-06-04 11:38:14 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
static const IDirectSoundNotifyVtbl dscnvt =
|
2005-06-04 11:38:14 +02:00
|
|
|
{
|
2012-01-12 00:09:01 +01:00
|
|
|
IDirectSoundNotifyImpl_QueryInterface,
|
|
|
|
IDirectSoundNotifyImpl_AddRef,
|
|
|
|
IDirectSoundNotifyImpl_Release,
|
|
|
|
IDirectSoundNotifyImpl_SetNotificationPositions
|
2009-12-02 12:12:37 +01:00
|
|
|
};
|
2006-08-18 07:13:31 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
|
|
|
|
static const char * const captureStateString[] = {
|
|
|
|
"STATE_STOPPED",
|
|
|
|
"STATE_STARTING",
|
|
|
|
"STATE_CAPTURING",
|
|
|
|
"STATE_STOPPING"
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2012-01-12 00:06:48 +01:00
|
|
|
* IDirectSoundCaptureBuffer
|
2002-06-13 21:15:06 +02:00
|
|
|
*/
|
2012-01-12 00:06:48 +01:00
|
|
|
static inline IDirectSoundCaptureBufferImpl *impl_from_IDirectSoundCaptureBuffer8(IDirectSoundCaptureBuffer8 *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectSoundCaptureBufferImpl, IDirectSoundCaptureBuffer8_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_QueryInterface(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
REFIID riid, void **ppobj)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2011-09-24 16:02:52 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE( "(%p,%s,%p)\n", This, debugstr_guid(riid), ppobj );
|
2005-06-04 11:38:14 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (ppobj == NULL) {
|
|
|
|
WARN("invalid parameter\n");
|
|
|
|
return E_INVALIDARG;
|
2005-06-04 11:38:14 +02:00
|
|
|
}
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
*ppobj = NULL;
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2016-05-16 16:55:43 +02:00
|
|
|
if ( IsEqualIID( &IID_IUnknown, riid ) ||
|
|
|
|
IsEqualIID( &IID_IDirectSoundCaptureBuffer, riid ) ||
|
|
|
|
(This->has_dsc8 && IsEqualIID( &IID_IDirectSoundCaptureBuffer8, riid )) ) {
|
2009-12-02 12:12:37 +01:00
|
|
|
IDirectSoundCaptureBuffer8_AddRef(iface);
|
2012-01-12 00:06:48 +01:00
|
|
|
*ppobj = iface;
|
|
|
|
return S_OK;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2012-01-12 00:19:48 +01:00
|
|
|
if ( IsEqualGUID( &IID_IDirectSoundNotify, riid ) ) {
|
|
|
|
IDirectSoundNotify_AddRef(&This->IDirectSoundNotify_iface);
|
|
|
|
*ppobj = &This->IDirectSoundNotify_iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
FIXME("(%p,%s,%p) unsupported GUID\n", This, debugstr_guid(riid), ppobj);
|
2005-06-05 19:44:30 +02:00
|
|
|
return E_NOINTERFACE;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static ULONG WINAPI IDirectSoundCaptureBufferImpl_AddRef(IDirectSoundCaptureBuffer8 *iface)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2012-01-12 00:11:20 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2012-01-12 00:06:48 +01:00
|
|
|
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p) ref was %d\n", This, ref - 1);
|
2012-01-12 00:11:20 +01:00
|
|
|
|
|
|
|
if(ref == 1)
|
|
|
|
InterlockedIncrement(&This->numIfaces);
|
|
|
|
|
2005-02-11 12:49:05 +01:00
|
|
|
return ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static ULONG WINAPI IDirectSoundCaptureBufferImpl_Release(IDirectSoundCaptureBuffer8 *iface)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2012-01-12 00:11:20 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2012-01-12 00:06:48 +01:00
|
|
|
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("(%p) ref was %d\n", This, ref + 1);
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2012-01-12 00:11:20 +01:00
|
|
|
if (!ref && !InterlockedDecrement(&This->numIfaces))
|
|
|
|
capturebuffer_destroy(This);
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2005-02-11 12:49:05 +01:00
|
|
|
return ref;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetCaps(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
DSCBCAPS *lpDSCBCaps)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE( "(%p,%p)\n", This, lpDSCBCaps );
|
2003-05-22 05:39:13 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (lpDSCBCaps == NULL) {
|
|
|
|
WARN("invalid parameter: lpDSCBCaps == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (lpDSCBCaps->dwSize < sizeof(DSCBCAPS)) {
|
|
|
|
WARN("invalid parameter: lpDSCBCaps->dwSize = %d\n", lpDSCBCaps->dwSize);
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (This->device == NULL) {
|
|
|
|
WARN("invalid parameter: This->device == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
lpDSCBCaps->dwSize = sizeof(DSCBCAPS);
|
|
|
|
lpDSCBCaps->dwFlags = This->flags;
|
|
|
|
lpDSCBCaps->dwBufferBytes = This->pdscbd->dwBufferBytes;
|
|
|
|
lpDSCBCaps->dwReserved = 0;
|
2003-05-22 05:39:13 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("returning DS_OK\n");
|
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetCurrentPosition(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
DWORD *lpdwCapturePosition, DWORD *lpdwReadPosition)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE( "(%p,%p,%p)\n", This, lpdwCapturePosition, lpdwReadPosition );
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2005-06-05 19:44:30 +02:00
|
|
|
if (This->device == NULL) {
|
2009-12-02 12:12:37 +01:00
|
|
|
WARN("invalid parameter: This->device == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-05-22 05:39:13 +02:00
|
|
|
}
|
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
EnterCriticalSection(&This->device->lock);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
if (!This->device->client) {
|
2009-12-02 12:12:37 +01:00
|
|
|
LeaveCriticalSection(&This->device->lock);
|
|
|
|
WARN("no driver\n");
|
2011-09-27 15:51:22 +02:00
|
|
|
return DSERR_NODRIVER;
|
2009-12-02 12:12:37 +01:00
|
|
|
}
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
if(lpdwCapturePosition)
|
|
|
|
*lpdwCapturePosition = This->device->write_pos_bytes;
|
|
|
|
|
|
|
|
if(lpdwReadPosition)
|
|
|
|
*lpdwReadPosition = This->device->write_pos_bytes;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&This->device->lock);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("cappos=%d readpos=%d\n", (lpdwCapturePosition?*lpdwCapturePosition:-1), (lpdwReadPosition?*lpdwReadPosition:-1));
|
2011-09-27 15:51:22 +02:00
|
|
|
TRACE("returning DS_OK\n");
|
|
|
|
|
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetFormat(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
WAVEFORMATEX *lpwfxFormat, DWORD dwSizeAllocated, DWORD *lpdwSizeWritten)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2009-12-02 12:12:37 +01:00
|
|
|
HRESULT hres = DS_OK;
|
2012-01-12 00:06:48 +01:00
|
|
|
|
|
|
|
TRACE("(%p,%p,0x%08x,%p)\n", This, lpwfxFormat, dwSizeAllocated, lpdwSizeWritten);
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (This->device == NULL) {
|
|
|
|
WARN("invalid parameter: This->device == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (dwSizeAllocated > (sizeof(WAVEFORMATEX) + This->device->pwfx->cbSize))
|
|
|
|
dwSizeAllocated = sizeof(WAVEFORMATEX) + This->device->pwfx->cbSize;
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (lpwfxFormat) { /* NULL is valid (just want size) */
|
|
|
|
CopyMemory(lpwfxFormat, This->device->pwfx, dwSizeAllocated);
|
|
|
|
if (lpdwSizeWritten)
|
|
|
|
*lpdwSizeWritten = dwSizeAllocated;
|
|
|
|
} else {
|
|
|
|
if (lpdwSizeWritten)
|
|
|
|
*lpdwSizeWritten = sizeof(WAVEFORMATEX) + This->device->pwfx->cbSize;
|
|
|
|
else {
|
|
|
|
TRACE("invalid parameter: lpdwSizeWritten = NULL\n");
|
|
|
|
hres = DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("returning %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetStatus(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
DWORD *lpdwStatus)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE( "(%p, %p), thread is %04x\n", This, lpdwStatus, GetCurrentThreadId() );
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (This->device == NULL) {
|
|
|
|
WARN("invalid parameter: This->device == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (lpdwStatus == NULL) {
|
|
|
|
WARN("invalid parameter: lpdwStatus == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
*lpdwStatus = 0;
|
|
|
|
EnterCriticalSection(&(This->device->lock));
|
2003-09-02 01:58:43 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("old This->device->state=%s, old lpdwStatus=%08x\n",
|
|
|
|
captureStateString[This->device->state],*lpdwStatus);
|
|
|
|
if ((This->device->state == STATE_STARTING) ||
|
|
|
|
(This->device->state == STATE_CAPTURING)) {
|
|
|
|
*lpdwStatus |= DSCBSTATUS_CAPTURING;
|
|
|
|
if (This->flags & DSCBSTART_LOOPING)
|
|
|
|
*lpdwStatus |= DSCBSTATUS_LOOPING;
|
2003-09-02 01:58:43 +02:00
|
|
|
}
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("new This->device->state=%s, new lpdwStatus=%08x\n",
|
|
|
|
captureStateString[This->device->state],*lpdwStatus);
|
|
|
|
LeaveCriticalSection(&(This->device->lock));
|
2003-09-02 01:58:43 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("status=%x\n", *lpdwStatus);
|
|
|
|
TRACE("returning DS_OK\n");
|
|
|
|
return DS_OK;
|
2003-09-02 01:58:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_Initialize(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
IDirectSoundCapture *lpDSC, const DSCBUFFERDESC *lpcDSCBDesc)
|
2003-09-02 01:58:43 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2003-09-02 01:58:43 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
FIXME( "(%p,%p,%p): stub\n", This, lpDSC, lpcDSCBDesc );
|
2003-09-02 01:58:43 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
return DS_OK;
|
2003-09-02 01:58:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_Lock(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
DWORD dwReadCusor, DWORD dwReadBytes, void **lplpvAudioPtr1, DWORD *lpdwAudioBytes1,
|
|
|
|
void **lplpvAudioPtr2, DWORD *lpdwAudioBytes2, DWORD dwFlags)
|
2003-09-02 01:58:43 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2009-12-02 12:12:37 +01:00
|
|
|
HRESULT hres = DS_OK;
|
2012-01-12 00:06:48 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE( "(%p,%08u,%08u,%p,%p,%p,%p,0x%08x) at %d\n", This, dwReadCusor,
|
|
|
|
dwReadBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2,
|
|
|
|
lpdwAudioBytes2, dwFlags, GetTickCount() );
|
2003-09-02 01:58:43 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (This->device == NULL) {
|
|
|
|
WARN("invalid parameter: This->device == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-09-02 01:58:43 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (lplpvAudioPtr1 == NULL) {
|
|
|
|
WARN("invalid parameter: lplpvAudioPtr1 == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-09-02 01:58:43 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (lpdwAudioBytes1 == NULL) {
|
|
|
|
WARN("invalid parameter: lpdwAudioBytes1 == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-09-02 01:58:43 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
EnterCriticalSection(&(This->device->lock));
|
2003-09-02 01:58:43 +02:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
if (This->device->client) {
|
2009-12-02 12:12:37 +01:00
|
|
|
*lplpvAudioPtr1 = This->device->buffer + dwReadCusor;
|
|
|
|
if ( (dwReadCusor + dwReadBytes) > This->device->buflen) {
|
|
|
|
*lpdwAudioBytes1 = This->device->buflen - dwReadCusor;
|
|
|
|
if (lplpvAudioPtr2)
|
|
|
|
*lplpvAudioPtr2 = This->device->buffer;
|
|
|
|
if (lpdwAudioBytes2)
|
|
|
|
*lpdwAudioBytes2 = dwReadBytes - *lpdwAudioBytes1;
|
|
|
|
} else {
|
|
|
|
*lpdwAudioBytes1 = dwReadBytes;
|
|
|
|
if (lplpvAudioPtr2)
|
|
|
|
*lplpvAudioPtr2 = 0;
|
|
|
|
if (lpdwAudioBytes2)
|
|
|
|
*lpdwAudioBytes2 = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TRACE("invalid call\n");
|
|
|
|
hres = DSERR_INVALIDCALL; /* DSERR_NODRIVER ? */
|
2003-09-02 01:58:43 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
LeaveCriticalSection(&(This->device->lock));
|
2003-09-02 01:58:43 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("returning %08x\n", hres);
|
|
|
|
return hres;
|
2003-09-02 01:58:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_Start(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
DWORD dwFlags)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2011-09-27 15:51:22 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE( "(%p,0x%08x)\n", This, dwFlags );
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (This->device == NULL) {
|
|
|
|
WARN("invalid parameter: This->device == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2003-08-07 00:57:24 +02:00
|
|
|
}
|
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
if ( !This->device->client ) {
|
2009-12-02 12:12:37 +01:00
|
|
|
WARN("no driver\n");
|
|
|
|
return DSERR_NODRIVER;
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
EnterCriticalSection(&(This->device->lock));
|
2003-03-04 03:12:34 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (This->device->state == STATE_STOPPED)
|
|
|
|
This->device->state = STATE_STARTING;
|
|
|
|
else if (This->device->state == STATE_STOPPING)
|
|
|
|
This->device->state = STATE_CAPTURING;
|
2012-10-16 14:06:26 +02:00
|
|
|
else
|
|
|
|
goto out;
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("new This->device->state=%s\n",captureStateString[This->device->state]);
|
2012-10-16 14:06:26 +02:00
|
|
|
This->flags = dwFlags;
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
if (This->device->buffer)
|
|
|
|
FillMemory(This->device->buffer, This->device->buflen, (This->device->pwfx->wBitsPerSample == 8) ? 128 : 0);
|
2003-03-04 03:12:34 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
hres = IAudioClient_Start(This->device->client);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
WARN("Start failed: %08x\n", hres);
|
|
|
|
LeaveCriticalSection(&This->device->lock);
|
|
|
|
return hres;
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2012-10-16 14:06:26 +02:00
|
|
|
out:
|
2011-09-27 15:51:22 +02:00
|
|
|
LeaveCriticalSection(&This->device->lock);
|
|
|
|
|
|
|
|
TRACE("returning DS_OK\n");
|
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_Stop(IDirectSoundCaptureBuffer8 *iface)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2011-09-27 15:51:22 +02:00
|
|
|
HRESULT hres;
|
2012-01-12 00:06:48 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
2003-05-22 05:39:13 +02:00
|
|
|
|
2006-01-05 13:37:15 +01:00
|
|
|
if (This->device == NULL) {
|
|
|
|
WARN("invalid parameter: This->device == NULL\n");
|
2003-02-15 01:01:17 +01:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
EnterCriticalSection(&(This->device->lock));
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("old This->device->state=%s\n",captureStateString[This->device->state]);
|
|
|
|
if (This->device->state == STATE_CAPTURING)
|
|
|
|
This->device->state = STATE_STOPPING;
|
|
|
|
else if (This->device->state == STATE_STARTING)
|
|
|
|
This->device->state = STATE_STOPPED;
|
|
|
|
TRACE("new This->device->state=%s\n",captureStateString[This->device->state]);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
if(This->device->client){
|
|
|
|
hres = IAudioClient_Stop(This->device->client);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
LeaveCriticalSection(&This->device->lock);
|
|
|
|
return hres;
|
|
|
|
}
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
2004-10-21 22:57:26 +02:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
LeaveCriticalSection(&(This->device->lock));
|
|
|
|
|
|
|
|
TRACE("returning DS_OK\n");
|
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_Unlock(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
void *lpvAudioPtr1, DWORD dwAudioBytes1, void *lpvAudioPtr2, DWORD dwAudioBytes2)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2004-11-19 18:56:56 +01:00
|
|
|
HRESULT hres = DS_OK;
|
2012-01-12 00:06:48 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE( "(%p,%p,%08u,%p,%08u)\n", This, lpvAudioPtr1, dwAudioBytes1,
|
|
|
|
lpvAudioPtr2, dwAudioBytes2 );
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (lpvAudioPtr1 == NULL) {
|
|
|
|
WARN("invalid parameter: lpvAudioPtr1 == NULL\n");
|
2003-02-15 01:01:17 +01:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
if (!This->device->client) {
|
2009-12-02 12:12:37 +01:00
|
|
|
WARN("invalid call\n");
|
|
|
|
hres = DSERR_INVALIDCALL;
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2006-11-12 14:40:35 +01:00
|
|
|
TRACE("returning %08x\n", hres);
|
2004-11-19 18:56:56 +01:00
|
|
|
return hres;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetObjectInPath(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
REFGUID rguidObject, DWORD dwIndex, REFGUID rguidInterface, void **ppObject)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2003-05-22 05:39:13 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
FIXME( "(%p,%s,%u,%s,%p): stub\n", This, debugstr_guid(rguidObject),
|
|
|
|
dwIndex, debugstr_guid(rguidInterface), ppObject );
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2012-09-17 21:06:51 +02:00
|
|
|
if (!ppObject)
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
|
|
|
|
*ppObject = NULL;
|
|
|
|
return DSERR_CONTROLUNAVAIL;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureBufferImpl_GetFXStatus(IDirectSoundCaptureBuffer8 *iface,
|
|
|
|
DWORD dwFXCount, DWORD *pdwFXStatus)
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl *This = impl_from_IDirectSoundCaptureBuffer8(iface);
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
FIXME( "(%p,%u,%p): stub\n", This, dwFXCount, pdwFXStatus );
|
2002-06-13 21:15:06 +02:00
|
|
|
|
2003-02-15 01:01:17 +01:00
|
|
|
return DS_OK;
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
static const IDirectSoundCaptureBuffer8Vtbl dscbvt =
|
2002-06-13 21:15:06 +02:00
|
|
|
{
|
2009-12-02 12:12:37 +01:00
|
|
|
/* IUnknown methods */
|
|
|
|
IDirectSoundCaptureBufferImpl_QueryInterface,
|
|
|
|
IDirectSoundCaptureBufferImpl_AddRef,
|
|
|
|
IDirectSoundCaptureBufferImpl_Release,
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
/* IDirectSoundCaptureBuffer methods */
|
|
|
|
IDirectSoundCaptureBufferImpl_GetCaps,
|
|
|
|
IDirectSoundCaptureBufferImpl_GetCurrentPosition,
|
|
|
|
IDirectSoundCaptureBufferImpl_GetFormat,
|
|
|
|
IDirectSoundCaptureBufferImpl_GetStatus,
|
|
|
|
IDirectSoundCaptureBufferImpl_Initialize,
|
|
|
|
IDirectSoundCaptureBufferImpl_Lock,
|
|
|
|
IDirectSoundCaptureBufferImpl_Start,
|
|
|
|
IDirectSoundCaptureBufferImpl_Stop,
|
|
|
|
IDirectSoundCaptureBufferImpl_Unlock,
|
2003-05-22 05:39:13 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
/* IDirectSoundCaptureBuffer methods */
|
|
|
|
IDirectSoundCaptureBufferImpl_GetObjectInPath,
|
|
|
|
IDirectSoundCaptureBufferImpl_GetFXStatus
|
|
|
|
};
|
2003-05-22 05:39:13 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
static void capture_CheckNotify(IDirectSoundCaptureBufferImpl *This, DWORD from, DWORD len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < This->nrofnotifies; ++i) {
|
|
|
|
LPDSBPOSITIONNOTIFY event = This->notifies + i;
|
|
|
|
DWORD offset = event->dwOffset;
|
|
|
|
TRACE("checking %d, position %d, event = %p\n", i, offset, event->hEventNotify);
|
2003-02-15 01:01:17 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (offset == DSBPN_OFFSETSTOP) {
|
|
|
|
if (!from && !len) {
|
|
|
|
SetEvent(event->hEventNotify);
|
|
|
|
TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else return;
|
|
|
|
}
|
2003-03-04 03:12:34 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (offset >= from && offset < (from + len))
|
|
|
|
{
|
|
|
|
TRACE("signalled event %p (%d)\n", event->hEventNotify, i);
|
|
|
|
SetEvent(event->hEventNotify);
|
2003-02-15 01:01:17 +01:00
|
|
|
}
|
|
|
|
}
|
2002-06-13 21:15:06 +02:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:47 +01:00
|
|
|
static HRESULT IDirectSoundCaptureBufferImpl_Create(
|
2006-01-05 13:37:15 +01:00
|
|
|
DirectSoundCaptureDevice *device,
|
|
|
|
IDirectSoundCaptureBufferImpl ** ppobj,
|
|
|
|
LPCDSCBUFFERDESC lpcDSCBufferDesc)
|
2006-01-04 14:49:34 +01:00
|
|
|
{
|
|
|
|
LPWAVEFORMATEX wfex;
|
2011-10-17 21:52:23 +02:00
|
|
|
IDirectSoundCaptureBufferImpl *This;
|
2006-01-05 13:37:15 +01:00
|
|
|
TRACE( "(%p,%p,%p)\n", device, ppobj, lpcDSCBufferDesc);
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2006-01-05 13:37:15 +01:00
|
|
|
if (ppobj == NULL) {
|
|
|
|
WARN("invalid parameter: ppobj == NULL\n");
|
2006-01-04 14:49:34 +01:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2011-10-17 21:52:23 +02:00
|
|
|
*ppobj = NULL;
|
|
|
|
|
2006-01-05 13:37:15 +01:00
|
|
|
if (!device) {
|
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
2006-01-04 14:49:34 +01:00
|
|
|
}
|
|
|
|
|
2006-01-05 13:37:15 +01:00
|
|
|
if (lpcDSCBufferDesc == NULL) {
|
|
|
|
WARN("invalid parameter: lpcDSCBufferDesc == NULL\n");
|
2006-01-04 14:49:34 +01:00
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ((lpcDSCBufferDesc->dwSize != sizeof(DSCBUFFERDESC)) &&
|
|
|
|
(lpcDSCBufferDesc->dwSize != sizeof(DSCBUFFERDESC1))) ||
|
|
|
|
(lpcDSCBufferDesc->dwBufferBytes == 0) ||
|
2009-10-04 14:30:50 +02:00
|
|
|
(lpcDSCBufferDesc->lpwfxFormat == NULL) ) { /* FIXME: DSERR_BADFORMAT ? */
|
2006-01-04 14:49:34 +01:00
|
|
|
WARN("invalid lpcDSCBufferDesc\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
wfex = lpcDSCBufferDesc->lpwfxFormat;
|
|
|
|
|
2009-10-04 14:30:50 +02:00
|
|
|
TRACE("(formattag=0x%04x,chans=%d,samplerate=%d,"
|
|
|
|
"bytespersec=%d,blockalign=%d,bitspersamp=%d,cbSize=%d)\n",
|
|
|
|
wfex->wFormatTag, wfex->nChannels, wfex->nSamplesPerSec,
|
|
|
|
wfex->nAvgBytesPerSec, wfex->nBlockAlign,
|
|
|
|
wfex->wBitsPerSample, wfex->cbSize);
|
|
|
|
|
2009-10-04 08:05:20 +02:00
|
|
|
device->pwfx = DSOUND_CopyFormat(wfex);
|
2011-10-17 21:52:23 +02:00
|
|
|
if ( device->pwfx == NULL )
|
2009-10-04 08:05:20 +02:00
|
|
|
return DSERR_OUTOFMEMORY;
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2011-10-17 21:52:23 +02:00
|
|
|
This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
2006-01-04 14:49:34 +01:00
|
|
|
sizeof(IDirectSoundCaptureBufferImpl));
|
|
|
|
|
2011-10-17 21:52:23 +02:00
|
|
|
if ( This == NULL ) {
|
2006-01-04 14:49:34 +01:00
|
|
|
WARN("out of memory\n");
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
} else {
|
2011-09-24 16:02:52 +02:00
|
|
|
HRESULT err = DS_OK;
|
2006-01-04 14:49:34 +01:00
|
|
|
LPBYTE newbuf;
|
|
|
|
DWORD buflen;
|
|
|
|
|
2012-01-12 00:11:20 +01:00
|
|
|
This->numIfaces = 0;
|
|
|
|
This->ref = 0;
|
2012-01-12 00:19:48 +01:00
|
|
|
This->refn = 0;
|
2006-01-05 13:37:15 +01:00
|
|
|
This->device = device;
|
|
|
|
This->device->capture_buffer = This;
|
2011-09-24 16:02:52 +02:00
|
|
|
This->nrofnotifies = 0;
|
2006-01-04 14:49:34 +01:00
|
|
|
|
|
|
|
This->pdscbd = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,
|
|
|
|
lpcDSCBufferDesc->dwSize);
|
|
|
|
if (This->pdscbd)
|
|
|
|
CopyMemory(This->pdscbd, lpcDSCBufferDesc, lpcDSCBufferDesc->dwSize);
|
|
|
|
else {
|
|
|
|
WARN("no memory\n");
|
2006-01-05 13:37:15 +01:00
|
|
|
This->device->capture_buffer = 0;
|
2006-01-04 14:49:34 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, This );
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2012-01-12 00:06:48 +01:00
|
|
|
This->IDirectSoundCaptureBuffer8_iface.lpVtbl = &dscbvt;
|
2012-01-12 00:19:48 +01:00
|
|
|
This->IDirectSoundNotify_iface.lpVtbl = &dscnvt;
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
err = IMMDevice_Activate(device->mmdevice, &IID_IAudioClient,
|
|
|
|
CLSCTX_INPROC_SERVER, NULL, (void**)&device->client);
|
|
|
|
if(FAILED(err)){
|
|
|
|
WARN("Activate failed: %08x\n", err);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->pdscbd);
|
|
|
|
This->device->capture_buffer = 0;
|
|
|
|
HeapFree( GetProcessHeap(), 0, This );
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = IAudioClient_Initialize(device->client,
|
2013-08-21 17:16:08 +02:00
|
|
|
AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_NOPERSIST | AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
|
|
|
|
200 * 100000, 0, device->pwfx, NULL);
|
2011-09-27 15:51:22 +02:00
|
|
|
if(FAILED(err)){
|
|
|
|
WARN("Initialize failed: %08x\n", err);
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->pdscbd);
|
|
|
|
This->device->capture_buffer = 0;
|
|
|
|
HeapFree( GetProcessHeap(), 0, This );
|
2012-04-26 21:14:59 +02:00
|
|
|
if(err == AUDCLNT_E_UNSUPPORTED_FORMAT)
|
|
|
|
return DSERR_BADFORMAT;
|
2011-09-27 15:51:22 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-08-21 17:16:08 +02:00
|
|
|
This->sleepev = CreateEventW(NULL, 0, 0, NULL);
|
|
|
|
|
|
|
|
err = IAudioClient_SetEventHandle(device->client, This->sleepev);
|
|
|
|
if(FAILED(err)){
|
|
|
|
WARN("SetEventHandle failed: %08x\n", err);
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
|
|
|
CloseHandle(This->sleepev);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->pdscbd);
|
|
|
|
This->device->capture_buffer = 0;
|
|
|
|
HeapFree( GetProcessHeap(), 0, This );
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
err = IAudioClient_GetService(device->client, &IID_IAudioCaptureClient,
|
|
|
|
(void**)&device->capture);
|
|
|
|
if(FAILED(err)){
|
|
|
|
WARN("GetService failed: %08x\n", err);
|
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
2013-08-21 17:16:08 +02:00
|
|
|
CloseHandle(This->sleepev);
|
2011-09-27 15:51:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->pdscbd);
|
2011-09-24 16:02:52 +02:00
|
|
|
This->device->capture_buffer = 0;
|
|
|
|
HeapFree( GetProcessHeap(), 0, This );
|
|
|
|
return err;
|
|
|
|
}
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2011-09-24 16:02:52 +02:00
|
|
|
buflen = lpcDSCBufferDesc->dwBufferBytes;
|
|
|
|
TRACE("desired buflen=%d, old buffer=%p\n", buflen, device->buffer);
|
|
|
|
if (device->buffer)
|
|
|
|
newbuf = HeapReAlloc(GetProcessHeap(),0,device->buffer,buflen);
|
|
|
|
else
|
|
|
|
newbuf = HeapAlloc(GetProcessHeap(),0,buflen);
|
|
|
|
if (newbuf == NULL) {
|
2011-09-27 15:51:22 +02:00
|
|
|
IAudioClient_Release(device->client);
|
|
|
|
device->client = NULL;
|
|
|
|
IAudioCaptureClient_Release(device->capture);
|
|
|
|
device->capture = NULL;
|
2013-08-21 17:16:08 +02:00
|
|
|
CloseHandle(This->sleepev);
|
2011-09-27 15:51:22 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->pdscbd);
|
|
|
|
This->device->capture_buffer = 0;
|
|
|
|
HeapFree( GetProcessHeap(), 0, This );
|
|
|
|
return DSERR_OUTOFMEMORY;
|
2011-09-24 16:02:52 +02:00
|
|
|
}
|
2011-09-27 15:51:22 +02:00
|
|
|
device->buffer = newbuf;
|
|
|
|
device->buflen = buflen;
|
2013-08-21 17:16:08 +02:00
|
|
|
This->thread = CreateThread(NULL, 0, DSOUND_capture_thread, This, 0, NULL);
|
2006-01-04 14:49:34 +01:00
|
|
|
}
|
|
|
|
|
2018-03-30 06:04:48 +02:00
|
|
|
IDirectSoundCaptureBuffer8_AddRef(&This->IDirectSoundCaptureBuffer8_iface);
|
2011-10-17 21:52:23 +02:00
|
|
|
*ppobj = This;
|
|
|
|
|
2006-01-04 14:49:34 +01:00
|
|
|
TRACE("returning DS_OK\n");
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2006-01-04 14:49:34 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* DirectSoundCaptureDevice
|
|
|
|
*/
|
2009-12-02 12:12:37 +01:00
|
|
|
static HRESULT DirectSoundCaptureDevice_Create(
|
|
|
|
DirectSoundCaptureDevice ** ppDevice)
|
2006-01-05 13:37:15 +01:00
|
|
|
{
|
2009-12-02 12:12:37 +01:00
|
|
|
DirectSoundCaptureDevice * device;
|
|
|
|
TRACE("(%p)\n", ppDevice);
|
2006-01-05 13:37:15 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
/* Allocate memory */
|
|
|
|
device = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DirectSoundCaptureDevice));
|
2006-01-05 13:37:15 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (device == NULL) {
|
|
|
|
WARN("out of memory\n");
|
|
|
|
return DSERR_OUTOFMEMORY;
|
2006-01-05 13:37:15 +01:00
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
device->ref = 1;
|
|
|
|
device->state = STATE_STOPPED;
|
2006-01-05 13:37:15 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
InitializeCriticalSection( &(device->lock) );
|
|
|
|
device->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": DirectSoundCaptureDevice.lock");
|
2006-01-05 13:37:15 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
*ppDevice = device;
|
2006-01-05 13:37:15 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:47 +01:00
|
|
|
static ULONG DirectSoundCaptureDevice_Release(
|
2009-12-02 12:12:37 +01:00
|
|
|
DirectSoundCaptureDevice * device)
|
|
|
|
{
|
|
|
|
ULONG ref = InterlockedDecrement(&(device->ref));
|
|
|
|
TRACE("(%p) ref was %d\n", device, ref + 1);
|
|
|
|
|
|
|
|
if (!ref) {
|
|
|
|
TRACE("deleting object\n");
|
2011-09-27 15:51:22 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&DSOUND_capturers_lock);
|
|
|
|
list_remove(&device->entry);
|
|
|
|
LeaveCriticalSection(&DSOUND_capturers_lock);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (device->capture_buffer)
|
2012-01-12 00:06:48 +01:00
|
|
|
IDirectSoundCaptureBufferImpl_Release(&device->capture_buffer->IDirectSoundCaptureBuffer8_iface);
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
if(device->mmdevice)
|
|
|
|
IMMDevice_Release(device->mmdevice);
|
2009-12-02 12:12:37 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, device->pwfx);
|
|
|
|
device->lock.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection( &(device->lock) );
|
|
|
|
HeapFree(GetProcessHeap(), 0, device);
|
|
|
|
TRACE("(%p) released\n", device);
|
|
|
|
}
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2013-08-21 17:16:08 +02:00
|
|
|
static HRESULT DSOUND_capture_data(DirectSoundCaptureDevice *device)
|
2011-09-27 15:51:22 +02:00
|
|
|
{
|
2013-08-21 17:16:08 +02:00
|
|
|
if(!device->capture_buffer || device->state == STATE_STOPPED)
|
|
|
|
return S_FALSE;
|
2011-09-27 15:51:22 +02:00
|
|
|
|
|
|
|
if(device->state == STATE_STOPPING){
|
|
|
|
device->state = STATE_STOPPED;
|
2013-08-21 17:16:08 +02:00
|
|
|
return S_FALSE;
|
2011-09-27 15:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(device->state == STATE_STARTING)
|
|
|
|
device->state = STATE_CAPTURING;
|
|
|
|
|
2016-06-15 15:44:42 +02:00
|
|
|
while(1){
|
|
|
|
HRESULT hr;
|
|
|
|
UINT32 packet_frames, packet_bytes, avail_bytes, skip_bytes = 0;
|
|
|
|
DWORD flags;
|
|
|
|
BYTE *buf;
|
|
|
|
|
|
|
|
hr = IAudioCaptureClient_GetBuffer(device->capture, &buf, &packet_frames,
|
|
|
|
&flags, NULL, NULL);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("GetBuffer failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
if(hr == AUDCLNT_S_BUFFER_EMPTY)
|
|
|
|
break;
|
2011-09-27 15:51:22 +02:00
|
|
|
|
2016-06-15 15:44:42 +02:00
|
|
|
packet_bytes = packet_frames * device->pwfx->nBlockAlign;
|
|
|
|
if(packet_bytes > device->buflen){
|
|
|
|
TRACE("audio glitch: dsound buffer too small for data\n");
|
|
|
|
skip_bytes = packet_bytes - device->buflen;
|
|
|
|
packet_bytes = device->buflen;
|
|
|
|
}
|
2011-09-27 15:51:22 +02:00
|
|
|
|
2016-06-15 15:44:42 +02:00
|
|
|
avail_bytes = device->buflen - device->write_pos_bytes;
|
|
|
|
if(avail_bytes > packet_bytes)
|
|
|
|
avail_bytes = packet_bytes;
|
|
|
|
|
|
|
|
memcpy(device->buffer + device->write_pos_bytes, buf + skip_bytes, avail_bytes);
|
|
|
|
capture_CheckNotify(device->capture_buffer, device->write_pos_bytes, avail_bytes);
|
|
|
|
|
|
|
|
packet_bytes -= avail_bytes;
|
|
|
|
if(packet_bytes > 0){
|
|
|
|
if(device->capture_buffer->flags & DSCBSTART_LOOPING){
|
|
|
|
memcpy(device->buffer, buf + skip_bytes + avail_bytes, packet_bytes);
|
|
|
|
capture_CheckNotify(device->capture_buffer, 0, packet_bytes);
|
|
|
|
}else{
|
|
|
|
device->state = STATE_STOPPED;
|
|
|
|
capture_CheckNotify(device->capture_buffer, 0, 0);
|
|
|
|
}
|
2011-09-27 15:51:22 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 15:44:42 +02:00
|
|
|
device->write_pos_bytes += avail_bytes + packet_bytes;
|
|
|
|
device->write_pos_bytes %= device->buflen;
|
2011-09-27 15:51:22 +02:00
|
|
|
|
2016-06-15 15:44:42 +02:00
|
|
|
hr = IAudioCaptureClient_ReleaseBuffer(device->capture, packet_frames);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("ReleaseBuffer failed: %08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2011-09-27 15:51:22 +02:00
|
|
|
}
|
|
|
|
|
2013-08-21 17:16:08 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI DSOUND_capture_thread(void *user)
|
|
|
|
{
|
|
|
|
IDirectSoundCaptureBufferImpl *buffer = user;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD ret, wait_ms;
|
|
|
|
REFERENCE_TIME period;
|
|
|
|
|
|
|
|
hr = IAudioClient_GetDevicePeriod(buffer->device->client, &period, NULL);
|
|
|
|
if(FAILED(hr)){
|
|
|
|
WARN("GetDevicePeriod failed: %08x\n", hr);
|
|
|
|
wait_ms = 5;
|
|
|
|
}else
|
|
|
|
wait_ms = MulDiv(5, period, 10000);
|
|
|
|
|
|
|
|
while(buffer->ref){
|
|
|
|
ret = WaitForSingleObject(buffer->sleepev, wait_ms);
|
|
|
|
|
|
|
|
if(!buffer->device->ref)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(ret == WAIT_OBJECT_0){
|
|
|
|
EnterCriticalSection(&buffer->device->lock);
|
|
|
|
|
|
|
|
DSOUND_capture_data(buffer->device);
|
|
|
|
|
|
|
|
LeaveCriticalSection(&buffer->device->lock);
|
|
|
|
}else if(ret != WAIT_TIMEOUT)
|
|
|
|
WARN("WaitForSingleObject failed: %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2011-09-27 15:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct _TestFormat {
|
|
|
|
DWORD flag;
|
|
|
|
DWORD rate;
|
|
|
|
DWORD depth;
|
|
|
|
WORD channels;
|
|
|
|
} formats_to_test[] = {
|
|
|
|
{ WAVE_FORMAT_1M08, 11025, 8, 1 },
|
|
|
|
{ WAVE_FORMAT_1M16, 11025, 16, 1 },
|
|
|
|
{ WAVE_FORMAT_1S08, 11025, 8, 2 },
|
|
|
|
{ WAVE_FORMAT_1S16, 11025, 16, 2 },
|
|
|
|
{ WAVE_FORMAT_2M08, 22050, 8, 1 },
|
|
|
|
{ WAVE_FORMAT_2M16, 22050, 16, 1 },
|
|
|
|
{ WAVE_FORMAT_2S08, 22050, 8, 2 },
|
|
|
|
{ WAVE_FORMAT_2S16, 22050, 16, 2 },
|
|
|
|
{ WAVE_FORMAT_4M08, 44100, 8, 1 },
|
|
|
|
{ WAVE_FORMAT_4M16, 44100, 16, 1 },
|
|
|
|
{ WAVE_FORMAT_4S08, 44100, 8, 2 },
|
|
|
|
{ WAVE_FORMAT_4S16, 44100, 16, 2 },
|
|
|
|
{ WAVE_FORMAT_48M08, 48000, 8, 1 },
|
|
|
|
{ WAVE_FORMAT_48M16, 48000, 16, 1 },
|
|
|
|
{ WAVE_FORMAT_48S08, 48000, 8, 2 },
|
|
|
|
{ WAVE_FORMAT_48S16, 48000, 16, 2 },
|
|
|
|
{ WAVE_FORMAT_96M08, 96000, 8, 1 },
|
|
|
|
{ WAVE_FORMAT_96M16, 96000, 16, 1 },
|
|
|
|
{ WAVE_FORMAT_96S08, 96000, 8, 2 },
|
|
|
|
{ WAVE_FORMAT_96S16, 96000, 16, 2 },
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2009-12-02 12:12:47 +01:00
|
|
|
static HRESULT DirectSoundCaptureDevice_Initialize(
|
2009-12-02 12:12:37 +01:00
|
|
|
DirectSoundCaptureDevice ** ppDevice,
|
|
|
|
LPCGUID lpcGUID)
|
|
|
|
{
|
2011-09-27 15:51:22 +02:00
|
|
|
HRESULT hr;
|
2009-12-02 12:12:37 +01:00
|
|
|
GUID devGUID;
|
2011-09-27 15:51:22 +02:00
|
|
|
IMMDevice *mmdevice;
|
|
|
|
struct _TestFormat *fmt;
|
|
|
|
DirectSoundCaptureDevice *device;
|
|
|
|
IAudioClient *client;
|
2011-09-24 16:02:52 +02:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("(%p, %s)\n", ppDevice, debugstr_guid(lpcGUID));
|
|
|
|
|
|
|
|
/* Default device? */
|
|
|
|
if ( !lpcGUID || IsEqualGUID(lpcGUID, &GUID_NULL) )
|
2011-09-27 15:51:22 +02:00
|
|
|
lpcGUID = &DSDEVID_DefaultCapture;
|
|
|
|
|
|
|
|
if(IsEqualGUID(lpcGUID, &DSDEVID_DefaultPlayback) ||
|
|
|
|
IsEqualGUID(lpcGUID, &DSDEVID_DefaultVoicePlayback))
|
|
|
|
return DSERR_NODRIVER;
|
2009-12-02 12:12:37 +01:00
|
|
|
|
|
|
|
if (GetDeviceID(lpcGUID, &devGUID) != DS_OK) {
|
|
|
|
WARN("invalid parameter: lpcGUID\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
hr = get_mmdevice(eCapture, &devGUID, &mmdevice);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
EnterCriticalSection(&DSOUND_capturers_lock);
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
hr = DirectSoundCaptureDevice_Create(&device);
|
|
|
|
if (hr != DS_OK) {
|
2006-01-05 13:37:15 +01:00
|
|
|
WARN("DirectSoundCaptureDevice_Create failed\n");
|
2011-09-27 15:51:22 +02:00
|
|
|
LeaveCriticalSection(&DSOUND_capturers_lock);
|
|
|
|
return hr;
|
2006-01-05 13:37:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
device->guid = devGUID;
|
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
device->mmdevice = mmdevice;
|
|
|
|
|
|
|
|
device->drvcaps.dwFlags = 0;
|
2006-01-05 13:37:15 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
device->drvcaps.dwFormats = 0;
|
|
|
|
device->drvcaps.dwChannels = 0;
|
|
|
|
hr = IMMDevice_Activate(mmdevice, &IID_IAudioClient,
|
|
|
|
CLSCTX_INPROC_SERVER, NULL, (void**)&client);
|
|
|
|
if(FAILED(hr)){
|
2011-11-14 11:32:27 +01:00
|
|
|
device->lock.DebugInfo->Spare[0] = 0;
|
2011-09-27 15:51:22 +02:00
|
|
|
DeleteCriticalSection(&device->lock);
|
|
|
|
HeapFree(GetProcessHeap(), 0, device);
|
2011-10-16 13:09:44 +02:00
|
|
|
LeaveCriticalSection(&DSOUND_capturers_lock);
|
2011-09-27 15:51:22 +02:00
|
|
|
return DSERR_NODRIVER;
|
|
|
|
}
|
2011-09-24 16:02:52 +02:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
for(fmt = formats_to_test; fmt->flag; ++fmt){
|
|
|
|
if(DSOUND_check_supported(client, fmt->rate, fmt->depth, fmt->channels)){
|
|
|
|
device->drvcaps.dwFormats |= fmt->flag;
|
|
|
|
if(fmt->channels > device->drvcaps.dwChannels)
|
|
|
|
device->drvcaps.dwChannels = fmt->channels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
IAudioClient_Release(client);
|
2006-01-05 13:37:15 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
list_add_tail(&DSOUND_capturers, &device->entry);
|
2006-01-05 13:37:15 +01:00
|
|
|
|
2011-09-27 15:51:22 +02:00
|
|
|
*ppDevice = device;
|
|
|
|
|
|
|
|
LeaveCriticalSection(&DSOUND_capturers_lock);
|
|
|
|
|
|
|
|
return S_OK;
|
2006-01-05 13:37:15 +01:00
|
|
|
}
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* IDirectSoundCapture implementation structure
|
|
|
|
*/
|
2012-08-16 01:21:26 +02:00
|
|
|
typedef struct IDirectSoundCaptureImpl
|
2006-01-04 14:49:34 +01:00
|
|
|
{
|
2012-08-16 01:49:10 +02:00
|
|
|
IUnknown IUnknown_inner;
|
2011-10-07 13:28:54 +02:00
|
|
|
IDirectSoundCapture IDirectSoundCapture_iface;
|
2012-08-16 01:21:26 +02:00
|
|
|
LONG ref, refdsc, numIfaces;
|
2012-08-16 01:49:10 +02:00
|
|
|
IUnknown *outer_unk; /* internal */
|
2011-10-07 13:28:54 +02:00
|
|
|
DirectSoundCaptureDevice *device;
|
2012-08-16 01:20:01 +02:00
|
|
|
BOOL has_dsc8;
|
2012-08-16 01:21:26 +02:00
|
|
|
} IDirectSoundCaptureImpl;
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
static void capture_destroy(IDirectSoundCaptureImpl *This)
|
2011-10-07 13:28:54 +02:00
|
|
|
{
|
2012-08-16 01:21:26 +02:00
|
|
|
if (This->device)
|
|
|
|
DirectSoundCaptureDevice_Release(This->device);
|
|
|
|
HeapFree(GetProcessHeap(),0,This);
|
|
|
|
TRACE("(%p) released\n", This);
|
2011-10-07 13:28:54 +02:00
|
|
|
}
|
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* IUnknown Implementation for DirectSoundCapture
|
2009-12-02 12:12:37 +01:00
|
|
|
*/
|
2012-08-16 01:21:26 +02:00
|
|
|
static inline IDirectSoundCaptureImpl *impl_from_IUnknown(IUnknown *iface)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2012-08-16 01:49:10 +02:00
|
|
|
return CONTAINING_RECORD(iface, IDirectSoundCaptureImpl, IUnknown_inner);
|
2012-08-16 01:21:26 +02:00
|
|
|
}
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
static HRESULT WINAPI IUnknownImpl_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IUnknown(iface);
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv);
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
if (!ppv) {
|
|
|
|
WARN("invalid parameter\n");
|
|
|
|
return E_INVALIDARG;
|
2009-12-02 12:12:37 +01:00
|
|
|
}
|
2012-08-16 01:21:26 +02:00
|
|
|
*ppv = NULL;
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
if (IsEqualIID(riid, &IID_IUnknown))
|
2012-08-16 01:49:10 +02:00
|
|
|
*ppv = &This->IUnknown_inner;
|
2012-08-16 01:21:26 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IDirectSoundCapture))
|
|
|
|
*ppv = &This->IDirectSoundCapture_iface;
|
|
|
|
else {
|
|
|
|
WARN("unknown IID %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IUnknownImpl_AddRef(IUnknown *iface)
|
|
|
|
{
|
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IUnknown(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(ref == 1)
|
|
|
|
InterlockedIncrement(&This->numIfaces);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IUnknownImpl_Release(IUnknown *iface)
|
|
|
|
{
|
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IUnknown(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if (!ref && !InterlockedDecrement(&This->numIfaces))
|
|
|
|
capture_destroy(This);
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl unk_vtbl =
|
|
|
|
{
|
|
|
|
IUnknownImpl_QueryInterface,
|
|
|
|
IUnknownImpl_AddRef,
|
|
|
|
IUnknownImpl_Release
|
|
|
|
};
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* IDirectSoundCaptureImpl
|
|
|
|
*/
|
|
|
|
static inline struct IDirectSoundCaptureImpl *impl_from_IDirectSoundCapture(IDirectSoundCapture *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct IDirectSoundCaptureImpl, IDirectSoundCapture_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI IDirectSoundCaptureImpl_QueryInterface(IDirectSoundCapture *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IDirectSoundCapture(iface);
|
|
|
|
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(riid), ppv);
|
2012-08-16 01:49:10 +02:00
|
|
|
return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
|
2009-12-02 12:12:37 +01:00
|
|
|
}
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2011-10-07 13:28:54 +02:00
|
|
|
static ULONG WINAPI IDirectSoundCaptureImpl_AddRef(IDirectSoundCapture *iface)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2011-10-07 13:28:54 +02:00
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IDirectSoundCapture(iface);
|
2012-08-16 01:21:26 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->refdsc);
|
2011-10-07 13:28:54 +02:00
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(ref == 1)
|
|
|
|
InterlockedIncrement(&This->numIfaces);
|
2009-12-02 12:12:37 +01:00
|
|
|
return ref;
|
2006-01-04 14:49:34 +01:00
|
|
|
}
|
|
|
|
|
2011-10-07 13:28:54 +02:00
|
|
|
static ULONG WINAPI IDirectSoundCaptureImpl_Release(IDirectSoundCapture *iface)
|
2006-01-04 14:49:34 +01:00
|
|
|
{
|
2011-10-07 13:28:54 +02:00
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IDirectSoundCapture(iface);
|
2012-08-16 01:21:26 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->refdsc);
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2012-08-16 01:21:26 +02:00
|
|
|
if (!ref && !InterlockedDecrement(&This->numIfaces))
|
|
|
|
capture_destroy(This);
|
2009-12-02 12:12:37 +01:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2011-10-07 13:28:54 +02:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureImpl_CreateCaptureBuffer(IDirectSoundCapture *iface,
|
|
|
|
LPCDSCBUFFERDESC lpcDSCBufferDesc, IDirectSoundCaptureBuffer **lplpDSCaptureBuffer,
|
|
|
|
IUnknown *pUnk)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2011-10-07 13:28:54 +02:00
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IDirectSoundCapture(iface);
|
2009-12-02 12:12:37 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE( "(%p,%p,%p,%p)\n",iface,lpcDSCBufferDesc,lplpDSCaptureBuffer,pUnk);
|
|
|
|
|
2012-01-12 00:28:21 +01:00
|
|
|
if (pUnk) {
|
|
|
|
WARN("invalid parameter: pUnk != NULL\n");
|
|
|
|
return DSERR_NOAGGREGATION;
|
|
|
|
}
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
if (lpcDSCBufferDesc == NULL) {
|
|
|
|
WARN("invalid parameter: lpcDSCBufferDesc == NULL)\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lplpDSCaptureBuffer == NULL) {
|
|
|
|
WARN("invalid parameter: lplpDSCaptureBuffer == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: We can only have one buffer so what do we do here? */
|
|
|
|
if (This->device->capture_buffer) {
|
2010-01-12 11:28:33 +01:00
|
|
|
WARN("invalid parameter: already has buffer\n");
|
2009-12-02 12:12:37 +01:00
|
|
|
return DSERR_INVALIDPARAM; /* DSERR_GENERIC ? */
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDirectSoundCaptureBufferImpl_Create(This->device,
|
|
|
|
(IDirectSoundCaptureBufferImpl **)lplpDSCaptureBuffer, lpcDSCBufferDesc);
|
|
|
|
|
|
|
|
if (hr != DS_OK)
|
|
|
|
WARN("IDirectSoundCaptureBufferImpl_Create failed\n");
|
2016-05-16 16:55:43 +02:00
|
|
|
else
|
|
|
|
This->device->capture_buffer->has_dsc8 = This->has_dsc8;
|
2009-12-02 12:12:37 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-10-07 13:28:54 +02:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureImpl_GetCaps(IDirectSoundCapture *iface,
|
|
|
|
LPDSCCAPS lpDSCCaps)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2011-10-07 13:28:54 +02:00
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IDirectSoundCapture(iface);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("(%p,%p)\n",This,lpDSCCaps);
|
|
|
|
|
|
|
|
if (This->device == NULL) {
|
|
|
|
WARN("not initialized\n");
|
|
|
|
return DSERR_UNINITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpDSCCaps== NULL) {
|
|
|
|
WARN("invalid parameter: lpDSCCaps== NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpDSCCaps->dwSize < sizeof(*lpDSCCaps)) {
|
|
|
|
WARN("invalid parameter: lpDSCCaps->dwSize = %d\n", lpDSCCaps->dwSize);
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpDSCCaps->dwFlags = This->device->drvcaps.dwFlags;
|
|
|
|
lpDSCCaps->dwFormats = This->device->drvcaps.dwFormats;
|
|
|
|
lpDSCCaps->dwChannels = This->device->drvcaps.dwChannels;
|
|
|
|
|
|
|
|
TRACE("(flags=0x%08x,format=0x%08x,channels=%d)\n",lpDSCCaps->dwFlags,
|
|
|
|
lpDSCCaps->dwFormats, lpDSCCaps->dwChannels);
|
|
|
|
|
|
|
|
return DS_OK;
|
|
|
|
}
|
|
|
|
|
2011-10-07 13:28:54 +02:00
|
|
|
static HRESULT WINAPI IDirectSoundCaptureImpl_Initialize(IDirectSoundCapture *iface,
|
|
|
|
LPCGUID lpcGUID)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2011-10-07 13:28:54 +02:00
|
|
|
IDirectSoundCaptureImpl *This = impl_from_IDirectSoundCapture(iface);
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("(%p,%s)\n", This, debugstr_guid(lpcGUID));
|
|
|
|
|
|
|
|
if (This->device != NULL) {
|
|
|
|
WARN("already initialized\n");
|
|
|
|
return DSERR_ALREADYINITIALIZED;
|
|
|
|
}
|
|
|
|
return DirectSoundCaptureDevice_Initialize(&This->device, lpcGUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IDirectSoundCaptureVtbl dscvt =
|
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
IDirectSoundCaptureImpl_QueryInterface,
|
|
|
|
IDirectSoundCaptureImpl_AddRef,
|
|
|
|
IDirectSoundCaptureImpl_Release,
|
|
|
|
|
|
|
|
/* IDirectSoundCapture methods */
|
|
|
|
IDirectSoundCaptureImpl_CreateCaptureBuffer,
|
|
|
|
IDirectSoundCaptureImpl_GetCaps,
|
|
|
|
IDirectSoundCaptureImpl_Initialize
|
|
|
|
};
|
|
|
|
|
2012-08-16 01:49:10 +02:00
|
|
|
HRESULT IDirectSoundCaptureImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_dsc8)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2012-08-16 01:20:01 +02:00
|
|
|
IDirectSoundCaptureImpl *obj;
|
|
|
|
HRESULT hr;
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2012-08-16 01:20:01 +02:00
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
obj = HeapAlloc(GetProcessHeap(), 0, sizeof(*obj));
|
|
|
|
if (obj == NULL) {
|
2009-12-02 12:12:37 +01:00
|
|
|
WARN("out of memory\n");
|
|
|
|
return DSERR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_dsound_options();
|
|
|
|
|
2012-08-16 01:49:10 +02:00
|
|
|
obj->IUnknown_inner.lpVtbl = &unk_vtbl;
|
2012-08-16 01:20:01 +02:00
|
|
|
obj->IDirectSoundCapture_iface.lpVtbl = &dscvt;
|
|
|
|
obj->ref = 1;
|
2012-08-16 01:21:26 +02:00
|
|
|
obj->refdsc = 0;
|
|
|
|
obj->numIfaces = 1;
|
2012-08-16 01:20:01 +02:00
|
|
|
obj->device = NULL;
|
|
|
|
obj->has_dsc8 = has_dsc8;
|
|
|
|
|
2012-08-16 01:49:10 +02:00
|
|
|
/* COM aggregation supported only internally */
|
|
|
|
if (outer_unk)
|
|
|
|
obj->outer_unk = outer_unk;
|
|
|
|
else
|
|
|
|
obj->outer_unk = &obj->IUnknown_inner;
|
|
|
|
|
|
|
|
hr = IUnknown_QueryInterface(&obj->IUnknown_inner, riid, ppv);
|
|
|
|
IUnknown_Release(&obj->IUnknown_inner);
|
2009-12-02 12:12:37 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-08-16 01:20:01 +02:00
|
|
|
HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppv)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
2012-08-16 01:49:10 +02:00
|
|
|
return IDirectSoundCaptureImpl_Create(NULL, riid, ppv, FALSE);
|
2012-08-16 01:20:01 +02:00
|
|
|
}
|
2009-12-02 12:12:37 +01:00
|
|
|
|
2012-08-16 01:20:01 +02:00
|
|
|
HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppv)
|
|
|
|
{
|
2012-08-16 01:49:10 +02:00
|
|
|
return IDirectSoundCaptureImpl_Create(NULL, riid, ppv, TRUE);
|
2009-12-02 12:12:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* DirectSoundCaptureCreate [DSOUND.6]
|
|
|
|
*
|
|
|
|
* Create and initialize a DirectSoundCapture interface.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpcGUID [I] Address of the GUID that identifies the sound capture device.
|
|
|
|
* lplpDSC [O] Address of a variable to receive the interface pointer.
|
|
|
|
* pUnkOuter [I] Must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: DS_OK
|
|
|
|
* Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
|
|
|
|
* DSERR_OUTOFMEMORY
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
|
|
|
|
* or NULL for the default device or DSDEVID_DefaultCapture or
|
|
|
|
* DSDEVID_DefaultVoiceCapture.
|
|
|
|
*
|
|
|
|
* DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
|
|
|
|
*/
|
2011-10-07 13:28:54 +02:00
|
|
|
HRESULT WINAPI DirectSoundCaptureCreate(LPCGUID lpcGUID, IDirectSoundCapture **ppDSC,
|
|
|
|
IUnknown *pUnkOuter)
|
2009-12-02 12:12:37 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2011-10-07 13:28:54 +02:00
|
|
|
IDirectSoundCapture *pDSC;
|
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), ppDSC, pUnkOuter);
|
|
|
|
|
|
|
|
if (ppDSC == NULL) {
|
|
|
|
WARN("invalid parameter: ppDSC == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pUnkOuter) {
|
|
|
|
WARN("invalid parameter: pUnkOuter != NULL\n");
|
|
|
|
return DSERR_NOAGGREGATION;
|
|
|
|
}
|
|
|
|
|
2012-08-16 01:20:01 +02:00
|
|
|
hr = DSOUND_CaptureCreate(&IID_IDirectSoundCapture, (void**)&pDSC);
|
2009-12-02 12:12:37 +01:00
|
|
|
if (hr == DS_OK) {
|
|
|
|
hr = IDirectSoundCapture_Initialize(pDSC, lpcGUID);
|
|
|
|
if (hr != DS_OK) {
|
|
|
|
IDirectSoundCapture_Release(pDSC);
|
|
|
|
pDSC = 0;
|
2006-01-04 14:49:34 +01:00
|
|
|
}
|
2009-12-02 12:12:37 +01:00
|
|
|
}
|
2006-01-04 14:49:34 +01:00
|
|
|
|
2009-12-02 12:12:37 +01:00
|
|
|
*ppDSC = pDSC;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* DirectSoundCaptureCreate8 [DSOUND.12]
|
|
|
|
*
|
|
|
|
* Create and initialize a DirectSoundCapture interface.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpcGUID [I] Address of the GUID that identifies the sound capture device.
|
|
|
|
* lplpDSC [O] Address of a variable to receive the interface pointer.
|
|
|
|
* pUnkOuter [I] Must be NULL.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: DS_OK
|
|
|
|
* Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
|
|
|
|
* DSERR_OUTOFMEMORY
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* lpcGUID must be one of the values returned from DirectSoundCaptureEnumerate
|
|
|
|
* or NULL for the default device or DSDEVID_DefaultCapture or
|
|
|
|
* DSDEVID_DefaultVoiceCapture.
|
|
|
|
*
|
|
|
|
* DSERR_ALLOCATED is returned for sound devices that do not support full duplex.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DirectSoundCaptureCreate8(
|
|
|
|
LPCGUID lpcGUID,
|
|
|
|
LPDIRECTSOUNDCAPTURE8 *ppDSC8,
|
|
|
|
LPUNKNOWN pUnkOuter)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTSOUNDCAPTURE8 pDSC8;
|
|
|
|
TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), ppDSC8, pUnkOuter);
|
|
|
|
|
|
|
|
if (ppDSC8 == NULL) {
|
|
|
|
WARN("invalid parameter: ppDSC8 == NULL\n");
|
|
|
|
return DSERR_INVALIDPARAM;
|
2006-01-04 14:49:34 +01:00
|
|
|
}
|
2009-12-02 12:12:37 +01:00
|
|
|
|
|
|
|
if (pUnkOuter) {
|
|
|
|
WARN("invalid parameter: pUnkOuter != NULL\n");
|
|
|
|
*ppDSC8 = NULL;
|
|
|
|
return DSERR_NOAGGREGATION;
|
|
|
|
}
|
|
|
|
|
2012-08-16 01:20:01 +02:00
|
|
|
hr = DSOUND_CaptureCreate8(&IID_IDirectSoundCapture8, (void**)&pDSC8);
|
2009-12-02 12:12:37 +01:00
|
|
|
if (hr == DS_OK) {
|
|
|
|
hr = IDirectSoundCapture_Initialize(pDSC8, lpcGUID);
|
|
|
|
if (hr != DS_OK) {
|
|
|
|
IDirectSoundCapture_Release(pDSC8);
|
|
|
|
pDSC8 = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppDSC8 = pDSC8;
|
|
|
|
|
|
|
|
return hr;
|
2006-01-04 14:49:34 +01:00
|
|
|
}
|