OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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/fake_desktop_capturer.h" |
| 12 |
| 13 #include <utility> |
| 14 |
| 15 namespace webrtc { |
| 16 |
| 17 FakeDesktopCapturer::FakeDesktopCapturer() |
| 18 : callback_(nullptr), |
| 19 result_(DesktopCapturer::Result::SUCCESS), |
| 20 generator_(nullptr) {} |
| 21 |
| 22 FakeDesktopCapturer::~FakeDesktopCapturer() = default; |
| 23 |
| 24 void FakeDesktopCapturer::set_result(DesktopCapturer::Result result) { |
| 25 result_ = result; |
| 26 } |
| 27 |
| 28 // Uses the |generator| provided as DesktopFrameGenerator, FakeDesktopCapturer |
| 29 // does |
| 30 // not take the ownership of |generator|. |
| 31 void FakeDesktopCapturer::set_frame_generator( |
| 32 DesktopFrameGenerator* generator) { |
| 33 generator_ = generator; |
| 34 } |
| 35 |
| 36 void FakeDesktopCapturer::Start(DesktopCapturer::Callback* callback) { |
| 37 callback_ = callback; |
| 38 } |
| 39 |
| 40 void FakeDesktopCapturer::CaptureFrame() { |
| 41 if (generator_) { |
| 42 std::unique_ptr<DesktopFrame> frame( |
| 43 generator_->GetNextFrame(shared_memory_factory_.get())); |
| 44 if (frame) { |
| 45 callback_->OnCaptureResult(result_, std::move(frame)); |
| 46 } else { |
| 47 callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_TEMPORARY, |
| 48 nullptr); |
| 49 } |
| 50 return; |
| 51 } |
| 52 callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_PERMANENT, nullptr); |
| 53 } |
| 54 |
| 55 void FakeDesktopCapturer::SetSharedMemoryFactory( |
| 56 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { |
| 57 shared_memory_factory_ = std::move(shared_memory_factory); |
| 58 } |
| 59 |
| 60 bool FakeDesktopCapturer::GetSourceList(DesktopCapturer::SourceList* sources) { |
| 61 sources->push_back({kWindowId, "A-Fake-DesktopCapturer-Window"}); |
| 62 sources->push_back({kScreenId}); |
| 63 return true; |
| 64 } |
| 65 |
| 66 bool FakeDesktopCapturer::SelectSource(DesktopCapturer::SourceId id) { |
| 67 return id == kWindowId || id == kScreenId || id == kFullDesktopScreenId; |
| 68 } |
| 69 |
| 70 } // namespace webrtc |
OLD | NEW |