fallback_desktop_capturer_wrapper.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2017 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_FALLBACK_DESKTOP_CAPTURER_WRAPPER_H_
  11. #define MODULES_DESKTOP_CAPTURE_FALLBACK_DESKTOP_CAPTURER_WRAPPER_H_
  12. #include <memory>
  13. #include "modules/desktop_capture/desktop_capture_types.h"
  14. #include "modules/desktop_capture/desktop_capturer.h"
  15. #include "modules/desktop_capture/desktop_frame.h"
  16. #include "modules/desktop_capture/desktop_geometry.h"
  17. #include "modules/desktop_capture/shared_memory.h"
  18. namespace webrtc {
  19. // A DesktopCapturer wrapper owns two DesktopCapturer implementations. If the
  20. // main DesktopCapturer fails, it uses the secondary one instead. Two capturers
  21. // are expected to return same SourceList, and the meaning of each SourceId is
  22. // identical, otherwise FallbackDesktopCapturerWrapper may return frames from
  23. // different sources. Using asynchronized DesktopCapturer implementations with
  24. // SharedMemoryFactory is not supported, and may result crash or assertion
  25. // failure.
  26. class FallbackDesktopCapturerWrapper final : public DesktopCapturer,
  27. public DesktopCapturer::Callback {
  28. public:
  29. FallbackDesktopCapturerWrapper(
  30. std::unique_ptr<DesktopCapturer> main_capturer,
  31. std::unique_ptr<DesktopCapturer> secondary_capturer);
  32. ~FallbackDesktopCapturerWrapper() override;
  33. // DesktopCapturer interface.
  34. void Start(DesktopCapturer::Callback* callback) override;
  35. void SetSharedMemoryFactory(
  36. std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
  37. void CaptureFrame() override;
  38. void SetExcludedWindow(WindowId window) override;
  39. bool GetSourceList(SourceList* sources) override;
  40. bool SelectSource(SourceId id) override;
  41. bool FocusOnSelectedSource() override;
  42. bool IsOccluded(const DesktopVector& pos) override;
  43. private:
  44. // DesktopCapturer::Callback interface.
  45. void OnCaptureResult(Result result,
  46. std::unique_ptr<DesktopFrame> frame) override;
  47. const std::unique_ptr<DesktopCapturer> main_capturer_;
  48. const std::unique_ptr<DesktopCapturer> secondary_capturer_;
  49. std::unique_ptr<SharedMemoryFactory> shared_memory_factory_;
  50. bool main_capturer_permanent_error_ = false;
  51. DesktopCapturer::Callback* callback_ = nullptr;
  52. };
  53. } // namespace webrtc
  54. #endif // MODULES_DESKTOP_CAPTURE_FALLBACK_DESKTOP_CAPTURER_WRAPPER_H_