tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fallback_desktop_capturer_wrapper.h (2710B)


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