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