| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "media/video/capture/mac/avfoundation_glue.h" |
| 6 |
| 7 #include <dlfcn.h> |
| 8 |
| 9 #include "base/mac/mac_util.h" |
| 10 |
| 11 @implementation AVFoundationGlue |
| 12 |
| 13 + (BOOL)isAVFoundationSupported { |
| 14 return (base::mac::IsOSLionOrLater() && |
| 15 [[AVFoundationGlue avFoundationBundle] load]); |
| 16 } |
| 17 |
| 18 + (NSBundle const*)avFoundationBundle { |
| 19 static NSBundle* bundle = [NSBundle |
| 20 bundleWithPath:@"/System/Library/Frameworks/AVFoundation.framework"]; |
| 21 return bundle; |
| 22 } |
| 23 |
| 24 + (void*)avFoundationLibraryHandle { |
| 25 static void* library_handle = dlopen([[[AVFoundationGlue avFoundationBundle] |
| 26 executablePath] fileSystemRepresentation], RTLD_LAZY | RTLD_LOCAL); |
| 27 DCHECK(library_handle) << dlerror(); |
| 28 return library_handle; |
| 29 } |
| 30 |
| 31 + (NSString* const)avCaptureDeviceWasConnectedNotification{ |
| 32 return [AVFoundationGlue readNSStringPtr: |
| 33 "AVCaptureDeviceWasConnectedNotification" |
| 34 fromLibrary:[AVFoundationGlue |
| 35 avFoundationLibraryHandle]]; |
| 36 } |
| 37 |
| 38 + (NSString* const)avCaptureDeviceWasDisconnectedNotification{ |
| 39 return [AVFoundationGlue readNSStringPtr: |
| 40 "AVCaptureDeviceWasDisconnectedNotification" |
| 41 fromLibrary:[AVFoundationGlue |
| 42 avFoundationLibraryHandle]]; |
| 43 } |
| 44 |
| 45 + (NSString* const)avMediaTypeVideo{ |
| 46 return [AVFoundationGlue readNSStringPtr:"AVMediaTypeVideo" |
| 47 fromLibrary:[AVFoundationGlue |
| 48 avFoundationLibraryHandle]]; |
| 49 } |
| 50 |
| 51 + (NSString* const)avMediaTypeAudio{ |
| 52 return [AVFoundationGlue readNSStringPtr:"AVMediaTypeAudio" |
| 53 fromLibrary:[AVFoundationGlue |
| 54 avFoundationLibraryHandle]]; |
| 55 } |
| 56 |
| 57 + (NSString* const)avMediaTypeMuxed{ |
| 58 return [AVFoundationGlue readNSStringPtr:"AVMediaTypeMuxed" |
| 59 fromLibrary:[AVFoundationGlue |
| 60 avFoundationLibraryHandle]]; |
| 61 } |
| 62 |
| 63 +(NSString* const)readNSStringPtr:(char const* const)symbol |
| 64 fromLibrary:(void* const)handle { |
| 65 NSString** stringPointer = (NSString**) dlsym(handle, symbol); |
| 66 DCHECK(stringPointer) << dlerror(); |
| 67 return *stringPointer; |
| 68 } |
| 69 |
| 70 @end // @implementation AVFoundationGlue |
| 71 |
| 72 |
| 73 @implementation AVCaptureDeviceGlue |
| 74 |
| 75 + (NSArray*)devices { |
| 76 Class avcClass = [[AVFoundationGlue avFoundationBundle] |
| 77 classNamed:@"AVCaptureDevice"]; |
| 78 SEL selectorDevices = NSSelectorFromString(@"devices"); |
| 79 if ([avcClass respondsToSelector:selectorDevices]){ |
| 80 return [avcClass performSelector:selectorDevices]; |
| 81 } |
| 82 return nil; |
| 83 } |
| 84 |
| 85 + (BOOL)hasMediaType:(NSString*)mediaType |
| 86 forCaptureDevice:(CrAVCaptureDevice const*)device { |
| 87 SEL selectorHasMediaType = NSSelectorFromString(@"hasMediaType:"); |
| 88 if ([device respondsToSelector:selectorHasMediaType]) { |
| 89 return [device hasMediaType:mediaType]; |
| 90 } |
| 91 return NO; |
| 92 } |
| 93 |
| 94 @end // @implementation AVCaptureDevice |
| OLD | NEW |