summaryrefslogtreecommitdiff
path: root/indra/media_plugins/winmmshim/winmm_shim.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/media_plugins/winmmshim/winmm_shim.cpp')
-rwxr-xr-x[-rw-r--r--]indra/media_plugins/winmmshim/winmm_shim.cpp85
1 files changed, 58 insertions, 27 deletions
diff --git a/indra/media_plugins/winmmshim/winmm_shim.cpp b/indra/media_plugins/winmmshim/winmm_shim.cpp
index 9563a3b664..78f7a9b0da 100644..100755
--- a/indra/media_plugins/winmmshim/winmm_shim.cpp
+++ b/indra/media_plugins/winmmshim/winmm_shim.cpp
@@ -4,7 +4,7 @@
*
* $LicenseInfo:firstyear=2010&license=viewerlgpl$
* Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
+ * Copyright (C) 2010-2014, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -30,37 +30,53 @@
using std::wstring;
-static float sVolumeLevel = 1.f;
-static bool sMute = false;
+static float sVolumeLevel = 1.f; // Could be covered by critical section,
+static bool sMute = false; // not needed with atomicity and alignment.
+static CRITICAL_SECTION sCriticalSection;
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
- static bool initialized = false;
- // do this only once
+ if (ul_reason_for_call == DLL_PROCESS_ATTACH)
+ {
+ InitializeCriticalSection(&sCriticalSection);
+ }
+ return TRUE;
+}
+
+void ll_winmm_shim_initialize(){
+ static volatile bool initialized = false;
+
+ // do this only once using double-check locking
if (!initialized)
- { // bind to original winmm.dll
- TCHAR system_path[MAX_PATH];
- TCHAR dll_path[MAX_PATH];
- ::GetSystemDirectory(system_path, MAX_PATH);
-
- // grab winmm.dll from system path, where it should live
- wsprintf(dll_path, "%s\\winmm.dll", system_path);
- HMODULE winmm_handle = ::LoadLibrary(dll_path);
-
- if (winmm_handle != NULL)
- { // we have a dll, let's get out pointers!
- initialized = true;
- init_function_pointers(winmm_handle);
- return true;
+ {
+ EnterCriticalSection(&sCriticalSection);
+ if (!initialized)
+ { // bind to original winmm.dll
+ TCHAR system_path[MAX_PATH];
+ TCHAR dll_path[MAX_PATH];
+ ::GetSystemDirectory(system_path, MAX_PATH);
+
+ // grab winmm.dll from system path, where it should live
+ wsprintf(dll_path, "%s\\winmm.dll", system_path);
+ HMODULE winmm_handle = ::LoadLibrary(dll_path);
+
+ if (winmm_handle != NULL)
+ { // we have a dll, let's get out pointers!
+ init_function_pointers(winmm_handle);
+ ::OutputDebugStringA("WINMM_SHIM.DLL: real winmm.dll initialized successfully\n");
+ initialized = true; // Last thing after completing setup
+ }
+ else
+ {
+ // failed to initialize real winmm.dll
+ ::OutputDebugStringA("WINMM_SHIM.DLL: Failed to initialize real winmm.dll\n");
+ }
}
-
- // failed to initialize real winmm.dll
- return false;
+ LeaveCriticalSection(&sCriticalSection);
}
- return true;
}
@@ -75,10 +91,11 @@ extern "C"
int mBitsPerSample;
};
typedef std::map<HWAVEOUT, WaveOutFormat*> wave_out_map_t;
- static wave_out_map_t sWaveOuts;
+ static wave_out_map_t sWaveOuts; // Covered by sCriticalSection
MMRESULT WINAPI waveOutOpen( LPHWAVEOUT phwo, UINT uDeviceID, LPCWAVEFORMATEX pwfx, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen)
{
+ ll_winmm_shim_initialize();
if (pwfx->wFormatTag != WAVE_FORMAT_PCM
|| (pwfx->wBitsPerSample != 8 && pwfx->wBitsPerSample != 16))
{ // uncompressed 8 and 16 bit sound are the only types we support
@@ -90,24 +107,30 @@ extern "C"
&& ((fdwOpen & WAVE_FORMAT_QUERY) == 0)) // not just querying for format support
{ // remember the requested bits per sample, and associate with the given handle
WaveOutFormat* wave_outp = new WaveOutFormat(pwfx->wBitsPerSample);
+ EnterCriticalSection(&sCriticalSection);
sWaveOuts.insert(std::make_pair(*phwo, wave_outp));
+ LeaveCriticalSection(&sCriticalSection);
}
return result;
}
MMRESULT WINAPI waveOutClose( HWAVEOUT hwo)
{
+ ll_winmm_shim_initialize();
+ EnterCriticalSection(&sCriticalSection);
wave_out_map_t::iterator found_it = sWaveOuts.find(hwo);
if (found_it != sWaveOuts.end())
{ // forget what we know about this handle
delete found_it->second;
sWaveOuts.erase(found_it);
}
- return waveOutClose_orig( hwo);
+ LeaveCriticalSection(&sCriticalSection);
+ return waveOutClose_orig(hwo);
}
MMRESULT WINAPI waveOutWrite( HWAVEOUT hwo, LPWAVEHDR pwh, UINT cbwh)
{
+ ll_winmm_shim_initialize();
MMRESULT result = MMSYSERR_NOERROR;
if (sMute)
@@ -116,11 +139,19 @@ extern "C"
}
else if (sVolumeLevel != 1.f)
{ // need to apply volume level
+ int bits_per_sample(0);
+
+ EnterCriticalSection(&sCriticalSection);
wave_out_map_t::iterator found_it = sWaveOuts.find(hwo);
if (found_it != sWaveOuts.end())
{
- WaveOutFormat* formatp = found_it->second;
- switch (formatp->mBitsPerSample){
+ bits_per_sample = found_it->second->mBitsPerSample;
+ }
+ LeaveCriticalSection(&sCriticalSection);
+ if (bits_per_sample)
+ {
+ switch (bits_per_sample)
+ {
case 8:
{
char volume = (char)(sVolumeLevel * 127.f);