desktop_frame_provider.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_DESKTOP_FRAME_PROVIDER_H_
  11. #define MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_PROVIDER_H_
  12. #include <CoreGraphics/CoreGraphics.h>
  13. #include <IOSurface/IOSurface.h>
  14. #include <map>
  15. #include <memory>
  16. #include "modules/desktop_capture/shared_desktop_frame.h"
  17. #include "rtc_base/thread_checker.h"
  18. #include "sdk/objc/helpers/scoped_cftyperef.h"
  19. namespace webrtc {
  20. class DesktopFrameProvider {
  21. public:
  22. explicit DesktopFrameProvider(bool allow_iosurface);
  23. ~DesktopFrameProvider();
  24. // The caller takes ownership of the returned desktop frame. Otherwise
  25. // returns null if |display_id| is invalid or not ready. Note that this
  26. // function does not remove the frame from the internal container. Caller
  27. // has to call the Release function.
  28. std::unique_ptr<DesktopFrame> TakeLatestFrameForDisplay(
  29. CGDirectDisplayID display_id);
  30. // OS sends the latest IOSurfaceRef through
  31. // CGDisplayStreamFrameAvailableHandler callback; we store it here.
  32. void InvalidateIOSurface(CGDirectDisplayID display_id,
  33. rtc::ScopedCFTypeRef<IOSurfaceRef> io_surface);
  34. // Expected to be called before stopping the CGDisplayStreamRef streams.
  35. void Release();
  36. private:
  37. rtc::ThreadChecker thread_checker_;
  38. const bool allow_iosurface_;
  39. // Most recent IOSurface that contains a capture of matching display.
  40. std::map<CGDirectDisplayID, std::unique_ptr<SharedDesktopFrame>> io_surfaces_;
  41. RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrameProvider);
  42. };
  43. } // namespace webrtc
  44. #endif // MODULES_DESKTOP_CAPTURE_MAC_DESKTOP_FRAME_PROVIDER_H_