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