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| of |pixmap_size|. The ownership of the | |
116 // surface is transferred to the caller. It differs from surfaces created | |
117 // using CreateSurfaces(), where VaapiWrapper is the owner of the surfaces. | |
118 scoped_refptr<VASurface> CreateVASurfaceForPixmap( | |
119 const scoped_refptr<ui::NativePixmap>& pixmap, | |
120 const gfx::Size& pixmap_size); | |
121 | |
122 // Use VPP to process |source_pixmap|, scaling to |target_size| and | |
123 // converting to |target_format|. Return the processed pixmap. | |
124 scoped_refptr<ui::NativePixmap> ProcessPixmap( | |
125 const scoped_refptr<ui::NativePixmap>& source_pixmap, | |
126 const gfx::Size& target_size, | |
127 gfx::BufferFormat target_format); | |
128 | |
129 // Create native pixmap with size |size| and format |format|. | |
130 scoped_refptr<ui::NativePixmap> CreateNativePixmap(gfx::Size size, | |
131 gfx::BufferFormat format); | |
132 #endif | |
133 | |
109 // Submit parameters or slice data of |va_buffer_type|, copying them from | 134 // 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 | 135 // |buffer| of size |size|, into HW codec. The data in |buffer| is no |
111 // longer needed and can be freed after this method returns. | 136 // longer needed and can be freed after this method returns. |
112 // Data submitted via this method awaits in the HW codec until | 137 // Data submitted via this method awaits in the HW codec until |
113 // ExecuteAndDestroyPendingBuffers() is called to execute or | 138 // ExecuteAndDestroyPendingBuffers() is called to execute or |
114 // DestroyPendingBuffers() is used to cancel a pending job. | 139 // DestroyPendingBuffers() is used to cancel a pending job. |
115 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); | 140 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); |
116 | 141 |
117 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its | 142 // 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 | 143 // 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, | 217 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src, |
193 const scoped_refptr<VASurface>& va_surface_dest); | 218 const scoped_refptr<VASurface>& va_surface_dest); |
194 | 219 |
195 // Initialize static data before sandbox is enabled. | 220 // Initialize static data before sandbox is enabled. |
196 static void PreSandboxInitialization(); | 221 static void PreSandboxInitialization(); |
197 | 222 |
198 // Get the created surfaces format. | 223 // Get the created surfaces format. |
199 unsigned int va_surface_format() const { return va_surface_format_; } | 224 unsigned int va_surface_format() const { return va_surface_format_; } |
200 | 225 |
201 private: | 226 private: |
227 friend class base::RefCountedThreadSafe<VaapiWrapper>; | |
kalyank
2015/11/24 23:00:24
nit: should be at the end ?
william.xie1
2015/11/25 02:19:26
Done.
| |
228 ~VaapiWrapper(); | |
229 | |
202 struct ProfileInfo { | 230 struct ProfileInfo { |
203 VAProfile va_profile; | 231 VAProfile va_profile; |
204 gfx::Size max_resolution; | 232 gfx::Size max_resolution; |
205 }; | 233 }; |
206 | 234 |
207 class LazyProfileInfos { | 235 class LazyProfileInfos { |
208 public: | 236 public: |
209 LazyProfileInfos(); | 237 LazyProfileInfos(); |
210 ~LazyProfileInfos(); | 238 ~LazyProfileInfos(); |
211 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( | 239 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 // Singleton variable to store supported profile information for encode and | 391 // Singleton variable to store supported profile information for encode and |
364 // decode. | 392 // decode. |
365 static base::LazyInstance<LazyProfileInfos> profile_infos_; | 393 static base::LazyInstance<LazyProfileInfos> profile_infos_; |
366 | 394 |
367 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 395 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
368 }; | 396 }; |
369 | 397 |
370 } // namespace content | 398 } // namespace content |
371 | 399 |
372 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 400 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |