| 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 #import <IOKit/audio/IOAudioTypes.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 10 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 11 #import "media/video/capture/mac/avfoundation_glue.h" | 13 #import "media/video/capture/mac/avfoundation_glue.h" |
| 12 #include "media/video/capture/mac/video_capture_device_mac.h" | 14 #include "media/video/capture/mac/video_capture_device_mac.h" |
| 13 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" | 15 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" |
| 14 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" | 16 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" |
| 15 | 17 |
| 16 namespace media { | 18 namespace media { |
| 17 | 19 |
| 18 // Some devices are not correctly supported in AVFoundation, f.i. Blackmagic, | 20 // Some devices are not correctly supported in AVFoundation, f.i. Blackmagic, |
| 19 // see http://crbug.com/347371. The devices are identified by a characteristic | 21 // see http://crbug.com/347371. The devices are identified by a characteristic |
| 20 // trailing substring of uniqueId and by (part of) the vendor's name. | 22 // trailing substring of uniqueId and by (part of) the vendor's name. |
| 21 const struct NameAndVid { | 23 const struct NameAndVid { |
| 22 const char* unique_id_signature; | 24 const char* unique_id_signature; |
| 23 const char* name; | 25 const char* name; |
| 24 } kBlacklistedCameras[] = { { "-01FDA82C8A9C", "Blackmagic" } }; | 26 } kBlacklistedCameras[] = { { "-01FDA82C8A9C", "Blackmagic" } }; |
| 25 | 27 |
| 26 static scoped_ptr<media::VideoCaptureDevice::Names> | 28 static scoped_ptr<media::VideoCaptureDevice::Names> |
| 27 EnumerateDevicesUsingQTKit() { | 29 EnumerateDevicesUsingQTKit() { |
| 28 scoped_ptr<VideoCaptureDevice::Names> device_names( | 30 scoped_ptr<VideoCaptureDevice::Names> device_names( |
| 29 new VideoCaptureDevice::Names()); | 31 new VideoCaptureDevice::Names()); |
| 30 NSMutableDictionary* capture_devices = | 32 NSMutableDictionary* capture_devices = |
| 31 [[[NSMutableDictionary alloc] init] autorelease]; | 33 [[[NSMutableDictionary alloc] init] autorelease]; |
| 32 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; | 34 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; |
| 33 for (NSString* key in capture_devices) { | 35 for (NSString* key in capture_devices) { |
| 34 VideoCaptureDevice::Name name( | 36 VideoCaptureDevice::Name name( |
| 35 [[capture_devices valueForKey:key] UTF8String], | 37 [[[capture_devices valueForKey:key] deviceName] UTF8String], |
| 36 [key UTF8String], VideoCaptureDevice::Name::QTKIT); | 38 [key UTF8String], VideoCaptureDevice::Name::QTKIT); |
| 37 device_names->push_back(name); | 39 device_names->push_back(name); |
| 38 } | 40 } |
| 39 return device_names.Pass(); | 41 return device_names.Pass(); |
| 40 } | 42 } |
| 41 | 43 |
| 42 static void RunDevicesEnumeratedCallback( | 44 static void RunDevicesEnumeratedCallback( |
| 43 const base::Callback<void(scoped_ptr<media::VideoCaptureDevice::Names>)>& | 45 const base::Callback<void(scoped_ptr<media::VideoCaptureDevice::Names>)>& |
| 44 callback, | 46 callback, |
| 45 scoped_ptr<media::VideoCaptureDevice::Names> device_names) { | 47 scoped_ptr<media::VideoCaptureDevice::Names> device_names) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DCHECK(thread_checker_.CalledOnValidThread()); | 98 DCHECK(thread_checker_.CalledOnValidThread()); |
| 97 // Loop through all available devices and add to |device_names|. | 99 // Loop through all available devices and add to |device_names|. |
| 98 NSDictionary* capture_devices; | 100 NSDictionary* capture_devices; |
| 99 if (AVFoundationGlue::IsAVFoundationSupported()) { | 101 if (AVFoundationGlue::IsAVFoundationSupported()) { |
| 100 bool is_any_device_blacklisted = false; | 102 bool is_any_device_blacklisted = false; |
| 101 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; | 103 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; |
| 102 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; | 104 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; |
| 103 // Enumerate all devices found by AVFoundation, translate the info for each | 105 // Enumerate all devices found by AVFoundation, translate the info for each |
| 104 // to class Name and add it to |device_names|. | 106 // to class Name and add it to |device_names|. |
| 105 for (NSString* key in capture_devices) { | 107 for (NSString* key in capture_devices) { |
| 108 int transport_type = [[capture_devices valueForKey:key] transportType]; |
| 109 // Transport types are defined for Audio devices and reused for video. |
| 110 VideoCaptureDevice::Name::TransportType device_transport_type = |
| 111 (transport_type == kIOAudioDeviceTransportTypeBuiltIn || |
| 112 transport_type == kIOAudioDeviceTransportTypeUSB) |
| 113 ? VideoCaptureDevice::Name::USB_OR_BUILT_IN |
| 114 : VideoCaptureDevice::Name::OTHER_TRANSPORT; |
| 106 VideoCaptureDevice::Name name( | 115 VideoCaptureDevice::Name name( |
| 107 [[capture_devices valueForKey:key] UTF8String], | 116 [[[capture_devices valueForKey:key] deviceName] UTF8String], |
| 108 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION); | 117 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION, |
| 118 device_transport_type); |
| 109 device_names->push_back(name); | 119 device_names->push_back(name); |
| 110 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { | 120 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { |
| 111 is_any_device_blacklisted = EndsWith(name.id(), | 121 is_any_device_blacklisted = EndsWith(name.id(), |
| 112 kBlacklistedCameras[i].unique_id_signature, false); | 122 kBlacklistedCameras[i].unique_id_signature, false); |
| 113 if (is_any_device_blacklisted) | 123 if (is_any_device_blacklisted) |
| 114 break; | 124 break; |
| 115 } | 125 } |
| 116 } | 126 } |
| 117 // If there is any device blacklisted in the system, walk the QTKit device | 127 // If there is any device blacklisted in the system, walk the QTKit device |
| 118 // list and add those devices with a blacklisted name to the |device_names|. | 128 // list and add those devices with a blacklisted name to the |device_names|. |
| 119 // AVFoundation and QTKit device lists partially overlap, so add a "QTKit" | 129 // AVFoundation and QTKit device lists partially overlap, so add a "QTKit" |
| 120 // prefix to the latter ones to distinguish them from the AVFoundation ones. | 130 // prefix to the latter ones to distinguish them from the AVFoundation ones. |
| 121 if (is_any_device_blacklisted) { | 131 if (is_any_device_blacklisted) { |
| 122 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; | 132 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; |
| 123 for (NSString* key in capture_devices) { | 133 for (NSString* key in capture_devices) { |
| 124 NSString* device_name = [capture_devices valueForKey:key]; | 134 NSString* device_name = [[capture_devices valueForKey:key] deviceName]; |
| 125 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { | 135 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { |
| 126 if ([device_name rangeOfString:@(kBlacklistedCameras[i].name) | 136 if ([device_name rangeOfString:@(kBlacklistedCameras[i].name) |
| 127 options:NSCaseInsensitiveSearch].length != 0) { | 137 options:NSCaseInsensitiveSearch].length != 0) { |
| 128 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; | 138 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; |
| 129 VideoCaptureDevice::Name name( | 139 VideoCaptureDevice::Name name( |
| 130 "QTKit " + std::string([device_name UTF8String]), | 140 "QTKit " + std::string([device_name UTF8String]), |
| 131 [key UTF8String], VideoCaptureDevice::Name::QTKIT); | 141 [key UTF8String], VideoCaptureDevice::Name::QTKIT); |
| 132 device_names->push_back(name); | 142 device_names->push_back(name); |
| 133 } | 143 } |
| 134 } | 144 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 163 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { | 173 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { |
| 164 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; | 174 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; |
| 165 [VideoCaptureDeviceAVFoundation getDevice:device | 175 [VideoCaptureDeviceAVFoundation getDevice:device |
| 166 supportedFormats:supported_formats]; | 176 supportedFormats:supported_formats]; |
| 167 } else { | 177 } else { |
| 168 NOTIMPLEMENTED(); | 178 NOTIMPLEMENTED(); |
| 169 } | 179 } |
| 170 } | 180 } |
| 171 | 181 |
| 172 } // namespace media | 182 } // namespace media |
| OLD | NEW |