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 | */ |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 10 | #include "webrtc/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 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 20 | #include "webrtc/base/checks.h" |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 21 | #include "webrtc/base/event.h" |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 22 | #include "webrtc/base/format_macros.h" |
nisse | c7fe3c2 | 2016-04-20 03:25:36 -0700 | [diff] [blame] | 23 | #include "webrtc/base/optional.h" |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 24 | #include "webrtc/base/platform_file.h" |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 25 | #include "webrtc/base/timeutils.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 26 | #include "webrtc/call/call.h" |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 27 | #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 28 | #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
aleloi | 10111bc | 2016-11-17 06:48:48 -0800 | [diff] [blame] | 29 | #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 30 | #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 31 | #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 32 | #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" |
| 33 | #include "webrtc/modules/video_coding/codecs/vp8/include/vp8.h" |
| 34 | #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 35 | #include "webrtc/system_wrappers/include/cpu_info.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 36 | #include "webrtc/test/gtest.h" |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 37 | #include "webrtc/test/layer_filtering_transport.h" |
| 38 | #include "webrtc/test/run_loop.h" |
| 39 | #include "webrtc/test/statistics.h" |
| 40 | #include "webrtc/test/testsupport/fileutils.h" |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 41 | #include "webrtc/test/vcm_capturer.h" |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 42 | #include "webrtc/test/video_renderer.h" |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 43 | #include "webrtc/voice_engine/include/voe_base.h" |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 44 | |
| 45 | namespace { |
| 46 | |
| 47 | constexpr int kSendStatsPollingIntervalMs = 1000; |
| 48 | constexpr int kPayloadTypeH264 = 122; |
| 49 | constexpr int kPayloadTypeVP8 = 123; |
| 50 | constexpr int kPayloadTypeVP9 = 124; |
| 51 | constexpr size_t kMaxComparisons = 10; |
| 52 | constexpr char kSyncGroup[] = "av_sync"; |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 53 | constexpr int kOpusMinBitrateBps = 6000; |
| 54 | constexpr int kOpusBitrateFbBps = 32000; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 55 | |
| 56 | struct VoiceEngineState { |
| 57 | VoiceEngineState() |
| 58 | : voice_engine(nullptr), |
| 59 | base(nullptr), |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 60 | send_channel_id(-1), |
| 61 | receive_channel_id(-1) {} |
| 62 | |
| 63 | webrtc::VoiceEngine* voice_engine; |
| 64 | webrtc::VoEBase* base; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 65 | int send_channel_id; |
| 66 | int receive_channel_id; |
| 67 | }; |
| 68 | |
| 69 | void CreateVoiceEngine(VoiceEngineState* voe, |
| 70 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> |
| 71 | decoder_factory) { |
| 72 | voe->voice_engine = webrtc::VoiceEngine::Create(); |
| 73 | voe->base = webrtc::VoEBase::GetInterface(voe->voice_engine); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 74 | EXPECT_EQ(0, voe->base->Init(nullptr, nullptr, decoder_factory)); |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 75 | webrtc::VoEBase::ChannelConfig config; |
| 76 | config.enable_voice_pacing = true; |
| 77 | voe->send_channel_id = voe->base->CreateChannel(config); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 78 | EXPECT_GE(voe->send_channel_id, 0); |
| 79 | voe->receive_channel_id = voe->base->CreateChannel(); |
| 80 | EXPECT_GE(voe->receive_channel_id, 0); |
| 81 | } |
| 82 | |
| 83 | void DestroyVoiceEngine(VoiceEngineState* voe) { |
| 84 | voe->base->DeleteChannel(voe->send_channel_id); |
| 85 | voe->send_channel_id = -1; |
| 86 | voe->base->DeleteChannel(voe->receive_channel_id); |
| 87 | voe->receive_channel_id = -1; |
| 88 | voe->base->Release(); |
| 89 | voe->base = nullptr; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 90 | |
| 91 | webrtc::VoiceEngine::Delete(voe->voice_engine); |
| 92 | voe->voice_engine = nullptr; |
| 93 | } |
| 94 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 95 | class VideoStreamFactory |
| 96 | : public webrtc::VideoEncoderConfig::VideoStreamFactoryInterface { |
| 97 | public: |
| 98 | explicit VideoStreamFactory(const std::vector<webrtc::VideoStream>& streams) |
| 99 | : streams_(streams) {} |
| 100 | |
| 101 | private: |
| 102 | std::vector<webrtc::VideoStream> CreateEncoderStreams( |
| 103 | int width, |
| 104 | int height, |
| 105 | const webrtc::VideoEncoderConfig& encoder_config) override { |
| 106 | return streams_; |
| 107 | } |
| 108 | |
| 109 | std::vector<webrtc::VideoStream> streams_; |
| 110 | }; |
| 111 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 112 | } // namespace |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 113 | |
| 114 | namespace webrtc { |
| 115 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 116 | class VideoAnalyzer : public PacketReceiver, |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 117 | public Transport, |
nisse | 7ade7b3 | 2016-03-23 04:48:10 -0700 | [diff] [blame] | 118 | public rtc::VideoSinkInterface<VideoFrame>, |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 119 | public EncodedFrameObserver { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 120 | public: |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 121 | VideoAnalyzer(test::LayerFilteringTransport* transport, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 122 | const std::string& test_label, |
| 123 | double avg_psnr_threshold, |
| 124 | double avg_ssim_threshold, |
| 125 | int duration_frames, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 126 | FILE* graph_data_output_file, |
| 127 | const std::string& graph_title, |
| 128 | uint32_t ssrc_to_analyze) |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 129 | : transport_(transport), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 130 | receiver_(nullptr), |
| 131 | send_stream_(nullptr), |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 132 | captured_frame_forwarder_(this), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 133 | test_label_(test_label), |
| 134 | graph_data_output_file_(graph_data_output_file), |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 135 | graph_title_(graph_title), |
| 136 | ssrc_to_analyze_(ssrc_to_analyze), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 137 | pre_encode_proxy_(this), |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 138 | encode_timing_proxy_(this), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 139 | frames_to_process_(duration_frames), |
| 140 | frames_recorded_(0), |
| 141 | frames_processed_(0), |
| 142 | dropped_frames_(0), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 143 | dropped_frames_before_first_encode_(0), |
| 144 | dropped_frames_before_rendering_(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 145 | last_render_time_(0), |
| 146 | rtp_timestamp_delta_(0), |
| 147 | avg_psnr_threshold_(avg_psnr_threshold), |
| 148 | avg_ssim_threshold_(avg_ssim_threshold), |
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), |
Peter Boström | dd45eb6 | 2016-01-19 15:22:32 +0100 | [diff] [blame] | 151 | done_(true, false) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 152 | // Create thread pool for CPU-expensive PSNR/SSIM calculations. |
| 153 | |
| 154 | // Try to use about as many threads as cores, but leave kMinCoresLeft alone, |
| 155 | // so that we don't accidentally starve "real" worker threads (codec etc). |
| 156 | // Also, don't allocate more than kMaxComparisonThreads, even if there are |
| 157 | // spare cores. |
| 158 | |
| 159 | uint32_t num_cores = CpuInfo::DetectNumberOfCores(); |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 160 | RTC_DCHECK_GE(num_cores, 1); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 161 | static const uint32_t kMinCoresLeft = 4; |
| 162 | static const uint32_t kMaxComparisonThreads = 8; |
| 163 | |
| 164 | if (num_cores <= kMinCoresLeft) { |
| 165 | num_cores = 1; |
| 166 | } else { |
| 167 | num_cores -= kMinCoresLeft; |
| 168 | num_cores = std::min(num_cores, kMaxComparisonThreads); |
| 169 | } |
| 170 | |
| 171 | for (uint32_t i = 0; i < num_cores; ++i) { |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 172 | rtc::PlatformThread* thread = |
| 173 | new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer"); |
| 174 | thread->Start(); |
| 175 | comparison_thread_pool_.push_back(thread); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 176 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | ~VideoAnalyzer() { |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 180 | for (rtc::PlatformThread* thread : comparison_thread_pool_) { |
| 181 | thread->Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 182 | delete thread; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | virtual void SetReceiver(PacketReceiver* receiver) { receiver_ = receiver; } |
| 187 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 188 | void SetSendStream(VideoSendStream* stream) { |
| 189 | rtc::CritScope lock(&crit_); |
| 190 | RTC_DCHECK(!send_stream_); |
| 191 | send_stream_ = stream; |
| 192 | } |
| 193 | |
| 194 | rtc::VideoSinkInterface<VideoFrame>* InputInterface() { |
| 195 | return &captured_frame_forwarder_; |
| 196 | } |
| 197 | rtc::VideoSourceInterface<VideoFrame>* OutputInterface() { |
| 198 | return &captured_frame_forwarder_; |
| 199 | } |
| 200 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 201 | DeliveryStatus DeliverPacket(MediaType media_type, |
| 202 | const uint8_t* packet, |
| 203 | size_t length, |
| 204 | const PacketTime& packet_time) override { |
Taylor Brandstetter | 433b95a | 2016-03-18 11:41:03 -0700 | [diff] [blame] | 205 | // Ignore timestamps of RTCP packets. They're not synchronized with |
| 206 | // RTP packet timestamps and so they would confuse wrap_handler_. |
| 207 | if (RtpHeaderParser::IsRtcp(packet, length)) { |
| 208 | return receiver_->DeliverPacket(media_type, packet, length, packet_time); |
| 209 | } |
| 210 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 211 | RtpUtility::RtpHeaderParser parser(packet, length); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 212 | RTPHeader header; |
danilchap | f6975f4 | 2015-12-28 10:18:46 -0800 | [diff] [blame] | 213 | parser.Parse(&header); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 214 | { |
| 215 | rtc::CritScope lock(&crit_); |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 216 | int64_t timestamp = |
| 217 | wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_); |
| 218 | recv_times_[timestamp] = |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 219 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
| 220 | } |
| 221 | |
| 222 | return receiver_->DeliverPacket(media_type, packet, length, packet_time); |
| 223 | } |
| 224 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 225 | void MeasuredEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 226 | rtc::CritScope crit(&comparison_lock_); |
| 227 | samples_encode_time_ms_[ntp_time_ms] = encode_time_ms; |
| 228 | } |
| 229 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 230 | void PreEncodeOnFrame(const VideoFrame& video_frame) { |
| 231 | rtc::CritScope lock(&crit_); |
| 232 | if (!first_send_timestamp_ && rtp_timestamp_delta_ == 0) { |
| 233 | while (frames_.front().timestamp() != video_frame.timestamp()) { |
| 234 | ++dropped_frames_before_first_encode_; |
| 235 | frames_.pop_front(); |
| 236 | RTC_CHECK(!frames_.empty()); |
| 237 | } |
| 238 | first_send_timestamp_ = rtc::Optional<uint32_t>(video_frame.timestamp()); |
| 239 | } |
| 240 | } |
| 241 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 242 | bool SendRtp(const uint8_t* packet, |
| 243 | size_t length, |
| 244 | const PacketOptions& options) override { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 245 | RtpUtility::RtpHeaderParser parser(packet, length); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 246 | RTPHeader header; |
danilchap | f6975f4 | 2015-12-28 10:18:46 -0800 | [diff] [blame] | 247 | parser.Parse(&header); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 248 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 249 | int64_t current_time = |
| 250 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
| 251 | bool result = transport_->SendRtp(packet, length, options); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 252 | { |
| 253 | rtc::CritScope lock(&crit_); |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 254 | |
Peter Boström | 81cbd92 | 2016-03-22 12:19:07 +0100 | [diff] [blame] | 255 | if (rtp_timestamp_delta_ == 0) { |
nisse | c7fe3c2 | 2016-04-20 03:25:36 -0700 | [diff] [blame] | 256 | rtp_timestamp_delta_ = header.timestamp - *first_send_timestamp_; |
| 257 | first_send_timestamp_ = rtc::Optional<uint32_t>(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 258 | } |
sprang | 1b3530b | 2016-03-10 01:32:53 -0800 | [diff] [blame] | 259 | int64_t timestamp = |
| 260 | wrap_handler_.Unwrap(header.timestamp - rtp_timestamp_delta_); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 261 | send_times_[timestamp] = current_time; |
| 262 | if (!transport_->DiscardedLastPacket() && |
| 263 | header.ssrc == ssrc_to_analyze_) { |
| 264 | encoded_frame_sizes_[timestamp] += |
| 265 | length - (header.headerLength + header.paddingLength); |
| 266 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 267 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 268 | return result; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | bool SendRtcp(const uint8_t* packet, size_t length) override { |
| 272 | return transport_->SendRtcp(packet, length); |
| 273 | } |
| 274 | |
| 275 | void EncodedFrameCallback(const EncodedFrame& frame) override { |
| 276 | rtc::CritScope lock(&comparison_lock_); |
| 277 | if (frames_recorded_ < frames_to_process_) |
| 278 | encoded_frame_size_.AddSample(frame.length_); |
| 279 | } |
| 280 | |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 281 | void OnFrame(const VideoFrame& video_frame) override { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 282 | int64_t render_time_ms = |
| 283 | Clock::GetRealTimeClock()->CurrentNtpInMilliseconds(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 284 | |
| 285 | rtc::CritScope lock(&crit_); |
Taylor Brandstetter | 433b95a | 2016-03-18 11:41:03 -0700 | [diff] [blame] | 286 | int64_t send_timestamp = |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 287 | wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 288 | |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 289 | while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) { |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 290 | if (!last_rendered_frame_) { |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 291 | // No previous frame rendered, this one was dropped after sending but |
| 292 | // before rendering. |
| 293 | ++dropped_frames_before_rendering_; |
| 294 | frames_.pop_front(); |
| 295 | RTC_CHECK(!frames_.empty()); |
| 296 | continue; |
| 297 | } |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 298 | AddFrameComparison(frames_.front(), *last_rendered_frame_, true, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 299 | render_time_ms); |
| 300 | frames_.pop_front(); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 301 | RTC_DCHECK(!frames_.empty()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | VideoFrame reference_frame = frames_.front(); |
| 305 | frames_.pop_front(); |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 306 | int64_t reference_timestamp = |
| 307 | wrap_handler_.Unwrap(reference_frame.timestamp()); |
| 308 | if (send_timestamp == reference_timestamp - 1) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 309 | // TODO(ivica): Make this work for > 2 streams. |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 310 | // Look at RTPSender::BuildRTPHeader. |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 311 | ++send_timestamp; |
| 312 | } |
sprang | 16daaa5 | 2016-03-09 01:30:24 -0800 | [diff] [blame] | 313 | ASSERT_EQ(reference_timestamp, send_timestamp); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 314 | |
| 315 | AddFrameComparison(reference_frame, video_frame, false, render_time_ms); |
| 316 | |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 317 | last_rendered_frame_ = rtc::Optional<VideoFrame>(video_frame); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 318 | } |
| 319 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 320 | void Wait() { |
| 321 | // Frame comparisons can be very expensive. Wait for test to be done, but |
| 322 | // at time-out check if frames_processed is going up. If so, give it more |
| 323 | // time, otherwise fail. Hopefully this will reduce test flakiness. |
| 324 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 325 | stats_polling_thread_.Start(); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 326 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 327 | int last_frames_processed = -1; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 328 | int iteration = 0; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 329 | while (!done_.Wait(VideoQualityTest::kDefaultTimeoutMs)) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 330 | int frames_processed; |
| 331 | { |
| 332 | rtc::CritScope crit(&comparison_lock_); |
| 333 | frames_processed = frames_processed_; |
| 334 | } |
| 335 | |
| 336 | // Print some output so test infrastructure won't think we've crashed. |
| 337 | const char* kKeepAliveMessages[3] = { |
| 338 | "Uh, I'm-I'm not quite dead, sir.", |
| 339 | "Uh, I-I think uh, I could pull through, sir.", |
| 340 | "Actually, I think I'm all right to come with you--"}; |
| 341 | printf("- %s\n", kKeepAliveMessages[iteration++ % 3]); |
| 342 | |
| 343 | if (last_frames_processed == -1) { |
| 344 | last_frames_processed = frames_processed; |
| 345 | continue; |
| 346 | } |
Peter Boström | dd45eb6 | 2016-01-19 15:22:32 +0100 | [diff] [blame] | 347 | if (frames_processed == last_frames_processed) { |
| 348 | EXPECT_GT(frames_processed, last_frames_processed) |
| 349 | << "Analyzer stalled while waiting for test to finish."; |
| 350 | done_.Set(); |
| 351 | break; |
| 352 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 353 | last_frames_processed = frames_processed; |
| 354 | } |
| 355 | |
| 356 | if (iteration > 0) |
| 357 | printf("- Farewell, sweet Concorde!\n"); |
| 358 | |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 359 | stats_polling_thread_.Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 360 | } |
| 361 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 362 | rtc::VideoSinkInterface<VideoFrame>* pre_encode_proxy() { |
| 363 | return &pre_encode_proxy_; |
| 364 | } |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 365 | EncodedFrameObserver* encode_timing_proxy() { return &encode_timing_proxy_; } |
| 366 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 367 | test::LayerFilteringTransport* const transport_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 368 | PacketReceiver* receiver_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 369 | |
| 370 | private: |
| 371 | struct FrameComparison { |
| 372 | FrameComparison() |
| 373 | : dropped(false), |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 374 | input_time_ms(0), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 375 | send_time_ms(0), |
| 376 | recv_time_ms(0), |
| 377 | render_time_ms(0), |
| 378 | encoded_frame_size(0) {} |
| 379 | |
| 380 | FrameComparison(const VideoFrame& reference, |
| 381 | const VideoFrame& render, |
| 382 | bool dropped, |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 383 | int64_t input_time_ms, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 384 | int64_t send_time_ms, |
| 385 | int64_t recv_time_ms, |
| 386 | int64_t render_time_ms, |
| 387 | size_t encoded_frame_size) |
| 388 | : reference(reference), |
| 389 | render(render), |
| 390 | dropped(dropped), |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 391 | input_time_ms(input_time_ms), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 392 | send_time_ms(send_time_ms), |
| 393 | recv_time_ms(recv_time_ms), |
| 394 | render_time_ms(render_time_ms), |
| 395 | encoded_frame_size(encoded_frame_size) {} |
| 396 | |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 397 | FrameComparison(bool dropped, |
| 398 | int64_t input_time_ms, |
| 399 | int64_t send_time_ms, |
| 400 | int64_t recv_time_ms, |
| 401 | int64_t render_time_ms, |
| 402 | size_t encoded_frame_size) |
| 403 | : dropped(dropped), |
| 404 | input_time_ms(input_time_ms), |
| 405 | send_time_ms(send_time_ms), |
| 406 | recv_time_ms(recv_time_ms), |
| 407 | render_time_ms(render_time_ms), |
| 408 | encoded_frame_size(encoded_frame_size) {} |
| 409 | |
| 410 | rtc::Optional<VideoFrame> reference; |
| 411 | rtc::Optional<VideoFrame> render; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 412 | bool dropped; |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 413 | int64_t input_time_ms; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 414 | int64_t send_time_ms; |
| 415 | int64_t recv_time_ms; |
| 416 | int64_t render_time_ms; |
| 417 | size_t encoded_frame_size; |
| 418 | }; |
| 419 | |
| 420 | struct Sample { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 421 | Sample(int dropped, |
| 422 | int64_t input_time_ms, |
| 423 | int64_t send_time_ms, |
| 424 | int64_t recv_time_ms, |
| 425 | int64_t render_time_ms, |
| 426 | size_t encoded_frame_size, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 427 | double psnr, |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 428 | double ssim) |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 429 | : dropped(dropped), |
| 430 | input_time_ms(input_time_ms), |
| 431 | send_time_ms(send_time_ms), |
| 432 | recv_time_ms(recv_time_ms), |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 433 | render_time_ms(render_time_ms), |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 434 | encoded_frame_size(encoded_frame_size), |
| 435 | psnr(psnr), |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 436 | ssim(ssim) {} |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 437 | |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 438 | int dropped; |
| 439 | int64_t input_time_ms; |
| 440 | int64_t send_time_ms; |
| 441 | int64_t recv_time_ms; |
| 442 | int64_t render_time_ms; |
| 443 | size_t encoded_frame_size; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 444 | double psnr; |
| 445 | double ssim; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 446 | }; |
| 447 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 448 | // This class receives the send-side OnEncodeTiming and is provided to not |
| 449 | // conflict with the receiver-side pre_decode_callback. |
| 450 | class OnEncodeTimingProxy : public EncodedFrameObserver { |
| 451 | public: |
| 452 | explicit OnEncodeTimingProxy(VideoAnalyzer* parent) : parent_(parent) {} |
| 453 | |
| 454 | void OnEncodeTiming(int64_t ntp_time_ms, int encode_time_ms) override { |
| 455 | parent_->MeasuredEncodeTiming(ntp_time_ms, encode_time_ms); |
| 456 | } |
| 457 | void EncodedFrameCallback(const EncodedFrame& frame) override {} |
| 458 | |
| 459 | private: |
| 460 | VideoAnalyzer* const parent_; |
| 461 | }; |
| 462 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 463 | // This class receives the send-side OnFrame callback and is provided to not |
| 464 | // conflict with the receiver-side renderer callback. |
| 465 | class PreEncodeProxy : public rtc::VideoSinkInterface<VideoFrame> { |
| 466 | public: |
| 467 | explicit PreEncodeProxy(VideoAnalyzer* parent) : parent_(parent) {} |
| 468 | |
| 469 | void OnFrame(const VideoFrame& video_frame) override { |
| 470 | parent_->PreEncodeOnFrame(video_frame); |
| 471 | } |
| 472 | |
| 473 | private: |
| 474 | VideoAnalyzer* const parent_; |
| 475 | }; |
| 476 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 477 | void AddFrameComparison(const VideoFrame& reference, |
| 478 | const VideoFrame& render, |
| 479 | bool dropped, |
| 480 | int64_t render_time_ms) |
| 481 | EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 482 | int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp()); |
| 483 | int64_t send_time_ms = send_times_[reference_timestamp]; |
| 484 | send_times_.erase(reference_timestamp); |
| 485 | int64_t recv_time_ms = recv_times_[reference_timestamp]; |
| 486 | recv_times_.erase(reference_timestamp); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 487 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 488 | // TODO(ivica): Make this work for > 2 streams. |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 489 | auto it = encoded_frame_sizes_.find(reference_timestamp); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 490 | if (it == encoded_frame_sizes_.end()) |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 491 | it = encoded_frame_sizes_.find(reference_timestamp - 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 492 | size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second; |
| 493 | if (it != encoded_frame_sizes_.end()) |
| 494 | encoded_frame_sizes_.erase(it); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 495 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 496 | rtc::CritScope crit(&comparison_lock_); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 497 | if (comparisons_.size() < kMaxComparisons) { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 498 | comparisons_.push_back(FrameComparison(reference, render, dropped, |
| 499 | reference.ntp_time_ms(), |
| 500 | send_time_ms, recv_time_ms, |
| 501 | render_time_ms, encoded_size)); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 502 | } else { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 503 | comparisons_.push_back(FrameComparison(dropped, |
| 504 | reference.ntp_time_ms(), |
| 505 | send_time_ms, recv_time_ms, |
| 506 | render_time_ms, encoded_size)); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 507 | } |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 508 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static bool PollStatsThread(void* obj) { |
| 512 | return static_cast<VideoAnalyzer*>(obj)->PollStats(); |
| 513 | } |
| 514 | |
| 515 | bool PollStats() { |
Peter Boström | dd45eb6 | 2016-01-19 15:22:32 +0100 | [diff] [blame] | 516 | if (done_.Wait(kSendStatsPollingIntervalMs)) |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 517 | return false; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 518 | |
| 519 | VideoSendStream::Stats stats = send_stream_->GetStats(); |
| 520 | |
| 521 | rtc::CritScope crit(&comparison_lock_); |
Peter Boström | b1eaa8d | 2016-02-23 17:30:49 +0100 | [diff] [blame] | 522 | // It's not certain that we yet have estimates for any of these stats. Check |
| 523 | // that they are positive before mixing them in. |
| 524 | if (stats.encode_frame_rate > 0) |
| 525 | encode_frame_rate_.AddSample(stats.encode_frame_rate); |
| 526 | if (stats.avg_encode_time_ms > 0) |
| 527 | encode_time_ms.AddSample(stats.avg_encode_time_ms); |
| 528 | if (stats.encode_usage_percent > 0) |
| 529 | encode_usage_percent.AddSample(stats.encode_usage_percent); |
| 530 | if (stats.media_bitrate_bps > 0) |
| 531 | media_bitrate_bps.AddSample(stats.media_bitrate_bps); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 532 | |
| 533 | return true; |
| 534 | } |
| 535 | |
| 536 | static bool FrameComparisonThread(void* obj) { |
| 537 | return static_cast<VideoAnalyzer*>(obj)->CompareFrames(); |
| 538 | } |
| 539 | |
| 540 | bool CompareFrames() { |
| 541 | if (AllFramesRecorded()) |
| 542 | return false; |
| 543 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 544 | FrameComparison comparison; |
| 545 | |
| 546 | if (!PopComparison(&comparison)) { |
| 547 | // Wait until new comparison task is available, or test is done. |
| 548 | // If done, wake up remaining threads waiting. |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 549 | comparison_available_event_.Wait(1000); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 550 | if (AllFramesRecorded()) { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 551 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 552 | return false; |
| 553 | } |
| 554 | return true; // Try again. |
| 555 | } |
| 556 | |
| 557 | PerformFrameComparison(comparison); |
| 558 | |
| 559 | if (FrameProcessed()) { |
| 560 | PrintResults(); |
| 561 | if (graph_data_output_file_) |
| 562 | PrintSamplesToFile(); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 563 | done_.Set(); |
| 564 | comparison_available_event_.Set(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 565 | return false; |
| 566 | } |
| 567 | |
| 568 | return true; |
| 569 | } |
| 570 | |
| 571 | bool PopComparison(FrameComparison* comparison) { |
| 572 | rtc::CritScope crit(&comparison_lock_); |
| 573 | // If AllFramesRecorded() is true, it means we have already popped |
| 574 | // frames_to_process_ frames from comparisons_, so there is no more work |
| 575 | // for this thread to be done. frames_processed_ might still be lower if |
| 576 | // all comparisons are not done, but those frames are currently being |
| 577 | // worked on by other threads. |
| 578 | if (comparisons_.empty() || AllFramesRecorded()) |
| 579 | return false; |
| 580 | |
| 581 | *comparison = comparisons_.front(); |
| 582 | comparisons_.pop_front(); |
| 583 | |
| 584 | FrameRecorded(); |
| 585 | return true; |
| 586 | } |
| 587 | |
| 588 | // Increment counter for number of frames received for comparison. |
| 589 | void FrameRecorded() { |
| 590 | rtc::CritScope crit(&comparison_lock_); |
| 591 | ++frames_recorded_; |
| 592 | } |
| 593 | |
| 594 | // Returns true if all frames to be compared have been taken from the queue. |
| 595 | bool AllFramesRecorded() { |
| 596 | rtc::CritScope crit(&comparison_lock_); |
| 597 | assert(frames_recorded_ <= frames_to_process_); |
| 598 | return frames_recorded_ == frames_to_process_; |
| 599 | } |
| 600 | |
| 601 | // Increase count of number of frames processed. Returns true if this was the |
| 602 | // last frame to be processed. |
| 603 | bool FrameProcessed() { |
| 604 | rtc::CritScope crit(&comparison_lock_); |
| 605 | ++frames_processed_; |
| 606 | assert(frames_processed_ <= frames_to_process_); |
| 607 | return frames_processed_ == frames_to_process_; |
| 608 | } |
| 609 | |
| 610 | void PrintResults() { |
| 611 | rtc::CritScope crit(&comparison_lock_); |
| 612 | PrintResult("psnr", psnr_, " dB"); |
tnakamura | 3123cbc | 2016-02-10 11:21:51 -0800 | [diff] [blame] | 613 | PrintResult("ssim", ssim_, " score"); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 614 | PrintResult("sender_time", sender_time_, " ms"); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 615 | PrintResult("receiver_time", receiver_time_, " ms"); |
| 616 | PrintResult("total_delay_incl_network", end_to_end_, " ms"); |
| 617 | PrintResult("time_between_rendered_frames", rendered_delta_, " ms"); |
| 618 | PrintResult("encoded_frame_size", encoded_frame_size_, " bytes"); |
| 619 | PrintResult("encode_frame_rate", encode_frame_rate_, " fps"); |
| 620 | PrintResult("encode_time", encode_time_ms, " ms"); |
| 621 | PrintResult("encode_usage_percent", encode_usage_percent, " percent"); |
| 622 | PrintResult("media_bitrate", media_bitrate_bps, " bps"); |
| 623 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 624 | printf("RESULT dropped_frames: %s = %d frames\n", test_label_.c_str(), |
| 625 | dropped_frames_); |
| 626 | printf("RESULT dropped_frames_before_first_encode: %s = %d frames\n", |
| 627 | test_label_.c_str(), dropped_frames_before_first_encode_); |
| 628 | printf("RESULT dropped_frames_before_rendering: %s = %d frames\n", |
| 629 | test_label_.c_str(), dropped_frames_before_rendering_); |
| 630 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 631 | EXPECT_GT(psnr_.Mean(), avg_psnr_threshold_); |
| 632 | EXPECT_GT(ssim_.Mean(), avg_ssim_threshold_); |
| 633 | } |
| 634 | |
| 635 | void PerformFrameComparison(const FrameComparison& comparison) { |
| 636 | // Perform expensive psnr and ssim calculations while not holding lock. |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 637 | double psnr = -1.0; |
| 638 | double ssim = -1.0; |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 639 | if (comparison.reference) { |
| 640 | psnr = I420PSNR(&*comparison.reference, &*comparison.render); |
| 641 | ssim = I420SSIM(&*comparison.reference, &*comparison.render); |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 642 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 643 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 644 | rtc::CritScope crit(&comparison_lock_); |
| 645 | if (graph_data_output_file_) { |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 646 | samples_.push_back(Sample( |
| 647 | comparison.dropped, comparison.input_time_ms, comparison.send_time_ms, |
| 648 | comparison.recv_time_ms, comparison.render_time_ms, |
| 649 | comparison.encoded_frame_size, psnr, ssim)); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 650 | } |
stefan | b179767 | 2016-08-11 07:00:57 -0700 | [diff] [blame] | 651 | if (psnr >= 0.0) |
| 652 | psnr_.AddSample(psnr); |
| 653 | if (ssim >= 0.0) |
| 654 | ssim_.AddSample(ssim); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 655 | |
| 656 | if (comparison.dropped) { |
| 657 | ++dropped_frames_; |
| 658 | return; |
| 659 | } |
| 660 | if (last_render_time_ != 0) |
| 661 | rendered_delta_.AddSample(comparison.render_time_ms - last_render_time_); |
| 662 | last_render_time_ = comparison.render_time_ms; |
| 663 | |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 664 | sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 665 | receiver_time_.AddSample(comparison.render_time_ms - |
| 666 | comparison.recv_time_ms); |
nisse | df2ceb8 | 2016-12-15 06:29:53 -0800 | [diff] [blame^] | 667 | end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 668 | encoded_frame_size_.AddSample(comparison.encoded_frame_size); |
| 669 | } |
| 670 | |
| 671 | void PrintResult(const char* result_type, |
| 672 | test::Statistics stats, |
| 673 | const char* unit) { |
| 674 | printf("RESULT %s: %s = {%f, %f}%s\n", |
| 675 | result_type, |
| 676 | test_label_.c_str(), |
| 677 | stats.Mean(), |
| 678 | stats.StandardDeviation(), |
| 679 | unit); |
| 680 | } |
| 681 | |
| 682 | void PrintSamplesToFile(void) { |
| 683 | FILE* out = graph_data_output_file_; |
| 684 | rtc::CritScope crit(&comparison_lock_); |
| 685 | std::sort(samples_.begin(), samples_.end(), |
| 686 | [](const Sample& A, const Sample& B) -> bool { |
| 687 | return A.input_time_ms < B.input_time_ms; |
| 688 | }); |
| 689 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 690 | fprintf(out, "%s\n", graph_title_.c_str()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 691 | fprintf(out, "%" PRIuS "\n", samples_.size()); |
| 692 | fprintf(out, |
| 693 | "dropped " |
| 694 | "input_time_ms " |
| 695 | "send_time_ms " |
| 696 | "recv_time_ms " |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 697 | "render_time_ms " |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 698 | "encoded_frame_size " |
| 699 | "psnr " |
| 700 | "ssim " |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 701 | "encode_time_ms\n"); |
| 702 | int missing_encode_time_samples = 0; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 703 | for (const Sample& sample : samples_) { |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 704 | auto it = samples_encode_time_ms_.find(sample.input_time_ms); |
| 705 | int encode_time_ms; |
| 706 | if (it != samples_encode_time_ms_.end()) { |
| 707 | encode_time_ms = it->second; |
| 708 | } else { |
| 709 | ++missing_encode_time_samples; |
| 710 | encode_time_ms = -1; |
| 711 | } |
| 712 | fprintf(out, "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRIuS |
| 713 | " %lf %lf %d\n", |
| 714 | sample.dropped, sample.input_time_ms, sample.send_time_ms, |
| 715 | sample.recv_time_ms, sample.render_time_ms, |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 716 | sample.encoded_frame_size, sample.psnr, sample.ssim, |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 717 | encode_time_ms); |
| 718 | } |
| 719 | if (missing_encode_time_samples) { |
| 720 | fprintf(stderr, |
| 721 | "Warning: Missing encode_time_ms samples for %d frame(s).\n", |
| 722 | missing_encode_time_samples); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 726 | // Implements VideoSinkInterface to receive captured frames from a |
| 727 | // FrameGeneratorCapturer. Implements VideoSourceInterface to be able to act |
| 728 | // as a source to VideoSendStream. |
| 729 | // It forwards all input frames to the VideoAnalyzer for later comparison and |
| 730 | // forwards the captured frames to the VideoSendStream. |
| 731 | class CapturedFrameForwarder : public rtc::VideoSinkInterface<VideoFrame>, |
| 732 | public rtc::VideoSourceInterface<VideoFrame> { |
| 733 | public: |
| 734 | explicit CapturedFrameForwarder(VideoAnalyzer* analyzer) |
| 735 | : analyzer_(analyzer), send_stream_input_(nullptr) {} |
| 736 | |
| 737 | private: |
| 738 | void OnFrame(const VideoFrame& video_frame) override { |
| 739 | VideoFrame copy = video_frame; |
| 740 | copy.set_timestamp(copy.ntp_time_ms() * 90); |
| 741 | |
| 742 | analyzer_->AddCapturedFrameForComparison(video_frame); |
| 743 | rtc::CritScope lock(&crit_); |
| 744 | if (send_stream_input_) |
| 745 | send_stream_input_->OnFrame(video_frame); |
| 746 | } |
| 747 | |
| 748 | // Called when |send_stream_.SetSource()| is called. |
| 749 | void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
| 750 | const rtc::VideoSinkWants& wants) override { |
| 751 | rtc::CritScope lock(&crit_); |
| 752 | RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink); |
| 753 | send_stream_input_ = sink; |
| 754 | } |
| 755 | |
| 756 | // Called by |send_stream_| when |send_stream_.SetSource()| is called. |
| 757 | void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override { |
| 758 | rtc::CritScope lock(&crit_); |
| 759 | RTC_DCHECK(sink == send_stream_input_); |
| 760 | send_stream_input_ = nullptr; |
| 761 | } |
| 762 | |
| 763 | VideoAnalyzer* const analyzer_; |
| 764 | rtc::CriticalSection crit_; |
| 765 | rtc::VideoSinkInterface<VideoFrame>* send_stream_input_ GUARDED_BY(crit_); |
| 766 | }; |
| 767 | |
| 768 | void AddCapturedFrameForComparison(const VideoFrame& video_frame) { |
| 769 | rtc::CritScope lock(&crit_); |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 770 | RTC_DCHECK_EQ(0, video_frame.timestamp()); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 771 | // Frames from the capturer does not have a rtp timestamp. Create one so it |
| 772 | // can be used for comparison. |
| 773 | VideoFrame copy = video_frame; |
| 774 | copy.set_timestamp(copy.ntp_time_ms() * 90); |
| 775 | frames_.push_back(copy); |
| 776 | } |
| 777 | |
| 778 | VideoSendStream* send_stream_; |
| 779 | CapturedFrameForwarder captured_frame_forwarder_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 780 | const std::string test_label_; |
| 781 | FILE* const graph_data_output_file_; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 782 | const std::string graph_title_; |
| 783 | const uint32_t ssrc_to_analyze_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 784 | PreEncodeProxy pre_encode_proxy_; |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 785 | OnEncodeTimingProxy encode_timing_proxy_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 786 | std::vector<Sample> samples_ GUARDED_BY(comparison_lock_); |
ivica | 8d15bd6 | 2015-10-07 02:43:12 -0700 | [diff] [blame] | 787 | std::map<int64_t, int> samples_encode_time_ms_ GUARDED_BY(comparison_lock_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 788 | test::Statistics sender_time_ GUARDED_BY(comparison_lock_); |
| 789 | test::Statistics receiver_time_ GUARDED_BY(comparison_lock_); |
| 790 | test::Statistics psnr_ GUARDED_BY(comparison_lock_); |
| 791 | test::Statistics ssim_ GUARDED_BY(comparison_lock_); |
| 792 | test::Statistics end_to_end_ GUARDED_BY(comparison_lock_); |
| 793 | test::Statistics rendered_delta_ GUARDED_BY(comparison_lock_); |
| 794 | test::Statistics encoded_frame_size_ GUARDED_BY(comparison_lock_); |
| 795 | test::Statistics encode_frame_rate_ GUARDED_BY(comparison_lock_); |
| 796 | test::Statistics encode_time_ms GUARDED_BY(comparison_lock_); |
| 797 | test::Statistics encode_usage_percent GUARDED_BY(comparison_lock_); |
| 798 | test::Statistics media_bitrate_bps GUARDED_BY(comparison_lock_); |
| 799 | |
| 800 | const int frames_to_process_; |
| 801 | int frames_recorded_; |
| 802 | int frames_processed_; |
| 803 | int dropped_frames_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 804 | int dropped_frames_before_first_encode_; |
| 805 | int dropped_frames_before_rendering_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 806 | int64_t last_render_time_; |
| 807 | uint32_t rtp_timestamp_delta_; |
| 808 | |
| 809 | rtc::CriticalSection crit_; |
| 810 | std::deque<VideoFrame> frames_ GUARDED_BY(crit_); |
nisse | 97f0b93 | 2016-05-26 09:44:40 -0700 | [diff] [blame] | 811 | rtc::Optional<VideoFrame> last_rendered_frame_ GUARDED_BY(crit_); |
sprang | e1f2f1f | 2016-02-01 02:04:52 -0800 | [diff] [blame] | 812 | rtc::TimestampWrapAroundHandler wrap_handler_ GUARDED_BY(crit_); |
| 813 | std::map<int64_t, int64_t> send_times_ GUARDED_BY(crit_); |
| 814 | std::map<int64_t, int64_t> recv_times_ GUARDED_BY(crit_); |
| 815 | std::map<int64_t, size_t> encoded_frame_sizes_ GUARDED_BY(crit_); |
nisse | c7fe3c2 | 2016-04-20 03:25:36 -0700 | [diff] [blame] | 816 | rtc::Optional<uint32_t> first_send_timestamp_ GUARDED_BY(crit_); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 817 | const double avg_psnr_threshold_; |
| 818 | const double avg_ssim_threshold_; |
| 819 | |
| 820 | rtc::CriticalSection comparison_lock_; |
Peter Boström | 8c38e8b | 2015-11-26 17:45:47 +0100 | [diff] [blame] | 821 | std::vector<rtc::PlatformThread*> comparison_thread_pool_; |
| 822 | rtc::PlatformThread stats_polling_thread_; |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 823 | rtc::Event comparison_available_event_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 824 | std::deque<FrameComparison> comparisons_ GUARDED_BY(comparison_lock_); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 825 | rtc::Event done_; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 826 | }; |
| 827 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 828 | VideoQualityTest::VideoQualityTest() |
| 829 | : clock_(Clock::GetRealTimeClock()), receive_logs_(0), send_logs_(0) {} |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 830 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 831 | VideoQualityTest::Params::Params() |
| 832 | : call({false, Call::Config::BitrateConfig()}), |
| 833 | video({false, 640, 480, 30, 50, 800, 800, false, "VP8", 1, -1, 0, false, |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 834 | false, "", ""}), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 835 | audio({false, false}), |
| 836 | screenshare({false, 10, 0}), |
| 837 | analyzer({"", 0.0, 0.0, 0, "", ""}), |
| 838 | pipe(), |
| 839 | logs(false), |
| 840 | ss({std::vector<VideoStream>(), 0, 0, -1, std::vector<SpatialLayer>()}) {} |
| 841 | |
| 842 | VideoQualityTest::Params::~Params() = default; |
| 843 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 844 | void VideoQualityTest::TestBody() {} |
| 845 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 846 | std::string VideoQualityTest::GenerateGraphTitle() const { |
| 847 | std::stringstream ss; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 848 | ss << params_.video.codec; |
| 849 | ss << " (" << params_.video.target_bitrate_bps / 1000 << "kbps"; |
| 850 | ss << ", " << params_.video.fps << " FPS"; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 851 | if (params_.screenshare.scroll_duration) |
| 852 | ss << ", " << params_.screenshare.scroll_duration << "s scroll"; |
| 853 | if (params_.ss.streams.size() > 1) |
| 854 | ss << ", Stream #" << params_.ss.selected_stream; |
| 855 | if (params_.ss.num_spatial_layers > 1) |
| 856 | ss << ", Layer #" << params_.ss.selected_sl; |
| 857 | ss << ")"; |
| 858 | return ss.str(); |
| 859 | } |
| 860 | |
| 861 | void VideoQualityTest::CheckParams() { |
| 862 | // Add a default stream in none specified. |
| 863 | if (params_.ss.streams.empty()) |
| 864 | params_.ss.streams.push_back(VideoQualityTest::DefaultVideoStream(params_)); |
| 865 | if (params_.ss.num_spatial_layers == 0) |
| 866 | params_.ss.num_spatial_layers = 1; |
| 867 | |
| 868 | if (params_.pipe.loss_percent != 0 || |
| 869 | params_.pipe.queue_length_packets != 0) { |
| 870 | // Since LayerFilteringTransport changes the sequence numbers, we can't |
| 871 | // use that feature with pack loss, since the NACK request would end up |
| 872 | // retransmitting the wrong packets. |
| 873 | RTC_CHECK(params_.ss.selected_sl == -1 || |
sprang | ee37de3 | 2015-11-23 06:10:23 -0800 | [diff] [blame] | 874 | params_.ss.selected_sl == params_.ss.num_spatial_layers - 1); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 875 | RTC_CHECK(params_.video.selected_tl == -1 || |
| 876 | params_.video.selected_tl == |
| 877 | params_.video.num_temporal_layers - 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | // TODO(ivica): Should max_bitrate_bps == -1 represent inf max bitrate, as it |
| 881 | // does in some parts of the code? |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 882 | RTC_CHECK_GE(params_.video.max_bitrate_bps, params_.video.target_bitrate_bps); |
| 883 | RTC_CHECK_GE(params_.video.target_bitrate_bps, params_.video.min_bitrate_bps); |
| 884 | RTC_CHECK_LT(params_.video.selected_tl, params_.video.num_temporal_layers); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 885 | RTC_CHECK_LT(params_.ss.selected_stream, params_.ss.streams.size()); |
| 886 | for (const VideoStream& stream : params_.ss.streams) { |
| 887 | RTC_CHECK_GE(stream.min_bitrate_bps, 0); |
| 888 | RTC_CHECK_GE(stream.target_bitrate_bps, stream.min_bitrate_bps); |
| 889 | RTC_CHECK_GE(stream.max_bitrate_bps, stream.target_bitrate_bps); |
kwiberg | 352444f | 2016-11-28 15:58:53 -0800 | [diff] [blame] | 890 | RTC_CHECK_EQ(stream.temporal_layer_thresholds_bps.size(), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 891 | params_.video.num_temporal_layers - 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 892 | } |
| 893 | // TODO(ivica): Should we check if the sum of all streams/layers is equal to |
| 894 | // the total bitrate? We anyway have to update them in the case bitrate |
| 895 | // estimator changes the total bitrates. |
| 896 | RTC_CHECK_GE(params_.ss.num_spatial_layers, 1); |
| 897 | RTC_CHECK_LE(params_.ss.selected_sl, params_.ss.num_spatial_layers); |
| 898 | RTC_CHECK(params_.ss.spatial_layers.empty() || |
| 899 | params_.ss.spatial_layers.size() == |
| 900 | static_cast<size_t>(params_.ss.num_spatial_layers)); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 901 | if (params_.video.codec == "VP8") { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 902 | RTC_CHECK_EQ(params_.ss.num_spatial_layers, 1); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 903 | } else if (params_.video.codec == "VP9") { |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 904 | RTC_CHECK_EQ(params_.ss.streams.size(), 1); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 905 | } |
| 906 | } |
| 907 | |
| 908 | // Static. |
| 909 | std::vector<int> VideoQualityTest::ParseCSV(const std::string& str) { |
| 910 | // Parse comma separated nonnegative integers, where some elements may be |
| 911 | // empty. The empty values are replaced with -1. |
| 912 | // E.g. "10,-20,,30,40" --> {10, 20, -1, 30,40} |
| 913 | // E.g. ",,10,,20," --> {-1, -1, 10, -1, 20, -1} |
| 914 | std::vector<int> result; |
| 915 | if (str.empty()) |
| 916 | return result; |
| 917 | |
| 918 | const char* p = str.c_str(); |
| 919 | int value = -1; |
| 920 | int pos; |
| 921 | while (*p) { |
| 922 | if (*p == ',') { |
| 923 | result.push_back(value); |
| 924 | value = -1; |
| 925 | ++p; |
| 926 | continue; |
| 927 | } |
| 928 | RTC_CHECK_EQ(sscanf(p, "%d%n", &value, &pos), 1) |
| 929 | << "Unexpected non-number value."; |
| 930 | p += pos; |
| 931 | } |
| 932 | result.push_back(value); |
| 933 | return result; |
| 934 | } |
| 935 | |
| 936 | // Static. |
| 937 | VideoStream VideoQualityTest::DefaultVideoStream(const Params& params) { |
| 938 | VideoStream stream; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 939 | stream.width = params.video.width; |
| 940 | stream.height = params.video.height; |
| 941 | stream.max_framerate = params.video.fps; |
| 942 | stream.min_bitrate_bps = params.video.min_bitrate_bps; |
| 943 | stream.target_bitrate_bps = params.video.target_bitrate_bps; |
| 944 | stream.max_bitrate_bps = params.video.max_bitrate_bps; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 945 | stream.max_qp = 52; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 946 | if (params.video.num_temporal_layers == 2) |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 947 | stream.temporal_layer_thresholds_bps.push_back(stream.target_bitrate_bps); |
| 948 | return stream; |
| 949 | } |
| 950 | |
| 951 | // Static. |
| 952 | void VideoQualityTest::FillScalabilitySettings( |
| 953 | Params* params, |
| 954 | const std::vector<std::string>& stream_descriptors, |
| 955 | size_t selected_stream, |
| 956 | int num_spatial_layers, |
| 957 | int selected_sl, |
| 958 | const std::vector<std::string>& sl_descriptors) { |
| 959 | // Read VideoStream and SpatialLayer elements from a list of comma separated |
| 960 | // lists. To use a default value for an element, use -1 or leave empty. |
| 961 | // Validity checks performed in CheckParams. |
| 962 | |
| 963 | RTC_CHECK(params->ss.streams.empty()); |
| 964 | for (auto descriptor : stream_descriptors) { |
| 965 | if (descriptor.empty()) |
| 966 | continue; |
| 967 | VideoStream stream = VideoQualityTest::DefaultVideoStream(*params); |
| 968 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
| 969 | if (v[0] != -1) |
| 970 | stream.width = static_cast<size_t>(v[0]); |
| 971 | if (v[1] != -1) |
| 972 | stream.height = static_cast<size_t>(v[1]); |
| 973 | if (v[2] != -1) |
| 974 | stream.max_framerate = v[2]; |
| 975 | if (v[3] != -1) |
| 976 | stream.min_bitrate_bps = v[3]; |
| 977 | if (v[4] != -1) |
| 978 | stream.target_bitrate_bps = v[4]; |
| 979 | if (v[5] != -1) |
| 980 | stream.max_bitrate_bps = v[5]; |
| 981 | if (v.size() > 6 && v[6] != -1) |
| 982 | stream.max_qp = v[6]; |
| 983 | if (v.size() > 7) { |
| 984 | stream.temporal_layer_thresholds_bps.clear(); |
| 985 | stream.temporal_layer_thresholds_bps.insert( |
| 986 | stream.temporal_layer_thresholds_bps.end(), v.begin() + 7, v.end()); |
| 987 | } else { |
| 988 | // Automatic TL thresholds for more than two layers not supported. |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 989 | RTC_CHECK_LE(params->video.num_temporal_layers, 2); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 990 | } |
| 991 | params->ss.streams.push_back(stream); |
| 992 | } |
| 993 | params->ss.selected_stream = selected_stream; |
| 994 | |
| 995 | params->ss.num_spatial_layers = num_spatial_layers ? num_spatial_layers : 1; |
| 996 | params->ss.selected_sl = selected_sl; |
| 997 | RTC_CHECK(params->ss.spatial_layers.empty()); |
| 998 | for (auto descriptor : sl_descriptors) { |
| 999 | if (descriptor.empty()) |
| 1000 | continue; |
| 1001 | std::vector<int> v = VideoQualityTest::ParseCSV(descriptor); |
| 1002 | RTC_CHECK_GT(v[2], 0); |
| 1003 | |
| 1004 | SpatialLayer layer; |
| 1005 | layer.scaling_factor_num = v[0] == -1 ? 1 : v[0]; |
| 1006 | layer.scaling_factor_den = v[1] == -1 ? 1 : v[1]; |
| 1007 | layer.target_bitrate_bps = v[2]; |
| 1008 | params->ss.spatial_layers.push_back(layer); |
| 1009 | } |
| 1010 | } |
| 1011 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1012 | void VideoQualityTest::SetupVideo(Transport* send_transport, |
| 1013 | Transport* recv_transport) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1014 | if (params_.logs) |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1015 | trace_to_stderr_.reset(new test::TraceToStderr); |
| 1016 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1017 | size_t num_streams = params_.ss.streams.size(); |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 1018 | CreateSendConfig(num_streams, 0, 0, send_transport); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1019 | |
| 1020 | int payload_type; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1021 | if (params_.video.codec == "H264") { |
magjed | ceecea4 | 2016-11-28 07:20:21 -0800 | [diff] [blame] | 1022 | video_encoder_.reset(H264Encoder::Create(cricket::VideoCodec("H264"))); |
hbos | bab934b | 2016-01-27 01:36:03 -0800 | [diff] [blame] | 1023 | payload_type = kPayloadTypeH264; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1024 | } else if (params_.video.codec == "VP8") { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 1025 | video_encoder_.reset(VP8Encoder::Create()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1026 | payload_type = kPayloadTypeVP8; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1027 | } else if (params_.video.codec == "VP9") { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 1028 | video_encoder_.reset(VP9Encoder::Create()); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1029 | payload_type = kPayloadTypeVP9; |
| 1030 | } else { |
| 1031 | RTC_NOTREACHED() << "Codec not supported!"; |
| 1032 | return; |
| 1033 | } |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1034 | video_send_config_.encoder_settings.encoder = video_encoder_.get(); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1035 | video_send_config_.encoder_settings.payload_name = params_.video.codec; |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1036 | video_send_config_.encoder_settings.payload_type = payload_type; |
| 1037 | video_send_config_.rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
| 1038 | video_send_config_.rtp.rtx.payload_type = kSendRtxPayloadType; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1039 | for (size_t i = 0; i < num_streams; ++i) |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1040 | video_send_config_.rtp.rtx.ssrcs.push_back(kSendRtxSsrcs[i]); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1041 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1042 | video_send_config_.rtp.extensions.clear(); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1043 | if (params_.call.send_side_bwe) { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1044 | video_send_config_.rtp.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1045 | RtpExtension(RtpExtension::kTransportSequenceNumberUri, |
Stefan Holmer | 1295297 | 2015-10-29 15:13:24 +0100 | [diff] [blame] | 1046 | test::kTransportSequenceNumberExtensionId)); |
| 1047 | } else { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1048 | video_send_config_.rtp.extensions.push_back(RtpExtension( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 1049 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
Erik SprĂ¥ng | 6b8d355 | 2015-09-24 15:06:57 +0200 | [diff] [blame] | 1050 | } |
| 1051 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1052 | video_encoder_config_.min_transmit_bitrate_bps = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1053 | params_.video.min_transmit_bps; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1054 | |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1055 | video_send_config_.suspend_below_min_bitrate = |
| 1056 | params_.video.suspend_below_min_bitrate; |
| 1057 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1058 | video_encoder_config_.number_of_streams = params_.ss.streams.size(); |
| 1059 | video_encoder_config_.max_bitrate_bps = 0; |
| 1060 | for (size_t i = 0; i < params_.ss.streams.size(); ++i) { |
| 1061 | video_encoder_config_.max_bitrate_bps += |
| 1062 | params_.ss.streams[i].max_bitrate_bps; |
| 1063 | } |
| 1064 | video_encoder_config_.video_stream_factory = |
| 1065 | new rtc::RefCountedObject<VideoStreamFactory>(params_.ss.streams); |
| 1066 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1067 | video_encoder_config_.spatial_layers = params_.ss.spatial_layers; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1068 | |
| 1069 | CreateMatchingReceiveConfigs(recv_transport); |
| 1070 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1071 | for (size_t i = 0; i < num_streams; ++i) { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1072 | video_receive_configs_[i].rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
Stefan Holmer | 1088001 | 2016-02-03 13:29:59 +0100 | [diff] [blame] | 1073 | video_receive_configs_[i].rtp.rtx[payload_type].ssrc = kSendRtxSsrcs[i]; |
| 1074 | video_receive_configs_[i].rtp.rtx[payload_type].payload_type = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1075 | kSendRtxPayloadType; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1076 | video_receive_configs_[i].rtp.transport_cc = params_.call.send_side_bwe; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1077 | } |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1078 | |
| 1079 | if (params_.video.flexfec) { |
| 1080 | video_send_config_.rtp.flexfec.flexfec_payload_type = kFlexfecPayloadType; |
| 1081 | video_send_config_.rtp.flexfec.flexfec_ssrc = kFlexfecSendSsrc; |
| 1082 | video_send_config_.rtp.flexfec.protected_media_ssrcs = { |
| 1083 | kVideoSendSsrcs[params_.ss.selected_stream]}; |
| 1084 | |
| 1085 | FlexfecReceiveStream::Config flexfec_receive_config; |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 1086 | flexfec_receive_config.payload_type = |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1087 | video_send_config_.rtp.flexfec.flexfec_payload_type; |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 1088 | flexfec_receive_config.remote_ssrc = |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1089 | video_send_config_.rtp.flexfec.flexfec_ssrc; |
| 1090 | flexfec_receive_config.protected_media_ssrcs = |
| 1091 | video_send_config_.rtp.flexfec.protected_media_ssrcs; |
| 1092 | flexfec_receive_configs_.push_back(flexfec_receive_config); |
| 1093 | } |
| 1094 | |
| 1095 | if (params_.video.ulpfec) { |
| 1096 | video_send_config_.rtp.ulpfec.red_payload_type = kRedPayloadType; |
| 1097 | video_send_config_.rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType; |
| 1098 | video_send_config_.rtp.ulpfec.red_rtx_payload_type = kRtxRedPayloadType; |
| 1099 | |
| 1100 | video_receive_configs_[params_.ss.selected_stream] |
| 1101 | .rtp.ulpfec.red_payload_type = |
| 1102 | video_send_config_.rtp.ulpfec.red_payload_type; |
| 1103 | video_receive_configs_[params_.ss.selected_stream] |
| 1104 | .rtp.ulpfec.ulpfec_payload_type = |
| 1105 | video_send_config_.rtp.ulpfec.ulpfec_payload_type; |
| 1106 | video_receive_configs_[params_.ss.selected_stream] |
| 1107 | .rtp.ulpfec.red_rtx_payload_type = |
| 1108 | video_send_config_.rtp.ulpfec.red_rtx_payload_type; |
| 1109 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1112 | void VideoQualityTest::SetupScreenshare() { |
| 1113 | RTC_CHECK(params_.screenshare.enabled); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1114 | |
| 1115 | // Fill out codec settings. |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1116 | video_encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1117 | if (params_.video.codec == "VP8") { |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1118 | VideoCodecVP8 vp8_settings = VideoEncoder::GetDefaultVp8Settings(); |
| 1119 | vp8_settings.denoisingOn = false; |
| 1120 | vp8_settings.frameDroppingOn = false; |
| 1121 | vp8_settings.numberOfTemporalLayers = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1122 | static_cast<unsigned char>(params_.video.num_temporal_layers); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1123 | video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject< |
| 1124 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(vp8_settings); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1125 | } else if (params_.video.codec == "VP9") { |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1126 | VideoCodecVP9 vp9_settings = VideoEncoder::GetDefaultVp9Settings(); |
| 1127 | vp9_settings.denoisingOn = false; |
| 1128 | vp9_settings.frameDroppingOn = false; |
| 1129 | vp9_settings.numberOfTemporalLayers = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1130 | static_cast<unsigned char>(params_.video.num_temporal_layers); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1131 | vp9_settings.numberOfSpatialLayers = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1132 | static_cast<unsigned char>(params_.ss.num_spatial_layers); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 1133 | video_encoder_config_.encoder_specific_settings = new rtc::RefCountedObject< |
| 1134 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | // Setup frame generator. |
| 1138 | const size_t kWidth = 1850; |
| 1139 | const size_t kHeight = 1110; |
| 1140 | std::vector<std::string> slides; |
| 1141 | slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); |
| 1142 | slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); |
| 1143 | slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); |
| 1144 | slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv")); |
| 1145 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1146 | if (params_.screenshare.scroll_duration == 0) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1147 | // Cycle image every slide_change_interval seconds. |
| 1148 | frame_generator_.reset(test::FrameGenerator::CreateFromYuvFile( |
| 1149 | slides, kWidth, kHeight, |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1150 | params_.screenshare.slide_change_interval * params_.video.fps)); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1151 | } else { |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1152 | RTC_CHECK_LE(params_.video.width, kWidth); |
| 1153 | RTC_CHECK_LE(params_.video.height, kHeight); |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1154 | RTC_CHECK_GT(params_.screenshare.slide_change_interval, 0); |
| 1155 | const int kPauseDurationMs = (params_.screenshare.slide_change_interval - |
| 1156 | params_.screenshare.scroll_duration) * |
| 1157 | 1000; |
| 1158 | RTC_CHECK_LE(params_.screenshare.scroll_duration, |
| 1159 | params_.screenshare.slide_change_interval); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1160 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1161 | frame_generator_.reset( |
| 1162 | test::FrameGenerator::CreateScrollingInputFromYuvFiles( |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1163 | clock_, slides, kWidth, kHeight, params_.video.width, |
| 1164 | params_.video.height, params_.screenshare.scroll_duration * 1000, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1165 | kPauseDurationMs)); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1169 | void VideoQualityTest::CreateCapturer() { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1170 | if (params_.screenshare.enabled) { |
| 1171 | test::FrameGeneratorCapturer* frame_generator_capturer = |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1172 | new test::FrameGeneratorCapturer(clock_, frame_generator_.release(), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1173 | params_.video.fps); |
ivica | 2d4e6c5 | 2015-09-23 01:57:06 -0700 | [diff] [blame] | 1174 | EXPECT_TRUE(frame_generator_capturer->Init()); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1175 | video_capturer_.reset(frame_generator_capturer); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1176 | } else { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1177 | if (params_.video.clip_name.empty()) { |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1178 | video_capturer_.reset(test::VcmCapturer::Create( |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1179 | params_.video.width, params_.video.height, params_.video.fps)); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1180 | } else { |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1181 | video_capturer_.reset(test::FrameGeneratorCapturer::CreateFromYuvFile( |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1182 | test::ResourcePath(params_.video.clip_name, "yuv"), |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1183 | params_.video.width, params_.video.height, params_.video.fps, |
ivica | 2d4e6c5 | 2015-09-23 01:57:06 -0700 | [diff] [blame] | 1184 | clock_)); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1185 | ASSERT_TRUE(video_capturer_) << "Could not create capturer for " |
| 1186 | << params_.video.clip_name |
| 1187 | << ".yuv. Is this resource file present?"; |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | } |
| 1191 | |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1192 | void VideoQualityTest::RunWithAnalyzer(const Params& params) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1193 | params_ = params; |
| 1194 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1195 | RTC_CHECK(!params_.audio.enabled); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1196 | // TODO(ivica): Merge with RunWithRenderer and use a flag / argument to |
| 1197 | // differentiate between the analyzer and the renderer case. |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1198 | CheckParams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1199 | |
| 1200 | FILE* graph_data_output_file = nullptr; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1201 | if (!params_.analyzer.graph_data_output_filename.empty()) { |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1202 | graph_data_output_file = |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1203 | fopen(params_.analyzer.graph_data_output_filename.c_str(), "w"); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 1204 | RTC_CHECK(graph_data_output_file) |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1205 | << "Can't open the file " << params_.analyzer.graph_data_output_filename |
| 1206 | << "!"; |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1207 | } |
sprang | 7a975f7 | 2015-10-12 06:33:21 -0700 | [diff] [blame] | 1208 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 1209 | webrtc::RtcEventLogNullImpl event_log; |
| 1210 | Call::Config call_config(&event_log_); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1211 | call_config.bitrate_config = params.call.call_bitrate_config; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1212 | CreateCalls(call_config, call_config); |
| 1213 | |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1214 | test::LayerFilteringTransport send_transport( |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1215 | params_.pipe, sender_call_.get(), kPayloadTypeVP8, kPayloadTypeVP9, |
| 1216 | params_.video.selected_tl, params_.ss.selected_sl); |
| 1217 | test::DirectTransport recv_transport(params_.pipe, receiver_call_.get()); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1218 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1219 | std::string graph_title = params_.analyzer.graph_title; |
| 1220 | if (graph_title.empty()) |
| 1221 | graph_title = VideoQualityTest::GenerateGraphTitle(); |
| 1222 | |
| 1223 | // In the case of different resolutions, the functions calculating PSNR and |
| 1224 | // SSIM return -1.0, instead of a positive value as usual. VideoAnalyzer |
| 1225 | // aborts if the average psnr/ssim are below the given threshold, which is |
| 1226 | // 0.0 by default. Setting the thresholds to -1.1 prevents the unnecessary |
| 1227 | // abort. |
| 1228 | VideoStream& selected_stream = params_.ss.streams[params_.ss.selected_stream]; |
| 1229 | int selected_sl = params_.ss.selected_sl != -1 |
| 1230 | ? params_.ss.selected_sl |
| 1231 | : params_.ss.num_spatial_layers - 1; |
| 1232 | bool disable_quality_check = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1233 | selected_stream.width != params_.video.width || |
| 1234 | selected_stream.height != params_.video.height || |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1235 | (!params_.ss.spatial_layers.empty() && |
| 1236 | params_.ss.spatial_layers[selected_sl].scaling_factor_num != |
| 1237 | params_.ss.spatial_layers[selected_sl].scaling_factor_den); |
| 1238 | if (disable_quality_check) { |
| 1239 | fprintf(stderr, |
| 1240 | "Warning: Calculating PSNR and SSIM for downsized resolution " |
| 1241 | "not implemented yet! Skipping PSNR and SSIM calculations!"); |
| 1242 | } |
| 1243 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1244 | VideoAnalyzer analyzer( |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1245 | &send_transport, params_.analyzer.test_label, |
| 1246 | disable_quality_check ? -1.1 : params_.analyzer.avg_psnr_threshold, |
| 1247 | disable_quality_check ? -1.1 : params_.analyzer.avg_ssim_threshold, |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1248 | params_.analyzer.test_durations_secs * params_.video.fps, |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1249 | graph_data_output_file, graph_title, |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 1250 | kVideoSendSsrcs[params_.ss.selected_stream]); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1251 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1252 | analyzer.SetReceiver(receiver_call_->Receiver()); |
| 1253 | send_transport.SetReceiver(&analyzer); |
| 1254 | recv_transport.SetReceiver(sender_call_->Receiver()); |
| 1255 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1256 | SetupVideo(&analyzer, &recv_transport); |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1257 | video_receive_configs_[params_.ss.selected_stream].renderer = &analyzer; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1258 | video_send_config_.pre_encode_callback = analyzer.pre_encode_proxy(); |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1259 | for (auto& config : video_receive_configs_) |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1260 | config.pre_decode_callback = &analyzer; |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 1261 | RTC_DCHECK(!video_send_config_.post_encode_callback); |
| 1262 | video_send_config_.post_encode_callback = analyzer.encode_timing_proxy(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1263 | |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1264 | if (params_.screenshare.enabled) |
| 1265 | SetupScreenshare(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1266 | |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1267 | CreateFlexfecStreams(); |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 1268 | CreateVideoStreams(); |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1269 | analyzer.SetSendStream(video_send_stream_); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 1270 | video_send_stream_->SetSource( |
| 1271 | analyzer.OutputInterface(), |
| 1272 | VideoSendStream::DegradationPreference::kBalanced); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1273 | |
perkj | a49cbd3 | 2016-09-16 07:53:41 -0700 | [diff] [blame] | 1274 | CreateCapturer(); |
| 1275 | rtc::VideoSinkWants wants; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1276 | video_capturer_->AddOrUpdateSink(analyzer.InputInterface(), wants); |
ivica | c1cc854 | 2015-10-08 03:44:06 -0700 | [diff] [blame] | 1277 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1278 | StartEncodedFrameLogs(video_send_stream_); |
| 1279 | StartEncodedFrameLogs(video_receive_streams_[0]); |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1280 | video_send_stream_->Start(); |
| 1281 | for (VideoReceiveStream* receive_stream : video_receive_streams_) |
| 1282 | receive_stream->Start(); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1283 | for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_) |
| 1284 | receive_stream->Start(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1285 | video_capturer_->Start(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1286 | |
| 1287 | analyzer.Wait(); |
| 1288 | |
| 1289 | send_transport.StopSending(); |
| 1290 | recv_transport.StopSending(); |
| 1291 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1292 | video_capturer_->Stop(); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1293 | for (FlexfecReceiveStream* receive_stream : flexfec_receive_streams_) |
| 1294 | receive_stream->Stop(); |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1295 | for (VideoReceiveStream* receive_stream : video_receive_streams_) |
| 1296 | receive_stream->Stop(); |
| 1297 | video_send_stream_->Stop(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1298 | |
| 1299 | DestroyStreams(); |
| 1300 | |
| 1301 | if (graph_data_output_file) |
| 1302 | fclose(graph_data_output_file); |
| 1303 | } |
| 1304 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1305 | void VideoQualityTest::SetupAudio(int send_channel_id, |
| 1306 | int receive_channel_id, |
| 1307 | Call* call, |
| 1308 | Transport* transport, |
| 1309 | AudioReceiveStream** audio_receive_stream) { |
| 1310 | audio_send_config_ = AudioSendStream::Config(transport); |
| 1311 | audio_send_config_.voe_channel_id = send_channel_id; |
| 1312 | audio_send_config_.rtp.ssrc = kAudioSendSsrc; |
| 1313 | |
| 1314 | // Add extension to enable audio send side BWE, and allow audio bit rate |
| 1315 | // adaptation. |
| 1316 | audio_send_config_.rtp.extensions.clear(); |
| 1317 | if (params_.call.send_side_bwe) { |
| 1318 | audio_send_config_.rtp.extensions.push_back( |
| 1319 | webrtc::RtpExtension(webrtc::RtpExtension::kTransportSequenceNumberUri, |
| 1320 | test::kTransportSequenceNumberExtensionId)); |
minyue | 10cbb46 | 2016-11-07 09:29:22 -0800 | [diff] [blame] | 1321 | audio_send_config_.min_bitrate_bps = kOpusMinBitrateBps; |
| 1322 | audio_send_config_.max_bitrate_bps = kOpusBitrateFbBps; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1323 | } |
| 1324 | audio_send_config_.send_codec_spec.codec_inst = |
| 1325 | CodecInst{120, "OPUS", 48000, 960, 2, 64000}; |
| 1326 | |
| 1327 | audio_send_stream_ = call->CreateAudioSendStream(audio_send_config_); |
| 1328 | |
| 1329 | AudioReceiveStream::Config audio_config; |
| 1330 | audio_config.rtp.local_ssrc = kReceiverLocalAudioSsrc; |
| 1331 | audio_config.rtcp_send_transport = transport; |
| 1332 | audio_config.voe_channel_id = receive_channel_id; |
| 1333 | audio_config.rtp.remote_ssrc = audio_send_config_.rtp.ssrc; |
| 1334 | audio_config.rtp.transport_cc = params_.call.send_side_bwe; |
| 1335 | audio_config.rtp.extensions = audio_send_config_.rtp.extensions; |
| 1336 | audio_config.decoder_factory = decoder_factory_; |
| 1337 | if (params_.video.enabled && params_.audio.sync_video) |
| 1338 | audio_config.sync_group = kSyncGroup; |
| 1339 | |
| 1340 | *audio_receive_stream = call->CreateAudioReceiveStream(audio_config); |
| 1341 | } |
| 1342 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1343 | void VideoQualityTest::RunWithRenderers(const Params& params) { |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1344 | params_ = params; |
| 1345 | CheckParams(); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1346 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1347 | // TODO(ivica): Remove bitrate_config and use the default Call::Config(), to |
| 1348 | // match the full stack tests. |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 1349 | webrtc::RtcEventLogNullImpl event_log; |
| 1350 | Call::Config call_config(&event_log_); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1351 | call_config.bitrate_config = params_.call.call_bitrate_config; |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1352 | |
| 1353 | ::VoiceEngineState voe; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1354 | if (params_.audio.enabled) { |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1355 | CreateVoiceEngine(&voe, decoder_factory_); |
| 1356 | AudioState::Config audio_state_config; |
| 1357 | audio_state_config.voice_engine = voe.voice_engine; |
aleloi | 10111bc | 2016-11-17 06:48:48 -0800 | [diff] [blame] | 1358 | audio_state_config.audio_mixer = AudioMixerImpl::Create(); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1359 | call_config.audio_state = AudioState::Create(audio_state_config); |
| 1360 | } |
| 1361 | |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 1362 | std::unique_ptr<Call> call(Call::Create(call_config)); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1363 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1364 | // TODO(minyue): consider if this is a good transport even for audio only |
| 1365 | // calls. |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1366 | test::LayerFilteringTransport transport( |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1367 | params.pipe, call.get(), kPayloadTypeVP8, kPayloadTypeVP9, |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1368 | params.video.selected_tl, params_.ss.selected_sl); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1369 | // TODO(ivica): Use two calls to be able to merge with RunWithAnalyzer or at |
| 1370 | // least share as much code as possible. That way this test would also match |
| 1371 | // the full stack tests better. |
| 1372 | transport.SetReceiver(call->Receiver()); |
| 1373 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1374 | VideoReceiveStream* video_receive_stream = nullptr; |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1375 | FlexfecReceiveStream* flexfec_receive_stream = nullptr; |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1376 | std::unique_ptr<test::VideoRenderer> local_preview; |
| 1377 | std::unique_ptr<test::VideoRenderer> loopback_video; |
| 1378 | if (params_.video.enabled) { |
| 1379 | // Create video renderers. |
| 1380 | local_preview.reset(test::VideoRenderer::Create( |
| 1381 | "Local Preview", params_.video.width, params_.video.height)); |
ivica | 87f83a9 | 2015-10-08 05:13:32 -0700 | [diff] [blame] | 1382 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1383 | size_t stream_id = params_.ss.selected_stream; |
| 1384 | std::string title = "Loopback Video"; |
| 1385 | if (params_.ss.streams.size() > 1) { |
| 1386 | std::ostringstream s; |
| 1387 | s << stream_id; |
| 1388 | title += " - Stream #" + s.str(); |
| 1389 | } |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 1390 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1391 | loopback_video.reset(test::VideoRenderer::Create( |
| 1392 | title.c_str(), params_.ss.streams[stream_id].width, |
| 1393 | params_.ss.streams[stream_id].height)); |
mflodman | 48a4beb | 2016-07-01 13:03:59 +0200 | [diff] [blame] | 1394 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1395 | SetupVideo(&transport, &transport); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1396 | video_send_config_.pre_encode_callback = local_preview.get(); |
| 1397 | video_receive_configs_[stream_id].renderer = loopback_video.get(); |
| 1398 | if (params_.audio.enabled && params_.audio.sync_video) |
| 1399 | video_receive_configs_[stream_id].sync_group = kSyncGroup; |
| 1400 | |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1401 | if (params_.screenshare.enabled) |
| 1402 | SetupScreenshare(); |
| 1403 | |
| 1404 | video_send_stream_ = call->CreateVideoSendStream( |
| 1405 | video_send_config_.Copy(), video_encoder_config_.Copy()); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1406 | if (params_.video.flexfec) { |
| 1407 | RTC_DCHECK(!flexfec_receive_configs_.empty()); |
| 1408 | flexfec_receive_stream = |
| 1409 | call->CreateFlexfecReceiveStream(flexfec_receive_configs_[0]); |
| 1410 | } |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1411 | video_receive_stream = call->CreateVideoReceiveStream( |
| 1412 | video_receive_configs_[stream_id].Copy()); |
| 1413 | CreateCapturer(); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 1414 | video_send_stream_->SetSource( |
| 1415 | video_capturer_.get(), |
| 1416 | VideoSendStream::DegradationPreference::kBalanced); |
philipel | 274c1dc | 2016-05-04 06:21:01 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1419 | AudioReceiveStream* audio_receive_stream = nullptr; |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1420 | if (params_.audio.enabled) { |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1421 | SetupAudio(voe.send_channel_id, voe.receive_channel_id, call.get(), |
| 1422 | &transport, &audio_receive_stream); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1425 | StartEncodedFrameLogs(video_receive_stream); |
| 1426 | StartEncodedFrameLogs(video_send_stream_); |
| 1427 | |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1428 | // Start sending and receiving video. |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1429 | if (params_.video.enabled) { |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1430 | if (flexfec_receive_stream) |
| 1431 | flexfec_receive_stream->Start(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1432 | video_receive_stream->Start(); |
| 1433 | video_send_stream_->Start(); |
| 1434 | video_capturer_->Start(); |
| 1435 | } |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1436 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1437 | if (params_.audio.enabled) { |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1438 | // Start receiving audio. |
| 1439 | audio_receive_stream->Start(); |
| 1440 | EXPECT_EQ(0, voe.base->StartPlayout(voe.receive_channel_id)); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1441 | |
| 1442 | // Start sending audio. |
| 1443 | audio_send_stream_->Start(); |
| 1444 | EXPECT_EQ(0, voe.base->StartSend(voe.send_channel_id)); |
| 1445 | } |
| 1446 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1447 | test::PressEnterToContinue(); |
| 1448 | |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1449 | if (params_.audio.enabled) { |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1450 | // Stop sending audio. |
| 1451 | EXPECT_EQ(0, voe.base->StopSend(voe.send_channel_id)); |
| 1452 | audio_send_stream_->Stop(); |
| 1453 | |
| 1454 | // Stop receiving audio. |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1455 | EXPECT_EQ(0, voe.base->StopPlayout(voe.receive_channel_id)); |
| 1456 | audio_receive_stream->Stop(); |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1457 | call->DestroyAudioSendStream(audio_send_stream_); |
| 1458 | call->DestroyAudioReceiveStream(audio_receive_stream); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | // Stop receiving and sending video. |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1462 | if (params_.video.enabled) { |
| 1463 | video_capturer_->Stop(); |
| 1464 | video_send_stream_->Stop(); |
| 1465 | video_receive_stream->Stop(); |
brandtr | 1293aca | 2016-11-16 22:47:29 -0800 | [diff] [blame] | 1466 | if (flexfec_receive_stream) { |
| 1467 | flexfec_receive_stream->Stop(); |
| 1468 | call->DestroyFlexfecReceiveStream(flexfec_receive_stream); |
| 1469 | } |
minyue | a27172d | 2016-11-01 05:59:29 -0700 | [diff] [blame] | 1470 | call->DestroyVideoReceiveStream(video_receive_stream); |
| 1471 | call->DestroyVideoSendStream(video_send_stream_); |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1474 | transport.StopSending(); |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1475 | if (params_.audio.enabled) |
minyue | 7320866 | 2016-08-18 06:28:55 -0700 | [diff] [blame] | 1476 | DestroyVoiceEngine(&voe); |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1477 | } |
| 1478 | |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1479 | void VideoQualityTest::StartEncodedFrameLogs(VideoSendStream* stream) { |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1480 | if (!params_.video.encoded_frame_base_path.empty()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1481 | std::ostringstream str; |
| 1482 | str << send_logs_++; |
| 1483 | std::string prefix = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1484 | params_.video.encoded_frame_base_path + "." + str.str() + ".send."; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1485 | stream->EnableEncodedFrameRecording( |
| 1486 | std::vector<rtc::PlatformFile>( |
| 1487 | {rtc::CreatePlatformFile(prefix + "1.ivf"), |
| 1488 | rtc::CreatePlatformFile(prefix + "2.ivf"), |
| 1489 | rtc::CreatePlatformFile(prefix + "3.ivf")}), |
| 1490 | 10000000); |
| 1491 | } |
| 1492 | } |
| 1493 | void VideoQualityTest::StartEncodedFrameLogs(VideoReceiveStream* stream) { |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1494 | if (!params_.video.encoded_frame_base_path.empty()) { |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1495 | std::ostringstream str; |
| 1496 | str << receive_logs_++; |
| 1497 | std::string path = |
minyue | 626bc95 | 2016-10-31 05:47:02 -0700 | [diff] [blame] | 1498 | params_.video.encoded_frame_base_path + "." + str.str() + ".recv.ivf"; |
palmkvist | e75f204 | 2016-09-28 06:19:48 -0700 | [diff] [blame] | 1499 | stream->EnableEncodedFrameRecording(rtc::CreatePlatformFile(path), |
| 1500 | 10000000); |
| 1501 | } |
| 1502 | } |
| 1503 | |
ivica | 5d6a06c | 2015-09-17 05:30:24 -0700 | [diff] [blame] | 1504 | } // namespace webrtc |