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

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: rsesek@ comments 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
Robert Sesek 2014/04/10 16:19:38 // static
mcasas 2014/04/10 16:31:34 Done.
66 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { 72 void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
67 // Loop through all available devices and add to |device_names|. 73 // Loop through all available devices and add to |device_names|.
68 device_names->clear(); 74 device_names->clear();
69 75
70 NSDictionary* capture_devices; 76 NSDictionary* capture_devices;
77 bool is_blacklisted_device = false;
71 if (AVFoundationGlue::IsAVFoundationSupported()) { 78 if (AVFoundationGlue::IsAVFoundationSupported()) {
72 DVLOG(1) << "Enumerating video capture devices using AVFoundation"; 79 DVLOG(1) << "Enumerating video capture devices using AVFoundation";
73 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; 80 capture_devices = [VideoCaptureDeviceAVFoundation deviceNames];
81 std::string device_vid;
82 for (NSString* key in capture_devices) {
83 Name name([[capture_devices valueForKey:key] UTF8String],
84 [key UTF8String], Name::AVFOUNDATION);
85 device_names->push_back(name);
86 device_vid = name.GetModel().substr(0, kVidPidSize);
87 // Compare the USB VendorID of the device to the blacklisted ones.
88 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) {
89 is_blacklisted_device |= (device_vid == kBlacklistedCameras[i].vid);
90 if (is_blacklisted_device)
91 continue;
92 }
93 }
74 } else { 94 } else {
75 DVLOG(1) << "Enumerating video capture devices using QTKit"; 95 DVLOG(1) << "Enumerating video capture devices using QTKit";
76 capture_devices = [VideoCaptureDeviceQTKit deviceNames]; 96 capture_devices = [VideoCaptureDeviceQTKit deviceNames];
97 for (NSString* key in capture_devices) {
98 Name name([[capture_devices valueForKey:key] UTF8String],
99 [key UTF8String], Name::QTKIT);
100 device_names->push_back(name);
101 }
77 } 102 }
78 for (NSString* key in capture_devices) { 103
79 Name name([[capture_devices valueForKey:key] UTF8String], 104 if (is_blacklisted_device) {
80 [key UTF8String]); 105 // Walk the QTKit device list and add those devices with a blacklisted name
81 device_names->push_back(name); 106 // to the |device_names|, with a "QTKit" prefix to distinguish them from the
107 // AVFoundation ones.
108 capture_devices = [VideoCaptureDeviceQTKit deviceNames];
109 NSString* device_name;
110 for (NSString* key in capture_devices) {
111 device_name = [capture_devices valueForKey:key];
112 for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) {
113 if ([device_name rangeOfString:@(kBlacklistedCameras[i].name)
114 options:NSCaseInsensitiveSearch].length != 0) {
115 DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String];
116 Name name("QTKit " + std::string([device_name UTF8String]),
117 [key UTF8String], Name::QTKIT);
118 device_names->push_back(name);
119 }
120 }
121 }
82 } 122 }
83 } 123 }
84 124
85 // static 125 // static
86 void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device, 126 void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device,
87 VideoCaptureFormats* formats) { 127 VideoCaptureFormats* formats) {
88 if (AVFoundationGlue::IsAVFoundationSupported()) { 128 if (device.capture_api_type() == Name::AVFOUNDATION) {
89 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; 129 DVLOG(1) << "Enumerating video capture capabilities, AVFoundation";
90 [VideoCaptureDeviceAVFoundation getDevice:device 130 [VideoCaptureDeviceAVFoundation getDevice:device
91 supportedFormats:formats]; 131 supportedFormats:formats];
92 } else { 132 } else {
93 NOTIMPLEMENTED(); 133 NOTIMPLEMENTED();
94 } 134 }
95 } 135 }
96 136
97 const std::string VideoCaptureDevice::Name::GetModel() const { 137 const std::string VideoCaptureDevice::Name::GetModel() const {
98 // Both PID and VID are 4 characters. 138 // Both PID and VID are 4 characters.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 Names device_names; 252 Names device_names;
213 GetDeviceNames(&device_names); 253 GetDeviceNames(&device_names);
214 Names::iterator it = device_names.begin(); 254 Names::iterator it = device_names.begin();
215 for (; it != device_names.end(); ++it) { 255 for (; it != device_names.end(); ++it) {
216 if (it->id() == device_name_.id()) 256 if (it->id() == device_name_.id())
217 break; 257 break;
218 } 258 }
219 if (it == device_names.end()) 259 if (it == device_names.end())
220 return false; 260 return false;
221 261
222 if (AVFoundationGlue::IsAVFoundationSupported()) { 262 DCHECK_NE(it->capture_api_type(), Name::API_TYPE_UNKNOWN);
263 if (it->capture_api_type() == Name::AVFOUNDATION) {
223 capture_device_ = 264 capture_device_ =
224 [[VideoCaptureDeviceAVFoundation alloc] initWithFrameReceiver:this]; 265 [[VideoCaptureDeviceAVFoundation alloc] initWithFrameReceiver:this];
225 } else { 266 } else {
226 capture_device_ = 267 capture_device_ =
227 [[VideoCaptureDeviceQTKit alloc] initWithFrameReceiver:this]; 268 [[VideoCaptureDeviceQTKit alloc] initWithFrameReceiver:this];
228 } 269 }
229 270
230 if (!capture_device_) 271 if (!capture_device_)
231 return false; 272 return false;
232 273
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() 375 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height()
335 width:capture_format_.frame_size.width() 376 width:capture_format_.frame_size.width()
336 frameRate:capture_format_.frame_rate]) { 377 frameRate:capture_format_.frame_rate]) {
337 ReceiveError("Could not configure capture device."); 378 ReceiveError("Could not configure capture device.");
338 return false; 379 return false;
339 } 380 }
340 return true; 381 return true;
341 } 382 }
342 383
343 } // namespace media 384 } // 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