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 14 matching lines...) Expand all Loading... | |
| 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) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) |
| 32 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | 32 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" |
| 33 #include "content/common/gpu/media/v4l2_video_device.h" | 33 #include "content/common/gpu/media/v4l2_video_device.h" |
| 34 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 34 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
| 35 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | |
| 36 #include "content/common/gpu/media/v4l2_video_device.h" | |
| 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_context_glx.h" | 38 #include "ui/gl/gl_context_glx.h" |
| 37 #include "ui/gl/gl_implementation.h" | 39 #include "ui/gl/gl_implementation.h" |
| 38 #elif defined(USE_OZONE) | 40 #elif defined(USE_OZONE) |
| 39 #include "media/ozone/media_ozone_platform.h" | 41 #include "media/ozone/media_ozone_platform.h" |
| 40 #elif defined(OS_ANDROID) | 42 #elif defined(OS_ANDROID) |
| 41 #include "content/common/gpu/media/android_video_decode_accelerator.h" | 43 #include "content/common/gpu/media/android_video_decode_accelerator.h" |
| 42 #endif | 44 #endif |
| 43 | 45 |
| 44 #include "ui/gfx/size.h" | 46 #include "ui/gfx/size.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 220 |
| 219 void GpuVideoDecodeAccelerator::NotifyError( | 221 void GpuVideoDecodeAccelerator::NotifyError( |
| 220 media::VideoDecodeAccelerator::Error error) { | 222 media::VideoDecodeAccelerator::Error error) { |
| 221 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( | 223 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification( |
| 222 host_route_id_, error))) { | 224 host_route_id_, error))) { |
| 223 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " | 225 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) " |
| 224 << "failed"; | 226 << "failed"; |
| 225 } | 227 } |
| 226 } | 228 } |
| 227 | 229 |
| 228 void GpuVideoDecodeAccelerator::Initialize( | 230 void GpuVideoDecodeAccelerator::Initialize( |
|
Pawel Osciak
2014/12/28 23:28:01
Please document the behavior of this method.
henryhsu
2014/12/29 09:43:26
described in header file.
| |
| 229 const media::VideoCodecProfile profile, | 231 const media::VideoCodecProfile profile, |
| 230 IPC::Message* init_done_msg) { | 232 IPC::Message* init_done_msg) { |
| 231 DCHECK(!video_decode_accelerator_.get()); | 233 DCHECK(!video_decode_accelerator_.get()); |
| 232 | 234 |
| 233 if (!stub_->channel()->AddRoute(host_route_id_, this)) { | 235 if (!stub_->channel()->AddRoute(host_route_id_, this)) { |
| 234 DLOG(ERROR) << "GpuVideoDecodeAccelerator::Initialize(): " | 236 DLOG(ERROR) << "GpuVideoDecodeAccelerator::Initialize(): " |
| 235 "failed to add route"; | 237 "failed to add route"; |
| 236 SendCreateDecoderReply(init_done_msg, false); | 238 SendCreateDecoderReply(init_done_msg, false); |
| 237 } | 239 } |
| 238 | 240 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 252 return; | 254 return; |
| 253 } | 255 } |
| 254 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | 256 DVLOG(0) << "Initializing DXVA HW decoder for windows."; |
| 255 video_decode_accelerator_.reset( | 257 video_decode_accelerator_.reset( |
| 256 new DXVAVideoDecodeAccelerator(make_context_current_)); | 258 new DXVAVideoDecodeAccelerator(make_context_current_)); |
| 257 #elif defined(OS_MACOSX) | 259 #elif defined(OS_MACOSX) |
| 258 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( | 260 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( |
| 259 static_cast<CGLContextObj>( | 261 static_cast<CGLContextObj>( |
| 260 stub_->decoder()->GetGLContext()->GetHandle()), | 262 stub_->decoder()->GetGLContext()->GetHandle()), |
| 261 make_context_current_)); | 263 make_context_current_)); |
| 262 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 264 #elif defined(OS_CHROMEOS) && defined(USE_X11) && \ |
| 265 (defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARMEL)) | |
|
Pawel Osciak
2014/12/28 23:28:02
I don't think it would hurt to not check for arch
henryhsu
2014/12/29 09:43:26
How to check we have EGL? I think we cannot use 'g
Pawel Osciak
2014/12/30 06:14:38
We'll have a separate CL for this, so we can skip
| |
| 263 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 266 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
| 264 if (!device.get()) { | 267 if (device.get()) { |
| 265 SendCreateDecoderReply(init_done_msg, false); | 268 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( |
| 266 return; | 269 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| 270 stub_->decoder()->GetGLContext()->GetHandle(), | |
| 271 weak_factory_for_io_.GetWeakPtr(), | |
| 272 make_context_current_, | |
| 273 device.Pass(), | |
| 274 io_message_loop_)); | |
| 267 } | 275 } |
| 268 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( | |
| 269 gfx::GLSurfaceEGL::GetHardwareDisplay(), | |
| 270 stub_->decoder()->GetGLContext()->GetHandle(), | |
| 271 weak_factory_for_io_.GetWeakPtr(), | |
| 272 make_context_current_, | |
| 273 device.Pass(), | |
| 274 io_message_loop_)); | |
| 275 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | |
| 276 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | |
| 277 VLOG(1) << "HW video decode acceleration not available without " | |
| 278 "DesktopGL (GLX)."; | |
| 279 SendCreateDecoderReply(init_done_msg, false); | |
| 280 return; | |
| 281 } | |
| 282 gfx::GLContextGLX* glx_context = | |
| 283 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | |
| 284 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( | |
| 285 glx_context->display(), make_context_current_)); | |
| 286 #elif defined(USE_OZONE) | 276 #elif defined(USE_OZONE) |
| 287 media::MediaOzonePlatform* platform = | 277 media::MediaOzonePlatform* platform = |
| 288 media::MediaOzonePlatform::GetInstance(); | 278 media::MediaOzonePlatform::GetInstance(); |
| 289 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( | 279 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( |
| 290 make_context_current_)); | 280 make_context_current_)); |
| 291 if (!video_decode_accelerator_) { | 281 if (!video_decode_accelerator_) { |
| 292 SendCreateDecoderReply(init_done_msg, false); | 282 SendCreateDecoderReply(init_done_msg, false); |
| 293 return; | 283 return; |
| 294 } | 284 } |
| 295 #elif defined(OS_ANDROID) | 285 #elif defined(OS_ANDROID) |
| 296 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | 286 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( |
| 297 stub_->decoder()->AsWeakPtr(), | 287 stub_->decoder()->AsWeakPtr(), |
| 298 make_context_current_)); | 288 make_context_current_)); |
| 299 #else | 289 #else |
| 300 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 290 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| 301 SendCreateDecoderReply(init_done_msg, false); | 291 SendCreateDecoderReply(init_done_msg, false); |
| 302 return; | 292 return; |
| 303 #endif | 293 #endif |
| 304 | 294 |
| 305 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | 295 if (InitializeDecoder(profile)) { |
|
Pawel Osciak
2014/12/28 23:28:02
I think the code would be simpler and more extensi
henryhsu
2014/12/29 09:43:26
yes. But ScopedVector does not support DefaultDele
| |
| 306 filter_ = new MessageFilter(this, host_route_id_); | 296 SendCreateDecoderReply(init_done_msg, true); |
| 307 stub_->channel()->AddFilter(filter_.get()); | 297 return; |
| 308 } | 298 } |
| 309 | 299 |
| 310 if (!video_decode_accelerator_->Initialize(profile, this)) { | 300 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
| 301 // X86 platforms try V4L2 device first. If V4L2 device initialization fails, | |
|
Pawel Osciak
2014/12/28 23:28:02
s/X86/x86/
s/V4L2 device/V4L2 VDA/
henryhsu
2014/12/29 09:43:26
Done.
| |
| 302 // try VAAPI device again. | |
|
Pawel Osciak
2014/12/28 23:28:01
s/VAAPI device/VAAPI VDA/
s/ again//
henryhsu
2014/12/29 09:43:26
Done.
| |
| 303 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | |
| 304 VLOG(1) << "HW video decode acceleration not available without " | |
| 305 "DesktopGL (GLX)."; | |
| 311 SendCreateDecoderReply(init_done_msg, false); | 306 SendCreateDecoderReply(init_done_msg, false); |
| 312 return; | 307 return; |
| 313 } | 308 } |
| 309 gfx::GLContextGLX* glx_context = | |
| 310 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | |
| 311 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( | |
| 312 glx_context->display(), make_context_current_)); | |
| 314 | 313 |
| 315 SendCreateDecoderReply(init_done_msg, true); | 314 if (InitializeDecoder(profile)) { |
| 315 SendCreateDecoderReply(init_done_msg, true); | |
| 316 return; | |
| 317 } | |
| 318 #endif | |
| 319 SendCreateDecoderReply(init_done_msg, false); | |
| 320 } | |
| 321 | |
| 322 bool GpuVideoDecodeAccelerator::InitializeDecoder( | |
| 323 media::VideoCodecProfile profile) { | |
| 324 if (video_decode_accelerator_.get() && | |
| 325 video_decode_accelerator_->Initialize(profile, this)) { | |
| 326 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
|
Pawel Osciak
2014/12/28 23:28:01
if (!vda_.get() || !vda_->Initialize())
return f
henryhsu
2014/12/29 09:43:26
Done.
| |
| 327 filter_ = new MessageFilter(this, host_route_id_); | |
| 328 stub_->channel()->AddFilter(filter_.get()); | |
| 329 } | |
| 330 return true; | |
| 331 } | |
| 332 return false; | |
| 316 } | 333 } |
| 317 | 334 |
| 318 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 335 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
| 319 // true, otherwise on the main thread. | 336 // true, otherwise on the main thread. |
| 320 void GpuVideoDecodeAccelerator::OnDecode( | 337 void GpuVideoDecodeAccelerator::OnDecode( |
| 321 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 338 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
| 322 DCHECK(video_decode_accelerator_.get()); | 339 DCHECK(video_decode_accelerator_.get()); |
| 323 if (id < 0) { | 340 if (id < 0) { |
| 324 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; | 341 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
| 325 if (child_message_loop_->BelongsToCurrentThread()) { | 342 if (child_message_loop_->BelongsToCurrentThread()) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 return stub_->channel()->Send(message); | 531 return stub_->channel()->Send(message); |
| 515 } | 532 } |
| 516 | 533 |
| 517 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, | 534 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, |
| 518 bool succeeded) { | 535 bool succeeded) { |
| 519 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); | 536 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); |
| 520 Send(message); | 537 Send(message); |
| 521 } | 538 } |
| 522 | 539 |
| 523 } // namespace content | 540 } // namespace content |
| OLD | NEW |