Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | */ |
| 10 | #include "video/video_analyzer.h" |
| 11 | |
| 12 | #include <algorithm> |
| 13 | #include <utility> |
| 14 | |
Steve Anton | bd631a0 | 2019-03-28 10:51:27 -0700 | [diff] [blame] | 15 | #include "absl/algorithm/container.h" |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 16 | #include "absl/flags/flag.h" |
| 17 | #include "absl/flags/parse.h" |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 18 | #include "common_video/libyuv/include/webrtc_libyuv.h" |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 19 | #include "modules/rtp_rtcp/source/create_video_rtp_depacketizer.h" |
| 20 | #include "modules/rtp_rtcp/source/rtp_packet.h" |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 21 | #include "rtc_base/cpu_time.h" |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 22 | #include "rtc_base/format_macros.h" |
| 23 | #include "rtc_base/memory_usage.h" |
Danil Chapovalov | 9cd53b4 | 2019-10-21 13:36:59 +0200 | [diff] [blame] | 24 | #include "rtc_base/task_queue_for_test.h" |
| 25 | #include "rtc_base/task_utils/repeating_task.h" |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 26 | #include "system_wrappers/include/cpu_info.h" |
| 27 | #include "test/call_test.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 28 | #include "test/testsupport/file_utils.h" |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 29 | #include "test/testsupport/frame_writer.h" |
| 30 | #include "test/testsupport/perf_test.h" |
| 31 | #include "test/testsupport/test_artifacts.h" |
| 32 | |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 33 | ABSL_FLAG(bool, |
| 34 | save_worst_frame, |
| 35 | false, |
| 36 | "Enable saving a frame with the lowest PSNR to a jpeg file in the " |
| 37 | "test_artifacts_dir"); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 38 | |
| 39 | namespace webrtc { |
| 40 | namespace { |
Danil Chapovalov | 9cd53b4 | 2019-10-21 13:36:59 +0200 | [diff] [blame] | 41 | constexpr TimeDelta kSendStatsPollingInterval = TimeDelta::Seconds<1>(); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 42 | constexpr size_t kMaxComparisons = 10; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 43 | // How often is keep alive message printed. |
| 44 | constexpr int kKeepAliveIntervalSeconds = 30; |
| 45 | // Interval between checking that the test is over. |
| 46 | constexpr int kProbingIntervalMs = 500; |
| 47 | constexpr int kKeepAliveIntervalIterations = |
| 48 | kKeepAliveIntervalSeconds * 1000 / kProbingIntervalMs; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 49 | |
| 50 | bool IsFlexfec(int payload_type) { |
| 51 | return payload_type == test::CallTest::kFlexfecPayloadType; |
| 52 | } |
| 53 | } // namespace |
| 54 | |
Danil Chapovalov | 9cd53b4 | 2019-10-21 13:36:59 +0200 | [diff] [blame] | 55 | VideoAnalyzer::VideoAnalyzer(test::LayerFilteringTransport* transport, |
| 56 | const std::string& test_label, |
| 57 | double avg_psnr_threshold, |
| 58 | double avg_ssim_threshold, |
| 59 | int duration_frames, |
| 60 | FILE* graph_data_output_file, |
| 61 | const std::string& graph_title, |
| 62 | uint32_t ssrc_to_analyze, |
| 63 | uint32_t rtx_ssrc_to_analyze, |
| 64 | size_t selected_stream, |
| 65 | int selected_sl, |
| 66 | int selected_tl, |
| 67 | bool is_quick_test_enabled, |
| 68 | Clock* clock, |
| 69 | std::string rtp_dump_name, |
| 70 | TaskQueueBase* task_queue) |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 71 | : transport_(transport), |
| 72 | receiver_(nullptr), |
| 73 | call_(nullptr), |
| 74 | send_stream_(nullptr), |
| 75 | receive_stream_(nullptr), |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 76 | audio_receive_stream_(nullptr), |
Ilya Nikolaevskiy | 85fc325 | 2019-02-11 10:41:50 +0100 | [diff] [blame] | 77 | captured_frame_forwarder_(this, clock, duration_frames), |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 78 | test_label_(test_label), |
| 79 | graph_data_output_file_(graph_data_output_file), |
| 80 | graph_title_(graph_title), |
| 81 | ssrc_to_analyze_(ssrc_to_analyze), |
| 82 | rtx_ssrc_to_analyze_(rtx_ssrc_to_analyze), |
| 83 | selected_stream_(selected_stream), |
| 84 | selected_sl_(selected_sl), |
| 85 | selected_tl_(selected_tl), |
Johannes Kron | a1b99b3 | 2019-07-30 15:08:16 +0200 | [diff] [blame] | 86 | mean_decode_time_ms_(0.0), |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 87 | freeze_count_(0), |
| 88 | total_freezes_duration_ms_(0), |
| 89 | total_frames_duration_ms_(0), |
| 90 | sum_squared_frame_durations_(0), |
Elad Alon | 58e0657 | 2019-05-08 15:34:24 +0200 | [diff] [blame] | 91 | decode_frame_rate_(0), |
| 92 | render_frame_rate_(0), |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 93 | last_fec_bytes_(0), |
| 94 | frames_to_process_(duration_frames), |
| 95 | frames_recorded_(0), |
| 96 | frames_processed_(0), |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 97 | captured_frames_(0), |
Yves Gerey | 0c67c80 | 2019-08-01 17:45:54 +0200 | [diff] [blame] | 98 | dropped_frames_(0), |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 99 | dropped_frames_before_first_encode_(0), |
| 100 | dropped_frames_before_rendering_(0), |
| 101 | last_render_time_(0), |
| 102 | last_render_delta_ms_(0), |
| 103 | last_unfreeze_time_ms_(0), |
| 104 | rtp_timestamp_delta_(0), |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 105 | cpu_time_(0), |
| 106 | wallclock_time_(0), |
| 107 | avg_psnr_threshold_(avg_psnr_threshold), |
| 108 | avg_ssim_threshold_(avg_ssim_threshold), |
| 109 | is_quick_test_enabled_(is_quick_test_enabled), |
Niels Möller | 4731f00 | 2019-05-03 09:34:24 +0200 | [diff] [blame] | 110 | quit_(false), |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 111 | done_(true, false), |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 112 | vp8_depacketizer_(CreateVideoRtpDepacketizer(kVideoCodecVP8)), |
| 113 | vp9_depacketizer_(CreateVideoRtpDepacketizer(kVideoCodecVP9)), |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 114 | clock_(clock), |
Artem Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 115 | start_ms_(clock->TimeInMilliseconds()), |
| 116 | task_queue_(task_queue) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 117 | // Create thread pool for CPU-expensive PSNR/SSIM calculations. |
| 118 | |
| 119 | // Try to use about as many threads as cores, but leave kMinCoresLeft alone, |
| 120 | // so that we don't accidentally starve "real" worker threads (codec etc). |
| 121 | // Also, don't allocate more than kMaxComparisonThreads, even if there are |
| 122 | // spare cores. |
| 123 | |
| 124 | uint32_t num_cores = CpuInfo::DetectNumberOfCores(); |
| 125 | RTC_DCHECK_GE(num_cores, 1); |
| 126 | static const uint32_t kMinCoresLeft = 4; |
| 127 | static const uint32_t kMaxComparisonThreads = 8; |
| 128 | |
| 129 | if (num_cores <= kMinCoresLeft) { |
| 130 | num_cores = 1; |
| 131 | } else { |
| 132 | num_cores -= kMinCoresLeft; |
| 133 | num_cores = std::min(num_cores, kMaxComparisonThreads); |
| 134 | } |
| 135 | |
| 136 | for (uint32_t i = 0; i < num_cores; ++i) { |
| 137 | rtc::PlatformThread* thread = |
| 138 | new rtc::PlatformThread(&FrameComparisonThread, this, "Analyzer"); |
| 139 | thread->Start(); |
| 140 | comparison_thread_pool_.push_back(thread); |
| 141 | } |
| 142 | |
| 143 | if (!rtp_dump_name.empty()) { |
| 144 | fprintf(stdout, "Writing rtp dump to %s\n", rtp_dump_name.c_str()); |
| 145 | rtp_file_writer_.reset(test::RtpFileWriter::Create( |
| 146 | test::RtpFileWriter::kRtpDump, rtp_dump_name)); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | VideoAnalyzer::~VideoAnalyzer() { |
Niels Möller | 4731f00 | 2019-05-03 09:34:24 +0200 | [diff] [blame] | 151 | { |
| 152 | rtc::CritScope crit(&comparison_lock_); |
| 153 | quit_ = true; |
| 154 | } |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 155 | for (rtc::PlatformThread* thread : comparison_thread_pool_) { |
| 156 | thread->Stop(); |
| 157 | delete thread; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void VideoAnalyzer::SetReceiver(PacketReceiver* receiver) { |
| 162 | receiver_ = receiver; |
| 163 | } |
| 164 | |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 165 | void VideoAnalyzer::SetSource( |
| 166 | rtc::VideoSourceInterface<VideoFrame>* video_source, |
| 167 | bool respect_sink_wants) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 168 | if (respect_sink_wants) |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 169 | captured_frame_forwarder_.SetSource(video_source); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 170 | rtc::VideoSinkWants wants; |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 171 | video_source->AddOrUpdateSink(InputInterface(), wants); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void VideoAnalyzer::SetCall(Call* call) { |
| 175 | rtc::CritScope lock(&crit_); |
| 176 | RTC_DCHECK(!call_); |
| 177 | call_ = call; |
| 178 | } |
| 179 | |
| 180 | void VideoAnalyzer::SetSendStream(VideoSendStream* stream) { |
| 181 | rtc::CritScope lock(&crit_); |
| 182 | RTC_DCHECK(!send_stream_); |
| 183 | send_stream_ = stream; |
| 184 | } |
| 185 | |
| 186 | void VideoAnalyzer::SetReceiveStream(VideoReceiveStream* stream) { |
| 187 | rtc::CritScope lock(&crit_); |
| 188 | RTC_DCHECK(!receive_stream_); |
| 189 | receive_stream_ = stream; |
| 190 | } |
| 191 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 192 | void VideoAnalyzer::SetAudioReceiveStream(AudioReceiveStream* recv_stream) { |
| 193 | rtc::CritScope lock(&crit_); |
| 194 | RTC_CHECK(!audio_receive_stream_); |
| 195 | audio_receive_stream_ = recv_stream; |
| 196 | } |
| 197 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 198 | rtc::VideoSinkInterface<VideoFrame>* VideoAnalyzer::InputInterface() { |
| 199 | return &captured_frame_forwarder_; |
| 200 | } |
| 201 | |
| 202 | rtc::VideoSourceInterface<VideoFrame>* VideoAnalyzer::OutputInterface() { |
| 203 | return &captured_frame_forwarder_; |
| 204 | } |
| 205 | |
| 206 | PacketReceiver::DeliveryStatus VideoAnalyzer::DeliverPacket( |
| 207 | MediaType media_type, |
| 208 | rtc::CopyOnWriteBuffer packet, |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 209 | int64_t packet_time_us) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 210 | // Ignore timestamps of RTCP packets. They're not synchronized with |
| 211 | // RTP packet timestamps and so they would confuse wrap_handler_. |
| 212 | if (RtpHeaderParser::IsRtcp(packet.cdata(), packet.size())) { |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 213 | return receiver_->DeliverPacket(media_type, std::move(packet), |
| 214 | packet_time_us); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | if (rtp_file_writer_) { |
| 218 | test::RtpPacket p; |
| 219 | memcpy(p.data, packet.cdata(), packet.size()); |
| 220 | p.length = packet.size(); |
| 221 | p.original_length = packet.size(); |
| 222 | p.time_ms = clock_->TimeInMilliseconds() - start_ms_; |
| 223 | rtp_file_writer_->WritePacket(&p); |
| 224 | } |
| 225 | |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 226 | RtpPacket rtp_packet; |
| 227 | rtp_packet.Parse(packet); |
| 228 | if (!IsFlexfec(rtp_packet.PayloadType()) && |
| 229 | (rtp_packet.Ssrc() == ssrc_to_analyze_ || |
| 230 | rtp_packet.Ssrc() == rtx_ssrc_to_analyze_)) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 231 | // Ignore FlexFEC timestamps, to avoid collisions with media timestamps. |
| 232 | // (FlexFEC and media are sent on different SSRCs, which have different |
| 233 | // timestamps spaces.) |
| 234 | // Also ignore packets from wrong SSRC, but include retransmits. |
| 235 | rtc::CritScope lock(&crit_); |
| 236 | int64_t timestamp = |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 237 | wrap_handler_.Unwrap(rtp_packet.Timestamp() - rtp_timestamp_delta_); |
Sebastian Jansson | 11c012a | 2019-03-29 14:17:26 +0100 | [diff] [blame] | 238 | recv_times_[timestamp] = clock_->CurrentNtpInMilliseconds(); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 239 | } |
| 240 | |
Niels Möller | 7008287 | 2018-08-07 11:03:12 +0200 | [diff] [blame] | 241 | return receiver_->DeliverPacket(media_type, std::move(packet), |
| 242 | packet_time_us); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void VideoAnalyzer::PreEncodeOnFrame(const VideoFrame& video_frame) { |
| 246 | rtc::CritScope lock(&crit_); |
| 247 | if (!first_encoded_timestamp_) { |
| 248 | while (frames_.front().timestamp() != video_frame.timestamp()) { |
| 249 | ++dropped_frames_before_first_encode_; |
| 250 | frames_.pop_front(); |
| 251 | RTC_CHECK(!frames_.empty()); |
| 252 | } |
| 253 | first_encoded_timestamp_ = video_frame.timestamp(); |
| 254 | } |
| 255 | } |
| 256 | |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 257 | void VideoAnalyzer::PostEncodeOnFrame(size_t stream_id, uint32_t timestamp) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 258 | rtc::CritScope lock(&crit_); |
Niels Möller | 88be972 | 2018-10-10 10:58:52 +0200 | [diff] [blame] | 259 | if (!first_sent_timestamp_ && stream_id == selected_stream_) { |
| 260 | first_sent_timestamp_ = timestamp; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 261 | } |
| 262 | } |
| 263 | |
| 264 | bool VideoAnalyzer::SendRtp(const uint8_t* packet, |
| 265 | size_t length, |
| 266 | const PacketOptions& options) { |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 267 | RtpPacket rtp_packet; |
| 268 | rtp_packet.Parse(packet, length); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 269 | |
Sebastian Jansson | 11c012a | 2019-03-29 14:17:26 +0100 | [diff] [blame] | 270 | int64_t current_time = clock_->CurrentNtpInMilliseconds(); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 271 | |
| 272 | bool result = transport_->SendRtp(packet, length, options); |
| 273 | { |
| 274 | rtc::CritScope lock(&crit_); |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 275 | if (rtp_timestamp_delta_ == 0 && rtp_packet.Ssrc() == ssrc_to_analyze_) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 276 | RTC_CHECK(static_cast<bool>(first_sent_timestamp_)); |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 277 | rtp_timestamp_delta_ = rtp_packet.Timestamp() - *first_sent_timestamp_; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 280 | if (!IsFlexfec(rtp_packet.PayloadType()) && |
| 281 | rtp_packet.Ssrc() == ssrc_to_analyze_) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 282 | // Ignore FlexFEC timestamps, to avoid collisions with media timestamps. |
| 283 | // (FlexFEC and media are sent on different SSRCs, which have different |
| 284 | // timestamps spaces.) |
| 285 | // Also ignore packets from wrong SSRC and retransmits. |
| 286 | int64_t timestamp = |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 287 | wrap_handler_.Unwrap(rtp_packet.Timestamp() - rtp_timestamp_delta_); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 288 | send_times_[timestamp] = current_time; |
| 289 | |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 290 | if (IsInSelectedSpatialAndTemporalLayer(rtp_packet)) { |
| 291 | encoded_frame_sizes_[timestamp] += rtp_packet.payload_size(); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 292 | } |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | return result; |
| 296 | } |
| 297 | |
| 298 | bool VideoAnalyzer::SendRtcp(const uint8_t* packet, size_t length) { |
| 299 | return transport_->SendRtcp(packet, length); |
| 300 | } |
| 301 | |
| 302 | void VideoAnalyzer::OnFrame(const VideoFrame& video_frame) { |
Sebastian Jansson | 11c012a | 2019-03-29 14:17:26 +0100 | [diff] [blame] | 303 | int64_t render_time_ms = clock_->CurrentNtpInMilliseconds(); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 304 | |
| 305 | rtc::CritScope lock(&crit_); |
| 306 | |
| 307 | StartExcludingCpuThreadTime(); |
| 308 | |
| 309 | int64_t send_timestamp = |
| 310 | wrap_handler_.Unwrap(video_frame.timestamp() - rtp_timestamp_delta_); |
| 311 | |
| 312 | while (wrap_handler_.Unwrap(frames_.front().timestamp()) < send_timestamp) { |
| 313 | if (!last_rendered_frame_) { |
| 314 | // No previous frame rendered, this one was dropped after sending but |
| 315 | // before rendering. |
| 316 | ++dropped_frames_before_rendering_; |
| 317 | } else { |
| 318 | AddFrameComparison(frames_.front(), *last_rendered_frame_, true, |
| 319 | render_time_ms); |
| 320 | } |
| 321 | frames_.pop_front(); |
| 322 | RTC_DCHECK(!frames_.empty()); |
| 323 | } |
| 324 | |
| 325 | VideoFrame reference_frame = frames_.front(); |
| 326 | frames_.pop_front(); |
| 327 | int64_t reference_timestamp = |
| 328 | wrap_handler_.Unwrap(reference_frame.timestamp()); |
| 329 | if (send_timestamp == reference_timestamp - 1) { |
| 330 | // TODO(ivica): Make this work for > 2 streams. |
| 331 | // Look at RTPSender::BuildRTPHeader. |
| 332 | ++send_timestamp; |
| 333 | } |
| 334 | ASSERT_EQ(reference_timestamp, send_timestamp); |
| 335 | |
| 336 | AddFrameComparison(reference_frame, video_frame, false, render_time_ms); |
| 337 | |
| 338 | last_rendered_frame_ = video_frame; |
| 339 | |
| 340 | StopExcludingCpuThreadTime(); |
| 341 | } |
| 342 | |
| 343 | void VideoAnalyzer::Wait() { |
| 344 | // Frame comparisons can be very expensive. Wait for test to be done, but |
| 345 | // at time-out check if frames_processed is going up. If so, give it more |
| 346 | // time, otherwise fail. Hopefully this will reduce test flakiness. |
| 347 | |
Danil Chapovalov | 9cd53b4 | 2019-10-21 13:36:59 +0200 | [diff] [blame] | 348 | RepeatingTaskHandle stats_polling_task = RepeatingTaskHandle::DelayedStart( |
| 349 | task_queue_, kSendStatsPollingInterval, [this] { |
| 350 | PollStats(); |
| 351 | return kSendStatsPollingInterval; |
| 352 | }); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 353 | |
| 354 | int last_frames_processed = -1; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 355 | int last_frames_captured = -1; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 356 | int iteration = 0; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 357 | |
| 358 | while (!done_.Wait(kProbingIntervalMs)) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 359 | int frames_processed; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 360 | int frames_captured; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 361 | { |
| 362 | rtc::CritScope crit(&comparison_lock_); |
| 363 | frames_processed = frames_processed_; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 364 | frames_captured = captured_frames_; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | // Print some output so test infrastructure won't think we've crashed. |
| 368 | const char* kKeepAliveMessages[3] = { |
| 369 | "Uh, I'm-I'm not quite dead, sir.", |
| 370 | "Uh, I-I think uh, I could pull through, sir.", |
| 371 | "Actually, I think I'm all right to come with you--"}; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 372 | if (++iteration % kKeepAliveIntervalIterations == 0) { |
| 373 | printf("- %s\n", kKeepAliveMessages[iteration % 3]); |
| 374 | } |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 375 | |
| 376 | if (last_frames_processed == -1) { |
| 377 | last_frames_processed = frames_processed; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 378 | last_frames_captured = frames_captured; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 379 | continue; |
| 380 | } |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 381 | if (frames_processed == last_frames_processed && |
| 382 | last_frames_captured == frames_captured) { |
| 383 | if (frames_captured < frames_to_process_) { |
| 384 | EXPECT_GT(frames_processed, last_frames_processed) |
| 385 | << "Analyzer stalled while waiting for test to finish."; |
| 386 | } |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 387 | done_.Set(); |
| 388 | break; |
| 389 | } |
| 390 | last_frames_processed = frames_processed; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 391 | last_frames_captured = frames_captured; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | if (iteration > 0) |
| 395 | printf("- Farewell, sweet Concorde!\n"); |
| 396 | |
Danil Chapovalov | 9cd53b4 | 2019-10-21 13:36:59 +0200 | [diff] [blame] | 397 | SendTask(RTC_FROM_HERE, task_queue_, [&] { stats_polling_task.Stop(); }); |
Artem Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 398 | |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 399 | PrintResults(); |
| 400 | if (graph_data_output_file_) |
| 401 | PrintSamplesToFile(); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 404 | void VideoAnalyzer::StartMeasuringCpuProcessTime() { |
| 405 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 406 | cpu_time_ -= rtc::GetProcessCpuTimeNanos(); |
| 407 | wallclock_time_ -= rtc::SystemTimeNanos(); |
| 408 | } |
| 409 | |
| 410 | void VideoAnalyzer::StopMeasuringCpuProcessTime() { |
| 411 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 412 | cpu_time_ += rtc::GetProcessCpuTimeNanos(); |
| 413 | wallclock_time_ += rtc::SystemTimeNanos(); |
| 414 | } |
| 415 | |
| 416 | void VideoAnalyzer::StartExcludingCpuThreadTime() { |
| 417 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 418 | cpu_time_ += rtc::GetThreadCpuTimeNanos(); |
| 419 | } |
| 420 | |
| 421 | void VideoAnalyzer::StopExcludingCpuThreadTime() { |
| 422 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 423 | cpu_time_ -= rtc::GetThreadCpuTimeNanos(); |
| 424 | } |
| 425 | |
| 426 | double VideoAnalyzer::GetCpuUsagePercent() { |
| 427 | rtc::CritScope lock(&cpu_measurement_lock_); |
| 428 | return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0; |
| 429 | } |
| 430 | |
| 431 | bool VideoAnalyzer::IsInSelectedSpatialAndTemporalLayer( |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 432 | const RtpPacket& rtp_packet) { |
| 433 | if (rtp_packet.PayloadType() == test::CallTest::kPayloadTypeVP8) { |
| 434 | auto parsed_payload = vp8_depacketizer_->Parse(rtp_packet.PayloadBuffer()); |
| 435 | RTC_DCHECK(parsed_payload); |
| 436 | const auto& vp8_header = absl::get<RTPVideoHeaderVP8>( |
| 437 | parsed_payload->video_header.video_type_header); |
| 438 | int temporal_idx = vp8_header.temporalIdx; |
| 439 | return selected_tl_ < 0 || temporal_idx == kNoTemporalIdx || |
| 440 | temporal_idx <= selected_tl_; |
| 441 | } |
philipel | 29d8846 | 2018-08-08 14:26:00 +0200 | [diff] [blame] | 442 | |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 443 | if (rtp_packet.PayloadType() == test::CallTest::kPayloadTypeVP9) { |
| 444 | auto parsed_payload = vp9_depacketizer_->Parse(rtp_packet.PayloadBuffer()); |
| 445 | RTC_DCHECK(parsed_payload); |
| 446 | const auto& vp9_header = absl::get<RTPVideoHeaderVP9>( |
| 447 | parsed_payload->video_header.video_type_header); |
| 448 | int temporal_idx = vp9_header.temporal_idx; |
| 449 | int spatial_idx = vp9_header.spatial_idx; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 450 | return (selected_tl_ < 0 || temporal_idx == kNoTemporalIdx || |
| 451 | temporal_idx <= selected_tl_) && |
| 452 | (selected_sl_ < 0 || spatial_idx == kNoSpatialIdx || |
| 453 | spatial_idx <= selected_sl_); |
| 454 | } |
Danil Chapovalov | b57fe17 | 2019-12-11 09:38:44 +0100 | [diff] [blame] | 455 | |
| 456 | return true; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 457 | } |
| 458 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 459 | void VideoAnalyzer::PollStats() { |
Artem Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 460 | rtc::CritScope crit(&comparison_lock_); |
Artem Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 461 | |
| 462 | Call::Stats call_stats = call_->GetStats(); |
| 463 | send_bandwidth_bps_.AddSample(call_stats.send_bandwidth_bps); |
| 464 | |
| 465 | VideoSendStream::Stats send_stats = send_stream_->GetStats(); |
| 466 | // It's not certain that we yet have estimates for any of these stats. |
| 467 | // Check that they are positive before mixing them in. |
| 468 | if (send_stats.encode_frame_rate > 0) |
| 469 | encode_frame_rate_.AddSample(send_stats.encode_frame_rate); |
| 470 | if (send_stats.avg_encode_time_ms > 0) |
| 471 | encode_time_ms_.AddSample(send_stats.avg_encode_time_ms); |
| 472 | if (send_stats.encode_usage_percent > 0) |
| 473 | encode_usage_percent_.AddSample(send_stats.encode_usage_percent); |
| 474 | if (send_stats.media_bitrate_bps > 0) |
| 475 | media_bitrate_bps_.AddSample(send_stats.media_bitrate_bps); |
| 476 | size_t fec_bytes = 0; |
| 477 | for (const auto& kv : send_stats.substreams) { |
| 478 | fec_bytes += kv.second.rtp_stats.fec.payload_bytes + |
| 479 | kv.second.rtp_stats.fec.padding_bytes; |
| 480 | } |
| 481 | fec_bitrate_bps_.AddSample((fec_bytes - last_fec_bytes_) * 8); |
| 482 | last_fec_bytes_ = fec_bytes; |
| 483 | |
| 484 | if (receive_stream_ != nullptr) { |
| 485 | VideoReceiveStream::Stats receive_stats = receive_stream_->GetStats(); |
Johannes Kron | a1b99b3 | 2019-07-30 15:08:16 +0200 | [diff] [blame] | 486 | // |total_decode_time_ms| gives a good estimate of the mean decode time, |
| 487 | // |decode_ms| is used to keep track of the standard deviation. |
| 488 | if (receive_stats.frames_decoded > 0) |
| 489 | mean_decode_time_ms_ = |
| 490 | static_cast<double>(receive_stats.total_decode_time_ms) / |
| 491 | receive_stats.frames_decoded; |
Artem Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 492 | if (receive_stats.decode_ms > 0) |
| 493 | decode_time_ms_.AddSample(receive_stats.decode_ms); |
| 494 | if (receive_stats.max_decode_ms > 0) |
| 495 | decode_time_max_ms_.AddSample(receive_stats.max_decode_ms); |
| 496 | if (receive_stats.width > 0 && receive_stats.height > 0) { |
| 497 | pixels_.AddSample(receive_stats.width * receive_stats.height); |
| 498 | } |
Elad Alon | 58e0657 | 2019-05-08 15:34:24 +0200 | [diff] [blame] | 499 | |
| 500 | // |frames_decoded| and |frames_rendered| are used because they are more |
| 501 | // accurate than |decode_frame_rate| and |render_frame_rate|. |
| 502 | // The latter two are calculated on a momentary basis. |
| 503 | const double total_frames_duration_sec_double = |
| 504 | static_cast<double>(receive_stats.total_frames_duration_ms) / 1000.0; |
| 505 | if (total_frames_duration_sec_double > 0) { |
| 506 | decode_frame_rate_ = static_cast<double>(receive_stats.frames_decoded) / |
| 507 | total_frames_duration_sec_double; |
| 508 | render_frame_rate_ = static_cast<double>(receive_stats.frames_rendered) / |
| 509 | total_frames_duration_sec_double; |
| 510 | } |
| 511 | |
| 512 | // Freeze metrics. |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 513 | freeze_count_ = receive_stats.freeze_count; |
| 514 | total_freezes_duration_ms_ = receive_stats.total_freezes_duration_ms; |
| 515 | total_frames_duration_ms_ = receive_stats.total_frames_duration_ms; |
| 516 | sum_squared_frame_durations_ = receive_stats.sum_squared_frame_durations; |
Artem Titov | ff7730d | 2019-04-02 13:46:53 +0200 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | if (audio_receive_stream_ != nullptr) { |
| 520 | AudioReceiveStream::Stats receive_stats = audio_receive_stream_->GetStats(); |
| 521 | audio_expand_rate_.AddSample(receive_stats.expand_rate); |
| 522 | audio_accelerate_rate_.AddSample(receive_stats.accelerate_rate); |
| 523 | audio_jitter_buffer_ms_.AddSample(receive_stats.jitter_buffer_ms); |
| 524 | } |
| 525 | |
| 526 | memory_usage_.AddSample(rtc::GetProcessResidentSizeBytes()); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 527 | } |
| 528 | |
Niels Möller | 4731f00 | 2019-05-03 09:34:24 +0200 | [diff] [blame] | 529 | void VideoAnalyzer::FrameComparisonThread(void* obj) { |
| 530 | VideoAnalyzer* analyzer = static_cast<VideoAnalyzer*>(obj); |
| 531 | while (analyzer->CompareFrames()) { |
| 532 | } |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | bool VideoAnalyzer::CompareFrames() { |
| 536 | if (AllFramesRecorded()) |
| 537 | return false; |
| 538 | |
| 539 | FrameComparison comparison; |
| 540 | |
| 541 | if (!PopComparison(&comparison)) { |
| 542 | // Wait until new comparison task is available, or test is done. |
| 543 | // If done, wake up remaining threads waiting. |
| 544 | comparison_available_event_.Wait(1000); |
| 545 | if (AllFramesRecorded()) { |
| 546 | comparison_available_event_.Set(); |
| 547 | return false; |
| 548 | } |
| 549 | return true; // Try again. |
| 550 | } |
| 551 | |
| 552 | StartExcludingCpuThreadTime(); |
| 553 | |
| 554 | PerformFrameComparison(comparison); |
| 555 | |
| 556 | StopExcludingCpuThreadTime(); |
| 557 | |
| 558 | if (FrameProcessed()) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 559 | done_.Set(); |
| 560 | comparison_available_event_.Set(); |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | return true; |
| 565 | } |
| 566 | |
| 567 | bool VideoAnalyzer::PopComparison(VideoAnalyzer::FrameComparison* comparison) { |
| 568 | rtc::CritScope crit(&comparison_lock_); |
| 569 | // If AllFramesRecorded() is true, it means we have already popped |
| 570 | // frames_to_process_ frames from comparisons_, so there is no more work |
| 571 | // for this thread to be done. frames_processed_ might still be lower if |
| 572 | // all comparisons are not done, but those frames are currently being |
| 573 | // worked on by other threads. |
| 574 | if (comparisons_.empty() || AllFramesRecorded()) |
| 575 | return false; |
| 576 | |
| 577 | *comparison = comparisons_.front(); |
| 578 | comparisons_.pop_front(); |
| 579 | |
| 580 | FrameRecorded(); |
| 581 | return true; |
| 582 | } |
| 583 | |
| 584 | void VideoAnalyzer::FrameRecorded() { |
| 585 | rtc::CritScope crit(&comparison_lock_); |
| 586 | ++frames_recorded_; |
| 587 | } |
| 588 | |
| 589 | bool VideoAnalyzer::AllFramesRecorded() { |
| 590 | rtc::CritScope crit(&comparison_lock_); |
Niels Möller | 4731f00 | 2019-05-03 09:34:24 +0200 | [diff] [blame] | 591 | RTC_DCHECK(frames_recorded_ <= frames_to_process_); |
| 592 | return frames_recorded_ == frames_to_process_ || quit_; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | bool VideoAnalyzer::FrameProcessed() { |
| 596 | rtc::CritScope crit(&comparison_lock_); |
| 597 | ++frames_processed_; |
| 598 | assert(frames_processed_ <= frames_to_process_); |
| 599 | return frames_processed_ == frames_to_process_; |
| 600 | } |
| 601 | |
| 602 | void VideoAnalyzer::PrintResults() { |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 603 | using ::webrtc::test::ImproveDirection; |
| 604 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 605 | StopMeasuringCpuProcessTime(); |
Yves Gerey | 0c67c80 | 2019-08-01 17:45:54 +0200 | [diff] [blame] | 606 | int dropped_frames_diff; |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 607 | { |
| 608 | rtc::CritScope crit(&crit_); |
Yves Gerey | 0c67c80 | 2019-08-01 17:45:54 +0200 | [diff] [blame] | 609 | dropped_frames_diff = dropped_frames_before_first_encode_ + |
| 610 | dropped_frames_before_rendering_ + frames_.size(); |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 611 | } |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 612 | rtc::CritScope crit(&comparison_lock_); |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 613 | PrintResult("psnr", psnr_, "dB", ImproveDirection::kBiggerIsBetter); |
| 614 | PrintResult("ssim", ssim_, "unitless", ImproveDirection::kBiggerIsBetter); |
| 615 | PrintResult("sender_time", sender_time_, "ms", |
| 616 | ImproveDirection::kSmallerIsBetter); |
| 617 | PrintResult("receiver_time", receiver_time_, "ms", |
| 618 | ImproveDirection::kSmallerIsBetter); |
| 619 | PrintResult("network_time", network_time_, "ms", |
| 620 | ImproveDirection::kSmallerIsBetter); |
| 621 | PrintResult("total_delay_incl_network", end_to_end_, "ms", |
| 622 | ImproveDirection::kSmallerIsBetter); |
| 623 | PrintResult("time_between_rendered_frames", rendered_delta_, "ms", |
| 624 | ImproveDirection::kSmallerIsBetter); |
| 625 | PrintResult("encode_frame_rate", encode_frame_rate_, "fps", |
| 626 | ImproveDirection::kBiggerIsBetter); |
| 627 | PrintResult("encode_time", encode_time_ms_, "ms", |
| 628 | ImproveDirection::kSmallerIsBetter); |
| 629 | PrintResult("media_bitrate", media_bitrate_bps_, "bps", |
| 630 | ImproveDirection::kNone); |
| 631 | PrintResult("fec_bitrate", fec_bitrate_bps_, "bps", ImproveDirection::kNone); |
| 632 | PrintResult("send_bandwidth", send_bandwidth_bps_, "bps", |
| 633 | ImproveDirection::kNone); |
| 634 | PrintResult("pixels_per_frame", pixels_, "count", |
| 635 | ImproveDirection::kBiggerIsBetter); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 636 | |
Elad Alon | 58e0657 | 2019-05-08 15:34:24 +0200 | [diff] [blame] | 637 | test::PrintResult("decode_frame_rate", "", test_label_.c_str(), |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 638 | decode_frame_rate_, "fps", false, |
| 639 | ImproveDirection::kBiggerIsBetter); |
Elad Alon | 58e0657 | 2019-05-08 15:34:24 +0200 | [diff] [blame] | 640 | test::PrintResult("render_frame_rate", "", test_label_.c_str(), |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 641 | render_frame_rate_, "fps", false, |
| 642 | ImproveDirection::kBiggerIsBetter); |
Elad Alon | 58e0657 | 2019-05-08 15:34:24 +0200 | [diff] [blame] | 643 | |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 644 | // Record the time from the last freeze until the last rendered frame to |
| 645 | // ensure we cover the full timespan of the session. Otherwise the metric |
| 646 | // would penalize an early freeze followed by no freezes until the end. |
| 647 | time_between_freezes_.AddSample(last_render_time_ - last_unfreeze_time_ms_); |
| 648 | |
| 649 | // Freeze metrics. |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 650 | PrintResult("time_between_freezes", time_between_freezes_, "ms", |
| 651 | ImproveDirection::kBiggerIsBetter); |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 652 | |
| 653 | const double freeze_count_double = static_cast<double>(freeze_count_); |
| 654 | const double total_freezes_duration_ms_double = |
| 655 | static_cast<double>(total_freezes_duration_ms_); |
| 656 | const double total_frames_duration_ms_double = |
| 657 | static_cast<double>(total_frames_duration_ms_); |
| 658 | |
| 659 | if (total_frames_duration_ms_double > 0) { |
| 660 | test::PrintResult( |
| 661 | "freeze_duration_ratio", "", test_label_.c_str(), |
Artem Titov | ea9798c | 2019-07-31 14:27:42 +0200 | [diff] [blame] | 662 | total_freezes_duration_ms_double / total_frames_duration_ms_double, |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 663 | "unitless", false, ImproveDirection::kSmallerIsBetter); |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 664 | RTC_DCHECK_LE(total_freezes_duration_ms_double, |
| 665 | total_frames_duration_ms_double); |
| 666 | |
| 667 | constexpr double ms_per_minute = 60 * 1000; |
| 668 | const double total_frames_duration_min = |
| 669 | total_frames_duration_ms_double / ms_per_minute; |
| 670 | if (total_frames_duration_min > 0) { |
| 671 | test::PrintResult("freeze_count_per_minute", "", test_label_.c_str(), |
| 672 | freeze_count_double / total_frames_duration_min, |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 673 | "unitless", false, ImproveDirection::kSmallerIsBetter); |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
Elad Alon | 133f7e7 | 2019-05-08 09:51:56 +0200 | [diff] [blame] | 677 | test::PrintResult("freeze_duration_average", "", test_label_.c_str(), |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 678 | freeze_count_double > 0 |
| 679 | ? total_freezes_duration_ms_double / freeze_count_double |
| 680 | : 0, |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 681 | "ms", false, ImproveDirection::kSmallerIsBetter); |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 682 | |
| 683 | if (1000 * sum_squared_frame_durations_ > 0) { |
| 684 | test::PrintResult( |
| 685 | "harmonic_frame_rate", "", test_label_.c_str(), |
| 686 | total_frames_duration_ms_double / (1000 * sum_squared_frame_durations_), |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 687 | "fps", false, ImproveDirection::kBiggerIsBetter); |
Elad Alon | 8c513c7 | 2019-05-07 21:22:24 +0200 | [diff] [blame] | 688 | } |
| 689 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 690 | if (worst_frame_) { |
| 691 | test::PrintResult("min_psnr", "", test_label_.c_str(), worst_frame_->psnr, |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 692 | "dB", false, ImproveDirection::kBiggerIsBetter); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | if (receive_stream_ != nullptr) { |
Johannes Kron | a1b99b3 | 2019-07-30 15:08:16 +0200 | [diff] [blame] | 696 | PrintResultWithExternalMean("decode_time", mean_decode_time_ms_, |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 697 | decode_time_ms_, "ms", |
| 698 | ImproveDirection::kSmallerIsBetter); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 699 | } |
Yves Gerey | 0c67c80 | 2019-08-01 17:45:54 +0200 | [diff] [blame] | 700 | dropped_frames_ += dropped_frames_diff; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 701 | test::PrintResult("dropped_frames", "", test_label_.c_str(), dropped_frames_, |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 702 | "count", false, ImproveDirection::kSmallerIsBetter); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 703 | test::PrintResult("cpu_usage", "", test_label_.c_str(), GetCpuUsagePercent(), |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 704 | "%", false, ImproveDirection::kSmallerIsBetter); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 705 | |
| 706 | #if defined(WEBRTC_WIN) |
| 707 | // On Linux and Mac in Resident Set some unused pages may be counted. |
| 708 | // Therefore this metric will depend on order in which tests are run and |
| 709 | // will be flaky. |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 710 | PrintResult("memory_usage", memory_usage_, "sizeInBytes", |
| 711 | ImproveDirection::kSmallerIsBetter); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 712 | #endif |
| 713 | |
| 714 | // Saving only the worst frame for manual analysis. Intention here is to |
| 715 | // only detect video corruptions and not to track picture quality. Thus, |
| 716 | // jpeg is used here. |
Mirko Bonadei | 2ab97f6 | 2019-07-18 13:44:12 +0200 | [diff] [blame] | 717 | if (absl::GetFlag(FLAGS_save_worst_frame) && worst_frame_) { |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 718 | std::string output_dir; |
| 719 | test::GetTestArtifactsDir(&output_dir); |
| 720 | std::string output_path = |
Niels Möller | 7b3c76b | 2018-11-07 09:54:28 +0100 | [diff] [blame] | 721 | test::JoinFilename(output_dir, test_label_ + ".jpg"); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 722 | RTC_LOG(LS_INFO) << "Saving worst frame to " << output_path; |
| 723 | test::JpegFrameWriter frame_writer(output_path); |
| 724 | RTC_CHECK( |
| 725 | frame_writer.WriteFrame(worst_frame_->frame, 100 /*best quality*/)); |
| 726 | } |
| 727 | |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 728 | if (audio_receive_stream_ != nullptr) { |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 729 | PrintResult("audio_expand_rate", audio_expand_rate_, "unitless", |
| 730 | ImproveDirection::kSmallerIsBetter); |
| 731 | PrintResult("audio_accelerate_rate", audio_accelerate_rate_, "unitless", |
| 732 | ImproveDirection::kSmallerIsBetter); |
| 733 | PrintResult("audio_jitter_buffer", audio_jitter_buffer_ms_, "ms", |
| 734 | ImproveDirection::kNone); |
Christoffer Rodbro | c2a0288 | 2018-08-07 14:10:56 +0200 | [diff] [blame] | 735 | } |
| 736 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 737 | // Disable quality check for quick test, as quality checks may fail |
| 738 | // because too few samples were collected. |
| 739 | if (!is_quick_test_enabled_) { |
Yves Gerey | 79e9f4b | 2019-04-13 18:59:53 +0200 | [diff] [blame] | 740 | EXPECT_GT(*psnr_.GetMean(), avg_psnr_threshold_); |
| 741 | EXPECT_GT(*ssim_.GetMean(), avg_ssim_threshold_); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | |
| 745 | void VideoAnalyzer::PerformFrameComparison( |
| 746 | const VideoAnalyzer::FrameComparison& comparison) { |
| 747 | // Perform expensive psnr and ssim calculations while not holding lock. |
| 748 | double psnr = -1.0; |
| 749 | double ssim = -1.0; |
| 750 | if (comparison.reference && !comparison.dropped) { |
| 751 | psnr = I420PSNR(&*comparison.reference, &*comparison.render); |
| 752 | ssim = I420SSIM(&*comparison.reference, &*comparison.render); |
| 753 | } |
| 754 | |
| 755 | rtc::CritScope crit(&comparison_lock_); |
| 756 | |
| 757 | if (psnr >= 0.0 && (!worst_frame_ || worst_frame_->psnr > psnr)) { |
| 758 | worst_frame_.emplace(FrameWithPsnr{psnr, *comparison.render}); |
| 759 | } |
| 760 | |
| 761 | if (graph_data_output_file_) { |
| 762 | samples_.push_back(Sample(comparison.dropped, comparison.input_time_ms, |
| 763 | comparison.send_time_ms, comparison.recv_time_ms, |
| 764 | comparison.render_time_ms, |
| 765 | comparison.encoded_frame_size, psnr, ssim)); |
| 766 | } |
| 767 | if (psnr >= 0.0) |
| 768 | psnr_.AddSample(psnr); |
| 769 | if (ssim >= 0.0) |
| 770 | ssim_.AddSample(ssim); |
| 771 | |
| 772 | if (comparison.dropped) { |
| 773 | ++dropped_frames_; |
| 774 | return; |
| 775 | } |
| 776 | if (last_unfreeze_time_ms_ == 0) |
| 777 | last_unfreeze_time_ms_ = comparison.render_time_ms; |
| 778 | if (last_render_time_ != 0) { |
| 779 | const int64_t render_delta_ms = |
| 780 | comparison.render_time_ms - last_render_time_; |
| 781 | rendered_delta_.AddSample(render_delta_ms); |
| 782 | if (last_render_delta_ms_ != 0 && |
| 783 | render_delta_ms - last_render_delta_ms_ > 150) { |
| 784 | time_between_freezes_.AddSample(last_render_time_ - |
| 785 | last_unfreeze_time_ms_); |
| 786 | last_unfreeze_time_ms_ = comparison.render_time_ms; |
| 787 | } |
| 788 | last_render_delta_ms_ = render_delta_ms; |
| 789 | } |
| 790 | last_render_time_ = comparison.render_time_ms; |
| 791 | |
| 792 | sender_time_.AddSample(comparison.send_time_ms - comparison.input_time_ms); |
| 793 | if (comparison.recv_time_ms > 0) { |
| 794 | // If recv_time_ms == 0, this frame consisted of a packets which were all |
| 795 | // lost in the transport. Since we were able to render the frame, however, |
| 796 | // the dropped packets were recovered by FlexFEC. The FlexFEC recovery |
| 797 | // happens internally in Call, and we can therefore here not know which |
| 798 | // FEC packets that protected the lost media packets. Consequently, we |
| 799 | // were not able to record a meaningful recv_time_ms. We therefore skip |
| 800 | // this sample. |
| 801 | // |
| 802 | // The reasoning above does not hold for ULPFEC and RTX, as for those |
| 803 | // strategies the timestamp of the received packets is set to the |
| 804 | // timestamp of the protected/retransmitted media packet. I.e., then |
| 805 | // recv_time_ms != 0, even though the media packets were lost. |
| 806 | receiver_time_.AddSample(comparison.render_time_ms - |
| 807 | comparison.recv_time_ms); |
| 808 | network_time_.AddSample(comparison.recv_time_ms - comparison.send_time_ms); |
| 809 | } |
| 810 | end_to_end_.AddSample(comparison.render_time_ms - comparison.input_time_ms); |
| 811 | encoded_frame_size_.AddSample(comparison.encoded_frame_size); |
| 812 | } |
| 813 | |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 814 | void VideoAnalyzer::PrintResult( |
| 815 | const char* result_type, |
| 816 | Statistics stats, |
| 817 | const char* unit, |
| 818 | webrtc::test::ImproveDirection improve_direction) { |
Yves Gerey | 79e9f4b | 2019-04-13 18:59:53 +0200 | [diff] [blame] | 819 | test::PrintResultMeanAndError( |
| 820 | result_type, "", test_label_.c_str(), stats.GetMean().value_or(0), |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 821 | stats.GetStandardDeviation().value_or(0), unit, false, improve_direction); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 822 | } |
| 823 | |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 824 | void VideoAnalyzer::PrintResultWithExternalMean( |
| 825 | const char* result_type, |
| 826 | double mean, |
| 827 | Statistics stats, |
| 828 | const char* unit, |
| 829 | webrtc::test::ImproveDirection improve_direction) { |
Johannes Kron | a1b99b3 | 2019-07-30 15:08:16 +0200 | [diff] [blame] | 830 | // If the true mean is different than the sample mean, the sample variance is |
| 831 | // too low. The sample variance given a known mean is obtained by adding the |
| 832 | // squared error between the true mean and the sample mean. |
| 833 | double compensated_variance = |
| 834 | stats.Size() > 0 |
| 835 | ? *stats.GetVariance() + pow(mean - *stats.GetMean(), 2.0) |
| 836 | : 0.0; |
| 837 | test::PrintResultMeanAndError(result_type, "", test_label_.c_str(), mean, |
Artem Titov | 82ce384 | 2019-09-23 17:55:52 +0200 | [diff] [blame] | 838 | std::sqrt(compensated_variance), unit, false, |
| 839 | improve_direction); |
Johannes Kron | a1b99b3 | 2019-07-30 15:08:16 +0200 | [diff] [blame] | 840 | } |
| 841 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 842 | void VideoAnalyzer::PrintSamplesToFile() { |
| 843 | FILE* out = graph_data_output_file_; |
| 844 | rtc::CritScope crit(&comparison_lock_); |
Steve Anton | bd631a0 | 2019-03-28 10:51:27 -0700 | [diff] [blame] | 845 | absl::c_sort(samples_, [](const Sample& A, const Sample& B) -> bool { |
| 846 | return A.input_time_ms < B.input_time_ms; |
| 847 | }); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 848 | |
| 849 | fprintf(out, "%s\n", graph_title_.c_str()); |
Oleh Prypin | b168678 | 2019-08-02 09:36:47 +0200 | [diff] [blame] | 850 | fprintf(out, "%" RTC_PRIuS "\n", samples_.size()); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 851 | fprintf(out, |
| 852 | "dropped " |
| 853 | "input_time_ms " |
| 854 | "send_time_ms " |
| 855 | "recv_time_ms " |
| 856 | "render_time_ms " |
| 857 | "encoded_frame_size " |
| 858 | "psnr " |
| 859 | "ssim " |
| 860 | "encode_time_ms\n"); |
| 861 | for (const Sample& sample : samples_) { |
| 862 | fprintf(out, |
Oleh Prypin | b168678 | 2019-08-02 09:36:47 +0200 | [diff] [blame] | 863 | "%d %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" RTC_PRIuS |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 864 | " %lf %lf\n", |
| 865 | sample.dropped, sample.input_time_ms, sample.send_time_ms, |
| 866 | sample.recv_time_ms, sample.render_time_ms, |
| 867 | sample.encoded_frame_size, sample.psnr, sample.ssim); |
| 868 | } |
| 869 | } |
| 870 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 871 | void VideoAnalyzer::AddCapturedFrameForComparison( |
| 872 | const VideoFrame& video_frame) { |
Yves Gerey | 0c67c80 | 2019-08-01 17:45:54 +0200 | [diff] [blame] | 873 | bool must_capture = false; |
| 874 | { |
| 875 | rtc::CritScope lock(&comparison_lock_); |
| 876 | must_capture = captured_frames_ < frames_to_process_; |
| 877 | if (must_capture) { |
| 878 | ++captured_frames_; |
| 879 | } |
| 880 | } |
| 881 | if (must_capture) { |
| 882 | rtc::CritScope lock(&crit_); |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 883 | frames_.push_back(video_frame); |
| 884 | } |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | void VideoAnalyzer::AddFrameComparison(const VideoFrame& reference, |
| 888 | const VideoFrame& render, |
| 889 | bool dropped, |
| 890 | int64_t render_time_ms) { |
| 891 | int64_t reference_timestamp = wrap_handler_.Unwrap(reference.timestamp()); |
| 892 | int64_t send_time_ms = send_times_[reference_timestamp]; |
| 893 | send_times_.erase(reference_timestamp); |
| 894 | int64_t recv_time_ms = recv_times_[reference_timestamp]; |
| 895 | recv_times_.erase(reference_timestamp); |
| 896 | |
| 897 | // TODO(ivica): Make this work for > 2 streams. |
| 898 | auto it = encoded_frame_sizes_.find(reference_timestamp); |
| 899 | if (it == encoded_frame_sizes_.end()) |
| 900 | it = encoded_frame_sizes_.find(reference_timestamp - 1); |
| 901 | size_t encoded_size = it == encoded_frame_sizes_.end() ? 0 : it->second; |
| 902 | if (it != encoded_frame_sizes_.end()) |
| 903 | encoded_frame_sizes_.erase(it); |
| 904 | |
| 905 | rtc::CritScope crit(&comparison_lock_); |
| 906 | if (comparisons_.size() < kMaxComparisons) { |
| 907 | comparisons_.push_back(FrameComparison( |
| 908 | reference, render, dropped, reference.ntp_time_ms(), send_time_ms, |
| 909 | recv_time_ms, render_time_ms, encoded_size)); |
| 910 | } else { |
| 911 | comparisons_.push_back(FrameComparison(dropped, reference.ntp_time_ms(), |
| 912 | send_time_ms, recv_time_ms, |
| 913 | render_time_ms, encoded_size)); |
| 914 | } |
| 915 | comparison_available_event_.Set(); |
| 916 | } |
| 917 | |
| 918 | VideoAnalyzer::FrameComparison::FrameComparison() |
| 919 | : dropped(false), |
| 920 | input_time_ms(0), |
| 921 | send_time_ms(0), |
| 922 | recv_time_ms(0), |
| 923 | render_time_ms(0), |
| 924 | encoded_frame_size(0) {} |
| 925 | |
| 926 | VideoAnalyzer::FrameComparison::FrameComparison(const VideoFrame& reference, |
| 927 | const VideoFrame& render, |
| 928 | bool dropped, |
| 929 | int64_t input_time_ms, |
| 930 | int64_t send_time_ms, |
| 931 | int64_t recv_time_ms, |
| 932 | int64_t render_time_ms, |
| 933 | size_t encoded_frame_size) |
| 934 | : reference(reference), |
| 935 | render(render), |
| 936 | dropped(dropped), |
| 937 | input_time_ms(input_time_ms), |
| 938 | send_time_ms(send_time_ms), |
| 939 | recv_time_ms(recv_time_ms), |
| 940 | render_time_ms(render_time_ms), |
| 941 | encoded_frame_size(encoded_frame_size) {} |
| 942 | |
| 943 | VideoAnalyzer::FrameComparison::FrameComparison(bool dropped, |
| 944 | int64_t input_time_ms, |
| 945 | int64_t send_time_ms, |
| 946 | int64_t recv_time_ms, |
| 947 | int64_t render_time_ms, |
| 948 | size_t encoded_frame_size) |
| 949 | : dropped(dropped), |
| 950 | input_time_ms(input_time_ms), |
| 951 | send_time_ms(send_time_ms), |
| 952 | recv_time_ms(recv_time_ms), |
| 953 | render_time_ms(render_time_ms), |
| 954 | encoded_frame_size(encoded_frame_size) {} |
| 955 | |
| 956 | VideoAnalyzer::Sample::Sample(int dropped, |
| 957 | int64_t input_time_ms, |
| 958 | int64_t send_time_ms, |
| 959 | int64_t recv_time_ms, |
| 960 | int64_t render_time_ms, |
| 961 | size_t encoded_frame_size, |
| 962 | double psnr, |
| 963 | double ssim) |
| 964 | : dropped(dropped), |
| 965 | input_time_ms(input_time_ms), |
| 966 | send_time_ms(send_time_ms), |
| 967 | recv_time_ms(recv_time_ms), |
| 968 | render_time_ms(render_time_ms), |
| 969 | encoded_frame_size(encoded_frame_size), |
| 970 | psnr(psnr), |
| 971 | ssim(ssim) {} |
| 972 | |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 973 | VideoAnalyzer::CapturedFrameForwarder::CapturedFrameForwarder( |
| 974 | VideoAnalyzer* analyzer, |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 975 | Clock* clock, |
Ilya Nikolaevskiy | 85fc325 | 2019-02-11 10:41:50 +0100 | [diff] [blame] | 976 | int frames_to_process) |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 977 | : analyzer_(analyzer), |
| 978 | send_stream_input_(nullptr), |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 979 | video_source_(nullptr), |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 980 | clock_(clock), |
| 981 | captured_frames_(0), |
Ilya Nikolaevskiy | 85fc325 | 2019-02-11 10:41:50 +0100 | [diff] [blame] | 982 | frames_to_process_(frames_to_process) {} |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 983 | |
| 984 | void VideoAnalyzer::CapturedFrameForwarder::SetSource( |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 985 | VideoSourceInterface<VideoFrame>* video_source) { |
| 986 | video_source_ = video_source; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | void VideoAnalyzer::CapturedFrameForwarder::OnFrame( |
| 990 | const VideoFrame& video_frame) { |
| 991 | VideoFrame copy = video_frame; |
| 992 | // Frames from the capturer does not have a rtp timestamp. |
| 993 | // Create one so it can be used for comparison. |
| 994 | RTC_DCHECK_EQ(0, video_frame.timestamp()); |
| 995 | if (video_frame.ntp_time_ms() == 0) |
| 996 | copy.set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()); |
| 997 | copy.set_timestamp(copy.ntp_time_ms() * 90); |
| 998 | analyzer_->AddCapturedFrameForComparison(copy); |
| 999 | rtc::CritScope lock(&crit_); |
Ilya Nikolaevskiy | 6957abe | 2019-01-29 16:33:04 +0100 | [diff] [blame] | 1000 | ++captured_frames_; |
Ilya Nikolaevskiy | 85fc325 | 2019-02-11 10:41:50 +0100 | [diff] [blame] | 1001 | if (send_stream_input_ && captured_frames_ <= frames_to_process_) |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 1002 | send_stream_input_->OnFrame(copy); |
| 1003 | } |
| 1004 | |
| 1005 | void VideoAnalyzer::CapturedFrameForwarder::AddOrUpdateSink( |
| 1006 | rtc::VideoSinkInterface<VideoFrame>* sink, |
| 1007 | const rtc::VideoSinkWants& wants) { |
| 1008 | { |
| 1009 | rtc::CritScope lock(&crit_); |
| 1010 | RTC_DCHECK(!send_stream_input_ || send_stream_input_ == sink); |
| 1011 | send_stream_input_ = sink; |
| 1012 | } |
Niels Möller | 1c931c4 | 2018-12-18 16:08:11 +0100 | [diff] [blame] | 1013 | if (video_source_) { |
| 1014 | video_source_->AddOrUpdateSink(this, wants); |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | void VideoAnalyzer::CapturedFrameForwarder::RemoveSink( |
| 1019 | rtc::VideoSinkInterface<VideoFrame>* sink) { |
| 1020 | rtc::CritScope lock(&crit_); |
| 1021 | RTC_DCHECK(sink == send_stream_input_); |
| 1022 | send_stream_input_ = nullptr; |
Sebastian Jansson | d4c5d63 | 2018-07-10 12:57:37 +0200 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | } // namespace webrtc |