OLD | NEW |
(Empty) | |
| 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 WEBRTC_MODULES_DESKTOP_CAPTURE_BLANK_DETECTOR_DESKTOP_CAPTURER_WRAPPER_H
_ |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_BLANK_DETECTOR_DESKTOP_CAPTURER_WRAPPER_H
_ |
| 13 |
| 14 #include <memory> |
| 15 |
| 16 #include "webrtc/modules/desktop_capture/desktop_capturer.h" |
| 17 #include "webrtc/modules/desktop_capture/rgba_color.h" |
| 18 |
| 19 namespace webrtc { |
| 20 |
| 21 // A DesktopCapturer wrapper detects the return value of its owned |
| 22 // DesktopCapturer implementation. If sampled pixels returned by the |
| 23 // DesktopCapturer implementation all equal to the blank pixel, this wrapper |
| 24 // returns ERROR_TEMPORARY. If the DesktopCapturer implementation fails for too |
| 25 // many times, this wrapper returns ERROR_PERMANENT. |
| 26 class BlankDetectorDesktopCapturerWrapper final |
| 27 : public DesktopCapturer, |
| 28 public DesktopCapturer::Callback { |
| 29 public: |
| 30 BlankDetectorDesktopCapturerWrapper(std::unique_ptr<DesktopCapturer> capturer, |
| 31 RgbaColor blank_pixel, |
| 32 int permenant_failure_threshold); |
| 33 ~BlankDetectorDesktopCapturerWrapper() override; |
| 34 |
| 35 // DesktopCapturer interface. |
| 36 void Start(DesktopCapturer::Callback* callback) override; |
| 37 void SetSharedMemoryFactory( |
| 38 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; |
| 39 void CaptureFrame() override; |
| 40 void SetExcludedWindow(WindowId window) override; |
| 41 bool GetSourceList(SourceList* sources) override; |
| 42 bool SelectSource(SourceId id) override; |
| 43 bool FocusOnSelectedSource() override; |
| 44 |
| 45 private: |
| 46 // DesktopCapturer::Callback interface. |
| 47 void OnCaptureResult(Result result, |
| 48 std::unique_ptr<DesktopFrame> frame) override; |
| 49 |
| 50 bool IsBlankFrame(const DesktopFrame& frame) const; |
| 51 |
| 52 // Detects whether pixel at (x, y) equals to |blank_pixel_|. |
| 53 bool IsBlankPixel(const DesktopFrame& frame, int x, int y) const; |
| 54 |
| 55 const std::unique_ptr<DesktopCapturer> capturer_; |
| 56 const RgbaColor blank_pixel_; |
| 57 // The count of failures before this wrapper returns an ERROR_PERMANENT. Set |
| 58 // this value to negative to always return ERROR_TEMPORARY. |
| 59 const int permenant_failure_threshold_; |
| 60 // The count of blank frames received in sequence. Any frames passing the |
| 61 // blank detection resets this counter. |
| 62 int failure_count_ = 0; |
| 63 DesktopCapturer::Callback* callback_ = nullptr; |
| 64 }; |
| 65 |
| 66 } // namespace webrtc |
| 67 |
| 68 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_BLANK_DETECTOR_DESKTOP_CAPTURER_WRAPPE
R_H_ |
OLD | NEW |