Added bits required for webkit volume adjustment to work on windows (xp included).

This commit is contained in:
Shyotl
2013-08-12 20:15:57 -05:00
parent f68e89cec6
commit 2f7b1e3d9b
9 changed files with 2541 additions and 15 deletions

View File

@@ -27,8 +27,6 @@
*/
#include "volume_catcher.h"
# define WIN32_LEAN_AND_MEAN
# include <winsock2.h>
#include <windows.h>
#include "llmemory.h"
class VolumeCatcherImpl : public LLSingleton<VolumeCatcherImpl>
@@ -50,18 +48,37 @@ private:
set_volume_func_t mSetVolumeFunc;
set_mute_func_t mSetMuteFunc;
// tests if running on Vista, 7, 8 + once in CTOR
bool isWindowsVistaOrHigher();
F32 mVolume;
F32 mPan;
bool mSystemIsVistaOrHigher;
};
VolumeCatcherImpl::VolumeCatcherImpl()
: mVolume(1.0f), // default volume is max
mPan(0.f) // default pan is centered
bool VolumeCatcherImpl::isWindowsVistaOrHigher()
{
HMODULE handle = ::LoadLibrary(L"winmm.dll");
if(handle)
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
return osvi.dwMajorVersion >= 6;
}
VolumeCatcherImpl::VolumeCatcherImpl()
: mVolume(1.0f), // default volume is max
mPan(0.f) // default pan is centered
{
mSystemIsVistaOrHigher = isWindowsVistaOrHigher();
if ( ! mSystemIsVistaOrHigher )
{
mSetVolumeFunc = (set_volume_func_t)::GetProcAddress(handle, "setPluginVolume");
mSetMuteFunc = (set_mute_func_t)::GetProcAddress(handle, "setPluginMute");
HMODULE handle = ::LoadLibrary(L"winmm.dll");
if(handle)
{
mSetVolumeFunc = (set_volume_func_t)::GetProcAddress(handle, "setPluginVolume");
mSetMuteFunc = (set_mute_func_t)::GetProcAddress(handle, "setPluginMute");
}
}
}
@@ -69,18 +86,29 @@ VolumeCatcherImpl::~VolumeCatcherImpl()
{
}
void VolumeCatcherImpl::setVolume(F32 volume)
{
mVolume = volume;
if (mSetMuteFunc)
if ( mSystemIsVistaOrHigher )
{
mSetMuteFunc(volume == 0.f);
// set both left/right to same volume
// TODO: use pan value to set independently
DWORD left_channel = (DWORD)(mVolume * 65535.0f);
DWORD right_channel = (DWORD)(mVolume * 65535.0f);
DWORD hw_volume = left_channel << 16 | right_channel;
::waveOutSetVolume(NULL, hw_volume);
}
if (mSetVolumeFunc)
else
{
mSetVolumeFunc(mVolume);
if (mSetMuteFunc)
{
mSetMuteFunc(volume == 0.f);
}
if (mSetVolumeFunc)
{
mSetVolumeFunc(mVolume);
}
}
}