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