analyzer_helper.h 2.3 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_ANALYZER_HELPER_H_
  11. #define TEST_PC_E2E_ANALYZER_HELPER_H_
  12. #include <map>
  13. #include <string>
  14. #include "absl/strings/string_view.h"
  15. #include "api/test/track_id_stream_info_map.h"
  16. #include "rtc_base/synchronization/sequence_checker.h"
  17. #include "rtc_base/thread_annotations.h"
  18. namespace webrtc {
  19. namespace webrtc_pc_e2e {
  20. // This class is a utility that provides bookkeeping capabilities that
  21. // are useful to associate stats reports track_ids to the remote stream info.
  22. // The framework will populate an instance of this class and it will pass
  23. // it to the Start method of Media Quality Analyzers.
  24. // An instance of AnalyzerHelper must only be accessed from a single
  25. // thread and since stats collection happens on the signaling thread,
  26. // AddTrackToStreamMapping, GetStreamLabelFromTrackId and
  27. // GetSyncGroupLabelFromTrackId must be invoked from the signaling thread. Get
  28. // methods should be invoked only after all data is added. Mixing Get methods
  29. // with adding new data may lead to undefined behaviour.
  30. class AnalyzerHelper : public TrackIdStreamInfoMap {
  31. public:
  32. AnalyzerHelper();
  33. void AddTrackToStreamMapping(std::string track_id, std::string stream_label);
  34. void AddTrackToStreamMapping(std::string track_id,
  35. std::string stream_label,
  36. std::string sync_group);
  37. absl::string_view GetStreamLabelFromTrackId(
  38. absl::string_view track_id) const override;
  39. absl::string_view GetSyncGroupLabelFromTrackId(
  40. absl::string_view track_id) const override;
  41. private:
  42. struct StreamInfo {
  43. std::string stream_label;
  44. std::string sync_group;
  45. };
  46. const StreamInfo& GetStreamInfoFromTrackId(absl::string_view track_id) const;
  47. SequenceChecker signaling_sequence_checker_;
  48. std::map<std::string, StreamInfo> track_to_stream_map_
  49. RTC_GUARDED_BY(signaling_sequence_checker_);
  50. };
  51. } // namespace webrtc_pc_e2e
  52. } // namespace webrtc
  53. #endif // TEST_PC_E2E_ANALYZER_HELPER_H_