Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: content/common/gpu/media/gpu_video_decode_accelerator_factory.cc

Issue 1745903002: Introduce GpuVideoDecodeAcceleratorFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/command_line.h"
6 #include "content/common/gpu/media/gpu_video_accelerator_util.h"
7 #include "content/common/gpu/media/gpu_video_decode_accelerator.h"
8 #include "content/public/common/content_switches.h"
9 #include "content/public/gpu/gpu_video_decode_accelerator_factory.h"
10
11 #if defined(OS_WIN)
12 #include "base/win/windows_version.h"
13 #include "content/common/gpu/media/dxva_video_decode_accelerator_win.h"
14 #elif defined(OS_MACOSX)
15 #include "content/common/gpu/media/vt_video_decode_accelerator_mac.h"
16 #elif defined(OS_CHROMEOS)
17 #if defined(USE_V4L2_CODEC)
18 #include "content/common/gpu/media/v4l2_device.h"
19 #include "content/common/gpu/media/v4l2_slice_video_decode_accelerator.h"
20 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h"
21 #include "ui/gl/gl_surface_egl.h"
22 #endif
23 #if defined(ARCH_CPU_X86_FAMILY)
24 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
25 #include "ui/gl/gl_implementation.h"
26 #endif
27 #elif defined(USE_OZONE)
28 #include "media/ozone/media_ozone_platform.h"
29 #elif defined(OS_ANDROID)
30 #include "content/common/gpu/media/android_video_decode_accelerator.h"
31 #endif
32
33 namespace content {
34
35 namespace {
36 static base::WeakPtr<gpu::gles2::GLES2Decoder> GetEmptyGLES2Decoder() {
37 NOTREACHED() << "VDA requests a GLES2Decoder, but client did not provide it";
38 return base::WeakPtr<gpu::gles2::GLES2Decoder>();
39 }
40 }
41
42 // static
43 scoped_ptr<GpuVideoDecodeAcceleratorFactory>
44 GpuVideoDecodeAcceleratorFactory::Create(
45 const GetGLContextCallback& get_gl_context_cb,
46 const MakeGLContextCurrentCallback& make_context_current_cb,
47 const BindGLImageCallback& bind_image_cb) {
48 return make_scoped_ptr(new GpuVideoDecodeAcceleratorFactory(
49 get_gl_context_cb, make_context_current_cb, bind_image_cb,
50 base::Bind(&GetEmptyGLES2Decoder)));
51 }
52
53 // static
54 scoped_ptr<GpuVideoDecodeAcceleratorFactory>
55 GpuVideoDecodeAcceleratorFactory::CreateWithGLES2Decoder(
56 const GetGLContextCallback& get_gl_context_cb,
57 const MakeGLContextCurrentCallback& make_context_current_cb,
58 const BindGLImageCallback& bind_image_cb,
59 const GetGLES2DecoderCallback& get_gles2_decoder_cb) {
60 return make_scoped_ptr(new GpuVideoDecodeAcceleratorFactory(
61 get_gl_context_cb, make_context_current_cb, bind_image_cb,
62 get_gles2_decoder_cb));
63 }
64
65 // static
66 gpu::VideoDecodeAcceleratorCapabilities
67 GpuVideoDecodeAcceleratorFactory::GetDecoderCapabilities() {
68 media::VideoDecodeAccelerator::Capabilities capabilities;
69 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
70 if (cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
71 return gpu::VideoDecodeAcceleratorCapabilities();
72
73 // Query VDAs for their capabilities and construct a set of supported
74 // profiles for current platform. This must be done in the same order as in
75 // CreateVDA(), as we currently preserve additional capabilities (such as
76 // resolutions supported) only for the first VDA supporting the given codec
77 // profile (instead of calculating a superset).
78 // TODO(posciak,henryhsu): improve this so that we choose a superset of
79 // resolutions and other supported profile parameters.
80 #if defined(OS_WIN)
81 capabilities.supported_profiles =
82 DXVAVideoDecodeAccelerator::GetSupportedProfiles();
83 #elif defined(OS_CHROMEOS)
84 media::VideoDecodeAccelerator::SupportedProfiles vda_profiles;
85 #if defined(USE_V4L2_CODEC)
86 vda_profiles = V4L2VideoDecodeAccelerator::GetSupportedProfiles();
87 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
88 vda_profiles, &capabilities.supported_profiles);
89 vda_profiles = V4L2SliceVideoDecodeAccelerator::GetSupportedProfiles();
90 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
91 vda_profiles, &capabilities.supported_profiles);
92 #endif
93 #if defined(ARCH_CPU_X86_FAMILY)
94 vda_profiles = VaapiVideoDecodeAccelerator::GetSupportedProfiles();
95 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(
96 vda_profiles, &capabilities.supported_profiles);
97 #endif
98 #elif defined(OS_MACOSX)
99 capabilities.supported_profiles =
100 VTVideoDecodeAccelerator::GetSupportedProfiles();
101 #elif defined(OS_ANDROID)
102 capabilities = AndroidVideoDecodeAccelerator::GetCapabilities();
103 #endif
104 return GpuVideoAcceleratorUtil::ConvertMediaToGpuDecodeCapabilities(
105 capabilities);
106 }
107
108 scoped_ptr<media::VideoDecodeAccelerator>
109 GpuVideoDecodeAcceleratorFactory::CreateVDA(
110 media::VideoDecodeAccelerator::Client* client,
111 const media::VideoDecodeAccelerator::Config& config) {
112 DCHECK(thread_checker_.CalledOnValidThread());
113
114 // Array of Create..VDA() function pointers, potentially usable on current
115 // platform. This list is ordered by priority, from most to least preferred,
116 // if applicable. This list must be in the same order as the querying order
117 // in GetDecoderCapabilities() above.
118 using CreateVDAFp = scoped_ptr<media::VideoDecodeAccelerator> (
119 GpuVideoDecodeAcceleratorFactory::*)() const;
120 const CreateVDAFp create_vda_fps[] = {
121 &GpuVideoDecodeAcceleratorFactory::CreateDXVAVDA,
122 &GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA,
123 &GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA,
124 &GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA,
125 &GpuVideoDecodeAcceleratorFactory::CreateVTVDA,
126 &GpuVideoDecodeAcceleratorFactory::CreateOzoneVDA,
127 &GpuVideoDecodeAcceleratorFactory::CreateAndroidVDA};
128
129 scoped_ptr<media::VideoDecodeAccelerator> vda;
130
131 for (const auto& create_vda_function : create_vda_fps) {
132 vda = (this->*create_vda_function)();
133 if (vda && vda->Initialize(config, client))
134 return vda;
135 }
136
137 return nullptr;
138 }
139
140 scoped_ptr<media::VideoDecodeAccelerator>
141 GpuVideoDecodeAcceleratorFactory::CreateDXVAVDA() const {
142 scoped_ptr<media::VideoDecodeAccelerator> decoder;
143 #if defined(OS_WIN)
144 if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
145 DVLOG(0) << "Initializing DXVA HW decoder for windows.";
146 decoder.reset(new DXVAVideoDecodeAccelerator(get_gl_context_cb_,
147 make_context_current_cb_));
148 }
149 #endif
150 return decoder;
151 }
152
153 scoped_ptr<media::VideoDecodeAccelerator>
154 GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA() const {
155 scoped_ptr<media::VideoDecodeAccelerator> decoder;
156 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
157 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
158 if (device.get()) {
159 decoder.reset(new V4L2VideoDecodeAccelerator(
160 gfx::GLSurfaceEGL::GetHardwareDisplay(), get_gl_context_cb_,
161 make_context_current_cb_, device));
162 }
163 #endif
164 return decoder;
165 }
166
167 scoped_ptr<media::VideoDecodeAccelerator>
168 GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA() const {
169 scoped_ptr<media::VideoDecodeAccelerator> decoder;
170 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
171 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
172 if (device.get()) {
173 decoder.reset(new V4L2SliceVideoDecodeAccelerator(
174 device, gfx::GLSurfaceEGL::GetHardwareDisplay(), get_gl_context_cb_,
175 make_context_current_cb_));
176 }
177 #endif
178 return decoder;
179 }
180
181 scoped_ptr<media::VideoDecodeAccelerator>
182 GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA() const {
183 scoped_ptr<media::VideoDecodeAccelerator> decoder;
184 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
185 decoder.reset(new VaapiVideoDecodeAccelerator(make_context_current_cb_,
186 bind_image_cb_));
187 #endif
188 return decoder;
189 }
190
191 scoped_ptr<media::VideoDecodeAccelerator>
192 GpuVideoDecodeAcceleratorFactory::CreateVTVDA() const {
193 scoped_ptr<media::VideoDecodeAccelerator> decoder;
194 #if defined(OS_MACOSX)
195 decoder.reset(
196 new VTVideoDecodeAccelerator(make_context_current_cb_, bind_image_cb_));
197 #endif
198 return decoder;
199 }
200
201 scoped_ptr<media::VideoDecodeAccelerator>
202 GpuVideoDecodeAcceleratorFactory::CreateOzoneVDA() const {
203 scoped_ptr<media::VideoDecodeAccelerator> decoder;
204 #if !defined(OS_CHROMEOS) && defined(USE_OZONE)
205 media::MediaOzonePlatform* platform =
206 media::MediaOzonePlatform::GetInstance();
207 decoder.reset(
208 platform->CreateVideoDecodeAccelerator(make_context_current_cb_));
209 #endif
210 return decoder;
211 }
212
213 scoped_ptr<media::VideoDecodeAccelerator>
214 GpuVideoDecodeAcceleratorFactory::CreateAndroidVDA() const {
215 scoped_ptr<media::VideoDecodeAccelerator> decoder;
216 #if defined(OS_ANDROID)
217 decoder.reset(new AndroidVideoDecodeAccelerator(make_context_current_cb_,
218 get_gles2_decoder_cb_));
219 #endif
220 return decoder;
221 }
222
223 GpuVideoDecodeAcceleratorFactory::GpuVideoDecodeAcceleratorFactory(
224 const GetGLContextCallback& get_gl_context_cb,
225 const MakeGLContextCurrentCallback& make_context_current_cb,
226 const BindGLImageCallback& bind_image_cb,
227 const GetGLES2DecoderCallback& get_gles2_decoder_cb)
228 : get_gl_context_cb_(get_gl_context_cb),
229 make_context_current_cb_(make_context_current_cb),
230 bind_image_cb_(bind_image_cb),
231 get_gles2_decoder_cb_(get_gles2_decoder_cb) {}
232
233 GpuVideoDecodeAcceleratorFactory::~GpuVideoDecodeAcceleratorFactory() {}
234
235 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698