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

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

Issue 825163004: Add Vaapi support on Ozone/Freon (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 5 years, 12 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/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
19 #include "content/common/gpu/media/va_surface.h" 19 #include "content/common/gpu/media/va_surface.h"
20 #include "media/base/video_decoder_config.h" 20 #include "media/base/video_decoder_config.h"
21 #include "media/base/video_frame.h" 21 #include "media/base/video_frame.h"
22 #include "third_party/libva/va/va.h" 22 #include "third_party/libva/va/va.h"
23 #include "third_party/libva/va/va_vpp.h"
23 #include "ui/gfx/size.h" 24 #include "ui/gfx/size.h"
24 #if defined(USE_X11) 25 #if defined(USE_X11)
25 #include "third_party/libva/va/va_x11.h" 26 #include "third_party/libva/va/va_x11.h"
26 #endif // USE_X11 27 #endif // USE_X11
27 28
28 namespace content { 29 namespace content {
29 30
30 // This class handles VA-API calls and ensures proper locking of VA-API calls 31 // This class handles VA-API calls and ensures proper locking of VA-API calls
31 // to libva, the userspace shim to the HW codec driver. libva is not 32 // to libva, the userspace shim to the HW codec driver. libva is not
32 // thread-safe, so we have to perform locking ourselves. This class is fully 33 // thread-safe, so we have to perform locking ourselves. This class is fully
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // again to free the allocated surfaces first, but is not required to do so 65 // again to free the allocated surfaces first, but is not required to do so
65 // at destruction time, as this will be done automatically from 66 // at destruction time, as this will be done automatically from
66 // the destructor. 67 // the destructor.
67 bool CreateSurfaces(const gfx::Size& size, 68 bool CreateSurfaces(const gfx::Size& size,
68 size_t num_surfaces, 69 size_t num_surfaces,
69 std::vector<VASurfaceID>* va_surfaces); 70 std::vector<VASurfaceID>* va_surfaces);
70 71
71 // Free all memory allocated in CreateSurfaces. 72 // Free all memory allocated in CreateSurfaces.
72 void DestroySurfaces(); 73 void DestroySurfaces();
73 74
75 // Create a VASurface of |va_format|, |size| and using
76 // |num_va_attribs| attributes from |va_attribs|. The ownership of
77 // the surface is transfered to the caller. It differs from surfaces
Pawel Osciak 2014/12/26 00:38:56 s/transfered/transferred/
llandwerlin-old 2014/12/26 02:50:02 Done.
78 // created using CreateSurfaces() where VaapiWrapper is the owner of
Pawel Osciak 2014/12/26 00:38:56 s/()/(),/
llandwerlin-old 2014/12/26 02:50:02 Done.
79 // the surfaces.
80 scoped_refptr<VASurface> CreateUnownedSurface(unsigned int va_format,
Pawel Osciak 2014/12/26 00:38:56 Should we also be passing va_format to CreateSurfa
llandwerlin-old 2014/12/26 02:50:02 Surfaces used by the decoder/encoder are assumed t
81 const gfx::Size& size,
82 VASurfaceAttrib* va_attribs,
Pawel Osciak 2014/12/26 00:38:56 Could we instead pass a vector, remove num_va_attr
llandwerlin-old 2014/12/26 02:50:02 Done.
83 size_t num_va_attribs);
84
74 // Submit parameters or slice data of |va_buffer_type|, copying them from 85 // Submit parameters or slice data of |va_buffer_type|, copying them from
75 // |buffer| of size |size|, into HW codec. The data in |buffer| is no 86 // |buffer| of size |size|, into HW codec. The data in |buffer| is no
76 // longer needed and can be freed after this method returns. 87 // longer needed and can be freed after this method returns.
77 // Data submitted via this method awaits in the HW codec until 88 // Data submitted via this method awaits in the HW codec until
78 // ExecuteAndDestroyPendingBuffers() is called to execute or 89 // ExecuteAndDestroyPendingBuffers() is called to execute or
79 // DestroyPendingBuffers() is used to cancel a pending job. 90 // DestroyPendingBuffers() is used to cancel a pending job.
80 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); 91 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer);
81 92
82 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its 93 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its
83 // data from |buffer| of size |size|, into HW codec. The data in |buffer| is 94 // data from |buffer| of size |size|, into HW codec. The data in |buffer| is
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // to the encode job. 145 // to the encode job.
135 bool DownloadAndDestroyCodedBuffer(VABufferID buffer_id, 146 bool DownloadAndDestroyCodedBuffer(VABufferID buffer_id,
136 VASurfaceID sync_surface_id, 147 VASurfaceID sync_surface_id,
137 uint8* target_ptr, 148 uint8* target_ptr,
138 size_t target_size, 149 size_t target_size,
139 size_t* coded_data_size); 150 size_t* coded_data_size);
140 151
141 // Destroy all previously-allocated (and not yet destroyed) coded buffers. 152 // Destroy all previously-allocated (and not yet destroyed) coded buffers.
142 void DestroyCodedBuffers(); 153 void DestroyCodedBuffers();
143 154
155 // Blits a VASurface |va_surface_id_src| into another VASurface
156 // |va_surface_id_dest| applying pixel format conversion and scaling
157 // if needed.
158 bool BlitSurface(VASurfaceID va_surface_id_src,
159 const gfx::Size& src_size,
160 VASurfaceID va_surface_id_dest,
161 const gfx::Size& dest_size);
162
144 private: 163 private:
145 VaapiWrapper(); 164 VaapiWrapper();
146 165
147 bool Initialize(CodecMode mode, 166 bool Initialize(CodecMode mode,
148 media::VideoCodecProfile profile, 167 media::VideoCodecProfile profile,
149 const base::Closure& report_error__to_uma_cb); 168 const base::Closure& report_error__to_uma_cb);
150 void Deinitialize(); 169 void Deinitialize();
151 bool VaInitialize(const base::Closure& report_error_to_uma_cb); 170 bool VaInitialize(const base::Closure& report_error_to_uma_cb);
152 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); 171 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles);
153 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); 172 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint);
154 bool AreAttribsSupported(VAProfile va_profile, 173 bool AreAttribsSupported(VAProfile va_profile,
155 VAEntrypoint entrypoint, 174 VAEntrypoint entrypoint,
156 const std::vector<VAConfigAttrib>& required_attribs); 175 const std::vector<VAConfigAttrib>& required_attribs);
157 176
177 // Destroys a |va_surface| created using CreateUnownedSurface.
178 void DestroyUnownedSurface(VASurfaceID va_surface);
Pawel Osciak 2014/12/26 00:38:56 s/va_surface/va_surface_id/
llandwerlin-old 2014/12/26 02:50:02 Done.
179
180 // Initialize the video post processing context with the |size| of
181 // the input pictures to be processed.
182 bool InitializeVpp_Locked();
183
184 // Deinitialize the video post processing context.
185 void DeinitializeVpp();
186
158 // Execute pending job in hardware and destroy pending buffers. Return false 187 // Execute pending job in hardware and destroy pending buffers. Return false
159 // if vaapi driver refuses to accept parameter or slice buffers submitted 188 // if vaapi driver refuses to accept parameter or slice buffers submitted
160 // by client, or if execution fails in hardware. 189 // by client, or if execution fails in hardware.
161 bool Execute(VASurfaceID va_surface_id); 190 bool Execute(VASurfaceID va_surface_id);
162 191
163 // Attempt to set render mode to "render to texture.". Failure is non-fatal. 192 // Attempt to set render mode to "render to texture.". Failure is non-fatal.
164 void TryToSetVADisplayAttributeToLocalGPU(); 193 void TryToSetVADisplayAttributeToLocalGPU();
165 194
166 // Lazily initialize static data after sandbox is enabled. Return false on 195 // Lazily initialize static data after sandbox is enabled. Return false on
167 // init failure. 196 // init failure.
(...skipping 24 matching lines...) Expand all
192 std::vector<VABufferID> pending_slice_bufs_; 221 std::vector<VABufferID> pending_slice_bufs_;
193 std::vector<VABufferID> pending_va_bufs_; 222 std::vector<VABufferID> pending_va_bufs_;
194 223
195 // Bitstream buffers for encode. 224 // Bitstream buffers for encode.
196 std::set<VABufferID> coded_buffers_; 225 std::set<VABufferID> coded_buffers_;
197 226
198 // Called to report codec errors to UMA. Errors to clients are reported via 227 // Called to report codec errors to UMA. Errors to clients are reported via
199 // return values from public methods. 228 // return values from public methods.
200 base::Closure report_error_to_uma_cb_; 229 base::Closure report_error_to_uma_cb_;
201 230
231 // VPP context
Pawel Osciak 2014/12/26 00:38:56 Please describe what VPP is and what it is used fo
llandwerlin-old 2014/12/26 02:50:02 Done.
232 VAConfigID va_vpp_config_id_;
233 VAContextID va_vpp_context_id_;
234 VABufferID va_vpp_buffer_id_;
235
202 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 236 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
203 }; 237 };
204 238
205 } // namespace content 239 } // namespace content
206 240
207 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 241 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698