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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); | 127 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); |
128 | 128 |
129 #if defined(USE_X11) | 129 #if defined(USE_X11) |
130 // Put data from |va_surface_id| into |x_pixmap| of size | 130 // Put data from |va_surface_id| into |x_pixmap| of size |
131 // |dest_size|, converting/scaling to it. | 131 // |dest_size|, converting/scaling to it. |
132 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, | 132 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id, |
133 Pixmap x_pixmap, | 133 Pixmap x_pixmap, |
134 gfx::Size dest_size); | 134 gfx::Size dest_size); |
135 #endif // USE_X11 | 135 #endif // USE_X11 |
136 | 136 |
137 // Returns true if the VAAPI version is less than the specified version. | |
138 bool VAAPIVersionLessThan(int major, int minor); | |
139 | |
140 // Get a VAImage from a VASurface and map it into memory. The size and format | 137 // Get a VAImage from a VASurface and map it into memory. The size and format |
141 // are derived from the surface. Use GetVaImage() instead if |format| or | 138 // are derived from the surface. Use GetVaImage() instead if |format| or |
142 // |size| are different from surface internal representation. The VAImage | 139 // |size| are different from surface internal representation. The VAImage |
143 // should be released using the ReturnVaImage function. Returns true when | 140 // should be released using the ReturnVaImage function. Returns true when |
144 // successful. | 141 // successful. |
145 bool GetDerivedVaImage(VASurfaceID va_surface_id, VAImage* image, void** mem); | 142 bool GetDerivedVaImage(VASurfaceID va_surface_id, VAImage* image, void** mem); |
146 | 143 |
147 // Get a VAImage from a VASurface |va_surface_id| and map it into memory with | 144 // Get a VAImage from a VASurface |va_surface_id| and map it into memory with |
148 // given |format| and |size|. The output is |image| and the mapped memory is | 145 // given |format| and |size|. The output is |image| and the mapped memory is |
149 // |mem|. If |format| doesn't equal to the internal format, the underlying | 146 // |mem|. If |format| doesn't equal to the internal format, the underlying |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 void DestroyCodedBuffers(); | 181 void DestroyCodedBuffers(); |
185 | 182 |
186 // Blits a VASurface |va_surface_id_src| into another VASurface | 183 // Blits a VASurface |va_surface_id_src| into another VASurface |
187 // |va_surface_id_dest| applying pixel format conversion and scaling | 184 // |va_surface_id_dest| applying pixel format conversion and scaling |
188 // if needed. | 185 // if needed. |
189 bool BlitSurface(VASurfaceID va_surface_id_src, | 186 bool BlitSurface(VASurfaceID va_surface_id_src, |
190 const gfx::Size& src_size, | 187 const gfx::Size& src_size, |
191 VASurfaceID va_surface_id_dest, | 188 VASurfaceID va_surface_id_dest, |
192 const gfx::Size& dest_size); | 189 const gfx::Size& dest_size); |
193 | 190 |
191 // Initialize static data before sandbox is enabled. | |
192 static void PreSandboxInitialization(); | |
193 | |
194 private: | 194 private: |
195 struct ProfileInfo { | 195 struct ProfileInfo { |
196 VAProfile va_profile; | 196 VAProfile va_profile; |
197 gfx::Size max_resolution; | 197 gfx::Size max_resolution; |
198 }; | 198 }; |
199 | 199 |
200 class LazyProfileInfos { | 200 class LazyProfileInfos { |
201 public: | 201 public: |
202 LazyProfileInfos(); | 202 LazyProfileInfos(); |
203 ~LazyProfileInfos(); | 203 ~LazyProfileInfos(); |
204 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( | 204 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( |
205 CodecMode mode); | 205 CodecMode mode); |
206 bool IsProfileSupported(CodecMode mode, VAProfile va_profile); | 206 bool IsProfileSupported(CodecMode mode, VAProfile va_profile); |
207 | 207 |
208 private: | 208 private: |
209 std::vector<ProfileInfo> supported_profiles_[kCodecModeMax]; | 209 std::vector<ProfileInfo> supported_profiles_[kCodecModeMax]; |
210 }; | 210 }; |
211 | 211 |
212 class VADisplayState { | |
213 public: | |
214 VADisplayState(); | |
215 ~VADisplayState(); | |
216 | |
217 // |va_lock_| must be held on entry. | |
218 bool Initialize(VAStatus* status); | |
219 void Deinitialize(VAStatus* status); | |
220 | |
221 base::Lock* va_lock() { return &va_lock_; } | |
222 VADisplay GetVADisplay() const { return va_display_; } | |
hshi1
2015/05/11 23:33:01
note: minor naming change to accessor: GetVADispla
| |
223 | |
224 #if defined(USE_OZONE) | |
225 void SetDrmFd(base::PlatformFile fd); | |
226 #endif // USE_OZONE | |
227 | |
228 private: | |
229 friend class base::LazyInstance<VADisplayState>; | |
230 | |
231 // Returns true if the VAAPI version is less than the specified version. | |
232 bool VAAPIVersionLessThan(int major, int minor); | |
233 | |
234 int refcount_; | |
235 | |
236 // Libva is not thread safe, so we have to do locking for it ourselves. | |
237 // This lock is to be taken for the duration of all VA-API calls and for | |
238 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). | |
239 base::Lock va_lock_; | |
240 | |
241 #if defined(USE_OZONE) | |
242 // Drm fd used to obtain access to the driver interface by VA. | |
243 base::ScopedFD drm_fd_; | |
244 #endif // USE_OZONE | |
245 | |
246 // The VADisplay handle. | |
247 VADisplay va_display_; | |
248 | |
249 // The VAAPI version. | |
250 int major_version_, minor_version_; | |
251 | |
252 // True if vaInitialize has been called successfully. | |
253 bool va_initialized_; | |
254 }; | |
255 | |
212 VaapiWrapper(); | 256 VaapiWrapper(); |
213 | 257 |
214 bool Initialize(CodecMode mode, VAProfile va_profile); | 258 bool Initialize(CodecMode mode, VAProfile va_profile); |
215 void Deinitialize(); | 259 void Deinitialize(); |
216 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 260 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
217 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 261 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
218 | 262 |
219 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be | 263 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be |
220 // held on entry. | 264 // held on entry. |
221 bool IsEntrypointSupported_Locked(VAProfile va_profile, | 265 bool IsEntrypointSupported_Locked(VAProfile va_profile, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 // Lazily initialize static data after sandbox is enabled. Return false on | 306 // Lazily initialize static data after sandbox is enabled. Return false on |
263 // init failure. | 307 // init failure. |
264 static bool PostSandboxInitialization(); | 308 static bool PostSandboxInitialization(); |
265 | 309 |
266 // Map VideoCodecProfile enum values to VaProfile values. This function | 310 // Map VideoCodecProfile enum values to VaProfile values. This function |
267 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline | 311 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline |
268 // and it is not supported, we try constrained baseline. | 312 // and it is not supported, we try constrained baseline. |
269 static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile, | 313 static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile, |
270 CodecMode mode); | 314 CodecMode mode); |
271 | 315 |
272 // Libva is not thread safe, so we have to do locking for it ourselves. | 316 // Pointer to VADisplayState's member |va_lock_|. Guaranteed to be valid for |
273 // This lock is to be taken for the duration of all VA-API calls and for | 317 // the lifetime of VaapiWrapper. |
274 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). | 318 base::Lock* va_lock_; |
275 base::Lock va_lock_; | |
276 | 319 |
277 // Allocated ids for VASurfaces. | 320 // Allocated ids for VASurfaces. |
278 std::vector<VASurfaceID> va_surface_ids_; | 321 std::vector<VASurfaceID> va_surface_ids_; |
279 | 322 |
280 // The VAAPI version. | 323 // Singleton instance of VADisplayState. |
281 int major_version_, minor_version_; | 324 static base::LazyInstance<VADisplayState> va_display_state_; |
282 | 325 |
283 // VA handles. | 326 // VA handles. |
284 // All valid after successful Initialize() and until Deinitialize(). | 327 // All valid after successful Initialize() and until Deinitialize(). |
285 VADisplay va_display_; | 328 VADisplay va_display_; |
286 VAConfigID va_config_id_; | 329 VAConfigID va_config_id_; |
287 // Created for the current set of va_surface_ids_ in CreateSurfaces() and | 330 // Created for the current set of va_surface_ids_ in CreateSurfaces() and |
288 // valid until DestroySurfaces(). | 331 // valid until DestroySurfaces(). |
289 VAContextID va_context_id_; | 332 VAContextID va_context_id_; |
290 // True if vaInitialize has been called successfully. | |
291 bool va_initialized_; | |
292 | 333 |
293 // Data queued up for HW codec, to be committed on next execution. | 334 // Data queued up for HW codec, to be committed on next execution. |
294 std::vector<VABufferID> pending_slice_bufs_; | 335 std::vector<VABufferID> pending_slice_bufs_; |
295 std::vector<VABufferID> pending_va_bufs_; | 336 std::vector<VABufferID> pending_va_bufs_; |
296 | 337 |
297 // Bitstream buffers for encode. | 338 // Bitstream buffers for encode. |
298 std::set<VABufferID> coded_buffers_; | 339 std::set<VABufferID> coded_buffers_; |
299 | 340 |
300 // Called to report codec errors to UMA. Errors to clients are reported via | 341 // Called to report codec errors to UMA. Errors to clients are reported via |
301 // return values from public methods. | 342 // return values from public methods. |
302 base::Closure report_error_to_uma_cb_; | 343 base::Closure report_error_to_uma_cb_; |
303 | 344 |
304 // VPP (Video Post Processing) context, this is used to convert | 345 // VPP (Video Post Processing) context, this is used to convert |
305 // pictures used by the decoder to RGBA pictures usable by GL or the | 346 // pictures used by the decoder to RGBA pictures usable by GL or the |
306 // display hardware. | 347 // display hardware. |
307 VAConfigID va_vpp_config_id_; | 348 VAConfigID va_vpp_config_id_; |
308 VAContextID va_vpp_context_id_; | 349 VAContextID va_vpp_context_id_; |
309 VABufferID va_vpp_buffer_id_; | 350 VABufferID va_vpp_buffer_id_; |
310 | 351 |
311 #if defined(USE_OZONE) | |
312 // Drm file used to obtain access to the driver interface by VA. | |
313 base::File drm_file_; | |
314 #endif // USE_OZONE | |
315 | |
316 // Singleton variable to store supported profile information for encode and | 352 // Singleton variable to store supported profile information for encode and |
317 // decode. | 353 // decode. |
318 static base::LazyInstance<LazyProfileInfos> profile_infos_; | 354 static base::LazyInstance<LazyProfileInfos> profile_infos_; |
319 | 355 |
320 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 356 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
321 }; | 357 }; |
322 | 358 |
323 } // namespace content | 359 } // namespace content |
324 | 360 |
325 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 361 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |