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