blob: 4a4b7f638d5c45ac046721e2c0747e68ccd575b5 [file] [log] [blame]
Sebastian Jansson98b07e92018-09-27 13:47:01 +02001/*
2 * Copyright 2018 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 */
Sebastian Jansson105a10a2019-04-01 09:18:14 +020010#include <atomic>
Sebastian Jansson98b07e92018-09-27 13:47:01 +020011
12#include "test/scenario/scenario.h"
13#include "test/gtest.h"
14namespace webrtc {
15namespace test {
16TEST(ScenarioTest, StartsAndStopsWithoutErrors) {
Sebastian Jansson105a10a2019-04-01 09:18:14 +020017 std::atomic<bool> packet_received(false);
18 std::atomic<bool> bitrate_changed(false);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020019 Scenario s;
20 CallClientConfig call_client_config;
21 call_client_config.transport.rates.start_rate = DataRate::kbps(300);
22 auto* alice = s.CreateClient("alice", call_client_config);
23 auto* bob = s.CreateClient("bob", call_client_config);
24 NetworkNodeConfig network_config;
25 auto alice_net = s.CreateSimulationNode(network_config);
26 auto bob_net = s.CreateSimulationNode(network_config);
Sebastian Jansson800e1212018-10-22 11:49:03 +020027 auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net});
Sebastian Jansson98b07e92018-09-27 13:47:01 +020028
29 VideoStreamConfig video_stream_config;
Sebastian Jansson800e1212018-10-22 11:49:03 +020030 s.CreateVideoStream(route->forward(), video_stream_config);
31 s.CreateVideoStream(route->reverse(), video_stream_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020032
33 AudioStreamConfig audio_stream_config;
Sebastian Jansson82858412018-10-11 19:48:05 +020034 audio_stream_config.encoder.min_rate = DataRate::kbps(6);
35 audio_stream_config.encoder.max_rate = DataRate::kbps(64);
36 audio_stream_config.encoder.allocate_bitrate = true;
37 audio_stream_config.stream.in_bandwidth_estimation = false;
Sebastian Jansson800e1212018-10-22 11:49:03 +020038 s.CreateAudioStream(route->forward(), audio_stream_config);
39 s.CreateAudioStream(route->reverse(), audio_stream_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020040
41 CrossTrafficConfig cross_traffic_config;
42 s.CreateCrossTraffic({alice_net}, cross_traffic_config);
43
Sebastian Jansson98b07e92018-09-27 13:47:01 +020044 s.NetworkDelayedAction({alice_net, bob_net}, 100,
45 [&packet_received] { packet_received = true; });
Sebastian Jansson98b07e92018-09-27 13:47:01 +020046 s.Every(TimeDelta::ms(10), [alice, bob, &bitrate_changed] {
47 if (alice->GetStats().send_bandwidth_bps != 300000 &&
48 bob->GetStats().send_bandwidth_bps != 300000)
49 bitrate_changed = true;
50 });
51 s.RunUntil(TimeDelta::seconds(2), TimeDelta::ms(5),
52 [&bitrate_changed, &packet_received] {
53 return packet_received && bitrate_changed;
54 });
55 EXPECT_TRUE(packet_received);
56 EXPECT_TRUE(bitrate_changed);
57}
58} // namespace test
59} // namespace webrtc