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
3 // found in the LICENSE file.
5 #include "media/capture/video/fake_video_capture_device_factory.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h"
10 #include "media/base/media_switches.h"
11 #include "media/capture/video/fake_video_capture_device.h"
15 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory()
16 : number_of_devices_(1) {
19 scoped_ptr
<VideoCaptureDevice
> FakeVideoCaptureDeviceFactory::Create(
20 const VideoCaptureDevice::Name
& device_name
) {
21 DCHECK(thread_checker_
.CalledOnValidThread());
23 const std::string option
=
24 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
25 switches::kUseFakeDeviceForMediaStream
);
27 const FakeVideoCaptureDevice::BufferOwnership fake_vcd_ownership
=
28 base::StartsWith(option
, "client", base::CompareCase::INSENSITIVE_ASCII
)
29 ? FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS
30 : FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS
;
32 const FakeVideoCaptureDevice::BufferPlanarity fake_vcd_planarity
=
33 base::EndsWith(option
, "triplanar", base::CompareCase::INSENSITIVE_ASCII
)
34 ? FakeVideoCaptureDevice::BufferPlanarity::TRIPLANAR
35 : FakeVideoCaptureDevice::BufferPlanarity::PACKED
;
37 for (int n
= 0; n
< number_of_devices_
; ++n
) {
38 std::string possible_id
= base::StringPrintf("/dev/video%d", n
);
39 if (device_name
.id().compare(possible_id
) == 0) {
40 return scoped_ptr
<VideoCaptureDevice
>(
41 new FakeVideoCaptureDevice(fake_vcd_ownership
, fake_vcd_planarity
));
44 return scoped_ptr
<VideoCaptureDevice
>();
47 void FakeVideoCaptureDeviceFactory::GetDeviceNames(
48 VideoCaptureDevice::Names
* const device_names
) {
49 DCHECK(thread_checker_
.CalledOnValidThread());
50 DCHECK(device_names
->empty());
51 for (int n
= 0; n
< number_of_devices_
; ++n
) {
52 VideoCaptureDevice::Name
name(base::StringPrintf("fake_device_%d", n
),
53 base::StringPrintf("/dev/video%d", n
)
56 VideoCaptureDevice::Name::V4L2_SINGLE_PLANE
57 #elif defined(OS_MACOSX)
59 VideoCaptureDevice::Name::AVFOUNDATION
62 VideoCaptureDevice::Name::DIRECT_SHOW
63 #elif defined(OS_ANDROID)
65 VideoCaptureDevice::Name::API2_LEGACY
68 device_names
->push_back(name
);
72 void FakeVideoCaptureDeviceFactory::GetDeviceSupportedFormats(
73 const VideoCaptureDevice::Name
& device
,
74 VideoCaptureFormats
* supported_formats
) {
75 DCHECK(thread_checker_
.CalledOnValidThread());
76 const int frame_rate
= 1000 / FakeVideoCaptureDevice::FakeCapturePeriodMs();
77 const gfx::Size supported_sizes
[] = {gfx::Size(320, 240),
80 gfx::Size(1920, 1080)};
81 supported_formats
->clear();
82 for (const auto& size
: supported_sizes
) {
83 supported_formats
->push_back(
84 VideoCaptureFormat(size
, frame_rate
, media::PIXEL_FORMAT_I420
));