media_plugin_base.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. * $LicenseInfo:firstyear=2008&license=viewergpl$
  8. *
  9. * Copyright (c) 2008-2009, Linden Research, Inc.
  10. *
  11. * Second Life Viewer Source Code
  12. * The source code in this file ("Source Code") is provided by Linden Lab
  13. * to you under the terms of the GNU General Public License, version 2.0
  14. * ("GPL"), unless you have obtained a separate licensing agreement
  15. * ("Other License"), formally executed by you and Linden Lab. Terms of
  16. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  17. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  18. *
  19. * There are special exceptions to the terms and conditions of the GPL as
  20. * it is applied to this Source Code. View the full text of the exception
  21. * in the file doc/FLOSS-exception.txt in this software distribution, or
  22. * online at
  23. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  24. *
  25. * By copying, modifying or distributing this software, you acknowledge
  26. * that you have read and understood your obligations described above,
  27. * and agree to abide by those obligations.
  28. *
  29. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  30. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  31. * COMPLETENESS OR PERFORMANCE.
  32. * $/LicenseInfo$
  33. */
  34. // *TODO: Make sure that the only symbol exported from this library is
  35. // LLPluginInitEntryPoint
  36. #include "linden_common.h"
  37. #include "media_plugin_base.h"
  38. MediaPluginBase::MediaPluginBase(LLPluginInstance::sendMessageFunction host_send_func,
  39. void* host_user_data)
  40. : mHostSendFunction(host_send_func),
  41. mHostUserData(host_user_data),
  42. mDeleteMe(false),
  43. mPixels(0),
  44. mWidth(0),
  45. mHeight(0),
  46. mTextureWidth(0),
  47. mTextureHeight(0),
  48. mDepth(0),
  49. mStatus(STATUS_NONE)
  50. {
  51. }
  52. std::string MediaPluginBase::statusString()
  53. {
  54. std::string result;
  55. switch (mStatus)
  56. {
  57. case STATUS_LOADING: result = "loading"; break;
  58. case STATUS_LOADED: result = "loaded"; break;
  59. case STATUS_ERROR: result = "error"; break;
  60. case STATUS_PLAYING: result = "playing"; break;
  61. case STATUS_PAUSED: result = "paused"; break;
  62. case STATUS_DONE: result = "done"; break;
  63. default:
  64. // keep the empty string
  65. break;
  66. }
  67. return result;
  68. }
  69. void MediaPluginBase::setStatus(EStatus status)
  70. {
  71. if(mStatus != status)
  72. {
  73. mStatus = status;
  74. sendStatus();
  75. }
  76. }
  77. void MediaPluginBase::staticReceiveMessage(const char* message_string,
  78. void** user_data)
  79. {
  80. MediaPluginBase* self = (MediaPluginBase*)*user_data;
  81. if (self)
  82. {
  83. self->receiveMessage(message_string);
  84. // If the plugin has processed the delete message, delete it.
  85. if (self->mDeleteMe)
  86. {
  87. std::cerr << "MediaPluginBase: deleting plugin on its request"
  88. << std::endl;
  89. delete self;
  90. *user_data = NULL;
  91. }
  92. }
  93. }
  94. void MediaPluginBase::sendMessage(const LLPluginMessage& message)
  95. {
  96. std::string output = message.generate();
  97. mHostSendFunction(output.c_str(), &mHostUserData);
  98. }
  99. void MediaPluginBase::setDirty(int left, int top, int right, int bottom)
  100. {
  101. LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "updated");
  102. message.setValueS32("left", left);
  103. message.setValueS32("top", top);
  104. message.setValueS32("right", right);
  105. message.setValueS32("bottom", bottom);
  106. sendMessage(message);
  107. }
  108. void MediaPluginBase::sendStatus()
  109. {
  110. LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_MEDIA, "media_status");
  111. message.setValue("status", statusString());
  112. sendMessage(message);
  113. }
  114. #if LL_WINDOWS
  115. # define LLSYMEXPORT __declspec(dllexport)
  116. #else
  117. # define LLSYMEXPORT __attribute__ ((visibility("default")))
  118. #endif
  119. extern "C"
  120. {
  121. LLSYMEXPORT int LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_fn,
  122. void* host_userdatap,
  123. LLPluginInstance::sendMessageFunction* plugin_fn,
  124. void** plugin_userdatap);
  125. }
  126. // Plugin initialization and entry point. Establishes communication channel for
  127. // messages between plugin and plugin loader shell.
  128. // Input parameters are 'host_send_fn' which is the function for sending
  129. // messages from the plugin to the pluginloader shell and 'host_userdatap is the
  130. // host data pointer used in that function. Output parameters are 'plugin_send_fn'
  131. // (normally a pointer on staticReceiveMessage() which is the function for the
  132. // plugin to receive messages from the plugin loader shell and plugin_userdatap
  133. // (normally a pointer on the plugin itself) which is the plugin data pointer
  134. // used in that function.
  135. // On return, 0 indicates a success and anything else an error.
  136. LLSYMEXPORT int LLPluginInitEntryPoint(LLPluginInstance::sendMessageFunction host_send_fn,
  137. void* host_userdatap,
  138. LLPluginInstance::sendMessageFunction* plugin_send_fn,
  139. void** plugin_userdatap)
  140. {
  141. return init_media_plugin(host_send_fn, host_userdatap, plugin_send_fn,
  142. plugin_userdatap);
  143. }
  144. #if LL_WINDOWS
  145. int WINAPI DllEntryPoint(HINSTANCE, unsigned long, void*)
  146. {
  147. return 1;
  148. }
  149. #endif