| 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/base/mac/avfoundation_glue.h" | 5 #import "media/base/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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 NSString* AVCaptureSessionDidStopRunningNotification_; | 112 NSString* AVCaptureSessionDidStopRunningNotification_; |
| 113 NSString* AVCaptureSessionErrorKey_; | 113 NSString* AVCaptureSessionErrorKey_; |
| 114 NSString* AVVideoScalingModeKey_; | 114 NSString* AVVideoScalingModeKey_; |
| 115 NSString* AVVideoScalingModeResizeAspectFill_; | 115 NSString* AVVideoScalingModeResizeAspectFill_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(AVFoundationInternal); | 117 DISALLOW_COPY_AND_ASSIGN(AVFoundationInternal); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 // This contains the logic of checking whether AVFoundation is supported. | 120 // This contains the logic of checking whether AVFoundation is supported. |
| 121 // It's called only once and the results are cached in a static bool. | 121 // It's called only once and the results are cached in a static bool. |
| 122 bool IsAVFoundationSupportedHelper() { | 122 bool LoadAVFoundationInternal() { |
| 123 // AVFoundation is only available on OS Lion and above. | 123 // AVFoundation is only available on OS Lion and above. |
| 124 if (!base::mac::IsOSLionOrLater()) { | 124 if (!base::mac::IsOSLionOrLater()) { |
| 125 LogCaptureApi(CAPTURE_API_QTKIT_DUE_TO_OS_PREVIOUS_TO_LION); | 125 LogCaptureApi(CAPTURE_API_QTKIT_DUE_TO_OS_PREVIOUS_TO_LION); |
| 126 return false; | 126 return false; |
| 127 } | 127 } |
| 128 | 128 |
| 129 const base::CommandLine* command_line = | 129 const base::CommandLine* command_line = |
| 130 base::CommandLine::ForCurrentProcess(); | 130 base::CommandLine::ForCurrentProcess(); |
| 131 // The force-qtkit flag takes precedence over enable-avfoundation. | 131 // The force-qtkit flag takes precedence over enable-avfoundation. |
| 132 if (command_line->HasSwitch(switches::kForceQTKit)) { | 132 if (command_line->HasSwitch(switches::kForceQTKit)) { |
| 133 LogCaptureApi(CAPTURE_API_QTKIT_FORCED_BY_FLAG); | 133 LogCaptureApi(CAPTURE_API_QTKIT_FORCED_BY_FLAG); |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 if (!command_line->HasSwitch(switches::kEnableAVFoundation)) { | 137 if (!command_line->HasSwitch(switches::kEnableAVFoundation)) { |
| 138 LogCaptureApi(CAPTURE_API_QTKIT_DUE_TO_NO_FLAG); | 138 LogCaptureApi(CAPTURE_API_QTKIT_DUE_TO_NO_FLAG); |
| 139 return false; | 139 return false; |
| 140 } | 140 } |
| 141 const bool ret = [AVFoundationGlue::AVFoundationBundle() load]; | 141 const bool ret = [AVFoundationGlue::AVFoundationBundle() load]; |
| 142 LogCaptureApi(ret ? CAPTURE_API_AVFOUNDATION_LOADED_OK | 142 LogCaptureApi(ret ? CAPTURE_API_AVFOUNDATION_LOADED_OK |
| 143 : CAPTURE_API_QTKIT_DUE_TO_AVFOUNDATION_LOAD_ERROR); | 143 : CAPTURE_API_QTKIT_DUE_TO_AVFOUNDATION_LOAD_ERROR); |
| 144 return ret; | 144 return ret; |
| 145 } | 145 } |
| 146 | 146 |
| 147 } // namespace | 147 } // namespace |
| 148 | 148 |
| 149 static base::LazyInstance<AVFoundationInternal>::Leaky g_avfoundation_handle = | 149 static base::LazyInstance<AVFoundationInternal>::Leaky g_avfoundation_handle = |
| 150 LAZY_INSTANCE_INITIALIZER; | 150 LAZY_INSTANCE_INITIALIZER; |
| 151 | 151 |
| 152 enum { |
| 153 INITIALIZE_NOT_CALLED = 0, |
| 154 AVFOUNDATION_IS_SUPPORTED, |
| 155 AVFOUNDATION_NOT_SUPPORTED |
| 156 } static g_avfoundation_initialization = INITIALIZE_NOT_CALLED; |
| 157 |
| 158 void AVFoundationGlue::InitializeAVFoundation() { |
| 159 CHECK([NSThread isMainThread]); |
| 160 if (g_avfoundation_initialization != INITIALIZE_NOT_CALLED) |
| 161 return; |
| 162 g_avfoundation_initialization = LoadAVFoundationInternal() ? |
| 163 AVFOUNDATION_IS_SUPPORTED : AVFOUNDATION_NOT_SUPPORTED; |
| 164 } |
| 165 |
| 152 bool AVFoundationGlue::IsAVFoundationSupported() { | 166 bool AVFoundationGlue::IsAVFoundationSupported() { |
| 153 // DeviceMonitorMac will initialize this static bool from the main UI thread | 167 CHECK_NE(g_avfoundation_initialization, INITIALIZE_NOT_CALLED); |
| 154 // once, during Chrome startup so this construction is thread safe. | 168 return g_avfoundation_initialization == AVFOUNDATION_IS_SUPPORTED; |
| 155 static const bool is_supported = IsAVFoundationSupportedHelper(); | |
| 156 return is_supported; | |
| 157 } | 169 } |
| 158 | 170 |
| 159 NSBundle const* AVFoundationGlue::AVFoundationBundle() { | 171 NSBundle const* AVFoundationGlue::AVFoundationBundle() { |
| 160 return g_avfoundation_handle.Get().bundle(); | 172 return g_avfoundation_handle.Get().bundle(); |
| 161 } | 173 } |
| 162 | 174 |
| 163 NSString* AVFoundationGlue::AVCaptureDeviceWasConnectedNotification() { | 175 NSString* AVFoundationGlue::AVCaptureDeviceWasConnectedNotification() { |
| 164 return g_avfoundation_handle.Get().AVCaptureDeviceWasConnectedNotification(); | 176 return g_avfoundation_handle.Get().AVCaptureDeviceWasConnectedNotification(); |
| 165 } | 177 } |
| 166 | 178 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 @implementation AVCaptureDeviceInputGlue | 245 @implementation AVCaptureDeviceInputGlue |
| 234 | 246 |
| 235 + (CrAVCaptureDeviceInput*)deviceInputWithDevice:(CrAVCaptureDevice*)device | 247 + (CrAVCaptureDeviceInput*)deviceInputWithDevice:(CrAVCaptureDevice*)device |
| 236 error:(NSError**)outError { | 248 error:(NSError**)outError { |
| 237 return [[AVFoundationGlue::AVFoundationBundle() | 249 return [[AVFoundationGlue::AVFoundationBundle() |
| 238 classNamed:@"AVCaptureDeviceInput"] deviceInputWithDevice:device | 250 classNamed:@"AVCaptureDeviceInput"] deviceInputWithDevice:device |
| 239 error:outError]; | 251 error:outError]; |
| 240 } | 252 } |
| 241 | 253 |
| 242 @end // @implementation AVCaptureDeviceInputGlue | 254 @end // @implementation AVCaptureDeviceInputGlue |
| OLD | NEW |