Index: media/capture/video/fake_video_capture_device_factory.cc |
diff --git a/media/capture/video/fake_video_capture_device_factory.cc b/media/capture/video/fake_video_capture_device_factory.cc |
index 38ef6054ecb237593f6ec916050fb036b80aa2b0..07d9f67bdcd9e036e8c5d1feb78a89cfb5ca5bf5 100644 |
--- a/media/capture/video/fake_video_capture_device_factory.cc |
+++ b/media/capture/video/fake_video_capture_device_factory.cc |
@@ -13,6 +13,17 @@ |
#include "build/build_config.h" |
#include "media/base/media_switches.h" |
+namespace { |
+ |
+// Factory has one device by default; I420. If there are more, the second device |
+// is of Y16 format while the rest are I420. |
+media::VideoPixelFormat GetPixelFormat(const std::string& device_id) { |
+ if (device_id == "/dev/video1") |
+ return media::PIXEL_FORMAT_Y16; |
+ return media::PIXEL_FORMAT_I420; |
+} |
+} |
+ |
namespace media { |
// Cap the frame rate command line input to reasonable values. |
@@ -20,6 +31,9 @@ static const float kFakeCaptureMinFrameRate = 5.0f; |
static const float kFakeCaptureMaxFrameRate = 60.0f; |
// Default rate if none is specified as part of the command line. |
static const float kFakeCaptureDefaultFrameRate = 20.0f; |
+// Cap the device count command line input to reasonable values. |
+static const int kFakeCaptureMinDeviceCount = 1; |
+static const int kFakeCaptureMaxDeviceCount = 10; |
FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() |
: number_of_devices_(1), |
@@ -35,8 +49,8 @@ std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( |
for (int n = 0; n < number_of_devices_; ++n) { |
std::string possible_id = base::StringPrintf("/dev/video%d", n); |
if (device_descriptor.device_id.compare(possible_id) == 0) { |
- return std::unique_ptr<VideoCaptureDevice>( |
- new FakeVideoCaptureDevice(fake_vcd_ownership_, frame_rate_)); |
+ return std::unique_ptr<VideoCaptureDevice>(new FakeVideoCaptureDevice( |
+ fake_vcd_ownership_, frame_rate_, GetPixelFormat(possible_id))); |
} |
} |
return std::unique_ptr<VideoCaptureDevice>(); |
@@ -46,6 +60,9 @@ void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( |
VideoCaptureDeviceDescriptors* device_descriptors) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
DCHECK(device_descriptors->empty()); |
+ |
+ parse_command_line(); |
+ |
for (int n = 0; n < number_of_devices_; ++n) { |
device_descriptors->emplace_back(base::StringPrintf("fake_device_%d", n), |
base::StringPrintf("/dev/video%d", n), |
@@ -66,21 +83,23 @@ void FakeVideoCaptureDeviceFactory::GetSupportedFormats( |
const VideoCaptureDeviceDescriptor& device_descriptor, |
VideoCaptureFormats* supported_formats) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- const gfx::Size supported_sizes[] = {gfx::Size(320, 240), |
- gfx::Size(640, 480), |
- gfx::Size(1280, 720), |
- gfx::Size(1920, 1080)}; |
+ const gfx::Size supported_sizes[] = { |
+ gfx::Size(96, 96), gfx::Size(320, 240), gfx::Size(640, 480), |
+ gfx::Size(1280, 720), gfx::Size(1920, 1080)}; |
supported_formats->clear(); |
for (const auto& size : supported_sizes) { |
- supported_formats->push_back( |
- VideoCaptureFormat(size, frame_rate_, media::PIXEL_FORMAT_I420)); |
+ supported_formats->push_back(VideoCaptureFormat( |
+ size, frame_rate_, GetPixelFormat(device_descriptor.device_id))); |
} |
} |
// Optional comma delimited parameters to the command line can specify buffer |
-// ownership, buffer planarity, and the fake video device FPS. |
-// Examples: "ownership=client, planarity=triplanar, fps=60" "fps=30" |
+// ownership, device count, and the fake video devices FPS. |
+// Examples: "ownership=client, device-count=2, fps=60" "fps=30" |
void FakeVideoCaptureDeviceFactory::parse_command_line() { |
+ if (command_line_parsed_) |
+ return; |
+ command_line_parsed_ = true; |
mcasas
2016/10/26 02:03:15
nit; consider doing this flag management directly
aleksandar.stojiljkovic
2016/10/26 14:46:01
Done, both good points.
|
const std::string option = |
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
switches::kUseFakeDeviceForMediaStream); |
@@ -109,6 +128,14 @@ void FakeVideoCaptureDeviceFactory::parse_command_line() { |
std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps)); |
frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); |
} |
+ } else if (base::EqualsCaseInsensitiveASCII(param.front(), |
+ "device-count")) { |
+ unsigned int count = 0; |
+ if (base::StringToUint(param.back(), &count)) { |
+ number_of_devices_ = std::min( |
+ kFakeCaptureMaxDeviceCount, |
+ std::max(kFakeCaptureMinDeviceCount, static_cast<int>(count))); |
+ } |
} |
} |
} |