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

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/common/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 return base::WeakPtr<gpu::gles2::GLES2Decoder>();
38 }
39 }
40
41 // static
42 scoped_ptr<GpuVideoDecodeAcceleratorFactory>
43 GpuVideoDecodeAcceleratorFactory::Create(
44 const gpu_vda_helpers::GetGLContextCb& get_gl_context_cb,
45 const gpu_vda_helpers::MakeGLContextCurrentCb& make_context_current_cb,
46 const gpu_vda_helpers::BindGLImageCb& 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 gpu_vda_helpers::GetGLContextCb& get_gl_context_cb,
56 const gpu_vda_helpers::MakeGLContextCurrentCb& make_context_current_cb,
57 const gpu_vda_helpers::BindGLImageCb& bind_image_cb,
58 const gpu_vda_helpers::GetGLES2DecoderCb& 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 media::VideoDecodeAccelerator::Capabilities capabilities;
68 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
69 if (cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
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 DCHECK(thread_checker_.CalledOnValidThread());
112
113 // Array of Create..VDA() function pointers, potentially usable on current
114 // platform. This list is ordered by priority, from most to least preferred,
115 // if applicable. This list must be in the same order as the querying order
116 // in GetDecoderCapabilities() above.
117 const GpuVideoDecodeAcceleratorFactory::CreateVDAFp create_vda_fps[] = {
118 &GpuVideoDecodeAcceleratorFactory::CreateDXVAVDA,
119 &GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA,
120 &GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA,
121 &GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA,
122 &GpuVideoDecodeAcceleratorFactory::CreateVTVDA,
123 &GpuVideoDecodeAcceleratorFactory::CreateOzoneVDA,
124 &GpuVideoDecodeAcceleratorFactory::CreateAndroidVDA};
125
126 scoped_ptr<media::VideoDecodeAccelerator> vda;
127
128 for (const auto& create_vda_function : create_vda_fps) {
129 vda = (this->*create_vda_function)();
130 if (vda && vda->Initialize(config, client))
131 return vda;
132 }
133
134 return nullptr;
135 }
136
137 scoped_ptr<media::VideoDecodeAccelerator>
138 GpuVideoDecodeAcceleratorFactory::CreateDXVAVDA() {
139 scoped_ptr<media::VideoDecodeAccelerator> decoder;
140 #if defined(OS_WIN)
141 if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
142 DVLOG(0) << "Initializing DXVA HW decoder for windows.";
143 decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_cb_,
144 get_gl_context_cb_));
145 }
146 #endif
147 return decoder;
148 }
149
150 scoped_ptr<media::VideoDecodeAccelerator>
151 GpuVideoDecodeAcceleratorFactory::CreateV4L2VDA() {
152 scoped_ptr<media::VideoDecodeAccelerator> decoder;
153 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
154 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
155 if (device.get()) {
156 decoder.reset(new V4L2VideoDecodeAccelerator(
157 gfx::GLSurfaceEGL::GetHardwareDisplay(), get_gl_context_cb_,
158 make_context_current_cb_, device));
159 }
160 #endif
161 return decoder;
162 }
163
164 scoped_ptr<media::VideoDecodeAccelerator>
165 GpuVideoDecodeAcceleratorFactory::CreateV4L2SVDA() {
166 scoped_ptr<media::VideoDecodeAccelerator> decoder;
167 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
168 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
169 if (device.get()) {
170 decoder.reset(new V4L2SliceVideoDecodeAccelerator(
171 device, gfx::GLSurfaceEGL::GetHardwareDisplay(), get_gl_context_cb_,
172 make_context_current_cb_));
173 }
174 #endif
175 return decoder;
176 }
177
178 scoped_ptr<media::VideoDecodeAccelerator>
179 GpuVideoDecodeAcceleratorFactory::CreateVaapiVDA() {
180 scoped_ptr<media::VideoDecodeAccelerator> decoder;
181 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
182 decoder.reset(new VaapiVideoDecodeAccelerator(make_context_current_cb_,
183 bind_image_cb_));
184 #endif
185 return decoder;
186 }
187
188 scoped_ptr<media::VideoDecodeAccelerator>
189 GpuVideoDecodeAcceleratorFactory::CreateVTVDA() {
190 scoped_ptr<media::VideoDecodeAccelerator> decoder;
191 #if defined(OS_MACOSX)
192 decoder.reset(
193 new VTVideoDecodeAccelerator(make_context_current_cb_, bind_image_cb_));
194 #endif
195 return decoder;
196 }
197
198 scoped_ptr<media::VideoDecodeAccelerator>
199 GpuVideoDecodeAcceleratorFactory::CreateOzoneVDA() {
200 scoped_ptr<media::VideoDecodeAccelerator> decoder;
201 #if !defined(OS_CHROMEOS) && defined(USE_OZONE)
202 media::MediaOzonePlatform* platform =
203 media::MediaOzonePlatform::GetInstance();
204 decoder.reset(
205 platform->CreateVideoDecodeAccelerator(make_context_current_cb_));
206 #endif
207 return decoder;
208 }
209
210 scoped_ptr<media::VideoDecodeAccelerator>
211 GpuVideoDecodeAcceleratorFactory::CreateAndroidVDA() {
212 scoped_ptr<media::VideoDecodeAccelerator> decoder;
213 #if defined(OS_ANDROID)
214 decoder.reset(new AndroidVideoDecodeAccelerator(make_context_current_cb_,
215 get_gles2_decoder_cb_));
216 #endif
217 return decoder;
218 }
219
220 GpuVideoDecodeAcceleratorFactory::GpuVideoDecodeAcceleratorFactory(
221 const gpu_vda_helpers::GetGLContextCb& get_gl_context_cb,
222 const gpu_vda_helpers::MakeGLContextCurrentCb& make_context_current_cb,
223 const gpu_vda_helpers::BindGLImageCb& bind_image_cb,
224 const gpu_vda_helpers::GetGLES2DecoderCb& get_gles2_decoder_cb)
225 : get_gl_context_cb_(get_gl_context_cb),
226 make_context_current_cb_(make_context_current_cb),
227 bind_image_cb_(bind_image_cb),
228 get_gles2_decoder_cb_(get_gles2_decoder_cb) {}
229
230 GpuVideoDecodeAcceleratorFactory::~GpuVideoDecodeAcceleratorFactory() {}
231
232 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698