diff --git a/gst/rtpmanager/gstrtpsession.c b/gst/rtpmanager/gstrtpsession.c index b1223d6585..64abc94ba6 100644 --- a/gst/rtpmanager/gstrtpsession.c +++ b/gst/rtpmanager/gstrtpsession.c @@ -1581,6 +1581,7 @@ gst_rtp_session_chain_recv_rtcp (GstPad * pad, GstBuffer * buffer) GstRtpSession *rtpsession; GstRtpSessionPrivate *priv; GstClockTime current_time; + guint64 ntpnstime; GstFlowReturn ret; rtpsession = GST_RTP_SESSION (gst_pad_get_parent (pad)); @@ -1589,7 +1590,10 @@ gst_rtp_session_chain_recv_rtcp (GstPad * pad, GstBuffer * buffer) GST_LOG_OBJECT (rtpsession, "received RTCP packet"); current_time = gst_clock_get_time (priv->sysclock); - ret = rtp_session_process_rtcp (priv->session, buffer, current_time); + get_current_times (rtpsession, NULL, &ntpnstime); + + ret = + rtp_session_process_rtcp (priv->session, buffer, current_time, ntpnstime); gst_object_unref (rtpsession); diff --git a/gst/rtpmanager/rtpsession.c b/gst/rtpmanager/rtpsession.c index 49ce69b613..a455ad3564 100644 --- a/gst/rtpmanager/rtpsession.c +++ b/gst/rtpmanager/rtpsession.c @@ -1598,11 +1598,12 @@ rtp_session_create_source (RTPSession * sess) static void update_arrival_stats (RTPSession * sess, RTPArrivalStats * arrival, gboolean rtp, GstBuffer * buffer, GstClockTime current_time, - GstClockTime running_time) + GstClockTime running_time, guint64 ntpnstime) { /* get time of arrival */ arrival->current_time = current_time; arrival->running_time = running_time; + arrival->ntpnstime = ntpnstime; /* get packet size including header overhead */ arrival->bytes = GST_BUFFER_SIZE (buffer) + sess->header_len; @@ -1657,7 +1658,7 @@ rtp_session_process_rtp (RTPSession * sess, GstBuffer * buffer, RTP_SESSION_LOCK (sess); /* update arrival stats */ update_arrival_stats (sess, &arrival, TRUE, buffer, current_time, - running_time); + running_time, -1); /* ignore more RTP packets when we left the session */ if (sess->source->received_bye) @@ -1778,7 +1779,7 @@ rtp_session_process_rb (RTPSession * sess, RTPSource * source, /* only deal with report blocks for our session, we update the stats of * the sender of the RTCP message. We could also compare our stats against * the other sender to see if we are better or worse. */ - rtp_source_process_rb (source, arrival->current_time, fractionlost, + rtp_source_process_rb (source, arrival->ntpnstime, fractionlost, packetslost, exthighestseq, jitter, lsr, dlsr); } } @@ -2153,6 +2154,7 @@ rtp_session_process_feedback (RTPSession * sess, GstRTCPPacket * packet, * @sess: and #RTPSession * @buffer: an RTCP buffer * @current_time: the current system time + * @ntpnstime: the current NTP time in nanoseconds * * Process an RTCP buffer in the session manager. This function takes ownership * of @buffer. @@ -2161,7 +2163,7 @@ rtp_session_process_feedback (RTPSession * sess, GstRTCPPacket * packet, */ GstFlowReturn rtp_session_process_rtcp (RTPSession * sess, GstBuffer * buffer, - GstClockTime current_time) + GstClockTime current_time, guint64 ntpnstime) { GstRTCPPacket packet; gboolean more, is_bye = FALSE, do_sync = FALSE; @@ -2178,7 +2180,8 @@ rtp_session_process_rtcp (RTPSession * sess, GstBuffer * buffer, RTP_SESSION_LOCK (sess); /* update arrival stats */ - update_arrival_stats (sess, &arrival, FALSE, buffer, current_time, -1); + update_arrival_stats (sess, &arrival, FALSE, buffer, current_time, -1, + ntpnstime); if (sess->sent_bye) goto ignore; diff --git a/gst/rtpmanager/rtpsession.h b/gst/rtpmanager/rtpsession.h index 3268490cac..6dee1cbe28 100644 --- a/gst/rtpmanager/rtpsession.h +++ b/gst/rtpmanager/rtpsession.h @@ -326,7 +326,8 @@ GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer GstClockTime current_time, GstClockTime running_time); GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer, - GstClockTime current_time); + GstClockTime current_time, + guint64 ntpnstime); /* processing packets for sending */ GstFlowReturn rtp_session_send_rtp (RTPSession *sess, gpointer data, gboolean is_list, diff --git a/gst/rtpmanager/rtpsource.c b/gst/rtpmanager/rtpsource.c index 423d2b65d2..e7872d8087 100644 --- a/gst/rtpmanager/rtpsource.c +++ b/gst/rtpmanager/rtpsource.c @@ -1350,7 +1350,7 @@ rtp_source_process_sr (RTPSource * src, GstClockTime time, guint64 ntptime, /** * rtp_source_process_rb: * @src: an #RTPSource - * @time: the current time in nanoseconds since 1970 + * @ntpnstime: the current time in nanoseconds since 1970 * @fractionlost: fraction lost since last SR/RR * @packetslost: the cumululative number of packets lost * @exthighestseq: the extended last sequence number received @@ -1361,13 +1361,14 @@ rtp_source_process_sr (RTPSource * src, GstClockTime time, guint64 ntptime, * Update the report block in @src. */ void -rtp_source_process_rb (RTPSource * src, GstClockTime time, guint8 fractionlost, - gint32 packetslost, guint32 exthighestseq, guint32 jitter, guint32 lsr, - guint32 dlsr) +rtp_source_process_rb (RTPSource * src, GstClockTime ntpnstime, + guint8 fractionlost, gint32 packetslost, guint32 exthighestseq, + guint32 jitter, guint32 lsr, guint32 dlsr) { RTPReceiverReport *curr; gint curridx; guint32 ntp, A; + guint64 f_ntp; g_return_if_fail (RTP_IS_SOURCE (src)); @@ -1388,8 +1389,11 @@ rtp_source_process_rb (RTPSource * src, GstClockTime time, guint8 fractionlost, curr->lsr = lsr; curr->dlsr = dlsr; + /* convert the NTP time in nanoseconds to 32.32 fixed point */ + f_ntp = gst_util_uint64_scale (ntpnstime, (1LL << 32), GST_SECOND); /* calculate round trip, round the time up */ - ntp = ((gst_rtcp_unix_to_ntp (time) + 0xffff) >> 16) & 0xffffffff; + ntp = ((f_ntp + 0xffff) >> 16) & 0xffffffff; + A = dlsr + lsr; if (A > 0 && ntp > A) A = ntp - A; diff --git a/gst/rtpmanager/rtpsource.h b/gst/rtpmanager/rtpsource.h index fadbe3068a..6db0a6a678 100644 --- a/gst/rtpmanager/rtpsource.h +++ b/gst/rtpmanager/rtpsource.h @@ -220,7 +220,7 @@ GstFlowReturn rtp_source_send_rtp (RTPSource *src, gpointer data, g void rtp_source_process_bye (RTPSource *src, const gchar *reason); void rtp_source_process_sr (RTPSource *src, GstClockTime time, guint64 ntptime, guint32 rtptime, guint32 packet_count, guint32 octet_count); -void rtp_source_process_rb (RTPSource *src, GstClockTime time, guint8 fractionlost, +void rtp_source_process_rb (RTPSource *src, guint64 ntpnstime, guint8 fractionlost, gint32 packetslost, guint32 exthighestseq, guint32 jitter, guint32 lsr, guint32 dlsr); diff --git a/gst/rtpmanager/rtpstats.h b/gst/rtpmanager/rtpstats.h index 643da004ab..4560595edb 100644 --- a/gst/rtpmanager/rtpstats.h +++ b/gst/rtpmanager/rtpstats.h @@ -58,6 +58,7 @@ typedef struct { * RTPArrivalStats: * @current_time: current time according to the system clock * @running_time: arrival time of a packet as buffer running_time + * @ntpnstime: arrival time of a packet NTP time in nanoseconds * @have_address: if the @address field contains a valid address * @address: address of the sender of the packet * @bytes: bytes of the packet including lowlevel overhead @@ -68,6 +69,7 @@ typedef struct { typedef struct { GstClockTime current_time; GstClockTime running_time; + guint64 ntpnstime; gboolean have_address; GstNetAddress address; guint bytes;