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_ |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "media/video/jpeg_decode_accelerator.h" | 24 #include "media/video/jpeg_decode_accelerator.h" |
25 #include "media/video/video_decode_accelerator.h" | 25 #include "media/video/video_decode_accelerator.h" |
26 #include "media/video/video_encode_accelerator.h" | 26 #include "media/video/video_encode_accelerator.h" |
27 #include "third_party/libva/va/va.h" | 27 #include "third_party/libva/va/va.h" |
28 #include "third_party/libva/va/va_vpp.h" | 28 #include "third_party/libva/va/va_vpp.h" |
29 #include "ui/gfx/geometry/size.h" | 29 #include "ui/gfx/geometry/size.h" |
30 #if defined(USE_X11) | 30 #if defined(USE_X11) |
31 #include "third_party/libva/va/va_x11.h" | 31 #include "third_party/libva/va/va_x11.h" |
32 #endif // USE_X11 | 32 #endif // USE_X11 |
33 | 33 |
| 34 #if defined(USE_OZONE) |
| 35 namespace ui { |
| 36 class NativePixmap; |
| 37 } |
| 38 #endif |
| 39 |
34 namespace content { | 40 namespace content { |
35 | 41 |
36 // This class handles VA-API calls and ensures proper locking of VA-API calls | 42 // This class handles VA-API calls and ensures proper locking of VA-API calls |
37 // to libva, the userspace shim to the HW codec driver. libva is not | 43 // to libva, the userspace shim to the HW codec driver. libva is not |
38 // thread-safe, so we have to perform locking ourselves. This class is fully | 44 // thread-safe, so we have to perform locking ourselves. This class is fully |
39 // synchronous and its methods can be called from any thread and may wait on | 45 // synchronous and its methods can be called from any thread and may wait on |
40 // the va_lock_ while other, concurrent calls run. | 46 // the va_lock_ while other, concurrent calls run. |
41 // | 47 // |
42 // This class is responsible for managing VAAPI connection, contexts and state. | 48 // This class is responsible for managing VAAPI connection, contexts and state. |
43 // It is also responsible for managing and freeing VABuffers (not VASurfaces), | 49 // It is also responsible for managing and freeing VABuffers (not VASurfaces), |
44 // which are used to queue parameters and slice data to the HW codec, | 50 // which are used to queue parameters and slice data to the HW codec, |
45 // as well as underlying memory for VASurfaces themselves. | 51 // as well as underlying memory for VASurfaces themselves. |
46 class CONTENT_EXPORT VaapiWrapper { | 52 class CONTENT_EXPORT VaapiWrapper |
| 53 : public base::RefCountedThreadSafe<VaapiWrapper> { |
47 public: | 54 public: |
48 enum CodecMode { | 55 enum CodecMode { |
49 kDecode, | 56 kDecode, |
50 kEncode, | 57 kEncode, |
51 kCodecModeMax, | 58 kCodecModeMax, |
52 }; | 59 }; |
53 | 60 |
54 // Return an instance of VaapiWrapper initialized for |va_profile| and | 61 // Return an instance of VaapiWrapper initialized for |va_profile| and |
55 // |mode|. |report_error_to_uma_cb| will be called independently from | 62 // |mode|. |report_error_to_uma_cb| will be called independently from |
56 // reporting errors to clients via method return values. | 63 // reporting errors to clients via method return values. |
57 static scoped_ptr<VaapiWrapper> Create( | 64 static scoped_refptr<VaapiWrapper> Create( |
58 CodecMode mode, | 65 CodecMode mode, |
59 VAProfile va_profile, | 66 VAProfile va_profile, |
60 const base::Closure& report_error_to_uma_cb); | 67 const base::Closure& report_error_to_uma_cb); |
61 | 68 |
62 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile | 69 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile |
63 // |profile| to VAProfile. | 70 // |profile| to VAProfile. |
64 // |report_error_to_uma_cb| will be called independently from reporting | 71 // |report_error_to_uma_cb| will be called independently from reporting |
65 // errors to clients via method return values. | 72 // errors to clients via method return values. |
66 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( | 73 static scoped_refptr<VaapiWrapper> CreateForVideoCodec( |
67 CodecMode mode, | 74 CodecMode mode, |
68 media::VideoCodecProfile profile, | 75 media::VideoCodecProfile profile, |
69 const base::Closure& report_error_to_uma_cb); | 76 const base::Closure& report_error_to_uma_cb); |
70 | 77 |
71 // Return the supported video encode profiles. | 78 // Return the supported video encode profiles. |
72 static media::VideoEncodeAccelerator::SupportedProfiles | 79 static media::VideoEncodeAccelerator::SupportedProfiles |
73 GetSupportedEncodeProfiles(); | 80 GetSupportedEncodeProfiles(); |
74 | 81 |
75 // Return the supported video decode profiles. | 82 // Return the supported video decode profiles. |
76 static media::VideoDecodeAccelerator::SupportedProfiles | 83 static media::VideoDecodeAccelerator::SupportedProfiles |
77 GetSupportedDecodeProfiles(); | 84 GetSupportedDecodeProfiles(); |
78 | 85 |
79 // Return true when JPEG decode is supported. | 86 // Return true when JPEG decode is supported. |
80 static bool IsJpegDecodeSupported(); | 87 static bool IsJpegDecodeSupported(); |
81 | 88 |
82 ~VaapiWrapper(); | |
83 | |
84 // Create |num_surfaces| backing surfaces in driver for VASurfaces of | 89 // Create |num_surfaces| backing surfaces in driver for VASurfaces of |
85 // |va_format|, each of size |size|. Returns true when successful, with the | 90 // |va_format|, each of size |size|. Returns true when successful, with the |
86 // created IDs in |va_surfaces| to be managed and later wrapped in | 91 // created IDs in |va_surfaces| to be managed and later wrapped in |
87 // VASurfaces. | 92 // VASurfaces. |
88 // The client must DestroySurfaces() each time before calling this method | 93 // The client must DestroySurfaces() each time before calling this method |
89 // again to free the allocated surfaces first, but is not required to do so | 94 // again to free the allocated surfaces first, but is not required to do so |
90 // at destruction time, as this will be done automatically from | 95 // at destruction time, as this will be done automatically from |
91 // the destructor. | 96 // the destructor. |
92 bool CreateSurfaces(unsigned int va_format, | 97 bool CreateSurfaces(unsigned int va_format, |
93 const gfx::Size& size, | 98 const gfx::Size& size, |
94 size_t num_surfaces, | 99 size_t num_surfaces, |
95 std::vector<VASurfaceID>* va_surfaces); | 100 std::vector<VASurfaceID>* va_surfaces); |
96 | 101 |
97 // Free all memory allocated in CreateSurfaces. | 102 // Free all memory allocated in CreateSurfaces. |
98 void DestroySurfaces(); | 103 void DestroySurfaces(); |
99 | 104 |
100 // Create a VASurface of |va_format|, |size| and using |va_attribs| | 105 // Create a VASurface of |va_format|, |size| and using |va_attribs| |
101 // attributes. The ownership of the surface is transferred to the | 106 // attributes. The ownership of the surface is transferred to the |
102 // caller. It differs from surfaces created using CreateSurfaces(), | 107 // caller. It differs from surfaces created using CreateSurfaces(), |
103 // where VaapiWrapper is the owner of the surfaces. | 108 // where VaapiWrapper is the owner of the surfaces. |
104 scoped_refptr<VASurface> CreateUnownedSurface( | 109 scoped_refptr<VASurface> CreateUnownedSurface( |
105 unsigned int va_format, | 110 unsigned int va_format, |
106 const gfx::Size& size, | 111 const gfx::Size& size, |
107 const std::vector<VASurfaceAttrib>& va_attribs); | 112 const std::vector<VASurfaceAttrib>& va_attribs); |
108 | 113 |
| 114 #if defined(USE_OZONE) |
| 115 // Create a VASurface for |pixmap|. The ownership of the surface is |
| 116 // transferred to the caller. It differs from surfaces created using |
| 117 // CreateSurfaces(), where VaapiWrapper is the owner of the surfaces. |
| 118 scoped_refptr<VASurface> CreateVASurfaceForPixmap( |
| 119 const scoped_refptr<ui::NativePixmap>& pixmap); |
| 120 |
| 121 // Use VPP to process |source_pixmap| to |target_pixmap| with scaling and |
| 122 // color space conversion. |
| 123 bool ProcessPixmap(const scoped_refptr<ui::NativePixmap>& source_pixmap, |
| 124 scoped_refptr<ui::NativePixmap> target_pixmap); |
| 125 |
| 126 #endif |
| 127 |
109 // Submit parameters or slice data of |va_buffer_type|, copying them from | 128 // Submit parameters or slice data of |va_buffer_type|, copying them from |
110 // |buffer| of size |size|, into HW codec. The data in |buffer| is no | 129 // |buffer| of size |size|, into HW codec. The data in |buffer| is no |
111 // longer needed and can be freed after this method returns. | 130 // longer needed and can be freed after this method returns. |
112 // Data submitted via this method awaits in the HW codec until | 131 // Data submitted via this method awaits in the HW codec until |
113 // ExecuteAndDestroyPendingBuffers() is called to execute or | 132 // ExecuteAndDestroyPendingBuffers() is called to execute or |
114 // DestroyPendingBuffers() is used to cancel a pending job. | 133 // DestroyPendingBuffers() is used to cancel a pending job. |
115 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); | 134 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); |
116 | 135 |
117 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its | 136 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its |
118 // data from |buffer| of size |size|, into HW codec. The data in |buffer| is | 137 // data from |buffer| of size |size|, into HW codec. The data in |buffer| is |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src, | 211 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src, |
193 const scoped_refptr<VASurface>& va_surface_dest); | 212 const scoped_refptr<VASurface>& va_surface_dest); |
194 | 213 |
195 // Initialize static data before sandbox is enabled. | 214 // Initialize static data before sandbox is enabled. |
196 static void PreSandboxInitialization(); | 215 static void PreSandboxInitialization(); |
197 | 216 |
198 // Get the created surfaces format. | 217 // Get the created surfaces format. |
199 unsigned int va_surface_format() const { return va_surface_format_; } | 218 unsigned int va_surface_format() const { return va_surface_format_; } |
200 | 219 |
201 private: | 220 private: |
| 221 friend class base::RefCountedThreadSafe<VaapiWrapper>; |
| 222 |
202 struct ProfileInfo { | 223 struct ProfileInfo { |
203 VAProfile va_profile; | 224 VAProfile va_profile; |
204 gfx::Size max_resolution; | 225 gfx::Size max_resolution; |
205 }; | 226 }; |
206 | 227 |
207 class LazyProfileInfos { | 228 class LazyProfileInfos { |
208 public: | 229 public: |
209 LazyProfileInfos(); | 230 LazyProfileInfos(); |
210 ~LazyProfileInfos(); | 231 ~LazyProfileInfos(); |
211 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( | 232 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 VADisplay va_display_; | 276 VADisplay va_display_; |
256 | 277 |
257 // The VAAPI version. | 278 // The VAAPI version. |
258 int major_version_, minor_version_; | 279 int major_version_, minor_version_; |
259 | 280 |
260 // True if vaInitialize has been called successfully. | 281 // True if vaInitialize has been called successfully. |
261 bool va_initialized_; | 282 bool va_initialized_; |
262 }; | 283 }; |
263 | 284 |
264 VaapiWrapper(); | 285 VaapiWrapper(); |
| 286 ~VaapiWrapper(); |
265 | 287 |
266 bool Initialize(CodecMode mode, VAProfile va_profile); | 288 bool Initialize(CodecMode mode, VAProfile va_profile); |
267 void Deinitialize(); | 289 void Deinitialize(); |
268 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 290 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
269 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 291 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
270 | 292 |
271 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be | 293 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be |
272 // held on entry. | 294 // held on entry. |
273 bool IsEntrypointSupported_Locked(VAProfile va_profile, | 295 bool IsEntrypointSupported_Locked(VAProfile va_profile, |
274 VAEntrypoint entrypoint); | 296 VAEntrypoint entrypoint); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // Singleton variable to store supported profile information for encode and | 385 // Singleton variable to store supported profile information for encode and |
364 // decode. | 386 // decode. |
365 static base::LazyInstance<LazyProfileInfos> profile_infos_; | 387 static base::LazyInstance<LazyProfileInfos> profile_infos_; |
366 | 388 |
367 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 389 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
368 }; | 390 }; |
369 | 391 |
370 } // namespace content | 392 } // namespace content |
371 | 393 |
372 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 394 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |