Chromium Code Reviews| Index: content/common/gpu/media/gpu_video_decode_accelerator.cc |
| diff --git a/content/common/gpu/media/gpu_video_decode_accelerator.cc b/content/common/gpu/media/gpu_video_decode_accelerator.cc |
| index f741cb20418fbecfa99b83d54dd814f131c33892..a1dcd568c3f88ab00cb0e3edb2c60044c05c8253 100644 |
| --- a/content/common/gpu/media/gpu_video_decode_accelerator.cc |
| +++ b/content/common/gpu/media/gpu_video_decode_accelerator.cc |
| @@ -32,6 +32,8 @@ |
| #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" |
| #include "content/common/gpu/media/v4l2_video_device.h" |
| #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
| +#include "content/common/gpu/media/v4l2_video_decode_accelerator.h" |
| +#include "content/common/gpu/media/v4l2_video_device.h" |
| #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
| #include "ui/gl/gl_context_glx.h" |
| #include "ui/gl/gl_implementation.h" |
| @@ -245,74 +247,141 @@ void GpuVideoDecodeAccelerator::Initialize( |
| } |
| #endif |
| -#if defined(OS_WIN) |
| - if (base::win::GetVersion() < base::win::VERSION_WIN7) { |
| - NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| + std::vector<GpuVideoDecodeAccelerator::CreateVDACb> |
| + create_vda_cbs = CreateDecoderCbs(); |
| + |
| + if (create_vda_cbs.empty()) { |
|
Pawel Osciak
2014/12/31 07:55:59
I think not needed, since the for loop will not do
henryhsu
2014/12/31 08:47:53
Done.
|
| SendCreateDecoderReply(init_done_msg, false); |
| return; |
| } |
| - DVLOG(0) << "Initializing DXVA HW decoder for windows."; |
| - video_decode_accelerator_.reset( |
| - new DXVAVideoDecodeAccelerator(make_context_current_)); |
| + |
| + for (size_t i = 0; i < create_vda_cbs.size(); ++i) { |
| + video_decode_accelerator_ = create_vda_cbs[i].Run(); |
| + if (!video_decode_accelerator_.get() || |
|
Pawel Osciak
2014/12/31 07:55:59
IIRC, we don't need get()s on scoped_ptr?
henryhsu
2014/12/31 08:47:53
yes. We don't need. This references other codes in
Pawel Osciak
2015/01/02 01:49:14
Not sure if we need this kind of consistency ;)
Bu
|
| + !video_decode_accelerator_->Initialize(profile, this)) |
| + continue; |
| + |
| + if (video_decode_accelerator_->CanDecodeOnIOThread()) { |
| + filter_ = new MessageFilter(this, host_route_id_); |
| + stub_->channel()->AddFilter(filter_.get()); |
| + } |
| + SendCreateDecoderReply(init_done_msg, true); |
| + return; |
| + } |
| + video_decode_accelerator_.reset(); |
| + SendCreateDecoderReply(init_done_msg, false); |
| +} |
| + |
| +std::vector<GpuVideoDecodeAccelerator::CreateVDACb> |
| +GpuVideoDecodeAccelerator::CreateDecoderCbs() { |
| + std::vector<GpuVideoDecodeAccelerator::CreateVDACb> create_vda_cbs; |
| +#if defined(OS_WIN) |
|
Pawel Osciak
2014/12/31 07:55:59
Technically, we don't need all the #ifs here. The
henryhsu
2014/12/31 08:47:53
Sure. Then we will have many callback functions wi
|
| + create_vda_cbs.push_back(base::Bind( |
| + &GpuVideoDecodeAccelerator::CreateDXVADecoder, base::Unretained(this))); |
| +#elif defined(OS_CHROMEOS) && defined(USE_X11) && \ |
| + (defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARMEL)) |
| + create_vda_cbs.push_back(base::Bind( |
| + &GpuVideoDecodeAccelerator::CreateV4L2Decoder, base::Unretained(this))); |
| +#if defined(ARCH_CPU_X86_FAMILY) |
| + create_vda_cbs.push_back(base::Bind( |
| + &GpuVideoDecodeAccelerator::CreateVaapiDecoder, base::Unretained(this))); |
| +#endif |
| #elif defined(OS_MACOSX) |
| - video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( |
| - static_cast<CGLContextObj>( |
| - stub_->decoder()->GetGLContext()->GetHandle()), |
| - make_context_current_)); |
| -#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) |
| + create_vda_cbs.push_back(base::Bind( |
| + &GpuVideoDecodeAccelerator::CreateVTDecoder, base::Unretained(this))); |
| +#elif defined(OS_ANDROID) |
| + create_vda_cbs.push_back(base::Bind( |
| + &GpuVideoDecodeAccelerator::CreateAndroidDecoder, |
| + base::Unretained(this))); |
| +#elif defined(USE_OZONE) |
| + create_vda_cbs.push_back(base::Bind( |
| + &GpuVideoDecodeAccelerator::CreateOzoneDecoder, base::Unretained(this))); |
| +#else |
| + NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| +#endif |
| + return create_vda_cbs; |
| +} |
| + |
| +scoped_ptr<media::VideoDecodeAccelerator> |
| +GpuVideoDecodeAccelerator::CreateDXVADecoder() { |
| + scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| +#if defined(OS_WIN) |
| + if (base::win::GetVersion() >= base::win::VERSION_WIN7) { |
| + DVLOG(0) << "Initializing DXVA HW decoder for windows."; |
| + decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_)); |
| + } else |
|
Pawel Osciak
2014/12/31 07:55:59
Per coding style both branches need a brace if one
henryhsu
2014/12/31 08:47:53
Done.
|
| + NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| +#endif |
| + return decoder.Pass(); |
| +} |
| + |
| +scoped_ptr<media::VideoDecodeAccelerator> |
| +GpuVideoDecodeAccelerator::CreateV4L2Decoder() { |
| + scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| +#if defined(OS_CHROMEOS) && defined(USE_X11) && \ |
| + (defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARMEL)) |
| scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
| - if (!device.get()) { |
| - SendCreateDecoderReply(init_done_msg, false); |
| - return; |
| + if (device.get()) { |
| + decoder.reset(new V4L2VideoDecodeAccelerator( |
| + gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| + stub_->decoder()->GetGLContext()->GetHandle(), |
| + weak_factory_for_io_.GetWeakPtr(), |
| + make_context_current_, |
| + device.Pass(), |
| + io_message_loop_)); |
| } |
| - video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( |
| - gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| - stub_->decoder()->GetGLContext()->GetHandle(), |
| - weak_factory_for_io_.GetWeakPtr(), |
| - make_context_current_, |
| - device.Pass(), |
| - io_message_loop_)); |
| -#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
| +#endif |
| + return decoder.Pass(); |
| +} |
| + |
| +scoped_ptr<media::VideoDecodeAccelerator> |
| +GpuVideoDecodeAccelerator::CreateVaapiDecoder() { |
| + scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| +#if defined(OS_CHROMEOS) && defined(USE_X11) && defined(ARCH_CPU_X86_FAMILY) |
| if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
| VLOG(1) << "HW video decode acceleration not available without " |
| "DesktopGL (GLX)."; |
| - SendCreateDecoderReply(init_done_msg, false); |
| - return; |
| + return decoder.Pass(); |
| } |
| gfx::GLContextGLX* glx_context = |
| static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); |
| - video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( |
| + decoder.reset(new VaapiVideoDecodeAccelerator( |
| glx_context->display(), make_context_current_)); |
| -#elif defined(USE_OZONE) |
| - media::MediaOzonePlatform* platform = |
| - media::MediaOzonePlatform::GetInstance(); |
| - video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( |
| +#endif |
| + return decoder.Pass(); |
| +} |
| + |
| +scoped_ptr<media::VideoDecodeAccelerator> |
| +GpuVideoDecodeAccelerator::CreateVTDecoder() { |
| + scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| +#if defined(OS_MACOSX) |
| + decoder.reset(new VTVideoDecodeAccelerator( |
| + static_cast<CGLContextObj>(stub_->decoder()->GetGLContext()->GetHandle()), |
| make_context_current_)); |
| - if (!video_decode_accelerator_) { |
| - SendCreateDecoderReply(init_done_msg, false); |
| - return; |
| - } |
| -#elif defined(OS_ANDROID) |
| - video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( |
| +#endif |
| + return decoder.Pass(); |
| +} |
| + |
| +scoped_ptr<media::VideoDecodeAccelerator> |
| +GpuVideoDecodeAccelerator::CreateAndroidDecoder() { |
| + scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| +#if defined(OS_ANDROID) |
| + decoder.reset(new AndroidVideoDecodeAccelerator( |
| stub_->decoder()->AsWeakPtr(), |
| make_context_current_)); |
| -#else |
| - NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| - SendCreateDecoderReply(init_done_msg, false); |
| - return; |
| #endif |
| + return decoder.Pass(); |
| +} |
| - if (video_decode_accelerator_->CanDecodeOnIOThread()) { |
| - filter_ = new MessageFilter(this, host_route_id_); |
| - stub_->channel()->AddFilter(filter_.get()); |
| - } |
| - |
| - if (!video_decode_accelerator_->Initialize(profile, this)) { |
| - SendCreateDecoderReply(init_done_msg, false); |
| - return; |
| - } |
| - |
| - SendCreateDecoderReply(init_done_msg, true); |
| +scoped_ptr<media::VideoDecodeAccelerator> |
| +GpuVideoDecodeAccelerator::CreateOzoneDecoder() { |
| + scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| +#if defined(USE_OZONE) |
| + media::MediaOzonePlatform* platform = |
| + media::MediaOzonePlatform::GetInstance(); |
| + decoder.reset(platform->CreateVideoDecodeAccelerator(make_context_current_)); |
| +#endif |
| + return decoder.Pass(); |
| } |
| // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |