gst/rtpmanager/: Do not mix the use of g_get_current_time() with gst_clock_get_time().

Original commit message from CVS:
* gst/rtpmanager/gstrtpsession.c: (gst_rtp_session_init),
(gst_rtp_session_finalize), (rtcp_thread),
(gst_rtp_session_chain_recv_rtp), (gst_rtp_session_chain_recv_rtcp),
(gst_rtp_session_event_send_rtp_sink),
(gst_rtp_session_chain_send_rtp):
* gst/rtpmanager/rtpsession.c: (check_collision),
(update_arrival_stats), (rtp_session_process_rtp),
(rtp_session_process_rtcp), (rtp_session_send_rtp),
(rtp_session_send_bye_locked), (rtp_session_send_bye),
(rtp_session_next_timeout), (session_report_blocks), (session_cleanup),
(is_rtcp_time), (rtp_session_on_timeout):
* gst/rtpmanager/rtpsession.h:
Do not mix the use of g_get_current_time() with gst_clock_get_time().
This commit is contained in:
Peter Kjellerstedt 2008-07-03 13:47:19 +00:00
parent 6da2ab35a9
commit 56988f51e1
5 changed files with 102 additions and 92 deletions

View file

@ -1,3 +1,19 @@
2008-07-03 Peter Kjellerstedt <pkj@axis.com>
* gst/rtpmanager/gstrtpsession.c: (gst_rtp_session_init),
(gst_rtp_session_finalize), (rtcp_thread),
(gst_rtp_session_chain_recv_rtp), (gst_rtp_session_chain_recv_rtcp),
(gst_rtp_session_event_send_rtp_sink),
(gst_rtp_session_chain_send_rtp):
* gst/rtpmanager/rtpsession.c: (check_collision),
(update_arrival_stats), (rtp_session_process_rtp),
(rtp_session_process_rtcp), (rtp_session_send_rtp),
(rtp_session_send_bye_locked), (rtp_session_send_bye),
(rtp_session_next_timeout), (session_report_blocks), (session_cleanup),
(is_rtcp_time), (rtp_session_on_timeout):
* gst/rtpmanager/rtpsession.h:
Do not mix the use of g_get_current_time() with gst_clock_get_time().
2008-07-01 Jan Schmidt <jan.schmidt@sun.com> 2008-07-01 Jan Schmidt <jan.schmidt@sun.com>
* gst/mpegvideoparse/mpegvideoparse.c: * gst/mpegvideoparse/mpegvideoparse.c:

2
common

@ -1 +1 @@
Subproject commit d9cd98b46aebaf143dc43d8563a3bff650be6a7e Subproject commit 593bb114c6f5c32b529aa6443be4c2d60d6484c7

View file

