blob: 645906467362ed905199834e832fce22b0aa5e81 [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
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000017#include "webrtc/base/thread_annotations.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000018#include "webrtc/call.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000019#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
20#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
21#include "webrtc/system_wrappers/interface/clock.h"
22#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
23#include "webrtc/system_wrappers/interface/event_wrapper.h"
24#include "webrtc/system_wrappers/interface/scoped_ptr.h"
pbos@webrtc.org94015242013-10-16 11:05:37 +000025#include "webrtc/system_wrappers/interface/sleep.h"
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000026#include "webrtc/test/call_test.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000027#include "webrtc/test/direct_transport.h"
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000028#include "webrtc/test/encoder_settings.h"
29#include "webrtc/test/fake_encoder.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000030#include "webrtc/test/frame_generator_capturer.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000031#include "webrtc/test/statistics.h"
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +000032#include "webrtc/test/testsupport/fileutils.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000033#include "webrtc/typedefs.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000034
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000035namespace webrtc {
36
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +000037static const int kFullStackTestDurationSecs = 60;
pbos@webrtc.orgb613b5a2013-12-03 10:13:04 +000038
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000039struct FullStackTestParams {
40 const char* test_label;
41 struct {
42 const char* name;
pbos@webrtc.orgf3f13582013-07-09 14:04:46 +000043 size_t width, height;
44 int fps;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000045 } clip;
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +000046 int min_bitrate_bps;
47 int target_bitrate_bps;
48 int max_bitrate_bps;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000049 double avg_psnr_threshold;
50 double avg_ssim_threshold;
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +000051 FakeNetworkPipe::Config link;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000052};
53
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000054class FullStackTest : public test::CallTest {
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000055 protected:
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +000056 void RunTest(const FullStackTestParams& params);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000057};
58
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000059class VideoAnalyzer : public PacketReceiver,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000060 public newapi::Transport,
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000061 public VideoRenderer,
62 public VideoSendStreamInput {
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000063 public:
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000064 VideoAnalyzer(VideoSendStreamInput* input,
65 Transport* transport,
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000066 const char* test_label,
67 double avg_psnr_threshold,
68 double avg_ssim_threshold,
pbos@webrtc.org94015242013-10-16 11:05:37 +000069 int duration_frames)
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000070 : input_(input),
71 transport_(transport),
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000072 receiver_(NULL),
73 test_label_(test_label),
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000074 frames_left_(duration_frames),
pbos@webrtc.org94015242013-10-16 11:05:37 +000075 dropped_frames_(0),
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000076 last_render_time_(0),
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000077 rtp_timestamp_delta_(0),
78 crit_(CriticalSectionWrapper::CreateCriticalSection()),
79 first_send_frame_(NULL),
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000080 avg_psnr_threshold_(avg_psnr_threshold),
81 avg_ssim_threshold_(avg_ssim_threshold),
pbos@webrtc.org94015242013-10-16 11:05:37 +000082 comparison_lock_(CriticalSectionWrapper::CreateCriticalSection()),
83 comparison_thread_(ThreadWrapper::CreateThread(&FrameComparisonThread,
84 this)),
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +000085 done_(EventWrapper::Create()) {
pbos@webrtc.org94015242013-10-16 11:05:37 +000086 unsigned int id;
87 EXPECT_TRUE(comparison_thread_->Start(id));
88 }
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000089
90 ~VideoAnalyzer() {
pbos@webrtc.org94015242013-10-16 11:05:37 +000091 EXPECT_TRUE(comparison_thread_->Stop());
92
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +000093 while (!frames_.empty()) {
94 delete frames_.back();
95 frames_.pop_back();
96 }
97 while (!frame_pool_.empty()) {
98 delete frame_pool_.back();
99 frame_pool_.pop_back();
100 }
101 }
102
pbos@webrtc.org94015242013-10-16 11:05:37 +0000103 virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; }
104
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +0000105 virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
106 size_t length) OVERRIDE {
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000107 scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
108 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000109 parser->Parse(packet, length, &header);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000110 {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000111 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000112 recv_times_[header.timestamp - rtp_timestamp_delta_] =
113 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
114 }
115
116 return receiver_->DeliverPacket(packet, length);
117 }
118
pbos@webrtc.org724947b2013-12-11 16:26:16 +0000119 virtual void SwapFrame(I420VideoFrame* video_frame) OVERRIDE {
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000120 I420VideoFrame* copy = NULL;
121 {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000122 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000123 if (frame_pool_.size() > 0) {
124 copy = frame_pool_.front();
125 frame_pool_.pop_front();
126 }
127 }
128 if (copy == NULL)
129 copy = new I420VideoFrame();
130
pbos@webrtc.org724947b2013-12-11 16:26:16 +0000131 copy->CopyFrame(*video_frame);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000132 copy->set_timestamp(copy->render_time_ms() * 90);
133
134 {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000135 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000136 if (first_send_frame_ == NULL && rtp_timestamp_delta_ == 0)
137 first_send_frame_ = copy;
138
139 frames_.push_back(copy);
140 }
141
pbos@webrtc.org724947b2013-12-11 16:26:16 +0000142 input_->SwapFrame(video_frame);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000143 }
144
pbos@webrtc.org27326b62013-11-20 12:17:04 +0000145 virtual bool SendRtp(const uint8_t* packet, size_t length) OVERRIDE {
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000146 scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create());
147 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000148 parser->Parse(packet, length, &header);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000149
150 {
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000151 CriticalSectionScoped lock(crit_.get());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000152 if (rtp_timestamp_delta_ == 0) {
153 rtp_timestamp_delta_ =
154 header.timestamp - first_send_frame_->timestamp();
155 first_send_frame_ = NULL;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000156 }
pbos@webrtc.org7fb9ce02013-08-05 09:29:50 +0000157 send_times_[header.timestamp - rtp_timestamp_delta_] =
158 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000159 }
160
pbos@webrtc.org27326b62013-11-20 12:17:04 +0000161 return transport_->SendRtp(packet, length);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000162 }
163
pbos@webrtc.org27326b62013-11-20 12:17:04 +0000164 virtual bool SendRtcp(const uint8_t* packet, size_t length) OVERRIDE {
165 return transport_->SendRtcp(packet, length);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000166 }
167
168 virtual void RenderFrame(const I420VideoFrame& video_frame,
169 int time_to_render_ms) OVERRIDE {
pbos@webrtc.org94015242013-10-16 11:05:37 +0000170 int64_t render_time_ms =
171 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000172 uint32_t send_timestamp = video_frame.timestamp() - rtp_timestamp_delta_;
173
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000174 CriticalSectionScoped lock(crit_.get());
175 while (frames_.front()->timestamp() < send_timestamp) {
176 AddFrameComparison(
177 frames_.front(), &last_rendered_frame_, true, render_time_ms);
178 frame_pool_.push_back(frames_.front());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000179 frames_.pop_front();
pbos@webrtc.org94015242013-10-16 11:05:37 +0000180 }
181
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000182 I420VideoFrame* reference_frame = frames_.front();
183 frames_.pop_front();
184 assert(reference_frame != NULL);
185 EXPECT_EQ(reference_frame->timestamp(), send_timestamp);
186 assert(reference_frame->timestamp() == send_timestamp);
187
188 AddFrameComparison(reference_frame, &video_frame, false, render_time_ms);
189 frame_pool_.push_back(reference_frame);
190
pbos@webrtc.org94015242013-10-16 11:05:37 +0000191 last_rendered_frame_.CopyFrame(video_frame);
192 }
193
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000194 void Wait() {
195 EXPECT_EQ(kEventSignaled, done_->Wait(FullStackTest::kLongTimeoutMs));
196 }
pbos@webrtc.org94015242013-10-16 11:05:37 +0000197
198 VideoSendStreamInput* input_;
199 Transport* transport_;
200 PacketReceiver* receiver_;
201
202 private:
203 struct FrameComparison {
204 FrameComparison(const I420VideoFrame* reference,
205 const I420VideoFrame* render,
206 bool dropped,
207 int64_t send_time_ms,
208 int64_t recv_time_ms,
209 int64_t render_time_ms)
210 : dropped(dropped),
211 send_time_ms(send_time_ms),
212 recv_time_ms(recv_time_ms),
213 render_time_ms(render_time_ms) {
214 this->reference.CopyFrame(*reference);
215 this->render.CopyFrame(*render);
216 }
217
218 FrameComparison(const FrameComparison& compare)
219 : dropped(compare.dropped),
220 send_time_ms(compare.send_time_ms),
221 recv_time_ms(compare.recv_time_ms),
222 render_time_ms(compare.render_time_ms) {
223 this->reference.CopyFrame(compare.reference);
224 this->render.CopyFrame(compare.render);
225 }
226
227 ~FrameComparison() {}
228
229 I420VideoFrame reference;
230 I420VideoFrame render;
231 bool dropped;
232 int64_t send_time_ms;
233 int64_t recv_time_ms;
234 int64_t render_time_ms;
235 };
236
237 void AddFrameComparison(const I420VideoFrame* reference,
238 const I420VideoFrame* render,
239 bool dropped,
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000240 int64_t render_time_ms)
241 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
pbos@webrtc.org94015242013-10-16 11:05:37 +0000242 int64_t send_time_ms = send_times_[reference->timestamp()];
243 send_times_.erase(reference->timestamp());
244 int64_t recv_time_ms = recv_times_[reference->timestamp()];
245 recv_times_.erase(reference->timestamp());
246
247 CriticalSectionScoped crit(comparison_lock_.get());
248 comparisons_.push_back(FrameComparison(reference,
249 render,
250 dropped,
251 send_time_ms,
252 recv_time_ms,
253 render_time_ms));
254 }
255
256 static bool FrameComparisonThread(void* obj) {
257 return static_cast<VideoAnalyzer*>(obj)->CompareFrames();
258 }
259
260 bool CompareFrames() {
261 assert(frames_left_ > 0);
262
263 I420VideoFrame reference;
264 I420VideoFrame render;
265 bool dropped;
266 int64_t send_time_ms;
267 int64_t recv_time_ms;
268 int64_t render_time_ms;
269
270 SleepMs(10);
271
272 while (true) {
273 {
274 CriticalSectionScoped crit(comparison_lock_.get());
275 if (comparisons_.empty())
276 return true;
277 reference.SwapFrame(&comparisons_.front().reference);
278 render.SwapFrame(&comparisons_.front().render);
279 dropped = comparisons_.front().dropped;
280 send_time_ms = comparisons_.front().send_time_ms;
281 recv_time_ms = comparisons_.front().recv_time_ms;
282 render_time_ms = comparisons_.front().render_time_ms;
283 comparisons_.pop_front();
284 }
285
286 PerformFrameComparison(&reference,
287 &render,
288 dropped,
289 send_time_ms,
290 recv_time_ms,
291 render_time_ms);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000292
293 if (--frames_left_ == 0) {
294 PrintResult("psnr", psnr_, " dB");
295 PrintResult("ssim", ssim_, "");
296 PrintResult("sender_time", sender_time_, " ms");
pbos@webrtc.orga5d29fc2014-11-10 09:54:19 +0000297 printf("RESULT dropped_frames: %s = %d frames\n", test_label_,
298 dropped_frames_);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000299 PrintResult("receiver_time", receiver_time_, " ms");
300 PrintResult("total_delay_incl_network", end_to_end_, " ms");
301 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
302 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
303 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_);
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000304 done_->Set();
pbos@webrtc.org94015242013-10-16 11:05:37 +0000305
306 return false;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000307 }
308 }
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000309 }
310
pbos@webrtc.org94015242013-10-16 11:05:37 +0000311 void PerformFrameComparison(const I420VideoFrame* reference,
312 const I420VideoFrame* render,
313 bool dropped,
314 int64_t send_time_ms,
315 int64_t recv_time_ms,
316 int64_t render_time_ms) {
317 psnr_.AddSample(I420PSNR(reference, render));
318 ssim_.AddSample(I420SSIM(reference, render));
319 if (dropped) {
320 ++dropped_frames_;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000321 return;
pbos@webrtc.org94015242013-10-16 11:05:37 +0000322 }
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000323 if (last_render_time_ != 0)
pbos@webrtc.org94015242013-10-16 11:05:37 +0000324 rendered_delta_.AddSample(render_time_ms - last_render_time_);
325 last_render_time_ = render_time_ms;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000326
pbos@webrtc.org94015242013-10-16 11:05:37 +0000327 int64_t input_time_ms = reference->render_time_ms();
328 sender_time_.AddSample(send_time_ms - input_time_ms);
329 receiver_time_.AddSample(render_time_ms - recv_time_ms);
330 end_to_end_.AddSample(render_time_ms - input_time_ms);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000331 }
332
333 void PrintResult(const char* result_type,
334 test::Statistics stats,
335 const char* unit) {
336 printf("RESULT %s: %s = {%f, %f}%s\n",
337 result_type,
338 test_label_,
339 stats.Mean(),
340 stats.StandardDeviation(),
341 unit);
342 }
343
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000344 const char* const test_label_;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000345 test::Statistics sender_time_;
346 test::Statistics receiver_time_;
347 test::Statistics psnr_;
348 test::Statistics ssim_;
349 test::Statistics end_to_end_;
350 test::Statistics rendered_delta_;
pbos@webrtc.org94015242013-10-16 11:05:37 +0000351 int frames_left_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000352 int dropped_frames_;
353 int64_t last_render_time_;
354 uint32_t rtp_timestamp_delta_;
355
356 const scoped_ptr<CriticalSectionWrapper> crit_;
357 std::deque<I420VideoFrame*> frames_ GUARDED_BY(crit_);
358 std::deque<I420VideoFrame*> frame_pool_ GUARDED_BY(crit_);
359 I420VideoFrame last_rendered_frame_ GUARDED_BY(crit_);
360 std::map<uint32_t, int64_t> send_times_ GUARDED_BY(crit_);
361 std::map<uint32_t, int64_t> recv_times_ GUARDED_BY(crit_);
362 I420VideoFrame* first_send_frame_ GUARDED_BY(crit_);
pbos@webrtc.orgb35b1362014-10-20 09:14:38 +0000363 const double avg_psnr_threshold_;
364 const double avg_ssim_threshold_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +0000365
366 const scoped_ptr<CriticalSectionWrapper> comparison_lock_;
367 const scoped_ptr<ThreadWrapper> comparison_thread_;
368 std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_);
369 const scoped_ptr<EventWrapper> done_;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000370};
371
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000372void FullStackTest::RunTest(const FullStackTestParams& params) {
373 test::DirectTransport send_transport(params.link);
374 test::DirectTransport recv_transport(params.link);
pbos@webrtc.org94015242013-10-16 11:05:37 +0000375 VideoAnalyzer analyzer(NULL,
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000376 &send_transport,
pbos@webrtc.org94015242013-10-16 11:05:37 +0000377 params.test_label,
378 params.avg_psnr_threshold,
379 params.avg_ssim_threshold,
pbos@webrtc.org023b1012014-05-13 11:26:40 +0000380 kFullStackTestDurationSecs * params.clip.fps);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000381
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000382 CreateCalls(Call::Config(&analyzer), Call::Config(&recv_transport));
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000383
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000384 analyzer.SetReceiver(receiver_call_->Receiver());
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000385 send_transport.SetReceiver(&analyzer);
386 recv_transport.SetReceiver(sender_call_->Receiver());
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000387
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000388 CreateSendConfig(1);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000389
pbos@webrtc.orgab990ae2014-09-17 09:02:25 +0000390 scoped_ptr<VideoEncoder> encoder(
391 VideoEncoder::Create(VideoEncoder::kVp8));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000392 send_config_.encoder_settings.encoder = encoder.get();
393 send_config_.encoder_settings.payload_name = "VP8";
394 send_config_.encoder_settings.payload_type = 124;
stefan@webrtc.orgc216b9a2014-10-14 10:38:49 +0000395 send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000396
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000397 VideoStream* stream = &encoder_config_.streams[0];
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000398 stream->width = params.clip.width;
399 stream->height = params.clip.height;
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000400 stream->min_bitrate_bps = params.min_bitrate_bps;
401 stream->target_bitrate_bps = params.target_bitrate_bps;
402 stream->max_bitrate_bps = params.max_bitrate_bps;
pbos@webrtc.orgf577ae92014-03-19 08:43:57 +0000403 stream->max_framerate = params.clip.fps;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000404
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000405 CreateMatchingReceiveConfigs();
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000406 receive_configs_[0].renderer = &analyzer;
stefan@webrtc.orgc216b9a2014-10-14 10:38:49 +0000407 receive_configs_[0].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000408
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000409 CreateStreams();
410 analyzer.input_ = send_stream_->Input();
411
412 frame_generator_capturer_.reset(
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000413 test::FrameGeneratorCapturer::CreateFromYuvFile(
pbos@webrtc.org4c966012013-08-21 12:07:37 +0000414 &analyzer,
andresp@webrtc.orgab654952013-09-19 12:14:03 +0000415 test::ResourcePath(params.clip.name, "yuv").c_str(),
416 params.clip.width,
417 params.clip.height,
418 params.clip.fps,
419 Clock::GetRealTimeClock()));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000420
421 ASSERT_TRUE(frame_generator_capturer_.get() != NULL)
pbos@webrtc.org94015242013-10-16 11:05:37 +0000422 << "Could not create capturer for " << params.clip.name
423 << ".yuv. Is this resource file present?";
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000424
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000425 Start();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000426
427 analyzer.Wait();
428
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000429 send_transport.StopSending();
430 recv_transport.StopSending();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000431
432 Stop();
433
434 DestroyStreams();
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000435}
436
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000437TEST_F(FullStackTest, ParisQcifWithoutPacketLoss) {
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000438 FullStackTestParams paris_qcif = {"net_delay_0_0_plr_0",
439 {"paris_qcif", 176, 144, 30},
440 300000,
441 300000,
442 300000,
443 36.0,
444 0.96
445 };
446 RunTest(paris_qcif);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000447}
448
449TEST_F(FullStackTest, ForemanCifWithoutPacketLoss) {
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000450 // TODO(pbos): Decide on psnr/ssim thresholds for foreman_cif.
451 FullStackTestParams foreman_cif = {"foreman_cif_net_delay_0_0_plr_0",
452 {"foreman_cif", 352, 288, 30},
453 700000,
454 700000,
455 700000,
456 0.0,
457 0.0
458 };
459 RunTest(foreman_cif);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000460}
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000461
stefan@webrtc.orgc216b9a2014-10-14 10:38:49 +0000462TEST_F(FullStackTest, ForemanCifPlr5) {
463 FullStackTestParams foreman_cif = {"foreman_cif_delay_50_0_plr_5",
464 {"foreman_cif", 352, 288, 30},
465 30000,
466 500000,
467 2000000,
468 0.0,
469 0.0
470 };
471 foreman_cif.link.loss_percent = 5;
472 foreman_cif.link.queue_delay_ms = 50;
473 RunTest(foreman_cif);
474}
475
stefan@webrtc.orgb8e9e442014-07-09 11:29:06 +0000476TEST_F(FullStackTest, ForemanCif500kbps) {
477 FullStackTestParams foreman_cif = {"foreman_cif_500kbps",
478 {"foreman_cif", 352, 288, 30},
479 30000,
480 500000,
481 2000000,
482 0.0,
483 0.0
484 };
485 foreman_cif.link.queue_length_packets = 0;
486 foreman_cif.link.queue_delay_ms = 0;
487 foreman_cif.link.link_capacity_kbps = 500;
488 RunTest(foreman_cif);
489}
490
491TEST_F(FullStackTest, ForemanCif500kbpsLimitedQueue) {
492 FullStackTestParams foreman_cif = {"foreman_cif_500kbps_32pkts_queue",
493 {"foreman_cif", 352, 288, 30},
494 30000,
495 500000,
496 2000000,
497 0.0,
498 0.0
499 };
500 foreman_cif.link.queue_length_packets = 32;
501 foreman_cif.link.queue_delay_ms = 0;
502 foreman_cif.link.link_capacity_kbps = 500;
503 RunTest(foreman_cif);
504}
505
506TEST_F(FullStackTest, ForemanCif500kbps100ms) {
507 FullStackTestParams foreman_cif = {"foreman_cif_500kbps_100ms",
508 {"foreman_cif", 352, 288, 30},
509 30000,
510 500000,
511 2000000,
512 0.0,
513 0.0
514 };
515 foreman_cif.link.queue_length_packets = 0;
516 foreman_cif.link.queue_delay_ms = 100;
517 foreman_cif.link.link_capacity_kbps = 500;
518 RunTest(foreman_cif);
519}
520
521TEST_F(FullStackTest, ForemanCif500kbps100msLimitedQueue) {
522 FullStackTestParams foreman_cif = {"foreman_cif_500kbps_100ms_32pkts_queue",
523 {"foreman_cif", 352, 288, 30},
524 30000,
525 500000,
526 2000000,
527 0.0,
528 0.0
529 };
530 foreman_cif.link.queue_length_packets = 32;
531 foreman_cif.link.queue_delay_ms = 100;
532 foreman_cif.link.link_capacity_kbps = 500;
533 RunTest(foreman_cif);
534}
535
536TEST_F(FullStackTest, ForemanCif1000kbps100msLimitedQueue) {
537 FullStackTestParams foreman_cif = {"foreman_cif_1000kbps_100ms_32pkts_queue",
538 {"foreman_cif", 352, 288, 30},
539 30000,
540 2000000,
541 2000000,
542 0.0,
543 0.0
544 };
545 foreman_cif.link.queue_length_packets = 32;
546 foreman_cif.link.queue_delay_ms = 100;
547 foreman_cif.link.link_capacity_kbps = 1000;
548 RunTest(foreman_cif);
549}
pbos@webrtc.orgaf8d5af2013-07-09 08:02:33 +0000550} // namespace webrtc