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

Unified Diff: media/video/capture/mac/video_capture_device_mac.mm

Issue 265263004: Mac Video Capture Device: split VCD into VCD and Factory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: perkj@s suggestions and nits. 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 side-by-side diff with in-line comments
Download patch
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 bc3d54153c5bd355e01d6f18181546f8832d01e1..fe199d2a30434f808cd3586e19b0898e5c3d287d 100644
--- a/media/video/capture/mac/video_capture_device_mac.mm
+++ b/media/video/capture/mac/video_capture_device_mac.mm
@@ -22,14 +22,6 @@ const int kMaxFrameRate = 30;
// 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;
@@ -49,6 +41,27 @@ const struct Resolution* const kWellSupportedResolutions[] = {
// aspect ratio is tolerable.
const float kMaxPixelAspectRatio = 1.15;
+// TODO(mcasas): Remove the static methods implementations all platforms have
perkj_chrome 2014/05/06 18:26:00 nit: fix readable sentence.
mcasas 2014/05/07 07:49:12 Done.
+// splitted the VideoCaptureDevice into VideoCaptureDevice and
+// VideoCaptureDeviceFactory.
+
+// static
+VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
+ NOTREACHED();
+ return NULL;
+}
+// static
+void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
+ NOTREACHED();
+}
+
+// static
+void VideoCaptureDevice::GetDeviceSupportedFormats(
+ const Name& device,
+ VideoCaptureFormats* supported_formats) {
+ NOTREACHED();
+}
+
// TODO(ronghuawu): Replace this with CapabilityList::GetBestMatchedCapability.
void GetBestMatchSupportedResolution(int* width, int* height) {
int min_diff = kint32max;
@@ -69,72 +82,6 @@ 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|.
- 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* 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 {
// Both PID and VID are 4 characters.
if (unique_id_.size() < 2 * kVidPidSize) {
@@ -150,17 +97,6 @@ const std::string VideoCaptureDevice::Name::GetModel() const {
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),
@@ -244,25 +180,12 @@ void VideoCaptureDeviceMac::StopAndDeAllocate() {
tried_to_square_pixels_ = false;
}
-bool VideoCaptureDeviceMac::Init() {
+bool VideoCaptureDeviceMac::Init(
+ VideoCaptureDevice::Name::CaptureApiType capture_api_type) {
DCHECK(task_runner_->BelongsToCurrentThread());
DCHECK_EQ(state_, kNotInitialized);
- // 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) {
+ if (capture_api_type == Name::AVFOUNDATION) {
capture_device_ =
[[VideoCaptureDeviceAVFoundation alloc] initWithFrameReceiver:this];
} else {

Powered by Google App Engine
This is Rietveld 408576698