@ -236,6 +236,7 @@ enum
struct _GstRtpSessionPrivate struct _GstRtpSessionPrivate
{ {
GMutex *lock; GMutex *lock;
GstClock *sysclock;
RTPSession *session; RTPSession *session;
/* thread for sending out RTCP */ /* thread for sending out RTCP */
@ -651,6 +652,7 @@ gst_rtp_session_init (GstRtpSession * rtpsession, GstRtpSessionClass * klass)
{ {
rtpsession->priv = GST_RTP_SESSION_GET_PRIVATE (rtpsession); rtpsession->priv = GST_RTP_SESSION_GET_PRIVATE (rtpsession);
rtpsession->priv->lock = g_mutex_new (); rtpsession->priv->lock = g_mutex_new ();
rtpsession->priv->sysclock = gst_system_clock_obtain ();
rtpsession->priv->session = rtp_session_new (); rtpsession->priv->session = rtp_session_new ();
/* configure callbacks */ /* configure callbacks */
rtp_session_set_callbacks (rtpsession->priv->session, &callbacks, rtpsession); rtp_session_set_callbacks (rtpsession->priv->session, &callbacks, rtpsession);
@ -698,6 +700,7 @@ gst_rtp_session_finalize (GObject * object)
g_hash_table_destroy (rtpsession->priv->ptmap); g_hash_table_destroy (rtpsession->priv->ptmap);
g_mutex_free (rtpsession->priv->lock); g_mutex_free (rtpsession->priv->lock);
g_object_unref (rtpsession->priv->sysclock);
g_object_unref (rtpsession->priv->session); g_object_unref (rtpsession->priv->session);
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
@ -857,23 +860,17 @@ get_current_ntp_ns_time (GstRtpSession * rtpsession)
static void static void
rtcp_thread (GstRtpSession * rtpsession) rtcp_thread (GstRtpSession * rtpsession)
{ {
GstClock *sysclock;
GstClockID id; GstClockID id;
GstClockTime current_time; GstClockTime current_time;
GstClockTime next_timeout; GstClockTime next_timeout;
guint64 ntpnstime; guint64 ntpnstime;
/* for RTCP timeouts we use the system clock */
sysclock = gst_system_clock_obtain ();
if (sysclock == NULL)
goto no_sysclock;
current_time = gst_clock_get_time (sysclock);
GST_DEBUG_OBJECT (rtpsession, "entering RTCP thread"); GST_DEBUG_OBJECT (rtpsession, "entering RTCP thread");
GST_RTP_SESSION_LOCK (rtpsession); GST_RTP_SESSION_LOCK (rtpsession);
current_time = gst_clock_get_time (rtpsession->priv->sysclock);
while (!rtpsession->priv->stop_thread) { while (!rtpsession->priv->stop_thread) {
GstClockReturn res; GstClockReturn res;
@ -889,7 +886,7 @@ rtcp_thread (GstRtpSession * rtpsession)
break; break;
id = rtpsession->priv->id = id = rtpsession->priv->id =
gst_clock_new_single_shot_id (sysclock, next_timeout); gst_clock_new_single_shot_id (rtpsession->priv->sysclock, next_timeout);
GST_RTP_SESSION_UNLOCK (rtpsession); GST_RTP_SESSION_UNLOCK (rtpsession);
res = gst_clock_id_wait (id, NULL); res = gst_clock_id_wait (id, NULL);
@ -902,7 +899,7 @@ rtcp_thread (GstRtpSession * rtpsession)
break; break;
/* update current time */ /* update current time */
current_time = gst_clock_get_time (sysclock); current_time = gst_clock_get_time (rtpsession->priv->sysclock);
/* get current NTP time */ /* get current NTP time */
ntpnstime = get_current_ntp_ns_time (rtpsession); ntpnstime = get_current_ntp_ns_time (rtpsession);
@ -921,18 +918,7 @@ rtcp_thread (GstRtpSession * rtpsession)
rtpsession->priv->thread_stopped = TRUE; rtpsession->priv->thread_stopped = TRUE;
GST_RTP_SESSION_UNLOCK (rtpsession); GST_RTP_SESSION_UNLOCK (rtpsession);
gst_object_unref (sysclock);
GST_DEBUG_OBJECT (rtpsession, "leaving RTCP thread"); GST_DEBUG_OBJECT (rtpsession, "leaving RTCP thread");
return;
/* ERRORS */
no_sysclock:
{
GST_ELEMENT_ERROR (rtpsession, CORE, CLOCK, (NULL),
("Could not get system clock"));
return;
}
} }
static gboolean static gboolean
@ -1397,6 +1383,7 @@ gst_rtp_session_chain_recv_rtp (GstPad * pad, GstBuffer * buffer)
GstRtpSession *rtpsession; GstRtpSession *rtpsession;
GstRtpSessionPrivate *priv; GstRtpSessionPrivate *priv;
GstFlowReturn ret; GstFlowReturn ret;
GstClockTime current_time;
guint64 ntpnstime; guint64 ntpnstime;
GstClockTime timestamp; GstClockTime timestamp;
@ -1418,7 +1405,9 @@ gst_rtp_session_chain_recv_rtp (GstPad * pad, GstBuffer * buffer)
ntpnstime = get_current_ntp_ns_time (rtpsession); ntpnstime = get_current_ntp_ns_time (rtpsession);
} }
ret = rtp_session_process_rtp (priv->session, buffer, ntpnstime); current_time = gst_clock_get_time (priv->sysclock);
ret = rtp_session_process_rtp (priv->session, buffer, current_time,
ntpnstime);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
goto push_error; goto push_error;
@ -1472,6 +1461,7 @@ gst_rtp_session_chain_recv_rtcp (GstPad * pad, GstBuffer * buffer)
{ {
GstRtpSession *rtpsession; GstRtpSession *rtpsession;
GstRtpSessionPrivate *priv; GstRtpSessionPrivate *priv;
GstClockTime current_time;
GstFlowReturn ret; GstFlowReturn ret;
rtpsession = GST_RTP_SESSION (gst_pad_get_parent (pad)); rtpsession = GST_RTP_SESSION (gst_pad_get_parent (pad));
@ -1479,7 +1469,8 @@ gst_rtp_session_chain_recv_rtcp (GstPad * pad, GstBuffer * buffer)
GST_DEBUG_OBJECT (rtpsession, "received RTCP packet"); GST_DEBUG_OBJECT (rtpsession, "received RTCP packet");
ret = rtp_session_process_rtcp (priv->session, buffer); current_time = gst_clock_get_time (priv->sysclock);
ret = rtp_session_process_rtcp (priv->session, buffer, current_time);
gst_object_unref (rtpsession); gst_object_unref (rtpsession);
@ -1531,8 +1522,7 @@ gst_rtp_session_event_send_rtp_sink (GstPad * pad, GstEvent * event)
gst_segment_init (&rtpsession->send_rtp_seg, GST_FORMAT_UNDEFINED); gst_segment_init (&rtpsession->send_rtp_seg, GST_FORMAT_UNDEFINED);
ret = gst_pad_push_event (rtpsession->send_rtp_src, event); ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
break; break;
case GST_EVENT_NEWSEGMENT: case GST_EVENT_NEWSEGMENT:{
{
gboolean update; gboolean update;
gdouble rate, arate; gdouble rate, arate;
GstFormat format; GstFormat format;
@ -1563,10 +1553,15 @@ gst_rtp_session_event_send_rtp_sink (GstPad * pad, GstEvent * event)
ret = gst_pad_push_event (rtpsession->send_rtp_src, event); ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
break; break;
} }
case GST_EVENT_EOS: case GST_EVENT_EOS:{
GstClockTime current_time;
ret = gst_pad_push_event (rtpsession->send_rtp_src, event); ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
rtp_session_send_bye (rtpsession->priv->session, "End of stream"); current_time = gst_clock_get_time (rtpsession->priv->sysclock);
rtp_session_send_bye (rtpsession->priv->session, "End of stream",
current_time);
break; break;
}
default: default:
ret = gst_pad_push_event (rtpsession->send_rtp_src, event); ret = gst_pad_push_event (rtpsession->send_rtp_src, event);
break; break;
@ -1613,6 +1608,7 @@ gst_rtp_session_chain_send_rtp (GstPad * pad, GstBuffer * buffer)
GstRtpSessionPrivate *priv; GstRtpSessionPrivate *priv;
GstFlowReturn ret; GstFlowReturn ret;
GstClockTime timestamp; GstClockTime timestamp;
GstClockTime current_time;
guint64 ntpnstime; guint64 ntpnstime;
rtpsession = GST_RTP_SESSION (gst_pad_get_parent (pad)); rtpsession = GST_RTP_SESSION (gst_pad_get_parent (pad));
@ -1635,7 +1631,8 @@ gst_rtp_session_chain_send_rtp (GstPad * pad, GstBuffer * buffer)
ntpnstime = -1; ntpnstime = -1;
} }
ret = rtp_session_send_rtp (priv->session, buffer, ntpnstime); current_time = gst_clock_get_time (priv->sysclock);
ret = rtp_session_send_rtp (priv->session, buffer, current_time, ntpnstime);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
goto push_error; goto push_error;

View file

@ -101,7 +101,7 @@ G_DEFINE_TYPE (RTPSession, rtp_session, G_TYPE_OBJECT);
static RTPSource *obtain_source (RTPSession * sess, guint32 ssrc, static RTPSource *obtain_source (RTPSession * sess, guint32 ssrc,
gboolean * created, RTPArrivalStats * arrival, gboolean rtp); gboolean * created, RTPArrivalStats * arrival, gboolean rtp);
static GstFlowReturn rtp_session_send_bye_locked (RTPSession * sess, static GstFlowReturn rtp_session_send_bye_locked (RTPSession * sess,
const gchar * reason); const gchar * reason, GstClockTime current_time);
static GstClockTime calculate_rtcp_interval (RTPSession * sess, static GstClockTime calculate_rtcp_interval (RTPSession * sess,
gboolean deterministic, gboolean first); gboolean deterministic, gboolean first);
@ -959,7 +959,7 @@ check_collision (RTPSession * sess, RTPSource * source,
GST_DEBUG ("Collision for SSRC %x", rtp_source_get_ssrc (source)); GST_DEBUG ("Collision for SSRC %x", rtp_source_get_ssrc (source));
on_ssrc_collision (sess, source); on_ssrc_collision (sess, source);
rtp_session_send_bye_locked (sess, "SSRC Collision"); rtp_session_send_bye_locked (sess, "SSRC Collision", arrival->time);
sess->change_ssrc = TRUE; sess->change_ssrc = TRUE;
} }
@ -1230,13 +1230,11 @@ rtp_session_create_source (RTPSession * sess)
*/ */
static void static void
update_arrival_stats (RTPSession * sess, RTPArrivalStats * arrival, update_arrival_stats (RTPSession * sess, RTPArrivalStats * arrival,
gboolean rtp, GstBuffer * buffer, guint64 ntpnstime) gboolean rtp, GstBuffer * buffer, GstClockTime current_time,
guint64 ntpnstime)
{ {
GTimeVal current;
/* get time of arrival */ /* get time of arrival */
g_get_current_time (&current); arrival->time = current_time;
arrival->time = GST_TIMEVAL_TO_TIME (current);
arrival->timestamp = GST_BUFFER_TIMESTAMP (buffer); arrival->timestamp = GST_BUFFER_TIMESTAMP (buffer);
arrival->ntpnstime = ntpnstime; arrival->ntpnstime = ntpnstime;
@ -1262,6 +1260,7 @@ update_arrival_stats (RTPSession * sess, RTPArrivalStats * arrival,
* rtp_session_process_rtp: * rtp_session_process_rtp:
* @sess: and #RTPSession * @sess: and #RTPSession
* @buffer: an RTP buffer * @buffer: an RTP buffer
* @current_time: the current system time
* @ntpnstime: the NTP arrival time in nanoseconds * @ntpnstime: the NTP arrival time in nanoseconds
* *
* Process an RTP buffer in the session manager. This function takes ownership * Process an RTP buffer in the session manager. This function takes ownership
@ -1271,7 +1270,7 @@ update_arrival_stats (RTPSession * sess, RTPArrivalStats * arrival,
*/ */
GstFlowReturn GstFlowReturn
rtp_session_process_rtp (RTPSession * sess, GstBuffer * buffer, rtp_session_process_rtp (RTPSession * sess, GstBuffer * buffer,
guint64 ntpnstime) GstClockTime current_time, guint64 ntpnstime)
{ {
GstFlowReturn result; GstFlowReturn result;
guint32 ssrc; guint32 ssrc;
@ -1288,7 +1287,7 @@ rtp_session_process_rtp (RTPSession * sess, GstBuffer * buffer,
RTP_SESSION_LOCK (sess); RTP_SESSION_LOCK (sess);
/* update arrival stats */ /* update arrival stats */
update_arrival_stats (sess, &arrival, TRUE, buffer, ntpnstime); update_arrival_stats (sess, &arrival, TRUE, buffer, current_time, ntpnstime);
/* ignore more RTP packets when we left the session */ /* ignore more RTP packets when we left the session */
if (sess->source->received_bye) if (sess->source->received_bye)
@ -1639,6 +1638,7 @@ rtp_session_process_app (RTPSession * sess, GstRTCPPacket * packet,
* rtp_session_process_rtcp: * rtp_session_process_rtcp:
* @sess: and #RTPSession * @sess: and #RTPSession
* @buffer: an RTCP buffer * @buffer: an RTCP buffer
* @current_time: the current system time
* *
* Process an RTCP buffer in the session manager. This function takes ownership * Process an RTCP buffer in the session manager. This function takes ownership
* of @buffer. * of @buffer.
@ -1646,7 +1646,8 @@ rtp_session_process_app (RTPSession * sess, GstRTCPPacket * packet,
* Returns: a #GstFlowReturn. * Returns: a #GstFlowReturn.
*/ */
GstFlowReturn GstFlowReturn
rtp_session_process_rtcp (RTPSession * sess, GstBuffer * buffer) rtp_session_process_rtcp (RTPSession * sess, GstBuffer * buffer,
GstClockTime current_time)
{ {
GstRTCPPacket packet; GstRTCPPacket packet;
gboolean more, is_bye = FALSE, is_sr = FALSE; gboolean more, is_bye = FALSE, is_sr = FALSE;
@ -1663,7 +1664,7 @@ rtp_session_process_rtcp (RTPSession * sess, GstBuffer * buffer)
RTP_SESSION_LOCK (sess); RTP_SESSION_LOCK (sess);
/* update arrival stats */ /* update arrival stats */
update_arrival_stats (sess, &arrival, FALSE, buffer, -1); update_arrival_stats (sess, &arrival, FALSE, buffer, current_time, -1);
if (sess->sent_bye) if (sess->sent_bye)
goto ignore; goto ignore;
@ -1749,6 +1750,7 @@ ignore:
* rtp_session_send_rtp: * rtp_session_send_rtp:
* @sess: an #RTPSession * @sess: an #RTPSession
* @buffer: an RTP buffer * @buffer: an RTP buffer
* @current_time: the current system time
* @ntpnstime: the NTP time in nanoseconds of when this buffer was captured. * @ntpnstime: the NTP time in nanoseconds of when this buffer was captured.
* *
* Send the RTP buffer in the session manager. This function takes ownership of * Send the RTP buffer in the session manager. This function takes ownership of
@ -1757,12 +1759,12 @@ ignore:
* Returns: a #GstFlowReturn. * Returns: a #GstFlowReturn.
*/ */
GstFlowReturn GstFlowReturn
rtp_session_send_rtp (RTPSession * sess, GstBuffer * buffer, guint64 ntpnstime) rtp_session_send_rtp (RTPSession * sess, GstBuffer * buffer,
GstClockTime current_time, guint64 ntpnstime)
{ {
GstFlowReturn result; GstFlowReturn result;
RTPSource *source; RTPSource *source;
gboolean prevsender; gboolean prevsender;
GTimeVal current;
g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR); g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR); g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
@ -1776,8 +1778,7 @@ rtp_session_send_rtp (RTPSession * sess, GstBuffer * buffer, guint64 ntpnstime)
source = sess->source; source = sess->source;
/* update last activity */ /* update last activity */
g_get_current_time (&current); source->last_rtp_activity = current_time;
source->last_rtp_activity = GST_TIMEVAL_TO_TIME (current);
prevsender = RTP_SOURCE_IS_SENDER (source); prevsender = RTP_SOURCE_IS_SENDER (source);
@ -1835,12 +1836,12 @@ calculate_rtcp_interval (RTPSession * sess, gboolean deterministic,
* Returns: a #GstFlowReturn. * Returns: a #GstFlowReturn.
*/ */
static GstFlowReturn static GstFlowReturn
rtp_session_send_bye_locked (RTPSession * sess, const gchar * reason) rtp_session_send_bye_locked (RTPSession * sess, const gchar * reason,
GstClockTime current_time)
{ {
GstFlowReturn result = GST_FLOW_OK; GstFlowReturn result = GST_FLOW_OK;
RTPSource *source; RTPSource *source;
GstClockTime current, interval; GstClockTime interval;
GTimeVal curtv;
g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR); g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
@ -1860,14 +1861,10 @@ rtp_session_send_bye_locked (RTPSession * sess, const gchar * reason)
sess->first_rtcp = TRUE; sess->first_rtcp = TRUE;
sess->sent_bye = FALSE; sess->sent_bye = FALSE;
/* get current time */
g_get_current_time (&curtv);
current = GST_TIMEVAL_TO_TIME (curtv);
/* reschedule transmission */ /* reschedule transmission */
sess->last_rtcp_send_time = current; sess->last_rtcp_send_time = current_time;
interval = calculate_rtcp_interval (sess, FALSE, TRUE); interval = calculate_rtcp_interval (sess, FALSE, TRUE);
sess->next_rtcp_check_time = current + interval; sess->next_rtcp_check_time = current_time + interval;
GST_DEBUG ("Schedule BYE for %" GST_TIME_FORMAT ", %" GST_TIME_FORMAT, GST_DEBUG ("Schedule BYE for %" GST_TIME_FORMAT ", %" GST_TIME_FORMAT,
GST_TIME_ARGS (interval), GST_TIME_ARGS (sess->next_rtcp_check_time)); GST_TIME_ARGS (interval), GST_TIME_ARGS (sess->next_rtcp_check_time));
@ -1886,6 +1883,7 @@ done:
* rtp_session_send_bye: * rtp_session_send_bye:
* @sess: an #RTPSession * @sess: an #RTPSession
* @reason: a reason or NULL * @reason: a reason or NULL
* @current_time: the current system time
* *
* Stop the current @sess and schedule a BYE message for the other members. * Stop the current @sess and schedule a BYE message for the other members.
* *
@ -1894,14 +1892,15 @@ done:
* Returns: a #GstFlowReturn. * Returns: a #GstFlowReturn.
*/ */
GstFlowReturn GstFlowReturn
rtp_session_send_bye (RTPSession * sess, const gchar * reason) rtp_session_send_bye (RTPSession * sess, const gchar * reason,
GstClockTime current_time)
{ {
GstFlowReturn result = GST_FLOW_OK; GstFlowReturn result = GST_FLOW_OK;
g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR); g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
RTP_SESSION_LOCK (sess); RTP_SESSION_LOCK (sess);
result = rtp_session_send_bye_locked (sess, reason); result = rtp_session_send_bye_locked (sess, reason, current_time);
RTP_SESSION_UNLOCK (sess); RTP_SESSION_UNLOCK (sess);
return result; return result;
@ -1910,7 +1909,7 @@ rtp_session_send_bye (RTPSession * sess, const gchar * reason)
/** /**
* rtp_session_next_timeout: * rtp_session_next_timeout:
* @sess: an #RTPSession * @sess: an #RTPSession
* @time: the current system time * @current_time: the current system time
* *
* Get the next time we should perform session maintenance tasks. * Get the next time we should perform session maintenance tasks.
* *
@ -1918,7 +1917,7 @@ rtp_session_send_bye (RTPSession * sess, const gchar * reason)
* current system time. * current system time.
*/ */
GstClockTime GstClockTime
rtp_session_next_timeout (RTPSession * sess, GstClockTime time) rtp_session_next_timeout (RTPSession * sess, GstClockTime current_time)
{ {
GstClockTime result; GstClockTime result;
@ -1929,13 +1928,13 @@ rtp_session_next_timeout (RTPSession * sess, GstClockTime time)
result = sess->next_rtcp_check_time; result = sess->next_rtcp_check_time;
GST_DEBUG ("current time: %" GST_TIME_FORMAT ", next :%" GST_TIME_FORMAT, GST_DEBUG ("current time: %" GST_TIME_FORMAT ", next :%" GST_TIME_FORMAT,
GST_TIME_ARGS (time), GST_TIME_ARGS (result)); GST_TIME_ARGS (current_time), GST_TIME_ARGS (result));
if (result < time) { if (result < current_time) {
GST_DEBUG ("take current time as base"); GST_DEBUG ("take current time as base");
/* our previous check time expired, start counting from the current time /* our previous check time expired, start counting from the current time
* again. */ * again. */
result = time; result = current_time;
} }
if (sess->source->received_bye) { if (sess->source->received_bye) {
@ -1952,7 +1951,7 @@ rtp_session_next_timeout (RTPSession * sess, GstClockTime time)
GST_DEBUG ("first RTCP packet"); GST_DEBUG ("first RTCP packet");
/* we are called for the first time */ /* we are called for the first time */
result += calculate_rtcp_interval (sess, FALSE, TRUE); result += calculate_rtcp_interval (sess, FALSE, TRUE);
} else if (sess->next_rtcp_check_time < time) { } else if (sess->next_rtcp_check_time < current_time) {
GST_DEBUG ("old check time expired, getting new timeout"); GST_DEBUG ("old check time expired, getting new timeout");
/* get a new timeout when we need to */ /* get a new timeout when we need to */
result += calculate_rtcp_interval (sess, FALSE, FALSE); result += calculate_rtcp_interval (sess, FALSE, FALSE);
@ -1970,7 +1969,7 @@ typedef struct
{ {
RTPSession *sess; RTPSession *sess;
GstBuffer *rtcp; GstBuffer *rtcp;
GstClockTime time; GstClockTime current_time;
guint64 ntpnstime; guint64 ntpnstime;
GstClockTime interval; GstClockTime interval;
GstRTCPPacket packet; GstRTCPPacket packet;
@ -2033,8 +2032,8 @@ session_report_blocks (const gchar * key, RTPSource * source, ReportData * data)
guint32 lsr, dlsr; guint32 lsr, dlsr;
/* get new stats */ /* get new stats */
rtp_source_get_new_rb (source, data->time, &fractionlost, &packetslost, rtp_source_get_new_rb (source, data->current_time, &fractionlost,
&exthighestseq, &jitter, &lsr, &dlsr); &packetslost, &exthighestseq, &jitter, &lsr, &dlsr);
/* packet is not yet filled, add report block for this source. */ /* packet is not yet filled, add report block for this source. */
gst_rtcp_packet_add_rb (packet, source->ssrc, fractionlost, packetslost, gst_rtcp_packet_add_rb (packet, source->ssrc, fractionlost, packetslost,
@ -2061,8 +2060,8 @@ session_cleanup (const gchar * key, RTPSource * source, ReportData * data)
if (source->received_bye) { if (source->received_bye) {
/* if we received a BYE from the source, remove the source after some /* if we received a BYE from the source, remove the source after some
* time. */ * time. */
if (data->time > source->bye_time && if (data->current_time > source->bye_time &&
data->time - source->bye_time > sess->stats.bye_timeout) { data->current_time - source->bye_time > sess->stats.bye_timeout) {
GST_DEBUG ("removing BYE source %08x", source->ssrc); GST_DEBUG ("removing BYE source %08x", source->ssrc);
remove = TRUE; remove = TRUE;
byetimeout = TRUE; byetimeout = TRUE;
@ -2070,9 +2069,9 @@ session_cleanup (const gchar * key, RTPSource * source, ReportData * data)
} }
/* sources that were inactive for more than 5 times the deterministic reporting /* sources that were inactive for more than 5 times the deterministic reporting
* interval get timed out. the min timeout is 5 seconds. */ * interval get timed out. the min timeout is 5 seconds. */
if (data->time > source->last_activity) { if (data->current_time > source->last_activity) {
interval = MAX (data->interval * 5, 5 * GST_SECOND); interval = MAX (data->interval * 5, 5 * GST_SECOND);
if (data->time - source->last_activity > interval) { if (data->current_time - source->last_activity > interval) {
GST_DEBUG ("removing timeout source %08x, last %" GST_TIME_FORMAT, GST_DEBUG ("removing timeout source %08x, last %" GST_TIME_FORMAT,
source->ssrc, GST_TIME_ARGS (source->last_activity)); source->ssrc, GST_TIME_ARGS (source->last_activity));
remove = TRUE; remove = TRUE;
@ -2083,9 +2082,9 @@ session_cleanup (const gchar * key, RTPSource * source, ReportData * data)
/* senders that did not send for a long time become a receiver, this also /* senders that did not send for a long time become a receiver, this also
* holds for our own source. */ * holds for our own source. */
if (is_sender) { if (is_sender) {
if (data->time > source->last_rtp_activity) { if (data->current_time > source->last_rtp_activity) {
interval = MAX (data->interval * 2, 5 * GST_SECOND); interval = MAX (data->interval * 2, 5 * GST_SECOND);
if (data->time - source->last_rtp_activity > interval) { if (data->current_time - source->last_rtp_activity > interval) {
GST_DEBUG ("sender source %08x timed out and became receiver, last %" GST_DEBUG ("sender source %08x timed out and became receiver, last %"
GST_TIME_FORMAT, source->ssrc, GST_TIME_FORMAT, source->ssrc,
GST_TIME_ARGS (source->last_rtp_activity)); GST_TIME_ARGS (source->last_rtp_activity));
@ -2162,21 +2161,21 @@ session_bye (RTPSession * sess, ReportData * data)
} }
static gboolean static gboolean
is_rtcp_time (RTPSession * sess, GstClockTime time, ReportData * data) is_rtcp_time (RTPSession * sess, GstClockTime current_time, ReportData * data)
{ {
GstClockTime new_send_time, elapsed; GstClockTime new_send_time, elapsed;
gboolean result; gboolean result;
/* no need to check yet */ /* no need to check yet */
if (sess->next_rtcp_check_time > time) { if (sess->next_rtcp_check_time > current_time) {
GST_DEBUG ("no check time yet, next %" GST_TIME_FORMAT " > now %" GST_DEBUG ("no check time yet, next %" GST_TIME_FORMAT " > now %"
GST_TIME_FORMAT, GST_TIME_ARGS (sess->next_rtcp_check_time), GST_TIME_FORMAT, GST_TIME_ARGS (sess->next_rtcp_check_time),
GST_TIME_ARGS (time)); GST_TIME_ARGS (current_time));
return FALSE; return FALSE;
} }
/* get elapsed time since we last reported */ /* get elapsed time since we last reported */
elapsed = time - sess->last_rtcp_send_time; elapsed = current_time - sess->last_rtcp_send_time;
/* perform forward reconsideration */ /* perform forward reconsideration */
new_send_time = rtp_stats_add_rtcp_jitter (&sess->stats, data->interval); new_send_time = rtp_stats_add_rtcp_jitter (&sess->stats, data->interval);
@ -2187,7 +2186,7 @@ is_rtcp_time (RTPSession * sess, GstClockTime time, ReportData * data)
new_send_time += sess->last_rtcp_send_time; new_send_time += sess->last_rtcp_send_time;
/* check if reconsideration */ /* check if reconsideration */
if (time < new_send_time) { if (current_time < new_send_time) {
GST_DEBUG ("reconsider RTCP for %" GST_TIME_FORMAT, GST_DEBUG ("reconsider RTCP for %" GST_TIME_FORMAT,
GST_TIME_ARGS (new_send_time)); GST_TIME_ARGS (new_send_time));
result = FALSE; result = FALSE;
@ -2199,7 +2198,7 @@ is_rtcp_time (RTPSession * sess, GstClockTime time, ReportData * data)
GST_DEBUG ("can send RTCP now, next interval %" GST_TIME_FORMAT, GST_DEBUG ("can send RTCP now, next interval %" GST_TIME_FORMAT,
GST_TIME_ARGS (new_send_time)); GST_TIME_ARGS (new_send_time));
sess->next_rtcp_check_time = time + new_send_time; sess->next_rtcp_check_time = current_time + new_send_time;
} }
return result; return result;
} }
@ -2207,7 +2206,7 @@ is_rtcp_time (RTPSession * sess, GstClockTime time, ReportData * data)
/** /**
* rtp_session_on_timeout: * rtp_session_on_timeout:
* @sess: an #RTPSession * @sess: an #RTPSession
* @time: the current system time * @current_time: the current system time
* @ntpnstime: the current NTP time in nanoseconds * @ntpnstime: the current NTP time in nanoseconds
* *
* Perform maintenance actions after the timeout obtained with * Perform maintenance actions after the timeout obtained with
@ -2222,7 +2221,8 @@ is_rtcp_time (RTPSession * sess, GstClockTime time, ReportData * data)
* Returns: a #GstFlowReturn. * Returns: a #GstFlowReturn.
*/ */
GstFlowReturn GstFlowReturn
rtp_session_on_timeout (RTPSession * sess, GstClockTime time, guint64 ntpnstime) rtp_session_on_timeout (RTPSession * sess, GstClockTime current_time,
guint64 ntpnstime)
{ {
GstFlowReturn result = GST_FLOW_OK; GstFlowReturn result = GST_FLOW_OK;
GList *item; GList *item;
@ -2231,11 +2231,11 @@ rtp_session_on_timeout (RTPSession * sess, GstClockTime time, guint64 ntpnstime)
g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR); g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
GST_DEBUG ("reporting at %" GST_TIME_FORMAT ", NTP time %" GST_TIME_FORMAT, GST_DEBUG ("reporting at %" GST_TIME_FORMAT ", NTP time %" GST_TIME_FORMAT,
GST_TIME_ARGS (time), GST_TIME_ARGS (ntpnstime)); GST_TIME_ARGS (current_time), GST_TIME_ARGS (ntpnstime));
data.sess = sess; data.sess = sess;
data.rtcp = NULL; data.rtcp = NULL;
data.time = time; data.current_time = current_time;
data.ntpnstime = ntpnstime; data.ntpnstime = ntpnstime;
data.is_bye = FALSE; data.is_bye = FALSE;
data.has_sdes = FALSE; data.has_sdes = FALSE;
@ -2249,7 +2249,7 @@ rtp_session_on_timeout (RTPSession * sess, GstClockTime time, guint64 ntpnstime)
(GHRFunc) session_cleanup, &data); (GHRFunc) session_cleanup, &data);
/* see if we need to generate SR or RR packets */ /* see if we need to generate SR or RR packets */
if (is_rtcp_time (sess, time, &data)) { if (is_rtcp_time (sess, current_time, &data)) {
if (sess->source->received_bye) { if (sess->source->received_bye) {
/* generate BYE instead */ /* generate BYE instead */
session_bye (sess, &data); session_bye (sess, &data);
@ -2266,7 +2266,7 @@ rtp_session_on_timeout (RTPSession * sess, GstClockTime time, guint64 ntpnstime)
/* we keep track of the last report time in order to timeout inactive /* we keep track of the last report time in order to timeout inactive
* receivers or senders */ * receivers or senders */
sess->last_rtcp_send_time = data.time; sess->last_rtcp_send_time = data.current_time;
sess->first_rtcp = FALSE; sess->first_rtcp = FALSE;
/* add SDES for this source when not already added */ /* add SDES for this source when not already added */
@ -2284,7 +2284,7 @@ rtp_session_on_timeout (RTPSession * sess, GstClockTime time, guint64 ntpnstime)
RTPConflictingAddress *known_conflict = item->data; RTPConflictingAddress *known_conflict = item->data;
GList *next_item = g_list_next (item); GList *next_item = g_list_next (item);
if (known_conflict->time < time - (data.interval * if (known_conflict->time < current_time - (data.interval *
RTCP_INTERVAL_COLLISION_TIMEOUT)) { RTCP_INTERVAL_COLLISION_TIMEOUT)) {
sess->conflicting_addresses = sess->conflicting_addresses =
g_list_delete_link (sess->conflicting_addresses, item); g_list_delete_link (sess->conflicting_addresses, item);

View file

@ -205,9 +205,6 @@ struct _RTPSession {
GList *conflicting_addresses; GList *conflicting_addresses;
gboolean change_ssrc; gboolean change_ssrc;
/* for mapping clock time to NTP time */
GstClockTime base_time;
}; };
/** /**
@ -275,17 +272,17 @@ RTPSource* rtp_session_get_source_by_cname (RTPSession *sess, const gcha
RTPSource* rtp_session_create_source (RTPSession *sess); RTPSource* rtp_session_create_source (RTPSession *sess);
/* processing packets from receivers */ /* processing packets from receivers */
GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer *buffer, guint64 ntpnstime); GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer *buffer, GstClockTime current_time, guint64 ntpnstime);
GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer); GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer, GstClockTime current_time);
/* processing packets for sending */ /* processing packets for sending */
GstFlowReturn rtp_session_send_rtp (RTPSession *sess, GstBuffer *buffer, guint64 ntpnstime); GstFlowReturn rtp_session_send_rtp (RTPSession *sess, GstBuffer *buffer, GstClockTime current_time, guint64 ntpnstime);
/* stopping the session */ /* stopping the session */
GstFlowReturn rtp_session_send_bye (RTPSession *sess, const gchar *reason); GstFlowReturn rtp_session_send_bye (RTPSession *sess, const gchar *reason, GstClockTime current_time);
/* get interval for next RTCP interval */ /* get interval for next RTCP interval */
GstClockTime rtp_session_next_timeout (RTPSession *sess, GstClockTime time); GstClockTime rtp_session_next_timeout (RTPSession *sess, GstClockTime current_time);
GstFlowReturn rtp_session_on_timeout (RTPSession *sess, GstClockTime time, guint64 ntpnstime); GstFlowReturn rtp_session_on_timeout (RTPSession *sess, GstClockTime current_time, guint64 ntpnstime);
#endif /* __RTP_SESSION_H__ */ #endif /* __RTP_SESSION_H__ */