hlsdemux: add stream switch patch 85/188085/3
authorEunhae Choi <eunhae1.choi@samsung.com>
Fri, 31 Aug 2018 06:38:47 +0000 (15:38 +0900)
committerEunhae Choi <eunhae1.choi@samsung.com>
Fri, 31 Aug 2018 08:26:14 +0000 (17:26 +0900)
Change-Id: Ic6cce49a7e8be86d592b977e38894b6b02d9eaea

ext/hls/gsthlsdemux.c

index c29017cf59252d4c1e065527a9e1274daeffe0b4..e21bf342079c4a650f9c61e38649cf1d5a2e27db 100644 (file)
@@ -488,6 +488,83 @@ gst_hls_demux_update_manifest (GstAdaptiveDemux * demux)
   return GST_FLOW_OK;
 }
 
+#ifdef TIZEN_FEATURE_AVOID_PAD_SWITCHING
+static GstAdaptiveDemuxStream *
+gst_adaptive_demux_find_stream (GstAdaptiveDemux * demux, gboolean is_primary_playlist, GstHLSMediaType type)
+{
+  GstAdaptiveDemuxStream *stream;
+  GstHLSDemuxStream *hls_stream;
+  GList *iter;
+  GstCaps *caps;
+  gchar *caps_str;
+  gboolean find_stream = FALSE;
+
+  for (iter = demux->streams; iter; iter = g_list_next (iter)) {
+    stream = iter->data;
+    if (!stream) {
+      GST_ERROR_OBJECT(demux, "no stream data");
+      continue;
+    }
+    hls_stream = GST_HLS_DEMUX_STREAM_CAST(stream);
+    if (is_primary_playlist && hls_stream->is_primary_playlist)
+      return stream;
+
+    caps = gst_pad_get_current_caps(stream->pad);
+    caps_str = gst_caps_to_string(caps);
+    GST_DEBUG_OBJECT(demux, "pad %s:%s, caps %s", GST_DEBUG_PAD_NAME(stream->pad), caps_str);
+
+    if (((type == GST_HLS_MEDIA_TYPE_AUDIO) && (g_strrstr(caps_str, "audio"))) ||
+        ((type == GST_HLS_MEDIA_TYPE_VIDEO) && (g_strrstr(caps_str, "video"))))
+      find_stream = TRUE;
+
+      g_free (caps_str);
+      gst_caps_unref(caps);
+
+    if (find_stream)
+      return stream;
+  }
+
+  GST_WARNING_OBJECT(demux, "failed to find stream %d %d", is_primary_playlist, type);
+  return NULL;
+}
+
+static void
+create_stream_for_playlist (GstAdaptiveDemux * demux, GstM3U8 * playlist,
+    gboolean is_primary_playlist, GstHLSMediaType type)
+{
+  GstHLSDemux *hlsdemux = GST_HLS_DEMUX_CAST (demux);
+  GstHLSDemuxStream *hlsdemux_stream = NULL;
+  GstAdaptiveDemuxStream *stream = NULL;
+
+  if (!is_primary_playlist &&
+      type != GST_HLS_MEDIA_TYPE_AUDIO && type != GST_HLS_MEDIA_TYPE_VIDEO) {
+    /* FIXME: Later, create the stream but mark not-selected */
+    GST_LOG_OBJECT (demux, "Ignoring not-selected stream");
+    return;
+  }
+
+  GST_DEBUG_OBJECT(demux, "streams list %d", g_list_length(demux->streams));
+
+  if (demux->streams)
+    stream = gst_adaptive_demux_find_stream(demux, is_primary_playlist, type);
+
+  if (!stream) {
+    GST_LOG_OBJECT(demux, "new pad will be created");
+    stream = gst_adaptive_demux_stream_new (demux,
+        gst_hls_demux_create_pad (hlsdemux));
+  }
+
+  hlsdemux_stream = GST_HLS_DEMUX_STREAM_CAST (stream);
+
+  hlsdemux_stream->stream_type = GST_HLS_TSREADER_NONE;
+
+  hlsdemux_stream->playlist = gst_m3u8_ref (playlist);
+  hlsdemux_stream->is_primary_playlist = is_primary_playlist;
+
+  hlsdemux_stream->do_typefind = TRUE;
+  hlsdemux_stream->reset_pts = TRUE;
+}
+#else
 static void
 create_stream_for_playlist (GstAdaptiveDemux * demux, GstM3U8 * playlist,
     gboolean is_primary_playlist, gboolean selected)
@@ -515,7 +592,7 @@ create_stream_for_playlist (GstAdaptiveDemux * demux, GstM3U8 * playlist,
   hlsdemux_stream->do_typefind = TRUE;
   hlsdemux_stream->reset_pts = TRUE;
 }
-
+#endif
 static gboolean
 gst_hls_demux_setup_streams (GstAdaptiveDemux * demux)
 {
@@ -531,8 +608,11 @@ gst_hls_demux_setup_streams (GstAdaptiveDemux * demux)
   gst_hls_demux_clear_all_pending_data (hlsdemux);
 
   /* 1 output for the main playlist */
+#ifdef TIZEN_FEATURE_AVOID_PAD_SWITCHING
+  create_stream_for_playlist (demux, playlist->m3u8, TRUE, GST_HLS_MEDIA_TYPE_INVALID);
+#else
   create_stream_for_playlist (demux, playlist->m3u8, TRUE, TRUE);
-
+#endif
   for (i = 0; i < GST_HLS_N_MEDIA_TYPES; ++i) {
     GList *mlist = playlist->media[i];
     while (mlist != NULL) {
@@ -548,9 +628,13 @@ gst_hls_demux_setup_streams (GstAdaptiveDemux * demux)
       }
       GST_LOG_OBJECT (demux, "media of type %d - %s, uri: %s", i,
           media->name, media->uri);
+#ifdef TIZEN_FEATURE_AVOID_PAD_SWITCHING
+      create_stream_for_playlist (demux, media->playlist, FALSE, media->mtype);
+#else
       create_stream_for_playlist (demux, media->playlist, FALSE,
           (media->mtype == GST_HLS_MEDIA_TYPE_VIDEO ||
               media->mtype == GST_HLS_MEDIA_TYPE_AUDIO));
+#endif
 
       mlist = mlist->next;
     }