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

Side by Side Diff: media/capture/video/mac/video_capture_device_factory_mac.mm

Issue 1815983003: Remove deprecated QTKit Video Capture Support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 unified diff | Download patch
OLDNEW
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/capture/video/mac/video_capture_device_factory_mac.h" 5 #include "media/capture/video/mac/video_capture_device_factory_mac.h"
6 6
7 #import <IOKit/audio/IOAudioTypes.h> 7 #import <IOKit/audio/IOAudioTypes.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/profiler/scoped_tracker.h" 15 #include "base/profiler/scoped_tracker.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/task_runner_util.h" 17 #include "base/task_runner_util.h"
18 #import "media/base/mac/avfoundation_glue.h" 18 #import "media/base/mac/avfoundation_glue.h"
19 #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" 19 #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h"
20 #import "media/capture/video/mac/video_capture_device_decklink_mac.h" 20 #import "media/capture/video/mac/video_capture_device_decklink_mac.h"
21 #include "media/capture/video/mac/video_capture_device_mac.h" 21 #include "media/capture/video/mac/video_capture_device_mac.h"
22 #import "media/capture/video/mac/video_capture_device_qtkit_mac.h"
23 22
24 namespace media { 23 namespace media {
25 24
26 // In QTKit API, some devices are known to crash if VGA is requested, for them 25 // Blacklisted devices are identified by a characteristic trailing substring of
27 // HD is the only supported resolution (see http://crbug.com/396812). In the 26 // uniqueId. At the moment these are just Blackmagic devices.
28 // AVfoundation case, we skip enumerating them altogether. These devices are
29 // identified by a characteristic trailing substring of uniqueId. At the moment
30 // these are just Blackmagic devices.
31 const struct NameAndVid { 27 const struct NameAndVid {
32 const char* unique_id_signature; 28 const char* unique_id_signature;
33 const int capture_width; 29 const int capture_width;
34 const int capture_height; 30 const int capture_height;
35 const float capture_frame_rate; 31 const float capture_frame_rate;
36 } kBlacklistedCameras[] = {{"-01FDA82C8A9C", 1280, 720, 60.0f}}; 32 } kBlacklistedCameras[] = {{"-01FDA82C8A9C", 1280, 720, 60.0f}};
37 33
38 static bool IsDeviceBlacklisted(const VideoCaptureDevice::Name& name) { 34 static bool IsDeviceBlacklisted(const VideoCaptureDevice::Name& name) {
39 bool is_device_blacklisted = false; 35 bool is_device_blacklisted = false;
40 for(size_t i = 0; 36 for(size_t i = 0;
41 !is_device_blacklisted && i < arraysize(kBlacklistedCameras); ++i) { 37 !is_device_blacklisted && i < arraysize(kBlacklistedCameras); ++i) {
42 is_device_blacklisted = 38 is_device_blacklisted =
43 base::EndsWith(name.id(), 39 base::EndsWith(name.id(),
44 kBlacklistedCameras[i].unique_id_signature, 40 kBlacklistedCameras[i].unique_id_signature,
45 base::CompareCase::INSENSITIVE_ASCII); 41 base::CompareCase::INSENSITIVE_ASCII);
46 } 42 }
47 DVLOG_IF(2, is_device_blacklisted) << "Blacklisted camera: " << name.name() 43 DVLOG_IF(2, is_device_blacklisted) << "Blacklisted camera: " << name.name()
48 << ", id: " << name.id(); 44 << ", id: " << name.id();
49 return is_device_blacklisted; 45 return is_device_blacklisted;
50 } 46 }
51 47
52 static scoped_ptr<media::VideoCaptureDevice::Names> 48 VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac() {
53 EnumerateDevicesUsingQTKit() {
54 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/458397 is
55 // fixed.
56 tracked_objects::ScopedTracker tracking_profile(
57 FROM_HERE_WITH_EXPLICIT_FUNCTION(
58 "458397 media::EnumerateDevicesUsingQTKit"));
59
60 scoped_ptr<VideoCaptureDevice::Names> device_names(
61 new VideoCaptureDevice::Names());
62 NSMutableDictionary* capture_devices =
63 [[[NSMutableDictionary alloc] init] autorelease];
64 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices];
65 for (NSString* key in capture_devices) {
66 VideoCaptureDevice::Name name(
67 [[[capture_devices valueForKey:key] deviceName] UTF8String],
68 [key UTF8String], VideoCaptureDevice::Name::QTKIT);
69 if (IsDeviceBlacklisted(name))
70 name.set_is_blacklisted(true);
71 device_names->push_back(name);
72 }
73 return device_names;
74 }
75
76 static void RunDevicesEnumeratedCallback(
77 const base::Callback<void(scoped_ptr<media::VideoCaptureDevice::Names>)>&
78 callback,
79 scoped_ptr<media::VideoCaptureDevice::Names> device_names) {
80 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/458397 is
81 // fixed.
82 tracked_objects::ScopedTracker tracking_profile(
83 FROM_HERE_WITH_EXPLICIT_FUNCTION(
84 "458397 media::RunDevicesEnumeratedCallback"));
85 callback.Run(std::move(device_names));
86 }
87
88 VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac(
89 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
90 : ui_task_runner_(ui_task_runner) {
91 thread_checker_.DetachFromThread(); 49 thread_checker_.DetachFromThread();
92 } 50 }
93 51
94 VideoCaptureDeviceFactoryMac::~VideoCaptureDeviceFactoryMac() { 52 VideoCaptureDeviceFactoryMac::~VideoCaptureDeviceFactoryMac() {
95 } 53 }
96 54
97 scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create( 55 scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create(
98 const VideoCaptureDevice::Name& device_name) { 56 const VideoCaptureDevice::Name& device_name) {
99 DCHECK(thread_checker_.CalledOnValidThread()); 57 DCHECK(thread_checker_.CalledOnValidThread());
100 DCHECK_NE(device_name.capture_api_type(), 58 DCHECK_NE(device_name.capture_api_type(),
(...skipping 16 matching lines...) Expand all
117 void VideoCaptureDeviceFactoryMac::GetDeviceNames( 75 void VideoCaptureDeviceFactoryMac::GetDeviceNames(
118 VideoCaptureDevice::Names* device_names) { 76 VideoCaptureDevice::Names* device_names) {
119 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/458397 is 77 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/458397 is
120 // fixed. 78 // fixed.
121 tracked_objects::ScopedTracker tracking_profile( 79 tracked_objects::ScopedTracker tracking_profile(
122 FROM_HERE_WITH_EXPLICIT_FUNCTION( 80 FROM_HERE_WITH_EXPLICIT_FUNCTION(
123 "458397 VideoCaptureDeviceFactoryMac::GetDeviceNames")); 81 "458397 VideoCaptureDeviceFactoryMac::GetDeviceNames"));
124 DCHECK(thread_checker_.CalledOnValidThread()); 82 DCHECK(thread_checker_.CalledOnValidThread());
125 // Loop through all available devices and add to |device_names|. 83 // Loop through all available devices and add to |device_names|.
126 NSDictionary* capture_devices; 84 NSDictionary* capture_devices;
127 if (AVFoundationGlue::IsAVFoundationSupported()) { 85 CHECK(AVFoundationGlue::IsAVFoundationSupported());
128 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; 86 DVLOG(1) << "Enumerating video capture devices using AVFoundation";
129 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; 87 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames];
130 // Enumerate all devices found by AVFoundation, translate the info for each 88 // Enumerate all devices found by AVFoundation, translate the info for each
131 // to class Name and add it to |device_names|. 89 // to class Name and add it to |device_names|.
132 for (NSString* key in capture_devices) { 90 for (NSString* key in capture_devices) {
133 int transport_type = [[capture_devices valueForKey:key] transportType]; 91 int transport_type = [[capture_devices valueForKey:key] transportType];
134 // Transport types are defined for Audio devices and reused for video. 92 // Transport types are defined for Audio devices and reused for video.
135 VideoCaptureDevice::Name::TransportType device_transport_type = 93 VideoCaptureDevice::Name::TransportType device_transport_type =
136 (transport_type == kIOAudioDeviceTransportTypeBuiltIn || 94 (transport_type == kIOAudioDeviceTransportTypeBuiltIn ||
137 transport_type == kIOAudioDeviceTransportTypeUSB) 95 transport_type == kIOAudioDeviceTransportTypeUSB)
138 ? VideoCaptureDevice::Name::USB_OR_BUILT_IN 96 ? VideoCaptureDevice::Name::USB_OR_BUILT_IN
139 : VideoCaptureDevice::Name::OTHER_TRANSPORT; 97 : VideoCaptureDevice::Name::OTHER_TRANSPORT;
140 VideoCaptureDevice::Name name( 98 VideoCaptureDevice::Name name(
141 [[[capture_devices valueForKey:key] deviceName] UTF8String], 99 [[[capture_devices valueForKey:key] deviceName] UTF8String],
142 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION, 100 [key UTF8String], VideoCaptureDevice::Name::AVFOUNDATION,
143 device_transport_type); 101 device_transport_type);
144 if (IsDeviceBlacklisted(name)) 102 if (IsDeviceBlacklisted(name))
145 continue; 103 continue;
146 device_names->push_back(name); 104 device_names->push_back(name);
147 } 105 }
tommi (sloooow) - chröme 2016/03/20 22:37:44 looks like the indent is off
perkj_chrome 2016/03/21 09:45:40 git cl format missed does not think this is off. W
148 // Also retrieve Blackmagic devices, if present, via DeckLink SDK API. 106 // Also retrieve Blackmagic devices, if present, via DeckLink SDK API.
149 VideoCaptureDeviceDeckLinkMac::EnumerateDevices(device_names); 107 VideoCaptureDeviceDeckLinkMac::EnumerateDevices(device_names);
150 } else {
151 // We should not enumerate QTKit devices in Device Thread;
152 NOTREACHED();
153 }
154 } 108 }
155 109
156 void VideoCaptureDeviceFactoryMac::EnumerateDeviceNames(const base::Callback< 110 void VideoCaptureDeviceFactoryMac::EnumerateDeviceNames(const base::Callback<
157 void(scoped_ptr<media::VideoCaptureDevice::Names>)>& callback) { 111 void(scoped_ptr<media::VideoCaptureDevice::Names>)>& callback) {
158 DCHECK(thread_checker_.CalledOnValidThread()); 112 DCHECK(thread_checker_.CalledOnValidThread());
159 if (AVFoundationGlue::IsAVFoundationSupported()) { 113 CHECK(AVFoundationGlue::IsAVFoundationSupported());
160 scoped_ptr<VideoCaptureDevice::Names> device_names( 114 scoped_ptr<VideoCaptureDevice::Names> device_names(
161 new VideoCaptureDevice::Names()); 115 new VideoCaptureDevice::Names());
162 GetDeviceNames(device_names.get()); 116 GetDeviceNames(device_names.get());
tommi (sloooow) - chröme 2016/03/20 22:37:44 out of curiosity, what thread are we running on he
perkj_chrome 2016/03/21 09:45:40 device_task_runnner_ which we changed to be the UI
163 callback.Run(std::move(device_names)); 117 callback.Run(std::move(device_names));
164 } else {
165 DVLOG(1) << "Enumerating video capture devices using QTKit";
166 base::PostTaskAndReplyWithResult(
167 ui_task_runner_.get(), FROM_HERE,
168 base::Bind(&EnumerateDevicesUsingQTKit),
169 base::Bind(&RunDevicesEnumeratedCallback, callback));
170 }
171 } 118 }
172 119
173 void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats( 120 void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats(
174 const VideoCaptureDevice::Name& device, 121 const VideoCaptureDevice::Name& device,
175 VideoCaptureFormats* supported_formats) { 122 VideoCaptureFormats* supported_formats) {
176 DCHECK(thread_checker_.CalledOnValidThread()); 123 DCHECK(thread_checker_.CalledOnValidThread());
177 switch (device.capture_api_type()) { 124 switch (device.capture_api_type()) {
178 case VideoCaptureDevice::Name::AVFOUNDATION: 125 case VideoCaptureDevice::Name::AVFOUNDATION:
179 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; 126 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation";
180 [VideoCaptureDeviceAVFoundation getDevice:device 127 [VideoCaptureDeviceAVFoundation getDevice:device
181 supportedFormats:supported_formats]; 128 supportedFormats:supported_formats];
182 break; 129 break;
183 case VideoCaptureDevice::Name::QTKIT:
184 // Blacklisted cameras provide their own supported format(s), otherwise no
185 // such information is provided for QTKit devices.
186 if (device.is_blacklisted()) {
187 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) {
188 if (base::EndsWith(device.id(),
189 kBlacklistedCameras[i].unique_id_signature,
190 base::CompareCase::INSENSITIVE_ASCII)) {
191 supported_formats->push_back(media::VideoCaptureFormat(
192 gfx::Size(kBlacklistedCameras[i].capture_width,
193 kBlacklistedCameras[i].capture_height),
194 kBlacklistedCameras[i].capture_frame_rate,
195 media::PIXEL_FORMAT_UYVY));
196 break;
197 }
198 }
199 }
200 break;
201 case VideoCaptureDevice::Name::DECKLINK: 130 case VideoCaptureDevice::Name::DECKLINK:
202 DVLOG(1) << "Enumerating video capture capabilities " << device.name(); 131 DVLOG(1) << "Enumerating video capture capabilities " << device.name();
203 VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities( 132 VideoCaptureDeviceDeckLinkMac::EnumerateDeviceCapabilities(
204 device, supported_formats); 133 device, supported_formats);
205 break; 134 break;
206 default: 135 default:
207 NOTREACHED(); 136 NOTREACHED();
208 } 137 }
209 } 138 }
210 139
211 // static 140 // static
212 VideoCaptureDeviceFactory* 141 VideoCaptureDeviceFactory*
213 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( 142 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
214 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { 143 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
215 return new VideoCaptureDeviceFactoryMac(ui_task_runner); 144 return new VideoCaptureDeviceFactoryMac();
216 } 145 }
217 146
218 } // namespace media 147 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698