| 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 { |
| 17 |
| 18 media::VideoPixelFormat get_pixelformat(const std::string& device_id) { |
| 19 if (device_id == "/dev/video1") |
| 20 return media::PIXEL_FORMAT_Y16; |
| 21 return media::PIXEL_FORMAT_I420; |
| 22 } |
| 23 } |
| 24 |
| 16 namespace media { | 25 namespace media { |
| 17 | 26 |
| 18 // Cap the frame rate command line input to reasonable values. | 27 // Cap the frame rate command line input to reasonable values. |
| 19 static const float kFakeCaptureMinFrameRate = 5.0f; | 28 static const float kFakeCaptureMinFrameRate = 5.0f; |
| 20 static const float kFakeCaptureMaxFrameRate = 60.0f; | 29 static const float kFakeCaptureMaxFrameRate = 60.0f; |
| 21 // Default rate if none is specified as part of the command line. | 30 // Default rate if none is specified as part of the command line. |
| 22 static const float kFakeCaptureDefaultFrameRate = 20.0f; | 31 static const float kFakeCaptureDefaultFrameRate = 20.0f; |
| 23 | 32 |
| 24 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() | 33 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() |
| 25 : number_of_devices_(1), | 34 : number_of_devices_(2), |
| 26 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS), | 35 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS), |
| 27 frame_rate_(kFakeCaptureDefaultFrameRate) {} | 36 frame_rate_(kFakeCaptureDefaultFrameRate) {} |
| 28 | 37 |
| 29 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( | 38 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( |
| 30 const VideoCaptureDeviceDescriptor& device_descriptor) { | 39 const VideoCaptureDeviceDescriptor& device_descriptor) { |
| 31 DCHECK(thread_checker_.CalledOnValidThread()); | 40 DCHECK(thread_checker_.CalledOnValidThread()); |
| 32 | 41 |
| 33 parse_command_line(); | 42 parse_command_line(); |
| 34 | 43 |
| 35 for (int n = 0; n < number_of_devices_; ++n) { | 44 for (int n = 0; n < number_of_devices_; ++n) { |
| 36 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 45 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
| 37 if (device_descriptor.device_id.compare(possible_id) == 0) { | 46 if (device_descriptor.device_id.compare(possible_id) == 0) { |
| 38 return std::unique_ptr<VideoCaptureDevice>( | 47 return std::unique_ptr<VideoCaptureDevice>(new FakeVideoCaptureDevice( |
| 39 new FakeVideoCaptureDevice(fake_vcd_ownership_, frame_rate_)); | 48 fake_vcd_ownership_, frame_rate_, get_pixelformat(possible_id))); |
| 40 } | 49 } |
| 41 } | 50 } |
| 42 return std::unique_ptr<VideoCaptureDevice>(); | 51 return std::unique_ptr<VideoCaptureDevice>(); |
| 43 } | 52 } |
| 44 | 53 |
| 45 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( | 54 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( |
| 46 VideoCaptureDeviceDescriptors* device_descriptors) { | 55 VideoCaptureDeviceDescriptors* device_descriptors) { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 DCHECK(device_descriptors->empty()); | 57 DCHECK(device_descriptors->empty()); |
| 49 for (int n = 0; n < number_of_devices_; ++n) { | 58 for (int n = 0; n < number_of_devices_; ++n) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 65 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( | 74 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( |
| 66 const VideoCaptureDeviceDescriptor& device_descriptor, | 75 const VideoCaptureDeviceDescriptor& device_descriptor, |
| 67 VideoCaptureFormats* supported_formats) { | 76 VideoCaptureFormats* supported_formats) { |
| 68 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
| 69 const gfx::Size supported_sizes[] = {gfx::Size(320, 240), | 78 const gfx::Size supported_sizes[] = {gfx::Size(320, 240), |
| 70 gfx::Size(640, 480), | 79 gfx::Size(640, 480), |
| 71 gfx::Size(1280, 720), | 80 gfx::Size(1280, 720), |
| 72 gfx::Size(1920, 1080)}; | 81 gfx::Size(1920, 1080)}; |
| 73 supported_formats->clear(); | 82 supported_formats->clear(); |
| 74 for (const auto& size : supported_sizes) { | 83 for (const auto& size : supported_sizes) { |
| 75 supported_formats->push_back( | 84 supported_formats->push_back(VideoCaptureFormat( |
| 76 VideoCaptureFormat(size, frame_rate_, media::PIXEL_FORMAT_I420)); | 85 size, frame_rate_, get_pixelformat(device_descriptor.device_id))); |
| 77 } | 86 } |
| 78 } | 87 } |
| 79 | 88 |
| 80 // Optional comma delimited parameters to the command line can specify buffer | 89 // Optional comma delimited parameters to the command line can specify buffer |
| 81 // ownership, buffer planarity, and the fake video device FPS. | 90 // ownership, buffer planarity, and the fake video device FPS. |
| 82 // Examples: "ownership=client, planarity=triplanar, fps=60" "fps=30" | 91 // Examples: "ownership=client, planarity=triplanar, fps=60" "fps=30" |
| 83 void FakeVideoCaptureDeviceFactory::parse_command_line() { | 92 void FakeVideoCaptureDeviceFactory::parse_command_line() { |
| 84 const std::string option = | 93 const std::string option = |
| 85 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 94 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 86 switches::kUseFakeDeviceForMediaStream); | 95 switches::kUseFakeDeviceForMediaStream); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 107 if (base::StringToDouble(param.back(), &fps)) { | 116 if (base::StringToDouble(param.back(), &fps)) { |
| 108 frame_rate_ = | 117 frame_rate_ = |
| 109 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps)); | 118 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps)); |
| 110 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); | 119 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); |
| 111 } | 120 } |
| 112 } | 121 } |
| 113 } | 122 } |
| 114 } | 123 } |
| 115 | 124 |
| 116 } // namespace media | 125 } // namespace media |
| OLD | NEW |