cropping_window_capturer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2014 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_CROPPING_WINDOW_CAPTURER_H_
  11. #define MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_
  12. #include <memory>
  13. #include "modules/desktop_capture/desktop_capture_options.h"
  14. #include "modules/desktop_capture/desktop_capture_types.h"
  15. #include "modules/desktop_capture/desktop_capturer.h"
  16. #include "modules/desktop_capture/desktop_frame.h"
  17. #include "modules/desktop_capture/desktop_geometry.h"
  18. #include "modules/desktop_capture/shared_memory.h"
  19. #include "rtc_base/system/rtc_export.h"
  20. namespace webrtc {
  21. // WindowCapturer implementation that uses a screen capturer to capture the
  22. // whole screen and crops the video frame to the window area when the captured
  23. // window is on top.
  24. class RTC_EXPORT CroppingWindowCapturer : public DesktopCapturer,
  25. public DesktopCapturer::Callback {
  26. public:
  27. static std::unique_ptr<DesktopCapturer> CreateCapturer(
  28. const DesktopCaptureOptions& options);
  29. ~CroppingWindowCapturer() override;
  30. // DesktopCapturer implementation.
  31. void Start(DesktopCapturer::Callback* callback) override;
  32. void SetSharedMemoryFactory(
  33. std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
  34. void CaptureFrame() override;
  35. void SetExcludedWindow(WindowId window) override;
  36. bool GetSourceList(SourceList* sources) override;
  37. bool SelectSource(SourceId id) override;
  38. bool FocusOnSelectedSource() override;
  39. bool IsOccluded(const DesktopVector& pos) override;
  40. // DesktopCapturer::Callback implementation, passed to |screen_capturer_| to
  41. // intercept the capture result.
  42. void OnCaptureResult(DesktopCapturer::Result result,
  43. std::unique_ptr<DesktopFrame> frame) override;
  44. protected:
  45. explicit CroppingWindowCapturer(const DesktopCaptureOptions& options);
  46. // The platform implementation should override these methods.
  47. // Returns true if it is OK to capture the whole screen and crop to the
  48. // selected window, i.e. the selected window is opaque, rectangular, and not
  49. // occluded.
  50. virtual bool ShouldUseScreenCapturer() = 0;
  51. // Returns the window area relative to the top left of the virtual screen
  52. // within the bounds of the virtual screen. This function should return the
  53. // DesktopRect in full desktop coordinates, i.e. the top-left monitor starts
  54. // from (0, 0).
  55. virtual DesktopRect GetWindowRectInVirtualScreen() = 0;
  56. WindowId selected_window() const { return selected_window_; }
  57. WindowId excluded_window() const { return excluded_window_; }
  58. DesktopCapturer* window_capturer() const { return window_capturer_.get(); }
  59. private:
  60. DesktopCaptureOptions options_;
  61. DesktopCapturer::Callback* callback_;
  62. std::unique_ptr<DesktopCapturer> window_capturer_;
  63. std::unique_ptr<DesktopCapturer> screen_capturer_;
  64. SourceId selected_window_;
  65. WindowId excluded_window_;
  66. };
  67. } // namespace webrtc
  68. #endif // MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_