pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | #include <functional> |
| 11 | #include <list> |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 12 | #include <memory> |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "call/call.h" |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 16 | #include "call/fake_network_pipe.h" |
| 17 | #include "call/simulated_network.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
| 19 | #include "rtc_base/event.h" |
| 20 | #include "rtc_base/logging.h" |
Danil Chapovalov | 82a3f0a | 2019-10-21 09:24:27 +0200 | [diff] [blame] | 21 | #include "rtc_base/task_queue_for_test.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "rtc_base/thread_annotations.h" |
| 23 | #include "test/call_test.h" |
| 24 | #include "test/direct_transport.h" |
| 25 | #include "test/encoder_settings.h" |
| 26 | #include "test/fake_decoder.h" |
| 27 | #include "test/fake_encoder.h" |
| 28 | #include "test/frame_generator_capturer.h" |
| 29 | #include "test/gtest.h" |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 30 | |
| 31 | namespace webrtc { |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 32 | namespace { |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 33 | // Note: If you consider to re-use this class, think twice and instead consider |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 34 | // writing tests that don't depend on the logging system. |
| 35 | class LogObserver { |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 36 | public: |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 37 | LogObserver() { rtc::LogMessage::AddLogToStream(&callback_, rtc::LS_INFO); } |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 38 | |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 39 | ~LogObserver() { rtc::LogMessage::RemoveLogToStream(&callback_); } |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 40 | |
| 41 | void PushExpectedLogLine(const std::string& expected_log_line) { |
| 42 | callback_.PushExpectedLogLine(expected_log_line); |
| 43 | } |
| 44 | |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 45 | bool Wait() { return callback_.Wait(); } |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 46 | |
| 47 | private: |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 48 | class Callback : public rtc::LogSink { |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 49 | public: |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 50 | void OnLogMessage(const std::string& message) override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 51 | rtc::CritScope lock(&crit_sect_); |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 52 | // Ignore log lines that are due to missing AST extensions, these are |
| 53 | // logged when we switch back from AST to TOF until the wrapping bitrate |
| 54 | // estimator gives up on using AST. |
| 55 | if (message.find("BitrateEstimator") != std::string::npos && |
| 56 | message.find("packet is missing") == std::string::npos) { |
| 57 | received_log_lines_.push_back(message); |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 58 | } |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 59 | |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 60 | int num_popped = 0; |
| 61 | while (!received_log_lines_.empty() && !expected_log_lines_.empty()) { |
| 62 | std::string a = received_log_lines_.front(); |
| 63 | std::string b = expected_log_lines_.front(); |
| 64 | received_log_lines_.pop_front(); |
| 65 | expected_log_lines_.pop_front(); |
| 66 | num_popped++; |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 67 | EXPECT_TRUE(a.find(b) != std::string::npos) << a << " != " << b; |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 68 | } |
Benjamin Wright | 41f9f2c | 2019-03-13 18:03:29 -0700 | [diff] [blame] | 69 | if (expected_log_lines_.empty()) { |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 70 | if (num_popped > 0) { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 71 | done_.Set(); |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 72 | } |
| 73 | return; |
| 74 | } |
| 75 | } |
| 76 | |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 77 | bool Wait() { return done_.Wait(test::CallTest::kDefaultTimeoutMs); } |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 78 | |
| 79 | void PushExpectedLogLine(const std::string& expected_log_line) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 80 | rtc::CritScope lock(&crit_sect_); |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 81 | expected_log_lines_.push_back(expected_log_line); |
| 82 | } |
| 83 | |
| 84 | private: |
| 85 | typedef std::list<std::string> Strings; |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 86 | rtc::CriticalSection crit_sect_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 87 | Strings received_log_lines_ RTC_GUARDED_BY(crit_sect_); |
| 88 | Strings expected_log_lines_ RTC_GUARDED_BY(crit_sect_); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 89 | rtc::Event done_; |
andresp@webrtc.org | b941fe8 | 2014-07-07 08:50:48 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | Callback callback_; |
| 93 | }; |
| 94 | } // namespace |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 95 | |
| 96 | static const int kTOFExtensionId = 4; |
| 97 | static const int kASTExtensionId = 5; |
| 98 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 99 | class BitrateEstimatorTest : public test::CallTest { |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 100 | public: |
aleloi | 5d78e8d | 2016-11-08 03:44:54 -0800 | [diff] [blame] | 101 | BitrateEstimatorTest() : receive_config_(nullptr) {} |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 102 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 103 | virtual ~BitrateEstimatorTest() { EXPECT_TRUE(streams_.empty()); } |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 104 | |
| 105 | virtual void SetUp() { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 106 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 107 | CreateCalls(); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 108 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 109 | send_transport_.reset(new test::DirectTransport( |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 110 | task_queue(), |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 111 | std::make_unique<FakeNetworkPipe>( |
| 112 | Clock::GetRealTimeClock(), std::make_unique<SimulatedNetwork>( |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 113 | BuiltInNetworkBehaviorConfig())), |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 114 | sender_call_.get(), payload_type_map_)); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 115 | send_transport_->SetReceiver(receiver_call_->Receiver()); |
| 116 | receive_transport_.reset(new test::DirectTransport( |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 117 | task_queue(), |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 118 | std::make_unique<FakeNetworkPipe>( |
| 119 | Clock::GetRealTimeClock(), std::make_unique<SimulatedNetwork>( |
Artem Titov | 75e3647 | 2018-10-08 12:28:56 +0200 | [diff] [blame] | 120 | BuiltInNetworkBehaviorConfig())), |
Artem Titov | dd2eebe | 2018-08-20 13:27:45 +0200 | [diff] [blame] | 121 | receiver_call_.get(), payload_type_map_)); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 122 | receive_transport_->SetReceiver(sender_call_->Receiver()); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 123 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 124 | VideoSendStream::Config video_send_config(send_transport_.get()); |
| 125 | video_send_config.rtp.ssrcs.push_back(kVideoSendSsrcs[0]); |
| 126 | video_send_config.encoder_settings.encoder_factory = |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 127 | &fake_encoder_factory_; |
Jiawei Ou | c2ebe21 | 2018-11-08 10:02:56 -0800 | [diff] [blame] | 128 | video_send_config.encoder_settings.bitrate_allocator_factory = |
| 129 | bitrate_allocator_factory_.get(); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 130 | video_send_config.rtp.payload_name = "FAKE"; |
| 131 | video_send_config.rtp.payload_type = kFakeVideoSendPayloadType; |
| 132 | SetVideoSendConfig(video_send_config); |
| 133 | VideoEncoderConfig video_encoder_config; |
| 134 | test::FillEncoderConfiguration(kVideoCodecVP8, 1, &video_encoder_config); |
| 135 | SetVideoEncoderConfig(video_encoder_config); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 136 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 137 | receive_config_ = VideoReceiveStream::Config(receive_transport_.get()); |
| 138 | // receive_config_.decoders will be set by every stream separately. |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 139 | receive_config_.rtp.remote_ssrc = GetVideoSendConfig()->rtp.ssrcs[0]; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 140 | receive_config_.rtp.local_ssrc = kReceiverLocalVideoSsrc; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 141 | receive_config_.rtp.extensions.push_back( |
| 142 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId)); |
| 143 | receive_config_.rtp.extensions.push_back( |
| 144 | RtpExtension(RtpExtension::kAbsSendTimeUri, kASTExtensionId)); |
| 145 | }); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | virtual void TearDown() { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 149 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Yusuke Suzuki | f8d8d6d | 2018-05-17 22:01:13 +0900 | [diff] [blame] | 150 | for (auto* stream : streams_) { |
| 151 | stream->StopSending(); |
| 152 | delete stream; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 153 | } |
Yusuke Suzuki | f8d8d6d | 2018-05-17 22:01:13 +0900 | [diff] [blame] | 154 | streams_.clear(); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 155 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 156 | send_transport_.reset(); |
| 157 | receive_transport_.reset(); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 158 | |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 159 | DestroyCalls(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 160 | }); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | protected: |
| 164 | friend class Stream; |
| 165 | |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 166 | class Stream { |
| 167 | public: |
aleloi | 5d78e8d | 2016-11-08 03:44:54 -0800 | [diff] [blame] | 168 | explicit Stream(BitrateEstimatorTest* test) |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 169 | : test_(test), |
| 170 | is_sending_receiving_(false), |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 171 | send_stream_(nullptr), |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 172 | frame_generator_capturer_(), |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 173 | decoder_factory_( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 174 | []() { return std::make_unique<test::FakeDecoder>(); }) { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 175 | test_->GetVideoSendConfig()->rtp.ssrcs[0]++; |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 176 | send_stream_ = test_->sender_call_->CreateVideoSendStream( |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 177 | test_->GetVideoSendConfig()->Copy(), |
| 178 | test_->GetVideoEncoderConfig()->Copy()); |
| 179 | RTC_DCHECK_EQ(1, test_->GetVideoEncoderConfig()->number_of_streams); |
Danil Chapovalov | 81687b3 | 2019-04-18 15:39:53 +0200 | [diff] [blame] | 180 | frame_generator_capturer_ = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 181 | std::make_unique<test::FrameGeneratorCapturer>( |
Danil Chapovalov | 81687b3 | 2019-04-18 15:39:53 +0200 | [diff] [blame] | 182 | test->clock_, |
| 183 | test::FrameGenerator::CreateSquareGenerator( |
| 184 | kDefaultWidth, kDefaultHeight, absl::nullopt, absl::nullopt), |
| 185 | kDefaultFramerate, *test->task_queue_factory_); |
| 186 | frame_generator_capturer_->Init(); |
Taylor Brandstetter | 49fcc10 | 2018-05-16 14:20:41 -0700 | [diff] [blame] | 187 | send_stream_->SetSource(frame_generator_capturer_.get(), |
| 188 | DegradationPreference::MAINTAIN_FRAMERATE); |
pbos@webrtc.org | a5c8d2c | 2014-04-24 11:13:21 +0000 | [diff] [blame] | 189 | send_stream_->Start(); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 190 | |
aleloi | 5d78e8d | 2016-11-08 03:44:54 -0800 | [diff] [blame] | 191 | VideoReceiveStream::Decoder decoder; |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 192 | decoder.decoder_factory = &decoder_factory_; |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 193 | decoder.payload_type = test_->GetVideoSendConfig()->rtp.payload_type; |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 194 | decoder.video_format = |
| 195 | SdpVideoFormat(test_->GetVideoSendConfig()->rtp.payload_name); |
aleloi | 5d78e8d | 2016-11-08 03:44:54 -0800 | [diff] [blame] | 196 | test_->receive_config_.decoders.clear(); |
| 197 | test_->receive_config_.decoders.push_back(decoder); |
| 198 | test_->receive_config_.rtp.remote_ssrc = |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 199 | test_->GetVideoSendConfig()->rtp.ssrcs[0]; |
aleloi | 5d78e8d | 2016-11-08 03:44:54 -0800 | [diff] [blame] | 200 | test_->receive_config_.rtp.local_ssrc++; |
| 201 | test_->receive_config_.renderer = &test->fake_renderer_; |
| 202 | video_receive_stream_ = test_->receiver_call_->CreateVideoReceiveStream( |
| 203 | test_->receive_config_.Copy()); |
| 204 | video_receive_stream_->Start(); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 205 | is_sending_receiving_ = true; |
| 206 | } |
| 207 | |
| 208 | ~Stream() { |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 209 | EXPECT_FALSE(is_sending_receiving_); |
perkj | 9fdbda6 | 2016-09-15 09:19:20 -0700 | [diff] [blame] | 210 | test_->sender_call_->DestroyVideoSendStream(send_stream_); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 211 | frame_generator_capturer_.reset(nullptr); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 212 | send_stream_ = nullptr; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 213 | if (video_receive_stream_) { |
| 214 | test_->receiver_call_->DestroyVideoReceiveStream(video_receive_stream_); |
| 215 | video_receive_stream_ = nullptr; |
| 216 | } |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void StopSending() { |
| 220 | if (is_sending_receiving_) { |
pbos@webrtc.org | a5c8d2c | 2014-04-24 11:13:21 +0000 | [diff] [blame] | 221 | send_stream_->Stop(); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 222 | if (video_receive_stream_) { |
| 223 | video_receive_stream_->Stop(); |
| 224 | } |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 225 | is_sending_receiving_ = false; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | private: |
| 230 | BitrateEstimatorTest* test_; |
| 231 | bool is_sending_receiving_; |
| 232 | VideoSendStream* send_stream_; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 233 | VideoReceiveStream* video_receive_stream_; |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 234 | std::unique_ptr<test::FrameGeneratorCapturer> frame_generator_capturer_; |
Niels Möller | cbcbc22 | 2018-09-28 09:07:24 +0200 | [diff] [blame] | 235 | |
| 236 | test::FunctionVideoDecoderFactory decoder_factory_; |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
Peter Boström | 7c704b8 | 2015-12-04 16:13:05 +0100 | [diff] [blame] | 239 | LogObserver receiver_log_; |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 240 | std::unique_ptr<test::DirectTransport> send_transport_; |
| 241 | std::unique_ptr<test::DirectTransport> receive_transport_; |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 242 | VideoReceiveStream::Config receive_config_; |
| 243 | std::vector<Stream*> streams_; |
| 244 | }; |
| 245 | |
Erik Språng | 468e62a | 2015-07-06 10:50:47 +0200 | [diff] [blame] | 246 | static const char* kAbsSendTimeLog = |
| 247 | "RemoteBitrateEstimatorAbsSendTime: Instantiating."; |
| 248 | static const char* kSingleStreamLog = |
| 249 | "RemoteBitrateEstimatorSingleStream: Instantiating."; |
| 250 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 251 | TEST_F(BitrateEstimatorTest, InstantiatesTOFPerDefaultForVideo) { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 252 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 253 | GetVideoSendConfig()->rtp.extensions.push_back( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 254 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId)); |
| 255 | receiver_log_.PushExpectedLogLine(kSingleStreamLog); |
| 256 | receiver_log_.PushExpectedLogLine(kSingleStreamLog); |
| 257 | streams_.push_back(new Stream(this)); |
| 258 | }); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 259 | EXPECT_TRUE(receiver_log_.Wait()); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 262 | TEST_F(BitrateEstimatorTest, ImmediatelySwitchToASTForVideo) { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 263 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 264 | GetVideoSendConfig()->rtp.extensions.push_back( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 265 | RtpExtension(RtpExtension::kAbsSendTimeUri, kASTExtensionId)); |
| 266 | receiver_log_.PushExpectedLogLine(kSingleStreamLog); |
| 267 | receiver_log_.PushExpectedLogLine(kSingleStreamLog); |
| 268 | receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE."); |
| 269 | receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); |
| 270 | streams_.push_back(new Stream(this)); |
| 271 | }); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 272 | EXPECT_TRUE(receiver_log_.Wait()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 275 | TEST_F(BitrateEstimatorTest, SwitchesToASTForVideo) { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 276 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 277 | GetVideoSendConfig()->rtp.extensions.push_back( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 278 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId)); |
| 279 | receiver_log_.PushExpectedLogLine(kSingleStreamLog); |
| 280 | receiver_log_.PushExpectedLogLine(kSingleStreamLog); |
| 281 | streams_.push_back(new Stream(this)); |
| 282 | }); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 283 | EXPECT_TRUE(receiver_log_.Wait()); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 284 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 285 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 286 | GetVideoSendConfig()->rtp.extensions[0] = |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 287 | RtpExtension(RtpExtension::kAbsSendTimeUri, kASTExtensionId); |
| 288 | receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE."); |
| 289 | receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); |
| 290 | streams_.push_back(new Stream(this)); |
| 291 | }); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 292 | EXPECT_TRUE(receiver_log_.Wait()); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 293 | } |
| 294 | |
deadbeef | 1086ed6 | 2016-04-22 10:52:40 -0700 | [diff] [blame] | 295 | // This test is flaky. See webrtc:5790. |
| 296 | TEST_F(BitrateEstimatorTest, DISABLED_SwitchesToASTThenBackToTOFForVideo) { |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 297 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 298 | GetVideoSendConfig()->rtp.extensions.push_back( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 299 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId)); |
| 300 | receiver_log_.PushExpectedLogLine(kSingleStreamLog); |
| 301 | receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); |
| 302 | receiver_log_.PushExpectedLogLine(kSingleStreamLog); |
| 303 | streams_.push_back(new Stream(this)); |
| 304 | }); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 305 | EXPECT_TRUE(receiver_log_.Wait()); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 306 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 307 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 308 | GetVideoSendConfig()->rtp.extensions[0] = |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 309 | RtpExtension(RtpExtension::kAbsSendTimeUri, kASTExtensionId); |
| 310 | receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); |
| 311 | receiver_log_.PushExpectedLogLine("Switching to absolute send time RBE."); |
| 312 | streams_.push_back(new Stream(this)); |
| 313 | }); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 314 | EXPECT_TRUE(receiver_log_.Wait()); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 315 | |
Danil Chapovalov | d15a028 | 2019-10-22 10:48:17 +0200 | [diff] [blame] | 316 | SendTask(RTC_FROM_HERE, task_queue(), [this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 317 | GetVideoSendConfig()->rtp.extensions[0] = |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 318 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOFExtensionId); |
| 319 | receiver_log_.PushExpectedLogLine(kAbsSendTimeLog); |
| 320 | receiver_log_.PushExpectedLogLine( |
| 321 | "WrappingBitrateEstimator: Switching to transmission time offset RBE."); |
| 322 | streams_.push_back(new Stream(this)); |
| 323 | streams_[0]->StopSending(); |
| 324 | streams_[1]->StopSending(); |
| 325 | }); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 326 | EXPECT_TRUE(receiver_log_.Wait()); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 327 | } |
| 328 | } // namespace webrtc |