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