xref: /aosp_15_r20/external/webrtc/test/test_video_capturer.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2013 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_TEST_VIDEO_CAPTURER_H_
11 #define TEST_TEST_VIDEO_CAPTURER_H_
12 
13 #include <stddef.h>
14 
15 #include <memory>
16 
17 #include "api/video/video_frame.h"
18 #include "api/video/video_source_interface.h"
19 #include "media/base/video_adapter.h"
20 #include "media/base/video_broadcaster.h"
21 #include "rtc_base/synchronization/mutex.h"
22 
23 namespace webrtc {
24 namespace test {
25 
26 class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> {
27  public:
28   class FramePreprocessor {
29    public:
30     virtual ~FramePreprocessor() = default;
31 
32     virtual VideoFrame Preprocess(const VideoFrame& frame) = 0;
33   };
34 
35   ~TestVideoCapturer() override;
36 
37   void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink,
38                        const rtc::VideoSinkWants& wants) override;
39   void RemoveSink(rtc::VideoSinkInterface<VideoFrame>* sink) override;
SetFramePreprocessor(std::unique_ptr<FramePreprocessor> preprocessor)40   void SetFramePreprocessor(std::unique_ptr<FramePreprocessor> preprocessor) {
41     MutexLock lock(&lock_);
42     preprocessor_ = std::move(preprocessor);
43   }
44   void OnOutputFormatRequest(int width,
45                              int height,
46                              const absl::optional<int>& max_fps);
47 
48  protected:
49   void OnFrame(const VideoFrame& frame);
50   rtc::VideoSinkWants GetSinkWants();
51 
52  private:
53   void UpdateVideoAdapter();
54   VideoFrame MaybePreprocess(const VideoFrame& frame);
55 
56   Mutex lock_;
57   std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_);
58   rtc::VideoBroadcaster broadcaster_;
59   cricket::VideoAdapter video_adapter_;
60 };
61 }  // namespace test
62 }  // namespace webrtc
63 
64 #endif  // TEST_TEST_VIDEO_CAPTURER_H_
65