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/video/capture/mac/video_capture_device_factory_mac.h" | 5 #include "media/video/capture/mac/video_capture_device_factory_mac.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/strings/string_util.h" |
9 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
10 #import "media/video/capture/mac/avfoundation_glue.h" | 11 #import "media/video/capture/mac/avfoundation_glue.h" |
11 #include "media/video/capture/mac/video_capture_device_mac.h" | 12 #include "media/video/capture/mac/video_capture_device_mac.h" |
12 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" | 13 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" |
13 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" | 14 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" |
14 | 15 |
15 namespace media { | 16 namespace media { |
16 | 17 |
17 // Some devices are not correctly supported in AVFoundation, f.i. Blackmagic, | 18 // Some devices are not correctly supported in AVFoundation, f.i. Blackmagic, |
18 // see http://crbug.com/347371. The devices are identified by USB Vendor ID and | 19 // see http://crbug.com/347371. The devices are identified by a characteristic |
19 // by a characteristic substring of the name, usually the vendor's name. | 20 // trailing substring of uniqueId and by (part of) the vendor's name. |
20 const struct NameAndVid { | 21 const struct NameAndVid { |
21 const char* vid; | 22 const char* unique_id_signature; |
22 const char* name; | 23 const char* name; |
23 } kBlacklistedCameras[] = { { "a82c", "Blackmagic" } }; | 24 } kBlacklistedCameras[] = { { "-01FDA82C8A9C", "Blackmagic" } }; |
24 | |
25 // In device identifiers, the USB VID and PID are stored in 4 bytes each. | |
26 const size_t kVidPidSize = 4; | |
27 | 25 |
28 static scoped_ptr<media::VideoCaptureDevice::Names> | 26 static scoped_ptr<media::VideoCaptureDevice::Names> |
29 EnumerateDevicesUsingQTKit() { | 27 EnumerateDevicesUsingQTKit() { |
30 scoped_ptr<VideoCaptureDevice::Names> device_names( | 28 scoped_ptr<VideoCaptureDevice::Names> device_names( |
31 new VideoCaptureDevice::Names()); | 29 new VideoCaptureDevice::Names()); |
32 NSMutableDictionary* capture_devices = | 30 NSMutableDictionary* capture_devices = |
33 [[[NSMutableDictionary alloc] init] autorelease]; | 31 [[[NSMutableDictionary alloc] init] autorelease]; |
34 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; | 32 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; |
35 for (NSString* key in capture_devices) { | 33 for (NSString* key in capture_devices) { |
36 VideoCaptureDevice::Name name( | 34 VideoCaptureDevice::Name name( |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 93 |
96 void VideoCaptureDeviceFactoryMac::GetDeviceNames( | 94 void VideoCaptureDeviceFactoryMac::GetDeviceNames( |
97 VideoCaptureDevice::Names* device_names) { | 95 VideoCaptureDevice::Names* device_names) { |
98 DCHECK(thread_checker_.CalledOnValidThread()); | 96 DCHECK(thread_checker_.CalledOnValidThread()); |
99 // Loop through all available devices and add to |device_names|. | 97 // Loop through all available devices and add to |device_names|. |
100 NSDictionary* capture_devices; | 98 NSDictionary* capture_devices; |
101 if (AVFoundationGlue::IsAVFoundationSupported()) { | 99 if (AVFoundationGlue::IsAVFoundationSupported()) { |
102 bool is_any_device_blacklisted = false; | 100 bool is_any_device_blacklisted = false; |
103 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; | 101 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; |
104 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; | 102 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; |
105 std::string device_vid; | |
106 // Enumerate all devices found by AVFoundation, translate the info for each | 103 // Enumerate all devices found by AVFoundation, translate the info for each |
107 // to class Name and add it to |device_names|. | 104 // to class Name and add it to |device_names|. |
108 for (NSString* key in capture_devices) { | 105 for (NSString* key in capture_devices) { |
109 VideoCaptureDevice::Name name( | 106 VideoCaptureDevice::Name name( |
110 [[capture_devices valueForKey:key] UTF8String], | 107 [[capture_devices valueForKey:key] UTF8String], |
111 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION); | 108 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION); |
112 device_names->push_back(name); | 109 device_names->push_back(name); |
113 // Extract the device's Vendor ID and compare to all blacklisted ones. | |
114 device_vid = name.GetModel().substr(0, kVidPidSize); | |
115 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { | 110 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { |
116 is_any_device_blacklisted |= | 111 is_any_device_blacklisted = EndsWith(name.id(), |
117 !strcasecmp(device_vid.c_str(), kBlacklistedCameras[i].vid); | 112 kBlacklistedCameras[i].unique_id_signature, false); |
118 if (is_any_device_blacklisted) | 113 if (is_any_device_blacklisted) |
119 break; | 114 break; |
120 } | 115 } |
121 } | 116 } |
122 // If there is any device blacklisted in the system, walk the QTKit device | 117 // If there is any device blacklisted in the system, walk the QTKit device |
123 // list and add those devices with a blacklisted name to the |device_names|. | 118 // list and add those devices with a blacklisted name to the |device_names|. |
124 // AVFoundation and QTKit device lists partially overlap, so add a "QTKit" | 119 // AVFoundation and QTKit device lists partially overlap, so add a "QTKit" |
125 // prefix to the latter ones to distinguish them from the AVFoundation ones. | 120 // prefix to the latter ones to distinguish them from the AVFoundation ones. |
126 if (is_any_device_blacklisted) { | 121 if (is_any_device_blacklisted) { |
127 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; | 122 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { | 163 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { |
169 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; | 164 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; |
170 [VideoCaptureDeviceAVFoundation getDevice:device | 165 [VideoCaptureDeviceAVFoundation getDevice:device |
171 supportedFormats:supported_formats]; | 166 supportedFormats:supported_formats]; |
172 } else { | 167 } else { |
173 NOTIMPLEMENTED(); | 168 NOTIMPLEMENTED(); |
174 } | 169 } |
175 } | 170 } |
176 | 171 |
177 } // namespace media | 172 } // namespace media |
OLD | NEW |