Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: media/capture/video/fake_video_capture_device_factory.cc

Issue 2143903003: [WIP] Move media/capture to device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "media/capture/video/fake_video_capture_device_factory.h"
6
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h"
10 #include "base/strings/string_tokenizer.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h"
13 #include "build/build_config.h"
14 #include "media/base/media_switches.h"
15
16 namespace media {
17
18 // Cap the frame rate command line input to reasonable values.
19 static const float kFakeCaptureMinFrameRate = 5.0f;
20 static const float kFakeCaptureMaxFrameRate = 60.0f;
21 // Default rate if none is specified as part of the command line.
22 static const float kFakeCaptureDefaultFrameRate = 20.0f;
23
24 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory()
25 : number_of_devices_(1),
26 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS),
27 frame_rate_(kFakeCaptureDefaultFrameRate) {}
28
29 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::Create(
30 const VideoCaptureDevice::Name& device_name) {
31 DCHECK(thread_checker_.CalledOnValidThread());
32
33 parse_command_line();
34
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 std::unique_ptr<VideoCaptureDevice>(
39 new FakeVideoCaptureDevice(fake_vcd_ownership_, frame_rate_));
40 }
41 }
42 return std::unique_ptr<VideoCaptureDevice>();
43 }
44
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)
53 ,
54 VideoCaptureDevice::Name::V4L2_SINGLE_PLANE
55 #elif defined(OS_MACOSX)
56 ,
57 VideoCaptureDevice::Name::AVFOUNDATION
58 #elif defined(OS_WIN)
59 ,
60 VideoCaptureDevice::Name::DIRECT_SHOW
61 #elif defined(OS_ANDROID)
62 ,
63 VideoCaptureDevice::Name::API2_LEGACY
64 #endif
65 );
66 device_names->push_back(name);
67 }
68 }
69
70 void FakeVideoCaptureDeviceFactory::GetDeviceSupportedFormats(
71 const VideoCaptureDevice::Name& device,
72 VideoCaptureFormats* supported_formats) {
73 DCHECK(thread_checker_.CalledOnValidThread());
74 const gfx::Size supported_sizes[] = {gfx::Size(320, 240),
75 gfx::Size(640, 480),
76 gfx::Size(1280, 720),
77 gfx::Size(1920, 1080)};
78 supported_formats->clear();
79 for (const auto& size : supported_sizes) {
80 supported_formats->push_back(
81 VideoCaptureFormat(size, frame_rate_, media::PIXEL_FORMAT_I420));
82 }
83 }
84
85 // Optional comma delimited parameters to the command line can specify buffer
86 // ownership, buffer planarity, and the fake video device FPS.
87 // Examples: "ownership=client, planarity=triplanar, fps=60" "fps=30"
88 void FakeVideoCaptureDeviceFactory::parse_command_line() {
89 const std::string option =
90 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
91 switches::kUseFakeDeviceForMediaStream);
92 base::StringTokenizer option_tokenizer(option, ", ");
93 option_tokenizer.set_quote_chars("\"");
94
95 while (option_tokenizer.GetNext()) {
96 std::vector<std::string> param =
97 base::SplitString(option_tokenizer.token(), "=", base::TRIM_WHITESPACE,
98 base::SPLIT_WANT_NONEMPTY);
99
100 if (param.size() != 2u) {
101 LOG(WARNING) << "Forget a value '" << option << "'? Use name=value for "
102 << switches::kUseFakeDeviceForMediaStream << ".";
103 return;
104 }
105
106 if (base::EqualsCaseInsensitiveASCII(param.front(), "ownership") &&
107 base::EqualsCaseInsensitiveASCII(param.back(), "client")) {
108 fake_vcd_ownership_ =
109 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS;
110 } else if (base::EqualsCaseInsensitiveASCII(param.front(), "fps")) {
111 double fps = 0;
112 if (base::StringToDouble(param.back(), &fps)) {
113 frame_rate_ =
114 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps));
115 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_);
116 }
117 }
118 }
119 }
120
121 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/fake_video_capture_device_factory.h ('k') | media/capture/video/fake_video_capture_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698