Chromium Code Reviews| Index: content/common/gpu/media/vaapi_wrapper.h |
| diff --git a/content/common/gpu/media/vaapi_wrapper.h b/content/common/gpu/media/vaapi_wrapper.h |
| index 39906a0f405004b98a68bd7a18347041557dc326..096cb407ba1ec030aa214e9e16400b26bdbbb11c 100644 |
| --- a/content/common/gpu/media/vaapi_wrapper.h |
| +++ b/content/common/gpu/media/vaapi_wrapper.h |
| @@ -13,18 +13,23 @@ |
| #include <set> |
| #include <vector> |
| -#include "base/callback.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/synchronization/lock.h" |
| #include "content/common/content_export.h" |
| #include "content/common/gpu/media/va_surface.h" |
| #include "media/base/video_decoder_config.h" |
| #include "media/base/video_frame.h" |
| -#include "third_party/libva/va/va_x11.h" |
| +#include "third_party/libva/va/va.h" |
| +#include "third_party/libva/va/va_vpp.h" |
| #include "ui/gfx/size.h" |
| +#if defined(USE_X11) |
| +#include "third_party/libva/va/va_x11.h" |
| +#endif // USE_X11 |
| namespace content { |
| +class VaapiPicture; |
| + |
| // This class handles VA-API calls and ensures proper locking of VA-API calls |
| // to libva, the userspace shim to the HW codec driver. libva is not |
| // thread-safe, so we have to perform locking ourselves. This class is fully |
| @@ -35,7 +40,7 @@ namespace content { |
| // It is also responsible for managing and freeing VABuffers (not VASurfaces), |
| // which are used to queue parameters and slice data to the HW codec, |
| // as well as underlying memory for VASurfaces themselves. |
| -class CONTENT_EXPORT VaapiWrapper { |
| +class CONTENT_EXPORT VaapiWrapper : public base::RefCounted<VaapiWrapper> { |
|
scherkus (not reviewing)
2014/12/10 18:56:48
what's necessitates ref-counting? is it possible t
llandwerlin-old
2014/12/13 15:23:54
To support X11 and Ozone, we need to abstract the
seanvk
2014/12/16 17:21:51
As long as X11 needs to be supported, this is the
|
| public: |
| enum CodecMode { |
| kDecode, |
| @@ -44,19 +49,15 @@ class CONTENT_EXPORT VaapiWrapper { |
| // |report_error_to_uma_cb| will be called independently from reporting |
| // errors to clients via method return values. |
| - static scoped_ptr<VaapiWrapper> Create( |
| + static scoped_refptr<VaapiWrapper> Create( |
| CodecMode mode, |
| media::VideoCodecProfile profile, |
| - Display* x_display, |
| const base::Closure& report_error_to_uma_cb); |
| // Return the supported encode profiles. |
| static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( |
| - Display* x_display, |
| const base::Closure& report_error_to_uma_cb); |
| - ~VaapiWrapper(); |
| - |
| // Create |num_surfaces| backing surfaces in driver for VASurfaces, each |
| // of size |size|. Returns true when successful, with the created IDs in |
| // |va_surfaces| to be managed and later wrapped in VASurfaces. |
| @@ -64,13 +65,23 @@ class CONTENT_EXPORT VaapiWrapper { |
| // again to free the allocated surfaces first, but is not required to do so |
| // at destruction time, as this will be done automatically from |
| // the destructor. |
| - bool CreateSurfaces(gfx::Size size, |
| + bool CreateSurfaces(const gfx::Size& size, |
| size_t num_surfaces, |
| std::vector<VASurfaceID>* va_surfaces); |
| // Free all memory allocated in CreateSurfaces. |
| void DestroySurfaces(); |
| + // Create a VASurface of |va_format|, |size| and using |
| + // |num_va_attribs| attributes from |va_attribs|. The ownership of |
| + // the surface is transfered to the caller. It differs from surfaces |
| + // created using CreateSurfaces() where VaapiWrapper is the owner of |
| + // the surfaces. |
| + scoped_refptr<VASurface> CreateUnownedSurface(unsigned int va_format, |
| + const gfx::Size& size, |
| + VASurfaceAttrib* va_attribs, |
| + size_t num_va_attribs); |
| + |
| // Submit parameters or slice data of |va_buffer_type|, copying them from |
| // |buffer| of size |size|, into HW codec. The data in |buffer| is no |
| // longer needed and can be freed after this method returns. |
| @@ -97,12 +108,6 @@ class CONTENT_EXPORT VaapiWrapper { |
| // buffers. Return false if Execute() fails. |
| bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); |
| - // Put data from |va_surface_id| into |x_pixmap| of size |size|, |
| - // converting/scaling to it. |
| - bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
| - Pixmap x_pixmap, |
| - gfx::Size dest_size); |
| - |
| // Returns true if the VAAPI version is less than the specified version. |
| bool VAAPIVersionLessThan(int major, int minor); |
| @@ -139,22 +144,48 @@ class CONTENT_EXPORT VaapiWrapper { |
| // Destroy all previously-allocated (and not yet destroyed) coded buffers. |
| void DestroyCodedBuffers(); |
| + // Blits a VASurface |va_surface_id_src| into another VASurface |
| + // |va_surface_id_dest| applying pixel format conversion and scaling |
| + // if needed. |
| + bool BlitSurface(VASurfaceID va_surface_id_src, |
| + const gfx::Size& src_size, |
| + VASurfaceID va_surface_id_dest, |
| + const gfx::Size& dest_size); |
| + |
| +#if defined(USE_X11) |
| + // Put data from |va_surface_id| into |x_pixmap| of size |
| + // |dest_size|, converting/scaling to it. |
| + bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
| + Pixmap x_pixmap, |
| + gfx::Size dest_size); |
| +#endif // USE_X11 |
| + |
| private: |
| + friend class base::RefCounted<VaapiWrapper>; |
| VaapiWrapper(); |
| + ~VaapiWrapper(); |
| bool Initialize(CodecMode mode, |
| media::VideoCodecProfile profile, |
| - Display* x_display, |
| - const base::Closure& report_error_to_uma_cb); |
| + const base::Closure& report_error__to_uma_cb); |
| void Deinitialize(); |
| - bool VaInitialize(Display* x_display, |
| - const base::Closure& report_error_to_uma_cb); |
| + bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
| bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
| bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); |
| bool AreAttribsSupported(VAProfile va_profile, |
| VAEntrypoint entrypoint, |
| const std::vector<VAConfigAttrib>& required_attribs); |
| + // Destroys a |va_surface| created using CreateUnownedSurface. |
| + void DestroyUnownedSurface(VASurfaceID va_surface); |
| + |
| + // Initialize the video post processing context with the |size| of |
| + // the input pictures to be processed. |
| + bool InitializeVpp_Locked(); |
| + |
| + // Deinitialize the video post processing context. |
| + void DeinitializeVpp(); |
| + |
| // Execute pending job in hardware and destroy pending buffers. Return false |
| // if vaapi driver refuses to accept parameter or slice buffers submitted |
| // by client, or if execution fails in hardware. |
| @@ -179,7 +210,7 @@ class CONTENT_EXPORT VaapiWrapper { |
| int major_version_, minor_version_; |
| // VA handles. |
| - // Both valid after successful Initialize() and until Deinitialize(). |
| + // All valid after successful Initialize() and until Deinitialize(). |
| VADisplay va_display_; |
| VAConfigID va_config_id_; |
| // Created for the current set of va_surface_ids_ in CreateSurfaces() and |
| @@ -197,6 +228,11 @@ class CONTENT_EXPORT VaapiWrapper { |
| // return values from public methods. |
| base::Closure report_error_to_uma_cb_; |
| + // VPP context |
| + VAConfigID va_vpp_config_id_; |
| + VAContextID va_vpp_context_id_; |
| + VABufferID va_vpp_buffer_id_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
| }; |