PageRenderTime 172ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llplugin/llpluginclassmedia.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 436 lines | 253 code | 96 blank | 87 comment | 1 complexity | 043eab5df62155a664c462f982d15faf MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpluginclassmedia.h
  3. * @brief LLPluginClassMedia handles interaction with a plugin which knows about the "media" message class.
  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. #ifndef LL_LLPLUGINCLASSMEDIA_H
  29. #define LL_LLPLUGINCLASSMEDIA_H
  30. #include "llgltypes.h"
  31. #include "llpluginprocessparent.h"
  32. #include "llrect.h"
  33. #include "llpluginclassmediaowner.h"
  34. #include <queue>
  35. #include "v4color.h"
  36. class LLPluginClassMedia : public LLPluginProcessParentOwner
  37. {
  38. LOG_CLASS(LLPluginClassMedia);
  39. public:
  40. LLPluginClassMedia(LLPluginClassMediaOwner *owner);
  41. virtual ~LLPluginClassMedia();
  42. // local initialization, called by the media manager when creating a source
  43. bool init(const std::string &launcher_filename,
  44. const std::string &plugin_dir,
  45. const std::string &plugin_filename,
  46. bool debug);
  47. // undoes everything init() didm called by the media manager when destroying a source
  48. void reset();
  49. void idle(void);
  50. // All of these may return 0 or an actual valid value.
  51. // Callers need to check the return for 0, and not use the values in that case.
  52. int getWidth() const { return (mMediaWidth > 0) ? mMediaWidth : 0; };
  53. int getHeight() const { return (mMediaHeight > 0) ? mMediaHeight : 0; };
  54. int getNaturalWidth() const { return mNaturalMediaWidth; };
  55. int getNaturalHeight() const { return mNaturalMediaHeight; };
  56. int getSetWidth() const { return mSetMediaWidth; };
  57. int getSetHeight() const { return mSetMediaHeight; };
  58. int getBitsWidth() const { return (mTextureWidth > 0) ? mTextureWidth : 0; };
  59. int getBitsHeight() const { return (mTextureHeight > 0) ? mTextureHeight : 0; };
  60. int getTextureWidth() const;
  61. int getTextureHeight() const;
  62. int getFullWidth() const { return mFullMediaWidth; };
  63. int getFullHeight() const { return mFullMediaHeight; };
  64. // This may return NULL. Callers need to check for and handle this case.
  65. unsigned char* getBitsData();
  66. // gets the format details of the texture data
  67. // These may return 0 if they haven't been set up yet. The caller needs to detect this case.
  68. int getTextureDepth() const { return mRequestedTextureDepth; };
  69. int getTextureFormatInternal() const { return mRequestedTextureInternalFormat; };
  70. int getTextureFormatPrimary() const { return mRequestedTextureFormat; };
  71. int getTextureFormatType() const { return mRequestedTextureType; };
  72. bool getTextureFormatSwapBytes() const { return mRequestedTextureSwapBytes; };
  73. bool getTextureCoordsOpenGL() const { return mRequestedTextureCoordsOpenGL; };
  74. void setSize(int width, int height);
  75. void setAutoScale(bool auto_scale);
  76. void setBackgroundColor(LLColor4 color) { mBackgroundColor = color; };
  77. void setOwner(LLPluginClassMediaOwner *owner) { mOwner = owner; };
  78. // Returns true if all of the texture parameters (depth, format, size, and texture size) are set up and consistent.
  79. // This will initially be false, and will also be false for some time after setSize while the resize is processed.
  80. // Note that if this returns true, it is safe to use all the get() functions above without checking for invalid return values
  81. // until you call idle() again.
  82. bool textureValid(void);
  83. bool getDirty(LLRect *dirty_rect = NULL);
  84. void resetDirty(void);
  85. typedef enum
  86. {
  87. MOUSE_EVENT_DOWN,
  88. MOUSE_EVENT_UP,
  89. MOUSE_EVENT_MOVE,
  90. MOUSE_EVENT_DOUBLE_CLICK
  91. }EMouseEventType;
  92. void mouseEvent(EMouseEventType type, int button, int x, int y, MASK modifiers);
  93. typedef enum
  94. {
  95. KEY_EVENT_DOWN,
  96. KEY_EVENT_UP,
  97. KEY_EVENT_REPEAT
  98. }EKeyEventType;
  99. bool keyEvent(EKeyEventType type, int key_code, MASK modifiers, LLSD native_key_data);
  100. void scrollEvent(int x, int y, MASK modifiers);
  101. // enable/disable media plugin debugging messages and info spam
  102. void enableMediaPluginDebugging( bool enable );
  103. // Javascript <-> viewer events
  104. void jsEnableObject( bool enable );
  105. void jsAgentLocationEvent( double x, double y, double z );
  106. void jsAgentGlobalLocationEvent( double x, double y, double z );
  107. void jsAgentOrientationEvent( double angle );
  108. void jsAgentLanguageEvent( const std::string& language );
  109. void jsAgentRegionEvent( const std::string& region_name );
  110. void jsAgentMaturityEvent( const std::string& maturity );
  111. // Text may be unicode (utf8 encoded)
  112. bool textInput(const std::string &text, MASK modifiers, LLSD native_key_data);
  113. void loadURI(const std::string &uri);
  114. // "Loading" means uninitialized or any state prior to fully running (processing commands)
  115. bool isPluginLoading(void) { return mPlugin?mPlugin->isLoading():false; };
  116. // "Running" means the steady state -- i.e. processing messages
  117. bool isPluginRunning(void) { return mPlugin?mPlugin->isRunning():false; };
  118. // "Exited" means any regular or error state after "Running" (plugin may have crashed or exited normally)
  119. bool isPluginExited(void) { return mPlugin?mPlugin->isDone():false; };
  120. std::string getPluginVersion() { return mPlugin?mPlugin->getPluginVersion():std::string(""); };
  121. bool getDisableTimeout() { return mPlugin?mPlugin->getDisableTimeout():false; };
  122. void setDisableTimeout(bool disable) { if(mPlugin) mPlugin->setDisableTimeout(disable); };
  123. // Inherited from LLPluginProcessParentOwner
  124. /* virtual */ void receivePluginMessage(const LLPluginMessage &message);
  125. /* virtual */ void pluginLaunchFailed();
  126. /* virtual */ void pluginDied();
  127. typedef enum
  128. {
  129. PRIORITY_UNLOADED, // media plugin isn't even loaded.
  130. PRIORITY_STOPPED, // media is not playing, shouldn't need to update at all.
  131. PRIORITY_HIDDEN, // media is not being displayed or is out of view, don't need to do graphic updates, but may still update audio, playhead, etc.
  132. PRIORITY_SLIDESHOW, // media is in the far distance, updates very infrequently
  133. PRIORITY_LOW, // media is in the distance, may be rendered at reduced size
  134. PRIORITY_NORMAL, // normal (default) priority
  135. PRIORITY_HIGH // media has user focus and/or is taking up most of the screen
  136. }EPriority;
  137. static const char* priorityToString(EPriority priority);
  138. void setPriority(EPriority priority);
  139. void setLowPrioritySizeLimit(int size);
  140. F64 getCPUUsage();
  141. void sendPickFileResponse(const std::string &file);
  142. void sendAuthResponse(bool ok, const std::string &username, const std::string &password);
  143. // Valid after a MEDIA_EVENT_CURSOR_CHANGED event
  144. std::string getCursorName() const { return mCursorName; };
  145. LLPluginClassMediaOwner::EMediaStatus getStatus() const { return mStatus; }
  146. void cut();
  147. bool canCut() const { return mCanCut; };
  148. void copy();
  149. bool canCopy() const { return mCanCopy; };
  150. void paste();
  151. bool canPaste() const { return mCanPaste; };
  152. // These can be called before init(), and they will be queued and sent before the media init message.
  153. void setUserDataPath(const std::string &user_data_path);
  154. void setLanguageCode(const std::string &language_code);
  155. void setPluginsEnabled(const bool enabled);
  156. void setJavascriptEnabled(const bool enabled);
  157. void setTarget(const std::string &target);
  158. ///////////////////////////////////
  159. // media browser class functions
  160. bool pluginSupportsMediaBrowser(void);
  161. void focus(bool focused);
  162. void set_page_zoom_factor( double factor );
  163. void clear_cache();
  164. void clear_cookies();
  165. void set_cookies(const std::string &cookies);
  166. void enable_cookies(bool enable);
  167. void proxy_setup(bool enable, const std::string &host = LLStringUtil::null, int port = 0);
  168. void browse_stop();
  169. void browse_reload(bool ignore_cache = false);
  170. void browse_forward();
  171. void browse_back();
  172. void setBrowserUserAgent(const std::string& user_agent);
  173. void showWebInspector( bool show );
  174. void proxyWindowOpened(const std::string &target, const std::string &uuid);
  175. void proxyWindowClosed(const std::string &uuid);
  176. void ignore_ssl_cert_errors(bool ignore);
  177. void addCertificateFilePath(const std::string& path);
  178. // This is valid after MEDIA_EVENT_NAVIGATE_BEGIN or MEDIA_EVENT_NAVIGATE_COMPLETE
  179. std::string getNavigateURI() const { return mNavigateURI; };
  180. // These are valid after MEDIA_EVENT_NAVIGATE_COMPLETE
  181. S32 getNavigateResultCode() const { return mNavigateResultCode; };
  182. std::string getNavigateResultString() const { return mNavigateResultString; };
  183. bool getHistoryBackAvailable() const { return mHistoryBackAvailable; };
  184. bool getHistoryForwardAvailable() const { return mHistoryForwardAvailable; };
  185. // This is valid after MEDIA_EVENT_PROGRESS_UPDATED
  186. int getProgressPercent() const { return mProgressPercent; };
  187. // This is valid after MEDIA_EVENT_STATUS_TEXT_CHANGED
  188. std::string getStatusText() const { return mStatusText; };
  189. // This is valid after MEDIA_EVENT_LOCATION_CHANGED
  190. std::string getLocation() const { return mLocation; };
  191. // This is valid after MEDIA_EVENT_CLICK_LINK_HREF or MEDIA_EVENT_CLICK_LINK_NOFOLLOW
  192. std::string getClickURL() const { return mClickURL; };
  193. // This is valid after MEDIA_EVENT_CLICK_LINK_NOFOLLOW
  194. std::string getClickNavType() const { return mClickNavType; };
  195. // This is valid after MEDIA_EVENT_CLICK_LINK_HREF
  196. std::string getClickTarget() const { return mClickTarget; };
  197. // This is valid during MEDIA_EVENT_CLICK_LINK_HREF and MEDIA_EVENT_GEOMETRY_CHANGE
  198. std::string getClickUUID() const { return mClickUUID; };
  199. // These are valid during MEDIA_EVENT_DEBUG_MESSAGE
  200. std::string getDebugMessageText() const { return mDebugMessageText; };
  201. std::string getDebugMessageLevel() const { return mDebugMessageLevel; };
  202. // This is valid after MEDIA_EVENT_NAVIGATE_ERROR_PAGE
  203. S32 getStatusCode() const { return mStatusCode; };
  204. // These are valid during MEDIA_EVENT_GEOMETRY_CHANGE
  205. S32 getGeometryX() const { return mGeometryX; };
  206. S32 getGeometryY() const { return mGeometryY; };
  207. S32 getGeometryWidth() const { return mGeometryWidth; };
  208. S32 getGeometryHeight() const { return mGeometryHeight; };
  209. // These are valid during MEDIA_EVENT_AUTH_REQUEST
  210. std::string getAuthURL() const { return mAuthURL; };
  211. std::string getAuthRealm() const { return mAuthRealm; };
  212. // These are valid during MEDIA_EVENT_LINK_HOVERED
  213. std::string getHoverText() const { return mHoverText; };
  214. std::string getHoverLink() const { return mHoverLink; };
  215. const std::string& getMediaName() const { return mMediaName; };
  216. std::string getMediaDescription() const { return mMediaDescription; };
  217. // Crash the plugin. If you use this outside of a testbed, you will be punished.
  218. void crashPlugin();
  219. // Hang the plugin. If you use this outside of a testbed, you will be punished.
  220. void hangPlugin();
  221. ///////////////////////////////////
  222. // media time class functions
  223. bool pluginSupportsMediaTime(void);
  224. void stop();
  225. void start(float rate = 0.0f);
  226. void pause();
  227. void seek(float time);
  228. void setLoop(bool loop);
  229. void setVolume(float volume);
  230. float getVolume();
  231. F64 getCurrentTime(void) const { return mCurrentTime; };
  232. F64 getDuration(void) const { return mDuration; };
  233. F64 getCurrentPlayRate(void) { return mCurrentRate; };
  234. F64 getLoadedDuration(void) const { return mLoadedDuration; };
  235. // Initialize the URL history of the plugin by sending
  236. // "init_history" message
  237. void initializeUrlHistory(const LLSD& url_history);
  238. protected:
  239. LLPluginClassMediaOwner *mOwner;
  240. // Notify this object's owner that an event has occurred.
  241. void mediaEvent(LLPluginClassMediaOwner::EMediaEvent event);
  242. void sendMessage(const LLPluginMessage &message); // Send message internally, either queueing or sending directly.
  243. std::queue<LLPluginMessage> mSendQueue; // Used to queue messages while the plugin initializes.
  244. void setSizeInternal(void);
  245. bool mTextureParamsReceived; // the mRequestedTexture* fields are only valid when this is true
  246. S32 mRequestedTextureDepth;
  247. LLGLenum mRequestedTextureInternalFormat;
  248. LLGLenum mRequestedTextureFormat;
  249. LLGLenum mRequestedTextureType;
  250. bool mRequestedTextureSwapBytes;
  251. bool mRequestedTextureCoordsOpenGL;
  252. std::string mTextureSharedMemoryName;
  253. size_t mTextureSharedMemorySize;
  254. // True to scale requested media up to the full size of the texture (i.e. next power of two)
  255. bool mAutoScaleMedia;
  256. // default media size for the plugin, from the texture_params message.
  257. int mDefaultMediaWidth;
  258. int mDefaultMediaHeight;
  259. // Size that has been requested by the plugin itself
  260. int mNaturalMediaWidth;
  261. int mNaturalMediaHeight;
  262. // Size that has been requested with setSize()
  263. int mSetMediaWidth;
  264. int mSetMediaHeight;
  265. // Full calculated media size (before auto-scale and downsample calculations)
  266. int mFullMediaWidth;
  267. int mFullMediaHeight;
  268. // Actual media size being set (after auto-scale)
  269. int mRequestedMediaWidth;
  270. int mRequestedMediaHeight;
  271. // Texture size calculated from actual media size
  272. int mRequestedTextureWidth;
  273. int mRequestedTextureHeight;
  274. // Size that the plugin has acknowledged
  275. int mTextureWidth;
  276. int mTextureHeight;
  277. int mMediaWidth;
  278. int mMediaHeight;
  279. float mRequestedVolume;
  280. // Priority of this media stream
  281. EPriority mPriority;
  282. int mLowPrioritySizeLimit;
  283. bool mAllowDownsample;
  284. int mPadding;
  285. LLPluginProcessParent *mPlugin;
  286. LLRect mDirtyRect;
  287. std::string translateModifiers(MASK modifiers);
  288. std::string mCursorName;
  289. int mLastMouseX;
  290. int mLastMouseY;
  291. LLPluginClassMediaOwner::EMediaStatus mStatus;
  292. F64 mSleepTime;
  293. bool mCanCut;
  294. bool mCanCopy;
  295. bool mCanPaste;
  296. std::string mMediaName;
  297. std::string mMediaDescription;
  298. LLColor4 mBackgroundColor;
  299. std::string mTarget;
  300. /////////////////////////////////////////
  301. // media_browser class
  302. std::string mNavigateURI;
  303. S32 mNavigateResultCode;
  304. std::string mNavigateResultString;
  305. bool mHistoryBackAvailable;
  306. bool mHistoryForwardAvailable;
  307. std::string mStatusText;
  308. int mProgressPercent;
  309. std::string mLocation;
  310. std::string mClickURL;
  311. std::string mClickNavType;
  312. std::string mClickTarget;
  313. std::string mClickUUID;
  314. std::string mDebugMessageText;
  315. std::string mDebugMessageLevel;
  316. S32 mGeometryX;
  317. S32 mGeometryY;
  318. S32 mGeometryWidth;
  319. S32 mGeometryHeight;
  320. S32 mStatusCode;
  321. std::string mAuthURL;
  322. std::string mAuthRealm;
  323. std::string mHoverText;
  324. std::string mHoverLink;
  325. /////////////////////////////////////////
  326. // media_time class
  327. F64 mCurrentTime;
  328. F64 mDuration;
  329. F64 mCurrentRate;
  330. F64 mLoadedDuration;
  331. //--------------------------------------
  332. //debug use only
  333. //
  334. private:
  335. bool mDeleteOK ;
  336. public:
  337. void setDeleteOK(bool flag) { mDeleteOK = flag ;}
  338. //--------------------------------------
  339. };
  340. #endif // LL_LLPLUGINCLASSMEDIA_H