blob: 4284bee87607ecbd3a8bb402da3d91a29c30d3d2 [file] [log] [blame]
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +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 */
10#include <stdio.h>
11
12#include <deque>
13#include <map>
14
pbos@webrtc.org69215d82013-07-10 15:02:02 +000015#include "testing/gtest/include/gtest/gtest.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000016
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.org16e03b72013-10-28 16:32:01 +000019#include "webrtc/call.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000020#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
21#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
22#include "webrtc/system_wrappers/interface/clock.h"
sprang@webrtc.org131bea82015-02-18 12:46:06 +000023#include "webrtc/system_wrappers/interface/cpu_info.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000024#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
25#include "webrtc/system_wrappers/interface/event_wrapper.h"
pbos@webrtc.org94015242013-10-16 11:05:37 +000026#include "webrtc/system_wrappers/interface/sleep.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000027#include "webrtc/test/call_test.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000028#include "webrtc/test/direct_transport.h"
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000029#include "webrtc/test/encoder_settings.h"
30#include "webrtc/test/fake_encoder.h"
sprang@webrtc.org131bea82015-02-18 12:46:06 +000031#include "webrtc/test/frame_generator.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000032#include "webrtc/test/frame_generator_capturer.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000033#include "webrtc/test/statistics.h"
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000034#include "webrtc/test/testsupport/fileutils.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000035#include "webrtc/typedefs.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000036
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000037namespace webrtc {
38
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +000039static const int kFullStackTestDurationSecs = 60;
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +000040
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000041struct FullStackTestParams {
42 const char* test_label;
43 struct {
44 const char* name;
pbos@webrtc.orgf3f13582013-07-09 14:04:46 +000045 size_t width, height;
46 int fps;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000047 } clip;
sprang@webrtc.org131bea82015-02-18 12:46:06 +000048 bool screenshare;
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +000049 int min_bitrate_bps;
50 int target_bitrate_bps;
51 int max_bitrate_bps;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000052 double avg_psnr_threshold;
53 double avg_ssim_threshold;
sprang@webrtc.org131bea82015-02-18 12:46:06 +000054 int test_durations_secs;
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +000055 FakeNetworkPipe::Config link;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000056};
57
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000058class FullStackTest : public test::CallTest {
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000059 protected:
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +000060 void RunTest(const FullStackTestParams& params);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000061};
62
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000063class VideoAnalyzer : public PacketReceiver,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000064 public newapi::Transport,
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000065 public VideoRenderer,
66 public VideoSendStreamInput {
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000067 public:
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000068 VideoAnalyzer(VideoSendStreamInput* input,
69 Transport* transport,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000070 const char* test_label,
71 double avg_psnr_threshold,
72 double avg_ssim_threshold,
pbos@webrtc.org94015242013-10-16 11:05:37 +000073 int duration_frames)
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000074 : input_(input),
75 transport_(transport),
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000076 receiver_(nullptr),
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000077 test_label_(test_label),
sprang@webrtc.org131bea82015-02-18 12:46:06 +000078 frames_to_process_(duration_frames),
79 frames_recorded_(0),
80 frames_processed_(0),
pbos@webrtc.org94015242013-10-16 11:05:37 +000081 dropped_frames_(0),
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000082 last_render_time_(0),
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000083 rtp_timestamp_delta_(0),
84 crit_(CriticalSectionWrapper::CreateCriticalSection()),
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000085 avg_psnr_threshold_(avg_psnr_threshold),
86 avg_ssim_threshold_(avg_ssim_threshold),
pbos@webrtc.org94015242013-10-16 11:05:37 +000087 comparison_lock_(CriticalSectionWrapper::CreateCriticalSection()),
sprang@webrtc.org131bea82015-02-18 12:46:06 +000088 comparison_available_event_(EventWrapper::Create()),
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000089 done_(EventWrapper::Create()) {
sprang@webrtc.org131bea82015-02-18 12:46:06 +000090 // Create thread pool for CPU-expensive PSNR/SSIM calculations.
91
92 // Try to use about as many threads as cores, but leave kMinCoresLeft alone,
93 // so that we don't accidentally starve "real" worker threads (codec etc).
94 // Also, don't allocate more than kMaxComparisonThreads, even if there are
95 // spare cores.
96
97 uint32_t num_cores = CpuInfo::DetectNumberOfCores();
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +000098 DCHECK_GE(num_cores, 1u);
sprang@webrtc.org131bea82015-02-18 12:46:06 +000099 static const uint32_t kMinCoresLeft = 4;
sprang@webrtc.org343096a2015-02-23 08:34:17 +0000100 static const uint32_t kMaxComparisonThreads = 8;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000101
102 if (num_cores <= kMinCoresLeft) {
103 num_cores = 1;
104 } else {
105 num_cores -= kMinCoresLeft;
106 num_cores = std::min(num_cores, kMaxComparisonThreads);
107 }
108
109 for (uint32_t i = 0; i < num_cores; ++i) {
tommi@webrtc.org361981f2015-03-19 14:44:18 +0000110 rtc::scoped_ptr<ThreadWrapper> thread =
tommi@webrtc.org38492c52015-03-22 14:41:46 +0000111 ThreadWrapper::CreateThread(&FrameComparisonThread, this, "Analyzer");
pbos@webrtc.org86639732015-03-13 00:06:21 +0000112 EXPECT_TRUE(thread->Start());
tommi@webrtc.org361981f2015-03-19 14:44:18 +0000113 comparison_thread_pool_.push_back(thread.release());
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000114 }
pbos@webrtc.org94015242013-10-16 11:05:37 +0000115 }
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000116
117 ~VideoAnalyzer() {
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000118 for (ThreadWrapper* thread : comparison_thread_pool_) {
119 EXPECT_TRUE(thread->Stop());
120 delete thread;
121 }
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000122 }
123
pbos@webrtc.org94015242013-10-16 11:05:37 +0000124 virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; }
125
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200126 DeliveryStatus DeliverPacket(MediaType media_type, const uint8_t* packet,
127 size_t length) override {
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000128 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000129 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000130 parser->Parse(packet, length, &header);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000131 {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000132 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000133 recv_times_[header.timestamp - rtp_timestamp_delta_] =
134 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
135 }
136
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200137 return receiver_->DeliverPacket(media_type, packet, length);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000138 }
139
perkj@webrtc.orgaf612d52015-03-18 09:51:05 +0000140 void IncomingCapturedFrame(const I420VideoFrame& video_frame) override {
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000141 I420VideoFrame copy = video_frame;
142 copy.set_timestamp(copy.ntp_time_ms() * 90);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000143
144 {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000145 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000146 if (first_send_frame_.IsZeroSize() && rtp_timestamp_delta_ == 0)
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000147 first_send_frame_ = copy;
148
149 frames_.push_back(copy);
150 }
151
perkj@webrtc.orgaf612d52015-03-18 09:51:05 +0000152 input_->IncomingCapturedFrame(video_frame);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000153 }
154
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000155 bool SendRtp(const uint8_t* packet, size_t length) override {
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000156 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000157 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000158 parser->Parse(packet, length, &header);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000159
160 {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000161 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000162 if (rtp_timestamp_delta_ == 0) {
163 rtp_timestamp_delta_ =
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000164 header.timestamp - first_send_frame_.timestamp();
165 first_send_frame_.Reset();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000166 }
pbos@webrtc.org7fb9ce02013-08-05 09:29:50 +0000167 send_times_[header.timestamp - rtp_timestamp_delta_] =
168 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000169 }
170
pbos@webrtc.org27326b62013-11-20 12:17:04 +0000171 return transport_->SendRtp(packet, length);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000172 }
173
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000174 bool SendRtcp(const uint8_t* packet, size_t length) override {
pbos@webrtc.org27326b62013-11-20 12:17:04 +0000175 return transport_->SendRtcp(packet, length);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000176 }
177
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000178 void RenderFrame(const I420VideoFrame& video_frame,
179 int time_to_render_ms) override {
pbos@webrtc.org94015242013-10-16 11:05:37 +0000180 int64_t render_time_ms =
181 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000182 uint32_t send_timestamp = video_frame.timestamp() - rtp_timestamp_delta_;
183
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000184 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000185
186 while (frames_.front().timestamp() < send_timestamp) {
187 AddFrameComparison(frames_.front(), last_rendered_frame_, true,
188 render_time_ms);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000189 frames_.pop_front();
pbos@webrtc.org94015242013-10-16 11:05:37 +0000190 }
191
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000192 I420VideoFrame reference_frame = frames_.front();
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000193 frames_.pop_front();
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000194 assert(!reference_frame.IsZeroSize());
195 EXPECT_EQ(reference_frame.timestamp(), send_timestamp);
196 assert(reference_frame.timestamp() == send_timestamp);
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000197
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000198 AddFrameComparison(reference_frame, video_frame, false, render_time_ms);
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000199
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000200 last_rendered_frame_ = video_frame;
pbos@webrtc.org94015242013-10-16 11:05:37 +0000201 }
202
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000203 bool IsTextureSupported() const override { return false; }
pbos@webrtc.org0d852d52015-02-09 15:14:36 +0000204
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000205 void Wait() {
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000206 // Frame comparisons can be very expensive. Wait for test to be done, but
207 // at time-out check if frames_processed is going up. If so, give it more
208 // time, otherwise fail. Hopefully this will reduce test flakiness.
209
210 int last_frames_processed = -1;
211 EventTypeWrapper eventType;
212 while ((eventType = done_->Wait(FullStackTest::kDefaultTimeoutMs)) !=
213 kEventSignaled) {
214 int frames_processed;
215 {
216 CriticalSectionScoped crit(comparison_lock_.get());
217 frames_processed = frames_processed_;
218 }
219 if (last_frames_processed == -1) {
220 last_frames_processed = frames_processed;
221 continue;
222 }
223 ASSERT_GT(frames_processed, last_frames_processed)
224 << "Analyzer stalled while waiting for test to finish.";
225 last_frames_processed = frames_processed;
226 }
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000227 }
pbos@webrtc.org94015242013-10-16 11:05:37 +0000228
229 VideoSendStreamInput* input_;
230 Transport* transport_;
231 PacketReceiver* receiver_;
232
233 private:
234 struct FrameComparison {
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000235 FrameComparison()
236 : dropped(false), send_time_ms(0), recv_time_ms(0), render_time_ms(0) {}
237
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000238 FrameComparison(const I420VideoFrame& reference,
239 const I420VideoFrame& render,
pbos@webrtc.org94015242013-10-16 11:05:37 +0000240 bool dropped,
241 int64_t send_time_ms,
242 int64_t recv_time_ms,
243 int64_t render_time_ms)
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000244 : reference(reference),
245 render(render),
246 dropped(dropped),
pbos@webrtc.org94015242013-10-16 11:05:37 +0000247 send_time_ms(send_time_ms),
248 recv_time_ms(recv_time_ms),
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000249 render_time_ms(render_time_ms) {}
pbos@webrtc.org94015242013-10-16 11:05:37 +0000250
251 I420VideoFrame reference;
252 I420VideoFrame render;
253 bool dropped;
254 int64_t send_time_ms;
255 int64_t recv_time_ms;
256 int64_t render_time_ms;
257 };
258
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000259 void AddFrameComparison(const I420VideoFrame& reference,
260 const I420VideoFrame& render,
pbos@webrtc.org94015242013-10-16 11:05:37 +0000261 bool dropped,
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000262 int64_t render_time_ms)
263 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000264 int64_t send_time_ms = send_times_[reference.timestamp()];
265 send_times_.erase(reference.timestamp());
266 int64_t recv_time_ms = recv_times_[reference.timestamp()];
267 recv_times_.erase(reference.timestamp());
pbos@webrtc.org94015242013-10-16 11:05:37 +0000268
269 CriticalSectionScoped crit(comparison_lock_.get());
270 comparisons_.push_back(FrameComparison(reference,
271 render,
272 dropped,
273 send_time_ms,
274 recv_time_ms,
275 render_time_ms));
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000276 comparison_available_event_->Set();
pbos@webrtc.org94015242013-10-16 11:05:37 +0000277 }
278
279 static bool FrameComparisonThread(void* obj) {
280 return static_cast<VideoAnalyzer*>(obj)->CompareFrames();
281 }
282
283 bool CompareFrames() {
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000284 if (AllFramesRecorded())
285 return false;
pbos@webrtc.org94015242013-10-16 11:05:37 +0000286
287 I420VideoFrame reference;
288 I420VideoFrame render;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000289 FrameComparison comparison;
pbos@webrtc.org94015242013-10-16 11:05:37 +0000290
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000291 if (!PopComparison(&comparison)) {
292 // Wait until new comparison task is available, or test is done.
293 // If done, wake up remaining threads waiting.
294 comparison_available_event_->Wait(1000);
295 if (AllFramesRecorded()) {
296 comparison_available_event_->Set();
pbos@webrtc.org94015242013-10-16 11:05:37 +0000297 return false;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000298 }
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000299 return true; // Try again.
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000300 }
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000301
302 PerformFrameComparison(comparison);
303
304 if (FrameProcessed()) {
305 PrintResults();
306 done_->Set();
307 comparison_available_event_->Set();
308 return false;
309 }
310
311 return true;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000312 }
313
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000314 bool PopComparison(FrameComparison* comparison) {
315 CriticalSectionScoped crit(comparison_lock_.get());
316 // If AllFramesRecorded() is true, it means we have already popped
317 // frames_to_process_ frames from comparisons_, so there is no more work
318 // for this thread to be done. frames_processed_ might still be lower if
319 // all comparisons are not done, but those frames are currently being
320 // worked on by other threads.
321 if (comparisons_.empty() || AllFramesRecorded())
322 return false;
323
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000324 *comparison = comparisons_.front();
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000325 comparisons_.pop_front();
326
327 FrameRecorded();
328 return true;
329 }
330
331 // Increment counter for number of frames received for comparison.
332 void FrameRecorded() {
333 CriticalSectionScoped crit(comparison_lock_.get());
334 ++frames_recorded_;
335 }
336
337 // Returns true if all frames to be compared have been taken from the queue.
338 bool AllFramesRecorded() {
339 CriticalSectionScoped crit(comparison_lock_.get());
340 assert(frames_recorded_ <= frames_to_process_);
341 return frames_recorded_ == frames_to_process_;
342 }
343
344 // Increase count of number of frames processed. Returns true if this was the
345 // last frame to be processed.
346 bool FrameProcessed() {
347 CriticalSectionScoped crit(comparison_lock_.get());
348 ++frames_processed_;
349 assert(frames_processed_ <= frames_to_process_);
350 return frames_processed_ == frames_to_process_;
351 }
352
353 void PrintResults() {
354 CriticalSectionScoped crit(comparison_lock_.get());
355 PrintResult("psnr", psnr_, " dB");
356 PrintResult("ssim", ssim_, "");
357 PrintResult("sender_time", sender_time_, " ms");
358 printf("RESULT dropped_frames: %s = %d frames\n", test_label_,
359 dropped_frames_);
360 PrintResult("receiver_time", receiver_time_, " ms");
361 PrintResult("total_delay_incl_network", end_to_end_, " ms");
362 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
363 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
364 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_);
365 }
366
367 void PerformFrameComparison(const FrameComparison& comparison) {
368 // Perform expensive psnr and ssim calculations while not holding lock.
magjed@webrtc.org2056ee32015-03-16 13:46:52 +0000369 double psnr = I420PSNR(&comparison.reference, &comparison.render);
370 double ssim = I420SSIM(&comparison.reference, &comparison.render);
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000371
372 CriticalSectionScoped crit(comparison_lock_.get());
373 psnr_.AddSample(psnr);
374 ssim_.AddSample(ssim);
375 if (comparison.dropped) {
pbos@webrtc.org94015242013-10-16 11:05:37 +0000376 ++dropped_frames_;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000377 return;
pbos@webrtc.org94015242013-10-16 11:05:37 +0000378 }
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000379 if (last_render_time_ != 0)
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000380 rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_);
381 last_render_time_ = comparison.render_time_ms;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000382
perkj@webrtc.orgaf612d52015-03-18 09:51:05 +0000383 int64_t input_time_ms = comparison.reference.ntp_time_ms();
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000384 sender_time_.AddSample(comparison.send_time_ms - input_time_ms);
385 receiver_time_.AddSample(comparison.render_time_ms -
386 comparison.recv_time_ms);
387 end_to_end_.AddSample(comparison.render_time_ms - input_time_ms);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000388 }
389
390 void PrintResult(const char* result_type,
391 test::Statistics stats,
392 const char* unit) {
393 printf("RESULT %s: %s = {%f, %f}%s\n",
394 result_type,
395 test_label_,
396 stats.Mean(),
397 stats.StandardDeviation(),
398 unit);
399 }
400
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000401 const char* const test_label_;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000402 test::Statistics sender_time_;
403 test::Statistics receiver_time_;
404 test::Statistics psnr_;
405 test::Statistics ssim_;
406 test::Statistics end_to_end_;
407 test::Statistics rendered_delta_;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000408 const int frames_to_process_;
409 int frames_recorded_;
410 int frames_processed_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000411 int dropped_frames_;
412 int64_t last_render_time_;
413 uint32_t rtp_timestamp_delta_;
414
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000415 const rtc::scoped_ptr<CriticalSectionWrapper> crit_;
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000416 std::deque<I420VideoFrame> frames_ GUARDED_BY(crit_);
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000417 I420VideoFrame last_rendered_frame_ GUARDED_BY(crit_);
418 std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_);
419 std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_);
pbos@webrtc.org443ad402015-03-20 07:34:28 +0000420 I420VideoFrame first_send_frame_ GUARDED_BY(crit_);
pbos@webrtc.orgb35b1362014-10-20 09:14:38 +0000421 const double avg_psnr_threshold_;
422 const double avg_ssim_threshold_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000423
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000424 const rtc::scoped_ptr<CriticalSectionWrapper> comparison_lock_;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000425 std::vector<ThreadWrapper*> comparison_thread_pool_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000426 const rtc::scoped_ptr<EventWrapper> comparison_available_event_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000427 std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_);
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000428 const rtc::scoped_ptr<EventWrapper> done_;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000429};
430
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000431void FullStackTest::RunTest(const FullStackTestParams& params) {
432 test::DirectTransport send_transport(params.link);
433 test::DirectTransport recv_transport(params.link);
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000434 VideoAnalyzer analyzer(nullptr, &send_transport, params.test_label,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000435 params.avg_psnr_threshold, params.avg_ssim_threshold,
436 params.test_durations_secs * params.clip.fps);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000437
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000438 CreateCalls(Call::Config(&analyzer), Call::Config(&recv_transport));
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000439
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000440 analyzer.SetReceiver(receiver_call_->Receiver());
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000441 send_transport.SetReceiver(&analyzer);
442 recv_transport.SetReceiver(sender_call_->Receiver());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000443
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000444 CreateSendConfig(1);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000445
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000446 rtc::scoped_ptr<VideoEncoder> encoder(
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000447 VideoEncoder::Create(VideoEncoder::kVp8));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000448 send_config_.encoder_settings.encoder = encoder.get();
449 send_config_.encoder_settings.payload_name = "VP8";
450 send_config_.encoder_settings.payload_type = 124;
stefan@webrtc.orgc216b9a2014-10-14 10:38:49 +0000451 send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000452 send_config_.rtp.rtx.ssrcs.push_back(kSendRtxSsrcs[0]);
453 send_config_.rtp.rtx.payload_type = kSendRtxPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000454
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000455 VideoStream* stream = &encoder_config_.streams[0];
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000456 stream->width = params.clip.width;
457 stream->height = params.clip.height;
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000458 stream->min_bitrate_bps = params.min_bitrate_bps;
459 stream->target_bitrate_bps = params.target_bitrate_bps;
460 stream->max_bitrate_bps = params.max_bitrate_bps;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000461 stream->max_framerate = params.clip.fps;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000462
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000463 if (params.screenshare) {
Erik Språng143cec12015-04-28 10:01:41 +0200464 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000465 encoder_config_.min_transmit_bitrate_bps = 400 * 1000;
466 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
467 vp8_settings.denoisingOn = false;
468 vp8_settings.frameDroppingOn = false;
469 vp8_settings.numberOfTemporalLayers = 2;
470 encoder_config_.encoder_specific_settings = &vp8_settings;
471
472 stream->temporal_layer_thresholds_bps.clear();
473 stream->temporal_layer_thresholds_bps.push_back(stream->target_bitrate_bps);
474 }
475
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000476 CreateMatchingReceiveConfigs();
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000477 receive_configs_[0].renderer = &analyzer;
stefan@webrtc.orgc216b9a2014-10-14 10:38:49 +0000478 receive_configs_[0].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000479 receive_configs_[0].rtp.rtx[kSendRtxPayloadType].ssrc = kSendRtxSsrcs[0];
480 receive_configs_[0].rtp.rtx[kSendRtxPayloadType].payload_type =
sprang@webrtc.org343096a2015-02-23 08:34:17 +0000481 kSendRtxPayloadType;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000482
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000483 CreateStreams();
484 analyzer.input_ = send_stream_->Input();
485
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000486 if (params.screenshare) {
487 std::vector<std::string> slides;
488 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
489 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
490 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
491 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000492
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000493 rtc::scoped_ptr<test::FrameGenerator> frame_generator(
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000494 test::FrameGenerator::CreateFromYuvFile(
495 slides, 1850, 1110,
496 10 * params.clip.fps) // Cycle image every 10 seconds.
497 );
498 frame_generator_capturer_.reset(new test::FrameGeneratorCapturer(
499 Clock::GetRealTimeClock(), &analyzer, frame_generator.release(),
500 params.clip.fps));
501 ASSERT_TRUE(frame_generator_capturer_->Init());
502 } else {
503 frame_generator_capturer_.reset(
504 test::FrameGeneratorCapturer::CreateFromYuvFile(
505 &analyzer, test::ResourcePath(params.clip.name, "yuv"),
506 params.clip.width, params.clip.height, params.clip.fps,
507 Clock::GetRealTimeClock()));
508
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +0000509 ASSERT_TRUE(frame_generator_capturer_.get() != nullptr)
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000510 << "Could not create capturer for " << params.clip.name
511 << ".yuv. Is this resource file present?";
512 }
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000513
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000514 Start();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000515
516 analyzer.Wait();
517
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000518 send_transport.StopSending();
519 recv_transport.StopSending();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000520
521 Stop();
522
523 DestroyStreams();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000524}
525
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000526TEST_F(FullStackTest, ParisQcifWithoutPacketLoss) {
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000527 FullStackTestParams paris_qcif = {"net_delay_0_0_plr_0",
528 {"paris_qcif", 176, 144, 30},
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000529 false,
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000530 300000,
531 300000,
532 300000,
533 36.0,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000534 0.96,
535 kFullStackTestDurationSecs};
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000536 RunTest(paris_qcif);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000537}
538
539TEST_F(FullStackTest, ForemanCifWithoutPacketLoss) {
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000540 // TODO(pbos): Decide on psnr/ssim thresholds for foreman_cif.
541 FullStackTestParams foreman_cif = {"foreman_cif_net_delay_0_0_plr_0",
542 {"foreman_cif", 352, 288, 30},
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000543 false,
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000544 700000,
545 700000,
546 700000,
547 0.0,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000548 0.0,
549 kFullStackTestDurationSecs};
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000550 RunTest(foreman_cif);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000551}
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000552
sprang@webrtc.org343096a2015-02-23 08:34:17 +0000553TEST_F(FullStackTest, ForemanCifPlr5) {
stefan@webrtc.orgc216b9a2014-10-14 10:38:49 +0000554 FullStackTestParams foreman_cif = {"foreman_cif_delay_50_0_plr_5",
555 {"foreman_cif", 352, 288, 30},
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000556 false,
stefan@webrtc.orgc216b9a2014-10-14 10:38:49 +0000557 30000,
558 500000,
559 2000000,
560 0.0,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000561 0.0,
562 kFullStackTestDurationSecs};
stefan@webrtc.orgc216b9a2014-10-14 10:38:49 +0000563 foreman_cif.link.loss_percent = 5;
564 foreman_cif.link.queue_delay_ms = 50;
565 RunTest(foreman_cif);
566}
567
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000568TEST_F(FullStackTest, ForemanCif500kbps) {
569 FullStackTestParams foreman_cif = {"foreman_cif_500kbps",
570 {"foreman_cif", 352, 288, 30},
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000571 false,
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000572 30000,
573 500000,
574 2000000,
575 0.0,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000576 0.0,
577 kFullStackTestDurationSecs};
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000578 foreman_cif.link.queue_length_packets = 0;
579 foreman_cif.link.queue_delay_ms = 0;
580 foreman_cif.link.link_capacity_kbps = 500;
581 RunTest(foreman_cif);
582}
583
584TEST_F(FullStackTest, ForemanCif500kbpsLimitedQueue) {
585 FullStackTestParams foreman_cif = {"foreman_cif_500kbps_32pkts_queue",
586 {"foreman_cif", 352, 288, 30},
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000587 false,
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000588 30000,
589 500000,
590 2000000,
591 0.0,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000592 0.0,
593 kFullStackTestDurationSecs};
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000594 foreman_cif.link.queue_length_packets = 32;
595 foreman_cif.link.queue_delay_ms = 0;
596 foreman_cif.link.link_capacity_kbps = 500;
597 RunTest(foreman_cif);
598}
599
600TEST_F(FullStackTest, ForemanCif500kbps100ms) {
601 FullStackTestParams foreman_cif = {"foreman_cif_500kbps_100ms",
602 {"foreman_cif", 352, 288, 30},
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000603 false,
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000604 30000,
605 500000,
606 2000000,
607 0.0,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000608 0.0,
609 kFullStackTestDurationSecs};
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000610 foreman_cif.link.queue_length_packets = 0;
611 foreman_cif.link.queue_delay_ms = 100;
612 foreman_cif.link.link_capacity_kbps = 500;
613 RunTest(foreman_cif);
614}
615
616TEST_F(FullStackTest, ForemanCif500kbps100msLimitedQueue) {
617 FullStackTestParams foreman_cif = {"foreman_cif_500kbps_100ms_32pkts_queue",
618 {"foreman_cif", 352, 288, 30},
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000619 false,
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000620 30000,
621 500000,
622 2000000,
623 0.0,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000624 0.0,
625 kFullStackTestDurationSecs};
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000626 foreman_cif.link.queue_length_packets = 32;
627 foreman_cif.link.queue_delay_ms = 100;
628 foreman_cif.link.link_capacity_kbps = 500;
629 RunTest(foreman_cif);
630}
631
632TEST_F(FullStackTest, ForemanCif1000kbps100msLimitedQueue) {
633 FullStackTestParams foreman_cif = {"foreman_cif_1000kbps_100ms_32pkts_queue",
634 {"foreman_cif", 352, 288, 30},
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000635 false,
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000636 30000,
637 2000000,
638 2000000,
639 0.0,
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000640 0.0,
641 kFullStackTestDurationSecs};
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000642 foreman_cif.link.queue_length_packets = 32;
643 foreman_cif.link.queue_delay_ms = 100;
644 foreman_cif.link.link_capacity_kbps = 1000;
645 RunTest(foreman_cif);
646}
sprang@webrtc.org131bea82015-02-18 12:46:06 +0000647
648TEST_F(FullStackTest, ScreenshareSlides) {
649 FullStackTestParams screenshare_params = {
650 "screenshare_slides",
651 {"screenshare_slides", 1850, 1110, 5},
652 true,
653 50000,
654 100000,
655 1000000,
656 0.0,
657 0.0,
658 kFullStackTestDurationSecs};
659 RunTest(screenshare_params);
660}
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000661} // namespace webrtc