Index: media/video/capture/mac/video_capture_device_mac.mm |
diff --git a/media/video/capture/mac/video_capture_device_mac.mm b/media/video/capture/mac/video_capture_device_mac.mm |
index 75f3937e894355b1cce4dc8274dad0586209b276..6293759c6fb76dff36325bf664a0eb20309c1937 100644 |
--- a/media/video/capture/mac/video_capture_device_mac.mm |
+++ b/media/video/capture/mac/video_capture_device_mac.mm |
@@ -19,27 +19,33 @@ namespace media { |
const int kMinFrameRate = 1; |
const int kMaxFrameRate = 30; |
-// In QT device identifiers, the USB VID and PID are stored in 4 bytes each. |
+// In device identifiers, the USB VID and PID are stored in 4 bytes each. |
const size_t kVidPidSize = 4; |
-struct Resolution { |
- int width; |
- int height; |
-}; |
- |
-const Resolution kQVGA = { 320, 240 }, |
- kVGA = { 640, 480 }, |
- kHD = { 1280, 720 }; |
- |
-const Resolution* const kWellSupportedResolutions[] = { |
- &kQVGA, |
- &kVGA, |
- &kHD, |
+// Some devices are not correctly supported in AVFoundation, f.i. Blackmagic, |
+// see http://crbug.com/347371. The devices are identified by USB Vendor ID and |
+// by a characteristic substring of the name, usually the vendor's name. |
+const struct NameAndVid { |
+ const char* vid; |
+ const char* name; |
+} kBlacklistedCameras[] = { { "a82c", "Blackmagic" } }; |
+ |
+const struct Resolution { |
+ const int width; |
+ const int height; |
+} kQVGA = { 320, 240 }, |
+ kVGA = { 640, 480 }, |
+ kHD = { 1280, 720 }; |
+ |
+const struct Resolution* const kWellSupportedResolutions[] = { |
+ &kQVGA, |
+ &kVGA, |
+ &kHD, |
}; |
// Rescaling the image to fix the pixel aspect ratio runs the risk of making |
// the aspect ratio worse, if QTKit selects a new source mode with a different |
-// shape. This constant ensures that we don't take this risk if the current |
+// shape. This constant ensures that we don't take this risk if the current |
// aspect ratio is tolerable. |
const float kMaxPixelAspectRatio = 1.15; |
@@ -63,29 +69,64 @@ void GetBestMatchSupportedResolution(int* width, int* height) { |
*height = matched_height; |
} |
+//static |
void VideoCaptureDevice::GetDeviceNames(Names* device_names) { |
// Loop through all available devices and add to |device_names|. |
device_names->clear(); |
NSDictionary* capture_devices; |
+ bool is_blacklisted_device = false; |
if (AVFoundationGlue::IsAVFoundationSupported()) { |
DVLOG(1) << "Enumerating video capture devices using AVFoundation"; |
capture_devices = [VideoCaptureDeviceAVFoundation deviceNames]; |
+ std::string device_vid; |
+ 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.
|
+ Name name([[capture_devices valueForKey:key] UTF8String], |
+ [key UTF8String], Name::AVFOUNDATION); |
+ device_names->push_back(name); |
+ device_vid = name.GetModel().substr(0, kVidPidSize); |
+ // 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
|
+ 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.
|
+ is_blacklisted_device |= (device_vid == kBlacklistedCameras[i].vid); |
+ 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
|
+ continue; |
+ } |
+ } |
} else { |
DVLOG(1) << "Enumerating video capture devices using QTKit"; |
capture_devices = [VideoCaptureDeviceQTKit deviceNames]; |
+ for (NSString* key in capture_devices) { |
+ Name name([[capture_devices valueForKey:key] UTF8String], |
+ [key UTF8String], Name::QTKIT); |
+ device_names->push_back(name); |
+ } |
} |
- for (NSString* key in capture_devices) { |
- Name name([[capture_devices valueForKey:key] UTF8String], |
- [key UTF8String]); |
- device_names->push_back(name); |
+ |
+ 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.
|
+ // Walk the QTKit device list and add those devices with a blacklisted name |
+ // to the |device_names|, with a "QTKit" prefix to distinguish them from the |
+ // AVFoundation ones. |
+ capture_devices = [VideoCaptureDeviceQTKit deviceNames]; |
+ NSString* device_name; |
+ for (NSString* key in capture_devices) { |
+ device_name = [capture_devices valueForKey:key]; |
+ for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) { |
+ if ([device_name rangeOfString:@(kBlacklistedCameras[i].name) |
+ options:NSCaseInsensitiveSearch].length != 0) { |
+ DVLOG(1) << "Enumerated blacklisted " << [device_name UTF8String]; |
+ 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
|
+ [key UTF8String], Name::QTKIT); |
+ device_names->push_back(name); |
+ } |
+ } |
+ } |
} |
} |
// static |
void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device, |
VideoCaptureFormats* formats) { |
- if (AVFoundationGlue::IsAVFoundationSupported()) { |
+ if (device.capture_api_type() == Name::AVFOUNDATION) { |
DVLOG(1) << "Enumerating video capture capabilities, AVFoundation"; |
[VideoCaptureDeviceAVFoundation getDevice:device |
supportedFormats:formats]; |
@@ -219,7 +260,8 @@ bool VideoCaptureDeviceMac::Init() { |
if (it == device_names.end()) |
return false; |
- if (AVFoundationGlue::IsAVFoundationSupported()) { |
+ DCHECK_NE(it->capture_api_type(), Name::API_TYPE_UNKNOWN); |
+ if (it->capture_api_type() == Name::AVFOUNDATION) { |
capture_device_ = |
[[VideoCaptureDeviceAVFoundation alloc] initWithFrameReceiver:this]; |
} else { |