totem r5158 - in trunk: . browser-plugin



Author: hadess
Date: Thu Feb 21 01:18:25 2008
New Revision: 5158
URL: http://svn.gnome.org/viewvc/totem?rev=5158&view=rev

Log:
2008-02-21  Bastien Nocera  <hadess hadess net>

	* browser-plugin/totemNarrowSpacePlugin.cpp:
	* browser-plugin/totemPlugin.cpp:
	* browser-plugin/totemPlugin.h: Implement SetTime
	using NPN_RequestRead() if it's available on the stream
	(which it usually never is...) (Closes: #474841)



Modified:
   trunk/ChangeLog
   trunk/browser-plugin/totemNarrowSpacePlugin.cpp
   trunk/browser-plugin/totemPlugin.cpp
   trunk/browser-plugin/totemPlugin.h

Modified: trunk/browser-plugin/totemNarrowSpacePlugin.cpp
==============================================================================
--- trunk/browser-plugin/totemNarrowSpacePlugin.cpp	(original)
+++ trunk/browser-plugin/totemNarrowSpacePlugin.cpp	Thu Feb 21 01:18:25 2008
@@ -860,6 +860,8 @@
 {
   TOTEM_SCRIPTABLE_LOG_ACCESS ();
 
+  NS_ENSURE_STATE (IsValid ());
+
   *_retval = mPlugin->mTime;
   return NS_OK;
 }
@@ -868,9 +870,16 @@
 NS_IMETHODIMP
 totemScriptablePlugin::SetTime(PRUint32 time)
 {
-  TOTEM_SCRIPTABLE_WARN_UNIMPLEMENTED();
+  NPByteRange byterange;
 
-  return NS_OK;
+  TOTEM_SCRIPTABLE_LOG_ACCESS ();
+
+  NS_ENSURE_STATE (IsValid ());
+
+  if (mPlugin->mTime <= 0)
+    return NS_ERROR_NOT_AVAILABLE;
+
+  return mPlugin->RequestRead (time * mPlugin->mBytesLength / mPlugin->mTime);
 }
 
 /* unsigned long GetTimeScale (); */

Modified: trunk/browser-plugin/totemPlugin.cpp
==============================================================================
--- trunk/browser-plugin/totemPlugin.cpp	(original)
+++ trunk/browser-plugin/totemPlugin.cpp	Thu Feb 21 01:18:25 2008
@@ -2085,7 +2085,7 @@
 	if (!stream || !stream->url)
 		return NPERR_GENERIC_ERROR;
 
-	D ("NewStream mimetype '%s' URL '%s'", (const char *) type, stream->url);
+	D ("NewStream mimetype '%s' URL '%s' seekable '%s'", (const char *) type, stream->url, seekable ? "TRUE" : "FALSE");
 
 	/* We already have a live stream */
 	if (mStream) {
@@ -2143,6 +2143,9 @@
 	if (g_str_has_prefix (stream->url, "file://")) {
 		*stype = NP_ASFILEONLY;
 		mStreamType = NP_ASFILEONLY;
+	} else if (seekable) {
+		*stype = NP_SEEK;
+		mStreamType = NP_SEEK;
 	} else {
 		*stype = NP_ASFILE;
 		mStreamType = NP_ASFILE;
@@ -2162,6 +2165,7 @@
 	/* To track how many data we get from ::Write */
 	mBytesStreamed = 0;
 	mBytesLength = stream->end;
+	mSeekable = seekable;
 
 	return NPERR_NO_ERROR;
 }
@@ -2178,6 +2182,7 @@
 	mStream = nsnull;
 	mBytesStreamed = 0;
 	mBytesLength = 0;
+	mSeekable = PR_FALSE;
 
 	int ret = close (mViewerFD);
 	if (ret < 0) {
@@ -2190,6 +2195,30 @@
 	return NPERR_NO_ERROR;
 }
 
+nsresult
+totemPlugin::RequestRead (PRInt32 offset)
+{
+	NPByteRange range;
+
+	if (!mStream)
+		return NS_ERROR_INVALID_POINTER;
+	if (!mSeekable)
+		return NS_ERROR_NOT_AVAILABLE;
+
+	D ("RequestRead %d", offset);
+
+	range.offset = offset;
+	range.length = mBytesLength - offset;
+	range.next = NULL;
+
+	if (CallNPN_RequestReadProc (sNPN.requestread,
+				     mStream,
+				     &range) == NPERR_NO_ERROR)
+		return NPERR_NO_ERROR;
+
+	return NPERR_GENERIC_ERROR;
+}
+
 int32
 totemPlugin::WriteReady (NPStream *stream)
 {
@@ -2280,7 +2309,7 @@
 	} else /* ret >= 0 */ {
 		DD ("Wrote %d bytes", ret);
 
-		mBytesStreamed += ret;
+		mBytesStreamed = offset + ret;
 	}
 
 	return ret;

Modified: trunk/browser-plugin/totemPlugin.h
==============================================================================
--- trunk/browser-plugin/totemPlugin.h	(original)
+++ trunk/browser-plugin/totemPlugin.h	Thu Feb 21 01:18:25 2008
@@ -87,7 +87,7 @@
                        uint16* stype);
     NPError DestroyStream (NPStream* stream,
                            NPError reason);
-  
+    nsresult RequestRead (PRInt32 offset);
     int32 WriteReady (NPStream *stream);
     int32 Write (NPStream *stream,
                 int32 offset,
@@ -193,6 +193,7 @@
   public:
     PRUint32 mBytesStreamed;
     PRUint32 mBytesLength;
+    PRBool   mSeekable;
   private:
     PRUint8 mStreamType;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]