blob: 086e6df0e2d4329aae278043dd6e00007dc19802 [file] [log] [blame]
zijiehefef86532016-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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_
12#define MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_
zijiehefef86532016-09-05 22:26:3213
14#include <memory>
zijiehefef86532016-09-05 22:26:3215
Yves Gerey665174f2018-06-19 13:03:0516#include "modules/desktop_capture/desktop_capturer.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "modules/desktop_capture/desktop_frame_generator.h"
18#include "modules/desktop_capture/shared_memory.h"
Mirko Bonadei3d255302018-10-11 08:50:4519#include "rtc_base/system/rtc_export.h"
zijiehefef86532016-09-05 22:26:3220
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.
Mirko Bonadei3d255302018-10-11 08:50:4534class RTC_EXPORT FakeDesktopCapturer : public DesktopCapturer {
zijiehefef86532016-09-05 22:26:3235 public:
zijiehe98903d22016-11-11 05:57:1036 FakeDesktopCapturer();
37 ~FakeDesktopCapturer() override;
zijiehefef86532016-09-05 22:26:3238
39 // Decides the result which will be returned in next Capture() callback.
zijiehe98903d22016-11-11 05:57:1040 void set_result(DesktopCapturer::Result result);
zijiehefef86532016-09-05 22:26:3241
Artem Titovcec43432021-07-28 21:35:3942 // Uses the `generator` provided as DesktopFrameGenerator, FakeDesktopCapturer
43 // does not take the ownership of `generator`.
zijiehe98903d22016-11-11 05:57:1044 void set_frame_generator(DesktopFrameGenerator* generator);
zijiehefef86532016-09-05 22:26:3245
zijiehe8fefe982017-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
zijiehefef86532016-09-05 22:26:3254 // DesktopCapturer interface
zijiehe98903d22016-11-11 05:57:1055 void Start(DesktopCapturer::Callback* callback) override;
56 void CaptureFrame() override;
zijiehefef86532016-09-05 22:26:3257 void SetSharedMemoryFactory(
zijiehe98903d22016-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;
zijiehe54fd5792016-11-02 21:49:3561
zijiehefef86532016-09-05 22:26:3262 private:
zijiehe54fd5792016-11-02 21:49:3563 static constexpr DesktopCapturer::SourceId kWindowId = 1378277495;
64 static constexpr DesktopCapturer::SourceId kScreenId = 1378277496;
65
zijiehe8fefe982017-02-17 22:32:0466 DesktopCapturer::Callback* callback_ = nullptr;
zijiehefef86532016-09-05 22:26:3267 std::unique_ptr<SharedMemoryFactory> shared_memory_factory_;
zijiehe8fefe982017-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;
zijiehefef86532016-09-05 22:26:3272};
73
74} // namespace webrtc
75
Mirko Bonadei92ea95e2017-09-15 04:47:3176#endif // MODULES_DESKTOP_CAPTURE_FAKE_DESKTOP_CAPTURER_H_