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