From b8fc27d6a339af2360baca1227396fe525a9f813 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Wed, 4 Nov 2009 02:16:49 +0000 Subject: [PATCH] - Add sanity checks - Implement IDirectSoundCaptureBuffer8::Stop - Implement changing the stream format for secondary buffers - Silence debug flood svn path=/trunk/; revision=43946 --- .../dll/directx/dsound_new/capturebuffer.c | 44 +++++++++++++++++-- reactos/dll/directx/dsound_new/misc.c | 39 ++++++++++++++++ reactos/dll/directx/dsound_new/precomp.h | 7 ++- reactos/dll/directx/dsound_new/primary.c | 10 ++++- reactos/dll/directx/dsound_new/secondary.c | 18 +++++--- 5 files changed, 104 insertions(+), 14 deletions(-) diff --git a/reactos/dll/directx/dsound_new/capturebuffer.c b/reactos/dll/directx/dsound_new/capturebuffer.c index 0c9ab6bcb03..8762ff2da49 100644 --- a/reactos/dll/directx/dsound_new/capturebuffer.c +++ b/reactos/dll/directx/dsound_new/capturebuffer.c @@ -335,8 +335,10 @@ IDirectSoundCaptureBufferImpl_Start( if (This->State == KSSTATE_RUN) return DS_OK; - /* sanity check */ - ASSERT(This->hPin); + + /* check if there is a pin instance */ + if (!This->hPin) + return DSERR_GENERIC; /* setup request */ Property.Set = KSPROPSETID_Connection; @@ -385,8 +387,42 @@ HRESULT WINAPI IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface ) { - UNIMPLEMENTED - return DSERR_INVALIDPARAM; + KSPROPERTY Property; + DWORD Result; + KSSTATE State; + + LPCDirectSoundCaptureBufferImpl This = (LPCDirectSoundCaptureBufferImpl)CONTAINING_RECORD(iface, CDirectSoundCaptureBufferImpl, lpVtbl); + + if (This->State == KSSTATE_STOP) + { + /* stream has already been stopped */ + return DS_OK; + } + + if (!This->hPin) + return DSERR_GENERIC; + + /* setup request */ + Property.Set = KSPROPSETID_Connection; + Property.Id = KSPROPERTY_CONNECTION_STATE; + Property.Flags = KSPROPERTY_TYPE_SET; + State = KSSTATE_STOP; + + + /* set pin to stop */ + Result = SyncOverlappedDeviceIoControl(This->hPin, IOCTL_KS_PROPERTY, (PVOID)&Property, sizeof(KSPROPERTY), (PVOID)&State, sizeof(KSSTATE), NULL); + + ASSERT(Result == ERROR_SUCCESS); + + if (Result == ERROR_SUCCESS) + { + /* store result */ + This->State = State; + return DS_OK; + } + + DPRINT("Failed to stop pin\n"); + return DSERR_GENERIC; } HRESULT diff --git a/reactos/dll/directx/dsound_new/misc.c b/reactos/dll/directx/dsound_new/misc.c index ae78716dc70..ae313c90cbe 100644 --- a/reactos/dll/directx/dsound_new/misc.c +++ b/reactos/dll/directx/dsound_new/misc.c @@ -13,6 +13,45 @@ const GUID KSPROPSETID_Pin = {0x8C134960L, 0x51AD, 0x11CF, { const GUID KSPROPSETID_Topology = {0x720D4AC0L, 0x7533, 0x11D0, {0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00}}; const GUID KSPROPSETID_Audio = {0x45FFAAA0L, 0x6E1B, 0x11D0, {0xBC, 0xF2, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00}}; +BOOL +SetPinFormat( + IN HANDLE hPin, + IN LPWAVEFORMATEX WaveFormatEx) +{ + DWORD dwResult; + KSPROPERTY Property; + KSDATAFORMAT_WAVEFORMATEX DataFormat; + + /* setup connection request */ + Property.Id = KSPROPERTY_CONNECTION_DATAFORMAT; + Property.Set = KSPROPSETID_Connection; + Property.Flags = KSPROPERTY_TYPE_SET; + + /* setup data format */ + DataFormat.WaveFormatEx.wFormatTag = WaveFormatEx->wFormatTag; + DataFormat.WaveFormatEx.nSamplesPerSec = WaveFormatEx->nSamplesPerSec; + DataFormat.WaveFormatEx.nBlockAlign = WaveFormatEx->nBlockAlign; + DataFormat.WaveFormatEx.cbSize = 0; + DataFormat.DataFormat.FormatSize = sizeof(KSDATAFORMAT) + sizeof(WAVEFORMATEX); + DataFormat.DataFormat.Flags = 0; + DataFormat.DataFormat.Reserved = 0; + DataFormat.DataFormat.MajorFormat = KSDATAFORMAT_TYPE_AUDIO; + DataFormat.DataFormat.SubFormat = KSDATAFORMAT_SUBTYPE_PCM; + DataFormat.DataFormat.Specifier = KSDATAFORMAT_SPECIFIER_WAVEFORMATEX; + DataFormat.DataFormat.SampleSize = 4; + DataFormat.WaveFormatEx.nChannels = WaveFormatEx->nChannels; + DataFormat.WaveFormatEx.nAvgBytesPerSec = WaveFormatEx->nAvgBytesPerSec; + DataFormat.WaveFormatEx.wBitsPerSample = WaveFormatEx->wBitsPerSample; + + dwResult = SyncOverlappedDeviceIoControl(hPin, IOCTL_KS_PROPERTY, (LPVOID)&Property, sizeof(KSPROPERTY),(LPVOID)&DataFormat, sizeof(KSDATAFORMAT_WAVEFORMATEX), NULL); + + if (dwResult == ERROR_SUCCESS) + return TRUE; + else + return FALSE; +} + + BOOL DoDataIntersection( HANDLE hFilter, diff --git a/reactos/dll/directx/dsound_new/precomp.h b/reactos/dll/directx/dsound_new/precomp.h index 5ead080adfd..0bf9b199ada 100644 --- a/reactos/dll/directx/dsound_new/precomp.h +++ b/reactos/dll/directx/dsound_new/precomp.h @@ -15,7 +15,7 @@ #include #include #include -#define YDEBUG +#define NDEBUG #include #include #include @@ -110,6 +110,11 @@ NewDirectSound( /* misc.c */ +BOOL +SetPinFormat( + IN HANDLE hPin, + IN LPWAVEFORMATEX WaveFormatEx); + BOOL CreateCompatiblePin( IN HANDLE hFilter, diff --git a/reactos/dll/directx/dsound_new/primary.c b/reactos/dll/directx/dsound_new/primary.c index 5be2352c05d..9b5e822e8bc 100644 --- a/reactos/dll/directx/dsound_new/primary.c +++ b/reactos/dll/directx/dsound_new/primary.c @@ -519,8 +519,14 @@ PrimaryDirectSoundBuffer_SetFormat( if (This->hPin) { - /* fixme change format */ - ASSERT(0); + // FIXME + // check if multiple buffers are active + // in that case need mixing + + if (SetPinFormat(This->hPin, pcfxFormat)) + return DS_OK; + else + return DSERR_GENERIC; } do diff --git a/reactos/dll/directx/dsound_new/secondary.c b/reactos/dll/directx/dsound_new/secondary.c index 08c51605244..a3fe2b17a62 100644 --- a/reactos/dll/directx/dsound_new/secondary.c +++ b/reactos/dll/directx/dsound_new/secondary.c @@ -294,25 +294,29 @@ SecondaryDirectSoundBuffer8Impl_fnPlay( return DSERR_INVALIDPARAM; } - DPRINT("SecondaryDirectSoundBuffer8Impl_fnPlay dwPriority %x dwFlags %x\n", dwPriority, dwFlags); - hResult = PrimaryDirectSoundBuffer_SetFormat(This->PrimaryBuffer, This->Format, (dwFlags & DSBPLAY_LOOPING)); + /* sanity check */ + ASSERT(dwFlags & DSBPLAY_LOOPING); + + /* set dataformat */ + hResult = PrimaryDirectSoundBuffer_SetFormat(This->PrimaryBuffer, This->Format, TRUE); - DPRINT("Result %x\n", hResult); if (!SUCCEEDED(hResult)) { /* failed */ + DPRINT1("Failed to set format Tag %u Samples %u Bytes %u nChannels %u\n", This->Format->wFormatTag, This->Format->nSamplesPerSec, This->Format->wBitsPerSample, This->Format->nChannels); return hResult; } + /* start primary buffer */ PrimaryDirectSoundBuffer_SetState(This->PrimaryBuffer, KSSTATE_RUN); - - + /* acquire primary buffer */ PrimaryDirectSoundBuffer_AcquireLock(This->PrimaryBuffer); - + /* HACK write buffer */ PrimaryDirectSoundBuffer_Write(This->PrimaryBuffer, This->Buffer, This->BufferSize); - + /* release primary buffer */ PrimaryDirectSoundBuffer_ReleaseLock(This->PrimaryBuffer); + DPRINT1("SetFormatSuccess PrimaryBuffer %p\n", This->PrimaryBuffer); return DS_OK; }