Chromium Code Reviews| 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/macros.h" | |
| 8 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_tokenizer.h" | 11 #include "base/strings/string_tokenizer.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 29 namespace media { | 30 namespace media { |
| 30 | 31 |
| 31 // Cap the frame rate command line input to reasonable values. | 32 // Cap the frame rate command line input to reasonable values. |
| 32 static const float kFakeCaptureMinFrameRate = 5.0f; | 33 static const float kFakeCaptureMinFrameRate = 5.0f; |
| 33 static const float kFakeCaptureMaxFrameRate = 60.0f; | 34 static const float kFakeCaptureMaxFrameRate = 60.0f; |
| 34 // Default rate if none is specified as part of the command line. | 35 // Default rate if none is specified as part of the command line. |
| 35 static const float kFakeCaptureDefaultFrameRate = 20.0f; | 36 static const float kFakeCaptureDefaultFrameRate = 20.0f; |
| 36 // Cap the device count command line input to reasonable values. | 37 // Cap the device count command line input to reasonable values. |
| 37 static const int kFakeCaptureMinDeviceCount = 1; | 38 static const int kFakeCaptureMinDeviceCount = 1; |
| 38 static const int kFakeCaptureMaxDeviceCount = 10; | 39 static const int kFakeCaptureMaxDeviceCount = 10; |
| 40 static const int kFakeCaptureMinFormatCount = 0; | |
| 39 | 41 |
| 40 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() | 42 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() |
| 41 : number_of_devices_(1), | 43 : number_of_devices_(1), |
| 44 number_of_formats_per_device_(5), | |
| 42 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS), | 45 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS), |
| 43 frame_rate_(kFakeCaptureDefaultFrameRate) {} | 46 frame_rate_(kFakeCaptureDefaultFrameRate) {} |
| 44 | 47 |
| 45 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( | 48 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( |
| 46 const VideoCaptureDeviceDescriptor& device_descriptor) { | 49 const VideoCaptureDeviceDescriptor& device_descriptor) { |
| 47 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 48 | 51 |
| 49 if (!command_line_parsed_) { | 52 if (!command_line_parsed_) { |
| 50 ParseCommandLine(); | 53 ParseCommandLine(); |
| 51 command_line_parsed_ = true; | 54 command_line_parsed_ = true; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 103 } |
| 101 | 104 |
| 102 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( | 105 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( |
| 103 const VideoCaptureDeviceDescriptor& device_descriptor, | 106 const VideoCaptureDeviceDescriptor& device_descriptor, |
| 104 VideoCaptureFormats* supported_formats) { | 107 VideoCaptureFormats* supported_formats) { |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); | 108 DCHECK(thread_checker_.CalledOnValidThread()); |
| 106 const gfx::Size supported_sizes[] = { | 109 const gfx::Size supported_sizes[] = { |
| 107 gfx::Size(96, 96), gfx::Size(320, 240), gfx::Size(640, 480), | 110 gfx::Size(96, 96), gfx::Size(320, 240), gfx::Size(640, 480), |
| 108 gfx::Size(1280, 720), gfx::Size(1920, 1080)}; | 111 gfx::Size(1280, 720), gfx::Size(1920, 1080)}; |
| 109 supported_formats->clear(); | 112 supported_formats->clear(); |
| 110 for (const auto& size : supported_sizes) { | 113 size_t num_formats = |
| 111 supported_formats->push_back(VideoCaptureFormat( | 114 std::min(arraysize(supported_sizes), |
| 112 size, frame_rate_, GetPixelFormat(device_descriptor.device_id))); | 115 static_cast<size_t>(number_of_formats_per_device_)); |
| 116 for (size_t i = 0; i < num_formats; ++i) { | |
| 117 supported_formats->push_back( | |
| 118 VideoCaptureFormat(supported_sizes[i], frame_rate_, | |
| 119 GetPixelFormat(device_descriptor.device_id))); | |
| 113 } | 120 } |
| 114 } | 121 } |
| 115 | 122 |
| 116 // Optional comma delimited parameters to the command line can specify buffer | 123 // Optional comma delimited parameters to the command line can specify buffer |
| 117 // ownership, device count, and the fake video devices FPS. | 124 // ownership, device count, and the fake video devices FPS. |
| 118 // Examples: "ownership=client, device-count=2, fps=60" "fps=30" | 125 // Examples: "ownership=client, device-count=2, fps=60" "fps=30" |
| 119 void FakeVideoCaptureDeviceFactory::ParseCommandLine() { | 126 void FakeVideoCaptureDeviceFactory::ParseCommandLine() { |
| 120 const std::string option = | 127 const std::string option = |
| 121 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 128 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 122 switches::kUseFakeDeviceForMediaStream); | 129 switches::kUseFakeDeviceForMediaStream); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 146 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); | 153 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); |
| 147 } | 154 } |
| 148 } else if (base::EqualsCaseInsensitiveASCII(param.front(), | 155 } else if (base::EqualsCaseInsensitiveASCII(param.front(), |
| 149 "device-count")) { | 156 "device-count")) { |
| 150 unsigned int count = 0; | 157 unsigned int count = 0; |
| 151 if (base::StringToUint(param.back(), &count)) { | 158 if (base::StringToUint(param.back(), &count)) { |
| 152 number_of_devices_ = std::min( | 159 number_of_devices_ = std::min( |
| 153 kFakeCaptureMaxDeviceCount, | 160 kFakeCaptureMaxDeviceCount, |
| 154 std::max(kFakeCaptureMinDeviceCount, static_cast<int>(count))); | 161 std::max(kFakeCaptureMinDeviceCount, static_cast<int>(count))); |
| 155 } | 162 } |
| 163 } else if (base::EqualsCaseInsensitiveASCII(param.front(), | |
| 164 "format-count")) { | |
| 165 unsigned int count = 0; | |
| 166 if (base::StringToUint(param.back(), &count)) { | |
| 167 number_of_formats_per_device_ = | |
| 168 std::max(kFakeCaptureMinFormatCount, static_cast<int>(count)); | |
| 169 } | |
|
mcasas
2017/02/14 17:01:01
I think adding a new command line flag and member
| |
| 156 } | 170 } |
| 157 } | 171 } |
| 158 } | 172 } |
| 159 | 173 |
| 160 } // namespace media | 174 } // namespace media |
| OLD | NEW |