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/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
10 #import "media/video/capture/mac/avfoundation_glue.h" | 12 #import "media/video/capture/mac/avfoundation_glue.h" |
11 #include "media/video/capture/mac/video_capture_device_mac.h" | 13 #include "media/video/capture/mac/video_capture_device_mac.h" |
12 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" | 14 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" |
13 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" | 15 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" |
14 | 16 |
15 namespace media { | 17 namespace media { |
16 | 18 |
(...skipping 10 matching lines...) Expand all Loading... | |
27 | 29 |
28 static scoped_ptr<media::VideoCaptureDevice::Names> | 30 static scoped_ptr<media::VideoCaptureDevice::Names> |
29 EnumerateDevicesUsingQTKit() { | 31 EnumerateDevicesUsingQTKit() { |
30 scoped_ptr<VideoCaptureDevice::Names> device_names( | 32 scoped_ptr<VideoCaptureDevice::Names> device_names( |
31 new VideoCaptureDevice::Names()); | 33 new VideoCaptureDevice::Names()); |
32 NSMutableDictionary* capture_devices = | 34 NSMutableDictionary* capture_devices = |
33 [[[NSMutableDictionary alloc] init] autorelease]; | 35 [[[NSMutableDictionary alloc] init] autorelease]; |
34 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; | 36 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; |
35 for (NSString* key in capture_devices) { | 37 for (NSString* key in capture_devices) { |
36 VideoCaptureDevice::Name name( | 38 VideoCaptureDevice::Name name( |
37 [[capture_devices valueForKey:key] UTF8String], | 39 [[[capture_devices valueForKey:key] deviceName] UTF8String], |
38 [key UTF8String], VideoCaptureDevice::Name::QTKIT); | 40 [key UTF8String], VideoCaptureDevice::Name::QTKIT); |
39 device_names->push_back(name); | 41 device_names->push_back(name); |
40 } | 42 } |
41 return device_names.Pass(); | 43 return device_names.Pass(); |
42 } | 44 } |
43 | 45 |
44 static void RunDevicesEnumeratedCallback( | 46 static void RunDevicesEnumeratedCallback( |
45 const base::Callback<void(scoped_ptr<media::VideoCaptureDevice::Names>)>& | 47 const base::Callback<void(scoped_ptr<media::VideoCaptureDevice::Names>)>& |
46 callback, | 48 callback, |
47 scoped_ptr<media::VideoCaptureDevice::Names> device_names) { | 49 scoped_ptr<media::VideoCaptureDevice::Names> device_names) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 // Loop through all available devices and add to |device_names|. | 101 // Loop through all available devices and add to |device_names|. |
100 NSDictionary* capture_devices; | 102 NSDictionary* capture_devices; |
101 if (AVFoundationGlue::IsAVFoundationSupported()) { | 103 if (AVFoundationGlue::IsAVFoundationSupported()) { |
102 bool is_any_device_blacklisted = false; | 104 bool is_any_device_blacklisted = false; |
103 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; | 105 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; |
104 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; | 106 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; |
105 std::string device_vid; | 107 std::string device_vid; |
106 // Enumerate all devices found by AVFoundation, translate the info for each | 108 // Enumerate all devices found by AVFoundation, translate the info for each |
107 // to class Name and add it to |device_names|. | 109 // to class Name and add it to |device_names|. |
108 for (NSString* key in capture_devices) { | 110 for (NSString* key in capture_devices) { |
111 int transport_type = [[capture_devices valueForKey:key] transportType]; | |
112 // Transport types are defined for Audio devices and reused for video. | |
113 VideoCaptureDevice::Name::TransportType device_transport_type = | |
114 (transport_type == kIOAudioDeviceTransportTypeBuiltIn || | |
115 transport_type == kIOAudioDeviceTransportTypeUSB) ? | |
Robert Sesek
2014/07/01 16:23:57
nit: indent this line 4 more spaces, since the con
mcasas
2014/07/02 07:37:35
Done.
| |
116 VideoCaptureDevice::Name::USB_OR_BUILT_IN : | |
117 VideoCaptureDevice::Name::OTHER_TRANSPORT; | |
109 VideoCaptureDevice::Name name( | 118 VideoCaptureDevice::Name name( |
110 [[capture_devices valueForKey:key] UTF8String], | 119 [[[capture_devices valueForKey:key] deviceName] UTF8String], |
111 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION); | 120 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION, |
121 device_transport_type); | |
112 device_names->push_back(name); | 122 device_names->push_back(name); |
113 // Extract the device's Vendor ID and compare to all blacklisted ones. | 123 // Extract the device's Vendor ID and compare to all blacklisted ones. |
114 device_vid = name.GetModel().substr(0, kVidPidSize); | 124 device_vid = name.GetModel().substr(0, kVidPidSize); |
115 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { | 125 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { |
116 is_any_device_blacklisted |= | 126 is_any_device_blacklisted |= |
117 !strcasecmp(device_vid.c_str(), kBlacklistedCameras[i].vid); | 127 !strcasecmp(device_vid.c_str(), kBlacklistedCameras[i].vid); |
118 if (is_any_device_blacklisted) | 128 if (is_any_device_blacklisted) |
119 break; | 129 break; |
120 } | 130 } |
121 } | 131 } |
122 // If there is any device blacklisted in the system, walk the QTKit device | 132 // 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|. | 133 // 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" | 134 // AVFoundation and QTKit device lists partially overlap, so add a "QTKit" |
125 // prefix to the latter ones to distinguish them from the AVFoundation ones. | 135 // prefix to the latter ones to distinguish them from the AVFoundation ones. |
126 if (is_any_device_blacklisted) { | 136 if (is_any_device_blacklisted) { |
127 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; | 137 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; |
128 for (NSString* key in capture_devices) { | 138 for (NSString* key in capture_devices) { |
129 NSString* device_name = [capture_devices valueForKey:key]; | 139 NSString* device_name = [[capture_devices valueForKey:key] deviceName]; |
130 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { | 140 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { |
131 if ([device_name rangeOfString:@(kBlacklistedCameras[i].name) | 141 if ([device_name rangeOfString:@(kBlacklistedCameras[i].name) |
132 options:NSCaseInsensitiveSearch].length != 0) { | 142 options:NSCaseInsensitiveSearch].length != 0) { |
133 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; | 143 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; |
134 VideoCaptureDevice::Name name( | 144 VideoCaptureDevice::Name name( |
135 "QTKit " + std::string([device_name UTF8String]), | 145 "QTKit " + std::string([device_name UTF8String]), |
136 [key UTF8String], VideoCaptureDevice::Name::QTKIT); | 146 [key UTF8String], VideoCaptureDevice::Name::QTKIT); |
137 device_names->push_back(name); | 147 device_names->push_back(name); |
138 } | 148 } |
139 } | 149 } |
(...skipping 28 matching lines...) Expand all Loading... | |
168 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { | 178 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { |
169 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; | 179 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; |
170 [VideoCaptureDeviceAVFoundation getDevice:device | 180 [VideoCaptureDeviceAVFoundation getDevice:device |
171 supportedFormats:supported_formats]; | 181 supportedFormats:supported_formats]; |
172 } else { | 182 } else { |
173 NOTIMPLEMENTED(); | 183 NOTIMPLEMENTED(); |
174 } | 184 } |
175 } | 185 } |
176 | 186 |
177 } // namespace media | 187 } // namespace media |
OLD | NEW |