PageRenderTime 1203ms CodeModel.GetById 202ms app.highlight 137ms RepoModel.GetById 746ms app.codeStats 1ms

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