Fix overflow for high bitrates in BitrateProber

Bug: webrtc:9395
Change-Id: Ic63d9a5ca40673eb87419d0d9e2e3b67fb1a81e4
Reviewed-on: https://webrtc-review.googlesource.com/c/110460
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25592}
This commit is contained in:
Johannes Kron
2018-11-09 12:39:38 +01:00
committed by Commit Bot
parent 09102a02cf
commit 8584667583
2 changed files with 21 additions and 2 deletions

View File

@ -96,8 +96,9 @@ void BitrateProber::CreateProbeCluster(int bitrate_bps, int64_t now_ms) {
ProbeCluster cluster;
cluster.time_created_ms = now_ms;
cluster.pace_info.probe_cluster_min_probes = kMinProbePacketsSent;
cluster.pace_info.probe_cluster_min_bytes =
bitrate_bps * kMinProbeDurationMs / 8000;
cluster.pace_info.probe_cluster_min_bytes = static_cast<int32_t>(
static_cast<int64_t>(bitrate_bps) * kMinProbeDurationMs / 8000);
RTC_DCHECK_GE(cluster.pace_info.probe_cluster_min_bytes, 0);
cluster.pace_info.send_bitrate_bps = bitrate_bps;
cluster.pace_info.probe_cluster_id = next_cluster_id_++;
clusters_.push(cluster);

View File

@ -147,6 +147,24 @@ TEST(BitrateProberTest, ScaleBytesUsedForProbing) {
EXPECT_FALSE(prober.IsProbing());
}
TEST(BitrateProberTest, HighBitrateProbing) {
BitrateProber prober;
constexpr int kBitrateBps = 1000000000; // 1 Gbps.
constexpr int kPacketSizeBytes = 1000;
constexpr int kExpectedBytesSent = (kBitrateBps / 8000) * 15;
prober.CreateProbeCluster(kBitrateBps, 0);
prober.OnIncomingPacket(kPacketSizeBytes);
int bytes_sent = 0;
while (bytes_sent < kExpectedBytesSent) {
ASSERT_TRUE(prober.IsProbing());
prober.ProbeSent(0, kPacketSizeBytes);
bytes_sent += kPacketSizeBytes;
}
EXPECT_FALSE(prober.IsProbing());
}
TEST(BitrateProberTest, ProbeClusterTimeout) {
BitrateProber prober;
constexpr int kBitrateBps = 300000; // 300 kbps