/* create an active SSRC for this session manager */
sess->source = rtp_session_create_source (sess);
sess->source->validated = TRUE;
+ sess->source->internal = TRUE;
sess->stats.active_sources++;
/* default UDP header length */
static void
update_arrival_stats (RTPSession * sess, RTPArrivalStats * arrival,
gboolean rtp, GstBuffer * buffer, GstClockTime current_time,
- guint64 ntpnstime)
+ GstClockTime running_time, guint64 ntpnstime)
{
/* get time of arrival */
arrival->time = current_time;
- arrival->timestamp = GST_BUFFER_TIMESTAMP (buffer);
+ arrival->running_time = running_time;
arrival->ntpnstime = ntpnstime;
/* get packet size including header overhead */
*/
GstFlowReturn
rtp_session_process_rtp (RTPSession * sess, GstBuffer * buffer,
- GstClockTime current_time, guint64 ntpnstime)
+ GstClockTime current_time, GstClockTime running_time, guint64 ntpnstime)
{
GstFlowReturn result;
guint32 ssrc;
RTP_SESSION_LOCK (sess);
/* update arrival stats */
- update_arrival_stats (sess, &arrival, TRUE, buffer, current_time, ntpnstime);
+ update_arrival_stats (sess, &arrival, TRUE, buffer, current_time,
+ running_time, ntpnstime);
/* ignore more RTP packets when we left the session */
if (sess->source->received_bye)
j++;
}
+ source->validated = TRUE;
+
if (created)
on_new_ssrc (sess, source);
if (changed)
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, -1);
if (sess->sent_bye)
goto ignore;
rtp_source_get_new_sr (own, data->ntpnstime, &ntptime, &rtptime,
&packet_count, &octet_count);
/* store stats */
- rtp_source_process_sr (own, data->ntpnstime, ntptime, rtptime, packet_count,
- octet_count);
+ rtp_source_process_sr (own, data->current_time, ntptime, rtptime,
+ packet_count, octet_count);
/* fill in sender report info */
gst_rtcp_packet_sr_set_sender_info (packet, own->ssrc,
GstFlowReturn result = GST_FLOW_OK;
GList *item;
ReportData data;
+ RTPSource *own;
g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
data.is_bye = FALSE;
data.has_sdes = FALSE;
+ own = sess->source;
+
RTP_SESSION_LOCK (sess);
/* get a new interval, we need this for various cleanups etc */
data.interval = calculate_rtcp_interval (sess, TRUE, sess->first_rtcp);
/* see if we need to generate SR or RR packets */
if (is_rtcp_time (sess, current_time, &data)) {
- if (sess->source->received_bye) {
+ if (own->received_bye) {
/* generate BYE instead */
GST_DEBUG ("generating BYE message");
session_bye (sess, &data);
}
if (sess->change_ssrc) {
- GST_DEBUG ("need to change our SSRC (%08x)", sess->source->ssrc);
+ GST_DEBUG ("need to change our SSRC (%08x)", own->ssrc);
g_hash_table_steal (sess->ssrcs[sess->mask_idx],
- GINT_TO_POINTER (sess->source->ssrc));
+ GINT_TO_POINTER (own->ssrc));
- sess->source->ssrc = rtp_session_create_new_ssrc (sess);
- rtp_source_reset (sess->source);
+ own->ssrc = rtp_session_create_new_ssrc (sess);
+ rtp_source_reset (own);
g_hash_table_insert (sess->ssrcs[sess->mask_idx],
- GINT_TO_POINTER (sess->source->ssrc), sess->source);
+ GINT_TO_POINTER (own->ssrc), own);
g_free (sess->bye_reason);
sess->bye_reason = NULL;
sess->sent_bye = FALSE;
sess->change_ssrc = FALSE;
- GST_DEBUG ("changed our SSRC to %08x", sess->source->ssrc);
+ GST_DEBUG ("changed our SSRC to %08x", own->ssrc);
}
RTP_SESSION_UNLOCK (sess);
GST_DEBUG ("sending packet");
if (sess->callbacks.send_rtcp)
- result = sess->callbacks.send_rtcp (sess, sess->source, data.rtcp,
+ result = sess->callbacks.send_rtcp (sess, own, data.rtcp,
sess->sent_bye, sess->send_rtcp_user_data);
else {
GST_DEBUG ("freeing packet");
PROP_SDES_LOCATION,
PROP_SDES_TOOL,
PROP_SDES_NOTE,
+ PROP_STATS,
PROP_LAST
};
g_object_class_install_property (gobject_class, PROP_SSRC,
g_param_spec_uint ("ssrc", "SSRC",
"The SSRC of this source", 0, G_MAXUINT,
- DEFAULT_SSRC, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ DEFAULT_SSRC,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_IS_CSRC,
g_param_spec_boolean ("is-csrc", "Is CSRC",
"If this SSRC is acting as a contributing source",
- DEFAULT_IS_CSRC, G_PARAM_READABLE));
+ DEFAULT_IS_CSRC, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_IS_VALIDATED,
g_param_spec_boolean ("is-validated", "Is Validated",
- "If this SSRC is validated", DEFAULT_IS_VALIDATED, G_PARAM_READABLE));
+ "If this SSRC is validated", DEFAULT_IS_VALIDATED,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_IS_SENDER,
g_param_spec_boolean ("is-sender", "Is Sender",
- "If this SSRC is a sender", DEFAULT_IS_SENDER, G_PARAM_READABLE));
+ "If this SSRC is a sender", DEFAULT_IS_SENDER,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SDES_CNAME,
g_param_spec_string ("sdes-cname", "SDES CNAME",
"The CNAME to put in SDES messages of this source",
- DEFAULT_SDES_CNAME, G_PARAM_READWRITE));
+ DEFAULT_SDES_CNAME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SDES_NAME,
g_param_spec_string ("sdes-name", "SDES NAME",
"The NAME to put in SDES messages of this source",
- DEFAULT_SDES_NAME, G_PARAM_READWRITE));
+ DEFAULT_SDES_NAME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SDES_EMAIL,
g_param_spec_string ("sdes-email", "SDES EMAIL",
"The EMAIL to put in SDES messages of this source",
- DEFAULT_SDES_EMAIL, G_PARAM_READWRITE));
+ DEFAULT_SDES_EMAIL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SDES_PHONE,
g_param_spec_string ("sdes-phone", "SDES PHONE",
"The PHONE to put in SDES messages of this source",
- DEFAULT_SDES_PHONE, G_PARAM_READWRITE));
+ DEFAULT_SDES_PHONE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SDES_LOCATION,
g_param_spec_string ("sdes-location", "SDES LOCATION",
"The LOCATION to put in SDES messages of this source",
- DEFAULT_SDES_LOCATION, G_PARAM_READWRITE));
+ DEFAULT_SDES_LOCATION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SDES_TOOL,
g_param_spec_string ("sdes-tool", "SDES TOOL",
"The TOOL to put in SDES messages of this source",
- DEFAULT_SDES_TOOL, G_PARAM_READWRITE));
+ DEFAULT_SDES_TOOL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_SDES_NOTE,
g_param_spec_string ("sdes-note", "SDES NOTE",
"The NOTE to put in SDES messages of this source",
- DEFAULT_SDES_NOTE, G_PARAM_READWRITE));
+ DEFAULT_SDES_NOTE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * RTPSource::stats
+ *
+ * The statistics of the source. This property returns a GstStructure with
+ * name application/x-rtp-source-stats with the following fields:
+ *
+ *
+ *
+ *
+ */
+ g_object_class_install_property (gobject_class, PROP_STATS,
+ g_param_spec_boxed ("stats", "Stats",
+ "The stats of this source", GST_TYPE_STRUCTURE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
GST_DEBUG_CATEGORY_INIT (rtp_source_debug, "rtpsource", 0, "RTP Source");
}
/* sources are initialy on probation until we receive enough valid RTP
* packets or a valid RTCP packet */
src->validated = FALSE;
+ src->internal = FALSE;
src->probation = RTP_DEFAULT_PROBATION;
src->payload = 0;
G_OBJECT_CLASS (rtp_source_parent_class)->finalize (object);
}
+static GstStructure *
+rtp_source_create_stats (RTPSource * src)
+{
+ GstStructure *s;
+ gboolean is_sender = src->is_sender;
+ gboolean internal = src->internal;
+
+ /* common data for all types of sources */
+ s = gst_structure_new ("application/x-rtp-source-stats",
+ "ssrc", G_TYPE_UINT, (guint) src->ssrc,
+ "internal", G_TYPE_BOOLEAN, internal,
+ "validated", G_TYPE_BOOLEAN, src->validated,
+ "received-bye", G_TYPE_BOOLEAN, src->received_bye,
+ "is-csrc", G_TYPE_BOOLEAN, src->is_csrc,
+ "is-sender", G_TYPE_BOOLEAN, is_sender, NULL);
+
+ if (internal) {
+ /* our internal source */
+ if (is_sender) {
+ /* if we are sending, report about how much we sent, other sources will
+ * have a RB with info on reception. */
+ gst_structure_set (s,
+ "octets-sent", G_TYPE_UINT64, src->stats.octets_sent,
+ "packets-sent", G_TYPE_UINT64, src->stats.packets_sent,
+ "bitrate", G_TYPE_UINT64, src->bitrate, NULL);
+ } else {
+ /* if we are not sending we have nothing more to report */
+ }
+ } else {
+ gboolean have_rb;
+ guint8 fractionlost = 0;
+ gint32 packetslost = 0;
+ guint32 exthighestseq = 0;
+ guint32 jitter = 0;
+ guint32 lsr = 0;
+ guint32 dlsr = 0;
+ guint32 round_trip = 0;
+
+ /* other sources */
+ if (is_sender) {
+ gboolean have_sr;
+ GstClockTime time = 0;
+ guint64 ntptime = 0;
+ guint32 rtptime = 0;
+ guint32 packet_count = 0;
+ guint32 octet_count = 0;
+
+ /* this source is sending to us, get the last SR. */
+ have_sr = rtp_source_get_last_sr (src, &time, &ntptime, &rtptime,
+ &packet_count, &octet_count);
+ gst_structure_set (s,
+ "octets-received", G_TYPE_UINT64, src->stats.octets_received,
+ "packets-received", G_TYPE_UINT64, src->stats.packets_received,
+ "have-sr", G_TYPE_BOOLEAN, have_sr,
+ "sr-ntptime", G_TYPE_UINT64, ntptime,
+ "sr-rtptime", G_TYPE_UINT, (guint) rtptime,
+ "sr-octet-count", G_TYPE_UINT, (guint) octet_count,
+ "sr-packet-count", G_TYPE_UINT, (guint) packet_count, NULL);
+ }
+ /* we might be sending to this SSRC so we report about how it is
+ * receiving our data */
+ have_rb = rtp_source_get_last_rb (src, &fractionlost, &packetslost,
+ &exthighestseq, &jitter, &lsr, &dlsr, &round_trip);
+
+ gst_structure_set (s,
+ "have-rb", G_TYPE_BOOLEAN, have_rb,
+ "rb-fractionlost", G_TYPE_UINT, (guint) fractionlost,
+ "rb-packetslost", G_TYPE_INT, (gint) packetslost,
+ "rb-exthighestseq", G_TYPE_UINT, (guint) exthighestseq,
+ "rb-jitter", G_TYPE_UINT, (guint) jitter,
+ "rb-lsr", G_TYPE_UINT, (guint) lsr,
+ "rb-dlsr", G_TYPE_UINT, (guint) dlsr,
+ "rb-round-trip", G_TYPE_UINT, (guint) round_trip, NULL);
+ }
+
+ return s;
+}
+
static void
rtp_source_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
g_value_take_string (value, rtp_source_get_sdes_string (src,
GST_RTCP_SDES_NOTE));
break;
+ case PROP_STATS:
+ g_value_take_boxed (value, rtp_source_create_stats (src));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
guint32 rtptime;
guint64 ext_rtptime;
guint64 ntp_diff, rtp_diff;
+ guint64 elapsed;
g_return_val_if_fail (RTP_IS_SOURCE (src), GST_FLOW_ERROR);
g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
/* update stats for the SR */
src->stats.packets_sent++;
src->stats.octets_sent += len;
+ src->bytes_sent += len;
+
+ if (src->prev_ntpnstime) {
+ elapsed = ntpnstime - src->prev_ntpnstime;
+
+ if (elapsed > (G_GINT64_CONSTANT (1) << 31)) {
+ guint64 rate;
+
+ rate =
+ gst_util_uint64_scale (src->bytes_sent, elapsed,
+ (G_GINT64_CONSTANT (1) << 29));
+
+ GST_LOG ("Elapsed %" G_GUINT64_FORMAT ", bytes %" G_GUINT64_FORMAT
+ ", rate %" G_GUINT64_FORMAT, elapsed, src->bytes_sent, rate);
+
+ if (src->bitrate == 0)
+ src->bitrate = rate;
+ else
+ src->bitrate = ((src->bitrate * 3) + rate) / 4;
+
+ src->prev_ntpnstime = ntpnstime;
+ src->bytes_sent = 0;
+ }
+ } else {
+ GST_LOG ("Reset bitrate measurement");
+ src->prev_ntpnstime = ntpnstime;
+ src->bitrate = 0;
+ }
rtptime = gst_rtp_buffer_get_timestamp (buffer);
ext_rtptime = src->last_rtptime;
curr->lsr = lsr;
curr->dlsr = dlsr;
- /* calculate round trip */
- ntp = (gst_rtcp_unix_to_ntp (time) >> 16) & 0xffffffff;
- A = ntp - dlsr;
- A -= lsr;
+ /* calculate round trip, round the time up */
+ ntp = ((gst_rtcp_unix_to_ntp (time) + 0xffff) >> 16) & 0xffffffff;
+ A = dlsr + lsr;
+ if (A > 0 && ntp > A)
+ A = ntp - A;
+ else
+ A = 0;
curr->round_trip = A;
GST_DEBUG ("NTP %04x:%04x, round trip %04x:%04x", ntp >> 16, ntp & 0xffff,
/**
* rtp_source_get_new_rb:
* @src: an #RTPSource
- * @ntpnstime: the current time in nanoseconds since 1970
+ * @time: the current time of the system clock
* @fractionlost: fraction lost since last SR/RR
* @packetslost: the cumululative number of packets lost
* @exthighestseq: the extended last sequence number received
* Returns: %TRUE on success.
*/
gboolean
-rtp_source_get_new_rb (RTPSource * src, guint64 ntpnstime,
+rtp_source_get_new_rb (RTPSource * src, GstClockTime time,
guint8 * fractionlost, gint32 * packetslost, guint32 * exthighestseq,
guint32 * jitter, guint32 * lsr, guint32 * dlsr)
{
/* LSR is middle 32 bits of the last ntptime */
LSR = (ntptime >> 16) & 0xffffffff;
- diff = ntpnstime - sr_time;
+ diff = time - sr_time;
GST_DEBUG ("last SR time diff %" GST_TIME_FORMAT, GST_TIME_ARGS (diff));
/* DLSR, delay since last SR is expressed in 1/65536 second units */
DLSR = gst_util_uint64_scale_int (diff, 65536, GST_SECOND);
* @jitter: the interarrival jitter
* @lsr: the last SR packet from this source
* @dlsr: the delay since last SR packet
+ * @round_trip: the round trip time
*
* Get the values of the last RB report set with rtp_source_process_rb().
*
gboolean
rtp_source_get_last_rb (RTPSource * src, guint8 * fractionlost,
gint32 * packetslost, guint32 * exthighestseq, guint32 * jitter,
- guint32 * lsr, guint32 * dlsr)
+ guint32 * lsr, guint32 * dlsr, guint32 * round_trip)
{
RTPReceiverReport *curr;
*lsr = curr->lsr;
if (dlsr)
*dlsr = curr->dlsr;
+ if (round_trip)
+ *round_trip = curr->round_trip;
return TRUE;
}