adaptivedemux: Support period change in live playlist

Regardless of LIVE or VOD, "a manifest has next period but
currently EOSed" state is meaning that it's time to advance period.

Previous behavior of adpativedemux, however, was able to period
advancing only for VOD case, since the adaptivedemux tried to
update and wait new manifest without respecting existence of the next period.

https://bugzilla.gnome.org/show_bug.cgi?id=781183
diff --git a/gst-libs/gst/adaptivedemux/gstadaptivedemux.c b/gst-libs/gst/adaptivedemux/gstadaptivedemux.c
index 540cd52..a0c075b 100644
--- a/gst-libs/gst/adaptivedemux/gstadaptivedemux.c
+++ b/gst-libs/gst/adaptivedemux/gstadaptivedemux.c
@@ -3783,8 +3783,11 @@
         if (!demux_class->requires_periodical_playlist_update (demux)) {
           ret = gst_adaptive_demux_update_manifest (demux);
           break;
-        } else if (gst_adaptive_demux_stream_wait_manifest_update (demux,
-                stream)) {
+          /* Wait only if we can ensure current manifest has been expired.
+           * The meaning "we have next period" *WITH* EOS is that, current
+           * period has been ended but we can continue to the next period */
+        } else if (!gst_adaptive_demux_has_next_period (demux) &&
+            gst_adaptive_demux_stream_wait_manifest_update (demux, stream)) {
           goto end;
         }
         gst_task_stop (stream->download_task);
@@ -3793,13 +3796,14 @@
         }
       } else {
         gst_task_stop (stream->download_task);
-        if (gst_adaptive_demux_combine_flows (demux) == GST_FLOW_EOS) {
-          if (gst_adaptive_demux_has_next_period (demux)) {
-            GST_DEBUG_OBJECT (stream->pad,
-                "Next period available, not sending EOS");
-            gst_adaptive_demux_advance_period (demux);
-            ret = GST_FLOW_OK;
-          }
+      }
+
+      if (gst_adaptive_demux_combine_flows (demux) == GST_FLOW_EOS) {
+        if (gst_adaptive_demux_has_next_period (demux)) {
+          GST_DEBUG_OBJECT (stream->pad,
+              "Next period available, not sending EOS");
+          gst_adaptive_demux_advance_period (demux);
+          ret = GST_FLOW_OK;
         }
       }
       break;