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 |
| 230 bool GpuVideoDecodeAccelerator::InitialDecoder( | |
| 231 const media::VideoCodecProfile profile) { | |
| 232 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
| 233 filter_ = new MessageFilter(this, host_route_id_); | |
| 234 stub_->channel()->AddFilter(filter_.get()); | |
|
Pawel Osciak
2014/12/26 01:11:35
Unless I'm missing something, if vda->Initialize()
henryhsu
2014/12/26 08:40:40
I'd like to move AddFilter after VDA initialize. T
| |
| 235 } | |
| 236 | |
| 237 return video_decode_accelerator_->Initialize(profile, this); | |
| 238 } | |
| 239 | |
| 228 void GpuVideoDecodeAccelerator::Initialize( | 240 void GpuVideoDecodeAccelerator::Initialize( |
| 229 const media::VideoCodecProfile profile, | 241 const media::VideoCodecProfile profile, |
| 230 IPC::Message* init_done_msg) { | 242 IPC::Message* init_done_msg) { |
| 231 DCHECK(!video_decode_accelerator_.get()); | 243 DCHECK(!video_decode_accelerator_.get()); |
| 232 | 244 |
| 233 if (!stub_->channel()->AddRoute(host_route_id_, this)) { | 245 if (!stub_->channel()->AddRoute(host_route_id_, this)) { |
| 234 DLOG(ERROR) << "GpuVideoDecodeAccelerator::Initialize(): " | 246 DLOG(ERROR) << "GpuVideoDecodeAccelerator::Initialize(): " |
| 235 "failed to add route"; | 247 "failed to add route"; |
| 236 SendCreateDecoderReply(init_done_msg, false); | 248 SendCreateDecoderReply(init_done_msg, false); |
| 237 } | 249 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 252 return; | 264 return; |
| 253 } | 265 } |
| 254 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | 266 DVLOG(0) << "Initializing DXVA HW decoder for windows."; |
| 255 video_decode_accelerator_.reset( | 267 video_decode_accelerator_.reset( |
| 256 new DXVAVideoDecodeAccelerator(make_context_current_)); | 268 new DXVAVideoDecodeAccelerator(make_context_current_)); |
| 257 #elif defined(OS_MACOSX) | 269 #elif defined(OS_MACOSX) |
| 258 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( | 270 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( |
| 259 static_cast<CGLContextObj>( | 271 static_cast<CGLContextObj>( |
| 260 stub_->decoder()->GetGLContext()->GetHandle()), | 272 stub_->decoder()->GetGLContext()->GetHandle()), |
| 261 make_context_current_)); | 273 make_context_current_)); |
| 262 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 274 #elif defined(OS_CHROMEOS) && defined(USE_X11) |
| 263 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 275 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
| 264 if (!device.get()) { | 276 if (device.get()) { |
| 265 SendCreateDecoderReply(init_done_msg, false); | 277 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( |
| 266 return; | 278 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| 279 stub_->decoder()->GetGLContext()->GetHandle(), | |
| 280 weak_factory_for_io_.GetWeakPtr(), | |
| 281 make_context_current_, | |
| 282 device.Pass(), | |
| 283 io_message_loop_)); | |
| 267 } | 284 } |
| 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) | 285 #elif defined(USE_OZONE) |
| 287 media::MediaOzonePlatform* platform = | 286 media::MediaOzonePlatform* platform = |
| 288 media::MediaOzonePlatform::GetInstance(); | 287 media::MediaOzonePlatform::GetInstance(); |
| 289 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( | 288 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( |
| 290 make_context_current_)); | 289 make_context_current_)); |
| 291 if (!video_decode_accelerator_) { | 290 if (!video_decode_accelerator_) { |
| 292 SendCreateDecoderReply(init_done_msg, false); | 291 SendCreateDecoderReply(init_done_msg, false); |
| 293 return; | 292 return; |
| 294 } | 293 } |
| 295 #elif defined(OS_ANDROID) | 294 #elif defined(OS_ANDROID) |
| 296 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | 295 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( |
| 297 stub_->decoder()->AsWeakPtr(), | 296 stub_->decoder()->AsWeakPtr(), |
| 298 make_context_current_)); | 297 make_context_current_)); |
| 299 #else | 298 #else |
| 300 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 299 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| 301 SendCreateDecoderReply(init_done_msg, false); | 300 SendCreateDecoderReply(init_done_msg, false); |
| 302 return; | 301 return; |
| 303 #endif | 302 #endif |
| 304 | 303 |
| 305 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | 304 if (video_decode_accelerator_.get() && InitialDecoder(profile)) { |
| 306 filter_ = new MessageFilter(this, host_route_id_); | 305 SendCreateDecoderReply(init_done_msg, true); |
| 307 stub_->channel()->AddFilter(filter_.get()); | 306 return; |
| 308 } | 307 } |
| 309 | 308 |
| 310 if (!video_decode_accelerator_->Initialize(profile, this)) { | 309 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) |
|
Pawel Osciak
2014/12/26 01:11:35
What's the latency of failing to create a V4L2 dec
henryhsu
2014/12/26 08:40:40
I tested on Squawks and the latency is 149 microse
| |
| 310 // X86 platforms try V4L2 device first. If V4L2 device initialization fails, | |
| 311 // try VAAPI device again. | |
| 312 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | |
| 313 VLOG(1) << "HW video decode acceleration not available without " | |
| 314 "DesktopGL (GLX)."; | |
| 311 SendCreateDecoderReply(init_done_msg, false); | 315 SendCreateDecoderReply(init_done_msg, false); |
| 312 return; | 316 return; |
| 313 } | 317 } |
| 318 gfx::GLContextGLX* glx_context = | |
| 319 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | |
| 320 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( | |
| 321 glx_context->display(), make_context_current_)); | |
| 314 | 322 |
| 315 SendCreateDecoderReply(init_done_msg, true); | 323 if (InitialDecoder(profile)) { |
| 324 SendCreateDecoderReply(init_done_msg, true); | |
| 325 return; | |
| 326 } | |
| 327 | |
| 328 SendCreateDecoderReply(init_done_msg, false); | |
| 329 #endif | |
| 316 } | 330 } |
| 317 | 331 |
| 318 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 332 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
| 319 // true, otherwise on the main thread. | 333 // true, otherwise on the main thread. |
| 320 void GpuVideoDecodeAccelerator::OnDecode( | 334 void GpuVideoDecodeAccelerator::OnDecode( |
| 321 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 335 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
| 322 DCHECK(video_decode_accelerator_.get()); | 336 DCHECK(video_decode_accelerator_.get()); |
| 323 if (id < 0) { | 337 if (id < 0) { |
| 324 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; | 338 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
| 325 if (child_message_loop_->BelongsToCurrentThread()) { | 339 if (child_message_loop_->BelongsToCurrentThread()) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 return stub_->channel()->Send(message); | 528 return stub_->channel()->Send(message); |
| 515 } | 529 } |
| 516 | 530 |
| 517 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, | 531 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, |
| 518 bool succeeded) { | 532 bool succeeded) { |
| 519 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); | 533 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); |
| 520 Send(message); | 534 Send(message); |
| 521 } | 535 } |
| 522 | 536 |
| 523 } // namespace content | 537 } // namespace content |
| OLD | NEW |