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/callback.h" | 16 #include "base/callback.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/synchronization/lock.h" | 18 #include "base/synchronization/lock.h" |
19 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
20 #include "content/common/gpu/media/va_surface.h" | 20 #include "content/common/gpu/media/va_surface.h" |
21 #include "media/base/video_decoder_config.h" | 21 #include "media/base/video_decoder_config.h" |
22 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
23 #if defined(USE_X11) | |
23 #include "third_party/libva/va/va_x11.h" | 24 #include "third_party/libva/va/va_x11.h" |
25 #else | |
26 #include "third_party/libva/va/drm/va_drm.h" | |
27 #endif | |
24 #include "ui/gfx/size.h" | 28 #include "ui/gfx/size.h" |
25 | 29 |
26 namespace content { | 30 namespace content { |
27 | 31 |
28 // 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 |
29 // 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 |
30 // 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 |
31 // 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 |
32 // the va_lock_ while other, concurrent calls run. | 36 // the va_lock_ while other, concurrent calls run. |
33 // | 37 // |
34 // This class is responsible for managing VAAPI connection, contexts and state. | 38 // This class is responsible for managing VAAPI connection, contexts and state. |
35 // It is also responsible for managing and freeing VABuffers (not VASurfaces), | 39 // It is also responsible for managing and freeing VABuffers (not VASurfaces), |
36 // 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, |
37 // as well as underlying memory for VASurfaces themselves. | 41 // as well as underlying memory for VASurfaces themselves. |
38 class CONTENT_EXPORT VaapiWrapper { | 42 class CONTENT_EXPORT VaapiWrapper { |
39 public: | 43 public: |
40 enum CodecMode { | 44 enum CodecMode { |
41 kDecode, | 45 kDecode, |
42 kEncode, | 46 kEncode, |
43 }; | 47 }; |
44 | 48 |
45 // |report_error_to_uma_cb| will be called independently from reporting | 49 // |report_error_to_uma_cb| will be called independently from reporting |
46 // errors to clients via method return values. | 50 // errors to clients via method return values. |
47 static scoped_ptr<VaapiWrapper> Create( | 51 static scoped_ptr<VaapiWrapper> Create( |
48 CodecMode mode, | 52 CodecMode mode, |
49 media::VideoCodecProfile profile, | 53 media::VideoCodecProfile profile, |
50 Display* x_display, | 54 #if defined(USE_X11) |
55 Display* display, | |
56 #else | |
57 int display, | |
58 #endif | |
51 const base::Closure& report_error_to_uma_cb); | 59 const base::Closure& report_error_to_uma_cb); |
52 | 60 |
53 ~VaapiWrapper(); | 61 ~VaapiWrapper(); |
54 | 62 |
55 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each | 63 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each |
56 // of size |size|. Returns true when successful, with the created IDs in | 64 // of size |size|. Returns true when successful, with the created IDs in |
57 // |va_surfaces| to be managed and later wrapped in VASurfaces. | 65 // |va_surfaces| to be managed and later wrapped in VASurfaces. |
58 // The client must DestroySurfaces() each time before calling this method | 66 // The client must DestroySurfaces() each time before calling this method |
59 // again to free the allocated surfaces first, but is not required to do so | 67 // again to free the allocated surfaces first, but is not required to do so |
60 // at destruction time, as this will be done automatically from | 68 // at destruction time, as this will be done automatically from |
(...skipping 24 matching lines...) Expand all Loading... | |
85 void* buffer); | 93 void* buffer); |
86 | 94 |
87 // Cancel and destroy all buffers queued to the HW codec via SubmitBuffer(). | 95 // Cancel and destroy all buffers queued to the HW codec via SubmitBuffer(). |
88 // Useful when a pending job is to be cancelled (on reset or error). | 96 // Useful when a pending job is to be cancelled (on reset or error). |
89 void DestroyPendingBuffers(); | 97 void DestroyPendingBuffers(); |
90 | 98 |
91 // Execute job in hardware on target |va_surface_id| and destroy pending | 99 // Execute job in hardware on target |va_surface_id| and destroy pending |
92 // buffers. Return false if Execute() fails. | 100 // buffers. Return false if Execute() fails. |
93 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); | 101 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); |
94 | 102 |
103 #if defined(USE_X11) | |
scherkus (not reviewing)
2014/07/29 17:48:55
out of curiosity, is USE_X11 sticking around for v
vignatti (out of this project)
2014/07/30 21:51:30
it's a good question that I don't know the answer.
| |
95 // Put data from |va_surface_id| into |x_pixmap| of size |size|, | 104 // Put data from |va_surface_id| into |x_pixmap| of size |size|, |
96 // converting/scaling to it. | 105 // converting/scaling to it. |
97 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, | 106 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
98 Pixmap x_pixmap, | 107 Pixmap x_pixmap, |
99 gfx::Size dest_size); | 108 gfx::Size dest_size); |
109 #else | |
110 // Create RGB image of size |size|, assigning it to |image|. | |
111 bool CreateRGBImage(gfx::Size size, VAImage* image); | |
100 | 112 |
113 // Destroy |image|. Should call DestroyImage before destroying the surface it | |
114 // is bound to. | |
115 void DestroyImage(VAImage* image); | |
116 | |
117 // Map data store of the |buffer| into the |image|'s. | |
118 bool MapImage(VAImage* image, void** buffer); | |
119 | |
120 // Unmap |image|. This must happens after making changes to a mapped data | |
121 // store, so the server knows that the data is ready to be consumed. | |
122 void UnmapImage(VAImage* image); | |
123 | |
124 // Put data from |va_surface_id| into |va_image|, converting/scaling it. | |
125 bool PutSurfaceIntoImage(VASurfaceID va_surface_id, | |
126 VAImage* va_image); | |
127 #endif | |
101 // Returns true if the VAAPI version is less than the specified version. | 128 // Returns true if the VAAPI version is less than the specified version. |
102 bool VAAPIVersionLessThan(int major, int minor); | 129 bool VAAPIVersionLessThan(int major, int minor); |
103 | 130 |
104 // Get a VAImage from a VASurface and map it into memory. The VAImage should | 131 // Get a VAImage from a VASurface and map it into memory. The VAImage should |
105 // be released using the ReturnVaImage function. Returns true when successful. | 132 // be released using the ReturnVaImage function. Returns true when successful. |
106 // This is intended for testing only. | 133 // This is intended for testing only. |
107 bool GetVaImageForTesting(VASurfaceID va_surface_id, | 134 bool GetVaImageForTesting(VASurfaceID va_surface_id, |
108 VAImage* image, | 135 VAImage* image, |
109 void** mem); | 136 void** mem); |
110 | 137 |
(...skipping 21 matching lines...) Expand all Loading... | |
132 size_t* coded_data_size); | 159 size_t* coded_data_size); |
133 | 160 |
134 // Destroy all previously-allocated (and not yet destroyed) coded buffers. | 161 // Destroy all previously-allocated (and not yet destroyed) coded buffers. |
135 void DestroyCodedBuffers(); | 162 void DestroyCodedBuffers(); |
136 | 163 |
137 private: | 164 private: |
138 VaapiWrapper(); | 165 VaapiWrapper(); |
139 | 166 |
140 bool Initialize(CodecMode mode, | 167 bool Initialize(CodecMode mode, |
141 media::VideoCodecProfile profile, | 168 media::VideoCodecProfile profile, |
169 #if defined(USE_X11) | |
142 Display* x_display, | 170 Display* x_display, |
171 #else | |
172 int display, | |
173 #endif | |
143 const base::Closure& report_error__to_uma_cb); | 174 const base::Closure& report_error__to_uma_cb); |
144 void Deinitialize(); | 175 void Deinitialize(); |
145 | 176 |
146 // Execute pending job in hardware and destroy pending buffers. Return false | 177 // Execute pending job in hardware and destroy pending buffers. Return false |
147 // if vaapi driver refuses to accept parameter or slice buffers submitted | 178 // if vaapi driver refuses to accept parameter or slice buffers submitted |
148 // by client, or if execution fails in hardware. | 179 // by client, or if execution fails in hardware. |
149 bool Execute(VASurfaceID va_surface_id); | 180 bool Execute(VASurfaceID va_surface_id); |
150 | 181 |
151 // Attempt to set render mode to "render to texture.". Failure is non-fatal. | 182 // Attempt to set render mode to "render to texture.". Failure is non-fatal. |
152 void TryToSetVADisplayAttributeToLocalGPU(); | 183 void TryToSetVADisplayAttributeToLocalGPU(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 // Called to report codec errors to UMA. Errors to clients are reported via | 215 // Called to report codec errors to UMA. Errors to clients are reported via |
185 // return values from public methods. | 216 // return values from public methods. |
186 base::Closure report_error_to_uma_cb_; | 217 base::Closure report_error_to_uma_cb_; |
187 | 218 |
188 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 219 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
189 }; | 220 }; |
190 | 221 |
191 } // namespace content | 222 } // namespace content |
192 | 223 |
193 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 224 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |