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..ca4ec63d57b837f1506c3ccf934c766dde0a9a69 |
| --- /dev/null |
| +++ b/media/video/capture/mac/avfoundation_glue.mm |
| @@ -0,0 +1,102 @@ |
| +// 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" |
| + |
| +@implementation AVFoundationGlue |
|
Mark Mentovai
2013/10/09 16:05:12
I’m not sure that there’s any benefit to this clas
mcasas
2013/10/12 09:59:27
Done --second option: Class with static methods an
|
| + |
| ++ (BOOL)isAVFoundationSupported { |
| + return (base::mac::IsOSLionOrLater() && |
| + [[AVFoundationGlue avFoundationBundle] load]); |
| +} |
| + |
| ++ (NSBundle const*)avFoundationBundle { |
| + static NSBundle* bundle = [NSBundle |
| + bundleWithPath:@"/System/Library/Frameworks/AVFoundation.framework"]; |
| + return bundle; |
| +} |
| + |
| ++ (void*)avFoundationLibraryHandle { |
| + static void* library_handle = dlopen([[[AVFoundationGlue avFoundationBundle] |
| + executablePath] fileSystemRepresentation], RTLD_LAZY | RTLD_LOCAL); |
|
Mark Mentovai
2013/10/09 16:05:12
Not cool to pass NULL to dlopen in case any of the
mcasas
2013/10/12 09:59:27
Separated, if NULL then DCHECK(FALSE) and return N
|
| + DCHECK(library_handle) << dlerror(); |
| + return library_handle; |
| +} |
| + |
| ++ (NSString* const)avCaptureDeviceWasConnectedNotification{ |
| + return [AVFoundationGlue readNSStringPtr: |
| + "AVCaptureDeviceWasConnectedNotification" |
| + fromLibrary:[AVFoundationGlue |
| + avFoundationLibraryHandle]]; |
| +} |
| + |
| ++ (NSString* const)avCaptureDeviceWasDisconnectedNotification{ |
| + return [AVFoundationGlue readNSStringPtr: |
| + "AVCaptureDeviceWasDisconnectedNotification" |
| + fromLibrary:[AVFoundationGlue |
| + avFoundationLibraryHandle]]; |
| +} |
| + |
| ++ (NSString* const)avMediaTypeVideo{ |
| + return [AVFoundationGlue readNSStringPtr:"AVMediaTypeVideo" |
| + fromLibrary:[AVFoundationGlue |
| + avFoundationLibraryHandle]]; |
| +} |
| + |
| ++ (NSString* const)avMediaTypeAudio{ |
| + return [AVFoundationGlue readNSStringPtr:"AVMediaTypeAudio" |
| + fromLibrary:[AVFoundationGlue |
| + avFoundationLibraryHandle]]; |
| +} |
| + |
| ++ (NSString* const)avMediaTypeMuxed{ |
| + return [AVFoundationGlue readNSStringPtr:"AVMediaTypeMuxed" |
| + fromLibrary:[AVFoundationGlue |
| + avFoundationLibraryHandle]]; |
| +} |
| + |
| ++(NSString* const)readNSStringPtr:(char const* const)symbol |
|
Mark Mentovai
2013/10/09 16:05:12
Space after +.
mcasas
2013/10/12 09:59:27
Done.
|
| + fromLibrary:(void* const)handle { |
| + NSString** stringPointer = (NSString**) dlsym(handle, symbol); |
| + DCHECK(stringPointer) << dlerror(); |
| + return *stringPointer; |
| +} |
| + |
| +@end // @implementation AVFoundationGlue |
| + |
| + |
| +@implementation AVCaptureDeviceGlue |
|
Mark Mentovai
2013/10/09 16:05:12
On the other hand, this “glue” class makes perfect
mcasas
2013/10/12 09:59:27
Ack!
|
| + |
| ++ (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 |