| 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 media { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 static const size_t kDepthDeviceIndex = 1; | 19 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 | 20 |
| 30 // Cap the frame rate command line input to reasonable values. | 21 // Cap the frame rate command line input to reasonable values. |
| 31 static const float kFakeCaptureMinFrameRate = 5.0f; | 22 static const float kFakeCaptureMinFrameRate = 5.0f; |
| 32 static const float kFakeCaptureMaxFrameRate = 60.0f; | 23 static const float kFakeCaptureMaxFrameRate = 60.0f; |
| 33 // Default rate if none is specified as part of the command line. | 24 // Default rate if none is specified as part of the command line. |
| 34 static const float kFakeCaptureDefaultFrameRate = 20.0f; | 25 static const float kFakeCaptureDefaultFrameRate = 20.0f; |
| 35 // Cap the device count command line input to reasonable values. | 26 // Cap the device count command line input to reasonable values. |
| 36 static const int kFakeCaptureMinDeviceCount = 1; | 27 static const int kFakeCaptureMinDeviceCount = 1; |
| 37 static const int kFakeCaptureMaxDeviceCount = 10; | 28 static const int kFakeCaptureMaxDeviceCount = 10; |
| 38 | 29 |
| 30 FakeVideoCaptureDeviceMaker::PixelFormat GetPixelFormatFromDeviceId( |
| 31 const std::string& device_id) { |
| 32 if (device_id == "/dev/video1") |
| 33 return FakeVideoCaptureDeviceMaker::PixelFormat::Y16; |
| 34 if (device_id == "/dev/video2") |
| 35 return FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG; |
| 36 return FakeVideoCaptureDeviceMaker::PixelFormat::I420; |
| 37 } |
| 38 |
| 39 } // anonymous namespace |
| 40 |
| 39 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() | 41 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() |
| 40 : number_of_devices_(1), | 42 : number_of_devices_(1), |
| 41 delivery_mode_(FakeVideoCaptureDeviceMaker::DeliveryMode:: | 43 delivery_mode_(FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 42 USE_DEVICE_INTERNAL_BUFFERS), | 44 USE_DEVICE_INTERNAL_BUFFERS), |
| 43 frame_rate_(kFakeCaptureDefaultFrameRate) {} | 45 frame_rate_(kFakeCaptureDefaultFrameRate) {} |
| 44 | 46 |
| 45 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( | 47 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( |
| 46 const VideoCaptureDeviceDescriptor& device_descriptor) { | 48 const VideoCaptureDeviceDescriptor& device_descriptor) { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 | 50 |
| 49 ParseCommandLine(); | 51 ParseCommandLine(); |
| 50 | 52 |
| 51 for (int n = 0; n < number_of_devices_; ++n) { | 53 for (int n = 0; n < number_of_devices_; ++n) { |
| 52 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 54 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
| 53 if (device_descriptor.device_id.compare(possible_id) == 0) { | 55 if (device_descriptor.device_id.compare(possible_id) == 0) { |
| 56 FakeVideoCaptureDeviceMaker::PixelFormat pixel_format = |
| 57 GetPixelFormatFromDeviceId(possible_id); |
| 58 FakeVideoCaptureDeviceMaker::DeliveryMode delivery_mode = delivery_mode_; |
| 59 if (delivery_mode == |
| 60 FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 61 USE_CLIENT_PROVIDED_BUFFERS && |
| 62 pixel_format == FakeVideoCaptureDeviceMaker::PixelFormat::MJPEG) { |
| 63 // Incompatible options. Fall back to using internal buffers. |
| 64 delivery_mode = FakeVideoCaptureDeviceMaker::DeliveryMode:: |
| 65 USE_DEVICE_INTERNAL_BUFFERS; |
| 66 } |
| 54 return FakeVideoCaptureDeviceMaker::MakeInstance( | 67 return FakeVideoCaptureDeviceMaker::MakeInstance( |
| 55 GetPixelFormatFromDeviceId(possible_id), delivery_mode_, frame_rate_); | 68 pixel_format, delivery_mode, frame_rate_); |
| 56 } | 69 } |
| 57 } | 70 } |
| 58 return std::unique_ptr<VideoCaptureDevice>(); | 71 return std::unique_ptr<VideoCaptureDevice>(); |
| 59 } | 72 } |
| 60 | 73 |
| 61 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( | 74 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( |
| 62 VideoCaptureDeviceDescriptors* device_descriptors) { | 75 VideoCaptureDeviceDescriptors* device_descriptors) { |
| 63 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
| 64 DCHECK(device_descriptors->empty()); | 77 DCHECK(device_descriptors->empty()); |
| 65 | 78 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 93 depth_device.camera_calibration->depth_far = 65.535; | 106 depth_device.camera_calibration->depth_far = 65.535; |
| 94 } | 107 } |
| 95 | 108 |
| 96 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( | 109 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( |
| 97 const VideoCaptureDeviceDescriptor& device_descriptor, | 110 const VideoCaptureDeviceDescriptor& device_descriptor, |
| 98 VideoCaptureFormats* supported_formats) { | 111 VideoCaptureFormats* supported_formats) { |
| 99 DCHECK(thread_checker_.CalledOnValidThread()); | 112 DCHECK(thread_checker_.CalledOnValidThread()); |
| 100 | 113 |
| 101 ParseCommandLine(); | 114 ParseCommandLine(); |
| 102 | 115 |
| 103 const VideoPixelFormat pixel_format = | 116 const VideoPixelFormat pixel_format = static_cast<VideoPixelFormat>( |
| 104 GetPixelFormatFromDeviceId(device_descriptor.device_id); | 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 |