OLD | NEW |
---|---|
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 27 matching lines...) Expand all Loading... | |
38 // It is also responsible for managing and freeing VABuffers (not VASurfaces), | 38 // 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, | 39 // which are used to queue parameters and slice data to the HW codec, |
40 // as well as underlying memory for VASurfaces themselves. | 40 // as well as underlying memory for VASurfaces themselves. |
41 class CONTENT_EXPORT VaapiWrapper { | 41 class CONTENT_EXPORT VaapiWrapper { |
42 public: | 42 public: |
43 enum CodecMode { | 43 enum CodecMode { |
44 kDecode, | 44 kDecode, |
45 kEncode, | 45 kEncode, |
46 }; | 46 }; |
47 | 47 |
48 // |report_error_to_uma_cb| will be called independently from reporting | 48 struct ProfileConfig { |
49 // errors to clients via method return values. | 49 media::VideoCodecProfile profile; |
wuchengli
2015/02/03 03:17:33
It should be better to store VaProfile in this cla
henryhsu
2015/02/13 04:01:03
Done.
| |
50 CodecMode mode; | |
51 gfx::Size max_resolution; | |
52 }; | |
53 | |
54 // Return an instance of VaapiWrapper and initialize by |profile| and | |
55 // |mode|. |report_error_to_uma_cb| will be called independently from | |
56 // reporting errors to clients via method return values. | |
50 static scoped_ptr<VaapiWrapper> Create( | 57 static scoped_ptr<VaapiWrapper> Create( |
51 CodecMode mode, | 58 CodecMode mode, |
52 media::VideoCodecProfile profile, | 59 media::VideoCodecProfile profile, |
53 const base::Closure& report_error_to_uma_cb); | 60 const base::Closure& report_error_to_uma_cb); |
54 | 61 |
55 // Return the supported encode profiles. | 62 // Return the supported profiles according to mode. |
56 static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( | 63 static std::vector<media::VideoCodecProfile> GetSupportedProfiles( |
wuchengli
2015/02/03 03:17:33
Now that we have to return both profile and resolu
henryhsu
2015/02/13 04:01:03
Done.
| |
57 const base::Closure& report_error_to_uma_cb); | 64 CodecMode mode); |
wuchengli
2015/02/03 03:17:33
No need to add CodecMode parameter in this CL. Dec
henryhsu
2015/02/13 04:01:04
Done.
| |
65 | |
66 // Return the hardware supported maximum resolution. | |
67 static gfx::Size GetCodecMaxResolution( | |
68 media::VideoCodecProfile profile, | |
69 CodecMode mode); | |
58 | 70 |
59 ~VaapiWrapper(); | 71 ~VaapiWrapper(); |
60 | 72 |
61 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each | 73 // Create |num_surfaces| backing surfaces in driver for VASurfaces, each |
62 // of size |size|. Returns true when successful, with the created IDs in | 74 // of size |size|. Returns true when successful, with the created IDs in |
63 // |va_surfaces| to be managed and later wrapped in VASurfaces. | 75 // |va_surfaces| to be managed and later wrapped in VASurfaces. |
64 // The client must DestroySurfaces() each time before calling this method | 76 // The client must DestroySurfaces() each time before calling this method |
65 // again to free the allocated surfaces first, but is not required to do so | 77 // again to free the allocated surfaces first, but is not required to do so |
66 // at destruction time, as this will be done automatically from | 78 // at destruction time, as this will be done automatically from |
67 // the destructor. | 79 // the destructor. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 // if needed. | 168 // if needed. |
157 bool BlitSurface(VASurfaceID va_surface_id_src, | 169 bool BlitSurface(VASurfaceID va_surface_id_src, |
158 const gfx::Size& src_size, | 170 const gfx::Size& src_size, |
159 VASurfaceID va_surface_id_dest, | 171 VASurfaceID va_surface_id_dest, |
160 const gfx::Size& dest_size); | 172 const gfx::Size& dest_size); |
161 | 173 |
162 private: | 174 private: |
163 VaapiWrapper(); | 175 VaapiWrapper(); |
164 | 176 |
165 bool Initialize(CodecMode mode, | 177 bool Initialize(CodecMode mode, |
166 media::VideoCodecProfile profile, | 178 media::VideoCodecProfile profile); |
167 const base::Closure& report_error__to_uma_cb); | |
168 void Deinitialize(); | 179 void Deinitialize(); |
169 bool VaInitialize(const base::Closure& report_error_to_uma_cb); | 180 bool VaInitialize(const base::Closure& report_error_to_uma_cb); |
170 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); | 181 bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); |
171 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); | 182 bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint); |
172 bool AreAttribsSupported(VAProfile va_profile, | 183 bool AreAttribsSupported(VAProfile va_profile, |
173 VAEntrypoint entrypoint, | 184 VAEntrypoint entrypoint, |
174 const std::vector<VAConfigAttrib>& required_attribs); | 185 const std::vector<VAConfigAttrib>& required_attribs); |
186 bool GetVaCodecMaxResolution(VAConfigID config, gfx::Size* resolution); | |
175 | 187 |
176 // Destroys a |va_surface| created using CreateUnownedSurface. | 188 // Destroys a |va_surface| created using CreateUnownedSurface. |
177 void DestroyUnownedSurface(VASurfaceID va_surface_id); | 189 void DestroyUnownedSurface(VASurfaceID va_surface_id); |
178 | 190 |
179 // Initialize the video post processing context with the |size| of | 191 // Initialize the video post processing context with the |size| of |
180 // the input pictures to be processed. | 192 // the input pictures to be processed. |
181 bool InitializeVpp_Locked(); | 193 bool InitializeVpp_Locked(); |
182 | 194 |
183 // Deinitialize the video post processing context. | 195 // Deinitialize the video post processing context. |
184 void DeinitializeVpp(); | 196 void DeinitializeVpp(); |
185 | 197 |
186 // Execute pending job in hardware and destroy pending buffers. Return false | 198 // Execute pending job in hardware and destroy pending buffers. Return false |
187 // if vaapi driver refuses to accept parameter or slice buffers submitted | 199 // if vaapi driver refuses to accept parameter or slice buffers submitted |
188 // by client, or if execution fails in hardware. | 200 // by client, or if execution fails in hardware. |
189 bool Execute(VASurfaceID va_surface_id); | 201 bool Execute(VASurfaceID va_surface_id); |
190 | 202 |
191 // Attempt to set render mode to "render to texture.". Failure is non-fatal. | 203 // Attempt to set render mode to "render to texture.". Failure is non-fatal. |
192 void TryToSetVADisplayAttributeToLocalGPU(); | 204 void TryToSetVADisplayAttributeToLocalGPU(); |
193 | 205 |
206 // Initialize all supported profiles. | |
207 void InitializeSupportedProfiles(); | |
208 | |
194 // Lazily initialize static data after sandbox is enabled. Return false on | 209 // Lazily initialize static data after sandbox is enabled. Return false on |
195 // init failure. | 210 // init failure. |
196 static bool PostSandboxInitialization(); | 211 static bool PostSandboxInitialization(); |
197 | 212 |
213 // Return an instance of VaapiWrapper. |report_error_to_uma_cb| will be called | |
214 // independently from reporting errors to clients via method return values. | |
215 static scoped_ptr<VaapiWrapper> CreateInstance( | |
216 const base::Closure& report_error_to_uma_cb); | |
217 | |
198 // Libva is not thread safe, so we have to do locking for it ourselves. | 218 // Libva is not thread safe, so we have to do locking for it ourselves. |
199 // This lock is to be taken for the duration of all VA-API calls and for | 219 // This lock is to be taken for the duration of all VA-API calls and for |
200 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). | 220 // the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). |
201 base::Lock va_lock_; | 221 base::Lock va_lock_; |
202 | 222 |
203 // Allocated ids for VASurfaces. | 223 // Allocated ids for VASurfaces. |
204 std::vector<VASurfaceID> va_surface_ids_; | 224 std::vector<VASurfaceID> va_surface_ids_; |
205 | 225 |
206 // The VAAPI version. | 226 // The VAAPI version. |
207 int major_version_, minor_version_; | 227 int major_version_, minor_version_; |
(...skipping 19 matching lines...) Expand all Loading... | |
227 // return values from public methods. | 247 // return values from public methods. |
228 base::Closure report_error_to_uma_cb_; | 248 base::Closure report_error_to_uma_cb_; |
229 | 249 |
230 // VPP (Video Post Processing) context, this is used to convert | 250 // VPP (Video Post Processing) context, this is used to convert |
231 // pictures used by the decoder to RGBA pictures usable by GL or the | 251 // pictures used by the decoder to RGBA pictures usable by GL or the |
232 // display hardware. | 252 // display hardware. |
233 VAConfigID va_vpp_config_id_; | 253 VAConfigID va_vpp_config_id_; |
234 VAContextID va_vpp_context_id_; | 254 VAContextID va_vpp_context_id_; |
235 VABufferID va_vpp_buffer_id_; | 255 VABufferID va_vpp_buffer_id_; |
236 | 256 |
257 // Initialize supported profiles once. | |
258 static bool is_initialize_profile_; | |
259 static ProfileConfig supported_profiles_[media::VIDEO_CODEC_PROFILE_MAX * 2]; | |
wuchengli
2015/02/02 09:01:07
Chromium way to do this is using base::LazyInstanc
kcwu
2015/02/02 10:11:02
Why not vector? if not vector, the size should be
henryhsu
2015/02/02 10:42:24
Static variables cannot use class object.
henryhsu
2015/02/13 04:01:03
Done.
henryhsu
2015/02/13 04:01:04
Done.
| |
260 | |
237 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); | 261 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); |
238 }; | 262 }; |
239 | 263 |
240 } // namespace content | 264 } // namespace content |
241 | 265 |
242 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ | 266 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ |
OLD | NEW |