diff options
Diffstat (limited to 'indra/media_plugins')
-rw-r--r-- | indra/media_plugins/webkit/windows_volume_catcher.cpp | 246 | ||||
-rw-r--r-- | indra/media_plugins/winmmshim/forwarding_api.cpp | 36 | ||||
-rw-r--r-- | indra/media_plugins/winmmshim/forwarding_api.h | 36 | ||||
-rw-r--r-- | indra/media_plugins/winmmshim/winmm_shim.cpp | 48 |
4 files changed, 91 insertions, 275 deletions
diff --git a/indra/media_plugins/webkit/windows_volume_catcher.cpp b/indra/media_plugins/webkit/windows_volume_catcher.cpp index 8debe8fac6..fdff28c2c1 100644 --- a/indra/media_plugins/webkit/windows_volume_catcher.cpp +++ b/indra/media_plugins/webkit/windows_volume_catcher.cpp @@ -33,262 +33,62 @@ #include "volume_catcher.h" #include <windows.h> +#include "llsingleton.h" -// -// Abstracts a Win32 mixer line and associated state -// for muting and changing volume on a given output -// -class Mixer -{ -public: - static Mixer* create(U32 index); - ~Mixer(); - - void setMute(bool mute); - void setVolume(F32 volume_left, F32 volume_right); - -private: - // use create(index) to create a Mixer - Mixer(HMIXER handle, U32 mute_control_id, U32 volume_control_id, U32 min_volume, U32 max_volume); - - HMIXER mHandle; - U32 mMuteControlID; // handle to mixer controller for muting - U32 mVolumeControlID; // handle to mixer controller for changing volume - U32 mMinVolume; // value that specifies minimum volume as reported by mixer - U32 mMaxVolume; // value that specifies maximum volume as reported by mixer -}; - -// factory function that attempts to create a Mixer object associated with a given mixer line index -// returns NULL if creation failed -// static -Mixer* Mixer::create(U32 index) -{ - // get handle to mixer object - HMIXER mixer_handle; - MMRESULT result = mixerOpen( &mixer_handle, - index, - 0, // HWND to call when state changes - not used - 0, // user data for callback - not used - MIXER_OBJECTF_MIXER ); - - if (result == MMSYSERR_NOERROR) - { - MIXERLINE mixer_line; - mixer_line.cbStruct = sizeof( MIXERLINE ); - - // try speakers first - mixer_line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS; - - MMRESULT result = mixerGetLineInfo( reinterpret_cast< HMIXEROBJ >( mixer_handle ), - &mixer_line, - MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE ); - if (result != MMSYSERR_NOERROR) - { // failed - try headphones next - mixer_line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_HEADPHONES; - result = mixerGetLineInfo( reinterpret_cast< HMIXEROBJ >( mixer_handle ), - &mixer_line, - MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE ); - } - - if (result == MMSYSERR_NOERROR) - { // successfully found mixer line object, now use it to get volume and mute controls - - // reuse these objects to query for both volume and mute controls - MIXERCONTROL mixer_control; - MIXERLINECONTROLS mixer_line_controls; - mixer_line_controls.cbStruct = sizeof( MIXERLINECONTROLS ); - mixer_line_controls.dwLineID = mixer_line.dwLineID; - mixer_line_controls.cControls = 1; - mixer_line_controls.cbmxctrl = sizeof( MIXERCONTROL ); - mixer_line_controls.pamxctrl = &mixer_control; - - // first, query for mute - mixer_line_controls.dwControlType = MIXERCONTROL_CONTROLTYPE_MUTE; - - // get control id for mute controls - result = mixerGetLineControls( reinterpret_cast< HMIXEROBJ >( mixer_handle ), - &mixer_line_controls, - MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE ); - if (result == MMSYSERR_NOERROR ) - { // we have a mute controls. Remember the mute control id and then query for - // volume controls using the same struct, but different dwControlType - - U32 mute_control_id = mixer_control.dwControlID; - mixer_line_controls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME; - result = mixerGetLineControls( reinterpret_cast< HMIXEROBJ >( mixer_handle ), - &mixer_line_controls, - MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE ); - - if (result == MMSYSERR_NOERROR) - { // we have both mute and volume controls for this mixer, so we're keeping it - return new Mixer(mixer_handle, - mute_control_id, - mixer_control.dwControlID, - mixer_control.Bounds.dwMinimum, - mixer_control.Bounds.dwMaximum); - } - } - } - } - - // if we got here, we didn't successfully create a Mixer object - mixerClose(mixer_handle); - return NULL; -} - -Mixer::Mixer(HMIXER handle, U32 mute_control_id, U32 volume_control_id, U32 min_volume, U32 max_volume) -: mHandle(handle), - mMuteControlID(mute_control_id), - mVolumeControlID(volume_control_id), - mMinVolume(min_volume), - mMaxVolume(max_volume) -{} - -Mixer::~Mixer() -{} - -// toggle mute for this mixer -// if mute is set, then volume level will be ignored -void Mixer::setMute(bool mute) -{ - MIXERCONTROLDETAILS_BOOLEAN mixer_control_details_bool = { mute }; - MIXERCONTROLDETAILS mixer_control_details; - mixer_control_details.cbStruct = sizeof( MIXERCONTROLDETAILS ); - mixer_control_details.dwControlID = mMuteControlID; - mixer_control_details.cChannels = 1; - mixer_control_details.cMultipleItems = 0; - mixer_control_details.cbDetails = sizeof( MIXERCONTROLDETAILS_BOOLEAN ); - mixer_control_details.paDetails = &mixer_control_details_bool; - - mixerSetControlDetails( reinterpret_cast< HMIXEROBJ >( mHandle ), - &mixer_control_details, - MIXER_OBJECTF_HMIXER | MIXER_SETCONTROLDETAILSF_VALUE ); -} - -// set individual volume levels for left and right channels -// if mute is set, then these values will apply once mute is unset -void Mixer::setVolume(F32 volume_left, F32 volume_right) -{ - // assuming pan is in range [-1, 1] set volume levels accordingly - // if pan == -1 then volume_left_mixer = volume_left && volume_right_mixer = 0 - // if pan == 0 then volume_left_mixer = volume_left && volume_right_mixer = volume_right - // if pan == 1 then volume_left_mixer = 0 && volume_right_mixer = volume_right - U32 volume_left_mixer = (U32) - ((F32)mMinVolume - + (volume_left * ((F32)mMaxVolume - (F32)mMinVolume))); - U32 volume_right_mixer = (U32) - ((F32)mMinVolume - + (volume_right * ((F32)mMaxVolume - (F32)mMinVolume))); - - // pass volume levels on to mixer - MIXERCONTROLDETAILS_UNSIGNED mixer_control_details_unsigned[ 2 ] = { volume_left_mixer, volume_right_mixer }; - MIXERCONTROLDETAILS mixer_control_details; - mixer_control_details.cbStruct = sizeof( MIXERCONTROLDETAILS ); - mixer_control_details.dwControlID = mVolumeControlID; - mixer_control_details.cChannels = 2; - mixer_control_details.cMultipleItems = 0; - mixer_control_details.cbDetails = sizeof( MIXERCONTROLDETAILS_UNSIGNED ); - mixer_control_details.paDetails = &mixer_control_details_unsigned; - - mixerSetControlDetails( reinterpret_cast< HMIXEROBJ >( mHandle ), - &mixer_control_details, - MIXER_OBJECTF_HMIXER | MIXER_SETCONTROLDETAILSF_VALUE ); -} - -class VolumeCatcherImpl +class VolumeCatcherImpl : public LLSingleton<VolumeCatcherImpl> { +friend LLSingleton<VolumeCatcherImpl>; public: void setVolume(F32 volume); void setPan(F32 pan); - static VolumeCatcherImpl *getInstance(); private: // This is a singleton class -- both callers and the component implementation should use getInstance() to find the instance. VolumeCatcherImpl(); ~VolumeCatcherImpl(); - static VolumeCatcherImpl *sInstance; - + typedef void (*set_volume_func_t)(F32); + typedef void (*set_mute_func_t)(bool); + + set_volume_func_t mSetVolumeFunc; + set_mute_func_t mSetMuteFunc; + F32 mVolume; F32 mPan; - typedef std::vector<Mixer*> mixer_vector_t; - mixer_vector_t mMixers; }; -VolumeCatcherImpl *VolumeCatcherImpl::sInstance = NULL; - -VolumeCatcherImpl *VolumeCatcherImpl::getInstance() -{ - if(!sInstance) - { - sInstance = new VolumeCatcherImpl; - } - - return sInstance; -} - VolumeCatcherImpl::VolumeCatcherImpl() : mVolume(1.0f), // default volume is max mPan(0.f) // default pan is centered { - OSVERSIONINFOEX V = {sizeof(OSVERSIONINFOEX)}; //EX for NT 5.0 and later - - ::GetVersionEx((POSVERSIONINFO)&V); - - // disable volume on XP and below - if (V.dwPlatformId == VER_PLATFORM_WIN32_NT && V.dwMajorVersion >= 6) + HMODULE handle = ::LoadLibrary(L"winmm.dll"); + if(handle) { - // for each reported mixer "device", create a proxy object and add to list - U32 num_mixers = mixerGetNumDevs(); - for (U32 mixer_index = 0; mixer_index < num_mixers; ++mixer_index) - { - Mixer* mixerp = Mixer::create(mixer_index); - if (mixerp) - { - mMixers.push_back(mixerp); - } - } + mSetVolumeFunc = (set_volume_func_t)::GetProcAddress(handle, "setPluginVolume"); + mSetMuteFunc = (set_mute_func_t)::GetProcAddress(handle, "setPluginMute"); } } VolumeCatcherImpl::~VolumeCatcherImpl() { - for(mixer_vector_t::iterator it = mMixers.begin(), end_it = mMixers.end(); - it != end_it; - ++it) - { - delete *it; - *it = NULL; - } } void VolumeCatcherImpl::setVolume(F32 volume) { - F32 left_volume = volume * min(1.f, 1.f - mPan); - F32 right_volume = volume * max(0.f, 1.f + mPan); + //F32 left_volume = volume * min(1.f, 1.f - mPan); + //F32 right_volume = volume * max(0.f, 1.f + mPan); - for(mixer_vector_t::iterator it = mMixers.begin(), end_it = mMixers.end(); - it != end_it; - ++it) - { // set volume levels and mute for each mixer - // note that a muted mixer will ignore this volume level - - (*it)->setVolume(left_volume, right_volume); - - if (volume == 0.f && mVolume != 0.f) - { - (*it)->setMute(true); - } - else if (mVolume == 0.f && volume != 0.f) - { - (*it)->setMute(false); - } - - } - mVolume = volume; + if (mSetMuteFunc) + { + mSetMuteFunc(volume == 0.f); + } + if (mSetVolumeFunc) + { + mSetVolumeFunc(mVolume); + } } void VolumeCatcherImpl::setPan(F32 pan) diff --git a/indra/media_plugins/winmmshim/forwarding_api.cpp b/indra/media_plugins/winmmshim/forwarding_api.cpp index eff7e20451..c2f553dfef 100644 --- a/indra/media_plugins/winmmshim/forwarding_api.cpp +++ b/indra/media_plugins/winmmshim/forwarding_api.cpp @@ -2,25 +2,31 @@ * @file forwarding_api.cpp * @brief forwards winmm API calls to real winmm.dll * - * $LicenseInfo:firstyear=2010&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. + * $LicenseInfo:firstyear=2010&license=viewergpl$ + * + * Copyright (c) 2010, 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 - * License as published by the Free Software Foundation; - * version 2.1 of the License only. + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. * $/LicenseInfo$ */ diff --git a/indra/media_plugins/winmmshim/forwarding_api.h b/indra/media_plugins/winmmshim/forwarding_api.h index 89a6b347f3..31e2186aa2 100644 --- a/indra/media_plugins/winmmshim/forwarding_api.h +++ b/indra/media_plugins/winmmshim/forwarding_api.h @@ -2,25 +2,31 @@ * @file forwarding_api.h * @brief forwards winmm API calls to real winmm.dll * - * $LicenseInfo:firstyear=2010&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. + * $LicenseInfo:firstyear=2010&license=viewergpl$ + * + * Copyright (c) 2010, 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 - * License as published by the Free Software Foundation; - * version 2.1 of the License only. + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. * $/LicenseInfo$ */ diff --git a/indra/media_plugins/winmmshim/winmm_shim.cpp b/indra/media_plugins/winmmshim/winmm_shim.cpp index 9563a3b664..f7df3b19a0 100644 --- a/indra/media_plugins/winmmshim/winmm_shim.cpp +++ b/indra/media_plugins/winmmshim/winmm_shim.cpp @@ -2,25 +2,31 @@ * @file winmmshim.cpp * @brief controls volume level of process by intercepting calls to winmm.dll * - * $LicenseInfo:firstyear=2010&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. + * $LicenseInfo:firstyear=2010&license=viewergpl$ + * + * Copyright (c) 2010, 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 - * License as published by the Free Software Foundation; - * version 2.1 of the License only. + * Second Life Viewer Source Code + * The source code in this file ("Source Code") is provided by Linden Lab + * to you under the terms of the GNU General Public License, version 2.0 + * ("GPL"), unless you have obtained a separate licensing agreement + * ("Other License"), formally executed by you and Linden Lab. Terms of + * the GPL can be found in doc/GPL-license.txt in this distribution, or + * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. + * There are special exceptions to the terms and conditions of the GPL as + * it is applied to this Source Code. View the full text of the exception + * in the file doc/FLOSS-exception.txt in this software distribution, or + * online at + * http://secondlifegrid.net/programs/open_source/licensing/flossexception * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * By copying, modifying or distributing this software, you acknowledge + * that you have read and understood your obligations described above, + * and agree to abide by those obligations. * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO + * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, + * COMPLETENESS OR PERFORMANCE. * $/LicenseInfo$ */ #include "forwarding_api.h" @@ -114,8 +120,8 @@ extern "C" { // zero out the audio buffer when muted memset(pwh->lpData, 0, pwh->dwBufferLength); } - else if (sVolumeLevel != 1.f) - { // need to apply volume level + else + { wave_out_map_t::iterator found_it = sWaveOuts.find(hwo); if (found_it != sWaveOuts.end()) { @@ -138,11 +144,10 @@ extern "C" // copy volume level 4 times into 64 bit MMX register __m64 volume_64 = _mm_set_pi16(volume_16, volume_16, volume_16, volume_16); - __m64* sample_64; - __m64* last_sample_64 = (__m64*)(pwh->lpData + pwh->dwBufferLength - sizeof(__m64)); + __m64 *sample_64; // for everything that can be addressed in 64 bit multiples... for (sample_64 = (__m64*)pwh->lpData; - sample_64 <= last_sample_64; + sample_64 < (__m64*)(pwh->lpData + pwh->dwBufferLength); ++sample_64) { //...multiply the samples by the volume... @@ -157,11 +162,10 @@ extern "C" // the captain has turned off the MMX sign, you are now free to use floating point registers _mm_empty(); - // finish remaining samples that didn't fit into 64 bit register for (short* sample_16 = (short*)sample_64; sample_16 < (short*)(pwh->lpData + pwh->dwBufferLength); ++sample_16) - { + { // finish remaining samples that didn't fit into 64 bit register *sample_16 = (*sample_16 * volume_16) >> 15; } |