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/numerics/samples_stats_counter.h" 19 #include "api/test/metrics/metrics_logger.h" 20 #include "api/test/peerconnection_quality_test_fixture.h" 21 #include "api/test/track_id_stream_info_map.h" 22 #include "api/units/data_size.h" 23 #include "api/units/timestamp.h" 24 #include "rtc_base/synchronization/mutex.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: 38 VideoQualityMetricsReporter(Clock* const clock, 39 test::MetricsLogger* const metrics_logger); 40 ~VideoQualityMetricsReporter() override = default; 41 42 void Start(absl::string_view test_case_name, 43 const TrackIdStreamInfoMap* reporter_helper) override; 44 void OnStatsReports( 45 absl::string_view pc_label, 46 const rtc::scoped_refptr<const RTCStatsReport>& report) override; 47 void StopAndReportResults() override; 48 49 private: 50 struct StatsSample { 51 DataSize bytes_sent = DataSize::Zero(); 52 DataSize header_bytes_sent = DataSize::Zero(); 53 DataSize retransmitted_bytes_sent = DataSize::Zero(); 54 55 Timestamp sample_time = Timestamp::Zero(); 56 }; 57 58 std::string GetTestCaseName(const std::string& peer_name) const; 59 void ReportVideoBweResults(const std::string& peer_name, 60 const VideoBweStats& video_bwe_stats); Now()61 Timestamp Now() const { return clock_->CurrentTime(); } 62 63 Clock* const clock_; 64 test::MetricsLogger* const metrics_logger_; 65 66 std::string test_case_name_; 67 absl::optional<Timestamp> start_time_; 68 69 Mutex video_bwe_stats_lock_; 70 // Map between a peer connection label (provided by the framework) and 71 // its video BWE stats. 72 std::map<std::string, VideoBweStats> video_bwe_stats_ 73 RTC_GUARDED_BY(video_bwe_stats_lock_); 74 std::map<std::string, StatsSample> last_stats_sample_ 75 RTC_GUARDED_BY(video_bwe_stats_lock_); 76 }; 77 78 } // namespace webrtc_pc_e2e 79 } // namespace webrtc 80 81 #endif // TEST_PC_E2E_ANALYZER_VIDEO_VIDEO_QUALITY_METRICS_REPORTER_H_ 82