Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: content/common/gpu/media/vaapi_wrapper.h

Issue 1137483002: VAAPI Wrapper: refactor management of drm file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move va_lock_ into VADisplayState and ensure its validity for lifetime of VaapiWrapper. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_; }
223
224 #if defined(USE_OZONE)
225 void SetDrmFd(base::PlatformFile fd);
226 #endif // USE_OZONE
227
228 private:
229 #if defined(USE_OZONE)
230 friend class base::LazyInstance<VADisplayState>;
231 #endif // USE_OZONE
232
233 // Returns true if the VAAPI version is less than the specified version.
234 bool VAAPIVersionLessThan(int major, int minor);
235
236 int refcount_;
237
238 // Libva is not thread safe, so we have to do locking for it ourselves.
239 // This lock is to be taken for the duration of all VA-API calls and for
240 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers().
241 base::Lock va_lock_;
242
243 #if defined(USE_OZONE)
244 // Drm fd used to obtain access to the driver interface by VA.
245 base::ScopedFD drm_fd_;
246 #endif // USE_OZONE
247
248 // The VADisplay handle.
249 VADisplay va_display_;
250
251 // The VAAPI version.
252 int major_version_, minor_version_;
253
254 // True if vaInitialize has been called successfully.
255 bool va_initialized_;
256 };
257
212 VaapiWrapper(); 258 VaapiWrapper();
213 259
214 bool Initialize(CodecMode mode, VAProfile va_profile); 260 bool Initialize(CodecMode mode, VAProfile va_profile);
215 void Deinitialize(); 261 void Deinitialize();
216 bool VaInitialize(const base::Closure& report_error_to_uma_cb); 262 bool VaInitialize(const base::Closure& report_error_to_uma_cb);
217 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); 263 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles);
218 264
219 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be 265 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be
220 // held on entry. 266 // held on entry.
221 bool IsEntrypointSupported_Locked(VAProfile va_profile, 267 bool IsEntrypointSupported_Locked(VAProfile va_profile,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Lazily initialize static data after sandbox is enabled. Return false on 308 // Lazily initialize static data after sandbox is enabled. Return false on
263 // init failure. 309 // init failure.
264 static bool PostSandboxInitialization(); 310 static bool PostSandboxInitialization();
265 311
266 // Map VideoCodecProfile enum values to VaProfile values. This function 312 // Map VideoCodecProfile enum values to VaProfile values. This function
267 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline 313 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline
268 // and it is not supported, we try constrained baseline. 314 // and it is not supported, we try constrained baseline.
269 static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile, 315 static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile,
270 CodecMode mode); 316 CodecMode mode);
271 317
272 // Libva is not thread safe, so we have to do locking for it ourselves. 318 // 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 319 // the lifetime of VaapiWrapper.
274 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). 320 base::Lock* va_lock_;
275 base::Lock va_lock_;
276 321
277 // Allocated ids for VASurfaces. 322 // Allocated ids for VASurfaces.
278 std::vector<VASurfaceID> va_surface_ids_; 323 std::vector<VASurfaceID> va_surface_ids_;
279 324
280 // The VAAPI version. 325 #if defined(USE_X11)
281 int major_version_, minor_version_; 326 // VADisplay and related state.
327 scoped_ptr<VADisplayState> va_display_state_;
piman 2015/05/11 21:54:07 Why does it have to be different between X11 and O
hshi1 2015/05/11 22:26:40 Done.
328 #elif defined(USE_OZONE)
329 // Singleton instance of VADisplayState.
330 static base::LazyInstance<VADisplayState> g_va_display_state_;
331 #endif // USE_X11
282 332
283 // VA handles. 333 // VA handles.
284 // All valid after successful Initialize() and until Deinitialize(). 334 // All valid after successful Initialize() and until Deinitialize().
285 VADisplay va_display_; 335 VADisplay va_display_;
286 VAConfigID va_config_id_; 336 VAConfigID va_config_id_;
287 // Created for the current set of va_surface_ids_ in CreateSurfaces() and 337 // Created for the current set of va_surface_ids_ in CreateSurfaces() and
288 // valid until DestroySurfaces(). 338 // valid until DestroySurfaces().
289 VAContextID va_context_id_; 339 VAContextID va_context_id_;
290 // True if vaInitialize has been called successfully.
291 bool va_initialized_;
292 340
293 // Data queued up for HW codec, to be committed on next execution. 341 // Data queued up for HW codec, to be committed on next execution.
294 std::vector<VABufferID> pending_slice_bufs_; 342 std::vector<VABufferID> pending_slice_bufs_;
295 std::vector<VABufferID> pending_va_bufs_; 343 std::vector<VABufferID> pending_va_bufs_;
296 344
297 // Bitstream buffers for encode. 345 // Bitstream buffers for encode.
298 std::set<VABufferID> coded_buffers_; 346 std::set<VABufferID> coded_buffers_;
299 347
300 // Called to report codec errors to UMA. Errors to clients are reported via 348 // Called to report codec errors to UMA. Errors to clients are reported via
301 // return values from public methods. 349 // return values from public methods.
302 base::Closure report_error_to_uma_cb_; 350 base::Closure report_error_to_uma_cb_;
303 351
304 // VPP (Video Post Processing) context, this is used to convert 352 // VPP (Video Post Processing) context, this is used to convert
305 // pictures used by the decoder to RGBA pictures usable by GL or the 353 // pictures used by the decoder to RGBA pictures usable by GL or the
306 // display hardware. 354 // display hardware.
307 VAConfigID va_vpp_config_id_; 355 VAConfigID va_vpp_config_id_;
308 VAContextID va_vpp_context_id_; 356 VAContextID va_vpp_context_id_;
309 VABufferID va_vpp_buffer_id_; 357 VABufferID va_vpp_buffer_id_;
310 358
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 359 // Singleton variable to store supported profile information for encode and
317 // decode. 360 // decode.
318 static base::LazyInstance<LazyProfileInfos> profile_infos_; 361 static base::LazyInstance<LazyProfileInfos> profile_infos_;
319 362
320 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 363 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
321 }; 364 };
322 365
323 } // namespace content 366 } // namespace content
324 367
325 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 368 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/media/vaapi_wrapper.cc » ('j') | content/common/gpu/media/vaapi_wrapper.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698