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" | |
8 #include "base/location.h" | |
9 #include "base/task_runner_util.h" | |
7 #import "media/video/capture/mac/avfoundation_glue.h" | 10 #import "media/video/capture/mac/avfoundation_glue.h" |
8 #include "media/video/capture/mac/video_capture_device_mac.h" | 11 #include "media/video/capture/mac/video_capture_device_mac.h" |
9 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" | 12 #import "media/video/capture/mac/video_capture_device_avfoundation_mac.h" |
10 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" | 13 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" |
11 | 14 |
12 namespace media { | 15 namespace media { |
13 | 16 |
14 // Some devices are not correctly supported in AVFoundation, f.i. Blackmagic, | 17 // Some devices are not correctly supported in AVFoundation, f.i. Blackmagic, |
15 // see http://crbug.com/347371. The devices are identified by USB Vendor ID and | 18 // see http://crbug.com/347371. The devices are identified by USB Vendor ID and |
16 // by a characteristic substring of the name, usually the vendor's name. | 19 // by a characteristic substring of the name, usually the vendor's name. |
17 const struct NameAndVid { | 20 const struct NameAndVid { |
18 const char* vid; | 21 const char* vid; |
19 const char* name; | 22 const char* name; |
20 } kBlacklistedCameras[] = { { "a82c", "Blackmagic" } }; | 23 } kBlacklistedCameras[] = { { "a82c", "Blackmagic" } }; |
21 | 24 |
22 // In device identifiers, the USB VID and PID are stored in 4 bytes each. | 25 // In device identifiers, the USB VID and PID are stored in 4 bytes each. |
23 const size_t kVidPidSize = 4; | 26 const size_t kVidPidSize = 4; |
24 | 27 |
25 VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac() { | 28 static VideoCaptureDevice::Names EnumerateDevicesUsingQTKit(){ |
tommi (sloooow) - chröme
2014/05/30 12:37:51
space before {
mcasas
2014/05/30 14:08:50
Done.
| |
29 VideoCaptureDevice::Names device_names; | |
30 NSMutableDictionary* capture_devices = | |
31 [[[NSMutableDictionary alloc] init] autorelease]; | |
32 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices]; | |
33 for (NSString* key in capture_devices) { | |
34 VideoCaptureDevice::Name name( | |
35 [[capture_devices valueForKey:key] UTF8String], | |
36 [key UTF8String], VideoCaptureDevice::Name::QTKIT); | |
37 device_names.push_back(name); | |
38 } | |
39 return device_names; | |
40 } | |
41 | |
42 static void RunDevicesEnumeratedCallback( | |
43 const base::Callback<void(media::VideoCaptureDevice::Names&)>& callback, | |
44 VideoCaptureDevice::Names device_names) { | |
45 callback.Run(device_names); | |
46 } | |
47 | |
48 VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac( | |
49 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) | |
50 : ui_task_runner_(ui_task_runner) { | |
26 thread_checker_.DetachFromThread(); | 51 thread_checker_.DetachFromThread(); |
27 } | 52 } |
28 | 53 |
54 VideoCaptureDeviceFactoryMac::~VideoCaptureDeviceFactoryMac() {} | |
55 | |
29 scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create( | 56 scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create( |
30 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | |
31 const VideoCaptureDevice::Name& device_name) { | 57 const VideoCaptureDevice::Name& device_name) { |
32 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
33 DCHECK_NE(device_name.capture_api_type(), | 59 DCHECK_NE(device_name.capture_api_type(), |
34 VideoCaptureDevice::Name::API_TYPE_UNKNOWN); | 60 VideoCaptureDevice::Name::API_TYPE_UNKNOWN); |
35 | 61 |
36 VideoCaptureDevice::Names device_names; | |
37 GetDeviceNames(&device_names); | |
38 VideoCaptureDevice::Names::iterator it = device_names.begin(); | |
39 for (; it != device_names.end(); ++it) { | |
40 if (it->id() == device_name.id()) | |
41 break; | |
42 } | |
43 if (it == device_names.end()) | |
44 return scoped_ptr<VideoCaptureDevice>(); | |
45 | |
46 scoped_ptr<VideoCaptureDeviceMac> capture_device( | 62 scoped_ptr<VideoCaptureDeviceMac> capture_device( |
47 new VideoCaptureDeviceMac(device_name)); | 63 new VideoCaptureDeviceMac(device_name)); |
48 if (!capture_device->Init(device_name.capture_api_type())) { | 64 if (!capture_device->Init(device_name.capture_api_type())) { |
49 LOG(ERROR) << "Could not initialize VideoCaptureDevice."; | 65 LOG(ERROR) << "Could not initialize VideoCaptureDevice."; |
50 capture_device.reset(); | 66 capture_device.reset(); |
51 } | 67 } |
52 return scoped_ptr<VideoCaptureDevice>(capture_device.Pass()); | 68 return scoped_ptr<VideoCaptureDevice>(capture_device.Pass()); |
53 } | 69 } |
54 | 70 |
55 void VideoCaptureDeviceFactoryMac::GetDeviceNames( | 71 void VideoCaptureDeviceFactoryMac::GetDeviceNames( |
56 VideoCaptureDevice::Names* const device_names) { | 72 VideoCaptureDevice::Names* device_names) { |
57 DCHECK(thread_checker_.CalledOnValidThread()); | 73 DCHECK(thread_checker_.CalledOnValidThread()); |
58 // Loop through all available devices and add to |device_names|. | 74 // Loop through all available devices and add to |device_names|. |
59 NSDictionary* capture_devices; | 75 NSDictionary* capture_devices; |
60 if (AVFoundationGlue::IsAVFoundationSupported()) { | 76 if (AVFoundationGlue::IsAVFoundationSupported()) { |
61 bool is_any_device_blacklisted = false; | 77 bool is_any_device_blacklisted = false; |
62 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; | 78 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; |
63 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; | 79 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; |
64 std::string device_vid; | 80 std::string device_vid; |
65 // Enumerate all devices found by AVFoundation, translate the info for each | 81 // Enumerate all devices found by AVFoundation, translate the info for each |
66 // to class Name and add it to |device_names|. | 82 // to class Name and add it to |device_names|. |
(...skipping 25 matching lines...) Expand all Loading... | |
92 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; | 108 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; |
93 VideoCaptureDevice::Name name( | 109 VideoCaptureDevice::Name name( |
94 "QTKit " + std::string([device_name UTF8String]), | 110 "QTKit " + std::string([device_name UTF8String]), |
95 [key UTF8String], VideoCaptureDevice::Name::QTKIT); | 111 [key UTF8String], VideoCaptureDevice::Name::QTKIT); |
96 device_names->push_back(name); | 112 device_names->push_back(name); |
97 } | 113 } |
98 } | 114 } |
99 } | 115 } |
100 } | 116 } |
101 } else { | 117 } else { |
102 DVLOG(1) << "Enumerating video capture devices using QTKit"; | 118 // We should not enumerate QTKit devices in Device Thread; |
103 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; | 119 NOTREACHED(); |
104 for (NSString* key in capture_devices) { | |
105 VideoCaptureDevice::Name name( | |
106 [[capture_devices valueForKey:key] UTF8String], | |
107 [key UTF8String], VideoCaptureDevice::Name::QTKIT); | |
108 device_names->push_back(name); | |
109 } | |
110 } | 120 } |
111 } | 121 } |
112 | 122 |
123 void VideoCaptureDeviceFactoryMac::EnumerateDeviceNames( | |
124 const base::Callback<void(media::VideoCaptureDevice::Names&)>& callback) { | |
125 DCHECK(thread_checker_.CalledOnValidThread()); | |
126 if (AVFoundationGlue::IsAVFoundationSupported()) { | |
127 VideoCaptureDevice::Names device_names; | |
128 GetDeviceNames(&device_names); | |
129 callback.Run(device_names); | |
130 } else { | |
131 DVLOG(1) << "Enumerating video capture devices using QTKit"; | |
132 base::PostTaskAndReplyWithResult(ui_task_runner_, FROM_HERE, | |
133 base::Bind(&EnumerateDevicesUsingQTKit), | |
tommi (sloooow) - chröme
2014/05/30 12:37:51
indent
mcasas
2014/05/30 14:08:50
Done.
| |
134 base::Bind(&RunDevicesEnumeratedCallback, callback)); | |
135 } | |
136 } | |
137 | |
113 void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats( | 138 void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats( |
114 const VideoCaptureDevice::Name& device, | 139 const VideoCaptureDevice::Name& device, |
115 VideoCaptureFormats* supported_formats) { | 140 VideoCaptureFormats* supported_formats) { |
116 DCHECK(thread_checker_.CalledOnValidThread()); | 141 DCHECK(thread_checker_.CalledOnValidThread()); |
117 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { | 142 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { |
118 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; | 143 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; |
119 [VideoCaptureDeviceAVFoundation getDevice:device | 144 [VideoCaptureDeviceAVFoundation getDevice:device |
120 supportedFormats:supported_formats]; | 145 supportedFormats:supported_formats]; |
121 } else { | 146 } else { |
122 NOTIMPLEMENTED(); | 147 NOTIMPLEMENTED(); |
123 } | 148 } |
124 } | 149 } |
125 | 150 |
126 } // namespace media | 151 } // namespace media |
OLD | NEW |