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

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 addressed. 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() &&
13 [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 = [[AvFoundationBundle()
24 executablePath] fileSystemRepresentation];
25 if (library_path == NULL) {
26 DCHECK(false);
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 ReadNSStringPtr("AVCaptureDeviceWasConnectedNotification",
36 AvFoundationLibraryHandle());
37 }
38
39 NSString* AVFoundationGlue::AvCaptureDeviceWasDisconnectedNotification() {
40 return ReadNSStringPtr("AVCaptureDeviceWasDisconnectedNotification",
41 AvFoundationLibraryHandle());
42 }
43
44 NSString* AVFoundationGlue::AvMediaTypeVideo() {
45 return ReadNSStringPtr("AVMediaTypeVideo", AvFoundationLibraryHandle());
46 }
47
48 NSString* AVFoundationGlue::AvMediaTypeAudio() {
49 return ReadNSStringPtr("AVMediaTypeAudio", AvFoundationLibraryHandle());
50 }
51
52 NSString* AVFoundationGlue::AvMediaTypeMuxed() {
53 return ReadNSStringPtr("AVMediaTypeMuxed", AvFoundationLibraryHandle());
54 }
55
56 NSString* AVFoundationGlue::ReadNSStringPtr(char const* const symbol,
57 void* const handle) {
58 NSString** stringPointer = (NSString**)dlsym(handle, symbol);
59 DCHECK(stringPointer) << dlerror();
60 return *stringPointer;
61 }
62
63 @implementation AVCaptureDeviceGlue
64
65 + (NSArray*)devices {
66 Class avcClass =
67 [AVFoundationGlue::AvFoundationBundle() classNamed:@"AVCaptureDevice"];
68 SEL selectorDevices = NSSelectorFromString(@"devices");
69 if ([avcClass respondsToSelector:selectorDevices]) {
70 return [avcClass performSelector:selectorDevices];
71 }
72 return nil;
73 }
74
75 + (BOOL)hasMediaType:(NSString*)mediaType
76 forCaptureDevice:(CrAVCaptureDevice const*)device {
77 SEL selectorHasMediaType = NSSelectorFromString(@"hasMediaType:");
78 if ([device respondsToSelector:selectorHasMediaType]) {
79 return [device hasMediaType:mediaType];
80 }
81 return NO;
82 }
83
84 + (NSString*)uniqueID:(CrAVCaptureDevice const*)device {
85 SEL selectorUniqueID = NSSelectorFromString(@"uniqueID");
86 if ([device respondsToSelector:selectorUniqueID]) {
87 return [device uniqueID];
88 }
89 return nil;
90 }
91
92 @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