From 1f17b334ff2c31061dbeff0a5b42b77872cdb97e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Tue, 1 Jun 2010 21:35:40 -0400 Subject: [PATCH] rtpsession: Calculate RTCP bandwidth as a fraction of the RTP bandwidth Calculate the RTCP bandwidth to be a fraction of the RTP bandwidth if it is specified as a value between 0 and 1. --- gst/rtpmanager/gstrtpsession.c | 4 ++-- gst/rtpmanager/rtpsession.c | 4 ++-- gst/rtpmanager/rtpsession.h | 2 +- gst/rtpmanager/rtpstats.c | 21 +++++++++++++++------ gst/rtpmanager/rtpstats.h | 6 ++++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/gst/rtpmanager/gstrtpsession.c b/gst/rtpmanager/gstrtpsession.c index d46ceaf..63123cd 100644 --- a/gst/rtpmanager/gstrtpsession.c +++ b/gst/rtpmanager/gstrtpsession.c @@ -192,7 +192,7 @@ enum #define DEFAULT_NTP_NS_BASE 0 #define DEFAULT_BANDWIDTH RTP_STATS_BANDWIDTH -#define DEFAULT_RTCP_FRACTION RTP_STATS_RTCP_BANDWIDTH +#define DEFAULT_RTCP_FRACTION (RTP_STATS_BANDWIDTH * RTP_STATS_RTCP_FRACTION) #define DEFAULT_RTCP_RR_BANDWIDTH -1 #define DEFAULT_RTCP_RS_BANDWIDTH -1 #define DEFAULT_SDES NULL @@ -542,7 +542,7 @@ gst_rtp_session_class_init (GstRtpSessionClass * klass) g_object_class_install_property (gobject_class, PROP_RTCP_FRACTION, g_param_spec_double ("rtcp-fraction", "RTCP Fraction", - "The RTCP bandwidth of the session in bytes per second", + "The RTCP bandwidth of the session in bytes per second (or as a real fraction of the RTP bandwidth if < 1)", 0.0, G_MAXDOUBLE, DEFAULT_RTCP_FRACTION, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, PROP_RTCP_RR_BANDWIDTH, diff --git a/gst/rtpmanager/rtpsession.c b/gst/rtpmanager/rtpsession.c index 6d48858..3f0bd3b 100644 --- a/gst/rtpmanager/rtpsession.c +++ b/gst/rtpmanager/rtpsession.c @@ -47,7 +47,7 @@ enum #define DEFAULT_INTERNAL_SOURCE NULL #define DEFAULT_BANDWIDTH RTP_STATS_BANDWIDTH -#define DEFAULT_RTCP_FRACTION RTP_STATS_RTCP_BANDWIDTH +#define DEFAULT_RTCP_FRACTION (RTP_STATS_RTCP_FRACTION * RTP_STATS_BANDWIDTH) #define DEFAULT_RTCP_RR_BANDWIDTH -1 #define DEFAULT_RTCP_RS_BANDWIDTH -1 #define DEFAULT_RTCP_MTU 1400 @@ -256,7 +256,7 @@ rtp_session_class_init (RTPSessionClass * klass) g_object_class_install_property (gobject_class, PROP_RTCP_FRACTION, g_param_spec_double ("rtcp-fraction", "RTCP Fraction", - "The fraction of the bandwidth used for RTCP", + "The fraction of the bandwidth used for RTCP (or as a real fraction of the RTP bandwidth if < 1)", 0.0, G_MAXDOUBLE, DEFAULT_RTCP_FRACTION, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); diff --git a/gst/rtpmanager/rtpsession.h b/gst/rtpmanager/rtpsession.h index 8a1fb3e..3fc9874 100644 --- a/gst/rtpmanager/rtpsession.h +++ b/gst/rtpmanager/rtpsession.h @@ -166,7 +166,7 @@ struct _RTPSession { /* bandwidths */ gboolean recalc_bandwidth; guint bandwidth; - guint rtcp_bandwidth; + gdouble rtcp_bandwidth; guint rtcp_rr_bandwidth; guint rtcp_rs_bandwidth; diff --git a/gst/rtpmanager/rtpstats.c b/gst/rtpmanager/rtpstats.c index dc3bb8e..8d1f5cf 100644 --- a/gst/rtpmanager/rtpstats.c +++ b/gst/rtpmanager/rtpstats.c @@ -46,8 +46,8 @@ rtp_stats_init_defaults (RTPSessionStats * stats) * defaults. */ void -rtp_stats_set_bandwidths (RTPSessionStats * stats, guint rtp_bw, guint rtcp_bw, - guint rs, guint rr) +rtp_stats_set_bandwidths (RTPSessionStats * stats, guint rtp_bw, + gdouble rtcp_bw, guint rs, guint rr) { GST_DEBUG ("recalc bandwidths: RTP %u, RTCP %u, RS %u, RR %u", rtp_bw, rtcp_bw, rs, rr); @@ -57,16 +57,25 @@ rtp_stats_set_bandwidths (RTPSessionStats * stats, guint rtp_bw, guint rtcp_bw, if (rs != -1 && rr != -1) rtcp_bw = rs + rr; + /* If rtcp_bw is between 0 and 1, it is a fraction of rtp_bw */ + if (rtcp_bw > 0 && rtcp_bw < 1) { + if (rtp_bw > 0) + rtcp_bw = rtp_bw * rtcp_bw; + else + rtcp_bw = -1; + } + /* RTCP is 5% of the RTP bandwidth */ - if (rtp_bw == -1 && rtcp_bw != -1) + if (rtp_bw == -1 && rtcp_bw > 0) rtp_bw = rtcp_bw * 20; - else if (rtp_bw != -1 && rtcp_bw == -1) + else if (rtp_bw != -1 && rtcp_bw < 0) rtcp_bw = rtp_bw / 20; - else if (rtp_bw == -1 && rtcp_bw == -1) { + else if (rtp_bw == -1 && rtcp_bw < 0) { /* nothing given, take defaults */ rtp_bw = RTP_STATS_BANDWIDTH; - rtcp_bw = RTP_STATS_RTCP_BANDWIDTH; + rtcp_bw = rtp_bw = RTP_STATS_RTCP_FRACTION; } + stats->bandwidth = rtp_bw; stats->rtcp_bandwidth = rtcp_bw; diff --git a/gst/rtpmanager/rtpstats.h b/gst/rtpmanager/rtpstats.h index d71bac4..cb447b8 100644 --- a/gst/rtpmanager/rtpstats.h +++ b/gst/rtpmanager/rtpstats.h @@ -128,7 +128,7 @@ typedef struct { } RTPSourceStats; #define RTP_STATS_BANDWIDTH 64000 -#define RTP_STATS_RTCP_BANDWIDTH 3200 +#define RTP_STATS_RTCP_FRACTION 0.05 /* * Minimum average time between RTCP packets from this site (in * seconds). This time prevents the reports from `clumping' when @@ -186,7 +186,9 @@ typedef struct { void rtp_stats_init_defaults (RTPSessionStats *stats); -void rtp_stats_set_bandwidths (RTPSessionStats *stats, guint rtp_bw, guint rtcp_bw, +void rtp_stats_set_bandwidths (RTPSessionStats *stats, + guint rtp_bw, + gdouble rtcp_bw, guint rs, guint rr); GstClockTime rtp_stats_calculate_rtcp_interval (RTPSessionStats *stats, gboolean sender, gboolean first); -- 2.7.4