reactos/dll/win32/wdmaud.drv/wdmaud.c
Joachim Henze 5bb36e92c5 [WDMAUD.DRV] Revert "Workaround multiple issues with AC97 driver from rapps"
This reverts commit 0.4.15-dev-791-g
6d7ebc2048

It was a workaround just. To bypass sysaudio. It had a very positive effect on
our playback performance, but using the different codepaths did also lead to
regressions, that I have no idea how to address, therefore I think it's my
personal responsibility to revert it. I guess it's better to improve on the
code-paths that we intend to use finally, instead of fixing what will
be dead paths in the future.

The revert will fix:
- CORE-17277 crash of dsound:duplex on "GCCLin_x86 on Test VBox"
- CORE-17278 crash of dsound:capture on "GCCLin_x86 on Test VBox"
- CORE-17285 Realtek HD Audio does no longer work in ReactOS

But ofc now we will suffer again from very severe things that the hack could workaround:
- CORE-13202 Unhandled exception from wdmaud.drv when recording sound in Scratch 1.4 leads to app-crash
- CORE-13488 A deadlock in "DiabloII" character selection screen and "The Lion King II"
- CORE-8726/CORE-9986/CORE-16564 AC97 driver from rapps will need reboot-orgies again, does not longer
  work in the same session that we installed the driver
- CORE-9981 "DosBox + Commander Keen6" totally garbled sound output instead of music
    "ScummVM 2.0 with Monkey Island 2" totally garbled sound output instead of music
- the test execution times of "GCCLin_x86 on Test VBox" will almost double
2020-10-03 16:39:13 +02:00

230 lines
6.2 KiB
C

