| 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 va_display() const { return va_display_; } |
| 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 // Protected by |va_lock_|. |
| 235 int refcount_; |
| 236 |
| 237 // Libva is not thread safe, so we have to do locking for it ourselves. |
| 238 // This lock is to be taken for the duration of all VA-API calls and for |
| 239 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). |
| 240 base::Lock va_lock_; |
| 241 |
| 242 #if defined(USE_OZONE) |
| 243 // Drm fd used to obtain access to the driver interface by VA. |
| 244 base::ScopedFD drm_fd_; |
| 245 #endif // USE_OZONE |
| 246 |
| 247 // The VADisplay handle. |
| 248 VADisplay va_display_; |
| 249 |
| 250 // The VAAPI version. |
| 251 int major_version_, minor_version_; |
| 252 |
| 253 // True if vaInitialize has been called successfully. |
| 254 bool va_initialized_; |
| 255 }; |
| 256 |
| 212 VaapiWrapper(); | 257 VaapiWrapper(); |
| 213 | 258 |
| 214 bool Initialize(CodecMode mode, VAProfile va_profile); | 259 bool Initialize(CodecMode mode, VAProfile va_profile); |
| 215 void Deinitialize(); | 260 void Deinitialize(); |
| 216 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 261 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
| 217 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 262 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
| 218 | 263 |
| 219 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be | 264 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be |
| 220 // held on entry. | 265 // held on entry. |
| 221 bool IsEntrypointSupported_Locked(VAProfile va_profile, | 266 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 | 307 // Lazily initialize static data after sandbox is enabled. Return false on |
| 263 // init failure. | 308 // init failure. |
| 264 static bool PostSandboxInitialization(); | 309 static bool PostSandboxInitialization(); |
| 265 | 310 |
| 266 // Map VideoCodecProfile enum values to VaProfile values. This function | 311 // Map VideoCodecProfile enum values to VaProfile values. This function |
| 267 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline | 312 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline |
| 268 // and it is not supported, we try constrained baseline. | 313 // and it is not supported, we try constrained baseline. |
| 269 static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile, | 314 static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile, |
| 270 CodecMode mode); | 315 CodecMode mode); |
| 271 | 316 |
| 272 // Libva is not thread safe, so we have to do locking for it ourselves. | 317 // 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 | 318 // the lifetime of VaapiWrapper. |
| 274 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). | 319 base::Lock* va_lock_; |
| 275 base::Lock va_lock_; | |
| 276 | 320 |
| 277 // Allocated ids for VASurfaces. | 321 // Allocated ids for VASurfaces. |
| 278 std::vector<VASurfaceID> va_surface_ids_; | 322 std::vector<VASurfaceID> va_surface_ids_; |
| 279 | 323 |
| 280 // The VAAPI version. | 324 // Singleton instance of VADisplayState. |
| 281 int major_version_, minor_version_; | 325 static base::LazyInstance<VADisplayState> va_display_state_; |
| 282 | 326 |
| 283 // VA handles. | 327 // VA handles. |
| 284 // All valid after successful Initialize() and until Deinitialize(). | 328 // All valid after successful Initialize() and until Deinitialize(). |
| 285 VADisplay va_display_; | 329 VADisplay va_display_; |
| 286 VAConfigID va_config_id_; | 330 VAConfigID va_config_id_; |
| 287 // Created for the current set of va_surface_ids_ in CreateSurfaces() and | 331 // Created for the current set of va_surface_ids_ in CreateSurfaces() and |
| 288 // valid until DestroySurfaces(). | 332 // valid until DestroySurfaces(). |
| 289 VAContextID va_context_id_; | 333 VAContextID va_context_id_; |
| 290 // True if vaInitialize has been called successfully. | |
| 291 bool va_initialized_; | |
| 292 | 334 |
| 293 // Data queued up for HW codec, to be committed on next execution. | 335 // Data queued up for HW codec, to be committed on next execution. |
| 294 std::vector<VABufferID> pending_slice_bufs_; | 336 std::vector<VABufferID> pending_slice_bufs_; |
| 295 std::vector<VABufferID> pending_va_bufs_; | 337 std::vector<VABufferID> pending_va_bufs_; |
| 296 | 338 |
| 297 // Bitstream buffers for encode. | 339 // Bitstream buffers for encode. |
| 298 std::set<VABufferID> coded_buffers_; | 340 std::set<VABufferID> coded_buffers_; |
| 299 | 341 |
| 300 // Called to report codec errors to UMA. Errors to clients are reported via | 342 // Called to report codec errors to UMA. Errors to clients are reported via |
| 301 // return values from public methods. | 343 // return values from public methods. |
| 302 base::Closure report_error_to_uma_cb_; | 344 base::Closure report_error_to_uma_cb_; |
| 303 | 345 |
| 304 // VPP (Video Post Processing) context, this is used to convert | 346 // VPP (Video Post Processing) context, this is used to convert |
| 305 // pictures used by the decoder to RGBA pictures usable by GL or the | 347 // pictures used by the decoder to RGBA pictures usable by GL or the |
| 306 // display hardware. | 348 // display hardware. |
| 307 VAConfigID va_vpp_config_id_; | 349 VAConfigID va_vpp_config_id_; |
| 308 VAContextID va_vpp_context_id_; | 350 VAContextID va_vpp_context_id_; |
| 309 VABufferID va_vpp_buffer_id_; | 351 VABufferID va_vpp_buffer_id_; |
| 310 | 352 |
| 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 | 353 // Singleton variable to store supported profile information for encode and |
| 317 // decode. | 354 // decode. |
| 318 static base::LazyInstance<LazyProfileInfos> profile_infos_; | 355 static base::LazyInstance<LazyProfileInfos> profile_infos_; |
| 319 | 356 |
| 320 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 357 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
| 321 }; | 358 }; |
| 322 | 359 |
| 323 } // namespace content | 360 } // namespace content |
| 324 | 361 |
| 325 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 362 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
| OLD | NEW |