jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_ |
| 12 | #define MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_ |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 13 | |
kwiberg | 2bb3afa | 2016-03-16 15:58:08 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/desktop_capture/desktop_capturer.h" |
| 17 | #include "modules/desktop_capture/desktop_capture_options.h" |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 18 | |
| 19 | namespace 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. |
zijiehe | 98903d2 | 2016-11-10 21:57:10 -0800 | [diff] [blame] | 24 | class CroppingWindowCapturer : public DesktopCapturer, |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 25 | public DesktopCapturer::Callback { |
| 26 | public: |
zijiehe | c9a6e4a | 2016-11-11 15:13:32 -0800 | [diff] [blame] | 27 | static std::unique_ptr<DesktopCapturer> CreateCapturer( |
| 28 | const DesktopCaptureOptions& options); |
| 29 | |
sergeyu | e183121 | 2016-10-26 13:15:42 -0700 | [diff] [blame] | 30 | ~CroppingWindowCapturer() override; |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 31 | |
| 32 | // DesktopCapturer implementation. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 33 | void Start(DesktopCapturer::Callback* callback) override; |
sergeyu | cc9669c | 2016-02-09 15:13:26 -0800 | [diff] [blame] | 34 | void SetSharedMemoryFactory( |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 35 | std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; |
zijiehe | 91902cb | 2016-10-13 16:47:49 -0700 | [diff] [blame] | 36 | void CaptureFrame() override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 37 | void SetExcludedWindow(WindowId window) override; |
zijiehe | fce4905 | 2016-11-07 15:25:18 -0800 | [diff] [blame] | 38 | bool GetSourceList(SourceList* sources) override; |
| 39 | bool SelectSource(SourceId id) override; |
| 40 | bool FocusOnSelectedSource() override; |
Zijie He | 9cad501 | 2017-09-14 08:32:46 -0700 | [diff] [blame] | 41 | bool IsOccluded(const DesktopVector& pos) override; |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 42 | |
| 43 | // DesktopCapturer::Callback implementation, passed to |screen_capturer_| to |
| 44 | // intercept the capture result. |
sergeyu | 5d91028 | 2016-06-07 16:41:58 -0700 | [diff] [blame] | 45 | void OnCaptureResult(DesktopCapturer::Result result, |
| 46 | std::unique_ptr<DesktopFrame> frame) override; |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 47 | |
| 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 He | f75daa8 | 2017-09-05 15:15:59 -0700 | [diff] [blame] | 59 | // 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.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 62 | 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_; |
zijiehe | 3045589 | 2016-11-09 16:37:48 -0800 | [diff] [blame] | 70 | std::unique_ptr<DesktopCapturer> window_capturer_; |
| 71 | std::unique_ptr<DesktopCapturer> screen_capturer_; |
zijiehe | fce4905 | 2016-11-07 15:25:18 -0800 | [diff] [blame] | 72 | SourceId selected_window_; |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 73 | WindowId excluded_window_; |
| 74 | }; |
| 75 | |
| 76 | } // namespace webrtc |
| 77 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 78 | #endif // MODULES_DESKTOP_CAPTURE_CROPPING_WINDOW_CAPTURER_H_ |
jiayl@webrtc.org | 0e71070 | 2014-11-11 18:15:55 +0000 | [diff] [blame] | 79 | |