Chromium Code Reviews| 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 "content/common/gpu/media/gpu_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "ipc/message_filter.h" | 21 #include "ipc/message_filter.h" |
| 22 #include "media/base/limits.h" | 22 #include "media/base/limits.h" |
| 23 #include "ui/gl/gl_context.h" | 23 #include "ui/gl/gl_context.h" |
| 24 #include "ui/gl/gl_surface_egl.h" | 24 #include "ui/gl/gl_surface_egl.h" |
| 25 | 25 |
| 26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
| 27 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
| 28 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" | 28 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" |
| 29 #elif defined(OS_MACOSX) | 29 #elif defined(OS_MACOSX) |
| 30 #include "content/common/gpu/media/vt_video_decode_accelerator.h" | 30 #include "content/common/gpu/media/vt_video_decode_accelerator.h" |
| 31 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 31 #elif defined(OS_CHROMEOS) |
| 32 #if defined(USE_OZONE) || defined(ARCH_CPU_ARMEL) | |
| 32 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | 33 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" |
| 33 #include "content/common/gpu/media/v4l2_video_device.h" | 34 #include "content/common/gpu/media/v4l2_video_device.h" |
| 34 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 35 #endif // defined(USE_OZONE) || defined(ARCH_CPU_ARMEL) |
| 36 #if defined(ARCH_CPU_X86_FAMILY) | |
| 35 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | 37 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
| 36 #include "ui/gl/gl_implementation.h" | 38 #include "ui/gl/gl_implementation.h" |
| 39 #endif // defined(ARCH_CPU_X86_FAMILY) | |
| 37 #elif defined(USE_OZONE) | 40 #elif defined(USE_OZONE) |
| 38 #include "media/ozone/media_ozone_platform.h" | 41 #include "media/ozone/media_ozone_platform.h" |
| 39 #elif defined(OS_ANDROID) | 42 #elif defined(OS_ANDROID) |
| 40 #include "content/common/gpu/media/android_video_decode_accelerator.h" | 43 #include "content/common/gpu/media/android_video_decode_accelerator.h" |
| 41 #endif | 44 #endif |
| 42 | 45 |
| 43 #include "ui/gfx/size.h" | 46 #include "ui/gfx/size.h" |
| 44 | 47 |
| 45 namespace content { | 48 namespace content { |
| 46 | 49 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 | 240 |
| 238 #if !defined(OS_WIN) | 241 #if !defined(OS_WIN) |
| 239 // Ensure we will be able to get a GL context at all before initializing | 242 // Ensure we will be able to get a GL context at all before initializing |
| 240 // non-Windows VDAs. | 243 // non-Windows VDAs. |
| 241 if (!make_context_current_.Run()) { | 244 if (!make_context_current_.Run()) { |
| 242 SendCreateDecoderReply(init_done_msg, false); | 245 SendCreateDecoderReply(init_done_msg, false); |
| 243 return; | 246 return; |
| 244 } | 247 } |
| 245 #endif | 248 #endif |
| 246 | 249 |
| 247 #if defined(OS_WIN) | 250 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> |
| 248 if (base::win::GetVersion() < base::win::VERSION_WIN7) { | 251 create_vda_cbs = CreateVDACbs(); |
| 249 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 252 |
| 250 SendCreateDecoderReply(init_done_msg, false); | 253 for (size_t i = 0; i < create_vda_cbs.size(); ++i) { |
| 254 video_decode_accelerator_ = create_vda_cbs[i].Run(); | |
| 255 if (!video_decode_accelerator_ || | |
| 256 !video_decode_accelerator_->Initialize(profile, this)) | |
| 257 continue; | |
| 258 | |
| 259 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
| 260 filter_ = new MessageFilter(this, host_route_id_); | |
| 261 stub_->channel()->AddFilter(filter_.get()); | |
| 262 } | |
| 263 SendCreateDecoderReply(init_done_msg, true); | |
| 251 return; | 264 return; |
| 252 } | 265 } |
| 253 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | 266 video_decode_accelerator_.reset(); |
| 254 video_decode_accelerator_.reset( | 267 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| 255 new DXVAVideoDecodeAccelerator(make_context_current_)); | 268 SendCreateDecoderReply(init_done_msg, false); |
| 256 #elif defined(OS_MACOSX) | 269 } |
| 257 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( | 270 |
| 258 static_cast<CGLContextObj>( | 271 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> |
| 259 stub_->decoder()->GetGLContext()->GetHandle()), | 272 GpuVideoDecodeAccelerator::CreateVDACbs() { |
| 273 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> create_vda_cbs; | |
|
piman
2015/01/05 23:50:05
This seems overkill to allocate a vector and fill
henryhsu
2015/01/06 08:13:40
CreateDXVAVDA functions are private and not static
| |
| 274 create_vda_cbs.push_back(base::Bind( | |
| 275 &GpuVideoDecodeAccelerator::CreateDXVAVDA, base::Unretained(this))); | |
| 276 create_vda_cbs.push_back(base::Bind( | |
| 277 &GpuVideoDecodeAccelerator::CreateV4L2VDA, base::Unretained(this))); | |
| 278 create_vda_cbs.push_back(base::Bind( | |
| 279 &GpuVideoDecodeAccelerator::CreateVaapiVDA, base::Unretained(this))); | |
| 280 create_vda_cbs.push_back(base::Bind( | |
| 281 &GpuVideoDecodeAccelerator::CreateVTVDA, base::Unretained(this))); | |
| 282 create_vda_cbs.push_back(base::Bind( | |
| 283 &GpuVideoDecodeAccelerator::CreateOzoneVDA, base::Unretained(this))); | |
| 284 create_vda_cbs.push_back(base::Bind( | |
| 285 &GpuVideoDecodeAccelerator::CreateAndroidVDA, | |
| 286 base::Unretained(this))); | |
| 287 return create_vda_cbs; | |
| 288 } | |
| 289 | |
| 290 scoped_ptr<media::VideoDecodeAccelerator> | |
| 291 GpuVideoDecodeAccelerator::CreateDXVAVDA() { | |
| 292 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
| 293 #if defined(OS_WIN) | |
| 294 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { | |
| 295 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | |
| 296 decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_)); | |
| 297 } else { | |
| 298 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
| 299 } | |
| 300 #endif | |
| 301 return decoder.Pass(); | |
| 302 } | |
| 303 | |
| 304 scoped_ptr<media::VideoDecodeAccelerator> | |
| 305 GpuVideoDecodeAccelerator::CreateV4L2VDA() { | |
| 306 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
| 307 #if defined(OS_CHROMEOS) && (defined(USE_OZONE) || defined(ARCH_CPU_ARMEL)) | |
| 308 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
| 309 if (device.get()) { | |
| 310 decoder.reset(new V4L2VideoDecodeAccelerator( | |
| 311 gfx::GLSurfaceEGL::GetHardwareDisplay(), | |
| 312 stub_->decoder()->GetGLContext()->GetHandle(), | |
| 313 weak_factory_for_io_.GetWeakPtr(), | |
| 314 make_context_current_, | |
| 315 device.Pass(), | |
| 316 io_message_loop_)); | |
| 317 } | |
| 318 #endif | |
| 319 return decoder.Pass(); | |
| 320 } | |
| 321 | |
| 322 scoped_ptr<media::VideoDecodeAccelerator> | |
| 323 GpuVideoDecodeAccelerator::CreateVaapiVDA() { | |
| 324 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
| 325 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 326 decoder.reset(new VaapiVideoDecodeAccelerator(make_context_current_)); | |
| 327 #endif | |
| 328 return decoder.Pass(); | |
| 329 } | |
| 330 | |
| 331 scoped_ptr<media::VideoDecodeAccelerator> | |
| 332 GpuVideoDecodeAccelerator::CreateVTVDA() { | |
| 333 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
| 334 #if defined(OS_MACOSX) | |
| 335 decoder.reset(new VTVideoDecodeAccelerator( | |
| 336 static_cast<CGLContextObj>(stub_->decoder()->GetGLContext()->GetHandle()), | |
| 260 make_context_current_)); | 337 make_context_current_)); |
| 261 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 338 #endif |
| 262 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 339 return decoder.Pass(); |
| 263 if (!device.get()) { | 340 } |
| 264 SendCreateDecoderReply(init_done_msg, false); | 341 |
| 265 return; | 342 scoped_ptr<media::VideoDecodeAccelerator> |
| 266 } | 343 GpuVideoDecodeAccelerator::CreateOzoneVDA() { |
| 267 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( | 344 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 268 gfx::GLSurfaceEGL::GetHardwareDisplay(), | 345 #if !defined(OS_CHROMEOS) && defined(USE_OZONE) |
| 269 stub_->decoder()->GetGLContext()->GetHandle(), | |
| 270 weak_factory_for_io_.GetWeakPtr(), | |
| 271 make_context_current_, | |
| 272 device.Pass(), | |
| 273 io_message_loop_)); | |
| 274 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 275 video_decode_accelerator_.reset( | |
| 276 new VaapiVideoDecodeAccelerator(make_context_current_)); | |
| 277 #elif defined(USE_OZONE) | |
| 278 media::MediaOzonePlatform* platform = | 346 media::MediaOzonePlatform* platform = |
| 279 media::MediaOzonePlatform::GetInstance(); | 347 media::MediaOzonePlatform::GetInstance(); |
| 280 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( | 348 decoder.reset(platform->CreateVideoDecodeAccelerator(make_context_current_)); |
| 281 make_context_current_)); | 349 #endif |
| 282 if (!video_decode_accelerator_) { | 350 return decoder.Pass(); |
| 283 SendCreateDecoderReply(init_done_msg, false); | 351 } |
| 284 return; | 352 |
| 285 } | 353 scoped_ptr<media::VideoDecodeAccelerator> |
| 286 #elif defined(OS_ANDROID) | 354 GpuVideoDecodeAccelerator::CreateAndroidVDA() { |
| 287 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | 355 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 356 #if defined(OS_ANDROID) | |
| 357 decoder.reset(new AndroidVideoDecodeAccelerator( | |
| 288 stub_->decoder()->AsWeakPtr(), | 358 stub_->decoder()->AsWeakPtr(), |
| 289 make_context_current_)); | 359 make_context_current_)); |
| 290 #else | |
| 291 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
| 292 SendCreateDecoderReply(init_done_msg, false); | |
| 293 return; | |
| 294 #endif | 360 #endif |
| 295 | 361 return decoder.Pass(); |
| 296 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
| 297 filter_ = new MessageFilter(this, host_route_id_); | |
| 298 stub_->channel()->AddFilter(filter_.get()); | |
| 299 } | |
| 300 | |
| 301 if (!video_decode_accelerator_->Initialize(profile, this)) { | |
| 302 SendCreateDecoderReply(init_done_msg, false); | |
| 303 return; | |
| 304 } | |
| 305 | |
| 306 SendCreateDecoderReply(init_done_msg, true); | |
| 307 } | 362 } |
| 308 | 363 |
| 309 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 364 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
| 310 // true, otherwise on the main thread. | 365 // true, otherwise on the main thread. |
| 311 void GpuVideoDecodeAccelerator::OnDecode( | 366 void GpuVideoDecodeAccelerator::OnDecode( |
| 312 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 367 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
| 313 DCHECK(video_decode_accelerator_.get()); | 368 DCHECK(video_decode_accelerator_.get()); |
| 314 if (id < 0) { | 369 if (id < 0) { |
| 315 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; | 370 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
| 316 if (child_message_loop_->BelongsToCurrentThread()) { | 371 if (child_message_loop_->BelongsToCurrentThread()) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 return stub_->channel()->Send(message); | 560 return stub_->channel()->Send(message); |
| 506 } | 561 } |
| 507 | 562 |
| 508 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, | 563 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, |
| 509 bool succeeded) { | 564 bool succeeded) { |
| 510 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); | 565 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); |
| 511 Send(message); | 566 Send(message); |
| 512 } | 567 } |
| 513 | 568 |
| 514 } // namespace content | 569 } // namespace content |
| OLD | NEW |