blob: 79f1ff69473846f09d355b2a5e85b62377feae98 [file] [log] [blame]
pbos@webrtc.org1d096902013-12-13 12:48:05 +00001/*
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 */
pbos@webrtc.org1d096902013-12-13 12:48:05 +000010#include <algorithm>
11#include <sstream>
12#include <string>
13
14#include "testing/gtest/include/gtest/gtest.h"
15
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000016#include "webrtc/base/checks.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000017#include "webrtc/base/scoped_ptr.h"
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000018#include "webrtc/base/thread_annotations.h"
pbos@webrtc.org1d096902013-12-13 12:48:05 +000019#include "webrtc/call.h"
Peter Boström5c389d32015-09-25 13:58:30 +020020#include "webrtc/call/transport_adapter.h"
Stefan Holmerb86d4e42015-12-07 10:26:18 +010021#include "webrtc/common.h"
22#include "webrtc/config.h"
kjellander3e6db232015-11-26 04:44:54 -080023#include "webrtc/modules/audio_coding/include/audio_coding_module.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010024#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
pbos@webrtc.org1d096902013-12-13 12:48:05 +000025#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010026#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
27#include "webrtc/system_wrappers/include/rtp_to_ntp.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000028#include "webrtc/test/call_test.h"
pbos@webrtc.org1d096902013-12-13 12:48:05 +000029#include "webrtc/test/direct_transport.h"
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000030#include "webrtc/test/encoder_settings.h"
pbos@webrtc.org1d096902013-12-13 12:48:05 +000031#include "webrtc/test/fake_audio_device.h"
32#include "webrtc/test/fake_decoder.h"
33#include "webrtc/test/fake_encoder.h"
34#include "webrtc/test/frame_generator.h"
35#include "webrtc/test/frame_generator_capturer.h"
36#include "webrtc/test/rtp_rtcp_observer.h"
37#include "webrtc/test/testsupport/fileutils.h"
38#include "webrtc/test/testsupport/perf_test.h"
pbos@webrtc.org1d096902013-12-13 12:48:05 +000039#include "webrtc/voice_engine/include/voe_base.h"
40#include "webrtc/voice_engine/include/voe_codec.h"
41#include "webrtc/voice_engine/include/voe_network.h"
42#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
43#include "webrtc/voice_engine/include/voe_video_sync.h"
44
45namespace webrtc {
46
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000047class CallPerfTest : public test::CallTest {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000048 protected:
pbos8fc7fa72015-07-15 08:02:58 -070049 void TestAudioVideoSync(bool fec, bool create_audio_first);
stefan@webrtc.org01581da2014-09-04 06:48:14 +000050
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +000051 void TestCpuOveruse(LoadObserver::Load tested_load, int encode_delay_ms);
52
pbos@webrtc.org3349ae02014-03-13 12:52:27 +000053 void TestMinTransmitBitrate(bool pad_to_min_bitrate);
54
wu@webrtc.orgcd701192014-04-24 22:10:24 +000055 void TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config,
56 int threshold_ms,
57 int start_time_ms,
58 int run_time_ms);
pbos@webrtc.org1d096902013-12-13 12:48:05 +000059};
60
61class SyncRtcpObserver : public test::RtpRtcpObserver {
62 public:
stefanf116bd02015-10-27 08:29:42 -070063 SyncRtcpObserver() : test::RtpRtcpObserver(CallPerfTest::kLongTimeoutMs) {}
pbos@webrtc.org1d096902013-12-13 12:48:05 +000064
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000065 Action OnSendRtcp(const uint8_t* packet, size_t length) override {
pbos@webrtc.org1d096902013-12-13 12:48:05 +000066 RTCPUtility::RTCPParserV2 parser(packet, length, true);
67 EXPECT_TRUE(parser.IsValid());
68
69 for (RTCPUtility::RTCPPacketTypes packet_type = parser.Begin();
Erik Språng242e22b2015-05-11 10:17:43 +020070 packet_type != RTCPUtility::RTCPPacketTypes::kInvalid;
pbos@webrtc.org1d096902013-12-13 12:48:05 +000071 packet_type = parser.Iterate()) {
Erik Språng242e22b2015-05-11 10:17:43 +020072 if (packet_type == RTCPUtility::RTCPPacketTypes::kSr) {
pbos@webrtc.org1d096902013-12-13 12:48:05 +000073 const RTCPUtility::RTCPPacket& packet = parser.Packet();
wu@webrtc.org66773a02014-05-07 17:09:44 +000074 RtcpMeasurement ntp_rtp_pair(
pbos@webrtc.org1d096902013-12-13 12:48:05 +000075 packet.SR.NTPMostSignificant,
76 packet.SR.NTPLeastSignificant,
77 packet.SR.RTPTimestamp);
78 StoreNtpRtpPair(ntp_rtp_pair);
79 }
80 }
81 return SEND_PACKET;
82 }
83
84 int64_t RtpTimestampToNtp(uint32_t timestamp) const {
Peter Boströmf2f82832015-05-01 13:00:41 +020085 rtc::CritScope lock(&crit_);
pbos@webrtc.org1d096902013-12-13 12:48:05 +000086 int64_t timestamp_in_ms = -1;
87 if (ntp_rtp_pairs_.size() == 2) {
88 // TODO(stefan): We can't EXPECT_TRUE on this call due to a bug in the
89 // RTCP sender where it sends RTCP SR before any RTP packets, which leads
90 // to a bogus NTP/RTP mapping.
wu@webrtc.org66773a02014-05-07 17:09:44 +000091 RtpToNtpMs(timestamp, ntp_rtp_pairs_, &timestamp_in_ms);
pbos@webrtc.org1d096902013-12-13 12:48:05 +000092 return timestamp_in_ms;
93 }
94 return -1;
95 }
96
97 private:
wu@webrtc.org66773a02014-05-07 17:09:44 +000098 void StoreNtpRtpPair(RtcpMeasurement ntp_rtp_pair) {
Peter Boströmf2f82832015-05-01 13:00:41 +020099 rtc::CritScope lock(&crit_);
wu@webrtc.org66773a02014-05-07 17:09:44 +0000100 for (RtcpList::iterator it = ntp_rtp_pairs_.begin();
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000101 it != ntp_rtp_pairs_.end();
102 ++it) {
103 if (ntp_rtp_pair.ntp_secs == it->ntp_secs &&
104 ntp_rtp_pair.ntp_frac == it->ntp_frac) {
105 // This RTCP has already been added to the list.
106 return;
107 }
108 }
109 // We need two RTCP SR reports to map between RTP and NTP. More than two
110 // will not improve the mapping.
111 if (ntp_rtp_pairs_.size() == 2) {
112 ntp_rtp_pairs_.pop_back();
113 }
114 ntp_rtp_pairs_.push_front(ntp_rtp_pair);
115 }
116
Peter Boströmf2f82832015-05-01 13:00:41 +0200117 mutable rtc::CriticalSection crit_;
wu@webrtc.org66773a02014-05-07 17:09:44 +0000118 RtcpList ntp_rtp_pairs_ GUARDED_BY(crit_);
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000119};
120
121class VideoRtcpAndSyncObserver : public SyncRtcpObserver, public VideoRenderer {
122 static const int kInSyncThresholdMs = 50;
123 static const int kStartupTimeMs = 2000;
124 static const int kMinRunTimeMs = 30000;
125
126 public:
127 VideoRtcpAndSyncObserver(Clock* clock,
128 int voe_channel,
129 VoEVideoSync* voe_sync,
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33 +0000130 SyncRtcpObserver* audio_observer)
stefanf116bd02015-10-27 08:29:42 -0700131 : clock_(clock),
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000132 voe_channel_(voe_channel),
133 voe_sync_(voe_sync),
134 audio_observer_(audio_observer),
135 creation_time_ms_(clock_->TimeInMilliseconds()),
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33 +0000136 first_time_in_sync_(-1) {}
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000137
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700138 void RenderFrame(const VideoFrame& video_frame,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000139 int time_to_render_ms) override {
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000140 int64_t now_ms = clock_->TimeInMilliseconds();
141 uint32_t playout_timestamp = 0;
142 if (voe_sync_->GetPlayoutTimestamp(voe_channel_, playout_timestamp) != 0)
143 return;
144 int64_t latest_audio_ntp =
145 audio_observer_->RtpTimestampToNtp(playout_timestamp);
146 int64_t latest_video_ntp = RtpTimestampToNtp(video_frame.timestamp());
147 if (latest_audio_ntp < 0 || latest_video_ntp < 0)
148 return;
149 int time_until_render_ms =
150 std::max(0, static_cast<int>(video_frame.render_time_ms() - now_ms));
151 latest_video_ntp += time_until_render_ms;
152 int64_t stream_offset = latest_audio_ntp - latest_video_ntp;
153 std::stringstream ss;
154 ss << stream_offset;
henrik.lundin@webrtc.orged865b52014-03-06 10:28:07 +0000155 webrtc::test::PrintResult("stream_offset",
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33 +0000156 "",
henrik.lundin@webrtc.orged865b52014-03-06 10:28:07 +0000157 "synchronization",
158 ss.str(),
159 "ms",
160 false);
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000161 int64_t time_since_creation = now_ms - creation_time_ms_;
162 // During the first couple of seconds audio and video can falsely be
163 // estimated as being synchronized. We don't want to trigger on those.
164 if (time_since_creation < kStartupTimeMs)
165 return;
pbos@webrtc.orgb5f30292014-03-13 08:53:39 +0000166 if (std::abs(latest_audio_ntp - latest_video_ntp) < kInSyncThresholdMs) {
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000167 if (first_time_in_sync_ == -1) {
168 first_time_in_sync_ = now_ms;
169 webrtc::test::PrintResult("sync_convergence_time",
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33 +0000170 "",
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000171 "synchronization",
172 time_since_creation,
173 "ms",
174 false);
175 }
176 if (time_since_creation > kMinRunTimeMs)
Peter Boström5811a392015-12-10 13:02:50 +0100177 observation_complete_.Set();
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000178 }
179 }
180
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000181 bool IsTextureSupported() const override { return false; }
pbos@webrtc.org0d852d52015-02-09 15:14:36 +0000182
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000183 private:
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000184 Clock* const clock_;
stefanf116bd02015-10-27 08:29:42 -0700185 const int voe_channel_;
186 VoEVideoSync* const voe_sync_;
187 SyncRtcpObserver* const audio_observer_;
188 const int64_t creation_time_ms_;
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000189 int64_t first_time_in_sync_;
190};
191
pbos8fc7fa72015-07-15 08:02:58 -0700192void CallPerfTest::TestAudioVideoSync(bool fec, bool create_audio_first) {
193 const char* kSyncGroup = "av_sync";
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100194 const uint32_t kAudioSendSsrc = 1234;
195 const uint32_t kAudioRecvSsrc = 5678;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000196 class AudioPacketReceiver : public PacketReceiver {
197 public:
198 AudioPacketReceiver(int channel, VoENetwork* voe_network)
199 : channel_(channel),
200 voe_network_(voe_network),
201 parser_(RtpHeaderParser::Create()) {}
stefan68786d22015-09-08 05:36:15 -0700202 DeliveryStatus DeliverPacket(MediaType media_type,
203 const uint8_t* packet,
204 size_t length,
205 const PacketTime& packet_time) override {
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200206 EXPECT_TRUE(media_type == MediaType::ANY ||
207 media_type == MediaType::AUDIO);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000208 int ret;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000209 if (parser_->IsRtcp(packet, length)) {
210 ret = voe_network_->ReceivedRTCPPacket(channel_, packet, length);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000211 } else {
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000212 ret = voe_network_->ReceivedRTPPacket(channel_, packet, length,
213 PacketTime());
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000214 }
215 return ret == 0 ? DELIVERY_OK : DELIVERY_PACKET_ERROR;
216 }
217
218 private:
219 int channel_;
220 VoENetwork* voe_network_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000221 rtc::scoped_ptr<RtpHeaderParser> parser_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000222 };
223
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000224 VoiceEngine* voice_engine = VoiceEngine::Create();
225 VoEBase* voe_base = VoEBase::GetInterface(voice_engine);
226 VoECodec* voe_codec = VoECodec::GetInterface(voice_engine);
227 VoENetwork* voe_network = VoENetwork::GetInterface(voice_engine);
228 VoEVideoSync* voe_sync = VoEVideoSync::GetInterface(voice_engine);
229 const std::string audio_filename =
230 test::ResourcePath("voice_engine/audio_long16", "pcm");
231 ASSERT_STRNE("", audio_filename.c_str());
232 test::FakeAudioDevice fake_audio_device(Clock::GetRealTimeClock(),
233 audio_filename);
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000234 EXPECT_EQ(0, voe_base->Init(&fake_audio_device, nullptr));
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100235 Config voe_config;
236 voe_config.Set<VoicePacing>(new VoicePacing(true));
237 int send_channel_id = voe_base->CreateChannel(voe_config);
238 int recv_channel_id = voe_base->CreateChannel();
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000239
stefanf116bd02015-10-27 08:29:42 -0700240 SyncRtcpObserver audio_observer;
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000241
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100242 AudioState::Config send_audio_state_config;
243 send_audio_state_config.voice_engine = voice_engine;
244 Call::Config sender_config;
245 sender_config.audio_state = AudioState::Create(send_audio_state_config);
solenberg4fbae2b2015-08-28 04:07:10 -0700246 Call::Config receiver_config;
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100247 receiver_config.audio_state = sender_config.audio_state;
248 CreateCalls(sender_config, receiver_config);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000249
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100250 AudioPacketReceiver voe_send_packet_receiver(send_channel_id, voe_network);
251 AudioPacketReceiver voe_recv_packet_receiver(recv_channel_id, voe_network);
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000252
stefanf116bd02015-10-27 08:29:42 -0700253 FakeNetworkPipe::Config net_config;
254 net_config.queue_delay_ms = 500;
255 net_config.loss_percent = 5;
256 test::PacketTransport audio_send_transport(
257 nullptr, &audio_observer, test::PacketTransport::kSender, net_config);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100258 audio_send_transport.SetReceiver(&voe_recv_packet_receiver);
stefanf116bd02015-10-27 08:29:42 -0700259 test::PacketTransport audio_receive_transport(
260 nullptr, &audio_observer, test::PacketTransport::kReceiver, net_config);
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100261 audio_receive_transport.SetReceiver(&voe_send_packet_receiver);
stefanf116bd02015-10-27 08:29:42 -0700262
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100263 internal::TransportAdapter send_transport_adapter(&audio_send_transport);
264 send_transport_adapter.Enable();
265 EXPECT_EQ(0, voe_network->RegisterExternalTransport(send_channel_id,
266 send_transport_adapter));
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000267
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100268 internal::TransportAdapter recv_transport_adapter(&audio_receive_transport);
269 recv_transport_adapter.Enable();
270 EXPECT_EQ(0, voe_network->RegisterExternalTransport(recv_channel_id,
271 recv_transport_adapter));
272
273 VideoRtcpAndSyncObserver observer(Clock::GetRealTimeClock(), recv_channel_id,
stefanf116bd02015-10-27 08:29:42 -0700274 voe_sync, &audio_observer);
275
276 test::PacketTransport sync_send_transport(sender_call_.get(), &observer,
277 test::PacketTransport::kSender,
278 FakeNetworkPipe::Config());
279 sync_send_transport.SetReceiver(receiver_call_->Receiver());
280 test::PacketTransport sync_receive_transport(receiver_call_.get(), &observer,
281 test::PacketTransport::kReceiver,
282 FakeNetworkPipe::Config());
283 sync_receive_transport.SetReceiver(sender_call_->Receiver());
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000284
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000285 test::FakeDecoder fake_decoder;
286
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100287 CreateSendConfig(1, 0, &sync_send_transport);
stefanf116bd02015-10-27 08:29:42 -0700288 CreateMatchingReceiveConfigs(&sync_receive_transport);
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000289
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100290 AudioSendStream::Config audio_send_config(&audio_send_transport);
291 audio_send_config.voe_channel_id = send_channel_id;
292 audio_send_config.rtp.ssrc = kAudioSendSsrc;
293 AudioSendStream* audio_send_stream =
294 sender_call_->CreateAudioSendStream(audio_send_config);
295
296 CodecInst isac = {103, "ISAC", 16000, 480, 1, 32000};
297 EXPECT_EQ(0, voe_codec->SetSendCodec(send_channel_id, isac));
298
stefanff483612015-12-21 03:14:00 -0800299 video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
stefan@webrtc.org01581da2014-09-04 06:48:14 +0000300 if (fec) {
stefanff483612015-12-21 03:14:00 -0800301 video_send_config_.rtp.fec.red_payload_type = kRedPayloadType;
302 video_send_config_.rtp.fec.ulpfec_payload_type = kUlpfecPayloadType;
303 video_receive_configs_[0].rtp.fec.red_payload_type = kRedPayloadType;
304 video_receive_configs_[0].rtp.fec.ulpfec_payload_type = kUlpfecPayloadType;
stefan@webrtc.org01581da2014-09-04 06:48:14 +0000305 }
stefanff483612015-12-21 03:14:00 -0800306 video_receive_configs_[0].rtp.nack.rtp_history_ms = 1000;
307 video_receive_configs_[0].renderer = &observer;
308 video_receive_configs_[0].sync_group = kSyncGroup;
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000309
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100310 AudioReceiveStream::Config audio_recv_config;
311 audio_recv_config.rtp.remote_ssrc = kAudioSendSsrc;
312 audio_recv_config.rtp.local_ssrc = kAudioRecvSsrc;
313 audio_recv_config.voe_channel_id = recv_channel_id;
314 audio_recv_config.sync_group = kSyncGroup;
pbos8fc7fa72015-07-15 08:02:58 -0700315
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100316 AudioReceiveStream* audio_receive_stream;
pbos8fc7fa72015-07-15 08:02:58 -0700317
318 if (create_audio_first) {
319 audio_receive_stream =
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100320 receiver_call_->CreateAudioReceiveStream(audio_recv_config);
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100321 CreateVideoStreams();
pbos8fc7fa72015-07-15 08:02:58 -0700322 } else {
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100323 CreateVideoStreams();
pbos8fc7fa72015-07-15 08:02:58 -0700324 audio_receive_stream =
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100325 receiver_call_->CreateAudioReceiveStream(audio_recv_config);
pbos8fc7fa72015-07-15 08:02:58 -0700326 }
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000327
328 CreateFrameGeneratorCapturer();
329
330 Start();
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000331
332 fake_audio_device.Start();
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100333 EXPECT_EQ(0, voe_base->StartPlayout(recv_channel_id));
334 EXPECT_EQ(0, voe_base->StartReceive(recv_channel_id));
335 EXPECT_EQ(0, voe_base->StartSend(send_channel_id));
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000336
Peter Boström5811a392015-12-10 13:02:50 +0100337 EXPECT_TRUE(observer.Wait())
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000338 << "Timed out while waiting for audio and video to be synchronized.";
339
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100340 EXPECT_EQ(0, voe_base->StopSend(send_channel_id));
341 EXPECT_EQ(0, voe_base->StopReceive(recv_channel_id));
342 EXPECT_EQ(0, voe_base->StopPlayout(recv_channel_id));
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000343 fake_audio_device.Stop();
344
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000345 Stop();
stefanf116bd02015-10-27 08:29:42 -0700346 sync_send_transport.StopSending();
347 sync_receive_transport.StopSending();
348 audio_send_transport.StopSending();
349 audio_receive_transport.StopSending();
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000350
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100351 DestroyStreams();
352
353 sender_call_->DestroyAudioSendStream(audio_send_stream);
354 receiver_call_->DestroyAudioReceiveStream(audio_receive_stream);
355
356 voe_base->DeleteChannel(send_channel_id);
357 voe_base->DeleteChannel(recv_channel_id);
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000358 voe_base->Release();
359 voe_codec->Release();
360 voe_network->Release();
361 voe_sync->Release();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000362
Fredrik Solenberg4f4ec0a2015-10-22 10:49:27 +0200363 DestroyCalls();
364
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000365 VoiceEngine::Delete(voice_engine);
366}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000367
pbos8fc7fa72015-07-15 08:02:58 -0700368TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithAudioCreatedFirst) {
369 TestAudioVideoSync(false, true);
370}
371
372TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithVideoCreatedFirst) {
373 TestAudioVideoSync(false, false);
stefan@webrtc.org01581da2014-09-04 06:48:14 +0000374}
375
376TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSyncWithFec) {
pbos8fc7fa72015-07-15 08:02:58 -0700377 TestAudioVideoSync(true, false);
stefan@webrtc.org01581da2014-09-04 06:48:14 +0000378}
379
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000380void CallPerfTest::TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config,
381 int threshold_ms,
382 int start_time_ms,
383 int run_time_ms) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000384 class CaptureNtpTimeObserver : public test::EndToEndTest,
385 public VideoRenderer {
386 public:
stefanf116bd02015-10-27 08:29:42 -0700387 CaptureNtpTimeObserver(int threshold_ms, int start_time_ms, int run_time_ms)
388 : EndToEndTest(kLongTimeoutMs),
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000389 clock_(Clock::GetRealTimeClock()),
390 threshold_ms_(threshold_ms),
391 start_time_ms_(start_time_ms),
392 run_time_ms_(run_time_ms),
393 creation_time_ms_(clock_->TimeInMilliseconds()),
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000394 capturer_(nullptr),
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000395 rtp_start_timestamp_set_(false),
396 rtp_start_timestamp_(0) {}
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000397
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000398 private:
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700399 void RenderFrame(const VideoFrame& video_frame,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000400 int time_to_render_ms) override {
stefanf116bd02015-10-27 08:29:42 -0700401 rtc::CritScope lock(&crit_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000402 if (video_frame.ntp_time_ms() <= 0) {
403 // Haven't got enough RTCP SR in order to calculate the capture ntp
404 // time.
405 return;
406 }
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000407
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000408 int64_t now_ms = clock_->TimeInMilliseconds();
409 int64_t time_since_creation = now_ms - creation_time_ms_;
410 if (time_since_creation < start_time_ms_) {
411 // Wait for |start_time_ms_| before start measuring.
412 return;
413 }
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000414
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000415 if (time_since_creation > run_time_ms_) {
Peter Boström5811a392015-12-10 13:02:50 +0100416 observation_complete_.Set();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000417 }
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000418
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000419 FrameCaptureTimeList::iterator iter =
420 capture_time_list_.find(video_frame.timestamp());
421 EXPECT_TRUE(iter != capture_time_list_.end());
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000422
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000423 // The real capture time has been wrapped to uint32_t before converted
424 // to rtp timestamp in the sender side. So here we convert the estimated
425 // capture time to a uint32_t 90k timestamp also for comparing.
426 uint32_t estimated_capture_timestamp =
427 90 * static_cast<uint32_t>(video_frame.ntp_time_ms());
428 uint32_t real_capture_timestamp = iter->second;
429 int time_offset_ms = real_capture_timestamp - estimated_capture_timestamp;
430 time_offset_ms = time_offset_ms / 90;
431 std::stringstream ss;
432 ss << time_offset_ms;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000433
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000434 webrtc::test::PrintResult(
435 "capture_ntp_time", "", "real - estimated", ss.str(), "ms", true);
436 EXPECT_TRUE(std::abs(time_offset_ms) < threshold_ms_);
437 }
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000438
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000439 bool IsTextureSupported() const override { return false; }
pbos@webrtc.org0d852d52015-02-09 15:14:36 +0000440
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000441 virtual Action OnSendRtp(const uint8_t* packet, size_t length) {
stefanf116bd02015-10-27 08:29:42 -0700442 rtc::CritScope lock(&crit_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000443 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000444 EXPECT_TRUE(parser_->Parse(packet, length, &header));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000445
446 if (!rtp_start_timestamp_set_) {
447 // Calculate the rtp timestamp offset in order to calculate the real
448 // capture time.
449 uint32_t first_capture_timestamp =
450 90 * static_cast<uint32_t>(capturer_->first_frame_capture_time());
451 rtp_start_timestamp_ = header.timestamp - first_capture_timestamp;
452 rtp_start_timestamp_set_ = true;
453 }
454
455 uint32_t capture_timestamp = header.timestamp - rtp_start_timestamp_;
456 capture_time_list_.insert(
457 capture_time_list_.end(),
458 std::make_pair(header.timestamp, capture_timestamp));
459 return SEND_PACKET;
460 }
461
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000462 void OnFrameGeneratorCapturerCreated(
463 test::FrameGeneratorCapturer* frame_generator_capturer) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000464 capturer_ = frame_generator_capturer;
465 }
466
stefanff483612015-12-21 03:14:00 -0800467 void ModifyVideoConfigs(
468 VideoSendStream::Config* send_config,
469 std::vector<VideoReceiveStream::Config>* receive_configs,
470 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000471 (*receive_configs)[0].renderer = this;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000472 // Enable the receiver side rtt calculation.
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000473 (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000474 }
475
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000476 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100477 EXPECT_TRUE(Wait()) << "Timed out while waiting for "
478 "estimated capture NTP time to be "
479 "within bounds.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000480 }
481
stefanf116bd02015-10-27 08:29:42 -0700482 rtc::CriticalSection crit_;
483 Clock* const clock_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000484 int threshold_ms_;
485 int start_time_ms_;
486 int run_time_ms_;
487 int64_t creation_time_ms_;
488 test::FrameGeneratorCapturer* capturer_;
489 bool rtp_start_timestamp_set_;
490 uint32_t rtp_start_timestamp_;
491 typedef std::map<uint32_t, uint32_t> FrameCaptureTimeList;
stefanf116bd02015-10-27 08:29:42 -0700492 FrameCaptureTimeList capture_time_list_ GUARDED_BY(&crit_);
493 } test(threshold_ms, start_time_ms, run_time_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000494
stefanf116bd02015-10-27 08:29:42 -0700495 RunBaseTest(&test, net_config);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000496}
497
wu@webrtc.org9aa7d8d2014-05-29 05:03:52 +0000498TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkDelay) {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000499 FakeNetworkPipe::Config net_config;
500 net_config.queue_delay_ms = 100;
501 // TODO(wu): lower the threshold as the calculation/estimatation becomes more
502 // accurate.
wu@webrtc.org9aa7d8d2014-05-29 05:03:52 +0000503 const int kThresholdMs = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000504 const int kStartTimeMs = 10000;
505 const int kRunTimeMs = 20000;
506 TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs);
507}
508
wu@webrtc.org0224c202014-05-05 17:42:43 +0000509TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkJitter) {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000510 FakeNetworkPipe::Config net_config;
wu@webrtc.org0224c202014-05-05 17:42:43 +0000511 net_config.queue_delay_ms = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000512 net_config.delay_standard_deviation_ms = 10;
513 // TODO(wu): lower the threshold as the calculation/estimatation becomes more
514 // accurate.
wu@webrtc.org0224c202014-05-05 17:42:43 +0000515 const int kThresholdMs = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000516 const int kStartTimeMs = 10000;
517 const int kRunTimeMs = 20000;
518 TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs);
519}
520
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000521void CallPerfTest::TestCpuOveruse(LoadObserver::Load tested_load,
522 int encode_delay_ms) {
pbos@webrtc.org42684be2014-10-03 11:25:45 +0000523 class LoadObserver : public test::SendTest, public webrtc::LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000524 public:
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000525 LoadObserver(LoadObserver::Load tested_load, int encode_delay_ms)
526 : SendTest(kLongTimeoutMs),
527 tested_load_(tested_load),
528 encoder_(Clock::GetRealTimeClock(), encode_delay_ms) {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000529
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000530 void OnLoadUpdate(Load load) override {
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000531 if (load == tested_load_)
Peter Boström5811a392015-12-10 13:02:50 +0100532 observation_complete_.Set();
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000533 }
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000534
stefanff483612015-12-21 03:14:00 -0800535 void ModifyVideoConfigs(
536 VideoSendStream::Config* send_config,
537 std::vector<VideoReceiveStream::Config>* receive_configs,
538 VideoEncoderConfig* encoder_config) override {
solenberge5269742015-09-08 05:13:22 -0700539 send_config->overuse_callback = this;
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000540 send_config->encoder_settings.encoder = &encoder_;
541 }
542
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000543 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100544 EXPECT_TRUE(Wait()) << "Timed out before receiving an overuse callback.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000545 }
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000546
547 LoadObserver::Load tested_load_;
548 test::DelayedEncoder encoder_;
549 } test(tested_load, encode_delay_ms);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000550
stefanf116bd02015-10-27 08:29:42 -0700551 RunBaseTest(&test, FakeNetworkPipe::Config());
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +0000552}
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000553
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000554TEST_F(CallPerfTest, ReceivesCpuUnderuse) {
555 const int kEncodeDelayMs = 2;
556 TestCpuOveruse(LoadObserver::kUnderuse, kEncodeDelayMs);
557}
558
559TEST_F(CallPerfTest, ReceivesCpuOveruse) {
560 const int kEncodeDelayMs = 35;
561 TestCpuOveruse(LoadObserver::kOveruse, kEncodeDelayMs);
562}
563
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000564void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) {
565 static const int kMaxEncodeBitrateKbps = 30;
pbos@webrtc.org709e2972014-03-19 10:59:52 +0000566 static const int kMinTransmitBitrateBps = 150000;
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000567 static const int kMinAcceptableTransmitBitrate = 130;
568 static const int kMaxAcceptableTransmitBitrate = 170;
569 static const int kNumBitrateObservationsInRange = 100;
sprang867fb522015-08-03 04:38:41 -0700570 static const int kAcceptableBitrateErrorMargin = 15; // +- 7
stefanf116bd02015-10-27 08:29:42 -0700571 class BitrateObserver : public test::EndToEndTest {
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000572 public:
573 explicit BitrateObserver(bool using_min_transmit_bitrate)
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000574 : EndToEndTest(kLongTimeoutMs),
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000575 send_stream_(nullptr),
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000576 pad_to_min_bitrate_(using_min_transmit_bitrate),
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000577 num_bitrate_observations_in_range_(0) {}
578
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000579 private:
stefanf116bd02015-10-27 08:29:42 -0700580 // TODO(holmer): Run this with a timer instead of once per packet.
581 Action OnSendRtp(const uint8_t* packet, size_t length) override {
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000582 VideoSendStream::Stats stats = send_stream_->GetStats();
583 if (stats.substreams.size() > 0) {
henrikg91d6ede2015-09-17 00:24:34 -0700584 RTC_DCHECK_EQ(1u, stats.substreams.size());
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000585 int bitrate_kbps =
586 stats.substreams.begin()->second.total_bitrate_bps / 1000;
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000587 if (bitrate_kbps > 0) {
588 test::PrintResult(
589 "bitrate_stats_",
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000590 (pad_to_min_bitrate_ ? "min_transmit_bitrate"
591 : "without_min_transmit_bitrate"),
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000592 "bitrate_kbps",
593 static_cast<size_t>(bitrate_kbps),
594 "kbps",
595 false);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000596 if (pad_to_min_bitrate_) {
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000597 if (bitrate_kbps > kMinAcceptableTransmitBitrate &&
598 bitrate_kbps < kMaxAcceptableTransmitBitrate) {
599 ++num_bitrate_observations_in_range_;
600 }
601 } else {
602 // Expect bitrate stats to roughly match the max encode bitrate.
sprang867fb522015-08-03 04:38:41 -0700603 if (bitrate_kbps > (kMaxEncodeBitrateKbps -
604 kAcceptableBitrateErrorMargin / 2) &&
605 bitrate_kbps < (kMaxEncodeBitrateKbps +
606 kAcceptableBitrateErrorMargin / 2)) {
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000607 ++num_bitrate_observations_in_range_;
608 }
609 }
610 if (num_bitrate_observations_in_range_ ==
611 kNumBitrateObservationsInRange)
Peter Boström5811a392015-12-10 13:02:50 +0100612 observation_complete_.Set();
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000613 }
614 }
stefanf116bd02015-10-27 08:29:42 -0700615 return SEND_PACKET;
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000616 }
617
stefanff483612015-12-21 03:14:00 -0800618 void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000619 VideoSendStream* send_stream,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000620 const std::vector<VideoReceiveStream*>& receive_streams) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000621 send_stream_ = send_stream;
622 }
623
stefanff483612015-12-21 03:14:00 -0800624 void ModifyVideoConfigs(
625 VideoSendStream::Config* send_config,
626 std::vector<VideoReceiveStream::Config>* receive_configs,
627 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000628 if (pad_to_min_bitrate_) {
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000629 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000630 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700631 RTC_DCHECK_EQ(0, encoder_config->min_transmit_bitrate_bps);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000632 }
633 }
634
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000635 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100636 EXPECT_TRUE(Wait()) << "Timeout while waiting for send-bitrate stats.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000637 }
638
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000639 VideoSendStream* send_stream_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000640 const bool pad_to_min_bitrate_;
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000641 int num_bitrate_observations_in_range_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000642 } test(pad_to_min_bitrate);
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000643
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000644 fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps);
stefanf116bd02015-10-27 08:29:42 -0700645 RunBaseTest(&test, FakeNetworkPipe::Config());
pbos@webrtc.org3349ae02014-03-13 12:52:27 +0000646}
647
648TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { TestMinTransmitBitrate(true); }
649
650TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) {
651 TestMinTransmitBitrate(false);
652}
653
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000654TEST_F(CallPerfTest, KeepsHighBitrateWhenReconfiguringSender) {
655 static const uint32_t kInitialBitrateKbps = 400;
656 static const uint32_t kReconfigureThresholdKbps = 600;
657 static const uint32_t kPermittedReconfiguredBitrateDiffKbps = 100;
658
659 class BitrateObserver : public test::EndToEndTest, public test::FakeEncoder {
660 public:
661 BitrateObserver()
662 : EndToEndTest(kDefaultTimeoutMs),
663 FakeEncoder(Clock::GetRealTimeClock()),
Peter Boström5811a392015-12-10 13:02:50 +0100664 time_to_reconfigure_(false, false),
sprang867fb522015-08-03 04:38:41 -0700665 encoder_inits_(0),
666 last_set_bitrate_(0),
667 send_stream_(nullptr) {}
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000668
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000669 int32_t InitEncode(const VideoCodec* config,
670 int32_t number_of_cores,
671 size_t max_payload_size) override {
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000672 if (encoder_inits_ == 0) {
673 EXPECT_EQ(kInitialBitrateKbps, config->startBitrate)
674 << "Encoder not initialized at expected bitrate.";
675 }
676 ++encoder_inits_;
677 if (encoder_inits_ == 2) {
678 EXPECT_GE(last_set_bitrate_, kReconfigureThresholdKbps);
679 EXPECT_NEAR(config->startBitrate,
680 last_set_bitrate_,
681 kPermittedReconfiguredBitrateDiffKbps)
682 << "Encoder reconfigured with bitrate too far away from last set.";
Peter Boström5811a392015-12-10 13:02:50 +0100683 observation_complete_.Set();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000684 }
685 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
686 }
687
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000688 int32_t SetRates(uint32_t new_target_bitrate_kbps,
689 uint32_t framerate) override {
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000690 last_set_bitrate_ = new_target_bitrate_kbps;
691 if (encoder_inits_ == 1 &&
692 new_target_bitrate_kbps > kReconfigureThresholdKbps) {
Peter Boström5811a392015-12-10 13:02:50 +0100693 time_to_reconfigure_.Set();
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000694 }
695 return FakeEncoder::SetRates(new_target_bitrate_kbps, framerate);
696 }
697
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000698 Call::Config GetSenderCallConfig() override {
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000699 Call::Config config = EndToEndTest::GetSenderCallConfig();
Stefan Holmere5904162015-03-26 11:11:06 +0100700 config.bitrate_config.start_bitrate_bps = kInitialBitrateKbps * 1000;
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000701 return config;
702 }
703
stefanff483612015-12-21 03:14:00 -0800704 void ModifyVideoConfigs(
705 VideoSendStream::Config* send_config,
706 std::vector<VideoReceiveStream::Config>* receive_configs,
707 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000708 send_config->encoder_settings.encoder = this;
709 encoder_config->streams[0].min_bitrate_bps = 50000;
710 encoder_config->streams[0].target_bitrate_bps =
711 encoder_config->streams[0].max_bitrate_bps = 2000000;
712
713 encoder_config_ = *encoder_config;
714 }
715
stefanff483612015-12-21 03:14:00 -0800716 void OnVideoStreamsCreated(
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000717 VideoSendStream* send_stream,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000718 const std::vector<VideoReceiveStream*>& receive_streams) override {
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000719 send_stream_ = send_stream;
720 }
721
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000722 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100723 ASSERT_TRUE(time_to_reconfigure_.Wait(kDefaultTimeoutMs))
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000724 << "Timed out before receiving an initial high bitrate.";
725 encoder_config_.streams[0].width *= 2;
726 encoder_config_.streams[0].height *= 2;
727 EXPECT_TRUE(send_stream_->ReconfigureVideoEncoder(encoder_config_));
Peter Boström5811a392015-12-10 13:02:50 +0100728 EXPECT_TRUE(Wait())
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000729 << "Timed out while waiting for a couple of high bitrate estimates "
730 "after reconfiguring the send stream.";
731 }
732
733 private:
Peter Boström5811a392015-12-10 13:02:50 +0100734 rtc::Event time_to_reconfigure_;
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000735 int encoder_inits_;
736 uint32_t last_set_bitrate_;
737 VideoSendStream* send_stream_;
738 VideoEncoderConfig encoder_config_;
739 } test;
740
stefanf116bd02015-10-27 08:29:42 -0700741 RunBaseTest(&test, FakeNetworkPipe::Config());
pbos@webrtc.org32452b22014-10-22 12:15:24 +0000742}
743
pbos@webrtc.org1d096902013-12-13 12:48:05 +0000744} // namespace webrtc