OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
jam
2016/03/16 20:56:43
this file should be in content/gpu to match the lo
Pawel Osciak
2016/03/17 11:15:16
content/gpu is very generic, perhaps the public he
jam
2016/03/17 15:43:26
not sure what "generic" has to do with it?
in gen
jam
2016/03/18 01:18:56
ditto, ignore this comment now. the current files
| |
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 "content/common/gpu/media/gpu_video_accelerator_util.h" | |
6 #include "content/common/gpu/media/gpu_video_decode_accelerator.h" | |
7 #include "content/public/gpu/gpu_video_decode_accelerator_factory.h" | |
8 #include "gpu/command_buffer/service/gpu_preferences.h" | |
9 | |
10 #if defined(OS_WIN) | |
11 #include "base/win/windows_version.h" | |
12 #include "content/common/gpu/media/dxva_video_decode_accelerator_win.h" | |
13 #elif defined(OS_MACOSX) | |
14 #include "content/common/gpu/media/vt_video_decode_accelerator_mac.h" | |
15 #elif defined(OS_CHROMEOS) | |
16 #if defined(USE_V4L2_CODEC) | |
17 #include "content/common/gpu/media/v4l2_device.h" | |
18 #include "content/common/gpu/media/v4l2_slice_video_decode_accelerator.h" | |
19 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h" | |
20 #include "ui/gl/gl_surface_egl.h" | |
21 #endif | |
22 #if defined(ARCH_CPU_X86_FAMILY) | |
23 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" | |
24 #include "ui/gl/gl_implementation.h" | |
25 #endif | |
26 #elif defined(USE_OZONE) | |
27 #include "media/ozone/media_ozone_platform.h" | |
28 #elif defined(OS_ANDROID) | |
29 #include "content/common/gpu/media/android_video_decode_accelerator.h" | |
30 #endif | |
31 | |
32 namespace content { | |
33 | |
34 namespace { | |
35 static base::WeakPtr<gpu::gles2::GLES2Decoder> GetEmptyGLES2Decoder() { | |
36 NOTREACHED() << "VDA requests a GLES2Decoder, but client did not provide it"; | |
37 return base::WeakPtr<gpu::gles2::GLES2Decoder>(); | |
38 } | |
39 } | |
40 | |
41 // static | |
42 scoped_ptr<GpuVideoDecodeAcceleratorFactory> | |
43 GpuVideoDecodeAcceleratorFactory::Create( | |
44 const GetGLContextCallback& get_gl_context_cb, | |
45 const MakeGLContextCurrentCallback& make_context_current_cb, | |
46 const BindGLImageCallback& bind_image_cb) { | |
47 return make_scoped_ptr(new GpuVideoDecodeAcceleratorFactory( | |
48 get_gl_context_cb, make_context_current_cb, bind_image_cb, | |
49 base::Bind(&GetEmptyGLES2Decoder))); | |
50 } | |
51 | |
52 // static | |
53 scoped_ptr<GpuVideoDecodeAcceleratorFactory> | |
54 GpuVideoDecodeAcceleratorFactory::CreateWithGLES2Decoder( | |
55 const GetGLContextCallback& get_gl_context_cb, | |
56 const MakeGLContextCurrentCallback& make_context_current_cb, | |
57 const BindGLImageCallback& bind_image_cb, | |
58 const GetGLES2DecoderCallback& get_gles2_decoder_cb) { | |
59 return make_scoped_ptr(new GpuVideoDecodeAcceleratorFactory( | |
60 get_gl_context_cb, make_context_current_cb, bind_image_cb, | |
61 get_gles2_decoder_cb)); | |
62 } | |
63 | |
64 // static | |
65 gpu::VideoDecodeAcceleratorCapabilities | |
66 GpuVideoDecodeAcceleratorFactory::GetDecoderCapabilities( | |
67 const gpu::GpuPreferences& gpu_preferences) { | |
68 media::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 media::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 = AndroidVideoDecodeAccelerator::GetCapabilities(); | |
102 #endif | |
103 return GpuVideoAcceleratorUtil::ConvertMediaToGpuDecodeCapabilities( | |
104 capabilities); | |
105 } | |
106 | |
107 scoped_ptr<media::VideoDecodeAccelerator> | |
108 GpuVideoDecodeAcceleratorFactory::CreateVDA( | |
109 media::VideoDecodeAccelerator::Client* client, | |
110 const media::VideoDecodeAccelerator::Config& config, | |
111 const gpu::GpuPreferences& gpu_preferences) { | |
112 DCHECK(thread_checker_.CalledOnValidThread()); | |
113 | |
114 if (gpu_preferences.disable_accelerated_video_decode) | |
115 return nullptr; | |
116 | |
117 // Array of Create..VDA() function pointers, potentially usable on current | |
118 // platform. This list is ordered by priority, from most to least preferred, | |
119 // if applicable. This list must be in the same order as the querying order | |
120 // in GetDecoderCapabilities() above. | |
121 using CreateVDAFp = scoped_ptr<media::VideoDecodeAccelerator> ( | |
122 GpuVideoDecodeAcceleratorFactory::*)(const gpu::GpuPreferences&) const; | |
123 const CreateVDAFp create_vda_fps[] = { | |
124 #if defined(OS_WIN) | |
125 &GpuVideoDecodeAcceleratorFactory::CreateDXVAVDA, | |
126 #endif | |
127 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
128 &GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA, | |
129 &GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA, | |
130 #endif | |
131 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
132 &GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA, | |
133 #endif | |
134 #if defined(OS_MACOSX) | |
135 &GpuVideoDecodeAcceleratorFactory::CreateVTVDA, | |
136 #endif | |
137 #if !defined(OS_CHROMEOS) && defined(USE_OZONE) | |
138 &GpuVideoDecodeAcceleratorFactory::CreateOzoneVDA, | |
139 #endif | |
140 #if defined(OS_ANDROID) | |
141 &GpuVideoDecodeAcceleratorFactory::CreateAndroidVDA, | |
142 #endif | |
143 }; | |
144 | |
145 scoped_ptr<media::VideoDecodeAccelerator> vda; | |
146 | |
147 for (const auto& create_vda_function : create_vda_fps) { | |
148 vda = (this->*create_vda_function)(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 scoped_ptr<media::VideoDecodeAccelerator> | |
158 GpuVideoDecodeAcceleratorFactory::CreateDXVAVDA( | |
159 const gpu::GpuPreferences& gpu_preferences) const { | |
160 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
161 if (base::win::GetVersion() >= base::win::VERSION_WIN7) { | |
162 DVLOG(0) << "Initializing DXVA HW decoder for windows."; | |
163 decoder.reset(new DXVAVideoDecodeAccelerator( | |
164 get_gl_context_cb_, make_context_current_cb_, | |
165 gpu_preferences.enable_accelerated_vpx_decode)); | |
166 } | |
167 return decoder; | |
168 } | |
169 #endif | |
170 | |
171 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
172 scoped_ptr<media::VideoDecodeAccelerator> | |
173 GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA( | |
174 const gpu::GpuPreferences& gpu_preferences) const { | |
175 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
176 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
177 if (device.get()) { | |
178 decoder.reset(new V4L2VideoDecodeAccelerator( | |
179 gfx::GLSurfaceEGL::GetHardwareDisplay(), get_gl_context_cb_, | |
180 make_context_current_cb_, device)); | |
181 } | |
182 return decoder; | |
183 } | |
184 | |
185 scoped_ptr<media::VideoDecodeAccelerator> | |
186 GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA( | |
187 const gpu::GpuPreferences& gpu_preferences) const { | |
188 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
189 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder); | |
190 if (device.get()) { | |
191 decoder.reset(new V4L2SliceVideoDecodeAccelerator( | |
192 device, gfx::GLSurfaceEGL::GetHardwareDisplay(), get_gl_context_cb_, | |
193 make_context_current_cb_)); | |
194 } | |
195 return decoder; | |
196 } | |
197 #endif | |
198 | |
199 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
200 scoped_ptr<media::VideoDecodeAccelerator> | |
201 GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA( | |
202 const gpu::GpuPreferences& gpu_preferences) const { | |
203 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
204 decoder.reset(new VaapiVideoDecodeAccelerator(make_context_current_cb_, | |
205 bind_image_cb_)); | |
206 return decoder; | |
207 } | |
208 #endif | |
209 | |
210 #if defined(OS_MACOSX) | |
211 scoped_ptr<media::VideoDecodeAccelerator> | |
212 GpuVideoDecodeAcceleratorFactory::CreateVTVDA( | |
213 const gpu::GpuPreferences& gpu_preferences) const { | |
214 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
215 decoder.reset( | |
216 new VTVideoDecodeAccelerator(make_context_current_cb_, bind_image_cb_)); | |
217 return decoder; | |
218 } | |
219 #endif | |
220 | |
221 #if !defined(OS_CHROMEOS) && defined(USE_OZONE) | |
222 scoped_ptr<media::VideoDecodeAccelerator> | |
223 GpuVideoDecodeAcceleratorFactory::CreateOzoneVDA( | |
224 const gpu::GpuPreferences& gpu_preferences) const { | |
225 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
226 media::MediaOzonePlatform* platform = | |
227 media::MediaOzonePlatform::GetInstance(); | |
228 decoder.reset( | |
229 platform->CreateVideoDecodeAccelerator(make_context_current_cb_)); | |
230 return decoder; | |
231 } | |
232 #endif | |
233 | |
234 #if defined(OS_ANDROID) | |
235 scoped_ptr<media::VideoDecodeAccelerator> | |
236 GpuVideoDecodeAcceleratorFactory::CreateAndroidVDA( | |
237 const gpu::GpuPreferences& gpu_preferences) const { | |
238 scoped_ptr<media::VideoDecodeAccelerator> decoder; | |
239 decoder.reset(new AndroidVideoDecodeAccelerator(make_context_current_cb_, | |
240 get_gles2_decoder_cb_)); | |
241 return decoder; | |
242 } | |
243 #endif | |
244 | |
245 GpuVideoDecodeAcceleratorFactory::GpuVideoDecodeAcceleratorFactory( | |
246 const GetGLContextCallback& get_gl_context_cb, | |
247 const MakeGLContextCurrentCallback& make_context_current_cb, | |
248 const BindGLImageCallback& bind_image_cb, | |
249 const GetGLES2DecoderCallback& get_gles2_decoder_cb) | |
250 : get_gl_context_cb_(get_gl_context_cb), | |
251 make_context_current_cb_(make_context_current_cb), | |
252 bind_image_cb_(bind_image_cb), | |
253 get_gles2_decoder_cb_(get_gles2_decoder_cb) {} | |
254 | |
255 GpuVideoDecodeAcceleratorFactory::~GpuVideoDecodeAcceleratorFactory() {} | |
256 | |
257 } // namespace content | |
OLD | NEW |