Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 class AVFoundationInternal { | 21 class AVFoundationInternal { |
| 22 public: | 22 public: |
| 23 AVFoundationInternal() { | 23 AVFoundationInternal() { |
| 24 bundle_ = [NSBundle | 24 bundle_ = [NSBundle |
| 25 bundleWithPath:@"/System/Library/Frameworks/AVFoundation.framework"]; | 25 bundleWithPath:@"/System/Library/Frameworks/AVFoundation.framework"]; |
| 26 | 26 |
| 27 const char* path = [[bundle_ executablePath] fileSystemRepresentation]; | 27 const char* path = [[bundle_ executablePath] fileSystemRepresentation]; |
| 28 CHECK(path); | 28 CHECK(path); |
| 29 library_handle_ = dlopen(path, RTLD_LAZY | RTLD_LOCAL); | 29 library_handle_ = dlopen(path, RTLD_LAZY | RTLD_LOCAL); |
| 30 CHECK(library_handle_) << dlerror(); | 30 CHECK(library_handle_) << dlerror(); |
| 31 | |
| 32 AVCaptureDeviceWasConnectedNotification_ = *reinterpret_cast<NSString**>( | |
|
tommi (sloooow) - chröme
2014/01/14 15:08:49
There's lot of code duplication here. What about
| |
| 33 dlsym(library_handle_, "AVCaptureDeviceWasConnectedNotification")); | |
| 34 DCHECK(AVCaptureDeviceWasConnectedNotification_) << dlerror(); | |
| 35 AVCaptureDeviceWasDisconnectedNotification_ = *reinterpret_cast<NSString**>( | |
| 36 dlsym(library_handle_, "AVCaptureDeviceWasDisconnectedNotification")); | |
| 37 DCHECK(AVCaptureDeviceWasDisconnectedNotification_) << dlerror(); | |
| 38 | |
| 39 AVMediaTypeVideo_ = *reinterpret_cast<NSString**>( | |
| 40 dlsym(library_handle_, "AVMediaTypeVideo")); | |
| 41 DCHECK(AVMediaTypeVideo_) << dlerror(); | |
| 42 AVMediaTypeAudio_ = *reinterpret_cast<NSString**>( | |
| 43 dlsym(library_handle_, "AVMediaTypeAudio")); | |
| 44 DCHECK(AVMediaTypeAudio_) << dlerror(); | |
| 45 AVMediaTypeMuxed_ = *reinterpret_cast<NSString**>( | |
| 46 dlsym(library_handle_, "AVMediaTypeMuxed")); | |
| 47 DCHECK(AVMediaTypeMuxed_) << dlerror(); | |
| 48 | |
| 49 AVCaptureSessionRuntimeErrorNotification_ = *reinterpret_cast<NSString**>( | |
| 50 dlsym(library_handle_, "AVCaptureSessionRuntimeErrorNotification")); | |
| 51 DCHECK(AVCaptureSessionRuntimeErrorNotification_) << dlerror(); | |
| 52 AVCaptureSessionDidStopRunningNotification_ = *reinterpret_cast<NSString**>( | |
| 53 dlsym(library_handle_, "AVCaptureSessionDidStopRunningNotification")); | |
| 54 DCHECK(AVCaptureSessionDidStopRunningNotification_) << dlerror(); | |
| 55 AVCaptureSessionErrorKey_ = *reinterpret_cast<NSString**>( | |
| 56 dlsym(library_handle_, "AVCaptureSessionErrorKey")); | |
| 57 DCHECK(AVCaptureSessionErrorKey_) << dlerror(); | |
| 58 | |
| 59 AVCaptureSessionPreset320x240_ = *reinterpret_cast<NSString**>( | |
| 60 dlsym(library_handle_, "AVCaptureSessionPreset320x240")); | |
| 61 DCHECK(AVCaptureSessionPreset320x240_) << dlerror(); | |
| 62 AVCaptureSessionPreset640x480_ = *reinterpret_cast<NSString**>( | |
| 63 dlsym(library_handle_, "AVCaptureSessionPreset640x480")); | |
| 64 DCHECK(AVCaptureSessionPreset640x480_) << dlerror(); | |
| 65 AVCaptureSessionPreset1280x720_ = *reinterpret_cast<NSString**>( | |
| 66 dlsym(library_handle_, "AVCaptureSessionPreset1280x720")); | |
| 67 DCHECK(AVCaptureSessionPreset1280x720_) << dlerror(); | |
| 68 | |
| 69 AVVideoScalingModeKey_ = *reinterpret_cast<NSString**>( | |
| 70 dlsym(library_handle_, "AVVideoScalingModeKey")); | |
| 71 DCHECK(AVVideoScalingModeKey_) << dlerror(); | |
| 72 AVVideoScalingModeResizeAspect_ = *reinterpret_cast<NSString**>( | |
| 73 dlsym(library_handle_, "AVVideoScalingModeResizeAspect")); | |
| 74 DCHECK(AVVideoScalingModeResizeAspect_) << dlerror(); | |
| 31 } | 75 } |
| 76 | |
| 32 NSBundle* bundle() const { return bundle_; } | 77 NSBundle* bundle() const { return bundle_; } |
| 33 void* library_handle() const { return library_handle_; } | 78 void* library_handle() const { return library_handle_; } |
| 34 | 79 |
| 80 NSString* AVCaptureDeviceWasConnectedNotification() const { | |
| 81 return AVCaptureDeviceWasConnectedNotification_; | |
| 82 } | |
| 83 NSString* AVCaptureDeviceWasDisconnectedNotification() const { | |
| 84 return AVCaptureDeviceWasDisconnectedNotification_; | |
| 85 } | |
| 86 NSString* AVMediaTypeVideo() const { return AVMediaTypeVideo_; } | |
| 87 NSString* AVMediaTypeAudio() const { return AVMediaTypeAudio_; } | |
| 88 NSString* AVMediaTypeMuxed() const { return AVMediaTypeMuxed_; } | |
| 89 NSString* AVCaptureSessionRuntimeErrorNotification() const { | |
| 90 return AVCaptureSessionRuntimeErrorNotification_; | |
| 91 } | |
| 92 NSString* AVCaptureSessionDidStopRunningNotification() const { | |
| 93 return AVCaptureSessionDidStopRunningNotification_; | |
| 94 } | |
| 95 NSString* AVCaptureSessionErrorKey() const { | |
| 96 return AVCaptureSessionErrorKey_; | |
| 97 } | |
| 98 NSString* AVCaptureSessionPreset320x240() const { | |
| 99 return AVCaptureSessionPreset320x240_; | |
| 100 } | |
| 101 NSString* AVCaptureSessionPreset640x480() const { | |
| 102 return AVCaptureSessionPreset640x480_; | |
| 103 } | |
| 104 NSString* AVCaptureSessionPreset1280x720() const { | |
| 105 return AVCaptureSessionPreset1280x720_; | |
| 106 } | |
| 107 NSString* AVVideoScalingModeKey() const { return AVVideoScalingModeKey_; } | |
| 108 NSString* AVVideoScalingModeResizeAspect() const { | |
| 109 return AVVideoScalingModeResizeAspect_; | |
| 110 } | |
| 111 | |
| 35 private: | 112 private: |
| 36 NSBundle* bundle_; | 113 NSBundle* bundle_; |
| 37 void* library_handle_; | 114 void* library_handle_; |
| 115 NSString* AVCaptureDeviceWasConnectedNotification_; | |
|
tommi (sloooow) - chröme
2014/01/14 15:08:49
Since these names don't adhere to the style guide,
| |
| 116 NSString* AVCaptureDeviceWasDisconnectedNotification_; | |
| 117 NSString* AVMediaTypeVideo_; | |
| 118 NSString* AVMediaTypeAudio_; | |
| 119 NSString* AVMediaTypeMuxed_; | |
| 120 NSString* AVCaptureSessionRuntimeErrorNotification_; | |
| 121 NSString* AVCaptureSessionDidStopRunningNotification_; | |
| 122 NSString* AVCaptureSessionErrorKey_; | |
| 123 NSString* AVCaptureSessionPreset320x240_; | |
| 124 NSString* AVCaptureSessionPreset640x480_; | |
| 125 NSString* AVCaptureSessionPreset1280x720_; | |
| 126 NSString* AVVideoScalingModeKey_; | |
| 127 NSString* AVVideoScalingModeResizeAspect_; | |
| 38 | 128 |
| 39 DISALLOW_COPY_AND_ASSIGN(AVFoundationInternal); | 129 DISALLOW_COPY_AND_ASSIGN(AVFoundationInternal); |
| 40 }; | 130 }; |
| 41 | 131 |
| 42 } // namespace | 132 } // namespace |
| 43 | 133 |
| 44 static base::LazyInstance<AVFoundationInternal> g_avfoundation_handle = | 134 static base::LazyInstance<AVFoundationInternal> g_avfoundation_handle = |
| 45 LAZY_INSTANCE_INITIALIZER; | 135 LAZY_INSTANCE_INITIALIZER; |
| 46 | 136 |
| 47 namespace media { | |
| 48 | |
| 49 // TODO(mcasas):http://crbug.com/323536 cache the string pointers. | |
| 50 static NSString* ReadNSStringPtr(const char* symbol) { | |
| 51 NSString** string_pointer = reinterpret_cast<NSString**>( | |
| 52 dlsym(AVFoundationGlue::AVFoundationLibraryHandle(), symbol)); | |
| 53 DCHECK(string_pointer) << dlerror(); | |
| 54 return *string_pointer; | |
| 55 } | |
| 56 | |
| 57 } // namespace media | |
| 58 | |
| 59 bool AVFoundationGlue::IsAVFoundationSupported() { | 137 bool AVFoundationGlue::IsAVFoundationSupported() { |
| 60 if (!base::mac::IsOSLionOrLater()) | 138 if (!base::mac::IsOSLionOrLater()) |
| 61 return false; | 139 return false; |
| 62 const std::string group_name = | 140 const std::string group_name = |
| 63 base::FieldTrialList::FindFullName("AVFoundationMacVideoCapture"); | 141 base::FieldTrialList::FindFullName("AVFoundationMacVideoCapture"); |
| 64 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 142 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 65 return (cmd_line->HasSwitch(switches::kEnableAVFoundation) || | 143 return (cmd_line->HasSwitch(switches::kEnableAVFoundation) || |
| 66 group_name == "Enabled") && [AVFoundationBundle() load]; | 144 group_name == "Enabled") && [AVFoundationBundle() load]; |
| 67 } | 145 } |
| 68 | 146 |
| 69 NSBundle const* AVFoundationGlue::AVFoundationBundle() { | 147 NSBundle const* AVFoundationGlue::AVFoundationBundle() { |
| 70 return g_avfoundation_handle.Get().bundle(); | 148 return g_avfoundation_handle.Get().bundle(); |
| 71 } | 149 } |
| 72 | 150 |
| 73 void* AVFoundationGlue::AVFoundationLibraryHandle() { | 151 void* AVFoundationGlue::AVFoundationLibraryHandle() { |
| 74 return g_avfoundation_handle.Get().library_handle(); | 152 return g_avfoundation_handle.Get().library_handle(); |
| 75 } | 153 } |
| 76 | 154 |
| 77 NSString* AVFoundationGlue::AVCaptureDeviceWasConnectedNotification() { | 155 NSString* AVFoundationGlue::AVCaptureDeviceWasConnectedNotification() { |
| 78 return media::ReadNSStringPtr("AVCaptureDeviceWasConnectedNotification"); | 156 return g_avfoundation_handle.Get().AVCaptureDeviceWasConnectedNotification(); |
| 79 } | 157 } |
| 80 | 158 |
| 81 NSString* AVFoundationGlue::AVCaptureDeviceWasDisconnectedNotification() { | 159 NSString* AVFoundationGlue::AVCaptureDeviceWasDisconnectedNotification() { |
| 82 return media::ReadNSStringPtr("AVCaptureDeviceWasDisconnectedNotification"); | 160 return |
| 161 g_avfoundation_handle.Get().AVCaptureDeviceWasDisconnectedNotification(); | |
| 83 } | 162 } |
| 84 | 163 |
| 85 NSString* AVFoundationGlue::AVMediaTypeVideo() { | 164 NSString* AVFoundationGlue::AVMediaTypeVideo() { |
| 86 return media::ReadNSStringPtr("AVMediaTypeVideo"); | 165 return g_avfoundation_handle.Get().AVMediaTypeVideo(); |
| 87 } | 166 } |
| 88 | 167 |
| 89 NSString* AVFoundationGlue::AVMediaTypeAudio() { | 168 NSString* AVFoundationGlue::AVMediaTypeAudio() { |
| 90 return media::ReadNSStringPtr("AVMediaTypeAudio"); | 169 return g_avfoundation_handle.Get().AVMediaTypeAudio(); |
| 91 } | 170 } |
| 92 | 171 |
| 93 NSString* AVFoundationGlue::AVMediaTypeMuxed() { | 172 NSString* AVFoundationGlue::AVMediaTypeMuxed() { |
| 94 return media::ReadNSStringPtr("AVMediaTypeMuxed"); | 173 return g_avfoundation_handle.Get().AVMediaTypeMuxed(); |
| 95 } | 174 } |
| 96 | 175 |
| 97 NSString* AVFoundationGlue::AVCaptureSessionRuntimeErrorNotification() { | 176 NSString* AVFoundationGlue::AVCaptureSessionRuntimeErrorNotification() { |
| 98 return media::ReadNSStringPtr("AVCaptureSessionRuntimeErrorNotification"); | 177 return g_avfoundation_handle.Get().AVCaptureSessionRuntimeErrorNotification(); |
| 99 } | 178 } |
| 100 | 179 |
| 101 NSString* AVFoundationGlue::AVCaptureSessionDidStopRunningNotification() { | 180 NSString* AVFoundationGlue::AVCaptureSessionDidStopRunningNotification() { |
| 102 return media::ReadNSStringPtr("AVCaptureSessionDidStopRunningNotification"); | 181 return |
| 182 g_avfoundation_handle.Get().AVCaptureSessionDidStopRunningNotification(); | |
| 103 } | 183 } |
| 104 | 184 |
| 105 NSString* AVFoundationGlue::AVCaptureSessionErrorKey() { | 185 NSString* AVFoundationGlue::AVCaptureSessionErrorKey() { |
| 106 return media::ReadNSStringPtr("AVCaptureSessionErrorKey"); | 186 return g_avfoundation_handle.Get().AVCaptureSessionErrorKey(); |
| 107 } | 187 } |
| 108 | 188 |
| 109 NSString* AVFoundationGlue::AVCaptureSessionPreset320x240() { | 189 NSString* AVFoundationGlue::AVCaptureSessionPreset320x240() { |
| 110 return media::ReadNSStringPtr("AVCaptureSessionPreset320x240"); | 190 return g_avfoundation_handle.Get().AVCaptureSessionPreset320x240(); |
| 111 } | 191 } |
| 112 | 192 |
| 113 NSString* AVFoundationGlue::AVCaptureSessionPreset640x480() { | 193 NSString* AVFoundationGlue::AVCaptureSessionPreset640x480() { |
| 114 return media::ReadNSStringPtr("AVCaptureSessionPreset640x480"); | 194 return g_avfoundation_handle.Get().AVCaptureSessionPreset640x480(); |
| 115 } | 195 } |
| 116 | 196 |
| 117 NSString* AVFoundationGlue::AVCaptureSessionPreset1280x720() { | 197 NSString* AVFoundationGlue::AVCaptureSessionPreset1280x720() { |
| 118 return media::ReadNSStringPtr("AVCaptureSessionPreset1280x720"); | 198 return g_avfoundation_handle.Get().AVCaptureSessionPreset1280x720(); |
| 119 } | 199 } |
| 120 | 200 |
| 121 NSString* AVFoundationGlue::AVVideoScalingModeKey() { | 201 NSString* AVFoundationGlue::AVVideoScalingModeKey() { |
| 122 return media::ReadNSStringPtr("AVVideoScalingModeKey"); | 202 return g_avfoundation_handle.Get().AVVideoScalingModeKey(); |
| 123 } | 203 } |
| 124 | 204 |
| 125 NSString* AVFoundationGlue::AVVideoScalingModeResizeAspect() { | 205 NSString* AVFoundationGlue::AVVideoScalingModeResizeAspect() { |
| 126 return media::ReadNSStringPtr("AVVideoScalingModeResizeAspect"); | 206 return g_avfoundation_handle.Get().AVVideoScalingModeResizeAspect(); |
| 127 } | 207 } |
| 128 | 208 |
| 129 Class AVFoundationGlue::AVCaptureSessionClass() { | 209 Class AVFoundationGlue::AVCaptureSessionClass() { |
| 130 return [AVFoundationBundle() classNamed:@"AVCaptureSession"]; | 210 return [AVFoundationBundle() classNamed:@"AVCaptureSession"]; |
| 131 } | 211 } |
| 132 | 212 |
| 133 Class AVFoundationGlue::AVCaptureVideoDataOutputClass() { | 213 Class AVFoundationGlue::AVCaptureVideoDataOutputClass() { |
| 134 return [AVFoundationBundle() classNamed:@"AVCaptureVideoDataOutput"]; | 214 return [AVFoundationBundle() classNamed:@"AVCaptureVideoDataOutput"]; |
| 135 } | 215 } |
| 136 | 216 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 157 @implementation AVCaptureDeviceInputGlue | 237 @implementation AVCaptureDeviceInputGlue |
| 158 | 238 |
| 159 + (CrAVCaptureDeviceInput*)deviceInputWithDevice:(CrAVCaptureDevice*)device | 239 + (CrAVCaptureDeviceInput*)deviceInputWithDevice:(CrAVCaptureDevice*)device |
| 160 error:(NSError**)outError { | 240 error:(NSError**)outError { |
| 161 return [[AVFoundationGlue::AVFoundationBundle() | 241 return [[AVFoundationGlue::AVFoundationBundle() |
| 162 classNamed:@"AVCaptureDeviceInput"] deviceInputWithDevice:device | 242 classNamed:@"AVCaptureDeviceInput"] deviceInputWithDevice:device |
| 163 error:outError]; | 243 error:outError]; |
| 164 } | 244 } |
| 165 | 245 |
| 166 @end // @implementation AVCaptureDeviceInputGlue | 246 @end // @implementation AVCaptureDeviceInputGlue |
| OLD | NEW |