rtpbin: correctly calculate RTCP packet size

This commit is contained in:
Wim Taymans 2010-12-14 17:15:23 +01:00
parent 957eac9579
commit 7ebd374766
2 changed files with 16 additions and 13 deletions

View file

@ -74,13 +74,14 @@ enum
PROP_LAST PROP_LAST
}; };
/* update average packet size, we keep this scaled by 16 to keep enough /* update average packet size */
* precision. */ #define INIT_AVG(avg, val) \
(avg) = (val);
#define UPDATE_AVG(avg, val) \ #define UPDATE_AVG(avg, val) \
if ((avg) == 0) \ if ((avg) == 0) \
(avg) = (val) << 4; \ (avg) = (val); \
else \ else \
(avg) = ((val) + (15 * (avg))); (avg) = ((val) + (15 * (val))) >> 4;
/* The number RTCP intervals after which to timeout entries in the /* The number RTCP intervals after which to timeout entries in the
* collision table * collision table
@ -2169,8 +2170,7 @@ rtp_session_schedule_bye_locked (RTPSession * sess, const gchar * reason,
/* at least one member wants to send a BYE */ /* at least one member wants to send a BYE */
g_free (sess->bye_reason); g_free (sess->bye_reason);
sess->bye_reason = g_strdup (reason); sess->bye_reason = g_strdup (reason);
/* The avg packet size is kept scaled by 16 */ INIT_AVG (sess->stats.avg_rtcp_packet_size, 100);
sess->stats.avg_rtcp_packet_size = 100 * 16;
sess->stats.bye_members = 1; sess->stats.bye_members = 1;
sess->first_rtcp = TRUE; sess->first_rtcp = TRUE;
sess->sent_bye = FALSE; sess->sent_bye = FALSE;
@ -2692,12 +2692,14 @@ rtp_session_on_timeout (RTPSession * sess, GstClockTime current_time,
/* close the RTCP packet */ /* close the RTCP packet */
gst_rtcp_buffer_end (data.rtcp); gst_rtcp_buffer_end (data.rtcp);
GST_DEBUG ("sending packet");
if (sess->callbacks.send_rtcp) { if (sess->callbacks.send_rtcp) {
UPDATE_AVG (sess->stats.avg_rtcp_packet_size, UPDATE_AVG (sess->stats.avg_rtcp_packet_size,
GST_BUFFER_SIZE (data.rtcp)); GST_BUFFER_SIZE (data.rtcp));
result = sess->callbacks.send_rtcp (sess, own, data.rtcp, GST_DEBUG ("sending RTCP packet, avg size %u",
sess->sent_bye, sess->send_rtcp_user_data); sess->stats.avg_rtcp_packet_size);
result =
sess->callbacks.send_rtcp (sess, own, data.rtcp, sess->sent_bye,
sess->send_rtcp_user_data);
} else { } else {
GST_DEBUG ("freeing packet"); GST_DEBUG ("freeing packet");
gst_buffer_unref (data.rtcp); gst_buffer_unref (data.rtcp);

View file

@ -166,7 +166,7 @@ rtp_stats_calculate_rtcp_interval (RTPSessionStats * stats, gboolean we_send,
if (rtcp_bw <= 0.00001) if (rtcp_bw <= 0.00001)
return GST_CLOCK_TIME_NONE; return GST_CLOCK_TIME_NONE;
avg_rtcp_size = stats->avg_rtcp_packet_size / 16.0; avg_rtcp_size = stats->avg_rtcp_packet_size;
/* /*
* The effective number of sites times the average packet size is * The effective number of sites times the average packet size is
* the total number of octets sent when each site sends a report. * the total number of octets sent when each site sends a report.
@ -176,6 +176,7 @@ rtp_stats_calculate_rtcp_interval (RTPSessionStats * stats, gboolean we_send,
* time interval we send one report so this time is also our * time interval we send one report so this time is also our
* average time between reports. * average time between reports.
*/ */
GST_DEBUG ("avg size %f, n %f, rtcp_bw %f", avg_rtcp_size, n, rtcp_bw);
interval = avg_rtcp_size * n / rtcp_bw; interval = avg_rtcp_size * n / rtcp_bw;
if (interval < rtcp_min_time) if (interval < rtcp_min_time)
interval = rtcp_min_time; interval = rtcp_min_time;
@ -245,7 +246,7 @@ rtp_stats_calculate_bye_interval (RTPSessionStats * stats)
if (rtcp_bw <= 0.0001) if (rtcp_bw <= 0.0001)
return GST_CLOCK_TIME_NONE; return GST_CLOCK_TIME_NONE;
avg_rtcp_size = stats->avg_rtcp_packet_size / 16.0; avg_rtcp_size = stats->avg_rtcp_packet_size;
/* /*
* The effective number of sites times the average packet size is * The effective number of sites times the average packet size is
* the total number of octets sent when each site sends a report. * the total number of octets sent when each site sends a report.
@ -274,7 +275,7 @@ rtp_stats_calculate_bye_interval (RTPSessionStats * stats)
* Returns: total RTP packets lost. * Returns: total RTP packets lost.
*/ */
gint64 gint64
rtp_stats_get_packets_lost (const RTPSourceStats *stats) rtp_stats_get_packets_lost (const RTPSourceStats * stats)
{ {
gint64 lost; gint64 lost;
guint64 extended_max, expected; guint64 extended_max, expected;
@ -284,4 +285,4 @@ rtp_stats_get_packets_lost (const RTPSourceStats *stats)
lost = expected - stats->packets_received; lost = expected - stats->packets_received;
return lost; return lost;
} }