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 "webrtc/modules/desktop_capture/blank_detector_desktop_capturer_wrapper
.h" |
| 12 |
| 13 #include <algorithm> |
| 14 #include <utility> |
| 15 |
| 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| 18 |
| 19 namespace webrtc { |
| 20 |
| 21 BlankDetectorDesktopCapturerWrapper::BlankDetectorDesktopCapturerWrapper( |
| 22 std::unique_ptr<DesktopCapturer> capturer, |
| 23 RgbaColor blank_pixel) |
| 24 : capturer_(std::move(capturer)), |
| 25 blank_pixel_(blank_pixel) { |
| 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 || non_blank_frame_received_) { |
| 69 callback_->OnCaptureResult(result, std::move(frame)); |
| 70 return; |
| 71 } |
| 72 |
| 73 RTC_DCHECK(frame); |
| 74 |
| 75 // If nothing has been changed in current frame, we do not need to check it |
| 76 // again. |
| 77 if (!frame->updated_region().is_empty() || is_first_frame_) { |
| 78 last_frame_is_blank_ = IsBlankFrame(*frame); |
| 79 is_first_frame_ = false; |
| 80 } |
| 81 if (!last_frame_is_blank_) { |
| 82 non_blank_frame_received_ = true; |
| 83 callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); |
| 84 return; |
| 85 } |
| 86 |
| 87 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, |
| 88 std::unique_ptr<DesktopFrame>()); |
| 89 } |
| 90 |
| 91 bool BlankDetectorDesktopCapturerWrapper::IsBlankFrame( |
| 92 const DesktopFrame& frame) const { |
| 93 // We will check 7489 pixels for a frame with 1024 x 768 resolution. |
| 94 for (int i = 0; i < frame.size().width() * frame.size().height(); i += 105) { |
| 95 const int x = i % frame.size().width(); |
| 96 const int y = i / frame.size().width(); |
| 97 if (!IsBlankPixel(frame, x, y)) { |
| 98 return false; |
| 99 } |
| 100 } |
| 101 |
| 102 // We are verifying the pixel in the center as well. |
| 103 return IsBlankPixel(frame, frame.size().width() / 2, |
| 104 frame.size().height() / 2); |
| 105 } |
| 106 |
| 107 bool BlankDetectorDesktopCapturerWrapper::IsBlankPixel( |
| 108 const DesktopFrame& frame, |
| 109 int x, |
| 110 int y) const { |
| 111 uint8_t* pixel_data = frame.GetFrameDataAtPos(DesktopVector(x, y)); |
| 112 return RgbaColor(pixel_data) == blank_pixel_; |
| 113 } |
| 114 |
| 115 } // namespace webrtc |
OLD | NEW |