diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn index 8c6fec0efa..355e65a8cb 100644 --- a/test/pc/e2e/BUILD.gn +++ b/test/pc/e2e/BUILD.gn @@ -444,6 +444,7 @@ if (!build_with_chromium) { deps = [ ":default_audio_quality_analyzer", ":default_video_quality_analyzer", + ":default_video_quality_analyzer_shared", ":network_quality_metrics_reporter", ":stats_based_network_quality_metrics_reporter", "../../../api:callfactory_api", @@ -502,6 +503,7 @@ if (!build_with_chromium) { sources = [ "analyzer/video/default_video_quality_analyzer_test.cc" ] deps = [ ":default_video_quality_analyzer", + ":default_video_quality_analyzer_shared", "../..:test_support", "../../../api:create_frame_generator", "../../../api:rtp_packet_info", @@ -617,11 +619,11 @@ if (!build_with_chromium) { sources = [ "analyzer/video/default_video_quality_analyzer.cc", "analyzer/video/default_video_quality_analyzer.h", - "analyzer/video/default_video_quality_analyzer_shared_objects.cc", - "analyzer/video/default_video_quality_analyzer_shared_objects.h", ] deps = [ + ":default_video_quality_analyzer_internal", + ":default_video_quality_analyzer_shared", ":multi_head_queue", "../..:perf_test", "../../../api:array_view", @@ -645,6 +647,46 @@ if (!build_with_chromium) { "../../../rtc_tools:video_quality_analysis", "../../../system_wrappers", ] + absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] + } + + # This target contains implementation details of DefaultVideoQualityAnalyzer, + # so headers exported by it shouldn't be used in other places. + rtc_library("default_video_quality_analyzer_internal") { + visibility = [ ":default_video_quality_analyzer" ] + + testonly = true + sources = [ + "analyzer/video/default_video_quality_analyzer_internal_shared_objects.cc", + "analyzer/video/default_video_quality_analyzer_internal_shared_objects.h", + ] + + deps = [ + ":default_video_quality_analyzer_shared", + "../../../api/numerics:numerics", + "../../../api/units:timestamp", + "../../../api/video:video_frame", + "../../../rtc_base:stringutils", + ] + absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] + } + + rtc_library("default_video_quality_analyzer_shared") { + visibility = [ "*" ] + + testonly = true + sources = [ + "analyzer/video/default_video_quality_analyzer_shared_objects.cc", + "analyzer/video/default_video_quality_analyzer_shared_objects.h", + ] + + deps = [ + "../../../api/numerics:numerics", + "../../../api/units:timestamp", + "../../../rtc_base:checks", + "../../../rtc_base:stringutils", + ] + absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] } rtc_library("network_quality_metrics_reporter") { diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc index a40782ba0d..fc8fea4289 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.cc @@ -25,6 +25,7 @@ #include "rtc_base/strings/string_builder.h" #include "rtc_base/time_utils.h" #include "rtc_tools/frame_analyzer/video_geometry_aligner.h" +#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.h" #include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.h" namespace webrtc { @@ -1027,20 +1028,6 @@ double DefaultVideoQualityAnalyzer::GetCpuUsagePercent() { return static_cast(cpu_time_) / wallclock_time_ * 100.0; } -DefaultVideoQualityAnalyzer::FrameComparison::FrameComparison( - InternalStatsKey stats_key, - absl::optional captured, - absl::optional rendered, - bool dropped, - FrameStats frame_stats, - OverloadReason overload_reason) - : stats_key(std::move(stats_key)), - captured(std::move(captured)), - rendered(std::move(rendered)), - dropped(dropped), - frame_stats(std::move(frame_stats)), - overload_reason(overload_reason) {} - uint16_t DefaultVideoQualityAnalyzer::StreamState::PopFront(size_t peer) { absl::optional frame_id = frame_ids_.PopFront(peer); RTC_DCHECK(frame_id.has_value()); @@ -1217,8 +1204,8 @@ bool DefaultVideoQualityAnalyzer::FrameInFlight::HasRenderedTime( return it->second.rendered_time.IsFinite(); } -DefaultVideoQualityAnalyzer::FrameStats -DefaultVideoQualityAnalyzer::FrameInFlight::GetStatsForPeer(size_t peer) const { +FrameStats DefaultVideoQualityAnalyzer::FrameInFlight::GetStatsForPeer( + size_t peer) const { FrameStats stats(captured_time_); stats.pre_encode_time = pre_encode_time_; stats.encoded_time = encoded_time_; diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h index 1b8c661342..6c7507b6a8 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer.h @@ -29,6 +29,7 @@ #include "rtc_base/platform_thread.h" #include "rtc_base/synchronization/mutex.h" #include "system_wrappers/include/clock.h" +#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.h" #include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.h" #include "test/pc/e2e/analyzer/video/multi_head_queue.h" #include "test/testsupport/perf_test.h" @@ -113,73 +114,6 @@ class DefaultVideoQualityAnalyzer : public VideoQualityAnalyzerInterface { double GetCpuUsagePercent(); private: - // Final stats computed for frame after it went through the whole video - // pipeline from capturing to rendering or dropping. - struct FrameStats { - FrameStats(Timestamp captured_time) : captured_time(captured_time) {} - - // Frame events timestamp. - Timestamp captured_time; - Timestamp pre_encode_time = Timestamp::MinusInfinity(); - Timestamp encoded_time = Timestamp::MinusInfinity(); - // Time when last packet of a frame was received. - Timestamp received_time = Timestamp::MinusInfinity(); - Timestamp decode_start_time = Timestamp::MinusInfinity(); - Timestamp decode_end_time = Timestamp::MinusInfinity(); - Timestamp rendered_time = Timestamp::MinusInfinity(); - Timestamp prev_frame_rendered_time = Timestamp::MinusInfinity(); - - int64_t encoded_image_size = 0; - uint32_t target_encode_bitrate = 0; - - absl::optional rendered_frame_width = absl::nullopt; - absl::optional rendered_frame_height = absl::nullopt; - - // Can be not set if frame was dropped by encoder. - absl::optional used_encoder = absl::nullopt; - // Can be not set if frame was dropped in the network. - absl::optional used_decoder = absl::nullopt; - }; - - // Describes why comparison was done in overloaded mode (without calculating - // PSNR and SSIM). - enum class OverloadReason { - kNone, - // Not enough CPU to process all incoming comparisons. - kCpu, - // Not enough memory to store captured frames for all comparisons. - kMemory - }; - - // Represents comparison between two VideoFrames. Contains video frames itself - // and stats. Can be one of two types: - // 1. Normal - in this case `captured` is presented and either `rendered` is - // presented and `dropped` is false, either `rendered` is omitted and - // `dropped` is true. - // 2. Overloaded - in this case both `captured` and `rendered` are omitted - // because there were too many comparisons in the queue. `dropped` can be - // true or false showing was frame dropped or not. - struct FrameComparison { - FrameComparison(InternalStatsKey stats_key, - absl::optional captured, - absl::optional rendered, - bool dropped, - FrameStats frame_stats, - OverloadReason overload_reason); - - InternalStatsKey stats_key; - // Frames can be omitted if there too many computations waiting in the - // queue. - absl::optional captured; - absl::optional rendered; - // If true frame was dropped somewhere from capturing to rendering and - // wasn't rendered on remote peer side. If `dropped` is true, `rendered` - // will be `absl::nullopt`. - bool dropped; - FrameStats frame_stats; - OverloadReason overload_reason; - }; - // Represents a current state of video stream. class StreamState { public: diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.cc b/test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.cc new file mode 100644 index 0000000000..cb1d93914c --- /dev/null +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.cc @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ +#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.h" + +#include "api/video/video_frame.h" +#include "rtc_base/strings/string_builder.h" + +namespace webrtc { + +std::string InternalStatsKey::ToString() const { + rtc::StringBuilder out; + out << "stream=" << stream << "_sender=" << sender + << "_receiver=" << receiver; + return out.str(); +} + +bool operator<(const InternalStatsKey& a, const InternalStatsKey& b) { + if (a.stream != b.stream) { + return a.stream < b.stream; + } + if (a.sender != b.sender) { + return a.sender < b.sender; + } + return a.receiver < b.receiver; +} + +bool operator==(const InternalStatsKey& a, const InternalStatsKey& b) { + return a.stream == b.stream && a.sender == b.sender && + a.receiver == b.receiver; +} + +FrameComparison::FrameComparison(InternalStatsKey stats_key, + absl::optional captured, + absl::optional rendered, + bool dropped, + FrameStats frame_stats, + OverloadReason overload_reason) + : stats_key(std::move(stats_key)), + captured(std::move(captured)), + rendered(std::move(rendered)), + dropped(dropped), + frame_stats(std::move(frame_stats)), + overload_reason(overload_reason) {} + +} // namespace webrtc diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.h b/test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.h new file mode 100644 index 0000000000..6e275f47ad --- /dev/null +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef TEST_PC_E2E_ANALYZER_VIDEO_DEFAULT_VIDEO_QUALITY_ANALYZER_INTERNAL_SHARED_OBJECTS_H_ +#define TEST_PC_E2E_ANALYZER_VIDEO_DEFAULT_VIDEO_QUALITY_ANALYZER_INTERNAL_SHARED_OBJECTS_H_ + +#include +#include +#include + +#include "absl/types/optional.h" +#include "api/units/timestamp.h" +#include "api/video/video_frame.h" +#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.h" + +namespace webrtc { + +struct InternalStatsKey { + InternalStatsKey(size_t stream, size_t sender, size_t receiver) + : stream(stream), sender(sender), receiver(receiver) {} + + std::string ToString() const; + + size_t stream; + size_t sender; + size_t receiver; +}; + +// Required to use InternalStatsKey as std::map key. +bool operator<(const InternalStatsKey& a, const InternalStatsKey& b); +bool operator==(const InternalStatsKey& a, const InternalStatsKey& b); + +// Final stats computed for frame after it went through the whole video +// pipeline from capturing to rendering or dropping. +struct FrameStats { + explicit FrameStats(Timestamp captured_time) : captured_time(captured_time) {} + + // Frame events timestamp. + Timestamp captured_time; + Timestamp pre_encode_time = Timestamp::MinusInfinity(); + Timestamp encoded_time = Timestamp::MinusInfinity(); + // Time when last packet of a frame was received. + Timestamp received_time = Timestamp::MinusInfinity(); + Timestamp decode_start_time = Timestamp::MinusInfinity(); + Timestamp decode_end_time = Timestamp::MinusInfinity(); + Timestamp rendered_time = Timestamp::MinusInfinity(); + Timestamp prev_frame_rendered_time = Timestamp::MinusInfinity(); + + int64_t encoded_image_size = 0; + uint32_t target_encode_bitrate = 0; + + absl::optional rendered_frame_width = absl::nullopt; + absl::optional rendered_frame_height = absl::nullopt; + + // Can be not set if frame was dropped by encoder. + absl::optional used_encoder = absl::nullopt; + // Can be not set if frame was dropped in the network. + absl::optional used_decoder = absl::nullopt; +}; + +// Describes why comparison was done in overloaded mode (without calculating +// PSNR and SSIM). +enum class OverloadReason { + kNone, + // Not enough CPU to process all incoming comparisons. + kCpu, + // Not enough memory to store captured frames for all comparisons. + kMemory +}; + +// Represents comparison between two VideoFrames. Contains video frames itself +// and stats. Can be one of two types: +// 1. Normal - in this case `captured` is presented and either `rendered` is +// presented and `dropped` is false, either `rendered` is omitted and +// `dropped` is true. +// 2. Overloaded - in this case both `captured` and `rendered` are omitted +// because there were too many comparisons in the queue. `dropped` can be +// true or false showing was frame dropped or not. +struct FrameComparison { + FrameComparison(InternalStatsKey stats_key, + absl::optional captured, + absl::optional rendered, + bool dropped, + FrameStats frame_stats, + OverloadReason overload_reason); + + InternalStatsKey stats_key; + // Frames can be omitted if there too many computations waiting in the + // queue. + absl::optional captured; + absl::optional rendered; + // If true frame was dropped somewhere from capturing to rendering and + // wasn't rendered on remote peer side. If `dropped` is true, `rendered` + // will be `absl::nullopt`. + bool dropped; + FrameStats frame_stats; + OverloadReason overload_reason; +}; + +} // namespace webrtc + +#endif // TEST_PC_E2E_ANALYZER_VIDEO_DEFAULT_VIDEO_QUALITY_ANALYZER_INTERNAL_SHARED_OBJECTS_H_ diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.cc b/test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.cc index c2705d85cf..d82309174f 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.cc +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.cc @@ -59,27 +59,5 @@ bool operator==(const StatsKey& a, const StatsKey& b) { a.receiver == b.receiver; } -std::string InternalStatsKey::ToString() const { - rtc::StringBuilder out; - out << "stream=" << stream << "_sender=" << sender - << "_receiver=" << receiver; - return out.str(); -} - -bool operator<(const InternalStatsKey& a, const InternalStatsKey& b) { - if (a.stream != b.stream) { - return a.stream < b.stream; - } - if (a.sender != b.sender) { - return a.sender < b.sender; - } - return a.receiver < b.receiver; -} - -bool operator==(const InternalStatsKey& a, const InternalStatsKey& b) { - return a.stream == b.stream && a.sender == b.sender && - a.receiver == b.receiver; -} - } // namespace webrtc_pc_e2e } // namespace webrtc diff --git a/test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.h b/test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.h index ad507ae427..b5fdedd629 100644 --- a/test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.h +++ b/test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.h @@ -16,6 +16,7 @@ #include #include +#include "absl/types/optional.h" #include "api/numerics/samples_stats_counter.h" #include "api/units/timestamp.h" @@ -164,21 +165,6 @@ struct StatsKey { bool operator<(const StatsKey& a, const StatsKey& b); bool operator==(const StatsKey& a, const StatsKey& b); -struct InternalStatsKey { - InternalStatsKey(size_t stream, size_t sender, size_t receiver) - : stream(stream), sender(sender), receiver(receiver) {} - - std::string ToString() const; - - size_t stream; - size_t sender; - size_t receiver; -}; - -// Required to use InternalStatsKey as std::map key. -bool operator<(const InternalStatsKey& a, const InternalStatsKey& b); -bool operator==(const InternalStatsKey& a, const InternalStatsKey& b); - } // namespace webrtc_pc_e2e } // namespace webrtc