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_BLANK_DETECTOR_DESKTOP_CAPTURER_WRAPPER_H_ 12 #define MODULES_DESKTOP_CAPTURE_BLANK_DETECTOR_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/rgba_color.h" 20 #include "modules/desktop_capture/shared_memory.h" 21 22 namespace webrtc { 23 24 // A DesktopCapturer wrapper detects the return value of its owned 25 // DesktopCapturer implementation. If sampled pixels returned by the 26 // DesktopCapturer implementation all equal to the blank pixel, this wrapper 27 // returns ERROR_TEMPORARY. If the DesktopCapturer implementation fails for too 28 // many times, this wrapper returns ERROR_PERMANENT. 29 class BlankDetectorDesktopCapturerWrapper final 30 : public DesktopCapturer, 31 public DesktopCapturer::Callback { 32 public: 33 // Creates BlankDetectorDesktopCapturerWrapper. BlankDesktopCapturerWrapper 34 // takes ownership of `capturer`. The `blank_pixel` is the unmodified color 35 // returned by the `capturer`. 36 BlankDetectorDesktopCapturerWrapper(std::unique_ptr<DesktopCapturer> capturer, 37 RgbaColor blank_pixel, 38 bool check_per_capture = false); 39 ~BlankDetectorDesktopCapturerWrapper() override; 40 41 // DesktopCapturer interface. 42 void Start(DesktopCapturer::Callback* callback) override; 43 void SetSharedMemoryFactory( 44 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; 45 void CaptureFrame() override; 46 void SetExcludedWindow(WindowId window) override; 47 bool GetSourceList(SourceList* sources) override; 48 bool SelectSource(SourceId id) override; 49 bool FocusOnSelectedSource() override; 50 bool IsOccluded(const DesktopVector& pos) override; 51 52 private: 53 // DesktopCapturer::Callback interface. 54 void OnCaptureResult(Result result, 55 std::unique_ptr<DesktopFrame> frame) override; 56 57 bool IsBlankFrame(const DesktopFrame& frame) const; 58 59 // Detects whether pixel at (x, y) equals to `blank_pixel_`. 60 bool IsBlankPixel(const DesktopFrame& frame, int x, int y) const; 61 62 const std::unique_ptr<DesktopCapturer> capturer_; 63 const RgbaColor blank_pixel_; 64 65 // Whether a non-blank frame has been received. 66 bool non_blank_frame_received_ = false; 67 68 // Whether the last frame is blank. 69 bool last_frame_is_blank_ = false; 70 71 // Whether current frame is the first frame. 72 bool is_first_frame_ = true; 73 74 // Blank inspection is made per capture instead of once for all 75 // screens or windows. 76 bool check_per_capture_ = false; 77 78 DesktopCapturer::Callback* callback_ = nullptr; 79 }; 80 81 } // namespace webrtc 82 83 #endif // MODULES_DESKTOP_CAPTURE_BLANK_DETECTOR_DESKTOP_CAPTURER_WRAPPER_H_ 84