|
| 1 | +/* |
| 2 | + * Copyright 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | + * |
| 4 | + * Use of this source code is governed by a BSD-style license |
| 5 | + * that can be found in the LICENSE file in the root of the source |
| 6 | + * tree. An additional intellectual property rights grant can be found |
| 7 | + * in the file PATENTS. All contributing project authors may |
| 8 | + * be found in the AUTHORS file in the root of the source tree. |
| 9 | + */ |
| 10 | +#include "test/gtest.h" |
| 11 | +#include "test/scenario/scenario.h" |
| 12 | + |
| 13 | +namespace webrtc { |
| 14 | +namespace test { |
| 15 | + |
| 16 | +TEST(ProbingTest, InitialProbingRampsUpTargetRateWhenNetworkIsGood) { |
| 17 | + Scenario s; |
| 18 | + NetworkSimulationConfig good_network; |
| 19 | + good_network.bandwidth = DataRate::KilobitsPerSec(2000); |
| 20 | + |
| 21 | + VideoStreamConfig video_config; |
| 22 | + video_config.encoder.codec = |
| 23 | + VideoStreamConfig::Encoder::Codec::kVideoCodecVP8; |
| 24 | + CallClientConfig send_config; |
| 25 | + auto* caller = s.CreateClient("caller", send_config); |
| 26 | + auto* callee = s.CreateClient("callee", CallClientConfig()); |
| 27 | + auto route = |
| 28 | + s.CreateRoutes(caller, {s.CreateSimulationNode(good_network)}, callee, |
| 29 | + {s.CreateSimulationNode(NetworkSimulationConfig())}); |
| 30 | + s.CreateVideoStream(route->forward(), video_config); |
| 31 | + |
| 32 | + s.RunFor(TimeDelta::Seconds(1)); |
| 33 | + EXPECT_GE(DataRate::BitsPerSec(caller->GetStats().send_bandwidth_bps), |
| 34 | + 3 * send_config.transport.rates.start_rate); |
| 35 | +} |
| 36 | + |
| 37 | +TEST(ProbingTest, MidCallProbingRampupTriggeredByUpdatedBitrateConstraints) { |
| 38 | + Scenario s; |
| 39 | + |
| 40 | + const DataRate kStartRate = DataRate::KilobitsPerSec(300); |
| 41 | + const DataRate kConstrainedRate = DataRate::KilobitsPerSec(100); |
| 42 | + const DataRate kHighRate = DataRate::KilobitsPerSec(2500); |
| 43 | + |
| 44 | + VideoStreamConfig video_config; |
| 45 | + video_config.encoder.codec = |
| 46 | + VideoStreamConfig::Encoder::Codec::kVideoCodecVP8; |
| 47 | + CallClientConfig send_call_config; |
| 48 | + send_call_config.transport.rates.start_rate = kStartRate; |
| 49 | + send_call_config.transport.rates.max_rate = kHighRate * 2; |
| 50 | + auto* caller = s.CreateClient("caller", send_call_config); |
| 51 | + auto* callee = s.CreateClient("callee", CallClientConfig()); |
| 52 | + auto route = s.CreateRoutes( |
| 53 | + caller, {s.CreateSimulationNode(NetworkSimulationConfig())}, callee, |
| 54 | + {s.CreateSimulationNode(NetworkSimulationConfig())}); |
| 55 | + s.CreateVideoStream(route->forward(), video_config); |
| 56 | + |
| 57 | + // Wait until initial probing rampup is done and then set a low max bitrate. |
| 58 | + s.RunFor(TimeDelta::Seconds(1)); |
| 59 | + EXPECT_GE(DataRate::BitsPerSec(caller->GetStats().send_bandwidth_bps), |
| 60 | + 5 * send_call_config.transport.rates.start_rate); |
| 61 | + BitrateConstraints bitrate_config; |
| 62 | + bitrate_config.max_bitrate_bps = kConstrainedRate.bps(); |
| 63 | + caller->UpdateBitrateConstraints(bitrate_config); |
| 64 | + |
| 65 | + // Wait until the low send bitrate has taken effect, and then set a much |
| 66 | + // higher max bitrate. |
| 67 | + s.RunFor(TimeDelta::Seconds(2)); |
| 68 | + EXPECT_LT(DataRate::BitsPerSec(caller->GetStats().send_bandwidth_bps), |
| 69 | + kConstrainedRate * 1.1); |
| 70 | + bitrate_config.max_bitrate_bps = 2 * kHighRate.bps(); |
| 71 | + caller->UpdateBitrateConstraints(bitrate_config); |
| 72 | + |
| 73 | + // Check that the max send bitrate is reached quicker than would be possible |
| 74 | + // with simple AIMD rate control. |
| 75 | + s.RunFor(TimeDelta::Seconds(1)); |
| 76 | + EXPECT_GE(DataRate::BitsPerSec(caller->GetStats().send_bandwidth_bps), |
| 77 | + kHighRate); |
| 78 | +} |
| 79 | + |
| 80 | +TEST(ProbingTest, ProbesRampsUpWhenVideoEncoderConfigChanges) { |
| 81 | + Scenario s; |
| 82 | + const DataRate kStartRate = DataRate::KilobitsPerSec(50); |
| 83 | + const DataRate kHdRate = DataRate::KilobitsPerSec(3250); |
| 84 | + |
| 85 | + // Set up 3-layer simulcast. |
| 86 | + VideoStreamConfig video_config; |
| 87 | + video_config.encoder.codec = |
| 88 | + VideoStreamConfig::Encoder::Codec::kVideoCodecVP8; |
| 89 | + video_config.encoder.layers.spatial = 3; |
| 90 | + video_config.source.generator.width = 1280; |
| 91 | + video_config.source.generator.height = 720; |
| 92 | + |
| 93 | + CallClientConfig send_call_config; |
| 94 | + send_call_config.transport.rates.start_rate = kStartRate; |
| 95 | + send_call_config.transport.rates.max_rate = kHdRate * 2; |
| 96 | + auto* caller = s.CreateClient("caller", send_call_config); |
| 97 | + auto* callee = s.CreateClient("callee", CallClientConfig()); |
| 98 | + auto send_net = |
| 99 | + s.CreateMutableSimulationNode([&](NetworkSimulationConfig* c) { |
| 100 | + c->bandwidth = DataRate::KilobitsPerSec(200); |
| 101 | + }); |
| 102 | + auto route = |
| 103 | + s.CreateRoutes(caller, {send_net->node()}, callee, |
| 104 | + {s.CreateSimulationNode(NetworkSimulationConfig())}); |
| 105 | + auto* video_stream = s.CreateVideoStream(route->forward(), video_config); |
| 106 | + |
| 107 | + // Only QVGA enabled initially. Run until initial probing is done and BWE |
| 108 | + // has settled. |
| 109 | + video_stream->send()->UpdateActiveLayers({true, false, false}); |
| 110 | + s.RunFor(TimeDelta::Seconds(2)); |
| 111 | + |
| 112 | + // Remove network constraints and run for a while more, BWE should be much |
| 113 | + // less than required HD rate. |
| 114 | + send_net->UpdateConfig([&](NetworkSimulationConfig* c) { |
| 115 | + c->bandwidth = DataRate::PlusInfinity(); |
| 116 | + }); |
| 117 | + s.RunFor(TimeDelta::Seconds(2)); |
| 118 | + |
| 119 | + DataRate bandwidth = |
| 120 | + DataRate::BitsPerSec(caller->GetStats().send_bandwidth_bps); |
| 121 | + EXPECT_LT(bandwidth, kHdRate / 4); |
| 122 | + |
| 123 | + // Enable all layers, triggering a probe. |
| 124 | + video_stream->send()->UpdateActiveLayers({true, true, true}); |
| 125 | + |
| 126 | + // Run for a short while and verify BWE has ramped up fast. |
| 127 | + s.RunFor(TimeDelta::Seconds(2)); |
| 128 | + EXPECT_GT(DataRate::BitsPerSec(caller->GetStats().send_bandwidth_bps), |
| 129 | + kHdRate); |
| 130 | +} |
| 131 | + |
| 132 | +} // namespace test |
| 133 | +} // namespace webrtc |
0 commit comments