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...) 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 namespace ui { | |
35 class NativePixmap; | |
36 } | |
37 | |
34 namespace content { | 38 namespace content { |
35 | 39 |
36 // This class handles VA-API calls and ensures proper locking of VA-API calls | 40 // 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 | 41 // 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 | 42 // 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 | 43 // synchronous and its methods can be called from any thread and may wait on |
40 // the va_lock_ while other, concurrent calls run. | 44 // the va_lock_ while other, concurrent calls run. |
41 // | 45 // |
42 // This class is responsible for managing VAAPI connection, contexts and state. | 46 // This class is responsible for managing VAAPI connection, contexts and state. |
43 // It is also responsible for managing and freeing VABuffers (not VASurfaces), | 47 // 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, | 48 // which are used to queue parameters and slice data to the HW codec, |
45 // as well as underlying memory for VASurfaces themselves. | 49 // as well as underlying memory for VASurfaces themselves. |
46 class CONTENT_EXPORT VaapiWrapper { | 50 class CONTENT_EXPORT VaapiWrapper |
51 : public base::RefCountedThreadSafe<VaapiWrapper> { | |
47 public: | 52 public: |
48 enum CodecMode { | 53 enum CodecMode { |
49 kDecode, | 54 kDecode, |
50 kEncode, | 55 kEncode, |
51 kCodecModeMax, | 56 kCodecModeMax, |
52 }; | 57 }; |
53 | 58 |
54 // Return an instance of VaapiWrapper initialized for |va_profile| and | 59 // Return an instance of VaapiWrapper initialized for |va_profile| and |
55 // |mode|. |report_error_to_uma_cb| will be called independently from | 60 // |mode|. |report_error_to_uma_cb| will be called independently from |
56 // reporting errors to clients via method return values. | 61 // reporting errors to clients via method return values. |
57 static scoped_ptr<VaapiWrapper> Create( | 62 static scoped_refptr<VaapiWrapper> Create( |
58 CodecMode mode, | 63 CodecMode mode, |
59 VAProfile va_profile, | 64 VAProfile va_profile, |
60 const base::Closure& report_error_to_uma_cb); | 65 const base::Closure& report_error_to_uma_cb); |
61 | 66 |
62 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile | 67 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile |
63 // |profile| to VAProfile. | 68 // |profile| to VAProfile. |
64 // |report_error_to_uma_cb| will be called independently from reporting | 69 // |report_error_to_uma_cb| will be called independently from reporting |
65 // errors to clients via method return values. | 70 // errors to clients via method return values. |
66 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( | 71 static scoped_refptr<VaapiWrapper> CreateForVideoCodec( |
67 CodecMode mode, | 72 CodecMode mode, |
68 media::VideoCodecProfile profile, | 73 media::VideoCodecProfile profile, |
69 const base::Closure& report_error_to_uma_cb); | 74 const base::Closure& report_error_to_uma_cb); |
70 | 75 |
71 // Return the supported video encode profiles. | 76 // Return the supported video encode profiles. |
72 static media::VideoEncodeAccelerator::SupportedProfiles | 77 static media::VideoEncodeAccelerator::SupportedProfiles |
73 GetSupportedEncodeProfiles(); | 78 GetSupportedEncodeProfiles(); |
74 | 79 |
75 // Return the supported video decode profiles. | 80 // Return the supported video decode profiles. |
76 static media::VideoDecodeAccelerator::SupportedProfiles | 81 static media::VideoDecodeAccelerator::SupportedProfiles |
77 GetSupportedDecodeProfiles(); | 82 GetSupportedDecodeProfiles(); |
78 | 83 |
79 // Return true when JPEG decode is supported. | 84 // Return true when JPEG decode is supported. |
80 static bool IsJpegDecodeSupported(); | 85 static bool IsJpegDecodeSupported(); |
81 | 86 |
82 ~VaapiWrapper(); | 87 ~VaapiWrapper(); |
kalyank
2015/11/23 17:51:07
This is refcounted, destructor should be made priv
william.xie1
2015/11/24 06:19:39
Done.
| |
83 | 88 |
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 // Create a VASurface for |pixmap| of |pixmap_size|. The ownership of the | |
115 // surface is transferred to the caller. It differs from surfaces created | |
116 // using CreateSurfaces(), where VaapiWrapper is the owner of the surfaces. | |
117 scoped_refptr<VASurface> CreateVASurfaceForPixmap( | |
118 const scoped_refptr<ui::NativePixmap>& pixmap, | |
119 const gfx::Size& pixmap_size); | |
120 | |
109 // Submit parameters or slice data of |va_buffer_type|, copying them from | 121 // 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 | 122 // |buffer| of size |size|, into HW codec. The data in |buffer| is no |
111 // longer needed and can be freed after this method returns. | 123 // longer needed and can be freed after this method returns. |
112 // Data submitted via this method awaits in the HW codec until | 124 // Data submitted via this method awaits in the HW codec until |
113 // ExecuteAndDestroyPendingBuffers() is called to execute or | 125 // ExecuteAndDestroyPendingBuffers() is called to execute or |
114 // DestroyPendingBuffers() is used to cancel a pending job. | 126 // DestroyPendingBuffers() is used to cancel a pending job. |
115 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); | 127 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); |
116 | 128 |
117 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its | 129 // 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 | 130 // data from |buffer| of size |size|, into HW codec. The data in |buffer| is |
(...skipping 72 matching lines...) Loading... | |
191 // if needed. | 203 // if needed. |
192 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src, | 204 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src, |
193 const scoped_refptr<VASurface>& va_surface_dest); | 205 const scoped_refptr<VASurface>& va_surface_dest); |
194 | 206 |
195 // Initialize static data before sandbox is enabled. | 207 // Initialize static data before sandbox is enabled. |
196 static void PreSandboxInitialization(); | 208 static void PreSandboxInitialization(); |
197 | 209 |
198 // Get the created surfaces format. | 210 // Get the created surfaces format. |
199 unsigned int va_surface_format() const { return va_surface_format_; } | 211 unsigned int va_surface_format() const { return va_surface_format_; } |
200 | 212 |
213 // Use VPP to process |source_pixmap|, scaling to |target_size| and | |
214 // converting to |target_format|. Return the processed pixmap. | |
215 scoped_refptr<ui::NativePixmap> ProcessPixmap( | |
216 const scoped_refptr<ui::NativePixmap>& source_pixmap, | |
217 const gfx::Size& target_size, | |
218 gfx::BufferFormat target_format); | |
219 | |
220 // Create native pixmap with size |size| and format |format|. | |
221 scoped_refptr<ui::NativePixmap> CreateNativePixmap(gfx::Size size, | |
222 gfx::BufferFormat format); | |
223 | |
201 private: | 224 private: |
202 struct ProfileInfo { | 225 struct ProfileInfo { |
203 VAProfile va_profile; | 226 VAProfile va_profile; |
204 gfx::Size max_resolution; | 227 gfx::Size max_resolution; |
205 }; | 228 }; |
206 | 229 |
207 class LazyProfileInfos { | 230 class LazyProfileInfos { |
208 public: | 231 public: |
209 LazyProfileInfos(); | 232 LazyProfileInfos(); |
210 ~LazyProfileInfos(); | 233 ~LazyProfileInfos(); |
(...skipping 152 matching lines...) Loading... | |
363 // Singleton variable to store supported profile information for encode and | 386 // Singleton variable to store supported profile information for encode and |
364 // decode. | 387 // decode. |
365 static base::LazyInstance<LazyProfileInfos> profile_infos_; | 388 static base::LazyInstance<LazyProfileInfos> profile_infos_; |
366 | 389 |
367 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 390 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
368 }; | 391 }; |
369 | 392 |
370 } // namespace content | 393 } // namespace content |
371 | 394 |
372 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 395 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |