summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/test/pc/e2e/analyzer/video/analyzing_video_sinks_helper.h
blob: 5f38c5a40e005724a1e531fc04236811a1945949 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 *  Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef TEST_PC_E2E_ANALYZER_VIDEO_ANALYZING_VIDEO_SINKS_HELPER_H_
#define TEST_PC_E2E_ANALYZER_VIDEO_ANALYZING_VIDEO_SINKS_HELPER_H_

#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>

#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/test/pclf/media_configuration.h"
#include "api/test/video/video_frame_writer.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"

namespace webrtc {
namespace webrtc_pc_e2e {

// Registry of known video configs and video writers.
// This class is thread safe.
class AnalyzingVideoSinksHelper {
 public:
  // Adds config in the registry. If config with such stream label was
  // registered before, the new value will override the old one.
  void AddConfig(absl::string_view sender_peer_name, VideoConfig config);
  absl::optional<std::pair<std::string, VideoConfig>> GetPeerAndConfig(
      absl::string_view stream_label);
  // Removes video config for specified stream label. If there are no know video
  // config for such stream label - does nothing.
  void RemoveConfig(absl::string_view stream_label);

  // Takes ownership of the provided video writer. All video writers owned by
  // this class will be closed during `AnalyzingVideoSinksHelper` destruction
  // and guaranteed to be alive either until explicitly removed by
  // `CloseAndRemoveVideoWriters` or until `AnalyzingVideoSinksHelper` is
  // destroyed.
  //
  // Returns pointer to the added writer. Ownership is maintained by
  // `AnalyzingVideoSinksHelper`.
  test::VideoFrameWriter* AddVideoWriter(
      std::unique_ptr<test::VideoFrameWriter> video_writer);
  // For each provided `writers_to_close`, if it is known, will close and
  // destroy it, otherwise does nothing with it.
  void CloseAndRemoveVideoWriters(
      std::set<test::VideoFrameWriter*> writers_to_close);

  // Removes all added configs and close and removes all added writers.
  void Clear();

 private:
  Mutex mutex_;
  std::map<std::string, std::pair<std::string, VideoConfig>> video_configs_
      RTC_GUARDED_BY(mutex_);
  std::list<std::unique_ptr<test::VideoFrameWriter>> video_writers_
      RTC_GUARDED_BY(mutex_);
};

}  // namespace webrtc_pc_e2e
}  // namespace webrtc

#endif  // TEST_PC_E2E_ANALYZER_VIDEO_ANALYZING_VIDEO_SINKS_HELPER_H_