Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: content/common/gpu/media/gpu_video_decode_accelerator.cc

Issue 1784193003: content gpu refactor: get rid of gpu related content switches. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/location.h" 10 #include "base/location.h"
12 #include "base/logging.h" 11 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
14 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
15 #include "base/stl_util.h" 14 #include "base/stl_util.h"
16 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
17 #include "build/build_config.h" 16 #include "build/build_config.h"
18 17
19 #include "content/common/gpu/gpu_channel.h" 18 #include "content/common/gpu/gpu_channel.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/media_messages.h" 21 #include "content/common/gpu/media/media_messages.h"
22 #include "content/public/common/content_switches.h"
23 #include "gpu/command_buffer/common/command_buffer.h" 22 #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" 30 #include "ui/gl/gl_surface_egl.h"
31 31
32 #if defined(OS_WIN) 32 #if defined(OS_WIN)
33 #include "base/win/windows_version.h" 33 #include "base/win/windows_version.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 145 }
146 146
147 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() { 147 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() {
148 // This class can only be self-deleted from OnWillDestroyStub(), which means 148 // This class can only be self-deleted from OnWillDestroyStub(), which means
149 // the VDA has already been destroyed in there. 149 // the VDA has already been destroyed in there.
150 DCHECK(!video_decode_accelerator_); 150 DCHECK(!video_decode_accelerator_);
151 } 151 }
152 152
153 // static 153 // static
154 gpu::VideoDecodeAcceleratorCapabilities 154 gpu::VideoDecodeAcceleratorCapabilities
155 GpuVideoDecodeAccelerator::GetCapabilities() { 155 GpuVideoDecodeAccelerator::GetCapabilities(
156 const gpu::GpuPreferences& gpu_preferences) {
156 media::VideoDecodeAccelerator::Capabilities capabilities; 157 media::VideoDecodeAccelerator::Capabilities capabilities;
157 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 158 if (gpu_preferences.disable_accelerated_video_decode)
158 if (cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
159 return gpu::VideoDecodeAcceleratorCapabilities(); 159 return gpu::VideoDecodeAcceleratorCapabilities();
160 160
161 // Query supported profiles for each VDA. The order of querying VDAs should 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 162 // be the same as the order of initializing VDAs. Then the returned profile
163 // can be initialized by corresponding VDA successfully. 163 // can be initialized by corresponding VDA successfully.
164 #if defined(OS_WIN) 164 #if defined(OS_WIN)
165 capabilities.supported_profiles = 165 capabilities.supported_profiles =
166 DXVAVideoDecodeAccelerator::GetSupportedProfiles(); 166 DXVAVideoDecodeAccelerator::GetSupportedProfiles();
167 #elif defined(OS_CHROMEOS) 167 #elif defined(OS_CHROMEOS)
168 media::VideoDecodeAccelerator::SupportedProfiles vda_profiles; 168 media::VideoDecodeAccelerator::SupportedProfiles vda_profiles;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 322
323 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) { 323 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) {
324 if (filter_ && io_task_runner_->BelongsToCurrentThread()) 324 if (filter_ && io_task_runner_->BelongsToCurrentThread())
325 return filter_->SendOnIOThread(message); 325 return filter_->SendOnIOThread(message);
326 DCHECK(child_task_runner_->BelongsToCurrentThread()); 326 DCHECK(child_task_runner_->BelongsToCurrentThread());
327 return stub_->channel()->Send(message); 327 return stub_->channel()->Send(message);
328 } 328 }
329 329
330 bool GpuVideoDecodeAccelerator::Initialize( 330 bool GpuVideoDecodeAccelerator::Initialize(
331 const media::VideoDecodeAccelerator::Config& config) { 331 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
332 DCHECK(!video_decode_accelerator_); 337 DCHECK(!video_decode_accelerator_);
333 338
334 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) { 339 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) {
335 DLOG(ERROR) << "Initialize(): failed to add route"; 340 DLOG(ERROR) << "Initialize(): failed to add route";
336 return false; 341 return false;
337 } 342 }
338 343
339 #if !defined(OS_WIN) 344 #if !defined(OS_WIN)
340 // Ensure we will be able to get a GL context at all before initializing 345 // Ensure we will be able to get a GL context at all before initializing
341 // non-Windows VDAs. 346 // non-Windows VDAs.
342 if (!make_context_current_.Run()) { 347 if (!make_context_current_.Run()) {
343 return false; 348 return false;
344 } 349 }
345 #endif 350 #endif
346 351
347 // Array of Create..VDA() function pointers, maybe applicable to the current 352 // Array of Create..VDA() function pointers, maybe applicable to the current
348 // platform. This list is ordered by priority of use and it should be the 353 // platform. This list is ordered by priority of use and it should be the
349 // same as the order of querying supported profiles of VDAs. 354 // same as the order of querying supported profiles of VDAs.
350 const GpuVideoDecodeAccelerator::CreateVDAFp create_vda_fps[] = { 355 const GpuVideoDecodeAccelerator::CreateVDAFp create_vda_fps[] = {
351 &GpuVideoDecodeAccelerator::CreateDXVAVDA, 356 #if defined(OS_WIN)
352 &GpuVideoDecodeAccelerator::CreateV4L2VDA, 357 &GpuVideoDecodeAccelerator::CreateDXVAVDA,
353 &GpuVideoDecodeAccelerator::CreateV4L2SliceVDA, 358 #endif
354 &GpuVideoDecodeAccelerator::CreateVaapiVDA, 359 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
355 &GpuVideoDecodeAccelerator::CreateVTVDA, 360 &GpuVideoDecodeAccelerator::CreateV4L2VDA,
356 &GpuVideoDecodeAccelerator::CreateOzoneVDA, 361 &GpuVideoDecodeAccelerator::CreateV4L2SliceVDA,
357 &GpuVideoDecodeAccelerator::CreateAndroidVDA}; 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 };
358 376
359 for (const auto& create_vda_function : create_vda_fps) { 377 for (const auto& create_vda_function : create_vda_fps) {
360 video_decode_accelerator_ = (this->*create_vda_function)(); 378 video_decode_accelerator_ = (this->*create_vda_function)();
361 if (!video_decode_accelerator_ || 379 if (!video_decode_accelerator_ ||
362 !video_decode_accelerator_->Initialize(config, this)) 380 !video_decode_accelerator_->Initialize(config, this))
363 continue; 381 continue;
364 382
365 if (video_decode_accelerator_->CanDecodeOnIOThread()) { 383 if (video_decode_accelerator_->CanDecodeOnIOThread()) {
366 filter_ = new MessageFilter(this, host_route_id_); 384 filter_ = new MessageFilter(this, host_route_id_);
367 stub_->channel()->AddFilter(filter_.get()); 385 stub_->channel()->AddFilter(filter_.get());
368 } 386 }
369 return true; 387 return true;
370 } 388 }
371 video_decode_accelerator_.reset(); 389 video_decode_accelerator_.reset();
372 LOG(ERROR) << "HW video decode not available for profile " << config.profile 390 LOG(ERROR) << "HW video decode not available for profile " << config.profile
373 << (config.is_encrypted ? " with encryption" : ""); 391 << (config.is_encrypted ? " with encryption" : "");
374 return false; 392 return false;
375 } 393 }
376 394
395 #if defined(OS_WIN)
377 scoped_ptr<media::VideoDecodeAccelerator> 396 scoped_ptr<media::VideoDecodeAccelerator>
378 GpuVideoDecodeAccelerator::CreateDXVAVDA() { 397 GpuVideoDecodeAccelerator::CreateDXVAVDA() {
379 scoped_ptr<media::VideoDecodeAccelerator> decoder; 398 scoped_ptr<media::VideoDecodeAccelerator> decoder;
380 #if defined(OS_WIN) 399 const gpu::GpuPreferences& gpu_preferences =
400 stub_->channel()->gpu_channel_manager()->gpu_preferences();
381 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { 401 if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
382 DVLOG(0) << "Initializing DXVA HW decoder for windows."; 402 DVLOG(0) << "Initializing DXVA HW decoder for windows.";
383 decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_, 403 decoder.reset(new DXVAVideoDecodeAccelerator(
384 stub_->decoder()->GetGLContext())); 404 make_context_current_, stub_->decoder()->GetGLContext(),
405 gpu_preferences.enable_accelerated_vpx_decode));
385 } else { 406 } else {
386 NOTIMPLEMENTED() << "HW video decode acceleration not available."; 407 NOTIMPLEMENTED() << "HW video decode acceleration not available.";
387 } 408 }
388 #endif
389 return decoder; 409 return decoder;
390 } 410 }
411 #endif
391 412
413 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
392 scoped_ptr<media::VideoDecodeAccelerator> 414 scoped_ptr<media::VideoDecodeAccelerator>
393 GpuVideoDecodeAccelerator::CreateV4L2VDA() { 415 GpuVideoDecodeAccelerator::CreateV4L2VDA() {
394 scoped_ptr<media::VideoDecodeAccelerator> decoder; 416 scoped_ptr<media::VideoDecodeAccelerator> decoder;
395 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
396 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); 417 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
397 if (device.get()) { 418 if (device.get()) {
398 decoder.reset(new V4L2VideoDecodeAccelerator( 419 decoder.reset(new V4L2VideoDecodeAccelerator(
399 gfx::GLSurfaceEGL::GetHardwareDisplay(), 420 gfx::GLSurfaceEGL::GetHardwareDisplay(),
400 stub_->decoder()->GetGLContext()->GetHandle(), 421 stub_->decoder()->GetGLContext()->GetHandle(),
401 weak_factory_for_io_.GetWeakPtr(), 422 weak_factory_for_io_.GetWeakPtr(),
402 make_context_current_, 423 make_context_current_,
403 device, 424 device,
404 io_task_runner_)); 425 io_task_runner_));
405 } 426 }
406 #endif
407 return decoder; 427 return decoder;
408 } 428 }
409 429
410 scoped_ptr<media::VideoDecodeAccelerator> 430 scoped_ptr<media::VideoDecodeAccelerator>
411 GpuVideoDecodeAccelerator::CreateV4L2SliceVDA() { 431 GpuVideoDecodeAccelerator::CreateV4L2SliceVDA() {
412 scoped_ptr<media::VideoDecodeAccelerator> decoder; 432 scoped_ptr<media::VideoDecodeAccelerator> decoder;
413 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
414 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); 433 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
415 if (device.get()) { 434 if (device.get()) {
416 decoder.reset(new V4L2SliceVideoDecodeAccelerator( 435 decoder.reset(new V4L2SliceVideoDecodeAccelerator(
417 device, 436 device,
418 gfx::GLSurfaceEGL::GetHardwareDisplay(), 437 gfx::GLSurfaceEGL::GetHardwareDisplay(),
419 stub_->decoder()->GetGLContext()->GetHandle(), 438 stub_->decoder()->GetGLContext()->GetHandle(),
420 weak_factory_for_io_.GetWeakPtr(), 439 weak_factory_for_io_.GetWeakPtr(),
421 make_context_current_, 440 make_context_current_,
422 io_task_runner_)); 441 io_task_runner_));
423 } 442 }
424 #endif
425 return decoder; 443 return decoder;
426 } 444 }
445 #endif
427 446
447 #if (defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)) || defined(OS_MACOSX)
428 void GpuVideoDecodeAccelerator::BindImage(uint32_t client_texture_id, 448 void GpuVideoDecodeAccelerator::BindImage(uint32_t client_texture_id,
429 uint32_t texture_target, 449 uint32_t texture_target,
430 scoped_refptr<gl::GLImage> image) { 450 scoped_refptr<gl::GLImage> image) {
431 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder(); 451 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder();
432 gpu::gles2::TextureManager* texture_manager = 452 gpu::gles2::TextureManager* texture_manager =
433 command_decoder->GetContextGroup()->texture_manager(); 453 command_decoder->GetContextGroup()->texture_manager();
434 gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id); 454 gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id);
435 if (ref) { 455 if (ref) {
436 texture_manager->SetLevelImage(ref, texture_target, 0, image.get(), 456 texture_manager->SetLevelImage(ref, texture_target, 0, image.get(),
437 gpu::gles2::Texture::BOUND); 457 gpu::gles2::Texture::BOUND);
438 } 458 }
439 } 459 }
460 #endif
440 461
462 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
441 scoped_ptr<media::VideoDecodeAccelerator> 463 scoped_ptr<media::VideoDecodeAccelerator>
442 GpuVideoDecodeAccelerator::CreateVaapiVDA() { 464 GpuVideoDecodeAccelerator::CreateVaapiVDA() {
443 scoped_ptr<media::VideoDecodeAccelerator> decoder; 465 return make_scoped_ptr<media::VideoDecodeAccelerator>(
dcheng 2016/03/13 09:23:35 Nit: omit template parameter here, it's automatica
Peng 2016/03/13 20:33:40 I tried it without template arg. But it didn't com
444 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 466 new VaapiVideoDecodeAccelerator(
445 decoder.reset(new VaapiVideoDecodeAccelerator( 467 make_context_current_,
446 make_context_current_, base::Bind(&GpuVideoDecodeAccelerator::BindImage, 468 base::Bind(&GpuVideoDecodeAccelerator::BindImage,
447 base::Unretained(this)))); 469 base::Unretained(this))));
470 }
448 #endif 471 #endif
449 return decoder;
450 }
451 472
473 #if defined(OS_MACOSX)
452 scoped_ptr<media::VideoDecodeAccelerator> 474 scoped_ptr<media::VideoDecodeAccelerator>
453 GpuVideoDecodeAccelerator::CreateVTVDA() { 475 GpuVideoDecodeAccelerator::CreateVTVDA() {
454 scoped_ptr<media::VideoDecodeAccelerator> decoder; 476 return make_scoped_ptr<media::VideoDecodeAccelerator>(
dcheng 2016/03/13 09:23:35 Ditto.
455 #if defined(OS_MACOSX) 477 new VTVideoDecodeAccelerator(
456 decoder.reset(new VTVideoDecodeAccelerator( 478 make_context_current_,
457 make_context_current_, base::Bind(&GpuVideoDecodeAccelerator::BindImage, 479 base::Bind(&GpuVideoDecodeAccelerator::BindImage,
458 base::Unretained(this)))); 480 base::Unretained(this))));
481 }
459 #endif 482 #endif
460 return decoder;
461 }
462 483
484 #if !defined(OS_CHROMEOS) && defined(USE_OZONE)
463 scoped_ptr<media::VideoDecodeAccelerator> 485 scoped_ptr<media::VideoDecodeAccelerator>
464 GpuVideoDecodeAccelerator::CreateOzoneVDA() { 486 GpuVideoDecodeAccelerator::CreateOzoneVDA() {
465 scoped_ptr<media::VideoDecodeAccelerator> decoder;
466 #if !defined(OS_CHROMEOS) && defined(USE_OZONE)
467 media::MediaOzonePlatform* platform = 487 media::MediaOzonePlatform* platform =
468 media::MediaOzonePlatform::GetInstance(); 488 media::MediaOzonePlatform::GetInstance();
469 decoder.reset(platform->CreateVideoDecodeAccelerator(make_context_current_)); 489 return make_scoped_ptr<media::VideoDecodeAccelerator>(
dcheng 2016/03/13 09:23:35 etc etc here and elsewhere.
490 platform->CreateVideoDecodeAccelerator(make_context_current_));
491 }
470 #endif 492 #endif
471 return decoder;
472 }
473 493
494 #if defined(OS_ANDROID)
474 scoped_ptr<media::VideoDecodeAccelerator> 495 scoped_ptr<media::VideoDecodeAccelerator>
475 GpuVideoDecodeAccelerator::CreateAndroidVDA() { 496 GpuVideoDecodeAccelerator::CreateAndroidVDA() {
476 scoped_ptr<media::VideoDecodeAccelerator> decoder; 497 return make_scoped_ptr<media::VideoDecodeAccelerator>(
477 #if defined(OS_ANDROID) 498 new AndroidVideoDecodeAccelerator(stub_->decoder()->AsWeakPtr(),
478 decoder.reset(new AndroidVideoDecodeAccelerator(stub_->decoder()->AsWeakPtr(), 499 make_context_current_));
479 make_context_current_)); 500 }
480 #endif 501 #endif
481 return decoder;
482 }
483 502
484 void GpuVideoDecodeAccelerator::OnSetCdm(int cdm_id) { 503 void GpuVideoDecodeAccelerator::OnSetCdm(int cdm_id) {
485 DCHECK(video_decode_accelerator_); 504 DCHECK(video_decode_accelerator_);
486 video_decode_accelerator_->SetCdm(cdm_id); 505 video_decode_accelerator_->SetCdm(cdm_id);
487 } 506 }
488 507
489 void GpuVideoDecodeAccelerator::CallOrPostNotifyError( 508 void GpuVideoDecodeAccelerator::CallOrPostNotifyError(
490 media::VideoDecodeAccelerator::Error error) { 509 media::VideoDecodeAccelerator::Error error) {
491 if (child_task_runner_->BelongsToCurrentThread()) { 510 if (child_task_runner_->BelongsToCurrentThread()) {
492 NotifyError(error); 511 NotifyError(error);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 scoped_refptr<gpu::gles2::TextureRef> texture_ref = it->second; 635 scoped_refptr<gpu::gles2::TextureRef> texture_ref = it->second;
617 GLenum target = texture_ref->texture()->target(); 636 GLenum target = texture_ref->texture()->target();
618 gpu::gles2::TextureManager* texture_manager = 637 gpu::gles2::TextureManager* texture_manager =
619 stub_->decoder()->GetContextGroup()->texture_manager(); 638 stub_->decoder()->GetContextGroup()->texture_manager();
620 DCHECK(!texture_ref->texture()->IsLevelCleared(target, 0)); 639 DCHECK(!texture_ref->texture()->IsLevelCleared(target, 0));
621 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true); 640 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true);
622 uncleared_textures_.erase(it); 641 uncleared_textures_.erase(it);
623 } 642 }
624 643
625 } // namespace content 644 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/gpu_video_decode_accelerator.h ('k') | content/common/gpu/media/gpu_video_encode_accelerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698