Chromium Code Reviews| 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() && | |
| 13 [AVFoundationGlue::avFoundationBundle() load]); | |
| 14 } | |
| 15 | |
| 16 NSBundle const* AVFoundationGlue::avFoundationBundle() { | |
| 17 static NSBundle* bundle = [NSBundle | |
| 18 bundleWithPath:@"/System/Library/Frameworks/AVFoundation.framework"]; | |
| 19 return bundle; | |
| 20 } | |
| 21 | |
| 22 void* AVFoundationGlue::avFoundationLibraryHandle() { | |
| 23 const char* library_path = [[AVFoundationGlue::avFoundationBundle() | |
|
Robert Sesek
2013/10/14 17:26:44
You shouldn't need |AVFoundationGlue::| since you'
mcasas
2013/10/15 11:50:11
Done.
| |
| 24 executablePath] fileSystemRepresentation]; | |
| 25 if (library_path == NULL) { | |
| 26 DCHECK(FALSE); | |
|
Robert Sesek
2013/10/14 17:26:44
FALSE -> false
mcasas
2013/10/15 11:50:11
Done.
| |
| 27 return NULL; | |
| 28 } | |
| 29 static void* library_handle = dlopen(library_path, RTLD_LAZY | RTLD_LOCAL); | |
| 30 DCHECK(library_handle) << dlerror(); | |
| 31 return library_handle; | |
| 32 } | |
| 33 | |
| 34 NSString* AVFoundationGlue::avCaptureDeviceWasConnectedNotification() { | |
| 35 return AVFoundationGlue::readNSStringPtr( | |
| 36 "AVCaptureDeviceWasConnectedNotification", | |
| 37 AVFoundationGlue::avFoundationLibraryHandle()); | |
| 38 } | |
| 39 | |
| 40 NSString* AVFoundationGlue::avCaptureDeviceWasDisconnectedNotification() { | |
| 41 return AVFoundationGlue::readNSStringPtr( | |
| 42 "AVCaptureDeviceWasDisconnectedNotification", | |
| 43 AVFoundationGlue::avFoundationLibraryHandle()); | |
| 44 } | |
| 45 | |
| 46 NSString* AVFoundationGlue::avMediaTypeVideo() { | |
| 47 return AVFoundationGlue::readNSStringPtr( | |
| 48 "AVMediaTypeVideo", AVFoundationGlue::avFoundationLibraryHandle()); | |
| 49 } | |
| 50 | |
| 51 NSString* AVFoundationGlue::avMediaTypeAudio() { | |
| 52 return AVFoundationGlue::readNSStringPtr( | |
| 53 "AVMediaTypeAudio", AVFoundationGlue::avFoundationLibraryHandle()); | |
| 54 } | |
| 55 | |
| 56 NSString* AVFoundationGlue::avMediaTypeMuxed() { | |
| 57 return AVFoundationGlue::readNSStringPtr( | |
| 58 "AVMediaTypeMuxed", AVFoundationGlue::avFoundationLibraryHandle()); | |
| 59 } | |
| 60 | |
| 61 NSString* AVFoundationGlue::readNSStringPtr(char const* const symbol, | |
| 62 void* const handle) { | |
| 63 NSString** stringPointer = (NSString**)dlsym(handle, symbol); | |
| 64 DCHECK(stringPointer) << dlerror(); | |
| 65 return *stringPointer; | |
| 66 } | |
| 67 | |
| 68 @implementation AVCaptureDeviceGlue | |
| 69 | |
| 70 + (NSArray*)devices { | |
| 71 Class avcClass = | |
| 72 [AVFoundationGlue::avFoundationBundle() classNamed:@"AVCaptureDevice"]; | |
| 73 SEL selectorDevices = NSSelectorFromString(@"devices"); | |
| 74 if ([avcClass respondsToSelector:selectorDevices]) { | |
| 75 return [avcClass performSelector:selectorDevices]; | |
| 76 } | |
| 77 return nil; | |
| 78 } | |
| 79 | |
| 80 + (BOOL)hasMediaType:(NSString*)mediaType | |
| 81 forCaptureDevice:(CrAVCaptureDevice const*)device { | |
| 82 SEL selectorHasMediaType = NSSelectorFromString(@"hasMediaType:"); | |
| 83 if ([device respondsToSelector:selectorHasMediaType]) { | |
| 84 return [device hasMediaType:mediaType]; | |
| 85 } | |
| 86 return NO; | |
| 87 } | |
| 88 | |
| 89 + (NSString*)uniqueID:(CrAVCaptureDevice const*)device { | |
| 90 SEL selectorUniqueID = NSSelectorFromString(@"uniqueID"); | |
| 91 if ([device respondsToSelector:selectorUniqueID]) { | |
| 92 return [device uniqueID]; | |
| 93 } | |
| 94 return nil; | |
| 95 } | |
| 96 | |
| 97 @end // @implementation AVCaptureDevice | |
| OLD | NEW |