session: improve RTP-Info
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-stream-transport.c
index 9c1f9c2..4020ee4 100644 (file)
@@ -315,10 +315,10 @@ gst_rtsp_stream_transport_get_url (GstRTSPStreamTransport * trans)
  * @trans: a #GstRTSPStreamTransport
  * @start_time: a star time
  *
- * Get the RTPInfo string for @trans and @start_time.
+ * Get the RTP-Info string for @trans and @start_time.
  *
- * Returns: the RTPInfo string for @trans and @start_time. g_free() after
- * usage.
+ * 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,
@@ -327,15 +327,35 @@ gst_rtsp_stream_transport_get_rtpinfo (GstRTSPStreamTransport * trans,
   GstRTSPStreamTransportPrivate *priv;
   gchar *url_str;
   GString *rtpinfo;
-  guint rtptime, seq;
+  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, NULL))
+  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);