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 #include "media/capture/video/fake_video_capture_device_factory.h" | 5 #include "media/capture/video/fake_video_capture_device_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
15 | 15 |
16 namespace { | 16 namespace media { |
17 | 17 |
18 static const size_t kDepthDeviceIndex = 1; | 18 static const size_t kDepthDeviceIndex = 1; |
19 static const char kDepthDeviceId[] = "/dev/video1"; | |
20 | |
21 media::VideoPixelFormat GetPixelFormatFromDeviceId( | |
22 const std::string& device_id) { | |
23 return (device_id == kDepthDeviceId) ? media::PIXEL_FORMAT_Y16 | |
24 : media::PIXEL_FORMAT_I420; | |
25 } | |
26 } | |
27 | |
28 namespace media { | |
29 | 19 |
30 // Cap the frame rate command line input to reasonable values. | 20 // Cap the frame rate command line input to reasonable values. |
31 static const float kFakeCaptureMinFrameRate = 5.0f; | 21 static const float kFakeCaptureMinFrameRate = 5.0f; |
32 static const float kFakeCaptureMaxFrameRate = 60.0f; | 22 static const float kFakeCaptureMaxFrameRate = 60.0f; |
33 // Default rate if none is specified as part of the command line. | 23 // Default rate if none is specified as part of the command line. |
34 static const float kFakeCaptureDefaultFrameRate = 20.0f; | 24 static const float kFakeCaptureDefaultFrameRate = 20.0f; |
35 // Cap the device count command line input to reasonable values. | 25 // Cap the device count command line input to reasonable values. |
36 static const int kFakeCaptureMinDeviceCount = 1; | 26 static const int kFakeCaptureMinDeviceCount = 1; |
37 static const int kFakeCaptureMaxDeviceCount = 10; | 27 static const int kFakeCaptureMaxDeviceCount = 10; |
38 | 28 |
39 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() | 29 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() |
40 : number_of_devices_(1), | 30 : number_of_devices_(1), |
41 delivery_mode_(FakeVideoCaptureDeviceMaker::DeliveryMode:: | 31 delivery_mode_(FakeVideoCaptureDeviceMaker::DeliveryMode:: |
42 USE_DEVICE_INTERNAL_BUFFERS), | 32 USE_DEVICE_INTERNAL_BUFFERS), |
43 frame_rate_(kFakeCaptureDefaultFrameRate) {} | 33 frame_rate_(kFakeCaptureDefaultFrameRate) {} |
44 | 34 |
| 35 // static |
| 36 FakeVideoCaptureDeviceMaker::PixelFormat |
| 37 FakeVideoCaptureDeviceFactory::GetPixelFormatFromDeviceId( |
| 38 const std::string& device_id) { |
| 39 if (device_id == "/dev/video1") |
| 40 return FakeVideoCaptureDeviceMaker::PixelFormat::Y16; |
| 41 if (device_id == "/dev/video2") |
| 42 return FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG; |
| 43 return FakeVideoCaptureDeviceMaker::PixelFormat::I420; |
| 44 } |
| 45 |
45 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( | 46 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( |
46 const VideoCaptureDeviceDescriptor& device_descriptor) { | 47 const VideoCaptureDeviceDescriptor& device_descriptor) { |
47 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
48 | 49 |
49 ParseCommandLine(); | 50 ParseCommandLine(); |
50 | 51 |
51 for (int n = 0; n < number_of_devices_; ++n) { | 52 for (int n = 0; n < number_of_devices_; ++n) { |
52 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 53 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
53 if (device_descriptor.device_id.compare(possible_id) == 0) { | 54 if (device_descriptor.device_id.compare(possible_id) == 0) { |
| 55 FakeVideoCaptureDeviceMaker::PixelFormat pixel_format = |
| 56 GetPixelFormatFromDeviceId(possible_id); |
| 57 FakeVideoCaptureDeviceMaker::DeliveryMode delivery_mode = delivery_mode_; |
| 58 if (delivery_mode == |
| 59 FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 60 USE_CLIENT_PROVIDED_BUFFERS && |
| 61 pixel_format == FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG) { |
| 62 // Incompatible options. Fall back to using internal buffers. |
| 63 delivery_mode = FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 64 USE_DEVICE_INTERNAL_BUFFERS; |
| 65 } |
54 return FakeVideoCaptureDeviceMaker::MakeInstance( | 66 return FakeVideoCaptureDeviceMaker::MakeInstance( |
55 GetPixelFormatFromDeviceId(possible_id), delivery_mode_, frame_rate_); | 67 pixel_format, delivery_mode, frame_rate_); |
56 } | 68 } |
57 } | 69 } |
58 return std::unique_ptr<VideoCaptureDevice>(); | 70 return std::unique_ptr<VideoCaptureDevice>(); |
59 } | 71 } |
60 | 72 |
61 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( | 73 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( |
62 VideoCaptureDeviceDescriptors* device_descriptors) { | 74 VideoCaptureDeviceDescriptors* device_descriptors) { |
63 DCHECK(thread_checker_.CalledOnValidThread()); | 75 DCHECK(thread_checker_.CalledOnValidThread()); |
64 DCHECK(device_descriptors->empty()); | 76 DCHECK(device_descriptors->empty()); |
65 | 77 |
(...skipping 28 matching lines...) Expand all Loading... |
94 } | 106 } |
95 | 107 |
96 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( | 108 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( |
97 const VideoCaptureDeviceDescriptor& device_descriptor, | 109 const VideoCaptureDeviceDescriptor& device_descriptor, |
98 VideoCaptureFormats* supported_formats) { | 110 VideoCaptureFormats* supported_formats) { |
99 DCHECK(thread_checker_.CalledOnValidThread()); | 111 DCHECK(thread_checker_.CalledOnValidThread()); |
100 | 112 |
101 ParseCommandLine(); | 113 ParseCommandLine(); |
102 | 114 |
103 const VideoPixelFormat pixel_format = | 115 const VideoPixelFormat pixel_format = |
104 GetPixelFormatFromDeviceId(device_descriptor.device_id); | 116 FakeVideoCaptureDeviceMaker::TranslateToMediaVideoPixelFormat( |
| 117 GetPixelFormatFromDeviceId(device_descriptor.device_id)); |
105 const VideoPixelStorage pixel_storage = PIXEL_STORAGE_CPU; | 118 const VideoPixelStorage pixel_storage = PIXEL_STORAGE_CPU; |
106 std::vector<gfx::Size> supported_sizes; | 119 std::vector<gfx::Size> supported_sizes; |
107 FakeVideoCaptureDeviceMaker::GetSupportedSizes(&supported_sizes); | 120 FakeVideoCaptureDeviceMaker::GetSupportedSizes(&supported_sizes); |
108 for (const auto& supported_size : supported_sizes) { | 121 for (const auto& supported_size : supported_sizes) { |
109 supported_formats->emplace_back(supported_size, frame_rate_, pixel_format, | 122 supported_formats->emplace_back(supported_size, frame_rate_, pixel_format, |
110 pixel_storage); | 123 pixel_storage); |
111 } | 124 } |
112 } | 125 } |
113 | 126 |
114 // Optional comma delimited parameters to the command line can specify buffer | 127 // Optional comma delimited parameters to the command line can specify buffer |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 if (base::StringToUint(param.back(), &count)) { | 166 if (base::StringToUint(param.back(), &count)) { |
154 number_of_devices_ = std::min( | 167 number_of_devices_ = std::min( |
155 kFakeCaptureMaxDeviceCount, | 168 kFakeCaptureMaxDeviceCount, |
156 std::max(kFakeCaptureMinDeviceCount, static_cast<int>(count))); | 169 std::max(kFakeCaptureMinDeviceCount, static_cast<int>(count))); |
157 } | 170 } |
158 } | 171 } |
159 } | 172 } |
160 } | 173 } |
161 | 174 |
162 } // namespace media | 175 } // namespace media |
OLD | NEW |