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..92627e77bff470ca50ca25eea85555b9612d60be |
| --- /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); |
|
DaleCurtis
2013/10/22 19:17:56
Presumably rsesek@ and mmentovai@ decided against
mcasas
2013/10/23 12:52:08
base::NativeLibrary uses CFBundle and we are using
|
| + 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(char const* const symbol) { |
|
DaleCurtis
2013/10/22 19:17:56
"const char* symbol" is normally how this is writt
mcasas
2013/10/23 12:52:08
"const char* symbol" would be a mutable-pointer po
|
| + NSString** stringPointer = reinterpret_cast<NSString**>( |
|
DaleCurtis
2013/10/22 19:17:56
string_pointer ?
mcasas
2013/10/23 12:52:08
Absolutely. Done.
|
| + dlsym(AVFoundationLibraryHandle(), 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*)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 |