rtpbin: Get and use the NTP time when receiving RTCP
When we receive an RTCP packet, get the current NTP time in nanseconds so that we can correctly calculate the round-trip time.
This commit is contained in:
parent
564976b609
commit
8598aaf81b
@ -1581,6 +1581,7 @@ gst_rtp_session_chain_recv_rtcp (GstPad * pad, GstBuffer * buffer)
|
|||||||
GstRtpSession *rtpsession;
|
GstRtpSession *rtpsession;
|
||||||
GstRtpSessionPrivate *priv;
|
GstRtpSessionPrivate *priv;
|
||||||
GstClockTime current_time;
|
GstClockTime current_time;
|
||||||
|
guint64 ntpnstime;
|
||||||
GstFlowReturn ret;
|
GstFlowReturn ret;
|
||||||
|
|
||||||
rtpsession = GST_RTP_SESSION (gst_pad_get_parent (pad));
|
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");
|
GST_LOG_OBJECT (rtpsession, "received RTCP packet");
|
||||||
|
|
||||||
current_time = gst_clock_get_time (priv->sysclock);
|
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);
|
gst_object_unref (rtpsession);
|
||||||
|
|
||||||
|
@ -1598,11 +1598,12 @@ 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, GstClockTime current_time,
|
gboolean rtp, GstBuffer * buffer, GstClockTime current_time,
|
||||||
GstClockTime running_time)
|
GstClockTime running_time, guint64 ntpnstime)
|
||||||
{
|
{
|
||||||
/* get time of arrival */
|
/* get time of arrival */
|
||||||
arrival->current_time = current_time;
|
arrival->current_time = current_time;
|
||||||
arrival->running_time = running_time;
|
arrival->running_time = running_time;
|
||||||
|
arrival->ntpnstime = ntpnstime;
|
||||||
|
|
||||||
/* get packet size including header overhead */
|
/* get packet size including header overhead */
|
||||||
arrival->bytes = GST_BUFFER_SIZE (buffer) + sess->header_len;
|
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);
|
RTP_SESSION_LOCK (sess);
|
||||||
/* update arrival stats */
|
/* update arrival stats */
|
||||||
update_arrival_stats (sess, &arrival, TRUE, buffer, current_time,
|
update_arrival_stats (sess, &arrival, TRUE, buffer, current_time,
|
||||||
running_time);
|
running_time, -1);
|
||||||
|
|
||||||
/* 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)
|
||||||
@ -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
|
/* 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 sender of the RTCP message. We could also compare our stats against
|
||||||
* the other sender to see if we are better or worse. */
|
* 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);
|
packetslost, exthighestseq, jitter, lsr, dlsr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2153,6 +2154,7 @@ rtp_session_process_feedback (RTPSession * sess, GstRTCPPacket * packet,
|
|||||||
* @sess: and #RTPSession
|
* @sess: and #RTPSession
|
||||||
* @buffer: an RTCP buffer
|
* @buffer: an RTCP buffer
|
||||||
* @current_time: the current system time
|
* @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
|
* Process an RTCP buffer in the session manager. This function takes ownership
|
||||||
* of @buffer.
|
* of @buffer.
|
||||||
@ -2161,7 +2163,7 @@ rtp_session_process_feedback (RTPSession * sess, GstRTCPPacket * packet,
|
|||||||
*/
|
*/
|
||||||
GstFlowReturn
|
GstFlowReturn
|
||||||
rtp_session_process_rtcp (RTPSession * sess, GstBuffer * buffer,
|
rtp_session_process_rtcp (RTPSession * sess, GstBuffer * buffer,
|
||||||
GstClockTime current_time)
|
GstClockTime current_time, guint64 ntpnstime)
|
||||||
{
|
{
|
||||||
GstRTCPPacket packet;
|
GstRTCPPacket packet;
|
||||||
gboolean more, is_bye = FALSE, do_sync = FALSE;
|
gboolean more, is_bye = FALSE, do_sync = FALSE;
|
||||||
@ -2178,7 +2180,8 @@ 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, current_time, -1);
|
update_arrival_stats (sess, &arrival, FALSE, buffer, current_time, -1,
|
||||||
|
ntpnstime);
|
||||||
|
|
||||||
if (sess->sent_bye)
|
if (sess->sent_bye)
|
||||||
goto ignore;
|
goto ignore;
|
||||||
|
@ -326,7 +326,8 @@ GstFlowReturn rtp_session_process_rtp (RTPSession *sess, GstBuffer
|
|||||||
GstClockTime current_time,
|
GstClockTime current_time,
|
||||||
GstClockTime running_time);
|
GstClockTime running_time);
|
||||||
GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer,
|
GstFlowReturn rtp_session_process_rtcp (RTPSession *sess, GstBuffer *buffer,
|
||||||
GstClockTime current_time);
|
GstClockTime current_time,
|
||||||
|
guint64 ntpnstime);
|
||||||
|
|
||||||
/* processing packets for sending */
|
/* processing packets for sending */
|
||||||
GstFlowReturn rtp_session_send_rtp (RTPSession *sess, gpointer data, gboolean is_list,
|
GstFlowReturn rtp_session_send_rtp (RTPSession *sess, gpointer data, gboolean is_list,
|
||||||
|
@ -1350,7 +1350,7 @@ rtp_source_process_sr (RTPSource * src, GstClockTime time, guint64 ntptime,
|
|||||||
/**
|
/**
|
||||||
* rtp_source_process_rb:
|
* rtp_source_process_rb:
|
||||||
* @src: an #RTPSource
|
* @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
|
* @fractionlost: fraction lost since last SR/RR
|
||||||
* @packetslost: the cumululative number of packets lost
|
* @packetslost: the cumululative number of packets lost
|
||||||
* @exthighestseq: the extended last sequence number received
|
* @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.
|
* Update the report block in @src.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
rtp_source_process_rb (RTPSource * src, GstClockTime time, guint8 fractionlost,
|
rtp_source_process_rb (RTPSource * src, GstClockTime ntpnstime,
|
||||||
gint32 packetslost, guint32 exthighestseq, guint32 jitter, guint32 lsr,
|
guint8 fractionlost, gint32 packetslost, guint32 exthighestseq,
|
||||||
guint32 dlsr)
|
guint32 jitter, guint32 lsr, guint32 dlsr)
|
||||||
{
|
{
|
||||||
RTPReceiverReport *curr;
|
RTPReceiverReport *curr;
|
||||||
gint curridx;
|
gint curridx;
|
||||||
guint32 ntp, A;
|
guint32 ntp, A;
|
||||||
|
guint64 f_ntp;
|
||||||
|
|
||||||
g_return_if_fail (RTP_IS_SOURCE (src));
|
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->lsr = lsr;
|
||||||
curr->dlsr = dlsr;
|
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 */
|
/* 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;
|
A = dlsr + lsr;
|
||||||
if (A > 0 && ntp > A)
|
if (A > 0 && ntp > A)
|
||||||
A = ntp - A;
|
A = ntp - A;
|
||||||
|
@ -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_bye (RTPSource *src, const gchar *reason);
|
||||||
void rtp_source_process_sr (RTPSource *src, GstClockTime time, guint64 ntptime,
|
void rtp_source_process_sr (RTPSource *src, GstClockTime time, guint64 ntptime,
|
||||||
guint32 rtptime, guint32 packet_count, guint32 octet_count);
|
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,
|
gint32 packetslost, guint32 exthighestseq, guint32 jitter,
|
||||||
guint32 lsr, guint32 dlsr);
|
guint32 lsr, guint32 dlsr);
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ typedef struct {
|
|||||||
* RTPArrivalStats:
|
* RTPArrivalStats:
|
||||||
* @current_time: current time according to the system clock
|
* @current_time: current time according to the system clock
|
||||||
* @running_time: arrival time of a packet as buffer running_time
|
* @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
|
* @have_address: if the @address field contains a valid address
|
||||||
* @address: address of the sender of the packet
|
* @address: address of the sender of the packet
|
||||||
* @bytes: bytes of the packet including lowlevel overhead
|
* @bytes: bytes of the packet including lowlevel overhead
|
||||||
@ -68,6 +69,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
GstClockTime current_time;
|
GstClockTime current_time;
|
||||||
GstClockTime running_time;
|
GstClockTime running_time;
|
||||||
|
guint64 ntpnstime;
|
||||||
gboolean have_address;
|
gboolean have_address;
|
||||||
GstNetAddress address;
|
GstNetAddress address;
|
||||||
guint bytes;
|
guint bytes;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user