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

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

Issue 294893006: VideoCaptureDeviceFactory: Change device enumeration to callback + QTKit enumerates in UI thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adapted VCD unittests to enumeration via callback. Created 6 years, 7 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 | Annotate | Revision Log
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/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(){
29 // DCHECK that ui_device_thread_ belongs to me.
perkj_chrome 2014/05/26 11:49:42 remove this comment.
mcasas 2014/05/26 13:00:18 Done.
30 VideoCaptureDevice::Names device_names;
31 NSMutableDictionary* capture_devices =
32 [[[NSMutableDictionary alloc] init] autorelease];
33 [VideoCaptureDeviceQTKit getDeviceNames:capture_devices];
34 for (NSString* key in capture_devices) {
35 VideoCaptureDevice::Name name(
36 [[capture_devices valueForKey:key] UTF8String],
37 [key UTF8String], VideoCaptureDevice::Name::QTKIT);
38 device_names.push_back(name);
39 }
40 return device_names;
41 }
42
43 static void RunDevicesEnumeratedCallback(
44 const base::Callback<void(media::VideoCaptureDevice::Names&)>& callback,
45 VideoCaptureDevice::Names device_names) {
46 callback.Run(device_names);
47 }
48
49 VideoCaptureDeviceFactoryMac::VideoCaptureDeviceFactoryMac(
50 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
51 : ui_task_runner_(ui_task_runner) {
26 thread_checker_.DetachFromThread(); 52 thread_checker_.DetachFromThread();
27 } 53 }
28 54
55 VideoCaptureDeviceFactoryMac::~VideoCaptureDeviceFactoryMac() {}
56
29 scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create( 57 scoped_ptr<VideoCaptureDevice> VideoCaptureDeviceFactoryMac::Create(
30 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
31 const VideoCaptureDevice::Name& device_name) { 58 const VideoCaptureDevice::Name& device_name) {
32 DCHECK(thread_checker_.CalledOnValidThread()); 59 DCHECK(thread_checker_.CalledOnValidThread());
33 DCHECK_NE(device_name.capture_api_type(), 60 DCHECK_NE(device_name.capture_api_type(),
34 VideoCaptureDevice::Name::API_TYPE_UNKNOWN); 61 VideoCaptureDevice::Name::API_TYPE_UNKNOWN);
35 62
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( 63 scoped_ptr<VideoCaptureDeviceMac> capture_device(
47 new VideoCaptureDeviceMac(device_name)); 64 new VideoCaptureDeviceMac(device_name));
48 if (!capture_device->Init(device_name.capture_api_type())) { 65 if (!capture_device->Init(device_name.capture_api_type())) {
49 LOG(ERROR) << "Could not initialize VideoCaptureDevice."; 66 LOG(ERROR) << "Could not initialize VideoCaptureDevice.";
50 capture_device.reset(); 67 capture_device.reset();
51 } 68 }
52 return scoped_ptr<VideoCaptureDevice>(capture_device.Pass()); 69 return scoped_ptr<VideoCaptureDevice>(capture_device.Pass());
53 } 70 }
54 71
55 void VideoCaptureDeviceFactoryMac::GetDeviceNames( 72 void VideoCaptureDeviceFactoryMac::GetDeviceNames(
56 VideoCaptureDevice::Names* const device_names) { 73 VideoCaptureDevice::Names* device_names) {
57 DCHECK(thread_checker_.CalledOnValidThread()); 74 DCHECK(thread_checker_.CalledOnValidThread());
58 // Loop through all available devices and add to |device_names|. 75 // Loop through all available devices and add to |device_names|.
59 NSDictionary* capture_devices; 76 NSDictionary* capture_devices;
60 if (AVFoundationGlue::IsAVFoundationSupported()) { 77 if (AVFoundationGlue::IsAVFoundationSupported()) {
61 bool is_any_device_blacklisted = false; 78 bool is_any_device_blacklisted = false;
62 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; 79 DVLOG(1) << "Enumerating video capture devices using AVFoundation";
63 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; 80 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames];
64 std::string device_vid; 81 std::string device_vid;
65 // Enumerate all devices found by AVFoundation, translate the info for each 82 // Enumerate all devices found by AVFoundation, translate the info for each
66 // to class Name and add it to |device_names|. 83 // to class Name and add it to |device_names|.
(...skipping 25 matching lines...) Expand all
92 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; 109 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String];
93 VideoCaptureDevice::Name name( 110 VideoCaptureDevice::Name name(
94 "QTKit " + std::string([device_name UTF8String]), 111 "QTKit " + std::string([device_name UTF8String]),
95 [key UTF8String], VideoCaptureDevice::Name::QTKIT); 112 [key UTF8String], VideoCaptureDevice::Name::QTKIT);
96 device_names->push_back(name); 113 device_names->push_back(name);
97 } 114 }
98 } 115 }
99 } 116 }
100 } 117 }
101 } else { 118 } else {
102 DVLOG(1) << "Enumerating video capture devices using QTKit"; 119 // We should not enumerate QTKit devices in Device Thread;
103 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; 120 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 } 121 }
111 } 122 }
112 123
124 void VideoCaptureDeviceFactoryMac::EnumerateDeviceNames(
125 const base::Callback<void(media::VideoCaptureDevice::Names&)>& callback) {
126 if (AVFoundationGlue::IsAVFoundationSupported()) {
127 VideoCaptureDeviceFactory::EnumerateDeviceNames(callback);
perkj_chrome 2014/05/26 11:49:42 This seems fragile. Remove GetDevicesNames and to
mcasas 2014/05/26 13:00:18 Done.
128 } else {
129 DVLOG(1) << "Enumerating video capture devices using QTKit";
130 base::PostTaskAndReplyWithResult(ui_task_runner_, FROM_HERE,
131 base::Bind(&EnumerateDevicesUsingQTKit),
132 base::Bind(&RunDevicesEnumeratedCallback, callback));
133 }
134 }
135
113 void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats( 136 void VideoCaptureDeviceFactoryMac::GetDeviceSupportedFormats(
114 const VideoCaptureDevice::Name& device, 137 const VideoCaptureDevice::Name& device,
115 VideoCaptureFormats* supported_formats) { 138 VideoCaptureFormats* supported_formats) {
116 DCHECK(thread_checker_.CalledOnValidThread()); 139 DCHECK(thread_checker_.CalledOnValidThread());
117 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) { 140 if (device.capture_api_type() == VideoCaptureDevice::Name::AVFOUNDATION) {
118 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; 141 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation";
119 [VideoCaptureDeviceAVFoundation getDevice:device 142 [VideoCaptureDeviceAVFoundation getDevice:device
120 supportedFormats:supported_formats]; 143 supportedFormats:supported_formats];
121 } else { 144 } else {
122 NOTIMPLEMENTED(); 145 NOTIMPLEMENTED();
123 } 146 }
124 } 147 }
125 148
126 } // namespace media 149 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698