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

Unified Diff: media/video/capture/mac/video_capture_device_factory_mac.mm

Issue 265263004: Mac Video Capture Device: split VCD into VCD and Factory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: perkj@ suggestion: Factory method in VCDFactory. Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: media/video/capture/mac/video_capture_device_factory_mac.mm
diff --git a/media/video/capture/mac/video_capture_device_factory_mac.mm b/media/video/capture/mac/video_capture_device_factory_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..80b34a383ad5f7048f66f242e75e6cc4089cfe9f
--- /dev/null
+++ b/media/video/capture/mac/video_capture_device_factory_mac.mm
@@ -0,0 +1,128 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/video/capture/mac/video_capture_device_factory_mac.h"
+
+#import "media/video/capture/mac/avfoundation_glue.h"
+#include "media/video/capture/mac/video_capture_device_mac.h"
+#import "media/video/capture/mac/video_capture_device_avfoundation_mac.h"
+#import "media/video/capture/mac/video_capture_device_qtkit_mac.h"
+
+namespace media {
+
+// Some devices are not correctly supported in AVFoundation, f.i. Blackmagic,
+// see http://crbug.com/347371. The devices are identified by USB Vendor ID and
+// by a characteristic substring of the name, usually the vendor's name.
+const struct NameAndVid {
+ const char* vid;
+ const char* name;
+} kBlacklistedCameras[] = { { "a82c", "Blackmagic" } };
+
+// In device identifiers, the USB VID and PID are stored in 4 bytes each.
+const size_t kVidPidSize = 4;
+
+VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac() {
+ thread_checker_.DetachFromThread();
+}
+
+scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create(
+ const VideoCaptureDevice::Name& device_name) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ VideoCaptureDeviceMac* capture_device =
+ new VideoCaptureDeviceMac(device_name);
+
+ // TODO(mcasas): The following check might not be necessary; if the device has
+ // disappeared after enumeration and before coming here, opening would just
+ // fail but not necessarily produce a crash.
+ VideoCaptureDevice::Names device_names;
+ GetDeviceNames(&device_names);
+ VideoCaptureDevice::Names::const_iterator it = device_names.begin();
+ for (; it != device_names.end(); ++it) {
+ if (it->id() == device_name.id())
+ break;
+ }
+ if (it == device_names.end())
+ return scoped_ptr<VideoCaptureDevice>();
+ DCHECK_NE(it->capture_api_type(), VideoCaptureDevice::Name::API_TYPE_UNKNOWN);
+
+ if (!capture_device->Init(it->capture_api_type())) {
+ LOG(ERROR) << "Could not initialize VideoCaptureDevice.";
+ delete capture_device;
+ capture_device = NULL;
+ }
+ return scoped_ptr<VideoCaptureDevice>(capture_device);
+}
+
+void VideoCaptureDeviceFactoryMac::GetDeviceNames(
+ VideoCaptureDevice::Names* const device_names) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ // Loop through all available devices and add to |device_names|.
+ NSDictionary* capture_devices;
+ if (AVFoundationGlue::IsAVFoundationSupported()) {
perkj_chrome 2014/05/06 06:44:46 How about we do this check already in VideoCapture
mcasas 2014/05/06 07:26:30 I'd rather do that in a later CL, so this one is c
+ bool is_any_device_blacklisted = false;
+ DVLOG(1) << "Enumerating video capture devices using AVFoundation";
+ capture_devices = [VideoCaptureDeviceAVFoundation deviceNames];
+ std::string device_vid;
+ // Enumerate all devices found by AVFoundation, translate the info for each
+ // to class Name and add it to |device_names|.
+ for (NSString* key in capture_devices) {
+ VideoCaptureDevice::Name name(
+ [[capture_devices valueForKey:key] UTF8String],
+ [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION);
+ device_names->push_back(name);
+ // Extract the device's Vendor ID and compare to all blacklisted ones.
+ device_vid = name.GetModel().substr(0, kVidPidSize);
+ for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) {
+ is_any_device_blacklisted |=
+ !strcasecmp(device_vid.c_str(), kBlacklistedCameras[i].vid);
+ if (is_any_device_blacklisted)
+ break;
+ }
+ }
+ // If there is any device blacklisted in the system, walk the QTKit device
+ // list and add those devices with a blacklisted name to the |device_names|.
+ // AVFoundation and QTKit device lists partially overlap, so add a "QTKit"
+ // prefix to the latter ones to distinguish them from the AVFoundation ones.
+ if (is_any_device_blacklisted) {
+ capture_devices = [VideoCaptureDeviceQTKit deviceNames];
+ for (NSString* key in capture_devices) {
+ NSString* device_name = [capture_devices valueForKey:key];
+ for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) {
+ if ([device_name rangeOfString:@(kBlacklistedCameras[i].name)
+ options:NSCaseInsensitiveSearch].length != 0) {
+ DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String];
+ VideoCaptureDevice::Name name(
+ "QTKit " + std::string([device_name UTF8String]),
+ [key UTF8String], VideoCaptureDevice::Name::QTKIT);
+ device_names->push_back(name);
+ }
+ }
+ }
+ }
+ } else {
+ DVLOG(1) << "Enumerating video capture devices using QTKit";
+ capture_devices = [VideoCaptureDeviceQTKit deviceNames];
+ for (NSString* key in capture_devices) {
+ VideoCaptureDevice::Name name(
+ [[capture_devices valueForKey:key] UTF8String],
+ [key UTF8String], VideoCaptureDevice::Name::QTKIT);
+ device_names->push_back(name);
+ }
+ }
+}
+
+void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats(
+ const VideoCaptureDevice::Name& device,
+ VideoCaptureFormats* supported_formats) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) {
+ DVLOG(1) << "Enumerating video capture capabilities, AVFoundation";
+ [VideoCaptureDeviceAVFoundation getDevice:device
+ supportedFormats:supported_formats];
+ } else {
+ NOTIMPLEMENTED();
+ }
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698