2014-05-22 02:16:17 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/bandwidth_estimator.h"
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-06-22 23:19:30 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-05-22 02:16:17 +00:00
|
|
|
|
|
|
|
namespace {
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint64_t kBitsInByte = 8;
|
2014-05-22 02:16:17 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(BandwidthEstimatorTest, AllBlocks) {
|
|
|
|
const double kDuration = 1.0;
|
2019-07-11 21:32:10 +00:00
|
|
|
BandwidthEstimator be;
|
2018-11-14 20:47:48 +00:00
|
|
|
const uint64_t kNumBlocksToAdd = 100;
|
2018-06-22 23:19:30 +00:00
|
|
|
uint64_t total_bytes = 0;
|
|
|
|
for (uint64_t i = 1; i <= kNumBlocksToAdd; ++i) {
|
2014-05-22 02:16:17 +00:00
|
|
|
be.AddBlock(i, kDuration);
|
2018-06-22 23:19:30 +00:00
|
|
|
total_bytes += i;
|
|
|
|
}
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-06-22 23:19:30 +00:00
|
|
|
const uint64_t kExptectedEstimate =
|
|
|
|
total_bytes * kBitsInByte / kNumBlocksToAdd;
|
2014-05-22 02:16:17 +00:00
|
|
|
EXPECT_EQ(kExptectedEstimate, be.Estimate());
|
2018-06-22 23:19:30 +00:00
|
|
|
const uint64_t kMax = kNumBlocksToAdd * kBitsInByte;
|
2018-04-13 18:48:11 +00:00
|
|
|
EXPECT_EQ(kMax, be.Max());
|
2014-05-22 02:16:17 +00:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:32:10 +00:00
|
|
|
TEST(BandwidthEstimatorTest, ExcludeShortBlocks) {
|
2018-11-14 20:47:48 +00:00
|
|
|
const double kDuration = 1.0;
|
2019-07-11 21:32:10 +00:00
|
|
|
BandwidthEstimator be;
|
2018-11-14 20:47:48 +00:00
|
|
|
|
|
|
|
// Add 4 blocks with duration 0.1, 0.8, 1.8 and 0.2 respectively. The first
|
|
|
|
// and the last blocks are excluded as they are too short.
|
|
|
|
be.AddBlock(1, 0.1 * kDuration);
|
|
|
|
be.AddBlock(1, 0.8 * kDuration);
|
|
|
|
be.AddBlock(1, 1.8 * kDuration);
|
|
|
|
be.AddBlock(1, 0.2 * kDuration);
|
|
|
|
|
|
|
|
const uint64_t kExpectedMax = 1 / 0.8 * kBitsInByte;
|
|
|
|
EXPECT_EQ(kExpectedMax, be.Max());
|
|
|
|
}
|
|
|
|
|
2019-07-11 21:32:10 +00:00
|
|
|
TEST(BandwidthEstimatorTest, ExcludeShortBlocksMore) {
|
|
|
|
const double kDuration = 1.0;
|
|
|
|
BandwidthEstimator be;
|
|
|
|
|
|
|
|
for (int k = 0; k < 100; k++) {
|
|
|
|
// Add 4 blocks with duration 0.1, 0.8, 1.8 and 0.2 respectively. The first
|
|
|
|
// and the last blocks are excluded as they are too short.
|
|
|
|
be.AddBlock(1, 0.1 * kDuration);
|
|
|
|
be.AddBlock(1, 0.8 * kDuration);
|
|
|
|
be.AddBlock(1, 1.8 * kDuration);
|
|
|
|
be.AddBlock(1, 0.2 * kDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint64_t kExpectedMax = 1 / 0.8 * kBitsInByte;
|
|
|
|
EXPECT_EQ(kExpectedMax, be.Max());
|
|
|
|
}
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|