Commit 935e3df3 authored by Ove Kaaven's avatar Ove Kaaven Committed by Alexandre Julliard

Support DirectSound 8 interfaces. Split interface implementations into

separate files. Split primary buffer and secondary buffer interfaces into separate implementations. Made the primary buffer state part of the dsound object, so primary buffer objects can be created and refcounted independently. Made the interfaces follow COM aggregation rules more closely. Converted the dsound critical section to a R/W lock to improve potential remixing concurrency. Fixed various bugs and refcounting issues.
parent 8e4eb3ab
......@@ -10,7 +10,13 @@ LDDLLFLAGS = @LDDLLFLAGS@
SYMBOLFILE = $(MODULE).tmp.o
C_SRCS = \
dsound_main.c
buffer.c \
capture.c \
dsound_main.c \
mixer.c \
primary.c \
propset.c \
sound3d.c
@MAKE_DLL_RULES@
......
name dsound
0 stub DirectSoundUnknown
1 stdcall DirectSoundCreate(ptr ptr ptr) DirectSoundCreate
1 stdcall DirectSoundCreate(ptr ptr ptr) DirectSoundCreate8
2 stdcall DirectSoundEnumerateA(ptr ptr) DirectSoundEnumerateA
3 stdcall DirectSoundEnumerateW(ptr ptr) DirectSoundEnumerateW
4 stdcall DllCanUnloadNow() DSOUND_DllCanUnloadNow
5 stdcall DllGetClassObject(ptr ptr ptr) DSOUND_DllGetClassObject
6 stdcall DirectSoundCaptureCreate(ptr ptr ptr) DirectSoundCaptureCreate
6 stdcall DirectSoundCaptureCreate(ptr ptr ptr) DirectSoundCaptureCreate8
7 stdcall DirectSoundCaptureEnumerateA(ptr ptr) DirectSoundCaptureEnumerateA
8 stdcall DirectSoundCaptureEnumerateW(ptr ptr) DirectSoundCaptureEnumerateW
9 stub GetDeviceID
10 stub DirectSoundFullDuplexCreate
11 stdcall DirectSoundCreate8(ptr ptr ptr) DirectSoundCreate8
12 stdcall DirectSoundCaptureCreate8(ptr ptr ptr) DirectSoundCaptureCreate8
This source diff could not be displayed because it is too large. You can view the blob instead.
/* DirectSound
*
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Linux does not support better timing than 10ms */
#define DS_TIME_RES 10 /* Resolution of multimedia timer */
#define DS_TIME_DEL 10 /* Delay of multimedia timer callback, and duration of HEL fragment */
#define DS_HEL_FRAGS 48 /* HEL only: number of waveOut fragments in primary buffer
* (changing this won't help you) */
extern int ds_emuldriver;
extern int ds_hel_margin;
extern int ds_hel_queue;
extern int ds_snd_queue_max;
extern int ds_snd_queue_min;
/*****************************************************************************
* Predeclare the interface implementation structures
*/
typedef struct IDirectSoundImpl IDirectSoundImpl;
typedef struct IDirectSoundBufferImpl IDirectSoundBufferImpl;
typedef struct IDirectSoundNotifyImpl IDirectSoundNotifyImpl;
typedef struct IDirectSound3DListenerImpl IDirectSound3DListenerImpl;
typedef struct IDirectSound3DBufferImpl IDirectSound3DBufferImpl;
typedef struct IKsPropertySetImpl IKsPropertySetImpl;
typedef struct PrimaryBufferImpl PrimaryBufferImpl;
/*****************************************************************************
* IDirectSound implementation structure
*/
struct IDirectSoundImpl
{
/* IUnknown fields */
ICOM_VFIELD(IDirectSound8);
DWORD ref;
/* IDirectSoundImpl fields */
PIDSDRIVER driver;
DSDRIVERDESC drvdesc;
DSDRIVERCAPS drvcaps;
DWORD priolevel;
WAVEFORMATEX wfx; /* current main waveformat */
HWAVEOUT hwo;
LPWAVEHDR pwave[DS_HEL_FRAGS];
UINT timerID, pwplay, pwwrite, pwqueue, prebuf, precount;
DWORD fraglen;
PIDSDRIVERBUFFER hwbuf;
LPBYTE buffer;
DWORD writelead, buflen, state, playpos, mixpos;
BOOL need_remix;
int nrofbuffers;
IDirectSoundBufferImpl** buffers;
IDirectSound3DListenerImpl* listener;
RTL_RWLOCK lock;
CRITICAL_SECTION mixlock;
DSVOLUMEPAN volpan;
};
/*****************************************************************************
* IDirectSoundBuffer implementation structure
*/
struct IDirectSoundBufferImpl
{
/* FIXME: document */
/* IUnknown fields */
ICOM_VFIELD(IDirectSoundBuffer8);
DWORD ref;
/* IDirectSoundBufferImpl fields */
IDirectSoundImpl* dsound;
IDirectSoundBufferImpl* parent; /* for duplicates */
IDirectSound3DBufferImpl* ds3db;
IKsPropertySetImpl* iks;
CRITICAL_SECTION lock;
PIDSDRIVERBUFFER hwbuf;
WAVEFORMATEX wfx;
LPBYTE buffer;
DWORD playflags,state,leadin;
DWORD playpos,startpos,writelead,buflen;
DWORD nAvgBytesPerSec;
DWORD freq;
DSVOLUMEPAN volpan, cvolpan;
DSBUFFERDESC dsbd;
/* used for frequency conversion (PerfectPitch) */
ULONG freqAdjust, freqAcc;
/* used for intelligent (well, sort of) prebuffering */
DWORD probably_valid_to, last_playpos;
DWORD primary_mixpos, buf_mixpos;
BOOL need_remix;
/* IDirectSoundNotifyImpl fields */
LPDSBPOSITIONNOTIFY notifies;
int nrofnotifies;
};
HRESULT WINAPI SecondaryBuffer_Create(
IDirectSoundImpl *This,
IDirectSoundBufferImpl **pdsb,
LPDSBUFFERDESC dsbd);
struct PrimaryBufferImpl {
ICOM_VFIELD(IDirectSoundBuffer8);
DWORD ref;
IDirectSoundImpl* dsound;
DSBUFFERDESC dsbd;
};
HRESULT WINAPI PrimaryBuffer_Create(
IDirectSoundImpl *This,
PrimaryBufferImpl **pdsb,
LPDSBUFFERDESC dsbd);
/*****************************************************************************
* IDirectSoundNotify implementation structure
*/
struct IDirectSoundNotifyImpl
{
/* IUnknown fields */
ICOM_VFIELD(IDirectSoundNotify);
DWORD ref;
/* IDirectSoundNotifyImpl fields */
IDirectSoundBufferImpl* dsb;
};
/*****************************************************************************
* IDirectSound3DListener implementation structure
*/
struct IDirectSound3DListenerImpl
{
/* IUnknown fields */
ICOM_VFIELD(IDirectSound3DListener);
DWORD ref;
/* IDirectSound3DListenerImpl fields */
PrimaryBufferImpl* dsb;
DS3DLISTENER ds3dl;
CRITICAL_SECTION lock;
BOOL need_recalc;
};
HRESULT WINAPI IDirectSound3DListenerImpl_Create(
PrimaryBufferImpl *This,
IDirectSound3DListenerImpl **pdsl);
/*****************************************************************************
* IKsPropertySet implementation structure
*/
struct IKsPropertySetImpl
{
/* IUnknown fields */
ICOM_VFIELD(IKsPropertySet);
DWORD ref;
/* IKsPropertySetImpl fields */
IDirectSoundBufferImpl* dsb;
};
HRESULT WINAPI IKsPropertySetImpl_Create(
IDirectSoundBufferImpl *This,
IKsPropertySetImpl **piks);
/*****************************************************************************
* IDirectSound3DBuffer implementation structure
*/
struct IDirectSound3DBufferImpl
{
/* IUnknown fields */
ICOM_VFIELD(IDirectSound3DBuffer);
DWORD ref;
/* IDirectSound3DBufferImpl fields */
IDirectSoundBufferImpl* dsb;
DS3DBUFFER ds3db;
LONG lVolume;
CRITICAL_SECTION lock;
BOOL need_recalc;
};
HRESULT WINAPI IDirectSound3DBufferImpl_Create(
IDirectSoundBufferImpl *This,
IDirectSound3DBufferImpl **pds3db);
void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan);
void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb);
/* primary.c */
HRESULT DSOUND_PrimaryCreate(IDirectSoundImpl *This);
HRESULT DSOUND_PrimaryDestroy(IDirectSoundImpl *This);
HRESULT DSOUND_PrimaryPlay(IDirectSoundImpl *This);
HRESULT DSOUND_PrimaryStop(IDirectSoundImpl *This);
HRESULT DSOUND_PrimaryGetPosition(IDirectSoundImpl *This, LPDWORD playpos, LPDWORD writepos);
/* buffer.c */
DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
DWORD state, DWORD pplay, DWORD pwrite, DWORD pmix, DWORD bmix);
/* mixer.c */
void DSOUND_CheckEvent(IDirectSoundBufferImpl *dsb, int len);
void DSOUND_ForceRemix(IDirectSoundBufferImpl *dsb);
void DSOUND_MixCancelAt(IDirectSoundBufferImpl *dsb, DWORD buf_writepos);
void DSOUND_WaveQueue(IDirectSoundImpl *dsound, DWORD mixq);
void DSOUND_PerformMix(void);
void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
void CALLBACK DSOUND_callback(HWAVEOUT hwo, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
#define STATE_STOPPED 0
#define STATE_STARTING 1
#define STATE_PLAYING 2
#define STATE_STOPPING 3
#define DSOUND_FREQSHIFT (14)
extern IDirectSoundImpl* dsound;
struct PrimaryBuffer {
DWORD ref;
PIDSDRIVERBUFFER hwbuf;
DWORD state;
};
/* DirectSound
*
* Copyright 1998 Marcus Meissner
* Copyright 1998 Rob Riggs
* Copyright 2000-2002 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> /* Insomnia - pow() function */
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winerror.h"
#include "mmsystem.h"
#include "ntddk.h"
#include "mmddk.h"
#include "wine/windef16.h"
#include "wine/debug.h"
#include "dsound.h"
#include "dsdriver.h"
#include "dsound_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(dsound);
/*******************************************************************************
* IKsPropertySet
*/
/* IUnknown methods */
static HRESULT WINAPI IKsPropertySetImpl_QueryInterface(
LPKSPROPERTYSET iface, REFIID riid, LPVOID *ppobj
) {
ICOM_THIS(IKsPropertySetImpl,iface);
TRACE("(%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
return IDirectSoundBuffer_QueryInterface((LPDIRECTSOUNDBUFFER8)This->dsb, riid, ppobj);
}
static ULONG WINAPI IKsPropertySetImpl_AddRef(LPKSPROPERTYSET iface) {
ICOM_THIS(IKsPropertySetImpl,iface);
ULONG ulReturn;
ulReturn = InterlockedIncrement(&This->ref);
if (ulReturn == 1)
IDirectSoundBuffer_AddRef((LPDIRECTSOUND3DBUFFER)This->dsb);
return ulReturn;
}
static ULONG WINAPI IKsPropertySetImpl_Release(LPKSPROPERTYSET iface) {
ICOM_THIS(IKsPropertySetImpl,iface);
ULONG ulReturn;
ulReturn = InterlockedDecrement(&This->ref);
if (ulReturn)
return ulReturn;
IDirectSoundBuffer_Release((LPDIRECTSOUND3DBUFFER)This->dsb);
return 0;
}
static HRESULT WINAPI IKsPropertySetImpl_Get(LPKSPROPERTYSET iface,
REFGUID guidPropSet, ULONG dwPropID,
LPVOID pInstanceData, ULONG cbInstanceData,
LPVOID pPropData, ULONG cbPropData,
PULONG pcbReturned
) {
ICOM_THIS(IKsPropertySetImpl,iface);
FIXME("(%p,%s,%ld,%p,%ld,%p,%ld,%p), stub!\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData,pcbReturned);
return E_PROP_ID_UNSUPPORTED;
}
static HRESULT WINAPI IKsPropertySetImpl_Set(LPKSPROPERTYSET iface,
REFGUID guidPropSet, ULONG dwPropID,
LPVOID pInstanceData, ULONG cbInstanceData,
LPVOID pPropData, ULONG cbPropData
) {
ICOM_THIS(IKsPropertySetImpl,iface);
FIXME("(%p,%s,%ld,%p,%ld,%p,%ld), stub!\n",This,debugstr_guid(guidPropSet),dwPropID,pInstanceData,cbInstanceData,pPropData,cbPropData);
return E_PROP_ID_UNSUPPORTED;
}
static HRESULT WINAPI IKsPropertySetImpl_QuerySupport(LPKSPROPERTYSET iface,
REFGUID guidPropSet, ULONG dwPropID, PULONG pTypeSupport
) {
ICOM_THIS(IKsPropertySetImpl,iface);
FIXME("(%p,%s,%ld,%p), stub!\n",This,debugstr_guid(guidPropSet),dwPropID,pTypeSupport);
return E_PROP_ID_UNSUPPORTED;
}
static ICOM_VTABLE(IKsPropertySet) iksvt = {
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
IKsPropertySetImpl_QueryInterface,
IKsPropertySetImpl_AddRef,
IKsPropertySetImpl_Release,
IKsPropertySetImpl_Get,
IKsPropertySetImpl_Set,
IKsPropertySetImpl_QuerySupport
};
HRESULT WINAPI IKsPropertySetImpl_Create(
IDirectSoundBufferImpl *This,
IKsPropertySetImpl **piks)
{
IKsPropertySetImpl *iks;
iks = (IKsPropertySetImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(*iks));
iks->ref = 0;
iks->dsb = This;
ICOM_VTBL(iks) = &iksvt;
*piks = iks;
return S_OK;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment