/indra/media_plugins/base/media_plugin_base.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 129 lines · 52 code · 18 blank · 59 comment · 0 complexity · 748c71ea0f5cc2c5af6b8a2f8a40753d MD5 · raw file

  1. /**
  2. * @file media_plugin_base.h
  3. * @brief Media plugin base class for LLMedia API plugin system
  4. *
  5. * @cond
  6. * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. * @endcond
  27. */
  28. #include "linden_common.h"
  29. #include "llplugininstance.h"
  30. #include "llpluginmessage.h"
  31. #include "llpluginmessageclasses.h"
  32. class MediaPluginBase
  33. {
  34. public:
  35. MediaPluginBase(LLPluginInstance::sendMessageFunction host_send_func, void *host_user_data);
  36. /** Media plugin destructor. */
  37. virtual ~MediaPluginBase() {}
  38. /** Handle received message from plugin loader shell. */
  39. virtual void receiveMessage(const char *message_string) = 0;
  40. static void staticReceiveMessage(const char *message_string, void **user_data);
  41. protected:
  42. /** Plugin status. */
  43. typedef enum
  44. {
  45. STATUS_NONE,
  46. STATUS_LOADING,
  47. STATUS_LOADED,
  48. STATUS_ERROR,
  49. STATUS_PLAYING,
  50. STATUS_PAUSED,
  51. STATUS_DONE
  52. } EStatus;
  53. /** Plugin shared memory. */
  54. class SharedSegmentInfo
  55. {
  56. public:
  57. /** Shared memory address. */
  58. void *mAddress;
  59. /** Shared memory size. */
  60. size_t mSize;
  61. };
  62. void sendMessage(const LLPluginMessage &message);
  63. void sendStatus();
  64. std::string statusString();
  65. void setStatus(EStatus status);
  66. /// Note: The quicktime plugin overrides this to add current time and duration to the message.
  67. virtual void setDirty(int left, int top, int right, int bottom);
  68. /** Map of shared memory names to shared memory. */
  69. typedef std::map<std::string, SharedSegmentInfo> SharedSegmentMap;
  70. /** Function to send message from plugin to plugin loader shell. */
  71. LLPluginInstance::sendMessageFunction mHostSendFunction;
  72. /** Message data being sent to plugin loader shell by mHostSendFunction. */
  73. void *mHostUserData;
  74. /** Flag to delete plugin instance (self). */
  75. bool mDeleteMe;
  76. /** Pixel array to display. TODO:DOC are pixels always 24-bit RGB format, aligned on 32-bit boundary? Also: calling this a pixel array may be misleading since 1 pixel > 1 char. */
  77. unsigned char* mPixels;
  78. /** TODO:DOC what's this for -- does a texture have its own piece of shared memory? updated on size_change_request, cleared on shm_remove */
  79. std::string mTextureSegmentName;
  80. /** Width of plugin display in pixels. */
  81. int mWidth;
  82. /** Height of plugin display in pixels. */
  83. int mHeight;
  84. /** Width of plugin texture. */
  85. int mTextureWidth;
  86. /** Height of plugin texture. */
  87. int mTextureHeight;
  88. /** Pixel depth (pixel size in bytes). */
  89. int mDepth;
  90. /** Current status of plugin. */
  91. EStatus mStatus;
  92. /** Map of shared memory segments. */
  93. SharedSegmentMap mSharedSegments;
  94. };
  95. /** The plugin <b>must</b> define this function to create its instance.
  96. * It should look something like this:
  97. * @code
  98. * {
  99. * MediaPluginFoo *self = new MediaPluginFoo(host_send_func, host_user_data);
  100. * *plugin_send_func = MediaPluginFoo::staticReceiveMessage;
  101. * *plugin_user_data = (void*)self;
  102. *
  103. * return 0;
  104. * }
  105. * @endcode
  106. */
  107. int init_media_plugin(
  108. LLPluginInstance::sendMessageFunction host_send_func,
  109. void *host_user_data,
  110. LLPluginInstance::sendMessageFunction *plugin_send_func,
  111. void **plugin_user_data);