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