Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // This file contains an implementation of VaapiWrapper, used by | 5 // This file contains an implementation of VaapiWrapper, used by |
| 6 // VaapiVideoDecodeAccelerator and VaapiH264Decoder for decode, | 6 // VaapiVideoDecodeAccelerator and VaapiH264Decoder for decode, |
| 7 // and VaapiVideoEncodeAccelerator for encode, to interface | 7 // and VaapiVideoEncodeAccelerator for encode, to interface |
| 8 // with libva (VA-API library for hardware video codec). | 8 // with libva (VA-API library for hardware video codec). |
| 9 | 9 |
| 10 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 10 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
| 11 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 11 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
| 12 | 12 |
| 13 #include <set> | 13 #include <set> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/lazy_instance.h" | |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
| 18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 19 #include "content/common/gpu/media/va_surface.h" | 20 #include "content/common/gpu/media/va_surface.h" |
| 20 #include "media/base/video_decoder_config.h" | 21 #include "media/base/video_decoder_config.h" |
| 21 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
| 23 #include "media/video/video_encode_accelerator.h" | |
| 22 #include "third_party/libva/va/va.h" | 24 #include "third_party/libva/va/va.h" |
| 23 #include "third_party/libva/va/va_vpp.h" | 25 #include "third_party/libva/va/va_vpp.h" |
| 24 #include "ui/gfx/geometry/size.h" | 26 #include "ui/gfx/geometry/size.h" |
| 25 #if defined(USE_X11) | 27 #if defined(USE_X11) |
| 26 #include "third_party/libva/va/va_x11.h" | 28 #include "third_party/libva/va/va_x11.h" |
| 27 #endif // USE_X11 | 29 #endif // USE_X11 |
| 28 | 30 |
| 29 namespace content { | 31 namespace content { |
| 30 | 32 |
| 31 // This class handles VA-API calls and ensures proper locking of VA-API calls | 33 // This class handles VA-API calls and ensures proper locking of VA-API calls |
| 32 // to libva, the userspace shim to the HW codec driver. libva is not | 34 // to libva, the userspace shim to the HW codec driver. libva is not |
| 33 // thread-safe, so we have to perform locking ourselves. This class is fully | 35 // thread-safe, so we have to perform locking ourselves. This class is fully |
| 34 // synchronous and its methods can be called from any thread and may wait on | 36 // synchronous and its methods can be called from any thread and may wait on |
| 35 // the va_lock_ while other, concurrent calls run. | 37 // the va_lock_ while other, concurrent calls run. |
| 36 // | 38 // |
| 37 // This class is responsible for managing VAAPI connection, contexts and state. | 39 // This class is responsible for managing VAAPI connection, contexts and state. |
| 38 // It is also responsible for managing and freeing VABuffers (not VASurfaces), | 40 // It is also responsible for managing and freeing VABuffers (not VASurfaces), |
| 39 // which are used to queue parameters and slice data to the HW codec, | 41 // which are used to queue parameters and slice data to the HW codec, |
| 40 // as well as underlying memory for VASurfaces themselves. | 42 // as well as underlying memory for VASurfaces themselves. |
| 41 class CONTENT_EXPORT VaapiWrapper { | 43 class CONTENT_EXPORT VaapiWrapper { |
| 42 public: | 44 public: |
| 43 enum CodecMode { | 45 enum CodecMode { |
| 44 kDecode, | 46 kDecode, |
| 45 kEncode, | 47 kEncode, |
| 48 kCodecModeMax, | |
| 46 }; | 49 }; |
| 47 | 50 |
| 48 // Create VaapiWrapper for VAProfile. | 51 // Return an instance of VaapiWrapper and initialize by |va_profile| and |
|
Pawel Osciak
2015/03/02 11:00:21
s/and initialize by/initialized for/
henryhsu
2015/03/03 10:48:03
Done.
| |
| 49 // |report_error_to_uma_cb| will be called independently from reporting | 52 // |mode|. |report_error_to_uma_cb| will be called independently from |
| 50 // errors to clients via method return values. | 53 // reporting errors to clients via method return values. |
| 51 static scoped_ptr<VaapiWrapper> Create( | 54 static scoped_ptr<VaapiWrapper> Create( |
| 52 CodecMode mode, | 55 CodecMode mode, |
| 53 VAProfile profile, | 56 VAProfile va_profile, |
| 54 const base::Closure& report_error_to_uma_cb); | 57 const base::Closure& report_error_to_uma_cb); |
| 55 | 58 |
| 56 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile | 59 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile |
| 57 // |profile| to VAProfile. | 60 // |profile| to VAProfile. |
| 58 // |report_error_to_uma_cb| will be called independently from reporting | 61 // |report_error_to_uma_cb| will be called independently from reporting |
| 59 // errors to clients via method return values. | 62 // errors to clients via method return values. |
| 60 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( | 63 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( |
| 61 CodecMode mode, | 64 CodecMode mode, |
| 62 media::VideoCodecProfile profile, | 65 media::VideoCodecProfile profile, |
| 63 const base::Closure& report_error_to_uma_cb); | 66 const base::Closure& report_error_to_uma_cb); |
| 64 | 67 |
| 65 // Return the supported encode profiles. | 68 // Return the supported encode profiles. |
| 66 static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( | 69 static std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
| 67 const base::Closure& report_error_to_uma_cb); | 70 GetSupportedEncodeProfiles(); |
| 68 | 71 |
| 69 ~VaapiWrapper(); | 72 ~VaapiWrapper(); |
| 70 | 73 |
| 71 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each | 74 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each |
| 72 // of size |size|. Returns true when successful, with the created IDs in | 75 // of size |size|. Returns true when successful, with the created IDs in |
| 73 // |va_surfaces| to be managed and later wrapped in VASurfaces. | 76 // |va_surfaces| to be managed and later wrapped in VASurfaces. |
| 74 // The client must DestroySurfaces() each time before calling this method | 77 // The client must DestroySurfaces() each time before calling this method |
| 75 // again to free the allocated surfaces first, but is not required to do so | 78 // again to free the allocated surfaces first, but is not required to do so |
| 76 // at destruction time, as this will be done automatically from | 79 // at destruction time, as this will be done automatically from |
| 77 // the destructor. | 80 // the destructor. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 | 179 |
| 177 // Blits a VASurface |va_surface_id_src| into another VASurface | 180 // Blits a VASurface |va_surface_id_src| into another VASurface |
| 178 // |va_surface_id_dest| applying pixel format conversion and scaling | 181 // |va_surface_id_dest| applying pixel format conversion and scaling |
| 179 // if needed. | 182 // if needed. |
| 180 bool BlitSurface(VASurfaceID va_surface_id_src, | 183 bool BlitSurface(VASurfaceID va_surface_id_src, |
| 181 const gfx::Size& src_size, | 184 const gfx::Size& src_size, |
| 182 VASurfaceID va_surface_id_dest, | 185 VASurfaceID va_surface_id_dest, |
| 183 const gfx::Size& dest_size); | 186 const gfx::Size& dest_size); |
| 184 | 187 |
| 185 private: | 188 private: |
| 189 struct ProfileInfo { | |
| 190 VAProfile va_profile; | |
| 191 VaapiWrapper::CodecMode mode; | |
|
Pawel Osciak
2015/03/02 11:00:20
s/VaapiWrapper::// ?
henryhsu
2015/03/03 10:48:02
Done.
| |
| 192 gfx::Size max_resolution; | |
| 193 }; | |
| 194 | |
| 195 class LazyProfileInfo { | |
|
wuchengli
2015/03/02 07:10:12
s/LazyProfileInfo/LazyProfileInfos/ to distinguish
henryhsu
2015/03/03 10:48:02
Done.
| |
| 196 public: | |
| 197 LazyProfileInfo(); | |
| 198 ~LazyProfileInfo(); | |
| 199 std::vector<VaapiWrapper::ProfileInfo> GetSupportedProfileInfos( | |
|
Pawel Osciak
2015/03/02 11:00:21
Are VaapiWrapper:: prefixes needed?
henryhsu
2015/03/03 10:48:02
Done.
| |
| 200 VaapiWrapper::CodecMode mode); | |
| 201 bool IsProfileSupported( | |
| 202 VaapiWrapper::CodecMode mode, VAProfile va_profile); | |
| 203 private: | |
| 204 std::vector<VaapiWrapper::ProfileInfo> | |
| 205 supported_profiles_[VaapiWrapper::kCodecModeMax]; | |
| 206 }; | |
| 207 | |
| 186 VaapiWrapper(); | 208 VaapiWrapper(); |
| 187 | 209 |
| 210 // Initialize all supported profile configs. | |
| 211 static std::vector<ProfileInfo> InitSupportedProfileInfos(); | |
|
wuchengli
2015/03/02 07:10:12
Move this near PostSandboxInitialization(). Static
henryhsu
2015/03/03 10:48:02
Done.
| |
| 212 | |
| 188 bool Initialize(CodecMode mode, VAProfile va_profile); | 213 bool Initialize(CodecMode mode, VAProfile va_profile); |
| 189 void Deinitialize(); | 214 void Deinitialize(); |
| 190 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 215 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
| 191 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 216 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
| 192 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); | 217 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); |
| 193 bool AreAttribsSupported(VAProfile va_profile, | 218 bool AreAttribsSupported(VAProfile va_profile, |
| 194 VAEntrypoint entrypoint, | 219 VAEntrypoint entrypoint, |
| 195 const std::vector<VAConfigAttrib>& required_attribs); | 220 const std::vector<VAConfigAttrib>& required_attribs); |
| 221 bool GetVaCodecMaxResolution(VAConfigID config, gfx::Size* resolution); | |
|
wuchengli
2015/03/02 07:10:12
Add function comments.
Pawel Osciak
2015/03/02 11:00:20
s/config/va_config_id/
Could we just return empty
henryhsu
2015/03/03 10:48:02
I prefer to return boolean value to consist with o
henryhsu
2015/03/03 10:48:02
Done.
| |
| 196 | 222 |
| 197 // Destroys a |va_surface| created using CreateUnownedSurface. | 223 // Destroys a |va_surface| created using CreateUnownedSurface. |
| 198 void DestroyUnownedSurface(VASurfaceID va_surface_id); | 224 void DestroyUnownedSurface(VASurfaceID va_surface_id); |
| 199 | 225 |
| 200 // Initialize the video post processing context with the |size| of | 226 // Initialize the video post processing context with the |size| of |
| 201 // the input pictures to be processed. | 227 // the input pictures to be processed. |
| 202 bool InitializeVpp_Locked(); | 228 bool InitializeVpp_Locked(); |
| 203 | 229 |
| 204 // Deinitialize the video post processing context. | 230 // Deinitialize the video post processing context. |
| 205 void DeinitializeVpp(); | 231 void DeinitializeVpp(); |
| 206 | 232 |
| 207 // Execute pending job in hardware and destroy pending buffers. Return false | 233 // Execute pending job in hardware and destroy pending buffers. Return false |
| 208 // if vaapi driver refuses to accept parameter or slice buffers submitted | 234 // if vaapi driver refuses to accept parameter or slice buffers submitted |
| 209 // by client, or if execution fails in hardware. | 235 // by client, or if execution fails in hardware. |
| 210 bool Execute(VASurfaceID va_surface_id); | 236 bool Execute(VASurfaceID va_surface_id); |
| 211 | 237 |
| 212 // Attempt to set render mode to "render to texture.". Failure is non-fatal. | 238 // Attempt to set render mode to "render to texture.". Failure is non-fatal. |
| 213 void TryToSetVADisplayAttributeToLocalGPU(); | 239 void TryToSetVADisplayAttributeToLocalGPU(); |
| 214 | 240 |
| 241 // Get all supported profile configs. | |
|
wuchengli
2015/03/02 07:10:12
s/configs/infos/
henryhsu
2015/03/03 10:48:02
Done.
| |
| 242 std::vector<ProfileInfo> GetSupportedProfileInfos(); | |
| 243 | |
| 215 // Lazily initialize static data after sandbox is enabled. Return false on | 244 // Lazily initialize static data after sandbox is enabled. Return false on |
| 216 // init failure. | 245 // init failure. |
| 217 static bool PostSandboxInitialization(); | 246 static bool PostSandboxInitialization(); |
| 218 | 247 |
| 219 // Libva is not thread safe, so we have to do locking for it ourselves. | 248 // Libva is not thread safe, so we have to do locking for it ourselves. |
| 220 // This lock is to be taken for the duration of all VA-API calls and for | 249 // This lock is to be taken for the duration of all VA-API calls and for |
| 221 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). | 250 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). |
| 222 base::Lock va_lock_; | 251 base::Lock va_lock_; |
| 223 | 252 |
| 224 // Allocated ids for VASurfaces. | 253 // Allocated ids for VASurfaces. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 248 // return values from public methods. | 277 // return values from public methods. |
| 249 base::Closure report_error_to_uma_cb_; | 278 base::Closure report_error_to_uma_cb_; |
| 250 | 279 |
| 251 // VPP (Video Post Processing) context, this is used to convert | 280 // VPP (Video Post Processing) context, this is used to convert |
| 252 // pictures used by the decoder to RGBA pictures usable by GL or the | 281 // pictures used by the decoder to RGBA pictures usable by GL or the |
| 253 // display hardware. | 282 // display hardware. |
| 254 VAConfigID va_vpp_config_id_; | 283 VAConfigID va_vpp_config_id_; |
| 255 VAContextID va_vpp_context_id_; | 284 VAContextID va_vpp_context_id_; |
| 256 VABufferID va_vpp_buffer_id_; | 285 VABufferID va_vpp_buffer_id_; |
| 257 | 286 |
| 287 static base::LazyInstance<LazyProfileInfo> profile_info_; | |
|
wuchengli
2015/03/02 07:10:12
s/profile_info/profile_infos_/. Add variable comme
henryhsu
2015/03/03 10:48:02
Done.
| |
| 288 | |
| 258 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 289 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
| 259 }; | 290 }; |
| 260 | 291 |
| 261 } // namespace content | 292 } // namespace content |
| 262 | 293 |
| 263 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 294 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
| OLD | NEW |