OLD | NEW |
| (Empty) |
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 | |
5 #include "media/gpu/gpu_video_decode_accelerator_factory_impl.h" | |
6 | |
7 #include "base/memory/ptr_util.h" | |
8 #include "gpu/command_buffer/service/gpu_preferences.h" | |
9 #include "media/gpu/gpu_video_accelerator_util.h" | |
10 #include "media/gpu/media_gpu_export.h" | |
11 | |
12 #if defined(OS_WIN) | |
13 #include "base/win/windows_version.h" | |
14 #include "media/gpu/dxva_video_decode_accelerator_win.h" | |
15 #elif defined(OS_MACOSX) | |
16 #include "media/gpu/vt_video_decode_accelerator_mac.h" | |
17 #elif defined(OS_CHROMEOS) | |
18 #if defined(USE_V4L2_CODEC) | |
19 #include "media/gpu/v4l2_device.h" | |
20 #include "media/gpu/v4l2_slice_video_decode_accelerator.h" | |
21 #include "media/gpu/v4l2_video_decode_accelerator.h" | |
22 #include "ui/gl/gl_surface_egl.h" | |
23 #endif | |
24 #if defined(ARCH_CPU_X86_FAMILY) | |
25 #include "media/gpu/vaapi_video_decode_accelerator.h" | |
26 #include "ui/gl/gl_implementation.h" | |
27 #endif | |
28 #elif defined(OS_ANDROID) | |
29 #include "media/gpu/android_video_decode_accelerator.h" | |
30 #endif | |
31 | |
32 namespace media { | |
33 | |
34 // static | |
35 MEDIA_GPU_EXPORT std::unique_ptr<GpuVideoDecodeAcceleratorFactoryImpl> | |
36 GpuVideoDecodeAcceleratorFactoryImpl::Create( | |
37 const GetGLContextCallback& get_gl_context_cb, | |
38 const MakeGLContextCurrentCallback& make_context_current_cb, | |
39 const BindGLImageCallback& bind_image_cb) { | |
40 return base::WrapUnique(new GpuVideoDecodeAcceleratorFactoryImpl( | |
41 get_gl_context_cb, make_context_current_cb, bind_image_cb, | |
42 GetGLES2DecoderCallback())); | |
43 } | |
44 | |
45 // static | |
46 MEDIA_GPU_EXPORT std::unique_ptr<GpuVideoDecodeAcceleratorFactoryImpl> | |
47 GpuVideoDecodeAcceleratorFactoryImpl::CreateWithGLES2Decoder( | |
48 const GetGLContextCallback& get_gl_context_cb, | |
49 const MakeGLContextCurrentCallback& make_context_current_cb, | |
50 const BindGLImageCallback& bind_image_cb, | |
51 const GetGLES2DecoderCallback& get_gles2_decoder_cb) { | |
52 return base::WrapUnique(new GpuVideoDecodeAcceleratorFactoryImpl( | |
53 get_gl_context_cb, make_context_current_cb, bind_image_cb, | |
54 get_gles2_decoder_cb)); | |
55 } | |
56 | |
57 // static | |
58 MEDIA_GPU_EXPORT std::unique_ptr<GpuVideoDecodeAcceleratorFactoryImpl> | |
59 GpuVideoDecodeAcceleratorFactoryImpl::CreateWithNoGL() { | |
60 return Create(GetGLContextCallback(), MakeGLContextCurrentCallback(), | |
61 BindGLImageCallback()); | |
62 } | |
63 | |
64 // static | |
65 MEDIA_GPU_EXPORT gpu::VideoDecodeAcceleratorCapabilities | |
66 GpuVideoDecodeAcceleratorFactoryImpl::GetDecoderCapabilities( | |
67 const gpu::GpuPreferences& gpu_preferences) { | |
68 VideoDecodeAccelerator::Capabilities capabilities; | |
69 if (gpu_preferences.disable_accelerated_video_decode) | |
70 return gpu::VideoDecodeAcceleratorCapabilities(); | |
71 | |
72 // Query VDAs for their capabilities and construct a set of supported | |
73 // profiles for current platform. This must be done in the same order as in | |
74 // CreateVDA(), as we currently preserve additional capabilities (such as | |
75 // resolutions supported) only for the first VDA supporting the given codec | |
76 // profile (instead of calculating a superset). | |
77 // TODO(posciak,henryhsu): improve this so that we choose a superset of | |
78 // resolutions and other supported profile parameters. | |
79 #if defined(OS_WIN) | |
80 capabilities.supported_profiles = | |
81 DXVAVideoDecodeAccelerator::GetSupportedProfiles(); | |
82 #elif defined(OS_CHROMEOS) | |
83 VideoDecodeAccelerator::SupportedProfiles vda_profiles; | |
84 #if defined(USE_V4L2_CODEC) | |
85 vda_profiles = V4L2VideoDecodeAccelerator::GetSupportedProfiles(); | |
86 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles( | |
87 vda_profiles, &capabilities.supported_profiles); | |
88 vda_profiles = V4L2SliceVideoDecodeAccelerator::GetSupportedProfiles(); | |
89 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles( | |
90 vda_profiles, &capabilities.supported_profiles); | |
91 #endif | |
92 #if defined(ARCH_CPU_X86_FAMILY) | |
93 vda_profiles = VaapiVideoDecodeAccelerator::GetSupportedProfiles(); | |
94 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles( | |
95 vda_profiles, &capabilities.supported_profiles); | |
96 #endif | |
97 #elif defined(OS_MACOSX) | |
98 capabilities.supported_profiles = | |
99 VTVideoDecodeAccelerator::GetSupportedProfiles(); | |
100 #elif defined(OS_ANDROID) | |
101 capabilities = | |
102 AndroidVideoDecodeAccelerator::GetCapabilities(gpu_preferences); | |
103 #endif | |
104 return GpuVideoAcceleratorUtil::ConvertMediaToGpuDecodeCapabilities( | |
105 capabilities); | |
106 } | |
107 | |
108 MEDIA_GPU_EXPORT std::unique_ptr<VideoDecodeAccelerator> | |
109 GpuVideoDecodeAcceleratorFactoryImpl::CreateVDA( | |
110 VideoDecodeAccelerator::Client* client, | |
111 const VideoDecodeAccelerator::Config& config, | |
112 const gpu::GpuDriverBugWorkarounds& workarounds, | |
113 const gpu::GpuPreferences& gpu_preferences) { | |
114 DCHECK(thread_checker_.CalledOnValidThread()); | |
115 | |
116 if (gpu_preferences.disable_accelerated_video_decode) | |
117 return nullptr; | |
118 | |
119 // Array of Create..VDA() function pointers, potentially usable on current | |
120 // platform. This list is ordered by priority, from most to least preferred, | |
121 // if applicable. This list must be in the same order as the querying order | |
122 // in GetDecoderCapabilities() above. | |
123 using CreateVDAFp = std::unique_ptr<VideoDecodeAccelerator> ( | |
124 GpuVideoDecodeAcceleratorFactoryImpl::*)( | |
125 const gpu::GpuDriverBugWorkarounds&, const gpu::GpuPreferences&) const; | |
126 const CreateVDAFp create_vda_fps[] = { | |
127 #if defined(OS_WIN) | |
128 &GpuVideoDecodeAcceleratorFactoryImpl::CreateDXVAVDA, | |
129 #endif | |
130 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
131 &GpuVideoDecodeAcceleratorFactoryImpl::CreateV4L2VDA, | |
132 &GpuVideoDecodeAcceleratorFactoryImpl::CreateV4L2SVDA, | |
133 #endif | |
134 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
135 &GpuVideoDecodeAcceleratorFactoryImpl::CreateVaapiVDA, | |
136 #endif | |
137 #if defined(OS_MACOSX) | |
138 &GpuVideoDecodeAcceleratorFactoryImpl::CreateVTVDA, | |
139 #endif | |
140 #if defined(OS_ANDROID) | |
141 &GpuVideoDecodeAcceleratorFactoryImpl::CreateAndroidVDA, | |
142 #endif | |
143 }; | |
144 | |
145 std::unique_ptr<VideoDecodeAccelerator> vda; | |
146 | |
147 for (const auto& create_vda_function : create_vda_fps) { | |
148 vda = (this->*create_vda_function)(workarounds, gpu_preferences); | |
149 if (vda && vda->Initialize(config, client)) | |
150 return vda; | |
151 } | |
152 | |
153 return nullptr; | |
154 } | |
155 | |
156 #if defined(OS_WIN) | |
157 std::unique_ptr<VideoDecodeAccelerator> | |
158 GpuVideoDecodeAcceleratorFactoryImpl::CreateDXVAVDA( | |
159 const gpu::GpuDriverBugWorkarounds& workarounds, | |
160 const gpu::GpuPreferences& gpu_preferences) const { | |
161 std::unique_ptr<VideoDecodeAccelerator> decoder; | |
162 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { | |
163 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | |
164 decoder.reset(new DXVAVideoDecodeAccelerator(get_gl_context_cb_, | |
165 make_context_current_cb_, | |
166 workarounds, gpu_preferences)); | |
167 } | |
168 return decoder; | |
169 } | |
170 #endif | |
171 | |
172 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
173 std::unique_ptr<VideoDecodeAccelerator> | |
174 GpuVideoDecodeAcceleratorFactoryImpl::CreateV4L2VDA( | |
175 const gpu::GpuDriverBugWorkarounds& workarounds, | |
176 const gpu::GpuPreferences& gpu_preferences) const { | |
177 std::unique_ptr<VideoDecodeAccelerator> decoder; | |
178 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
179 if (device.get()) { | |
180 decoder.reset(new V4L2VideoDecodeAccelerator( | |
181 gl::GLSurfaceEGL::GetHardwareDisplay(), get_gl_context_cb_, | |
182 make_context_current_cb_, device)); | |
183 } | |
184 return decoder; | |
185 } | |
186 | |
187 std::unique_ptr<VideoDecodeAccelerator> | |
188 GpuVideoDecodeAcceleratorFactoryImpl::CreateV4L2SVDA( | |
189 const gpu::GpuDriverBugWorkarounds& workarounds, | |
190 const gpu::GpuPreferences& gpu_preferences) const { | |
191 std::unique_ptr<VideoDecodeAccelerator> decoder; | |
192 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
193 if (device.get()) { | |
194 decoder.reset(new V4L2SliceVideoDecodeAccelerator( | |
195 device, gl::GLSurfaceEGL::GetHardwareDisplay(), get_gl_context_cb_, | |
196 make_context_current_cb_)); | |
197 } | |
198 return decoder; | |
199 } | |
200 #endif | |
201 | |
202 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
203 std::unique_ptr<VideoDecodeAccelerator> | |
204 GpuVideoDecodeAcceleratorFactoryImpl::CreateVaapiVDA( | |
205 const gpu::GpuDriverBugWorkarounds& workarounds, | |
206 const gpu::GpuPreferences& gpu_preferences) const { | |
207 std::unique_ptr<VideoDecodeAccelerator> decoder; | |
208 decoder.reset(new VaapiVideoDecodeAccelerator(make_context_current_cb_, | |
209 bind_image_cb_)); | |
210 return decoder; | |
211 } | |
212 #endif | |
213 | |
214 #if defined(OS_MACOSX) | |
215 std::unique_ptr<VideoDecodeAccelerator> | |
216 GpuVideoDecodeAcceleratorFactoryImpl::CreateVTVDA( | |
217 const gpu::GpuDriverBugWorkarounds& workarounds, | |
218 const gpu::GpuPreferences& gpu_preferences) const { | |
219 std::unique_ptr<VideoDecodeAccelerator> decoder; | |
220 decoder.reset( | |
221 new VTVideoDecodeAccelerator(make_context_current_cb_, bind_image_cb_)); | |
222 return decoder; | |
223 } | |
224 #endif | |
225 | |
226 #if defined(OS_ANDROID) | |
227 std::unique_ptr<VideoDecodeAccelerator> | |
228 GpuVideoDecodeAcceleratorFactoryImpl::CreateAndroidVDA( | |
229 const gpu::GpuDriverBugWorkarounds& workarounds, | |
230 const gpu::GpuPreferences& gpu_preferences) const { | |
231 std::unique_ptr<VideoDecodeAccelerator> decoder; | |
232 decoder.reset(new AndroidVideoDecodeAccelerator(make_context_current_cb_, | |
233 get_gles2_decoder_cb_)); | |
234 return decoder; | |
235 } | |
236 #endif | |
237 | |
238 GpuVideoDecodeAcceleratorFactoryImpl::GpuVideoDecodeAcceleratorFactoryImpl( | |
239 const GetGLContextCallback& get_gl_context_cb, | |
240 const MakeGLContextCurrentCallback& make_context_current_cb, | |
241 const BindGLImageCallback& bind_image_cb, | |
242 const GetGLES2DecoderCallback& get_gles2_decoder_cb) | |
243 : get_gl_context_cb_(get_gl_context_cb), | |
244 make_context_current_cb_(make_context_current_cb), | |
245 bind_image_cb_(bind_image_cb), | |
246 get_gles2_decoder_cb_(get_gles2_decoder_cb) {} | |
247 | |
248 GpuVideoDecodeAcceleratorFactoryImpl::~GpuVideoDecodeAcceleratorFactoryImpl() {} | |
249 | |
250 } // namespace media | |
OLD | NEW |