Author: silverblade
Date: Tue Jul 15 17:42:34 2008
New Revision: 34538
URL:
http://svn.reactos.org/svn/reactos?rev=34538&view=rev
Log:
Implemented WOM_OPEN, WOM_DONE and WOM_CLOSE callbacks. Added missing prototype
of DriverCallback to digitalv.h in the PSDK (as per MSDN). Looped buffers aren't
meant to be marked "done" until all loops are finished. But even then, NT4's
own
sndblst.dll seems to horde looped buffers if we break out of the loop. (Give the
damn things back!) So, don't expect WOM_DONE from looped buffers.
MSDN states that you shouldn't call any wave functions within the wave callback,
or a deadlock will occur. Since buffer submission is dealt with inside the
streaming thread, as is the callback, this situation holds true for my
implementation.
Things are almost at a state now where it may be possible to drop this in-place
of the original sndblst.dll on an NT4 installation and have it function for wave
audio playback. But there are still issues to be sorted out.
Modified:
branches/silverblade-audio/dll/win32/sndblst/sndblst.c
branches/silverblade-audio/include/psdk/digitalv.h
branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h
branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/callback.c
branches/silverblade-audio/lib/drivers/sound/mmebuddy/mmebuddy.rbuild
branches/silverblade-audio/lib/drivers/sound/mmebuddy/wave/streaming.c
branches/silverblade-audio/lib/drivers/sound/mmebuddy/wave/wodMessage.c
Modified: branches/silverblade-audio/dll/win32/sndblst/sndblst.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/dll/win32/snd…
==============================================================================
--- branches/silverblade-audio/dll/win32/sndblst/sndblst.c [iso-8859-1] (original)
+++ branches/silverblade-audio/dll/win32/sndblst/sndblst.c [iso-8859-1] Tue Jul 15
17:42:34 2008
@@ -126,6 +126,19 @@
WORD Buffer[5347700 / 2];
WAVEHDR WaveHeaders[534];
+
+VOID CALLBACK
+callback(
+ HWAVEOUT Handle,
+ UINT Message,
+ DWORD_PTR Instance,
+ DWORD_PTR Parameter1,
+ DWORD_PTR Parameter2)
+{
+ printf("Callback called! Handle %d, message %d, instance %d, parameters %d
%d\n",
+ (int) Handle, (int) Message, (int) Instance, (int) Parameter1,
+ (int) Parameter2);
+}
int APIENTRY wWinMain(
HINSTANCE hInstance,
@@ -178,7 +191,9 @@
//SOUND_DEBUG(L"WODM_OPEN test 2");
OpenDesc.lpFormat = &Format;
- Result = wodMessage(0, WODM_OPEN, (DWORD) &InstanceData, (DWORD) &OpenDesc,
0);
+ OpenDesc.dwCallback = (DWORD) &callback;
+ OpenDesc.dwInstance = 0x69696969;
+ Result = wodMessage(0, WODM_OPEN, (DWORD) &InstanceData, (DWORD) &OpenDesc,
CALLBACK_FUNCTION);
/*SOUND_DEBUG_HEX(Result);*/
POPUP("Click for WODM_WRITE test");
Modified: branches/silverblade-audio/include/psdk/digitalv.h
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/psdk/…
==============================================================================
--- branches/silverblade-audio/include/psdk/digitalv.h [iso-8859-1] (original)
+++ branches/silverblade-audio/include/psdk/digitalv.h [iso-8859-1] Tue Jul 15 17:42:34
2008
@@ -857,6 +857,20 @@
LPWSTR lpstrText;
} MCI_DGV_WINDOW_PARMSW, *LPMCI_DGV_WINDOW_PARMSW;
+/* Driver callback for multimedia components (implemented in winmm) */
+
+WINAPI BOOL
+DriverCallback(
+ DWORD dwCallBack,
+ DWORD dwFlags,
+ HDRVR hdrvr,
+ DWORD msg,
+ DWORD dwUser,
+ DWORD dwParam1,
+ DWORD dwParam2
+);
+
+
#ifdef __cplusplus
}
#endif
Modified: branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/react…
==============================================================================
--- branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h [iso-8859-1]
(original)
+++ branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h [iso-8859-1] Tue Jul
15 17:42:34 2008
@@ -293,7 +293,10 @@
/* Stuff generously donated to us from WinMM */
struct
{
+ HDRVR Handle;
+ DWORD Flags;
DWORD ClientCallback;
+ DWORD ClientCallbackInstanceData;
} WinMM;
/* Device-specific parameters */
@@ -699,4 +702,15 @@
DWORD parameter2);
+/*
+ mme/callback.c
+*/
+
+VOID
+NotifySoundClient(
+ PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
+ DWORD Message,
+ DWORD Parameter);
+
+
#endif
Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/callback.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/callback.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/mme/callback.c [iso-8859-1] Tue
Jul 15 17:42:34 2008
@@ -11,11 +11,30 @@
#include <windows.h>
#include <mmsystem.h>
+#include <digitalv.h>
+
+#include <mmebuddy.h>
VOID
NotifySoundClient(
+ PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
DWORD Message,
DWORD Parameter)
{
- /* TODO... DriverCallback */
+ ASSERT( SoundDeviceInstance );
+
+ TRACE_("MME client callback - message %d, parameter %d\n",
+ (int) Message,
+ (int) Parameter);
+
+ if ( SoundDeviceInstance->WinMM.ClientCallback )
+ {
+ DriverCallback(SoundDeviceInstance->WinMM.ClientCallback,
+ HIWORD(SoundDeviceInstance->WinMM.Flags),
+ SoundDeviceInstance->WinMM.Handle,
+ Message,
+ SoundDeviceInstance->WinMM.ClientCallbackInstanceData,
+ Parameter,
+ 0);
+ }
}
Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/mmebuddy.rbuild
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/mmebuddy.rbuild [iso-8859-1]
(original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/mmebuddy.rbuild [iso-8859-1] Tue
Jul 15 17:42:34 2008
@@ -11,6 +11,7 @@
<file>utility.c</file>
<directory name="mme">
<file>DriverProc.c</file>
+ <file>callback.c</file>
</directory>
<directory name="wave">
<file>wodMessage.c</file>
Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/wave/streaming.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/wave/streaming.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/wave/streaming.c [iso-8859-1]
Tue Jul 15 17:42:34 2008
@@ -237,12 +237,36 @@
WaveHeader->reserved += BytesWritten;
ASSERT(WaveHeader->reserved <= WaveHeader->dwBufferLength);
+ StreamInfo = &SoundDeviceInstance->Streaming.Wave;
+
+ /* Did we complete a header sent by the client? */
if ( WaveHeader->reserved == WaveHeader->dwBufferLength )
{
TRACE_("* Completed wavehdr %p (length %d)\n",
WaveHeader,
(int) WaveHeader->dwBufferLength);
- /* TODO: Give it back to the client */
+
+ if ( StreamInfo->LoopsRemaining > 0 )
+ {
+ /* Let's go round again... */
+ WaveHeader->reserved = 0;
+
+ /*
+ FIXME:
+ I have no idea wtf happens with completions - tests with the NT4
+ mmdrv indicate that they just randomly throw back completed
+ buffers later on. Like, a lot later on... Like, when the device
+ is being reset.
+ */
+ }
+ else
+ {
+ /* Mark the header as done */
+ WaveHeader->dwFlags |= WHDR_DONE;
+
+ /* Notify the client */
+ NotifySoundClient(SoundDeviceInstance, WOM_DONE, (DWORD) WaveHeader);
+ }
}
else
{
@@ -251,8 +275,6 @@
(int) WaveHeader->reserved,
(int) WaveHeader->dwBufferLength);
}
-
- StreamInfo = &SoundDeviceInstance->Streaming.Wave;
/* Decrease the number of outstanding buffers */
ASSERT(StreamInfo->BuffersOutstanding > 0);
@@ -422,6 +444,8 @@
/* ugly HACK to stop sound playback... FIXME */
SoundDeviceInstance->Streaming.Wave.CurrentBuffer = NULL;
+ /* TODO: Return all audio buffers to the client, marking as DONE */
+
return Functions->ResetWaveDevice(SoundDeviceInstance);
}
Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/wave/wodMessage.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/wave/wodMessage.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/wave/wodMessage.c [iso-8859-1]
Tue Jul 15 17:42:34 2008
@@ -95,10 +95,18 @@
return Result;
}
+ /* Set up the callback - TODO: Put this somewhere else? */
+ Instance->WinMM.ClientCallback = OpenParameters->dwCallback;
+ Instance->WinMM.ClientCallbackInstanceData =
+ OpenParameters->dwInstance;
+ Instance->WinMM.Handle = (HDRVR) OpenParameters->hWave;
+ Instance->WinMM.Flags = parameter2;
+
/* Provide winmm with instance handle */
*((PSOUND_DEVICE_INSTANCE*)private_handle) = Instance;
- /* TODO: Send callback... */
+ /* Notify the client */
+ NotifySoundClient(Instance, WOM_OPEN, 0);
return MMSYSERR_NOERROR;
}
@@ -118,10 +126,11 @@
if ( State != WAVE_DD_IDLE )
return WAVERR_STILLPLAYING;
+ /* Notify the client */
+ NotifySoundClient(Instance, WOM_CLOSE, 0);
+
Result = DestroySoundDeviceInstance(Instance);
ASSERT(Result == MMSYSERR_NOERROR);
-
- /* TODO: Send the callback */
return Result;
}