OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "media/video/capture/mac/avfoundation_glue.h" | 5 #import "media/video/capture/mac/avfoundation_glue.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #include "base/metrics/field_trial.h" | |
12 #include "media/base/media_switches.h" | 13 #include "media/base/media_switches.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // This class is used to retrieve AVFoundation NSBundle and library handle. It | 17 // This class is used to retrieve AVFoundation NSBundle and library handle. It |
17 // must be used as a LazyInstance so that it is initialised once and in a | 18 // must be used as a LazyInstance so that it is initialised once and in a |
18 // thread-safe way. Normally no work is done in constructors: LazyInstance is | 19 // thread-safe way. Normally no work is done in constructors: LazyInstance is |
19 // an exception. | 20 // an exception. |
20 class AVFoundationInternal { | 21 class AVFoundationInternal { |
21 public: | 22 public: |
(...skipping 24 matching lines...) Expand all Loading... | |
46 namespace media { | 47 namespace media { |
47 | 48 |
48 // TODO(mcasas):http://crbug.com/323536 cache the string pointers. | 49 // TODO(mcasas):http://crbug.com/323536 cache the string pointers. |
49 static NSString* ReadNSStringPtr(const char* symbol) { | 50 static NSString* ReadNSStringPtr(const char* symbol) { |
50 NSString** string_pointer = reinterpret_cast<NSString**>( | 51 NSString** string_pointer = reinterpret_cast<NSString**>( |
51 dlsym(AVFoundationGlue::AVFoundationLibraryHandle(), symbol)); | 52 dlsym(AVFoundationGlue::AVFoundationLibraryHandle(), symbol)); |
52 DCHECK(string_pointer) << dlerror(); | 53 DCHECK(string_pointer) << dlerror(); |
53 return *string_pointer; | 54 return *string_pointer; |
54 } | 55 } |
55 | 56 |
57 bool UseAVFoundationExperiment() { | |
58 const std::string group_name = | |
59 base::FieldTrialList::FindFullName("AVFoundationMacVideoCapture"); | |
60 return group_name == "Enabled"; | |
61 } | |
62 | |
56 } // namespace media | 63 } // namespace media |
57 | 64 |
58 bool AVFoundationGlue::IsAVFoundationSupported() { | 65 bool AVFoundationGlue::IsAVFoundationSupported() { |
59 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 66 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
60 return cmd_line->HasSwitch(switches::kEnableAVFoundation) && | 67 return (cmd_line->HasSwitch(switches::kEnableAVFoundation) || |
61 base::mac::IsOSLionOrLater() && [AVFoundationBundle() load]; | 68 media::UseAVFoundationExperiment()) && base::mac::IsOSLionOrLater() && |
Alexei Svitkine (slow)
2014/01/09 15:50:39
This is a bit tricky. One thing to understand is t
Alexei Svitkine (slow)
2014/01/09 15:56:20
Just to clarify, since I think I didn't give enoug
mcasas
2014/01/09 16:20:35
I think it makes sense: only use the experiment co
| |
69 [AVFoundationBundle() load]; | |
Alexei Svitkine (slow)
2014/01/09 15:50:39
Not super familiar with this code, but is it safe
mcasas
2014/01/09 16:20:35
NSBundle -load can be called safely several times
| |
62 } | 70 } |
63 | 71 |
64 NSBundle const* AVFoundationGlue::AVFoundationBundle() { | 72 NSBundle const* AVFoundationGlue::AVFoundationBundle() { |
65 return g_avfoundation_handle.Get().bundle(); | 73 return g_avfoundation_handle.Get().bundle(); |
66 } | 74 } |
67 | 75 |
68 void* AVFoundationGlue::AVFoundationLibraryHandle() { | 76 void* AVFoundationGlue::AVFoundationLibraryHandle() { |
69 return g_avfoundation_handle.Get().library_handle(); | 77 return g_avfoundation_handle.Get().library_handle(); |
70 } | 78 } |
71 | 79 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 @implementation AVCaptureDeviceInputGlue | 160 @implementation AVCaptureDeviceInputGlue |
153 | 161 |
154 + (CrAVCaptureDeviceInput*)deviceInputWithDevice:(CrAVCaptureDevice*)device | 162 + (CrAVCaptureDeviceInput*)deviceInputWithDevice:(CrAVCaptureDevice*)device |
155 error:(NSError**)outError { | 163 error:(NSError**)outError { |
156 return [[AVFoundationGlue::AVFoundationBundle() | 164 return [[AVFoundationGlue::AVFoundationBundle() |
157 classNamed:@"AVCaptureDeviceInput"] deviceInputWithDevice:device | 165 classNamed:@"AVCaptureDeviceInput"] deviceInputWithDevice:device |
158 error:outError]; | 166 error:outError]; |
159 } | 167 } |
160 | 168 |
161 @end // @implementation AVCaptureDeviceInputGlue | 169 @end // @implementation AVCaptureDeviceInputGlue |
OLD | NEW |