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