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.txt13
-rw-r--r--indra/media_plugins/webkit/dummy_volume_catcher.cpp35
-rw-r--r--indra/media_plugins/webkit/linux_volume_catcher.cpp40
-rw-r--r--indra/media_plugins/webkit/mac_volume_catcher.cpp39
-rw-r--r--indra/media_plugins/webkit/media_plugin_webkit.cpp149
-rw-r--r--indra/media_plugins/webkit/volume_catcher.h35
-rw-r--r--indra/media_plugins/webkit/windows_volume_catcher.cpp282
7 files changed, 231 insertions, 362 deletions
diff --git a/indra/media_plugins/webkit/CMakeLists.txt b/indra/media_plugins/webkit/CMakeLists.txt
index 1a559ed39c..57478ddf27 100644
--- a/indra/media_plugins/webkit/CMakeLists.txt
+++ b/indra/media_plugins/webkit/CMakeLists.txt
@@ -50,8 +50,12 @@ set(media_plugin_webkit_LINK_LIBRARIES
)
# Select which VolumeCatcher implementation to use
-if (LINUX AND PULSEAUDIO)
- list(APPEND media_plugin_webkit_SOURCE_FILES linux_volume_catcher.cpp)
+if (LINUX)
+ if (PULSEAUDIO_FOUND)
+ list(APPEND media_plugin_webkit_SOURCE_FILES linux_volume_catcher.cpp)
+ else (PULSEAUDIO_FOUND)
+ list(APPEND media_plugin_webkit_SOURCE_FILES dummy_volume_catcher.cpp)
+ endif (PULSEAUDIO_FOUND)
list(APPEND media_plugin_webkit_LINK_LIBRARIES
${UI_LIBRARIES} # for glib/GTK
)
@@ -65,10 +69,7 @@ elseif (DARWIN)
)
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)
+endif (LINUX)
set_source_files_properties(${media_plugin_webkit_HEADER_FILES}
PROPERTIES HEADER_FILE_ONLY TRUE)
diff --git a/indra/media_plugins/webkit/dummy_volume_catcher.cpp b/indra/media_plugins/webkit/dummy_volume_catcher.cpp
index 45b2c62eba..d54b31b2ae 100644
--- a/indra/media_plugins/webkit/dummy_volume_catcher.cpp
+++ b/indra/media_plugins/webkit/dummy_volume_catcher.cpp
@@ -3,30 +3,25 @@
* @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.
- *
+ * $LicenseInfo:firstyear=2010&license=viewerlgpl$
* 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
+ * 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.
*
- * 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
+ * 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.
*
- * 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.
+ * 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
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* @endcond
*/
diff --git a/indra/media_plugins/webkit/linux_volume_catcher.cpp b/indra/media_plugins/webkit/linux_volume_catcher.cpp
index 2e7fda865e..91be3a89e9 100644
--- a/indra/media_plugins/webkit/linux_volume_catcher.cpp
+++ b/indra/media_plugins/webkit/linux_volume_catcher.cpp
@@ -3,30 +3,25 @@
* @brief A Linux-specific, PulseAudio-specific hack to detect and volume-adjust new audio sources
*
* @cond
- * $LicenseInfo:firstyear=2010&license=viewergpl$
- *
- * Copyright (c) 2010, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2010&license=viewerlgpl$
* 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
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * 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
+ * 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.
*
- * 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.
+ * 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.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * 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
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* @endcond
*/
@@ -47,6 +42,7 @@
extern "C" {
#include <glib.h>
+#include <glib-object.h>
#include <pulse/introspect.h>
#include <pulse/context.h>
@@ -220,6 +216,10 @@ void VolumeCatcherImpl::init()
mGotSyms = loadsyms("libpulse-mainloop-glib.so.0");
if (!mGotSyms) return;
+ // better make double-sure glib itself is initialized properly.
+ if (!g_thread_supported ()) g_thread_init (NULL);
+ g_type_init();
+
mMainloop = llpa_glib_mainloop_new(g_main_context_default());
if (mMainloop)
{
diff --git a/indra/media_plugins/webkit/mac_volume_catcher.cpp b/indra/media_plugins/webkit/mac_volume_catcher.cpp
index 9788f10a58..8a06bb8487 100644
--- a/indra/media_plugins/webkit/mac_volume_catcher.cpp
+++ b/indra/media_plugins/webkit/mac_volume_catcher.cpp
@@ -1,32 +1,27 @@
/**
- * @file dummy_volume_catcher.cpp
+ * @file mac_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.
- *
+ * $LicenseInfo:firstyear=2010&license=viewerlgpl$
* 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
+ * 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.
*
- * 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
+ * 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.
*
- * 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.
+ * 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
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* @endcond
*/
@@ -98,7 +93,7 @@ VolumeCatcherImpl *VolumeCatcherImpl::getInstance()
VolumeCatcherImpl::VolumeCatcherImpl()
{
mVolume = 1.0; // default to full volume
- mPan = 0.5; // and center pan
+ mPan = 0.0; // and center pan
ComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
diff --git a/indra/media_plugins/webkit/media_plugin_webkit.cpp b/indra/media_plugins/webkit/media_plugin_webkit.cpp
index 47766a24cb..bd1a44a930 100644
--- a/indra/media_plugins/webkit/media_plugin_webkit.cpp
+++ b/indra/media_plugins/webkit/media_plugin_webkit.cpp
@@ -3,30 +3,25 @@
* @brief Webkit plugin for LLMedia API plugin system
*
* @cond
- * $LicenseInfo:firstyear=2008&license=viewergpl$
- *
- * Copyright (c) 2008, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2008&license=viewerlgpl$
* 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
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * 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
+ * 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.
*
- * 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.
+ * 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.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * 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
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* @endcond
*/
@@ -46,6 +41,10 @@
// set to 1 if you're using the version of llqtwebkit that's QPixmap-ified
#if LL_LINUX
# define LL_QTWEBKIT_USES_PIXMAPS 0
+extern "C" {
+# include <glib.h>
+# include <glib-object.h>
+}
#else
# define LL_QTWEBKIT_USES_PIXMAPS 0
#endif // LL_LINUX
@@ -60,7 +59,7 @@
#endif
#if LL_WINDOWS
- // *NOTE:Mani - This captures the module handle fo rthe dll. This is used below
+ // *NOTE:Mani - This captures the module handle for the dll. This is used below
// to get the path to this dll for webkit initialization.
// I don't know how/if this can be done with apr...
namespace { HMODULE gModuleHandle;};
@@ -116,6 +115,7 @@ private:
F32 mBackgroundR;
F32 mBackgroundG;
F32 mBackgroundB;
+ std::string mTarget;
VolumeCatcher mVolumeCatcher;
@@ -129,6 +129,16 @@ private:
//
void update(int milliseconds)
{
+#if LL_QTLINUX_DOESNT_HAVE_GLIB
+ // pump glib generously, as Linux browser plugins are on the
+ // glib main loop, even if the browser itself isn't - ugh
+ // This is NOT NEEDED if Qt itself was built with glib
+ // mainloop integration.
+ GMainContext *mainc = g_main_context_default();
+ while(g_main_context_iteration(mainc, FALSE));
+#endif // LL_QTLINUX_DOESNT_HAVE_GLIB
+
+ // pump qt
LLQtWebKit::getInstance()->pump( milliseconds );
mVolumeCatcher.pump();
@@ -200,6 +210,14 @@ private:
}
std::string application_dir = std::string( cwd );
+#if LL_LINUX
+ // take care to initialize glib properly, because some
+ // versions of Qt don't, and we indirectly need it for (some
+ // versions of) Flash to not crash the browser.
+ if (!g_thread_supported ()) g_thread_init (NULL);
+ g_type_init();
+#endif
+
#if LL_DARWIN
// When running under the Xcode debugger, there's a setting called "Break on Debugger()/DebugStr()" which defaults to being turned on.
// This causes the environment variable USERBREAK to be set to 1, which causes these legacy calls to break into the debugger.
@@ -286,7 +304,7 @@ private:
LLQtWebKit::getInstance()->enableJavascript( mJavascriptEnabled );
// create single browser window
- mBrowserWindowId = LLQtWebKit::getInstance()->createBrowserWindow( mWidth, mHeight );
+ mBrowserWindowId = LLQtWebKit::getInstance()->createBrowserWindow( mWidth, mHeight, mTarget);
// tell LLQtWebKit about the size of the browser window
LLQtWebKit::getInstance()->setSize( mBrowserWindowId, mWidth, mHeight );
@@ -296,12 +314,12 @@ private:
// append details to agent string
LLQtWebKit::getInstance()->setBrowserAgentId( mUserAgent );
-
+
#if !LL_QTWEBKIT_USES_PIXMAPS
// don't flip bitmap
LLQtWebKit::getInstance()->flipWindow( mBrowserWindowId, true );
#endif // !LL_QTWEBKIT_USES_PIXMAPS
-
+
// set background color
// convert background color channels from [0.0, 1.0] to [0, 255];
LLQtWebKit::getInstance()->setBackgroundColor( mBrowserWindowId, int(mBackgroundR * 255.0f), int(mBackgroundG * 255.0f), int(mBackgroundB * 255.0f) );
@@ -487,9 +505,9 @@ private:
void onClickLinkHref(const EventType& event)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "click_href");
- message.setValue("uri", event.getStringValue());
- message.setValue("target", event.getStringValue2());
- message.setValueU32("target_type", event.getLinkType());
+ message.setValue("uri", event.getEventUri());
+ message.setValue("target", event.getStringValue());
+ message.setValue("uuid", event.getStringValue2());
sendMessage(message);
}
@@ -498,7 +516,7 @@ private:
void onClickLinkNoFollow(const EventType& event)
{
LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "click_nofollow");
- message.setValue("uri", event.getStringValue());
+ message.setValue("uri", event.getEventUri());
sendMessage(message);
}
@@ -514,6 +532,42 @@ private:
// message.setValueBoolean("dead", (event.getIntValue() != 0))
sendMessage(message);
}
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // virtual
+ void onWindowCloseRequested(const EventType& event)
+ {
+ LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "close_request");
+ message.setValue("uuid", event.getStringValue());
+ sendMessage(message);
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // virtual
+ void onWindowGeometryChangeRequested(const EventType& event)
+ {
+ int x, y, width, height;
+ event.getRectValue(x, y, width, height);
+
+ // This sometimes gets called with a zero-size request. Don't pass these along.
+ if(width > 0 && height > 0)
+ {
+ LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER, "geometry_change");
+ message.setValue("uuid", event.getStringValue());
+ message.setValueS32("x", x);
+ message.setValueS32("y", y);
+ message.setValueS32("width", width);
+ message.setValueS32("height", height);
+ sendMessage(message);
+ }
+ }
+
+ ////////////////////////////////////////////////////////////////////////////////
+ // virtual
+ std::string onRequestFilePicker( const EventType& eventIn )
+ {
+ return blockingPickFile();
+ }
LLQtWebKit::EKeyboardModifier decodeModifiers(std::string &modifiers)
{
@@ -659,6 +713,26 @@ private:
}
}
+
+ std::string mPickedFile;
+
+ std::string blockingPickFile(void)
+ {
+ mPickedFile.clear();
+
+ LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "pick_file");
+ message.setValueBoolean("blocking_request", true);
+
+ // The "blocking_request" key in the message means this sendMessage call will block until a response is received.
+ sendMessage(message);
+
+ return mPickedFile;
+ }
+
+ void onPickFileResponse(const std::string &file)
+ {
+ mPickedFile = file;
+ }
};
@@ -797,6 +871,8 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
{
if(message_name == "init")
{
+ mTarget = message_in.getValue("target");
+
// This is the media init message -- all necessary data for initialization should have been received.
if(initBrowser())
{
@@ -1016,10 +1092,14 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
LLQtWebKit::getInstance()->userAction( mBrowserWindowId, LLQtWebKit::UA_EDIT_PASTE );
checkEditState();
}
+ if(message_name == "pick_file_response")
+ {
+ onPickFileResponse(message_in.getValue("file"));
+ }
else
{
// std::cerr << "MediaPluginWebKit::receiveMessage: unknown media message: " << message_string << std::endl;
- };
+ }
}
else if(message_class == LLPLUGIN_MESSAGE_CLASS_MEDIA_BROWSER)
{
@@ -1119,6 +1199,17 @@ void MediaPluginWebKit::receiveMessage(const char *message_string)
}
}
}
+ else if(message_name == "proxy_window_opened")
+ {
+ std::string target = message_in.getValue("target");
+ std::string uuid = message_in.getValue("uuid");
+ LLQtWebKit::getInstance()->proxyWindowOpened(mBrowserWindowId, target, uuid);
+ }
+ else if(message_name == "proxy_window_closed")
+ {
+ std::string uuid = message_in.getValue("uuid");
+ LLQtWebKit::getInstance()->proxyWindowClosed(mBrowserWindowId, uuid);
+ }
else
{
// std::cerr << "MediaPluginWebKit::receiveMessage: unknown media_browser message: " << message_string << std::endl;
diff --git a/indra/media_plugins/webkit/volume_catcher.h b/indra/media_plugins/webkit/volume_catcher.h
index 77b10cfed0..337f2913d3 100644
--- a/indra/media_plugins/webkit/volume_catcher.h
+++ b/indra/media_plugins/webkit/volume_catcher.h
@@ -3,30 +3,25 @@
* @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.
- *
+ * $LicenseInfo:firstyear=2010&license=viewerlgpl$
* 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
+ * 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.
*
- * 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
+ * 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.
*
- * 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.
+ * 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
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
* @endcond
*/
diff --git a/indra/media_plugins/webkit/windows_volume_catcher.cpp b/indra/media_plugins/webkit/windows_volume_catcher.cpp
index 8debe8fac6..5fb84756ee 100644
--- a/indra/media_plugins/webkit/windows_volume_catcher.cpp
+++ b/indra/media_plugins/webkit/windows_volume_catcher.cpp
@@ -3,292 +3,83 @@
* @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.
- *
+ * $LicenseInfo:firstyear=2010&license=viewerlgpl$
* 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
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * 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
+ * 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.
*
- * 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.
+ * 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.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * 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
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/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
+#include "llsingleton.h"
+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 (WINAPI *set_volume_func_t)(F32);
+ typedef void (WINAPI *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);
-
- 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);
}
-
- mVolume = volume;
}
void VolumeCatcherImpl::setPan(F32 pan)
@@ -323,3 +114,4 @@ void VolumeCatcher::pump()
// No periodic tasks are necessary for this implementation.
}
+