session-media: calculate start-time

This commit is contained in:
Wim Taymans 2013-12-26 16:28:59 +01:00
parent cfdc7408b5
commit 037e21b578
3 changed files with 51 additions and 5 deletions

View file

@ -248,15 +248,51 @@ gst_rtsp_session_media_get_rtpinfo (GstRTSPSessionMedia * media)
GstRTSPSessionMediaPrivate *priv; GstRTSPSessionMediaPrivate *priv;
GString *rtpinfo = NULL; GString *rtpinfo = NULL;
GstRTSPStreamTransport *transport; GstRTSPStreamTransport *transport;
GstRTSPStream *stream;
guint i, n_streams; guint i, n_streams;
GstClockTime earliest = GST_CLOCK_TIME_NONE;
g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL); g_return_val_if_fail (GST_IS_RTSP_SESSION_MEDIA (media), NULL);
priv = media->priv; priv = media->priv;
g_mutex_lock (&priv->lock); g_mutex_lock (&priv->lock);
if (gst_rtsp_media_get_status (priv->media) != GST_RTSP_MEDIA_STATUS_PREPARED)
goto not_prepared;
n_streams = priv->transports->len; n_streams = priv->transports->len;
/* first step, take lowest running-time from all streams */
GST_LOG_OBJECT (media, "determining start time among %d transports",
n_streams);
for (i = 0; i < n_streams; i++) {
GstClockTime running_time;
transport = g_ptr_array_index (priv->transports, i);
if (transport == NULL) {
GST_DEBUG_OBJECT (media, "ignoring unconfigured transport %d", i);
continue;
}
stream = gst_rtsp_stream_transport_get_stream (transport);
if (!gst_rtsp_stream_get_rtpinfo (stream, NULL, NULL, &running_time))
continue;
GST_LOG_OBJECT (media, "running time of %d stream: %" GST_TIME_FORMAT, i,
GST_TIME_ARGS (running_time));
if (!GST_CLOCK_TIME_IS_VALID (earliest)) {
earliest = running_time;
} else {
earliest = MIN (earliest, running_time);
}
}
GST_LOG_OBJECT (media, "media start time: %" GST_TIME_FORMAT,
GST_TIME_ARGS (earliest));
/* next step, scale all rtptime of all streams to lowest running-time */
GST_LOG_OBJECT (media, "collecting RTP info for %d transports", n_streams); GST_LOG_OBJECT (media, "collecting RTP info for %d transports", n_streams);
for (i = 0; i < n_streams; i++) { for (i = 0; i < n_streams; i++) {
@ -268,7 +304,8 @@ gst_rtsp_session_media_get_rtpinfo (GstRTSPSessionMedia * media)
continue; continue;
} }
stream_rtpinfo = gst_rtsp_stream_transport_get_rtpinfo (transport); stream_rtpinfo =
gst_rtsp_stream_transport_get_rtpinfo (transport, earliest);
if (stream_rtpinfo == NULL) if (stream_rtpinfo == NULL)
goto stream_rtpinfo_missing; goto stream_rtpinfo_missing;
@ -291,6 +328,12 @@ gst_rtsp_session_media_get_rtpinfo (GstRTSPSessionMedia * media)
return g_string_free (rtpinfo, FALSE); return g_string_free (rtpinfo, FALSE);
/* ERRORS */ /* ERRORS */
not_prepared:
{
g_mutex_unlock (&priv->lock);
GST_ERROR_OBJECT (media, "media was not prepared");
return NULL;
}
stream_rtpinfo_missing: stream_rtpinfo_missing:
{ {
g_mutex_unlock (&priv->lock); g_mutex_unlock (&priv->lock);

View file

@ -313,14 +313,16 @@ gst_rtsp_stream_transport_get_url (GstRTSPStreamTransport * trans)
/** /**
* gst_rtsp_stream_transport_get_rtpinfo: * gst_rtsp_stream_transport_get_rtpinfo:
* @trans: a #GstRTSPStreamTransport * @trans: a #GstRTSPStreamTransport
* @start_time: a star time
* *
* Get the RTPInfo string for @trans. * Get the RTPInfo string for @trans and @start_time.
* *
* Returns: the RTPInfo string for @trans. g_free() after * Returns: the RTPInfo string for @trans and @start_time. g_free() after
* usage. * usage.
*/ */
gchar * gchar *
gst_rtsp_stream_transport_get_rtpinfo (GstRTSPStreamTransport * trans) gst_rtsp_stream_transport_get_rtpinfo (GstRTSPStreamTransport * trans,
GstClockTime start_time)
{ {
GstRTSPStreamTransportPrivate *priv; GstRTSPStreamTransportPrivate *priv;
gchar *url_str; gchar *url_str;

View file

@ -100,7 +100,8 @@ void gst_rtsp_stream_transport_set_url (GstRTSPStreamT
const GstRTSPUrl * gst_rtsp_stream_transport_get_url (GstRTSPStreamTransport *trans); const GstRTSPUrl * gst_rtsp_stream_transport_get_url (GstRTSPStreamTransport *trans);
gchar * gst_rtsp_stream_transport_get_rtpinfo (GstRTSPStreamTransport *trans); gchar * gst_rtsp_stream_transport_get_rtpinfo (GstRTSPStreamTransport *trans,
GstClockTime start_time);
void gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport *trans, void gst_rtsp_stream_transport_set_callbacks (GstRTSPStreamTransport *trans,
GstRTSPSendFunc send_rtp, GstRTSPSendFunc send_rtp,