blob: ea622650b8ed2310babf675a4cb9f154c16ab918 [file] [log] [blame]
zijiehe99d036c2016-11-11 05:57:101/*
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
15namespace webrtc {
16
zijiehe062a1592017-02-17 22:32:0417FakeDesktopCapturer::FakeDesktopCapturer() = default;
zijiehe99d036c2016-11-11 05:57:1018FakeDesktopCapturer::~FakeDesktopCapturer() = default;
19
20void FakeDesktopCapturer::set_result(DesktopCapturer::Result result) {
21 result_ = result;
22}
23
zijiehe062a1592017-02-17 22:32:0424int FakeDesktopCapturer::num_frames_captured() const {
25 return num_frames_captured_;
26}
27
28int FakeDesktopCapturer::num_capture_attempts() const {
29 return num_capture_attempts_;
30}
31
zijiehe99d036c2016-11-11 05:57:1032// Uses the |generator| provided as DesktopFrameGenerator, FakeDesktopCapturer
33// does
34// not take the ownership of |generator|.
35void FakeDesktopCapturer::set_frame_generator(
36 DesktopFrameGenerator* generator) {
37 generator_ = generator;
38}
39
40void FakeDesktopCapturer::Start(DesktopCapturer::Callback* callback) {
41 callback_ = callback;
42}
43
44void FakeDesktopCapturer::CaptureFrame() {
zijiehe062a1592017-02-17 22:32:0445 num_capture_attempts_++;
zijiehe99d036c2016-11-11 05:57:1046 if (generator_) {
zijiehe062a1592017-02-17 22:32:0447 if (result_ != DesktopCapturer::Result::SUCCESS) {
48 callback_->OnCaptureResult(result_, nullptr);
49 return;
50 }
51
zijiehe99d036c2016-11-11 05:57:1052 std::unique_ptr<DesktopFrame> frame(
53 generator_->GetNextFrame(shared_memory_factory_.get()));
54 if (frame) {
zijiehe062a1592017-02-17 22:32:0455 num_frames_captured_++;
zijiehe99d036c2016-11-11 05:57:1056 callback_->OnCaptureResult(result_, std::move(frame));
57 } else {
58 callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_TEMPORARY,
59 nullptr);
60 }
61 return;
62 }
63 callback_->OnCaptureResult(DesktopCapturer::Result::ERROR_PERMANENT, nullptr);
64}
65
66void FakeDesktopCapturer::SetSharedMemoryFactory(
67 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {
68 shared_memory_factory_ = std::move(shared_memory_factory);
69}
70
71bool FakeDesktopCapturer::GetSourceList(DesktopCapturer::SourceList* sources) {
72 sources->push_back({kWindowId, "A-Fake-DesktopCapturer-Window"});
73 sources->push_back({kScreenId});
74 return true;
75}
76
77bool FakeDesktopCapturer::SelectSource(DesktopCapturer::SourceId id) {
78 return id == kWindowId || id == kScreenId || id == kFullDesktopScreenId;
79}
80
81} // namespace webrtc