| 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/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 | 17 |
| 18 #include "content/common/gpu/gpu_channel.h" | 18 #include "content/common/gpu/gpu_channel.h" |
| 19 #include "content/common/gpu/gpu_channel_manager.h" | 19 #include "content/common/gpu/gpu_channel_manager.h" |
| 20 #include "content/common/gpu/media/gpu_video_accelerator_util.h" | 20 #include "content/common/gpu/media/gpu_video_accelerator_util.h" |
| 21 #include "content/common/gpu/media/gpu_video_decode_accelerator_factory_impl.h" |
| 21 #include "content/common/gpu/media/media_messages.h" | 22 #include "content/common/gpu/media/media_messages.h" |
| 22 #include "gpu/command_buffer/common/command_buffer.h" | 23 #include "gpu/command_buffer/common/command_buffer.h" |
| 23 #include "gpu/command_buffer/service/gpu_preferences.h" | |
| 24 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
| 25 #include "ipc/ipc_message_utils.h" | 25 #include "ipc/ipc_message_utils.h" |
| 26 #include "ipc/message_filter.h" | 26 #include "ipc/message_filter.h" |
| 27 #include "media/base/limits.h" | 27 #include "media/base/limits.h" |
| 28 #include "ui/gl/gl_context.h" | 28 #include "ui/gl/gl_context.h" |
| 29 #include "ui/gl/gl_image.h" | 29 #include "ui/gl/gl_image.h" |
| 30 #include "ui/gl/gl_surface_egl.h" | |
| 31 | |
| 32 #if defined(OS_WIN) | |
| 33 #include "base/win/windows_version.h" | |
| 34 #include "content/common/gpu/media/dxva_video_decode_accelerator_win.h" | |
| 35 #elif defined(OS_MACOSX) | |
| 36 #include "content/common/gpu/media/vt_video_decode_accelerator_mac.h" | |
| 37 #elif defined(OS_CHROMEOS) | |
| 38 #if defined(USE_V4L2_CODEC) | |
| 39 #include "content/common/gpu/media/v4l2_device.h" | |
| 40 #include "content/common/gpu/media/v4l2_slice_video_decode_accelerator.h" | |
| 41 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | |
| 42 #endif | |
| 43 #if defined(ARCH_CPU_X86_FAMILY) | |
| 44 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | |
| 45 #include "ui/gl/gl_implementation.h" | |
| 46 #endif | |
| 47 #elif defined(USE_OZONE) | |
| 48 #include "media/ozone/media_ozone_platform.h" | |
| 49 #elif defined(OS_ANDROID) | |
| 50 #include "content/common/gpu/media/android_video_decode_accelerator.h" | |
| 51 #endif | |
| 52 | |
| 53 #include "ui/gfx/geometry/size.h" | 30 #include "ui/gfx/geometry/size.h" |
| 54 | 31 |
| 55 namespace content { | 32 namespace content { |
| 56 | 33 |
| 34 namespace { |
| 35 static gfx::GLContext* GetGLContext( |
| 36 const base::WeakPtr<GpuCommandBufferStub>& stub) { |
| 37 if (!stub) { |
| 38 DLOG(ERROR) << "Stub is gone; no GLContext."; |
| 39 return nullptr; |
| 40 } |
| 41 |
| 42 return stub->decoder()->GetGLContext(); |
| 43 } |
| 44 |
| 57 static bool MakeDecoderContextCurrent( | 45 static bool MakeDecoderContextCurrent( |
| 58 const base::WeakPtr<GpuCommandBufferStub> stub) { | 46 const base::WeakPtr<GpuCommandBufferStub>& stub) { |
| 59 if (!stub) { | 47 if (!stub) { |
| 60 DLOG(ERROR) << "Stub is gone; won't MakeCurrent()."; | 48 DLOG(ERROR) << "Stub is gone; won't MakeCurrent()."; |
| 61 return false; | 49 return false; |
| 62 } | 50 } |
| 63 | 51 |
| 64 if (!stub->decoder()->MakeCurrent()) { | 52 if (!stub->decoder()->MakeCurrent()) { |
| 65 DLOG(ERROR) << "Failed to MakeCurrent()"; | 53 DLOG(ERROR) << "Failed to MakeCurrent()"; |
| 66 return false; | 54 return false; |
| 67 } | 55 } |
| 68 | 56 |
| 69 return true; | 57 return true; |
| 70 } | 58 } |
| 71 | 59 |
| 60 #if (defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)) || defined(OS_MACOSX) |
| 61 static bool BindImage(const base::WeakPtr<GpuCommandBufferStub>& stub, |
| 62 uint32_t client_texture_id, |
| 63 uint32_t texture_target, |
| 64 const scoped_refptr<gl::GLImage>& image) { |
| 65 if (!stub) { |
| 66 DLOG(ERROR) << "Stub is gone; won't BindImage()."; |
| 67 return false; |
| 68 } |
| 69 |
| 70 gpu::gles2::GLES2Decoder* command_decoder = stub->decoder(); |
| 71 gpu::gles2::TextureManager* texture_manager = |
| 72 command_decoder->GetContextGroup()->texture_manager(); |
| 73 gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id); |
| 74 if (ref) { |
| 75 texture_manager->SetLevelImage(ref, texture_target, 0, image.get(), |
| 76 gpu::gles2::Texture::BOUND); |
| 77 } |
| 78 |
| 79 return true; |
| 80 } |
| 81 #endif |
| 82 |
| 83 static base::WeakPtr<gpu::gles2::GLES2Decoder> GetGLES2Decoder( |
| 84 const base::WeakPtr<GpuCommandBufferStub>& stub) { |
| 85 if (!stub) { |
| 86 DLOG(ERROR) << "Stub is gone; no GLES2Decoder."; |
| 87 return base::WeakPtr<gpu::gles2::GLES2Decoder>(); |
| 88 } |
| 89 |
| 90 return stub->decoder()->AsWeakPtr(); |
| 91 } |
| 92 } // anonymous namespace |
| 93 |
| 72 // DebugAutoLock works like AutoLock but only acquires the lock when | 94 // DebugAutoLock works like AutoLock but only acquires the lock when |
| 73 // DCHECK is on. | 95 // DCHECK is on. |
| 74 #if DCHECK_IS_ON() | 96 #if DCHECK_IS_ON() |
| 75 typedef base::AutoLock DebugAutoLock; | 97 typedef base::AutoLock DebugAutoLock; |
| 76 #else | 98 #else |
| 77 class DebugAutoLock { | 99 class DebugAutoLock { |
| 78 public: | 100 public: |
| 79 explicit DebugAutoLock(base::Lock&) {} | 101 explicit DebugAutoLock(base::Lock&) {} |
| 80 }; | 102 }; |
| 81 #endif | 103 #endif |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) | 155 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 134 : host_route_id_(host_route_id), | 156 : host_route_id_(host_route_id), |
| 135 stub_(stub), | 157 stub_(stub), |
| 136 texture_target_(0), | 158 texture_target_(0), |
| 137 filter_removed_(true, false), | 159 filter_removed_(true, false), |
| 138 child_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 160 child_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 139 io_task_runner_(io_task_runner), | 161 io_task_runner_(io_task_runner), |
| 140 weak_factory_for_io_(this) { | 162 weak_factory_for_io_(this) { |
| 141 DCHECK(stub_); | 163 DCHECK(stub_); |
| 142 stub_->AddDestructionObserver(this); | 164 stub_->AddDestructionObserver(this); |
| 143 make_context_current_ = | 165 get_gl_context_cb_ = base::Bind(&GetGLContext, stub_->AsWeakPtr()); |
| 166 make_context_current_cb_ = |
| 144 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); | 167 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); |
| 168 #if (defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)) || defined(OS_MACOSX) |
| 169 bind_image_cb_ = base::Bind(&BindImage, stub_->AsWeakPtr()); |
| 170 #endif |
| 171 get_gles2_decoder_cb_ = base::Bind(&GetGLES2Decoder, stub_->AsWeakPtr()); |
| 145 } | 172 } |
| 146 | 173 |
| 147 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { | 174 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { |
| 148 // This class can only be self-deleted from OnWillDestroyStub(), which means | 175 // This class can only be self-deleted from OnWillDestroyStub(), which means |
| 149 // the VDA has already been destroyed in there. | 176 // the VDA has already been destroyed in there. |
| 150 DCHECK(!video_decode_accelerator_); | 177 DCHECK(!video_decode_accelerator_); |
| 151 } | 178 } |
| 152 | 179 |
| 153 // static | 180 // static |
| 154 gpu::VideoDecodeAcceleratorCapabilities | 181 gpu::VideoDecodeAcceleratorCapabilities |
| 155 GpuVideoDecodeAccelerator::GetCapabilities( | 182 GpuVideoDecodeAccelerator::GetCapabilities( |
| 156 const gpu::GpuPreferences& gpu_preferences) { | 183 const gpu::GpuPreferences& gpu_preferences) { |
| 157 media::VideoDecodeAccelerator::Capabilities capabilities; | 184 return GpuVideoDecodeAcceleratorFactoryImpl::GetDecoderCapabilities( |
| 158 if (gpu_preferences.disable_accelerated_video_decode) | 185 gpu_preferences); |
| 159 return gpu::VideoDecodeAcceleratorCapabilities(); | |
| 160 | |
| 161 // Query supported profiles for each VDA. The order of querying VDAs should | |
| 162 // be the same as the order of initializing VDAs. Then the returned profile | |
| 163 // can be initialized by corresponding VDA successfully. | |
| 164 #if defined(OS_WIN) | |
| 165 capabilities.supported_profiles = | |
| 166 DXVAVideoDecodeAccelerator::GetSupportedProfiles(); | |
| 167 #elif defined(OS_CHROMEOS) | |
| 168 media::VideoDecodeAccelerator::SupportedProfiles vda_profiles; | |
| 169 #if defined(USE_V4L2_CODEC) | |
| 170 vda_profiles = V4L2VideoDecodeAccelerator::GetSupportedProfiles(); | |
| 171 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles( | |
| 172 vda_profiles, &capabilities.supported_profiles); | |
| 173 vda_profiles = V4L2SliceVideoDecodeAccelerator::GetSupportedProfiles(); | |
| 174 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles( | |
| 175 vda_profiles, &capabilities.supported_profiles); | |
| 176 #endif | |
| 177 #if defined(ARCH_CPU_X86_FAMILY) | |
| 178 vda_profiles = VaapiVideoDecodeAccelerator::GetSupportedProfiles(); | |
| 179 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles( | |
| 180 vda_profiles, &capabilities.supported_profiles); | |
| 181 #endif | |
| 182 #elif defined(OS_MACOSX) | |
| 183 capabilities.supported_profiles = | |
| 184 VTVideoDecodeAccelerator::GetSupportedProfiles(); | |
| 185 #elif defined(OS_ANDROID) | |
| 186 capabilities = AndroidVideoDecodeAccelerator::GetCapabilities(); | |
| 187 #endif | |
| 188 return GpuVideoAcceleratorUtil::ConvertMediaToGpuDecodeCapabilities( | |
| 189 capabilities); | |
| 190 } | 186 } |
| 191 | 187 |
| 192 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { | 188 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) { |
| 193 if (!video_decode_accelerator_) | 189 if (!video_decode_accelerator_) |
| 194 return false; | 190 return false; |
| 195 | 191 |
| 196 bool handled = true; | 192 bool handled = true; |
| 197 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) | 193 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg) |
| 198 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_SetCdm, OnSetCdm) | 194 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_SetCdm, OnSetCdm) |
| 199 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) | 195 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 318 |
| 323 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { | 319 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { |
| 324 if (filter_ && io_task_runner_->BelongsToCurrentThread()) | 320 if (filter_ && io_task_runner_->BelongsToCurrentThread()) |
| 325 return filter_->SendOnIOThread(message); | 321 return filter_->SendOnIOThread(message); |
| 326 DCHECK(child_task_runner_->BelongsToCurrentThread()); | 322 DCHECK(child_task_runner_->BelongsToCurrentThread()); |
| 327 return stub_->channel()->Send(message); | 323 return stub_->channel()->Send(message); |
| 328 } | 324 } |
| 329 | 325 |
| 330 bool GpuVideoDecodeAccelerator::Initialize( | 326 bool GpuVideoDecodeAccelerator::Initialize( |
| 331 const media::VideoDecodeAccelerator::Config& config) { | 327 const media::VideoDecodeAccelerator::Config& config) { |
| 332 const gpu::GpuPreferences& gpu_preferences = | |
| 333 stub_->channel()->gpu_channel_manager()->gpu_preferences(); | |
| 334 if (gpu_preferences.disable_accelerated_video_decode) | |
| 335 return false; | |
| 336 | |
| 337 DCHECK(!video_decode_accelerator_); | 328 DCHECK(!video_decode_accelerator_); |
| 338 | 329 |
| 339 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) { | 330 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) { |
| 340 DLOG(ERROR) << "Initialize(): failed to add route"; | 331 DLOG(ERROR) << "Initialize(): failed to add route"; |
| 341 return false; | 332 return false; |
| 342 } | 333 } |
| 343 | 334 |
| 344 #if !defined(OS_WIN) | 335 #if !defined(OS_WIN) |
| 345 // Ensure we will be able to get a GL context at all before initializing | 336 // Ensure we will be able to get a GL context at all before initializing |
| 346 // non-Windows VDAs. | 337 // non-Windows VDAs. |
| 347 if (!make_context_current_.Run()) { | 338 if (!make_context_current_cb_.Run()) |
| 339 return false; |
| 340 #endif |
| 341 |
| 342 scoped_ptr<GpuVideoDecodeAcceleratorFactory> vda_factory = |
| 343 GpuVideoDecodeAcceleratorFactoryImpl::CreateWithGLES2Decoder( |
| 344 get_gl_context_cb_, make_context_current_cb_, bind_image_cb_, |
| 345 get_gles2_decoder_cb_); |
| 346 |
| 347 if (!vda_factory) { |
| 348 LOG(ERROR) << "Failed creating the VDA factory"; |
| 348 return false; | 349 return false; |
| 349 } | 350 } |
| 350 #endif | |
| 351 | 351 |
| 352 // Array of Create..VDA() function pointers, maybe applicable to the current | |
| 353 // platform. This list is ordered by priority of use and it should be the | |
| 354 // same as the order of querying supported profiles of VDAs. | |
| 355 const GpuVideoDecodeAccelerator::CreateVDAFp create_vda_fps[] = { | |
| 356 #if defined(OS_WIN) | |
| 357 &GpuVideoDecodeAccelerator::CreateDXVAVDA, | |
| 358 #endif | |
| 359 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
| 360 &GpuVideoDecodeAccelerator::CreateV4L2VDA, | |
| 361 &GpuVideoDecodeAccelerator::CreateV4L2SliceVDA, | |
| 362 #endif | |
| 363 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 364 &GpuVideoDecodeAccelerator::CreateVaapiVDA, | |
| 365 #endif | |
| 366 #if defined(OS_MACOSX) | |
| 367 &GpuVideoDecodeAccelerator::CreateVTVDA, | |
| 368 #endif | |
| 369 #if !defined(OS_CHROMEOS) && defined(USE_OZONE) | |
| 370 &GpuVideoDecodeAccelerator::CreateOzoneVDA, | |
| 371 #endif | |
| 372 #if defined(OS_ANDROID) | |
| 373 &GpuVideoDecodeAccelerator::CreateAndroidVDA, | |
| 374 #endif | |
| 375 }; | |
| 376 | |
| 377 for (const auto& create_vda_function : create_vda_fps) { | |
| 378 video_decode_accelerator_ = (this->*create_vda_function)(); | |
| 379 if (!video_decode_accelerator_ || | |
| 380 !video_decode_accelerator_->Initialize(config, this)) | |
| 381 continue; | |
| 382 | |
| 383 if (video_decode_accelerator_->CanDecodeOnIOThread()) { | |
| 384 filter_ = new MessageFilter(this, host_route_id_); | |
| 385 stub_->channel()->AddFilter(filter_.get()); | |
| 386 } | |
| 387 return true; | |
| 388 } | |
| 389 video_decode_accelerator_.reset(); | |
| 390 LOG(ERROR) << "HW video decode not available for profile " << config.profile | |
| 391 << (config.is_encrypted ? " with encryption" : ""); | |
| 392 return false; | |
| 393 } | |
| 394 | |
| 395 #if defined(OS_WIN) | |
| 396 scoped_ptr<media::VideoDecodeAccelerator> | |
| 397 GpuVideoDecodeAccelerator::CreateDXVAVDA() { | |
| 398 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
| 399 const gpu::GpuPreferences& gpu_preferences = | 352 const gpu::GpuPreferences& gpu_preferences = |
| 400 stub_->channel()->gpu_channel_manager()->gpu_preferences(); | 353 stub_->channel()->gpu_channel_manager()->gpu_preferences(); |
| 401 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { | 354 video_decode_accelerator_ = |
| 402 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | 355 vda_factory->CreateVDA(this, config, gpu_preferences); |
| 403 decoder.reset(new DXVAVideoDecodeAccelerator( | 356 if (!video_decode_accelerator_) { |
| 404 make_context_current_, stub_->decoder()->GetGLContext(), | 357 LOG(ERROR) << "HW video decode not available for profile " << config.profile |
| 405 gpu_preferences.enable_accelerated_vpx_decode)); | 358 << (config.is_encrypted ? " with encryption" : ""); |
| 406 } else { | 359 return false; |
| 407 NOTIMPLEMENTED() << "HW video decode acceleration not available."; | |
| 408 } | 360 } |
| 409 return decoder; | 361 |
| 362 // Attempt to set up performing decoding tasks on IO thread, if supported by |
| 363 // the VDA. |
| 364 if (video_decode_accelerator_->TryToSetupDecodeOnSeparateThread( |
| 365 weak_factory_for_io_.GetWeakPtr(), io_task_runner_)) { |
| 366 filter_ = new MessageFilter(this, host_route_id_); |
| 367 stub_->channel()->AddFilter(filter_.get()); |
| 368 } |
| 369 |
| 370 return true; |
| 410 } | 371 } |
| 411 #endif | |
| 412 | |
| 413 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
| 414 scoped_ptr<media::VideoDecodeAccelerator> | |
| 415 GpuVideoDecodeAccelerator::CreateV4L2VDA() { | |
| 416 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
| 417 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
| 418 if (device.get()) { | |
| 419 decoder.reset(new V4L2VideoDecodeAccelerator( | |
| 420 gfx::GLSurfaceEGL::GetHardwareDisplay(), | |
| 421 stub_->decoder()->GetGLContext()->GetHandle(), | |
| 422 weak_factory_for_io_.GetWeakPtr(), | |
| 423 make_context_current_, | |
| 424 device, | |
| 425 io_task_runner_)); | |
| 426 } | |
| 427 return decoder; | |
| 428 } | |
| 429 | |
| 430 scoped_ptr<media::VideoDecodeAccelerator> | |
| 431 GpuVideoDecodeAccelerator::CreateV4L2SliceVDA() { | |
| 432 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
| 433 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
| 434 if (device.get()) { | |
| 435 decoder.reset(new V4L2SliceVideoDecodeAccelerator( | |
| 436 device, | |
| 437 gfx::GLSurfaceEGL::GetHardwareDisplay(), | |
| 438 stub_->decoder()->GetGLContext()->GetHandle(), | |
| 439 weak_factory_for_io_.GetWeakPtr(), | |
| 440 make_context_current_, | |
| 441 io_task_runner_)); | |
| 442 } | |
| 443 return decoder; | |
| 444 } | |
| 445 #endif | |
| 446 | |
| 447 #if (defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)) || defined(OS_MACOSX) | |
| 448 void GpuVideoDecodeAccelerator::BindImage(uint32_t client_texture_id, | |
| 449 uint32_t texture_target, | |
| 450 scoped_refptr<gl::GLImage> image) { | |
| 451 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); | |
| 452 gpu::gles2::TextureManager* texture_manager = | |
| 453 command_decoder->GetContextGroup()->texture_manager(); | |
| 454 gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id); | |
| 455 if (ref) { | |
| 456 texture_manager->SetLevelImage(ref, texture_target, 0, image.get(), | |
| 457 gpu::gles2::Texture::BOUND); | |
| 458 } | |
| 459 } | |
| 460 #endif | |
| 461 | |
| 462 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 463 scoped_ptr<media::VideoDecodeAccelerator> | |
| 464 GpuVideoDecodeAccelerator::CreateVaapiVDA() { | |
| 465 return make_scoped_ptr<media::VideoDecodeAccelerator>( | |
| 466 new VaapiVideoDecodeAccelerator( | |
| 467 make_context_current_, | |
| 468 base::Bind(&GpuVideoDecodeAccelerator::BindImage, | |
| 469 base::Unretained(this)))); | |
| 470 } | |
| 471 #endif | |
| 472 | |
| 473 #if defined(OS_MACOSX) | |
| 474 scoped_ptr<media::VideoDecodeAccelerator> | |
| 475 GpuVideoDecodeAccelerator::CreateVTVDA() { | |
| 476 return make_scoped_ptr<media::VideoDecodeAccelerator>( | |
| 477 new VTVideoDecodeAccelerator( | |
| 478 make_context_current_, | |
| 479 base::Bind(&GpuVideoDecodeAccelerator::BindImage, | |
| 480 base::Unretained(this)))); | |
| 481 } | |
| 482 #endif | |
| 483 | |
| 484 #if !defined(OS_CHROMEOS) && defined(USE_OZONE) | |
| 485 scoped_ptr<media::VideoDecodeAccelerator> | |
| 486 GpuVideoDecodeAccelerator::CreateOzoneVDA() { | |
| 487 media::MediaOzonePlatform* platform = | |
| 488 media::MediaOzonePlatform::GetInstance(); | |
| 489 return make_scoped_ptr<media::VideoDecodeAccelerator>( | |
| 490 platform->CreateVideoDecodeAccelerator(make_context_current_)); | |
| 491 } | |
| 492 #endif | |
| 493 | |
| 494 #if defined(OS_ANDROID) | |
| 495 scoped_ptr<media::VideoDecodeAccelerator> | |
| 496 GpuVideoDecodeAccelerator::CreateAndroidVDA() { | |
| 497 return make_scoped_ptr<media::VideoDecodeAccelerator>( | |
| 498 new AndroidVideoDecodeAccelerator(stub_->decoder()->AsWeakPtr(), | |
| 499 make_context_current_)); | |
| 500 } | |
| 501 #endif | |
| 502 | 372 |
| 503 void GpuVideoDecodeAccelerator::OnSetCdm(int cdm_id) { | 373 void GpuVideoDecodeAccelerator::OnSetCdm(int cdm_id) { |
| 504 DCHECK(video_decode_accelerator_); | 374 DCHECK(video_decode_accelerator_); |
| 505 video_decode_accelerator_->SetCdm(cdm_id); | 375 video_decode_accelerator_->SetCdm(cdm_id); |
| 506 } | 376 } |
| 507 | 377 |
| 508 void GpuVideoDecodeAccelerator::CallOrPostNotifyError( | 378 void GpuVideoDecodeAccelerator::CallOrPostNotifyError( |
| 509 media::VideoDecodeAccelerator::Error error) { | 379 media::VideoDecodeAccelerator::Error error) { |
| 510 if (child_task_runner_->BelongsToCurrentThread()) { | 380 if (child_task_runner_->BelongsToCurrentThread()) { |
| 511 NotifyError(error); | 381 NotifyError(error); |
| 512 } else { | 382 } else { |
| 513 child_task_runner_->PostTask( | 383 child_task_runner_->PostTask( |
| 514 FROM_HERE, base::Bind(&GpuVideoDecodeAccelerator::NotifyError, | 384 FROM_HERE, base::Bind(&GpuVideoDecodeAccelerator::NotifyError, |
| 515 base::Unretained(this), error)); | 385 base::Unretained(this), error)); |
| 516 } | 386 } |
| 517 } | 387 } |
| 518 | 388 |
| 519 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is | 389 // Runs on IO thread if VDA::TryToSetupDecodeOnSeparateThread() succeeded, |
| 520 // true, otherwise on the main thread. | 390 // otherwise on the main thread. |
| 521 void GpuVideoDecodeAccelerator::OnDecode( | 391 void GpuVideoDecodeAccelerator::OnDecode( |
| 522 const media::BitstreamBuffer& bitstream_buffer) { | 392 const media::BitstreamBuffer& bitstream_buffer) { |
| 523 DCHECK(video_decode_accelerator_); | 393 DCHECK(video_decode_accelerator_); |
| 524 video_decode_accelerator_->Decode(bitstream_buffer); | 394 video_decode_accelerator_->Decode(bitstream_buffer); |
| 525 } | 395 } |
| 526 | 396 |
| 527 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( | 397 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers( |
| 528 const std::vector<int32_t>& buffer_ids, | 398 const std::vector<int32_t>& buffer_ids, |
| 529 const std::vector<uint32_t>& texture_ids) { | 399 const std::vector<uint32_t>& texture_ids) { |
| 530 if (buffer_ids.size() != texture_ids.size()) { | 400 if (buffer_ids.size() != texture_ids.size()) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 scoped_refptr<gpu::gles2::TextureRef> texture_ref = it->second; | 505 scoped_refptr<gpu::gles2::TextureRef> texture_ref = it->second; |
| 636 GLenum target = texture_ref->texture()->target(); | 506 GLenum target = texture_ref->texture()->target(); |
| 637 gpu::gles2::TextureManager* texture_manager = | 507 gpu::gles2::TextureManager* texture_manager = |
| 638 stub_->decoder()->GetContextGroup()->texture_manager(); | 508 stub_->decoder()->GetContextGroup()->texture_manager(); |
| 639 DCHECK(!texture_ref->texture()->IsLevelCleared(target, 0)); | 509 DCHECK(!texture_ref->texture()->IsLevelCleared(target, 0)); |
| 640 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true); | 510 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true); |
| 641 uncleared_textures_.erase(it); | 511 uncleared_textures_.erase(it); |
| 642 } | 512 } |
| 643 | 513 |
| 644 } // namespace content | 514 } // namespace content |
| OLD | NEW |