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

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: Extends the lifetime of VaapiWrapper Created 5 years, 1 month 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 namespace ui {
35 class NativePixmap;
36 }
37
34 namespace content { 38 namespace content {
35 39
36 // This class handles VA-API calls and ensures proper locking of VA-API calls 40 // 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 41 // 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 42 // 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 43 // synchronous and its methods can be called from any thread and may wait on
40 // the va_lock_ while other, concurrent calls run. 44 // the va_lock_ while other, concurrent calls run.
41 // 45 //
42 // This class is responsible for managing VAAPI connection, contexts and state. 46 // This class is responsible for managing VAAPI connection, contexts and state.
43 // It is also responsible for managing and freeing VABuffers (not VASurfaces), 47 // 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, 48 // which are used to queue parameters and slice data to the HW codec,
45 // as well as underlying memory for VASurfaces themselves. 49 // as well as underlying memory for VASurfaces themselves.
46 class CONTENT_EXPORT VaapiWrapper { 50 class CONTENT_EXPORT VaapiWrapper
51 : public base::RefCountedThreadSafe<VaapiWrapper> {
47 public: 52 public:
48 enum CodecMode { 53 enum CodecMode {
49 kDecode, 54 kDecode,
50 kEncode, 55 kEncode,
51 kCodecModeMax, 56 kCodecModeMax,
52 }; 57 };
53 58
54 // Return an instance of VaapiWrapper initialized for |va_profile| and 59 // Return an instance of VaapiWrapper initialized for |va_profile| and
55 // |mode|. |report_error_to_uma_cb| will be called independently from 60 // |mode|. |report_error_to_uma_cb| will be called independently from
56 // reporting errors to clients via method return values. 61 // reporting errors to clients via method return values.
57 static scoped_ptr<VaapiWrapper> Create( 62 static scoped_refptr<VaapiWrapper> Create(
58 CodecMode mode, 63 CodecMode mode,
59 VAProfile va_profile, 64 VAProfile va_profile,
60 const base::Closure& report_error_to_uma_cb); 65 const base::Closure& report_error_to_uma_cb);
61 66
62 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile 67 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile
63 // |profile| to VAProfile. 68 // |profile| to VAProfile.
64 // |report_error_to_uma_cb| will be called independently from reporting 69 // |report_error_to_uma_cb| will be called independently from reporting
65 // errors to clients via method return values. 70 // errors to clients via method return values.
66 static scoped_ptr<VaapiWrapper> CreateForVideoCodec( 71 static scoped_refptr<VaapiWrapper> CreateForVideoCodec(
67 CodecMode mode, 72 CodecMode mode,
68 media::VideoCodecProfile profile, 73 media::VideoCodecProfile profile,
69 const base::Closure& report_error_to_uma_cb); 74 const base::Closure& report_error_to_uma_cb);
70 75
71 // Return the supported video encode profiles. 76 // Return the supported video encode profiles.
72 static media::VideoEncodeAccelerator::SupportedProfiles 77 static media::VideoEncodeAccelerator::SupportedProfiles
73 GetSupportedEncodeProfiles(); 78 GetSupportedEncodeProfiles();
74 79
75 // Return the supported video decode profiles. 80 // Return the supported video decode profiles.
76 static media::VideoDecodeAccelerator::SupportedProfiles 81 static media::VideoDecodeAccelerator::SupportedProfiles
(...skipping 22 matching lines...) Expand all
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 // Create a VASurface for |pixmap| of |pixmap_size|. The ownership of the
115 // surface is transferred to the caller. It differs from surfaces created
116 // using CreateSurfaces(), where VaapiWrapper is the owner of the surfaces.
117 scoped_refptr<VASurface> CreateVASurfaceForPixmap(
118 scoped_refptr<ui::NativePixmap> pixmap,
Pawel Osciak 2015/11/20 10:09:18 const&
william.xie1 2015/11/23 03:33:58 Done.
119 gfx::Size pixmap_size);
Pawel Osciak 2015/11/20 10:09:18 const&
william.xie1 2015/11/23 03:33:58 Done.
120
109 // Submit parameters or slice data of |va_buffer_type|, copying them from 121 // 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 122 // |buffer| of size |size|, into HW codec. The data in |buffer| is no
111 // longer needed and can be freed after this method returns. 123 // longer needed and can be freed after this method returns.
112 // Data submitted via this method awaits in the HW codec until 124 // Data submitted via this method awaits in the HW codec until
113 // ExecuteAndDestroyPendingBuffers() is called to execute or 125 // ExecuteAndDestroyPendingBuffers() is called to execute or
114 // DestroyPendingBuffers() is used to cancel a pending job. 126 // DestroyPendingBuffers() is used to cancel a pending job.
115 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer); 127 bool SubmitBuffer(VABufferType va_buffer_type, size_t size, void* buffer);
116 128
117 // Submit a VAEncMiscParameterBuffer of given |misc_param_type|, copying its 129 // 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 130 // data from |buffer| of size |size|, into HW codec. The data in |buffer| is
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // if needed. 203 // if needed.
192 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src, 204 bool BlitSurface(const scoped_refptr<VASurface>& va_surface_src,
193 const scoped_refptr<VASurface>& va_surface_dest); 205 const scoped_refptr<VASurface>& va_surface_dest);
194 206
195 // Initialize static data before sandbox is enabled. 207 // Initialize static data before sandbox is enabled.
196 static void PreSandboxInitialization(); 208 static void PreSandboxInitialization();
197 209
198 // Get the created surfaces format. 210 // Get the created surfaces format.
199 unsigned int va_surface_format() const { return va_surface_format_; } 211 unsigned int va_surface_format() const { return va_surface_format_; }
200 212
213 // Map gfx::BufferFormat value to VA FOURCC value.
214 static uint32_t BufferFormatToVAFourCC(gfx::BufferFormat fmt);
Pawel Osciak 2015/11/20 10:09:18 These methods don't need to be members of the clas
william.xie1 2015/11/23 03:33:58 Done.
215
216 // Map gfx::BufferFormat value to VA render target format value.
217 static uint32_t BufferFormatToVARTFormat(gfx::BufferFormat fmt);
218
201 private: 219 private:
202 struct ProfileInfo { 220 struct ProfileInfo {
203 VAProfile va_profile; 221 VAProfile va_profile;
204 gfx::Size max_resolution; 222 gfx::Size max_resolution;
205 }; 223 };
206 224
207 class LazyProfileInfos { 225 class LazyProfileInfos {
208 public: 226 public:
209 LazyProfileInfos(); 227 LazyProfileInfos();
210 ~LazyProfileInfos(); 228 ~LazyProfileInfos();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 // Singleton variable to store supported profile information for encode and 381 // Singleton variable to store supported profile information for encode and
364 // decode. 382 // decode.
365 static base::LazyInstance<LazyProfileInfos> profile_infos_; 383 static base::LazyInstance<LazyProfileInfos> profile_infos_;
366 384
367 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 385 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
368 }; 386 };
369 387
370 } // namespace content 388 } // namespace content
371 389
372 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 390 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698