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 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 GetDerivedVaImageForTesting(VASurfaceID va_surface_id, |
| 126 void** mem); | 136 VAImage* image, |
| 137 void** mem); | |
| 138 | |
| 139 // Get a VAImage from a VASurface |va_surface_id| and map it into memory with | |
| 140 // given |format| and |size|. The output is |image| and the mapped memory is | |
| 141 // |mem|. The VAImage should be released using the ReturnVaImage function. | |
| 142 // Returns true when successful. | |
| 143 bool GetVaImage(VASurfaceID va_surface_id, | |
|
wuchengli
2015/01/20 07:55:54
GetDerivedVaImageForTesting, GetVaImage, and Retur
kcwu
2015/01/21 12:23:48
Done.
| |
| 144 VAImageFormat* format, | |
| 145 const gfx::Size& size, | |
| 146 VAImage* image, | |
| 147 void** mem); | |
| 127 | 148 |
| 128 // Release the VAImage (and the associated memory mapping) obtained from | 149 // Release the VAImage (and the associated memory mapping) obtained from |
| 129 // GetVaImage(). This is intended for testing only. | 150 // GetVaImage(). |
| 130 void ReturnVaImageForTesting(VAImage* image); | 151 void ReturnVaImage(VAImage* image); |
| 131 | 152 |
| 132 // Upload contents of |frame| into |va_surface_id| for encode. | 153 // Upload contents of |frame| into |va_surface_id| for encode. |
| 133 bool UploadVideoFrameToSurface(const scoped_refptr<media::VideoFrame>& frame, | 154 bool UploadVideoFrameToSurface(const scoped_refptr<media::VideoFrame>& frame, |
| 134 VASurfaceID va_surface_id); | 155 VASurfaceID va_surface_id); |
| 135 | 156 |
| 136 // Create a buffer of |size| bytes to be used as encode output. | 157 // Create a buffer of |size| bytes to be used as encode output. |
| 137 bool CreateCodedBuffer(size_t size, VABufferID* buffer_id); | 158 bool CreateCodedBuffer(size_t size, VABufferID* buffer_id); |
| 138 | 159 |
| 139 // Download the contents of the buffer with given |buffer_id| into a buffer of | 160 // 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 | 161 // size |target_size|, pointed to by |target_ptr|. The number of bytes |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 156 // if needed. | 177 // if needed. |
| 157 bool BlitSurface(VASurfaceID va_surface_id_src, | 178 bool BlitSurface(VASurfaceID va_surface_id_src, |
| 158 const gfx::Size& src_size, | 179 const gfx::Size& src_size, |
| 159 VASurfaceID va_surface_id_dest, | 180 VASurfaceID va_surface_id_dest, |
| 160 const gfx::Size& dest_size); | 181 const gfx::Size& dest_size); |
| 161 | 182 |
| 162 private: | 183 private: |
| 163 VaapiWrapper(); | 184 VaapiWrapper(); |
| 164 | 185 |
| 165 bool Initialize(CodecMode mode, | 186 bool Initialize(CodecMode mode, |
| 166 media::VideoCodecProfile profile, | 187 VAProfile va_profile, |
| 167 const base::Closure& report_error__to_uma_cb); | 188 const base::Closure& report_error__to_uma_cb); |
| 168 void Deinitialize(); | 189 void Deinitialize(); |
| 169 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 190 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
| 170 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 191 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
| 171 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); | 192 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); |
| 172 bool AreAttribsSupported(VAProfile va_profile, | 193 bool AreAttribsSupported(VAProfile va_profile, |
| 173 VAEntrypoint entrypoint, | 194 VAEntrypoint entrypoint, |
| 174 const std::vector<VAConfigAttrib>& required_attribs); | 195 const std::vector<VAConfigAttrib>& required_attribs); |
| 175 | 196 |
| 176 // Destroys a |va_surface| created using CreateUnownedSurface. | 197 // 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_; | 254 VAConfigID va_vpp_config_id_; |
| 234 VAContextID va_vpp_context_id_; | 255 VAContextID va_vpp_context_id_; |
| 235 VABufferID va_vpp_buffer_id_; | 256 VABufferID va_vpp_buffer_id_; |
| 236 | 257 |
| 237 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 258 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
| 238 }; | 259 }; |
| 239 | 260 |
| 240 } // namespace content | 261 } // namespace content |
| 241 | 262 |
| 242 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 263 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
| OLD | NEW |