Chromium Code Reviews| Index: media/video/capture/mac/avfoundation_glue.mm |
| diff --git a/media/video/capture/mac/avfoundation_glue.mm b/media/video/capture/mac/avfoundation_glue.mm |
| index 4f7de4d480cea1a52f62ba1f7a2711b91c46bade..0355c8b0d006b8de1b7f330595d1649af0897607 100644 |
| --- a/media/video/capture/mac/avfoundation_glue.mm |
| +++ b/media/video/capture/mac/avfoundation_glue.mm |
| @@ -28,13 +28,103 @@ class AVFoundationInternal { |
| CHECK(path); |
| library_handle_ = dlopen(path, RTLD_LAZY | RTLD_LOCAL); |
| CHECK(library_handle_) << dlerror(); |
| + |
| + AVCaptureDeviceWasConnectedNotification_ = *reinterpret_cast<NSString**>( |
|
tommi (sloooow) - chröme
2014/01/14 15:08:49
There's lot of code duplication here. What about
|
| + dlsym(library_handle_, "AVCaptureDeviceWasConnectedNotification")); |
| + DCHECK(AVCaptureDeviceWasConnectedNotification_) << dlerror(); |
| + AVCaptureDeviceWasDisconnectedNotification_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVCaptureDeviceWasDisconnectedNotification")); |
| + DCHECK(AVCaptureDeviceWasDisconnectedNotification_) << dlerror(); |
| + |
| + AVMediaTypeVideo_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVMediaTypeVideo")); |
| + DCHECK(AVMediaTypeVideo_) << dlerror(); |
| + AVMediaTypeAudio_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVMediaTypeAudio")); |
| + DCHECK(AVMediaTypeAudio_) << dlerror(); |
| + AVMediaTypeMuxed_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVMediaTypeMuxed")); |
| + DCHECK(AVMediaTypeMuxed_) << dlerror(); |
| + |
| + AVCaptureSessionRuntimeErrorNotification_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVCaptureSessionRuntimeErrorNotification")); |
| + DCHECK(AVCaptureSessionRuntimeErrorNotification_) << dlerror(); |
| + AVCaptureSessionDidStopRunningNotification_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVCaptureSessionDidStopRunningNotification")); |
| + DCHECK(AVCaptureSessionDidStopRunningNotification_) << dlerror(); |
| + AVCaptureSessionErrorKey_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVCaptureSessionErrorKey")); |
| + DCHECK(AVCaptureSessionErrorKey_) << dlerror(); |
| + |
| + AVCaptureSessionPreset320x240_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVCaptureSessionPreset320x240")); |
| + DCHECK(AVCaptureSessionPreset320x240_) << dlerror(); |
| + AVCaptureSessionPreset640x480_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVCaptureSessionPreset640x480")); |
| + DCHECK(AVCaptureSessionPreset640x480_) << dlerror(); |
| + AVCaptureSessionPreset1280x720_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVCaptureSessionPreset1280x720")); |
| + DCHECK(AVCaptureSessionPreset1280x720_) << dlerror(); |
| + |
| + AVVideoScalingModeKey_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVVideoScalingModeKey")); |
| + DCHECK(AVVideoScalingModeKey_) << dlerror(); |
| + AVVideoScalingModeResizeAspect_ = *reinterpret_cast<NSString**>( |
| + dlsym(library_handle_, "AVVideoScalingModeResizeAspect")); |
| + DCHECK(AVVideoScalingModeResizeAspect_) << dlerror(); |
| } |
| + |
| NSBundle* bundle() const { return bundle_; } |
| void* library_handle() const { return library_handle_; } |
| + NSString* AVCaptureDeviceWasConnectedNotification() const { |
| + return AVCaptureDeviceWasConnectedNotification_; |
| + } |
| + NSString* AVCaptureDeviceWasDisconnectedNotification() const { |
| + return AVCaptureDeviceWasDisconnectedNotification_; |
| + } |
| + NSString* AVMediaTypeVideo() const { return AVMediaTypeVideo_; } |
| + NSString* AVMediaTypeAudio() const { return AVMediaTypeAudio_; } |
| + NSString* AVMediaTypeMuxed() const { return AVMediaTypeMuxed_; } |
| + NSString* AVCaptureSessionRuntimeErrorNotification() const { |
| + return AVCaptureSessionRuntimeErrorNotification_; |
| + } |
| + NSString* AVCaptureSessionDidStopRunningNotification() const { |
| + return AVCaptureSessionDidStopRunningNotification_; |
| + } |
| + NSString* AVCaptureSessionErrorKey() const { |
| + return AVCaptureSessionErrorKey_; |
| + } |
| + NSString* AVCaptureSessionPreset320x240() const { |
| + return AVCaptureSessionPreset320x240_; |
| + } |
| + NSString* AVCaptureSessionPreset640x480() const { |
| + return AVCaptureSessionPreset640x480_; |
| + } |
| + NSString* AVCaptureSessionPreset1280x720() const { |
| + return AVCaptureSessionPreset1280x720_; |
| + } |
| + NSString* AVVideoScalingModeKey() const { return AVVideoScalingModeKey_; } |
| + NSString* AVVideoScalingModeResizeAspect() const { |
| + return AVVideoScalingModeResizeAspect_; |
| + } |
| + |
| private: |
| NSBundle* bundle_; |
| void* library_handle_; |
| + NSString* AVCaptureDeviceWasConnectedNotification_; |
|
tommi (sloooow) - chröme
2014/01/14 15:08:49
Since these names don't adhere to the style guide,
|
| + NSString* AVCaptureDeviceWasDisconnectedNotification_; |
| + NSString* AVMediaTypeVideo_; |
| + NSString* AVMediaTypeAudio_; |
| + NSString* AVMediaTypeMuxed_; |
| + NSString* AVCaptureSessionRuntimeErrorNotification_; |
| + NSString* AVCaptureSessionDidStopRunningNotification_; |
| + NSString* AVCaptureSessionErrorKey_; |
| + NSString* AVCaptureSessionPreset320x240_; |
| + NSString* AVCaptureSessionPreset640x480_; |
| + NSString* AVCaptureSessionPreset1280x720_; |
| + NSString* AVVideoScalingModeKey_; |
| + NSString* AVVideoScalingModeResizeAspect_; |
| DISALLOW_COPY_AND_ASSIGN(AVFoundationInternal); |
| }; |
| @@ -44,18 +134,6 @@ class AVFoundationInternal { |
| static base::LazyInstance<AVFoundationInternal> g_avfoundation_handle = |
| LAZY_INSTANCE_INITIALIZER; |
| -namespace media { |
| - |
| -// TODO(mcasas):http://crbug.com/323536 cache the string pointers. |
| -static NSString* ReadNSStringPtr(const char* symbol) { |
| - NSString** string_pointer = reinterpret_cast<NSString**>( |
| - dlsym(AVFoundationGlue::AVFoundationLibraryHandle(), symbol)); |
| - DCHECK(string_pointer) << dlerror(); |
| - return *string_pointer; |
| -} |
| - |
| -} // namespace media |
| - |
| bool AVFoundationGlue::IsAVFoundationSupported() { |
| if (!base::mac::IsOSLionOrLater()) |
| return false; |
| @@ -75,55 +153,57 @@ void* AVFoundationGlue::AVFoundationLibraryHandle() { |
| } |
| NSString* AVFoundationGlue::AVCaptureDeviceWasConnectedNotification() { |
| - return media::ReadNSStringPtr("AVCaptureDeviceWasConnectedNotification"); |
| + return g_avfoundation_handle.Get().AVCaptureDeviceWasConnectedNotification(); |
| } |
| NSString* AVFoundationGlue::AVCaptureDeviceWasDisconnectedNotification() { |
| - return media::ReadNSStringPtr("AVCaptureDeviceWasDisconnectedNotification"); |
| + return |
| + g_avfoundation_handle.Get().AVCaptureDeviceWasDisconnectedNotification(); |
| } |
| NSString* AVFoundationGlue::AVMediaTypeVideo() { |
| - return media::ReadNSStringPtr("AVMediaTypeVideo"); |
| + return g_avfoundation_handle.Get().AVMediaTypeVideo(); |
| } |
| NSString* AVFoundationGlue::AVMediaTypeAudio() { |
| - return media::ReadNSStringPtr("AVMediaTypeAudio"); |
| + return g_avfoundation_handle.Get().AVMediaTypeAudio(); |
| } |
| NSString* AVFoundationGlue::AVMediaTypeMuxed() { |
| - return media::ReadNSStringPtr("AVMediaTypeMuxed"); |
| + return g_avfoundation_handle.Get().AVMediaTypeMuxed(); |
| } |
| NSString* AVFoundationGlue::AVCaptureSessionRuntimeErrorNotification() { |
| - return media::ReadNSStringPtr("AVCaptureSessionRuntimeErrorNotification"); |
| + return g_avfoundation_handle.Get().AVCaptureSessionRuntimeErrorNotification(); |
| } |
| NSString* AVFoundationGlue::AVCaptureSessionDidStopRunningNotification() { |
| - return media::ReadNSStringPtr("AVCaptureSessionDidStopRunningNotification"); |
| + return |
| + g_avfoundation_handle.Get().AVCaptureSessionDidStopRunningNotification(); |
| } |
| NSString* AVFoundationGlue::AVCaptureSessionErrorKey() { |
| - return media::ReadNSStringPtr("AVCaptureSessionErrorKey"); |
| + return g_avfoundation_handle.Get().AVCaptureSessionErrorKey(); |
| } |
| NSString* AVFoundationGlue::AVCaptureSessionPreset320x240() { |
| - return media::ReadNSStringPtr("AVCaptureSessionPreset320x240"); |
| + return g_avfoundation_handle.Get().AVCaptureSessionPreset320x240(); |
| } |
| NSString* AVFoundationGlue::AVCaptureSessionPreset640x480() { |
| - return media::ReadNSStringPtr("AVCaptureSessionPreset640x480"); |
| + return g_avfoundation_handle.Get().AVCaptureSessionPreset640x480(); |
| } |
| NSString* AVFoundationGlue::AVCaptureSessionPreset1280x720() { |
| - return media::ReadNSStringPtr("AVCaptureSessionPreset1280x720"); |
| + return g_avfoundation_handle.Get().AVCaptureSessionPreset1280x720(); |
| } |
| NSString* AVFoundationGlue::AVVideoScalingModeKey() { |
| - return media::ReadNSStringPtr("AVVideoScalingModeKey"); |
| + return g_avfoundation_handle.Get().AVVideoScalingModeKey(); |
| } |
| NSString* AVFoundationGlue::AVVideoScalingModeResizeAspect() { |
| - return media::ReadNSStringPtr("AVVideoScalingModeResizeAspect"); |
| + return g_avfoundation_handle.Get().AVVideoScalingModeResizeAspect(); |
| } |
| Class AVFoundationGlue::AVCaptureSessionClass() { |