[M120 Migration][MM][CAPI] Fix the logic for media using capi player.
[platform/framework/web/chromium-efl.git] / media / mojo / services / gpu_mojo_media_client.h
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_MOJO_SERVICES_GPU_MOJO_MEDIA_CLIENT_H_
6 #define MEDIA_MOJO_SERVICES_GPU_MOJO_MEDIA_CLIENT_H_
7
8 #include <memory>
9
10 #include "base/memory/raw_ptr.h"
11 #include "base/memory/scoped_refptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/task/sequenced_task_runner.h"
14 #include "base/task/single_thread_task_runner.h"
15 #include "build/build_config.h"
16 #include "gpu/config/gpu_driver_bug_workarounds.h"
17 #include "gpu/config/gpu_feature_info.h"
18 #include "gpu/config/gpu_info.h"
19 #include "gpu/config/gpu_preferences.h"
20 #include "gpu/ipc/service/command_buffer_stub.h"
21 #include "media/base/android_overlay_mojo_factory.h"
22 #include "media/base/supported_video_decoder_config.h"
23 #include "media/media_buildflags.h"
24 #include "media/mojo/services/mojo_media_client.h"
25 #include "third_party/abseil-cpp/absl/types/optional.h"
26
27 namespace gpu {
28 class GpuMemoryBufferFactory;
29 }  // namespace gpu
30
31 namespace media {
32
33 class MediaGpuChannelManager;
34 class GpuMojoMediaClient;
35
36 using GetConfigCacheCB =
37     base::RepeatingCallback<SupportedVideoDecoderConfigs()>;
38 using GetCommandBufferStubCB =
39     base::RepeatingCallback<gpu::CommandBufferStub*()>;
40
41 // Encapsulate parameters to pass to platform-specific helpers.
42 struct VideoDecoderTraits {
43   scoped_refptr<base::SequencedTaskRunner> task_runner;
44   scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner;
45   std::unique_ptr<MediaLog> media_log;
46   RequestOverlayInfoCB request_overlay_info_cb;
47   const raw_ptr<const gfx::ColorSpace> target_color_space;
48   gpu::GpuPreferences gpu_preferences;
49   gpu::GpuFeatureInfo gpu_feature_info;
50   gpu::GPUInfo gpu_info;
51   const raw_ptr<const gpu::GpuDriverBugWorkarounds> gpu_workarounds;
52   const raw_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory;
53
54   // Windows decoders need to ensure that the cache is populated.
55   GetConfigCacheCB get_cached_configs_cb;
56
57   // Android uses this twice.
58   GetCommandBufferStubCB get_command_buffer_stub_cb;
59
60   AndroidOverlayMojoFactoryCB android_overlay_factory_cb;
61
62   mojo::PendingRemote<stable::mojom::StableVideoDecoder> oop_video_decoder;
63
64   base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager;
65
66   VideoDecoderTraits(
67       scoped_refptr<base::SequencedTaskRunner> task_runner,
68       scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner,
69       std::unique_ptr<MediaLog> media_log,
70       RequestOverlayInfoCB request_overlay_info_cb,
71       const gfx::ColorSpace* target_color_space,
72       gpu::GpuPreferences gpu_preferences,
73       gpu::GpuFeatureInfo gpu_feature_info,
74       gpu::GPUInfo gpu_info,
75       const gpu::GpuDriverBugWorkarounds* gpu_workarounds,
76       gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory,
77       GetConfigCacheCB get_cached_configs_cb,
78       GetCommandBufferStubCB get_command_buffer_stub_cb,
79       AndroidOverlayMojoFactoryCB android_overlay_factory_cb,
80       mojo::PendingRemote<stable::mojom::StableVideoDecoder> oop_video_decoder,
81       base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager);
82   ~VideoDecoderTraits();
83 };
84
85 // Find platform specific implementations of these in
86 // gpu_mojo_media_client_{platform}.cc
87 // Creates a platform-specific media::VideoDecoder.
88 std::unique_ptr<VideoDecoder> CreatePlatformVideoDecoder(VideoDecoderTraits&);
89
90 #if BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC)
91 // Ensures that the platform video decoder supported configurations are known.
92 // When they are, |cb| is called with a PendingRemote that corresponds to the
93 // same connection as |oop_video_decoder| (which may be |oop_video_decoder|
94 // itself). |oop_video_decoder| may be used internally to query the supported
95 // configurations of an out-of-process video decoder.
96 //
97 // |cb| is called with |oop_video_decoder| before NotifyPlatformDecoderSupport()
98 // returns if the supported configurations are already known.
99 //
100 // This function is thread- and sequence-safe. |cb| is always called on the same
101 // sequence as NotifyPlatformDecoderSupport().
102 void NotifyPlatformDecoderSupport(
103     const gpu::GpuPreferences& gpu_preferences,
104     const gpu::GPUInfo& gpu_info,
105     mojo::PendingRemote<stable::mojom::StableVideoDecoder> oop_video_decoder,
106     base::OnceCallback<
107         void(mojo::PendingRemote<stable::mojom::StableVideoDecoder>)> cb);
108 #endif  // BUILDFLAG(USE_VAAPI) || BUILDFLAG(USE_V4L2_CODEC)
109
110 // Queries the platform-specific VideoDecoder implementation for its
111 // supported profiles. Some platforms fall back to use the VDAVideoDecoder
112 // so that implementation is shared, and its supported configs can be
113 // queries using the |get_vda_configs| callback.
114 absl::optional<SupportedVideoDecoderConfigs>
115 GetPlatformSupportedVideoDecoderConfigs(
116     base::WeakPtr<MediaGpuChannelManager> manager,
117     gpu::GpuDriverBugWorkarounds gpu_workarounds,
118     gpu::GpuPreferences gpu_preferences,
119     const gpu::GPUInfo& gpu_info,
120     base::OnceCallback<SupportedVideoDecoderConfigs()> get_vda_configs);
121
122 // Creates a platform-specific media::AudioDecoder. Most platforms don't do
123 // anything here, but android, for example, does.
124 std::unique_ptr<AudioDecoder> CreatePlatformAudioDecoder(
125     scoped_refptr<base::SequencedTaskRunner> task_runner,
126     std::unique_ptr<MediaLog> media_log);
127
128 // Creates a platform-specific media::AudioEncoder. Most platforms don't do
129 // anything here.
130 std::unique_ptr<AudioEncoder> CreatePlatformAudioEncoder(
131     scoped_refptr<base::SequencedTaskRunner> task_runner);
132
133 // Creates a CDM factory, right now only used on android and chromeos.
134 std::unique_ptr<CdmFactory> CreatePlatformCdmFactory(
135     mojom::FrameInterfaceFactory* frame_interfaces);
136
137 // Queries the platform decoder type.
138 VideoDecoderType GetPlatformDecoderImplementationType(
139     gpu::GpuDriverBugWorkarounds gpu_workarounds,
140     gpu::GpuPreferences gpu_preferences,
141     const gpu::GPUInfo& gpu_info);
142
143 class MEDIA_MOJO_EXPORT GpuMojoMediaClient final : public MojoMediaClient {
144  public:
145   // |media_gpu_channel_manager| must only be used on |gpu_task_runner|, which
146   // is expected to be the GPU main thread task runner.
147   GpuMojoMediaClient(
148       const gpu::GpuPreferences& gpu_preferences,
149       const gpu::GpuDriverBugWorkarounds& gpu_workarounds,
150       const gpu::GpuFeatureInfo& gpu_feature_info,
151       const gpu::GPUInfo& gpu_info,
152       scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner,
153       base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager,
154       gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory,
155       AndroidOverlayMojoFactoryCB android_overlay_factory_cb);
156
157   GpuMojoMediaClient(const GpuMojoMediaClient&) = delete;
158   GpuMojoMediaClient& operator=(const GpuMojoMediaClient&) = delete;
159
160   ~GpuMojoMediaClient() final;
161
162   const gpu::GPUInfo& gpu_info() const { return gpu_info_; }
163
164   // MojoMediaClient implementation.
165   SupportedVideoDecoderConfigs GetSupportedVideoDecoderConfigs() final;
166   VideoDecoderType GetDecoderImplementationType() final;
167   std::unique_ptr<AudioDecoder> CreateAudioDecoder(
168       scoped_refptr<base::SequencedTaskRunner> task_runner,
169       std::unique_ptr<MediaLog> media_log) final;
170   std::unique_ptr<AudioEncoder> CreateAudioEncoder(
171       scoped_refptr<base::SequencedTaskRunner> task_runner) final;
172
173 #if BUILDFLAG(ALLOW_OOP_VIDEO_DECODER)
174   void NotifyDecoderSupportKnown(
175       mojo::PendingRemote<stable::mojom::StableVideoDecoder> oop_video_decoder,
176       base::OnceCallback<void(
177           mojo::PendingRemote<stable::mojom::StableVideoDecoder>)> cb) final;
178 #endif  // BUILDFLAG(ALLOW_OOP_VIDEO_DECODER)
179   std::unique_ptr<VideoDecoder> CreateVideoDecoder(
180       scoped_refptr<base::SequencedTaskRunner> task_runner,
181       MediaLog* media_log,
182       mojom::CommandBufferIdPtr command_buffer_id,
183       RequestOverlayInfoCB request_overlay_info_cb,
184       const gfx::ColorSpace& target_color_space,
185       mojo::PendingRemote<stable::mojom::StableVideoDecoder> oop_video_decoder)
186       final;
187   std::unique_ptr<CdmFactory> CreateCdmFactory(
188       mojom::FrameInterfaceFactory* interface_provider) final;
189
190   static absl::optional<SupportedVideoDecoderConfigs>
191   GetSupportedVideoDecoderConfigsStatic(
192       base::WeakPtr<MediaGpuChannelManager> manager,
193       const gpu::GpuPreferences& gpu_preferences,
194       const gpu::GpuDriverBugWorkarounds& gpu_workarounds,
195       const gpu::GPUInfo& gpu_info);
196
197  private:
198   // Cross-platform cache supported config cache.
199   absl::optional<SupportedVideoDecoderConfigs> supported_config_cache_;
200
201   gpu::GpuPreferences gpu_preferences_;
202   gpu::GpuDriverBugWorkarounds gpu_workarounds_;
203   gpu::GpuFeatureInfo gpu_feature_info_;
204   gpu::GPUInfo gpu_info_;
205   scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner_;
206   base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager_;
207   AndroidOverlayMojoFactoryCB android_overlay_factory_cb_;
208   const raw_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory_;
209 };
210
211 }  // namespace media
212
213 #endif  // MEDIA_MOJO_SERVICES_GPU_MOJO_MEDIA_CLIENT_H_