screen_capturer_mac.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2018 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_MAC_SCREEN_CAPTURER_MAC_H_
  11. #define MODULES_DESKTOP_CAPTURE_MAC_SCREEN_CAPTURER_MAC_H_
  12. #include <CoreGraphics/CoreGraphics.h>
  13. #include <memory>
  14. #include <vector>
  15. #include "modules/desktop_capture/desktop_capture_options.h"
  16. #include "modules/desktop_capture/desktop_capturer.h"
  17. #include "modules/desktop_capture/desktop_frame.h"
  18. #include "modules/desktop_capture/desktop_geometry.h"
  19. #include "modules/desktop_capture/desktop_region.h"
  20. #include "modules/desktop_capture/mac/desktop_configuration.h"
  21. #include "modules/desktop_capture/mac/desktop_configuration_monitor.h"
  22. #include "modules/desktop_capture/mac/desktop_frame_provider.h"
  23. #include "modules/desktop_capture/screen_capture_frame_queue.h"
  24. #include "modules/desktop_capture/screen_capturer_helper.h"
  25. #include "modules/desktop_capture/shared_desktop_frame.h"
  26. #include "rtc_base/thread_checker.h"
  27. namespace webrtc {
  28. class DisplayStreamManager;
  29. // A class to perform video frame capturing for mac.
  30. class ScreenCapturerMac final : public DesktopCapturer {
  31. public:
  32. ScreenCapturerMac(
  33. rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor,
  34. bool detect_updated_region,
  35. bool allow_iosurface);
  36. ~ScreenCapturerMac() override;
  37. // TODO(julien.isorce): Remove Init() or make it private.
  38. bool Init();
  39. // DesktopCapturer interface.
  40. void Start(Callback* callback) override;
  41. void CaptureFrame() override;
  42. void SetExcludedWindow(WindowId window) override;
  43. bool GetSourceList(SourceList* screens) override;
  44. bool SelectSource(SourceId id) override;
  45. private:
  46. // Returns false if the selected screen is no longer valid.
  47. bool CgBlit(const DesktopFrame& frame, const DesktopRegion& region);
  48. // Called when the screen configuration is changed.
  49. void ScreenConfigurationChanged();
  50. bool RegisterRefreshAndMoveHandlers();
  51. void UnregisterRefreshAndMoveHandlers();
  52. void ScreenRefresh(CGDirectDisplayID display_id,
  53. CGRectCount count,
  54. const CGRect* rect_array,
  55. DesktopVector display_origin,
  56. IOSurfaceRef io_surface);
  57. void ReleaseBuffers();
  58. std::unique_ptr<DesktopFrame> CreateFrame();
  59. const bool detect_updated_region_;
  60. Callback* callback_ = nullptr;
  61. // Queue of the frames buffers.
  62. ScreenCaptureFrameQueue<SharedDesktopFrame> queue_;
  63. // Current display configuration.
  64. MacDesktopConfiguration desktop_config_;
  65. // Currently selected display, or 0 if the full desktop is selected. On OS X
  66. // 10.6 and before, this is always 0.
  67. CGDirectDisplayID current_display_ = 0;
  68. // The physical pixel bounds of the current screen.
  69. DesktopRect screen_pixel_bounds_;
  70. // The dip to physical pixel scale of the current screen.
  71. float dip_to_pixel_scale_ = 1.0f;
  72. // A thread-safe list of invalid rectangles, and the size of the most
  73. // recently captured screen.
  74. ScreenCapturerHelper helper_;
  75. // Contains an invalid region from the previous capture.
  76. DesktopRegion last_invalid_region_;
  77. // Monitoring display reconfiguration.
  78. rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor_;
  79. CGWindowID excluded_window_ = 0;
  80. // List of streams, one per screen.
  81. std::vector<CGDisplayStreamRef> display_streams_;
  82. // Container holding latest state of the snapshot per displays.
  83. DesktopFrameProvider desktop_frame_provider_;
  84. // Start, CaptureFrame and destructor have to called in the same thread.
  85. rtc::ThreadChecker thread_checker_;
  86. RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerMac);
  87. };
  88. } // namespace webrtc
  89. #endif // MODULES_DESKTOP_CAPTURE_MAC_SCREEN_CAPTURER_MAC_H_