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 // Creates BlankDetectorDesktopCapturerWrapper. BlankDesktopCapturerWrapper | |
31 // takes ownership of |capturer|. The |blank_pixel| is the unmodified color | |
32 // returned by the |capturer|. |permanent_failure_threshold| controls how | |
33 // many frames BlankDetectorDesktopCapturerWrapper checks before returning a | |
34 // permanent error. Setting |permanent_failure_threshold| to negative value to | |
35 // disable this function, i.e. BlankDetectorDesktopCapturerWrapper will check | |
36 // every frame, and never return permanent error. | |
Sergey Ulanov
2017/03/02 23:45:51
Do we actually need this feature? It adds complexi
Hzj_jie
2017/03/03 02:29:41
I am OK to remove the permanent_failure_threshold.
| |
37 BlankDetectorDesktopCapturerWrapper(std::unique_ptr<DesktopCapturer> capturer, | |
38 RgbaColor blank_pixel, | |
Sergey Ulanov
2017/03/02 23:45:51
Do we need this parameter? Will we even need to pa
Hzj_jie
2017/03/03 02:29:41
If we use this class with GDI capturer on Windows
| |
39 int permanent_failure_threshold); | |
40 ~BlankDetectorDesktopCapturerWrapper() override; | |
41 | |
42 // DesktopCapturer interface. | |
43 void Start(DesktopCapturer::Callback* callback) override; | |
44 void SetSharedMemoryFactory( | |
45 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; | |
46 void CaptureFrame() override; | |
47 void SetExcludedWindow(WindowId window) override; | |
48 bool GetSourceList(SourceList* sources) override; | |
49 bool SelectSource(SourceId id) override; | |
50 bool FocusOnSelectedSource() 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 // Whether permanent failure has been enabled by this instance, i.e. | |
63 // |permanent_failure_threshold_| >= 0. | |
64 bool permanent_failure_enabled() const; | |
65 | |
66 // Whether permanent error should be returned by this instance for current | |
67 // frame. | |
68 bool permanent_failure_reached() const; | |
69 | |
70 // Returns a permanent error to |callback_|. | |
71 void ReturnPermanentError(); | |
72 | |
73 const std::unique_ptr<DesktopCapturer> capturer_; | |
74 const RgbaColor blank_pixel_; | |
75 | |
76 // The count of failures before this wrapper returns an ERROR_PERMANENT. Set | |
77 // this value to negative to always return ERROR_TEMPORARY. | |
78 const int permanent_failure_threshold_; | |
79 | |
80 // The count of blank frames received in a sequence. | |
81 int failure_count_ = 0; | |
82 | |
83 // Whether a non-blank frame has been received. | |
84 bool non_blank_frame_received_ = false; | |
85 | |
86 // Whether the last frame is blank. | |
87 bool last_frame_is_blank_ = false; | |
88 | |
89 // Whether current frame is the first frame. | |
90 bool is_first_frame_ = true; | |
91 | |
92 DesktopCapturer::Callback* callback_ = nullptr; | |
93 }; | |
94 | |
95 } // namespace webrtc | |
96 | |
97 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_BLANK_DETECTOR_DESKTOP_CAPTURER_WRAPPE R_H_ | |
OLD | NEW |