blob: 9fbfddaa81ae09165ef261e21ce06d0c5f42ba96 [file] [log] [blame]
jiayl@webrtc.org0e710702014-11-11 18:15:55 +00001/*
2 * Copyright (c) 2014 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_
12#define MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000013
kwiberg2bb3afa2016-03-16 15:58:08 -070014#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "modules/desktop_capture/desktop_capturer.h"
17#include "modules/desktop_capture/desktop_capture_options.h"
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000018
19namespace webrtc {
20
21// WindowCapturer implementation that uses a screen capturer to capture the
22// whole screen and crops the video frame to the window area when the captured
23// window is on top.
zijiehe98903d22016-11-10 21:57:10 -080024class CroppingWindowCapturer : public DesktopCapturer,
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000025 public DesktopCapturer::Callback {
26 public:
zijiehec9a6e4a2016-11-11 15:13:32 -080027 static std::unique_ptr<DesktopCapturer> CreateCapturer(
28 const DesktopCaptureOptions& options);
29
sergeyue1831212016-10-26 13:15:42 -070030 ~CroppingWindowCapturer() override;
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000031
32 // DesktopCapturer implementation.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000033 void Start(DesktopCapturer::Callback* callback) override;
sergeyucc9669c2016-02-09 15:13:26 -080034 void SetSharedMemoryFactory(
kwiberg84be5112016-04-27 01:19:58 -070035 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
zijiehe91902cb2016-10-13 16:47:49 -070036 void CaptureFrame() override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000037 void SetExcludedWindow(WindowId window) override;
zijiehefce49052016-11-07 15:25:18 -080038 bool GetSourceList(SourceList* sources) override;
39 bool SelectSource(SourceId id) override;
40 bool FocusOnSelectedSource() override;
Zijie He9cad5012017-09-14 08:32:46 -070041 bool IsOccluded(const DesktopVector& pos) override;
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000042
43 // DesktopCapturer::Callback implementation, passed to |screen_capturer_| to
44 // intercept the capture result.
sergeyu5d910282016-06-07 16:41:58 -070045 void OnCaptureResult(DesktopCapturer::Result result,
46 std::unique_ptr<DesktopFrame> frame) override;
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000047
48 protected:
49 explicit CroppingWindowCapturer(const DesktopCaptureOptions& options);
50
51 // The platform implementation should override these methods.
52
53 // Returns true if it is OK to capture the whole screen and crop to the
54 // selected window, i.e. the selected window is opaque, rectangular, and not
55 // occluded.
56 virtual bool ShouldUseScreenCapturer() = 0;
57
58 // Returns the window area relative to the top left of the virtual screen
Zijie Hef75daa82017-09-05 15:15:59 -070059 // within the bounds of the virtual screen. This function should return the
60 // DesktopRect in full desktop coordinates, i.e. the top-left monitor starts
61 // from (0, 0).
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000062 virtual DesktopRect GetWindowRectInVirtualScreen() = 0;
63
64 WindowId selected_window() const { return selected_window_; }
65 WindowId excluded_window() const { return excluded_window_; }
66
67 private:
68 DesktopCaptureOptions options_;
69 DesktopCapturer::Callback* callback_;
zijiehe30455892016-11-09 16:37:48 -080070 std::unique_ptr<DesktopCapturer> window_capturer_;
71 std::unique_ptr<DesktopCapturer> screen_capturer_;
zijiehefce49052016-11-07 15:25:18 -080072 SourceId selected_window_;
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000073 WindowId excluded_window_;
74};
75
76} // namespace webrtc
77
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020078#endif // MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_
jiayl@webrtc.org0e710702014-11-11 18:15:55 +000079