| 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 fake_vcd_planarity_(FakeVideoCaptureDevice::BufferPlanarity::PACKED), | |
| 28 frame_rate_(kFakeCaptureDefaultFrameRate) {} | 27 frame_rate_(kFakeCaptureDefaultFrameRate) {} |
| 29 | 28 |
| 30 scoped_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::Create( | 29 scoped_ptr<VideoCaptureDevice> FakeVideoCaptureDeviceFactory::Create( |
| 31 const VideoCaptureDevice::Name& device_name) { | 30 const VideoCaptureDevice::Name& device_name) { |
| 32 DCHECK(thread_checker_.CalledOnValidThread()); | 31 DCHECK(thread_checker_.CalledOnValidThread()); |
| 33 | 32 |
| 34 parse_command_line(); | 33 parse_command_line(); |
| 35 | 34 |
| 36 for (int n = 0; n < number_of_devices_; ++n) { | 35 for (int n = 0; n < number_of_devices_; ++n) { |
| 37 std::string possible_id = base::StringPrintf("/dev/video%d", n); | 36 std::string possible_id = base::StringPrintf("/dev/video%d", n); |
| 38 if (device_name.id().compare(possible_id) == 0) { | 37 if (device_name.id().compare(possible_id) == 0) { |
| 39 return scoped_ptr<VideoCaptureDevice>(new FakeVideoCaptureDevice( | 38 return scoped_ptr<VideoCaptureDevice>( |
| 40 fake_vcd_ownership_, fake_vcd_planarity_, frame_rate_)); | 39 new FakeVideoCaptureDevice(fake_vcd_ownership_, frame_rate_)); |
| 41 } | 40 } |
| 42 } | 41 } |
| 43 return scoped_ptr<VideoCaptureDevice>(); | 42 return scoped_ptr<VideoCaptureDevice>(); |
| 44 } | 43 } |
| 45 | 44 |
| 46 void FakeVideoCaptureDeviceFactory::GetDeviceNames( | 45 void FakeVideoCaptureDeviceFactory::GetDeviceNames( |
| 47 VideoCaptureDevice::Names* const device_names) { | 46 VideoCaptureDevice::Names* const device_names) { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 47 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 DCHECK(device_names->empty()); | 48 DCHECK(device_names->empty()); |
| 50 for (int n = 0; n < number_of_devices_; ++n) { | 49 for (int n = 0; n < number_of_devices_; ++n) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 if (param.size() != 2u) { | 100 if (param.size() != 2u) { |
| 102 LOG(WARNING) << "Forget a value '" << option << "'? Use name=value for " | 101 LOG(WARNING) << "Forget a value '" << option << "'? Use name=value for " |
| 103 << switches::kUseFakeDeviceForMediaStream << "."; | 102 << switches::kUseFakeDeviceForMediaStream << "."; |
| 104 return; | 103 return; |
| 105 } | 104 } |
| 106 | 105 |
| 107 if (base::EqualsCaseInsensitiveASCII(param.front(), "ownership") && | 106 if (base::EqualsCaseInsensitiveASCII(param.front(), "ownership") && |
| 108 base::EqualsCaseInsensitiveASCII(param.back(), "client")) { | 107 base::EqualsCaseInsensitiveASCII(param.back(), "client")) { |
| 109 fake_vcd_ownership_ = | 108 fake_vcd_ownership_ = |
| 110 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS; | 109 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS; |
| 111 } else if (base::EqualsCaseInsensitiveASCII(param.front(), "planarity") && | |
| 112 base::EqualsCaseInsensitiveASCII(param.back(), "triplanar")) { | |
| 113 fake_vcd_planarity_ = FakeVideoCaptureDevice::BufferPlanarity::TRIPLANAR; | |
| 114 } else if (base::EqualsCaseInsensitiveASCII(param.front(), "fps")) { | 110 } else if (base::EqualsCaseInsensitiveASCII(param.front(), "fps")) { |
| 115 double fps = 0; | 111 double fps = 0; |
| 116 if (base::StringToDouble(param.back(), &fps)) { | 112 if (base::StringToDouble(param.back(), &fps)) { |
| 117 frame_rate_ = | 113 frame_rate_ = |
| 118 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps)); | 114 std::max(kFakeCaptureMinFrameRate, static_cast<float>(fps)); |
| 119 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); | 115 frame_rate_ = std::min(kFakeCaptureMaxFrameRate, frame_rate_); |
| 120 } | 116 } |
| 121 } | 117 } |
| 122 } | 118 } |
| 123 } | 119 } |
| 124 | 120 |
| 125 } // namespace media | 121 } // namespace media |
| OLD | NEW |