blob: ea96408ac7e9c2ac34ac61c47ac15fc3fc358f09 [file] [log] [blame]
Björn Terelius987ef482020-03-05 15:52:101/*
2 * Copyright (c) 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
11#include "api/stats/rtc_stats_collector_callback.h"
12#include "api/stats/rtcstats_objects.h"
13#include "pc/test/mock_peer_connection_observers.h"
14#include "test/field_trial.h"
15#include "test/gtest.h"
16#include "test/peer_scenario/peer_scenario.h"
17#include "test/peer_scenario/peer_scenario_client.h"
18
19namespace webrtc {
20namespace test {
21
22// TODO(terelius): Use fake encoder and enable on Android once
23// https://bugs.chromium.org/p/webrtc/issues/detail?id=11408 is fixed.
24#if defined(WEBRTC_ANDROID)
25#define MAYBE_NoBweChangeFromVideoUnmute DISABLED_NoBweChangeFromVideoUnmute
26#else
27#define MAYBE_NoBweChangeFromVideoUnmute NoBweChangeFromVideoUnmute
28#endif
29TEST(GoogCcPeerScenarioTest, MAYBE_NoBweChangeFromVideoUnmute) {
30 // If transport wide sequence numbers are used for audio, and the call
31 // switches from audio only to video only, there will be a sharp change in
32 // packets sizes. This will create a change in propagation time which might be
33 // detected as an overuse. Using separate overuse detectors for audio and
34 // video avoids the issue.
Jakob Ivarsson47a03e82020-11-23 14:05:4435 std::string audio_twcc_trials("WebRTC-Audio-AlrProbing/Disabled/");
Björn Terelius987ef482020-03-05 15:52:1036 std::string separate_audio_video(
37 "WebRTC-Bwe-SeparateAudioPackets/"
38 "enabled:true,packet_threshold:15,time_threshold:1000ms/");
39 ScopedFieldTrials field_trial(audio_twcc_trials + separate_audio_video);
40 PeerScenario s(*test_info_);
41 auto* caller = s.CreateClient(PeerScenarioClient::Config());
42 auto* callee = s.CreateClient(PeerScenarioClient::Config());
43
44 BuiltInNetworkBehaviorConfig net_conf;
45 net_conf.link_capacity_kbps = 350;
46 net_conf.queue_delay_ms = 50;
47 auto send_node = s.net()->CreateEmulatedNode(net_conf);
48 auto ret_node = s.net()->CreateEmulatedNode(net_conf);
49
50 PeerScenarioClient::VideoSendTrackConfig video_conf;
51 video_conf.generator.squares_video->framerate = 15;
52 auto video = caller->CreateVideo("VIDEO", video_conf);
53 auto audio = caller->CreateAudio("AUDIO", cricket::AudioOptions());
54
55 // Start ICE and exchange SDP.
56 s.SimpleConnection(caller, callee, {send_node}, {ret_node});
57
58 // Limit the encoder bitrate to ensure that there are no actual BWE overuses.
59 ASSERT_EQ(caller->pc()->GetSenders().size(), 2u); // 2 senders.
60 int num_video_streams = 0;
61 for (auto& rtp_sender : caller->pc()->GetSenders()) {
62 auto parameters = rtp_sender->GetParameters();
63 ASSERT_EQ(parameters.encodings.size(), 1u); // 1 stream per sender.
64 for (auto& encoding_parameters : parameters.encodings) {
65 if (encoding_parameters.ssrc == video.sender->ssrc()) {
66 num_video_streams++;
67 encoding_parameters.max_bitrate_bps = 220000;
68 encoding_parameters.max_framerate = 15;
69 }
70 }
71 rtp_sender->SetParameters(parameters);
72 }
73 ASSERT_EQ(num_video_streams, 1); // Exactly 1 video stream.
74
75 auto get_bwe = [&] {
Tommi87f70902021-04-27 12:43:0876 auto callback =
77 rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>();
Niels Möllerafb246b2022-04-20 12:26:5078 caller->pc()->GetStats(callback.get());
Björn Terelius987ef482020-03-05 15:52:1079 s.net()->time_controller()->Wait([&] { return callback->called(); });
80 auto stats =
81 callback->report()->GetStatsOfType<RTCIceCandidatePairStats>()[0];
82 return DataRate::BitsPerSec(*stats->available_outgoing_bitrate);
83 };
84
85 s.ProcessMessages(TimeDelta::Seconds(15));
86 const DataRate initial_bwe = get_bwe();
87 EXPECT_GE(initial_bwe, DataRate::KilobitsPerSec(300));
88
89 // 10 seconds audio only. Bandwidth should not drop.
90 video.capturer->Stop();
91 s.ProcessMessages(TimeDelta::Seconds(10));
92 EXPECT_GE(get_bwe(), initial_bwe);
93
94 // Resume video but stop audio. Bandwidth should not drop.
95 video.capturer->Start();
Harald Alvestrand09a0d012022-01-04 19:42:0796 RTCError status = caller->pc()->RemoveTrackOrError(audio.sender);
Björn Terelius987ef482020-03-05 15:52:1097 ASSERT_TRUE(status.ok());
98 audio.track->set_enabled(false);
99 for (int i = 0; i < 10; i++) {
100 s.ProcessMessages(TimeDelta::Seconds(1));
101 EXPECT_GE(get_bwe(), initial_bwe);
102 }
Mirko Bonadei0cb1cfa2022-02-25 10:45:32103
104 caller->pc()->Close();
105 callee->pc()->Close();
Björn Terelius987ef482020-03-05 15:52:10106}
107
108} // namespace test
109} // namespace webrtc