1 /* 2 * Copyright (c) 2020 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 11 #ifndef TEST_PC_E2E_ANALYZER_VIDEO_VIDEO_QUALITY_METRICS_REPORTER_H_ 12 #define TEST_PC_E2E_ANALYZER_VIDEO_VIDEO_QUALITY_METRICS_REPORTER_H_ 13 14 #include <map> 15 #include <string> 16 17 #include "absl/strings/string_view.h" 18 #include "api/test/peerconnection_quality_test_fixture.h" 19 #include "api/test/track_id_stream_info_map.h" 20 #include "api/units/data_size.h" 21 #include "api/units/timestamp.h" 22 #include "rtc_base/numerics/samples_stats_counter.h" 23 #include "rtc_base/synchronization/mutex.h" 24 #include "test/testsupport/perf_test.h" 25 26 namespace webrtc { 27 namespace webrtc_pc_e2e { 28 29 struct VideoBweStats { 30 SamplesStatsCounter available_send_bandwidth; 31 SamplesStatsCounter transmission_bitrate; 32 SamplesStatsCounter retransmission_bitrate; 33 }; 34 35 class VideoQualityMetricsReporter 36 : public PeerConnectionE2EQualityTestFixture::QualityMetricsReporter { 37 public: VideoQualityMetricsReporter(Clock * const clock)38 VideoQualityMetricsReporter(Clock* const clock) : clock_(clock) {} 39 ~VideoQualityMetricsReporter() override = default; 40 41 void Start(absl::string_view test_case_name, 42 const TrackIdStreamInfoMap* reporter_helper) override; 43 void OnStatsReports( 44 absl::string_view pc_label, 45 const rtc::scoped_refptr<const RTCStatsReport>& report) override; 46 void StopAndReportResults() override; 47 48 private: 49 struct StatsSample { 50 DataSize bytes_sent = DataSize::Zero(); 51 DataSize header_bytes_sent = DataSize::Zero(); 52 DataSize retransmitted_bytes_sent = DataSize::Zero(); 53 54 Timestamp sample_time = Timestamp::Zero(); 55 }; 56 57 std::string GetTestCaseName(const std::string& stream_label) const; 58 static void ReportVideoBweResults(const std::string& test_case_name, 59 const VideoBweStats& video_bwe_stats); 60 // Report result for single metric for specified stream. 61 static void ReportResult(const std::string& metric_name, 62 const std::string& test_case_name, 63 const SamplesStatsCounter& counter, 64 const std::string& unit, 65 webrtc::test::ImproveDirection improve_direction = 66 webrtc::test::ImproveDirection::kNone); Now()67 Timestamp Now() const { return clock_->CurrentTime(); } 68 69 Clock* const clock_; 70 71 std::string test_case_name_; 72 absl::optional<Timestamp> start_time_; 73 74 Mutex video_bwe_stats_lock_; 75 // Map between a peer connection label (provided by the framework) and 76 // its video BWE stats. 77 std::map<std::string, VideoBweStats> video_bwe_stats_ 78 RTC_GUARDED_BY(video_bwe_stats_lock_); 79 std::map<std::string, StatsSample> last_stats_sample_ 80 RTC_GUARDED_BY(video_bwe_stats_lock_); 81 }; 82 83 } // namespace webrtc_pc_e2e 84 } // namespace webrtc 85 86 #endif // TEST_PC_E2E_ANALYZER_VIDEO_VIDEO_QUALITY_METRICS_REPORTER_H_ 87