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