/*
* PROJECT: ReactOS Sound System
* LICENSE: GPL - See COPYING in the top level directory
* FILE: dll/win32/wdmaud.drv/wdmaud.c
*
* PURPOSE: WDM Audio Driver (User-mode part)
* PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
*
* NOTES: Looking for wodMessage & co? You won't find them here. Try
* the MME Buddy library, which is where these routines are
* actually implemented.
*
*/
#include "wdmaud.h"
#define NDEBUG
#include <debug.h>
#include <mmebuddy_debug.h>
#ifndef USE_MMIXER_LIB
#define FUNC_NAME(x) x##ByLegacy
#else
#define FUNC_NAME(x) x##ByMMixer
#endif
MMRESULT
QueryWdmWaveDeviceFormatSupport(
IN PSOUND_DEVICE Device,
IN PWAVEFORMATEX WaveFormat,
IN DWORD WaveFormatSize)
{
/* Whatever... */
return MMSYSERR_NOERROR;
}
MMRESULT
PopulateWdmDeviceList(
MMDEVICE_TYPE DeviceType)
{
MMRESULT Result;
DWORD DeviceCount = 0;
PSOUND_DEVICE SoundDevice = NULL;
MMFUNCTION_TABLE FuncTable;
DWORD i;
VALIDATE_MMSYS_PARAMETER( IS_VALID_SOUND_DEVICE_TYPE(DeviceType) );
Result = FUNC_NAME(WdmAudGetNumWdmDevs)(DeviceType, &DeviceCount);
if ( ! MMSUCCESS(Result) )
{
SND_ERR(L"Error %d while obtaining number of devices\n", Result);
return TranslateInternalMmResult(Result);
}
SND_TRACE(L"%d devices of type %d found\n", DeviceCount, DeviceType);
for ( i = 0; i < DeviceCount; ++ i )
{
Result = ListSoundDevice(DeviceType, UlongToPtr(i), &SoundDevice);
if ( ! MMSUCCESS(Result) )
{
SND_ERR(L"Failed to list sound device - error %d\n", Result);
return TranslateInternalMmResult(Result);
}
/* Set up our function table */
ZeroMemory(&FuncTable, sizeof(MMFUNCTION_TABLE));
FuncTable.GetCapabilities = FUNC_NAME(WdmAudGetCapabilities);
FuncTable.QueryWaveFormatSupport = QueryWdmWaveDeviceFormatSupport; //FIXME
FuncTable.Open = FUNC_NAME(WdmAudOpenSoundDevice);
FuncTable.Close = FUNC_NAME(WdmAudCloseSoundDevice);
FuncTable.GetDeviceInterfaceString = FUNC_NAME(WdmAudGetDeviceInterfaceString);
if (DeviceType == MIXER_DEVICE_TYPE)
{
FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetMixerDeviceFormat);
FuncTable.QueryMixerInfo = FUNC_NAME(WdmAudQueryMixerInfo);
}
else if (DeviceType == WAVE_IN_DEVICE_TYPE || DeviceType == WAVE_OUT_DEVICE_TYPE)
{
FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetWaveDeviceFormat);
FuncTable.SetState = FUNC_NAME(WdmAudSetWaveState);
FuncTable.ResetStream = FUNC_NAME(WdmAudResetStream);
FuncTable.GetPos = FUNC_NAME(WdmAudGetWavePosition);
#ifndef USERMODE_MIXER
FuncTable.CommitWaveBuffer = FUNC_NAME(WdmAudCommitWaveBuffer);
#else
FuncTable.CommitWaveBuffer = WriteFileEx_Remixer;
#endif
}
else if (DeviceType == MIDI_IN_DEVICE_TYPE || DeviceType == MIDI_OUT_DEVICE_TYPE)
{
FuncTable.SetWaveFormat = FUNC_NAME(WdmAudSetMixerDeviceFormat);
FuncTable.SetState = FUNC_NAME(WdmAudSetWaveState);
FuncTable.GetPos = FUNC_NAME(WdmAudGetWavePosition);
}
SetSoundDeviceFunctionTable(SoundDevice, &FuncTable);
}
return MMSYSERR_NOERROR;
}
LONG
APIENTRY
DriverProc(
DWORD DriverId,
HANDLE DriverHandle,
UINT Message,
LONG Parameter1,
LONG Parameter2)
{
switch ( Message )
{
case DRV_LOAD :
{
HANDLE Handle;
MMRESULT Result;
SND_TRACE(L"DRV_LOAD\n");
Result = InitEntrypointMutexes();
if ( ! MMSUCCESS(Result) )
return 0L;
Result = FUNC_NAME(WdmAudOpenSoundDevice)(NULL, &Handle);
if ( Result != MMSYSERR_NOERROR )
{
SND_ERR(L"Failed to open \\\\.\\wdmaud\n");
//UnlistAllSoundDevices();
return 0L;
}
/* Populate the device lists */
SND_TRACE(L"Populating device lists\n");
PopulateWdmDeviceList(WAVE_OUT_DEVICE_TYPE);
PopulateWdmDeviceList(WAVE_IN_DEVICE_TYPE);
PopulateWdmDeviceList(MIDI_OUT_DEVICE_TYPE);
PopulateWdmDeviceList(MIDI_IN_DEVICE_TYPE);
PopulateWdmDeviceList(AUX_DEVICE_TYPE);
PopulateWdmDeviceList(MIXER_DEVICE_TYPE);
SND_TRACE(L"Initialisation complete\n");
return 1L;
}
case DRV_FREE :
{
SND_TRACE(L"DRV_FREE\n");
FUNC_NAME(WdmAudCleanup)();
/* TODO: Clean up the path names! */
UnlistAllSoundDevices();
CleanupEntrypointMutexes();
SND_TRACE(L"Unfreed memory blocks: %d\n",
GetMemoryAllocationCount());
return 1L;
}
case DRV_ENABLE :
case DRV_DISABLE :
{
SND_TRACE(L"DRV_ENABLE / DRV_DISABLE\n");
return 1L;
}
case DRV_OPEN :
case DRV_CLOSE :
{
SND_TRACE(L"DRV_OPEN / DRV_CLOSE\n");
return 1L;
}
case DRV_QUERYCONFIGURE :
{
SND_TRACE(L"DRV_QUERYCONFIGURE\n");
return 0L;
}
case DRV_CONFIGURE :
return DRVCNF_OK;
default :
SND_TRACE(L"Unhandled message %d\n", Message);
return DefDriverProc(DriverId,
DriverHandle,
Message,
Parameter1,
Parameter2);
}
}
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpvReserved)
{
switch ( fdwReason )
{
case DLL_PROCESS_ATTACH :
SND_TRACE(L"WDMAUD.DRV - Process attached\n");
break;
case DLL_PROCESS_DETACH :
SND_TRACE(L"WDMAUD.DRV - Process detached\n");
break;
case DLL_THREAD_ATTACH :
SND_TRACE(L"WDMAUD.DRV - Thread attached\n");
break;
case DLL_THREAD_DETACH :
SND_TRACE(L"WDMAUD.DRV - Thread detached\n");
break;
}
return TRUE;
}