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 27 matching lines...) Expand all Loading... |
38 // It is also responsible for managing and freeing VABuffers (not VASurfaces), | 38 // 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, | 39 // which are used to queue parameters and slice data to the HW codec, |
40 // as well as underlying memory for VASurfaces themselves. | 40 // as well as underlying memory for VASurfaces themselves. |
41 class CONTENT_EXPORT VaapiWrapper { | 41 class CONTENT_EXPORT VaapiWrapper { |
42 public: | 42 public: |
43 enum CodecMode { | 43 enum CodecMode { |
44 kDecode, | 44 kDecode, |
45 kEncode, | 45 kEncode, |
46 }; | 46 }; |
47 | 47 |
| 48 // Create VaapiWrapper. |
48 // |report_error_to_uma_cb| will be called independently from reporting | 49 // |report_error_to_uma_cb| will be called independently from reporting |
49 // errors to clients via method return values. | 50 // errors to clients via method return values. |
50 static scoped_ptr<VaapiWrapper> Create( | 51 static scoped_ptr<VaapiWrapper> Create( |
51 CodecMode mode, | 52 CodecMode mode, |
| 53 VAProfile profile, |
| 54 const base::Closure& report_error_to_uma_cb); |
| 55 |
| 56 // Create VaapiWrapper for video codec. It maps VideoCodecProfile |profile| |
| 57 // to VAProfile according to supported profiles. |
| 58 // |report_error_to_uma_cb| will be called independently from reporting |
| 59 // errors to clients via method return values. |
| 60 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( |
| 61 CodecMode mode, |
52 media::VideoCodecProfile profile, | 62 media::VideoCodecProfile profile, |
53 const base::Closure& report_error_to_uma_cb); | 63 const base::Closure& report_error_to_uma_cb); |
54 | 64 |
55 // Return the supported encode profiles. | 65 // Return the supported encode profiles. |
56 static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( | 66 static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( |
57 const base::Closure& report_error_to_uma_cb); | 67 const base::Closure& report_error_to_uma_cb); |
58 | 68 |
59 ~VaapiWrapper(); | 69 ~VaapiWrapper(); |
60 | 70 |
61 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each | 71 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Put data from |va_surface_id| into |x_pixmap| of size | 121 // Put data from |va_surface_id| into |x_pixmap| of size |
112 // |dest_size|, converting/scaling to it. | 122 // |dest_size|, converting/scaling to it. |
113 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, | 123 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
114 Pixmap x_pixmap, | 124 Pixmap x_pixmap, |
115 gfx::Size dest_size); | 125 gfx::Size dest_size); |
116 #endif // USE_X11 | 126 #endif // USE_X11 |
117 | 127 |
118 // 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. |
119 bool VAAPIVersionLessThan(int major, int minor); | 129 bool VAAPIVersionLessThan(int major, int minor); |
120 | 130 |
121 // 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 size and format |
122 // be released using the ReturnVaImage function. Returns true when successful. | 132 // are derived from the surface. The VAImage should be released using the |
123 // This is intended for testing only. | 133 // ReturnVaImage function. Returns true when successful. This is intended |
124 bool GetVaImageForTesting(VASurfaceID va_surface_id, | 134 // for testing only. |
125 VAImage* image, | 135 bool GetDerivedVaImage(VASurfaceID va_surface_id, VAImage* image, void** mem); |
126 void** mem); | 136 |
| 137 // Get a VAImage from a VASurface |va_surface_id| and map it into memory with |
| 138 // given |format| and |size|. The output is |image| and the mapped memory is |
| 139 // |mem|. The VAImage should be released using the ReturnVaImage function. |
| 140 // Returns true when successful. |
| 141 bool GetVaImage(VASurfaceID va_surface_id, |
| 142 VAImageFormat* format, |
| 143 const gfx::Size& size, |
| 144 VAImage* image, |
| 145 void** mem); |
127 | 146 |
128 // Release the VAImage (and the associated memory mapping) obtained from | 147 // Release the VAImage (and the associated memory mapping) obtained from |
129 // GetVaImage(). This is intended for testing only. | 148 // GetVaImage(). |
130 void ReturnVaImageForTesting(VAImage* image); | 149 void ReturnVaImage(VAImage* image); |
131 | 150 |
132 // Upload contents of |frame| into |va_surface_id| for encode. | 151 // Upload contents of |frame| into |va_surface_id| for encode. |
133 bool UploadVideoFrameToSurface(const scoped_refptr<media::VideoFrame>& frame, | 152 bool UploadVideoFrameToSurface(const scoped_refptr<media::VideoFrame>& frame, |
134 VASurfaceID va_surface_id); | 153 VASurfaceID va_surface_id); |
135 | 154 |
136 // Create a buffer of |size| bytes to be used as encode output. | 155 // Create a buffer of |size| bytes to be used as encode output. |
137 bool CreateCodedBuffer(size_t size, VABufferID* buffer_id); | 156 bool CreateCodedBuffer(size_t size, VABufferID* buffer_id); |
138 | 157 |
139 // Download the contents of the buffer with given |buffer_id| into a buffer of | 158 // Download the contents of the buffer with given |buffer_id| into a buffer of |
140 // size |target_size|, pointed to by |target_ptr|. The number of bytes | 159 // size |target_size|, pointed to by |target_ptr|. The number of bytes |
(...skipping 15 matching lines...) Expand all Loading... |
156 // if needed. | 175 // if needed. |
157 bool BlitSurface(VASurfaceID va_surface_id_src, | 176 bool BlitSurface(VASurfaceID va_surface_id_src, |
158 const gfx::Size& src_size, | 177 const gfx::Size& src_size, |
159 VASurfaceID va_surface_id_dest, | 178 VASurfaceID va_surface_id_dest, |
160 const gfx::Size& dest_size); | 179 const gfx::Size& dest_size); |
161 | 180 |
162 private: | 181 private: |
163 VaapiWrapper(); | 182 VaapiWrapper(); |
164 | 183 |
165 bool Initialize(CodecMode mode, | 184 bool Initialize(CodecMode mode, |
166 media::VideoCodecProfile profile, | 185 VAProfile va_profile, |
167 const base::Closure& report_error__to_uma_cb); | 186 const base::Closure& report_error__to_uma_cb); |
168 void Deinitialize(); | 187 void Deinitialize(); |
169 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 188 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
170 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 189 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
171 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); | 190 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); |
172 bool AreAttribsSupported(VAProfile va_profile, | 191 bool AreAttribsSupported(VAProfile va_profile, |
173 VAEntrypoint entrypoint, | 192 VAEntrypoint entrypoint, |
174 const std::vector<VAConfigAttrib>& required_attribs); | 193 const std::vector<VAConfigAttrib>& required_attribs); |
175 | 194 |
176 // Destroys a |va_surface| created using CreateUnownedSurface. | 195 // Destroys a |va_surface| created using CreateUnownedSurface. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 VAConfigID va_vpp_config_id_; | 252 VAConfigID va_vpp_config_id_; |
234 VAContextID va_vpp_context_id_; | 253 VAContextID va_vpp_context_id_; |
235 VABufferID va_vpp_buffer_id_; | 254 VABufferID va_vpp_buffer_id_; |
236 | 255 |
237 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 256 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
238 }; | 257 }; |
239 | 258 |
240 } // namespace content | 259 } // namespace content |
241 | 260 |
242 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 261 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |