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

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

Issue 1432963003: [Ozone] Extends the lifetime of VaapiWrapper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits/API naming fix Created 5 years 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_
(...skipping 13 matching lines...) Expand all
24 #include "media/video/jpeg_decode_accelerator.h" 24 #include "media/video/jpeg_decode_accelerator.h"
25 #include "media/video/video_decode_accelerator.h" 25 #include "media/video/video_decode_accelerator.h"
26 #include "media/video/video_encode_accelerator.h" 26 #include "media/video/video_encode_accelerator.h"
27 #include "third_party/libva/va/va.h" 27 #include "third_party/libva/va/va.h"
28 #include "third_party/libva/va/va_vpp.h" 28 #include "third_party/libva/va/va_vpp.h"
29 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
30 #if defined(USE_X11) 30 #if defined(USE_X11)
31 #include "third_party/libva/va/va_x11.h" 31 #include "third_party/libva/va/va_x11.h"
32 #endif // USE_X11 32 #endif // USE_X11
33 33
34 #if defined(USE_OZONE)
35 namespace ui {
36 class NativePixmap;
37 }
38 #endif
39
34 namespace content { 40 namespace content {
35 41
36 // This class handles VA-API calls and ensures proper locking of VA-API calls 42 // This class handles VA-API calls and ensures proper locking of VA-API calls
37 // to libva, the userspace shim to the HW codec driver. libva is not 43 // to libva, the userspace shim to the HW codec driver. libva is not
38 // thread-safe, so we have to perform locking ourselves. This class is fully 44 // thread-safe, so we have to perform locking ourselves. This class is fully
39 // synchronous and its methods can be called from any thread and may wait on 45 // synchronous and its methods can be called from any thread and may wait on
40 // the va_lock_ while other, concurrent calls run. 46 // the va_lock_ while other, concurrent calls run.
41 // 47 //
42 // This class is responsible for managing VAAPI connection, contexts and state. 48 // This class is responsible for managing VAAPI connection, contexts and state.
43 // It is also responsible for managing and freeing VABuffers (not VASurfaces), 49 // It is also responsible for managing and freeing VABuffers (not VASurfaces),
44 // which are used to queue parameters and slice data to the HW codec, 50 // which are used to queue parameters and slice data to the HW codec,
45 // as well as underlying memory for VASurfaces themselves. 51 // as well as underlying memory for VASurfaces themselves.
46 class CONTENT_EXPORT VaapiWrapper { 52 class CONTENT_EXPORT VaapiWrapper
53 : public base::RefCountedThreadSafe<VaapiWrapper> {
47 public: 54 public:
48 enum CodecMode { 55 enum CodecMode {
49 kDecode, 56 kDecode,
50 kEncode, 57 kEncode,
51 kCodecModeMax, 58 kCodecModeMax,
52 }; 59 };
53 60
54 // Return an instance of VaapiWrapper initialized for |va_profile| and 61 // Return an instance of VaapiWrapper initialized for |va_profile| and
55 // |mode|. |report_error_to_uma_cb| will be called independently from 62 // |mode|. |report_error_to_uma_cb| will be called independently from
56 // reporting errors to clients via method return values. 63 // reporting errors to clients via method return values.
57 static scoped_ptr<VaapiWrapper> Create( 64 static scoped_refptr<VaapiWrapper> Create(
58 CodecMode mode, 65 CodecMode mode,
59 VAProfile va_profile, 66 VAProfile va_profile,
60 const base::Closure& report_error_to_uma_cb); 67 const base::Closure& report_error_to_uma_cb);
61 68
62 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile 69 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile
63 // |profile| to VAProfile. 70 // |profile| to VAProfile.
64 // |report_error_to_uma_cb| will be called independently from reporting 71 // |report_error_to_uma_cb| will be called independently from reporting
65 // errors to clients via method return values. 72 // errors to clients via method return values.
66 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( 73 static scoped_refptr<VaapiWrapper> CreateForVideoCodec(
67 CodecMode mode, 74 CodecMode mode,
68 media::VideoCodecProfile profile, 75 media::VideoCodecProfile profile,
69 const base::Closure& report_error_to_uma_cb); 76 const base::Closure& report_error_to_uma_cb);
70 77
71 // Return the supported video encode profiles. 78 // Return the supported video encode profiles.
72 static media::VideoEncodeAccelerator::SupportedProfiles 79 static media::VideoEncodeAccelerator::SupportedProfiles
73 GetSupportedEncodeProfiles(); 80 GetSupportedEncodeProfiles();
74 81
75 // Return the supported video decode profiles. 82 // Return the supported video decode profiles.
76 static media::VideoDecodeAccelerator::SupportedProfiles 83 static media::VideoDecodeAccelerator::SupportedProfiles
77 GetSupportedDecodeProfiles(); 84 GetSupportedDecodeProfiles();
78 85
79 // Return true when JPEG decode is supported. 86 // Return true when JPEG decode is supported.
80 static bool IsJpegDecodeSupported(); 87 static bool IsJpegDecodeSupported();
81 88
82 ~VaapiWrapper();
83
84 // Create |num_surfaces| backing surfaces in driver for VASurfaces of 89 // Create |num_surfaces| backing surfaces in driver for VASurfaces of
85 // |va_format|, each of size |size|. Returns true when successful, with the 90 // |va_format|, each of size |size|. Returns true when successful, with the
86 // created IDs in |va_surfaces| to be managed and later wrapped in 91 // created IDs in |va_surfaces| to be managed and later wrapped in
87 // VASurfaces. 92 // VASurfaces.
88 // The client must DestroySurfaces() each time before calling this method 93 // The client must DestroySurfaces() each time before calling this method
89 // again to free the allocated surfaces first, but is not required to do so 94 // again to free the allocated surfaces first, but is not required to do so
90 // at destruction time, as this will be done automatically from 95 // at destruction time, as this will be done automatically from
91 // the destructor. 96 // the destructor.
92 bool CreateSurfaces(unsigned int va_format, 97 bool CreateSurfaces(unsigned int va_format,
93 const gfx::Size& size, 98 const gfx::Size& size,
94 size_t num_surfaces, 99 size_t num_surfaces,
95 std::vector<VASurfaceID>* va_surfaces); 100 std::vector<VASurfaceID>* va_surfaces);
96 101
97 // Free all memory allocated in CreateSurfaces. 102 // Free all memory allocated in CreateSurfaces.
98 void DestroySurfaces(); 103 void DestroySurfaces();
99 104
100 // Create a VASurface of |va_format|, |size| and using |va_attribs| 105 // Create a VASurface of |va_format|, |size| and using |va_attribs|
101 // attributes. The ownership of the surface is transferred to the 106 // attributes. The ownership of the surface is transferred to the
102 // caller. It differs from surfaces created using CreateSurfaces(), 107 // caller. It differs from surfaces created using CreateSurfaces(),
103 // where VaapiWrapper is the owner of the surfaces. 108 // where VaapiWrapper is the owner of the surfaces.
104 scoped_refptr<VASurface> CreateUnownedSurface( 109 scoped_refptr<VASurface> CreateUnownedSurface(
105 unsigned int va_format, 110 unsigned int va_format,
106 const gfx::Size& size, 111 const gfx::Size& size,
107 const std::vector<VASurfaceAttrib>& va_attribs); 112 const std::vector<VASurfaceAttrib>& va_attribs);
108 113
114 #if defined(USE_OZONE)
115 // Create a VASurface for |pixmap| of |pixmap_size|. The ownership of the
116 // surface is transferred to the caller. It differs from surfaces created
117 // using CreateSurfaces(), where VaapiWrapper is the owner of the surfaces.
118 scoped_refptr<VASurface> CreateVASurfaceForPixmap(
119 const scoped_refptr<ui::NativePixmap>& pixmap,
120 const gfx::Size& pixmap_size);
121
122 // Use VPP to process |source_pixmap|, scaling to |target_size| and
123 // converting to |target_format|. Return the processed pixmap.
124 scoped_refptr<ui::NativePixmap> ProcessPixmap(
125 const scoped_refptr<ui::NativePixmap>& source_pixmap,
126 const gfx::Size& target_size,
127 gfx::BufferFormat target_format);
128
129 // Create native pixmap with size |size| and format |format|.
130 scoped_refptr<ui::NativePixmap> CreateNativePixmap(gfx::Size size,
Pawel Osciak 2015/11/30 05:57:02 Sorry, I think you misunderstood me previously: I
william.xie1 2015/11/30 08:02:02 Done.
131 gfx::BufferFormat format);
132 #endif
133
109 // Submit parameters or slice data of |va_buffer_type|, copying them from 134 // Submit parameters or slice data of |va_buffer_type|, copying them from
110 // |buffer| of size |size|, into HW codec. The data in |buffer| is no 135 // |buffer| of size |size|, into HW codec. The data in |buffer| is no
111 // longer needed and can be freed after this method returns. 136 // longer needed and can be freed after this method returns.
112 // Data submitted via this method awaits in the HW codec until 137 // Data submitted via this method awaits in the HW codec until
113 // ExecuteAndDestroyPendingBuffers() is called to execute or 138 // ExecuteAndDestroyPendingBuffers() is called to execute or
114 // DestroyPendingBuffers() is used to cancel a pending job. 139 // DestroyPendingBuffers() is used to cancel a pending job.
115 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); 140 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer);
116 141
117 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its 142 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its
118 // data from |buffer| of size |size|, into HW codec. The data in |buffer| is 143 // data from |buffer| of size |size|, into HW codec. The data in |buffer| is
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src, 217 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src,
193 const scoped_refptr<VASurface>& va_surface_dest); 218 const scoped_refptr<VASurface>& va_surface_dest);
194 219
195 // Initialize static data before sandbox is enabled. 220 // Initialize static data before sandbox is enabled.
196 static void PreSandboxInitialization(); 221 static void PreSandboxInitialization();
197 222
198 // Get the created surfaces format. 223 // Get the created surfaces format.
199 unsigned int va_surface_format() const { return va_surface_format_; } 224 unsigned int va_surface_format() const { return va_surface_format_; }
200 225
201 private: 226 private:
227 friend class base::RefCountedThreadSafe<VaapiWrapper>;
228
202 struct ProfileInfo { 229 struct ProfileInfo {
203 VAProfile va_profile; 230 VAProfile va_profile;
204 gfx::Size max_resolution; 231 gfx::Size max_resolution;
205 }; 232 };
206 233
207 class LazyProfileInfos { 234 class LazyProfileInfos {
208 public: 235 public:
209 LazyProfileInfos(); 236 LazyProfileInfos();
210 ~LazyProfileInfos(); 237 ~LazyProfileInfos();
211 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode( 238 std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 VADisplay va_display_; 282 VADisplay va_display_;
256 283
257 // The VAAPI version. 284 // The VAAPI version.
258 int major_version_, minor_version_; 285 int major_version_, minor_version_;
259 286
260 // True if vaInitialize has been called successfully. 287 // True if vaInitialize has been called successfully.
261 bool va_initialized_; 288 bool va_initialized_;
262 }; 289 };
263 290
264 VaapiWrapper(); 291 VaapiWrapper();
292 ~VaapiWrapper();
265 293
266 bool Initialize(CodecMode mode, VAProfile va_profile); 294 bool Initialize(CodecMode mode, VAProfile va_profile);
267 void Deinitialize(); 295 void Deinitialize();
268 bool VaInitialize(const base::Closure& report_error_to_uma_cb); 296 bool VaInitialize(const base::Closure& report_error_to_uma_cb);
269 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); 297 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles);
270 298
271 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be 299 // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be
272 // held on entry. 300 // held on entry.
273 bool IsEntrypointSupported_Locked(VAProfile va_profile, 301 bool IsEntrypointSupported_Locked(VAProfile va_profile,
274 VAEntrypoint entrypoint); 302 VAEntrypoint entrypoint);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // Singleton variable to store supported profile information for encode and 391 // Singleton variable to store supported profile information for encode and
364 // decode. 392 // decode.
365 static base::LazyInstance<LazyProfileInfos> profile_infos_; 393 static base::LazyInstance<LazyProfileInfos> profile_infos_;
366 394
367 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 395 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
368 }; 396 };
369 397
370 } // namespace content 398 } // namespace content
371 399
372 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 400 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_video_encode_accelerator.h ('k') | content/common/gpu/media/vaapi_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698