1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
media / capture / video / fake_video_capture_device_factory.h [blame]
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_
#define MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "build/build_config.h"
#include "media/base/video_facing.h"
#include "media/capture/video/fake_video_capture_device.h"
#include "media/capture/video/video_capture_device_descriptor.h"
#include "media/capture/video/video_capture_device_factory.h"
#if BUILDFLAG(IS_WIN)
#include "base/win/windows_types.h"
#include "media/base/win/dxgi_device_manager.h"
#endif
namespace gpu {
class GpuMemoryBufferSupport;
} // namespace gpu
namespace media {
struct CAPTURE_EXPORT FakeVideoCaptureDeviceSettings {
FakeVideoCaptureDeviceSettings();
~FakeVideoCaptureDeviceSettings();
FakeVideoCaptureDeviceSettings(const FakeVideoCaptureDeviceSettings& other);
std::string device_id;
FakeVideoCaptureDevice::DeliveryMode delivery_mode;
VideoCaptureFormats supported_formats;
FakePhotoDeviceConfig photo_device_config;
FakeVideoCaptureDevice::DisplayMediaType display_media_type;
std::optional<media::CameraAvailability> availability;
};
// Implementation of VideoCaptureDeviceFactory that creates fake devices
// that generate test output frames.
// By default, the factory has one device outputting I420 with
// USE_DEVICE_INTERNAL_BUFFERS. It supports a default set of resolutions.
// When a resolution is requested that is not part of the default set, it snaps
// to the resolution with the next larger width. It supports all frame rates
// within a default allowed range.
class CAPTURE_EXPORT FakeVideoCaptureDeviceFactory
: public VideoCaptureDeviceFactory {
public:
static constexpr const char kDeviceConfigForGetPhotoStateFails[] =
"GetPhotoStateFails";
static constexpr const char kDeviceConfigForSetPhotoOptionsFails[] =
"SetPhotoOptionsFails";
static constexpr const char kDeviceConfigForTakePhotoFails[] =
"TakePhotoFails";
FakeVideoCaptureDeviceFactory();
~FakeVideoCaptureDeviceFactory() override;
static std::unique_ptr<VideoCaptureDevice> CreateDeviceWithSettings(
const FakeVideoCaptureDeviceSettings& settings,
std::unique_ptr<gpu::GpuMemoryBufferSupport> gmb_support = nullptr);
static std::unique_ptr<VideoCaptureDevice> CreateDeviceWithDefaultResolutions(
VideoPixelFormat pixel_format,
FakeVideoCaptureDevice::DeliveryMode delivery_mode,
float frame_rate,
std::unique_ptr<gpu::GpuMemoryBufferSupport> gmb_support = nullptr);
// Creates a device that reports OnError() when AllocateAndStart() is called.
static std::unique_ptr<VideoCaptureDevice> CreateErrorDevice();
static void ParseFakeDevicesConfigFromOptionsString(
const std::string options_string,
std::vector<FakeVideoCaptureDeviceSettings>* config);
// All devices use the default set of resolution, the default range for
// allowed frame rates, as well as USE_DEVICE_INTERNAL_BUFFERS.
// Device 0 outputs I420.
// Device 1 outputs Y16.
// Device 2 outputs MJPEG.
// All additional devices output I420.
void SetToDefaultDevicesConfig(int device_count);
void SetToCustomDevicesConfig(
const std::vector<FakeVideoCaptureDeviceSettings>& config);
// VideoCaptureDeviceFactory implementation:
VideoCaptureErrorOrDevice CreateDevice(
const VideoCaptureDeviceDescriptor& device_descriptor) override;
void GetDevicesInfo(GetDevicesInfoCallback callback) override;
int number_of_devices() {
DCHECK(thread_checker_.CalledOnValidThread());
return static_cast<int>(devices_config_.size());
}
#if BUILDFLAG(IS_WIN)
void OnGpuInfoUpdate(const CHROME_LUID& luid) override;
scoped_refptr<DXGIDeviceManager> GetDxgiDeviceManager() override;
#endif
private:
// Helper used in GetDevicesInfo().
VideoCaptureFormats GetSupportedFormats(const std::string& device_id);
std::vector<FakeVideoCaptureDeviceSettings> devices_config_;
#if BUILDFLAG(IS_WIN)
scoped_refptr<DXGIDeviceManager> dxgi_device_manager_;
CHROME_LUID luid_ = {0, 0};
#endif
};
} // namespace media
#endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_