From 9d800cad434a12f5c0cad1e356482f97881cfa68 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Fri, 21 Jun 2019 17:46:36 +0200 Subject: [PATCH] rtpmanager: consider UDP and IP headers in bandwidth calculation According to RFC3550 lower-level headers should be considered for bandwidth calculation. See https://tools.ietf.org/html/rfc3550#section-6.2 paragraph 4: Bandwidth calculations for control and data traffic include lower-layer transport and network protocols (e.g., UDP and IP) since that is what the resource reservation system would need to know. Fix the source data to accommodate that. Assume UDPv4 over IP for now, this is a simplification but it's good enough for now. While at it define a constant and use that instead of a magic number. NOTE: this change basically reverts the logic of commit 529f443a6 (rtpsource: use payload size to estimate bitrate, 2010-03-02) --- gst/rtpmanager/rtpsession.c | 2 +- gst/rtpmanager/rtpsource.c | 6 +++--- gst/rtpmanager/rtpstats.h | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gst/rtpmanager/rtpsession.c b/gst/rtpmanager/rtpsession.c index 081de5070a..0ddb2b584f 100644 --- a/gst/rtpmanager/rtpsession.c +++ b/gst/rtpmanager/rtpsession.c @@ -673,7 +673,7 @@ rtp_session_init (RTPSession * sess) sess->rtcp_rs_bandwidth = DEFAULT_RTCP_RS_BANDWIDTH; /* default UDP header length */ - sess->header_len = 28; + sess->header_len = UDP_IP_HEADER_OVERHEAD; sess->mtu = DEFAULT_RTCP_MTU; sess->probation = DEFAULT_PROBATION; diff --git a/gst/rtpmanager/rtpsource.c b/gst/rtpmanager/rtpsource.c index 7079e168a7..78e6746e5e 100644 --- a/gst/rtpmanager/rtpsource.c +++ b/gst/rtpmanager/rtpsource.c @@ -1188,8 +1188,8 @@ update_receiver_stats (RTPSource * src, RTPPacketInfo * pinfo, src->stats.octets_received += pinfo->payload_len; src->stats.bytes_received += pinfo->bytes; src->stats.packets_received += pinfo->packets; - /* for the bitrate estimation */ - src->bytes_received += pinfo->payload_len; + /* for the bitrate estimation consider all lower level headers */ + src->bytes_received += pinfo->bytes; GST_LOG ("seq %u, PC: %" G_GUINT64_FORMAT ", OC: %" G_GUINT64_FORMAT, seqnr, src->stats.packets_received, src->stats.octets_received); @@ -1319,7 +1319,7 @@ rtp_source_send_rtp (RTPSource * src, RTPPacketInfo * pinfo) /* update stats for the SR */ src->stats.packets_sent += pinfo->packets; src->stats.octets_sent += pinfo->payload_len; - src->bytes_sent += pinfo->payload_len; + src->bytes_sent += pinfo->bytes; running_time = pinfo->running_time; diff --git a/gst/rtpmanager/rtpstats.h b/gst/rtpmanager/rtpstats.h index b8b26ecee6..bd3a54efed 100644 --- a/gst/rtpmanager/rtpstats.h +++ b/gst/rtpmanager/rtpstats.h @@ -27,6 +27,9 @@ #include #include +/* UDP/IP is assumed for bandwidth calculation */ +#define UDP_IP_HEADER_OVERHEAD 28 + /** * RTPSenderReport: *