From 9514f2d3549f1c8847e69d3ce6e76a693bd1dc38 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 24 Nov 2017 17:34:31 +0100 Subject: [PATCH] rtsp-media: Enable seeking query before pipeline is complete SDP are now provided *before* the pipeline is fully complete. In order to know whether a media is seekable or not therefore requires asking the invididual streams. API: gst_rtsp_stream_seekable https://bugzilla.gnome.org/show_bug.cgi?id=790674 --- docs/libs/gst-rtsp-server-sections.txt | 2 ++ gst/rtsp-server/rtsp-media.c | 12 ++++++++ gst/rtsp-server/rtsp-stream.c | 52 ++++++++++++++++++++++++++++++++++ gst/rtsp-server/rtsp-stream.h | 3 ++ win32/common/libgstrtspserver.def | 1 + 5 files changed, 70 insertions(+) diff --git a/docs/libs/gst-rtsp-server-sections.txt b/docs/libs/gst-rtsp-server-sections.txt index f57bc58..3299fd7 100644 --- a/docs/libs/gst-rtsp-server-sections.txt +++ b/docs/libs/gst-rtsp-server-sections.txt @@ -610,6 +610,8 @@ gst_rtsp_stream_update_crypto gst_rtsp_stream_set_pt_map gst_rtsp_stream_request_aux_sender +gst_rtsp_stream_seekable + GstRTSPStreamTransportFilterFunc gst_rtsp_stream_transport_filter diff --git a/gst/rtsp-server/rtsp-media.c b/gst/rtsp-server/rtsp-media.c index aead378..e10ad8b 100644 --- a/gst/rtsp-server/rtsp-media.c +++ b/gst/rtsp-server/rtsp-media.c @@ -703,8 +703,20 @@ check_seekable (GstRTSPMedia * media) gst_query_parse_seeking (query, &format, &seekable, &start, &end); priv->seekable = seekable ? G_MAXINT64 : 0; + } else if (priv->streams->len) { + gboolean seekable = TRUE; + guint i, n = priv->streams->len; + + GST_DEBUG_OBJECT (media, "Checking %d streams", n); + for (i = 0; i < n; i++) { + GstRTSPStream *stream = g_ptr_array_index (priv->streams, i); + seekable &= gst_rtsp_stream_seekable (stream); + } + priv->seekable = seekable ? G_MAXINT64 : -1; } + GST_DEBUG_OBJECT (media, "seekable:%" G_GINT64_FORMAT, priv->seekable); + gst_query_unref (query); } diff --git a/gst/rtsp-server/rtsp-stream.c b/gst/rtsp-server/rtsp-stream.c index 7b458b1..fee99ac 100644 --- a/gst/rtsp-server/rtsp-stream.c +++ b/gst/rtsp-server/rtsp-stream.c @@ -4450,6 +4450,58 @@ gst_rtsp_stream_query_stop (GstRTSPStream * stream, gint64 * stop) } /** + * gst_rtsp_stream_seekable: + * @stream: a #GstRTSPStream + * + * Checks whether the individual @stream is seekable. + * + * Returns: %TRUE if @stream is seekable, else %FALSE. + */ +gboolean +gst_rtsp_stream_seekable (GstRTSPStream * stream) +{ + GstRTSPStreamPrivate *priv; + GstPad *pad = NULL; + GstQuery *query = NULL; + gboolean seekable = FALSE; + + g_return_val_if_fail (GST_IS_RTSP_STREAM (stream), FALSE); + + /* query stop position: if no sinks have been added yet, + * we obtain the stop position from the pad otherwise we query the sinks */ + + priv = stream->priv; + + g_mutex_lock (&priv->lock); + /* depending on the transport type, it should query corresponding sink */ + if (priv->srcpad) { + pad = gst_object_ref (priv->srcpad); + } else { + g_mutex_unlock (&priv->lock); + GST_WARNING_OBJECT (stream, "Pad not available, can't query seekability"); + goto beach; + } + g_mutex_unlock (&priv->lock); + + query = gst_query_new_seeking (GST_FORMAT_TIME); + if (!gst_pad_query (pad, query)) { + GST_WARNING_OBJECT (stream, "seeking query failed"); + goto beach; + } + gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL); + +beach: + if (pad) + gst_object_unref (pad); + if (query) + gst_query_unref (query); + + GST_DEBUG_OBJECT (stream, "Returning %d", seekable); + + return seekable; +} + +/** * gst_rtsp_stream_complete_stream: * @stream: a #GstRTSPStream * @transport: a #GstRTSPTransport diff --git a/gst/rtsp-server/rtsp-stream.h b/gst/rtsp-server/rtsp-stream.h index 37a8275..3583d4a 100644 --- a/gst/rtsp-server/rtsp-stream.h +++ b/gst/rtsp-server/rtsp-stream.h @@ -244,6 +244,9 @@ gboolean gst_rtsp_stream_query_stop (GstRTSPStream * stream, gint64 * stop); GST_EXPORT +gboolean gst_rtsp_stream_seekable (GstRTSPStream *stream); + +GST_EXPORT void gst_rtsp_stream_set_seqnum_offset (GstRTSPStream *stream, guint16 seqnum); GST_EXPORT diff --git a/win32/common/libgstrtspserver.def b/win32/common/libgstrtspserver.def index c624920..f233ac8 100644 --- a/win32/common/libgstrtspserver.def +++ b/win32/common/libgstrtspserver.def @@ -281,6 +281,7 @@ EXPORTS gst_rtsp_stream_remove_transport gst_rtsp_stream_request_aux_sender gst_rtsp_stream_reserve_address + gst_rtsp_stream_seekable gst_rtsp_stream_set_address_pool gst_rtsp_stream_set_blocked gst_rtsp_stream_set_buffer_size -- 2.7.4