ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 10 | #include "webrtc/video/video_quality_test.h" |
perkj | 9fdbda6 | 2016-09-15 09:19:20 -0700 | [diff] [blame] | 11 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 12 | #include <stdio.h> |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 13 | #include <algorithm> |
| 14 | #include <deque> |
| 15 | #include <map> |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 16 | #include <sstream> |
mflodman | d1590b2 | 2015-12-09 07:07:59 -0800 | [diff] [blame] | 17 | #include <string> |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 20 | #include "webrtc/base/checks.h" |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 21 | #include "webrtc/base/cpu_time.h" |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 22 | #include "webrtc/base/event.h" |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 23 | #include "webrtc/base/format_macros.h" |
nisse | c7fe3c2 | 2016-04-20 03:25:36 -0700 | [diff] [blame] | 24 | #include "webrtc/base/optional.h" |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 25 | #include "webrtc/base/platform_file.h" |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 26 | #include "webrtc/base/timeutils.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 27 | #include "webrtc/call/call.h" |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 28 | #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 29 | #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
aleloi | 10111bc | 2016-11-17 06:48:48 -0800 | [diff] [blame] | 30 | #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 31 | #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 32 | #include "webrtc/modules/rtp_rtcp/source/rtp_format.h" |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 33 | #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 34 | #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
| 35 | #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
| 36 | #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 37 | #include "webrtc/system_wrappers/include/cpu_info.h" |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 38 | #include "webrtc/system_wrappers/include/field_trial.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 39 | #include "webrtc/test/gtest.h" |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 40 | #include "webrtc/test/layer_filtering_transport.h" |
| 41 | #include "webrtc/test/run_loop.h" |
| 42 | #include "webrtc/test/statistics.h" |
| 43 | #include "webrtc/test/testsupport/fileutils.h" |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 44 | #include "webrtc/test/vcm_capturer.h" |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 45 | #include "webrtc/test/video_renderer.h" |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 46 | #include "webrtc/voice_engine/include/voe_base.h" |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 47 | |
| 48 | namespace { |
| 49 | |
| 50 | constexpr int kSendStatsPollingIntervalMs = 1000; |
| 51 | constexpr int kPayloadTypeH264 = 122; |
| 52 | constexpr int kPayloadTypeVP8 = 123; |
| 53 | constexpr int kPayloadTypeVP9 = 124; |
| 54 | constexpr size_t kMaxComparisons = 10; |
| 55 | constexpr char kSyncGroup[] = "av_sync"; |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 56 | constexpr int kOpusMinBitrateBps = 6000; |
| 57 | constexpr int kOpusBitrateFbBps = 32000; |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 58 | constexpr int kFramesSentInQuickTest = 1; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 59 | |
| 60 | struct VoiceEngineState { |
| 61 | VoiceEngineState() |
| 62 | : voice_engine(nullptr), |
| 63 | base(nullptr), |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 64 | send_channel_id(-1), |
| 65 | receive_channel_id(-1) {} |
| 66 | |
| 67 | webrtc::VoiceEngine* voice_engine; |
| 68 | webrtc::VoEBase* base; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 69 | int send_channel_id; |
| 70 | int receive_channel_id; |
| 71 | }; |
| 72 | |
| 73 | void CreateVoiceEngine(VoiceEngineState* voe, |
| 74 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> |
| 75 | decoder_factory) { |
| 76 | voe->voice_engine = webrtc::VoiceEngine::Create(); |
| 77 | voe->base = webrtc::VoEBase::GetInterface(voe->voice_engine); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 78 | EXPECT_EQ(0, voe->base->Init(nullptr, nullptr, decoder_factory)); |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 79 | webrtc::VoEBase::ChannelConfig config; |
| 80 | config.enable_voice_pacing = true; |
| 81 | voe->send_channel_id = voe->base->CreateChannel(config); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 82 | EXPECT_GE(voe->send_channel_id, 0); |
| 83 | voe->receive_channel_id = voe->base->CreateChannel(); |
| 84 | EXPECT_GE(voe->receive_channel_id, 0); |
| 85 | } |
| 86 | |
| 87 | void DestroyVoiceEngine(VoiceEngineState* voe) { |
| 88 | voe->base->DeleteChannel(voe->send_channel_id); |
| 89 | voe->send_channel_id = -1; |
| 90 | voe->base->DeleteChannel(voe->receive_channel_id); |
| 91 | voe->receive_channel_id = -1; |
| 92 | voe->base->Release(); |
| 93 | voe->base = nullptr; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 94 | |
| 95 | webrtc::VoiceEngine::Delete(voe->voice_engine); |
| 96 | voe->voice_engine = nullptr; |
| 97 | } |
| 98 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 99 | class VideoStreamFactory |
| 100 | : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface { |
| 101 | public: |
| 102 | explicit VideoStreamFactory(const std::vector<webrtc::VideoStream>& streams) |
| 103 | : streams_(streams) {} |
| 104 | |
| 105 | private: |
| 106 | std::vector<webrtc::VideoStream> CreateEncoderStreams( |
| 107 | int width, |
| 108 | int height, |
| 109 | const webrtc::VideoEncoderConfig& encoder_config) override { |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 110 | // The highest layer must match the incoming resolution. |
| 111 | std::vector<webrtc::VideoStream> streams = streams_; |
| 112 | streams[streams_.size() - 1].height = height; |
| 113 | streams[streams_.size() - 1].width = width; |
| 114 | return streams; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | std::vector<webrtc::VideoStream> streams_; |
| 118 | }; |
| 119 | |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 120 | bool IsFlexfec(int payload_type) { |
| 121 | return payload_type == webrtc::VideoQualityTest::kFlexfecPayloadType; |
| 122 | } |
| 123 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 124 | } // namespace |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 125 | |
| 126 | namespace webrtc { |
| 127 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 128 | class VideoAnalyzer : public PacketReceiver, |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 129 | public Transport, |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 130 | public rtc::VideoSinkInterface<VideoFrame> { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 131 | public: |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 132 | VideoAnalyzer(test::LayerFilteringTransport* transport, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 133 | const std::string& test_label, |
| 134 | double avg_psnr_threshold, |
| 135 | double avg_ssim_threshold, |
| 136 | int duration_frames, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 137 | FILE* graph_data_output_file, |
| 138 | const std::string& graph_title, |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 139 | uint32_t ssrc_to_analyze, |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 140 | uint32_t rtx_ssrc_to_analyze, |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 141 | uint32_t selected_stream_width, |
| 142 | uint32_t selected_stream_height, |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 143 | int selected_sl, |
| 144 | int selected_tl, |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 145 | bool is_quick_test_enabled) |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 146 | : transport_(transport), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 147 | receiver_(nullptr), |
| 148 | send_stream_(nullptr), |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 149 | receive_stream_(nullptr), |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 150 | captured_frame_forwarder_(this), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 151 | test_label_(test_label), |
| 152 | graph_data_output_file_(graph_data_output_file), |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 153 | graph_title_(graph_title), |
| 154 | ssrc_to_analyze_(ssrc_to_analyze), |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 155 | rtx_ssrc_to_analyze_(rtx_ssrc_to_analyze), |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 156 | selected_stream_width_(selected_stream_width), |
| 157 | selected_stream_height_(selected_stream_height), |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 158 | selected_sl_(selected_sl), |
| 159 | selected_tl_(selected_tl), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 160 | pre_encode_proxy_(this), |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 161 | encode_timing_proxy_(this), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 162 | frames_to_process_(duration_frames), |
| 163 | frames_recorded_(0), |
| 164 | frames_processed_(0), |
| 165 | dropped_frames_(0), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 166 | dropped_frames_before_first_encode_(0), |
| 167 | dropped_frames_before_rendering_(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 168 | last_render_time_(0), |
| 169 | rtp_timestamp_delta_(0), |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 170 | total_media_bytes_(0), |
| 171 | first_sending_time_(0), |
| 172 | last_sending_time_(0), |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 173 | cpu_time_(0), |
| 174 | wallclock_time_(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 175 | avg_psnr_threshold_(avg_psnr_threshold), |
| 176 | avg_ssim_threshold_(avg_ssim_threshold), |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 177 | is_quick_test_enabled_(is_quick_test_enabled), |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 178 | stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 179 | comparison_available_event_(false, false), |
Peter Boström | dd45eb6 | 2016-01-19 15:22:32 +0100 | [diff] [blame] | 180 | done_(true, false) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 181 | // Create thread pool for CPU-expensive PSNR/SSIM calculations. |
| 182 | |
| 183 | // Try to use about as many threads as cores, but leave kMinCoresLeft alone, |
| 184 | // so that we don't accidentally starve "real" worker threads (codec etc). |
| 185 | // Also, don't allocate more than kMaxComparisonThreads, even if there are |
| 186 | // spare cores. |
| 187 | |
| 188 | uint32_t num_cores = CpuInfo::DetectNumberOfCores(); |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 189 | RTC_DCHECK_GE(num_cores, 1); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 190 | static const uint32_t kMinCoresLeft = 4; |
| 191 | static const uint32_t kMaxComparisonThreads = 8; |
| 192 | |
| 193 | if (num_cores <= kMinCoresLeft) { |
| 194 | num_cores = 1; |
| 195 | } else { |
| 196 | num_cores -= kMinCoresLeft; |
| 197 | num_cores = std::min(num_cores, kMaxComparisonThreads); |
| 198 | } |
| 199 | |
| 200 | for (uint32_t i = 0; i < num_cores; ++i) { |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 201 | rtc::PlatformThread* thread = |
| 202 | new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer"); |
| 203 | thread->Start(); |
| 204 | comparison_thread_pool_.push_back(thread); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 205 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | ~VideoAnalyzer() { |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 209 | for (rtc::PlatformThread* thread : comparison_thread_pool_) { |
| 210 | thread->Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 211 | delete thread; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; } |
| 216 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 217 | void SetSendStream(VideoSendStream* stream) { |
| 218 | rtc::CritScope lock(&crit_); |
| 219 | RTC_DCHECK(!send_stream_); |
| 220 | send_stream_ = stream; |
| 221 | } |
| 222 | |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 223 | void SetReceiveStream(VideoReceiveStream* stream) { |
| 224 | rtc::CritScope lock(&crit_); |
| 225 | RTC_DCHECK(!receive_stream_); |
| 226 | receive_stream_ = stream; |
| 227 | } |
| 228 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 229 | rtc::VideoSinkInterface<VideoFrame>* InputInterface() { |
| 230 | return &captured_frame_forwarder_; |
| 231 | } |
| 232 | rtc::VideoSourceInterface<VideoFrame>* OutputInterface() { |
| 233 | return &captured_frame_forwarder_; |
| 234 | } |
| 235 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 236 | DeliveryStatus DeliverPacket(MediaType media_type, |
| 237 | const uint8_t* packet, |
| 238 | size_t length, |
| 239 | const PacketTime& packet_time) override { |
Taylor Brandstetter | 433b95a | 2016-03-18 11:41:03 -0700 | [diff] [blame] | 240 | // Ignore timestamps of RTCP packets. They're not synchronized with |
| 241 | // RTP packet timestamps and so they would confuse wrap_handler_. |
| 242 | if (RtpHeaderParser::IsRtcp(packet, length)) { |
| 243 | return receiver_->DeliverPacket(media_type, packet, length, packet_time); |
| 244 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 245 | RtpUtility::RtpHeaderParser parser(packet, length); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 246 | RTPHeader header; |
danilchap | f6975f4 | 2015-12-28 10:18:46 -0800 | [diff] [blame] | 247 | parser.Parse(&header); |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 248 | if (!IsFlexfec(header.payloadType) && |
| 249 | (header.ssrc == ssrc_to_analyze_ || |
| 250 | header.ssrc == rtx_ssrc_to_analyze_)) { |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 251 | // Ignore FlexFEC timestamps, to avoid collisions with media timestamps. |
| 252 | // (FlexFEC and media are sent on different SSRCs, which have different |
| 253 | // timestamps spaces.) |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 254 | // Also ignore packets from wrong SSRC, but include retransmits. |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 255 | rtc::CritScope lock(&crit_); |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 256 | int64_t timestamp = |
| 257 | wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_); |
| 258 | recv_times_[timestamp] = |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 259 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
| 260 | } |
| 261 | |
| 262 | return receiver_->DeliverPacket(media_type, packet, length, packet_time); |
| 263 | } |
| 264 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 265 | void MeasuredEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 266 | rtc::CritScope crit(&comparison_lock_); |
| 267 | samples_encode_time_ms_[ntp_time_ms] = encode_time_ms; |
| 268 | } |
| 269 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 270 | void PreEncodeOnFrame(const VideoFrame& video_frame) { |
| 271 | rtc::CritScope lock(&crit_); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 272 | if (!first_encoded_timestamp_) { |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 273 | while (frames_.front().timestamp() != video_frame.timestamp()) { |
| 274 | ++dropped_frames_before_first_encode_; |
| 275 | frames_.pop_front(); |
| 276 | RTC_CHECK(!frames_.empty()); |
| 277 | } |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 278 | first_encoded_timestamp_ = |
| 279 | rtc::Optional<uint32_t>(video_frame.timestamp()); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | void PostEncodeFrameCallback(const EncodedFrame& encoded_frame) { |
| 284 | rtc::CritScope lock(&crit_); |
| 285 | if (!first_sent_timestamp_ && |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 286 | encoded_frame.encoded_width_ == selected_stream_width_ && |
| 287 | encoded_frame.encoded_height_ == selected_stream_height_) { |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 288 | first_sent_timestamp_ = rtc::Optional<uint32_t>(encoded_frame.timestamp_); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 292 | bool SendRtp(const uint8_t* packet, |
| 293 | size_t length, |
| 294 | const PacketOptions& options) override { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 295 | RtpUtility::RtpHeaderParser parser(packet, length); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 296 | RTPHeader header; |
danilchap | f6975f4 | 2015-12-28 10:18:46 -0800 | [diff] [blame] | 297 | parser.Parse(&header); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 298 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 299 | int64_t current_time = |
| 300 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 301 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 302 | bool result = transport_->SendRtp(packet, length, options); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 303 | { |
| 304 | rtc::CritScope lock(&crit_); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 305 | if (rtp_timestamp_delta_ == 0 && header.ssrc == ssrc_to_analyze_) { |
ilnik | 1e1c84d | 2017-02-09 08:32:53 -0800 | [diff] [blame] | 306 | RTC_CHECK(static_cast<bool>(first_sent_timestamp_)); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 307 | rtp_timestamp_delta_ = header.timestamp - *first_sent_timestamp_; |
ilnik | e67c59e | 2017-02-09 04:08:56 -0800 | [diff] [blame] | 308 | } |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 309 | |
| 310 | if (!IsFlexfec(header.payloadType) && header.ssrc == ssrc_to_analyze_) { |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 311 | // Ignore FlexFEC timestamps, to avoid collisions with media timestamps. |
| 312 | // (FlexFEC and media are sent on different SSRCs, which have different |
| 313 | // timestamps spaces.) |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 314 | // Also ignore packets from wrong SSRC and retransmits. |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 315 | int64_t timestamp = |
| 316 | wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_); |
| 317 | send_times_[timestamp] = current_time; |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 318 | |
| 319 | if (IsInSelectedSpatialAndTemporalLayer(packet, length, header)) { |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 320 | encoded_frame_sizes_[timestamp] += |
| 321 | length - (header.headerLength + header.paddingLength); |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 322 | total_media_bytes_ += |
| 323 | length - (header.headerLength + header.paddingLength); |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 324 | } |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 325 | if (first_sending_time_ == 0) |
| 326 | first_sending_time_ = current_time; |
| 327 | last_sending_time_ = current_time; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 328 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 329 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 330 | return result; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | bool SendRtcp(const uint8_t* packet, size_t length) override { |
| 334 | return transport_->SendRtcp(packet, length); |
| 335 | } |
| 336 | |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 337 | void OnFrame(const VideoFrame& video_frame) override { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 338 | int64_t render_time_ms = |
| 339 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 340 | |
| 341 | rtc::CritScope lock(&crit_); |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 342 | |
| 343 | StartExcludingCpuThreadTime(); |
| 344 | |
Taylor Brandstetter | 433b95a | 2016-03-18 11:41:03 -0700 | [diff] [blame] | 345 | int64_t send_timestamp = |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 346 | wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 347 | |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 348 | while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) { |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 349 | if (!last_rendered_frame_) { |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 350 | // No previous frame rendered, this one was dropped after sending but |
| 351 | // before rendering. |
| 352 | ++dropped_frames_before_rendering_; |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 353 | } else { |
| 354 | AddFrameComparison(frames_.front(), *last_rendered_frame_, true, |
| 355 | render_time_ms); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 356 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 357 | frames_.pop_front(); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 358 | RTC_DCHECK(!frames_.empty()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | VideoFrame reference_frame = frames_.front(); |
| 362 | frames_.pop_front(); |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 363 | int64_t reference_timestamp = |
| 364 | wrap_handler_.Unwrap(reference_frame.timestamp()); |
| 365 | if (send_timestamp == reference_timestamp - 1) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 366 | // TODO(ivica): Make this work for > 2 streams. |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 367 | // Look at RTPSender::BuildRTPHeader. |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 368 | ++send_timestamp; |
| 369 | } |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 370 | ASSERT_EQ(reference_timestamp, send_timestamp); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 371 | |
| 372 | AddFrameComparison(reference_frame, video_frame, false, render_time_ms); |
| 373 | |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 374 | last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame); |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 375 | |
| 376 | StopExcludingCpuThreadTime(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 377 | } |
| 378 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 379 | void Wait() { |
| 380 | // Frame comparisons can be very expensive. Wait for test to be done, but |
| 381 | // at time-out check if frames_processed is going up. If so, give it more |
| 382 | // time, otherwise fail. Hopefully this will reduce test flakiness. |
| 383 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 384 | stats_polling_thread_.Start(); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 385 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 386 | int last_frames_processed = -1; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 387 | int iteration = 0; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 388 | while (!done_.Wait(VideoQualityTest::kDefaultTimeoutMs)) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 389 | int frames_processed; |
| 390 | { |
| 391 | rtc::CritScope crit(&comparison_lock_); |
| 392 | frames_processed = frames_processed_; |
| 393 | } |
| 394 | |
| 395 | // Print some output so test infrastructure won't think we've crashed. |
| 396 | const char* kKeepAliveMessages[3] = { |
| 397 | "Uh, I'm-I'm not quite dead, sir.", |
| 398 | "Uh, I-I think uh, I could pull through, sir.", |
| 399 | "Actually, I think I'm all right to come with you--"}; |
| 400 | printf("- %s\n", kKeepAliveMessages[iteration++ % 3]); |
| 401 | |
| 402 | if (last_frames_processed == -1) { |
| 403 | last_frames_processed = frames_processed; |
| 404 | continue; |
| 405 | } |
Peter Boström | dd45eb6 | 2016-01-19 15:22:32 +0100 | [diff] [blame] | 406 | if (frames_processed == last_frames_processed) { |
| 407 | EXPECT_GT(frames_processed, last_frames_processed) |
| 408 | << "Analyzer stalled while waiting for test to finish."; |
| 409 | done_.Set(); |
| 410 | break; |
| 411 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 412 | last_frames_processed = frames_processed; |
| 413 | } |
| 414 | |
| 415 | if (iteration > 0) |
| 416 | printf("- Farewell, sweet Concorde!\n"); |
| 417 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 418 | stats_polling_thread_.Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 419 | } |
| 420 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 421 | rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() { |
| 422 | return &pre_encode_proxy_; |
| 423 | } |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 424 | EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; } |
| 425 | |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 426 | void StartMeasuringCpuProcessTime() { |
| 427 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 428 | cpu_time_ -= rtc::GetProcessCpuTimeNanos(); |
| 429 | wallclock_time_ -= rtc::SystemTimeNanos(); |
| 430 | } |
| 431 | |
| 432 | void StopMeasuringCpuProcessTime() { |
| 433 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 434 | cpu_time_ += rtc::GetProcessCpuTimeNanos(); |
| 435 | wallclock_time_ += rtc::SystemTimeNanos(); |
| 436 | } |
| 437 | |
| 438 | void StartExcludingCpuThreadTime() { |
| 439 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 440 | cpu_time_ += rtc::GetThreadCpuTimeNanos(); |
| 441 | } |
| 442 | |
| 443 | void StopExcludingCpuThreadTime() { |
| 444 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 445 | cpu_time_ -= rtc::GetThreadCpuTimeNanos(); |
| 446 | } |
| 447 | |
| 448 | double GetCpuUsagePercent() { |
| 449 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 450 | return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0; |
| 451 | } |
| 452 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 453 | test::LayerFilteringTransport* const transport_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 454 | PacketReceiver* receiver_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 455 | |
| 456 | private: |
| 457 | struct FrameComparison { |
| 458 | FrameComparison() |
| 459 | : dropped(false), |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 460 | input_time_ms(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 461 | send_time_ms(0), |
| 462 | recv_time_ms(0), |
| 463 | render_time_ms(0), |
| 464 | encoded_frame_size(0) {} |
| 465 | |
| 466 | FrameComparison(const VideoFrame& reference, |
| 467 | const VideoFrame& render, |
| 468 | bool dropped, |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 469 | int64_t input_time_ms, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 470 | int64_t send_time_ms, |
| 471 | int64_t recv_time_ms, |
| 472 | int64_t render_time_ms, |
| 473 | size_t encoded_frame_size) |
| 474 | : reference(reference), |
| 475 | render(render), |
| 476 | dropped(dropped), |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 477 | input_time_ms(input_time_ms), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 478 | send_time_ms(send_time_ms), |
| 479 | recv_time_ms(recv_time_ms), |
| 480 | render_time_ms(render_time_ms), |
| 481 | encoded_frame_size(encoded_frame_size) {} |
| 482 | |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 483 | FrameComparison(bool dropped, |
| 484 | int64_t input_time_ms, |
| 485 | int64_t send_time_ms, |
| 486 | int64_t recv_time_ms, |
| 487 | int64_t render_time_ms, |
| 488 | size_t encoded_frame_size) |
| 489 | : dropped(dropped), |
| 490 | input_time_ms(input_time_ms), |
| 491 | send_time_ms(send_time_ms), |
| 492 | recv_time_ms(recv_time_ms), |
| 493 | render_time_ms(render_time_ms), |
| 494 | encoded_frame_size(encoded_frame_size) {} |
| 495 | |
| 496 | rtc::Optional<VideoFrame> reference; |
| 497 | rtc::Optional<VideoFrame> render; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 498 | bool dropped; |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 499 | int64_t input_time_ms; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 500 | int64_t send_time_ms; |
| 501 | int64_t recv_time_ms; |
| 502 | int64_t render_time_ms; |
| 503 | size_t encoded_frame_size; |
| 504 | }; |
| 505 | |
| 506 | struct Sample { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 507 | Sample(int dropped, |
| 508 | int64_t input_time_ms, |
| 509 | int64_t send_time_ms, |
| 510 | int64_t recv_time_ms, |
| 511 | int64_t render_time_ms, |
| 512 | size_t encoded_frame_size, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 513 | double psnr, |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 514 | double ssim) |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 515 | : dropped(dropped), |
| 516 | input_time_ms(input_time_ms), |
| 517 | send_time_ms(send_time_ms), |
| 518 | recv_time_ms(recv_time_ms), |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 519 | render_time_ms(render_time_ms), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 520 | encoded_frame_size(encoded_frame_size), |
| 521 | psnr(psnr), |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 522 | ssim(ssim) {} |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 523 | |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 524 | int dropped; |
| 525 | int64_t input_time_ms; |
| 526 | int64_t send_time_ms; |
| 527 | int64_t recv_time_ms; |
| 528 | int64_t render_time_ms; |
| 529 | size_t encoded_frame_size; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 530 | double psnr; |
| 531 | double ssim; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 532 | }; |
| 533 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 534 | // This class receives the send-side OnEncodeTiming and is provided to not |
| 535 | // conflict with the receiver-side pre_decode_callback. |
| 536 | class OnEncodeTimingProxy : public EncodedFrameObserver { |
| 537 | public: |
| 538 | explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {} |
| 539 | |
| 540 | void OnEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) override { |
| 541 | parent_->MeasuredEncodeTiming(ntp_time_ms, encode_time_ms); |
| 542 | } |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 543 | void EncodedFrameCallback(const EncodedFrame& frame) override { |
| 544 | parent_->PostEncodeFrameCallback(frame); |
| 545 | } |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 546 | |
| 547 | private: |
| 548 | VideoAnalyzer* const parent_; |
| 549 | }; |
| 550 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 551 | // This class receives the send-side OnFrame callback and is provided to not |
| 552 | // conflict with the receiver-side renderer callback. |
| 553 | class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> { |
| 554 | public: |
| 555 | explicit PreEncodeProxy(VideoAnalyzer* parent) : parent_(parent) {} |
| 556 | |
| 557 | void OnFrame(const VideoFrame& video_frame) override { |
| 558 | parent_->PreEncodeOnFrame(video_frame); |
| 559 | } |
| 560 | |
| 561 | private: |
| 562 | VideoAnalyzer* const parent_; |
| 563 | }; |
| 564 | |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 565 | bool IsInSelectedSpatialAndTemporalLayer(const uint8_t* packet, |
| 566 | size_t length, |
| 567 | const RTPHeader& header) { |
| 568 | if (header.payloadType != kPayloadTypeVP9 && |
| 569 | header.payloadType != kPayloadTypeVP8) { |
| 570 | return true; |
| 571 | } else { |
| 572 | // Get VP8 and VP9 specific header to check layers indexes. |
| 573 | const uint8_t* payload = packet + header.headerLength; |
| 574 | const size_t payload_length = length - header.headerLength; |
| 575 | const size_t payload_data_length = payload_length - header.paddingLength; |
| 576 | const bool is_vp8 = header.payloadType == kPayloadTypeVP8; |
| 577 | std::unique_ptr<RtpDepacketizer> depacketizer( |
| 578 | RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); |
| 579 | RtpDepacketizer::ParsedPayload parsed_payload; |
| 580 | bool result = |
| 581 | depacketizer->Parse(&parsed_payload, payload, payload_data_length); |
| 582 | RTC_DCHECK(result); |
| 583 | const int temporal_idx = static_cast<int>( |
| 584 | is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx |
| 585 | : parsed_payload.type.Video.codecHeader.VP9.temporal_idx); |
| 586 | const int spatial_idx = static_cast<int>( |
| 587 | is_vp8 ? kNoSpatialIdx |
| 588 | : parsed_payload.type.Video.codecHeader.VP9.spatial_idx); |
| 589 | return (selected_tl_ < 0 || temporal_idx == kNoTemporalIdx || |
| 590 | temporal_idx <= selected_tl_) && |
| 591 | (selected_sl_ < 0 || spatial_idx == kNoSpatialIdx || |
| 592 | spatial_idx <= selected_sl_); |
| 593 | } |
| 594 | } |
| 595 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 596 | void AddFrameComparison(const VideoFrame& reference, |
| 597 | const VideoFrame& render, |
| 598 | bool dropped, |
| 599 | int64_t render_time_ms) |
| 600 | EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 601 | int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp()); |
| 602 | int64_t send_time_ms = send_times_[reference_timestamp]; |
| 603 | send_times_.erase(reference_timestamp); |
| 604 | int64_t recv_time_ms = recv_times_[reference_timestamp]; |
| 605 | recv_times_.erase(reference_timestamp); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 606 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 607 | // TODO(ivica): Make this work for > 2 streams. |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 608 | auto it = encoded_frame_sizes_.find(reference_timestamp); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 609 | if (it == encoded_frame_sizes_.end()) |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 610 | it = encoded_frame_sizes_.find(reference_timestamp - 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 611 | size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second; |
| 612 | if (it != encoded_frame_sizes_.end()) |
| 613 | encoded_frame_sizes_.erase(it); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 614 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 615 | rtc::CritScope crit(&comparison_lock_); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 616 | if (comparisons_.size() < kMaxComparisons) { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 617 | comparisons_.push_back(FrameComparison(reference, render, dropped, |
| 618 | reference.ntp_time_ms(), |
| 619 | send_time_ms, recv_time_ms, |
| 620 | render_time_ms, encoded_size)); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 621 | } else { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 622 | comparisons_.push_back(FrameComparison(dropped, |
| 623 | reference.ntp_time_ms(), |
| 624 | send_time_ms, recv_time_ms, |
| 625 | render_time_ms, encoded_size)); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 626 | } |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 627 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 628 | } |
| 629 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 630 | static void PollStatsThread(void* obj) { |
| 631 | static_cast<VideoAnalyzer*>(obj)->PollStats(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 632 | } |
| 633 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 634 | void PollStats() { |
| 635 | while (!done_.Wait(kSendStatsPollingIntervalMs)) { |
| 636 | rtc::CritScope crit(&comparison_lock_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 637 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 638 | VideoSendStream::Stats send_stats = send_stream_->GetStats(); |
| 639 | // It's not certain that we yet have estimates for any of these stats. |
| 640 | // Check that they are positive before mixing them in. |
| 641 | if (send_stats.encode_frame_rate > 0) |
| 642 | encode_frame_rate_.AddSample(send_stats.encode_frame_rate); |
| 643 | if (send_stats.avg_encode_time_ms > 0) |
| 644 | encode_time_ms_.AddSample(send_stats.avg_encode_time_ms); |
| 645 | if (send_stats.encode_usage_percent > 0) |
| 646 | encode_usage_percent_.AddSample(send_stats.encode_usage_percent); |
| 647 | if (send_stats.media_bitrate_bps > 0) |
| 648 | media_bitrate_bps_.AddSample(send_stats.media_bitrate_bps); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 649 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 650 | if (receive_stream_ != nullptr) { |
| 651 | VideoReceiveStream::Stats receive_stats = receive_stream_->GetStats(); |
| 652 | if (receive_stats.decode_ms > 0) |
| 653 | decode_time_ms_.AddSample(receive_stats.decode_ms); |
| 654 | if (receive_stats.max_decode_ms > 0) |
| 655 | decode_time_max_ms_.AddSample(receive_stats.max_decode_ms); |
| 656 | } |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 657 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static bool FrameComparisonThread(void* obj) { |
| 661 | return static_cast<VideoAnalyzer*>(obj)->CompareFrames(); |
| 662 | } |
| 663 | |
| 664 | bool CompareFrames() { |
| 665 | if (AllFramesRecorded()) |
| 666 | return false; |
| 667 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 668 | FrameComparison comparison; |
| 669 | |
| 670 | if (!PopComparison(&comparison)) { |
| 671 | // Wait until new comparison task is available, or test is done. |
| 672 | // If done, wake up remaining threads waiting. |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 673 | comparison_available_event_.Wait(1000); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 674 | if (AllFramesRecorded()) { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 675 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 676 | return false; |
| 677 | } |
| 678 | return true; // Try again. |
| 679 | } |
| 680 | |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 681 | StartExcludingCpuThreadTime(); |
| 682 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 683 | PerformFrameComparison(comparison); |
| 684 | |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 685 | StopExcludingCpuThreadTime(); |
| 686 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 687 | if (FrameProcessed()) { |
| 688 | PrintResults(); |
| 689 | if (graph_data_output_file_) |
| 690 | PrintSamplesToFile(); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 691 | done_.Set(); |
| 692 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 693 | return false; |
| 694 | } |
| 695 | |
| 696 | return true; |
| 697 | } |
| 698 | |
| 699 | bool PopComparison(FrameComparison* comparison) { |
| 700 | rtc::CritScope crit(&comparison_lock_); |
| 701 | // If AllFramesRecorded() is true, it means we have already popped |
| 702 | // frames_to_process_ frames from comparisons_, so there is no more work |
| 703 | // for this thread to be done. frames_processed_ might still be lower if |
| 704 | // all comparisons are not done, but those frames are currently being |
| 705 | // worked on by other threads. |
| 706 | if (comparisons_.empty() || AllFramesRecorded()) |
| 707 | return false; |
| 708 | |
| 709 | *comparison = comparisons_.front(); |
| 710 | comparisons_.pop_front(); |
| 711 | |
| 712 | FrameRecorded(); |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | // Increment counter for number of frames received for comparison. |
| 717 | void FrameRecorded() { |
| 718 | rtc::CritScope crit(&comparison_lock_); |
| 719 | ++frames_recorded_; |
| 720 | } |
| 721 | |
| 722 | // Returns true if all frames to be compared have been taken from the queue. |
| 723 | bool AllFramesRecorded() { |
| 724 | rtc::CritScope crit(&comparison_lock_); |
| 725 | assert(frames_recorded_ <= frames_to_process_); |
| 726 | return frames_recorded_ == frames_to_process_; |
| 727 | } |
| 728 | |
| 729 | // Increase count of number of frames processed. Returns true if this was the |
| 730 | // last frame to be processed. |
| 731 | bool FrameProcessed() { |
| 732 | rtc::CritScope crit(&comparison_lock_); |
| 733 | ++frames_processed_; |
| 734 | assert(frames_processed_ <= frames_to_process_); |
| 735 | return frames_processed_ == frames_to_process_; |
| 736 | } |
| 737 | |
| 738 | void PrintResults() { |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 739 | StopMeasuringCpuProcessTime(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 740 | rtc::CritScope crit(&comparison_lock_); |
| 741 | PrintResult("psnr", psnr_, " dB"); |
tnakamura | 3123cbc | 2016-02-10 11:21:51 -0800 | [diff] [blame] | 742 | PrintResult("ssim", ssim_, " score"); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 743 | PrintResult("sender_time", sender_time_, " ms"); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 744 | PrintResult("receiver_time", receiver_time_, " ms"); |
| 745 | PrintResult("total_delay_incl_network", end_to_end_, " ms"); |
| 746 | PrintResult("time_between_rendered_frames", rendered_delta_, " ms"); |
| 747 | PrintResult("encoded_frame_size", encoded_frame_size_, " bytes"); |
| 748 | PrintResult("encode_frame_rate", encode_frame_rate_, " fps"); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 749 | PrintResult("encode_time", encode_time_ms_, " ms"); |
| 750 | PrintResult("encode_usage_percent", encode_usage_percent_, " percent"); |
| 751 | PrintResult("media_bitrate", media_bitrate_bps_, " bps"); |
| 752 | |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 753 | printf("RESULT actual_bitrate: %s = %.6lf bps\n", test_label_.c_str(), |
| 754 | GetAverageMediaBitrateBps()); |
| 755 | |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 756 | if (receive_stream_ != nullptr) { |
| 757 | PrintResult("decode_time", decode_time_ms_, " ms"); |
| 758 | PrintResult("decode_time_max", decode_time_max_ms_, " ms"); |
| 759 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 760 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 761 | printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(), |
| 762 | dropped_frames_); |
| 763 | printf("RESULT dropped_frames_before_first_encode: %s = %d frames\n", |
| 764 | test_label_.c_str(), dropped_frames_before_first_encode_); |
| 765 | printf("RESULT dropped_frames_before_rendering: %s = %d frames\n", |
| 766 | test_label_.c_str(), dropped_frames_before_rendering_); |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 767 | printf("RESULT cpu_usage: %s = %lf %%\n", test_label_.c_str(), |
| 768 | GetCpuUsagePercent()); |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 769 | // Disable quality check for quick test, as quality checks may fail |
| 770 | // because too few samples were collected. |
| 771 | if (!is_quick_test_enabled_) { |
| 772 | EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); |
| 773 | EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_); |
| 774 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | void PerformFrameComparison(const FrameComparison& comparison) { |
| 778 | // Perform expensive psnr and ssim calculations while not holding lock. |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 779 | double psnr = -1.0; |
| 780 | double ssim = -1.0; |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 781 | if (comparison.reference) { |
| 782 | psnr = I420PSNR(&*comparison.reference, &*comparison.render); |
| 783 | ssim = I420SSIM(&*comparison.reference, &*comparison.render); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 784 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 785 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 786 | rtc::CritScope crit(&comparison_lock_); |
| 787 | if (graph_data_output_file_) { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 788 | samples_.push_back(Sample( |
| 789 | comparison.dropped, comparison.input_time_ms, comparison.send_time_ms, |
| 790 | comparison.recv_time_ms, comparison.render_time_ms, |
| 791 | comparison.encoded_frame_size, psnr, ssim)); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 792 | } |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 793 | if (psnr >= 0.0) |
| 794 | psnr_.AddSample(psnr); |
| 795 | if (ssim >= 0.0) |
| 796 | ssim_.AddSample(ssim); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 797 | |
| 798 | if (comparison.dropped) { |
| 799 | ++dropped_frames_; |
| 800 | return; |
| 801 | } |
| 802 | if (last_render_time_ != 0) |
| 803 | rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_); |
| 804 | last_render_time_ = comparison.render_time_ms; |
| 805 | |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 806 | sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms); |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 807 | if (comparison.recv_time_ms > 0) { |
| 808 | // If recv_time_ms == 0, this frame consisted of a packets which were all |
| 809 | // lost in the transport. Since we were able to render the frame, however, |
| 810 | // the dropped packets were recovered by FlexFEC. The FlexFEC recovery |
| 811 | // happens internally in Call, and we can therefore here not know which |
| 812 | // FEC packets that protected the lost media packets. Consequently, we |
| 813 | // were not able to record a meaningful recv_time_ms. We therefore skip |
| 814 | // this sample. |
| 815 | // |
| 816 | // The reasoning above does not hold for ULPFEC and RTX, as for those |
| 817 | // strategies the timestamp of the received packets is set to the |
| 818 | // timestamp of the protected/retransmitted media packet. I.e., then |
| 819 | // recv_time_ms != 0, even though the media packets were lost. |
| 820 | receiver_time_.AddSample(comparison.render_time_ms - |
| 821 | comparison.recv_time_ms); |
| 822 | } |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 823 | end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 824 | encoded_frame_size_.AddSample(comparison.encoded_frame_size); |
| 825 | } |
| 826 | |
| 827 | void PrintResult(const char* result_type, |
| 828 | test::Statistics stats, |
| 829 | const char* unit) { |
| 830 | printf("RESULT %s: %s = {%f, %f}%s\n", |
| 831 | result_type, |
| 832 | test_label_.c_str(), |
| 833 | stats.Mean(), |
| 834 | stats.StandardDeviation(), |
| 835 | unit); |
| 836 | } |
| 837 | |
| 838 | void PrintSamplesToFile(void) { |
| 839 | FILE* out = graph_data_output_file_; |
| 840 | rtc::CritScope crit(&comparison_lock_); |
| 841 | std::sort(samples_.begin(), samples_.end(), |
| 842 | [](const Sample& A, const Sample& B) -> bool { |
| 843 | return A.input_time_ms < B.input_time_ms; |
| 844 | }); |
| 845 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 846 | fprintf(out, "%s\n", graph_title_.c_str()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 847 | fprintf(out, "%" PRIuS "\n", samples_.size()); |
| 848 | fprintf(out, |
| 849 | "dropped " |
| 850 | "input_time_ms " |
| 851 | "send_time_ms " |
| 852 | "recv_time_ms " |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 853 | "render_time_ms " |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 854 | "encoded_frame_size " |
| 855 | "psnr " |
| 856 | "ssim " |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 857 | "encode_time_ms\n"); |
| 858 | int missing_encode_time_samples = 0; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 859 | for (const Sample& sample : samples_) { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 860 | auto it = samples_encode_time_ms_.find(sample.input_time_ms); |
| 861 | int encode_time_ms; |
| 862 | if (it != samples_encode_time_ms_.end()) { |
| 863 | encode_time_ms = it->second; |
| 864 | } else { |
| 865 | ++missing_encode_time_samples; |
| 866 | encode_time_ms = -1; |
| 867 | } |
| 868 | fprintf(out, "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRIuS |
| 869 | " %lf %lf %d\n", |
| 870 | sample.dropped, sample.input_time_ms, sample.send_time_ms, |
| 871 | sample.recv_time_ms, sample.render_time_ms, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 872 | sample.encoded_frame_size, sample.psnr, sample.ssim, |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 873 | encode_time_ms); |
| 874 | } |
| 875 | if (missing_encode_time_samples) { |
| 876 | fprintf(stderr, |
| 877 | "Warning: Missing encode_time_ms samples for %d frame(s).\n", |
| 878 | missing_encode_time_samples); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 882 | double GetAverageMediaBitrateBps() { |
| 883 | if (last_sending_time_ == first_sending_time_) { |
| 884 | return 0; |
| 885 | } else { |
| 886 | return static_cast<double>(total_media_bytes_) * 8 / |
| 887 | (last_sending_time_ - first_sending_time_) * |
| 888 | rtc::kNumMillisecsPerSec; |
| 889 | } |
| 890 | } |
| 891 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 892 | // Implements VideoSinkInterface to receive captured frames from a |
| 893 | // FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act |
| 894 | // as a source to VideoSendStream. |
| 895 | // It forwards all input frames to the VideoAnalyzer for later comparison and |
| 896 | // forwards the captured frames to the VideoSendStream. |
| 897 | class CapturedFrameForwarder : public rtc::VideoSinkInterface<VideoFrame>, |
| 898 | public rtc::VideoSourceInterface<VideoFrame> { |
| 899 | public: |
| 900 | explicit CapturedFrameForwarder(VideoAnalyzer* analyzer) |
| 901 | : analyzer_(analyzer), send_stream_input_(nullptr) {} |
| 902 | |
| 903 | private: |
| 904 | void OnFrame(const VideoFrame& video_frame) override { |
| 905 | VideoFrame copy = video_frame; |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 906 | // Frames from the capturer does not have a rtp timestamp. |
| 907 | // Create one so it can be used for comparison. |
| 908 | RTC_DCHECK_EQ(0, video_frame.timestamp()); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 909 | copy.set_timestamp(copy.ntp_time_ms() * 90); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 910 | analyzer_->AddCapturedFrameForComparison(copy); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 911 | rtc::CritScope lock(&crit_); |
| 912 | if (send_stream_input_) |
| 913 | send_stream_input_->OnFrame(video_frame); |
| 914 | } |
| 915 | |
| 916 | // Called when |send_stream_.SetSource()| is called. |
| 917 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 918 | const rtc::VideoSinkWants& wants) override { |
| 919 | rtc::CritScope lock(&crit_); |
| 920 | RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink); |
| 921 | send_stream_input_ = sink; |
| 922 | } |
| 923 | |
| 924 | // Called by |send_stream_| when |send_stream_.SetSource()| is called. |
| 925 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override { |
| 926 | rtc::CritScope lock(&crit_); |
| 927 | RTC_DCHECK(sink == send_stream_input_); |
| 928 | send_stream_input_ = nullptr; |
| 929 | } |
| 930 | |
| 931 | VideoAnalyzer* const analyzer_; |
| 932 | rtc::CriticalSection crit_; |
| 933 | rtc::VideoSinkInterface<VideoFrame>* send_stream_input_ GUARDED_BY(crit_); |
| 934 | }; |
| 935 | |
| 936 | void AddCapturedFrameForComparison(const VideoFrame& video_frame) { |
| 937 | rtc::CritScope lock(&crit_); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 938 | frames_.push_back(video_frame); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | VideoSendStream* send_stream_; |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 942 | VideoReceiveStream* receive_stream_; |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 943 | CapturedFrameForwarder captured_frame_forwarder_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 944 | const std::string test_label_; |
| 945 | FILE* const graph_data_output_file_; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 946 | const std::string graph_title_; |
| 947 | const uint32_t ssrc_to_analyze_; |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 948 | const uint32_t rtx_ssrc_to_analyze_; |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 949 | const uint32_t selected_stream_width_; |
| 950 | const uint32_t selected_stream_height_; |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 951 | const int selected_sl_; |
| 952 | const int selected_tl_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 953 | PreEncodeProxy pre_encode_proxy_; |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 954 | OnEncodeTimingProxy encode_timing_proxy_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 955 | std::vector<Sample> samples_ GUARDED_BY(comparison_lock_); |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 956 | std::map<int64_t, int> samples_encode_time_ms_ GUARDED_BY(comparison_lock_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 957 | test::Statistics sender_time_ GUARDED_BY(comparison_lock_); |
| 958 | test::Statistics receiver_time_ GUARDED_BY(comparison_lock_); |
| 959 | test::Statistics psnr_ GUARDED_BY(comparison_lock_); |
| 960 | test::Statistics ssim_ GUARDED_BY(comparison_lock_); |
| 961 | test::Statistics end_to_end_ GUARDED_BY(comparison_lock_); |
| 962 | test::Statistics rendered_delta_ GUARDED_BY(comparison_lock_); |
| 963 | test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_); |
| 964 | test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 965 | test::Statistics encode_time_ms_ GUARDED_BY(comparison_lock_); |
| 966 | test::Statistics encode_usage_percent_ GUARDED_BY(comparison_lock_); |
| 967 | test::Statistics decode_time_ms_ GUARDED_BY(comparison_lock_); |
| 968 | test::Statistics decode_time_max_ms_ GUARDED_BY(comparison_lock_); |
| 969 | test::Statistics media_bitrate_bps_ GUARDED_BY(comparison_lock_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 970 | |
| 971 | const int frames_to_process_; |
| 972 | int frames_recorded_; |
| 973 | int frames_processed_; |
| 974 | int dropped_frames_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 975 | int dropped_frames_before_first_encode_; |
| 976 | int dropped_frames_before_rendering_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 977 | int64_t last_render_time_; |
| 978 | uint32_t rtp_timestamp_delta_; |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 979 | int64_t total_media_bytes_; |
| 980 | int64_t first_sending_time_; |
| 981 | int64_t last_sending_time_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 982 | |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 983 | int64_t cpu_time_ GUARDED_BY(cpu_measurement_lock_); |
| 984 | int64_t wallclock_time_ GUARDED_BY(cpu_measurement_lock_); |
| 985 | rtc::CriticalSection cpu_measurement_lock_; |
| 986 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 987 | rtc::CriticalSection crit_; |
| 988 | std::deque<VideoFrame> frames_ GUARDED_BY(crit_); |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 989 | rtc::Optional<VideoFrame> last_rendered_frame_ GUARDED_BY(crit_); |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 990 | rtc::TimestampWrapAroundHandler wrap_handler_ GUARDED_BY(crit_); |
| 991 | std::map<int64_t, int64_t> send_times_ GUARDED_BY(crit_); |
| 992 | std::map<int64_t, int64_t> recv_times_ GUARDED_BY(crit_); |
| 993 | std::map<int64_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 994 | rtc::Optional<uint32_t> first_encoded_timestamp_ GUARDED_BY(crit_); |
| 995 | rtc::Optional<uint32_t> first_sent_timestamp_ GUARDED_BY(crit_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 996 | const double avg_psnr_threshold_; |
| 997 | const double avg_ssim_threshold_; |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 998 | bool is_quick_test_enabled_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 999 | |
| 1000 | rtc::CriticalSection comparison_lock_; |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 1001 | std::vector<rtc::PlatformThread*> comparison_thread_pool_; |
| 1002 | rtc::PlatformThread stats_polling_thread_; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1003 | rtc::Event comparison_available_event_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1004 | std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1005 | rtc::Event done_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1006 | }; |
| 1007 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1008 | VideoQualityTest::VideoQualityTest() |
| 1009 | : clock_(Clock::GetRealTimeClock()), receive_logs_(0), send_logs_(0) {} |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1010 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1011 | VideoQualityTest::Params::Params() |
| 1012 | : call({false, Call::Config::BitrateConfig()}), |
| 1013 | video({false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false, |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1014 | false, "", ""}), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1015 | audio({false, false}), |
| 1016 | screenshare({false, 10, 0}), |
| 1017 | analyzer({"", 0.0, 0.0, 0, "", ""}), |
| 1018 | pipe(), |
| 1019 | logs(false), |
| 1020 | ss({std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()}) {} |
| 1021 | |
| 1022 | VideoQualityTest::Params::~Params() = default; |
| 1023 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1024 | void VideoQualityTest::TestBody() {} |
| 1025 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1026 | std::string VideoQualityTest::GenerateGraphTitle() const { |
| 1027 | std::stringstream ss; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1028 | ss << params_.video.codec; |
| 1029 | ss << " (" << params_.video.target_bitrate_bps / 1000 << "kbps"; |
| 1030 | ss << ", " << params_.video.fps << " FPS"; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1031 | if (params_.screenshare.scroll_duration) |
| 1032 | ss << ", " << params_.screenshare.scroll_duration << "s scroll"; |
| 1033 | if (params_.ss.streams.size() > 1) |
| 1034 | ss << ", Stream #" << params_.ss.selected_stream; |
| 1035 | if (params_.ss.num_spatial_layers > 1) |
| 1036 | ss << ", Layer #" << params_.ss.selected_sl; |
| 1037 | ss << ")"; |
| 1038 | return ss.str(); |
| 1039 | } |
| 1040 | |
| 1041 | void VideoQualityTest::CheckParams() { |
stefan | 7de8d64 | 2017-02-07 07:14:08 -0800 | [diff] [blame] | 1042 | if (!params_.video.enabled) |
| 1043 | return; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1044 | // Add a default stream in none specified. |
| 1045 | if (params_.ss.streams.empty()) |
| 1046 | params_.ss.streams.push_back(VideoQualityTest::DefaultVideoStream(params_)); |
| 1047 | if (params_.ss.num_spatial_layers == 0) |
| 1048 | params_.ss.num_spatial_layers = 1; |
| 1049 | |
| 1050 | if (params_.pipe.loss_percent != 0 || |
| 1051 | params_.pipe.queue_length_packets != 0) { |
| 1052 | // Since LayerFilteringTransport changes the sequence numbers, we can't |
| 1053 | // use that feature with pack loss, since the NACK request would end up |
| 1054 | // retransmitting the wrong packets. |
| 1055 | RTC_CHECK(params_.ss.selected_sl == -1 || |
sprang | ee37de3 | 2015-11-23 06:10:23 -0800 | [diff] [blame] | 1056 | params_.ss.selected_sl == params_.ss.num_spatial_layers - 1); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1057 | RTC_CHECK(params_.video.selected_tl == -1 || |
| 1058 | params_.video.selected_tl == |
| 1059 | params_.video.num_temporal_layers - 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as it |
| 1063 | // does in some parts of the code? |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1064 | RTC_CHECK_GE(params_.video.max_bitrate_bps, params_.video.target_bitrate_bps); |
| 1065 | RTC_CHECK_GE(params_.video.target_bitrate_bps, params_.video.min_bitrate_bps); |
| 1066 | RTC_CHECK_LT(params_.video.selected_tl, params_.video.num_temporal_layers); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1067 | RTC_CHECK_LT(params_.ss.selected_stream, params_.ss.streams.size()); |
| 1068 | for (const VideoStream& stream : params_.ss.streams) { |
| 1069 | RTC_CHECK_GE(stream.min_bitrate_bps, 0); |
| 1070 | RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps); |
| 1071 | RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps); |
kwiberg | 352444f | 2016-11-28 15:58:53 -0800 | [diff] [blame] | 1072 | RTC_CHECK_EQ(stream.temporal_layer_thresholds_bps.size(), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1073 | params_.video.num_temporal_layers - 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1074 | } |
| 1075 | // TODO(ivica): Should we check if the sum of all streams/layers is equal to |
| 1076 | // the total bitrate? We anyway have to update them in the case bitrate |
| 1077 | // estimator changes the total bitrates. |
| 1078 | RTC_CHECK_GE(params_.ss.num_spatial_layers, 1); |
| 1079 | RTC_CHECK_LE(params_.ss.selected_sl, params_.ss.num_spatial_layers); |
| 1080 | RTC_CHECK(params_.ss.spatial_layers.empty() || |
| 1081 | params_.ss.spatial_layers.size() == |
| 1082 | static_cast<size_t>(params_.ss.num_spatial_layers)); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1083 | if (params_.video.codec == "VP8") { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1084 | RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1085 | } else if (params_.video.codec == "VP9") { |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 1086 | RTC_CHECK_EQ(params_.ss.streams.size(), 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | // Static. |
| 1091 | std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) { |
| 1092 | // Parse comma separated nonnegative integers, where some elements may be |
| 1093 | // empty. The empty values are replaced with -1. |
| 1094 | // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40} |
| 1095 | // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1} |
| 1096 | std::vector<int> result; |
| 1097 | if (str.empty()) |
| 1098 | return result; |
| 1099 | |
| 1100 | const char* p = str.c_str(); |
| 1101 | int value = -1; |
| 1102 | int pos; |
| 1103 | while (*p) { |
| 1104 | if (*p == ',') { |
| 1105 | result.push_back(value); |
| 1106 | value = -1; |
| 1107 | ++p; |
| 1108 | continue; |
| 1109 | } |
| 1110 | RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1) |
| 1111 | << "Unexpected non-number value."; |
| 1112 | p += pos; |
| 1113 | } |
| 1114 | result.push_back(value); |
| 1115 | return result; |
| 1116 | } |
| 1117 | |
| 1118 | // Static. |
| 1119 | VideoStream VideoQualityTest::DefaultVideoStream(const Params& params) { |
| 1120 | VideoStream stream; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1121 | stream.width = params.video.width; |
| 1122 | stream.height = params.video.height; |
| 1123 | stream.max_framerate = params.video.fps; |
| 1124 | stream.min_bitrate_bps = params.video.min_bitrate_bps; |
| 1125 | stream.target_bitrate_bps = params.video.target_bitrate_bps; |
| 1126 | stream.max_bitrate_bps = params.video.max_bitrate_bps; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1127 | stream.max_qp = 52; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1128 | if (params.video.num_temporal_layers == 2) |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1129 | stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps); |
| 1130 | return stream; |
| 1131 | } |
| 1132 | |
| 1133 | // Static. |
| 1134 | void VideoQualityTest::FillScalabilitySettings( |
| 1135 | Params* params, |
| 1136 | const std::vector<std::string>& stream_descriptors, |
| 1137 | size_t selected_stream, |
| 1138 | int num_spatial_layers, |
| 1139 | int selected_sl, |
| 1140 | const std::vector<std::string>& sl_descriptors) { |
| 1141 | // Read VideoStream and SpatialLayer elements from a list of comma separated |
| 1142 | // lists. To use a default value for an element, use -1 or leave empty. |
| 1143 | // Validity checks performed in CheckParams. |
| 1144 | |
| 1145 | RTC_CHECK(params->ss.streams.empty()); |
| 1146 | for (auto descriptor : stream_descriptors) { |
| 1147 | if (descriptor.empty()) |
| 1148 | continue; |
| 1149 | VideoStream stream = VideoQualityTest::DefaultVideoStream(*params); |
| 1150 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
| 1151 | if (v[0] != -1) |
| 1152 | stream.width = static_cast<size_t>(v[0]); |
| 1153 | if (v[1] != -1) |
| 1154 | stream.height = static_cast<size_t>(v[1]); |
| 1155 | if (v[2] != -1) |
| 1156 | stream.max_framerate = v[2]; |
| 1157 | if (v[3] != -1) |
| 1158 | stream.min_bitrate_bps = v[3]; |
| 1159 | if (v[4] != -1) |
| 1160 | stream.target_bitrate_bps = v[4]; |
| 1161 | if (v[5] != -1) |
| 1162 | stream.max_bitrate_bps = v[5]; |
| 1163 | if (v.size() > 6 && v[6] != -1) |
| 1164 | stream.max_qp = v[6]; |
| 1165 | if (v.size() > 7) { |
| 1166 | stream.temporal_layer_thresholds_bps.clear(); |
| 1167 | stream.temporal_layer_thresholds_bps.insert( |
| 1168 | stream.temporal_layer_thresholds_bps.end(), v.begin() + 7, v.end()); |
| 1169 | } else { |
| 1170 | // Automatic TL thresholds for more than two layers not supported. |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1171 | RTC_CHECK_LE(params->video.num_temporal_layers, 2); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1172 | } |
| 1173 | params->ss.streams.push_back(stream); |
| 1174 | } |
| 1175 | params->ss.selected_stream = selected_stream; |
| 1176 | |
| 1177 | params->ss.num_spatial_layers = num_spatial_layers ? num_spatial_layers : 1; |
| 1178 | params->ss.selected_sl = selected_sl; |
| 1179 | RTC_CHECK(params->ss.spatial_layers.empty()); |
| 1180 | for (auto descriptor : sl_descriptors) { |
| 1181 | if (descriptor.empty()) |
| 1182 | continue; |
| 1183 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
| 1184 | RTC_CHECK_GT(v[2], 0); |
| 1185 | |
| 1186 | SpatialLayer layer; |
| 1187 | layer.scaling_factor_num = v[0] == -1 ? 1 : v[0]; |
| 1188 | layer.scaling_factor_den = v[1] == -1 ? 1 : v[1]; |
| 1189 | layer.target_bitrate_bps = v[2]; |
| 1190 | params->ss.spatial_layers.push_back(layer); |
| 1191 | } |
| 1192 | } |
| 1193 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1194 | void VideoQualityTest::SetupVideo(Transport* send_transport, |
| 1195 | Transport* recv_transport) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1196 | if (params_.logs) |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1197 | trace_to_stderr_.reset(new test::TraceToStderr); |
| 1198 | |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1199 | size_t num_video_streams = params_.ss.streams.size(); |
| 1200 | size_t num_flexfec_streams = params_.video.flexfec ? 1 : 0; |
| 1201 | CreateSendConfig(num_video_streams, 0, num_flexfec_streams, send_transport); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1202 | |
| 1203 | int payload_type; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1204 | if (params_.video.codec == "H264") { |
magjed | ceecea4 | 2016-11-28 07:20:21 -0800 | [diff] [blame] | 1205 | video_encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264"))); |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 1206 | payload_type = kPayloadTypeH264; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1207 | } else if (params_.video.codec == "VP8") { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 1208 | video_encoder_.reset(VP8Encoder::Create()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1209 | payload_type = kPayloadTypeVP8; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1210 | } else if (params_.video.codec == "VP9") { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 1211 | video_encoder_.reset(VP9Encoder::Create()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1212 | payload_type = kPayloadTypeVP9; |
| 1213 | } else { |
| 1214 | RTC_NOTREACHED() << "Codec not supported!"; |
| 1215 | return; |
| 1216 | } |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1217 | video_send_config_.encoder_settings.encoder = video_encoder_.get(); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1218 | video_send_config_.encoder_settings.payload_name = params_.video.codec; |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1219 | video_send_config_.encoder_settings.payload_type = payload_type; |
| 1220 | video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 1221 | video_send_config_.rtp.rtx.payload_type = kSendRtxPayloadType; |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1222 | for (size_t i = 0; i < num_video_streams; ++i) |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1223 | video_send_config_.rtp.rtx.ssrcs.push_back(kSendRtxSsrcs[i]); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1224 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1225 | video_send_config_.rtp.extensions.clear(); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1226 | if (params_.call.send_side_bwe) { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1227 | video_send_config_.rtp.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1228 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
Stefan Holmer | 1295297 | 2015-10-29 15:13:24 +0100 | [diff] [blame] | 1229 | test::kTransportSequenceNumberExtensionId)); |
| 1230 | } else { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1231 | video_send_config_.rtp.extensions.push_back(RtpExtension( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1232 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
Erik SprĂ¥ng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1233 | } |
| 1234 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1235 | video_encoder_config_.min_transmit_bitrate_bps = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1236 | params_.video.min_transmit_bps; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1237 | |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1238 | video_send_config_.suspend_below_min_bitrate = |
| 1239 | params_.video.suspend_below_min_bitrate; |
| 1240 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1241 | video_encoder_config_.number_of_streams = params_.ss.streams.size(); |
| 1242 | video_encoder_config_.max_bitrate_bps = 0; |
| 1243 | for (size_t i = 0; i < params_.ss.streams.size(); ++i) { |
| 1244 | video_encoder_config_.max_bitrate_bps += |
| 1245 | params_.ss.streams[i].max_bitrate_bps; |
| 1246 | } |
| 1247 | video_encoder_config_.video_stream_factory = |
| 1248 | new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams); |
| 1249 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1250 | video_encoder_config_.spatial_layers = params_.ss.spatial_layers; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1251 | |
| 1252 | CreateMatchingReceiveConfigs(recv_transport); |
| 1253 | |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1254 | for (size_t i = 0; i < num_video_streams; ++i) { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1255 | video_receive_configs_[i].rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 1256 | video_receive_configs_[i].rtp.rtx_ssrc = kSendRtxSsrcs[i]; |
| 1257 | video_receive_configs_[i].rtp.rtx_payload_types[payload_type] = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1258 | kSendRtxPayloadType; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1259 | video_receive_configs_[i].rtp.transport_cc = params_.call.send_side_bwe; |
Stefan Holmer | 85d5ac7 | 2017-02-09 16:25:16 +0100 | [diff] [blame] | 1260 | video_receive_configs_[i].rtp.remb = !params_.call.send_side_bwe; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1261 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1262 | |
| 1263 | if (params_.video.flexfec) { |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1264 | // Override send config constructed by CreateSendConfig. |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1265 | video_send_config_.rtp.flexfec.protected_media_ssrcs = { |
| 1266 | kVideoSendSsrcs[params_.ss.selected_stream]}; |
| 1267 | |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1268 | // The matching receive config is _not_ created by |
| 1269 | // CreateMatchingReceiveConfigs, since VideoQualityTest is not a BaseTest. |
| 1270 | // Set up the receive config manually instead. |
| 1271 | FlexfecReceiveStream::Config flexfec_receive_config(recv_transport); |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 1272 | flexfec_receive_config.payload_type = |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 1273 | video_send_config_.rtp.flexfec.payload_type; |
| 1274 | flexfec_receive_config.remote_ssrc = video_send_config_.rtp.flexfec.ssrc; |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1275 | flexfec_receive_config.protected_media_ssrcs = |
| 1276 | video_send_config_.rtp.flexfec.protected_media_ssrcs; |
brandtr | fa5a368 | 2017-01-17 01:33:54 -0800 | [diff] [blame] | 1277 | flexfec_receive_config.local_ssrc = kReceiverLocalVideoSsrc; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 1278 | flexfec_receive_config.transport_cc = params_.call.send_side_bwe; |
| 1279 | if (params_.call.send_side_bwe) { |
| 1280 | flexfec_receive_config.rtp_header_extensions.push_back( |
| 1281 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 1282 | test::kTransportSequenceNumberExtensionId)); |
| 1283 | } else { |
| 1284 | flexfec_receive_config.rtp_header_extensions.push_back(RtpExtension( |
| 1285 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
| 1286 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1287 | flexfec_receive_configs_.push_back(flexfec_receive_config); |
| 1288 | } |
| 1289 | |
| 1290 | if (params_.video.ulpfec) { |
| 1291 | video_send_config_.rtp.ulpfec.red_payload_type = kRedPayloadType; |
| 1292 | video_send_config_.rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType; |
| 1293 | video_send_config_.rtp.ulpfec.red_rtx_payload_type = kRtxRedPayloadType; |
| 1294 | |
| 1295 | video_receive_configs_[params_.ss.selected_stream] |
| 1296 | .rtp.ulpfec.red_payload_type = |
| 1297 | video_send_config_.rtp.ulpfec.red_payload_type; |
| 1298 | video_receive_configs_[params_.ss.selected_stream] |
| 1299 | .rtp.ulpfec.ulpfec_payload_type = |
| 1300 | video_send_config_.rtp.ulpfec.ulpfec_payload_type; |
| 1301 | video_receive_configs_[params_.ss.selected_stream] |
| 1302 | .rtp.ulpfec.red_rtx_payload_type = |
| 1303 | video_send_config_.rtp.ulpfec.red_rtx_payload_type; |
| 1304 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1307 | void VideoQualityTest::SetupScreenshareOrSVC() { |
| 1308 | if (params_.screenshare.enabled) { |
| 1309 | // Fill out codec settings. |
| 1310 | video_encoder_config_.content_type = |
| 1311 | VideoEncoderConfig::ContentType::kScreen; |
| 1312 | degradation_preference_ = |
| 1313 | VideoSendStream::DegradationPreference::kMaintainResolution; |
| 1314 | if (params_.video.codec == "VP8") { |
| 1315 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 1316 | vp8_settings.denoisingOn = false; |
| 1317 | vp8_settings.frameDroppingOn = false; |
| 1318 | vp8_settings.numberOfTemporalLayers = |
| 1319 | static_cast<unsigned char>(params_.video.num_temporal_layers); |
| 1320 | video_encoder_config_.encoder_specific_settings = |
| 1321 | new rtc::RefCountedObject< |
| 1322 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
| 1323 | } else if (params_.video.codec == "VP9") { |
| 1324 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 1325 | vp9_settings.denoisingOn = false; |
| 1326 | vp9_settings.frameDroppingOn = false; |
| 1327 | vp9_settings.numberOfTemporalLayers = |
| 1328 | static_cast<unsigned char>(params_.video.num_temporal_layers); |
| 1329 | vp9_settings.numberOfSpatialLayers = |
| 1330 | static_cast<unsigned char>(params_.ss.num_spatial_layers); |
| 1331 | video_encoder_config_.encoder_specific_settings = |
| 1332 | new rtc::RefCountedObject< |
| 1333 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
| 1334 | } |
| 1335 | // Setup frame generator. |
| 1336 | const size_t kWidth = 1850; |
| 1337 | const size_t kHeight = 1110; |
| 1338 | std::vector<std::string> slides; |
| 1339 | slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); |
| 1340 | slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); |
| 1341 | slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); |
| 1342 | slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv")); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1343 | |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1344 | if (params_.screenshare.scroll_duration == 0) { |
| 1345 | // Cycle image every slide_change_interval seconds. |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 1346 | frame_generator_ = test::FrameGenerator::CreateFromYuvFile( |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1347 | slides, kWidth, kHeight, |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 1348 | params_.screenshare.slide_change_interval * params_.video.fps); |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1349 | } else { |
| 1350 | RTC_CHECK_LE(params_.video.width, kWidth); |
| 1351 | RTC_CHECK_LE(params_.video.height, kHeight); |
| 1352 | RTC_CHECK_GT(params_.screenshare.slide_change_interval, 0); |
| 1353 | const int kPauseDurationMs = (params_.screenshare.slide_change_interval - |
| 1354 | params_.screenshare.scroll_duration) * |
| 1355 | 1000; |
| 1356 | RTC_CHECK_LE(params_.screenshare.scroll_duration, |
| 1357 | params_.screenshare.slide_change_interval); |
| 1358 | |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 1359 | frame_generator_ = test::FrameGenerator::CreateScrollingInputFromYuvFiles( |
| 1360 | clock_, slides, kWidth, kHeight, params_.video.width, |
| 1361 | params_.video.height, params_.screenshare.scroll_duration * 1000, |
| 1362 | kPauseDurationMs); |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1363 | } |
| 1364 | } else if (params_.ss.num_spatial_layers > 1) { // For non-screenshare case. |
| 1365 | RTC_CHECK(params_.video.codec == "VP9"); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1366 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1367 | vp9_settings.numberOfTemporalLayers = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1368 | static_cast<unsigned char>(params_.video.num_temporal_layers); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1369 | vp9_settings.numberOfSpatialLayers = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1370 | static_cast<unsigned char>(params_.ss.num_spatial_layers); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1371 | video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject< |
| 1372 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1373 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1376 | void VideoQualityTest::CreateCapturer() { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1377 | if (params_.screenshare.enabled) { |
| 1378 | test::FrameGeneratorCapturer* frame_generator_capturer = |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 1379 | new test::FrameGeneratorCapturer(clock_, std::move(frame_generator_), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1380 | params_.video.fps); |
ivica | 2d4e6c5 | 2015-09-23 01:57:06 -0700 | [diff] [blame] | 1381 | EXPECT_TRUE(frame_generator_capturer->Init()); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1382 | video_capturer_.reset(frame_generator_capturer); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1383 | } else { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1384 | if (params_.video.clip_name.empty()) { |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1385 | video_capturer_.reset(test::VcmCapturer::Create( |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1386 | params_.video.width, params_.video.height, params_.video.fps)); |
sprang | 1bed2e4 | 2017-01-23 08:46:51 -0800 | [diff] [blame] | 1387 | if (!video_capturer_) { |
| 1388 | // Failed to get actual camera, use chroma generator as backup. |
| 1389 | video_capturer_.reset(test::FrameGeneratorCapturer::Create( |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 1390 | static_cast<int>(params_.video.width), |
| 1391 | static_cast<int>(params_.video.height), params_.video.fps, clock_)); |
sprang | 1bed2e4 | 2017-01-23 08:46:51 -0800 | [diff] [blame] | 1392 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1393 | } else { |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1394 | video_capturer_.reset(test::FrameGeneratorCapturer::CreateFromYuvFile( |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1395 | test::ResourcePath(params_.video.clip_name, "yuv"), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1396 | params_.video.width, params_.video.height, params_.video.fps, |
ivica | 2d4e6c5 | 2015-09-23 01:57:06 -0700 | [diff] [blame] | 1397 | clock_)); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1398 | ASSERT_TRUE(video_capturer_) << "Could not create capturer for " |
| 1399 | << params_.video.clip_name |
| 1400 | << ".yuv. Is this resource file present?"; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } |
sprang | 1bed2e4 | 2017-01-23 08:46:51 -0800 | [diff] [blame] | 1403 | RTC_DCHECK(video_capturer_.get()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1406 | void VideoQualityTest::RunWithAnalyzer(const Params& params) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1407 | params_ = params; |
| 1408 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1409 | RTC_CHECK(!params_.audio.enabled); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1410 | // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to |
| 1411 | // differentiate between the analyzer and the renderer case. |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1412 | CheckParams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1413 | |
| 1414 | FILE* graph_data_output_file = nullptr; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1415 | if (!params_.analyzer.graph_data_output_filename.empty()) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1416 | graph_data_output_file = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1417 | fopen(params_.analyzer.graph_data_output_filename.c_str(), "w"); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 1418 | RTC_CHECK(graph_data_output_file) |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1419 | << "Can't open the file " << params_.analyzer.graph_data_output_filename |
| 1420 | << "!"; |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1421 | } |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1422 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 1423 | webrtc::RtcEventLogNullImpl event_log; |
| 1424 | Call::Config call_config(&event_log_); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1425 | call_config.bitrate_config = params.call.call_bitrate_config; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1426 | CreateCalls(call_config, call_config); |
| 1427 | |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1428 | test::LayerFilteringTransport send_transport( |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1429 | params_.pipe, sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9, |
| 1430 | params_.video.selected_tl, params_.ss.selected_sl); |
| 1431 | test::DirectTransport recv_transport(params_.pipe, receiver_call_.get()); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1432 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1433 | std::string graph_title = params_.analyzer.graph_title; |
| 1434 | if (graph_title.empty()) |
| 1435 | graph_title = VideoQualityTest::GenerateGraphTitle(); |
| 1436 | |
| 1437 | // In the case of different resolutions, the functions calculating PSNR and |
| 1438 | // SSIM return -1.0, instead of a positive value as usual. VideoAnalyzer |
| 1439 | // aborts if the average psnr/ssim are below the given threshold, which is |
| 1440 | // 0.0 by default. Setting the thresholds to -1.1 prevents the unnecessary |
| 1441 | // abort. |
| 1442 | VideoStream& selected_stream = params_.ss.streams[params_.ss.selected_stream]; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1443 | |
sprang | c1b57a1 | 2017-02-28 08:50:47 -0800 | [diff] [blame^] | 1444 | bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest"); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1445 | VideoAnalyzer analyzer( |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1446 | &send_transport, params_.analyzer.test_label, |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1447 | |
| 1448 | params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold, |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 1449 | is_quick_test_enabled |
| 1450 | ? kFramesSentInQuickTest |
| 1451 | : params_.analyzer.test_durations_secs * params_.video.fps, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1452 | graph_data_output_file, graph_title, |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 1453 | kVideoSendSsrcs[params_.ss.selected_stream], |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 1454 | kSendRtxSsrcs[params_.ss.selected_stream], |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 1455 | static_cast<uint32_t>(selected_stream.width), |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 1456 | static_cast<uint32_t>(selected_stream.height), params.ss.selected_sl, |
| 1457 | params_.video.selected_tl, is_quick_test_enabled); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1458 | analyzer.SetReceiver(receiver_call_->Receiver()); |
| 1459 | send_transport.SetReceiver(&analyzer); |
| 1460 | recv_transport.SetReceiver(sender_call_->Receiver()); |
| 1461 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1462 | SetupVideo(&analyzer, &recv_transport); |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1463 | video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1464 | video_send_config_.pre_encode_callback = analyzer.pre_encode_proxy(); |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 1465 | RTC_DCHECK(!video_send_config_.post_encode_callback); |
| 1466 | video_send_config_.post_encode_callback = analyzer.encode_timing_proxy(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1467 | |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1468 | SetupScreenshareOrSVC(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1469 | |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1470 | CreateFlexfecStreams(); |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 1471 | CreateVideoStreams(); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1472 | analyzer.SetSendStream(video_send_stream_); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 1473 | if (video_receive_streams_.size() == 1) |
| 1474 | analyzer.SetReceiveStream(video_receive_streams_[0]); |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 1475 | |
| 1476 | video_send_stream_->SetSource(analyzer.OutputInterface(), |
| 1477 | degradation_preference_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1478 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1479 | CreateCapturer(); |
| 1480 | rtc::VideoSinkWants wants; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1481 | video_capturer_->AddOrUpdateSink(analyzer.InputInterface(), wants); |
ivica | c1cc854 | 2015-10-08 03:44:06 -0700 | [diff] [blame] | 1482 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1483 | StartEncodedFrameLogs(video_send_stream_); |
| 1484 | StartEncodedFrameLogs(video_receive_streams_[0]); |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1485 | video_send_stream_->Start(); |
| 1486 | for (VideoReceiveStream* receive_stream : video_receive_streams_) |
| 1487 | receive_stream->Start(); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1488 | for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_) |
| 1489 | receive_stream->Start(); |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 1490 | analyzer.StartMeasuringCpuProcessTime(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1491 | video_capturer_->Start(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1492 | |
| 1493 | analyzer.Wait(); |
| 1494 | |
| 1495 | send_transport.StopSending(); |
| 1496 | recv_transport.StopSending(); |
| 1497 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1498 | video_capturer_->Stop(); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1499 | for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_) |
| 1500 | receive_stream->Stop(); |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1501 | for (VideoReceiveStream* receive_stream : video_receive_streams_) |
| 1502 | receive_stream->Stop(); |
| 1503 | video_send_stream_->Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1504 | |
| 1505 | DestroyStreams(); |
| 1506 | |
| 1507 | if (graph_data_output_file) |
| 1508 | fclose(graph_data_output_file); |
| 1509 | } |
| 1510 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1511 | void VideoQualityTest::SetupAudio(int send_channel_id, |
| 1512 | int receive_channel_id, |
| 1513 | Call* call, |
| 1514 | Transport* transport, |
| 1515 | AudioReceiveStream** audio_receive_stream) { |
| 1516 | audio_send_config_ = AudioSendStream::Config(transport); |
| 1517 | audio_send_config_.voe_channel_id = send_channel_id; |
| 1518 | audio_send_config_.rtp.ssrc = kAudioSendSsrc; |
| 1519 | |
| 1520 | // Add extension to enable audio send side BWE, and allow audio bit rate |
| 1521 | // adaptation. |
| 1522 | audio_send_config_.rtp.extensions.clear(); |
| 1523 | if (params_.call.send_side_bwe) { |
| 1524 | audio_send_config_.rtp.extensions.push_back( |
| 1525 | webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri, |
| 1526 | test::kTransportSequenceNumberExtensionId)); |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 1527 | audio_send_config_.min_bitrate_bps = kOpusMinBitrateBps; |
| 1528 | audio_send_config_.max_bitrate_bps = kOpusBitrateFbBps; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1529 | } |
| 1530 | audio_send_config_.send_codec_spec.codec_inst = |
| 1531 | CodecInst{120, "OPUS", 48000, 960, 2, 64000}; |
| 1532 | |
| 1533 | audio_send_stream_ = call->CreateAudioSendStream(audio_send_config_); |
| 1534 | |
| 1535 | AudioReceiveStream::Config audio_config; |
| 1536 | audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc; |
| 1537 | audio_config.rtcp_send_transport = transport; |
| 1538 | audio_config.voe_channel_id = receive_channel_id; |
| 1539 | audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc; |
| 1540 | audio_config.rtp.transport_cc = params_.call.send_side_bwe; |
| 1541 | audio_config.rtp.extensions = audio_send_config_.rtp.extensions; |
| 1542 | audio_config.decoder_factory = decoder_factory_; |
| 1543 | if (params_.video.enabled && params_.audio.sync_video) |
| 1544 | audio_config.sync_group = kSyncGroup; |
| 1545 | |
| 1546 | *audio_receive_stream = call->CreateAudioReceiveStream(audio_config); |
| 1547 | } |
| 1548 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1549 | void VideoQualityTest::RunWithRenderers(const Params& params) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1550 | params_ = params; |
| 1551 | CheckParams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1552 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1553 | // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to |
| 1554 | // match the full stack tests. |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 1555 | webrtc::RtcEventLogNullImpl event_log; |
| 1556 | Call::Config call_config(&event_log_); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1557 | call_config.bitrate_config = params_.call.call_bitrate_config; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1558 | |
| 1559 | ::VoiceEngineState voe; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1560 | if (params_.audio.enabled) { |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1561 | CreateVoiceEngine(&voe, decoder_factory_); |
| 1562 | AudioState::Config audio_state_config; |
| 1563 | audio_state_config.voice_engine = voe.voice_engine; |
aleloi | 10111bc | 2016-11-17 06:48:48 -0800 | [diff] [blame] | 1564 | audio_state_config.audio_mixer = AudioMixerImpl::Create(); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1565 | call_config.audio_state = AudioState::Create(audio_state_config); |
| 1566 | } |
| 1567 | |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 1568 | std::unique_ptr<Call> call(Call::Create(call_config)); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1569 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1570 | // TODO(minyue): consider if this is a good transport even for audio only |
| 1571 | // calls. |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1572 | test::LayerFilteringTransport transport( |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1573 | params.pipe, call.get(), kPayloadTypeVP8, kPayloadTypeVP9, |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1574 | params.video.selected_tl, params_.ss.selected_sl); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1575 | // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at |
| 1576 | // least share as much code as possible. That way this test would also match |
| 1577 | // the full stack tests better. |
| 1578 | transport.SetReceiver(call->Receiver()); |
| 1579 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1580 | VideoReceiveStream* video_receive_stream = nullptr; |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1581 | FlexfecReceiveStream* flexfec_receive_stream = nullptr; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1582 | std::unique_ptr<test::VideoRenderer> local_preview; |
| 1583 | std::unique_ptr<test::VideoRenderer> loopback_video; |
| 1584 | if (params_.video.enabled) { |
| 1585 | // Create video renderers. |
| 1586 | local_preview.reset(test::VideoRenderer::Create( |
| 1587 | "Local Preview", params_.video.width, params_.video.height)); |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1588 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1589 | size_t stream_id = params_.ss.selected_stream; |
| 1590 | std::string title = "Loopback Video"; |
| 1591 | if (params_.ss.streams.size() > 1) { |
| 1592 | std::ostringstream s; |
| 1593 | s << stream_id; |
| 1594 | title += " - Stream #" + s.str(); |
| 1595 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1596 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1597 | loopback_video.reset(test::VideoRenderer::Create( |
| 1598 | title.c_str(), params_.ss.streams[stream_id].width, |
| 1599 | params_.ss.streams[stream_id].height)); |
mflodman | 48a4beb | 2016-07-01 13:03:59 +0200 | [diff] [blame] | 1600 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1601 | SetupVideo(&transport, &transport); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1602 | video_send_config_.pre_encode_callback = local_preview.get(); |
| 1603 | video_receive_configs_[stream_id].renderer = loopback_video.get(); |
| 1604 | if (params_.audio.enabled && params_.audio.sync_video) |
| 1605 | video_receive_configs_[stream_id].sync_group = kSyncGroup; |
| 1606 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1607 | if (params_.screenshare.enabled) |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1608 | SetupScreenshareOrSVC(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1609 | |
| 1610 | video_send_stream_ = call->CreateVideoSendStream( |
| 1611 | video_send_config_.Copy(), video_encoder_config_.Copy()); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1612 | if (params_.video.flexfec) { |
| 1613 | RTC_DCHECK(!flexfec_receive_configs_.empty()); |
| 1614 | flexfec_receive_stream = |
| 1615 | call->CreateFlexfecReceiveStream(flexfec_receive_configs_[0]); |
| 1616 | } |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1617 | video_receive_stream = call->CreateVideoReceiveStream( |
| 1618 | video_receive_configs_[stream_id].Copy()); |
| 1619 | CreateCapturer(); |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 1620 | video_send_stream_->SetSource(video_capturer_.get(), |
| 1621 | degradation_preference_); |
philipel | 274c1dc | 2016-05-04 06:21:01 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1624 | AudioReceiveStream* audio_receive_stream = nullptr; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1625 | if (params_.audio.enabled) { |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1626 | SetupAudio(voe.send_channel_id, voe.receive_channel_id, call.get(), |
| 1627 | &transport, &audio_receive_stream); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1630 | StartEncodedFrameLogs(video_receive_stream); |
| 1631 | StartEncodedFrameLogs(video_send_stream_); |
| 1632 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1633 | // Start sending and receiving video. |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1634 | if (params_.video.enabled) { |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1635 | if (flexfec_receive_stream) |
| 1636 | flexfec_receive_stream->Start(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1637 | video_receive_stream->Start(); |
| 1638 | video_send_stream_->Start(); |
| 1639 | video_capturer_->Start(); |
| 1640 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1641 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1642 | if (params_.audio.enabled) { |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1643 | // Start receiving audio. |
| 1644 | audio_receive_stream->Start(); |
| 1645 | EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id)); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1646 | |
| 1647 | // Start sending audio. |
| 1648 | audio_send_stream_->Start(); |
| 1649 | EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id)); |
| 1650 | } |
| 1651 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1652 | test::PressEnterToContinue(); |
| 1653 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1654 | if (params_.audio.enabled) { |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1655 | // Stop sending audio. |
| 1656 | EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id)); |
| 1657 | audio_send_stream_->Stop(); |
| 1658 | |
| 1659 | // Stop receiving audio. |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1660 | EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id)); |
| 1661 | audio_receive_stream->Stop(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1662 | call->DestroyAudioSendStream(audio_send_stream_); |
| 1663 | call->DestroyAudioReceiveStream(audio_receive_stream); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | // Stop receiving and sending video. |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1667 | if (params_.video.enabled) { |
| 1668 | video_capturer_->Stop(); |
| 1669 | video_send_stream_->Stop(); |
| 1670 | video_receive_stream->Stop(); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1671 | if (flexfec_receive_stream) { |
| 1672 | flexfec_receive_stream->Stop(); |
| 1673 | call->DestroyFlexfecReceiveStream(flexfec_receive_stream); |
| 1674 | } |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1675 | call->DestroyVideoReceiveStream(video_receive_stream); |
| 1676 | call->DestroyVideoSendStream(video_send_stream_); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1677 | } |
| 1678 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1679 | transport.StopSending(); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1680 | if (params_.audio.enabled) |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1681 | DestroyVoiceEngine(&voe); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1684 | void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) { |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1685 | if (!params_.video.encoded_frame_base_path.empty()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1686 | std::ostringstream str; |
| 1687 | str << send_logs_++; |
| 1688 | std::string prefix = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1689 | params_.video.encoded_frame_base_path + "." + str.str() + ".send."; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1690 | stream->EnableEncodedFrameRecording( |
| 1691 | std::vector<rtc::PlatformFile>( |
| 1692 | {rtc::CreatePlatformFile(prefix + "1.ivf"), |
| 1693 | rtc::CreatePlatformFile(prefix + "2.ivf"), |
| 1694 | rtc::CreatePlatformFile(prefix + "3.ivf")}), |
| 1695 | 10000000); |
| 1696 | } |
| 1697 | } |
| 1698 | void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) { |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1699 | if (!params_.video.encoded_frame_base_path.empty()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1700 | std::ostringstream str; |
| 1701 | str << receive_logs_++; |
| 1702 | std::string path = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1703 | params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1704 | stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), |
| 1705 | 10000000); |
| 1706 | } |
| 1707 | } |
| 1708 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1709 | } // namespace webrtc |