gpu_video_accelerator_factories.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // Copyright 2013 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_VIDEO_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
  5. #define MEDIA_VIDEO_GPU_VIDEO_ACCELERATOR_FACTORIES_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <memory>
  9. #include <vector>
  10. #include "base/memory/ref_counted.h"
  11. #include "base/memory/unsafe_shared_memory_region.h"
  12. #include "base/unguessable_token.h"
  13. #include "gpu/command_buffer/client/gles2_interface.h"
  14. #include "gpu/command_buffer/common/mailbox.h"
  15. #include "gpu/ipc/common/gpu_channel.mojom.h"
  16. #include "media/base/media_export.h"
  17. #include "media/base/overlay_info.h"
  18. #include "media/base/supported_video_decoder_config.h"
  19. #include "media/base/video_decoder.h"
  20. #include "media/base/video_types.h"
  21. #include "media/video/video_encode_accelerator.h"
  22. #include "third_party/abseil-cpp/absl/types/optional.h"
  23. #include "ui/gfx/gpu_memory_buffer.h"
  24. namespace base {
  25. class SequencedTaskRunner;
  26. } // namespace base
  27. namespace gfx {
  28. class ColorSpace;
  29. class Size;
  30. } // namespace gfx
  31. namespace gpu {
  32. class GpuMemoryBufferManager;
  33. class SharedImageInterface;
  34. } // namespace gpu
  35. namespace viz {
  36. class RasterContextProvider;
  37. } // namespace viz
  38. namespace media {
  39. class MediaLog;
  40. // Helper interface for specifying factories needed to instantiate a hardware
  41. // video accelerator.
  42. // Threading model:
  43. // * The GpuVideoAcceleratorFactories may be constructed on any thread.
  44. // * The GpuVideoAcceleratorFactories has an associated task runner, which may
  45. // be retrieved as |GetTaskRunner()|.
  46. // * All calls to the Factories after construction must be made on its task
  47. // runnner, unless otherwise documented below.
  48. class MEDIA_EXPORT GpuVideoAcceleratorFactories {
  49. public:
  50. enum class OutputFormat {
  51. UNDEFINED = 0, // Unset state
  52. I420, // 3 x R8 GMBs
  53. NV12_SINGLE_GMB, // One NV12 GMB
  54. NV12_DUAL_GMB, // One R8, one RG88 GMB
  55. XR30, // 10:10:10:2 BGRX in one GMB (Usually Mac)
  56. XB30, // 10:10:10:2 RGBX in one GMB
  57. RGBA, // One 8:8:8:8 RGBA
  58. BGRA, // One 8:8:8:8 BGRA (Usually Mac)
  59. P010, // One P010 GMB.
  60. };
  61. enum class Supported {
  62. kFalse = 0,
  63. kTrue,
  64. kUnknown,
  65. };
  66. // Return whether GPU decoding is enabled.
  67. virtual bool IsGpuVideoDecodeAcceleratorEnabled() = 0;
  68. // Return whether GPU encoding is enabled.
  69. virtual bool IsGpuVideoEncodeAcceleratorEnabled() = 0;
  70. // Return the channel token, or an empty token if the channel is unusable.
  71. // |cb| could be called re-entrantly. This function is not thread safe.
  72. virtual void GetChannelToken(
  73. gpu::mojom::GpuChannel::GetChannelTokenCallback cb) = 0;
  74. // Returns the |route_id| of the command buffer, or 0 if there is none.
  75. virtual int32_t GetCommandBufferRouteId() = 0;
  76. // Returns Supported::kTrue if |config| is supported by a decoder created with
  77. // CreateVideoDecoder() using |implementation|. Returns Supported::kMaybe if
  78. // it's not known at this time whether |config| is supported or not. Returns
  79. // Supported::kFalse if |config| is not supported.
  80. //
  81. // May be called on any thread.
  82. //
  83. // TODO(sandersd): Switch to bool if/when all clients check
  84. // IsDecoderSupportKnown().
  85. virtual Supported IsDecoderConfigSupported(
  86. const VideoDecoderConfig& config) = 0;
  87. // Returns VideoDecoderType::kUnknown in cases where IsDecoderSupportKnown()
  88. // is false. Otherwise, it returns the type of decoder that provided the
  89. // configs for the config support check.
  90. virtual VideoDecoderType GetDecoderType() = 0;
  91. // Callers must verify IsDecoderSupportKnown() prior to using this, or they
  92. // will immediately receive a kUnknown.
  93. //
  94. // May be called on any thread.
  95. Supported IsDecoderConfigSupportedOrUnknown(const VideoDecoderConfig& config);
  96. // Returns true if IsDecoderConfigSupported() is ready to answer queries.
  97. // Once decoder support is known, it remains known for the lifetime of |this|.
  98. //
  99. // May be called on any thread.
  100. virtual bool IsDecoderSupportKnown() = 0;
  101. // Registers a callback to be notified when IsDecoderConfigSupported() is
  102. // ready to answer queries. The callback will be invoked on the caller's
  103. // sequence.
  104. //
  105. // There is no way to unsubscribe a callback, it is recommended to use a
  106. // WeakPtr if you need this feature.
  107. //
  108. // May be called on any thread.
  109. virtual void NotifyDecoderSupportKnown(base::OnceClosure callback) = 0;
  110. virtual std::unique_ptr<media::VideoDecoder> CreateVideoDecoder(
  111. MediaLog* media_log,
  112. RequestOverlayInfoCB request_overlay_info_cb) = 0;
  113. // Returns the supported codec profiles of video encode accelerator.
  114. // Returns nullopt if GpuVideoAcceleratorFactories don't know the VEA
  115. // supported profiles.
  116. //
  117. // May be called on any thread.
  118. //
  119. // TODO(sandersd): Remove Optional if/when all clients check
  120. // IsEncoderSupportKnown().
  121. virtual absl::optional<VideoEncodeAccelerator::SupportedProfiles>
  122. GetVideoEncodeAcceleratorSupportedProfiles() = 0;
  123. // Returns true if GetVideoEncodeAcceleratorSupportedProfiles() is populated.
  124. // Once encoder support is known, it remains known for the lifetime of |this|.
  125. //
  126. // May be called on any thread.
  127. virtual bool IsEncoderSupportKnown() = 0;
  128. // Registers a callback to be notified when
  129. // GetVideoEncodeAcceleratorSupportedProfiles() has been populated. The
  130. // callback will be invoked on the caller's sequence.
  131. //
  132. // There is no way to unsubscribe a callback, it is recommended to use a
  133. // WeakPtr if you need this feature.
  134. //
  135. // May be called on any thread.
  136. virtual void NotifyEncoderSupportKnown(base::OnceClosure callback) = 0;
  137. // Caller owns returned pointer, but should call Destroy() on it (instead of
  138. // directly deleting) for proper destruction, as per the
  139. // VideoEncodeAccelerator interface.
  140. virtual std::unique_ptr<VideoEncodeAccelerator>
  141. CreateVideoEncodeAccelerator() = 0;
  142. virtual std::unique_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
  143. const gfx::Size& size,
  144. gfx::BufferFormat format,
  145. gfx::BufferUsage usage) = 0;
  146. // |for_media_stream| specifies webrtc use case of media streams.
  147. virtual bool ShouldUseGpuMemoryBuffersForVideoFrames(
  148. bool for_media_stream) const = 0;
  149. // The GLContextLock must be taken when calling this.
  150. virtual unsigned ImageTextureTarget(gfx::BufferFormat format) = 0;
  151. // Pixel format of the hardware video frames created when GpuMemoryBuffers
  152. // video frames are enabled.
  153. virtual OutputFormat VideoFrameOutputFormat(
  154. VideoPixelFormat pixel_format) = 0;
  155. // Returns a SharedImageInterface that can be used (on any thread) to allocate
  156. // and update shared images.
  157. // nullptr will be returned in cases where a context couldn't be created or
  158. // the context was lost.
  159. virtual gpu::SharedImageInterface* SharedImageInterface() = 0;
  160. // Returns the GpuMemoryBufferManager that is used to allocate
  161. // GpuMemoryBuffers. May return null if
  162. // ShouldUseGpuMemoryBuffersForVideoFrames return false.
  163. virtual gpu::GpuMemoryBufferManager* GpuMemoryBufferManager() = 0;
  164. // Allocate & return an unsafe shared memory region
  165. virtual base::UnsafeSharedMemoryRegion CreateSharedMemoryRegion(
  166. size_t size) = 0;
  167. // Returns the task runner the video accelerator runs on.
  168. virtual scoped_refptr<base::SequencedTaskRunner> GetTaskRunner() = 0;
  169. virtual viz::RasterContextProvider* GetMediaContextProvider() = 0;
  170. // Sets or gets the current pipeline rendering color space.
  171. virtual void SetRenderingColorSpace(const gfx::ColorSpace& color_space) = 0;
  172. virtual const gfx::ColorSpace& GetRenderingColorSpace() const = 0;
  173. virtual ~GpuVideoAcceleratorFactories() = default;
  174. };
  175. } // namespace media
  176. #endif // MEDIA_VIDEO_GPU_VIDEO_ACCELERATOR_FACTORIES_H_