OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_ | 5 #ifndef MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_ |
6 #define MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_ | 6 #define MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_ |
7 | 7 |
8 #include "media/capture/video/fake_video_capture_device.h" | 8 #include "media/capture/video/fake_video_capture_device.h" |
9 #include "media/capture/video/video_capture_device_factory.h" | 9 #include "media/capture/video/video_capture_device_factory.h" |
10 | 10 |
11 namespace media { | 11 namespace media { |
12 | 12 |
| 13 struct CAPTURE_EXPORT FakeVideoCaptureDeviceSettings { |
| 14 FakeVideoCaptureDeviceSettings(); |
| 15 ~FakeVideoCaptureDeviceSettings(); |
| 16 FakeVideoCaptureDeviceSettings(const FakeVideoCaptureDeviceSettings& other); |
| 17 |
| 18 std::string device_id; |
| 19 FakeVideoCaptureDevice::DeliveryMode delivery_mode; |
| 20 VideoCaptureFormats supported_formats; |
| 21 }; |
| 22 |
13 // Implementation of VideoCaptureDeviceFactory that creates fake devices | 23 // Implementation of VideoCaptureDeviceFactory that creates fake devices |
14 // that generate test output frames. | 24 // that generate test output frames. |
15 // By default, the factory has one device outputting I420. | 25 // By default, the factory has one device outputting I420 with |
16 // When increasing the number of devices using set_number_of_devices(), the | 26 // USE_DEVICE_INTERNAL_BUFFERS. It supports a default set of resolutions. |
17 // second device will use Y16, and any devices beyond that will use I420. | 27 // When a resolution is requested that is not part of the default set, it snaps |
18 // By default, the delivery mode of all devices is USE_OWN_BUFFERS. | 28 // to the resolution with the next larger width. It supports all frame rates |
19 // This, as well as other parameters, can be changed using command-line flags. | 29 // within a default allowed range. |
20 // See implementation of method ParseCommandLine() for details. | |
21 class CAPTURE_EXPORT FakeVideoCaptureDeviceFactory | 30 class CAPTURE_EXPORT FakeVideoCaptureDeviceFactory |
22 : public VideoCaptureDeviceFactory { | 31 : public VideoCaptureDeviceFactory { |
23 public: | 32 public: |
24 FakeVideoCaptureDeviceFactory(); | 33 FakeVideoCaptureDeviceFactory(); |
25 ~FakeVideoCaptureDeviceFactory() override {} | 34 ~FakeVideoCaptureDeviceFactory() override; |
26 | 35 |
| 36 static std::unique_ptr<VideoCaptureDevice> CreateDeviceWithSupportedFormats( |
| 37 FakeVideoCaptureDevice::DeliveryMode delivery_mode, |
| 38 const VideoCaptureFormats& formats); |
| 39 |
| 40 static std::unique_ptr<VideoCaptureDevice> CreateDeviceWithDefaultResolutions( |
| 41 VideoPixelFormat pixel_format, |
| 42 FakeVideoCaptureDevice::DeliveryMode delivery_mode, |
| 43 float frame_rate); |
| 44 |
| 45 // Creates a device that reports OnError() when AllocateAndStart() is called. |
| 46 static std::unique_ptr<VideoCaptureDevice> CreateErrorDevice(); |
| 47 |
| 48 static void ParseFakeDevicesConfigFromOptionsString( |
| 49 const std::string options_string, |
| 50 std::vector<FakeVideoCaptureDeviceSettings>* config); |
| 51 |
| 52 // All devices use the default set of resolution, the default range for |
| 53 // allowed frame rates, as well as USE_DEVICE_INTERNAL_BUFFERS. |
| 54 // Device 0 outputs I420. |
| 55 // Device 1 outputs Y16. |
| 56 // Device 2 outputs MJPEG. |
| 57 // All additional devices output I420. |
| 58 void SetToDefaultDevicesConfig(int device_count); |
| 59 void SetToCustomDevicesConfig( |
| 60 const std::vector<FakeVideoCaptureDeviceSettings>& config); |
| 61 |
| 62 // VideoCaptureDeviceFactory implementation: |
27 std::unique_ptr<VideoCaptureDevice> CreateDevice( | 63 std::unique_ptr<VideoCaptureDevice> CreateDevice( |
28 const VideoCaptureDeviceDescriptor& device_descriptor) override; | 64 const VideoCaptureDeviceDescriptor& device_descriptor) override; |
29 void GetDeviceDescriptors( | 65 void GetDeviceDescriptors( |
30 VideoCaptureDeviceDescriptors* device_descriptors) override; | 66 VideoCaptureDeviceDescriptors* device_descriptors) override; |
31 void GetSupportedFormats( | 67 void GetSupportedFormats( |
32 const VideoCaptureDeviceDescriptor& device_descriptor, | 68 const VideoCaptureDeviceDescriptor& device_descriptor, |
33 VideoCaptureFormats* supported_formats) override; | 69 VideoCaptureFormats* supported_formats) override; |
34 | 70 |
35 void set_number_of_devices(int number_of_devices) { | |
36 DCHECK(thread_checker_.CalledOnValidThread()); | |
37 number_of_devices_ = number_of_devices; | |
38 } | |
39 int number_of_devices() { | 71 int number_of_devices() { |
40 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
41 return number_of_devices_; | 73 return static_cast<int>(devices_config_.size()); |
42 } | 74 } |
43 | 75 |
44 private: | 76 private: |
45 void ParseCommandLine(); | 77 std::vector<FakeVideoCaptureDeviceSettings> devices_config_; |
46 | |
47 int number_of_devices_; | |
48 FakeVideoCaptureDeviceMaker::DeliveryMode delivery_mode_; | |
49 float frame_rate_; | |
50 bool command_line_parsed_ = false; | |
51 }; | 78 }; |
52 | 79 |
53 } // namespace media | 80 } // namespace media |
54 | 81 |
55 #endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_ | 82 #endif // MEDIA_CAPTURE_VIDEO_FAKE_VIDEO_CAPTURE_DEVICE_FACTORY_H_ |
OLD | NEW |