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

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: add 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);
212
213 // Check |va_profile| support |entrypoint| or not. |va_lock_| must be held on
wuchengli 2015/03/05 16:24:21 s/Check |va_profile| support/Check if |va_profile|
henryhsu 2015/03/09 03:56:52 Done.
214 // entry.
192 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); 215 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint);
Pawel Osciak 2015/03/08 00:58:24 s/IsEntrypointSupported/IsEntrypointSupported_Lock
henryhsu 2015/03/09 03:56:52 Done.
216
217 // Check |va_profile| support |required_attribs| or not. |va_lock_| must be
wuchengli 2015/03/05 16:24:21 Checks if |va_profile| / |entrypoint| pair support
henryhsu 2015/03/09 03:56:52 Done.
218 // held on entry.
193 bool AreAttribsSupported(VAProfile va_profile, 219 bool AreAttribsSupported(VAProfile va_profile,
Pawel Osciak 2015/03/08 00:58:24 s/AreAttribsSupported/AreAttribsSupported_Locked/
henryhsu 2015/03/09 03:56:52 Done.
194 VAEntrypoint entrypoint, 220 VAEntrypoint entrypoint,
195 const std::vector<VAConfigAttrib>& required_attribs); 221 const std::vector<VAConfigAttrib>& required_attribs);
196 222
223 // Get maximum resolution of a profile by |config|. If return value is true,
Pawel Osciak 2015/03/08 00:58:24 s/by |config|/for |va_config_id|/
henryhsu 2015/03/09 03:56:52 Done.
224 // |resolution| is the maximum resolution. |va_lock_| must be held on entry.
225 bool GetMaxResolutionForVAConfigID(VAConfigID va_config_id,
226 gfx::Size* resolution);
227
197 // Destroys a |va_surface| created using CreateUnownedSurface. 228 // Destroys a |va_surface| created using CreateUnownedSurface.
198 void DestroyUnownedSurface(VASurfaceID va_surface_id); 229 void DestroyUnownedSurface(VASurfaceID va_surface_id);
199 230
200 // Initialize the video post processing context with the |size| of 231 // Initialize the video post processing context with the |size| of
201 // the input pictures to be processed. 232 // the input pictures to be processed.
202 bool InitializeVpp_Locked(); 233 bool InitializeVpp_Locked();
203 234
204 // Deinitialize the video post processing context. 235 // Deinitialize the video post processing context.
205 void DeinitializeVpp(); 236 void DeinitializeVpp();
206 237
207 // Execute pending job in hardware and destroy pending buffers. Return false 238 // Execute pending job in hardware and destroy pending buffers. Return false
208 // if vaapi driver refuses to accept parameter or slice buffers submitted 239 // if vaapi driver refuses to accept parameter or slice buffers submitted
209 // by client, or if execution fails in hardware. 240 // by client, or if execution fails in hardware.
210 bool Execute(VASurfaceID va_surface_id); 241 bool Execute(VASurfaceID va_surface_id);
211 242
212 // Attempt to set render mode to "render to texture.". Failure is non-fatal. 243 // Attempt to set render mode to "render to texture.". Failure is non-fatal.
213 void TryToSetVADisplayAttributeToLocalGPU(); 244 void TryToSetVADisplayAttributeToLocalGPU();
214 245
246 // Get supported profile infos for |mode|.
247 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecModeInternal(
248 CodecMode mode);
249
215 // Lazily initialize static data after sandbox is enabled. Return false on 250 // Lazily initialize static data after sandbox is enabled. Return false on
216 // init failure. 251 // init failure.
217 static bool PostSandboxInitialization(); 252 static bool PostSandboxInitialization();
218 253
254 // Get supported profile infos for |mode|. This is a wrapper of
255 // GetSupportedProfileInfosForCodecModeInternal for static usage.
Pawel Osciak 2015/03/08 00:58:24 It looks like GetSupportedProfileInfosForCodecMode
henryhsu 2015/03/09 03:56:52 I prefer not. Because GetSupportedProfileInfosForC
wuchengli 2015/03/09 04:59:17 Can you move the body of GetSupportedProfileInfosF
256 static std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode(
257 CodecMode mode);
258
259 // Map VideoCodecProfile enum values to VaProfile values. This function
260 // includes a workaround for crbug.com/345569. If va_profile is h264 baseline
261 // and it is not supported, we try constrained baseline.
262 static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile,
263 CodecMode mode);
264
219 // 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.
220 // 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
221 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). 267 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers().
222 base::Lock va_lock_; 268 base::Lock va_lock_;
223 269
224 // Allocated ids for VASurfaces. 270 // Allocated ids for VASurfaces.
225 std::vector<VASurfaceID> va_surface_ids_; 271 std::vector<VASurfaceID> va_surface_ids_;
226 272
227 // The VAAPI version. 273 // The VAAPI version.
228 int major_version_, minor_version_; 274 int major_version_, minor_version_;
(...skipping 19 matching lines...) Expand all
248 // return values from public methods. 294 // return values from public methods.
249 base::Closure report_error_to_uma_cb_; 295 base::Closure report_error_to_uma_cb_;
250 296
251 // VPP (Video Post Processing) context, this is used to convert 297 // VPP (Video Post Processing) context, this is used to convert
252 // pictures used by the decoder to RGBA pictures usable by GL or the 298 // pictures used by the decoder to RGBA pictures usable by GL or the
253 // display hardware. 299 // display hardware.
254 VAConfigID va_vpp_config_id_; 300 VAConfigID va_vpp_config_id_;
255 VAContextID va_vpp_context_id_; 301 VAContextID va_vpp_context_id_;
256 VABufferID va_vpp_buffer_id_; 302 VABufferID va_vpp_buffer_id_;
257 303
304 // Singleton variable to store supported profile information for encode and
305 // decode.
306 static base::LazyInstance<LazyProfileInfos> profile_infos_;
307
258 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 308 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
259 }; 309 };
260 310
261 } // namespace content 311 } // namespace content
262 312
263 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 313 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698