gpu_video_decode_accelerator_factory.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_GPU_GPU_VIDEO_DECODE_ACCELERATOR_FACTORY_H_
  5. #define MEDIA_GPU_GPU_VIDEO_DECODE_ACCELERATOR_FACTORY_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "base/threading/thread_checker.h"
  9. #include "build/build_config.h"
  10. #include "gpu/config/gpu_driver_bug_workarounds.h"
  11. #include "gpu/config/gpu_info.h"
  12. #include "gpu/config/gpu_preferences.h"
  13. #include "media/base/android_overlay_mojo_factory.h"
  14. #include "media/gpu/buildflags.h"
  15. #include "media/gpu/gpu_video_decode_accelerator_helpers.h"
  16. #include "media/gpu/media_gpu_export.h"
  17. #include "media/video/video_decode_accelerator.h"
  18. namespace gl {
  19. class GLContext;
  20. class GLImage;
  21. }
  22. namespace gpu {
  23. struct GpuPreferences;
  24. namespace gles2 {
  25. class ContextGroup;
  26. }
  27. }
  28. namespace media {
  29. class MediaLog;
  30. class MEDIA_GPU_EXPORT GpuVideoDecodeAcceleratorFactory {
  31. public:
  32. GpuVideoDecodeAcceleratorFactory() = delete;
  33. GpuVideoDecodeAcceleratorFactory(const GpuVideoDecodeAcceleratorFactory&) =
  34. delete;
  35. GpuVideoDecodeAcceleratorFactory& operator=(
  36. const GpuVideoDecodeAcceleratorFactory&) = delete;
  37. ~GpuVideoDecodeAcceleratorFactory();
  38. // Return current GLContext.
  39. using GetGLContextCallback = base::RepeatingCallback<gl::GLContext*(void)>;
  40. // Make the applicable GL context current. To be called by VDAs before
  41. // executing any GL calls. Return true on success, false otherwise.
  42. using MakeGLContextCurrentCallback = base::RepeatingCallback<bool(void)>;
  43. // Bind |image| to |client_texture_id| given |texture_target|. If
  44. // |can_bind_to_sampler| is true, then the image may be used as a sampler
  45. // directly, otherwise a copy to a staging buffer is required.
  46. // Return true on success, false otherwise.
  47. using BindGLImageCallback =
  48. base::RepeatingCallback<bool(uint32_t client_texture_id,
  49. uint32_t texture_target,
  50. const scoped_refptr<gl::GLImage>& image,
  51. bool can_bind_to_sampler)>;
  52. // Return a ContextGroup*, if one is available.
  53. using GetContextGroupCallback =
  54. base::RepeatingCallback<gpu::gles2::ContextGroup*(void)>;
  55. static std::unique_ptr<GpuVideoDecodeAcceleratorFactory> Create(
  56. const GpuVideoDecodeGLClient& gl_client);
  57. static gpu::VideoDecodeAcceleratorCapabilities GetDecoderCapabilities(
  58. const gpu::GpuPreferences& gpu_preferences,
  59. const gpu::GpuDriverBugWorkarounds& workarounds);
  60. std::unique_ptr<VideoDecodeAccelerator> CreateVDA(
  61. VideoDecodeAccelerator::Client* client,
  62. const VideoDecodeAccelerator::Config& config,
  63. const gpu::GpuDriverBugWorkarounds& workarounds,
  64. const gpu::GpuPreferences& gpu_preferences,
  65. MediaLog* media_log = nullptr);
  66. private:
  67. GpuVideoDecodeAcceleratorFactory(const GpuVideoDecodeGLClient& gl_client);
  68. #if BUILDFLAG(IS_WIN)
  69. std::unique_ptr<VideoDecodeAccelerator> CreateD3D11VDA(
  70. const gpu::GpuDriverBugWorkarounds& workarounds,
  71. const gpu::GpuPreferences& gpu_preferences,
  72. MediaLog* media_log) const;
  73. std::unique_ptr<VideoDecodeAccelerator> CreateDXVAVDA(
  74. const gpu::GpuDriverBugWorkarounds& workarounds,
  75. const gpu::GpuPreferences& gpu_preferences,
  76. MediaLog* media_log) const;
  77. #endif
  78. #if BUILDFLAG(USE_VAAPI)
  79. std::unique_ptr<VideoDecodeAccelerator> CreateVaapiVDA(
  80. const gpu::GpuDriverBugWorkarounds& workarounds,
  81. const gpu::GpuPreferences& gpu_preferences,
  82. MediaLog* media_log) const;
  83. #elif BUILDFLAG(USE_V4L2_CODEC)
  84. std::unique_ptr<VideoDecodeAccelerator> CreateV4L2VDA(
  85. const gpu::GpuDriverBugWorkarounds& workarounds,
  86. const gpu::GpuPreferences& gpu_preferences,
  87. MediaLog* media_log) const;
  88. std::unique_ptr<VideoDecodeAccelerator> CreateV4L2SliceVDA(
  89. const gpu::GpuDriverBugWorkarounds& workarounds,
  90. const gpu::GpuPreferences& gpu_preferences,
  91. MediaLog* media_log) const;
  92. #endif
  93. #if BUILDFLAG(IS_MAC)
  94. std::unique_ptr<VideoDecodeAccelerator> CreateVTVDA(
  95. const gpu::GpuDriverBugWorkarounds& workarounds,
  96. const gpu::GpuPreferences& gpu_preferences,
  97. MediaLog* media_log) const;
  98. #endif
  99. #if BUILDFLAG(IS_ANDROID)
  100. std::unique_ptr<VideoDecodeAccelerator> CreateAndroidVDA(
  101. const gpu::GpuDriverBugWorkarounds& workarounds,
  102. const gpu::GpuPreferences& gpu_preferences,
  103. MediaLog* media_log) const;
  104. #endif
  105. const GpuVideoDecodeGLClient gl_client_;
  106. const AndroidOverlayMojoFactoryCB overlay_factory_cb_;
  107. base::ThreadChecker thread_checker_;
  108. };
  109. } // namespace media
  110. #endif // MEDIA_GPU_GPU_VIDEO_DECODE_ACCELERATOR_FACTORY_H_