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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); | 127 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); |
128 | 128 |
129 #if defined(USE_X11) | 129 #if defined(USE_X11) |
130 // Put data from |va_surface_id| into |x_pixmap| of size | 130 // Put data from |va_surface_id| into |x_pixmap| of size |
131 // |dest_size|, converting/scaling to it. | 131 // |dest_size|, converting/scaling to it. |
132 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, | 132 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
133 Pixmap x_pixmap, | 133 Pixmap x_pixmap, |
134 gfx::Size dest_size); | 134 gfx::Size dest_size); |
135 #endif // USE_X11 | 135 #endif // USE_X11 |
136 | 136 |
137 // Returns true if the VAAPI version is less than the specified version. | |
138 bool VAAPIVersionLessThan(int major, int minor); | |
139 | |
140 // Get a VAImage from a VASurface and map it into memory. The size and format | 137 // Get a VAImage from a VASurface and map it into memory. The size and format |
141 // are derived from the surface. Use GetVaImage() instead if |format| or | 138 // are derived from the surface. Use GetVaImage() instead if |format| or |
142 // |size| are different from surface internal representation. The VAImage | 139 // |size| are different from surface internal representation. The VAImage |
143 // should be released using the ReturnVaImage function. Returns true when | 140 // should be released using the ReturnVaImage function. Returns true when |
144 // successful. | 141 // successful. |
145 bool GetDerivedVaImage(VASurfaceID va_surface_id, VAImage* image, void** mem); | 142 bool GetDerivedVaImage(VASurfaceID va_surface_id, VAImage* image, void** mem); |
146 | 143 |
147 // Get a VAImage from a VASurface |va_surface_id| and map it into memory with | 144 // Get a VAImage from a VASurface |va_surface_id| and map it into memory with |
148 // given |format| and |size|. The output is |image| and the mapped memory is | 145 // given |format| and |size|. The output is |image| and the mapped memory is |
149 // |mem|. If |format| doesn't equal to the internal format, the underlying | 146 // |mem|. If |format| doesn't equal to the internal format, the underlying |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 void DestroyCodedBuffers(); | 181 void DestroyCodedBuffers(); |
185 | 182 |
186 // Blits a VASurface |va_surface_id_src| into another VASurface | 183 // Blits a VASurface |va_surface_id_src| into another VASurface |
187 // |va_surface_id_dest| applying pixel format conversion and scaling | 184 // |va_surface_id_dest| applying pixel format conversion and scaling |
188 // if needed. | 185 // if needed. |
189 bool BlitSurface(VASurfaceID va_surface_id_src, | 186 bool BlitSurface(VASurfaceID va_surface_id_src, |
190 const gfx::Size& src_size, | 187 const gfx::Size& src_size, |
191 VASurfaceID va_surface_id_dest, | 188 VASurfaceID va_surface_id_dest, |
192 const gfx::Size& dest_size); | 189 const gfx::Size& dest_size); |
193 | 190 |
191 // Initialize static data before sandbox is enabled. | |
192 static void PreSandboxInitialization(); | |
193 | |
194 private: | 194 private: |
195 struct ProfileInfo { | 195 struct ProfileInfo { |
196 VAProfile va_profile; | 196 VAProfile va_profile; |
197 gfx::Size max_resolution; | 197 gfx::Size max_resolution; |
198 }; | 198 }; |
199 | 199 |
200 class LazyProfileInfos { | 200 class LazyProfileInfos { |
201 public: | 201 public: |
202 LazyProfileInfos(); | 202 LazyProfileInfos(); |
203 ~LazyProfileInfos(); | 203 ~LazyProfileInfos(); |
204 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( | 204 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( |
205 CodecMode mode); | 205 CodecMode mode); |
206 bool IsProfileSupported(CodecMode mode, VAProfile va_profile); | 206 bool IsProfileSupported(CodecMode mode, VAProfile va_profile); |
207 | 207 |
208 private: | 208 private: |
209 std::vector<ProfileInfo> supported_profiles_[kCodecModeMax]; | 209 std::vector<ProfileInfo> supported_profiles_[kCodecModeMax]; |
210 }; | 210 }; |
211 | 211 |
212 class VADisplayState { | |
213 public: | |
214 VADisplayState(); | |
215 ~VADisplayState(); | |
216 | |
217 // |va_lock_| must be held on entry. | |
Pawel Osciak
2015/05/11 05:51:45
va_lock_ is not a member of this class and is per-
hshi1
2015/05/11 17:14:39
I have moved va_lock_ into VADisplayState, which w
| |
218 bool Initialize(VAStatus* status); | |
219 void Deinitialize(VAStatus* status); | |
220 | |
221 VADisplay GetVADisplay() const; | |
222 | |
223 #if defined(USE_OZONE) | |
224 void SetDrmFd(base::PlatformFile fd); | |
225 #endif // USE_OZONE | |
226 | |
227 private: | |
228 #if defined(USE_OZONE) | |
229 friend class base::LazyInstance<VADisplayState>; | |
230 #endif // USE_OZONE | |
231 | |
232 // Returns true if the VAAPI version is less than the specified version. | |
233 bool VAAPIVersionLessThan(int major, int minor); | |
234 | |
235 int refcount_; | |
236 | |
237 #if defined(USE_OZONE) | |
238 // Drm fd used to obtain access to the driver interface by VA. | |
239 base::ScopedFD drm_fd_; | |
240 #endif // USE_OZONE | |
241 | |
242 // The VADisplay handle. | |
243 VADisplay va_display_; | |
244 | |
245 // The VAAPI version. | |
246 int major_version_, minor_version_; | |
247 | |
248 // True if vaInitialize has been called successfully. | |
249 bool va_initialized_; | |
250 }; | |
251 | |
212 VaapiWrapper(); | 252 VaapiWrapper(); |
213 | 253 |
214 bool Initialize(CodecMode mode, VAProfile va_profile); | 254 bool Initialize(CodecMode mode, VAProfile va_profile); |
215 void Deinitialize(); | 255 void Deinitialize(); |
216 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 256 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
217 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 257 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
218 | 258 |
219 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be | 259 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be |
220 // held on entry. | 260 // held on entry. |
221 bool IsEntrypointSupported_Locked(VAProfile va_profile, | 261 bool IsEntrypointSupported_Locked(VAProfile va_profile, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 CodecMode mode); | 310 CodecMode mode); |
271 | 311 |
272 // Libva is not thread safe, so we have to do locking for it ourselves. | 312 // Libva is not thread safe, so we have to do locking for it ourselves. |
273 // This lock is to be taken for the duration of all VA-API calls and for | 313 // This lock is to be taken for the duration of all VA-API calls and for |
274 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). | 314 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). |
275 base::Lock va_lock_; | 315 base::Lock va_lock_; |
276 | 316 |
277 // Allocated ids for VASurfaces. | 317 // Allocated ids for VASurfaces. |
278 std::vector<VASurfaceID> va_surface_ids_; | 318 std::vector<VASurfaceID> va_surface_ids_; |
279 | 319 |
280 // The VAAPI version. | 320 #if defined(USE_X11) |
281 int major_version_, minor_version_; | 321 // VADisplay and related state. |
322 scoped_ptr<VADisplayState> va_display_state_; | |
323 #elif defined(USE_OZONE) | |
324 // Singleton instance of VADisplayState. | |
325 static base::LazyInstance<VADisplayState> g_va_display_state_; | |
326 #endif // USE_X11 | |
282 | 327 |
283 // VA handles. | 328 // VA handles. |
284 // All valid after successful Initialize() and until Deinitialize(). | 329 // All valid after successful Initialize() and until Deinitialize(). |
285 VADisplay va_display_; | 330 VADisplay va_display_; |
286 VAConfigID va_config_id_; | 331 VAConfigID va_config_id_; |
287 // Created for the current set of va_surface_ids_ in CreateSurfaces() and | 332 // Created for the current set of va_surface_ids_ in CreateSurfaces() and |
288 // valid until DestroySurfaces(). | 333 // valid until DestroySurfaces(). |
289 VAContextID va_context_id_; | 334 VAContextID va_context_id_; |
290 // True if vaInitialize has been called successfully. | |
291 bool va_initialized_; | |
292 | 335 |
293 // Data queued up for HW codec, to be committed on next execution. | 336 // Data queued up for HW codec, to be committed on next execution. |
294 std::vector<VABufferID> pending_slice_bufs_; | 337 std::vector<VABufferID> pending_slice_bufs_; |
295 std::vector<VABufferID> pending_va_bufs_; | 338 std::vector<VABufferID> pending_va_bufs_; |
296 | 339 |
297 // Bitstream buffers for encode. | 340 // Bitstream buffers for encode. |
298 std::set<VABufferID> coded_buffers_; | 341 std::set<VABufferID> coded_buffers_; |
299 | 342 |
300 // Called to report codec errors to UMA. Errors to clients are reported via | 343 // Called to report codec errors to UMA. Errors to clients are reported via |
301 // return values from public methods. | 344 // return values from public methods. |
302 base::Closure report_error_to_uma_cb_; | 345 base::Closure report_error_to_uma_cb_; |
303 | 346 |
304 // VPP (Video Post Processing) context, this is used to convert | 347 // VPP (Video Post Processing) context, this is used to convert |
305 // pictures used by the decoder to RGBA pictures usable by GL or the | 348 // pictures used by the decoder to RGBA pictures usable by GL or the |
306 // display hardware. | 349 // display hardware. |
307 VAConfigID va_vpp_config_id_; | 350 VAConfigID va_vpp_config_id_; |
308 VAContextID va_vpp_context_id_; | 351 VAContextID va_vpp_context_id_; |
309 VABufferID va_vpp_buffer_id_; | 352 VABufferID va_vpp_buffer_id_; |
310 | 353 |
311 #if defined(USE_OZONE) | |
312 // Drm file used to obtain access to the driver interface by VA. | |
313 base::File drm_file_; | |
314 #endif // USE_OZONE | |
315 | |
316 // Singleton variable to store supported profile information for encode and | 354 // Singleton variable to store supported profile information for encode and |
317 // decode. | 355 // decode. |
318 static base::LazyInstance<LazyProfileInfos> profile_infos_; | 356 static base::LazyInstance<LazyProfileInfos> profile_infos_; |
319 | 357 |
320 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 358 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
321 }; | 359 }; |
322 | 360 |
323 } // namespace content | 361 } // namespace content |
324 | 362 |
325 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 363 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |