PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewermedia.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 479 lines | 323 code | 91 blank | 65 comment | 1 complexity | 570a43ce637756fa522bcd22ac28788e MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewermedia.h
  3. * @brief Client interface to the media engine
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LLVIEWERMEDIA_H
  27. #define LLVIEWERMEDIA_H
  28. #include "llfocusmgr.h"
  29. #include "lleditmenuhandler.h"
  30. #include "llpanel.h"
  31. #include "llpluginclassmediaowner.h"
  32. #include "llviewermediaobserver.h"
  33. #include "llpluginclassmedia.h"
  34. #include "v4color.h"
  35. #include "llnotificationptr.h"
  36. #include "llurl.h"
  37. class LLViewerMediaImpl;
  38. class LLUUID;
  39. class LLViewerMediaTexture;
  40. class LLMediaEntry;
  41. class LLVOVolume;
  42. class LLMimeDiscoveryResponder;
  43. class LLPluginCookieStore;
  44. typedef LLPointer<LLViewerMediaImpl> viewer_media_t;
  45. ///////////////////////////////////////////////////////////////////////////////
  46. //
  47. class LLViewerMediaEventEmitter
  48. {
  49. public:
  50. virtual ~LLViewerMediaEventEmitter();
  51. bool addObserver( LLViewerMediaObserver* subject );
  52. bool remObserver( LLViewerMediaObserver* subject );
  53. virtual void emitEvent(LLPluginClassMedia* self, LLViewerMediaObserver::EMediaEvent event);
  54. private:
  55. typedef std::list< LLViewerMediaObserver* > observerListType;
  56. observerListType mObservers;
  57. };
  58. class LLViewerMediaImpl;
  59. class LLViewerMedia
  60. {
  61. LOG_CLASS(LLViewerMedia);
  62. public:
  63. // String to get/set media autoplay in gSavedSettings
  64. static const char* AUTO_PLAY_MEDIA_SETTING;
  65. static const char* SHOW_MEDIA_ON_OTHERS_SETTING;
  66. static const char* SHOW_MEDIA_WITHIN_PARCEL_SETTING;
  67. static const char* SHOW_MEDIA_OUTSIDE_PARCEL_SETTING;
  68. typedef std::list<LLViewerMediaImpl*> impl_list;
  69. typedef std::map<LLUUID, LLViewerMediaImpl*> impl_id_map;
  70. // Special case early init for just web browser component
  71. // so we can show login screen. See .cpp file for details. JC
  72. static viewer_media_t newMediaImpl(const LLUUID& texture_id,
  73. S32 media_width = 0,
  74. S32 media_height = 0,
  75. U8 media_auto_scale = false,
  76. U8 media_loop = false);
  77. static viewer_media_t updateMediaImpl(LLMediaEntry* media_entry, const std::string& previous_url, bool update_from_self);
  78. static LLViewerMediaImpl* getMediaImplFromTextureID(const LLUUID& texture_id);
  79. static std::string getCurrentUserAgent();
  80. static void updateBrowserUserAgent();
  81. static bool handleSkinCurrentChanged(const LLSD& /*newvalue*/);
  82. static bool textureHasMedia(const LLUUID& texture_id);
  83. static void setVolume(F32 volume);
  84. // Is any media currently "showing"? Includes Parcel Media. Does not include media in the UI.
  85. static bool isAnyMediaShowing();
  86. // Set all media enabled or disabled, depending on val. Does not include media in the UI.
  87. static void setAllMediaEnabled(bool val);
  88. static void updateMedia(void* dummy_arg = NULL);
  89. static void initClass();
  90. static void cleanupClass();
  91. static F32 getVolume();
  92. static void muteListChanged();
  93. static void setInWorldMediaDisabled(bool disabled);
  94. static bool getInWorldMediaDisabled();
  95. static bool isInterestingEnough(const LLVOVolume* object, const F64 &object_interest);
  96. // Returns the priority-sorted list of all media impls.
  97. static impl_list &getPriorityList();
  98. // This is the comparitor used to sort the list.
  99. static bool priorityComparitor(const LLViewerMediaImpl* i1, const LLViewerMediaImpl* i2);
  100. // These are just helper functions for the convenience of others working with media
  101. static bool hasInWorldMedia();
  102. static std::string getParcelAudioURL();
  103. static bool hasParcelMedia();
  104. static bool hasParcelAudio();
  105. static bool isParcelMediaPlaying();
  106. static bool isParcelAudioPlaying();
  107. static void onAuthSubmit(const LLSD& notification, const LLSD& response);
  108. // Clear all cookies for all plugins
  109. static void clearAllCookies();
  110. // Clear all plugins' caches
  111. static void clearAllCaches();
  112. // Set the "cookies enabled" flag for all loaded plugins
  113. static void setCookiesEnabled(bool enabled);
  114. // Set the proxy config for all loaded plugins
  115. static void setProxyConfig(bool enable, const std::string &host, int port);
  116. static LLPluginCookieStore *getCookieStore();
  117. static void loadCookieFile();
  118. static void saveCookieFile();
  119. static void addCookie(const std::string &name, const std::string &value, const std::string &domain, const LLDate &expires, const std::string &path = std::string("/"), bool secure = false );
  120. static void addSessionCookie(const std::string &name, const std::string &value, const std::string &domain, const std::string &path = std::string("/"), bool secure = false );
  121. static void removeCookie(const std::string &name, const std::string &domain, const std::string &path = std::string("/") );
  122. static void openIDSetup(const std::string &openid_url, const std::string &openid_token);
  123. static void openIDCookieResponse(const std::string &cookie);
  124. static void proxyWindowOpened(const std::string &target, const std::string &uuid);
  125. static void proxyWindowClosed(const std::string &uuid);
  126. static void createSpareBrowserMediaSource();
  127. static LLPluginClassMedia* getSpareBrowserMediaSource();
  128. static void setOnlyAudibleMediaTextureID(const LLUUID& texture_id);
  129. static LLSD getHeaders();
  130. private:
  131. static void setOpenIDCookie();
  132. static void onTeleportFinished();
  133. static LLPluginCookieStore *sCookieStore;
  134. static LLURL sOpenIDURL;
  135. static std::string sOpenIDCookie;
  136. static LLPluginClassMedia* sSpareBrowserMediaSource;
  137. };
  138. // Implementation functions not exported into header file
  139. class LLViewerMediaImpl
  140. : public LLMouseHandler, public LLRefCount, public LLPluginClassMediaOwner, public LLViewerMediaEventEmitter, public LLEditMenuHandler
  141. {
  142. LOG_CLASS(LLViewerMediaImpl);
  143. public:
  144. friend class LLViewerMedia;
  145. friend class LLMimeDiscoveryResponder;
  146. LLViewerMediaImpl(
  147. const LLUUID& texture_id,
  148. S32 media_width,
  149. S32 media_height,
  150. U8 media_auto_scale,
  151. U8 media_loop);
  152. ~LLViewerMediaImpl();
  153. // Override inherited version from LLViewerMediaEventEmitter
  154. virtual void emitEvent(LLPluginClassMedia* self, LLViewerMediaObserver::EMediaEvent event);
  155. void createMediaSource();
  156. void destroyMediaSource();
  157. void setMediaType(const std::string& media_type);
  158. bool initializeMedia(const std::string& mime_type);
  159. bool initializePlugin(const std::string& media_type);
  160. void loadURI();
  161. LLPluginClassMedia* getMediaPlugin() { return mMediaSource; }
  162. void setSize(int width, int height);
  163. void showNotification(LLNotificationPtr notify);
  164. void hideNotification();
  165. void play();
  166. void stop();
  167. void pause();
  168. void start();
  169. void seek(F32 time);
  170. void skipBack(F32 step_scale);
  171. void skipForward(F32 step_scale);
  172. void setVolume(F32 volume);
  173. void updateVolume();
  174. F32 getVolume();
  175. void focus(bool focus);
  176. // True if the impl has user focus.
  177. bool hasFocus() const;
  178. void mouseDown(S32 x, S32 y, MASK mask, S32 button = 0);
  179. void mouseUp(S32 x, S32 y, MASK mask, S32 button = 0);
  180. void mouseMove(S32 x, S32 y, MASK mask);
  181. void mouseDown(const LLVector2& texture_coords, MASK mask, S32 button = 0);
  182. void mouseUp(const LLVector2& texture_coords, MASK mask, S32 button = 0);
  183. void mouseMove(const LLVector2& texture_coords, MASK mask);
  184. void mouseDoubleClick(S32 x,S32 y, MASK mask, S32 button = 0);
  185. void scrollWheel(S32 x, S32 y, MASK mask);
  186. void mouseCapture();
  187. void navigateBack();
  188. void navigateForward();
  189. void navigateReload();
  190. void navigateHome();
  191. void unload();
  192. void navigateTo(const std::string& url, const std::string& mime_type = "", bool rediscover_type = false, bool server_request = false);
  193. void navigateInternal();
  194. void navigateStop();
  195. bool handleKeyHere(KEY key, MASK mask);
  196. bool handleUnicodeCharHere(llwchar uni_char);
  197. bool canNavigateForward();
  198. bool canNavigateBack();
  199. std::string getMediaURL() const { return mMediaURL; }
  200. std::string getCurrentMediaURL();
  201. std::string getHomeURL() { return mHomeURL; }
  202. std::string getMediaEntryURL() { return mMediaEntryURL; }
  203. void setHomeURL(const std::string& home_url, const std::string& mime_type = LLStringUtil::null) { mHomeURL = home_url; mHomeMimeType = mime_type;};
  204. void clearCache();
  205. void setPageZoomFactor( double factor );
  206. std::string getMimeType() { return mMimeType; }
  207. void scaleMouse(S32 *mouse_x, S32 *mouse_y);
  208. void scaleTextureCoords(const LLVector2& texture_coords, S32 *x, S32 *y);
  209. void update();
  210. void updateImagesMediaStreams();
  211. LLUUID getMediaTextureID() const;
  212. void suspendUpdates(bool suspend) { mSuspendUpdates = suspend; }
  213. void setVisible(bool visible);
  214. bool getVisible() const { return mVisible; }
  215. bool isVisible() const { return mVisible; }
  216. bool isMediaTimeBased();
  217. bool isMediaPlaying();
  218. bool isMediaPaused();
  219. bool hasMedia() const;
  220. bool isMediaFailed() const { return mMediaSourceFailed; }
  221. void setMediaFailed(bool val) { mMediaSourceFailed = val; }
  222. void resetPreviousMediaState();
  223. void setDisabled(bool disabled, bool forcePlayOnEnable = false);
  224. bool isMediaDisabled() const { return mIsDisabled; };
  225. void setInNearbyMediaList(bool in_list) { mInNearbyMediaList = in_list; }
  226. bool getInNearbyMediaList() { return mInNearbyMediaList; }
  227. // returns true if this instance should not be loaded (disabled, muted object, crashed, etc.)
  228. bool isForcedUnloaded() const;
  229. // returns true if this instance could be playable based on autoplay setting, current load state, etc.
  230. bool isPlayable() const;
  231. void setIsParcelMedia(bool is_parcel_media) { mIsParcelMedia = is_parcel_media; }
  232. bool isParcelMedia() const { return mIsParcelMedia; }
  233. ECursorType getLastSetCursor() { return mLastSetCursor; }
  234. void setTarget(const std::string& target) { mTarget = target; }
  235. // utility function to create a ready-to-use media instance from a desired media type.
  236. static LLPluginClassMedia* newSourceFromMediaType(std::string media_type, LLPluginClassMediaOwner *owner /* may be NULL */, S32 default_width, S32 default_height, const std::string target = LLStringUtil::null);
  237. // Internally set our desired browser user agent string, including
  238. // the Second Life version and skin name. Used because we can
  239. // switch skins without restarting the app.
  240. static void updateBrowserUserAgent();
  241. // Callback for when the SkinCurrent control is changed to
  242. // switch the user agent string to indicate the new skin.
  243. static bool handleSkinCurrentChanged(const LLSD& newvalue);
  244. // need these to handle mouseup...
  245. /*virtual*/ void onMouseCaptureLost();
  246. /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask);
  247. // Grr... the only thing I want as an LLMouseHandler are the onMouseCaptureLost and handleMouseUp calls.
  248. // Sadly, these are all pure virtual, so I have to supply implementations here:
  249. /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask) { return FALSE; };
  250. /*virtual*/ BOOL handleHover(S32 x, S32 y, MASK mask) { return FALSE; };
  251. /*virtual*/ BOOL handleScrollWheel(S32 x, S32 y, S32 clicks) { return FALSE; };
  252. /*virtual*/ BOOL handleDoubleClick(S32 x, S32 y, MASK mask) { return FALSE; };
  253. /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask) { return FALSE; };
  254. /*virtual*/ BOOL handleRightMouseUp(S32 x, S32 y, MASK mask) { return FALSE; };
  255. /*virtual*/ BOOL handleToolTip(S32 x, S32 y, MASK mask) { return FALSE; };
  256. /*virtual*/ BOOL handleMiddleMouseDown(S32 x, S32 y, MASK mask) { return FALSE; };
  257. /*virtual*/ BOOL handleMiddleMouseUp(S32 x, S32 y, MASK mask) {return FALSE; };
  258. /*virtual*/ const std::string& getName() const;
  259. /*virtual*/ void screenPointToLocal(S32 screen_x, S32 screen_y, S32* local_x, S32* local_y) const {};
  260. /*virtual*/ void localPointToScreen(S32 local_x, S32 local_y, S32* screen_x, S32* screen_y) const {};
  261. /*virtual*/ BOOL hasMouseCapture() { return gFocusMgr.getMouseCapture() == this; };
  262. // Inherited from LLPluginClassMediaOwner
  263. /*virtual*/ void handleMediaEvent(LLPluginClassMedia* plugin, LLPluginClassMediaOwner::EMediaEvent);
  264. /*virtual*/ void handleCookieSet(LLPluginClassMedia* self, const std::string &cookie);
  265. // LLEditMenuHandler overrides
  266. /*virtual*/ void cut();
  267. /*virtual*/ BOOL canCut() const;
  268. /*virtual*/ void copy();
  269. /*virtual*/ BOOL canCopy() const;
  270. /*virtual*/ void paste();
  271. /*virtual*/ BOOL canPaste() const;
  272. void addObject(LLVOVolume* obj) ;
  273. void removeObject(LLVOVolume* obj) ;
  274. const std::list< LLVOVolume* >* getObjectList() const ;
  275. LLVOVolume *getSomeObject();
  276. void setUpdated(BOOL updated) ;
  277. BOOL isUpdated() ;
  278. // updates the javascript object in the embedded browser with viewer values
  279. void updateJavascriptObject();
  280. // Updates the "interest" value in this object
  281. void calculateInterest();
  282. F64 getInterest() const { return mInterest; };
  283. F64 getApproximateTextureInterest();
  284. S32 getProximity() const { return mProximity; };
  285. F64 getProximityDistance() const { return mProximityDistance; };
  286. // Mark this object as being used in a UI panel instead of on a prim
  287. // This will be used as part of the interest sorting algorithm.
  288. void setUsedInUI(bool used_in_ui);
  289. bool getUsedInUI() const { return mUsedInUI; };
  290. void setBackgroundColor(LLColor4 color);
  291. F64 getCPUUsage() const;
  292. void setPriority(LLPluginClassMedia::EPriority priority);
  293. LLPluginClassMedia::EPriority getPriority() { return mPriority; };
  294. void setLowPrioritySizeLimit(int size);
  295. void setTextureID(LLUUID id = LLUUID::null);
  296. bool isTrustedBrowser() { return mTrustedBrowser; }
  297. void setTrustedBrowser(bool trusted) { mTrustedBrowser = trusted; }
  298. typedef enum
  299. {
  300. MEDIANAVSTATE_NONE, // State is outside what we need to track for navigation.
  301. MEDIANAVSTATE_BEGUN, // a MEDIA_EVENT_NAVIGATE_BEGIN has been received which was not server-directed
  302. MEDIANAVSTATE_FIRST_LOCATION_CHANGED, // first LOCATION_CHANGED event after a non-server-directed BEGIN
  303. MEDIANAVSTATE_FIRST_LOCATION_CHANGED_SPURIOUS, // Same as above, but the new URL is identical to the previously navigated URL.
  304. MEDIANAVSTATE_COMPLETE_BEFORE_LOCATION_CHANGED, // we received a NAVIGATE_COMPLETE event before the first LOCATION_CHANGED
  305. MEDIANAVSTATE_COMPLETE_BEFORE_LOCATION_CHANGED_SPURIOUS,// Same as above, but the new URL is identical to the previously navigated URL.
  306. MEDIANAVSTATE_SERVER_SENT, // server-directed nav has been requested, but MEDIA_EVENT_NAVIGATE_BEGIN hasn't been received yet
  307. MEDIANAVSTATE_SERVER_BEGUN, // MEDIA_EVENT_NAVIGATE_BEGIN has been received which was server-directed
  308. MEDIANAVSTATE_SERVER_FIRST_LOCATION_CHANGED, // first LOCATION_CHANGED event after a server-directed BEGIN
  309. MEDIANAVSTATE_SERVER_COMPLETE_BEFORE_LOCATION_CHANGED // we received a NAVIGATE_COMPLETE event before the first LOCATION_CHANGED
  310. }EMediaNavState;
  311. // Returns the current nav state of the media.
  312. // note that this will be updated BEFORE listeners and objects receive media messages
  313. EMediaNavState getNavState() { return mMediaNavState; }
  314. void setNavState(EMediaNavState state);
  315. void setNavigateSuspended(bool suspend);
  316. bool isNavigateSuspended() { return mNavigateSuspended; };
  317. void cancelMimeTypeProbe();
  318. // Is this media attached to an avatar *not* self
  319. bool isAttachedToAnotherAvatar() const;
  320. // Is this media in the agent's parcel?
  321. bool isInAgentParcel() const;
  322. // get currently active notification associated with this media instance
  323. LLNotificationPtr getCurrentNotification() const;
  324. private:
  325. bool isAutoPlayable() const;
  326. bool shouldShowBasedOnClass() const;
  327. static bool isObjectAttachedToAnotherAvatar(LLVOVolume *obj);
  328. static bool isObjectInAgentParcel(LLVOVolume *obj);
  329. private:
  330. // a single media url with some data and an impl.
  331. LLPluginClassMedia* mMediaSource;
  332. F64 mZoomFactor;
  333. LLUUID mTextureId;
  334. bool mMovieImageHasMips;
  335. std::string mMediaURL; // The last media url set with NavigateTo
  336. std::string mHomeURL;
  337. std::string mHomeMimeType; // forced mime type for home url
  338. std::string mMimeType;
  339. std::string mCurrentMediaURL; // The most current media url from the plugin (via the "location changed" or "navigate complete" events).
  340. std::string mCurrentMimeType; // The MIME type that caused the currently loaded plugin to be loaded.
  341. S32 mLastMouseX; // save the last mouse coord we get, so when we lose capture we can simulate a mouseup at that point.
  342. S32 mLastMouseY;
  343. S32 mMediaWidth;
  344. S32 mMediaHeight;
  345. bool mMediaAutoScale;
  346. bool mMediaLoop;
  347. bool mNeedsNewTexture;
  348. S32 mTextureUsedWidth;
  349. S32 mTextureUsedHeight;
  350. bool mSuspendUpdates;
  351. bool mVisible;
  352. ECursorType mLastSetCursor;
  353. EMediaNavState mMediaNavState;
  354. F64 mInterest;
  355. bool mUsedInUI;
  356. bool mHasFocus;
  357. LLPluginClassMedia::EPriority mPriority;
  358. bool mNavigateRediscoverType;
  359. bool mNavigateServerRequest;
  360. bool mMediaSourceFailed;
  361. F32 mRequestedVolume;
  362. bool mIsMuted;
  363. bool mNeedsMuteCheck;
  364. int mPreviousMediaState;
  365. F64 mPreviousMediaTime;
  366. bool mIsDisabled;
  367. bool mIsParcelMedia;
  368. S32 mProximity;
  369. F64 mProximityDistance;
  370. F64 mProximityCamera;
  371. LLMimeDiscoveryResponder *mMimeTypeProbe;
  372. bool mMediaAutoPlay;
  373. std::string mMediaEntryURL;
  374. bool mInNearbyMediaList; // used by LLPanelNearbyMedia::refreshList() for performance reasons
  375. bool mClearCache;
  376. LLColor4 mBackgroundColor;
  377. bool mNavigateSuspended;
  378. bool mNavigateSuspendedDeferred;
  379. bool mTrustedBrowser;
  380. std::string mTarget;
  381. LLNotificationPtr mNotification;
  382. private:
  383. BOOL mIsUpdated ;
  384. std::list< LLVOVolume* > mObjectList ;
  385. private:
  386. LLViewerMediaTexture *updatePlaceholderImage();
  387. };
  388. #endif // LLVIEWERMEDIA_H