diff options
author | Andre Moreira Magalhaes (andrunko) <andre.magalhaes@collabora.co.uk> | 2013-04-16 17:23:02 -0300 |
---|---|---|
committer | Thiago Santos <thiago.sousa.santos@collabora.com> | 2013-05-07 20:02:41 -0300 |
commit | f72869816c543ef9c01abdd79fecf63a1ba2fbec (patch) | |
tree | f38d6765d6492ef3a9bdfd0ad6dc731c5d19ef6d /gst-libs | |
parent | 859635ca0102bc286d1d8633d2688efb9bb4fae9 (diff) | |
download | gstreamer-plugins-bad-f72869816c543ef9c01abdd79fecf63a1ba2fbec.tar.gz |
uridownloader: make cancelled state 'permanent' until a reset
When downloading and cancelling quickly the uridownloader object and the
element using it could miss the cancelled window and the uridownloader
would fetch the wrong URI and block on subsequent fetches.
This was also problematic when stopping elements, while one task would
call the cancel, another element thread could issue a new fetch_uri. As
the cancel state isn't 'permanent' this fetch_uri would block and
prevent the whole element from stopping and going to NULL.
This patch makes the 'cancelled' state permanent until a
gst_uri_downloader_reset is called. This way the element knows the
window where the uridownloader isn't active and only reactivate it when
ready.
Diffstat (limited to 'gst-libs')
-rw-r--r-- | gst-libs/gst/uridownloader/gsturidownloader.c | 35 | ||||
-rw-r--r-- | gst-libs/gst/uridownloader/gsturidownloader.h | 1 |
2 files changed, 33 insertions, 3 deletions
diff --git a/gst-libs/gst/uridownloader/gsturidownloader.c b/gst-libs/gst/uridownloader/gsturidownloader.c index 5384141ae..4ca0dc70e 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.c +++ b/gst-libs/gst/uridownloader/gsturidownloader.c @@ -41,6 +41,7 @@ struct _GstUriDownloaderPrivate GstFragment *download; GMutex lock; GCond cond; + gboolean cancelled; }; static void gst_uri_downloader_finalize (GObject * object); @@ -264,6 +265,16 @@ gst_uri_downloader_stop (GstUriDownloader * downloader) } void +gst_uri_downloader_reset (GstUriDownloader * downloader) +{ + g_return_if_fail (downloader != NULL); + + GST_OBJECT_LOCK (downloader); + downloader->priv->cancelled = FALSE; + GST_OBJECT_UNLOCK (downloader); +} + +void gst_uri_downloader_cancel (GstUriDownloader * downloader) { GST_OBJECT_LOCK (downloader); @@ -271,15 +282,21 @@ gst_uri_downloader_cancel (GstUriDownloader * downloader) GST_DEBUG_OBJECT (downloader, "Cancelling download"); g_object_unref (downloader->priv->download); downloader->priv->download = NULL; + downloader->priv->cancelled = TRUE; GST_OBJECT_UNLOCK (downloader); GST_DEBUG_OBJECT (downloader, "Signaling chain funtion"); g_mutex_lock (&downloader->priv->lock); g_cond_signal (&downloader->priv->cond); g_mutex_unlock (&downloader->priv->lock); } else { + gboolean cancelled; + + cancelled = downloader->priv->cancelled; + downloader->priv->cancelled = TRUE; GST_OBJECT_UNLOCK (downloader); - GST_DEBUG_OBJECT (downloader, - "Trying to cancell a download that was alredy cancelled"); + if (cancelled) + GST_DEBUG_OBJECT (downloader, + "Trying to cancell a download that was alredy cancelled"); } } @@ -319,6 +336,10 @@ gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri) g_mutex_lock (&downloader->priv->lock); + if (downloader->priv->cancelled) { + goto quit; + } + if (!gst_uri_downloader_set_uri (downloader, uri)) { goto quit; } @@ -337,9 +358,17 @@ gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri) * - the download failed (Error message on the fetcher bus) * - the download was canceled */ - GST_DEBUG_OBJECT (downloader, "Waiting to fetch the URI"); + GST_DEBUG_OBJECT (downloader, "Waiting to fetch the URI %s", uri); g_cond_wait (&downloader->priv->cond, &downloader->priv->lock); + if (downloader->priv->cancelled) { + if (downloader->priv->download) { + g_object_unref (downloader->priv->download); + downloader->priv->download = NULL; + } + goto quit; + } + GST_OBJECT_LOCK (downloader); download = downloader->priv->download; downloader->priv->download = NULL; diff --git a/gst-libs/gst/uridownloader/gsturidownloader.h b/gst-libs/gst/uridownloader/gsturidownloader.h index 8c1a6ec28..c29cb52b3 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.h +++ b/gst-libs/gst/uridownloader/gsturidownloader.h @@ -57,6 +57,7 @@ GType gst_uri_downloader_get_type (void); GstUriDownloader * gst_uri_downloader_new (void); GstFragment * gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri); +void gst_uri_downloader_reset (GstUriDownloader *downloader); void gst_uri_downloader_cancel (GstUriDownloader *downloader); void gst_uri_downloader_free (GstUriDownloader *downloader); |