| 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 bool AVFoundationGlue::IsAVFoundationSupported() { |
| 12 return (base::mac::IsOSLionOrLater() && [AVFoundationBundle() load]); |
| 13 } |
| 14 |
| 15 NSBundle const* AVFoundationGlue::AVFoundationBundle() { |
| 16 static NSBundle* bundle = [NSBundle |
| 17 bundleWithPath:@"/System/Library/Frameworks/AVFoundation.framework"]; |
| 18 return bundle; |
| 19 } |
| 20 |
| 21 void* AVFoundationGlue::AVFoundationLibraryHandle() { |
| 22 const char* library_path = |
| 23 [[AVFoundationBundle() executablePath] fileSystemRepresentation]; |
| 24 if (library_path == NULL) { |
| 25 DCHECK(false); |
| 26 return NULL; |
| 27 } |
| 28 static void* library_handle = dlopen(library_path, RTLD_LAZY | RTLD_LOCAL); |
| 29 DCHECK(library_handle) << dlerror(); |
| 30 return library_handle; |
| 31 } |
| 32 |
| 33 NSString* AVFoundationGlue::AVCaptureDeviceWasConnectedNotification() { |
| 34 return ReadNSStringPtr("AVCaptureDeviceWasConnectedNotification"); |
| 35 } |
| 36 |
| 37 NSString* AVFoundationGlue::AVCaptureDeviceWasDisconnectedNotification() { |
| 38 return ReadNSStringPtr("AVCaptureDeviceWasDisconnectedNotification"); |
| 39 } |
| 40 |
| 41 NSString* AVFoundationGlue::AVMediaTypeVideo() { |
| 42 return ReadNSStringPtr("AVMediaTypeVideo"); |
| 43 } |
| 44 |
| 45 NSString* AVFoundationGlue::AVMediaTypeAudio() { |
| 46 return ReadNSStringPtr("AVMediaTypeAudio"); |
| 47 } |
| 48 |
| 49 NSString* AVFoundationGlue::AVMediaTypeMuxed() { |
| 50 return ReadNSStringPtr("AVMediaTypeMuxed"); |
| 51 } |
| 52 |
| 53 NSString* AVFoundationGlue::ReadNSStringPtr(const char* symbol) { |
| 54 NSString** string_pointer = reinterpret_cast<NSString**>( |
| 55 dlsym(AVFoundationLibraryHandle(), symbol)); |
| 56 DCHECK(string_pointer) << dlerror(); |
| 57 return *string_pointer; |
| 58 } |
| 59 |
| 60 @implementation AVCaptureDeviceGlue |
| 61 |
| 62 + (NSArray*)devices { |
| 63 Class avcClass = |
| 64 [AVFoundationGlue::AVFoundationBundle() classNamed:@"AVCaptureDevice"]; |
| 65 SEL selectorDevices = NSSelectorFromString(@"devices"); |
| 66 if ([avcClass respondsToSelector:selectorDevices]) { |
| 67 return [avcClass performSelector:selectorDevices]; |
| 68 } |
| 69 return nil; |
| 70 } |
| 71 |
| 72 + (BOOL)hasMediaType:(NSString*)mediaType |
| 73 forCaptureDevice:(CrAVCaptureDevice*)device { |
| 74 SEL selectorHasMediaType = NSSelectorFromString(@"hasMediaType:"); |
| 75 if ([device respondsToSelector:selectorHasMediaType]) { |
| 76 return [device hasMediaType:mediaType]; |
| 77 } |
| 78 return NO; |
| 79 } |
| 80 |
| 81 + (NSString*)uniqueID:(CrAVCaptureDevice*)device { |
| 82 SEL selectorUniqueID = NSSelectorFromString(@"uniqueID"); |
| 83 if ([device respondsToSelector:selectorUniqueID]) { |
| 84 return [device uniqueID]; |
| 85 } |
| 86 return nil; |
| 87 } |
| 88 |
| 89 @end // @implementation AVCaptureDevice |
| OLD | NEW |