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 ~BlankDetectorDesktopCapturerWrapper() override; 39 40 // DesktopCapturer interface. 41 void Start(DesktopCapturer::Callback* callback) override; 42 void SetSharedMemoryFactory( 43 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; 44 void CaptureFrame() override; 45 void SetExcludedWindow(WindowId window) override; 46 bool GetSourceList(SourceList* sources) override; 47 bool SelectSource(SourceId id) override; 48 bool FocusOnSelectedSource() override; 49 bool IsOccluded(const DesktopVector& pos) override; 50 51 private: 52 // DesktopCapturer::Callback interface. 53 void OnCaptureResult(Result result, 54 std::unique_ptr<DesktopFrame> frame) override; 55 56 bool IsBlankFrame(const DesktopFrame& frame) const; 57 58 // Detects whether pixel at (x, y) equals to |blank_pixel_|. 59 bool IsBlankPixel(const DesktopFrame& frame, int x, int y) const; 60 61 const std::unique_ptr<DesktopCapturer> capturer_; 62 const RgbaColor blank_pixel_; 63 64 // Whether a non-blank frame has been received. 65 bool non_blank_frame_received_ = false; 66 67 // Whether the last frame is blank. 68 bool last_frame_is_blank_ = false; 69 70 // Whether current frame is the first frame. 71 bool is_first_frame_ = true; 72 73 DesktopCapturer::Callback* callback_ = nullptr; 74 }; 75 76 } // namespace webrtc 77 78 #endif // MODULES_DESKTOP_CAPTURE_BLANK_DETECTOR_DESKTOP_CAPTURER_WRAPPER_H_ 79