xref: /aosp_15_r20/external/webrtc/test/pc/e2e/network_quality_metrics_reporter.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2019 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_NETWORK_QUALITY_METRICS_REPORTER_H_
12 #define TEST_PC_E2E_NETWORK_QUALITY_METRICS_REPORTER_H_
13 
14 #include <memory>
15 #include <string>
16 
17 #include "absl/strings/string_view.h"
18 #include "api/test/metrics/metrics_logger.h"
19 #include "api/test/network_emulation_manager.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 "rtc_base/synchronization/mutex.h"
24 
25 namespace webrtc {
26 namespace webrtc_pc_e2e {
27 
28 class NetworkQualityMetricsReporter
29     : public PeerConnectionE2EQualityTestFixture::QualityMetricsReporter {
30  public:
31   NetworkQualityMetricsReporter(EmulatedNetworkManagerInterface* alice_network,
32                                 EmulatedNetworkManagerInterface* bob_network,
33                                 test::MetricsLogger* metrics_logger);
34   ~NetworkQualityMetricsReporter() override = default;
35 
36   // Network stats must be empty when this method will be invoked.
37   void Start(absl::string_view test_case_name,
38              const TrackIdStreamInfoMap* reporter_helper) override;
39   void OnStatsReports(
40       absl::string_view pc_label,
41       const rtc::scoped_refptr<const RTCStatsReport>& report) override;
42   void StopAndReportResults() override;
43 
44  private:
45   struct PCStats {
46     // TODO(nisse): Separate audio and video counters. Depends on standard stat
47     // counters, enabled by field trial "WebRTC-UseStandardBytesStats".
48     DataSize payload_received = DataSize::Zero();
49     DataSize payload_sent = DataSize::Zero();
50   };
51 
52   static EmulatedNetworkStats PopulateStats(
53       EmulatedNetworkManagerInterface* network);
54   void ReportStats(const std::string& network_label,
55                    const EmulatedNetworkStats& stats,
56                    int64_t packet_loss);
57   void ReportPCStats(const std::string& pc_label, const PCStats& stats);
58   std::string GetTestCaseName(const std::string& network_label) const;
59 
60   std::string test_case_name_;
61 
62   EmulatedNetworkManagerInterface* const alice_network_;
63   EmulatedNetworkManagerInterface* const bob_network_;
64   test::MetricsLogger* const metrics_logger_;
65   Mutex lock_;
66   std::map<std::string, PCStats> pc_stats_ RTC_GUARDED_BY(lock_);
67 };
68 
69 }  // namespace webrtc_pc_e2e
70 }  // namespace webrtc
71 
72 #endif  // TEST_PC_E2E_NETWORK_QUALITY_METRICS_REPORTER_H_
73