| 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> | 7 #import <IOKit/audio/IOAudioTypes.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/task_runner_util.h" | 12 #include "base/task_runner_util.h" |
| 13 #import "media/base/mac/avfoundation_glue.h" | 13 #import "media/base/mac/avfoundation_glue.h" |
| 14 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" | 14 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" |
| 15 #include "media/video/capture/mac/video_capture_device_mac.h" | 15 #include "media/video/capture/mac/video_capture_device_mac.h" |
| 16 #import "media/video/capture/mac/video_capture_device_decklink_mac.h" | 16 #import "media/video/capture/mac/video_capture_device_decklink_mac.h" |
| 17 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" | 17 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| 20 | 20 |
| 21 // Some devices are not correctly supported in AVFoundation, f.i. Blackmagic, | 21 // Some devices are known to crash if VGA is requested: http://crbug.com/396812; |
| 22 // see http://crbug.com/347371. The devices are identified by a characteristic | 22 // for them HD is the only supported resolution. These devices are identified by |
| 23 // trailing substring of uniqueId and by (part of) the vendor's name. | 23 // a characteristic trailing substring of uniqueId and by (part of) the vendor's |
| 24 // Blackmagic cameras are known to crash if VGA is requested , see | 24 // name. |
| 25 // http://crbug.com/396812; for them HD is the only supported resolution. | |
| 26 const struct NameAndVid { | 25 const struct NameAndVid { |
| 27 const char* unique_id_signature; | |
| 28 const char* name; | 26 const char* name; |
| 29 const int capture_width; | 27 const int capture_width; |
| 30 const int capture_height; | 28 const int capture_height; |
| 31 const float capture_frame_rate; | 29 const float capture_frame_rate; |
| 32 } kBlacklistedCameras[] = { | 30 } kBlacklistedCameras[] = { {"Blackmagic", 1280, 720, 60.0f } }; |
| 33 { "-01FDA82C8A9C", "Blackmagic", 1280, 720, 60.0f } }; | |
| 34 | 31 |
| 35 static scoped_ptr<media::VideoCaptureDevice::Names> | 32 static scoped_ptr<media::VideoCaptureDevice::Names> |
| 36 EnumerateDevicesUsingQTKit() { | 33 EnumerateDevicesUsingQTKit() { |
| 37 scoped_ptr<VideoCaptureDevice::Names> device_names( | 34 scoped_ptr<VideoCaptureDevice::Names> device_names( |
| 38 new VideoCaptureDevice::Names()); | 35 new VideoCaptureDevice::Names()); |
| 39 NSMutableDictionary* capture_devices = | 36 NSMutableDictionary* capture_devices = |
| 40 [[[NSMutableDictionary alloc] init] autorelease]; | 37 [[[NSMutableDictionary alloc] init] autorelease]; |
| 41 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; | 38 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; |
| 42 for (NSString* key in capture_devices) { | 39 for (NSString* key in capture_devices) { |
| 43 VideoCaptureDevice::Name name( | 40 VideoCaptureDevice::Name name( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 108 } |
| 112 return scoped_ptr<VideoCaptureDevice>(capture_device.Pass()); | 109 return scoped_ptr<VideoCaptureDevice>(capture_device.Pass()); |
| 113 } | 110 } |
| 114 | 111 |
| 115 void VideoCaptureDeviceFactoryMac::GetDeviceNames( | 112 void VideoCaptureDeviceFactoryMac::GetDeviceNames( |
| 116 VideoCaptureDevice::Names* device_names) { | 113 VideoCaptureDevice::Names* device_names) { |
| 117 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
| 118 // Loop through all available devices and add to |device_names|. | 115 // Loop through all available devices and add to |device_names|. |
| 119 NSDictionary* capture_devices; | 116 NSDictionary* capture_devices; |
| 120 if (AVFoundationGlue::IsAVFoundationSupported()) { | 117 if (AVFoundationGlue::IsAVFoundationSupported()) { |
| 121 bool is_any_device_blacklisted = false; | |
| 122 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; | 118 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; |
| 123 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; | 119 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; |
| 124 // Enumerate all devices found by AVFoundation, translate the info for each | 120 // Enumerate all devices found by AVFoundation, translate the info for each |
| 125 // to class Name and add it to |device_names|. | 121 // to class Name and add it to |device_names|. |
| 126 for (NSString* key in capture_devices) { | 122 for (NSString* key in capture_devices) { |
| 127 int transport_type = [[capture_devices valueForKey:key] transportType]; | 123 int transport_type = [[capture_devices valueForKey:key] transportType]; |
| 128 // Transport types are defined for Audio devices and reused for video. | 124 // Transport types are defined for Audio devices and reused for video. |
| 129 VideoCaptureDevice::Name::TransportType device_transport_type = | 125 VideoCaptureDevice::Name::TransportType device_transport_type = |
| 130 (transport_type == kIOAudioDeviceTransportTypeBuiltIn || | 126 (transport_type == kIOAudioDeviceTransportTypeBuiltIn || |
| 131 transport_type == kIOAudioDeviceTransportTypeUSB) | 127 transport_type == kIOAudioDeviceTransportTypeUSB) |
| 132 ? VideoCaptureDevice::Name::USB_OR_BUILT_IN | 128 ? VideoCaptureDevice::Name::USB_OR_BUILT_IN |
| 133 : VideoCaptureDevice::Name::OTHER_TRANSPORT; | 129 : VideoCaptureDevice::Name::OTHER_TRANSPORT; |
| 134 VideoCaptureDevice::Name name( | 130 VideoCaptureDevice::Name name( |
| 135 [[[capture_devices valueForKey:key] deviceName] UTF8String], | 131 [[[capture_devices valueForKey:key] deviceName] UTF8String], |
| 136 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION, | 132 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION, |
| 137 device_transport_type); | 133 device_transport_type); |
| 138 device_names->push_back(name); | 134 device_names->push_back(name); |
| 139 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { | |
| 140 is_any_device_blacklisted |= EndsWith(name.id(), | |
| 141 kBlacklistedCameras[i].unique_id_signature, false); | |
| 142 if (is_any_device_blacklisted) | |
| 143 break; | |
| 144 } | |
| 145 } | 135 } |
| 146 // If there is any device blacklisted in the system, walk the QTKit device | |
| 147 // list and add those devices with a blacklisted name to the |device_names|. | |
| 148 // AVFoundation and QTKit device lists partially overlap, so add a "QTKit" | |
| 149 // prefix to the latter ones to distinguish them from the AVFoundation ones. | |
| 150 if (is_any_device_blacklisted) { | |
| 151 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; | |
| 152 for (NSString* key in capture_devices) { | |
| 153 NSString* device_name = [[capture_devices valueForKey:key] deviceName]; | |
| 154 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { | |
| 155 if ([device_name rangeOfString:@(kBlacklistedCameras[i].name) | |
| 156 options:NSCaseInsensitiveSearch].length != 0) { | |
| 157 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; | |
| 158 VideoCaptureDevice::Name name( | |
| 159 "QTKit " + std::string([device_name UTF8String]), | |
| 160 [key UTF8String], VideoCaptureDevice::Name::QTKIT); | |
| 161 device_names->push_back(name); | |
| 162 } | |
| 163 } | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 // Also retrieve Blackmagic devices, if present, via DeckLink SDK API. | 136 // Also retrieve Blackmagic devices, if present, via DeckLink SDK API. |
| 168 VideoCaptureDeviceDeckLinkMac::EnumerateDevices(device_names); | 137 VideoCaptureDeviceDeckLinkMac::EnumerateDevices(device_names); |
| 169 } else { | 138 } else { |
| 170 // We should not enumerate QTKit devices in Device Thread; | 139 // We should not enumerate QTKit devices in Device Thread; |
| 171 NOTREACHED(); | 140 NOTREACHED(); |
| 172 } | 141 } |
| 173 } | 142 } |
| 174 | 143 |
| 175 void VideoCaptureDeviceFactoryMac::EnumerateDeviceNames(const base::Callback< | 144 void VideoCaptureDeviceFactoryMac::EnumerateDeviceNames(const base::Callback< |
| 176 void(scoped_ptr<media::VideoCaptureDevice::Names>)>& callback) { | 145 void(scoped_ptr<media::VideoCaptureDevice::Names>)>& callback) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 DVLOG(1) << "Enumerating video capture capabilities " << device.name(); | 188 DVLOG(1) << "Enumerating video capture capabilities " << device.name(); |
| 220 VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities( | 189 VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities( |
| 221 device, supported_formats); | 190 device, supported_formats); |
| 222 break; | 191 break; |
| 223 default: | 192 default: |
| 224 NOTREACHED(); | 193 NOTREACHED(); |
| 225 } | 194 } |
| 226 } | 195 } |
| 227 | 196 |
| 228 } // namespace media | 197 } // namespace media |
| OLD | NEW |