stats_poller.h 1.9 KB

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