| Index: media/video/capture/mac/video_capture_device_mac.mm
|
| ===================================================================
|
| --- media/video/capture/mac/video_capture_device_mac.mm (revision 269380)
|
| +++ media/video/capture/mac/video_capture_device_mac.mm (working copy)
|
| @@ -22,6 +22,14 @@
|
| // In device identifiers, the USB VID and PID are stored in 4 bytes each.
|
| const size_t kVidPidSize = 4;
|
|
|
| +// 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;
|
| @@ -61,26 +69,70 @@
|
| *height = matched_height;
|
| }
|
|
|
| -// TODO(mcasas): Remove the following static methods when they are no longer
|
| -// referenced from VideoCaptureDeviceFactory, i.e. when all OS platforms have
|
| -// splitted the VideoCaptureDevice into VideoCaptureDevice and
|
| -// VideoCaptureDeviceFactory.
|
| -
|
| -// static
|
| -VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
|
| - NOTREACHED();
|
| - return NULL;
|
| -}
|
| -// static
|
| +//static
|
| void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
|
| - NOTREACHED();
|
| + // Loop through all available devices and add to |device_names|.
|
| + NSDictionary* capture_devices;
|
| + if (AVFoundationGlue::IsAVFoundationSupported()) {
|
| + bool is_any_device_blacklisted = false;
|
| + DVLOG(1) << "Enumerating video capture devices using AVFoundation";
|
| + capture_devices = [VideoCaptureDeviceAVFoundation deviceNames];
|
| + std::string device_vid;
|
| + // Enumerate all devices found by AVFoundation, translate the info for each
|
| + // to class Name and add it to |device_names|.
|
| + for (NSString* key in capture_devices) {
|
| + Name name([[capture_devices valueForKey:key] UTF8String],
|
| + [key UTF8String], Name::AVFOUNDATION);
|
| + device_names->push_back(name);
|
| + // Extract the device's Vendor ID and compare to all blacklisted ones.
|
| + device_vid = name.GetModel().substr(0, kVidPidSize);
|
| + for (size_t i = 0; i < arraysize(kBlacklistedCameras); ++i) {
|
| + is_any_device_blacklisted |=
|
| + !strcasecmp(device_vid.c_str(), kBlacklistedCameras[i].vid);
|
| + if (is_any_device_blacklisted)
|
| + break;
|
| + }
|
| + }
|
| + // If there is any device blacklisted in the system, walk the QTKit device
|
| + // list and add those devices with a blacklisted name to the |device_names|.
|
| + // AVFoundation and QTKit device lists partially overlap, so add a "QTKit"
|
| + // prefix to the latter ones to distinguish them from the AVFoundation ones.
|
| + if (is_any_device_blacklisted) {
|
| + capture_devices = [VideoCaptureDeviceQTKit deviceNames];
|
| + for (NSString* key in capture_devices) {
|
| + NSString* 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]),
|
| + [key UTF8String], Name::QTKIT);
|
| + device_names->push_back(name);
|
| + }
|
| + }
|
| + }
|
| + }
|
| + } 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);
|
| + }
|
| + }
|
| }
|
|
|
| // static
|
| -void VideoCaptureDevice::GetDeviceSupportedFormats(
|
| - const Name& device,
|
| - VideoCaptureFormats* supported_formats) {
|
| - NOTREACHED();
|
| +void VideoCaptureDevice::GetDeviceSupportedFormats(const Name& device,
|
| + VideoCaptureFormats* formats) {
|
| + if (device.capture_api_type() == Name::AVFOUNDATION) {
|
| + DVLOG(1) << "Enumerating video capture capabilities, AVFoundation";
|
| + [VideoCaptureDeviceAVFoundation getDevice:device
|
| + supportedFormats:formats];
|
| + } else {
|
| + NOTIMPLEMENTED();
|
| + }
|
| }
|
|
|
| const std::string VideoCaptureDevice::Name::GetModel() const {
|
| @@ -98,6 +150,17 @@
|
| return id_vendor + ":" + id_product;
|
| }
|
|
|
| +VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
|
| + VideoCaptureDeviceMac* capture_device =
|
| + new VideoCaptureDeviceMac(device_name);
|
| + if (!capture_device->Init()) {
|
| + LOG(ERROR) << "Could not initialize VideoCaptureDevice.";
|
| + delete capture_device;
|
| + capture_device = NULL;
|
| + }
|
| + return capture_device;
|
| +}
|
| +
|
| VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name)
|
| : device_name_(device_name),
|
| tried_to_square_pixels_(false),
|
| @@ -181,12 +244,25 @@
|
| tried_to_square_pixels_ = false;
|
| }
|
|
|
| -bool VideoCaptureDeviceMac::Init(
|
| - VideoCaptureDevice::Name::CaptureApiType capture_api_type) {
|
| +bool VideoCaptureDeviceMac::Init() {
|
| DCHECK(task_runner_->BelongsToCurrentThread());
|
| DCHECK_EQ(state_, kNotInitialized);
|
|
|
| - if (capture_api_type == Name::AVFOUNDATION) {
|
| + // TODO(mcasas): The following check might not be necessary; if the device has
|
| + // disappeared after enumeration and before coming here, opening would just
|
| + // fail but not necessarily produce a crash.
|
| + Names device_names;
|
| + GetDeviceNames(&device_names);
|
| + Names::iterator it = device_names.begin();
|
| + for (; it != device_names.end(); ++it) {
|
| + if (it->id() == device_name_.id())
|
| + break;
|
| + }
|
| + if (it == device_names.end())
|
| + return false;
|
| +
|
| + DCHECK_NE(it->capture_api_type(), Name::API_TYPE_UNKNOWN);
|
| + if (it->capture_api_type() == Name::AVFOUNDATION) {
|
| capture_device_ =
|
| [[VideoCaptureDeviceAVFoundation alloc] initWithFrameReceiver:this];
|
| } else {
|
|
|