Chromium Code Reviews| 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 to interface | 6 // VaapiVideoDecodeAccelerator and VaapiH264Decoder to interface |
| 7 // with libva (VA-API library for hardware video decode). | 7 // with libva (VA-API library for hardware video decode). |
| 8 | 8 |
| 9 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 9 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
| 10 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 10 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
| 11 | 11 |
| 12 #include <vector> | |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 16 #include "content/common/gpu/media/va_surface.h" | 17 #include "content/common/gpu/media/va_surface.h" |
| 17 #include "media/base/video_decoder_config.h" | 18 #include "media/base/video_decoder_config.h" |
| 18 #include "media/base/video_frame.h" | 19 #include "media/base/video_frame.h" |
| 20 #if defined (USE_OZONE) | |
| 21 #include "third_party/libva/va/wayland/va_wayland.h" | |
| 22 #else | |
| 19 #include "third_party/libva/va/va_x11.h" | 23 #include "third_party/libva/va/va_x11.h" |
| 24 #endif | |
| 20 #include "ui/gfx/size.h" | 25 #include "ui/gfx/size.h" |
| 21 | 26 |
| 22 namespace content { | 27 namespace content { |
| 23 | 28 |
| 24 // This class handles VA-API calls and ensures proper locking of VA-API calls | 29 // This class handles VA-API calls and ensures proper locking of VA-API calls |
| 25 // to libva, the userspace shim to the HW decoder driver. libva is not | 30 // to libva, the userspace shim to the HW decoder driver. libva is not |
| 26 // thread-safe, so we have to perform locking ourselves. This class is fully | 31 // thread-safe, so we have to perform locking ourselves. This class is fully |
| 27 // synchronous and its methods can be called from any thread and may wait on | 32 // synchronous and its methods can be called from any thread and may wait on |
| 28 // the va_lock_ while other, concurrent calls run. | 33 // the va_lock_ while other, concurrent calls run. |
| 29 // | 34 // |
| 30 // This class is responsible for managing VAAPI connection, contexts and state. | 35 // This class is responsible for managing VAAPI connection, contexts and state. |
| 31 // It is also responsible for managing and freeing VABuffers (not VASurfaces), | 36 // It is also responsible for managing and freeing VABuffers (not VASurfaces), |
| 32 // which are used to queue decode parameters and slice data to the HW decoder, | 37 // which are used to queue decode parameters and slice data to the HW decoder, |
| 33 // as well as underlying memory for VASurfaces themselves. | 38 // as well as underlying memory for VASurfaces themselves. |
| 34 class CONTENT_EXPORT VaapiWrapper { | 39 class CONTENT_EXPORT VaapiWrapper { |
| 35 public: | 40 public: |
| 36 // |report_error_to_uma_cb| will be called independently from reporting | 41 // |report_error_to_uma_cb| will be called independently from reporting |
| 37 // errors to clients via method return values. | 42 // errors to clients via method return values. |
| 38 static scoped_ptr<VaapiWrapper> Create( | 43 static scoped_ptr<VaapiWrapper> Create( |
| 39 media::VideoCodecProfile profile, | 44 media::VideoCodecProfile profile, |
| 40 Display* x_display, | 45 void* display, |
| 41 const base::Closure& report_error_to_uma_cb); | 46 const base::Closure& report_error_to_uma_cb); |
| 42 | 47 |
| 43 ~VaapiWrapper(); | 48 ~VaapiWrapper(); |
| 44 | 49 |
| 45 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each | 50 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each |
| 46 // of size |size|. Returns true when successful, with the created IDs in | 51 // of size |size|. Returns true when successful, with the created IDs in |
| 47 // |va_surfaces| to be managed and later wrapped in VASurfaces. | 52 // |va_surfaces| to be managed and later wrapped in VASurfaces. |
| 48 // The client must DestroySurfaces() each time before calling this method | 53 // The client must DestroySurfaces() each time before calling this method |
| 49 // again to free the allocated surfaces first, but is not required to do so | 54 // again to free the allocated surfaces first, but is not required to do so |
| 50 // at destruction time, as this will be done automatically from | 55 // at destruction time, as this will be done automatically from |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 65 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); | 70 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); |
| 66 | 71 |
| 67 // Cancel and destroy all buffers queued to the HW decoder via SubmitBuffer. | 72 // Cancel and destroy all buffers queued to the HW decoder via SubmitBuffer. |
| 68 // Useful when a pending decode is to be cancelled (on reset or error). | 73 // Useful when a pending decode is to be cancelled (on reset or error). |
| 69 void DestroyPendingBuffers(); | 74 void DestroyPendingBuffers(); |
| 70 | 75 |
| 71 // Execute decode in hardware into |va_surface_id} and destroy pending | 76 // Execute decode in hardware into |va_surface_id} and destroy pending |
| 72 // buffers. Return false if SubmitDecode() fails. | 77 // buffers. Return false if SubmitDecode() fails. |
| 73 bool DecodeAndDestroyPendingBuffers(VASurfaceID va_surface_id); | 78 bool DecodeAndDestroyPendingBuffers(VASurfaceID va_surface_id); |
| 74 | 79 |
| 80 #if defined (USE_OZONE) | |
| 81 bool CreateRGBImage(gfx::Size size, VAImage* image); | |
|
Ami GONE FROM CHROMIUM
2014/04/18 22:40:25
document methods please.
| |
| 82 void DestroyImage(VAImage* image); | |
| 83 | |
| 84 bool MapImage(VAImage* image, void** buffer); | |
| 85 void UnmapImage(VAImage* image); | |
| 86 | |
| 87 // Put data from |va_surface_id| into |va_image|, converting/scaling it. | |
| 88 bool PutSurfaceIntoImage(VASurfaceID va_surface_id, | |
| 89 VAImage* va_image); | |
| 90 #else | |
| 75 // Put data from |va_surface_id| into |x_pixmap| of size |size|, | 91 // Put data from |va_surface_id| into |x_pixmap| of size |size|, |
| 76 // converting/scaling to it. | 92 // converting/scaling to it. |
| 77 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, | 93 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
| 78 Pixmap x_pixmap, | 94 Pixmap x_pixmap, |
| 79 gfx::Size dest_size); | 95 gfx::Size dest_size); |
| 80 | 96 #endif |
| 81 // Returns true if the VAAPI version is less than the specified version. | 97 // Returns true if the VAAPI version is less than the specified version. |
| 82 bool VAAPIVersionLessThan(int major, int minor); | 98 bool VAAPIVersionLessThan(int major, int minor); |
| 83 | 99 |
| 84 // Get a VAImage from a VASurface and map it into memory. The VAImage should | 100 // Get a VAImage from a VASurface and map it into memory. The VAImage should |
| 85 // be released using the ReturnVaImage function. Returns true when successful. | 101 // be released using the ReturnVaImage function. Returns true when successful. |
| 86 // This is intended for testing only. | 102 // This is intended for testing only. |
| 87 bool GetVaImageForTesting(VASurfaceID va_surface_id, | 103 bool GetVaImageForTesting(VASurfaceID va_surface_id, |
| 88 VAImage* image, | 104 VAImage* image, |
| 89 void** mem); | 105 void** mem); |
| 90 | 106 |
| 91 // Release the VAImage (and the associated memory mapping) obtained from | 107 // Release the VAImage (and the associated memory mapping) obtained from |
| 92 // GetVaImage(). This is intended for testing only. | 108 // GetVaImage(). This is intended for testing only. |
| 93 void ReturnVaImageForTesting(VAImage* image); | 109 void ReturnVaImageForTesting(VAImage* image); |
| 94 | 110 |
| 95 private: | 111 private: |
| 96 VaapiWrapper(); | 112 VaapiWrapper(); |
| 97 | 113 |
| 98 bool Initialize(media::VideoCodecProfile profile, | 114 bool Initialize(media::VideoCodecProfile profile, |
| 99 Display* x_display, | 115 void* display, |
| 100 const base::Closure& report_error__to_uma_cb); | 116 const base::Closure& report_error__to_uma_cb); |
| 101 void Deinitialize(); | 117 void Deinitialize(); |
| 102 | 118 |
| 103 // Execute decode in hardware and destroy pending buffers. Return false if | 119 // Execute decode in hardware and destroy pending buffers. Return false if |
| 104 // vaapi driver refuses to accept parameter or slice buffers submitted | 120 // vaapi driver refuses to accept parameter or slice buffers submitted |
| 105 // by client or if decode fails in hardware. | 121 // by client or if decode fails in hardware. |
| 106 bool SubmitDecode(VASurfaceID va_surface_id); | 122 bool SubmitDecode(VASurfaceID va_surface_id); |
| 107 | 123 |
| 108 // Attempt to set render mode to "render to texture.". Failure is non-fatal. | 124 // Attempt to set render mode to "render to texture.". Failure is non-fatal. |
| 109 void TryToSetVADisplayAttributeToLocalGPU(); | 125 void TryToSetVADisplayAttributeToLocalGPU(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 138 // Called to report decoding errors to UMA. Errors to clients are reported via | 154 // Called to report decoding errors to UMA. Errors to clients are reported via |
| 139 // return values from public methods. | 155 // return values from public methods. |
| 140 base::Closure report_error_to_uma_cb_; | 156 base::Closure report_error_to_uma_cb_; |
| 141 | 157 |
| 142 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 158 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
| 143 }; | 159 }; |
| 144 | 160 |
| 145 } // namespace content | 161 } // namespace content |
| 146 | 162 |
| 147 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 163 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
| OLD | NEW |