| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "webrtc/media/devices/devicemanager.h" | 28 #include "webrtc/media/devices/devicemanager.h" |
| 29 | 29 |
| 30 #include "webrtc/base/fileutils.h" | 30 #include "webrtc/base/fileutils.h" |
| 31 #include "webrtc/base/logging.h" | 31 #include "webrtc/base/logging.h" |
| 32 #include "webrtc/base/pathutils.h" | 32 #include "webrtc/base/pathutils.h" |
| 33 #include "webrtc/base/stringutils.h" | 33 #include "webrtc/base/stringutils.h" |
| 34 #include "webrtc/base/thread.h" | 34 #include "webrtc/base/thread.h" |
| 35 #include "webrtc/base/windowpicker.h" | 35 #include "webrtc/base/windowpicker.h" |
| 36 #include "webrtc/base/windowpickerfactory.h" | 36 #include "webrtc/base/windowpickerfactory.h" |
| 37 #include "webrtc/media/base/mediacommon.h" | 37 #include "webrtc/media/base/mediacommon.h" |
| 38 #include "webrtc/media/base/videocapturer.h" |
| 38 #include "webrtc/media/base/videocapturerfactory.h" | 39 #include "webrtc/media/base/videocapturerfactory.h" |
| 39 #include "webrtc/media/devices/deviceinfo.h" | 40 #include "webrtc/media/devices/deviceinfo.h" |
| 40 #include "webrtc/media/devices/filevideocapturer.h" | |
| 41 #include "webrtc/media/devices/yuvframescapturer.h" | |
| 42 | 41 |
| 43 #ifdef HAVE_WEBRTC_VIDEO | 42 #ifdef HAVE_WEBRTC_VIDEO |
| 44 #include "webrtc/media/webrtc/webrtcvideocapturerfactory.h" | 43 #include "webrtc/media/webrtc/webrtcvideocapturerfactory.h" |
| 45 #endif // HAVE_WEBRTC_VIDEO | 44 #endif // HAVE_WEBRTC_VIDEO |
| 46 | 45 |
| 47 namespace { | 46 namespace { |
| 48 | 47 |
| 49 bool StringMatchWithWildcard( | 48 bool StringMatchWithWildcard( |
| 50 const std::pair<const std::basic_string<char>, cricket::VideoFormat> key, | 49 const std::pair<const std::basic_string<char>, cricket::VideoFormat> key, |
| 51 const std::string& val) { | 50 const std::string& val) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 146 } |
| 148 | 147 |
| 149 for (std::vector<Device>::const_iterator it = devices.begin(); | 148 for (std::vector<Device>::const_iterator it = devices.begin(); |
| 150 it != devices.end(); ++it) { | 149 it != devices.end(); ++it) { |
| 151 if (name == it->name) { | 150 if (name == it->name) { |
| 152 *out = *it; | 151 *out = *it; |
| 153 return true; | 152 return true; |
| 154 } | 153 } |
| 155 } | 154 } |
| 156 | 155 |
| 157 // If |name| is a valid name for a file or yuvframedevice, | |
| 158 // return a fake video capturer device. | |
| 159 if (GetFakeVideoCaptureDevice(name, out)) { | |
| 160 return true; | |
| 161 } | |
| 162 | |
| 163 return false; | 156 return false; |
| 164 } | 157 } |
| 165 | 158 |
| 166 bool DeviceManager::GetFakeVideoCaptureDevice(const std::string& name, | |
| 167 Device* out) const { | |
| 168 if (rtc::Filesystem::IsFile(name)) { | |
| 169 *out = FileVideoCapturer::CreateFileVideoCapturerDevice(name); | |
| 170 return true; | |
| 171 } | |
| 172 | |
| 173 if (name == YuvFramesCapturer::kYuvFrameDeviceName) { | |
| 174 *out = YuvFramesCapturer::CreateYuvFramesCapturerDevice(); | |
| 175 return true; | |
| 176 } | |
| 177 | |
| 178 return false; | |
| 179 } | |
| 180 | |
| 181 void DeviceManager::SetVideoCaptureDeviceMaxFormat( | 159 void DeviceManager::SetVideoCaptureDeviceMaxFormat( |
| 182 const std::string& usb_id, | 160 const std::string& usb_id, |
| 183 const VideoFormat& max_format) { | 161 const VideoFormat& max_format) { |
| 184 max_formats_[usb_id] = max_format; | 162 max_formats_[usb_id] = max_format; |
| 185 } | 163 } |
| 186 | 164 |
| 187 void DeviceManager::ClearVideoCaptureDeviceMaxFormat( | 165 void DeviceManager::ClearVideoCaptureDeviceMaxFormat( |
| 188 const std::string& usb_id) { | 166 const std::string& usb_id) { |
| 189 max_formats_.erase(usb_id); | 167 max_formats_.erase(usb_id); |
| 190 } | 168 } |
| 191 | 169 |
| 192 VideoCapturer* DeviceManager::CreateVideoCapturer(const Device& device) const { | 170 VideoCapturer* DeviceManager::CreateVideoCapturer(const Device& device) const { |
| 193 VideoCapturer* capturer = MaybeConstructFakeVideoCapturer(device); | |
| 194 if (capturer) { | |
| 195 return capturer; | |
| 196 } | |
| 197 | |
| 198 if (!video_device_capturer_factory_) { | 171 if (!video_device_capturer_factory_) { |
| 199 LOG(LS_ERROR) << "No video capturer factory for devices."; | 172 LOG(LS_ERROR) << "No video capturer factory for devices."; |
| 200 return NULL; | 173 return NULL; |
| 201 } | 174 } |
| 202 capturer = video_device_capturer_factory_->Create(device); | 175 cricket::VideoCapturer* capturer = |
| 176 video_device_capturer_factory_->Create(device); |
| 203 if (!capturer) { | 177 if (!capturer) { |
| 204 return NULL; | 178 return NULL; |
| 205 } | 179 } |
| 206 LOG(LS_INFO) << "Created VideoCapturer for " << device.name; | 180 LOG(LS_INFO) << "Created VideoCapturer for " << device.name; |
| 207 VideoFormat video_format; | 181 VideoFormat video_format; |
| 208 bool has_max = GetMaxFormat(device, &video_format); | 182 bool has_max = GetMaxFormat(device, &video_format); |
| 209 capturer->set_enable_camera_list(has_max); | 183 capturer->set_enable_camera_list(has_max); |
| 210 if (has_max) { | 184 if (has_max) { |
| 211 capturer->ConstrainSupportedFormats(video_format); | 185 capturer->ConstrainSupportedFormats(video_format); |
| 212 } | 186 } |
| 213 return capturer; | 187 return capturer; |
| 214 } | 188 } |
| 215 | 189 |
| 216 VideoCapturer* DeviceManager::MaybeConstructFakeVideoCapturer( | |
| 217 const Device& device) const { | |
| 218 // TODO(hellner): Throw out the creation of a file video capturer once the | |
| 219 // refactoring is completed. | |
| 220 if (FileVideoCapturer::IsFileVideoCapturerDevice(device)) { | |
| 221 FileVideoCapturer* capturer = new FileVideoCapturer; | |
| 222 if (!capturer->Init(device)) { | |
| 223 delete capturer; | |
| 224 return NULL; | |
| 225 } | |
| 226 LOG(LS_INFO) << "Created file video capturer " << device.name; | |
| 227 capturer->set_repeat(FileVideoCapturer::kForever); | |
| 228 return capturer; | |
| 229 } | |
| 230 | |
| 231 if (YuvFramesCapturer::IsYuvFramesCapturerDevice(device)) { | |
| 232 YuvFramesCapturer* capturer = new YuvFramesCapturer(); | |
| 233 capturer->Init(); | |
| 234 return capturer; | |
| 235 } | |
| 236 return NULL; | |
| 237 } | |
| 238 | |
| 239 bool DeviceManager::GetWindows( | 190 bool DeviceManager::GetWindows( |
| 240 std::vector<rtc::WindowDescription>* descriptions) { | 191 std::vector<rtc::WindowDescription>* descriptions) { |
| 241 if (!window_picker_) { | 192 if (!window_picker_) { |
| 242 return false; | 193 return false; |
| 243 } | 194 } |
| 244 return window_picker_->GetWindowList(descriptions); | 195 return window_picker_->GetWindowList(descriptions); |
| 245 } | 196 } |
| 246 | 197 |
| 247 bool DeviceManager::GetDesktops( | 198 bool DeviceManager::GetDesktops( |
| 248 std::vector<rtc::DesktopDescription>* descriptions) { | 199 std::vector<rtc::DesktopDescription>* descriptions) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if (ShouldDeviceBeIgnored(it->name, exclusion_list)) { | 313 if (ShouldDeviceBeIgnored(it->name, exclusion_list)) { |
| 363 it = devices->erase(it); | 314 it = devices->erase(it); |
| 364 } else { | 315 } else { |
| 365 ++it; | 316 ++it; |
| 366 } | 317 } |
| 367 } | 318 } |
| 368 return true; | 319 return true; |
| 369 } | 320 } |
| 370 | 321 |
| 371 } // namespace cricket | 322 } // namespace cricket |
| OLD | NEW |