From 9c487aff7017df24aa2f8b22e69b9c599725e4f3 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Fri, 9 Apr 2010 14:56:30 +0100 Subject: Split setting up and opening browser streams Wait until we have the browser stream set up before opening stdin in the browser, which means we might have a chance to get the stream size. With recent GStreamer changes, this means that download buffering would work, and that we'd get download progress and seeking without needing to wait until the end of the download. Helps with https://bugzilla.gnome.org/show_bug.cgi?id=608301 --- browser-plugin/org_gnome_totem_PluginViewer.xml | 5 +++- browser-plugin/totem-plugin-viewer.c | 39 ++++++++++++++++++------- browser-plugin/totemPlugin.cpp | 39 +++++++++++++++++++++++-- browser-plugin/totemPlugin.h | 3 ++ 4 files changed, 72 insertions(+), 14 deletions(-) (limited to 'browser-plugin') diff --git a/browser-plugin/org_gnome_totem_PluginViewer.xml b/browser-plugin/org_gnome_totem_PluginViewer.xml index efe97308..2218d27e 100644 --- a/browser-plugin/org_gnome_totem_PluginViewer.xml +++ b/browser-plugin/org_gnome_totem_PluginViewer.xml @@ -14,10 +14,13 @@ - + + + + diff --git a/browser-plugin/totem-plugin-viewer.c b/browser-plugin/totem-plugin-viewer.c index 0e40ce68..7459ea10 100644 --- a/browser-plugin/totem-plugin-viewer.c +++ b/browser-plugin/totem-plugin-viewer.c @@ -119,6 +119,7 @@ typedef struct _TotemEmbedded { char *href_uri; char *target; char *stream_uri; + gint64 size; /* the size of the streamed file for fd://0 */ BaconVideoWidget *bvw; TotemStates state; GdkCursor *cursor; @@ -403,14 +404,18 @@ totem_embedded_open_internal (TotemEmbedded *emb, GError **error) { gboolean retval; - const char *uri; + char *uri; /* FIXME: stop previous content, or is that automatic ? */ - if (emb->is_browser_stream) - uri = "fd://0"; - else - uri = emb->current_uri; + if (emb->is_browser_stream) { + if (emb->size > 0) + uri = g_strdup_printf ("fd://0?size=%"G_GINT64_FORMAT, emb->size); + else + uri = g_strdup ("fd://0"); + } else { + uri = g_strdup (emb->current_uri); + } if (!uri) { g_set_error_literal (error, @@ -428,6 +433,8 @@ totem_embedded_open_internal (TotemEmbedded *emb, bacon_video_widget_set_logo_mode (emb->bvw, FALSE); retval = bacon_video_widget_open (emb->bvw, uri, emb->current_subtitle_uri, NULL); + g_free (uri); + /* FIXME we shouldn't even do that here */ if (start_play) totem_embedded_play (emb, NULL); @@ -800,12 +807,12 @@ totem_embedded_open_uri (TotemEmbedded *emb, } static gboolean -totem_embedded_open_stream (TotemEmbedded *emb, - const char *uri, - const char *base_uri, - GError **error) +totem_embedded_setup_stream (TotemEmbedded *emb, + const char *uri, + const char *base_uri, + GError **error) { - g_message ("totem_embedded_open_stream called: uri %s, base_uri: %s", uri, base_uri); + g_message ("totem_embedded_setup_stream called: uri %s, base_uri: %s", uri, base_uri); totem_embedded_clear_playlist (emb, NULL); @@ -816,6 +823,18 @@ totem_embedded_open_stream (TotemEmbedded *emb, /* FIXME: consume any remaining input from stdin */ + return TRUE; +} + +static gboolean +totem_embedded_open_stream (TotemEmbedded *emb, + gint64 size, + GError **error) +{ + g_message ("totem_embedded_open_stream called: with size %"G_GINT64_FORMAT, size); + + emb->size = size; + return totem_embedded_open_internal (emb, TRUE, error); } diff --git a/browser-plugin/totemPlugin.cpp b/browser-plugin/totemPlugin.cpp index 12e9ac51..7c6f5a49 100644 --- a/browser-plugin/totemPlugin.cpp +++ b/browser-plugin/totemPlugin.cpp @@ -1064,7 +1064,7 @@ totemPlugin::RequestStream (bool aForceViewer) mRequestBaseURI = g_strdup (baseURI); /* If the URL is supported and the caller isn't asking us to make - * the viewer open the stream, we call OpenStream, and + * the viewer open the stream, we call SetupStream, and * otherwise OpenURI. */ if (!aForceViewer && IsSchemeSupported (requestURI, baseURI)) { /* This will fail for the 2nd stream, but we shouldn't @@ -1072,8 +1072,8 @@ totemPlugin::RequestStream (bool aForceViewer) mViewerPendingCall = dbus_g_proxy_begin_call (mViewerProxy, - "OpenStream", - ViewerOpenStreamCallback, + "SetupStream", + ViewerSetupStreamCallback, reinterpret_cast(this), NULL, G_TYPE_STRING, requestURI, @@ -1341,6 +1341,29 @@ totemPlugin::ViewerOpenStreamCallback (DBusGProxy *aProxy, plugin->mAutoPlay) { plugin->Command (TOTEM_COMMAND_PLAY); } +} + +/* static */ void +totemPlugin::ViewerSetupStreamCallback (DBusGProxy *aProxy, + DBusGProxyCall *aCall, + void *aData) +{ + totemPlugin *plugin = reinterpret_cast(aData); + + g_debug ("SetupStream reply"); + +// assert (aCall == plugin->mViewerPendingCall, "OpenStream not the current call"); + if (aCall != plugin->mViewerPendingCall) + return; + + plugin->mViewerPendingCall = NULL; + + GError *error = NULL; + if (!dbus_g_proxy_end_call (aProxy, aCall, &error, G_TYPE_INVALID)) { + g_warning ("SetupStream failed: %s", error->message); + g_error_free (error); + return; + } assert (!plugin->mExpectingStream); /* Already expecting a stream */ @@ -2235,6 +2258,16 @@ totemPlugin::NewStream (NPMIMEType type, mBytesStreamed = 0; mBytesLength = stream->end; + gint64 length = mBytesLength; + mViewerPendingCall = + dbus_g_proxy_begin_call (mViewerProxy, + "OpenStream", + ViewerOpenStreamCallback, + reinterpret_cast(this), + NULL, + G_TYPE_INT64, length, + G_TYPE_INVALID); + return NPERR_NO_ERROR; } diff --git a/browser-plugin/totemPlugin.h b/browser-plugin/totemPlugin.h index 14c56673..251b51f7 100644 --- a/browser-plugin/totemPlugin.h +++ b/browser-plugin/totemPlugin.h @@ -157,6 +157,9 @@ class totemPlugin { static void ViewerOpenStreamCallback (DBusGProxy *aProxy, DBusGProxyCall *aCall, void *aData); + static void ViewerSetupStreamCallback (DBusGProxy *aProxy, + DBusGProxyCall *aCall, + void *aData); static void ViewerOpenURICallback (DBusGProxy *aProxy, DBusGProxyCall *aCall, void *aData); -- cgit v1.2.3