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