Chromium Code Reviews| 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 #include <utility> | |
| 12 | |
| 13 #include "webrtc/base/checks.h" | |
| 14 #include "webrtc/modules/desktop_capture/blank_detector_desktop_capturer_wrapper .h" | |
| 15 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | |
| 16 | |
| 17 namespace webrtc { | |
| 18 | |
| 19 BlankDetectorDesktopCapturerWrapper::BlankDetectorDesktopCapturerWrapper( | |
| 20 std::unique_ptr<DesktopCapturer> capturer, | |
| 21 RgbaColor blank_pixel, | |
| 22 int permenant_failure_threshold) | |
| 23 : capturer_(std::move(capturer)), | |
| 24 blank_pixel_(blank_pixel), | |
| 25 permenant_failure_threshold_(permenant_failure_threshold) { | |
| 26 RTC_DCHECK(capturer_); | |
| 27 } | |
| 28 | |
| 29 BlankDetectorDesktopCapturerWrapper::~BlankDetectorDesktopCapturerWrapper() = | |
| 30 default; | |
| 31 | |
| 32 void BlankDetectorDesktopCapturerWrapper::Start( | |
| 33 DesktopCapturer::Callback* callback) { | |
| 34 capturer_->Start(this); | |
| 35 callback_ = callback; | |
| 36 } | |
| 37 | |
| 38 void BlankDetectorDesktopCapturerWrapper::SetSharedMemoryFactory( | |
| 39 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { | |
| 40 capturer_->SetSharedMemoryFactory(std::move(shared_memory_factory)); | |
| 41 } | |
| 42 | |
| 43 void BlankDetectorDesktopCapturerWrapper::CaptureFrame() { | |
| 44 RTC_DCHECK(callback_); | |
| 45 capturer_->CaptureFrame(); | |
| 46 } | |
| 47 | |
| 48 void BlankDetectorDesktopCapturerWrapper::SetExcludedWindow(WindowId window) { | |
| 49 capturer_->SetExcludedWindow(window); | |
| 50 } | |
| 51 | |
| 52 bool BlankDetectorDesktopCapturerWrapper::GetSourceList(SourceList* sources) { | |
| 53 return capturer_->GetSourceList(sources); | |
| 54 } | |
| 55 | |
| 56 bool BlankDetectorDesktopCapturerWrapper::SelectSource(SourceId id) { | |
| 57 return capturer_->SelectSource(id); | |
| 58 } | |
| 59 | |
| 60 bool BlankDetectorDesktopCapturerWrapper::FocusOnSelectedSource() { | |
| 61 return capturer_->FocusOnSelectedSource(); | |
| 62 } | |
| 63 | |
| 64 void BlankDetectorDesktopCapturerWrapper::OnCaptureResult( | |
| 65 Result result, | |
| 66 std::unique_ptr<DesktopFrame> frame) { | |
| 67 RTC_DCHECK(callback_); | |
| 68 if (result != Result::SUCCESS) { | |
| 69 callback_->OnCaptureResult(result, std::move(frame)); | |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 if (!frame) { | |
| 74 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, | |
| 75 std::unique_ptr<DesktopFrame>()); | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 if (!IsBlankFrame(*frame)) { | |
|
Sergey Ulanov
2017/02/21 21:58:48
Do we need to check every frame only only a few fi
Hzj_jie
2017/02/21 22:59:40
Oh, yes, at least when permanent_failure_threshold
| |
| 80 failure_count_ = 0; | |
| 81 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); | |
| 82 return; | |
| 83 } | |
| 84 | |
| 85 if (permenant_failure_threshold_ >= 0) { | |
| 86 failure_count_++; | |
| 87 if (failure_count_ >= permenant_failure_threshold_) { | |
| 88 callback_->OnCaptureResult(Result::ERROR_PERMANENT, | |
| 89 std::unique_ptr<DesktopFrame>()); | |
| 90 return; | |
| 91 } | |
| 92 } | |
| 93 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, | |
| 94 std::unique_ptr<DesktopFrame>()); | |
| 95 } | |
| 96 | |
| 97 bool BlankDetectorDesktopCapturerWrapper::IsBlankFrame( | |
| 98 const DesktopFrame& frame) const { | |
| 99 const int size = | |
| 100 (frame.size().width() < frame.size().height() ? frame.size().width() | |
| 101 : frame.size().height()); | |
| 102 // We will check 303 pixels for a frame with 1024 x 768 resolution. | |
| 103 for (int i = 0; i < size; i += 10) { | |
| 104 const int x1 = i; | |
| 105 const int x2 = frame.size().width() - i - 1; | |
| 106 const int y1 = i; | |
| 107 const int y2 = frame.size().height() - i - 1; | |
| 108 if (!IsBlankPixel(frame, x1, y1) || !IsBlankPixel(frame, x1, y2) || | |
| 109 !IsBlankPixel(frame, x2, y1) || !IsBlankPixel(frame, x2, y2)) { | |
| 110 return false; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 return IsBlankPixel(frame, frame.size().width() >> 1, | |
| 115 frame.size().height() >> 1); | |
| 116 } | |
| 117 | |
| 118 bool BlankDetectorDesktopCapturerWrapper::IsBlankPixel( | |
| 119 const DesktopFrame& frame, | |
| 120 int x, | |
| 121 int y) const { | |
| 122 uint8_t* pixel_data = frame.GetFrameDataAtPos(DesktopVector(x, y)); | |
| 123 return RgbaColor(pixel_data) == blank_pixel_; | |
| 124 } | |
| 125 | |
| 126 } // namespace webrtc | |
| OLD | NEW |