From: Eunhae Choi Date: Fri, 31 Aug 2018 06:38:47 +0000 (+0900) Subject: hlsdemux: add stream switch patch X-Git-Tag: submit/tizen/20180912.051644~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F85%2F188085%2F3;p=platform%2Fupstream%2Fgst-plugins-bad.git hlsdemux: add stream switch patch Change-Id: Ic6cce49a7e8be86d592b977e38894b6b02d9eaea --- diff --git a/ext/hls/gsthlsdemux.c b/ext/hls/gsthlsdemux.c index c29017cf5..e21bf3420 100644 --- a/ext/hls/gsthlsdemux.c +++ b/ext/hls/gsthlsdemux.c @@ -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; }