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