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 MEDIA_GPU_VAAPI_WRAPPER_H_ | 10 #ifndef MEDIA_GPU_VAAPI_WRAPPER_H_ |
11 #define MEDIA_GPU_VAAPI_WRAPPER_H_ | 11 #define MEDIA_GPU_VAAPI_WRAPPER_H_ |
12 | 12 |
13 #include <stddef.h> | 13 #include <stddef.h> |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 | 15 |
16 #include <set> | 16 #include <set> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "base/files/file.h" | 19 #include "base/files/file.h" |
20 #include "base/lazy_instance.h" | |
21 #include "base/macros.h" | 20 #include "base/macros.h" |
22 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
23 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
24 #include "media/base/video_decoder_config.h" | 23 #include "media/base/video_decoder_config.h" |
25 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
26 #include "media/gpu/media_gpu_export.h" | 25 #include "media/gpu/media_gpu_export.h" |
27 #include "media/gpu/va_surface.h" | 26 #include "media/gpu/va_surface.h" |
28 #include "media/video/jpeg_decode_accelerator.h" | 27 #include "media/video/jpeg_decode_accelerator.h" |
29 #include "media/video/video_decode_accelerator.h" | 28 #include "media/video/video_decode_accelerator.h" |
30 #include "media/video/video_encode_accelerator.h" | 29 #include "media/video/video_encode_accelerator.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 void Deinitialize(VAStatus* status); | 249 void Deinitialize(VAStatus* status); |
251 | 250 |
252 base::Lock* va_lock() { return &va_lock_; } | 251 base::Lock* va_lock() { return &va_lock_; } |
253 VADisplay va_display() const { return va_display_; } | 252 VADisplay va_display() const { return va_display_; } |
254 | 253 |
255 #if defined(USE_OZONE) | 254 #if defined(USE_OZONE) |
256 void SetDrmFd(base::PlatformFile fd); | 255 void SetDrmFd(base::PlatformFile fd); |
257 #endif // USE_OZONE | 256 #endif // USE_OZONE |
258 | 257 |
259 private: | 258 private: |
260 friend class base::LazyInstance<VADisplayState>; | |
261 | |
262 // Returns true if the VAAPI version is less than the specified version. | 259 // Returns true if the VAAPI version is less than the specified version. |
263 bool VAAPIVersionLessThan(int major, int minor); | 260 bool VAAPIVersionLessThan(int major, int minor); |
264 | 261 |
265 // Protected by |va_lock_|. | 262 // Protected by |va_lock_|. |
266 int refcount_; | 263 int refcount_; |
267 | 264 |
268 // Libva is not thread safe, so we have to do locking for it ourselves. | 265 // Libva is not thread safe, so we have to do locking for it ourselves. |
269 // This lock is to be taken for the duration of all VA-API calls and for | 266 // This lock is to be taken for the duration of all VA-API calls and for |
270 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). | 267 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). |
271 base::Lock va_lock_; | 268 base::Lock va_lock_; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 // Pointer to VADisplayState's member |va_lock_|. Guaranteed to be valid for | 345 // Pointer to VADisplayState's member |va_lock_|. Guaranteed to be valid for |
349 // the lifetime of VaapiWrapper. | 346 // the lifetime of VaapiWrapper. |
350 base::Lock* va_lock_; | 347 base::Lock* va_lock_; |
351 | 348 |
352 // Allocated ids for VASurfaces. | 349 // Allocated ids for VASurfaces. |
353 std::vector<VASurfaceID> va_surface_ids_; | 350 std::vector<VASurfaceID> va_surface_ids_; |
354 | 351 |
355 // VA format of surfaces with va_surface_ids_. | 352 // VA format of surfaces with va_surface_ids_. |
356 unsigned int va_surface_format_; | 353 unsigned int va_surface_format_; |
357 | 354 |
358 // Singleton instance of VADisplayState. | 355 // Points to singleton instance of VADisplayState. |
359 static base::LazyInstance<VADisplayState> va_display_state_; | 356 VADisplayState* va_display_state_; |
Mark Mentovai
2017/01/31 21:33:56
I don’t see a reason for this to be a member varia
DaleCurtis
2017/01/31 22:04:33
Agreed, I messed this conversion up anyways, these
| |
360 | 357 |
361 // VA handles. | 358 // VA handles. |
362 // All valid after successful Initialize() and until Deinitialize(). | 359 // All valid after successful Initialize() and until Deinitialize(). |
363 VADisplay va_display_; | 360 VADisplay va_display_; |
364 VAConfigID va_config_id_; | 361 VAConfigID va_config_id_; |
365 // Created for the current set of va_surface_ids_ in CreateSurfaces() and | 362 // Created for the current set of va_surface_ids_ in CreateSurfaces() and |
366 // valid until DestroySurfaces(). | 363 // valid until DestroySurfaces(). |
367 VAContextID va_context_id_; | 364 VAContextID va_context_id_; |
368 | 365 |
369 // Data queued up for HW codec, to be committed on next execution. | 366 // Data queued up for HW codec, to be committed on next execution. |
370 std::vector<VABufferID> pending_slice_bufs_; | 367 std::vector<VABufferID> pending_slice_bufs_; |
371 std::vector<VABufferID> pending_va_bufs_; | 368 std::vector<VABufferID> pending_va_bufs_; |
372 | 369 |
373 // Bitstream buffers for encode. | 370 // Bitstream buffers for encode. |
374 std::set<VABufferID> coded_buffers_; | 371 std::set<VABufferID> coded_buffers_; |
375 | 372 |
376 // Called to report codec errors to UMA. Errors to clients are reported via | 373 // Called to report codec errors to UMA. Errors to clients are reported via |
377 // return values from public methods. | 374 // return values from public methods. |
378 base::Closure report_error_to_uma_cb_; | 375 base::Closure report_error_to_uma_cb_; |
379 | 376 |
380 // VPP (Video Post Processing) context, this is used to convert | 377 // VPP (Video Post Processing) context, this is used to convert |
381 // pictures used by the decoder to RGBA pictures usable by GL or the | 378 // pictures used by the decoder to RGBA pictures usable by GL or the |
382 // display hardware. | 379 // display hardware. |
383 VAConfigID va_vpp_config_id_; | 380 VAConfigID va_vpp_config_id_; |
384 VAContextID va_vpp_context_id_; | 381 VAContextID va_vpp_context_id_; |
385 VABufferID va_vpp_buffer_id_; | 382 VABufferID va_vpp_buffer_id_; |
386 | 383 |
387 // Singleton variable to store supported profile information for encode and | 384 // Points to singleton variable to store supported profile information for |
388 // decode. | 385 // encode and decode. |
389 static base::LazyInstance<LazyProfileInfos> profile_infos_; | 386 LazyProfileInfos* profile_infos_; |
Mark Mentovai
2017/01/31 21:33:56
This one too.
DaleCurtis
2017/01/31 22:04:33
Done.
| |
390 | 387 |
391 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 388 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
392 }; | 389 }; |
393 | 390 |
394 } // namespace media | 391 } // namespace media |
395 | 392 |
396 #endif // MEDIA_GPU_VAAPI_WRAPPER_H_ | 393 #endif // MEDIA_GPU_VAAPI_WRAPPER_H_ |
OLD | NEW |