blob: 23487f49e8deb8e4affce33e7c353396785414ef [file] [log] [blame]
ivica5d6a06c2015-09-17 05:30:24 -07001/*
2 * Copyright (c) 2015 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 */
perkja49cbd32016-09-16 07:53:41 -070010#include "webrtc/video/video_quality_test.h"
perkj9fdbda62016-09-15 09:19:20 -070011
perkja49cbd32016-09-16 07:53:41 -070012#include <stdio.h>
ivica5d6a06c2015-09-17 05:30:24 -070013#include <algorithm>
14#include <deque>
15#include <map>
sprangce4aef12015-11-02 07:23:20 -080016#include <sstream>
mflodmand1590b22015-12-09 07:07:59 -080017#include <string>
ivica5d6a06c2015-09-17 05:30:24 -070018#include <vector>
19
ivica5d6a06c2015-09-17 05:30:24 -070020#include "webrtc/base/checks.h"
Peter Boström5811a392015-12-10 13:02:50 +010021#include "webrtc/base/event.h"
ivica5d6a06c2015-09-17 05:30:24 -070022#include "webrtc/base/format_macros.h"
nissec7fe3c22016-04-20 03:25:36 -070023#include "webrtc/base/optional.h"
palmkviste75f2042016-09-28 06:19:48 -070024#include "webrtc/base/platform_file.h"
sprange1f2f1f2016-02-01 02:04:52 -080025#include "webrtc/base/timeutils.h"
ossuf515ab82016-12-07 04:52:58 -080026#include "webrtc/call/call.h"
ivica5d6a06c2015-09-17 05:30:24 -070027#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
skvlad11a9cbf2016-10-07 11:53:05 -070028#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
aleloi10111bc2016-11-17 06:48:48 -080029#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010030#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
sprangce4aef12015-11-02 07:23:20 -080031#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
magjed509e4fe2016-11-18 01:34:11 -080032#include "webrtc/modules/video_coding/codecs/h264/include/h264.h"
33#include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h"
34#include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010035#include "webrtc/system_wrappers/include/cpu_info.h"
kwibergac9f8762016-09-30 22:29:43 -070036#include "webrtc/test/gtest.h"
ivica5d6a06c2015-09-17 05:30:24 -070037#include "webrtc/test/layer_filtering_transport.h"
38#include "webrtc/test/run_loop.h"
39#include "webrtc/test/statistics.h"
40#include "webrtc/test/testsupport/fileutils.h"
perkja49cbd32016-09-16 07:53:41 -070041#include "webrtc/test/vcm_capturer.h"
ivica5d6a06c2015-09-17 05:30:24 -070042#include "webrtc/test/video_renderer.h"
minyue73208662016-08-18 06:28:55 -070043#include "webrtc/voice_engine/include/voe_base.h"
minyue73208662016-08-18 06:28:55 -070044
45namespace {
46
47constexpr int kSendStatsPollingIntervalMs = 1000;
48constexpr int kPayloadTypeH264 = 122;
49constexpr int kPayloadTypeVP8 = 123;
50constexpr int kPayloadTypeVP9 = 124;
51constexpr size_t kMaxComparisons = 10;
52constexpr char kSyncGroup[] = "av_sync";
minyue10cbb462016-11-07 09:29:22 -080053constexpr int kOpusMinBitrateBps = 6000;
54constexpr int kOpusBitrateFbBps = 32000;
minyue73208662016-08-18 06:28:55 -070055
56struct VoiceEngineState {
57 VoiceEngineState()
58 : voice_engine(nullptr),
59 base(nullptr),
minyue73208662016-08-18 06:28:55 -070060 send_channel_id(-1),
61 receive_channel_id(-1) {}
62
63 webrtc::VoiceEngine* voice_engine;
64 webrtc::VoEBase* base;
minyue73208662016-08-18 06:28:55 -070065 int send_channel_id;
66 int receive_channel_id;
67};
68
69void CreateVoiceEngine(VoiceEngineState* voe,
70 rtc::scoped_refptr<webrtc::AudioDecoderFactory>
71 decoder_factory) {
72 voe->voice_engine = webrtc::VoiceEngine::Create();
73 voe->base = webrtc::VoEBase::GetInterface(voe->voice_engine);
minyue73208662016-08-18 06:28:55 -070074 EXPECT_EQ(0, voe->base->Init(nullptr, nullptr, decoder_factory));
solenberg88499ec2016-09-07 07:34:41 -070075 webrtc::VoEBase::ChannelConfig config;
76 config.enable_voice_pacing = true;
77 voe->send_channel_id = voe->base->CreateChannel(config);
minyue73208662016-08-18 06:28:55 -070078 EXPECT_GE(voe->send_channel_id, 0);
79 voe->receive_channel_id = voe->base->CreateChannel();
80 EXPECT_GE(voe->receive_channel_id, 0);
81}
82
83void DestroyVoiceEngine(VoiceEngineState* voe) {
84 voe->base->DeleteChannel(voe->send_channel_id);
85 voe->send_channel_id = -1;
86 voe->base->DeleteChannel(voe->receive_channel_id);
87 voe->receive_channel_id = -1;
88 voe->base->Release();
89 voe->base = nullptr;
minyue73208662016-08-18 06:28:55 -070090
91 webrtc::VoiceEngine::Delete(voe->voice_engine);
92 voe->voice_engine = nullptr;
93}
94
perkjfa10b552016-10-02 23:45:26 -070095class VideoStreamFactory
96 : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface {
97 public:
98 explicit VideoStreamFactory(const std::vector<webrtc::VideoStream>& streams)
99 : streams_(streams) {}
100
101 private:
102 std::vector<webrtc::VideoStream> CreateEncoderStreams(
103 int width,
104 int height,
105 const webrtc::VideoEncoderConfig& encoder_config) override {
mflodmand79f97b2016-12-15 07:24:33 -0800106 // The highest layer must match the incoming resolution.
107 std::vector<webrtc::VideoStream> streams = streams_;
108 streams[streams_.size() - 1].height = height;
109 streams[streams_.size() - 1].width = width;
110 return streams;
perkjfa10b552016-10-02 23:45:26 -0700111 }
112
113 std::vector<webrtc::VideoStream> streams_;
114};
115
brandtr504b95e2016-12-21 02:54:35 -0800116bool IsFlexfec(int payload_type) {
117 return payload_type == webrtc::VideoQualityTest::kFlexfecPayloadType;
118}
119
minyue73208662016-08-18 06:28:55 -0700120} // namespace
ivica5d6a06c2015-09-17 05:30:24 -0700121
122namespace webrtc {
123
ivica5d6a06c2015-09-17 05:30:24 -0700124class VideoAnalyzer : public PacketReceiver,
pbos2d566682015-09-28 09:59:31 -0700125 public Transport,
nisse7ade7b32016-03-23 04:48:10 -0700126 public rtc::VideoSinkInterface<VideoFrame>,
Peter Boströme4499152016-02-05 11:13:28 +0100127 public EncodedFrameObserver {
ivica5d6a06c2015-09-17 05:30:24 -0700128 public:
sprangce4aef12015-11-02 07:23:20 -0800129 VideoAnalyzer(test::LayerFilteringTransport* transport,
ivica5d6a06c2015-09-17 05:30:24 -0700130 const std::string& test_label,
131 double avg_psnr_threshold,
132 double avg_ssim_threshold,
133 int duration_frames,
sprangce4aef12015-11-02 07:23:20 -0800134 FILE* graph_data_output_file,
135 const std::string& graph_title,
ilnik3dd5ad92017-02-09 04:58:53 -0800136 uint32_t ssrc_to_analyze,
ilnik46a00212017-02-10 09:16:05 -0800137 uint32_t rtx_ssrc_to_analyze,
ilnik3dd5ad92017-02-09 04:58:53 -0800138 uint32_t selected_width,
139 uint32_t selected_height)
perkja49cbd32016-09-16 07:53:41 -0700140 : transport_(transport),
ivica5d6a06c2015-09-17 05:30:24 -0700141 receiver_(nullptr),
142 send_stream_(nullptr),
philipelfd870db2017-01-23 03:22:15 -0800143 receive_stream_(nullptr),
perkja49cbd32016-09-16 07:53:41 -0700144 captured_frame_forwarder_(this),
ivica5d6a06c2015-09-17 05:30:24 -0700145 test_label_(test_label),
146 graph_data_output_file_(graph_data_output_file),
sprangce4aef12015-11-02 07:23:20 -0800147 graph_title_(graph_title),
148 ssrc_to_analyze_(ssrc_to_analyze),
ilnik46a00212017-02-10 09:16:05 -0800149 rtx_ssrc_to_analyze_(rtx_ssrc_to_analyze),
ilnik3dd5ad92017-02-09 04:58:53 -0800150 selected_width_(selected_width),
151 selected_height_(selected_height),
pbos14fe7082016-04-20 06:35:56 -0700152 pre_encode_proxy_(this),
Peter Boströme4499152016-02-05 11:13:28 +0100153 encode_timing_proxy_(this),
ivica5d6a06c2015-09-17 05:30:24 -0700154 frames_to_process_(duration_frames),
155 frames_recorded_(0),
156 frames_processed_(0),
157 dropped_frames_(0),
pbos14fe7082016-04-20 06:35:56 -0700158 dropped_frames_before_first_encode_(0),
159 dropped_frames_before_rendering_(0),
ivica5d6a06c2015-09-17 05:30:24 -0700160 last_render_time_(0),
161 rtp_timestamp_delta_(0),
162 avg_psnr_threshold_(avg_psnr_threshold),
163 avg_ssim_threshold_(avg_ssim_threshold),
Peter Boström8c38e8b2015-11-26 17:45:47 +0100164 stats_polling_thread_(&PollStatsThread, this, "StatsPoller"),
Peter Boström5811a392015-12-10 13:02:50 +0100165 comparison_available_event_(false, false),
Peter Boströmdd45eb62016-01-19 15:22:32 +0100166 done_(true, false) {
ivica5d6a06c2015-09-17 05:30:24 -0700167 // Create thread pool for CPU-expensive PSNR/SSIM calculations.
168
169 // Try to use about as many threads as cores, but leave kMinCoresLeft alone,
170 // so that we don't accidentally starve "real" worker threads (codec etc).
171 // Also, don't allocate more than kMaxComparisonThreads, even if there are
172 // spare cores.
173
174 uint32_t num_cores = CpuInfo::DetectNumberOfCores();
kwibergaf476c72016-11-28 15:21:39 -0800175 RTC_DCHECK_GE(num_cores, 1);
ivica5d6a06c2015-09-17 05:30:24 -0700176 static const uint32_t kMinCoresLeft = 4;
177 static const uint32_t kMaxComparisonThreads = 8;
178
179 if (num_cores <= kMinCoresLeft) {
180 num_cores = 1;
181 } else {
182 num_cores -= kMinCoresLeft;
183 num_cores = std::min(num_cores, kMaxComparisonThreads);
184 }
185
186 for (uint32_t i = 0; i < num_cores; ++i) {
Peter Boström8c38e8b2015-11-26 17:45:47 +0100187 rtc::PlatformThread* thread =
188 new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer");
189 thread->Start();
190 comparison_thread_pool_.push_back(thread);
ivica5d6a06c2015-09-17 05:30:24 -0700191 }
ivica5d6a06c2015-09-17 05:30:24 -0700192 }
193
194 ~VideoAnalyzer() {
Peter Boström8c38e8b2015-11-26 17:45:47 +0100195 for (rtc::PlatformThread* thread : comparison_thread_pool_) {
196 thread->Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700197 delete thread;
198 }
199 }
200
201 virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; }
202
perkja49cbd32016-09-16 07:53:41 -0700203 void SetSendStream(VideoSendStream* stream) {
204 rtc::CritScope lock(&crit_);
205 RTC_DCHECK(!send_stream_);
206 send_stream_ = stream;
207 }
208
philipelfd870db2017-01-23 03:22:15 -0800209 void SetReceiveStream(VideoReceiveStream* stream) {
210 rtc::CritScope lock(&crit_);
211 RTC_DCHECK(!receive_stream_);
212 receive_stream_ = stream;
213 }
214
perkja49cbd32016-09-16 07:53:41 -0700215 rtc::VideoSinkInterface<VideoFrame>* InputInterface() {
216 return &captured_frame_forwarder_;
217 }
218 rtc::VideoSourceInterface<VideoFrame>* OutputInterface() {
219 return &captured_frame_forwarder_;
220 }
221
ivica5d6a06c2015-09-17 05:30:24 -0700222 DeliveryStatus DeliverPacket(MediaType media_type,
223 const uint8_t* packet,
224 size_t length,
225 const PacketTime& packet_time) override {
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700226 // Ignore timestamps of RTCP packets. They're not synchronized with
227 // RTP packet timestamps and so they would confuse wrap_handler_.
228 if (RtpHeaderParser::IsRtcp(packet, length)) {
229 return receiver_->DeliverPacket(media_type, packet, length, packet_time);
230 }
231
sprangce4aef12015-11-02 07:23:20 -0800232 RtpUtility::RtpHeaderParser parser(packet, length);
ivica5d6a06c2015-09-17 05:30:24 -0700233 RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -0800234 parser.Parse(&header);
ilnik46a00212017-02-10 09:16:05 -0800235 if (!IsFlexfec(header.payloadType) &&
236 (header.ssrc == ssrc_to_analyze_ ||
237 header.ssrc == rtx_ssrc_to_analyze_)) {
brandtr504b95e2016-12-21 02:54:35 -0800238 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
239 // (FlexFEC and media are sent on different SSRCs, which have different
240 // timestamps spaces.)
ilnik46a00212017-02-10 09:16:05 -0800241 // Also ignore packets from wrong SSRC, but include retransmits.
ivica5d6a06c2015-09-17 05:30:24 -0700242 rtc::CritScope lock(&crit_);
sprang16daaa52016-03-09 01:30:24 -0800243 int64_t timestamp =
244 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
245 recv_times_[timestamp] =
ivica5d6a06c2015-09-17 05:30:24 -0700246 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
247 }
248
249 return receiver_->DeliverPacket(media_type, packet, length, packet_time);
250 }
251
Peter Boströme4499152016-02-05 11:13:28 +0100252 void MeasuredEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) {
ivica8d15bd62015-10-07 02:43:12 -0700253 rtc::CritScope crit(&comparison_lock_);
254 samples_encode_time_ms_[ntp_time_ms] = encode_time_ms;
255 }
256
pbos14fe7082016-04-20 06:35:56 -0700257 void PreEncodeOnFrame(const VideoFrame& video_frame) {
258 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800259 if (!first_encoded_timestamp_) {
pbos14fe7082016-04-20 06:35:56 -0700260 while (frames_.front().timestamp() != video_frame.timestamp()) {
261 ++dropped_frames_before_first_encode_;
262 frames_.pop_front();
263 RTC_CHECK(!frames_.empty());
264 }
ilnik3dd5ad92017-02-09 04:58:53 -0800265 first_encoded_timestamp_ =
266 rtc::Optional<uint32_t>(video_frame.timestamp());
267 }
268 }
269
270 void PostEncodeFrameCallback(const EncodedFrame& encoded_frame) {
271 rtc::CritScope lock(&crit_);
272 if (!first_sent_timestamp_ &&
273 encoded_frame.encoded_width_ == selected_width_ &&
274 encoded_frame.encoded_height_ == selected_height_) {
275 first_sent_timestamp_ = rtc::Optional<uint32_t>(encoded_frame.timestamp_);
pbos14fe7082016-04-20 06:35:56 -0700276 }
277 }
278
stefan1d8a5062015-10-02 03:39:33 -0700279 bool SendRtp(const uint8_t* packet,
280 size_t length,
281 const PacketOptions& options) override {
sprangce4aef12015-11-02 07:23:20 -0800282 RtpUtility::RtpHeaderParser parser(packet, length);
ivica5d6a06c2015-09-17 05:30:24 -0700283 RTPHeader header;
danilchapf6975f42015-12-28 10:18:46 -0800284 parser.Parse(&header);
ivica5d6a06c2015-09-17 05:30:24 -0700285
sprangce4aef12015-11-02 07:23:20 -0800286 int64_t current_time =
287 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
288 bool result = transport_->SendRtp(packet, length, options);
ivica5d6a06c2015-09-17 05:30:24 -0700289 {
290 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800291 if (rtp_timestamp_delta_ == 0 && header.ssrc == ssrc_to_analyze_) {
ilnik1e1c84d2017-02-09 08:32:53 -0800292 RTC_CHECK(static_cast<bool>(first_sent_timestamp_));
ilnik3dd5ad92017-02-09 04:58:53 -0800293 rtp_timestamp_delta_ = header.timestamp - *first_sent_timestamp_;
ilnike67c59e2017-02-09 04:08:56 -0800294 }
ilnik3dd5ad92017-02-09 04:58:53 -0800295
296 if (!IsFlexfec(header.payloadType) && header.ssrc == ssrc_to_analyze_) {
brandtr504b95e2016-12-21 02:54:35 -0800297 // Ignore FlexFEC timestamps, to avoid collisions with media timestamps.
298 // (FlexFEC and media are sent on different SSRCs, which have different
299 // timestamps spaces.)
ilnik46a00212017-02-10 09:16:05 -0800300 // Also ignore packets from wrong SSRC and retransmits.
brandtr504b95e2016-12-21 02:54:35 -0800301 int64_t timestamp =
302 wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_);
303 send_times_[timestamp] = current_time;
304 if (!transport_->DiscardedLastPacket() &&
305 header.ssrc == ssrc_to_analyze_) {
306 encoded_frame_sizes_[timestamp] +=
307 length - (header.headerLength + header.paddingLength);
308 }
sprangce4aef12015-11-02 07:23:20 -0800309 }
ivica5d6a06c2015-09-17 05:30:24 -0700310 }
sprangce4aef12015-11-02 07:23:20 -0800311 return result;
ivica5d6a06c2015-09-17 05:30:24 -0700312 }
313
314 bool SendRtcp(const uint8_t* packet, size_t length) override {
315 return transport_->SendRtcp(packet, length);
316 }
317
318 void EncodedFrameCallback(const EncodedFrame& frame) override {
319 rtc::CritScope lock(&comparison_lock_);
320 if (frames_recorded_ < frames_to_process_)
321 encoded_frame_size_.AddSample(frame.length_);
322 }
323
nisseeb83a1a2016-03-21 01:27:56 -0700324 void OnFrame(const VideoFrame& video_frame) override {
ivica5d6a06c2015-09-17 05:30:24 -0700325 int64_t render_time_ms =
326 Clock::GetRealTimeClock()->CurrentNtpInMilliseconds();
ivica5d6a06c2015-09-17 05:30:24 -0700327
328 rtc::CritScope lock(&crit_);
Taylor Brandstetter433b95a2016-03-18 11:41:03 -0700329 int64_t send_timestamp =
sprang16daaa52016-03-09 01:30:24 -0800330 wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_);
ivica5d6a06c2015-09-17 05:30:24 -0700331
sprang16daaa52016-03-09 01:30:24 -0800332 while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) {
nisse97f0b932016-05-26 09:44:40 -0700333 if (!last_rendered_frame_) {
pbos14fe7082016-04-20 06:35:56 -0700334 // No previous frame rendered, this one was dropped after sending but
335 // before rendering.
336 ++dropped_frames_before_rendering_;
kthelgason2bc68642017-02-07 07:02:22 -0800337 } else {
338 AddFrameComparison(frames_.front(), *last_rendered_frame_, true,
339 render_time_ms);
pbos14fe7082016-04-20 06:35:56 -0700340 }
ivica5d6a06c2015-09-17 05:30:24 -0700341 frames_.pop_front();
pbos14fe7082016-04-20 06:35:56 -0700342 RTC_DCHECK(!frames_.empty());
ivica5d6a06c2015-09-17 05:30:24 -0700343 }
344
345 VideoFrame reference_frame = frames_.front();
346 frames_.pop_front();
sprang16daaa52016-03-09 01:30:24 -0800347 int64_t reference_timestamp =
348 wrap_handler_.Unwrap(reference_frame.timestamp());
349 if (send_timestamp == reference_timestamp - 1) {
sprangce4aef12015-11-02 07:23:20 -0800350 // TODO(ivica): Make this work for > 2 streams.
Peter Boströme4499152016-02-05 11:13:28 +0100351 // Look at RTPSender::BuildRTPHeader.
sprangce4aef12015-11-02 07:23:20 -0800352 ++send_timestamp;
353 }
sprang16daaa52016-03-09 01:30:24 -0800354 ASSERT_EQ(reference_timestamp, send_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700355
356 AddFrameComparison(reference_frame, video_frame, false, render_time_ms);
357
nisse97f0b932016-05-26 09:44:40 -0700358 last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame);
ivica5d6a06c2015-09-17 05:30:24 -0700359 }
360
ivica5d6a06c2015-09-17 05:30:24 -0700361 void Wait() {
362 // Frame comparisons can be very expensive. Wait for test to be done, but
363 // at time-out check if frames_processed is going up. If so, give it more
364 // time, otherwise fail. Hopefully this will reduce test flakiness.
365
Peter Boström8c38e8b2015-11-26 17:45:47 +0100366 stats_polling_thread_.Start();
sprangce4aef12015-11-02 07:23:20 -0800367
ivica5d6a06c2015-09-17 05:30:24 -0700368 int last_frames_processed = -1;
ivica5d6a06c2015-09-17 05:30:24 -0700369 int iteration = 0;
Peter Boström5811a392015-12-10 13:02:50 +0100370 while (!done_.Wait(VideoQualityTest::kDefaultTimeoutMs)) {
ivica5d6a06c2015-09-17 05:30:24 -0700371 int frames_processed;
372 {
373 rtc::CritScope crit(&comparison_lock_);
374 frames_processed = frames_processed_;
375 }
376
377 // Print some output so test infrastructure won't think we've crashed.
378 const char* kKeepAliveMessages[3] = {
379 "Uh, I'm-I'm not quite dead, sir.",
380 "Uh, I-I think uh, I could pull through, sir.",
381 "Actually, I think I'm all right to come with you--"};
382 printf("- %s\n", kKeepAliveMessages[iteration++ % 3]);
383
384 if (last_frames_processed == -1) {
385 last_frames_processed = frames_processed;
386 continue;
387 }
Peter Boströmdd45eb62016-01-19 15:22:32 +0100388 if (frames_processed == last_frames_processed) {
389 EXPECT_GT(frames_processed, last_frames_processed)
390 << "Analyzer stalled while waiting for test to finish.";
391 done_.Set();
392 break;
393 }
ivica5d6a06c2015-09-17 05:30:24 -0700394 last_frames_processed = frames_processed;
395 }
396
397 if (iteration > 0)
398 printf("- Farewell, sweet Concorde!\n");
399
Peter Boström8c38e8b2015-11-26 17:45:47 +0100400 stats_polling_thread_.Stop();
ivica5d6a06c2015-09-17 05:30:24 -0700401 }
402
pbos14fe7082016-04-20 06:35:56 -0700403 rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() {
404 return &pre_encode_proxy_;
405 }
Peter Boströme4499152016-02-05 11:13:28 +0100406 EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; }
407
sprangce4aef12015-11-02 07:23:20 -0800408 test::LayerFilteringTransport* const transport_;
ivica5d6a06c2015-09-17 05:30:24 -0700409 PacketReceiver* receiver_;
ivica5d6a06c2015-09-17 05:30:24 -0700410
411 private:
412 struct FrameComparison {
413 FrameComparison()
414 : dropped(false),
nissedf2ceb82016-12-15 06:29:53 -0800415 input_time_ms(0),
ivica5d6a06c2015-09-17 05:30:24 -0700416 send_time_ms(0),
417 recv_time_ms(0),
418 render_time_ms(0),
419 encoded_frame_size(0) {}
420
421 FrameComparison(const VideoFrame& reference,
422 const VideoFrame& render,
423 bool dropped,
nissedf2ceb82016-12-15 06:29:53 -0800424 int64_t input_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700425 int64_t send_time_ms,
426 int64_t recv_time_ms,
427 int64_t render_time_ms,
428 size_t encoded_frame_size)
429 : reference(reference),
430 render(render),
431 dropped(dropped),
nissedf2ceb82016-12-15 06:29:53 -0800432 input_time_ms(input_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700433 send_time_ms(send_time_ms),
434 recv_time_ms(recv_time_ms),
435 render_time_ms(render_time_ms),
436 encoded_frame_size(encoded_frame_size) {}
437
nissedf2ceb82016-12-15 06:29:53 -0800438 FrameComparison(bool dropped,
439 int64_t input_time_ms,
440 int64_t send_time_ms,
441 int64_t recv_time_ms,
442 int64_t render_time_ms,
443 size_t encoded_frame_size)
444 : dropped(dropped),
445 input_time_ms(input_time_ms),
446 send_time_ms(send_time_ms),
447 recv_time_ms(recv_time_ms),
448 render_time_ms(render_time_ms),
449 encoded_frame_size(encoded_frame_size) {}
450
451 rtc::Optional<VideoFrame> reference;
452 rtc::Optional<VideoFrame> render;
ivica5d6a06c2015-09-17 05:30:24 -0700453 bool dropped;
nissedf2ceb82016-12-15 06:29:53 -0800454 int64_t input_time_ms;
ivica5d6a06c2015-09-17 05:30:24 -0700455 int64_t send_time_ms;
456 int64_t recv_time_ms;
457 int64_t render_time_ms;
458 size_t encoded_frame_size;
459 };
460
461 struct Sample {
ivica8d15bd62015-10-07 02:43:12 -0700462 Sample(int dropped,
463 int64_t input_time_ms,
464 int64_t send_time_ms,
465 int64_t recv_time_ms,
466 int64_t render_time_ms,
467 size_t encoded_frame_size,
ivica5d6a06c2015-09-17 05:30:24 -0700468 double psnr,
ivica8d15bd62015-10-07 02:43:12 -0700469 double ssim)
ivica5d6a06c2015-09-17 05:30:24 -0700470 : dropped(dropped),
471 input_time_ms(input_time_ms),
472 send_time_ms(send_time_ms),
473 recv_time_ms(recv_time_ms),
ivica8d15bd62015-10-07 02:43:12 -0700474 render_time_ms(render_time_ms),
ivica5d6a06c2015-09-17 05:30:24 -0700475 encoded_frame_size(encoded_frame_size),
476 psnr(psnr),
ivica8d15bd62015-10-07 02:43:12 -0700477 ssim(ssim) {}
ivica5d6a06c2015-09-17 05:30:24 -0700478
ivica8d15bd62015-10-07 02:43:12 -0700479 int dropped;
480 int64_t input_time_ms;
481 int64_t send_time_ms;
482 int64_t recv_time_ms;
483 int64_t render_time_ms;
484 size_t encoded_frame_size;
ivica5d6a06c2015-09-17 05:30:24 -0700485 double psnr;
486 double ssim;
ivica5d6a06c2015-09-17 05:30:24 -0700487 };
488
Peter Boströme4499152016-02-05 11:13:28 +0100489 // This class receives the send-side OnEncodeTiming and is provided to not
490 // conflict with the receiver-side pre_decode_callback.
491 class OnEncodeTimingProxy : public EncodedFrameObserver {
492 public:
493 explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {}
494
495 void OnEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) override {
496 parent_->MeasuredEncodeTiming(ntp_time_ms, encode_time_ms);
497 }
ilnik3dd5ad92017-02-09 04:58:53 -0800498 void EncodedFrameCallback(const EncodedFrame& frame) override {
499 parent_->PostEncodeFrameCallback(frame);
500 }
Peter Boströme4499152016-02-05 11:13:28 +0100501
502 private:
503 VideoAnalyzer* const parent_;
504 };
505
pbos14fe7082016-04-20 06:35:56 -0700506 // This class receives the send-side OnFrame callback and is provided to not
507 // conflict with the receiver-side renderer callback.
508 class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> {
509 public:
510 explicit PreEncodeProxy(VideoAnalyzer* parent) : parent_(parent) {}
511
512 void OnFrame(const VideoFrame& video_frame) override {
513 parent_->PreEncodeOnFrame(video_frame);
514 }
515
516 private:
517 VideoAnalyzer* const parent_;
518 };
519
ivica5d6a06c2015-09-17 05:30:24 -0700520 void AddFrameComparison(const VideoFrame& reference,
521 const VideoFrame& render,
522 bool dropped,
523 int64_t render_time_ms)
524 EXCLUSIVE_LOCKS_REQUIRED(crit_) {
sprange1f2f1f2016-02-01 02:04:52 -0800525 int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp());
526 int64_t send_time_ms = send_times_[reference_timestamp];
527 send_times_.erase(reference_timestamp);
528 int64_t recv_time_ms = recv_times_[reference_timestamp];
529 recv_times_.erase(reference_timestamp);
ivica5d6a06c2015-09-17 05:30:24 -0700530
sprangce4aef12015-11-02 07:23:20 -0800531 // TODO(ivica): Make this work for > 2 streams.
sprange1f2f1f2016-02-01 02:04:52 -0800532 auto it = encoded_frame_sizes_.find(reference_timestamp);
sprangce4aef12015-11-02 07:23:20 -0800533 if (it == encoded_frame_sizes_.end())
sprange1f2f1f2016-02-01 02:04:52 -0800534 it = encoded_frame_sizes_.find(reference_timestamp - 1);
sprangce4aef12015-11-02 07:23:20 -0800535 size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second;
536 if (it != encoded_frame_sizes_.end())
537 encoded_frame_sizes_.erase(it);
ivica5d6a06c2015-09-17 05:30:24 -0700538
ivica5d6a06c2015-09-17 05:30:24 -0700539 rtc::CritScope crit(&comparison_lock_);
stefanb1797672016-08-11 07:00:57 -0700540 if (comparisons_.size() < kMaxComparisons) {
nissedf2ceb82016-12-15 06:29:53 -0800541 comparisons_.push_back(FrameComparison(reference, render, dropped,
542 reference.ntp_time_ms(),
543 send_time_ms, recv_time_ms,
544 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700545 } else {
nissedf2ceb82016-12-15 06:29:53 -0800546 comparisons_.push_back(FrameComparison(dropped,
547 reference.ntp_time_ms(),
548 send_time_ms, recv_time_ms,
549 render_time_ms, encoded_size));
stefanb1797672016-08-11 07:00:57 -0700550 }
Peter Boström5811a392015-12-10 13:02:50 +0100551 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700552 }
553
554 static bool PollStatsThread(void* obj) {
555 return static_cast<VideoAnalyzer*>(obj)->PollStats();
556 }
557
558 bool PollStats() {
Peter Boströmdd45eb62016-01-19 15:22:32 +0100559 if (done_.Wait(kSendStatsPollingIntervalMs))
Peter Boström5811a392015-12-10 13:02:50 +0100560 return false;
ivica5d6a06c2015-09-17 05:30:24 -0700561
ivica5d6a06c2015-09-17 05:30:24 -0700562 rtc::CritScope crit(&comparison_lock_);
philipelfd870db2017-01-23 03:22:15 -0800563
564 VideoSendStream::Stats send_stats = send_stream_->GetStats();
Peter Boströmb1eaa8d2016-02-23 17:30:49 +0100565 // It's not certain that we yet have estimates for any of these stats. Check
566 // that they are positive before mixing them in.
philipelfd870db2017-01-23 03:22:15 -0800567 if (send_stats.encode_frame_rate > 0)
568 encode_frame_rate_.AddSample(send_stats.encode_frame_rate);
569 if (send_stats.avg_encode_time_ms > 0)
570 encode_time_ms_.AddSample(send_stats.avg_encode_time_ms);
571 if (send_stats.encode_usage_percent > 0)
572 encode_usage_percent_.AddSample(send_stats.encode_usage_percent);
573 if (send_stats.media_bitrate_bps > 0)
574 media_bitrate_bps_.AddSample(send_stats.media_bitrate_bps);
575
576 if (receive_stream_ != nullptr) {
577 VideoReceiveStream::Stats receive_stats = receive_stream_->GetStats();
578 if (receive_stats.decode_ms > 0)
579 decode_time_ms_.AddSample(receive_stats.decode_ms);
580 if (receive_stats.max_decode_ms > 0)
581 decode_time_max_ms_.AddSample(receive_stats.max_decode_ms);
582 }
ivica5d6a06c2015-09-17 05:30:24 -0700583
584 return true;
585 }
586
587 static bool FrameComparisonThread(void* obj) {
588 return static_cast<VideoAnalyzer*>(obj)->CompareFrames();
589 }
590
591 bool CompareFrames() {
592 if (AllFramesRecorded())
593 return false;
594
ivica5d6a06c2015-09-17 05:30:24 -0700595 FrameComparison comparison;
596
597 if (!PopComparison(&comparison)) {
598 // Wait until new comparison task is available, or test is done.
599 // If done, wake up remaining threads waiting.
Peter Boström5811a392015-12-10 13:02:50 +0100600 comparison_available_event_.Wait(1000);
ivica5d6a06c2015-09-17 05:30:24 -0700601 if (AllFramesRecorded()) {
Peter Boström5811a392015-12-10 13:02:50 +0100602 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700603 return false;
604 }
605 return true; // Try again.
606 }
607
608 PerformFrameComparison(comparison);
609
610 if (FrameProcessed()) {
611 PrintResults();
612 if (graph_data_output_file_)
613 PrintSamplesToFile();
Peter Boström5811a392015-12-10 13:02:50 +0100614 done_.Set();
615 comparison_available_event_.Set();
ivica5d6a06c2015-09-17 05:30:24 -0700616 return false;
617 }
618
619 return true;
620 }
621
622 bool PopComparison(FrameComparison* comparison) {
623 rtc::CritScope crit(&comparison_lock_);
624 // If AllFramesRecorded() is true, it means we have already popped
625 // frames_to_process_ frames from comparisons_, so there is no more work
626 // for this thread to be done. frames_processed_ might still be lower if
627 // all comparisons are not done, but those frames are currently being
628 // worked on by other threads.
629 if (comparisons_.empty() || AllFramesRecorded())
630 return false;
631
632 *comparison = comparisons_.front();
633 comparisons_.pop_front();
634
635 FrameRecorded();
636 return true;
637 }
638
639 // Increment counter for number of frames received for comparison.
640 void FrameRecorded() {
641 rtc::CritScope crit(&comparison_lock_);
642 ++frames_recorded_;
643 }
644
645 // Returns true if all frames to be compared have been taken from the queue.
646 bool AllFramesRecorded() {
647 rtc::CritScope crit(&comparison_lock_);
648 assert(frames_recorded_ <= frames_to_process_);
649 return frames_recorded_ == frames_to_process_;
650 }
651
652 // Increase count of number of frames processed. Returns true if this was the
653 // last frame to be processed.
654 bool FrameProcessed() {
655 rtc::CritScope crit(&comparison_lock_);
656 ++frames_processed_;
657 assert(frames_processed_ <= frames_to_process_);
658 return frames_processed_ == frames_to_process_;
659 }
660
661 void PrintResults() {
662 rtc::CritScope crit(&comparison_lock_);
663 PrintResult("psnr", psnr_, " dB");
tnakamura3123cbc2016-02-10 11:21:51 -0800664 PrintResult("ssim", ssim_, " score");
ivica5d6a06c2015-09-17 05:30:24 -0700665 PrintResult("sender_time", sender_time_, " ms");
ivica5d6a06c2015-09-17 05:30:24 -0700666 PrintResult("receiver_time", receiver_time_, " ms");
667 PrintResult("total_delay_incl_network", end_to_end_, " ms");
668 PrintResult("time_between_rendered_frames", rendered_delta_, " ms");
669 PrintResult("encoded_frame_size", encoded_frame_size_, " bytes");
670 PrintResult("encode_frame_rate", encode_frame_rate_, " fps");
philipelfd870db2017-01-23 03:22:15 -0800671 PrintResult("encode_time", encode_time_ms_, " ms");
672 PrintResult("encode_usage_percent", encode_usage_percent_, " percent");
673 PrintResult("media_bitrate", media_bitrate_bps_, " bps");
674
675 if (receive_stream_ != nullptr) {
676 PrintResult("decode_time", decode_time_ms_, " ms");
677 PrintResult("decode_time_max", decode_time_max_ms_, " ms");
678 }
ivica5d6a06c2015-09-17 05:30:24 -0700679
pbos14fe7082016-04-20 06:35:56 -0700680 printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(),
681 dropped_frames_);
682 printf("RESULT dropped_frames_before_first_encode: %s = %d frames\n",
683 test_label_.c_str(), dropped_frames_before_first_encode_);
684 printf("RESULT dropped_frames_before_rendering: %s = %d frames\n",
685 test_label_.c_str(), dropped_frames_before_rendering_);
686
ivica5d6a06c2015-09-17 05:30:24 -0700687 EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_);
688 EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_);
689 }
690
691 void PerformFrameComparison(const FrameComparison& comparison) {
692 // Perform expensive psnr and ssim calculations while not holding lock.
stefanb1797672016-08-11 07:00:57 -0700693 double psnr = -1.0;
694 double ssim = -1.0;
nissedf2ceb82016-12-15 06:29:53 -0800695 if (comparison.reference) {
696 psnr = I420PSNR(&*comparison.reference, &*comparison.render);
697 ssim = I420SSIM(&*comparison.reference, &*comparison.render);
stefanb1797672016-08-11 07:00:57 -0700698 }
ivica5d6a06c2015-09-17 05:30:24 -0700699
ivica5d6a06c2015-09-17 05:30:24 -0700700 rtc::CritScope crit(&comparison_lock_);
701 if (graph_data_output_file_) {
nissedf2ceb82016-12-15 06:29:53 -0800702 samples_.push_back(Sample(
703 comparison.dropped, comparison.input_time_ms, comparison.send_time_ms,
704 comparison.recv_time_ms, comparison.render_time_ms,
705 comparison.encoded_frame_size, psnr, ssim));
ivica5d6a06c2015-09-17 05:30:24 -0700706 }
stefanb1797672016-08-11 07:00:57 -0700707 if (psnr >= 0.0)
708 psnr_.AddSample(psnr);
709 if (ssim >= 0.0)
710 ssim_.AddSample(ssim);
ivica5d6a06c2015-09-17 05:30:24 -0700711
712 if (comparison.dropped) {
713 ++dropped_frames_;
714 return;
715 }
716 if (last_render_time_ != 0)
717 rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_);
718 last_render_time_ = comparison.render_time_ms;
719
nissedf2ceb82016-12-15 06:29:53 -0800720 sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms);
brandtr504b95e2016-12-21 02:54:35 -0800721 if (comparison.recv_time_ms > 0) {
722 // If recv_time_ms == 0, this frame consisted of a packets which were all
723 // lost in the transport. Since we were able to render the frame, however,
724 // the dropped packets were recovered by FlexFEC. The FlexFEC recovery
725 // happens internally in Call, and we can therefore here not know which
726 // FEC packets that protected the lost media packets. Consequently, we
727 // were not able to record a meaningful recv_time_ms. We therefore skip
728 // this sample.
729 //
730 // The reasoning above does not hold for ULPFEC and RTX, as for those
731 // strategies the timestamp of the received packets is set to the
732 // timestamp of the protected/retransmitted media packet. I.e., then
733 // recv_time_ms != 0, even though the media packets were lost.
734 receiver_time_.AddSample(comparison.render_time_ms -
735 comparison.recv_time_ms);
736 }
nissedf2ceb82016-12-15 06:29:53 -0800737 end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms);
ivica5d6a06c2015-09-17 05:30:24 -0700738 encoded_frame_size_.AddSample(comparison.encoded_frame_size);
739 }
740
741 void PrintResult(const char* result_type,
742 test::Statistics stats,
743 const char* unit) {
744 printf("RESULT %s: %s = {%f, %f}%s\n",
745 result_type,
746 test_label_.c_str(),
747 stats.Mean(),
748 stats.StandardDeviation(),
749 unit);
750 }
751
752 void PrintSamplesToFile(void) {
753 FILE* out = graph_data_output_file_;
754 rtc::CritScope crit(&comparison_lock_);
755 std::sort(samples_.begin(), samples_.end(),
756 [](const Sample& A, const Sample& B) -> bool {
757 return A.input_time_ms < B.input_time_ms;
758 });
759
sprangce4aef12015-11-02 07:23:20 -0800760 fprintf(out, "%s\n", graph_title_.c_str());
ivica5d6a06c2015-09-17 05:30:24 -0700761 fprintf(out, "%" PRIuS "\n", samples_.size());
762 fprintf(out,
763 "dropped "
764 "input_time_ms "
765 "send_time_ms "
766 "recv_time_ms "
ivica8d15bd62015-10-07 02:43:12 -0700767 "render_time_ms "
ivica5d6a06c2015-09-17 05:30:24 -0700768 "encoded_frame_size "
769 "psnr "
770 "ssim "
ivica8d15bd62015-10-07 02:43:12 -0700771 "encode_time_ms\n");
772 int missing_encode_time_samples = 0;
ivica5d6a06c2015-09-17 05:30:24 -0700773 for (const Sample& sample : samples_) {
ivica8d15bd62015-10-07 02:43:12 -0700774 auto it = samples_encode_time_ms_.find(sample.input_time_ms);
775 int encode_time_ms;
776 if (it != samples_encode_time_ms_.end()) {
777 encode_time_ms = it->second;
778 } else {
779 ++missing_encode_time_samples;
780 encode_time_ms = -1;
781 }
782 fprintf(out, "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRIuS
783 " %lf %lf %d\n",
784 sample.dropped, sample.input_time_ms, sample.send_time_ms,
785 sample.recv_time_ms, sample.render_time_ms,
ivica5d6a06c2015-09-17 05:30:24 -0700786 sample.encoded_frame_size, sample.psnr, sample.ssim,
ivica8d15bd62015-10-07 02:43:12 -0700787 encode_time_ms);
788 }
789 if (missing_encode_time_samples) {
790 fprintf(stderr,
791 "Warning: Missing encode_time_ms samples for %d frame(s).\n",
792 missing_encode_time_samples);
ivica5d6a06c2015-09-17 05:30:24 -0700793 }
794 }
795
perkja49cbd32016-09-16 07:53:41 -0700796 // Implements VideoSinkInterface to receive captured frames from a
797 // FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act
798 // as a source to VideoSendStream.
799 // It forwards all input frames to the VideoAnalyzer for later comparison and
800 // forwards the captured frames to the VideoSendStream.
801 class CapturedFrameForwarder : public rtc::VideoSinkInterface<VideoFrame>,
802 public rtc::VideoSourceInterface<VideoFrame> {
803 public:
804 explicit CapturedFrameForwarder(VideoAnalyzer* analyzer)
805 : analyzer_(analyzer), send_stream_input_(nullptr) {}
806
807 private:
808 void OnFrame(const VideoFrame& video_frame) override {
809 VideoFrame copy = video_frame;
ilnik3dd5ad92017-02-09 04:58:53 -0800810 // Frames from the capturer does not have a rtp timestamp.
811 // Create one so it can be used for comparison.
812 RTC_DCHECK_EQ(0, video_frame.timestamp());
perkja49cbd32016-09-16 07:53:41 -0700813 copy.set_timestamp(copy.ntp_time_ms() * 90);
ilnik3dd5ad92017-02-09 04:58:53 -0800814 analyzer_->AddCapturedFrameForComparison(copy);
perkja49cbd32016-09-16 07:53:41 -0700815 rtc::CritScope lock(&crit_);
816 if (send_stream_input_)
817 send_stream_input_->OnFrame(video_frame);
818 }
819
820 // Called when |send_stream_.SetSource()| is called.
821 void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
822 const rtc::VideoSinkWants& wants) override {
823 rtc::CritScope lock(&crit_);
824 RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink);
825 send_stream_input_ = sink;
826 }
827
828 // Called by |send_stream_| when |send_stream_.SetSource()| is called.
829 void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override {
830 rtc::CritScope lock(&crit_);
831 RTC_DCHECK(sink == send_stream_input_);
832 send_stream_input_ = nullptr;
833 }
834
835 VideoAnalyzer* const analyzer_;
836 rtc::CriticalSection crit_;
837 rtc::VideoSinkInterface<VideoFrame>* send_stream_input_ GUARDED_BY(crit_);
838 };
839
840 void AddCapturedFrameForComparison(const VideoFrame& video_frame) {
841 rtc::CritScope lock(&crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800842 frames_.push_back(video_frame);
perkja49cbd32016-09-16 07:53:41 -0700843 }
844
845 VideoSendStream* send_stream_;
philipelfd870db2017-01-23 03:22:15 -0800846 VideoReceiveStream* receive_stream_;
perkja49cbd32016-09-16 07:53:41 -0700847 CapturedFrameForwarder captured_frame_forwarder_;
ivica5d6a06c2015-09-17 05:30:24 -0700848 const std::string test_label_;
849 FILE* const graph_data_output_file_;
sprangce4aef12015-11-02 07:23:20 -0800850 const std::string graph_title_;
851 const uint32_t ssrc_to_analyze_;
ilnik46a00212017-02-10 09:16:05 -0800852 const uint32_t rtx_ssrc_to_analyze_;
ilnik3dd5ad92017-02-09 04:58:53 -0800853 const uint32_t selected_width_;
854 const uint32_t selected_height_;
pbos14fe7082016-04-20 06:35:56 -0700855 PreEncodeProxy pre_encode_proxy_;
Peter Boströme4499152016-02-05 11:13:28 +0100856 OnEncodeTimingProxy encode_timing_proxy_;
ivica5d6a06c2015-09-17 05:30:24 -0700857 std::vector<Sample> samples_ GUARDED_BY(comparison_lock_);
ivica8d15bd62015-10-07 02:43:12 -0700858 std::map<int64_t, int> samples_encode_time_ms_ GUARDED_BY(comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700859 test::Statistics sender_time_ GUARDED_BY(comparison_lock_);
860 test::Statistics receiver_time_ GUARDED_BY(comparison_lock_);
861 test::Statistics psnr_ GUARDED_BY(comparison_lock_);
862 test::Statistics ssim_ GUARDED_BY(comparison_lock_);
863 test::Statistics end_to_end_ GUARDED_BY(comparison_lock_);
864 test::Statistics rendered_delta_ GUARDED_BY(comparison_lock_);
865 test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_);
866 test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_);
philipelfd870db2017-01-23 03:22:15 -0800867 test::Statistics encode_time_ms_ GUARDED_BY(comparison_lock_);
868 test::Statistics encode_usage_percent_ GUARDED_BY(comparison_lock_);
869 test::Statistics decode_time_ms_ GUARDED_BY(comparison_lock_);
870 test::Statistics decode_time_max_ms_ GUARDED_BY(comparison_lock_);
871 test::Statistics media_bitrate_bps_ GUARDED_BY(comparison_lock_);
ivica5d6a06c2015-09-17 05:30:24 -0700872
873 const int frames_to_process_;
874 int frames_recorded_;
875 int frames_processed_;
876 int dropped_frames_;
pbos14fe7082016-04-20 06:35:56 -0700877 int dropped_frames_before_first_encode_;
878 int dropped_frames_before_rendering_;
ivica5d6a06c2015-09-17 05:30:24 -0700879 int64_t last_render_time_;
880 uint32_t rtp_timestamp_delta_;
881
882 rtc::CriticalSection crit_;
883 std::deque<VideoFrame> frames_ GUARDED_BY(crit_);
nisse97f0b932016-05-26 09:44:40 -0700884 rtc::Optional<VideoFrame> last_rendered_frame_ GUARDED_BY(crit_);
sprange1f2f1f2016-02-01 02:04:52 -0800885 rtc::TimestampWrapAroundHandler wrap_handler_ GUARDED_BY(crit_);
886 std::map<int64_t, int64_t> send_times_ GUARDED_BY(crit_);
887 std::map<int64_t, int64_t> recv_times_ GUARDED_BY(crit_);
888 std::map<int64_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_);
ilnik3dd5ad92017-02-09 04:58:53 -0800889 rtc::Optional<uint32_t> first_encoded_timestamp_ GUARDED_BY(crit_);
890 rtc::Optional<uint32_t> first_sent_timestamp_ GUARDED_BY(crit_);
ivica5d6a06c2015-09-17 05:30:24 -0700891 const double avg_psnr_threshold_;
892 const double avg_ssim_threshold_;
893
894 rtc::CriticalSection comparison_lock_;
Peter Boström8c38e8b2015-11-26 17:45:47 +0100895 std::vector<rtc::PlatformThread*> comparison_thread_pool_;
896 rtc::PlatformThread stats_polling_thread_;
Peter Boström5811a392015-12-10 13:02:50 +0100897 rtc::Event comparison_available_event_;
ivica5d6a06c2015-09-17 05:30:24 -0700898 std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_);
Peter Boström5811a392015-12-10 13:02:50 +0100899 rtc::Event done_;
ivica5d6a06c2015-09-17 05:30:24 -0700900};
901
palmkviste75f2042016-09-28 06:19:48 -0700902VideoQualityTest::VideoQualityTest()
903 : clock_(Clock::GetRealTimeClock()), receive_logs_(0), send_logs_(0) {}
ivica5d6a06c2015-09-17 05:30:24 -0700904
minyue626bc952016-10-31 05:47:02 -0700905VideoQualityTest::Params::Params()
906 : call({false, Call::Config::BitrateConfig()}),
907 video({false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false,
brandtr1293aca2016-11-16 22:47:29 -0800908 false, "", ""}),
minyue626bc952016-10-31 05:47:02 -0700909 audio({false, false}),
910 screenshare({false, 10, 0}),
911 analyzer({"", 0.0, 0.0, 0, "", ""}),
912 pipe(),
913 logs(false),
914 ss({std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()}) {}
915
916VideoQualityTest::Params::~Params() = default;
917
ivica5d6a06c2015-09-17 05:30:24 -0700918void VideoQualityTest::TestBody() {}
919
sprangce4aef12015-11-02 07:23:20 -0800920std::string VideoQualityTest::GenerateGraphTitle() const {
921 std::stringstream ss;
minyue626bc952016-10-31 05:47:02 -0700922 ss << params_.video.codec;
923 ss << " (" << params_.video.target_bitrate_bps / 1000 << "kbps";
924 ss << ", " << params_.video.fps << " FPS";
sprangce4aef12015-11-02 07:23:20 -0800925 if (params_.screenshare.scroll_duration)
926 ss << ", " << params_.screenshare.scroll_duration << "s scroll";
927 if (params_.ss.streams.size() > 1)
928 ss << ", Stream #" << params_.ss.selected_stream;
929 if (params_.ss.num_spatial_layers > 1)
930 ss << ", Layer #" << params_.ss.selected_sl;
931 ss << ")";
932 return ss.str();
933}
934
935void VideoQualityTest::CheckParams() {
stefan7de8d642017-02-07 07:14:08 -0800936 if (!params_.video.enabled)
937 return;
sprangce4aef12015-11-02 07:23:20 -0800938 // Add a default stream in none specified.
939 if (params_.ss.streams.empty())
940 params_.ss.streams.push_back(VideoQualityTest::DefaultVideoStream(params_));
941 if (params_.ss.num_spatial_layers == 0)
942 params_.ss.num_spatial_layers = 1;
943
944 if (params_.pipe.loss_percent != 0 ||
945 params_.pipe.queue_length_packets != 0) {
946 // Since LayerFilteringTransport changes the sequence numbers, we can't
947 // use that feature with pack loss, since the NACK request would end up
948 // retransmitting the wrong packets.
949 RTC_CHECK(params_.ss.selected_sl == -1 ||
sprangee37de32015-11-23 06:10:23 -0800950 params_.ss.selected_sl == params_.ss.num_spatial_layers - 1);
minyue626bc952016-10-31 05:47:02 -0700951 RTC_CHECK(params_.video.selected_tl == -1 ||
952 params_.video.selected_tl ==
953 params_.video.num_temporal_layers - 1);
sprangce4aef12015-11-02 07:23:20 -0800954 }
955
956 // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as it
957 // does in some parts of the code?
minyue626bc952016-10-31 05:47:02 -0700958 RTC_CHECK_GE(params_.video.max_bitrate_bps, params_.video.target_bitrate_bps);
959 RTC_CHECK_GE(params_.video.target_bitrate_bps, params_.video.min_bitrate_bps);
960 RTC_CHECK_LT(params_.video.selected_tl, params_.video.num_temporal_layers);
sprangce4aef12015-11-02 07:23:20 -0800961 RTC_CHECK_LT(params_.ss.selected_stream, params_.ss.streams.size());
962 for (const VideoStream& stream : params_.ss.streams) {
963 RTC_CHECK_GE(stream.min_bitrate_bps, 0);
964 RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps);
965 RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps);
kwiberg352444f2016-11-28 15:58:53 -0800966 RTC_CHECK_EQ(stream.temporal_layer_thresholds_bps.size(),
minyue626bc952016-10-31 05:47:02 -0700967 params_.video.num_temporal_layers - 1);
sprangce4aef12015-11-02 07:23:20 -0800968 }
969 // TODO(ivica): Should we check if the sum of all streams/layers is equal to
970 // the total bitrate? We anyway have to update them in the case bitrate
971 // estimator changes the total bitrates.
972 RTC_CHECK_GE(params_.ss.num_spatial_layers, 1);
973 RTC_CHECK_LE(params_.ss.selected_sl, params_.ss.num_spatial_layers);
974 RTC_CHECK(params_.ss.spatial_layers.empty() ||
975 params_.ss.spatial_layers.size() ==
976 static_cast<size_t>(params_.ss.num_spatial_layers));
minyue626bc952016-10-31 05:47:02 -0700977 if (params_.video.codec == "VP8") {
sprangce4aef12015-11-02 07:23:20 -0800978 RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1);
minyue626bc952016-10-31 05:47:02 -0700979 } else if (params_.video.codec == "VP9") {
kwibergaf476c72016-11-28 15:21:39 -0800980 RTC_CHECK_EQ(params_.ss.streams.size(), 1);
sprangce4aef12015-11-02 07:23:20 -0800981 }
982}
983
984// Static.
985std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) {
986 // Parse comma separated nonnegative integers, where some elements may be
987 // empty. The empty values are replaced with -1.
988 // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40}
989 // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1}
990 std::vector<int> result;
991 if (str.empty())
992 return result;
993
994 const char* p = str.c_str();
995 int value = -1;
996 int pos;
997 while (*p) {
998 if (*p == ',') {
999 result.push_back(value);
1000 value = -1;
1001 ++p;
1002 continue;
1003 }
1004 RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1)
1005 << "Unexpected non-number value.";
1006 p += pos;
1007 }
1008 result.push_back(value);
1009 return result;
1010}
1011
1012// Static.
1013VideoStream VideoQualityTest::DefaultVideoStream(const Params& params) {
1014 VideoStream stream;
minyue626bc952016-10-31 05:47:02 -07001015 stream.width = params.video.width;
1016 stream.height = params.video.height;
1017 stream.max_framerate = params.video.fps;
1018 stream.min_bitrate_bps = params.video.min_bitrate_bps;
1019 stream.target_bitrate_bps = params.video.target_bitrate_bps;
1020 stream.max_bitrate_bps = params.video.max_bitrate_bps;
sprangce4aef12015-11-02 07:23:20 -08001021 stream.max_qp = 52;
minyue626bc952016-10-31 05:47:02 -07001022 if (params.video.num_temporal_layers == 2)
sprangce4aef12015-11-02 07:23:20 -08001023 stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps);
1024 return stream;
1025}
1026
1027// Static.
1028void VideoQualityTest::FillScalabilitySettings(
1029 Params* params,
1030 const std::vector<std::string>& stream_descriptors,
1031 size_t selected_stream,
1032 int num_spatial_layers,
1033 int selected_sl,
1034 const std::vector<std::string>& sl_descriptors) {
1035 // Read VideoStream and SpatialLayer elements from a list of comma separated
1036 // lists. To use a default value for an element, use -1 or leave empty.
1037 // Validity checks performed in CheckParams.
1038
1039 RTC_CHECK(params->ss.streams.empty());
1040 for (auto descriptor : stream_descriptors) {
1041 if (descriptor.empty())
1042 continue;
1043 VideoStream stream = VideoQualityTest::DefaultVideoStream(*params);
1044 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1045 if (v[0] != -1)
1046 stream.width = static_cast<size_t>(v[0]);
1047 if (v[1] != -1)
1048 stream.height = static_cast<size_t>(v[1]);
1049 if (v[2] != -1)
1050 stream.max_framerate = v[2];
1051 if (v[3] != -1)
1052 stream.min_bitrate_bps = v[3];
1053 if (v[4] != -1)
1054 stream.target_bitrate_bps = v[4];
1055 if (v[5] != -1)
1056 stream.max_bitrate_bps = v[5];
1057 if (v.size() > 6 && v[6] != -1)
1058 stream.max_qp = v[6];
1059 if (v.size() > 7) {
1060 stream.temporal_layer_thresholds_bps.clear();
1061 stream.temporal_layer_thresholds_bps.insert(
1062 stream.temporal_layer_thresholds_bps.end(), v.begin() + 7, v.end());
1063 } else {
1064 // Automatic TL thresholds for more than two layers not supported.
minyue626bc952016-10-31 05:47:02 -07001065 RTC_CHECK_LE(params->video.num_temporal_layers, 2);
sprangce4aef12015-11-02 07:23:20 -08001066 }
1067 params->ss.streams.push_back(stream);
1068 }
1069 params->ss.selected_stream = selected_stream;
1070
1071 params->ss.num_spatial_layers = num_spatial_layers ? num_spatial_layers : 1;
1072 params->ss.selected_sl = selected_sl;
1073 RTC_CHECK(params->ss.spatial_layers.empty());
1074 for (auto descriptor : sl_descriptors) {
1075 if (descriptor.empty())
1076 continue;
1077 std::vector<int> v = VideoQualityTest::ParseCSV(descriptor);
1078 RTC_CHECK_GT(v[2], 0);
1079
1080 SpatialLayer layer;
1081 layer.scaling_factor_num = v[0] == -1 ? 1 : v[0];
1082 layer.scaling_factor_den = v[1] == -1 ? 1 : v[1];
1083 layer.target_bitrate_bps = v[2];
1084 params->ss.spatial_layers.push_back(layer);
1085 }
1086}
1087
minyuea27172d2016-11-01 05:59:29 -07001088void VideoQualityTest::SetupVideo(Transport* send_transport,
1089 Transport* recv_transport) {
sprangce4aef12015-11-02 07:23:20 -08001090 if (params_.logs)
ivica5d6a06c2015-09-17 05:30:24 -07001091 trace_to_stderr_.reset(new test::TraceToStderr);
1092
brandtr8313a6f2017-01-13 07:41:19 -08001093 size_t num_video_streams = params_.ss.streams.size();
1094 size_t num_flexfec_streams = params_.video.flexfec ? 1 : 0;
1095 CreateSendConfig(num_video_streams, 0, num_flexfec_streams, send_transport);
ivica5d6a06c2015-09-17 05:30:24 -07001096
1097 int payload_type;
minyue626bc952016-10-31 05:47:02 -07001098 if (params_.video.codec == "H264") {
magjedceecea42016-11-28 07:20:21 -08001099 video_encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264")));
hbosbab934b2016-01-27 01:36:03 -08001100 payload_type = kPayloadTypeH264;
minyue626bc952016-10-31 05:47:02 -07001101 } else if (params_.video.codec == "VP8") {
magjed509e4fe2016-11-18 01:34:11 -08001102 video_encoder_.reset(VP8Encoder::Create());
ivica5d6a06c2015-09-17 05:30:24 -07001103 payload_type = kPayloadTypeVP8;
minyue626bc952016-10-31 05:47:02 -07001104 } else if (params_.video.codec == "VP9") {
magjed509e4fe2016-11-18 01:34:11 -08001105 video_encoder_.reset(VP9Encoder::Create());
ivica5d6a06c2015-09-17 05:30:24 -07001106 payload_type = kPayloadTypeVP9;
1107 } else {
1108 RTC_NOTREACHED() << "Codec not supported!";
1109 return;
1110 }
minyuea27172d2016-11-01 05:59:29 -07001111 video_send_config_.encoder_settings.encoder = video_encoder_.get();
minyue626bc952016-10-31 05:47:02 -07001112 video_send_config_.encoder_settings.payload_name = params_.video.codec;
stefanff483612015-12-21 03:14:00 -08001113 video_send_config_.encoder_settings.payload_type = payload_type;
1114 video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
1115 video_send_config_.rtp.rtx.payload_type = kSendRtxPayloadType;
brandtr8313a6f2017-01-13 07:41:19 -08001116 for (size_t i = 0; i < num_video_streams; ++i)
stefanff483612015-12-21 03:14:00 -08001117 video_send_config_.rtp.rtx.ssrcs.push_back(kSendRtxSsrcs[i]);
ivica5d6a06c2015-09-17 05:30:24 -07001118
stefanff483612015-12-21 03:14:00 -08001119 video_send_config_.rtp.extensions.clear();
minyue626bc952016-10-31 05:47:02 -07001120 if (params_.call.send_side_bwe) {
stefanff483612015-12-21 03:14:00 -08001121 video_send_config_.rtp.extensions.push_back(
isheriff6f8d6862016-05-26 11:24:55 -07001122 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
Stefan Holmer12952972015-10-29 15:13:24 +01001123 test::kTransportSequenceNumberExtensionId));
1124 } else {
stefanff483612015-12-21 03:14:00 -08001125 video_send_config_.rtp.extensions.push_back(RtpExtension(
isheriff6f8d6862016-05-26 11:24:55 -07001126 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
Erik SprĂ¥ng6b8d3552015-09-24 15:06:57 +02001127 }
1128
stefanff483612015-12-21 03:14:00 -08001129 video_encoder_config_.min_transmit_bitrate_bps =
minyue626bc952016-10-31 05:47:02 -07001130 params_.video.min_transmit_bps;
perkjfa10b552016-10-02 23:45:26 -07001131
brandtr1293aca2016-11-16 22:47:29 -08001132 video_send_config_.suspend_below_min_bitrate =
1133 params_.video.suspend_below_min_bitrate;
1134
perkjfa10b552016-10-02 23:45:26 -07001135 video_encoder_config_.number_of_streams = params_.ss.streams.size();
1136 video_encoder_config_.max_bitrate_bps = 0;
1137 for (size_t i = 0; i < params_.ss.streams.size(); ++i) {
1138 video_encoder_config_.max_bitrate_bps +=
1139 params_.ss.streams[i].max_bitrate_bps;
1140 }
1141 video_encoder_config_.video_stream_factory =
1142 new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams);
1143
stefanff483612015-12-21 03:14:00 -08001144 video_encoder_config_.spatial_layers = params_.ss.spatial_layers;
ivica5d6a06c2015-09-17 05:30:24 -07001145
1146 CreateMatchingReceiveConfigs(recv_transport);
1147
brandtr8313a6f2017-01-13 07:41:19 -08001148 for (size_t i = 0; i < num_video_streams; ++i) {
stefanff483612015-12-21 03:14:00 -08001149 video_receive_configs_[i].rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
brandtr14742122017-01-27 04:53:07 -08001150 video_receive_configs_[i].rtp.rtx_ssrc = kSendRtxSsrcs[i];
1151 video_receive_configs_[i].rtp.rtx_payload_types[payload_type] =
sprangce4aef12015-11-02 07:23:20 -08001152 kSendRtxPayloadType;
minyue626bc952016-10-31 05:47:02 -07001153 video_receive_configs_[i].rtp.transport_cc = params_.call.send_side_bwe;
Stefan Holmer85d5ac72017-02-09 16:25:16 +01001154 video_receive_configs_[i].rtp.remb = !params_.call.send_side_bwe;
sprangce4aef12015-11-02 07:23:20 -08001155 }
brandtr1293aca2016-11-16 22:47:29 -08001156
1157 if (params_.video.flexfec) {
brandtr8313a6f2017-01-13 07:41:19 -08001158 // Override send config constructed by CreateSendConfig.
brandtr1293aca2016-11-16 22:47:29 -08001159 video_send_config_.rtp.flexfec.protected_media_ssrcs = {
1160 kVideoSendSsrcs[params_.ss.selected_stream]};
1161
brandtr8313a6f2017-01-13 07:41:19 -08001162 // The matching receive config is _not_ created by
1163 // CreateMatchingReceiveConfigs, since VideoQualityTest is not a BaseTest.
1164 // Set up the receive config manually instead.
1165 FlexfecReceiveStream::Config flexfec_receive_config(recv_transport);
brandtr1cfbd602016-12-08 04:17:53 -08001166 flexfec_receive_config.payload_type =
brandtr3d200bd2017-01-16 06:59:19 -08001167 video_send_config_.rtp.flexfec.payload_type;
1168 flexfec_receive_config.remote_ssrc = video_send_config_.rtp.flexfec.ssrc;
brandtr1293aca2016-11-16 22:47:29 -08001169 flexfec_receive_config.protected_media_ssrcs =
1170 video_send_config_.rtp.flexfec.protected_media_ssrcs;
brandtrfa5a3682017-01-17 01:33:54 -08001171 flexfec_receive_config.local_ssrc = kReceiverLocalVideoSsrc;
brandtrb29e6522016-12-21 06:37:18 -08001172 flexfec_receive_config.transport_cc = params_.call.send_side_bwe;
1173 if (params_.call.send_side_bwe) {
1174 flexfec_receive_config.rtp_header_extensions.push_back(
1175 RtpExtension(RtpExtension::kTransportSequenceNumberUri,
1176 test::kTransportSequenceNumberExtensionId));
1177 } else {
1178 flexfec_receive_config.rtp_header_extensions.push_back(RtpExtension(
1179 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
1180 }
brandtr1293aca2016-11-16 22:47:29 -08001181 flexfec_receive_configs_.push_back(flexfec_receive_config);
1182 }
1183
1184 if (params_.video.ulpfec) {
1185 video_send_config_.rtp.ulpfec.red_payload_type = kRedPayloadType;
1186 video_send_config_.rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType;
1187 video_send_config_.rtp.ulpfec.red_rtx_payload_type = kRtxRedPayloadType;
1188
1189 video_receive_configs_[params_.ss.selected_stream]
1190 .rtp.ulpfec.red_payload_type =
1191 video_send_config_.rtp.ulpfec.red_payload_type;
1192 video_receive_configs_[params_.ss.selected_stream]
1193 .rtp.ulpfec.ulpfec_payload_type =
1194 video_send_config_.rtp.ulpfec.ulpfec_payload_type;
1195 video_receive_configs_[params_.ss.selected_stream]
1196 .rtp.ulpfec.red_rtx_payload_type =
1197 video_send_config_.rtp.ulpfec.red_rtx_payload_type;
1198 }
ivica5d6a06c2015-09-17 05:30:24 -07001199}
1200
sprangce4aef12015-11-02 07:23:20 -08001201void VideoQualityTest::SetupScreenshare() {
1202 RTC_CHECK(params_.screenshare.enabled);
ivica5d6a06c2015-09-17 05:30:24 -07001203
1204 // Fill out codec settings.
stefanff483612015-12-21 03:14:00 -08001205 video_encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen;
kthelgason2bc68642017-02-07 07:02:22 -08001206 degradation_preference_ =
1207 VideoSendStream::DegradationPreference::kMaintainResolution;
minyue626bc952016-10-31 05:47:02 -07001208 if (params_.video.codec == "VP8") {
kthelgason29a44e32016-09-27 03:52:02 -07001209 VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings();
1210 vp8_settings.denoisingOn = false;
1211 vp8_settings.frameDroppingOn = false;
1212 vp8_settings.numberOfTemporalLayers =
minyue626bc952016-10-31 05:47:02 -07001213 static_cast<unsigned char>(params_.video.num_temporal_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001214 video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject<
1215 VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings);
minyue626bc952016-10-31 05:47:02 -07001216 } else if (params_.video.codec == "VP9") {
kthelgason29a44e32016-09-27 03:52:02 -07001217 VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings();
1218 vp9_settings.denoisingOn = false;
1219 vp9_settings.frameDroppingOn = false;
1220 vp9_settings.numberOfTemporalLayers =
minyue626bc952016-10-31 05:47:02 -07001221 static_cast<unsigned char>(params_.video.num_temporal_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001222 vp9_settings.numberOfSpatialLayers =
sprangce4aef12015-11-02 07:23:20 -08001223 static_cast<unsigned char>(params_.ss.num_spatial_layers);
kthelgason29a44e32016-09-27 03:52:02 -07001224 video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject<
1225 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings);
ivica5d6a06c2015-09-17 05:30:24 -07001226 }
1227
1228 // Setup frame generator.
1229 const size_t kWidth = 1850;
1230 const size_t kHeight = 1110;
1231 std::vector<std::string> slides;
1232 slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv"));
1233 slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv"));
1234 slides.push_back(test::ResourcePath("photo_1850_1110", "yuv"));
1235 slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv"));
1236
sprangce4aef12015-11-02 07:23:20 -08001237 if (params_.screenshare.scroll_duration == 0) {
ivica5d6a06c2015-09-17 05:30:24 -07001238 // Cycle image every slide_change_interval seconds.
1239 frame_generator_.reset(test::FrameGenerator::CreateFromYuvFile(
1240 slides, kWidth, kHeight,
minyue626bc952016-10-31 05:47:02 -07001241 params_.screenshare.slide_change_interval * params_.video.fps));
ivica5d6a06c2015-09-17 05:30:24 -07001242 } else {
minyue626bc952016-10-31 05:47:02 -07001243 RTC_CHECK_LE(params_.video.width, kWidth);
1244 RTC_CHECK_LE(params_.video.height, kHeight);
sprangce4aef12015-11-02 07:23:20 -08001245 RTC_CHECK_GT(params_.screenshare.slide_change_interval, 0);
1246 const int kPauseDurationMs = (params_.screenshare.slide_change_interval -
1247 params_.screenshare.scroll_duration) *
1248 1000;
1249 RTC_CHECK_LE(params_.screenshare.scroll_duration,
1250 params_.screenshare.slide_change_interval);
ivica5d6a06c2015-09-17 05:30:24 -07001251
sprangce4aef12015-11-02 07:23:20 -08001252 frame_generator_.reset(
1253 test::FrameGenerator::CreateScrollingInputFromYuvFiles(
minyue626bc952016-10-31 05:47:02 -07001254 clock_, slides, kWidth, kHeight, params_.video.width,
1255 params_.video.height, params_.screenshare.scroll_duration * 1000,
sprangce4aef12015-11-02 07:23:20 -08001256 kPauseDurationMs));
ivica5d6a06c2015-09-17 05:30:24 -07001257 }
1258}
1259
perkja49cbd32016-09-16 07:53:41 -07001260void VideoQualityTest::CreateCapturer() {
sprangce4aef12015-11-02 07:23:20 -08001261 if (params_.screenshare.enabled) {
1262 test::FrameGeneratorCapturer* frame_generator_capturer =
perkja49cbd32016-09-16 07:53:41 -07001263 new test::FrameGeneratorCapturer(clock_, frame_generator_.release(),
minyue626bc952016-10-31 05:47:02 -07001264 params_.video.fps);
ivica2d4e6c52015-09-23 01:57:06 -07001265 EXPECT_TRUE(frame_generator_capturer->Init());
minyuea27172d2016-11-01 05:59:29 -07001266 video_capturer_.reset(frame_generator_capturer);
ivica5d6a06c2015-09-17 05:30:24 -07001267 } else {
sprangce4aef12015-11-02 07:23:20 -08001268 if (params_.video.clip_name.empty()) {
minyuea27172d2016-11-01 05:59:29 -07001269 video_capturer_.reset(test::VcmCapturer::Create(
minyue626bc952016-10-31 05:47:02 -07001270 params_.video.width, params_.video.height, params_.video.fps));
sprang1bed2e42017-01-23 08:46:51 -08001271 if (!video_capturer_) {
1272 // Failed to get actual camera, use chroma generator as backup.
1273 video_capturer_.reset(test::FrameGeneratorCapturer::Create(
1274 params_.video.width, params_.video.height, params_.video.fps,
1275 clock_));
1276 }
ivica5d6a06c2015-09-17 05:30:24 -07001277 } else {
minyuea27172d2016-11-01 05:59:29 -07001278 video_capturer_.reset(test::FrameGeneratorCapturer::CreateFromYuvFile(
perkja49cbd32016-09-16 07:53:41 -07001279 test::ResourcePath(params_.video.clip_name, "yuv"),
minyue626bc952016-10-31 05:47:02 -07001280 params_.video.width, params_.video.height, params_.video.fps,
ivica2d4e6c52015-09-23 01:57:06 -07001281 clock_));
minyuea27172d2016-11-01 05:59:29 -07001282 ASSERT_TRUE(video_capturer_) << "Could not create capturer for "
1283 << params_.video.clip_name
1284 << ".yuv. Is this resource file present?";
ivica5d6a06c2015-09-17 05:30:24 -07001285 }
1286 }
sprang1bed2e42017-01-23 08:46:51 -08001287 RTC_DCHECK(video_capturer_.get());
ivica5d6a06c2015-09-17 05:30:24 -07001288}
1289
sprang7a975f72015-10-12 06:33:21 -07001290void VideoQualityTest::RunWithAnalyzer(const Params& params) {
sprangce4aef12015-11-02 07:23:20 -08001291 params_ = params;
1292
minyue626bc952016-10-31 05:47:02 -07001293 RTC_CHECK(!params_.audio.enabled);
ivica5d6a06c2015-09-17 05:30:24 -07001294 // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to
1295 // differentiate between the analyzer and the renderer case.
sprangce4aef12015-11-02 07:23:20 -08001296 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001297
1298 FILE* graph_data_output_file = nullptr;
sprangce4aef12015-11-02 07:23:20 -08001299 if (!params_.analyzer.graph_data_output_filename.empty()) {
ivica5d6a06c2015-09-17 05:30:24 -07001300 graph_data_output_file =
sprangce4aef12015-11-02 07:23:20 -08001301 fopen(params_.analyzer.graph_data_output_filename.c_str(), "w");
Peter Boström74f6e9e2016-04-04 17:56:10 +02001302 RTC_CHECK(graph_data_output_file)
sprangce4aef12015-11-02 07:23:20 -08001303 << "Can't open the file " << params_.analyzer.graph_data_output_filename
1304 << "!";
ivica87f83a92015-10-08 05:13:32 -07001305 }
sprang7a975f72015-10-12 06:33:21 -07001306
skvlad11a9cbf2016-10-07 11:53:05 -07001307 webrtc::RtcEventLogNullImpl event_log;
1308 Call::Config call_config(&event_log_);
minyue626bc952016-10-31 05:47:02 -07001309 call_config.bitrate_config = params.call.call_bitrate_config;
stefanf116bd02015-10-27 08:29:42 -07001310 CreateCalls(call_config, call_config);
1311
ivica87f83a92015-10-08 05:13:32 -07001312 test::LayerFilteringTransport send_transport(
minyue626bc952016-10-31 05:47:02 -07001313 params_.pipe, sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9,
1314 params_.video.selected_tl, params_.ss.selected_sl);
1315 test::DirectTransport recv_transport(params_.pipe, receiver_call_.get());
stefanf116bd02015-10-27 08:29:42 -07001316
sprangce4aef12015-11-02 07:23:20 -08001317 std::string graph_title = params_.analyzer.graph_title;
1318 if (graph_title.empty())
1319 graph_title = VideoQualityTest::GenerateGraphTitle();
1320
1321 // In the case of different resolutions, the functions calculating PSNR and
1322 // SSIM return -1.0, instead of a positive value as usual. VideoAnalyzer
1323 // aborts if the average psnr/ssim are below the given threshold, which is
1324 // 0.0 by default. Setting the thresholds to -1.1 prevents the unnecessary
1325 // abort.
1326 VideoStream& selected_stream = params_.ss.streams[params_.ss.selected_stream];
1327 int selected_sl = params_.ss.selected_sl != -1
1328 ? params_.ss.selected_sl
1329 : params_.ss.num_spatial_layers - 1;
1330 bool disable_quality_check =
minyue626bc952016-10-31 05:47:02 -07001331 selected_stream.width != params_.video.width ||
1332 selected_stream.height != params_.video.height ||
sprangce4aef12015-11-02 07:23:20 -08001333 (!params_.ss.spatial_layers.empty() &&
1334 params_.ss.spatial_layers[selected_sl].scaling_factor_num !=
1335 params_.ss.spatial_layers[selected_sl].scaling_factor_den);
1336 if (disable_quality_check) {
1337 fprintf(stderr,
1338 "Warning: Calculating PSNR and SSIM for downsized resolution "
ilnik3dd5ad92017-02-09 04:58:53 -08001339 "not implemented yet! Skipping PSNR and SSIM calculations!\n");
sprangce4aef12015-11-02 07:23:20 -08001340 }
1341
ivica5d6a06c2015-09-17 05:30:24 -07001342 VideoAnalyzer analyzer(
sprangce4aef12015-11-02 07:23:20 -08001343 &send_transport, params_.analyzer.test_label,
1344 disable_quality_check ? -1.1 : params_.analyzer.avg_psnr_threshold,
1345 disable_quality_check ? -1.1 : params_.analyzer.avg_ssim_threshold,
minyue626bc952016-10-31 05:47:02 -07001346 params_.analyzer.test_durations_secs * params_.video.fps,
sprangce4aef12015-11-02 07:23:20 -08001347 graph_data_output_file, graph_title,
ilnik3dd5ad92017-02-09 04:58:53 -08001348 kVideoSendSsrcs[params_.ss.selected_stream],
ilnik46a00212017-02-10 09:16:05 -08001349 kSendRtxSsrcs[params_.ss.selected_stream],
ilnik3dd5ad92017-02-09 04:58:53 -08001350 static_cast<uint32_t>(selected_stream.width),
1351 static_cast<uint32_t>(selected_stream.height));
ivica5d6a06c2015-09-17 05:30:24 -07001352
ivica5d6a06c2015-09-17 05:30:24 -07001353 analyzer.SetReceiver(receiver_call_->Receiver());
1354 send_transport.SetReceiver(&analyzer);
1355 recv_transport.SetReceiver(sender_call_->Receiver());
1356
minyuea27172d2016-11-01 05:59:29 -07001357 SetupVideo(&analyzer, &recv_transport);
stefanff483612015-12-21 03:14:00 -08001358 video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer;
pbos14fe7082016-04-20 06:35:56 -07001359 video_send_config_.pre_encode_callback = analyzer.pre_encode_proxy();
stefanff483612015-12-21 03:14:00 -08001360 for (auto& config : video_receive_configs_)
ivica5d6a06c2015-09-17 05:30:24 -07001361 config.pre_decode_callback = &analyzer;
Peter Boströme4499152016-02-05 11:13:28 +01001362 RTC_DCHECK(!video_send_config_.post_encode_callback);
1363 video_send_config_.post_encode_callback = analyzer.encode_timing_proxy();
ivica5d6a06c2015-09-17 05:30:24 -07001364
sprangce4aef12015-11-02 07:23:20 -08001365 if (params_.screenshare.enabled)
1366 SetupScreenshare();
ivica5d6a06c2015-09-17 05:30:24 -07001367
brandtr1293aca2016-11-16 22:47:29 -08001368 CreateFlexfecStreams();
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001369 CreateVideoStreams();
perkja49cbd32016-09-16 07:53:41 -07001370 analyzer.SetSendStream(video_send_stream_);
philipelfd870db2017-01-23 03:22:15 -08001371 if (video_receive_streams_.size() == 1)
1372 analyzer.SetReceiveStream(video_receive_streams_[0]);
kthelgason2bc68642017-02-07 07:02:22 -08001373
1374 video_send_stream_->SetSource(analyzer.OutputInterface(),
1375 degradation_preference_);
ivica5d6a06c2015-09-17 05:30:24 -07001376
perkja49cbd32016-09-16 07:53:41 -07001377 CreateCapturer();
1378 rtc::VideoSinkWants wants;
minyuea27172d2016-11-01 05:59:29 -07001379 video_capturer_->AddOrUpdateSink(analyzer.InputInterface(), wants);
ivicac1cc8542015-10-08 03:44:06 -07001380
palmkviste75f2042016-09-28 06:19:48 -07001381 StartEncodedFrameLogs(video_send_stream_);
1382 StartEncodedFrameLogs(video_receive_streams_[0]);
stefanff483612015-12-21 03:14:00 -08001383 video_send_stream_->Start();
1384 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1385 receive_stream->Start();
brandtr1293aca2016-11-16 22:47:29 -08001386 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_)
1387 receive_stream->Start();
minyuea27172d2016-11-01 05:59:29 -07001388 video_capturer_->Start();
ivica5d6a06c2015-09-17 05:30:24 -07001389
1390 analyzer.Wait();
1391
1392 send_transport.StopSending();
1393 recv_transport.StopSending();
1394
minyuea27172d2016-11-01 05:59:29 -07001395 video_capturer_->Stop();
brandtr1293aca2016-11-16 22:47:29 -08001396 for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_)
1397 receive_stream->Stop();
stefanff483612015-12-21 03:14:00 -08001398 for (VideoReceiveStream* receive_stream : video_receive_streams_)
1399 receive_stream->Stop();
1400 video_send_stream_->Stop();
ivica5d6a06c2015-09-17 05:30:24 -07001401
1402 DestroyStreams();
1403
1404 if (graph_data_output_file)
1405 fclose(graph_data_output_file);
1406}
1407
minyuea27172d2016-11-01 05:59:29 -07001408void VideoQualityTest::SetupAudio(int send_channel_id,
1409 int receive_channel_id,
1410 Call* call,
1411 Transport* transport,
1412 AudioReceiveStream** audio_receive_stream) {
1413 audio_send_config_ = AudioSendStream::Config(transport);
1414 audio_send_config_.voe_channel_id = send_channel_id;
1415 audio_send_config_.rtp.ssrc = kAudioSendSsrc;
1416
1417 // Add extension to enable audio send side BWE, and allow audio bit rate
1418 // adaptation.
1419 audio_send_config_.rtp.extensions.clear();
1420 if (params_.call.send_side_bwe) {
1421 audio_send_config_.rtp.extensions.push_back(
1422 webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri,
1423 test::kTransportSequenceNumberExtensionId));
minyue10cbb462016-11-07 09:29:22 -08001424 audio_send_config_.min_bitrate_bps = kOpusMinBitrateBps;
1425 audio_send_config_.max_bitrate_bps = kOpusBitrateFbBps;
minyuea27172d2016-11-01 05:59:29 -07001426 }
1427 audio_send_config_.send_codec_spec.codec_inst =
1428 CodecInst{120, "OPUS", 48000, 960, 2, 64000};
1429
1430 audio_send_stream_ = call->CreateAudioSendStream(audio_send_config_);
1431
1432 AudioReceiveStream::Config audio_config;
1433 audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc;
1434 audio_config.rtcp_send_transport = transport;
1435 audio_config.voe_channel_id = receive_channel_id;
1436 audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc;
1437 audio_config.rtp.transport_cc = params_.call.send_side_bwe;
1438 audio_config.rtp.extensions = audio_send_config_.rtp.extensions;
1439 audio_config.decoder_factory = decoder_factory_;
1440 if (params_.video.enabled && params_.audio.sync_video)
1441 audio_config.sync_group = kSyncGroup;
1442
1443 *audio_receive_stream = call->CreateAudioReceiveStream(audio_config);
1444}
1445
minyue73208662016-08-18 06:28:55 -07001446void VideoQualityTest::RunWithRenderers(const Params& params) {
sprangce4aef12015-11-02 07:23:20 -08001447 params_ = params;
1448 CheckParams();
ivica5d6a06c2015-09-17 05:30:24 -07001449
ivica5d6a06c2015-09-17 05:30:24 -07001450 // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to
1451 // match the full stack tests.
skvlad11a9cbf2016-10-07 11:53:05 -07001452 webrtc::RtcEventLogNullImpl event_log;
1453 Call::Config call_config(&event_log_);
minyue626bc952016-10-31 05:47:02 -07001454 call_config.bitrate_config = params_.call.call_bitrate_config;
minyue73208662016-08-18 06:28:55 -07001455
1456 ::VoiceEngineState voe;
minyue626bc952016-10-31 05:47:02 -07001457 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001458 CreateVoiceEngine(&voe, decoder_factory_);
1459 AudioState::Config audio_state_config;
1460 audio_state_config.voice_engine = voe.voice_engine;
aleloi10111bc2016-11-17 06:48:48 -08001461 audio_state_config.audio_mixer = AudioMixerImpl::Create();
minyue73208662016-08-18 06:28:55 -07001462 call_config.audio_state = AudioState::Create(audio_state_config);
1463 }
1464
kwiberg27f982b2016-03-01 11:52:33 -08001465 std::unique_ptr<Call> call(Call::Create(call_config));
ivica5d6a06c2015-09-17 05:30:24 -07001466
minyuea27172d2016-11-01 05:59:29 -07001467 // TODO(minyue): consider if this is a good transport even for audio only
1468 // calls.
ivica5d6a06c2015-09-17 05:30:24 -07001469 test::LayerFilteringTransport transport(
stefanf116bd02015-10-27 08:29:42 -07001470 params.pipe, call.get(), kPayloadTypeVP8, kPayloadTypeVP9,
minyue626bc952016-10-31 05:47:02 -07001471 params.video.selected_tl, params_.ss.selected_sl);
ivica5d6a06c2015-09-17 05:30:24 -07001472 // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at
1473 // least share as much code as possible. That way this test would also match
1474 // the full stack tests better.
1475 transport.SetReceiver(call->Receiver());
1476
minyuea27172d2016-11-01 05:59:29 -07001477 VideoReceiveStream* video_receive_stream = nullptr;
brandtr1293aca2016-11-16 22:47:29 -08001478 FlexfecReceiveStream* flexfec_receive_stream = nullptr;
minyuea27172d2016-11-01 05:59:29 -07001479 std::unique_ptr<test::VideoRenderer> local_preview;
1480 std::unique_ptr<test::VideoRenderer> loopback_video;
1481 if (params_.video.enabled) {
1482 // Create video renderers.
1483 local_preview.reset(test::VideoRenderer::Create(
1484 "Local Preview", params_.video.width, params_.video.height));
ivica87f83a92015-10-08 05:13:32 -07001485
minyuea27172d2016-11-01 05:59:29 -07001486 size_t stream_id = params_.ss.selected_stream;
1487 std::string title = "Loopback Video";
1488 if (params_.ss.streams.size() > 1) {
1489 std::ostringstream s;
1490 s << stream_id;
1491 title += " - Stream #" + s.str();
1492 }
sprangce4aef12015-11-02 07:23:20 -08001493
minyuea27172d2016-11-01 05:59:29 -07001494 loopback_video.reset(test::VideoRenderer::Create(
1495 title.c_str(), params_.ss.streams[stream_id].width,
1496 params_.ss.streams[stream_id].height));
mflodman48a4beb2016-07-01 13:03:59 +02001497
minyuea27172d2016-11-01 05:59:29 -07001498 SetupVideo(&transport, &transport);
minyuea27172d2016-11-01 05:59:29 -07001499 video_send_config_.pre_encode_callback = local_preview.get();
1500 video_receive_configs_[stream_id].renderer = loopback_video.get();
1501 if (params_.audio.enabled && params_.audio.sync_video)
1502 video_receive_configs_[stream_id].sync_group = kSyncGroup;
1503
minyuea27172d2016-11-01 05:59:29 -07001504 if (params_.screenshare.enabled)
1505 SetupScreenshare();
1506
1507 video_send_stream_ = call->CreateVideoSendStream(
1508 video_send_config_.Copy(), video_encoder_config_.Copy());
brandtr1293aca2016-11-16 22:47:29 -08001509 if (params_.video.flexfec) {
1510 RTC_DCHECK(!flexfec_receive_configs_.empty());
1511 flexfec_receive_stream =
1512 call->CreateFlexfecReceiveStream(flexfec_receive_configs_[0]);
1513 }
minyuea27172d2016-11-01 05:59:29 -07001514 video_receive_stream = call->CreateVideoReceiveStream(
1515 video_receive_configs_[stream_id].Copy());
1516 CreateCapturer();
kthelgason2bc68642017-02-07 07:02:22 -08001517 video_send_stream_->SetSource(video_capturer_.get(),
1518 degradation_preference_);
philipel274c1dc2016-05-04 06:21:01 -07001519 }
1520
minyue73208662016-08-18 06:28:55 -07001521 AudioReceiveStream* audio_receive_stream = nullptr;
minyue626bc952016-10-31 05:47:02 -07001522 if (params_.audio.enabled) {
minyuea27172d2016-11-01 05:59:29 -07001523 SetupAudio(voe.send_channel_id, voe.receive_channel_id, call.get(),
1524 &transport, &audio_receive_stream);
minyue73208662016-08-18 06:28:55 -07001525 }
1526
palmkviste75f2042016-09-28 06:19:48 -07001527 StartEncodedFrameLogs(video_receive_stream);
1528 StartEncodedFrameLogs(video_send_stream_);
1529
minyue73208662016-08-18 06:28:55 -07001530 // Start sending and receiving video.
minyuea27172d2016-11-01 05:59:29 -07001531 if (params_.video.enabled) {
brandtr1293aca2016-11-16 22:47:29 -08001532 if (flexfec_receive_stream)
1533 flexfec_receive_stream->Start();
minyuea27172d2016-11-01 05:59:29 -07001534 video_receive_stream->Start();
1535 video_send_stream_->Start();
1536 video_capturer_->Start();
1537 }
ivica5d6a06c2015-09-17 05:30:24 -07001538
minyue626bc952016-10-31 05:47:02 -07001539 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001540 // Start receiving audio.
1541 audio_receive_stream->Start();
1542 EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id));
minyue73208662016-08-18 06:28:55 -07001543
1544 // Start sending audio.
1545 audio_send_stream_->Start();
1546 EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id));
1547 }
1548
ivica5d6a06c2015-09-17 05:30:24 -07001549 test::PressEnterToContinue();
1550
minyue626bc952016-10-31 05:47:02 -07001551 if (params_.audio.enabled) {
minyue73208662016-08-18 06:28:55 -07001552 // Stop sending audio.
1553 EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id));
1554 audio_send_stream_->Stop();
1555
1556 // Stop receiving audio.
minyue73208662016-08-18 06:28:55 -07001557 EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id));
1558 audio_receive_stream->Stop();
minyuea27172d2016-11-01 05:59:29 -07001559 call->DestroyAudioSendStream(audio_send_stream_);
1560 call->DestroyAudioReceiveStream(audio_receive_stream);
minyue73208662016-08-18 06:28:55 -07001561 }
1562
1563 // Stop receiving and sending video.
minyuea27172d2016-11-01 05:59:29 -07001564 if (params_.video.enabled) {
1565 video_capturer_->Stop();
1566 video_send_stream_->Stop();
1567 video_receive_stream->Stop();
brandtr1293aca2016-11-16 22:47:29 -08001568 if (flexfec_receive_stream) {
1569 flexfec_receive_stream->Stop();
1570 call->DestroyFlexfecReceiveStream(flexfec_receive_stream);
1571 }
minyuea27172d2016-11-01 05:59:29 -07001572 call->DestroyVideoReceiveStream(video_receive_stream);
1573 call->DestroyVideoSendStream(video_send_stream_);
minyue73208662016-08-18 06:28:55 -07001574 }
1575
ivica5d6a06c2015-09-17 05:30:24 -07001576 transport.StopSending();
minyue626bc952016-10-31 05:47:02 -07001577 if (params_.audio.enabled)
minyue73208662016-08-18 06:28:55 -07001578 DestroyVoiceEngine(&voe);
ivica5d6a06c2015-09-17 05:30:24 -07001579}
1580
palmkviste75f2042016-09-28 06:19:48 -07001581void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) {
minyue626bc952016-10-31 05:47:02 -07001582 if (!params_.video.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07001583 std::ostringstream str;
1584 str << send_logs_++;
1585 std::string prefix =
minyue626bc952016-10-31 05:47:02 -07001586 params_.video.encoded_frame_base_path + "." + str.str() + ".send.";
palmkviste75f2042016-09-28 06:19:48 -07001587 stream->EnableEncodedFrameRecording(
1588 std::vector<rtc::PlatformFile>(
1589 {rtc::CreatePlatformFile(prefix + "1.ivf"),
1590 rtc::CreatePlatformFile(prefix + "2.ivf"),
1591 rtc::CreatePlatformFile(prefix + "3.ivf")}),
1592 10000000);
1593 }
1594}
1595void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) {
minyue626bc952016-10-31 05:47:02 -07001596 if (!params_.video.encoded_frame_base_path.empty()) {
palmkviste75f2042016-09-28 06:19:48 -07001597 std::ostringstream str;
1598 str << receive_logs_++;
1599 std::string path =
minyue626bc952016-10-31 05:47:02 -07001600 params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf";
palmkviste75f2042016-09-28 06:19:48 -07001601 stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path),
1602 10000000);
1603 }
1604}
1605
ivica5d6a06c2015-09-17 05:30:24 -07001606} // namespace webrtc