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/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 #include "content/common/gpu/media/va_surface.h" | 19 #include "content/common/gpu/media/va_surface.h" |
20 #include "media/base/video_decoder_config.h" | 20 #include "media/base/video_decoder_config.h" |
21 #include "media/base/video_frame.h" | 21 #include "media/base/video_frame.h" |
22 #include "media/video/video_encode_accelerator.h" | |
22 #include "third_party/libva/va/va.h" | 23 #include "third_party/libva/va/va.h" |
23 #include "third_party/libva/va/va_vpp.h" | 24 #include "third_party/libva/va/va_vpp.h" |
24 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
25 #if defined(USE_X11) | 26 #if defined(USE_X11) |
26 #include "third_party/libva/va/va_x11.h" | 27 #include "third_party/libva/va/va_x11.h" |
27 #endif // USE_X11 | 28 #endif // USE_X11 |
28 | 29 |
29 namespace content { | 30 namespace content { |
30 | 31 |
31 // This class handles VA-API calls and ensures proper locking of VA-API calls | 32 // 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 | 33 // 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 | 34 // 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 | 35 // synchronous and its methods can be called from any thread and may wait on |
35 // the va_lock_ while other, concurrent calls run. | 36 // the va_lock_ while other, concurrent calls run. |
36 // | 37 // |
37 // This class is responsible for managing VAAPI connection, contexts and state. | 38 // This class is responsible for managing VAAPI connection, contexts and state. |
38 // It is also responsible for managing and freeing VABuffers (not VASurfaces), | 39 // 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, | 40 // which are used to queue parameters and slice data to the HW codec, |
40 // as well as underlying memory for VASurfaces themselves. | 41 // as well as underlying memory for VASurfaces themselves. |
41 class CONTENT_EXPORT VaapiWrapper { | 42 class CONTENT_EXPORT VaapiWrapper { |
42 public: | 43 public: |
43 enum CodecMode { | 44 enum CodecMode { |
44 kDecode, | 45 kDecode, |
45 kEncode, | 46 kEncode, |
46 }; | 47 }; |
47 | 48 |
48 // Create VaapiWrapper for VAProfile. | 49 struct ProfileConfig { |
wuchengli
2015/02/13 15:38:55
This name is not good. This is not a VAConfig. Thi
henryhsu
2015/02/13 17:24:28
Done.
| |
49 // |report_error_to_uma_cb| will be called independently from reporting | 50 VAProfile va_profile; |
50 // errors to clients via method return values. | 51 VaapiWrapper::CodecMode mode; |
wuchengli
2015/02/13 15:38:55
This field is redundant. All |mode| of |supported_
henryhsu
2015/02/13 17:24:28
InitSupportedProfileConfigs returns a vector of Pr
| |
52 gfx::Size max_resolution; | |
53 }; | |
54 | |
55 // Return an instance of VaapiWrapper and initialize by |profile| and | |
56 // |mode|. |report_error_to_uma_cb| will be called independently from | |
57 // reporting errors to clients via method return values. | |
51 static scoped_ptr<VaapiWrapper> Create( | 58 static scoped_ptr<VaapiWrapper> Create( |
52 CodecMode mode, | 59 CodecMode mode, |
53 VAProfile profile, | 60 VAProfile va_profile, |
54 const base::Closure& report_error_to_uma_cb); | 61 const base::Closure& report_error_to_uma_cb); |
55 | 62 |
56 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile | 63 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile |
57 // |profile| to VAProfile. | 64 // |profile| to VAProfile. |
58 // |report_error_to_uma_cb| will be called independently from reporting | 65 // |report_error_to_uma_cb| will be called independently from reporting |
59 // errors to clients via method return values. | 66 // errors to clients via method return values. |
60 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( | 67 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( |
61 CodecMode mode, | 68 CodecMode mode, |
62 media::VideoCodecProfile profile, | 69 media::VideoCodecProfile profile, |
63 const base::Closure& report_error_to_uma_cb); | 70 const base::Closure& report_error_to_uma_cb); |
64 | 71 |
65 // Return the supported encode profiles. | 72 // Return the supported encode profiles. |
66 static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( | 73 static std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
67 const base::Closure& report_error_to_uma_cb); | 74 GetSupportedEncodeProfiles(); |
75 | |
76 // Initialize all supported profile configs. | |
77 static std::vector<ProfileConfig> InitSupportedProfileConfigs(); | |
wuchengli
2015/02/13 15:38:55
this should be private.
henryhsu
2015/02/13 17:24:28
Done.
| |
68 | 78 |
69 ~VaapiWrapper(); | 79 ~VaapiWrapper(); |
70 | 80 |
71 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each | 81 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each |
72 // of size |size|. Returns true when successful, with the created IDs in | 82 // of size |size|. Returns true when successful, with the created IDs in |
73 // |va_surfaces| to be managed and later wrapped in VASurfaces. | 83 // |va_surfaces| to be managed and later wrapped in VASurfaces. |
74 // The client must DestroySurfaces() each time before calling this method | 84 // 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 | 85 // 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 | 86 // at destruction time, as this will be done automatically from |
77 // the destructor. | 87 // the destructor. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 VaapiWrapper(); | 196 VaapiWrapper(); |
187 | 197 |
188 bool Initialize(CodecMode mode, VAProfile va_profile); | 198 bool Initialize(CodecMode mode, VAProfile va_profile); |
189 void Deinitialize(); | 199 void Deinitialize(); |
190 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 200 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
191 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 201 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
192 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); | 202 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); |
193 bool AreAttribsSupported(VAProfile va_profile, | 203 bool AreAttribsSupported(VAProfile va_profile, |
194 VAEntrypoint entrypoint, | 204 VAEntrypoint entrypoint, |
195 const std::vector<VAConfigAttrib>& required_attribs); | 205 const std::vector<VAConfigAttrib>& required_attribs); |
206 bool GetVaCodecMaxResolution(VAConfigID config, gfx::Size* resolution); | |
196 | 207 |
197 // Destroys a |va_surface| created using CreateUnownedSurface. | 208 // Destroys a |va_surface| created using CreateUnownedSurface. |
198 void DestroyUnownedSurface(VASurfaceID va_surface_id); | 209 void DestroyUnownedSurface(VASurfaceID va_surface_id); |
199 | 210 |
200 // Initialize the video post processing context with the |size| of | 211 // Initialize the video post processing context with the |size| of |
201 // the input pictures to be processed. | 212 // the input pictures to be processed. |
202 bool InitializeVpp_Locked(); | 213 bool InitializeVpp_Locked(); |
203 | 214 |
204 // Deinitialize the video post processing context. | 215 // Deinitialize the video post processing context. |
205 void DeinitializeVpp(); | 216 void DeinitializeVpp(); |
206 | 217 |
207 // Execute pending job in hardware and destroy pending buffers. Return false | 218 // Execute pending job in hardware and destroy pending buffers. Return false |
208 // if vaapi driver refuses to accept parameter or slice buffers submitted | 219 // if vaapi driver refuses to accept parameter or slice buffers submitted |
209 // by client, or if execution fails in hardware. | 220 // by client, or if execution fails in hardware. |
210 bool Execute(VASurfaceID va_surface_id); | 221 bool Execute(VASurfaceID va_surface_id); |
211 | 222 |
212 // Attempt to set render mode to "render to texture.". Failure is non-fatal. | 223 // Attempt to set render mode to "render to texture.". Failure is non-fatal. |
213 void TryToSetVADisplayAttributeToLocalGPU(); | 224 void TryToSetVADisplayAttributeToLocalGPU(); |
214 | 225 |
226 // Get all supported profile configs. | |
227 std::vector<ProfileConfig> GetSupportedProfileConfigs(); | |
228 | |
215 // Lazily initialize static data after sandbox is enabled. Return false on | 229 // Lazily initialize static data after sandbox is enabled. Return false on |
216 // init failure. | 230 // init failure. |
217 static bool PostSandboxInitialization(); | 231 static bool PostSandboxInitialization(); |
218 | 232 |
219 // Libva is not thread safe, so we have to do locking for it ourselves. | 233 // 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 | 234 // This lock is to be taken for the duration of all VA-API calls and for |
221 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). | 235 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). |
222 base::Lock va_lock_; | 236 base::Lock va_lock_; |
223 | 237 |
224 // Allocated ids for VASurfaces. | 238 // Allocated ids for VASurfaces. |
(...skipping 26 matching lines...) Expand all Loading... | |
251 // VPP (Video Post Processing) context, this is used to convert | 265 // VPP (Video Post Processing) context, this is used to convert |
252 // pictures used by the decoder to RGBA pictures usable by GL or the | 266 // pictures used by the decoder to RGBA pictures usable by GL or the |
253 // display hardware. | 267 // display hardware. |
254 VAConfigID va_vpp_config_id_; | 268 VAConfigID va_vpp_config_id_; |
255 VAContextID va_vpp_context_id_; | 269 VAContextID va_vpp_context_id_; |
256 VABufferID va_vpp_buffer_id_; | 270 VABufferID va_vpp_buffer_id_; |
257 | 271 |
258 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 272 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
259 }; | 273 }; |
260 | 274 |
275 class CONTENT_EXPORT LazyProfileConfig { | |
wuchengli
2015/02/13 15:38:55
This is not used by other classes. Move this to va
henryhsu
2015/02/13 17:24:28
Done.
| |
276 public: | |
277 LazyProfileConfig(); | |
278 ~LazyProfileConfig(); | |
279 std::vector<VaapiWrapper::ProfileConfig> GetSupportedEncodeProfileConfigs(); | |
280 std::vector<VaapiWrapper::ProfileConfig> GetSupportedDecodeProfileConfigs(); | |
281 private: | |
282 std::vector<VaapiWrapper::ProfileConfig> supported_encode_profiles_; | |
283 std::vector<VaapiWrapper::ProfileConfig> supported_decode_profiles_; | |
284 }; | |
285 | |
261 } // namespace content | 286 } // namespace content |
262 | 287 |
263 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 288 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |