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

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

Issue 14914009: VAVDA: Redesign stage 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add CONTENT_EXPORT to VaapiWrapper Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // This file contains an implementation of VaapiWrapper, used by
6 // VaapiVideoDecodeAccelerator and VaapiH264Decoder to interface
7 // with libva (VA-API library for hardware video decode).
8
9 #ifndef CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
10 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
11
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/synchronization/lock.h"
15 #include "content/common/content_export.h"
16 #include "content/common/gpu/media/va_surface.h"
17 #include "media/base/video_decoder_config.h"
18 #include "third_party/libva/va/va.h"
19 #include "third_party/libva/va/va_x11.h"
20 #include "ui/gfx/size.h"
21
22 namespace content {
23
24 // This class handles VA-API calls and ensures proper locking of VA-API calls
25 // to libva, the userspace shim to the HW decoder driver. libva is not
26 // thread-safe, so we have to perform locking ourselves. This class is fully
27 // synchronous and its methods can be called from any thread and may wait on
28 // the va_lock_ while other, concurrent calls run.
29 //
30 // This class is responsible for managing VAAPI connection, contexts and state.
31 // It is also responsible for managing and freeing VABuffers (not VASurfaces),
32 // which are used to queue decode parameters and slice data to the HW decoder,
33 // as well as underlying memory for VASurfaces themselves.
34 class CONTENT_EXPORT VaapiWrapper {
35 public:
36 // |report_error_to_uma_cb| will be called independently from reporting
37 // errors to clients via method return values.
38 static scoped_ptr<VaapiWrapper> Create(
39 media::VideoCodecProfile profile,
40 Display* x_display,
41 const base::Closure& report_error_to_uma_cb);
42
43 ~VaapiWrapper();
44
45 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each
46 // of size |size|. Returns true when successful, with the created IDs in
47 // |va_surfaces| to be managed and later wrapped in VASurfaces.
48 // The client must DestroySurfaces() each time before calling this method
49 // again to free the allocated surfaces first, but is not required to do so
50 // at destruction time, as this will be done automatically from
51 // the destructor.
52 bool CreateSurfaces(gfx::Size size,
53 size_t num_surfaces,
54 std::vector<VASurfaceID>* va_surfaces);
55
56 // Free all memory allocated in CreateSurfaces.
57 void DestroySurfaces();
58
59 // Submit parameters or slice data of |va_buffer_type|, copying them from
60 // |buffer| of size |size|, into HW decoder. The data in |buffer| is no
61 // longer needed and can be freed after this method returns.
62 // Data submitted via this method awaits in the HW decoder until
63 // DecodeAndDestroyPendingBuffers is called to execute or
64 // DestroyPendingBuffers is used to cancel a pending decode.
65 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer);
66
67 // Cancel and destroy all buffers queued to the HW decoder via SubmitBuffer.
68 // Useful when a pending decode is to be cancelled (on reset or error).
69 void DestroyPendingBuffers();
70
71 // Execute decode in hardware into |va_surface_id} and destroy pending
72 // buffers. Return false if SubmitDecode() fails.
73 bool DecodeAndDestroyPendingBuffers(VASurfaceID va_surface_id);
74
75 // Put data from |va_surface_id| into |x_pixmap| of size |size|,
76 // converting/scaling to it.
77 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
78 Pixmap x_pixmap,
79 gfx::Size dest_size);
80
81 // Do any necessary initialization before the sandbox is enabled.
82 static void PreSandboxInitialization();
83
84 private:
85 VaapiWrapper();
86
87 bool Initialize(media::VideoCodecProfile profile,
88 Display* x_display,
89 const base::Closure& report_error__to_uma_cb);
90 void Deinitialize();
91
92 // Execute decode in hardware and destroy pending buffers. Return false if
93 // vaapi driver refuses to accept parameter or slice buffers submitted
94 // by client or if decode fails in hardware.
95 bool SubmitDecode(VASurfaceID va_surface_id);
96
97 // Lazily initialize static data after sandbox is enabled. Return false on
98 // init failure.
99 static bool PostSandboxInitialization();
100
101 // Libva is not thread safe, so we have to do locking for it ourselves.
102 // This lock is to be taken for the duration of all VA-API calls and for
103 // the entire decode execution sequence in DecodeAndDestroyPendingBuffers().
104 base::Lock va_lock_;
105
106 // Allocated ids for VASurfaces.
107 std::vector<VASurfaceID> va_surface_ids_;
108
109 // VA handles.
110 // Both valid after successful Initialize() and until Deinitialize().
111 VADisplay va_display_;
112 VAConfigID va_config_id_;
113 // Created for the current set of va_surface_ids_ in CreateSurfaces() and
114 // valid until DestroySurfaces().
115 VAContextID va_context_id_;
116
117 // Data queued up for HW decoder, to be committed on next HW decode.
118 std::vector<VABufferID> pending_slice_bufs_;
119 std::vector<VABufferID> pending_va_bufs_;
120
121 // Called to report decoding errors to UMA. Errors to clients are reported via
122 // return values from public methods.
123 base::Closure report_error_to_uma_cb_;
124
125 // Has static initialization of pre-sandbox components completed successfully?
126 static bool pre_sandbox_init_done_;
127
128 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
129 };
130
131 } // namespace content
132
133 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_video_decode_accelerator.cc ('k') | content/common/gpu/media/vaapi_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698