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/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
15 | 15 |
16 namespace media { | 16 namespace media { |
17 | 17 |
18 // Cap the frame rate command line input to reasonable values. | 18 // Cap the frame rate command line input to reasonable values. |
19 static const float kFakeCaptureMinFrameRate = 5.0f; | 19 static const float kFakeCaptureMinFrameRate = 5.0f; |
20 static const float kFakeCaptureMaxFrameRate = 60.0f; | 20 static const float kFakeCaptureMaxFrameRate = 60.0f; |
21 // Default rate if none is specified as part of the command line. | 21 // Default rate if none is specified as part of the command line. |
22 static const float kFakeCaptureDefaultFrameRate = 20.0f; | 22 static const float kFakeCaptureDefaultFrameRate = 20.0f; |
23 | 23 |
24 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() | 24 FakeVideoCaptureDeviceFactory::FakeVideoCaptureDeviceFactory() |
25 : number_of_devices_(1), | 25 : number_of_devices_(1), |
26 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS), | 26 fake_vcd_ownership_(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS), |
27 frame_rate_(kFakeCaptureDefaultFrameRate) {} | 27 frame_rate_(kFakeCaptureDefaultFrameRate) {} |
28 | 28 |
29 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::Create( | 29 std::unique_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::CreateDevice( |
30 const VideoCaptureDevice::Name& device_name) { | 30 const VideoCaptureDeviceDescriptor& device_descriptor) { |
31 DCHECK(thread_checker_.CalledOnValidThread()); | 31 DCHECK(thread_checker_.CalledOnValidThread()); |
32 | 32 |
33 parse_command_line(); | 33 parse_command_line(); |
34 | 34 |
35 for (int n = 0; n < number_of_devices_; ++n) { | 35 for (int n = 0; n < number_of_devices_; ++n) { |
36 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 36 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
37 if (device_name.id().compare(possible_id) == 0) { | 37 if (device_descriptor.device_id.compare(possible_id) == 0) { |
38 return std::unique_ptr<VideoCaptureDevice>( | 38 return std::unique_ptr<VideoCaptureDevice>( |
39 new FakeVideoCaptureDevice(fake_vcd_ownership_, frame_rate_)); | 39 new FakeVideoCaptureDevice(fake_vcd_ownership_, frame_rate_)); |
40 } | 40 } |
41 } | 41 } |
42 return std::unique_ptr<VideoCaptureDevice>(); | 42 return std::unique_ptr<VideoCaptureDevice>(); |
43 } | 43 } |
44 | 44 |
45 void FakeVideoCaptureDeviceFactory::GetDeviceNames( | 45 void FakeVideoCaptureDeviceFactory::GetDeviceDescriptors( |
46 VideoCaptureDevice::Names* const device_names) { | 46 VideoCaptureDeviceDescriptors* device_descriptors) { |
47 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
48 DCHECK(device_names->empty()); | 48 DCHECK(device_descriptors->empty()); |
49 for (int n = 0; n < number_of_devices_; ++n) { | 49 for (int n = 0; n < number_of_devices_; ++n) { |
50 VideoCaptureDevice::Name name(base::StringPrintf("fake_device_%d", n), | 50 device_descriptors->emplace_back(base::StringPrintf("fake_device_%d", n), |
51 base::StringPrintf("/dev/video%d", n) | 51 base::StringPrintf("/dev/video%d", n), |
52 #if defined(OS_LINUX) | 52 #if defined(OS_LINUX) |
53 , | 53 VideoCaptureApi::LINUX_V4L2_SINGLE_PLANE |
54 VideoCaptureDevice::Name::V4L2_SINGLE_PLANE | |
55 #elif defined(OS_MACOSX) | 54 #elif defined(OS_MACOSX) |
56 , | 55 VideoCaptureApi::MACOSX_AVFOUNDATION |
57 VideoCaptureDevice::Name::AVFOUNDATION | |
58 #elif defined(OS_WIN) | 56 #elif defined(OS_WIN) |
59 , | 57 VideoCaptureApi::WIN_DIRECT_SHOW |
60 VideoCaptureDevice::Name::DIRECT_SHOW | |
61 #elif defined(OS_ANDROID) | 58 #elif defined(OS_ANDROID) |
62 , | 59 VideoCaptureApi::ANDROID_API2_LEGACY |
63 VideoCaptureDevice::Name::API2_LEGACY | |
64 #endif | 60 #endif |
65 ); | 61 ); |
66 device_names->push_back(name); | |
67 } | 62 } |
68 } | 63 } |
69 | 64 |
70 void FakeVideoCaptureDeviceFactory::GetDeviceSupportedFormats( | 65 void FakeVideoCaptureDeviceFactory::GetSupportedFormats( |
71 const VideoCaptureDevice::Name& device, | 66 const VideoCaptureDeviceDescriptor& device_descriptor, |
72 VideoCaptureFormats* supported_formats) { | 67 VideoCaptureFormats* supported_formats) { |
73 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
74 const gfx::Size supported_sizes[] = {gfx::Size(320, 240), | 69 const gfx::Size supported_sizes[] = {gfx::Size(320, 240), |
75 gfx::Size(640, 480), | 70 gfx::Size(640, 480), |
76 gfx::Size(1280, 720), | 71 gfx::Size(1280, 720), |
77 gfx::Size(1920, 1080)}; | 72 gfx::Size(1920, 1080)}; |
78 supported_formats->clear(); | 73 supported_formats->clear(); |
79 for (const auto& size : supported_sizes) { | 74 for (const auto& size : supported_sizes) { |
80 supported_formats->push_back( | 75 supported_formats->push_back( |
81 VideoCaptureFormat(size, frame_rate_, media::PIXEL_FORMAT_I420)); | 76 VideoCaptureFormat(size, frame_rate_, media::PIXEL_FORMAT_I420)); |
(...skipping 30 matching lines...) Expand all Loading... |
112 if (base::StringToDouble(param.back(), &fps)) { | 107 if (base::StringToDouble(param.back(), &fps)) { |
113 frame_rate_ = | 108 frame_rate_ = |
114 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps)); | 109 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps)); |
115 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); | 110 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); |
116 } | 111 } |
117 } | 112 } |
118 } | 113 } |
119 } | 114 } |
120 | 115 |
121 } // namespace media | 116 } // namespace media |
OLD | NEW |