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

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

Issue 872623002: VaapiVEA: Get maximum resolution from libva (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 5 years, 9 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/lazy_instance.h"
16 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
17 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
18 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
19 #include "content/common/gpu/media/va_surface.h" 20 #include "content/common/gpu/media/va_surface.h"
20 #include "media/base/video_decoder_config.h" 21 #include "media/base/video_decoder_config.h"
21 #include "media/base/video_frame.h" 22 #include "media/base/video_frame.h"
23 #include "media/video/video_encode_accelerator.h"
22 #include "third_party/libva/va/va.h" 24 #include "third_party/libva/va/va.h"
23 #include "third_party/libva/va/va_vpp.h" 25 #include "third_party/libva/va/va_vpp.h"
24 #include "ui/gfx/geometry/size.h" 26 #include "ui/gfx/geometry/size.h"
25 #if defined(USE_X11) 27 #if defined(USE_X11)
26 #include "third_party/libva/va/va_x11.h" 28 #include "third_party/libva/va/va_x11.h"
27 #endif // USE_X11 29 #endif // USE_X11
28 30
29 namespace content { 31 namespace content {
30 32
31 // This class handles VA-API calls and ensures proper locking of VA-API calls 33 // This class handles VA-API calls and ensures proper locking of VA-API calls
32 // to libva, the userspace shim to the HW codec driver. libva is not 34 // to libva, the userspace shim to the HW codec driver. libva is not
33 // thread-safe, so we have to perform locking ourselves. This class is fully 35 // thread-safe, so we have to perform locking ourselves. This class is fully
34 // synchronous and its methods can be called from any thread and may wait on 36 // synchronous and its methods can be called from any thread and may wait on
35 // the va_lock_ while other, concurrent calls run. 37 // the va_lock_ while other, concurrent calls run.
36 // 38 //
37 // This class is responsible for managing VAAPI connection, contexts and state. 39 // This class is responsible for managing VAAPI connection, contexts and state.
38 // It is also responsible for managing and freeing VABuffers (not VASurfaces), 40 // It is also responsible for managing and freeing VABuffers (not VASurfaces),
39 // which are used to queue parameters and slice data to the HW codec, 41 // which are used to queue parameters and slice data to the HW codec,
40 // as well as underlying memory for VASurfaces themselves. 42 // as well as underlying memory for VASurfaces themselves.
41 class CONTENT_EXPORT VaapiWrapper { 43 class CONTENT_EXPORT VaapiWrapper {
42 public: 44 public:
43 enum CodecMode { 45 enum CodecMode {
44 kDecode, 46 kDecode,
45 kEncode, 47 kEncode,
48 kCodecModeMax,
46 }; 49 };
47 50
48 // Create VaapiWrapper for VAProfile. 51 // Return an instance of VaapiWrapper initialized for |va_profile| and
49 // |report_error_to_uma_cb| will be called independently from reporting 52 // |mode|. |report_error_to_uma_cb| will be called independently from
50 // errors to clients via method return values. 53 // reporting errors to clients via method return values.
51 static scoped_ptr<VaapiWrapper> Create( 54 static scoped_ptr<VaapiWrapper> Create(
52 CodecMode mode, 55 CodecMode mode,
53 VAProfile profile, 56 VAProfile va_profile,
54 const base::Closure& report_error_to_uma_cb); 57 const base::Closure& report_error_to_uma_cb);
55 58
56 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile 59 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile
57 // |profile| to VAProfile. 60 // |profile| to VAProfile.
58 // |report_error_to_uma_cb| will be called independently from reporting 61 // |report_error_to_uma_cb| will be called independently from reporting
59 // errors to clients via method return values. 62 // errors to clients via method return values.
60 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( 63 static scoped_ptr<VaapiWrapper> CreateForVideoCodec(
61 CodecMode mode, 64 CodecMode mode,
62 media::VideoCodecProfile profile, 65 media::VideoCodecProfile profile,
63 const base::Closure& report_error_to_uma_cb); 66 const base::Closure& report_error_to_uma_cb);
64 67
65 // Return the supported encode profiles. 68 // Return the supported encode profiles.
66 static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( 69 static std::vector<media::VideoEncodeAccelerator::SupportedProfile>
67 const base::Closure& report_error_to_uma_cb); 70 GetSupportedEncodeProfiles();
68 71
69 ~VaapiWrapper(); 72 ~VaapiWrapper();
70 73
71 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each 74 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each
72 // of size |size|. Returns true when successful, with the created IDs in 75 // of size |size|. Returns true when successful, with the created IDs in
73 // |va_surfaces| to be managed and later wrapped in VASurfaces. 76 // |va_surfaces| to be managed and later wrapped in VASurfaces.
74 // The client must DestroySurfaces() each time before calling this method 77 // The client must DestroySurfaces() each time before calling this method
75 // again to free the allocated surfaces first, but is not required to do so 78 // again to free the allocated surfaces first, but is not required to do so
76 // at destruction time, as this will be done automatically from 79 // at destruction time, as this will be done automatically from
77 // the destructor. 80 // the destructor.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 179
177 // Blits a VASurface |va_surface_id_src| into another VASurface 180 // Blits a VASurface |va_surface_id_src| into another VASurface
178 // |va_surface_id_dest| applying pixel format conversion and scaling 181 // |va_surface_id_dest| applying pixel format conversion and scaling
179 // if needed. 182 // if needed.
180 bool BlitSurface(VASurfaceID va_surface_id_src, 183 bool BlitSurface(VASurfaceID va_surface_id_src,
181 const gfx::Size& src_size, 184 const gfx::Size& src_size,
182 VASurfaceID va_surface_id_dest, 185 VASurfaceID va_surface_id_dest,
183 const gfx::Size& dest_size); 186 const gfx::Size& dest_size);
184 187
185 private: 188 private:
189 struct ProfileInfo {
190 VAProfile va_profile;
191 gfx::Size max_resolution;
192 };
193
194 class LazyProfileInfos {
195 public:
196 LazyProfileInfos();
197 ~LazyProfileInfos();
198 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode(
199 CodecMode mode);
200 bool IsProfileSupported(CodecMode mode, VAProfile va_profile);
201
202 private:
203 std::vector<ProfileInfo> supported_profiles_[kCodecModeMax];
204 };
205
186 VaapiWrapper(); 206 VaapiWrapper();
187 207
188 bool Initialize(CodecMode mode, VAProfile va_profile); 208 bool Initialize(CodecMode mode, VAProfile va_profile);
189 void Deinitialize(); 209 void Deinitialize();
190 bool VaInitialize(const base::Closure& report_error_to_uma_cb); 210 bool VaInitialize(const base::Closure& report_error_to_uma_cb);
191 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); 211 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles);
192 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); 212 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint);
wuchengli 2015/03/05 03:40:28 Add a comment to say |va_lock_| must be held on en
henryhsu 2015/03/05 09:14:40 Done.
193 bool AreAttribsSupported(VAProfile va_profile, 213 bool AreAttribsSupported(VAProfile va_profile,
wuchengli 2015/03/05 03:40:29 Add a comment to say |va_lock_| must be held on en
henryhsu 2015/03/05 09:14:40 Done.
194 VAEntrypoint entrypoint, 214 VAEntrypoint entrypoint,
195 const std::vector<VAConfigAttrib>& required_attribs); 215 const std::vector<VAConfigAttrib>& required_attribs);
196 216
217 // Get maximum resolution of a profile by |config|. If return value is true,
218 // |resolution| is the maximum resolution.
wuchengli 2015/03/05 03:40:28 Add a comment to say |va_lock_| must be held on en
henryhsu 2015/03/05 09:14:40 Done.
219 bool GetMaxResolutionForVAConfigID(VAConfigID va_config_id,
220 gfx::Size* resolution);
221
197 // Destroys a |va_surface| created using CreateUnownedSurface. 222 // Destroys a |va_surface| created using CreateUnownedSurface.
198 void DestroyUnownedSurface(VASurfaceID va_surface_id); 223 void DestroyUnownedSurface(VASurfaceID va_surface_id);
199 224
200 // Initialize the video post processing context with the |size| of 225 // Initialize the video post processing context with the |size| of
201 // the input pictures to be processed. 226 // the input pictures to be processed.
202 bool InitializeVpp_Locked(); 227 bool InitializeVpp_Locked();
203 228
204 // Deinitialize the video post processing context. 229 // Deinitialize the video post processing context.
205 void DeinitializeVpp(); 230 void DeinitializeVpp();
206 231
207 // Execute pending job in hardware and destroy pending buffers. Return false 232 // Execute pending job in hardware and destroy pending buffers. Return false
208 // if vaapi driver refuses to accept parameter or slice buffers submitted 233 // if vaapi driver refuses to accept parameter or slice buffers submitted
209 // by client, or if execution fails in hardware. 234 // by client, or if execution fails in hardware.
210 bool Execute(VASurfaceID va_surface_id); 235 bool Execute(VASurfaceID va_surface_id);
211 236
212 // Attempt to set render mode to "render to texture.". Failure is non-fatal. 237 // Attempt to set render mode to "render to texture.". Failure is non-fatal.
213 void TryToSetVADisplayAttributeToLocalGPU(); 238 void TryToSetVADisplayAttributeToLocalGPU();
214 239
240 // Get supported profile infos for |mode|.
241 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecModeInternal(
242 CodecMode mode);
243
215 // Lazily initialize static data after sandbox is enabled. Return false on 244 // Lazily initialize static data after sandbox is enabled. Return false on
216 // init failure. 245 // init failure.
217 static bool PostSandboxInitialization(); 246 static bool PostSandboxInitialization();
218 247
248 // Get supported profile infos for |mode|. This is a wrapper of
249 // GetSupportedProfileInfosForCodecModeInternal for static usage.
250 static std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode(
251 CodecMode mode);
252
253 // Map VideoCodecProfile enum values to VaProfile values. This function
254 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline
255 // and it is not supported, we try constrained baseline.
256 static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile,
257 CodecMode mode);
258
219 // Libva is not thread safe, so we have to do locking for it ourselves. 259 // Libva is not thread safe, so we have to do locking for it ourselves.
220 // This lock is to be taken for the duration of all VA-API calls and for 260 // This lock is to be taken for the duration of all VA-API calls and for
221 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). 261 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers().
222 base::Lock va_lock_; 262 base::Lock va_lock_;
223 263
224 // Allocated ids for VASurfaces. 264 // Allocated ids for VASurfaces.
225 std::vector<VASurfaceID> va_surface_ids_; 265 std::vector<VASurfaceID> va_surface_ids_;
226 266
227 // The VAAPI version. 267 // The VAAPI version.
228 int major_version_, minor_version_; 268 int major_version_, minor_version_;
(...skipping 19 matching lines...) Expand all
248 // return values from public methods. 288 // return values from public methods.
249 base::Closure report_error_to_uma_cb_; 289 base::Closure report_error_to_uma_cb_;
250 290
251 // VPP (Video Post Processing) context, this is used to convert 291 // VPP (Video Post Processing) context, this is used to convert
252 // pictures used by the decoder to RGBA pictures usable by GL or the 292 // pictures used by the decoder to RGBA pictures usable by GL or the
253 // display hardware. 293 // display hardware.
254 VAConfigID va_vpp_config_id_; 294 VAConfigID va_vpp_config_id_;
255 VAContextID va_vpp_context_id_; 295 VAContextID va_vpp_context_id_;
256 VABufferID va_vpp_buffer_id_; 296 VABufferID va_vpp_buffer_id_;
257 297
298 // Singleton variable to store supported profile information for encode and
299 // decode.
300 static base::LazyInstance<LazyProfileInfos> profile_infos_;
301
258 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 302 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
259 }; 303 };
260 304
261 } // namespace content 305 } // namespace content
262 306
263 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 307 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_video_encode_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