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

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

Issue 490233002: VaapiVideoAccelerator: make Vaapi accelerator work with ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reenable Ozone path Created 6 years, 3 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_
11 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 11 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
12 12
13 #include <set> 13 #include <set>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
19 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
20 #include "content/common/gpu/media/va_surface.h" 19 #include "content/common/gpu/media/va_surface.h"
21 #include "media/base/video_decoder_config.h" 20 #include "media/base/video_decoder_config.h"
22 #include "media/base/video_frame.h" 21 #include "media/base/video_frame.h"
23 #include "third_party/libva/va/va_x11.h" 22 #include "third_party/libva/va/va.h"
24 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
25 24
26 namespace content { 25 namespace content {
27 26
28 // This class handles VA-API calls and ensures proper locking of VA-API calls 27 // This class handles VA-API calls and ensures proper locking of VA-API calls
29 // to libva, the userspace shim to the HW codec driver. libva is not 28 // to libva, the userspace shim to the HW codec driver. libva is not
30 // thread-safe, so we have to perform locking ourselves. This class is fully 29 // thread-safe, so we have to perform locking ourselves. This class is fully
31 // synchronous and its methods can be called from any thread and may wait on 30 // synchronous and its methods can be called from any thread and may wait on
32 // the va_lock_ while other, concurrent calls run. 31 // the va_lock_ while other, concurrent calls run.
33 // 32 //
34 // This class is responsible for managing VAAPI connection, contexts and state. 33 // This class is responsible for managing VAAPI connection, contexts and state.
35 // It is also responsible for managing and freeing VABuffers (not VASurfaces), 34 // It is also responsible for managing and freeing VABuffers (not VASurfaces),
36 // which are used to queue parameters and slice data to the HW codec, 35 // which are used to queue parameters and slice data to the HW codec,
37 // as well as underlying memory for VASurfaces themselves. 36 // as well as underlying memory for VASurfaces themselves.
38 class CONTENT_EXPORT VaapiWrapper { 37 class CONTENT_EXPORT VaapiWrapper {
39 public: 38 public:
40 enum CodecMode { 39 enum CodecMode {
41 kDecode, 40 kDecode,
42 kEncode, 41 kEncode,
43 }; 42 };
44 43
45 // |report_error_to_uma_cb| will be called independently from reporting 44 // |report_error_to_uma_cb| will be called independently from reporting
46 // errors to clients via method return values. 45 // errors to clients via method return values.
47 static scoped_ptr<VaapiWrapper> Create( 46 static scoped_ptr<VaapiWrapper> Create(
48 CodecMode mode, 47 CodecMode mode,
49 media::VideoCodecProfile profile, 48 media::VideoCodecProfile profile,
50 Display* x_display,
51 const base::Closure& report_error_to_uma_cb); 49 const base::Closure& report_error_to_uma_cb);
52 50
53 ~VaapiWrapper(); 51 ~VaapiWrapper();
54 52
55 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each 53 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each
56 // of size |size|. Returns true when successful, with the created IDs in 54 // of size |size|. Returns true when successful, with the created IDs in
57 // |va_surfaces| to be managed and later wrapped in VASurfaces. 55 // |va_surfaces| to be managed and later wrapped in VASurfaces.
58 // The client must DestroySurfaces() each time before calling this method 56 // The client must DestroySurfaces() each time before calling this method
59 // again to free the allocated surfaces first, but is not required to do so 57 // again to free the allocated surfaces first, but is not required to do so
60 // at destruction time, as this will be done automatically from 58 // at destruction time, as this will be done automatically from
61 // the destructor. 59 // the destructor.
62 bool CreateSurfaces(gfx::Size size, 60 bool CreateSurfaces(const gfx::Size& size,
63 size_t num_surfaces, 61 size_t num_surfaces,
64 std::vector<VASurfaceID>* va_surfaces); 62 std::vector<VASurfaceID>* va_surfaces);
65 63
66 // Free all memory allocated in CreateSurfaces. 64 // Free all memory allocated in CreateSurfaces.
67 void DestroySurfaces(); 65 void DestroySurfaces();
68 66
69 // Submit parameters or slice data of |va_buffer_type|, copying them from 67 // Submit parameters or slice data of |va_buffer_type|, copying them from
70 // |buffer| of size |size|, into HW codec. The data in |buffer| is no 68 // |buffer| of size |size|, into HW codec. The data in |buffer| is no
71 // longer needed and can be freed after this method returns. 69 // longer needed and can be freed after this method returns.
72 // Data submitted via this method awaits in the HW codec until 70 // Data submitted via this method awaits in the HW codec until
(...skipping 12 matching lines...) Expand all
85 void* buffer); 83 void* buffer);
86 84
87 // Cancel and destroy all buffers queued to the HW codec via SubmitBuffer(). 85 // Cancel and destroy all buffers queued to the HW codec via SubmitBuffer().
88 // Useful when a pending job is to be cancelled (on reset or error). 86 // Useful when a pending job is to be cancelled (on reset or error).
89 void DestroyPendingBuffers(); 87 void DestroyPendingBuffers();
90 88
91 // Execute job in hardware on target |va_surface_id| and destroy pending 89 // Execute job in hardware on target |va_surface_id| and destroy pending
92 // buffers. Return false if Execute() fails. 90 // buffers. Return false if Execute() fails.
93 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); 91 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id);
94 92
95 // Put data from |va_surface_id| into |x_pixmap| of size |size|, 93 // Put data from |va_surface_id| into |picture|, converting/scaling to it.
96 // converting/scaling to it. 94 /* bool PutSurfaceIntoPicture(VASurfaceID va_surface_id, Picture* picture); */
97 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
98 Pixmap x_pixmap,
99 gfx::Size dest_size);
100 95
101 // Returns true if the VAAPI version is less than the specified version. 96 // Returns true if the VAAPI version is less than the specified version.
102 bool VAAPIVersionLessThan(int major, int minor); 97 bool VAAPIVersionLessThan(int major, int minor);
103 98
104 // Get a VAImage from a VASurface and map it into memory. The VAImage should 99 // Get a VAImage from a VASurface and map it into memory. The VAImage should
105 // be released using the ReturnVaImage function. Returns true when successful. 100 // be released using the ReturnVaImage function. Returns true when successful.
106 // This is intended for testing only. 101 // This is intended for testing only.
107 bool GetVaImageForTesting(VASurfaceID va_surface_id, 102 bool GetVaImageForTesting(VASurfaceID va_surface_id,
108 VAImage* image, 103 VAImage* image,
109 void** mem); 104 void** mem);
(...skipping 17 matching lines...) Expand all
127 // to the encode job. 122 // to the encode job.
128 bool DownloadAndDestroyCodedBuffer(VABufferID buffer_id, 123 bool DownloadAndDestroyCodedBuffer(VABufferID buffer_id,
129 VASurfaceID sync_surface_id, 124 VASurfaceID sync_surface_id,
130 uint8* target_ptr, 125 uint8* target_ptr,
131 size_t target_size, 126 size_t target_size,
132 size_t* coded_data_size); 127 size_t* coded_data_size);
133 128
134 // Destroy all previously-allocated (and not yet destroyed) coded buffers. 129 // Destroy all previously-allocated (and not yet destroyed) coded buffers.
135 void DestroyCodedBuffers(); 130 void DestroyCodedBuffers();
136 131
132 // Returns the initialized VADisplay
133 VADisplay GetDisplay();
134
137 private: 135 private:
136
138 VaapiWrapper(); 137 VaapiWrapper();
139 138
140 bool Initialize(CodecMode mode, 139 bool Initialize(VADisplay display,
140 CodecMode mode,
141 media::VideoCodecProfile profile, 141 media::VideoCodecProfile profile,
142 Display* x_display,
143 const base::Closure& report_error__to_uma_cb); 142 const base::Closure& report_error__to_uma_cb);
144 void Deinitialize(); 143 void Deinitialize();
145 144
146 // Execute pending job in hardware and destroy pending buffers. Return false 145 // Execute pending job in hardware and destroy pending buffers. Return false
147 // if vaapi driver refuses to accept parameter or slice buffers submitted 146 // if vaapi driver refuses to accept parameter or slice buffers submitted
148 // by client, or if execution fails in hardware. 147 // by client, or if execution fails in hardware.
149 bool Execute(VASurfaceID va_surface_id); 148 bool Execute(VASurfaceID va_surface_id);
150 149
151 // Attempt to set render mode to "render to texture.". Failure is non-fatal. 150 // Attempt to set render mode to "render to texture.". Failure is non-fatal.
152 void TryToSetVADisplayAttributeToLocalGPU(); 151 void TryToSetVADisplayAttributeToLocalGPU();
153 152
154 // Lazily initialize static data after sandbox is enabled. Return false on 153 // Lazily initialize static data after sandbox is enabled. Return false on
155 // init failure. 154 // init failure.
156 static bool PostSandboxInitialization(); 155 static bool PostSandboxInitialization();
157 156
158 // Libva is not thread safe, so we have to do locking for it ourselves. 157 // Libva is not thread safe, so we have to do locking for it ourselves.
159 // This lock is to be taken for the duration of all VA-API calls and for 158 // This lock is to be taken for the duration of all VA-API calls and for
160 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). 159 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers().
161 base::Lock va_lock_; 160 base::Lock va_lock_;
162 161
163 // Allocated ids for VASurfaces. 162 // Allocated ids for VASurfaces.
164 std::vector<VASurfaceID> va_surface_ids_; 163 std::vector<VASurfaceID> va_surface_ids_;
165 164
166 // The VAAPI version. 165 // The VAAPI version.
167 int major_version_, minor_version_; 166 int major_version_, minor_version_;
168 167
169 // VA handles. 168 // VA handles.
170 // Both valid after successful Initialize() and until Deinitialize(). 169 // All valid after successful Initialize() and until Deinitialize().
171 VADisplay va_display_; 170 VADisplay va_display_;
172 VAConfigID va_config_id_; 171 VAConfigID va_config_id_;
173 // Created for the current set of va_surface_ids_ in CreateSurfaces() and 172 // Created for the current set of va_surface_ids_ in CreateSurfaces() and
174 // valid until DestroySurfaces(). 173 // valid until DestroySurfaces().
175 VAContextID va_context_id_; 174 VAContextID va_context_id_;
176 175
177 // Data queued up for HW codec, to be committed on next execution. 176 // Data queued up for HW codec, to be committed on next execution.
178 std::vector<VABufferID> pending_slice_bufs_; 177 std::vector<VABufferID> pending_slice_bufs_;
179 std::vector<VABufferID> pending_va_bufs_; 178 std::vector<VABufferID> pending_va_bufs_;
180 179
181 // Bitstream buffers for encode. 180 // Bitstream buffers for encode.
182 std::set<VABufferID> coded_buffers_; 181 std::set<VABufferID> coded_buffers_;
183 182
184 // Called to report codec errors to UMA. Errors to clients are reported via 183 // Called to report codec errors to UMA. Errors to clients are reported via
185 // return values from public methods. 184 // return values from public methods.
186 base::Closure report_error_to_uma_cb_; 185 base::Closure report_error_to_uma_cb_;
187 186
188 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 187 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
189 }; 188 };
190 189
191 } // namespace content 190 } // namespace content
192 191
193 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 192 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698