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

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

Issue 24615005: Added AVFoundation Glue and Device Monitoring for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments following avi@ ones. Created 7 years, 2 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
« no previous file with comments | « media/video/capture/mac/avfoundation_glue.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/video/capture/mac/avfoundation_glue.mm
diff --git a/media/video/capture/mac/avfoundation_glue.mm b/media/video/capture/mac/avfoundation_glue.mm
new file mode 100644
index 0000000000000000000000000000000000000000..65e3dc3f009bd181b6bb7ce756ae978f572e5eec
--- /dev/null
+++ b/media/video/capture/mac/avfoundation_glue.mm
@@ -0,0 +1,89 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "media/video/capture/mac/avfoundation_glue.h"
+
+#include <dlfcn.h>
+
+#include "base/mac/mac_util.h"
+
+bool AVFoundationGlue::IsAVFoundationSupported() {
+ return (base::mac::IsOSLionOrLater() && [AVFoundationBundle() load]);
+}
+
+NSBundle const* AVFoundationGlue::AVFoundationBundle() {
+ static NSBundle* bundle = [NSBundle
+ bundleWithPath:@"/System/Library/Frameworks/AVFoundation.framework"];
+ return bundle;
+}
+
+void* AVFoundationGlue::AVFoundationLibraryHandle() {
+ const char* library_path =
+ [[AVFoundationBundle() executablePath] fileSystemRepresentation];
+ if (library_path == NULL) {
+ DCHECK(false);
+ return NULL;
+ }
+ static void* library_handle = dlopen(library_path, RTLD_LAZY | RTLD_LOCAL);
+ DCHECK(library_handle) << dlerror();
+ return library_handle;
+}
+
+NSString* AVFoundationGlue::AVCaptureDeviceWasConnectedNotification() {
+ return ReadNSStringPtr("AVCaptureDeviceWasConnectedNotification");
+}
+
+NSString* AVFoundationGlue::AVCaptureDeviceWasDisconnectedNotification() {
+ return ReadNSStringPtr("AVCaptureDeviceWasDisconnectedNotification");
+}
+
+NSString* AVFoundationGlue::AVMediaTypeVideo() {
+ return ReadNSStringPtr("AVMediaTypeVideo");
+}
+
+NSString* AVFoundationGlue::AVMediaTypeAudio() {
+ return ReadNSStringPtr("AVMediaTypeAudio");
+}
+
+NSString* AVFoundationGlue::AVMediaTypeMuxed() {
+ return ReadNSStringPtr("AVMediaTypeMuxed");
+}
+
+NSString* AVFoundationGlue::ReadNSStringPtr(const char* symbol) {
+ NSString** string_pointer = reinterpret_cast<NSString**>(
+ dlsym(AVFoundationLibraryHandle(), symbol));
+ DCHECK(string_pointer) << dlerror();
+ return *string_pointer;
+}
+
+@implementation AVCaptureDeviceGlue
+
++ (NSArray*)devices {
+ Class avcClass =
+ [AVFoundationGlue::AVFoundationBundle() classNamed:@"AVCaptureDevice"];
+ SEL selectorDevices = NSSelectorFromString(@"devices");
+ if ([avcClass respondsToSelector:selectorDevices]) {
+ return [avcClass performSelector:selectorDevices];
+ }
+ return nil;
+}
+
++ (BOOL)hasMediaType:(NSString*)mediaType
+ forCaptureDevice:(CrAVCaptureDevice*)device {
+ SEL selectorHasMediaType = NSSelectorFromString(@"hasMediaType:");
+ if ([device respondsToSelector:selectorHasMediaType]) {
+ return [device hasMediaType:mediaType];
+ }
+ return NO;
+}
+
++ (NSString*)uniqueID:(CrAVCaptureDevice*)device {
+ SEL selectorUniqueID = NSSelectorFromString(@"uniqueID");
+ if ([device respondsToSelector:selectorUniqueID]) {
+ return [device uniqueID];
+ }
+ return nil;
+}
+
+@end // @implementation AVCaptureDevice
« no previous file with comments | « media/video/capture/mac/avfoundation_glue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698