zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ |
| 12 | #define MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 15 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 16 | #include "modules/desktop_capture/desktop_capturer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "modules/desktop_capture/desktop_frame_generator.h" |
| 18 | #include "modules/desktop_capture/shared_memory.h" |
Mirko Bonadei | 3d25530 | 2018-10-11 08:50:45 | [diff] [blame] | 19 | #include "rtc_base/system/rtc_export.h" |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | // A fake implementation of DesktopCapturer or its derived interfaces to |
| 24 | // generate DesktopFrame for testing purpose. |
| 25 | // |
| 26 | // Consumers can provide a FrameGenerator instance to generate instances of |
| 27 | // DesktopFrame to return for each Capture() function call. |
| 28 | // If no FrameGenerator provided, FakeDesktopCapturer will always return a |
| 29 | // nullptr DesktopFrame. |
| 30 | // |
| 31 | // Double buffering is guaranteed by the FrameGenerator. FrameGenerator |
| 32 | // implements in desktop_frame_generator.h guarantee double buffering, they |
| 33 | // creates a new instance of DesktopFrame each time. |
Mirko Bonadei | 3d25530 | 2018-10-11 08:50:45 | [diff] [blame] | 34 | class RTC_EXPORT FakeDesktopCapturer : public DesktopCapturer { |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 35 | public: |
zijiehe | 98903d2 | 2016-11-11 05:57:10 | [diff] [blame] | 36 | FakeDesktopCapturer(); |
| 37 | ~FakeDesktopCapturer() override; |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 38 | |
| 39 | // Decides the result which will be returned in next Capture() callback. |
zijiehe | 98903d2 | 2016-11-11 05:57:10 | [diff] [blame] | 40 | void set_result(DesktopCapturer::Result result); |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 41 | |
Artem Titov | cec4343 | 2021-07-28 21:35:39 | [diff] [blame] | 42 | // Uses the `generator` provided as DesktopFrameGenerator, FakeDesktopCapturer |
| 43 | // does not take the ownership of `generator`. |
zijiehe | 98903d2 | 2016-11-11 05:57:10 | [diff] [blame] | 44 | void set_frame_generator(DesktopFrameGenerator* generator); |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 45 | |
zijiehe | 8fefe98 | 2017-02-17 22:32:04 | [diff] [blame] | 46 | // Count of DesktopFrame(s) have been returned by this instance. This field |
| 47 | // would never be negative. |
| 48 | int num_frames_captured() const; |
| 49 | |
| 50 | // Count of CaptureFrame() calls have been made. This field would never be |
| 51 | // negative. |
| 52 | int num_capture_attempts() const; |
| 53 | |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 54 | // DesktopCapturer interface |
zijiehe | 98903d2 | 2016-11-11 05:57:10 | [diff] [blame] | 55 | void Start(DesktopCapturer::Callback* callback) override; |
| 56 | void CaptureFrame() override; |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 57 | void SetSharedMemoryFactory( |
zijiehe | 98903d2 | 2016-11-11 05:57:10 | [diff] [blame] | 58 | std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; |
| 59 | bool GetSourceList(DesktopCapturer::SourceList* sources) override; |
| 60 | bool SelectSource(DesktopCapturer::SourceId id) override; |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 61 | |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 62 | private: |
zijiehe | 54fd579 | 2016-11-02 21:49:35 | [diff] [blame] | 63 | static constexpr DesktopCapturer::SourceId kWindowId = 1378277495; |
| 64 | static constexpr DesktopCapturer::SourceId kScreenId = 1378277496; |
| 65 | |
zijiehe | 8fefe98 | 2017-02-17 22:32:04 | [diff] [blame] | 66 | DesktopCapturer::Callback* callback_ = nullptr; |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 67 | std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; |
zijiehe | 8fefe98 | 2017-02-17 22:32:04 | [diff] [blame] | 68 | DesktopCapturer::Result result_ = Result::SUCCESS; |
| 69 | DesktopFrameGenerator* generator_ = nullptr; |
| 70 | int num_frames_captured_ = 0; |
| 71 | int num_capture_attempts_ = 0; |
zijiehe | fef8653 | 2016-09-05 22:26:32 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | } // namespace webrtc |
| 75 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 76 | #endif // MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_ |