Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 1 | /* |
| 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 Jansson | 105a10a | 2019-04-01 09:18:14 +0200 | [diff] [blame] | 10 | #include <atomic> |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 11 | |
| 12 | #include "test/scenario/scenario.h" |
| 13 | #include "test/gtest.h" |
| 14 | namespace webrtc { |
| 15 | namespace test { |
| 16 | TEST(ScenarioTest, StartsAndStopsWithoutErrors) { |
Sebastian Jansson | 105a10a | 2019-04-01 09:18:14 +0200 | [diff] [blame] | 17 | std::atomic<bool> packet_received(false); |
| 18 | std::atomic<bool> bitrate_changed(false); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 19 | 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 Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 27 | auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net}); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 28 | |
| 29 | VideoStreamConfig video_stream_config; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 30 | s.CreateVideoStream(route->forward(), video_stream_config); |
| 31 | s.CreateVideoStream(route->reverse(), video_stream_config); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 32 | |
| 33 | AudioStreamConfig audio_stream_config; |
Sebastian Jansson | 8285841 | 2018-10-11 19:48:05 +0200 | [diff] [blame] | 34 | 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 Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 38 | s.CreateAudioStream(route->forward(), audio_stream_config); |
| 39 | s.CreateAudioStream(route->reverse(), audio_stream_config); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 40 | |
| 41 | CrossTrafficConfig cross_traffic_config; |
| 42 | s.CreateCrossTraffic({alice_net}, cross_traffic_config); |
| 43 | |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 44 | s.NetworkDelayedAction({alice_net, bob_net}, 100, |
| 45 | [&packet_received] { packet_received = true; }); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 46 | 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 |