From 49a78430303fa8b0441a3cc0fd73b68bb3cb4a4c Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Tue, 20 Nov 2018 16:15:29 +0100 Subject: [PATCH] Don't restart streams in scenario tests. This CL changes the behavior for RunFor and RunUntil so they do not anymore restart the underlying streams every time they are called. This has a side effect on the semantics of the calls. Previously, both RunUntil and RunFor would restart the session and run until the given time had passed. Now RunFor will still run for the provided duration, however, to make the name of RunUntil more correct, it will run until the time since start is equal to the max_duration parameter. An extra overload of RunUntil was added to allow using this behavior without providing an ending condition. Bug: webrtc:9510 Change-Id: I9fe56a44116907fba3d102894b5c96af2ba6cffb Reviewed-on: https://webrtc-review.googlesource.com/c/111502 Reviewed-by: Christoffer Rodbro Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#25726} --- test/scenario/audio_stream.cc | 6 ++++ test/scenario/audio_stream.h | 1 + test/scenario/scenario.cc | 62 +++++++++++++++++++++-------------- test/scenario/scenario.h | 3 ++ test/scenario/video_stream.cc | 6 ++++ test/scenario/video_stream.h | 1 + 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/test/scenario/audio_stream.cc b/test/scenario/audio_stream.cc index 076b4eaf86..8359bd09ec 100644 --- a/test/scenario/audio_stream.cc +++ b/test/scenario/audio_stream.cc @@ -152,6 +152,7 @@ SendAudioStream::~SendAudioStream() { void SendAudioStream::Start() { send_stream_->Start(); + sender_->call_->SignalChannelNetworkState(MediaType::AUDIO, kNetworkUp); } ColumnPrinter SendAudioStream::StatsPrinter() { @@ -192,6 +193,11 @@ ReceiveAudioStream::~ReceiveAudioStream() { receiver_->call_->DestroyAudioReceiveStream(receive_stream_); } +void ReceiveAudioStream::Start() { + receive_stream_->Start(); + receiver_->call_->SignalChannelNetworkState(MediaType::AUDIO, kNetworkUp); +} + AudioStreamPair::~AudioStreamPair() = default; AudioStreamPair::AudioStreamPair( diff --git a/test/scenario/audio_stream.h b/test/scenario/audio_stream.h index 601a375a26..3ab0a1f2de 100644 --- a/test/scenario/audio_stream.h +++ b/test/scenario/audio_stream.h @@ -50,6 +50,7 @@ class ReceiveAudioStream { public: RTC_DISALLOW_COPY_AND_ASSIGN(ReceiveAudioStream); ~ReceiveAudioStream(); + void Start(); private: friend class Scenario; diff --git a/test/scenario/scenario.cc b/test/scenario/scenario.cc index 9dcdcbef4b..7589878d5b 100644 --- a/test/scenario/scenario.cc +++ b/test/scenario/scenario.cc @@ -75,6 +75,8 @@ Scenario::Scenario(std::string file_name, bool real_time) } Scenario::~Scenario() { + if (start_time_.IsFinite()) + Stop(); if (!real_time_mode_) rtc::SetClockForTesting(nullptr); } @@ -305,35 +307,18 @@ void Scenario::At(TimeDelta offset, std::function function) { } void Scenario::RunFor(TimeDelta duration) { - RunUntil(duration, TimeDelta::PlusInfinity(), []() { return false; }); + RunUntil(Duration() + duration); +} + +void Scenario::RunUntil(TimeDelta max_duration) { + RunUntil(max_duration, TimeDelta::PlusInfinity(), []() { return false; }); } void Scenario::RunUntil(TimeDelta max_duration, TimeDelta poll_interval, std::function exit_function) { - start_time_ = Timestamp::us(clock_->TimeInMicroseconds()); - for (auto& activity : repeated_activities_) { - activity->SetStartTime(start_time_); - } - - for (auto& stream_pair : video_streams_) - stream_pair->receive()->receive_stream_->Start(); - for (auto& stream_pair : audio_streams_) - stream_pair->receive()->receive_stream_->Start(); - for (auto& stream_pair : video_streams_) { - if (stream_pair->config_.autostart) { - stream_pair->send()->Start(); - } - } - for (auto& stream_pair : audio_streams_) { - if (stream_pair->config_.autostart) { - stream_pair->send()->Start(); - } - } - for (auto& call : clients_) { - call->call_->SignalChannelNetworkState(MediaType::AUDIO, kNetworkUp); - call->call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp); - } + if (start_time_.IsInfinite()) + Start(); rtc::Event done_; while (!exit_function() && Duration() < max_duration) { @@ -363,6 +348,32 @@ void Scenario::RunUntil(TimeDelta max_duration, 1000); } } +} + +void Scenario::Start() { + start_time_ = Timestamp::us(clock_->TimeInMicroseconds()); + for (auto& activity : repeated_activities_) { + activity->SetStartTime(start_time_); + } + + for (auto& stream_pair : video_streams_) + stream_pair->receive()->Start(); + for (auto& stream_pair : audio_streams_) + stream_pair->receive()->Start(); + for (auto& stream_pair : video_streams_) { + if (stream_pair->config_.autostart) { + stream_pair->send()->Start(); + } + } + for (auto& stream_pair : audio_streams_) { + if (stream_pair->config_.autostart) { + stream_pair->send()->Start(); + } + } +} + +void Scenario::Stop() { + RTC_DCHECK(start_time_.IsFinite()); for (auto& stream_pair : video_streams_) { stream_pair->send()->video_capturer_->Stop(); stream_pair->send()->send_stream_->Stop(); @@ -373,6 +384,7 @@ void Scenario::RunUntil(TimeDelta max_duration, stream_pair->receive()->receive_stream_->Stop(); for (auto& stream_pair : audio_streams_) stream_pair->receive()->receive_stream_->Stop(); + start_time_ = Timestamp::PlusInfinity(); } Timestamp Scenario::Now() { @@ -380,6 +392,8 @@ Timestamp Scenario::Now() { } TimeDelta Scenario::Duration() { + if (start_time_.IsInfinite()) + return TimeDelta::Zero(); return Now() - start_time_; } diff --git a/test/scenario/scenario.h b/test/scenario/scenario.h index 5ee017c806..38bef442ec 100644 --- a/test/scenario/scenario.h +++ b/test/scenario/scenario.h @@ -140,9 +140,12 @@ class Scenario { // Runs the scenario for the given time or until the exit function returns // true. void RunFor(TimeDelta duration); + void RunUntil(TimeDelta max_duration); void RunUntil(TimeDelta max_duration, TimeDelta probe_interval, std::function exit_function); + void Start(); + void Stop(); // Triggers sending of dummy packets over the given nodes. void TriggerPacketBurst(std::vector over_nodes, diff --git a/test/scenario/video_stream.cc b/test/scenario/video_stream.cc index 528a9cc2c5..36399234ad 100644 --- a/test/scenario/video_stream.cc +++ b/test/scenario/video_stream.cc @@ -256,6 +256,7 @@ SendVideoStream::~SendVideoStream() { void SendVideoStream::Start() { send_stream_->Start(); video_capturer_->Start(); + sender_->call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp); } void SendVideoStream::UpdateConfig( @@ -375,6 +376,11 @@ ReceiveVideoStream::~ReceiveVideoStream() { receiver_->call_->DestroyFlexfecReceiveStream(flecfec_stream_); } +void ReceiveVideoStream::Start() { + receive_stream_->Start(); + receiver_->call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp); +} + VideoStreamPair::~VideoStreamPair() = default; VideoStreamPair::VideoStreamPair(CallClient* sender, diff --git a/test/scenario/video_stream.h b/test/scenario/video_stream.h index a68dbf6c8a..ebf9c951b7 100644 --- a/test/scenario/video_stream.h +++ b/test/scenario/video_stream.h @@ -65,6 +65,7 @@ class ReceiveVideoStream { public: RTC_DISALLOW_COPY_AND_ASSIGN(ReceiveVideoStream); ~ReceiveVideoStream(); + void Start(); private: friend class Scenario;