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 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "api/optional.h" |
| 21 | #include "call/call.h" |
| 22 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 23 | #include "logging/rtc_event_log/output/rtc_event_log_output_file.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "logging/rtc_event_log/rtc_event_log.h" |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 25 | #include "media/engine/internalencoderfactory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "media/engine/webrtcvideoengine.h" |
| 27 | #include "modules/audio_mixer/audio_mixer_impl.h" |
| 28 | #include "modules/rtp_rtcp/include/rtp_header_parser.h" |
| 29 | #include "modules/rtp_rtcp/source/rtp_format.h" |
| 30 | #include "modules/rtp_rtcp/source/rtp_utility.h" |
| 31 | #include "modules/video_coding/codecs/h264/include/h264.h" |
| 32 | #include "modules/video_coding/codecs/vp8/include/vp8.h" |
| 33 | #include "modules/video_coding/codecs/vp8/include/vp8_common_types.h" |
| 34 | #include "modules/video_coding/codecs/vp9/include/vp9.h" |
| 35 | #include "rtc_base/checks.h" |
| 36 | #include "rtc_base/cpu_time.h" |
| 37 | #include "rtc_base/event.h" |
| 38 | #include "rtc_base/flags.h" |
| 39 | #include "rtc_base/format_macros.h" |
| 40 | #include "rtc_base/logging.h" |
| 41 | #include "rtc_base/memory_usage.h" |
| 42 | #include "rtc_base/pathutils.h" |
| 43 | #include "rtc_base/platform_file.h" |
| 44 | #include "rtc_base/ptr_util.h" |
| 45 | #include "rtc_base/timeutils.h" |
| 46 | #include "system_wrappers/include/cpu_info.h" |
| 47 | #include "system_wrappers/include/field_trial.h" |
| 48 | #include "test/gtest.h" |
| 49 | #include "test/layer_filtering_transport.h" |
| 50 | #include "test/run_loop.h" |
| 51 | #include "test/statistics.h" |
| 52 | #include "test/testsupport/fileutils.h" |
| 53 | #include "test/testsupport/frame_writer.h" |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 54 | #include "test/testsupport/test_artifacts.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 55 | #include "test/vcm_capturer.h" |
| 56 | #include "test/video_renderer.h" |
| 57 | #include "voice_engine/include/voe_base.h" |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 58 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 59 | #include "test/rtp_file_writer.h" |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 60 | |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 61 | DEFINE_bool(save_worst_frame, |
| 62 | false, |
| 63 | "Enable saving a frame with the lowest PSNR to a jpeg file in the " |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 64 | "test_artifacts_dir"); |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 65 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 66 | namespace { |
| 67 | |
| 68 | constexpr int kSendStatsPollingIntervalMs = 1000; |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 69 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 70 | constexpr size_t kMaxComparisons = 10; |
| 71 | constexpr char kSyncGroup[] = "av_sync"; |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 72 | constexpr int kOpusMinBitrateBps = 6000; |
| 73 | constexpr int kOpusBitrateFbBps = 32000; |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 74 | constexpr int kFramesSentInQuickTest = 1; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 75 | constexpr uint32_t kThumbnailSendSsrcStart = 0xE0000; |
| 76 | constexpr uint32_t kThumbnailRtxSsrcStart = 0xF0000; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 77 | |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 78 | constexpr int kDefaultMaxQp = cricket::WebRtcVideoChannel::kDefaultQpMax; |
| 79 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 80 | struct VoiceEngineState { |
| 81 | VoiceEngineState() |
| 82 | : voice_engine(nullptr), |
| 83 | base(nullptr), |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 84 | send_channel_id(-1), |
| 85 | receive_channel_id(-1) {} |
| 86 | |
| 87 | webrtc::VoiceEngine* voice_engine; |
| 88 | webrtc::VoEBase* base; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 89 | int send_channel_id; |
| 90 | int receive_channel_id; |
| 91 | }; |
| 92 | |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 93 | void CreateVoiceEngine( |
| 94 | VoiceEngineState* voe, |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 95 | webrtc::AudioDeviceModule* adm, |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 96 | webrtc::AudioProcessing* apm, |
| 97 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory) { |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 98 | voe->voice_engine = webrtc::VoiceEngine::Create(); |
| 99 | voe->base = webrtc::VoEBase::GetInterface(voe->voice_engine); |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 100 | EXPECT_EQ(0, adm->Init()); |
| 101 | EXPECT_EQ(0, voe->base->Init(adm, apm, decoder_factory)); |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 102 | webrtc::VoEBase::ChannelConfig config; |
| 103 | config.enable_voice_pacing = true; |
| 104 | voe->send_channel_id = voe->base->CreateChannel(config); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 105 | EXPECT_GE(voe->send_channel_id, 0); |
| 106 | voe->receive_channel_id = voe->base->CreateChannel(); |
| 107 | EXPECT_GE(voe->receive_channel_id, 0); |
| 108 | } |
| 109 | |
| 110 | void DestroyVoiceEngine(VoiceEngineState* voe) { |
| 111 | voe->base->DeleteChannel(voe->send_channel_id); |
| 112 | voe->send_channel_id = -1; |
| 113 | voe->base->DeleteChannel(voe->receive_channel_id); |
| 114 | voe->receive_channel_id = -1; |
| 115 | voe->base->Release(); |
| 116 | voe->base = nullptr; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 117 | |
| 118 | webrtc::VoiceEngine::Delete(voe->voice_engine); |
| 119 | voe->voice_engine = nullptr; |
| 120 | } |
| 121 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 122 | class VideoStreamFactory |
| 123 | : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface { |
| 124 | public: |
| 125 | explicit VideoStreamFactory(const std::vector<webrtc::VideoStream>& streams) |
| 126 | : streams_(streams) {} |
| 127 | |
| 128 | private: |
| 129 | std::vector<webrtc::VideoStream> CreateEncoderStreams( |
| 130 | int width, |
| 131 | int height, |
| 132 | const webrtc::VideoEncoderConfig& encoder_config) override { |
mflodman | d79f97b | 2016-12-15 07:24:33 -0800 | [diff] [blame] | 133 | // The highest layer must match the incoming resolution. |
| 134 | std::vector<webrtc::VideoStream> streams = streams_; |
| 135 | streams[streams_.size() - 1].height = height; |
| 136 | streams[streams_.size() - 1].width = width; |
| 137 | return streams; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | std::vector<webrtc::VideoStream> streams_; |
| 141 | }; |
| 142 | |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 143 | bool IsFlexfec(int payload_type) { |
| 144 | return payload_type == webrtc::VideoQualityTest::kFlexfecPayloadType; |
| 145 | } |
| 146 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 147 | } // namespace |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 148 | |
| 149 | namespace webrtc { |
| 150 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 151 | class VideoAnalyzer : public PacketReceiver, |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 152 | public Transport, |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 153 | public rtc::VideoSinkInterface<VideoFrame> { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 154 | public: |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 155 | VideoAnalyzer(test::LayerFilteringTransport* transport, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 156 | const std::string& test_label, |
| 157 | double avg_psnr_threshold, |
| 158 | double avg_ssim_threshold, |
| 159 | int duration_frames, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 160 | FILE* graph_data_output_file, |
| 161 | const std::string& graph_title, |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 162 | uint32_t ssrc_to_analyze, |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 163 | uint32_t rtx_ssrc_to_analyze, |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 164 | size_t selected_stream, |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 165 | int selected_sl, |
| 166 | int selected_tl, |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 167 | bool is_quick_test_enabled, |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 168 | Clock* clock, |
| 169 | std::string rtp_dump_name) |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 170 | : transport_(transport), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 171 | receiver_(nullptr), |
stefan | 889d965 | 2017-07-05 03:03:02 -0700 | [diff] [blame] | 172 | call_(nullptr), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 173 | send_stream_(nullptr), |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 174 | receive_stream_(nullptr), |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 175 | captured_frame_forwarder_(this, clock), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 176 | test_label_(test_label), |
| 177 | graph_data_output_file_(graph_data_output_file), |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 178 | graph_title_(graph_title), |
| 179 | ssrc_to_analyze_(ssrc_to_analyze), |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 180 | rtx_ssrc_to_analyze_(rtx_ssrc_to_analyze), |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 181 | selected_stream_(selected_stream), |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 182 | selected_sl_(selected_sl), |
| 183 | selected_tl_(selected_tl), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 184 | pre_encode_proxy_(this), |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 185 | encode_timing_proxy_(this), |
stefan | 889d965 | 2017-07-05 03:03:02 -0700 | [diff] [blame] | 186 | last_fec_bytes_(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 187 | frames_to_process_(duration_frames), |
| 188 | frames_recorded_(0), |
| 189 | frames_processed_(0), |
| 190 | dropped_frames_(0), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 191 | dropped_frames_before_first_encode_(0), |
| 192 | dropped_frames_before_rendering_(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 193 | last_render_time_(0), |
| 194 | rtp_timestamp_delta_(0), |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 195 | total_media_bytes_(0), |
| 196 | first_sending_time_(0), |
| 197 | last_sending_time_(0), |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 198 | cpu_time_(0), |
| 199 | wallclock_time_(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 200 | avg_psnr_threshold_(avg_psnr_threshold), |
| 201 | avg_ssim_threshold_(avg_ssim_threshold), |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 202 | is_quick_test_enabled_(is_quick_test_enabled), |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 203 | stats_polling_thread_(&PollStatsThread, this, "StatsPoller"), |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 204 | comparison_available_event_(false, false), |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 205 | done_(true, false), |
| 206 | clock_(clock), |
| 207 | start_ms_(clock->TimeInMilliseconds()) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 208 | // Create thread pool for CPU-expensive PSNR/SSIM calculations. |
| 209 | |
| 210 | // Try to use about as many threads as cores, but leave kMinCoresLeft alone, |
| 211 | // so that we don't accidentally starve "real" worker threads (codec etc). |
| 212 | // Also, don't allocate more than kMaxComparisonThreads, even if there are |
| 213 | // spare cores. |
| 214 | |
| 215 | uint32_t num_cores = CpuInfo::DetectNumberOfCores(); |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 216 | RTC_DCHECK_GE(num_cores, 1); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 217 | static const uint32_t kMinCoresLeft = 4; |
| 218 | static const uint32_t kMaxComparisonThreads = 8; |
| 219 | |
| 220 | if (num_cores <= kMinCoresLeft) { |
| 221 | num_cores = 1; |
| 222 | } else { |
| 223 | num_cores -= kMinCoresLeft; |
| 224 | num_cores = std::min(num_cores, kMaxComparisonThreads); |
| 225 | } |
| 226 | |
| 227 | for (uint32_t i = 0; i < num_cores; ++i) { |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 228 | rtc::PlatformThread* thread = |
| 229 | new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer"); |
| 230 | thread->Start(); |
| 231 | comparison_thread_pool_.push_back(thread); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 232 | } |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 233 | |
| 234 | if (!rtp_dump_name.empty()) { |
| 235 | fprintf(stdout, "Writing rtp dump to %s\n", rtp_dump_name.c_str()); |
| 236 | rtp_file_writer_.reset(test::RtpFileWriter::Create( |
| 237 | test::RtpFileWriter::kRtpDump, rtp_dump_name)); |
| 238 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | ~VideoAnalyzer() { |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 242 | for (rtc::PlatformThread* thread : comparison_thread_pool_) { |
| 243 | thread->Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 244 | delete thread; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; } |
| 249 | |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 250 | void SetSource(test::VideoCapturer* video_capturer, bool respect_sink_wants) { |
| 251 | if (respect_sink_wants) |
| 252 | captured_frame_forwarder_.SetSource(video_capturer); |
| 253 | rtc::VideoSinkWants wants; |
| 254 | video_capturer->AddOrUpdateSink(InputInterface(), wants); |
| 255 | } |
| 256 | |
stefan | 889d965 | 2017-07-05 03:03:02 -0700 | [diff] [blame] | 257 | void SetCall(Call* call) { |
| 258 | rtc::CritScope lock(&crit_); |
| 259 | RTC_DCHECK(!call_); |
| 260 | call_ = call; |
| 261 | } |
| 262 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 263 | void SetSendStream(VideoSendStream* stream) { |
| 264 | rtc::CritScope lock(&crit_); |
| 265 | RTC_DCHECK(!send_stream_); |
| 266 | send_stream_ = stream; |
| 267 | } |
| 268 | |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 269 | void SetReceiveStream(VideoReceiveStream* stream) { |
| 270 | rtc::CritScope lock(&crit_); |
| 271 | RTC_DCHECK(!receive_stream_); |
| 272 | receive_stream_ = stream; |
| 273 | } |
| 274 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 275 | rtc::VideoSinkInterface<VideoFrame>* InputInterface() { |
| 276 | return &captured_frame_forwarder_; |
| 277 | } |
| 278 | rtc::VideoSourceInterface<VideoFrame>* OutputInterface() { |
| 279 | return &captured_frame_forwarder_; |
| 280 | } |
| 281 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 282 | DeliveryStatus DeliverPacket(MediaType media_type, |
Danil Chapovalov | 292a73e | 2017-12-07 17:00:40 +0100 | [diff] [blame^] | 283 | rtc::CopyOnWriteBuffer packet, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 284 | const PacketTime& packet_time) override { |
Taylor Brandstetter | 433b95a | 2016-03-18 11:41:03 -0700 | [diff] [blame] | 285 | // Ignore timestamps of RTCP packets. They're not synchronized with |
| 286 | // RTP packet timestamps and so they would confuse wrap_handler_. |
Danil Chapovalov | 292a73e | 2017-12-07 17:00:40 +0100 | [diff] [blame^] | 287 | if (RtpHeaderParser::IsRtcp(packet.cdata(), packet.size())) { |
| 288 | return receiver_->DeliverPacket(media_type, std::move(packet), |
| 289 | packet_time); |
Taylor Brandstetter | 433b95a | 2016-03-18 11:41:03 -0700 | [diff] [blame] | 290 | } |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 291 | |
| 292 | if (rtp_file_writer_) { |
| 293 | test::RtpPacket p; |
Danil Chapovalov | 292a73e | 2017-12-07 17:00:40 +0100 | [diff] [blame^] | 294 | memcpy(p.data, packet.cdata(), packet.size()); |
| 295 | p.length = packet.size(); |
| 296 | p.original_length = packet.size(); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 297 | p.time_ms = clock_->TimeInMilliseconds() - start_ms_; |
| 298 | rtp_file_writer_->WritePacket(&p); |
| 299 | } |
| 300 | |
Danil Chapovalov | 292a73e | 2017-12-07 17:00:40 +0100 | [diff] [blame^] | 301 | RtpUtility::RtpHeaderParser parser(packet.cdata(), packet.size()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 302 | RTPHeader header; |
danilchap | f6975f4 | 2015-12-28 10:18:46 -0800 | [diff] [blame] | 303 | parser.Parse(&header); |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 304 | if (!IsFlexfec(header.payloadType) && |
| 305 | (header.ssrc == ssrc_to_analyze_ || |
| 306 | header.ssrc == rtx_ssrc_to_analyze_)) { |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 307 | // Ignore FlexFEC timestamps, to avoid collisions with media timestamps. |
| 308 | // (FlexFEC and media are sent on different SSRCs, which have different |
| 309 | // timestamps spaces.) |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 310 | // Also ignore packets from wrong SSRC, but include retransmits. |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 311 | rtc::CritScope lock(&crit_); |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 312 | int64_t timestamp = |
| 313 | wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_); |
| 314 | recv_times_[timestamp] = |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 315 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
| 316 | } |
| 317 | |
Danil Chapovalov | 292a73e | 2017-12-07 17:00:40 +0100 | [diff] [blame^] | 318 | return receiver_->DeliverPacket(media_type, std::move(packet), packet_time); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 321 | void MeasuredEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 322 | rtc::CritScope crit(&comparison_lock_); |
| 323 | samples_encode_time_ms_[ntp_time_ms] = encode_time_ms; |
| 324 | } |
| 325 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 326 | void PreEncodeOnFrame(const VideoFrame& video_frame) { |
| 327 | rtc::CritScope lock(&crit_); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 328 | if (!first_encoded_timestamp_) { |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 329 | while (frames_.front().timestamp() != video_frame.timestamp()) { |
| 330 | ++dropped_frames_before_first_encode_; |
| 331 | frames_.pop_front(); |
| 332 | RTC_CHECK(!frames_.empty()); |
| 333 | } |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 334 | first_encoded_timestamp_ = |
| 335 | rtc::Optional<uint32_t>(video_frame.timestamp()); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | void PostEncodeFrameCallback(const EncodedFrame& encoded_frame) { |
| 340 | rtc::CritScope lock(&crit_); |
| 341 | if (!first_sent_timestamp_ && |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 342 | encoded_frame.stream_id_ == selected_stream_) { |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 343 | first_sent_timestamp_ = rtc::Optional<uint32_t>(encoded_frame.timestamp_); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 347 | bool SendRtp(const uint8_t* packet, |
| 348 | size_t length, |
| 349 | const PacketOptions& options) override { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 350 | RtpUtility::RtpHeaderParser parser(packet, length); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 351 | RTPHeader header; |
danilchap | f6975f4 | 2015-12-28 10:18:46 -0800 | [diff] [blame] | 352 | parser.Parse(&header); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 353 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 354 | int64_t current_time = |
| 355 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 356 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 357 | bool result = transport_->SendRtp(packet, length, options); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 358 | { |
| 359 | rtc::CritScope lock(&crit_); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 360 | if (rtp_timestamp_delta_ == 0 && header.ssrc == ssrc_to_analyze_) { |
ilnik | 1e1c84d | 2017-02-09 08:32:53 -0800 | [diff] [blame] | 361 | RTC_CHECK(static_cast<bool>(first_sent_timestamp_)); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 362 | rtp_timestamp_delta_ = header.timestamp - *first_sent_timestamp_; |
ilnik | e67c59e | 2017-02-09 04:08:56 -0800 | [diff] [blame] | 363 | } |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 364 | |
| 365 | if (!IsFlexfec(header.payloadType) && header.ssrc == ssrc_to_analyze_) { |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 366 | // Ignore FlexFEC timestamps, to avoid collisions with media timestamps. |
| 367 | // (FlexFEC and media are sent on different SSRCs, which have different |
| 368 | // timestamps spaces.) |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 369 | // Also ignore packets from wrong SSRC and retransmits. |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 370 | int64_t timestamp = |
| 371 | wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_); |
| 372 | send_times_[timestamp] = current_time; |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 373 | |
| 374 | if (IsInSelectedSpatialAndTemporalLayer(packet, length, header)) { |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 375 | encoded_frame_sizes_[timestamp] += |
| 376 | length - (header.headerLength + header.paddingLength); |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 377 | total_media_bytes_ += |
| 378 | length - (header.headerLength + header.paddingLength); |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 379 | } |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 380 | if (first_sending_time_ == 0) |
| 381 | first_sending_time_ = current_time; |
| 382 | last_sending_time_ = current_time; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 383 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 384 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 385 | return result; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | bool SendRtcp(const uint8_t* packet, size_t length) override { |
| 389 | return transport_->SendRtcp(packet, length); |
| 390 | } |
| 391 | |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 392 | void OnFrame(const VideoFrame& video_frame) override { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 393 | int64_t render_time_ms = |
| 394 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 395 | |
| 396 | rtc::CritScope lock(&crit_); |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 397 | |
| 398 | StartExcludingCpuThreadTime(); |
| 399 | |
Taylor Brandstetter | 433b95a | 2016-03-18 11:41:03 -0700 | [diff] [blame] | 400 | int64_t send_timestamp = |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 401 | wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 402 | |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 403 | while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) { |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 404 | if (!last_rendered_frame_) { |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 405 | // No previous frame rendered, this one was dropped after sending but |
| 406 | // before rendering. |
| 407 | ++dropped_frames_before_rendering_; |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 408 | } else { |
| 409 | AddFrameComparison(frames_.front(), *last_rendered_frame_, true, |
| 410 | render_time_ms); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 411 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 412 | frames_.pop_front(); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 413 | RTC_DCHECK(!frames_.empty()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | VideoFrame reference_frame = frames_.front(); |
| 417 | frames_.pop_front(); |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 418 | int64_t reference_timestamp = |
| 419 | wrap_handler_.Unwrap(reference_frame.timestamp()); |
| 420 | if (send_timestamp == reference_timestamp - 1) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 421 | // TODO(ivica): Make this work for > 2 streams. |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 422 | // Look at RTPSender::BuildRTPHeader. |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 423 | ++send_timestamp; |
| 424 | } |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 425 | ASSERT_EQ(reference_timestamp, send_timestamp); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 426 | |
| 427 | AddFrameComparison(reference_frame, video_frame, false, render_time_ms); |
| 428 | |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 429 | last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame); |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 430 | |
| 431 | StopExcludingCpuThreadTime(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 432 | } |
| 433 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 434 | void Wait() { |
| 435 | // Frame comparisons can be very expensive. Wait for test to be done, but |
| 436 | // at time-out check if frames_processed is going up. If so, give it more |
| 437 | // time, otherwise fail. Hopefully this will reduce test flakiness. |
| 438 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 439 | stats_polling_thread_.Start(); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 440 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 441 | int last_frames_processed = -1; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 442 | int iteration = 0; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 443 | while (!done_.Wait(VideoQualityTest::kDefaultTimeoutMs)) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 444 | int frames_processed; |
| 445 | { |
| 446 | rtc::CritScope crit(&comparison_lock_); |
| 447 | frames_processed = frames_processed_; |
| 448 | } |
| 449 | |
| 450 | // Print some output so test infrastructure won't think we've crashed. |
| 451 | const char* kKeepAliveMessages[3] = { |
| 452 | "Uh, I'm-I'm not quite dead, sir.", |
| 453 | "Uh, I-I think uh, I could pull through, sir.", |
| 454 | "Actually, I think I'm all right to come with you--"}; |
| 455 | printf("- %s\n", kKeepAliveMessages[iteration++ % 3]); |
| 456 | |
| 457 | if (last_frames_processed == -1) { |
| 458 | last_frames_processed = frames_processed; |
| 459 | continue; |
| 460 | } |
Peter Boström | dd45eb6 | 2016-01-19 15:22:32 +0100 | [diff] [blame] | 461 | if (frames_processed == last_frames_processed) { |
| 462 | EXPECT_GT(frames_processed, last_frames_processed) |
| 463 | << "Analyzer stalled while waiting for test to finish."; |
| 464 | done_.Set(); |
| 465 | break; |
| 466 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 467 | last_frames_processed = frames_processed; |
| 468 | } |
| 469 | |
| 470 | if (iteration > 0) |
| 471 | printf("- Farewell, sweet Concorde!\n"); |
| 472 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 473 | stats_polling_thread_.Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 474 | } |
| 475 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 476 | rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() { |
| 477 | return &pre_encode_proxy_; |
| 478 | } |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 479 | EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; } |
| 480 | |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 481 | void StartMeasuringCpuProcessTime() { |
| 482 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 483 | cpu_time_ -= rtc::GetProcessCpuTimeNanos(); |
| 484 | wallclock_time_ -= rtc::SystemTimeNanos(); |
| 485 | } |
| 486 | |
| 487 | void StopMeasuringCpuProcessTime() { |
| 488 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 489 | cpu_time_ += rtc::GetProcessCpuTimeNanos(); |
| 490 | wallclock_time_ += rtc::SystemTimeNanos(); |
| 491 | } |
| 492 | |
| 493 | void StartExcludingCpuThreadTime() { |
| 494 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 495 | cpu_time_ += rtc::GetThreadCpuTimeNanos(); |
| 496 | } |
| 497 | |
| 498 | void StopExcludingCpuThreadTime() { |
| 499 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 500 | cpu_time_ -= rtc::GetThreadCpuTimeNanos(); |
| 501 | } |
| 502 | |
| 503 | double GetCpuUsagePercent() { |
| 504 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 505 | return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0; |
| 506 | } |
| 507 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 508 | test::LayerFilteringTransport* const transport_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 509 | PacketReceiver* receiver_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 510 | |
| 511 | private: |
| 512 | struct FrameComparison { |
| 513 | FrameComparison() |
| 514 | : dropped(false), |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 515 | input_time_ms(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 516 | send_time_ms(0), |
| 517 | recv_time_ms(0), |
| 518 | render_time_ms(0), |
| 519 | encoded_frame_size(0) {} |
| 520 | |
| 521 | FrameComparison(const VideoFrame& reference, |
| 522 | const VideoFrame& render, |
| 523 | bool dropped, |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 524 | int64_t input_time_ms, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 525 | int64_t send_time_ms, |
| 526 | int64_t recv_time_ms, |
| 527 | int64_t render_time_ms, |
| 528 | size_t encoded_frame_size) |
| 529 | : reference(reference), |
| 530 | render(render), |
| 531 | dropped(dropped), |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 532 | input_time_ms(input_time_ms), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 533 | send_time_ms(send_time_ms), |
| 534 | recv_time_ms(recv_time_ms), |
| 535 | render_time_ms(render_time_ms), |
| 536 | encoded_frame_size(encoded_frame_size) {} |
| 537 | |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 538 | FrameComparison(bool dropped, |
| 539 | int64_t input_time_ms, |
| 540 | int64_t send_time_ms, |
| 541 | int64_t recv_time_ms, |
| 542 | int64_t render_time_ms, |
| 543 | size_t encoded_frame_size) |
| 544 | : dropped(dropped), |
| 545 | input_time_ms(input_time_ms), |
| 546 | send_time_ms(send_time_ms), |
| 547 | recv_time_ms(recv_time_ms), |
| 548 | render_time_ms(render_time_ms), |
| 549 | encoded_frame_size(encoded_frame_size) {} |
| 550 | |
| 551 | rtc::Optional<VideoFrame> reference; |
| 552 | rtc::Optional<VideoFrame> render; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 553 | bool dropped; |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 554 | int64_t input_time_ms; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 555 | int64_t send_time_ms; |
| 556 | int64_t recv_time_ms; |
| 557 | int64_t render_time_ms; |
| 558 | size_t encoded_frame_size; |
| 559 | }; |
| 560 | |
| 561 | struct Sample { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 562 | Sample(int dropped, |
| 563 | int64_t input_time_ms, |
| 564 | int64_t send_time_ms, |
| 565 | int64_t recv_time_ms, |
| 566 | int64_t render_time_ms, |
| 567 | size_t encoded_frame_size, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 568 | double psnr, |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 569 | double ssim) |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 570 | : dropped(dropped), |
| 571 | input_time_ms(input_time_ms), |
| 572 | send_time_ms(send_time_ms), |
| 573 | recv_time_ms(recv_time_ms), |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 574 | render_time_ms(render_time_ms), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 575 | encoded_frame_size(encoded_frame_size), |
| 576 | psnr(psnr), |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 577 | ssim(ssim) {} |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 578 | |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 579 | int dropped; |
| 580 | int64_t input_time_ms; |
| 581 | int64_t send_time_ms; |
| 582 | int64_t recv_time_ms; |
| 583 | int64_t render_time_ms; |
| 584 | size_t encoded_frame_size; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 585 | double psnr; |
| 586 | double ssim; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 587 | }; |
| 588 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 589 | // This class receives the send-side OnEncodeTiming and is provided to not |
| 590 | // conflict with the receiver-side pre_decode_callback. |
| 591 | class OnEncodeTimingProxy : public EncodedFrameObserver { |
| 592 | public: |
| 593 | explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {} |
| 594 | |
| 595 | void OnEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) override { |
| 596 | parent_->MeasuredEncodeTiming(ntp_time_ms, encode_time_ms); |
| 597 | } |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 598 | void EncodedFrameCallback(const EncodedFrame& frame) override { |
| 599 | parent_->PostEncodeFrameCallback(frame); |
| 600 | } |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 601 | |
| 602 | private: |
| 603 | VideoAnalyzer* const parent_; |
| 604 | }; |
| 605 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 606 | // This class receives the send-side OnFrame callback and is provided to not |
| 607 | // conflict with the receiver-side renderer callback. |
| 608 | class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> { |
| 609 | public: |
| 610 | explicit PreEncodeProxy(VideoAnalyzer* parent) : parent_(parent) {} |
| 611 | |
| 612 | void OnFrame(const VideoFrame& video_frame) override { |
| 613 | parent_->PreEncodeOnFrame(video_frame); |
| 614 | } |
| 615 | |
| 616 | private: |
| 617 | VideoAnalyzer* const parent_; |
| 618 | }; |
| 619 | |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 620 | bool IsInSelectedSpatialAndTemporalLayer(const uint8_t* packet, |
| 621 | size_t length, |
| 622 | const RTPHeader& header) { |
ilnik | 863f03b | 2017-07-11 02:38:36 -0700 | [diff] [blame] | 623 | if (header.payloadType != test::CallTest::kPayloadTypeVP9 && |
| 624 | header.payloadType != test::CallTest::kPayloadTypeVP8) { |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 625 | return true; |
| 626 | } else { |
| 627 | // Get VP8 and VP9 specific header to check layers indexes. |
| 628 | const uint8_t* payload = packet + header.headerLength; |
| 629 | const size_t payload_length = length - header.headerLength; |
| 630 | const size_t payload_data_length = payload_length - header.paddingLength; |
ilnik | 863f03b | 2017-07-11 02:38:36 -0700 | [diff] [blame] | 631 | const bool is_vp8 = header.payloadType == test::CallTest::kPayloadTypeVP8; |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 632 | std::unique_ptr<RtpDepacketizer> depacketizer( |
| 633 | RtpDepacketizer::Create(is_vp8 ? kRtpVideoVp8 : kRtpVideoVp9)); |
| 634 | RtpDepacketizer::ParsedPayload parsed_payload; |
| 635 | bool result = |
| 636 | depacketizer->Parse(&parsed_payload, payload, payload_data_length); |
| 637 | RTC_DCHECK(result); |
| 638 | const int temporal_idx = static_cast<int>( |
| 639 | is_vp8 ? parsed_payload.type.Video.codecHeader.VP8.temporalIdx |
| 640 | : parsed_payload.type.Video.codecHeader.VP9.temporal_idx); |
| 641 | const int spatial_idx = static_cast<int>( |
| 642 | is_vp8 ? kNoSpatialIdx |
| 643 | : parsed_payload.type.Video.codecHeader.VP9.spatial_idx); |
| 644 | return (selected_tl_ < 0 || temporal_idx == kNoTemporalIdx || |
| 645 | temporal_idx <= selected_tl_) && |
| 646 | (selected_sl_ < 0 || spatial_idx == kNoSpatialIdx || |
| 647 | spatial_idx <= selected_sl_); |
| 648 | } |
| 649 | } |
| 650 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 651 | void AddFrameComparison(const VideoFrame& reference, |
| 652 | const VideoFrame& render, |
| 653 | bool dropped, |
| 654 | int64_t render_time_ms) |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 655 | RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 656 | int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp()); |
| 657 | int64_t send_time_ms = send_times_[reference_timestamp]; |
| 658 | send_times_.erase(reference_timestamp); |
| 659 | int64_t recv_time_ms = recv_times_[reference_timestamp]; |
| 660 | recv_times_.erase(reference_timestamp); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 661 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 662 | // TODO(ivica): Make this work for > 2 streams. |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 663 | auto it = encoded_frame_sizes_.find(reference_timestamp); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 664 | if (it == encoded_frame_sizes_.end()) |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 665 | it = encoded_frame_sizes_.find(reference_timestamp - 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 666 | size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second; |
| 667 | if (it != encoded_frame_sizes_.end()) |
| 668 | encoded_frame_sizes_.erase(it); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 669 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 670 | rtc::CritScope crit(&comparison_lock_); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 671 | if (comparisons_.size() < kMaxComparisons) { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 672 | comparisons_.push_back(FrameComparison(reference, render, dropped, |
| 673 | reference.ntp_time_ms(), |
| 674 | send_time_ms, recv_time_ms, |
| 675 | render_time_ms, encoded_size)); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 676 | } else { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 677 | comparisons_.push_back(FrameComparison(dropped, |
| 678 | reference.ntp_time_ms(), |
| 679 | send_time_ms, recv_time_ms, |
| 680 | render_time_ms, encoded_size)); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 681 | } |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 682 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 683 | } |
| 684 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 685 | static void PollStatsThread(void* obj) { |
| 686 | static_cast<VideoAnalyzer*>(obj)->PollStats(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 687 | } |
| 688 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 689 | void PollStats() { |
| 690 | while (!done_.Wait(kSendStatsPollingIntervalMs)) { |
| 691 | rtc::CritScope crit(&comparison_lock_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 692 | |
stefan | 889d965 | 2017-07-05 03:03:02 -0700 | [diff] [blame] | 693 | Call::Stats call_stats = call_->GetStats(); |
| 694 | send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps); |
| 695 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 696 | VideoSendStream::Stats send_stats = send_stream_->GetStats(); |
| 697 | // It's not certain that we yet have estimates for any of these stats. |
| 698 | // Check that they are positive before mixing them in. |
| 699 | if (send_stats.encode_frame_rate > 0) |
| 700 | encode_frame_rate_.AddSample(send_stats.encode_frame_rate); |
| 701 | if (send_stats.avg_encode_time_ms > 0) |
| 702 | encode_time_ms_.AddSample(send_stats.avg_encode_time_ms); |
| 703 | if (send_stats.encode_usage_percent > 0) |
| 704 | encode_usage_percent_.AddSample(send_stats.encode_usage_percent); |
| 705 | if (send_stats.media_bitrate_bps > 0) |
| 706 | media_bitrate_bps_.AddSample(send_stats.media_bitrate_bps); |
stefan | 889d965 | 2017-07-05 03:03:02 -0700 | [diff] [blame] | 707 | size_t fec_bytes = 0; |
| 708 | for (auto kv : send_stats.substreams) { |
| 709 | fec_bytes += kv.second.rtp_stats.fec.payload_bytes + |
| 710 | kv.second.rtp_stats.fec.padding_bytes; |
| 711 | } |
| 712 | fec_bitrate_bps_.AddSample((fec_bytes - last_fec_bytes_) * 8); |
| 713 | last_fec_bytes_ = fec_bytes; |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 714 | |
tommi | 0f8b403 | 2017-02-22 11:22:05 -0800 | [diff] [blame] | 715 | if (receive_stream_ != nullptr) { |
| 716 | VideoReceiveStream::Stats receive_stats = receive_stream_->GetStats(); |
| 717 | if (receive_stats.decode_ms > 0) |
| 718 | decode_time_ms_.AddSample(receive_stats.decode_ms); |
| 719 | if (receive_stats.max_decode_ms > 0) |
| 720 | decode_time_max_ms_.AddSample(receive_stats.max_decode_ms); |
| 721 | } |
ilnik | daa574d | 2017-03-01 06:46:05 -0800 | [diff] [blame] | 722 | |
| 723 | memory_usage_.AddSample(rtc::GetProcessResidentSizeBytes()); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 724 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | static bool FrameComparisonThread(void* obj) { |
| 728 | return static_cast<VideoAnalyzer*>(obj)->CompareFrames(); |
| 729 | } |
| 730 | |
| 731 | bool CompareFrames() { |
| 732 | if (AllFramesRecorded()) |
| 733 | return false; |
| 734 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 735 | FrameComparison comparison; |
| 736 | |
| 737 | if (!PopComparison(&comparison)) { |
| 738 | // Wait until new comparison task is available, or test is done. |
| 739 | // If done, wake up remaining threads waiting. |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 740 | comparison_available_event_.Wait(1000); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 741 | if (AllFramesRecorded()) { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 742 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 743 | return false; |
| 744 | } |
| 745 | return true; // Try again. |
| 746 | } |
| 747 | |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 748 | StartExcludingCpuThreadTime(); |
| 749 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 750 | PerformFrameComparison(comparison); |
| 751 | |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 752 | StopExcludingCpuThreadTime(); |
| 753 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 754 | if (FrameProcessed()) { |
| 755 | PrintResults(); |
| 756 | if (graph_data_output_file_) |
| 757 | PrintSamplesToFile(); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 758 | done_.Set(); |
| 759 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 760 | return false; |
| 761 | } |
| 762 | |
| 763 | return true; |
| 764 | } |
| 765 | |
| 766 | bool PopComparison(FrameComparison* comparison) { |
| 767 | rtc::CritScope crit(&comparison_lock_); |
| 768 | // If AllFramesRecorded() is true, it means we have already popped |
| 769 | // frames_to_process_ frames from comparisons_, so there is no more work |
| 770 | // for this thread to be done. frames_processed_ might still be lower if |
| 771 | // all comparisons are not done, but those frames are currently being |
| 772 | // worked on by other threads. |
| 773 | if (comparisons_.empty() || AllFramesRecorded()) |
| 774 | return false; |
| 775 | |
| 776 | *comparison = comparisons_.front(); |
| 777 | comparisons_.pop_front(); |
| 778 | |
| 779 | FrameRecorded(); |
| 780 | return true; |
| 781 | } |
| 782 | |
| 783 | // Increment counter for number of frames received for comparison. |
| 784 | void FrameRecorded() { |
| 785 | rtc::CritScope crit(&comparison_lock_); |
| 786 | ++frames_recorded_; |
| 787 | } |
| 788 | |
| 789 | // Returns true if all frames to be compared have been taken from the queue. |
| 790 | bool AllFramesRecorded() { |
| 791 | rtc::CritScope crit(&comparison_lock_); |
| 792 | assert(frames_recorded_ <= frames_to_process_); |
| 793 | return frames_recorded_ == frames_to_process_; |
| 794 | } |
| 795 | |
| 796 | // Increase count of number of frames processed. Returns true if this was the |
| 797 | // last frame to be processed. |
| 798 | bool FrameProcessed() { |
| 799 | rtc::CritScope crit(&comparison_lock_); |
| 800 | ++frames_processed_; |
| 801 | assert(frames_processed_ <= frames_to_process_); |
| 802 | return frames_processed_ == frames_to_process_; |
| 803 | } |
| 804 | |
| 805 | void PrintResults() { |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 806 | StopMeasuringCpuProcessTime(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 807 | rtc::CritScope crit(&comparison_lock_); |
| 808 | PrintResult("psnr", psnr_, " dB"); |
tnakamura | 3123cbc | 2016-02-10 11:21:51 -0800 | [diff] [blame] | 809 | PrintResult("ssim", ssim_, " score"); |
stefan | 2da7a24 | 2017-03-30 01:02:15 -0700 | [diff] [blame] | 810 | PrintResult("sender_time", sender_time_, " ms"); |
| 811 | PrintResult("receiver_time", receiver_time_, " ms"); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 812 | PrintResult("total_delay_incl_network", end_to_end_, " ms"); |
| 813 | PrintResult("time_between_rendered_frames", rendered_delta_, " ms"); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 814 | PrintResult("encode_frame_rate", encode_frame_rate_, " fps"); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 815 | PrintResult("encode_time", encode_time_ms_, " ms"); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 816 | PrintResult("media_bitrate", media_bitrate_bps_, " bps"); |
stefan | 889d965 | 2017-07-05 03:03:02 -0700 | [diff] [blame] | 817 | PrintResult("fec_bitrate", fec_bitrate_bps_, " bps"); |
| 818 | PrintResult("send_bandwidth", send_bandwidth_bps_, " bps"); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 819 | |
ilnik | 59cac99 | 2017-07-25 05:45:03 -0700 | [diff] [blame] | 820 | if (worst_frame_) { |
| 821 | printf("RESULT min_psnr: %s = %lf dB\n", test_label_.c_str(), |
| 822 | worst_frame_->psnr); |
| 823 | } |
| 824 | |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 825 | if (receive_stream_ != nullptr) { |
| 826 | PrintResult("decode_time", decode_time_ms_, " ms"); |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 827 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 828 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 829 | printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(), |
| 830 | dropped_frames_); |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 831 | printf("RESULT cpu_usage: %s = %lf %%\n", test_label_.c_str(), |
| 832 | GetCpuUsagePercent()); |
ilnik | daa574d | 2017-03-01 06:46:05 -0800 | [diff] [blame] | 833 | |
| 834 | #if defined(WEBRTC_WIN) |
| 835 | // On Linux and Mac in Resident Set some unused pages may be counted. |
| 836 | // Therefore this metric will depend on order in which tests are run and |
| 837 | // will be flaky. |
| 838 | PrintResult("memory_usage", memory_usage_, " bytes"); |
| 839 | #endif |
ilnik | 59cac99 | 2017-07-25 05:45:03 -0700 | [diff] [blame] | 840 | |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 841 | // Saving only the worst frame for manual analysis. Intention here is to |
| 842 | // only detect video corruptions and not to track picture quality. Thus, |
| 843 | // jpeg is used here. |
oprypin | 9b2f20c | 2017-08-29 05:51:57 -0700 | [diff] [blame] | 844 | if (FLAG_save_worst_frame && worst_frame_) { |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 845 | std::string output_dir; |
Edward Lemur | af8659a | 2017-09-27 14:46:24 +0200 | [diff] [blame] | 846 | test::GetTestArtifactsDir(&output_dir); |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 847 | std::string output_path = |
| 848 | rtc::Pathname(output_dir, test_label_ + ".jpg").pathname(); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 849 | RTC_LOG(LS_INFO) << "Saving worst frame to " << output_path; |
ilnik | ee42d19 | 2017-08-22 07:16:20 -0700 | [diff] [blame] | 850 | test::JpegFrameWriter frame_writer(output_path); |
| 851 | RTC_CHECK(frame_writer.WriteFrame(worst_frame_->frame, |
| 852 | 100 /*best quality*/)); |
ilnik | 59cac99 | 2017-07-25 05:45:03 -0700 | [diff] [blame] | 853 | } |
ilnik | daa574d | 2017-03-01 06:46:05 -0800 | [diff] [blame] | 854 | |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 855 | // Disable quality check for quick test, as quality checks may fail |
| 856 | // because too few samples were collected. |
| 857 | if (!is_quick_test_enabled_) { |
| 858 | EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); |
| 859 | EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_); |
| 860 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | void PerformFrameComparison(const FrameComparison& comparison) { |
| 864 | // Perform expensive psnr and ssim calculations while not holding lock. |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 865 | double psnr = -1.0; |
| 866 | double ssim = -1.0; |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 867 | if (comparison.reference && !comparison.dropped) { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 868 | psnr = I420PSNR(&*comparison.reference, &*comparison.render); |
| 869 | ssim = I420SSIM(&*comparison.reference, &*comparison.render); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 870 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 871 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 872 | rtc::CritScope crit(&comparison_lock_); |
ilnik | 59cac99 | 2017-07-25 05:45:03 -0700 | [diff] [blame] | 873 | |
| 874 | if (psnr >= 0.0 && (!worst_frame_ || worst_frame_->psnr > psnr)) { |
| 875 | worst_frame_.emplace(FrameWithPsnr{psnr, *comparison.render}); |
| 876 | } |
| 877 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 878 | if (graph_data_output_file_) { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 879 | samples_.push_back(Sample( |
| 880 | comparison.dropped, comparison.input_time_ms, comparison.send_time_ms, |
| 881 | comparison.recv_time_ms, comparison.render_time_ms, |
| 882 | comparison.encoded_frame_size, psnr, ssim)); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 883 | } |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 884 | if (psnr >= 0.0) |
| 885 | psnr_.AddSample(psnr); |
| 886 | if (ssim >= 0.0) |
| 887 | ssim_.AddSample(ssim); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 888 | |
| 889 | if (comparison.dropped) { |
| 890 | ++dropped_frames_; |
| 891 | return; |
| 892 | } |
| 893 | if (last_render_time_ != 0) |
| 894 | rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_); |
| 895 | last_render_time_ = comparison.render_time_ms; |
| 896 | |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 897 | sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms); |
brandtr | 504b95e | 2016-12-21 02:54:35 -0800 | [diff] [blame] | 898 | if (comparison.recv_time_ms > 0) { |
| 899 | // If recv_time_ms == 0, this frame consisted of a packets which were all |
| 900 | // lost in the transport. Since we were able to render the frame, however, |
| 901 | // the dropped packets were recovered by FlexFEC. The FlexFEC recovery |
| 902 | // happens internally in Call, and we can therefore here not know which |
| 903 | // FEC packets that protected the lost media packets. Consequently, we |
| 904 | // were not able to record a meaningful recv_time_ms. We therefore skip |
| 905 | // this sample. |
| 906 | // |
| 907 | // The reasoning above does not hold for ULPFEC and RTX, as for those |
| 908 | // strategies the timestamp of the received packets is set to the |
| 909 | // timestamp of the protected/retransmitted media packet. I.e., then |
| 910 | // recv_time_ms != 0, even though the media packets were lost. |
| 911 | receiver_time_.AddSample(comparison.render_time_ms - |
| 912 | comparison.recv_time_ms); |
| 913 | } |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame] | 914 | end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 915 | encoded_frame_size_.AddSample(comparison.encoded_frame_size); |
| 916 | } |
| 917 | |
| 918 | void PrintResult(const char* result_type, |
| 919 | test::Statistics stats, |
| 920 | const char* unit) { |
| 921 | printf("RESULT %s: %s = {%f, %f}%s\n", |
| 922 | result_type, |
| 923 | test_label_.c_str(), |
| 924 | stats.Mean(), |
| 925 | stats.StandardDeviation(), |
| 926 | unit); |
| 927 | } |
| 928 | |
| 929 | void PrintSamplesToFile(void) { |
| 930 | FILE* out = graph_data_output_file_; |
| 931 | rtc::CritScope crit(&comparison_lock_); |
| 932 | std::sort(samples_.begin(), samples_.end(), |
| 933 | [](const Sample& A, const Sample& B) -> bool { |
| 934 | return A.input_time_ms < B.input_time_ms; |
| 935 | }); |
| 936 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 937 | fprintf(out, "%s\n", graph_title_.c_str()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 938 | fprintf(out, "%" PRIuS "\n", samples_.size()); |
| 939 | fprintf(out, |
| 940 | "dropped " |
| 941 | "input_time_ms " |
| 942 | "send_time_ms " |
| 943 | "recv_time_ms " |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 944 | "render_time_ms " |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 945 | "encoded_frame_size " |
| 946 | "psnr " |
| 947 | "ssim " |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 948 | "encode_time_ms\n"); |
| 949 | int missing_encode_time_samples = 0; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 950 | for (const Sample& sample : samples_) { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 951 | auto it = samples_encode_time_ms_.find(sample.input_time_ms); |
| 952 | int encode_time_ms; |
| 953 | if (it != samples_encode_time_ms_.end()) { |
| 954 | encode_time_ms = it->second; |
| 955 | } else { |
| 956 | ++missing_encode_time_samples; |
| 957 | encode_time_ms = -1; |
| 958 | } |
| 959 | fprintf(out, "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRIuS |
| 960 | " %lf %lf %d\n", |
| 961 | sample.dropped, sample.input_time_ms, sample.send_time_ms, |
| 962 | sample.recv_time_ms, sample.render_time_ms, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 963 | sample.encoded_frame_size, sample.psnr, sample.ssim, |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 964 | encode_time_ms); |
| 965 | } |
| 966 | if (missing_encode_time_samples) { |
| 967 | fprintf(stderr, |
| 968 | "Warning: Missing encode_time_ms samples for %d frame(s).\n", |
| 969 | missing_encode_time_samples); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 970 | } |
| 971 | } |
| 972 | |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 973 | double GetAverageMediaBitrateBps() { |
| 974 | if (last_sending_time_ == first_sending_time_) { |
| 975 | return 0; |
| 976 | } else { |
| 977 | return static_cast<double>(total_media_bytes_) * 8 / |
| 978 | (last_sending_time_ - first_sending_time_) * |
| 979 | rtc::kNumMillisecsPerSec; |
| 980 | } |
| 981 | } |
| 982 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 983 | // Implements VideoSinkInterface to receive captured frames from a |
| 984 | // FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act |
| 985 | // as a source to VideoSendStream. |
| 986 | // It forwards all input frames to the VideoAnalyzer for later comparison and |
| 987 | // forwards the captured frames to the VideoSendStream. |
| 988 | class CapturedFrameForwarder : public rtc::VideoSinkInterface<VideoFrame>, |
| 989 | public rtc::VideoSourceInterface<VideoFrame> { |
| 990 | public: |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 991 | explicit CapturedFrameForwarder(VideoAnalyzer* analyzer, Clock* clock) |
| 992 | : analyzer_(analyzer), |
| 993 | send_stream_input_(nullptr), |
| 994 | video_capturer_(nullptr), |
| 995 | clock_(clock) {} |
| 996 | |
| 997 | void SetSource(test::VideoCapturer* video_capturer) { |
| 998 | video_capturer_ = video_capturer; |
| 999 | } |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1000 | |
| 1001 | private: |
| 1002 | void OnFrame(const VideoFrame& video_frame) override { |
| 1003 | VideoFrame copy = video_frame; |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 1004 | // Frames from the capturer does not have a rtp timestamp. |
| 1005 | // Create one so it can be used for comparison. |
| 1006 | RTC_DCHECK_EQ(0, video_frame.timestamp()); |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 1007 | if (video_frame.ntp_time_ms() == 0) |
| 1008 | copy.set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1009 | copy.set_timestamp(copy.ntp_time_ms() * 90); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 1010 | analyzer_->AddCapturedFrameForComparison(copy); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1011 | rtc::CritScope lock(&crit_); |
| 1012 | if (send_stream_input_) |
ilnik | b82ac6a | 2017-05-02 00:48:41 -0700 | [diff] [blame] | 1013 | send_stream_input_->OnFrame(copy); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | // Called when |send_stream_.SetSource()| is called. |
| 1017 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 1018 | const rtc::VideoSinkWants& wants) override { |
ilnik | 267041c | 2017-06-27 07:21:01 -0700 | [diff] [blame] | 1019 | { |
| 1020 | rtc::CritScope lock(&crit_); |
| 1021 | RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink); |
| 1022 | send_stream_input_ = sink; |
| 1023 | } |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 1024 | if (video_capturer_) { |
| 1025 | video_capturer_->AddOrUpdateSink(this, wants); |
| 1026 | } |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | // Called by |send_stream_| when |send_stream_.SetSource()| is called. |
| 1030 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override { |
| 1031 | rtc::CritScope lock(&crit_); |
| 1032 | RTC_DCHECK(sink == send_stream_input_); |
| 1033 | send_stream_input_ = nullptr; |
| 1034 | } |
| 1035 | |
| 1036 | VideoAnalyzer* const analyzer_; |
| 1037 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1038 | rtc::VideoSinkInterface<VideoFrame>* send_stream_input_ |
| 1039 | RTC_GUARDED_BY(crit_); |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 1040 | test::VideoCapturer* video_capturer_; |
| 1041 | Clock* clock_; |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1042 | }; |
| 1043 | |
| 1044 | void AddCapturedFrameForComparison(const VideoFrame& video_frame) { |
| 1045 | rtc::CritScope lock(&crit_); |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 1046 | frames_.push_back(video_frame); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
stefan | 889d965 | 2017-07-05 03:03:02 -0700 | [diff] [blame] | 1049 | Call* call_; |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1050 | VideoSendStream* send_stream_; |
philipel | fd870db | 2017-01-23 03:22:15 -0800 | [diff] [blame] | 1051 | VideoReceiveStream* receive_stream_; |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1052 | CapturedFrameForwarder captured_frame_forwarder_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1053 | const std::string test_label_; |
| 1054 | FILE* const graph_data_output_file_; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1055 | const std::string graph_title_; |
| 1056 | const uint32_t ssrc_to_analyze_; |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 1057 | const uint32_t rtx_ssrc_to_analyze_; |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 1058 | const size_t selected_stream_; |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 1059 | const int selected_sl_; |
| 1060 | const int selected_tl_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1061 | PreEncodeProxy pre_encode_proxy_; |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 1062 | OnEncodeTimingProxy encode_timing_proxy_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1063 | std::vector<Sample> samples_ RTC_GUARDED_BY(comparison_lock_); |
| 1064 | std::map<int64_t, int> samples_encode_time_ms_ |
| 1065 | RTC_GUARDED_BY(comparison_lock_); |
| 1066 | test::Statistics sender_time_ RTC_GUARDED_BY(comparison_lock_); |
| 1067 | test::Statistics receiver_time_ RTC_GUARDED_BY(comparison_lock_); |
| 1068 | test::Statistics psnr_ RTC_GUARDED_BY(comparison_lock_); |
| 1069 | test::Statistics ssim_ RTC_GUARDED_BY(comparison_lock_); |
| 1070 | test::Statistics end_to_end_ RTC_GUARDED_BY(comparison_lock_); |
| 1071 | test::Statistics rendered_delta_ RTC_GUARDED_BY(comparison_lock_); |
| 1072 | test::Statistics encoded_frame_size_ RTC_GUARDED_BY(comparison_lock_); |
| 1073 | test::Statistics encode_frame_rate_ RTC_GUARDED_BY(comparison_lock_); |
| 1074 | test::Statistics encode_time_ms_ RTC_GUARDED_BY(comparison_lock_); |
| 1075 | test::Statistics encode_usage_percent_ RTC_GUARDED_BY(comparison_lock_); |
| 1076 | test::Statistics decode_time_ms_ RTC_GUARDED_BY(comparison_lock_); |
| 1077 | test::Statistics decode_time_max_ms_ RTC_GUARDED_BY(comparison_lock_); |
| 1078 | test::Statistics media_bitrate_bps_ RTC_GUARDED_BY(comparison_lock_); |
| 1079 | test::Statistics fec_bitrate_bps_ RTC_GUARDED_BY(comparison_lock_); |
| 1080 | test::Statistics send_bandwidth_bps_ RTC_GUARDED_BY(comparison_lock_); |
| 1081 | test::Statistics memory_usage_ RTC_GUARDED_BY(comparison_lock_); |
ilnik | daa574d | 2017-03-01 06:46:05 -0800 | [diff] [blame] | 1082 | |
ilnik | 59cac99 | 2017-07-25 05:45:03 -0700 | [diff] [blame] | 1083 | struct FrameWithPsnr { |
| 1084 | double psnr; |
| 1085 | VideoFrame frame; |
| 1086 | }; |
| 1087 | |
| 1088 | // Rendered frame with worst PSNR is saved for further analysis. |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1089 | rtc::Optional<FrameWithPsnr> worst_frame_ RTC_GUARDED_BY(comparison_lock_); |
ilnik | 59cac99 | 2017-07-25 05:45:03 -0700 | [diff] [blame] | 1090 | |
stefan | 889d965 | 2017-07-05 03:03:02 -0700 | [diff] [blame] | 1091 | size_t last_fec_bytes_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1092 | |
| 1093 | const int frames_to_process_; |
| 1094 | int frames_recorded_; |
| 1095 | int frames_processed_; |
| 1096 | int dropped_frames_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1097 | int dropped_frames_before_first_encode_; |
| 1098 | int dropped_frames_before_rendering_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1099 | int64_t last_render_time_; |
| 1100 | uint32_t rtp_timestamp_delta_; |
ilnik | 1e7732c | 2017-02-23 05:07:56 -0800 | [diff] [blame] | 1101 | int64_t total_media_bytes_; |
| 1102 | int64_t first_sending_time_; |
| 1103 | int64_t last_sending_time_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1104 | |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1105 | int64_t cpu_time_ RTC_GUARDED_BY(cpu_measurement_lock_); |
| 1106 | int64_t wallclock_time_ RTC_GUARDED_BY(cpu_measurement_lock_); |
ilnik | df92c5c | 2017-02-23 02:08:44 -0800 | [diff] [blame] | 1107 | rtc::CriticalSection cpu_measurement_lock_; |
| 1108 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1109 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1110 | std::deque<VideoFrame> frames_ RTC_GUARDED_BY(crit_); |
| 1111 | rtc::Optional<VideoFrame> last_rendered_frame_ RTC_GUARDED_BY(crit_); |
| 1112 | rtc::TimestampWrapAroundHandler wrap_handler_ RTC_GUARDED_BY(crit_); |
| 1113 | std::map<int64_t, int64_t> send_times_ RTC_GUARDED_BY(crit_); |
| 1114 | std::map<int64_t, int64_t> recv_times_ RTC_GUARDED_BY(crit_); |
| 1115 | std::map<int64_t, size_t> encoded_frame_sizes_ RTC_GUARDED_BY(crit_); |
| 1116 | rtc::Optional<uint32_t> first_encoded_timestamp_ RTC_GUARDED_BY(crit_); |
| 1117 | rtc::Optional<uint32_t> first_sent_timestamp_ RTC_GUARDED_BY(crit_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1118 | const double avg_psnr_threshold_; |
| 1119 | const double avg_ssim_threshold_; |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 1120 | bool is_quick_test_enabled_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1121 | |
| 1122 | rtc::CriticalSection comparison_lock_; |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 1123 | std::vector<rtc::PlatformThread*> comparison_thread_pool_; |
| 1124 | rtc::PlatformThread stats_polling_thread_; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1125 | rtc::Event comparison_available_event_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1126 | std::deque<FrameComparison> comparisons_ RTC_GUARDED_BY(comparison_lock_); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1127 | rtc::Event done_; |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1128 | |
| 1129 | std::unique_ptr<test::RtpFileWriter> rtp_file_writer_; |
| 1130 | Clock* const clock_; |
| 1131 | const int64_t start_ms_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1132 | }; |
| 1133 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1134 | VideoQualityTest::VideoQualityTest() |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 1135 | : clock_(Clock::GetRealTimeClock()), receive_logs_(0), send_logs_(0) { |
| 1136 | payload_type_map_ = test::CallTest::payload_type_map_; |
| 1137 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeH264) == |
| 1138 | payload_type_map_.end()); |
| 1139 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP8) == |
| 1140 | payload_type_map_.end()); |
| 1141 | RTC_DCHECK(payload_type_map_.find(kPayloadTypeVP9) == |
| 1142 | payload_type_map_.end()); |
| 1143 | payload_type_map_[kPayloadTypeH264] = webrtc::MediaType::VIDEO; |
| 1144 | payload_type_map_[kPayloadTypeVP8] = webrtc::MediaType::VIDEO; |
| 1145 | payload_type_map_[kPayloadTypeVP9] = webrtc::MediaType::VIDEO; |
| 1146 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1147 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1148 | VideoQualityTest::Params::Params() |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1149 | : call({false, Call::Config::BitrateConfig(), 0}), |
Rasmus Brandt | 3102734 | 2017-09-29 13:48:12 +0000 | [diff] [blame] | 1150 | video({false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false, |
| 1151 | false, ""}), |
minyue | 4c8b942 | 2017-03-21 04:11:43 -0700 | [diff] [blame] | 1152 | audio({false, false, false}), |
erikvarga | 579de6f | 2017-08-29 09:12:57 -0700 | [diff] [blame] | 1153 | screenshare({false, false, 10, 0}), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1154 | analyzer({"", 0.0, 0.0, 0, "", ""}), |
| 1155 | pipe(), |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1156 | ss({std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()}), |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1157 | logging({false, "", "", ""}) {} |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1158 | |
| 1159 | VideoQualityTest::Params::~Params() = default; |
| 1160 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1161 | void VideoQualityTest::TestBody() {} |
| 1162 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1163 | std::string VideoQualityTest::GenerateGraphTitle() const { |
| 1164 | std::stringstream ss; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1165 | ss << params_.video.codec; |
| 1166 | ss << " (" << params_.video.target_bitrate_bps / 1000 << "kbps"; |
| 1167 | ss << ", " << params_.video.fps << " FPS"; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1168 | if (params_.screenshare.scroll_duration) |
| 1169 | ss << ", " << params_.screenshare.scroll_duration << "s scroll"; |
| 1170 | if (params_.ss.streams.size() > 1) |
| 1171 | ss << ", Stream #" << params_.ss.selected_stream; |
| 1172 | if (params_.ss.num_spatial_layers > 1) |
| 1173 | ss << ", Layer #" << params_.ss.selected_sl; |
| 1174 | ss << ")"; |
| 1175 | return ss.str(); |
| 1176 | } |
| 1177 | |
| 1178 | void VideoQualityTest::CheckParams() { |
stefan | 7de8d64 | 2017-02-07 07:14:08 -0800 | [diff] [blame] | 1179 | if (!params_.video.enabled) |
| 1180 | return; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1181 | // Add a default stream in none specified. |
| 1182 | if (params_.ss.streams.empty()) |
| 1183 | params_.ss.streams.push_back(VideoQualityTest::DefaultVideoStream(params_)); |
| 1184 | if (params_.ss.num_spatial_layers == 0) |
| 1185 | params_.ss.num_spatial_layers = 1; |
| 1186 | |
| 1187 | if (params_.pipe.loss_percent != 0 || |
| 1188 | params_.pipe.queue_length_packets != 0) { |
| 1189 | // Since LayerFilteringTransport changes the sequence numbers, we can't |
| 1190 | // use that feature with pack loss, since the NACK request would end up |
| 1191 | // retransmitting the wrong packets. |
| 1192 | RTC_CHECK(params_.ss.selected_sl == -1 || |
sprang | ee37de3 | 2015-11-23 06:10:23 -0800 | [diff] [blame] | 1193 | params_.ss.selected_sl == params_.ss.num_spatial_layers - 1); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1194 | RTC_CHECK(params_.video.selected_tl == -1 || |
| 1195 | params_.video.selected_tl == |
| 1196 | params_.video.num_temporal_layers - 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as it |
| 1200 | // does in some parts of the code? |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1201 | RTC_CHECK_GE(params_.video.max_bitrate_bps, params_.video.target_bitrate_bps); |
| 1202 | RTC_CHECK_GE(params_.video.target_bitrate_bps, params_.video.min_bitrate_bps); |
| 1203 | RTC_CHECK_LT(params_.video.selected_tl, params_.video.num_temporal_layers); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1204 | RTC_CHECK_LE(params_.ss.selected_stream, params_.ss.streams.size()); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1205 | for (const VideoStream& stream : params_.ss.streams) { |
| 1206 | RTC_CHECK_GE(stream.min_bitrate_bps, 0); |
| 1207 | RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps); |
| 1208 | RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1209 | } |
| 1210 | // TODO(ivica): Should we check if the sum of all streams/layers is equal to |
| 1211 | // the total bitrate? We anyway have to update them in the case bitrate |
| 1212 | // estimator changes the total bitrates. |
| 1213 | RTC_CHECK_GE(params_.ss.num_spatial_layers, 1); |
| 1214 | RTC_CHECK_LE(params_.ss.selected_sl, params_.ss.num_spatial_layers); |
| 1215 | RTC_CHECK(params_.ss.spatial_layers.empty() || |
| 1216 | params_.ss.spatial_layers.size() == |
| 1217 | static_cast<size_t>(params_.ss.num_spatial_layers)); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1218 | if (params_.video.codec == "VP8") { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1219 | RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1220 | } else if (params_.video.codec == "VP9") { |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 1221 | RTC_CHECK_EQ(params_.ss.streams.size(), 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1222 | } |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1223 | RTC_CHECK_GE(params_.call.num_thumbnails, 0); |
| 1224 | if (params_.call.num_thumbnails > 0) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1225 | RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1); |
| 1226 | RTC_CHECK_EQ(params_.ss.streams.size(), 3); |
| 1227 | RTC_CHECK_EQ(params_.video.num_temporal_layers, 3); |
| 1228 | RTC_CHECK_EQ(params_.video.codec, "VP8"); |
| 1229 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | // Static. |
| 1233 | std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) { |
| 1234 | // Parse comma separated nonnegative integers, where some elements may be |
| 1235 | // empty. The empty values are replaced with -1. |
| 1236 | // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40} |
| 1237 | // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1} |
| 1238 | std::vector<int> result; |
| 1239 | if (str.empty()) |
| 1240 | return result; |
| 1241 | |
| 1242 | const char* p = str.c_str(); |
| 1243 | int value = -1; |
| 1244 | int pos; |
| 1245 | while (*p) { |
| 1246 | if (*p == ',') { |
| 1247 | result.push_back(value); |
| 1248 | value = -1; |
| 1249 | ++p; |
| 1250 | continue; |
| 1251 | } |
| 1252 | RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1) |
| 1253 | << "Unexpected non-number value."; |
| 1254 | p += pos; |
| 1255 | } |
| 1256 | result.push_back(value); |
| 1257 | return result; |
| 1258 | } |
| 1259 | |
| 1260 | // Static. |
| 1261 | VideoStream VideoQualityTest::DefaultVideoStream(const Params& params) { |
| 1262 | VideoStream stream; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1263 | stream.width = params.video.width; |
| 1264 | stream.height = params.video.height; |
| 1265 | stream.max_framerate = params.video.fps; |
| 1266 | stream.min_bitrate_bps = params.video.min_bitrate_bps; |
| 1267 | stream.target_bitrate_bps = params.video.target_bitrate_bps; |
| 1268 | stream.max_bitrate_bps = params.video.max_bitrate_bps; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1269 | stream.max_qp = kDefaultMaxQp; |
sprang | 6ef1b34 | 2017-03-13 02:01:32 -0700 | [diff] [blame] | 1270 | // TODO(sprang): Can we make this less of a hack? |
| 1271 | if (params.video.num_temporal_layers == 2) { |
| 1272 | stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps); |
| 1273 | } else if (params.video.num_temporal_layers == 3) { |
| 1274 | stream.temporal_layer_thresholds_bps.push_back(stream.max_bitrate_bps / 4); |
| 1275 | stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps); |
sprang | ff19d35 | 2017-09-06 07:14:02 -0700 | [diff] [blame] | 1276 | } else { |
| 1277 | RTC_CHECK_LE(params.video.num_temporal_layers, kMaxTemporalStreams); |
| 1278 | for (int i = 0; i < params.video.num_temporal_layers - 1; ++i) { |
| 1279 | stream.temporal_layer_thresholds_bps.push_back(static_cast<int>( |
| 1280 | stream.max_bitrate_bps * kVp8LayerRateAlloction[0][i] + 0.5)); |
| 1281 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1282 | } |
| 1283 | return stream; |
| 1284 | } |
| 1285 | |
| 1286 | // Static. |
| 1287 | VideoStream VideoQualityTest::DefaultThumbnailStream() { |
| 1288 | VideoStream stream; |
| 1289 | stream.width = 320; |
| 1290 | stream.height = 180; |
| 1291 | stream.max_framerate = 7; |
| 1292 | stream.min_bitrate_bps = 7500; |
| 1293 | stream.target_bitrate_bps = 37500; |
| 1294 | stream.max_bitrate_bps = 50000; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1295 | stream.max_qp = kDefaultMaxQp; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1296 | return stream; |
| 1297 | } |
| 1298 | |
| 1299 | // Static. |
| 1300 | void VideoQualityTest::FillScalabilitySettings( |
| 1301 | Params* params, |
| 1302 | const std::vector<std::string>& stream_descriptors, |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1303 | int num_streams, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1304 | size_t selected_stream, |
| 1305 | int num_spatial_layers, |
| 1306 | int selected_sl, |
| 1307 | const std::vector<std::string>& sl_descriptors) { |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1308 | if (params->ss.streams.empty() && params->ss.infer_streams) { |
| 1309 | webrtc::VideoEncoderConfig encoder_config; |
| 1310 | encoder_config.content_type = |
| 1311 | params->screenshare.enabled |
| 1312 | ? webrtc::VideoEncoderConfig::ContentType::kScreen |
| 1313 | : webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
| 1314 | encoder_config.max_bitrate_bps = params->video.max_bitrate_bps; |
| 1315 | encoder_config.min_transmit_bitrate_bps = params->video.min_transmit_bps; |
| 1316 | encoder_config.number_of_streams = num_streams; |
| 1317 | encoder_config.spatial_layers = params->ss.spatial_layers; |
| 1318 | encoder_config.video_stream_factory = |
| 1319 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
| 1320 | params->video.codec, kDefaultMaxQp, params->video.fps, |
| 1321 | params->screenshare.enabled, true); |
| 1322 | params->ss.streams = |
| 1323 | encoder_config.video_stream_factory->CreateEncoderStreams( |
| 1324 | static_cast<int>(params->video.width), |
| 1325 | static_cast<int>(params->video.height), encoder_config); |
| 1326 | } else { |
| 1327 | // Read VideoStream and SpatialLayer elements from a list of comma separated |
| 1328 | // lists. To use a default value for an element, use -1 or leave empty. |
| 1329 | // Validity checks performed in CheckParams. |
| 1330 | RTC_CHECK(params->ss.streams.empty()); |
| 1331 | for (auto descriptor : stream_descriptors) { |
| 1332 | if (descriptor.empty()) |
| 1333 | continue; |
| 1334 | VideoStream stream = VideoQualityTest::DefaultVideoStream(*params); |
| 1335 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
| 1336 | if (v[0] != -1) |
| 1337 | stream.width = static_cast<size_t>(v[0]); |
| 1338 | if (v[1] != -1) |
| 1339 | stream.height = static_cast<size_t>(v[1]); |
| 1340 | if (v[2] != -1) |
| 1341 | stream.max_framerate = v[2]; |
| 1342 | if (v[3] != -1) |
| 1343 | stream.min_bitrate_bps = v[3]; |
| 1344 | if (v[4] != -1) |
| 1345 | stream.target_bitrate_bps = v[4]; |
| 1346 | if (v[5] != -1) |
| 1347 | stream.max_bitrate_bps = v[5]; |
| 1348 | if (v.size() > 6 && v[6] != -1) |
| 1349 | stream.max_qp = v[6]; |
| 1350 | if (v.size() > 7) { |
| 1351 | stream.temporal_layer_thresholds_bps.clear(); |
| 1352 | stream.temporal_layer_thresholds_bps.insert( |
| 1353 | stream.temporal_layer_thresholds_bps.end(), v.begin() + 7, v.end()); |
| 1354 | } else { |
| 1355 | // Automatic TL thresholds for more than two layers not supported. |
| 1356 | RTC_CHECK_LE(params->video.num_temporal_layers, 2); |
| 1357 | } |
| 1358 | params->ss.streams.push_back(stream); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1359 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1360 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1361 | |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1362 | params->ss.num_spatial_layers = std::max(1, num_spatial_layers); |
| 1363 | params->ss.selected_stream = selected_stream; |
| 1364 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1365 | params->ss.selected_sl = selected_sl; |
| 1366 | RTC_CHECK(params->ss.spatial_layers.empty()); |
| 1367 | for (auto descriptor : sl_descriptors) { |
| 1368 | if (descriptor.empty()) |
| 1369 | continue; |
| 1370 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
| 1371 | RTC_CHECK_GT(v[2], 0); |
| 1372 | |
| 1373 | SpatialLayer layer; |
| 1374 | layer.scaling_factor_num = v[0] == -1 ? 1 : v[0]; |
| 1375 | layer.scaling_factor_den = v[1] == -1 ? 1 : v[1]; |
| 1376 | layer.target_bitrate_bps = v[2]; |
| 1377 | params->ss.spatial_layers.push_back(layer); |
| 1378 | } |
| 1379 | } |
| 1380 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1381 | void VideoQualityTest::SetupVideo(Transport* send_transport, |
| 1382 | Transport* recv_transport) { |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1383 | size_t num_video_streams = params_.ss.streams.size(); |
| 1384 | size_t num_flexfec_streams = params_.video.flexfec ? 1 : 0; |
| 1385 | CreateSendConfig(num_video_streams, 0, num_flexfec_streams, send_transport); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1386 | |
| 1387 | int payload_type; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1388 | if (params_.video.codec == "H264") { |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 1389 | video_encoder_ = H264Encoder::Create(cricket::VideoCodec("H264")); |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 1390 | payload_type = kPayloadTypeH264; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1391 | } else if (params_.video.codec == "VP8") { |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 1392 | if (params_.screenshare.enabled && params_.ss.streams.size() > 1) { |
Rasmus Brandt | 3102734 | 2017-09-29 13:48:12 +0000 | [diff] [blame] | 1393 | // Simulcast screenshare needs a simulcast encoder adapter to work, since |
| 1394 | // encoders usually can't natively do simulcast with different frame rates |
| 1395 | // for the different layers. |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 1396 | video_encoder_.reset( |
Magnus Jedvert | df4883d | 2017-11-17 14:44:55 +0100 | [diff] [blame] | 1397 | new SimulcastEncoderAdapter(new InternalEncoderFactory())); |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 1398 | } else { |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 1399 | video_encoder_ = VP8Encoder::Create(); |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 1400 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1401 | payload_type = kPayloadTypeVP8; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1402 | } else if (params_.video.codec == "VP9") { |
Magnus Jedvert | 46a2765 | 2017-11-13 14:10:02 +0100 | [diff] [blame] | 1403 | video_encoder_ = VP9Encoder::Create(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1404 | payload_type = kPayloadTypeVP9; |
| 1405 | } else { |
| 1406 | RTC_NOTREACHED() << "Codec not supported!"; |
| 1407 | return; |
| 1408 | } |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1409 | video_send_config_.encoder_settings.encoder = video_encoder_.get(); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1410 | video_send_config_.encoder_settings.payload_name = params_.video.codec; |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1411 | video_send_config_.encoder_settings.payload_type = payload_type; |
| 1412 | video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 1413 | video_send_config_.rtp.rtx.payload_type = kSendRtxPayloadType; |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1414 | for (size_t i = 0; i < num_video_streams; ++i) |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1415 | video_send_config_.rtp.rtx.ssrcs.push_back(kSendRtxSsrcs[i]); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1416 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1417 | video_send_config_.rtp.extensions.clear(); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1418 | if (params_.call.send_side_bwe) { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1419 | video_send_config_.rtp.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1420 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
Stefan Holmer | 1295297 | 2015-10-29 15:13:24 +0100 | [diff] [blame] | 1421 | test::kTransportSequenceNumberExtensionId)); |
| 1422 | } else { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1423 | video_send_config_.rtp.extensions.push_back(RtpExtension( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1424 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1425 | } |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 1426 | video_send_config_.rtp.extensions.push_back(RtpExtension( |
| 1427 | RtpExtension::kVideoContentTypeUri, test::kVideoContentTypeExtensionId)); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 1428 | video_send_config_.rtp.extensions.push_back(RtpExtension( |
| 1429 | RtpExtension::kVideoTimingUri, test::kVideoTimingExtensionId)); |
Erik Språng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1430 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1431 | video_encoder_config_.min_transmit_bitrate_bps = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1432 | params_.video.min_transmit_bps; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1433 | |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1434 | video_send_config_.suspend_below_min_bitrate = |
| 1435 | params_.video.suspend_below_min_bitrate; |
| 1436 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1437 | video_encoder_config_.number_of_streams = params_.ss.streams.size(); |
| 1438 | video_encoder_config_.max_bitrate_bps = 0; |
| 1439 | for (size_t i = 0; i < params_.ss.streams.size(); ++i) { |
| 1440 | video_encoder_config_.max_bitrate_bps += |
| 1441 | params_.ss.streams[i].max_bitrate_bps; |
| 1442 | } |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 1443 | if (params_.ss.infer_streams) { |
| 1444 | video_encoder_config_.video_stream_factory = |
| 1445 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
| 1446 | params_.video.codec, params_.ss.streams[0].max_qp, |
| 1447 | params_.video.fps, params_.screenshare.enabled, true); |
| 1448 | } else { |
| 1449 | video_encoder_config_.video_stream_factory = |
| 1450 | new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams); |
| 1451 | } |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1452 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1453 | video_encoder_config_.spatial_layers = params_.ss.spatial_layers; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1454 | |
| 1455 | CreateMatchingReceiveConfigs(recv_transport); |
| 1456 | |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1457 | const bool decode_all_receive_streams = |
| 1458 | params_.ss.selected_stream == params_.ss.streams.size(); |
| 1459 | |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1460 | for (size_t i = 0; i < num_video_streams; ++i) { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1461 | video_receive_configs_[i].rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 1462 | video_receive_configs_[i].rtp.rtx_ssrc = kSendRtxSsrcs[i]; |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 1463 | video_receive_configs_[i] |
| 1464 | .rtp.rtx_associated_payload_types[kSendRtxPayloadType] = payload_type; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1465 | video_receive_configs_[i].rtp.transport_cc = params_.call.send_side_bwe; |
Stefan Holmer | 85d5ac7 | 2017-02-09 16:25:16 +0100 | [diff] [blame] | 1466 | video_receive_configs_[i].rtp.remb = !params_.call.send_side_bwe; |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 1467 | // Enable RTT calculation so NTP time estimator will work. |
| 1468 | video_receive_configs_[i].rtp.rtcp_xr.receiver_reference_time_report = true; |
ilnik | 9fd9f6c | 2017-03-02 08:10:10 -0800 | [diff] [blame] | 1469 | // Force fake decoders on non-selected simulcast streams. |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1470 | if (!decode_all_receive_streams && i != params_.ss.selected_stream) { |
ilnik | 9fd9f6c | 2017-03-02 08:10:10 -0800 | [diff] [blame] | 1471 | VideoReceiveStream::Decoder decoder; |
| 1472 | decoder.decoder = new test::FakeDecoder(); |
| 1473 | decoder.payload_type = video_send_config_.encoder_settings.payload_type; |
| 1474 | decoder.payload_name = video_send_config_.encoder_settings.payload_name; |
| 1475 | video_receive_configs_[i].decoders.clear(); |
| 1476 | allocated_decoders_.emplace_back(decoder.decoder); |
| 1477 | video_receive_configs_[i].decoders.push_back(decoder); |
| 1478 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1479 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1480 | |
| 1481 | if (params_.video.flexfec) { |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1482 | // Override send config constructed by CreateSendConfig. |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1483 | if (decode_all_receive_streams) { |
| 1484 | for (uint32_t media_ssrc : video_send_config_.rtp.ssrcs) { |
| 1485 | video_send_config_.rtp.flexfec.protected_media_ssrcs.push_back( |
| 1486 | media_ssrc); |
| 1487 | } |
| 1488 | } else { |
| 1489 | video_send_config_.rtp.flexfec.protected_media_ssrcs = { |
| 1490 | kVideoSendSsrcs[params_.ss.selected_stream]}; |
| 1491 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1492 | |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 1493 | // The matching receive config is _not_ created by |
| 1494 | // CreateMatchingReceiveConfigs, since VideoQualityTest is not a BaseTest. |
| 1495 | // Set up the receive config manually instead. |
| 1496 | FlexfecReceiveStream::Config flexfec_receive_config(recv_transport); |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 1497 | flexfec_receive_config.payload_type = |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 1498 | video_send_config_.rtp.flexfec.payload_type; |
| 1499 | flexfec_receive_config.remote_ssrc = video_send_config_.rtp.flexfec.ssrc; |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1500 | flexfec_receive_config.protected_media_ssrcs = |
| 1501 | video_send_config_.rtp.flexfec.protected_media_ssrcs; |
brandtr | fa5a368 | 2017-01-17 01:33:54 -0800 | [diff] [blame] | 1502 | flexfec_receive_config.local_ssrc = kReceiverLocalVideoSsrc; |
brandtr | b29e652 | 2016-12-21 06:37:18 -0800 | [diff] [blame] | 1503 | flexfec_receive_config.transport_cc = params_.call.send_side_bwe; |
| 1504 | if (params_.call.send_side_bwe) { |
| 1505 | flexfec_receive_config.rtp_header_extensions.push_back( |
| 1506 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 1507 | test::kTransportSequenceNumberExtensionId)); |
| 1508 | } else { |
| 1509 | flexfec_receive_config.rtp_header_extensions.push_back(RtpExtension( |
| 1510 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
| 1511 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1512 | flexfec_receive_configs_.push_back(flexfec_receive_config); |
brandtr | 7cd28b9 | 2017-09-22 00:26:25 -0700 | [diff] [blame] | 1513 | if (num_video_streams > 0) { |
| 1514 | video_receive_configs_[0].rtp.protected_by_flexfec = true; |
| 1515 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | if (params_.video.ulpfec) { |
| 1519 | video_send_config_.rtp.ulpfec.red_payload_type = kRedPayloadType; |
| 1520 | video_send_config_.rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType; |
| 1521 | video_send_config_.rtp.ulpfec.red_rtx_payload_type = kRtxRedPayloadType; |
| 1522 | |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1523 | if (decode_all_receive_streams) { |
| 1524 | for (auto it = video_receive_configs_.begin(); |
| 1525 | it != video_receive_configs_.end(); ++it) { |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 1526 | it->rtp.red_payload_type = |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1527 | video_send_config_.rtp.ulpfec.red_payload_type; |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 1528 | it->rtp.ulpfec_payload_type = |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1529 | video_send_config_.rtp.ulpfec.ulpfec_payload_type; |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 1530 | it->rtp.rtx_associated_payload_types[video_send_config_.rtp.ulpfec |
| 1531 | .red_rtx_payload_type] = |
| 1532 | video_send_config_.rtp.ulpfec.red_payload_type; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1533 | } |
| 1534 | } else { |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 1535 | video_receive_configs_[params_.ss.selected_stream].rtp.red_payload_type = |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1536 | video_send_config_.rtp.ulpfec.red_payload_type; |
| 1537 | video_receive_configs_[params_.ss.selected_stream] |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 1538 | .rtp.ulpfec_payload_type = |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1539 | video_send_config_.rtp.ulpfec.ulpfec_payload_type; |
| 1540 | video_receive_configs_[params_.ss.selected_stream] |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 1541 | .rtp.rtx_associated_payload_types[video_send_config_.rtp.ulpfec |
| 1542 | .red_rtx_payload_type] = |
| 1543 | video_send_config_.rtp.ulpfec.red_payload_type; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1544 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1545 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1548 | void VideoQualityTest::SetupThumbnails(Transport* send_transport, |
| 1549 | Transport* recv_transport) { |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1550 | for (int i = 0; i < params_.call.num_thumbnails; ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1551 | thumbnail_encoders_.emplace_back(VP8Encoder::Create()); |
| 1552 | |
| 1553 | // Thumbnails will be send in the other way: from receiver_call to |
| 1554 | // sender_call. |
| 1555 | VideoSendStream::Config thumbnail_send_config(recv_transport); |
| 1556 | thumbnail_send_config.rtp.ssrcs.push_back(kThumbnailSendSsrcStart + i); |
| 1557 | thumbnail_send_config.encoder_settings.encoder = |
| 1558 | thumbnail_encoders_.back().get(); |
| 1559 | thumbnail_send_config.encoder_settings.payload_name = params_.video.codec; |
| 1560 | thumbnail_send_config.encoder_settings.payload_type = kPayloadTypeVP8; |
| 1561 | thumbnail_send_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 1562 | thumbnail_send_config.rtp.rtx.payload_type = kSendRtxPayloadType; |
| 1563 | thumbnail_send_config.rtp.rtx.ssrcs.push_back(kThumbnailRtxSsrcStart + i); |
| 1564 | thumbnail_send_config.rtp.extensions.clear(); |
| 1565 | if (params_.call.send_side_bwe) { |
| 1566 | thumbnail_send_config.rtp.extensions.push_back( |
| 1567 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
| 1568 | test::kTransportSequenceNumberExtensionId)); |
| 1569 | } else { |
| 1570 | thumbnail_send_config.rtp.extensions.push_back(RtpExtension( |
| 1571 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
| 1572 | } |
| 1573 | |
| 1574 | VideoEncoderConfig thumbnail_encoder_config; |
| 1575 | thumbnail_encoder_config.min_transmit_bitrate_bps = 7500; |
| 1576 | thumbnail_send_config.suspend_below_min_bitrate = |
| 1577 | params_.video.suspend_below_min_bitrate; |
| 1578 | thumbnail_encoder_config.number_of_streams = 1; |
| 1579 | thumbnail_encoder_config.max_bitrate_bps = 50000; |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 1580 | if (params_.ss.infer_streams) { |
| 1581 | thumbnail_encoder_config.video_stream_factory = |
| 1582 | new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams); |
| 1583 | } else { |
| 1584 | thumbnail_encoder_config.video_stream_factory = |
| 1585 | new rtc::RefCountedObject<cricket::EncoderStreamFactory>( |
| 1586 | params_.video.codec, params_.ss.streams[0].max_qp, |
| 1587 | params_.video.fps, params_.screenshare.enabled, true); |
| 1588 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1589 | thumbnail_encoder_config.spatial_layers = params_.ss.spatial_layers; |
| 1590 | |
| 1591 | VideoReceiveStream::Config thumbnail_receive_config(send_transport); |
| 1592 | thumbnail_receive_config.rtp.remb = false; |
| 1593 | thumbnail_receive_config.rtp.transport_cc = true; |
| 1594 | thumbnail_receive_config.rtp.local_ssrc = kReceiverLocalVideoSsrc; |
| 1595 | for (const RtpExtension& extension : thumbnail_send_config.rtp.extensions) |
| 1596 | thumbnail_receive_config.rtp.extensions.push_back(extension); |
| 1597 | thumbnail_receive_config.renderer = &fake_renderer_; |
| 1598 | |
| 1599 | VideoReceiveStream::Decoder decoder = |
| 1600 | test::CreateMatchingDecoder(thumbnail_send_config.encoder_settings); |
| 1601 | allocated_decoders_.push_back( |
| 1602 | std::unique_ptr<VideoDecoder>(decoder.decoder)); |
| 1603 | thumbnail_receive_config.decoders.clear(); |
| 1604 | thumbnail_receive_config.decoders.push_back(decoder); |
| 1605 | thumbnail_receive_config.rtp.remote_ssrc = |
| 1606 | thumbnail_send_config.rtp.ssrcs[0]; |
| 1607 | |
| 1608 | thumbnail_receive_config.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 1609 | thumbnail_receive_config.rtp.rtx_ssrc = kThumbnailRtxSsrcStart + i; |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 1610 | thumbnail_receive_config.rtp |
| 1611 | .rtx_associated_payload_types[kSendRtxPayloadType] = kPayloadTypeVP8; |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1612 | thumbnail_receive_config.rtp.transport_cc = params_.call.send_side_bwe; |
| 1613 | thumbnail_receive_config.rtp.remb = !params_.call.send_side_bwe; |
| 1614 | |
| 1615 | thumbnail_encoder_configs_.push_back(thumbnail_encoder_config.Copy()); |
| 1616 | thumbnail_send_configs_.push_back(thumbnail_send_config.Copy()); |
| 1617 | thumbnail_receive_configs_.push_back(thumbnail_receive_config.Copy()); |
| 1618 | } |
| 1619 | |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1620 | for (int i = 0; i < params_.call.num_thumbnails; ++i) { |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1621 | thumbnail_send_streams_.push_back(receiver_call_->CreateVideoSendStream( |
| 1622 | thumbnail_send_configs_[i].Copy(), |
| 1623 | thumbnail_encoder_configs_[i].Copy())); |
| 1624 | thumbnail_receive_streams_.push_back(sender_call_->CreateVideoReceiveStream( |
| 1625 | thumbnail_receive_configs_[i].Copy())); |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | void VideoQualityTest::DestroyThumbnailStreams() { |
| 1630 | for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) |
| 1631 | receiver_call_->DestroyVideoSendStream(thumbnail_send_stream); |
| 1632 | thumbnail_send_streams_.clear(); |
| 1633 | for (VideoReceiveStream* thumbnail_receive_stream : |
| 1634 | thumbnail_receive_streams_) |
| 1635 | sender_call_->DestroyVideoReceiveStream(thumbnail_receive_stream); |
| 1636 | thumbnail_send_streams_.clear(); |
| 1637 | thumbnail_receive_streams_.clear(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1638 | for (std::unique_ptr<test::VideoCapturer>& video_caputurer : |
| 1639 | thumbnail_capturers_) { |
| 1640 | video_caputurer.reset(); |
| 1641 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1642 | } |
| 1643 | |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1644 | void VideoQualityTest::SetupScreenshareOrSVC() { |
| 1645 | if (params_.screenshare.enabled) { |
| 1646 | // Fill out codec settings. |
| 1647 | video_encoder_config_.content_type = |
| 1648 | VideoEncoderConfig::ContentType::kScreen; |
| 1649 | degradation_preference_ = |
| 1650 | VideoSendStream::DegradationPreference::kMaintainResolution; |
| 1651 | if (params_.video.codec == "VP8") { |
| 1652 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 1653 | vp8_settings.denoisingOn = false; |
| 1654 | vp8_settings.frameDroppingOn = false; |
| 1655 | vp8_settings.numberOfTemporalLayers = |
| 1656 | static_cast<unsigned char>(params_.video.num_temporal_layers); |
| 1657 | video_encoder_config_.encoder_specific_settings = |
| 1658 | new rtc::RefCountedObject< |
| 1659 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
| 1660 | } else if (params_.video.codec == "VP9") { |
| 1661 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 1662 | vp9_settings.denoisingOn = false; |
| 1663 | vp9_settings.frameDroppingOn = false; |
| 1664 | vp9_settings.numberOfTemporalLayers = |
| 1665 | static_cast<unsigned char>(params_.video.num_temporal_layers); |
| 1666 | vp9_settings.numberOfSpatialLayers = |
| 1667 | static_cast<unsigned char>(params_.ss.num_spatial_layers); |
| 1668 | video_encoder_config_.encoder_specific_settings = |
| 1669 | new rtc::RefCountedObject< |
| 1670 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
| 1671 | } |
| 1672 | // Setup frame generator. |
| 1673 | const size_t kWidth = 1850; |
| 1674 | const size_t kHeight = 1110; |
erikvarga | 579de6f | 2017-08-29 09:12:57 -0700 | [diff] [blame] | 1675 | if (params_.screenshare.generate_slides) { |
| 1676 | frame_generator_ = test::FrameGenerator::CreateSlideGenerator( |
| 1677 | kWidth, kHeight, |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 1678 | params_.screenshare.slide_change_interval * params_.video.fps); |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1679 | } else { |
erikvarga | 579de6f | 2017-08-29 09:12:57 -0700 | [diff] [blame] | 1680 | std::vector<std::string> slides = params_.screenshare.slides; |
| 1681 | if (slides.size() == 0) { |
| 1682 | slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); |
| 1683 | slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); |
| 1684 | slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); |
| 1685 | slides.push_back( |
| 1686 | test::ResourcePath("difficult_photo_1850_1110", "yuv")); |
| 1687 | } |
| 1688 | if (params_.screenshare.scroll_duration == 0) { |
| 1689 | // Cycle image every slide_change_interval seconds. |
| 1690 | frame_generator_ = test::FrameGenerator::CreateFromYuvFile( |
| 1691 | slides, kWidth, kHeight, |
| 1692 | params_.screenshare.slide_change_interval * params_.video.fps); |
| 1693 | } else { |
| 1694 | RTC_CHECK_LE(params_.video.width, kWidth); |
| 1695 | RTC_CHECK_LE(params_.video.height, kHeight); |
| 1696 | RTC_CHECK_GT(params_.screenshare.slide_change_interval, 0); |
| 1697 | const int kPauseDurationMs = |
| 1698 | (params_.screenshare.slide_change_interval - |
| 1699 | params_.screenshare.scroll_duration) * |
| 1700 | 1000; |
| 1701 | RTC_CHECK_LE(params_.screenshare.scroll_duration, |
| 1702 | params_.screenshare.slide_change_interval); |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1703 | |
erikvarga | 579de6f | 2017-08-29 09:12:57 -0700 | [diff] [blame] | 1704 | frame_generator_ = |
| 1705 | test::FrameGenerator::CreateScrollingInputFromYuvFiles( |
| 1706 | clock_, slides, kWidth, kHeight, params_.video.width, |
| 1707 | params_.video.height, |
| 1708 | params_.screenshare.scroll_duration * 1000, kPauseDurationMs); |
| 1709 | } |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1710 | } |
| 1711 | } else if (params_.ss.num_spatial_layers > 1) { // For non-screenshare case. |
| 1712 | RTC_CHECK(params_.video.codec == "VP9"); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1713 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1714 | vp9_settings.numberOfTemporalLayers = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1715 | static_cast<unsigned char>(params_.video.num_temporal_layers); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1716 | vp9_settings.numberOfSpatialLayers = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1717 | static_cast<unsigned char>(params_.ss.num_spatial_layers); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1718 | video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject< |
| 1719 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1720 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1723 | void VideoQualityTest::SetupThumbnailCapturers(size_t num_thumbnail_streams) { |
| 1724 | VideoStream thumbnail = DefaultThumbnailStream(); |
| 1725 | for (size_t i = 0; i < num_thumbnail_streams; ++i) { |
| 1726 | thumbnail_capturers_.emplace_back(test::FrameGeneratorCapturer::Create( |
| 1727 | static_cast<int>(thumbnail.width), static_cast<int>(thumbnail.height), |
| 1728 | thumbnail.max_framerate, clock_)); |
ilnik | f89a738 | 2017-03-07 06:15:27 -0800 | [diff] [blame] | 1729 | RTC_DCHECK(thumbnail_capturers_.back()); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1733 | void VideoQualityTest::CreateCapturer() { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1734 | if (params_.screenshare.enabled) { |
| 1735 | test::FrameGeneratorCapturer* frame_generator_capturer = |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 1736 | new test::FrameGeneratorCapturer(clock_, std::move(frame_generator_), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1737 | params_.video.fps); |
ivica | 2d4e6c5 | 2015-09-23 01:57:06 -0700 | [diff] [blame] | 1738 | EXPECT_TRUE(frame_generator_capturer->Init()); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1739 | video_capturer_.reset(frame_generator_capturer); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1740 | } else { |
ilnik | 6b826ef | 2017-06-16 06:53:48 -0700 | [diff] [blame] | 1741 | if (params_.video.clip_name == "Generator") { |
| 1742 | video_capturer_.reset(test::FrameGeneratorCapturer::Create( |
| 1743 | static_cast<int>(params_.video.width), |
| 1744 | static_cast<int>(params_.video.height), params_.video.fps, clock_)); |
| 1745 | } else if (params_.video.clip_name.empty()) { |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1746 | video_capturer_.reset(test::VcmCapturer::Create( |
Tarun Chawla | 8e857d1 | 2017-05-31 19:20:57 +0530 | [diff] [blame] | 1747 | params_.video.width, params_.video.height, params_.video.fps, |
| 1748 | params_.video.capture_device_index)); |
sprang | 1bed2e4 | 2017-01-23 08:46:51 -0800 | [diff] [blame] | 1749 | if (!video_capturer_) { |
| 1750 | // Failed to get actual camera, use chroma generator as backup. |
| 1751 | video_capturer_.reset(test::FrameGeneratorCapturer::Create( |
perkj | a8ba195 | 2017-02-27 06:52:10 -0800 | [diff] [blame] | 1752 | static_cast<int>(params_.video.width), |
| 1753 | static_cast<int>(params_.video.height), params_.video.fps, clock_)); |
sprang | 1bed2e4 | 2017-01-23 08:46:51 -0800 | [diff] [blame] | 1754 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1755 | } else { |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1756 | video_capturer_.reset(test::FrameGeneratorCapturer::CreateFromYuvFile( |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1757 | test::ResourcePath(params_.video.clip_name, "yuv"), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1758 | params_.video.width, params_.video.height, params_.video.fps, |
ivica | 2d4e6c5 | 2015-09-23 01:57:06 -0700 | [diff] [blame] | 1759 | clock_)); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1760 | ASSERT_TRUE(video_capturer_) << "Could not create capturer for " |
| 1761 | << params_.video.clip_name |
| 1762 | << ".yuv. Is this resource file present?"; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1763 | } |
| 1764 | } |
sprang | 1bed2e4 | 2017-01-23 08:46:51 -0800 | [diff] [blame] | 1765 | RTC_DCHECK(video_capturer_.get()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1766 | } |
| 1767 | |
Christoffer Rodbro | b4bb4eb | 2017-11-13 13:03:52 +0100 | [diff] [blame] | 1768 | std::unique_ptr<test::LayerFilteringTransport> |
| 1769 | VideoQualityTest::CreateSendTransport() { |
| 1770 | return rtc::MakeUnique<test::LayerFilteringTransport>( |
| 1771 | &task_queue_, params_.pipe, sender_call_.get(), kPayloadTypeVP8, |
| 1772 | kPayloadTypeVP9, params_.video.selected_tl, params_.ss.selected_sl, |
| 1773 | payload_type_map_); |
| 1774 | } |
| 1775 | |
| 1776 | std::unique_ptr<test::DirectTransport> |
| 1777 | VideoQualityTest::CreateReceiveTransport() { |
| 1778 | return rtc::MakeUnique<test::DirectTransport>( |
| 1779 | &task_queue_, params_.pipe, receiver_call_.get(), payload_type_map_); |
| 1780 | } |
| 1781 | |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1782 | void VideoQualityTest::RunWithAnalyzer(const Params& params) { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1783 | std::unique_ptr<test::LayerFilteringTransport> send_transport; |
| 1784 | std::unique_ptr<test::DirectTransport> recv_transport; |
| 1785 | FILE* graph_data_output_file = nullptr; |
| 1786 | std::unique_ptr<VideoAnalyzer> analyzer; |
| 1787 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1788 | params_ = params; |
| 1789 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1790 | RTC_CHECK(!params_.audio.enabled); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1791 | // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to |
| 1792 | // differentiate between the analyzer and the renderer case. |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1793 | CheckParams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1794 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1795 | if (!params_.analyzer.graph_data_output_filename.empty()) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1796 | graph_data_output_file = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1797 | fopen(params_.analyzer.graph_data_output_filename.c_str(), "w"); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 1798 | RTC_CHECK(graph_data_output_file) |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1799 | << "Can't open the file " << params_.analyzer.graph_data_output_filename |
| 1800 | << "!"; |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1801 | } |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1802 | |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1803 | if (!params.logging.rtc_event_log_name.empty()) { |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1804 | send_event_log_ = |
| 1805 | RtcEventLog::Create(clock_, RtcEventLog::EncodingType::Legacy); |
| 1806 | recv_event_log_ = |
| 1807 | RtcEventLog::Create(clock_, RtcEventLog::EncodingType::Legacy); |
| 1808 | std::unique_ptr<RtcEventLogOutputFile> send_output( |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 1809 | rtc::MakeUnique<RtcEventLogOutputFile>( |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1810 | params.logging.rtc_event_log_name + "_send", |
| 1811 | RtcEventLog::kUnlimitedOutput)); |
| 1812 | std::unique_ptr<RtcEventLogOutputFile> recv_output( |
| 1813 | rtc::MakeUnique<RtcEventLogOutputFile>( |
| 1814 | params.logging.rtc_event_log_name + "_recv", |
| 1815 | RtcEventLog::kUnlimitedOutput)); |
| 1816 | bool event_log_started = |
| 1817 | send_event_log_->StartLogging(std::move(send_output), |
| 1818 | RtcEventLog::kImmediateOutput) && |
| 1819 | recv_event_log_->StartLogging(std::move(recv_output), |
| 1820 | RtcEventLog::kImmediateOutput); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1821 | RTC_DCHECK(event_log_started); |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1822 | } else { |
| 1823 | send_event_log_ = RtcEventLog::CreateNull(); |
| 1824 | recv_event_log_ = RtcEventLog::CreateNull(); |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1825 | } |
| 1826 | |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1827 | Call::Config send_call_config(send_event_log_.get()); |
| 1828 | Call::Config recv_call_config(recv_event_log_.get()); |
| 1829 | send_call_config.bitrate_config = params.call.call_bitrate_config; |
| 1830 | recv_call_config.bitrate_config = params.call.call_bitrate_config; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1831 | |
Ilya Nikolaevskiy | a4259f6 | 2017-12-05 13:19:45 +0100 | [diff] [blame] | 1832 | task_queue_.SendTask([this, &send_call_config, &recv_call_config, |
| 1833 | &send_transport, &recv_transport]() { |
| 1834 | CreateCalls(send_call_config, recv_call_config); |
| 1835 | send_transport = CreateSendTransport(); |
| 1836 | recv_transport = CreateReceiveTransport(); |
| 1837 | }); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1838 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1839 | std::string graph_title = params_.analyzer.graph_title; |
| 1840 | if (graph_title.empty()) |
| 1841 | graph_title = VideoQualityTest::GenerateGraphTitle(); |
sprang | c1b57a1 | 2017-02-28 08:50:47 -0800 | [diff] [blame] | 1842 | bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest"); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1843 | analyzer = rtc::MakeUnique<VideoAnalyzer>( |
| 1844 | send_transport.get(), params_.analyzer.test_label, |
ilnik | 2a8c2f5 | 2017-02-15 02:23:28 -0800 | [diff] [blame] | 1845 | params_.analyzer.avg_psnr_threshold, params_.analyzer.avg_ssim_threshold, |
ilnik | 9ae0d76 | 2017-02-15 00:53:12 -0800 | [diff] [blame] | 1846 | is_quick_test_enabled |
| 1847 | ? kFramesSentInQuickTest |
| 1848 | : params_.analyzer.test_durations_secs * params_.video.fps, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1849 | graph_data_output_file, graph_title, |
ilnik | 3dd5ad9 | 2017-02-09 04:58:53 -0800 | [diff] [blame] | 1850 | kVideoSendSsrcs[params_.ss.selected_stream], |
ilnik | 46a0021 | 2017-02-10 09:16:05 -0800 | [diff] [blame] | 1851 | kSendRtxSsrcs[params_.ss.selected_stream], |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 1852 | static_cast<size_t>(params_.ss.selected_stream), params.ss.selected_sl, |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 1853 | params_.video.selected_tl, is_quick_test_enabled, clock_, |
| 1854 | params_.logging.rtp_dump_name); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1855 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1856 | task_queue_.SendTask([&]() { |
| 1857 | analyzer->SetCall(sender_call_.get()); |
| 1858 | analyzer->SetReceiver(receiver_call_->Receiver()); |
| 1859 | send_transport->SetReceiver(analyzer.get()); |
| 1860 | recv_transport->SetReceiver(sender_call_->Receiver()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1861 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1862 | SetupVideo(analyzer.get(), recv_transport.get()); |
| 1863 | SetupThumbnails(analyzer.get(), recv_transport.get()); |
| 1864 | video_receive_configs_[params_.ss.selected_stream].renderer = |
| 1865 | analyzer.get(); |
| 1866 | video_send_config_.pre_encode_callback = analyzer->pre_encode_proxy(); |
| 1867 | RTC_DCHECK(!video_send_config_.post_encode_callback); |
| 1868 | video_send_config_.post_encode_callback = analyzer->encode_timing_proxy(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1869 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1870 | SetupScreenshareOrSVC(); |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 1871 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1872 | CreateFlexfecStreams(); |
| 1873 | CreateVideoStreams(); |
| 1874 | analyzer->SetSendStream(video_send_stream_); |
| 1875 | if (video_receive_streams_.size() == 1) |
| 1876 | analyzer->SetReceiveStream(video_receive_streams_[0]); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1877 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1878 | video_send_stream_->SetSource(analyzer->OutputInterface(), |
| 1879 | degradation_preference_); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1880 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1881 | SetupThumbnailCapturers(params_.call.num_thumbnails); |
| 1882 | for (size_t i = 0; i < thumbnail_send_streams_.size(); ++i) { |
| 1883 | thumbnail_send_streams_[i]->SetSource(thumbnail_capturers_[i].get(), |
| 1884 | degradation_preference_); |
| 1885 | } |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1886 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1887 | CreateCapturer(); |
ivica | c1cc854 | 2015-10-08 03:44:06 -0700 | [diff] [blame] | 1888 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1889 | analyzer->SetSource(video_capturer_.get(), params_.ss.infer_streams); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1890 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1891 | StartEncodedFrameLogs(video_send_stream_); |
| 1892 | StartEncodedFrameLogs(video_receive_streams_[params_.ss.selected_stream]); |
| 1893 | video_send_stream_->Start(); |
| 1894 | for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) |
| 1895 | thumbnail_send_stream->Start(); |
| 1896 | for (VideoReceiveStream* receive_stream : video_receive_streams_) |
| 1897 | receive_stream->Start(); |
| 1898 | for (VideoReceiveStream* thumbnail_receive_stream : |
| 1899 | thumbnail_receive_streams_) |
| 1900 | thumbnail_receive_stream->Start(); |
ilnik | a014cc5 | 2017-03-07 04:21:04 -0800 | [diff] [blame] | 1901 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1902 | analyzer->StartMeasuringCpuProcessTime(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1903 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1904 | video_capturer_->Start(); |
| 1905 | for (std::unique_ptr<test::VideoCapturer>& video_caputurer : |
| 1906 | thumbnail_capturers_) { |
| 1907 | video_caputurer->Start(); |
| 1908 | } |
| 1909 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1910 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1911 | analyzer->Wait(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1912 | |
Ilya Nikolaevskiy | 2c72fe8 | 2017-10-02 13:01:04 +0200 | [diff] [blame] | 1913 | event_log_->StopLogging(); |
| 1914 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1915 | task_queue_.SendTask([&]() { |
| 1916 | for (std::unique_ptr<test::VideoCapturer>& video_caputurer : |
| 1917 | thumbnail_capturers_) |
| 1918 | video_caputurer->Stop(); |
| 1919 | video_capturer_->Stop(); |
| 1920 | for (VideoReceiveStream* thumbnail_receive_stream : |
| 1921 | thumbnail_receive_streams_) |
| 1922 | thumbnail_receive_stream->Stop(); |
| 1923 | for (VideoReceiveStream* receive_stream : video_receive_streams_) |
| 1924 | receive_stream->Stop(); |
| 1925 | for (VideoSendStream* thumbnail_send_stream : thumbnail_send_streams_) |
| 1926 | thumbnail_send_stream->Stop(); |
| 1927 | video_send_stream_->Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1928 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1929 | DestroyStreams(); |
| 1930 | DestroyThumbnailStreams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1931 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1932 | if (graph_data_output_file) |
| 1933 | fclose(graph_data_output_file); |
| 1934 | |
| 1935 | video_capturer_.reset(); |
| 1936 | send_transport.reset(); |
| 1937 | recv_transport.reset(); |
| 1938 | |
| 1939 | DestroyCalls(); |
| 1940 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1943 | void VideoQualityTest::SetupAudio(int send_channel_id, |
| 1944 | int receive_channel_id, |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1945 | Transport* transport, |
| 1946 | AudioReceiveStream** audio_receive_stream) { |
| 1947 | audio_send_config_ = AudioSendStream::Config(transport); |
| 1948 | audio_send_config_.voe_channel_id = send_channel_id; |
| 1949 | audio_send_config_.rtp.ssrc = kAudioSendSsrc; |
| 1950 | |
| 1951 | // Add extension to enable audio send side BWE, and allow audio bit rate |
| 1952 | // adaptation. |
| 1953 | audio_send_config_.rtp.extensions.clear(); |
| 1954 | if (params_.call.send_side_bwe) { |
| 1955 | audio_send_config_.rtp.extensions.push_back( |
| 1956 | webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri, |
| 1957 | test::kTransportSequenceNumberExtensionId)); |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 1958 | audio_send_config_.min_bitrate_bps = kOpusMinBitrateBps; |
| 1959 | audio_send_config_.max_bitrate_bps = kOpusBitrateFbBps; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1960 | } |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 1961 | audio_send_config_.send_codec_spec = |
| 1962 | rtc::Optional<AudioSendStream::Config::SendCodecSpec>( |
| 1963 | {kAudioSendPayloadType, |
| 1964 | {"OPUS", 48000, 2, |
| 1965 | {{"usedtx", (params_.audio.dtx ? "1" : "0")}, |
| 1966 | {"stereo", "1"}}}}); |
Rasmus Brandt | 3102734 | 2017-09-29 13:48:12 +0000 | [diff] [blame] | 1967 | audio_send_config_.encoder_factory = encoder_factory_; |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1968 | audio_send_stream_ = sender_call_->CreateAudioSendStream(audio_send_config_); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1969 | |
| 1970 | AudioReceiveStream::Config audio_config; |
| 1971 | audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc; |
| 1972 | audio_config.rtcp_send_transport = transport; |
| 1973 | audio_config.voe_channel_id = receive_channel_id; |
| 1974 | audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc; |
| 1975 | audio_config.rtp.transport_cc = params_.call.send_side_bwe; |
| 1976 | audio_config.rtp.extensions = audio_send_config_.rtp.extensions; |
Rasmus Brandt | 3102734 | 2017-09-29 13:48:12 +0000 | [diff] [blame] | 1977 | audio_config.decoder_factory = decoder_factory_; |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 1978 | audio_config.decoder_map = {{kAudioSendPayloadType, {"OPUS", 48000, 2}}}; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1979 | if (params_.video.enabled && params_.audio.sync_video) |
| 1980 | audio_config.sync_group = kSyncGroup; |
| 1981 | |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 1982 | *audio_receive_stream = |
| 1983 | receiver_call_->CreateAudioReceiveStream(audio_config); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1986 | void VideoQualityTest::RunWithRenderers(const Params& params) { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1987 | std::unique_ptr<test::LayerFilteringTransport> send_transport; |
| 1988 | std::unique_ptr<test::DirectTransport> recv_transport; |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 1989 | std::unique_ptr<test::FakeAudioDevice> fake_audio_device; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1990 | ::VoiceEngineState voe; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1991 | std::unique_ptr<test::VideoRenderer> local_preview; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1992 | std::vector<std::unique_ptr<test::VideoRenderer>> loopback_renderers; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1993 | AudioReceiveStream* audio_receive_stream = nullptr; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1994 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1995 | task_queue_.SendTask([&]() { |
| 1996 | params_ = params; |
| 1997 | CheckParams(); |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1998 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1999 | // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to |
| 2000 | // match the full stack tests. |
| 2001 | Call::Config call_config(event_log_.get()); |
| 2002 | call_config.bitrate_config = params_.call.call_bitrate_config; |
Niels Möller | 2bf9e73 | 2017-08-14 11:26:16 +0200 | [diff] [blame] | 2003 | |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 2004 | fake_audio_device.reset(new test::FakeAudioDevice( |
| 2005 | test::FakeAudioDevice::CreatePulsedNoiseCapturer(32000, 48000), |
| 2006 | test::FakeAudioDevice::CreateDiscardRenderer(48000), |
| 2007 | 1.f)); |
| 2008 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2009 | rtc::scoped_refptr<webrtc::AudioProcessing> audio_processing( |
| 2010 | webrtc::AudioProcessing::Create()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 2011 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2012 | if (params_.audio.enabled) { |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 2013 | CreateVoiceEngine(&voe, fake_audio_device.get(), audio_processing.get(), |
| 2014 | decoder_factory_); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2015 | AudioState::Config audio_state_config; |
| 2016 | audio_state_config.voice_engine = voe.voice_engine; |
| 2017 | audio_state_config.audio_mixer = AudioMixerImpl::Create(); |
| 2018 | audio_state_config.audio_processing = audio_processing; |
| 2019 | call_config.audio_state = AudioState::Create(audio_state_config); |
Fredrik Solenberg | d319534 | 2017-11-21 20:33:05 +0100 | [diff] [blame] | 2020 | fake_audio_device->RegisterAudioCallback( |
| 2021 | call_config.audio_state->audio_transport()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2022 | } |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 2023 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2024 | CreateCalls(call_config, call_config); |
| 2025 | |
| 2026 | // TODO(minyue): consider if this is a good transport even for audio only |
| 2027 | // calls. |
| 2028 | send_transport = rtc::MakeUnique<test::LayerFilteringTransport>( |
| 2029 | &task_queue_, params.pipe, sender_call_.get(), kPayloadTypeVP8, |
| 2030 | kPayloadTypeVP9, params.video.selected_tl, params_.ss.selected_sl, |
| 2031 | payload_type_map_); |
| 2032 | |
| 2033 | recv_transport = rtc::MakeUnique<test::DirectTransport>( |
| 2034 | &task_queue_, params_.pipe, receiver_call_.get(), payload_type_map_); |
| 2035 | |
| 2036 | // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at |
| 2037 | // least share as much code as possible. That way this test would also match |
| 2038 | // the full stack tests better. |
| 2039 | send_transport->SetReceiver(receiver_call_->Receiver()); |
| 2040 | recv_transport->SetReceiver(sender_call_->Receiver()); |
| 2041 | |
| 2042 | if (params_.video.enabled) { |
| 2043 | // Create video renderers. |
| 2044 | local_preview.reset(test::VideoRenderer::Create( |
| 2045 | "Local Preview", params_.video.width, params_.video.height)); |
| 2046 | |
| 2047 | const size_t selected_stream_id = params_.ss.selected_stream; |
| 2048 | const size_t num_streams = params_.ss.streams.size(); |
| 2049 | |
| 2050 | if (selected_stream_id == num_streams) { |
| 2051 | for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) { |
| 2052 | std::ostringstream oss; |
| 2053 | oss << "Loopback Video - Stream #" << static_cast<int>(stream_id); |
| 2054 | loopback_renderers.emplace_back(test::VideoRenderer::Create( |
| 2055 | oss.str().c_str(), params_.ss.streams[stream_id].width, |
| 2056 | params_.ss.streams[stream_id].height)); |
| 2057 | } |
| 2058 | } else { |
| 2059 | loopback_renderers.emplace_back(test::VideoRenderer::Create( |
| 2060 | "Loopback Video", params_.ss.streams[selected_stream_id].width, |
| 2061 | params_.ss.streams[selected_stream_id].height)); |
| 2062 | } |
| 2063 | |
| 2064 | SetupVideo(send_transport.get(), recv_transport.get()); |
| 2065 | |
| 2066 | video_send_config_.pre_encode_callback = local_preview.get(); |
| 2067 | if (selected_stream_id == num_streams) { |
| 2068 | for (size_t stream_id = 0; stream_id < num_streams; ++stream_id) { |
| 2069 | video_receive_configs_[stream_id].renderer = |
| 2070 | loopback_renderers[stream_id].get(); |
| 2071 | if (params_.audio.enabled && params_.audio.sync_video) |
| 2072 | video_receive_configs_[stream_id].sync_group = kSyncGroup; |
| 2073 | } |
| 2074 | } else { |
| 2075 | video_receive_configs_[selected_stream_id].renderer = |
| 2076 | loopback_renderers.back().get(); |
| 2077 | if (params_.audio.enabled && params_.audio.sync_video) |
| 2078 | video_receive_configs_[selected_stream_id].sync_group = kSyncGroup; |
| 2079 | } |
| 2080 | |
Sergey Silkin | 2248ab6 | 2017-11-09 18:01:13 +0100 | [diff] [blame] | 2081 | SetupScreenshareOrSVC(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2082 | |
| 2083 | CreateFlexfecStreams(); |
| 2084 | CreateVideoStreams(); |
| 2085 | |
| 2086 | CreateCapturer(); |
| 2087 | video_send_stream_->SetSource(video_capturer_.get(), |
| 2088 | degradation_preference_); |
| 2089 | } |
| 2090 | |
| 2091 | if (params_.audio.enabled) { |
| 2092 | SetupAudio(voe.send_channel_id, voe.receive_channel_id, |
| 2093 | send_transport.get(), &audio_receive_stream); |
| 2094 | } |
| 2095 | |
| 2096 | for (VideoReceiveStream* receive_stream : video_receive_streams_) |
| 2097 | StartEncodedFrameLogs(receive_stream); |
| 2098 | StartEncodedFrameLogs(video_send_stream_); |
| 2099 | |
| 2100 | // Start sending and receiving video. |
| 2101 | if (params_.video.enabled) { |
| 2102 | for (VideoReceiveStream* video_receive_stream : video_receive_streams_) |
| 2103 | video_receive_stream->Start(); |
| 2104 | |
| 2105 | video_send_stream_->Start(); |
| 2106 | video_capturer_->Start(); |
| 2107 | } |
| 2108 | |
| 2109 | if (params_.audio.enabled) { |
| 2110 | // Start receiving audio. |
| 2111 | audio_receive_stream->Start(); |
| 2112 | EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id)); |
| 2113 | |
| 2114 | // Start sending audio. |
| 2115 | audio_send_stream_->Start(); |
| 2116 | EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id)); |
| 2117 | } |
| 2118 | }); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 2119 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 2120 | test::PressEnterToContinue(); |
| 2121 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2122 | task_queue_.SendTask([&]() { |
| 2123 | if (params_.audio.enabled) { |
| 2124 | // Stop sending audio. |
| 2125 | EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id)); |
| 2126 | audio_send_stream_->Stop(); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 2127 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2128 | // Stop receiving audio. |
| 2129 | EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id)); |
| 2130 | audio_receive_stream->Stop(); |
| 2131 | sender_call_->DestroyAudioSendStream(audio_send_stream_); |
| 2132 | receiver_call_->DestroyAudioReceiveStream(audio_receive_stream); |
| 2133 | } |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 2134 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2135 | // Stop receiving and sending video. |
| 2136 | if (params_.video.enabled) { |
| 2137 | video_capturer_->Stop(); |
| 2138 | video_send_stream_->Stop(); |
| 2139 | for (FlexfecReceiveStream* flexfec_receive_stream : |
| 2140 | flexfec_receive_streams_) { |
| 2141 | for (VideoReceiveStream* video_receive_stream : |
| 2142 | video_receive_streams_) { |
| 2143 | video_receive_stream->RemoveSecondarySink(flexfec_receive_stream); |
| 2144 | } |
| 2145 | receiver_call_->DestroyFlexfecReceiveStream(flexfec_receive_stream); |
eladalon | c0d481a | 2017-08-02 07:39:07 -0700 | [diff] [blame] | 2146 | } |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2147 | for (VideoReceiveStream* receive_stream : video_receive_streams_) { |
| 2148 | receive_stream->Stop(); |
| 2149 | receiver_call_->DestroyVideoReceiveStream(receive_stream); |
| 2150 | } |
| 2151 | sender_call_->DestroyVideoSendStream(video_send_stream_); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 2152 | } |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 2153 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2154 | video_capturer_.reset(); |
| 2155 | send_transport.reset(); |
| 2156 | recv_transport.reset(); |
sprang | 1168fd4 | 2017-06-21 09:00:17 -0700 | [diff] [blame] | 2157 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2158 | if (params_.audio.enabled) |
| 2159 | DestroyVoiceEngine(&voe); |
| 2160 | |
| 2161 | local_preview.reset(); |
| 2162 | loopback_renderers.clear(); |
| 2163 | |
| 2164 | DestroyCalls(); |
| 2165 | }); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 2168 | void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) { |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 2169 | if (!params_.logging.encoded_frame_base_path.empty()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 2170 | std::ostringstream str; |
| 2171 | str << send_logs_++; |
| 2172 | std::string prefix = |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 2173 | params_.logging.encoded_frame_base_path + "." + str.str() + ".send."; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 2174 | stream->EnableEncodedFrameRecording( |
| 2175 | std::vector<rtc::PlatformFile>( |
| 2176 | {rtc::CreatePlatformFile(prefix + "1.ivf"), |
| 2177 | rtc::CreatePlatformFile(prefix + "2.ivf"), |
| 2178 | rtc::CreatePlatformFile(prefix + "3.ivf")}), |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 2179 | 100000000); |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 2180 | } |
| 2181 | } |
ilnik | cb8c146 | 2017-03-09 09:23:30 -0800 | [diff] [blame] | 2182 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 2183 | void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) { |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 2184 | if (!params_.logging.encoded_frame_base_path.empty()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 2185 | std::ostringstream str; |
| 2186 | str << receive_logs_++; |
| 2187 | std::string path = |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 2188 | params_.logging.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 2189 | stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), |
ilnik | 9843695 | 2017-07-13 00:47:03 -0700 | [diff] [blame] | 2190 | 100000000); |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 2191 | } |
| 2192 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 2193 | } // namespace webrtc |