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_STATS_POLLER_H_ 12 #define TEST_PC_E2E_STATS_POLLER_H_ 13 14 #include <map> 15 #include <string> 16 #include <utility> 17 #include <vector> 18 19 #include "api/peer_connection_interface.h" 20 #include "api/stats/rtc_stats_collector_callback.h" 21 #include "api/test/stats_observer_interface.h" 22 #include "test/pc/e2e/test_peer.h" 23 24 namespace webrtc { 25 namespace webrtc_pc_e2e { 26 27 // Helper class that will notify all the webrtc::test::StatsObserverInterface 28 // objects subscribed. 29 class InternalStatsObserver : public RTCStatsCollectorCallback { 30 public: InternalStatsObserver(std::string pc_label,TestPeer * peer,std::vector<StatsObserverInterface * > observers)31 InternalStatsObserver(std::string pc_label, 32 TestPeer* peer, 33 std::vector<StatsObserverInterface*> observers) 34 : pc_label_(std::move(pc_label)), 35 peer_(peer), 36 observers_(std::move(observers)) {} 37 38 void PollStats(); 39 40 void OnStatsDelivered( 41 const rtc::scoped_refptr<const RTCStatsReport>& report) override; 42 43 private: 44 std::string pc_label_; 45 TestPeer* peer_; 46 std::vector<StatsObserverInterface*> observers_; 47 }; 48 49 // Helper class to invoke GetStats on a PeerConnection by passing a 50 // webrtc::StatsObserver that will notify all the 51 // webrtc::test::StatsObserverInterface subscribed. 52 class StatsPoller { 53 public: 54 StatsPoller(std::vector<StatsObserverInterface*> observers, 55 std::map<std::string, TestPeer*> peers_to_observe); 56 57 void PollStatsAndNotifyObservers(); 58 59 private: 60 std::vector<rtc::scoped_refptr<InternalStatsObserver>> pollers_; 61 }; 62 63 } // namespace webrtc_pc_e2e 64 } // namespace webrtc 65 66 #endif // TEST_PC_E2E_STATS_POLLER_H_ 67