From af4ae2c94249a22abc5fd87ff034e1c390f140fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Sat, 22 Jun 2024 11:15:50 +0200 Subject: [PATCH] clapper: Fix missing "download-complete" signal on short videos Short video might be fully downloaded before playback starts. This prevents us from emitting "download-complete" signal with corresponding media item when download cache is enabled. Check if we have pending item, as this will be the item downloaded in such case (before it becomes playing item). --- src/lib/clapper/clapper-playbin-bus.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/lib/clapper/clapper-playbin-bus.c b/src/lib/clapper/clapper-playbin-bus.c index 33819c5d..fd624f56 100644 --- a/src/lib/clapper/clapper-playbin-bus.c +++ b/src/lib/clapper/clapper-playbin-bus.c @@ -828,23 +828,39 @@ _handle_element_msg (GstMessage *msg, ClapperPlayer *player) g_free (name); g_free (details); } else if (gst_message_has_name (msg, "GstCacheDownloadComplete")) { + ClapperMediaItem *downloaded_item = NULL; const GstStructure *structure; const gchar *location; guint signal_id; - if (G_UNLIKELY (player->played_item == NULL)) + GST_OBJECT_LOCK (player); + + /* Short video might be fully downloaded before playback starts */ + if (player->pending_item) + downloaded_item = gst_object_ref (player->pending_item); + else if (player->played_item) + downloaded_item = gst_object_ref (player->played_item); + + GST_OBJECT_UNLOCK (player); + + if (G_UNLIKELY (downloaded_item == NULL)) { + GST_WARNING_OBJECT (player, "Download completed without media item set"); return; + } structure = gst_message_get_structure (msg); location = gst_structure_get_string (structure, "location"); signal_id = g_signal_lookup ("download-complete", CLAPPER_TYPE_PLAYER); - GST_INFO_OBJECT (player, "Download complete: %s", location); - clapper_media_item_set_cache_location (player->played_item, location); + GST_INFO_OBJECT (player, "Download of %" GST_PTR_FORMAT + " complete: %s", downloaded_item, location); + clapper_media_item_set_cache_location (downloaded_item, location); clapper_app_bus_post_object_desc_signal (player->app_bus, GST_OBJECT_CAST (player), signal_id, - GST_OBJECT_CAST (player->played_item), location); + GST_OBJECT_CAST (downloaded_item), location); + + gst_object_unref (downloaded_item); } }