fake_desktop_capturer.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #ifndef MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_
  11. #define MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_
  12. #include <memory>
  13. #include "modules/desktop_capture/desktop_capturer.h"
  14. #include "modules/desktop_capture/desktop_frame_generator.h"
  15. #include "modules/desktop_capture/shared_memory.h"
  16. #include "rtc_base/system/rtc_export.h"
  17. namespace webrtc {
  18. // A fake implementation of DesktopCapturer or its derived interfaces to
  19. // generate DesktopFrame for testing purpose.
  20. //
  21. // Consumers can provide a FrameGenerator instance to generate instances of
  22. // DesktopFrame to return for each Capture() function call.
  23. // If no FrameGenerator provided, FakeDesktopCapturer will always return a
  24. // nullptr DesktopFrame.
  25. //
  26. // Double buffering is guaranteed by the FrameGenerator. FrameGenerator
  27. // implements in desktop_frame_generator.h guarantee double buffering, they
  28. // creates a new instance of DesktopFrame each time.
  29. class RTC_EXPORT FakeDesktopCapturer : public DesktopCapturer {
  30. public:
  31. FakeDesktopCapturer();
  32. ~FakeDesktopCapturer() override;
  33. // Decides the result which will be returned in next Capture() callback.
  34. void set_result(DesktopCapturer::Result result);
  35. // Uses the |generator| provided as DesktopFrameGenerator, FakeDesktopCapturer
  36. // does not take the ownership of |generator|.
  37. void set_frame_generator(DesktopFrameGenerator* generator);
  38. // Count of DesktopFrame(s) have been returned by this instance. This field
  39. // would never be negative.
  40. int num_frames_captured() const;
  41. // Count of CaptureFrame() calls have been made. This field would never be
  42. // negative.
  43. int num_capture_attempts() const;
  44. // DesktopCapturer interface
  45. void Start(DesktopCapturer::Callback* callback) override;
  46. void CaptureFrame() override;
  47. void SetSharedMemoryFactory(
  48. std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
  49. bool GetSourceList(DesktopCapturer::SourceList* sources) override;
  50. bool SelectSource(DesktopCapturer::SourceId id) override;
  51. private:
  52. static constexpr DesktopCapturer::SourceId kWindowId = 1378277495;
  53. static constexpr DesktopCapturer::SourceId kScreenId = 1378277496;
  54. DesktopCapturer::Callback* callback_ = nullptr;
  55. std::unique_ptr<SharedMemoryFactory> shared_memory_factory_;
  56. DesktopCapturer::Result result_ = Result::SUCCESS;
  57. DesktopFrameGenerator* generator_ = nullptr;
  58. int num_frames_captured_ = 0;
  59. int num_capture_attempts_ = 0;
  60. };
  61. } // namespace webrtc
  62. #endif // MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_