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 for VAProfile. |
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 VideoCodecProfile. It maps VideoCodecProfile |
| 57 // |profile| to VAProfile. |
| 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. Use GetVaImage() instead if |format| or |
123 // This is intended for testing only. | 133 // |size| are different from surface internal representation. The VAImage |
124 bool GetVaImageForTesting(VASurfaceID va_surface_id, | 134 // should be released using the ReturnVaImage function. Returns true when |
125 VAImage* image, | 135 // successful. |
126 void** mem); | 136 bool GetDerivedVaImage(VASurfaceID va_surface_id, VAImage* image, void** mem); |
| 137 |
| 138 // Get a VAImage from a VASurface |va_surface_id| and map it into memory with |
| 139 // given |format| and |size|. The output is |image| and the mapped memory is |
| 140 // |mem|. If |format| doesn't equal to the internal format, the underlying |
| 141 // implementation will do format conversion if supported. |size| should be |
| 142 // smaller than or equal to the surface. If |size| is smaller, the image will |
| 143 // be cropped. The VAImage should be released using the ReturnVaImage |
| 144 // function. Returns true when successful. |
| 145 bool GetVaImage(VASurfaceID va_surface_id, |
| 146 VAImageFormat* format, |
| 147 const gfx::Size& size, |
| 148 VAImage* image, |
| 149 void** mem); |
127 | 150 |
128 // Release the VAImage (and the associated memory mapping) obtained from | 151 // Release the VAImage (and the associated memory mapping) obtained from |
129 // GetVaImage(). This is intended for testing only. | 152 // GetVaImage() or GetDerivedVaImage(). |
130 void ReturnVaImageForTesting(VAImage* image); | 153 void ReturnVaImage(VAImage* image); |
131 | 154 |
132 // Upload contents of |frame| into |va_surface_id| for encode. | 155 // Upload contents of |frame| into |va_surface_id| for encode. |
133 bool UploadVideoFrameToSurface(const scoped_refptr<media::VideoFrame>& frame, | 156 bool UploadVideoFrameToSurface(const scoped_refptr<media::VideoFrame>& frame, |
134 VASurfaceID va_surface_id); | 157 VASurfaceID va_surface_id); |
135 | 158 |
136 // Create a buffer of |size| bytes to be used as encode output. | 159 // Create a buffer of |size| bytes to be used as encode output. |
137 bool CreateCodedBuffer(size_t size, VABufferID* buffer_id); | 160 bool CreateCodedBuffer(size_t size, VABufferID* buffer_id); |
138 | 161 |
139 // Download the contents of the buffer with given |buffer_id| into a buffer of | 162 // 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 | 163 // size |target_size|, pointed to by |target_ptr|. The number of bytes |
(...skipping 14 matching lines...) Expand all Loading... |
155 // |va_surface_id_dest| applying pixel format conversion and scaling | 178 // |va_surface_id_dest| applying pixel format conversion and scaling |
156 // if needed. | 179 // if needed. |
157 bool BlitSurface(VASurfaceID va_surface_id_src, | 180 bool BlitSurface(VASurfaceID va_surface_id_src, |
158 const gfx::Size& src_size, | 181 const gfx::Size& src_size, |
159 VASurfaceID va_surface_id_dest, | 182 VASurfaceID va_surface_id_dest, |
160 const gfx::Size& dest_size); | 183 const gfx::Size& dest_size); |
161 | 184 |
162 private: | 185 private: |
163 VaapiWrapper(); | 186 VaapiWrapper(); |
164 | 187 |
165 bool Initialize(CodecMode mode, | 188 bool Initialize(CodecMode mode, VAProfile va_profile); |
166 media::VideoCodecProfile profile, | |
167 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. |
177 void DestroyUnownedSurface(VASurfaceID va_surface_id); | 198 void DestroyUnownedSurface(VASurfaceID va_surface_id); |
(...skipping 55 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 |