summaryrefslogtreecommitdiffstats
path: root/gst/rtpmanager/rtpsource.c
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2007-09-12 18:04:32 +0000
committerTim-Philipp Müller <tim.muller@collabora.co.uk>2009-08-11 02:30:29 +0100
commit919deb449063c2b26485b7c07b829e081b7c7fae (patch)
treec1e38e98e20c340d66cd9a250412ff5df3c212a6 /gst/rtpmanager/rtpsource.c
parentaa8985d1e40d4d847788ff45b76fedba0e9cd6f5 (diff)
gst/rtpmanager/gstrtpbin.c: Calculate and configure the NTP base time so that we can generate better
Original commit message from CVS: * gst/rtpmanager/gstrtpbin.c: (calc_ntp_ns_base), (gst_rtp_bin_change_state), (new_payload_found), (create_send_rtp): Calculate and configure the NTP base time so that we can generate better NTP times in SR packets. Set caps on new ghostpad. * gst/rtpmanager/gstrtpjitterbuffer.c: (gst_rtp_jitter_buffer_loop): Clean debug statement. * gst/rtpmanager/gstrtpsession.c: (gst_rtp_session_class_init), (gst_rtp_session_init), (gst_rtp_session_set_property), (gst_rtp_session_get_property), (get_current_ntp_ns_time), (rtcp_thread), (gst_rtp_session_event_recv_rtp_sink), (gst_rtp_session_internal_links), (gst_rtp_session_chain_recv_rtp), (gst_rtp_session_event_send_rtp_sink), (gst_rtp_session_chain_send_rtp), (create_recv_rtp_sink), (create_send_rtp_sink): * gst/rtpmanager/gstrtpsession.h: Add ntp-ns-base property to convert running_time to NTP time. Handle NEWSEGMENT events on send and recv RTP pads so that we can calculate the running time and thus NTP time of the packets. Simplify getting the current NTP time using the pipeline clock. Implement internal links functions. Use the buffer timestamp to calculate the NTP time instead of the clock. * gst/rtpmanager/gstrtpssrcdemux.c: (create_demux_pad_for_ssrc), (gst_rtp_ssrc_demux_init), (gst_rtp_ssrc_demux_sink_event), (gst_rtp_ssrc_demux_chain), (gst_rtp_ssrc_demux_rtcp_chain), (gst_rtp_ssrc_demux_internal_links), (gst_rtp_ssrc_demux_src_query): * gst/rtpmanager/gstrtpssrcdemux.h: Implement internal links function. Calculate the diff between different streams, this might be used later to get the inter stream latency. * gst/rtpmanager/rtpsession.c: (rtp_session_send_rtp): Simple cleanup. * gst/rtpmanager/rtpsource.c: (rtp_source_init), (calculate_jitter), (rtp_source_send_rtp), (rtp_source_get_new_sr): Make the clock skew window a little bigger. Apply the clock skew to all buffers, not just one with a new timestamp. Calculate and debug sender clock drift. Use extended last timestamp to interpollate for SR reports.
Diffstat (limited to 'gst/rtpmanager/rtpsource.c')
-rw-r--r--gst/rtpmanager/rtpsource.c53
1 files changed, 37 insertions, 16 deletions
diff --git a/gst/rtpmanager/rtpsource.c b/gst/rtpmanager/rtpsource.c
index 63543358..c4152474 100644
--- a/gst/rtpmanager/rtpsource.c
+++ b/gst/rtpmanager/rtpsource.c
@@ -74,6 +74,7 @@ rtp_source_init (RTPSource * src)
src->prev_ext_rtptime = -1;
src->packets = g_queue_new ();
src->seqnum_base = -1;
+ src->last_rtptime = -1;
src->stats.cycles = -1;
src->stats.jitter = 0;
@@ -320,22 +321,19 @@ calculate_jitter (RTPSource * src, GstBuffer * buffer,
* out of sync and we must compensate. */
skew = ntpdiff - rtpdiff;
/* average out the skew to get a smooth value. */
- src->avg_skew = (31 * src->avg_skew + skew) / 32;
+ src->avg_skew = (63 * src->avg_skew + skew) / 64;
- GST_DEBUG ("skew %" G_GINT64_FORMAT ", avg %" G_GINT64_FORMAT, skew,
+ GST_DEBUG ("new skew %" G_GINT64_FORMAT ", avg %" G_GINT64_FORMAT, skew,
src->avg_skew);
- if (src->avg_skew != 0) {
- guint32 timestamp;
-
- /* patch the buffer RTP timestamp with the skew */
- GST_DEBUG ("adjusting timestamp %" G_GINT64_FORMAT, src->avg_skew);
- timestamp = gst_rtp_buffer_get_timestamp (buffer);
- timestamp += src->avg_skew;
- gst_rtp_buffer_set_timestamp (buffer, timestamp);
- }
/* store previous extended timestamp */
src->prev_ext_rtptime = ext_rtptime;
}
+ if (src->avg_skew != 0) {
+ /* patch the buffer RTP timestamp with the skew */
+ GST_DEBUG ("skew timestamp RTP %" G_GUINT32_FORMAT " -> %" G_GINT64_FORMAT,
+ rtptime, rtptime + src->avg_skew);
+ gst_rtp_buffer_set_timestamp (buffer, rtptime + src->avg_skew);
+ }
/* convert arrival time to RTP timestamp units, truncate to 32 bits, we don't
* care about the absolute value, just the difference. */
@@ -555,6 +553,9 @@ rtp_source_send_rtp (RTPSource * src, GstBuffer * buffer, guint64 ntpnstime)
{
GstFlowReturn result = GST_FLOW_OK;
guint len;
+ guint32 rtptime;
+ guint64 ext_rtptime;
+ guint64 ntp_diff, rtp_diff;
g_return_val_if_fail (RTP_IS_SOURCE (src), GST_FLOW_ERROR);
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
@@ -570,9 +571,27 @@ rtp_source_send_rtp (RTPSource * src, GstBuffer * buffer, guint64 ntpnstime)
src->stats.packets_sent++;
src->stats.octets_sent += len;
+ rtptime = gst_rtp_buffer_get_timestamp (buffer);
+ ext_rtptime = src->last_rtptime;
+ ext_rtptime = gst_rtp_buffer_ext_timestamp (&ext_rtptime, rtptime);
+
+ GST_DEBUG ("SSRC %08x, RTP %" G_GUINT64_FORMAT ", NTP %" GST_TIME_FORMAT,
+ src->ssrc, ext_rtptime, GST_TIME_ARGS (ntpnstime));
+
+ if (ext_rtptime > src->last_rtptime) {
+ rtp_diff = ext_rtptime - src->last_rtptime;
+ ntp_diff = ntpnstime - src->last_ntpnstime;
+
+ /* calc the diff so we can detect drift at the sender. This can also be used
+ * to guestimate the clock rate if the NTP time is locked to the RTP
+ * timestamps (as is the case when the capture device is providing the clock). */
+ GST_DEBUG ("SSRC %08x, diff RTP %" G_GUINT64_FORMAT ", diff NTP %"
+ GST_TIME_FORMAT, src->ssrc, rtp_diff, GST_TIME_ARGS (ntp_diff));
+ }
+
/* we keep track of the last received RTP timestamp and the corresponding
* NTP timestamp so that we can use this info when constructing SR reports */
- src->last_rtptime = gst_rtp_buffer_get_timestamp (buffer);
+ src->last_rtptime = ext_rtptime;
src->last_ntpnstime = ntpnstime;
/* push packet */
@@ -587,7 +606,8 @@ rtp_source_send_rtp (RTPSource * src, GstBuffer * buffer, guint64 ntpnstime)
* get the correct SSRC. */
buffer = gst_buffer_make_writable (buffer);
- GST_DEBUG ("updating SSRC from %08x to %08x", ssrc, src->ssrc);
+ GST_WARNING ("updating SSRC from %08x to %08x, fix the payloader", ssrc,
+ src->ssrc);
gst_rtp_buffer_set_ssrc (buffer, src->ssrc);
}
GST_DEBUG ("pushing RTP packet %" G_GUINT64_FORMAT,
@@ -716,7 +736,7 @@ rtp_source_get_new_sr (RTPSource * src, GstClockTime ntpnstime,
guint64 * ntptime, guint32 * rtptime, guint32 * packet_count,
guint32 * octet_count)
{
- guint32 t_rtp;
+ guint64 t_rtp;
guint64 t_current_ntp;
GstClockTimeDiff diff;
@@ -730,7 +750,7 @@ rtp_source_get_new_sr (RTPSource * src, GstClockTime ntpnstime,
t_rtp = src->last_rtptime;
GST_DEBUG ("last_ntpnstime %" GST_TIME_FORMAT ", last_rtptime %"
- G_GUINT32_FORMAT, GST_TIME_ARGS (src->last_ntpnstime), t_rtp);
+ G_GUINT64_FORMAT, GST_TIME_ARGS (src->last_ntpnstime), t_rtp);
if (src->clock_rate != -1) {
/* get the diff with the SR time */
@@ -752,11 +772,12 @@ rtp_source_get_new_sr (RTPSource * src, GstClockTime ntpnstime,
GST_WARNING ("no clock-rate, cannot interpollate rtp time");
}
+ /* convert the NTP time in nanoseconds to 32.32 fixed point */
t_current_ntp = gst_util_uint64_scale (ntpnstime, (1LL << 32), GST_SECOND);
GST_DEBUG ("NTP %08x:%08x, RTP %" G_GUINT32_FORMAT,
(guint32) (t_current_ntp >> 32), (guint32) (t_current_ntp & 0xffffffff),
- t_rtp);
+ (guint32) t_rtp);
if (ntptime)
*ntptime = t_current_ntp;