| 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..9a61e8918e653de722f7beef4a6dab121e763374
|
| --- /dev/null
|
| +++ b/media/video/capture/mac/avfoundation_glue.mm
|
| @@ -0,0 +1,94 @@
|
| +// 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
|
| +
|
| ++ (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);
|
| + 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
|
| + fromLibrary:(void* const)handle {
|
| + NSString** stringPointer = (NSString**) dlsym(handle, symbol);
|
| + DCHECK(stringPointer) << dlerror();
|
| + return *stringPointer;
|
| +}
|
| +
|
| +@end // @implementation AVFoundationGlue
|
| +
|
| +
|
| +@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;
|
| +}
|
| +
|
| +@end // @implementation AVCaptureDevice
|
|
|