blob: 18246168bc06b1f05446e960296ed87e5a36f1be [file] [log] [blame]
pbos@webrtc.org1d096902013-12-13 12:48:051/*
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 <assert.h>
11
12#include <algorithm>
13#include <sstream>
14#include <string>
15
16#include "testing/gtest/include/gtest/gtest.h"
17
18#include "webrtc/call.h"
henrik.lundin@webrtc.orged865b52014-03-06 10:28:0719#include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h"
pbos@webrtc.org1d096902013-12-13 12:48:0520#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
21#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
22#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
wu@webrtc.org66773a02014-05-07 17:09:4423#include "webrtc/system_wrappers/interface/rtp_to_ntp.h"
pbos@webrtc.org1d096902013-12-13 12:48:0524#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.orgde1429e2014-04-28 13:00:2125#include "webrtc/system_wrappers/interface/thread_annotations.h"
pbos@webrtc.org994d0b72014-06-27 08:47:5226#include "webrtc/test/call_test.h"
pbos@webrtc.org1d096902013-12-13 12:48:0527#include "webrtc/test/direct_transport.h"
pbos@webrtc.orgf577ae92014-03-19 08:43:5728#include "webrtc/test/encoder_settings.h"
pbos@webrtc.org1d096902013-12-13 12:48:0529#include "webrtc/test/fake_audio_device.h"
30#include "webrtc/test/fake_decoder.h"
31#include "webrtc/test/fake_encoder.h"
32#include "webrtc/test/frame_generator.h"
33#include "webrtc/test/frame_generator_capturer.h"
34#include "webrtc/test/rtp_rtcp_observer.h"
35#include "webrtc/test/testsupport/fileutils.h"
36#include "webrtc/test/testsupport/perf_test.h"
37#include "webrtc/video/transport_adapter.h"
38#include "webrtc/voice_engine/include/voe_base.h"
39#include "webrtc/voice_engine/include/voe_codec.h"
40#include "webrtc/voice_engine/include/voe_network.h"
41#include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
42#include "webrtc/voice_engine/include/voe_video_sync.h"
43
44namespace webrtc {
45
pbos@webrtc.org994d0b72014-06-27 08:47:5246class CallPerfTest : public test::CallTest {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:0747 protected:
pbos@webrtc.org3349ae02014-03-13 12:52:2748 void TestMinTransmitBitrate(bool pad_to_min_bitrate);
49
wu@webrtc.orgcd701192014-04-24 22:10:2450 void TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config,
51 int threshold_ms,
52 int start_time_ms,
53 int run_time_ms);
pbos@webrtc.org1d096902013-12-13 12:48:0554};
55
56class SyncRtcpObserver : public test::RtpRtcpObserver {
57 public:
stefan@webrtc.orgfaada6e2013-12-18 20:28:2558 explicit SyncRtcpObserver(const FakeNetworkPipe::Config& config)
pbos@webrtc.org994d0b72014-06-27 08:47:5259 : test::RtpRtcpObserver(CallPerfTest::kLongTimeoutMs, config),
pbos@webrtc.orgde1429e2014-04-28 13:00:2160 crit_(CriticalSectionWrapper::CreateCriticalSection()) {}
pbos@webrtc.org1d096902013-12-13 12:48:0561
62 virtual Action OnSendRtcp(const uint8_t* packet, size_t length) OVERRIDE {
63 RTCPUtility::RTCPParserV2 parser(packet, length, true);
64 EXPECT_TRUE(parser.IsValid());
65
66 for (RTCPUtility::RTCPPacketTypes packet_type = parser.Begin();
67 packet_type != RTCPUtility::kRtcpNotValidCode;
68 packet_type = parser.Iterate()) {
69 if (packet_type == RTCPUtility::kRtcpSrCode) {
70 const RTCPUtility::RTCPPacket& packet = parser.Packet();
wu@webrtc.org66773a02014-05-07 17:09:4471 RtcpMeasurement ntp_rtp_pair(
pbos@webrtc.org1d096902013-12-13 12:48:0572 packet.SR.NTPMostSignificant,
73 packet.SR.NTPLeastSignificant,
74 packet.SR.RTPTimestamp);
75 StoreNtpRtpPair(ntp_rtp_pair);
76 }
77 }
78 return SEND_PACKET;
79 }
80
81 int64_t RtpTimestampToNtp(uint32_t timestamp) const {
pbos@webrtc.orgde1429e2014-04-28 13:00:2182 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.org1d096902013-12-13 12:48:0583 int64_t timestamp_in_ms = -1;
84 if (ntp_rtp_pairs_.size() == 2) {
85 // TODO(stefan): We can't EXPECT_TRUE on this call due to a bug in the
86 // RTCP sender where it sends RTCP SR before any RTP packets, which leads
87 // to a bogus NTP/RTP mapping.
wu@webrtc.org66773a02014-05-07 17:09:4488 RtpToNtpMs(timestamp, ntp_rtp_pairs_, &timestamp_in_ms);
pbos@webrtc.org1d096902013-12-13 12:48:0589 return timestamp_in_ms;
90 }
91 return -1;
92 }
93
94 private:
wu@webrtc.org66773a02014-05-07 17:09:4495 void StoreNtpRtpPair(RtcpMeasurement ntp_rtp_pair) {
pbos@webrtc.orgde1429e2014-04-28 13:00:2196 CriticalSectionScoped lock(crit_.get());
wu@webrtc.org66773a02014-05-07 17:09:4497 for (RtcpList::iterator it = ntp_rtp_pairs_.begin();
pbos@webrtc.org1d096902013-12-13 12:48:0598 it != ntp_rtp_pairs_.end();
99 ++it) {
100 if (ntp_rtp_pair.ntp_secs == it->ntp_secs &&
101 ntp_rtp_pair.ntp_frac == it->ntp_frac) {
102 // This RTCP has already been added to the list.
103 return;
104 }
105 }
106 // We need two RTCP SR reports to map between RTP and NTP. More than two
107 // will not improve the mapping.
108 if (ntp_rtp_pairs_.size() == 2) {
109 ntp_rtp_pairs_.pop_back();
110 }
111 ntp_rtp_pairs_.push_front(ntp_rtp_pair);
112 }
113
pbos@webrtc.orgde1429e2014-04-28 13:00:21114 const scoped_ptr<CriticalSectionWrapper> crit_;
wu@webrtc.org66773a02014-05-07 17:09:44115 RtcpList ntp_rtp_pairs_ GUARDED_BY(crit_);
pbos@webrtc.org1d096902013-12-13 12:48:05116};
117
118class VideoRtcpAndSyncObserver : public SyncRtcpObserver, public VideoRenderer {
119 static const int kInSyncThresholdMs = 50;
120 static const int kStartupTimeMs = 2000;
121 static const int kMinRunTimeMs = 30000;
122
123 public:
124 VideoRtcpAndSyncObserver(Clock* clock,
125 int voe_channel,
126 VoEVideoSync* voe_sync,
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33127 SyncRtcpObserver* audio_observer)
stefan@webrtc.orgfaada6e2013-12-18 20:28:25128 : SyncRtcpObserver(FakeNetworkPipe::Config()),
pbos@webrtc.org1d096902013-12-13 12:48:05129 clock_(clock),
130 voe_channel_(voe_channel),
131 voe_sync_(voe_sync),
132 audio_observer_(audio_observer),
133 creation_time_ms_(clock_->TimeInMilliseconds()),
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33134 first_time_in_sync_(-1) {}
pbos@webrtc.org1d096902013-12-13 12:48:05135
136 virtual void RenderFrame(const I420VideoFrame& video_frame,
137 int time_to_render_ms) OVERRIDE {
138 int64_t now_ms = clock_->TimeInMilliseconds();
139 uint32_t playout_timestamp = 0;
140 if (voe_sync_->GetPlayoutTimestamp(voe_channel_, playout_timestamp) != 0)
141 return;
142 int64_t latest_audio_ntp =
143 audio_observer_->RtpTimestampToNtp(playout_timestamp);
144 int64_t latest_video_ntp = RtpTimestampToNtp(video_frame.timestamp());
145 if (latest_audio_ntp < 0 || latest_video_ntp < 0)
146 return;
147 int time_until_render_ms =
148 std::max(0, static_cast<int>(video_frame.render_time_ms() - now_ms));
149 latest_video_ntp += time_until_render_ms;
150 int64_t stream_offset = latest_audio_ntp - latest_video_ntp;
151 std::stringstream ss;
152 ss << stream_offset;
henrik.lundin@webrtc.orged865b52014-03-06 10:28:07153 webrtc::test::PrintResult("stream_offset",
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33154 "",
henrik.lundin@webrtc.orged865b52014-03-06 10:28:07155 "synchronization",
156 ss.str(),
157 "ms",
158 false);
pbos@webrtc.org1d096902013-12-13 12:48:05159 int64_t time_since_creation = now_ms - creation_time_ms_;
160 // During the first couple of seconds audio and video can falsely be
161 // estimated as being synchronized. We don't want to trigger on those.
162 if (time_since_creation < kStartupTimeMs)
163 return;
pbos@webrtc.orgb5f30292014-03-13 08:53:39164 if (std::abs(latest_audio_ntp - latest_video_ntp) < kInSyncThresholdMs) {
pbos@webrtc.org1d096902013-12-13 12:48:05165 if (first_time_in_sync_ == -1) {
166 first_time_in_sync_ = now_ms;
167 webrtc::test::PrintResult("sync_convergence_time",
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33168 "",
pbos@webrtc.org1d096902013-12-13 12:48:05169 "synchronization",
170 time_since_creation,
171 "ms",
172 false);
173 }
174 if (time_since_creation > kMinRunTimeMs)
175 observation_complete_->Set();
176 }
177 }
178
179 private:
pbos@webrtc.orgde1429e2014-04-28 13:00:21180 Clock* const clock_;
pbos@webrtc.org1d096902013-12-13 12:48:05181 int voe_channel_;
182 VoEVideoSync* voe_sync_;
183 SyncRtcpObserver* audio_observer_;
184 int64_t creation_time_ms_;
185 int64_t first_time_in_sync_;
186};
187
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33188TEST_F(CallPerfTest, PlaysOutAudioAndVideoInSync) {
pbos@webrtc.org994d0b72014-06-27 08:47:52189 class AudioPacketReceiver : public PacketReceiver {
190 public:
191 AudioPacketReceiver(int channel, VoENetwork* voe_network)
192 : channel_(channel),
193 voe_network_(voe_network),
194 parser_(RtpHeaderParser::Create()) {}
195 virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
196 size_t length) OVERRIDE {
197 int ret;
198 if (parser_->IsRtcp(packet, static_cast<int>(length))) {
199 ret = voe_network_->ReceivedRTCPPacket(
200 channel_, packet, static_cast<unsigned int>(length));
201 } else {
202 ret = voe_network_->ReceivedRTPPacket(
203 channel_, packet, static_cast<unsigned int>(length), PacketTime());
204 }
205 return ret == 0 ? DELIVERY_OK : DELIVERY_PACKET_ERROR;
206 }
207
208 private:
209 int channel_;
210 VoENetwork* voe_network_;
211 scoped_ptr<RtpHeaderParser> parser_;
212 };
213
pbos@webrtc.org1d096902013-12-13 12:48:05214 VoiceEngine* voice_engine = VoiceEngine::Create();
215 VoEBase* voe_base = VoEBase::GetInterface(voice_engine);
216 VoECodec* voe_codec = VoECodec::GetInterface(voice_engine);
217 VoENetwork* voe_network = VoENetwork::GetInterface(voice_engine);
218 VoEVideoSync* voe_sync = VoEVideoSync::GetInterface(voice_engine);
219 const std::string audio_filename =
220 test::ResourcePath("voice_engine/audio_long16", "pcm");
221 ASSERT_STRNE("", audio_filename.c_str());
222 test::FakeAudioDevice fake_audio_device(Clock::GetRealTimeClock(),
223 audio_filename);
224 EXPECT_EQ(0, voe_base->Init(&fake_audio_device, NULL));
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33225 int channel = voe_base->CreateChannel();
pbos@webrtc.org1d096902013-12-13 12:48:05226
stefan@webrtc.orgfaada6e2013-12-18 20:28:25227 FakeNetworkPipe::Config net_config;
228 net_config.queue_delay_ms = 500;
229 SyncRtcpObserver audio_observer(net_config);
henrik.lundin@webrtc.orged865b52014-03-06 10:28:07230 VideoRtcpAndSyncObserver observer(Clock::GetRealTimeClock(),
231 channel,
232 voe_sync,
henrik.lundin@webrtc.orgd144bb62014-04-22 08:36:33233 &audio_observer);
pbos@webrtc.org1d096902013-12-13 12:48:05234
235 Call::Config receiver_config(observer.ReceiveTransport());
236 receiver_config.voice_engine = voice_engine;
pbos@webrtc.org994d0b72014-06-27 08:47:52237 CreateCalls(Call::Config(observer.SendTransport()), receiver_config);
238
pbos@webrtc.org1d096902013-12-13 12:48:05239 CodecInst isac = {103, "ISAC", 16000, 480, 1, 32000};
240 EXPECT_EQ(0, voe_codec->SetSendCodec(channel, isac));
241
pbos@webrtc.org994d0b72014-06-27 08:47:52242 AudioPacketReceiver voe_packet_receiver(channel, voe_network);
pbos@webrtc.org1d096902013-12-13 12:48:05243 audio_observer.SetReceivers(&voe_packet_receiver, &voe_packet_receiver);
244
245 internal::TransportAdapter transport_adapter(audio_observer.SendTransport());
sprang@webrtc.orgd9b95602014-01-27 13:03:02246 transport_adapter.Enable();
pbos@webrtc.org1d096902013-12-13 12:48:05247 EXPECT_EQ(0,
248 voe_network->RegisterExternalTransport(channel, transport_adapter));
249
pbos@webrtc.org994d0b72014-06-27 08:47:52250 observer.SetReceivers(receiver_call_->Receiver(), sender_call_->Receiver());
pbos@webrtc.org1d096902013-12-13 12:48:05251
pbos@webrtc.org1d096902013-12-13 12:48:05252 test::FakeDecoder fake_decoder;
253
pbos@webrtc.org994d0b72014-06-27 08:47:52254 CreateSendConfig(1);
255 CreateMatchingReceiveConfigs();
pbos@webrtc.org1d096902013-12-13 12:48:05256
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09257 receive_configs_[0].renderer = &observer;
258 receive_configs_[0].audio_channel_id = channel;
pbos@webrtc.org1d096902013-12-13 12:48:05259
pbos@webrtc.org994d0b72014-06-27 08:47:52260 CreateStreams();
261
262 CreateFrameGeneratorCapturer();
263
264 Start();
pbos@webrtc.org1d096902013-12-13 12:48:05265
266 fake_audio_device.Start();
267 EXPECT_EQ(0, voe_base->StartPlayout(channel));
268 EXPECT_EQ(0, voe_base->StartReceive(channel));
269 EXPECT_EQ(0, voe_base->StartSend(channel));
270
271 EXPECT_EQ(kEventSignaled, observer.Wait())
272 << "Timed out while waiting for audio and video to be synchronized.";
273
274 EXPECT_EQ(0, voe_base->StopSend(channel));
275 EXPECT_EQ(0, voe_base->StopReceive(channel));
276 EXPECT_EQ(0, voe_base->StopPlayout(channel));
277 fake_audio_device.Stop();
278
pbos@webrtc.org994d0b72014-06-27 08:47:52279 Stop();
pbos@webrtc.org1d096902013-12-13 12:48:05280 observer.StopSending();
281 audio_observer.StopSending();
282
283 voe_base->DeleteChannel(channel);
284 voe_base->Release();
285 voe_codec->Release();
286 voe_network->Release();
287 voe_sync->Release();
pbos@webrtc.org994d0b72014-06-27 08:47:52288
289 DestroyStreams();
290
pbos@webrtc.org1d096902013-12-13 12:48:05291 VoiceEngine::Delete(voice_engine);
292}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07293
wu@webrtc.orgcd701192014-04-24 22:10:24294void CallPerfTest::TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config,
295 int threshold_ms,
296 int start_time_ms,
297 int run_time_ms) {
pbos@webrtc.org994d0b72014-06-27 08:47:52298 class CaptureNtpTimeObserver : public test::EndToEndTest,
299 public VideoRenderer {
300 public:
301 CaptureNtpTimeObserver(const FakeNetworkPipe::Config& config,
302 int threshold_ms,
303 int start_time_ms,
304 int run_time_ms)
305 : EndToEndTest(kLongTimeoutMs, config),
306 clock_(Clock::GetRealTimeClock()),
307 threshold_ms_(threshold_ms),
308 start_time_ms_(start_time_ms),
309 run_time_ms_(run_time_ms),
310 creation_time_ms_(clock_->TimeInMilliseconds()),
311 capturer_(NULL),
312 rtp_start_timestamp_set_(false),
313 rtp_start_timestamp_(0) {}
wu@webrtc.orgcd701192014-04-24 22:10:24314
pbos@webrtc.org994d0b72014-06-27 08:47:52315 private:
316 virtual void RenderFrame(const I420VideoFrame& video_frame,
317 int time_to_render_ms) OVERRIDE {
318 if (video_frame.ntp_time_ms() <= 0) {
319 // Haven't got enough RTCP SR in order to calculate the capture ntp
320 // time.
321 return;
322 }
wu@webrtc.orgcd701192014-04-24 22:10:24323
pbos@webrtc.org994d0b72014-06-27 08:47:52324 int64_t now_ms = clock_->TimeInMilliseconds();
325 int64_t time_since_creation = now_ms - creation_time_ms_;
326 if (time_since_creation < start_time_ms_) {
327 // Wait for |start_time_ms_| before start measuring.
328 return;
329 }
wu@webrtc.orgcd701192014-04-24 22:10:24330
pbos@webrtc.org994d0b72014-06-27 08:47:52331 if (time_since_creation > run_time_ms_) {
332 observation_complete_->Set();
333 }
wu@webrtc.orgcd701192014-04-24 22:10:24334
pbos@webrtc.org994d0b72014-06-27 08:47:52335 FrameCaptureTimeList::iterator iter =
336 capture_time_list_.find(video_frame.timestamp());
337 EXPECT_TRUE(iter != capture_time_list_.end());
wu@webrtc.orgcd701192014-04-24 22:10:24338
pbos@webrtc.org994d0b72014-06-27 08:47:52339 // The real capture time has been wrapped to uint32_t before converted
340 // to rtp timestamp in the sender side. So here we convert the estimated
341 // capture time to a uint32_t 90k timestamp also for comparing.
342 uint32_t estimated_capture_timestamp =
343 90 * static_cast<uint32_t>(video_frame.ntp_time_ms());
344 uint32_t real_capture_timestamp = iter->second;
345 int time_offset_ms = real_capture_timestamp - estimated_capture_timestamp;
346 time_offset_ms = time_offset_ms / 90;
347 std::stringstream ss;
348 ss << time_offset_ms;
wu@webrtc.orgcd701192014-04-24 22:10:24349
pbos@webrtc.org994d0b72014-06-27 08:47:52350 webrtc::test::PrintResult(
351 "capture_ntp_time", "", "real - estimated", ss.str(), "ms", true);
352 EXPECT_TRUE(std::abs(time_offset_ms) < threshold_ms_);
353 }
wu@webrtc.orgcd701192014-04-24 22:10:24354
pbos@webrtc.org994d0b72014-06-27 08:47:52355 virtual Action OnSendRtp(const uint8_t* packet, size_t length) {
356 RTPHeader header;
357 EXPECT_TRUE(parser_->Parse(packet, static_cast<int>(length), &header));
358
359 if (!rtp_start_timestamp_set_) {
360 // Calculate the rtp timestamp offset in order to calculate the real
361 // capture time.
362 uint32_t first_capture_timestamp =
363 90 * static_cast<uint32_t>(capturer_->first_frame_capture_time());
364 rtp_start_timestamp_ = header.timestamp - first_capture_timestamp;
365 rtp_start_timestamp_set_ = true;
366 }
367
368 uint32_t capture_timestamp = header.timestamp - rtp_start_timestamp_;
369 capture_time_list_.insert(
370 capture_time_list_.end(),
371 std::make_pair(header.timestamp, capture_timestamp));
372 return SEND_PACKET;
373 }
374
375 virtual void OnFrameGeneratorCapturerCreated(
376 test::FrameGeneratorCapturer* frame_generator_capturer) OVERRIDE {
377 capturer_ = frame_generator_capturer;
378 }
379
380 virtual void ModifyConfigs(
381 VideoSendStream::Config* send_config,
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09382 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.org994d0b72014-06-27 08:47:52383 std::vector<VideoStream>* video_streams) OVERRIDE {
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09384 (*receive_configs)[0].renderer = this;
pbos@webrtc.org994d0b72014-06-27 08:47:52385 // Enable the receiver side rtt calculation.
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09386 (*receive_configs)[0].rtp.rtcp_xr.receiver_reference_time_report = true;
pbos@webrtc.org994d0b72014-06-27 08:47:52387 }
388
389 virtual void PerformTest() OVERRIDE {
390 EXPECT_EQ(kEventSignaled, Wait()) << "Timed out while waiting for "
391 "estimated capture NTP time to be "
392 "within bounds.";
393 }
394
395 Clock* clock_;
396 int threshold_ms_;
397 int start_time_ms_;
398 int run_time_ms_;
399 int64_t creation_time_ms_;
400 test::FrameGeneratorCapturer* capturer_;
401 bool rtp_start_timestamp_set_;
402 uint32_t rtp_start_timestamp_;
403 typedef std::map<uint32_t, uint32_t> FrameCaptureTimeList;
404 FrameCaptureTimeList capture_time_list_;
405 } test(net_config, threshold_ms, start_time_ms, run_time_ms);
406
407 RunBaseTest(&test);
wu@webrtc.orgcd701192014-04-24 22:10:24408}
409
wu@webrtc.org9aa7d8d2014-05-29 05:03:52410TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkDelay) {
wu@webrtc.orgcd701192014-04-24 22:10:24411 FakeNetworkPipe::Config net_config;
412 net_config.queue_delay_ms = 100;
413 // TODO(wu): lower the threshold as the calculation/estimatation becomes more
414 // accurate.
wu@webrtc.org9aa7d8d2014-05-29 05:03:52415 const int kThresholdMs = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24416 const int kStartTimeMs = 10000;
417 const int kRunTimeMs = 20000;
418 TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs);
419}
420
wu@webrtc.org0224c202014-05-05 17:42:43421TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkJitter) {
wu@webrtc.orgcd701192014-04-24 22:10:24422 FakeNetworkPipe::Config net_config;
wu@webrtc.org0224c202014-05-05 17:42:43423 net_config.queue_delay_ms = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24424 net_config.delay_standard_deviation_ms = 10;
425 // TODO(wu): lower the threshold as the calculation/estimatation becomes more
426 // accurate.
wu@webrtc.org0224c202014-05-05 17:42:43427 const int kThresholdMs = 100;
wu@webrtc.orgcd701192014-04-24 22:10:24428 const int kStartTimeMs = 10000;
429 const int kRunTimeMs = 20000;
430 TestCaptureNtpTime(net_config, kThresholdMs, kStartTimeMs, kRunTimeMs);
431}
432
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07433TEST_F(CallPerfTest, RegisterCpuOveruseObserver) {
434 // Verifies that either a normal or overuse callback is triggered.
pbos@webrtc.org994d0b72014-06-27 08:47:52435 class OveruseCallbackObserver : public test::SendTest,
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07436 public webrtc::OveruseCallback {
437 public:
pbos@webrtc.org994d0b72014-06-27 08:47:52438 OveruseCallbackObserver() : SendTest(kLongTimeoutMs) {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07439
440 virtual void OnOveruse() OVERRIDE {
441 observation_complete_->Set();
442 }
pbos@webrtc.org994d0b72014-06-27 08:47:52443
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07444 virtual void OnNormalUse() OVERRIDE {
445 observation_complete_->Set();
446 }
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07447
pbos@webrtc.org994d0b72014-06-27 08:47:52448 virtual Call::Config GetSenderCallConfig() OVERRIDE {
449 Call::Config config(SendTransport());
450 config.overuse_callback = this;
451 return config;
452 }
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07453
pbos@webrtc.org994d0b72014-06-27 08:47:52454 virtual void PerformTest() OVERRIDE {
455 EXPECT_EQ(kEventSignaled, Wait())
456 << "Timed out before receiving an overuse callback.";
457 }
458 } test;
459
460 RunBaseTest(&test);
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07461}
pbos@webrtc.org3349ae02014-03-13 12:52:27462
463void CallPerfTest::TestMinTransmitBitrate(bool pad_to_min_bitrate) {
464 static const int kMaxEncodeBitrateKbps = 30;
pbos@webrtc.org709e2972014-03-19 10:59:52465 static const int kMinTransmitBitrateBps = 150000;
pbos@webrtc.org3349ae02014-03-13 12:52:27466 static const int kMinAcceptableTransmitBitrate = 130;
467 static const int kMaxAcceptableTransmitBitrate = 170;
468 static const int kNumBitrateObservationsInRange = 100;
pbos@webrtc.org994d0b72014-06-27 08:47:52469 class BitrateObserver : public test::EndToEndTest, public PacketReceiver {
pbos@webrtc.org3349ae02014-03-13 12:52:27470 public:
471 explicit BitrateObserver(bool using_min_transmit_bitrate)
pbos@webrtc.org994d0b72014-06-27 08:47:52472 : EndToEndTest(kLongTimeoutMs),
pbos@webrtc.org3349ae02014-03-13 12:52:27473 send_stream_(NULL),
474 send_transport_receiver_(NULL),
pbos@webrtc.org994d0b72014-06-27 08:47:52475 pad_to_min_bitrate_(using_min_transmit_bitrate),
pbos@webrtc.org3349ae02014-03-13 12:52:27476 num_bitrate_observations_in_range_(0) {}
477
pbos@webrtc.org994d0b72014-06-27 08:47:52478 private:
pbos@webrtc.org3349ae02014-03-13 12:52:27479 virtual void SetReceivers(PacketReceiver* send_transport_receiver,
480 PacketReceiver* receive_transport_receiver)
481 OVERRIDE {
482 send_transport_receiver_ = send_transport_receiver;
483 test::RtpRtcpObserver::SetReceivers(this, receive_transport_receiver);
484 }
485
pbos@webrtc.orgcaba2d22014-05-14 13:57:12486 virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
487 size_t length) OVERRIDE {
pbos@webrtc.org3349ae02014-03-13 12:52:27488 VideoSendStream::Stats stats = send_stream_->GetStats();
489 if (stats.substreams.size() > 0) {
490 assert(stats.substreams.size() == 1);
491 int bitrate_kbps = stats.substreams.begin()->second.bitrate_bps / 1000;
492 if (bitrate_kbps > 0) {
493 test::PrintResult(
494 "bitrate_stats_",
pbos@webrtc.org994d0b72014-06-27 08:47:52495 (pad_to_min_bitrate_ ? "min_transmit_bitrate"
496 : "without_min_transmit_bitrate"),
pbos@webrtc.org3349ae02014-03-13 12:52:27497 "bitrate_kbps",
498 static_cast<size_t>(bitrate_kbps),
499 "kbps",
500 false);
pbos@webrtc.org994d0b72014-06-27 08:47:52501 if (pad_to_min_bitrate_) {
pbos@webrtc.org3349ae02014-03-13 12:52:27502 if (bitrate_kbps > kMinAcceptableTransmitBitrate &&
503 bitrate_kbps < kMaxAcceptableTransmitBitrate) {
504 ++num_bitrate_observations_in_range_;
505 }
506 } else {
507 // Expect bitrate stats to roughly match the max encode bitrate.
508 if (bitrate_kbps > kMaxEncodeBitrateKbps - 5 &&
509 bitrate_kbps < kMaxEncodeBitrateKbps + 5) {
510 ++num_bitrate_observations_in_range_;
511 }
512 }
513 if (num_bitrate_observations_in_range_ ==
514 kNumBitrateObservationsInRange)
515 observation_complete_->Set();
516 }
517 }
518 return send_transport_receiver_->DeliverPacket(packet, length);
519 }
520
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09521 virtual void OnStreamsCreated(
522 VideoSendStream* send_stream,
523 const std::vector<VideoReceiveStream*>& receive_streams) OVERRIDE {
pbos@webrtc.org994d0b72014-06-27 08:47:52524 send_stream_ = send_stream;
525 }
526
527 virtual void ModifyConfigs(
528 VideoSendStream::Config* send_config,
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09529 std::vector<VideoReceiveStream::Config>* receive_configs,
pbos@webrtc.org994d0b72014-06-27 08:47:52530 std::vector<VideoStream>* video_streams) OVERRIDE {
531 if (pad_to_min_bitrate_) {
532 send_config->rtp.min_transmit_bitrate_bps = kMinTransmitBitrateBps;
533 } else {
534 assert(send_config->rtp.min_transmit_bitrate_bps == 0);
535 }
536 }
537
538 virtual void PerformTest() OVERRIDE {
539 EXPECT_EQ(kEventSignaled, Wait())
540 << "Timeout while waiting for send-bitrate stats.";
541 }
542
pbos@webrtc.org3349ae02014-03-13 12:52:27543 VideoSendStream* send_stream_;
544 PacketReceiver* send_transport_receiver_;
pbos@webrtc.org994d0b72014-06-27 08:47:52545 const bool pad_to_min_bitrate_;
pbos@webrtc.org3349ae02014-03-13 12:52:27546 int num_bitrate_observations_in_range_;
pbos@webrtc.org994d0b72014-06-27 08:47:52547 } test(pad_to_min_bitrate);
pbos@webrtc.org3349ae02014-03-13 12:52:27548
pbos@webrtc.org3349ae02014-03-13 12:52:27549 fake_encoder_.SetMaxBitrate(kMaxEncodeBitrateKbps);
pbos@webrtc.org994d0b72014-06-27 08:47:52550 RunBaseTest(&test);
pbos@webrtc.org3349ae02014-03-13 12:52:27551}
552
553TEST_F(CallPerfTest, PadsToMinTransmitBitrate) { TestMinTransmitBitrate(true); }
554
555TEST_F(CallPerfTest, NoPadWithoutMinTransmitBitrate) {
556 TestMinTransmitBitrate(false);
557}
558
pbos@webrtc.org1d096902013-12-13 12:48:05559} // namespace webrtc