blob: 9cab2d6edeaf3636b2fd3db76abb83d993be0cd1 [file] [log] [blame]
zijiehe653e14b2016-09-05 22:26:321/*
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#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_
12#define WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_
13
14#include <memory>
zijiehe653e14b2016-09-05 22:26:3215
16#include "webrtc/modules/desktop_capture/desktop_capturer.h"
zijiehe7d36ca02016-11-02 21:49:3517#include "webrtc/modules/desktop_capture/desktop_capture_types.h"
zijiehe653e14b2016-09-05 22:26:3218#include "webrtc/modules/desktop_capture/desktop_frame_generator.h"
zijiehe653e14b2016-09-05 22:26:3219#include "webrtc/modules/desktop_capture/shared_memory.h"
20
21namespace webrtc {
22
23// A fake implementation of DesktopCapturer or its derived interfaces to
24// generate DesktopFrame for testing purpose.
25//
26// Consumers can provide a FrameGenerator instance to generate instances of
27// DesktopFrame to return for each Capture() function call.
28// If no FrameGenerator provided, FakeDesktopCapturer will always return a
29// nullptr DesktopFrame.
30//
31// Double buffering is guaranteed by the FrameGenerator. FrameGenerator
32// implements in desktop_frame_generator.h guarantee double buffering, they
33// creates a new instance of DesktopFrame each time.
zijiehe99d036c2016-11-11 05:57:1034class FakeDesktopCapturer : public DesktopCapturer {
zijiehe653e14b2016-09-05 22:26:3235 public:
zijiehe99d036c2016-11-11 05:57:1036 FakeDesktopCapturer();
37 ~FakeDesktopCapturer() override;
zijiehe653e14b2016-09-05 22:26:3238
39 // Decides the result which will be returned in next Capture() callback.
zijiehe99d036c2016-11-11 05:57:1040 void set_result(DesktopCapturer::Result result);
zijiehe653e14b2016-09-05 22:26:3241
42 // Uses the |generator| provided as DesktopFrameGenerator, FakeDesktopCapturer
zijiehe99d036c2016-11-11 05:57:1043 // does not take the ownership of |generator|.
44 void set_frame_generator(DesktopFrameGenerator* generator);
zijiehe653e14b2016-09-05 22:26:3245
zijiehe062a1592017-02-17 22:32:0446 // Count of DesktopFrame(s) have been returned by this instance. This field
47 // would never be negative.
48 int num_frames_captured() const;
49
50 // Count of CaptureFrame() calls have been made. This field would never be
51 // negative.
52 int num_capture_attempts() const;
53
zijiehe653e14b2016-09-05 22:26:3254 // DesktopCapturer interface
zijiehe99d036c2016-11-11 05:57:1055 void Start(DesktopCapturer::Callback* callback) override;
56 void CaptureFrame() override;
zijiehe653e14b2016-09-05 22:26:3257 void SetSharedMemoryFactory(
zijiehe99d036c2016-11-11 05:57:1058 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override;
59 bool GetSourceList(DesktopCapturer::SourceList* sources) override;
60 bool SelectSource(DesktopCapturer::SourceId id) override;
zijiehe7d36ca02016-11-02 21:49:3561
zijiehe653e14b2016-09-05 22:26:3262 private:
zijiehe7d36ca02016-11-02 21:49:3563 static constexpr DesktopCapturer::SourceId kWindowId = 1378277495;
64 static constexpr DesktopCapturer::SourceId kScreenId = 1378277496;
65
zijiehe062a1592017-02-17 22:32:0466 DesktopCapturer::Callback* callback_ = nullptr;
zijiehe653e14b2016-09-05 22:26:3267 std::unique_ptr<SharedMemoryFactory> shared_memory_factory_;
zijiehe062a1592017-02-17 22:32:0468 DesktopCapturer::Result result_ = Result::SUCCESS;
69 DesktopFrameGenerator* generator_ = nullptr;
70 int num_frames_captured_ = 0;
71 int num_capture_attempts_ = 0;
zijiehe653e14b2016-09-05 22:26:3272};
73
74} // namespace webrtc
75
76#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_