PageRenderTime 17ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/media_plugins/base/media_plugin_base.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 206 lines | 96 code | 24 blank | 86 comment | 5 complexity | f0f36df1c173460a48929f7692523a55 MD5 | raw file
  1/** 
  2 * @file media_plugin_base.cpp
  3 * @brief Media plugin base class for LLMedia API plugin system
  4 *
  5 * All plugins should be a subclass of MediaPluginBase. 
  6 *
  7 * @cond
  8 * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  9 * Second Life Viewer Source Code
 10 * Copyright (C) 2010, Linden Research, Inc.
 11 * 
 12 * This library is free software; you can redistribute it and/or
 13 * modify it under the terms of the GNU Lesser General Public
 14 * License as published by the Free Software Foundation;
 15 * version 2.1 of the License only.
 16 * 
 17 * This library is distributed in the hope that it will be useful,
 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 20 * Lesser General Public License for more details.
 21 * 
 22 * You should have received a copy of the GNU Lesser General Public
 23 * License along with this library; if not, write to the Free Software
 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 25 * 
 26 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 27 * $/LicenseInfo$
 28 * @endcond
 29 */
 30
 31#include "linden_common.h"
 32#include "media_plugin_base.h"
 33
 34
 35// TODO: Make sure that the only symbol exported from this library is LLPluginInitEntryPoint
 36////////////////////////////////////////////////////////////////////////////////
 37/// Media plugin constructor.
 38///
 39/// @param[in] host_send_func Function for sending messages from plugin to plugin loader shell
 40/// @param[in] host_user_data Message data for messages from plugin to plugin loader shell
 41
 42MediaPluginBase::MediaPluginBase(
 43	LLPluginInstance::sendMessageFunction host_send_func,
 44	void *host_user_data )
 45{
 46	mHostSendFunction = host_send_func;
 47	mHostUserData = host_user_data;
 48	mDeleteMe = false;
 49	mPixels = 0;
 50	mWidth = 0;
 51	mHeight = 0;
 52	mTextureWidth = 0;
 53	mTextureHeight = 0;
 54	mDepth = 0;
 55	mStatus = STATUS_NONE;
 56}
 57
 58/**
 59 * Converts current media status enum value into string (STATUS_LOADING into "loading", etc.)
 60 * 
 61 * @return Media status string ("loading", "playing", "paused", etc)
 62 *
 63 */
 64std::string MediaPluginBase::statusString()
 65{
 66	std::string result;
 67	
 68	switch(mStatus)
 69	{
 70		case STATUS_LOADING:	result = "loading";		break;
 71		case STATUS_LOADED:		result = "loaded";		break;
 72		case STATUS_ERROR:		result = "error";		break;
 73		case STATUS_PLAYING:	result = "playing";		break;
 74		case STATUS_PAUSED:		result = "paused";		break;
 75		case STATUS_DONE:		result = "done";		break;
 76		default:
 77			// keep the empty string
 78		break;
 79	}
 80	
 81	return result;
 82}
 83	
 84/**
 85 * Set media status.
 86 * 
 87 * @param[in] status Media status (STATUS_LOADING, STATUS_PLAYING, STATUS_PAUSED, etc)
 88 *
 89 */
 90void MediaPluginBase::setStatus(EStatus status)
 91{
 92	if(mStatus != status)
 93	{
 94		mStatus = status;
 95		sendStatus();
 96	}
 97}
 98
 99
100/**
101 * Receive message from plugin loader shell.
102 * 
103 * @param[in] message_string Message string
104 * @param[in] user_data Message data
105 *
106 */
107void MediaPluginBase::staticReceiveMessage(const char *message_string, void **user_data)
108{
109	MediaPluginBase *self = (MediaPluginBase*)*user_data;
110
111	if(self != NULL)
112	{
113		self->receiveMessage(message_string);
114
115		// If the plugin has processed the delete message, delete it.
116		if(self->mDeleteMe)
117		{
118			delete self;
119			*user_data = NULL;
120		}
121	}
122}
123
124/**
125 * Send message to plugin loader shell.
126 * 
127 * @param[in] message Message data being sent to plugin loader shell
128 *
129 */
130void MediaPluginBase::sendMessage(const LLPluginMessage &message)
131{
132	std::string output = message.generate();
133	mHostSendFunction(output.c_str(), &mHostUserData);
134}
135
136/**
137 * Notifies plugin loader shell that part of display area needs to be redrawn.
138 * 
139 * @param[in] left Left X coordinate of area to redraw (0,0 is at top left corner)
140 * @param[in] top Top Y coordinate of area to redraw (0,0 is at top left corner)
141 * @param[in] right Right X-coordinate of area to redraw (0,0 is at top left corner)
142 * @param[in] bottom Bottom Y-coordinate of area to redraw (0,0 is at top left corner)
143 *
144 */
145void MediaPluginBase::setDirty(int left, int top, int right, int bottom)
146{
147	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "updated");
148
149	message.setValueS32("left", left);
150	message.setValueS32("top", top);
151	message.setValueS32("right", right);
152	message.setValueS32("bottom", bottom);
153	
154	sendMessage(message);
155}
156
157/**
158 * Sends "media_status" message to plugin loader shell ("loading", "playing", "paused", etc.)
159 * 
160 */
161void MediaPluginBase::sendStatus()
162{
163	LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "media_status");
164
165	message.setValue("status", statusString());
166	
167	sendMessage(message);
168}
169
170
171#if LL_WINDOWS
172# define LLSYMEXPORT __declspec(dllexport)
173#elif LL_LINUX
174# define LLSYMEXPORT __attribute__ ((visibility("default")))
175#else
176# define LLSYMEXPORT /**/
177#endif
178
179extern "C"
180{
181	LLSYMEXPORT int LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data);
182}
183
184/**
185 * Plugin initialization and entry point. Establishes communication channel for messages between plugin and plugin loader shell.  TODO:DOC - Please check!
186 * 
187 * @param[in] host_send_func Function for sending messages from plugin to plugin loader shell
188 * @param[in] host_user_data Message data for messages from plugin to plugin loader shell
189 * @param[out] plugin_send_func Function for plugin to receive messages from plugin loader shell
190 * @param[out] plugin_user_data Pointer to plugin instance
191 *
192 * @return int, where 0=success
193 *
194 */
195LLSYMEXPORT int
196LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data)
197{
198	return init_media_plugin(host_send_func, host_user_data, plugin_send_func, plugin_user_data);
199}
200
201#ifdef WIN32
202int WINAPI DllEntryPoint( HINSTANCE hInstance, unsigned long reason, void* params )
203{
204	return 1;
205}
206#endif