| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/gfx/video_decode_acceleration_support_mac.h" | 5 #include "ui/gfx/video_decode_acceleration_support_mac.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 loop_(base::MessageLoopProxy::current()) { | 115 loop_(base::MessageLoopProxy::current()) { |
| 116 } | 116 } |
| 117 | 117 |
| 118 VideoDecodeAccelerationSupport::Status VideoDecodeAccelerationSupport::Create( | 118 VideoDecodeAccelerationSupport::Status VideoDecodeAccelerationSupport::Create( |
| 119 int width, | 119 int width, |
| 120 int height, | 120 int height, |
| 121 int pixel_format, | 121 int pixel_format, |
| 122 const void* avc_bytes, | 122 const void* avc_bytes, |
| 123 size_t avc_size) { | 123 size_t avc_size) { |
| 124 if (!InitializeVdaApis()) | 124 if (!InitializeVdaApis()) |
| 125 return VDA_LOAD_FRAMEWORK_ERROR; | 125 return LOAD_FRAMEWORK_ERROR; |
| 126 | 126 |
| 127 NSData* avc_data = [NSData dataWithBytes:avc_bytes length:avc_size]; | 127 NSData* avc_data = [NSData dataWithBytes:avc_bytes length:avc_size]; |
| 128 NSDictionary* config = [NSDictionary dictionaryWithObjectsAndKeys: | 128 NSDictionary* config = [NSDictionary dictionaryWithObjectsAndKeys: |
| 129 [NSNumber numberWithInt:width], | 129 [NSNumber numberWithInt:width], |
| 130 CFToNSCast(kVDADecoderConfiguration_Width), | 130 CFToNSCast(kVDADecoderConfiguration_Width), |
| 131 [NSNumber numberWithInt:height], | 131 [NSNumber numberWithInt:height], |
| 132 CFToNSCast(kVDADecoderConfiguration_Height), | 132 CFToNSCast(kVDADecoderConfiguration_Height), |
| 133 [NSNumber numberWithInt:'avc1'], | 133 [NSNumber numberWithInt:'avc1'], |
| 134 CFToNSCast(kVDADecoderConfiguration_SourceFormat), | 134 CFToNSCast(kVDADecoderConfiguration_SourceFormat), |
| 135 avc_data, | 135 avc_data, |
| 136 CFToNSCast(kVDADecoderConfiguration_avcCData), | 136 CFToNSCast(kVDADecoderConfiguration_avcCData), |
| 137 nil]; | 137 nil]; |
| 138 | 138 |
| 139 NSDictionary* format_info = [NSDictionary dictionaryWithObjectsAndKeys: | 139 NSDictionary* format_info = [NSDictionary dictionaryWithObjectsAndKeys: |
| 140 [NSNumber numberWithInt:pixel_format], | 140 [NSNumber numberWithInt:pixel_format], |
| 141 CFToNSCast(kCVPixelBufferPixelFormatTypeKey), | 141 CFToNSCast(kCVPixelBufferPixelFormatTypeKey), |
| 142 // Must set to an empty dictionary as per documentation. | 142 // Must set to an empty dictionary as per documentation. |
| 143 [NSDictionary dictionary], | 143 [NSDictionary dictionary], |
| 144 CFToNSCast(kCVPixelBufferIOSurfacePropertiesKey), | 144 CFToNSCast(kCVPixelBufferIOSurfacePropertiesKey), |
| 145 nil]; | 145 nil]; |
| 146 | 146 |
| 147 OSStatus status = g_VDADecoderCreate(NSToCFCast(config), | 147 OSStatus status = g_VDADecoderCreate(NSToCFCast(config), |
| 148 NSToCFCast(format_info), | 148 NSToCFCast(format_info), |
| 149 reinterpret_cast<VDADecoderOutputCallback*>(OnFrameReadyCallback), this, | 149 reinterpret_cast<VDADecoderOutputCallback*>(OnFrameReadyCallback), this, |
| 150 &decoder_); | 150 &decoder_); |
| 151 switch (status) { | 151 switch (status) { |
| 152 case kVDADecoderNoErr: | 152 case kVDADecoderNoErr: |
| 153 return VDA_SUCCESS; | 153 return SUCCESS; |
| 154 case kVDADecoderHardwareNotSupportedErr: | 154 case kVDADecoderHardwareNotSupportedErr: |
| 155 return VDA_HARDWARE_NOT_SUPPORTED_ERROR; | 155 return HARDWARE_NOT_SUPPORTED_ERROR; |
| 156 default: | 156 default: |
| 157 return VDA_OTHER_ERROR; | 157 return OTHER_ERROR; |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 VideoDecodeAccelerationSupport::Status VideoDecodeAccelerationSupport::Decode( | 161 VideoDecodeAccelerationSupport::Status VideoDecodeAccelerationSupport::Decode( |
| 162 const void* bytes, | 162 const void* bytes, |
| 163 size_t size, | 163 size_t size, |
| 164 const FrameReadyCallback& cb) { | 164 const FrameReadyCallback& cb) { |
| 165 DCHECK(decoder_); | 165 DCHECK(decoder_); |
| 166 ++frame_id_count_; | 166 ++frame_id_count_; |
| 167 frame_ready_callbacks_[frame_id_count_] = cb; | 167 frame_ready_callbacks_[frame_id_count_] = cb; |
| 168 | 168 |
| 169 NSData* data = [NSData dataWithBytes:bytes length:size]; | 169 NSData* data = [NSData dataWithBytes:bytes length:size]; |
| 170 NSDictionary* frame_info = [NSDictionary | 170 NSDictionary* frame_info = [NSDictionary |
| 171 dictionaryWithObject:[NSNumber numberWithInt:frame_id_count_] | 171 dictionaryWithObject:[NSNumber numberWithInt:frame_id_count_] |
| 172 forKey:kFrameIdKey]; | 172 forKey:kFrameIdKey]; |
| 173 | 173 |
| 174 OSStatus status = g_VDADecoderDecode(decoder_, 0, NSToCFCast(data), | 174 OSStatus status = g_VDADecoderDecode(decoder_, 0, NSToCFCast(data), |
| 175 NSToCFCast(frame_info)); | 175 NSToCFCast(frame_info)); |
| 176 if (status != kVDADecoderNoErr) { | 176 if (status != kVDADecoderNoErr) { |
| 177 frame_ready_callbacks_.erase(frame_id_count_); | 177 frame_ready_callbacks_.erase(frame_id_count_); |
| 178 return VDA_OTHER_ERROR; | 178 return OTHER_ERROR; |
| 179 } | 179 } |
| 180 return VDA_SUCCESS; | 180 return SUCCESS; |
| 181 } | 181 } |
| 182 | 182 |
| 183 VideoDecodeAccelerationSupport::Status VideoDecodeAccelerationSupport::Flush( | 183 VideoDecodeAccelerationSupport::Status VideoDecodeAccelerationSupport::Flush( |
| 184 bool emit_frames) { | 184 bool emit_frames) { |
| 185 DCHECK(decoder_); | 185 DCHECK(decoder_); |
| 186 OSStatus status = g_VDADecoderFlush( | 186 OSStatus status = g_VDADecoderFlush( |
| 187 decoder_, emit_frames ? kVDADecoderFlush_EmitFrames : 0); | 187 decoder_, emit_frames ? kVDADecoderFlush_EmitFrames : 0); |
| 188 if (!emit_frames) | 188 if (!emit_frames) |
| 189 frame_ready_callbacks_.clear(); | 189 frame_ready_callbacks_.clear(); |
| 190 return status == kVDADecoderNoErr ? VDA_SUCCESS : VDA_OTHER_ERROR; | 190 return status == kVDADecoderNoErr ? SUCCESS : OTHER_ERROR; |
| 191 } | 191 } |
| 192 | 192 |
| 193 VideoDecodeAccelerationSupport::Status | 193 VideoDecodeAccelerationSupport::Status |
| 194 VideoDecodeAccelerationSupport::Destroy() { | 194 VideoDecodeAccelerationSupport::Destroy() { |
| 195 DCHECK(decoder_); | 195 DCHECK(decoder_); |
| 196 OSStatus status = g_VDADecoderDestroy(decoder_); | 196 OSStatus status = g_VDADecoderDestroy(decoder_); |
| 197 decoder_ = NULL; | 197 decoder_ = NULL; |
| 198 return status == kVDADecoderNoErr ? VDA_SUCCESS : VDA_OTHER_ERROR; | 198 return status == kVDADecoderNoErr ? SUCCESS : OTHER_ERROR; |
| 199 } | 199 } |
| 200 | 200 |
| 201 VideoDecodeAccelerationSupport::~VideoDecodeAccelerationSupport() { | 201 VideoDecodeAccelerationSupport::~VideoDecodeAccelerationSupport() { |
| 202 DCHECK(!decoder_); | 202 DCHECK(!decoder_); |
| 203 } | 203 } |
| 204 | 204 |
| 205 // static | 205 // static |
| 206 void VideoDecodeAccelerationSupport::OnFrameReadyCallback( | 206 void VideoDecodeAccelerationSupport::OnFrameReadyCallback( |
| 207 void* callback_data, | 207 void* callback_data, |
| 208 CFDictionaryRef frame_info, | 208 CFDictionaryRef frame_info, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 230 OSStatus status, | 230 OSStatus status, |
| 231 int frame_id) { | 231 int frame_id) { |
| 232 frame_ready_callbacks_[frame_id].Run(image_buffer, status); | 232 frame_ready_callbacks_[frame_id].Run(image_buffer, status); |
| 233 // Match the retain in OnFrameReadyCallback. | 233 // Match the retain in OnFrameReadyCallback. |
| 234 if (image_buffer) | 234 if (image_buffer) |
| 235 CFRelease(image_buffer); | 235 CFRelease(image_buffer); |
| 236 frame_ready_callbacks_.erase(frame_id); | 236 frame_ready_callbacks_.erase(frame_id); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace | 239 } // namespace |
| OLD | NEW |