xref: /aosp_15_r20/external/webrtc/test/scenario/probing_test.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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 
TEST(ProbingTest,InitialProbingRampsUpTargetRateWhenNetworkIsGood)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 
TEST(ProbingTest,MidCallProbingRampupTriggeredByUpdatedBitrateConstraints)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 
TEST(ProbingTest,ProbesRampsUpWhenVideoEncoderConfigChanges)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.simulcast_streams = {webrtc::ScalabilityMode::kL1T3,
90                                             webrtc::ScalabilityMode::kL1T3,
91                                             webrtc::ScalabilityMode::kL1T3};
92   video_config.source.generator.width = 1280;
93   video_config.source.generator.height = 720;
94 
95   CallClientConfig send_call_config;
96   send_call_config.transport.rates.start_rate = kStartRate;
97   send_call_config.transport.rates.max_rate = kHdRate * 2;
98   auto* caller = s.CreateClient("caller", send_call_config);
99   auto* callee = s.CreateClient("callee", CallClientConfig());
100   auto send_net =
101       s.CreateMutableSimulationNode([&](NetworkSimulationConfig* c) {
102         c->bandwidth = DataRate::KilobitsPerSec(200);
103       });
104   auto route =
105       s.CreateRoutes(caller, {send_net->node()}, callee,
106                      {s.CreateSimulationNode(NetworkSimulationConfig())});
107   auto* video_stream = s.CreateVideoStream(route->forward(), video_config);
108 
109   // Only QVGA enabled initially. Run until initial probing is done and BWE
110   // has settled.
111   video_stream->send()->UpdateActiveLayers({true, false, false});
112   s.RunFor(TimeDelta::Seconds(2));
113 
114   // Remove network constraints and run for a while more, BWE should be much
115   // less than required HD rate.
116   send_net->UpdateConfig([&](NetworkSimulationConfig* c) {
117     c->bandwidth = DataRate::PlusInfinity();
118   });
119   s.RunFor(TimeDelta::Seconds(2));
120 
121   DataRate bandwidth =
122       DataRate::BitsPerSec(caller->GetStats().send_bandwidth_bps);
123   EXPECT_LT(bandwidth, kHdRate / 4);
124 
125   // Enable all layers, triggering a probe.
126   video_stream->send()->UpdateActiveLayers({true, true, true});
127 
128   // Run for a short while and verify BWE has ramped up fast.
129   s.RunFor(TimeDelta::Seconds(2));
130   EXPECT_GT(DataRate::BitsPerSec(caller->GetStats().send_bandwidth_bps),
131             kHdRate);
132 }
133 
134 }  // namespace test
135 }  // namespace webrtc
136