| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 240 |
| 239 #if !defined(OS_WIN) | 241 #if !defined(OS_WIN) |
| 240 // 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 |
| 241 // non-Windows VDAs. | 243 // non-Windows VDAs. |
| 242 if (!make_context_current_.Run()) { | 244 if (!make_context_current_.Run()) { |
| 243 SendCreateDecoderReply(init_done_msg, false); | 245 SendCreateDecoderReply(init_done_msg, false); |
| 244 return; | 246 return; |
| 245 } | 247 } |
| 246 #endif | 248 #endif |
| 247 | 249 |
| 248 #if defined(OS_WIN) | 250 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> |
| 249 if (base::win::GetVersion() < base::win::VERSION_WIN7) { | 251 create_vda_cbs = CreateVDACbs(); |
| 250 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | 252 |
| 251 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); |
| 252 return; | 264 return; |
| 253 } | 265 } |
| 254 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | 266 video_decode_accelerator_.reset(); |
| 255 video_decode_accelerator_.reset( | 267 NOTIMPLEMENTED() << "HW video decode acceleration not available."; |
| 256 new DXVAVideoDecodeAccelerator(make_context_current_)); | 268 SendCreateDecoderReply(init_done_msg, false); |
| 257 #elif defined(OS_MACOSX) | 269 } |
| 258 video_decode_accelerator_.reset(new VTVideoDecodeAccelerator( | 270 |
| 259 static_cast<CGLContextObj>( | 271 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> |
| 260 stub_->decoder()->GetGLContext()->GetHandle()), | 272 GpuVideoDecodeAccelerator::CreateVDACbs() { |
| 261 make_context_current_)); | 273 std::vector<GpuVideoDecodeAccelerator::CreateVDACb> create_vda_cbs; |
| 262 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) | 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::CreateAndroidVDA, |
| 284 base::Unretained(this))); |
| 285 create_vda_cbs.push_back(base::Bind( |
| 286 &GpuVideoDecodeAccelerator::CreateOzoneVDA, 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_X11) && \ |
| 308 (defined(ARCH_CPU_X86_FAMILY) || defined(ARCH_CPU_ARMEL)) |
| 263 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | 309 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); |
| 264 if (!device.get()) { | 310 if (device.get()) { |
| 265 SendCreateDecoderReply(init_done_msg, false); | 311 decoder.reset(new V4L2VideoDecodeAccelerator( |
| 266 return; | 312 gfx::GLSurfaceEGL::GetHardwareDisplay(), |
| 313 stub_->decoder()->GetGLContext()->GetHandle(), |
| 314 weak_factory_for_io_.GetWeakPtr(), |
| 315 make_context_current_, |
| 316 device.Pass(), |
| 317 io_message_loop_)); |
| 267 } | 318 } |
| 268 video_decode_accelerator_.reset(new V4L2VideoDecodeAccelerator( | 319 #endif |
| 269 gfx::GLSurfaceEGL::GetHardwareDisplay(), | 320 return decoder.Pass(); |
| 270 stub_->decoder()->GetGLContext()->GetHandle(), | 321 } |
| 271 weak_factory_for_io_.GetWeakPtr(), | 322 |
| 272 make_context_current_, | 323 scoped_ptr<media::VideoDecodeAccelerator> |
| 273 device.Pass(), | 324 GpuVideoDecodeAccelerator::CreateVaapiVDA() { |
| 274 io_message_loop_)); | 325 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 275 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11) | 326 #if defined(OS_CHROMEOS) && defined(USE_X11) && defined(ARCH_CPU_X86_FAMILY) |
| 276 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { | 327 if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
| 277 VLOG(1) << "HW video decode acceleration not available without " | 328 VLOG(1) << "HW video decode acceleration not available without " |
| 278 "DesktopGL (GLX)."; | 329 "DesktopGL (GLX)."; |
| 279 SendCreateDecoderReply(init_done_msg, false); | 330 return decoder.Pass(); |
| 280 return; | |
| 281 } | 331 } |
| 282 gfx::GLContextGLX* glx_context = | 332 gfx::GLContextGLX* glx_context = |
| 283 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); | 333 static_cast<gfx::GLContextGLX*>(stub_->decoder()->GetGLContext()); |
| 284 video_decode_accelerator_.reset(new VaapiVideoDecodeAccelerator( | 334 decoder.reset(new VaapiVideoDecodeAccelerator( |
| 285 glx_context->display(), make_context_current_)); | 335 glx_context->display(), make_context_current_)); |
| 286 #elif defined(USE_OZONE) | 336 #endif |
| 337 return decoder.Pass(); |
| 338 } |
| 339 |
| 340 scoped_ptr<media::VideoDecodeAccelerator> |
| 341 GpuVideoDecodeAccelerator::CreateVTVDA() { |
| 342 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 343 #if defined(OS_MACOSX) |
| 344 decoder.reset(new VTVideoDecodeAccelerator( |
| 345 static_cast<CGLContextObj>(stub_->decoder()->GetGLContext()->GetHandle()), |
| 346 make_context_current_)); |
| 347 #endif |
| 348 return decoder.Pass(); |
| 349 } |
| 350 |
| 351 scoped_ptr<media::VideoDecodeAccelerator> |
| 352 GpuVideoDecodeAccelerator::CreateAndroidVDA() { |
| 353 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 354 #if defined(OS_ANDROID) |
| 355 decoder.reset(new AndroidVideoDecodeAccelerator( |
| 356 stub_->decoder()->AsWeakPtr(), |
| 357 make_context_current_)); |
| 358 #endif |
| 359 return decoder.Pass(); |
| 360 } |
| 361 |
| 362 scoped_ptr<media::VideoDecodeAccelerator> |
| 363 GpuVideoDecodeAccelerator::CreateOzoneVDA() { |
| 364 scoped_ptr<media::VideoDecodeAccelerator> decoder; |
| 365 #if defined(USE_OZONE) |
| 287 media::MediaOzonePlatform* platform = | 366 media::MediaOzonePlatform* platform = |
| 288 media::MediaOzonePlatform::GetInstance(); | 367 media::MediaOzonePlatform::GetInstance(); |
| 289 video_decode_accelerator_.reset(platform->CreateVideoDecodeAccelerator( | 368 decoder.reset(platform->CreateVideoDecodeAccelerator(make_context_current_)); |
| 290 make_context_current_)); | |
| 291 if (!video_decode_accelerator_) { | |
| 292 SendCreateDecoderReply(init_done_msg, false); | |
| 293 return; | |
| 294 } | |
| 295 #elif defined(OS_ANDROID) | |
| 296 video_decode_accelerator_.reset(new AndroidVideoDecodeAccelerator( | |
| 297 stub_->decoder()->AsWeakPtr(), | |
| 298 make_context_current_)); | |
| 299 #else | |
| 300 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
| 301 SendCreateDecoderReply(init_done_msg, false); | |
| 302 return; | |
| 303 #endif | 369 #endif |
| 304 | 370 return decoder.Pass(); |
| 305 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
| 306 filter_ = new MessageFilter(this, host_route_id_); | |
| 307 stub_->channel()->AddFilter(filter_.get()); | |
| 308 } | |
| 309 | |
| 310 if (!video_decode_accelerator_->Initialize(profile, this)) { | |
| 311 SendCreateDecoderReply(init_done_msg, false); | |
| 312 return; | |
| 313 } | |
| 314 | |
| 315 SendCreateDecoderReply(init_done_msg, true); | |
| 316 } | 371 } |
| 317 | 372 |
| 318 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 373 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is |
| 319 // true, otherwise on the main thread. | 374 // true, otherwise on the main thread. |
| 320 void GpuVideoDecodeAccelerator::OnDecode( | 375 void GpuVideoDecodeAccelerator::OnDecode( |
| 321 base::SharedMemoryHandle handle, int32 id, uint32 size) { | 376 base::SharedMemoryHandle handle, int32 id, uint32 size) { |
| 322 DCHECK(video_decode_accelerator_.get()); | 377 DCHECK(video_decode_accelerator_.get()); |
| 323 if (id < 0) { | 378 if (id < 0) { |
| 324 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; | 379 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range"; |
| 325 if (child_message_loop_->BelongsToCurrentThread()) { | 380 if (child_message_loop_->BelongsToCurrentThread()) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 return stub_->channel()->Send(message); | 569 return stub_->channel()->Send(message); |
| 515 } | 570 } |
| 516 | 571 |
| 517 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, | 572 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message, |
| 518 bool succeeded) { | 573 bool succeeded) { |
| 519 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); | 574 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded); |
| 520 Send(message); | 575 Send(message); |
| 521 } | 576 } |
| 522 | 577 |
| 523 } // namespace content | 578 } // namespace content |
| OLD | NEW |