Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: webrtc/modules/desktop_capture/blank_detector_desktop_capturer_wrapper.h

Issue 2709523003: BlankDetectorDesktopCapturerWrapper to detect a blank DesktopFrame (Closed)
Patch Set: Resolve review comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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"
Sergey Ulanov 2017/03/01 22:18:32 Comments for RgbaColor say that it's for tests onl
Hzj_jie 2017/03/01 23:31:38 AFAICT, on Linux, the blank pixel is 0xff, and on
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 permanent_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 // Whether permanent failure has been enabled by this instance.
56 bool permanent_failure_enabled() const;
57
58 // Whether permanent error should be returned by this instance for current
59 // frame.
60 bool permanent_failure_reached() const;
61
62 // Returns a permanent error to |callback_|.
63 void ReturnPermanentError();
64
65 // Returns a temporary error to |callback_|.
66 void ReturnTemporaryError();
67
68 const std::unique_ptr<DesktopCapturer> capturer_;
69 const RgbaColor blank_pixel_;
70
71 // The count of failures before this wrapper returns an ERROR_PERMANENT. Set
72 // this value to negative to always return ERROR_TEMPORARY.
73 const int permanent_failure_threshold_;
74
75 // The count of blank frames received in a sequence.
76 int failure_count_ = 0;
77
78 // Whether a non-blank frame has been received.
79 bool non_blank_frame_received_ = false;
80
81 // Whether the last frame is blank.
82 bool last_frame_is_blank_ = false;
83
84 // Whether current frame is the first frame.
85 bool is_first_frame_ = true;
86
87 DesktopCapturer::Callback* callback_ = nullptr;
88 };
89
90 } // namespace webrtc
91
92 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_BLANK_DETECTOR_DESKTOP_CAPTURER_WRAPPE R_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698