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