/indra/media_plugins/base/media_plugin_base.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 206 lines · 96 code · 24 blank · 86 comment · 6 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. #include "linden_common.h"
  31. #include "media_plugin_base.h"
  32. // TODO: Make sure that the only symbol exported from this library is LLPluginInitEntryPoint
  33. ////////////////////////////////////////////////////////////////////////////////
  34. /// Media plugin constructor.
  35. ///
  36. /// @param[in] host_send_func Function for sending messages from plugin to plugin loader shell
  37. /// @param[in] host_user_data Message data for messages from plugin to plugin loader shell
  38. MediaPluginBase::MediaPluginBase(
  39. LLPluginInstance::sendMessageFunction host_send_func,
  40. void *host_user_data )
  41. {
  42. mHostSendFunction = host_send_func;
  43. mHostUserData = host_user_data;
  44. mDeleteMe = false;
  45. mPixels = 0;
  46. mWidth = 0;
  47. mHeight = 0;
  48. mTextureWidth = 0;
  49. mTextureHeight = 0;
  50. mDepth = 0;
  51. mStatus = STATUS_NONE;
  52. }
  53. /**
  54. * Converts current media status enum value into string (STATUS_LOADING into "loading", etc.)
  55. *
  56. * @return Media status string ("loading", "playing", "paused", etc)
  57. *
  58. */
  59. std::string MediaPluginBase::statusString()
  60. {
  61. std::string result;
  62. switch(mStatus)
  63. {
  64. case STATUS_LOADING: result = "loading"; break;
  65. case STATUS_LOADED: result = "loaded"; break;
  66. case STATUS_ERROR: result = "error"; break;
  67. case STATUS_PLAYING: result = "playing"; break;
  68. case STATUS_PAUSED: result = "paused"; break;
  69. case STATUS_DONE: result = "done"; break;
  70. default:
  71. // keep the empty string
  72. break;
  73. }
  74. return result;
  75. }
  76. /**
  77. * Set media status.
  78. *
  79. * @param[in] status Media status (STATUS_LOADING, STATUS_PLAYING, STATUS_PAUSED, etc)
  80. *
  81. */
  82. void MediaPluginBase::setStatus(EStatus status)
  83. {
  84. if(mStatus != status)
  85. {
  86. mStatus = status;
  87. sendStatus();
  88. }
  89. }
  90. /**
  91. * Receive message from plugin loader shell.
  92. *
  93. * @param[in] message_string Message string
  94. * @param[in] user_data Message data
  95. *
  96. */
  97. void MediaPluginBase::staticReceiveMessage(const char *message_string, void **user_data)
  98. {
  99. MediaPluginBase *self = (MediaPluginBase*)*user_data;
  100. if(self != NULL)
  101. {
  102. self->receiveMessage(message_string);
  103. // If the plugin has processed the delete message, delete it.
  104. if(self->mDeleteMe)
  105. {
  106. delete self;
  107. *user_data = NULL;
  108. }
  109. }
  110. }
  111. /**
  112. * Send message to plugin loader shell.
  113. *
  114. * @param[in] message Message data being sent to plugin loader shell
  115. *
  116. */
  117. void MediaPluginBase::sendMessage(const LLPluginMessage &message)
  118. {
  119. std::string output = message.generate();
  120. mHostSendFunction(output.c_str(), &mHostUserData);
  121. }
  122. /**
  123. * Notifies plugin loader shell that part of display area needs to be redrawn.
  124. *
  125. * @param[in] left Left X coordinate of area to redraw (0,0 is at top left corner)
  126. * @param[in] top Top Y coordinate of area to redraw (0,0 is at top left corner)
  127. * @param[in] right Right X-coordinate of area to redraw (0,0 is at top left corner)
  128. * @param[in] bottom Bottom Y-coordinate of area to redraw (0,0 is at top left corner)
  129. *
  130. */
  131. void MediaPluginBase::setDirty(int left, int top, int right, int bottom)
  132. {
  133. LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "updated");
  134. message.setValueS32("left", left);
  135. message.setValueS32("top", top);
  136. message.setValueS32("right", right);
  137. message.setValueS32("bottom", bottom);
  138. sendMessage(message);
  139. }
  140. /**
  141. * Sends "media_status" message to plugin loader shell ("loading", "playing", "paused", etc.)
  142. *
  143. */
  144. void MediaPluginBase::sendStatus()
  145. {
  146. LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "media_status");
  147. message.setValue("status", statusString());
  148. sendMessage(message);
  149. }
  150. #if LL_WINDOWS
  151. # define LLSYMEXPORT __declspec(dllexport)
  152. #elif LL_LINUX
  153. # define LLSYMEXPORT __attribute__ ((visibility("default")))
  154. #else
  155. # define LLSYMEXPORT /**/
  156. #endif
  157. extern "C"
  158. {
  159. LLSYMEXPORT int LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data);
  160. }
  161. /**
  162. * Plugin initialization and entry point. Establishes communication channel for messages between plugin and plugin loader shell. TODO:DOC - Please check!
  163. *
  164. * @param[in] host_send_func Function for sending messages from plugin to plugin loader shell
  165. * @param[in] host_user_data Message data for messages from plugin to plugin loader shell
  166. * @param[out] plugin_send_func Function for plugin to receive messages from plugin loader shell
  167. * @param[out] plugin_user_data Pointer to plugin instance
  168. *
  169. * @return int, where 0=success
  170. *
  171. */
  172. LLSYMEXPORT int
  173. LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data, LLPluginInstance::sendMessageFunction *plugin_send_func, void **plugin_user_data)
  174. {
  175. return init_media_plugin(host_send_func, host_user_data, plugin_send_func, plugin_user_data);
  176. }
  177. #ifdef WIN32
  178. int WINAPI DllEntryPoint( HINSTANCE hInstance, unsigned long reason, void* params )
  179. {
  180. return 1;
  181. }
  182. #endif