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