| 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" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } // namespace | 103 } // namespace |
| 104 | 104 |
| 105 static base::LazyInstance<AVFoundationInternal> g_avfoundation_handle = | 105 static base::LazyInstance<AVFoundationInternal> g_avfoundation_handle = |
| 106 LAZY_INSTANCE_INITIALIZER; | 106 LAZY_INSTANCE_INITIALIZER; |
| 107 | 107 |
| 108 bool AVFoundationGlue::IsAVFoundationSupported() { | 108 bool AVFoundationGlue::IsAVFoundationSupported() { |
| 109 // DeviceMonitorMac will initialize this static bool from the main UI thread | 109 // DeviceMonitorMac will initialize this static bool from the main UI thread |
| 110 // once, during Chrome startup so this construction is thread safe. | 110 // once, during Chrome startup so this construction is thread safe. |
| 111 // Use AVFoundation if possible, enabled, and QTKit is not explicitly forced. | 111 // Use AVFoundation if possible, enabled, and QTKit is not explicitly forced. |
| 112 static CommandLine* command_line = CommandLine::ForCurrentProcess(); | 112 static CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 113 static bool is_av_foundation_supported = base::mac::IsOSLionOrLater() && | 113 |
| 114 ((command_line->HasSwitch(switches::kEnableAVFoundation) && | 114 // AVFoundation is only available on OS Lion and above. |
| 115 !command_line->HasSwitch(switches::kForceQTKit)) || | 115 if (!base::mac::IsOSLionOrLater()) |
| 116 return false; |
| 117 |
| 118 // The force-qtkit flag takes precedence over enable-avfoundation. |
| 119 if (command_line->HasSwitch(switches::kForceQTKit)) |
| 120 return false; |
| 121 |
| 122 // Next in precedence is the enable-avfoundation flag. |
| 123 // TODO(mcasas,vrk): There should be 3 states of AVFoundation: user forced on, |
| 124 // user forced off (i.e. force QTKit), and default (respect field trial). |
| 125 // crbug.com/396764 |
| 126 // TODO(vrk): Does this really need to be static? |
| 127 static bool should_enable_avfoundation = |
| 128 command_line->HasSwitch(switches::kEnableAVFoundation) || |
| 116 base::FieldTrialList::FindFullName("AVFoundationMacVideoCapture") | 129 base::FieldTrialList::FindFullName("AVFoundationMacVideoCapture") |
| 117 == "Enabled") && [AVFoundationBundle() load]; | 130 == "Enabled"; |
| 118 return is_av_foundation_supported; | 131 // Try to load AVFoundation. Save result in static bool to avoid loading |
| 132 // AVFoundationBundle every call. |
| 133 static bool loaded_successfully = [AVFoundationBundle() load]; |
| 134 return should_enable_avfoundation && loaded_successfully; |
| 119 } | 135 } |
| 120 | 136 |
| 121 NSBundle const* AVFoundationGlue::AVFoundationBundle() { | 137 NSBundle const* AVFoundationGlue::AVFoundationBundle() { |
| 122 return g_avfoundation_handle.Get().bundle(); | 138 return g_avfoundation_handle.Get().bundle(); |
| 123 } | 139 } |
| 124 | 140 |
| 125 void* AVFoundationGlue::AVFoundationLibraryHandle() { | 141 void* AVFoundationGlue::AVFoundationLibraryHandle() { |
| 126 return g_avfoundation_handle.Get().library_handle(); | 142 return g_avfoundation_handle.Get().library_handle(); |
| 127 } | 143 } |
| 128 | 144 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 @implementation AVCaptureDeviceInputGlue | 215 @implementation AVCaptureDeviceInputGlue |
| 200 | 216 |
| 201 + (CrAVCaptureDeviceInput*)deviceInputWithDevice:(CrAVCaptureDevice*)device | 217 + (CrAVCaptureDeviceInput*)deviceInputWithDevice:(CrAVCaptureDevice*)device |
| 202 error:(NSError**)outError { | 218 error:(NSError**)outError { |
| 203 return [[AVFoundationGlue::AVFoundationBundle() | 219 return [[AVFoundationGlue::AVFoundationBundle() |
| 204 classNamed:@"AVCaptureDeviceInput"] deviceInputWithDevice:device | 220 classNamed:@"AVCaptureDeviceInput"] deviceInputWithDevice:device |
| 205 error:outError]; | 221 error:outError]; |
| 206 } | 222 } |
| 207 | 223 |
| 208 @end // @implementation AVCaptureDeviceInputGlue | 224 @end // @implementation AVCaptureDeviceInputGlue |
| OLD | NEW |