stream: return clock-rate from get_rtpinfo
authorWim Taymans <wtaymans@redhat.com>
Thu, 26 Dec 2013 16:02:50 +0000 (17:02 +0100)
committerWim Taymans <wtaymans@redhat.com>
Thu, 26 Dec 2013 16:14:06 +0000 (17:14 +0100)
And use it to correct the rtptime to the requested start-time.

See https://bugzilla.gnome.org/show_bug.cgi?id=712198

gst/rtsp-server/rtsp-session-media.c
gst/rtsp-server/rtsp-stream-transport.c
gst/rtsp-server/rtsp-stream.c
gst/rtsp-server/rtsp-stream.h

index 78faeed..da82167 100644 (file)
@@ -276,7 +276,7 @@ gst_rtsp_session_media_get_rtpinfo (GstRTSPSessionMedia * media)
     }
 
     stream = gst_rtsp_stream_transport_get_stream (transport);
-    if (!gst_rtsp_stream_get_rtpinfo (stream, NULL, NULL, &running_time))
+    if (!gst_rtsp_stream_get_rtpinfo (stream, NULL, NULL, NULL, &running_time))
       continue;
 
     GST_LOG_OBJECT (media, "running time of %d stream: %" GST_TIME_FORMAT, i,
index 9c1f9c2..ea0a04f 100644 (file)
@@ -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);
index 3380bd0..01ed7b7 100644 (file)
@@ -1751,6 +1751,7 @@ was_not_joined:
  * @stream: a #GstRTSPStream
  * @rtptime: (allow-none): result RTP timestamp
  * @seq: (allow-none): result RTP seqnum
+ * @clock_rate: the clock rate
  * @running_time: (allow-none): result running-time
  *
  * Retrieve the current rtptime, seq and running-time. This is used to
@@ -1760,7 +1761,8 @@ was_not_joined:
  */
 gboolean
 gst_rtsp_stream_get_rtpinfo (GstRTSPStream * stream,
-    guint * rtptime, guint * seq, GstClockTime * running_time)
+    guint * rtptime, guint * seq, guint * clock_rate,
+    GstClockTime * running_time)
 {
   GstRTSPStreamPrivate *priv;
   GObjectClass *payobjclass;
@@ -1771,6 +1773,7 @@ gst_rtsp_stream_get_rtpinfo (GstRTSPStream * stream,
 
   payobjclass = G_OBJECT_GET_CLASS (priv->payloader);
 
+  g_mutex_lock (&priv->lock);
   if (seq && g_object_class_find_property (payobjclass, "seqnum"))
     g_object_get (priv->payloader, "seqnum", seq, NULL);
 
@@ -1781,6 +1784,16 @@ gst_rtsp_stream_get_rtpinfo (GstRTSPStream * stream,
       && g_object_class_find_property (payobjclass, "running-time"))
     g_object_get (priv->payloader, "running-time", running_time, NULL);
 
+  if (clock_rate && priv->caps) {
+    GstStructure *s;
+
+    s = gst_caps_get_structure (priv->caps, 0);
+    if (!gst_structure_get_int (s, "clock-rate", (gint *) clock_rate))
+      if (running_time)
+        *running_time = GST_CLOCK_TIME_NONE;
+  }
+  g_mutex_unlock (&priv->lock);
+
   return TRUE;
 }
 
index 0eac432..b665a66 100644 (file)
@@ -119,6 +119,7 @@ void              gst_rtsp_stream_get_ssrc         (GstRTSPStream *stream,
 
 gboolean          gst_rtsp_stream_get_rtpinfo      (GstRTSPStream *stream,
                                                     guint *rtptime, guint *seq,
+                                                    guint *clock_rate,
                                                     GstClockTime *running_time);
 GstCaps *         gst_rtsp_stream_get_caps         (GstRTSPStream *stream);