media_plugin_base.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**
  2. * @file media_plugin_base.h
  3. * @brief Media plugin base class for LLMedia API plugin system
  4. *
  5. * $LicenseInfo:firstyear=2008&license=viewergpl$
  6. *
  7. * Copyright (c) 2008-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llplugininstance.h"
  33. #include "llpluginmessage.h"
  34. #include "llpluginmessageclasses.h"
  35. class MediaPluginBase
  36. {
  37. public:
  38. // @param[in] host_send_func Function for sending messages from plugin to
  39. // plugin loader shell
  40. // @param[in] host_user_data Message data for messages from plugin to
  41. // plugin loader shell
  42. MediaPluginBase(LLPluginInstance::sendMessageFunction host_send_func,
  43. void* host_user_data);
  44. virtual ~MediaPluginBase() = default;
  45. // Handle received message from plugin loader shell.
  46. virtual void receiveMessage(const char* message_string) = 0;
  47. /**
  48. * Receives message from plugin loader shell.
  49. *
  50. * @param[in] message_string Message string
  51. * @param[in] user_data Message data
  52. */
  53. static void staticReceiveMessage(const char* message_string,
  54. void** user_data);
  55. protected:
  56. // Plugin status.
  57. typedef enum
  58. {
  59. STATUS_NONE,
  60. STATUS_LOADING,
  61. STATUS_LOADED,
  62. STATUS_ERROR,
  63. STATUS_PLAYING,
  64. STATUS_PAUSED,
  65. STATUS_DONE
  66. } EStatus;
  67. // Plugin shared memory.
  68. class SharedSegmentInfo
  69. {
  70. public:
  71. void* mAddress;
  72. size_t mSize;
  73. };
  74. /**
  75. * Sends message to plugin loader shell.
  76. *
  77. * @param[in] message Message data being sent to plugin loader shell
  78. */
  79. void sendMessage(const LLPluginMessage& message);
  80. /**
  81. * Sends "media_status" message to plugin loader shell ("loading",
  82. * "playing", "paused", etc.)
  83. */
  84. void sendStatus();
  85. /**
  86. * Converts current media status enum value into string (STATUS_LOADING
  87. * into "loading", etc.)
  88. *
  89. * @return Media status string ("loading", "playing", "paused", etc)
  90. */
  91. std::string statusString();
  92. /**
  93. * Sets media status.
  94. *
  95. * @param[in] status Media status (STATUS_LOADING, STATUS_PLAYING,
  96. * STATUS_PAUSED, etc)
  97. */
  98. void setStatus(EStatus status);
  99. /**
  100. * Notifies plugin loader shell that part of display area needs to be redrawn.
  101. *
  102. * @param[in] left Left X coordinate of area to redraw
  103. * @param[in] top Top Y coordinate of area to redraw
  104. * @param[in] right Right X-coordinate of area to redraw
  105. * @param[in] bottom Bottom Y-coordinate of area to redraw
  106. * Note: the (0,0) coordinates correspond to the top left corner.
  107. */
  108. virtual void setDirty(int left, int top, int right, int bottom);
  109. protected:
  110. // Map of shared memory names to shared memory.
  111. typedef std::map<std::string, SharedSegmentInfo> SharedSegmentMap;
  112. // Function to send message from plugin to plugin loader shell.
  113. LLPluginInstance::sendMessageFunction mHostSendFunction;
  114. // Message data being sent to plugin loader shell by mHostSendFunction.
  115. void* mHostUserData;
  116. // Pixel array to display. *TODO documentation: are pixels always 24 bits
  117. // RGB format, aligned on 32 bits boundary ? Also, calling this a pixel
  118. // array may be misleading since 1 pixel > 1 char.
  119. unsigned char* mPixels;
  120. // *TODO documentation: what is this for ? Does a texture have its own
  121. // piece of shared memory ? Updated on size_change_request, cleared on
  122. // shm_remove.
  123. std::string mTextureSegmentName;
  124. // Map of shared memory segments.
  125. SharedSegmentMap mSharedSegments;
  126. // Width of plugin display in pixels.
  127. int mWidth;
  128. // Height of plugin display in pixels.
  129. int mHeight;
  130. // Width of plugin texture.
  131. int mTextureWidth;
  132. // Height of plugin texture.
  133. int mTextureHeight;
  134. // Pixel depth (pixel size in bytes).
  135. int mDepth;
  136. // Current status of plugin.
  137. EStatus mStatus;
  138. // Flag to delete plugin instance (self).
  139. bool mDeleteMe;
  140. };
  141. /** The plugin <b>must</b> define this function to create its instance.
  142. * It should look something like this:
  143. * @code
  144. * {
  145. * MediaPluginFoo *self = new MediaPluginFoo(host_send_func, host_user_data);
  146. * *plugin_send_func = MediaPluginFoo::staticReceiveMessage;
  147. * *plugin_user_data = (void*)self;
  148. *
  149. * return 0;
  150. * }
  151. * @endcode
  152. */
  153. int init_media_plugin(LLPluginInstance::sendMessageFunction host_send_func,
  154. void* host_user_data,
  155. LLPluginInstance::sendMessageFunction* plugin_send_func,
  156. void** plugin_user_data);