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

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

Issue 2668813002: Remove LazyInstance usage from media/ (Closed)
Patch Set: Fix presubmit comments. Created 3 years, 10 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
« no previous file with comments | « media/gpu/tegra_v4l2_device.cc ('k') | media/gpu/vaapi_wrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 MEDIA_GPU_VAAPI_WRAPPER_H_ 10 #ifndef MEDIA_GPU_VAAPI_WRAPPER_H_
11 #define MEDIA_GPU_VAAPI_WRAPPER_H_ 11 #define MEDIA_GPU_VAAPI_WRAPPER_H_
12 12
13 #include <stddef.h> 13 #include <stddef.h>
14 #include <stdint.h> 14 #include <stdint.h>
15 15
16 #include <set> 16 #include <set>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/files/file.h" 19 #include "base/files/file.h"
20 #include "base/lazy_instance.h"
21 #include "base/macros.h" 20 #include "base/macros.h"
22 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
23 #include "base/synchronization/lock.h" 22 #include "base/synchronization/lock.h"
24 #include "media/base/video_decoder_config.h" 23 #include "media/base/video_decoder_config.h"
25 #include "media/base/video_frame.h" 24 #include "media/base/video_frame.h"
26 #include "media/gpu/media_gpu_export.h" 25 #include "media/gpu/media_gpu_export.h"
27 #include "media/gpu/va_surface.h" 26 #include "media/gpu/va_surface.h"
28 #include "media/video/jpeg_decode_accelerator.h" 27 #include "media/video/jpeg_decode_accelerator.h"
29 #include "media/video/video_decode_accelerator.h" 28 #include "media/video/video_decode_accelerator.h"
30 #include "media/video/video_encode_accelerator.h" 29 #include "media/video/video_encode_accelerator.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 void Deinitialize(VAStatus* status); 249 void Deinitialize(VAStatus* status);
251 250
252 base::Lock* va_lock() { return &va_lock_; } 251 base::Lock* va_lock() { return &va_lock_; }
253 VADisplay va_display() const { return va_display_; } 252 VADisplay va_display() const { return va_display_; }
254 253
255 #if defined(USE_OZONE) 254 #if defined(USE_OZONE)
256 void SetDrmFd(base::PlatformFile fd); 255 void SetDrmFd(base::PlatformFile fd);
257 #endif // USE_OZONE 256 #endif // USE_OZONE
258 257
259 private: 258 private:
260 friend class base::LazyInstance<VADisplayState>;
261
262 // Returns true if the VAAPI version is less than the specified version. 259 // Returns true if the VAAPI version is less than the specified version.
263 bool VAAPIVersionLessThan(int major, int minor); 260 bool VAAPIVersionLessThan(int major, int minor);
264 261
265 // Protected by |va_lock_|. 262 // Protected by |va_lock_|.
266 int refcount_; 263 int refcount_;
267 264
268 // Libva is not thread safe, so we have to do locking for it ourselves. 265 // Libva is not thread safe, so we have to do locking for it ourselves.
269 // This lock is to be taken for the duration of all VA-API calls and for 266 // This lock is to be taken for the duration of all VA-API calls and for
270 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). 267 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers().
271 base::Lock va_lock_; 268 base::Lock va_lock_;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Lazily initialize static data after sandbox is enabled. Return false on 335 // Lazily initialize static data after sandbox is enabled. Return false on
339 // init failure. 336 // init failure.
340 static bool PostSandboxInitialization(); 337 static bool PostSandboxInitialization();
341 338
342 // Map VideoCodecProfile enum values to VaProfile values. This function 339 // Map VideoCodecProfile enum values to VaProfile values. This function
343 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline 340 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline
344 // and it is not supported, we try constrained baseline. 341 // and it is not supported, we try constrained baseline.
345 static VAProfile ProfileToVAProfile(VideoCodecProfile profile, 342 static VAProfile ProfileToVAProfile(VideoCodecProfile profile,
346 CodecMode mode); 343 CodecMode mode);
347 344
345 // Singleton accessors.
346 static VADisplayState* GetDisplayState();
347 static LazyProfileInfos* GetProfileInfos();
348
348 // Pointer to VADisplayState's member |va_lock_|. Guaranteed to be valid for 349 // Pointer to VADisplayState's member |va_lock_|. Guaranteed to be valid for
349 // the lifetime of VaapiWrapper. 350 // the lifetime of VaapiWrapper.
350 base::Lock* va_lock_; 351 base::Lock* va_lock_;
351 352
352 // Allocated ids for VASurfaces. 353 // Allocated ids for VASurfaces.
353 std::vector<VASurfaceID> va_surface_ids_; 354 std::vector<VASurfaceID> va_surface_ids_;
354 355
355 // VA format of surfaces with va_surface_ids_. 356 // VA format of surfaces with va_surface_ids_.
356 unsigned int va_surface_format_; 357 unsigned int va_surface_format_;
357 358
358 // Singleton instance of VADisplayState.
359 static base::LazyInstance<VADisplayState> va_display_state_;
360
361 // VA handles. 359 // VA handles.
362 // All valid after successful Initialize() and until Deinitialize(). 360 // All valid after successful Initialize() and until Deinitialize().
363 VADisplay va_display_; 361 VADisplay va_display_;
364 VAConfigID va_config_id_; 362 VAConfigID va_config_id_;
365 // Created for the current set of va_surface_ids_ in CreateSurfaces() and 363 // Created for the current set of va_surface_ids_ in CreateSurfaces() and
366 // valid until DestroySurfaces(). 364 // valid until DestroySurfaces().
367 VAContextID va_context_id_; 365 VAContextID va_context_id_;
368 366
369 // Data queued up for HW codec, to be committed on next execution. 367 // Data queued up for HW codec, to be committed on next execution.
370 std::vector<VABufferID> pending_slice_bufs_; 368 std::vector<VABufferID> pending_slice_bufs_;
371 std::vector<VABufferID> pending_va_bufs_; 369 std::vector<VABufferID> pending_va_bufs_;
372 370
373 // Bitstream buffers for encode. 371 // Bitstream buffers for encode.
374 std::set<VABufferID> coded_buffers_; 372 std::set<VABufferID> coded_buffers_;
375 373
376 // Called to report codec errors to UMA. Errors to clients are reported via 374 // Called to report codec errors to UMA. Errors to clients are reported via
377 // return values from public methods. 375 // return values from public methods.
378 base::Closure report_error_to_uma_cb_; 376 base::Closure report_error_to_uma_cb_;
379 377
380 // VPP (Video Post Processing) context, this is used to convert 378 // VPP (Video Post Processing) context, this is used to convert
381 // pictures used by the decoder to RGBA pictures usable by GL or the 379 // pictures used by the decoder to RGBA pictures usable by GL or the
382 // display hardware. 380 // display hardware.
383 VAConfigID va_vpp_config_id_; 381 VAConfigID va_vpp_config_id_;
384 VAContextID va_vpp_context_id_; 382 VAContextID va_vpp_context_id_;
385 VABufferID va_vpp_buffer_id_; 383 VABufferID va_vpp_buffer_id_;
386 384
387 // Singleton variable to store supported profile information for encode and
388 // decode.
389 static base::LazyInstance<LazyProfileInfos> profile_infos_;
390
391 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 385 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
392 }; 386 };
393 387
394 } // namespace media 388 } // namespace media
395 389
396 #endif // MEDIA_GPU_VAAPI_WRAPPER_H_ 390 #endif // MEDIA_GPU_VAAPI_WRAPPER_H_
OLDNEW
« no previous file with comments | « media/gpu/tegra_v4l2_device.cc ('k') | media/gpu/vaapi_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698