Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / media / capture / video / fake_video_capture_device_factory.cc
blob510399097f9dfed8594b35387e51eee4548f5e58
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"
13 namespace media {
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 FakeVideoCaptureDevice::FakeVideoCaptureDeviceType fake_vcd_type;
28 if (option.empty())
29 fake_vcd_type = FakeVideoCaptureDevice::USING_OWN_BUFFERS;
30 else if (base::EqualsCaseInsensitiveASCII(option, "triplanar"))
31 fake_vcd_type = FakeVideoCaptureDevice::USING_OWN_BUFFERS_TRIPLANAR;
32 else
33 fake_vcd_type = FakeVideoCaptureDevice::USING_CLIENT_BUFFERS;
35 for (int n = 0; n < number_of_devices_; ++n) {
36 std::string possible_id = base::StringPrintf("/dev/video%d", n);
37 if (device_name.id().compare(possible_id) == 0) {
38 return scoped_ptr<VideoCaptureDevice>(
39 new FakeVideoCaptureDevice(fake_vcd_type));
42 return scoped_ptr<VideoCaptureDevice>();
45 void FakeVideoCaptureDeviceFactory::GetDeviceNames(
46 VideoCaptureDevice::Names* const device_names) {
47 DCHECK(thread_checker_.CalledOnValidThread());
48 DCHECK(device_names->empty());
49 for (int n = 0; n < number_of_devices_; ++n) {
50 VideoCaptureDevice::Name name(base::StringPrintf("fake_device_%d", n),
51 base::StringPrintf("/dev/video%d", n)
52 #if defined(OS_LINUX)
54 VideoCaptureDevice::Name::V4L2_SINGLE_PLANE
55 #elif defined(OS_MACOSX)
57 VideoCaptureDevice::Name::AVFOUNDATION
58 #elif defined(OS_WIN)
60 VideoCaptureDevice::Name::DIRECT_SHOW
61 #elif defined(OS_ANDROID)
63 VideoCaptureDevice::Name::API2_LEGACY
64 #endif
66 device_names->push_back(name);
70 void FakeVideoCaptureDeviceFactory::GetDeviceSupportedFormats(
71 const VideoCaptureDevice::Name& device,
72 VideoCaptureFormats* supported_formats) {
73 DCHECK(thread_checker_.CalledOnValidThread());
74 const int frame_rate = 1000 / FakeVideoCaptureDevice::FakeCapturePeriodMs();
75 const gfx::Size supported_sizes[] = {gfx::Size(320, 240),
76 gfx::Size(640, 480),
77 gfx::Size(1280, 720),
78 gfx::Size(1920, 1080)};
79 supported_formats->clear();
80 for (const auto& size : supported_sizes) {
81 supported_formats->push_back(VideoCaptureFormat(
82 size, frame_rate, media::VIDEO_CAPTURE_PIXEL_FORMAT_I420));
86 } // namespace media