session: improve RTP-Info
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-stream-transport.c
index 90e6310..4020ee4 100644 (file)
@@ -310,6 +310,62 @@ gst_rtsp_stream_transport_get_url (GstRTSPStreamTransport * trans)
   return trans->priv->url;
 }
 
+ /**
+ * gst_rtsp_stream_transport_get_rtpinfo:
+ * @trans: a #GstRTSPStreamTransport
+ * @start_time: a star time
+ *
+ * Get the RTP-Info string for @trans and @start_time.
+ *
+ * Returns: the RTPInfo string for @trans and @start_time or %NULL when
+ * the RTP-Info could not be determined. g_free() after usage.
+ */
+gchar *
+gst_rtsp_stream_transport_get_rtpinfo (GstRTSPStreamTransport * trans,
+    GstClockTime start_time)
+{
+  GstRTSPStreamTransportPrivate *priv;
+  gchar *url_str;
+  GString *rtpinfo;
+  guint rtptime, seq, clock_rate;
+  GstClockTime running_time = GST_CLOCK_TIME_NONE;
+
+  g_return_val_if_fail (GST_IS_RTSP_STREAM_TRANSPORT (trans), NULL);
+
+  priv = trans->priv;
+
+  if (!gst_rtsp_stream_get_rtpinfo (priv->stream, &rtptime, &seq, &clock_rate,
+          &running_time))
+    return NULL;
+
+  GST_DEBUG ("RTP time %u, seq %u, rate %u, running-time %" GST_TIME_FORMAT,
+      rtptime, seq, clock_rate, GST_TIME_ARGS (running_time));
+
+  if (GST_CLOCK_TIME_IS_VALID (running_time)
+      && GST_CLOCK_TIME_IS_VALID (start_time)) {
+    if (running_time > start_time) {
+      rtptime -=
+          gst_util_uint64_scale_int (running_time - start_time, clock_rate,
+          GST_SECOND);
+    } else {
+      rtptime +=
+          gst_util_uint64_scale_int (start_time - running_time, clock_rate,
+          GST_SECOND);
+    }
+  }
+  GST_DEBUG ("RTP time %u, for start-time %" GST_TIME_FORMAT,
+      rtptime, GST_TIME_ARGS (start_time));
+
+  rtpinfo = g_string_new ("");
+
+  url_str = gst_rtsp_url_get_request_uri (trans->priv->url);
+  g_string_append_printf (rtpinfo, "url=%s;seq=%u;rtptime=%u",
+      url_str, seq, rtptime);
+  g_free (url_str);
+
+  return g_string_free (rtpinfo, FALSE);
+}
+
 /**
  * gst_rtsp_stream_transport_set_active:
  * @trans: a #GstRTSPStreamTransport