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

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: 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 @implementation AVFoundationGlue
Mark Mentovai 2013/10/09 16:05:12 I’m not sure that there’s any benefit to this clas
mcasas 2013/10/12 09:59:27 Done --second option: Class with static methods an
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);
Mark Mentovai 2013/10/09 16:05:12 Not cool to pass NULL to dlopen in case any of the
mcasas 2013/10/12 09:59:27 Separated, if NULL then DCHECK(FALSE) and return N
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
Mark Mentovai 2013/10/09 16:05:12 Space after +.
mcasas 2013/10/12 09:59:27 Done.
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
Mark Mentovai 2013/10/09 16:05:12 On the other hand, this “glue” class makes perfect
mcasas 2013/10/12 09:59:27 Ack!
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 + (NSString*)uniqueID:(CrAVCaptureDevice const*)device {
95 SEL selectorUniqueID = NSSelectorFromString(@"uniqueID");
96 if ([device respondsToSelector:selectorUniqueID]) {
97 return [device uniqueID];
98 }
99 return nil;
100 }
101
102 @end // @implementation AVCaptureDevice
OLDNEW
« content/browser/device_monitor_mac.mm ('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