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 media::VideoPixelFormat | |
37 FakeVideoCaptureDeviceFactory::GetPixelFormatFromDeviceId( | |
38 const std::string& device_id) { | |
39 if (device_id == "/dev/video1") | |
40 return media::PIXEL_FORMAT_Y16; | |
41 if (device_id == "/dev/video2") | |
42 return media::PIXEL_FORMAT_MJPEG; | |
43 return media::PIXEL_FORMAT_I420; | |
44 } | |
mcasas
2017/02/17 18:35:47
Yeah, make this again file static.
chfremer
2017/02/22 17:28:42
See other comment.
| |
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 media::VideoPixelFormat pixel_format = | |
56 GetPixelFormatFromDeviceId(possible_id); | |
57 FakeVideoCaptureDeviceMaker::DeliveryMode delivery_mode = delivery_mode_; | |
58 if (delivery_mode == FakeVideoCaptureDeviceMaker::DeliveryMode:: | |
59 USE_CLIENT_PROVIDED_BUFFERS && | |
60 pixel_format == media::PIXEL_FORMAT_MJPEG) { | |
61 // Incompatible options. Fall back to using internal buffers. | |
62 delivery_mode = FakeVideoCaptureDeviceMaker::DeliveryMode:: | |
63 USE_DEVICE_INTERNAL_BUFFERS; | |
64 } | |
54 return FakeVideoCaptureDeviceMaker::MakeInstance( | 65 return FakeVideoCaptureDeviceMaker::MakeInstance( |
55 GetPixelFormatFromDeviceId(possible_id), delivery_mode_, frame_rate_); | 66 pixel_format, delivery_mode, frame_rate_); |
56 } | 67 } |
57 } | 68 } |
58 return std::unique_ptr<VideoCaptureDevice>(); | 69 return std::unique_ptr<VideoCaptureDevice>(); |
59 } | 70 } |
60 | 71 |
61 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( | 72 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( |
62 VideoCaptureDeviceDescriptors* device_descriptors) { | 73 VideoCaptureDeviceDescriptors* device_descriptors) { |
63 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
64 DCHECK(device_descriptors->empty()); | 75 DCHECK(device_descriptors->empty()); |
65 | 76 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 if (base::StringToUint(param.back(), &count)) { | 164 if (base::StringToUint(param.back(), &count)) { |
154 number_of_devices_ = std::min( | 165 number_of_devices_ = std::min( |
155 kFakeCaptureMaxDeviceCount, | 166 kFakeCaptureMaxDeviceCount, |
156 std::max(kFakeCaptureMinDeviceCount, static_cast<int>(count))); | 167 std::max(kFakeCaptureMinDeviceCount, static_cast<int>(count))); |
157 } | 168 } |
158 } | 169 } |
159 } | 170 } |
160 } | 171 } |
161 | 172 |
162 } // namespace media | 173 } // namespace media |
OLD | NEW |