adaptivedemux: start/stop the manifest update loop on liveness or periodic update...
authorMatthew Waters <matthew@centricular.com>
Mon, 14 Aug 2017 11:33:51 +0000 (21:33 +1000)
committerMatthew Waters <matthew@centricular.com>
Tue, 15 Aug 2017 05:19:32 +0000 (15:19 +1000)
Scenario:
A manifest starts out in live mode but then the recording is finalized
and a subsequent update changes the state to a non-live manifest when
the server has finished recording/transcoding/whatever with the full
list of fragments.

Without this patch, the manifest update task is never stopped on the
live->non-live transition and will busy loop, burning through one CPU
core.

https://bugzilla.gnome.org/show_bug.cgi?id=786275

gst-libs/gst/adaptivedemux/gstadaptivedemux.c

index 9ee1a76..32d565d 100644 (file)
@@ -2027,6 +2027,7 @@ gst_adaptive_demux_stop_manifest_update_task (GstAdaptiveDemux * demux)
   gst_task_stop (demux->priv->updates_task);
 
   g_mutex_lock (&demux->priv->updates_timed_lock);
+  GST_DEBUG_OBJECT (demux, "requesting stop of the manifest update task");
   demux->priv->stop_updates_task = TRUE;
   g_cond_signal (&demux->priv->updates_timed_cond);
   g_mutex_unlock (&demux->priv->updates_timed_lock);
@@ -2045,6 +2046,7 @@ gst_adaptive_demux_start_manifest_update_task (GstAdaptiveDemux * demux)
     g_mutex_unlock (&demux->priv->updates_timed_lock);
     /* Task to periodically update the manifest */
     if (demux_class->requires_periodical_playlist_update (demux)) {
+      GST_DEBUG_OBJECT (demux, "requesting start of the manifest update task");
       gst_task_start (demux->priv->updates_task);
     }
   }
@@ -4361,6 +4363,18 @@ gst_adaptive_demux_update_manifest (GstAdaptiveDemux * demux)
       GST_DEBUG_OBJECT (demux,
           "Duration unknown, can not send the duration message");
     }
+
+    /* If a manifest changes it's liveness or periodic updateness, we need
+     * to start/stop the manifest update task appropriately */
+    /* Keep this condition in sync with the one in
+     * gst_adaptive_demux_start_manifest_update_task()
+     */
+    if (gst_adaptive_demux_is_live (demux) &&
+        klass->requires_periodical_playlist_update (demux)) {
+      gst_adaptive_demux_start_manifest_update_task (demux);
+    } else {
+      gst_adaptive_demux_stop_manifest_update_task (demux);
+    }
   }
 
   return ret;