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

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

Issue 804353003: Revert of Refactor Vaapi video decoder/encoder in preparation of Freon support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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_
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/callback.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"
22 #include "third_party/libva/va/va.h" 23 #include "third_party/libva/va/va_x11.h"
23 #include "ui/gfx/size.h" 24 #include "ui/gfx/size.h"
24 #if defined(USE_X11)
25 #include "third_party/libva/va/va_x11.h"
26 #endif // USE_X11
27 25
28 namespace content { 26 namespace content {
29 27
30 // This class handles VA-API calls and ensures proper locking of VA-API calls 28 // 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 29 // 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 30 // thread-safe, so we have to perform locking ourselves. This class is fully
33 // synchronous and its methods can be called from any thread and may wait on 31 // synchronous and its methods can be called from any thread and may wait on
34 // the va_lock_ while other, concurrent calls run. 32 // the va_lock_ while other, concurrent calls run.
35 // 33 //
36 // This class is responsible for managing VAAPI connection, contexts and state. 34 // This class is responsible for managing VAAPI connection, contexts and state.
37 // It is also responsible for managing and freeing VABuffers (not VASurfaces), 35 // It is also responsible for managing and freeing VABuffers (not VASurfaces),
38 // which are used to queue parameters and slice data to the HW codec, 36 // which are used to queue parameters and slice data to the HW codec,
39 // as well as underlying memory for VASurfaces themselves. 37 // as well as underlying memory for VASurfaces themselves.
40 class CONTENT_EXPORT VaapiWrapper 38 class CONTENT_EXPORT VaapiWrapper {
41 : public base::RefCountedThreadSafe<VaapiWrapper> {
42 public: 39 public:
43 enum CodecMode { 40 enum CodecMode {
44 kDecode, 41 kDecode,
45 kEncode, 42 kEncode,
46 }; 43 };
47 44
48 // |report_error_to_uma_cb| will be called independently from reporting 45 // |report_error_to_uma_cb| will be called independently from reporting
49 // errors to clients via method return values. 46 // errors to clients via method return values.
50 static scoped_refptr<VaapiWrapper> Create( 47 static scoped_ptr<VaapiWrapper> Create(
51 CodecMode mode, 48 CodecMode mode,
52 media::VideoCodecProfile profile, 49 media::VideoCodecProfile profile,
50 Display* x_display,
53 const base::Closure& report_error_to_uma_cb); 51 const base::Closure& report_error_to_uma_cb);
54 52
55 // Return the supported encode profiles. 53 // Return the supported encode profiles.
56 static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( 54 static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles(
55 Display* x_display,
57 const base::Closure& report_error_to_uma_cb); 56 const base::Closure& report_error_to_uma_cb);
58 57
58 ~VaapiWrapper();
59
59 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each 60 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each
60 // of size |size|. Returns true when successful, with the created IDs in 61 // of size |size|. Returns true when successful, with the created IDs in
61 // |va_surfaces| to be managed and later wrapped in VASurfaces. 62 // |va_surfaces| to be managed and later wrapped in VASurfaces.
62 // The client must DestroySurfaces() each time before calling this method 63 // The client must DestroySurfaces() each time before calling this method
63 // again to free the allocated surfaces first, but is not required to do so 64 // again to free the allocated surfaces first, but is not required to do so
64 // at destruction time, as this will be done automatically from 65 // at destruction time, as this will be done automatically from
65 // the destructor. 66 // the destructor.
66 bool CreateSurfaces(const gfx::Size& size, 67 bool CreateSurfaces(gfx::Size size,
67 size_t num_surfaces, 68 size_t num_surfaces,
68 std::vector<VASurfaceID>* va_surfaces); 69 std::vector<VASurfaceID>* va_surfaces);
69 70
70 // Free all memory allocated in CreateSurfaces. 71 // Free all memory allocated in CreateSurfaces.
71 void DestroySurfaces(); 72 void DestroySurfaces();
72 73
73 // Submit parameters or slice data of |va_buffer_type|, copying them from 74 // Submit parameters or slice data of |va_buffer_type|, copying them from
74 // |buffer| of size |size|, into HW codec. The data in |buffer| is no 75 // |buffer| of size |size|, into HW codec. The data in |buffer| is no
75 // longer needed and can be freed after this method returns. 76 // longer needed and can be freed after this method returns.
76 // Data submitted via this method awaits in the HW codec until 77 // Data submitted via this method awaits in the HW codec until
(...skipping 12 matching lines...) Expand all
89 void* buffer); 90 void* buffer);
90 91
91 // Cancel and destroy all buffers queued to the HW codec via SubmitBuffer(). 92 // Cancel and destroy all buffers queued to the HW codec via SubmitBuffer().
92 // Useful when a pending job is to be cancelled (on reset or error). 93 // Useful when a pending job is to be cancelled (on reset or error).
93 void DestroyPendingBuffers(); 94 void DestroyPendingBuffers();
94 95
95 // Execute job in hardware on target |va_surface_id| and destroy pending 96 // Execute job in hardware on target |va_surface_id| and destroy pending
96 // buffers. Return false if Execute() fails. 97 // buffers. Return false if Execute() fails.
97 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id); 98 bool ExecuteAndDestroyPendingBuffers(VASurfaceID va_surface_id);
98 99
100 // Put data from |va_surface_id| into |x_pixmap| of size |size|,
101 // converting/scaling to it.
102 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
103 Pixmap x_pixmap,
104 gfx::Size dest_size);
105
99 // Returns true if the VAAPI version is less than the specified version. 106 // Returns true if the VAAPI version is less than the specified version.
100 bool VAAPIVersionLessThan(int major, int minor); 107 bool VAAPIVersionLessThan(int major, int minor);
101 108
102 // Get a VAImage from a VASurface and map it into memory. The VAImage should 109 // Get a VAImage from a VASurface and map it into memory. The VAImage should
103 // be released using the ReturnVaImage function. Returns true when successful. 110 // be released using the ReturnVaImage function. Returns true when successful.
104 // This is intended for testing only. 111 // This is intended for testing only.
105 bool GetVaImageForTesting(VASurfaceID va_surface_id, 112 bool GetVaImageForTesting(VASurfaceID va_surface_id,
106 VAImage* image, 113 VAImage* image,
107 void** mem); 114 void** mem);
108 115
(...skipping 16 matching lines...) Expand all
125 // to the encode job. 132 // to the encode job.
126 bool DownloadAndDestroyCodedBuffer(VABufferID buffer_id, 133 bool DownloadAndDestroyCodedBuffer(VABufferID buffer_id,
127 VASurfaceID sync_surface_id, 134 VASurfaceID sync_surface_id,
128 uint8* target_ptr, 135 uint8* target_ptr,
129 size_t target_size, 136 size_t target_size,
130 size_t* coded_data_size); 137 size_t* coded_data_size);
131 138
132 // Destroy all previously-allocated (and not yet destroyed) coded buffers. 139 // Destroy all previously-allocated (and not yet destroyed) coded buffers.
133 void DestroyCodedBuffers(); 140 void DestroyCodedBuffers();
134 141
135 #if defined(USE_X11)
136 // Put data from |va_surface_id| into |x_pixmap| of size
137 // |dest_size|, converting/scaling to it.
138 bool PutSurfaceIntoPixmap(VASurfaceID va_surface_id,
139 Pixmap x_pixmap,
140 gfx::Size dest_size);
141 #endif // USE_X11
142
143 private: 142 private:
144 friend class base::RefCountedThreadSafe<VaapiWrapper>;
145 VaapiWrapper(); 143 VaapiWrapper();
146 ~VaapiWrapper();
147 144
148 bool Initialize(CodecMode mode, 145 bool Initialize(CodecMode mode,
149 media::VideoCodecProfile profile, 146 media::VideoCodecProfile profile,
150 const base::Closure& report_error__to_uma_cb); 147 Display* x_display,
148 const base::Closure& report_error_to_uma_cb);
151 void Deinitialize(); 149 void Deinitialize();
152 bool VaInitialize(const base::Closure& report_error_to_uma_cb); 150 bool VaInitialize(Display* x_display,
151 const base::Closure& report_error_to_uma_cb);
153 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); 152 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles);
154 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); 153 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint);
155 bool AreAttribsSupported(VAProfile va_profile, 154 bool AreAttribsSupported(VAProfile va_profile,
156 VAEntrypoint entrypoint, 155 VAEntrypoint entrypoint,
157 const std::vector<VAConfigAttrib>& required_attribs); 156 const std::vector<VAConfigAttrib>& required_attribs);
158 157
159 // Execute pending job in hardware and destroy pending buffers. Return false 158 // Execute pending job in hardware and destroy pending buffers. Return false
160 // if vaapi driver refuses to accept parameter or slice buffers submitted 159 // if vaapi driver refuses to accept parameter or slice buffers submitted
161 // by client, or if execution fails in hardware. 160 // by client, or if execution fails in hardware.
162 bool Execute(VASurfaceID va_surface_id); 161 bool Execute(VASurfaceID va_surface_id);
(...skipping 10 matching lines...) Expand all
173 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). 172 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers().
174 base::Lock va_lock_; 173 base::Lock va_lock_;
175 174
176 // Allocated ids for VASurfaces. 175 // Allocated ids for VASurfaces.
177 std::vector<VASurfaceID> va_surface_ids_; 176 std::vector<VASurfaceID> va_surface_ids_;
178 177
179 // The VAAPI version. 178 // The VAAPI version.
180 int major_version_, minor_version_; 179 int major_version_, minor_version_;
181 180
182 // VA handles. 181 // VA handles.
183 // All valid after successful Initialize() and until Deinitialize(). 182 // Both valid after successful Initialize() and until Deinitialize().
184 VADisplay va_display_; 183 VADisplay va_display_;
185 VAConfigID va_config_id_; 184 VAConfigID va_config_id_;
186 // Created for the current set of va_surface_ids_ in CreateSurfaces() and 185 // Created for the current set of va_surface_ids_ in CreateSurfaces() and
187 // valid until DestroySurfaces(). 186 // valid until DestroySurfaces().
188 VAContextID va_context_id_; 187 VAContextID va_context_id_;
189 // True if vaInitialize has been called successfully. 188 // True if vaInitialize has been called successfully.
190 bool va_initialized_; 189 bool va_initialized_;
191 190
192 // Data queued up for HW codec, to be committed on next execution. 191 // Data queued up for HW codec, to be committed on next execution.
193 std::vector<VABufferID> pending_slice_bufs_; 192 std::vector<VABufferID> pending_slice_bufs_;
194 std::vector<VABufferID> pending_va_bufs_; 193 std::vector<VABufferID> pending_va_bufs_;
195 194
196 // Bitstream buffers for encode. 195 // Bitstream buffers for encode.
197 std::set<VABufferID> coded_buffers_; 196 std::set<VABufferID> coded_buffers_;
198 197
199 // Called to report codec errors to UMA. Errors to clients are reported via 198 // Called to report codec errors to UMA. Errors to clients are reported via
200 // return values from public methods. 199 // return values from public methods.
201 base::Closure report_error_to_uma_cb_; 200 base::Closure report_error_to_uma_cb_;
202 201
203 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 202 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
204 }; 203 };
205 204
206 } // namespace content 205 } // namespace content
207 206
208 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 207 #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