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

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

Issue 229063003: Mac AVFoundation: use QTKit for cameras not working with AVF (Blackmagic). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: //static Created 6 years, 8 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
« no previous file with comments | « no previous file | media/video/capture/video_capture_device.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_mac.h" 5 #include "media/video/capture/mac/video_capture_device_mac.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #import "media/video/capture/mac/avfoundation_glue.h" 12 #import "media/video/capture/mac/avfoundation_glue.h"
13 #import "media/video/capture/mac/platform_video_capturing_mac.h" 13 #import "media/video/capture/mac/platform_video_capturing_mac.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 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h" 15 #import "media/video/capture/mac/video_capture_device_qtkit_mac.h"
16 16
17 namespace media { 17 namespace media {
18 18
19 const int kMinFrameRate = 1; 19 const int kMinFrameRate = 1;
20 const int kMaxFrameRate = 30; 20 const int kMaxFrameRate = 30;
21 21
22 // In QT device identifiers, the USB VID and PID are stored in 4 bytes each. 22 // In device identifiers, the USB VID and PID are stored in 4 bytes each.
23 const size_t kVidPidSize = 4; 23 const size_t kVidPidSize = 4;
24 24
25 struct Resolution { 25 // Some devices are not correctly supported in AVFoundation, f.i. Blackmagic,
26 int width; 26 // see http://crbug.com/347371. The devices are identified by USB Vendor ID and
27 int height; 27 // by a characteristic substring of the name, usually the vendor's name.
28 }; 28 const struct NameAndVid {
29 const char* vid;
30 const char* name;
31 } kBlacklistedCameras[] = { { "a82c", "Blackmagic" } };
29 32
30 const Resolution kQVGA = { 320, 240 }, 33 const struct Resolution {
31 kVGA = { 640, 480 }, 34 const int width;
32 kHD = { 1280, 720 }; 35 const int height;
36 } kQVGA = { 320, 240 },
37 kVGA = { 640, 480 },
38 kHD = { 1280, 720 };
33 39
34 const Resolution* const kWellSupportedResolutions[] = { 40 const struct Resolution* const kWellSupportedResolutions[] = {
35 &kQVGA, 41 &kQVGA,
36 &kVGA, 42 &kVGA,
37 &kHD, 43 &kHD,
38 }; 44 };
39 45
40 // Rescaling the image to fix the pixel aspect ratio runs the risk of making 46 // Rescaling the image to fix the pixel aspect ratio runs the risk of making
41 // the aspect ratio worse, if QTKit selects a new source mode with a different 47 // the aspect ratio worse, if QTKit selects a new source mode with a different
42 // shape. This constant ensures that we don't take this risk if the current 48 // shape. This constant ensures that we don't take this risk if the current
43 // aspect ratio is tolerable. 49 // aspect ratio is tolerable.
44 const float kMaxPixelAspectRatio = 1.15; 50 const float kMaxPixelAspectRatio = 1.15;
45 51
46 // TODO(ronghuawu): Replace this with CapabilityList::GetBestMatchedCapability. 52 // TODO(ronghuawu): Replace this with CapabilityList::GetBestMatchedCapability.
47 void GetBestMatchSupportedResolution(int* width, int* height) { 53 void GetBestMatchSupportedResolution(int* width, int* height) {
48 int min_diff = kint32max; 54 int min_diff = kint32max;
49 int matched_width = *width; 55 int matched_width = *width;
50 int matched_height = *height; 56 int matched_height = *height;
51 int desired_res_area = *width * *height; 57 int desired_res_area = *width * *height;
52 for (size_t i = 0; i < arraysize(kWellSupportedResolutions); ++i) { 58 for (size_t i = 0; i < arraysize(kWellSupportedResolutions); ++i) {
53 int area = kWellSupportedResolutions[i]->width * 59 int area = kWellSupportedResolutions[i]->width *
54 kWellSupportedResolutions[i]->height; 60 kWellSupportedResolutions[i]->height;
55 int diff = std::abs(desired_res_area - area); 61 int diff = std::abs(desired_res_area - area);
56 if (diff < min_diff) { 62 if (diff < min_diff) {
57 min_diff = diff; 63 min_diff = diff;
58 matched_width = kWellSupportedResolutions[i]->width; 64 matched_width = kWellSupportedResolutions[i]->width;
59 matched_height = kWellSupportedResolutions[i]->height; 65 matched_height = kWellSupportedResolutions[i]->height;
60 } 66 }
61 } 67 }
62 *width = matched_width; 68 *width = matched_width;
63 *height = matched_height; 69 *height = matched_height;
64 } 70 }
65 71
72 //static
66 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { 73 void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
67 // Loop through all available devices and add to |device_names|. 74 // Loop through all available devices and add to |device_names|.
68 device_names->clear(); 75 device_names->clear();
69 76
70 NSDictionary* capture_devices; 77 NSDictionary* capture_devices;
78 bool is_blacklisted_device = false;
71 if (AVFoundationGlue::IsAVFoundationSupported()) { 79 if (AVFoundationGlue::IsAVFoundationSupported()) {
72 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; 80 DVLOG(1) << "Enumerating video capture devices using AVFoundation";
73 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; 81 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames];
82 std::string device_vid;
83 for (NSString* key in capture_devices) {
Robert Sesek 2014/04/10 17:49:10 I'd maybe add some comments: // Enumerate all the
mcasas 2014/04/10 20:23:05 Done.
84 Name name([[capture_devices valueForKey:key] UTF8String],
85 [key UTF8String], Name::AVFOUNDATION);
86 device_names->push_back(name);
87 device_vid = name.GetModel().substr(0, kVidPidSize);
88 // Compare the USB VendorID of the device to the blacklisted ones.
Robert Sesek 2014/04/10 17:49:10 You're still adding blacklisted devices, though, r
mcasas 2014/04/10 20:23:05 Yes, exactly, point being that some resolutions of
89 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) {
Robert Sesek 2014/04/10 17:49:10 // Find any blacklisted devices, and if there are
mcasas 2014/04/10 20:23:05 Done.
90 is_blacklisted_device |= (device_vid == kBlacklistedCameras[i].vid);
91 if (is_blacklisted_device)
Robert Sesek 2014/04/10 17:49:10 Doesn't this mean if your blacklist has more than
mcasas 2014/04/10 20:23:05 Wrong variable name, corrected to |is_any_device_b
92 continue;
93 }
94 }
74 } else { 95 } else {
75 DVLOG(1) << "Enumerating video capture devices using QTKit"; 96 DVLOG(1) << "Enumerating video capture devices using QTKit";
76 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; 97 capture_devices = [VideoCaptureDeviceQTKit deviceNames];
98 for (NSString* key in capture_devices) {
99 Name name([[capture_devices valueForKey:key] UTF8String],
100 [key UTF8String], Name::QTKIT);
101 device_names->push_back(name);
102 }
77 } 103 }
78 for (NSString* key in capture_devices) { 104
79 Name name([[capture_devices valueForKey:key] UTF8String], 105 if (is_blacklisted_device) {
Robert Sesek 2014/04/10 17:49:10 Since this only happens for AVFoundation, maybe fo
mcasas 2014/04/10 20:23:05 Done.
80 [key UTF8String]); 106 // Walk the QTKit device list and add those devices with a blacklisted name
81 device_names->push_back(name); 107 // to the |device_names|, with a "QTKit" prefix to distinguish them from the
108 // AVFoundation ones.
109 capture_devices = [VideoCaptureDeviceQTKit deviceNames];
110 NSString* device_name;
111 for (NSString* key in capture_devices) {
112 device_name = [capture_devices valueForKey:key];
113 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) {
114 if ([device_name rangeOfString:@(kBlacklistedCameras[i].name)
115 options:NSCaseInsensitiveSearch].length != 0) {
116 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String];
117 Name name("QTKit " + std::string([device_name UTF8String]),
Robert Sesek 2014/04/10 17:49:10 This string isn't visible anywhere, is it?
mcasas 2014/04/10 20:23:05 This is the string that shows when clicking on the
118 [key UTF8String], Name::QTKIT);
119 device_names->push_back(name);
120 }
121 }
122 }
82 } 123 }
83 } 124 }
84 125
85 // static 126 // static
86 void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device, 127 void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device,
87 VideoCaptureFormats* formats) { 128 VideoCaptureFormats* formats) {
88 if (AVFoundationGlue::IsAVFoundationSupported()) { 129 if (device.capture_api_type() == Name::AVFOUNDATION) {
89 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; 130 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation";
90 [VideoCaptureDeviceAVFoundation getDevice:device 131 [VideoCaptureDeviceAVFoundation getDevice:device
91 supportedFormats:formats]; 132 supportedFormats:formats];
92 } else { 133 } else {
93 NOTIMPLEMENTED(); 134 NOTIMPLEMENTED();
94 } 135 }
95 } 136 }
96 137
97 const std::string VideoCaptureDevice::Name::GetModel() const { 138 const std::string VideoCaptureDevice::Name::GetModel() const {
98 // Both PID and VID are 4 characters. 139 // Both PID and VID are 4 characters.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 Names device_names; 253 Names device_names;
213 GetDeviceNames(&device_names); 254 GetDeviceNames(&device_names);
214 Names::iterator it = device_names.begin(); 255 Names::iterator it = device_names.begin();
215 for (; it != device_names.end(); ++it) { 256 for (; it != device_names.end(); ++it) {
216 if (it->id() == device_name_.id()) 257 if (it->id() == device_name_.id())
217 break; 258 break;
218 } 259 }
219 if (it == device_names.end()) 260 if (it == device_names.end())
220 return false; 261 return false;
221 262
222 if (AVFoundationGlue::IsAVFoundationSupported()) { 263 DCHECK_NE(it->capture_api_type(), Name::API_TYPE_UNKNOWN);
264 if (it->capture_api_type() == Name::AVFOUNDATION) {
223 capture_device_ = 265 capture_device_ =
224 [[VideoCaptureDeviceAVFoundation alloc] initWithFrameReceiver:this]; 266 [[VideoCaptureDeviceAVFoundation alloc] initWithFrameReceiver:this];
225 } else { 267 } else {
226 capture_device_ = 268 capture_device_ =
227 [[VideoCaptureDeviceQTKit alloc] initWithFrameReceiver:this]; 269 [[VideoCaptureDeviceQTKit alloc] initWithFrameReceiver:this];
228 } 270 }
229 271
230 if (!capture_device_) 272 if (!capture_device_)
231 return false; 273 return false;
232 274
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() 376 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height()
335 width:capture_format_.frame_size.width() 377 width:capture_format_.frame_size.width()
336 frameRate:capture_format_.frame_rate]) { 378 frameRate:capture_format_.frame_rate]) {
337 ReceiveError("Could not configure capture device."); 379 ReceiveError("Could not configure capture device.");
338 return false; 380 return false;
339 } 381 }
340 return true; 382 return true;
341 } 383 }
342 384
343 } // namespace media 385 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/video/capture/video_capture_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698