Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: media/video/capture/mac/avfoundation_glue.mm

Issue 24615005: Added AVFoundation Glue and Device Monitoring for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rsesek@'s comments and some nits. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 AvFoundationLibraryHandle());
36 }
37
38 NSString* AVFoundationGlue::AvCaptureDeviceWasDisconnectedNotification() {
39 return ReadNSStringPtr("AVCaptureDeviceWasDisconnectedNotification",
40 AvFoundationLibraryHandle());
41 }
42
43 NSString* AVFoundationGlue::AvMediaTypeVideo() {
44 return ReadNSStringPtr("AVMediaTypeVideo", AvFoundationLibraryHandle());
45 }
46
47 NSString* AVFoundationGlue::AvMediaTypeAudio() {
48 return ReadNSStringPtr("AVMediaTypeAudio", AvFoundationLibraryHandle());
49 }
50
51 NSString* AVFoundationGlue::AvMediaTypeMuxed() {
52 return ReadNSStringPtr("AVMediaTypeMuxed", AvFoundationLibraryHandle());
53 }
54
55 NSString* AVFoundationGlue::ReadNSStringPtr(char const* const symbol,
56 void* const handle) {
57 NSString** stringPointer = (NSString**)dlsym(handle, symbol);
58 DCHECK(stringPointer) << dlerror();
59 return *stringPointer;
60 }
61
62 @implementation AVCaptureDeviceGlue
63
64 + (NSArray*)devices {
65 Class avcClass =
66 [AVFoundationGlue::AvFoundationBundle() classNamed:@"AVCaptureDevice"];
67 SEL selectorDevices = NSSelectorFromString(@"devices");
68 if ([avcClass respondsToSelector:selectorDevices]) {
69 return [avcClass performSelector:selectorDevices];
70 }
71 return nil;
72 }
73
74 + (BOOL)hasMediaType:(NSString*)mediaType
75 forCaptureDevice:(CrAVCaptureDevice*)device {
76 SEL selectorHasMediaType = NSSelectorFromString(@"hasMediaType:");
77 if ([device respondsToSelector:selectorHasMediaType]) {
78 return [device hasMediaType:mediaType];
79 }
80 return NO;
81 }
82
83 + (NSString*)uniqueID:(CrAVCaptureDevice*)device {
84 SEL selectorUniqueID = NSSelectorFromString(@"uniqueID");
85 if ([device respondsToSelector:selectorUniqueID]) {
86 return [device uniqueID];
87 }
88 return nil;
89 }
90
91 @end // @implementation AVCaptureDevice
OLDNEW
« media/video/capture/mac/avfoundation_glue.h ('K') | « media/video/capture/mac/avfoundation_glue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698