summaryrefslogtreecommitdiff
path: root/indra/media_plugins/webkit
diff options
context:
space:
mode:
Diffstat (limited to 'indra/media_plugins/webkit')
-rw-r--r--indra/media_plugins/webkit/CMakeLists.txt27
-rw-r--r--indra/media_plugins/webkit/dummy_volume_catcher.cpp63
-rw-r--r--indra/media_plugins/webkit/linux_volume_catcher.cpp72
-rw-r--r--indra/media_plugins/webkit/mac_volume_catcher.cpp273
-rw-r--r--indra/media_plugins/webkit/media_plugin_webkit.cpp33
-rw-r--r--indra/media_plugins/webkit/volume_catcher.h59
-rw-r--r--indra/media_plugins/webkit/windows_volume_catcher.cpp325
7 files changed, 792 insertions, 60 deletions
diff --git a/indra/media_plugins/webkit/CMakeLists.txt b/indra/media_plugins/webkit/CMakeLists.txt
index 9f66a77c64..1a559ed39c 100644
--- a/indra/media_plugins/webkit/CMakeLists.txt
+++ b/indra/media_plugins/webkit/CMakeLists.txt
@@ -36,6 +36,10 @@ set(media_plugin_webkit_SOURCE_FILES
media_plugin_webkit.cpp
)
+set(media_plugin_webkit_HEADER_FILES
+ volume_catcher.h
+ )
+
set(media_plugin_webkit_LINK_LIBRARIES
${LLPLUGIN_LIBRARIES}
${MEDIA_PLUGIN_BASE_LIBRARIES}
@@ -45,12 +49,31 @@ set(media_plugin_webkit_LINK_LIBRARIES
${PULSEAUDIO_LIBRARIES}
)
-if (LINUX)
+# Select which VolumeCatcher implementation to use
+if (LINUX AND PULSEAUDIO)
list(APPEND media_plugin_webkit_SOURCE_FILES linux_volume_catcher.cpp)
list(APPEND media_plugin_webkit_LINK_LIBRARIES
${UI_LIBRARIES} # for glib/GTK
)
-endif (LINUX)
+elseif (DARWIN)
+ list(APPEND media_plugin_webkit_SOURCE_FILES mac_volume_catcher.cpp)
+ find_library(CORESERVICES_LIBRARY CoreServices)
+ find_library(AUDIOUNIT_LIBRARY AudioUnit)
+ list(APPEND media_plugin_webkit_LINK_LIBRARIES
+ ${CORESERVICES_LIBRARY} # for Component Manager calls
+ ${AUDIOUNIT_LIBRARY} # for AudioUnit calls
+ )
+elseif (WINDOWS)
+ list(APPEND media_plugin_webkit_SOURCE_FILES windows_volume_catcher.cpp)
+else (LINUX AND PULSEAUDIO)
+ # All other platforms use the dummy volume catcher for now.
+ list(APPEND media_plugin_webkit_SOURCE_FILES dummy_volume_catcher.cpp)
+endif (LINUX AND PULSEAUDIO)
+
+set_source_files_properties(${media_plugin_webkit_HEADER_FILES}
+ PROPERTIES HEADER_FILE_ONLY TRUE)
+
+list(APPEND media_plugin_webkit_SOURCE_FILES ${media_plugin_webkit_HEADER_FILES})
add_library(media_plugin_webkit
SHARED
diff --git a/indra/media_plugins/webkit/dummy_volume_catcher.cpp b/indra/media_plugins/webkit/dummy_volume_catcher.cpp
new file mode 100644
index 0000000000..45b2c62eba
--- /dev/null
+++ b/indra/media_plugins/webkit/dummy_volume_catcher.cpp
@@ -0,0 +1,63 @@
+/**
+ * @file dummy_volume_catcher.cpp
+ * @brief A null implementation of the "VolumeCatcher" class for platforms where it's not implemented yet.
+ *
+ * @cond
+ * $LicenseInfo:firstyear=2010&license=viewergpl$
+ *
+ * Copyright (c) 2010, Linden Research, Inc.
+ *
+ * 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://secondlife.com/developers/opensource/gplv2
+ *
+ * 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://secondlife.com/developers/opensource/flossexception
+ *
+ * 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.
+ *
+ * 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$
+ * @endcond
+ */
+
+#include "volume_catcher.h"
+
+
+class VolumeCatcherImpl
+{
+};
+
+/////////////////////////////////////////////////////
+
+VolumeCatcher::VolumeCatcher()
+{
+ pimpl = NULL;
+}
+
+VolumeCatcher::~VolumeCatcher()
+{
+}
+
+void VolumeCatcher::setVolume(F32 volume)
+{
+}
+
+void VolumeCatcher::setPan(F32 pan)
+{
+}
+
+void VolumeCatcher::pump()
+{
+}
+
diff --git a/indra/media_plugins/webkit/linux_volume_catcher.cpp b/indra/media_plugins/webkit/linux_volume_catcher.cpp
index 52ab766f7f..2e7fda865e 100644
--- a/indra/media_plugins/webkit/linux_volume_catcher.cpp
+++ b/indra/media_plugins/webkit/linux_volume_catcher.cpp
@@ -42,11 +42,9 @@
#include "linden_common.h"
-#include "linux_volume_catcher.h"
+#include "volume_catcher.h"
-#if LL_PULSEAUDIO_ENABLED
-
extern "C" {
#include <glib.h>
@@ -161,11 +159,11 @@ extern "C" {
}
-class LinuxVolumeCatcherImpl
+class VolumeCatcherImpl
{
public:
- LinuxVolumeCatcherImpl();
- ~LinuxVolumeCatcherImpl();
+ VolumeCatcherImpl();
+ ~VolumeCatcherImpl();
void setVolume(F32 volume);
void pump(void);
@@ -189,7 +187,7 @@ public:
bool mGotSyms;
};
-LinuxVolumeCatcherImpl::LinuxVolumeCatcherImpl()
+VolumeCatcherImpl::VolumeCatcherImpl()
: mDesiredVolume(0.0f),
mMainloop(NULL),
mPAContext(NULL),
@@ -199,17 +197,17 @@ LinuxVolumeCatcherImpl::LinuxVolumeCatcherImpl()
init();
}
-LinuxVolumeCatcherImpl::~LinuxVolumeCatcherImpl()
+VolumeCatcherImpl::~VolumeCatcherImpl()
{
cleanup();
}
-bool LinuxVolumeCatcherImpl::loadsyms(std::string pulse_dso_name)
+bool VolumeCatcherImpl::loadsyms(std::string pulse_dso_name)
{
return grab_pa_syms(pulse_dso_name);
}
-void LinuxVolumeCatcherImpl::init()
+void VolumeCatcherImpl::init()
{
// try to be as defensive as possible because PA's interface is a
// bit fragile and (for our purposes) we'd rather simply not function
@@ -262,7 +260,7 @@ void LinuxVolumeCatcherImpl::init()
}
}
-void LinuxVolumeCatcherImpl::cleanup()
+void VolumeCatcherImpl::cleanup()
{
mConnected = false;
@@ -280,7 +278,7 @@ void LinuxVolumeCatcherImpl::cleanup()
mMainloop = NULL;
}
-void LinuxVolumeCatcherImpl::setVolume(F32 volume)
+void VolumeCatcherImpl::setVolume(F32 volume)
{
mDesiredVolume = volume;
@@ -294,13 +292,13 @@ void LinuxVolumeCatcherImpl::setVolume(F32 volume)
pump();
}
-void LinuxVolumeCatcherImpl::pump()
+void VolumeCatcherImpl::pump()
{
gboolean may_block = FALSE;
g_main_context_iteration(g_main_context_default(), may_block);
}
-void LinuxVolumeCatcherImpl::connected_okay()
+void VolumeCatcherImpl::connected_okay()
{
pa_operation *op;
@@ -324,7 +322,7 @@ void LinuxVolumeCatcherImpl::connected_okay()
}
}
-void LinuxVolumeCatcherImpl::update_all_volumes(F32 volume)
+void VolumeCatcherImpl::update_all_volumes(F32 volume)
{
for (std::set<U32>::iterator it = mSinkInputIndices.begin();
it != mSinkInputIndices.end(); ++it)
@@ -333,7 +331,7 @@ void LinuxVolumeCatcherImpl::update_all_volumes(F32 volume)
}
}
-void LinuxVolumeCatcherImpl::update_index_volume(U32 index, F32 volume)
+void VolumeCatcherImpl::update_index_volume(U32 index, F32 volume)
{
static pa_cvolume cvol;
llpa_cvolume_set(&cvol, mSinkInputNumChannels[index],
@@ -355,7 +353,7 @@ void LinuxVolumeCatcherImpl::update_index_volume(U32 index, F32 volume)
void callback_discovered_sinkinput(pa_context *context, const pa_sink_input_info *sii, int eol, void *userdata)
{
- LinuxVolumeCatcherImpl *impl = dynamic_cast<LinuxVolumeCatcherImpl*>((LinuxVolumeCatcherImpl*)userdata);
+ VolumeCatcherImpl *impl = dynamic_cast<VolumeCatcherImpl*>((VolumeCatcherImpl*)userdata);
llassert(impl);
if (0 == eol)
@@ -386,7 +384,7 @@ void callback_discovered_sinkinput(pa_context *context, const pa_sink_input_info
void callback_subscription_alert(pa_context *context, pa_subscription_event_type_t t, uint32_t index, void *userdata)
{
- LinuxVolumeCatcherImpl *impl = dynamic_cast<LinuxVolumeCatcherImpl*>((LinuxVolumeCatcherImpl*)userdata);
+ VolumeCatcherImpl *impl = dynamic_cast<VolumeCatcherImpl*>((VolumeCatcherImpl*)userdata);
llassert(impl);
switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) {
@@ -420,7 +418,7 @@ void callback_subscription_alert(pa_context *context, pa_subscription_event_type
void callback_context_state(pa_context *context, void *userdata)
{
- LinuxVolumeCatcherImpl *impl = dynamic_cast<LinuxVolumeCatcherImpl*>((LinuxVolumeCatcherImpl*)userdata);
+ VolumeCatcherImpl *impl = dynamic_cast<VolumeCatcherImpl*>((VolumeCatcherImpl*)userdata);
llassert(impl);
switch (llpa_context_get_state(context))
@@ -441,48 +439,30 @@ void callback_context_state(pa_context *context, void *userdata)
/////////////////////////////////////////////////////
-LinuxVolumeCatcher::LinuxVolumeCatcher()
+VolumeCatcher::VolumeCatcher()
{
- pimpl = new LinuxVolumeCatcherImpl();
+ pimpl = new VolumeCatcherImpl();
}
-LinuxVolumeCatcher::~LinuxVolumeCatcher()
+VolumeCatcher::~VolumeCatcher()
{
delete pimpl;
pimpl = NULL;
}
-void LinuxVolumeCatcher::setVolume(F32 volume)
+void VolumeCatcher::setVolume(F32 volume)
{
llassert(pimpl);
pimpl->setVolume(volume);
}
-void LinuxVolumeCatcher::pump()
-{
- llassert(pimpl);
- pimpl->pump();
-}
-
-#else // !LL_PULSEAUDIO_ENABLED
-
-// stub.
-
-LinuxVolumeCatcher::LinuxVolumeCatcher()
-{
- pimpl = NULL;
-}
-
-LinuxVolumeCatcher::~LinuxVolumeCatcher()
+void VolumeCatcher::setPan(F32 pan)
{
+ // TODO: implement this (if possible)
}
-void LinuxVolumeCatcher::setVolume(F32 volume)
-{
-}
-
-void LinuxVolumeCatcher::pump()
+void VolumeCatcher::pump()
{
+ llassert(pimpl);
+ pimpl->pump();
}
-
-#endif // LL_PULSEAUDIO_ENABLED
diff --git a/indra/media_plugins/webkit/mac_volume_catcher.cpp b/indra/media_plugins/webkit/mac_volume_catcher.cpp
new file mode 100644
index 0000000000..9788f10a58
--- /dev/null
+++ b/indra/media_plugins/webkit/mac_volume_catcher.cpp
@@ -0,0 +1,273 @@
+/**
+ * @file dummy_volume_catcher.cpp
+ * @brief A Mac OS X specific hack to control the volume level of all audio channels opened by a process.
+ *
+ * @cond
+ * $LicenseInfo:firstyear=2010&license=viewergpl$
+ *
+ * Copyright (c) 2010, Linden Research, Inc.
+ *
+ * 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://secondlife.com/developers/opensource/gplv2
+ *
+ * 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://secondlife.com/developers/opensource/flossexception
+ *
+ * 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.
+ *
+ * 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$
+ * @endcond
+ */
+
+/**************************************************************************************************************
+ This code works by using CaptureComponent to capture the "Default Output" audio component
+ (kAudioUnitType_Output/kAudioUnitSubType_DefaultOutput) and delegating all calls to the original component.
+ It does this just to keep track of all instances of the default output component, so that it can set the
+ kHALOutputParam_Volume parameter on all of them to adjust the output volume.
+**************************************************************************************************************/
+
+#include "volume_catcher.h"
+
+#include <Carbon/Carbon.h>
+#include <QuickTime/QuickTime.h>
+#include <AudioUnit/AudioUnit.h>
+
+struct VolumeCatcherStorage;
+
+class VolumeCatcherImpl
+{
+public:
+
+ void setVolume(F32 volume);
+ void setPan(F32 pan);
+
+ void setInstanceVolume(VolumeCatcherStorage *instance);
+
+ std::list<VolumeCatcherStorage*> mComponentInstances;
+ Component mOriginalDefaultOutput;
+ Component mVolumeAdjuster;
+
+ static VolumeCatcherImpl *getInstance();
+private:
+ // This is a singleton class -- both callers and the component implementation should use getInstance() to find the instance.
+ VolumeCatcherImpl();
+ static VolumeCatcherImpl *sInstance;
+
+ // The singlar instance of this class is expected to last until the process exits.
+ // To ensure this, we declare the destructor here but never define it, so any code which attempts to destroy the instance will not link.
+ ~VolumeCatcherImpl();
+
+ F32 mVolume;
+ F32 mPan;
+};
+
+VolumeCatcherImpl *VolumeCatcherImpl::sInstance = NULL;;
+
+struct VolumeCatcherStorage
+{
+ ComponentInstance self;
+ ComponentInstance delegate;
+};
+
+static ComponentResult volume_catcher_component_entry(ComponentParameters *cp, Handle componentStorage);
+static ComponentResult volume_catcher_component_open(VolumeCatcherStorage *storage, ComponentInstance self);
+static ComponentResult volume_catcher_component_close(VolumeCatcherStorage *storage, ComponentInstance self);
+
+VolumeCatcherImpl *VolumeCatcherImpl::getInstance()
+{
+ if(!sInstance)
+ {
+ sInstance = new VolumeCatcherImpl;
+ }
+
+ return sInstance;
+}
+
+VolumeCatcherImpl::VolumeCatcherImpl()
+{
+ mVolume = 1.0; // default to full volume
+ mPan = 0.5; // and center pan
+
+ ComponentDescription desc;
+ desc.componentType = kAudioUnitType_Output;
+ desc.componentSubType = kAudioUnitSubType_DefaultOutput;
+ desc.componentManufacturer = kAudioUnitManufacturer_Apple;
+ desc.componentFlags = 0;
+ desc.componentFlagsMask = 0;
+
+ // Find the original default output component
+ mOriginalDefaultOutput = FindNextComponent(NULL, &desc);
+
+ // Register our own output component with the same parameters
+ mVolumeAdjuster = RegisterComponent(&desc, NewComponentRoutineUPP(volume_catcher_component_entry), 0, NULL, NULL, NULL);
+
+ // Capture the original component, so we always get found instead.
+ CaptureComponent(mOriginalDefaultOutput, mVolumeAdjuster);
+
+}
+
+static ComponentResult volume_catcher_component_entry(ComponentParameters *cp, Handle componentStorage)
+{
+ ComponentResult result = badComponentSelector;
+ VolumeCatcherStorage *storage = (VolumeCatcherStorage*)componentStorage;
+
+ switch(cp->what)
+ {
+ case kComponentOpenSelect:
+// std::cerr << "kComponentOpenSelect" << std::endl;
+ result = CallComponentFunctionWithStorageProcInfo((Handle)storage, cp, (ProcPtr)volume_catcher_component_open, uppCallComponentOpenProcInfo);
+ break;
+
+ case kComponentCloseSelect:
+// std::cerr << "kComponentCloseSelect" << std::endl;
+ result = CallComponentFunctionWithStorageProcInfo((Handle)storage, cp, (ProcPtr)volume_catcher_component_close, uppCallComponentCloseProcInfo);
+ // CallComponentFunctionWithStorageProcInfo
+ break;
+
+ default:
+// std::cerr << "Delegating selector: " << cp->what << " to component instance " << storage->delegate << std::endl;
+ result = DelegateComponentCall(cp, storage->delegate);
+ break;
+ }
+
+ return result;
+}
+
+static ComponentResult volume_catcher_component_open(VolumeCatcherStorage *storage, ComponentInstance self)
+{
+ ComponentResult result = noErr;
+ VolumeCatcherImpl *impl = VolumeCatcherImpl::getInstance();
+
+ storage = new VolumeCatcherStorage;
+
+ storage->self = self;
+ storage->delegate = NULL;
+
+ result = OpenAComponent(impl->mOriginalDefaultOutput, &(storage->delegate));
+
+ if(result != noErr)
+ {
+// std::cerr << "OpenAComponent result = " << result << ", component ref = " << storage->delegate << std::endl;
+
+ // If we failed to open the delagate component, our open is going to fail. Clean things up.
+ delete storage;
+ }
+ else
+ {
+ // Success -- set up this component's storage
+ SetComponentInstanceStorage(self, (Handle)storage);
+
+ // add this instance to the global list
+ impl->mComponentInstances.push_back(storage);
+
+ // and set up the initial volume
+ impl->setInstanceVolume(storage);
+ }
+
+ return result;
+}
+
+static ComponentResult volume_catcher_component_close(VolumeCatcherStorage *storage, ComponentInstance self)
+{
+ ComponentResult result = noErr;
+
+ if(storage)
+ {
+ if(storage->delegate)
+ {
+ CloseComponent(storage->delegate);
+ storage->delegate = NULL;
+ }
+
+ VolumeCatcherImpl *impl = VolumeCatcherImpl::getInstance();
+ impl->mComponentInstances.remove(storage);
+ delete[] storage;
+ }
+
+ return result;
+}
+
+void VolumeCatcherImpl::setVolume(F32 volume)
+{
+ VolumeCatcherImpl *impl = VolumeCatcherImpl::getInstance();
+ impl->mVolume = volume;
+
+ // Iterate through all known instances, setting the volume on each.
+ for(std::list<VolumeCatcherStorage*>::iterator iter = mComponentInstances.begin(); iter != mComponentInstances.end(); ++iter)
+ {
+ impl->setInstanceVolume(*iter);
+ }
+}
+
+void VolumeCatcherImpl::setPan(F32 pan)
+{
+ VolumeCatcherImpl *impl = VolumeCatcherImpl::getInstance();
+ impl->mPan = pan;
+
+ // TODO: implement this.
+ // This will probably require adding a "panner" audio unit to the chain somehow.
+ // There's also a "3d mixer" component that we might be able to use...
+}
+
+void VolumeCatcherImpl::setInstanceVolume(VolumeCatcherStorage *instance)
+{
+// std::cerr << "Setting volume on component instance: " << (instance->delegate) << " to " << mVolume << std::endl;
+
+ OSStatus err = noErr;
+
+ if(instance && instance->delegate)
+ {
+ err = AudioUnitSetParameter(
+ instance->delegate,
+ kHALOutputParam_Volume,
+ kAudioUnitScope_Global,
+ 0,
+ mVolume,
+ 0);
+ }
+
+ if(err)
+ {
+// std::cerr << " AudioUnitSetParameter returned " << err << std::endl;
+ }
+}
+
+/////////////////////////////////////////////////////
+
+VolumeCatcher::VolumeCatcher()
+{
+ pimpl = VolumeCatcherImpl::getInstance();
+}
+
+VolumeCatcher::~VolumeCatcher()
+{
+ // Let the instance persist until exit.
+}
+
+void VolumeCatcher::setVolume(F32 volume)
+{
+ pimpl->setVolume(volume);
+}
+
+void VolumeCatcher::setPan(F32 pan)
+{
+ pimpl->setPan(pan);
+}
+
+void VolumeCatcher::pump()
+{
+ // No periodic tasks are necessary for this implementation.
+}
+
diff --git a/indra/media_plugins/webkit/media_plugin_webkit.cpp b/indra/media_plugins/webkit/media_plugin_webkit.cpp
index 5260636e11..47766a24cb 100644
--- a/indra/media_plugins/webkit/media_plugin_webkit.cpp
+++ b/indra/media_plugins/webkit/media_plugin_webkit.cpp
@@ -50,9 +50,7 @@
# define LL_QTWEBKIT_USES_PIXMAPS 0
#endif // LL_LINUX
-#if LL_LINUX
-# include "linux_volume_catcher.h"
-#endif // LL_LINUX
+# include "volume_catcher.h"
#if LL_WINDOWS
# include <direct.h>
@@ -119,9 +117,7 @@ private:
F32 mBackgroundG;
F32 mBackgroundB;
-#if LL_LINUX
- LinuxVolumeCatcher mLinuxVolumeCatcher;
-#endif // LL_LINUX
+ VolumeCatcher mVolumeCatcher;
void setInitState(int state)
{
@@ -135,9 +131,7 @@ private:
{
LLQtWebKit::getInstance()->pump( milliseconds );
-#if LL_LINUX
- mLinuxVolumeCatcher.pump();
-#endif // LL_LINUX
+ mVolumeCatcher.pump();
checkEditState();
@@ -508,6 +502,19 @@ private:
sendMessage(message);
}
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // virtual
+ void onCookieChanged(const EventType& event)
+ {
+ LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "cookie_set");
+ message.setValue("cookie", event.getStringValue());
+ // These could be passed through as well, but aren't really needed.
+// message.setValue("uri", event.getEventUri());
+// message.setValueBoolean("dead", (event.getIntValue() != 0))
+ sendMessage(message);
+ }
+
LLQtWebKit::EKeyboardModifier decodeModifiers(std::string &modifiers)
{
int result = 0;
@@ -1053,6 +1060,10 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
mJavascriptEnabled = message_in.getValueBoolean("enable");
//LLQtWebKit::getInstance()->enableJavascript( mJavascriptEnabled );
}
+ else if(message_name == "set_cookies")
+ {
+ LLQtWebKit::getInstance()->setCookies(message_in.getValue("cookies"));
+ }
else if(message_name == "proxy_setup")
{
bool val = message_in.getValueBoolean("enable");
@@ -1122,9 +1133,7 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
void MediaPluginWebKit::setVolume(F32 volume)
{
-#if LL_LINUX
- mLinuxVolumeCatcher.setVolume(volume);
-#endif // LL_LINUX
+ mVolumeCatcher.setVolume(volume);
}
int init_media_plugin(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data)
diff --git a/indra/media_plugins/webkit/volume_catcher.h b/indra/media_plugins/webkit/volume_catcher.h
new file mode 100644
index 0000000000..77b10cfed0
--- /dev/null
+++ b/indra/media_plugins/webkit/volume_catcher.h
@@ -0,0 +1,59 @@
+/**
+ * @file volume_catcher.h
+ * @brief Interface to a class with platform-specific implementations that allows control of the audio volume of all sources in the current process.
+ *
+ * @cond
+ * $LicenseInfo:firstyear=2010&license=viewergpl$
+ *
+ * Copyright (c) 2010, Linden Research, Inc.
+ *
+ * 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://secondlife.com/developers/opensource/gplv2
+ *
+ * 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://secondlife.com/developers/opensource/flossexception
+ *
+ * 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.
+ *
+ * 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$
+ * @endcond
+ */
+
+#ifndef VOLUME_CATCHER_H
+#define VOLUME_CATCHER_H
+
+#include "linden_common.h"
+
+class VolumeCatcherImpl;
+
+class VolumeCatcher
+{
+ public:
+ VolumeCatcher();
+ ~VolumeCatcher();
+
+ void setVolume(F32 volume); // 0.0 - 1.0
+
+ // Set the left-right pan of audio sources
+ // where -1.0 = left, 0 = center, and 1.0 = right
+ void setPan(F32 pan);
+
+ void pump(); // call this at least a few times a second if you can - it affects how quickly we can 'catch' a new audio source and adjust its volume
+
+ private:
+ VolumeCatcherImpl *pimpl;
+};
+
+#endif // VOLUME_CATCHER_H
diff --git a/indra/media_plugins/webkit/windows_volume_catcher.cpp b/indra/media_plugins/webkit/windows_volume_catcher.cpp
new file mode 100644
index 0000000000..8debe8fac6
--- /dev/null
+++ b/indra/media_plugins/webkit/windows_volume_catcher.cpp
@@ -0,0 +1,325 @@
+/**
+ * @file windows_volume_catcher.cpp
+ * @brief A Windows implementation of volume level control of all audio channels opened by a process.
+ *
+ * @cond
+ * $LicenseInfo:firstyear=2010&license=viewergpl$
+ *
+ * Copyright (c) 2010, Linden Research, Inc.
+ *
+ * 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://secondlife.com/developers/opensource/gplv2
+ *
+ * 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://secondlife.com/developers/opensource/flossexception
+ *
+ * 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.
+ *
+ * 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$
+ * @endcond
+ */
+
+#include "volume_catcher.h"
+#include <windows.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
+{
+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;
+
+ 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)
+ {
+ // 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);
+ }
+ }
+ }
+}
+
+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);
+
+ 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;
+}
+
+void VolumeCatcherImpl::setPan(F32 pan)
+{ // remember pan for calculating individual channel levels later
+ mPan = pan;
+}
+
+/////////////////////////////////////////////////////
+
+VolumeCatcher::VolumeCatcher()
+{
+ pimpl = VolumeCatcherImpl::getInstance();
+}
+
+VolumeCatcher::~VolumeCatcher()
+{
+ // Let the instance persist until exit.
+}
+
+void VolumeCatcher::setVolume(F32 volume)
+{
+ pimpl->setVolume(volume);
+}
+
+void VolumeCatcher::setPan(F32 pan)
+{
+ pimpl->setPan(pan);
+}
+
+void VolumeCatcher::pump()
+{
+ // No periodic tasks are necessary for this implementation.
+}
+