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.
This commit is contained in:
Olivier Crête 2010-06-01 21:35:40 -04:00 committed by Wim Taymans
parent 8381d9788d
commit 1f17b334ff
5 changed files with 24 additions and 13 deletions

View File

@ -192,7 +192,7 @@ enum
#define DEFAULT_NTP_NS_BASE 0 #define DEFAULT_NTP_NS_BASE 0
#define DEFAULT_BANDWIDTH RTP_STATS_BANDWIDTH #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_RR_BANDWIDTH -1
#define DEFAULT_RTCP_RS_BANDWIDTH -1 #define DEFAULT_RTCP_RS_BANDWIDTH -1
#define DEFAULT_SDES NULL #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_object_class_install_property (gobject_class, PROP_RTCP_FRACTION,
g_param_spec_double ("rtcp-fraction", "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)); 0.0, G_MAXDOUBLE, DEFAULT_RTCP_FRACTION, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_RTCP_RR_BANDWIDTH, g_object_class_install_property (gobject_class, PROP_RTCP_RR_BANDWIDTH,

View File

@ -47,7 +47,7 @@ enum
#define DEFAULT_INTERNAL_SOURCE NULL #define DEFAULT_INTERNAL_SOURCE NULL
#define DEFAULT_BANDWIDTH RTP_STATS_BANDWIDTH #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_RR_BANDWIDTH -1
#define DEFAULT_RTCP_RS_BANDWIDTH -1 #define DEFAULT_RTCP_RS_BANDWIDTH -1
#define DEFAULT_RTCP_MTU 1400 #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_object_class_install_property (gobject_class, PROP_RTCP_FRACTION,
g_param_spec_double ("rtcp-fraction", "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, 0.0, G_MAXDOUBLE, DEFAULT_RTCP_FRACTION,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));

View File

@ -166,7 +166,7 @@ struct _RTPSession {
/* bandwidths */ /* bandwidths */
gboolean recalc_bandwidth; gboolean recalc_bandwidth;
guint bandwidth; guint bandwidth;
guint rtcp_bandwidth; gdouble rtcp_bandwidth;
guint rtcp_rr_bandwidth; guint rtcp_rr_bandwidth;
guint rtcp_rs_bandwidth; guint rtcp_rs_bandwidth;

View File

@ -46,8 +46,8 @@ rtp_stats_init_defaults (RTPSessionStats * stats)
* defaults. * defaults.
*/ */
void void
rtp_stats_set_bandwidths (RTPSessionStats * stats, guint rtp_bw, guint rtcp_bw, rtp_stats_set_bandwidths (RTPSessionStats * stats, guint rtp_bw,
guint rs, guint rr) gdouble rtcp_bw, guint rs, guint rr)
{ {
GST_DEBUG ("recalc bandwidths: RTP %u, RTCP %u, RS %u, RR %u", rtp_bw, GST_DEBUG ("recalc bandwidths: RTP %u, RTCP %u, RS %u, RR %u", rtp_bw,
rtcp_bw, rs, rr); 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) if (rs != -1 && rr != -1)
rtcp_bw = rs + rr; 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 */ /* 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; 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; 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 */ /* nothing given, take defaults */
rtp_bw = RTP_STATS_BANDWIDTH; rtp_bw = RTP_STATS_BANDWIDTH;
rtcp_bw = RTP_STATS_RTCP_BANDWIDTH; rtcp_bw = rtp_bw = RTP_STATS_RTCP_FRACTION;
} }
stats->bandwidth = rtp_bw; stats->bandwidth = rtp_bw;
stats->rtcp_bandwidth = rtcp_bw; stats->rtcp_bandwidth = rtcp_bw;

View File

@ -128,7 +128,7 @@ typedef struct {
} RTPSourceStats; } RTPSourceStats;
#define RTP_STATS_BANDWIDTH 64000 #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 * Minimum average time between RTCP packets from this site (in
* seconds). This time prevents the reports from `clumping' when * 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_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); guint rs, guint rr);
GstClockTime rtp_stats_calculate_rtcp_interval (RTPSessionStats *stats, gboolean sender, gboolean first); GstClockTime rtp_stats_calculate_rtcp_interval (RTPSessionStats *stats, gboolean sender, gboolean first);