Chromium Code Reviews| 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..bd270672b74d42f36eeccbabb9d8f01e1bfc1447 |
| --- /dev/null |
| +++ b/media/video/capture/mac/avfoundation_glue.mm |
| @@ -0,0 +1,97 @@ |
| +// 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() && |
| + [AVFoundationGlue::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 = [[AVFoundationGlue::avFoundationBundle() |
|
Robert Sesek
2013/10/14 17:26:44
You shouldn't need |AVFoundationGlue::| since you'
mcasas
2013/10/15 11:50:11
Done.
|
| + executablePath] fileSystemRepresentation]; |
| + if (library_path == NULL) { |
| + DCHECK(FALSE); |
|
Robert Sesek
2013/10/14 17:26:44
FALSE -> false
mcasas
2013/10/15 11:50:11
Done.
|
| + return NULL; |
| + } |
| + static void* library_handle = dlopen(library_path, RTLD_LAZY | RTLD_LOCAL); |
| + DCHECK(library_handle) << dlerror(); |
| + return library_handle; |
| +} |
| + |
| +NSString* AVFoundationGlue::avCaptureDeviceWasConnectedNotification() { |
| + return AVFoundationGlue::readNSStringPtr( |
| + "AVCaptureDeviceWasConnectedNotification", |
| + AVFoundationGlue::avFoundationLibraryHandle()); |
| +} |
| + |
| +NSString* AVFoundationGlue::avCaptureDeviceWasDisconnectedNotification() { |
| + return AVFoundationGlue::readNSStringPtr( |
| + "AVCaptureDeviceWasDisconnectedNotification", |
| + AVFoundationGlue::avFoundationLibraryHandle()); |
| +} |
| + |
| +NSString* AVFoundationGlue::avMediaTypeVideo() { |
| + return AVFoundationGlue::readNSStringPtr( |
| + "AVMediaTypeVideo", AVFoundationGlue::avFoundationLibraryHandle()); |
| +} |
| + |
| +NSString* AVFoundationGlue::avMediaTypeAudio() { |
| + return AVFoundationGlue::readNSStringPtr( |
| + "AVMediaTypeAudio", AVFoundationGlue::avFoundationLibraryHandle()); |
| +} |
| + |
| +NSString* AVFoundationGlue::avMediaTypeMuxed() { |
| + return AVFoundationGlue::readNSStringPtr( |
| + "AVMediaTypeMuxed", AVFoundationGlue::avFoundationLibraryHandle()); |
| +} |
| + |
| +NSString* AVFoundationGlue::readNSStringPtr(char const* const symbol, |
| + void* const handle) { |
| + NSString** stringPointer = (NSString**)dlsym(handle, symbol); |
| + DCHECK(stringPointer) << dlerror(); |
| + return *stringPointer; |
| +} |
| + |
| +@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 const*)device { |
| + SEL selectorHasMediaType = NSSelectorFromString(@"hasMediaType:"); |
| + if ([device respondsToSelector:selectorHasMediaType]) { |
| + return [device hasMediaType:mediaType]; |
| + } |
| + return NO; |
| +} |
| + |
| ++ (NSString*)uniqueID:(CrAVCaptureDevice const*)device { |
| + SEL selectorUniqueID = NSSelectorFromString(@"uniqueID"); |
| + if ([device respondsToSelector:selectorUniqueID]) { |
| + return [device uniqueID]; |
| + } |
| + return nil; |
| +} |
| + |
| +@end // @implementation AVCaptureDevice |