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

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

Issue 1882373004: Migrate content/common/gpu/media code to media/gpu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix several more bot-identified build issues Created 4 years, 8 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 MEDIA_GPU_VAAPI_WRAPPER_H_
11 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 11 #define MEDIA_GPU_VAAPI_WRAPPER_H_
12 12
13 #include <stddef.h> 13 #include <stddef.h>
14 #include <stdint.h> 14 #include <stdint.h>
15 15
16 #include <set> 16 #include <set>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/files/file.h" 19 #include "base/files/file.h"
20 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/memory/ref_counted.h" 22 #include "base/memory/ref_counted.h"
23 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
24 #include "content/common/content_export.h"
25 #include "content/common/gpu/media/va_surface.h"
26 #include "media/base/video_decoder_config.h" 24 #include "media/base/video_decoder_config.h"
27 #include "media/base/video_frame.h" 25 #include "media/base/video_frame.h"
26 #include "media/gpu/media_gpu_export.h"
27 #include "media/gpu/va_surface.h"
28 #include "media/video/jpeg_decode_accelerator.h" 28 #include "media/video/jpeg_decode_accelerator.h"
29 #include "media/video/video_decode_accelerator.h" 29 #include "media/video/video_decode_accelerator.h"
30 #include "media/video/video_encode_accelerator.h" 30 #include "media/video/video_encode_accelerator.h"
31 #include "third_party/libva/va/va.h" 31 #include "third_party/libva/va/va.h"
32 #include "third_party/libva/va/va_vpp.h" 32 #include "third_party/libva/va/va_vpp.h"
33 #include "ui/gfx/geometry/size.h" 33 #include "ui/gfx/geometry/size.h"
34
34 #if defined(USE_X11) 35 #if defined(USE_X11)
35 #include "third_party/libva/va/va_x11.h" 36 #include "third_party/libva/va/va_x11.h"
36 #endif // USE_X11 37 #endif // USE_X11
37 38
38 #if defined(USE_OZONE) 39 #if defined(USE_OZONE)
39 namespace ui { 40 namespace ui {
40 class NativePixmap; 41 class NativePixmap;
41 } 42 }
42 #endif 43 #endif
43 44
44 namespace content { 45 namespace media {
45 46
46 // This class handles VA-API calls and ensures proper locking of VA-API calls 47 // This class handles VA-API calls and ensures proper locking of VA-API calls
47 // to libva, the userspace shim to the HW codec driver. libva is not 48 // to libva, the userspace shim to the HW codec driver. libva is not
48 // thread-safe, so we have to perform locking ourselves. This class is fully 49 // thread-safe, so we have to perform locking ourselves. This class is fully
49 // synchronous and its methods can be called from any thread and may wait on 50 // synchronous and its methods can be called from any thread and may wait on
50 // the va_lock_ while other, concurrent calls run. 51 // the va_lock_ while other, concurrent calls run.
51 // 52 //
52 // This class is responsible for managing VAAPI connection, contexts and state. 53 // This class is responsible for managing VAAPI connection, contexts and state.
53 // It is also responsible for managing and freeing VABuffers (not VASurfaces), 54 // It is also responsible for managing and freeing VABuffers (not VASurfaces),
54 // which are used to queue parameters and slice data to the HW codec, 55 // which are used to queue parameters and slice data to the HW codec,
55 // as well as underlying memory for VASurfaces themselves. 56 // as well as underlying memory for VASurfaces themselves.
56 class CONTENT_EXPORT VaapiWrapper 57 class MEDIA_GPU_EXPORT VaapiWrapper
57 : public base::RefCountedThreadSafe<VaapiWrapper> { 58 : public base::RefCountedThreadSafe<VaapiWrapper> {
58 public: 59 public:
59 enum CodecMode { 60 enum CodecMode {
60 kDecode, 61 kDecode,
61 kEncode, 62 kEncode,
62 kCodecModeMax, 63 kCodecModeMax,
63 }; 64 };
64 65
65 // Return an instance of VaapiWrapper initialized for |va_profile| and 66 // Return an instance of VaapiWrapper initialized for |va_profile| and
66 // |mode|. |report_error_to_uma_cb| will be called independently from 67 // |mode|. |report_error_to_uma_cb| will be called independently from
67 // reporting errors to clients via method return values. 68 // reporting errors to clients via method return values.
68 static scoped_refptr<VaapiWrapper> Create( 69 static scoped_refptr<VaapiWrapper> Create(
69 CodecMode mode, 70 CodecMode mode,
70 VAProfile va_profile, 71 VAProfile va_profile,
71 const base::Closure& report_error_to_uma_cb); 72 const base::Closure& report_error_to_uma_cb);
72 73
73 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile 74 // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile
74 // |profile| to VAProfile. 75 // |profile| to VAProfile.
75 // |report_error_to_uma_cb| will be called independently from reporting 76 // |report_error_to_uma_cb| will be called independently from reporting
76 // errors to clients via method return values. 77 // errors to clients via method return values.
77 static scoped_refptr<VaapiWrapper> CreateForVideoCodec( 78 static scoped_refptr<VaapiWrapper> CreateForVideoCodec(
78 CodecMode mode, 79 CodecMode mode,
79 media::VideoCodecProfile profile, 80 media::VideoCodecProfile profile,
80 const base::Closure& report_error_to_uma_cb); 81 const base::Closure& report_error_to_uma_cb);
81 82
82 // Return the supported video encode profiles. 83 // Return the supported video encode profiles.
83 static media::VideoEncodeAccelerator::SupportedProfiles 84 static media::VideoEncodeAccelerator::SupportedProfiles
84 GetSupportedEncodeProfiles(); 85 GetSupportedEncodeProfiles();
85 86
86 // Return the supported video decode profiles. 87 // Return the supported video decode profiles.
87 static media::VideoDecodeAccelerator::SupportedProfiles 88 static media::VideoDecodeAccelerator::SupportedProfiles
88 GetSupportedDecodeProfiles(); 89 GetSupportedDecodeProfiles();
89 90
90 // Return true when JPEG decode is supported. 91 // Return true when JPEG decode is supported.
91 static bool IsJpegDecodeSupported(); 92 static bool IsJpegDecodeSupported();
92 93
93 // Create |num_surfaces| backing surfaces in driver for VASurfaces of 94 // Create |num_surfaces| backing surfaces in driver for VASurfaces of
94 // |va_format|, each of size |size|. Returns true when successful, with the 95 // |va_format|, each of size |size|. Returns true when successful, with the
95 // created IDs in |va_surfaces| to be managed and later wrapped in 96 // created IDs in |va_surfaces| to be managed and later wrapped in
96 // VASurfaces. 97 // VASurfaces.
97 // The client must DestroySurfaces() each time before calling this method 98 // The client must DestroySurfaces() each time before calling this method
98 // again to free the allocated surfaces first, but is not required to do so 99 // again to free the allocated surfaces first, but is not required to do so
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Return true if |va_profile| for |entrypoint| with |required_attribs| is 303 // Return true if |va_profile| for |entrypoint| with |required_attribs| is
303 // supported. |va_lock_| must be held on entry. 304 // supported. |va_lock_| must be held on entry.
304 bool AreAttribsSupported_Locked( 305 bool AreAttribsSupported_Locked(
305 VAProfile va_profile, 306 VAProfile va_profile,
306 VAEntrypoint entrypoint, 307 VAEntrypoint entrypoint,
307 const std::vector<VAConfigAttrib>& required_attribs); 308 const std::vector<VAConfigAttrib>& required_attribs);
308 309
309 // Get maximum resolution for |va_profile| and |entrypoint| with 310 // Get maximum resolution for |va_profile| and |entrypoint| with
310 // |required_attribs|. If return value is true, |resolution| is the maximum 311 // |required_attribs|. If return value is true, |resolution| is the maximum
311 // resolution. |va_lock_| must be held on entry. 312 // resolution. |va_lock_| must be held on entry.
312 bool GetMaxResolution_Locked( 313 bool GetMaxResolution_Locked(VAProfile va_profile,
313 VAProfile va_profile, 314 VAEntrypoint entrypoint,
314 VAEntrypoint entrypoint, 315 std::vector<VAConfigAttrib>& required_attribs,
315 std::vector<VAConfigAttrib>& required_attribs, 316 gfx::Size* resolution);
316 gfx::Size* resolution);
317 317
318 // Destroys a |va_surface| created using CreateUnownedSurface. 318 // Destroys a |va_surface| created using CreateUnownedSurface.
319 void DestroyUnownedSurface(VASurfaceID va_surface_id); 319 void DestroyUnownedSurface(VASurfaceID va_surface_id);
320 320
321 // Initialize the video post processing context with the |size| of 321 // Initialize the video post processing context with the |size| of
322 // the input pictures to be processed. 322 // the input pictures to be processed.
323 bool InitializeVpp_Locked(); 323 bool InitializeVpp_Locked();
324 324
325 // Deinitialize the video post processing context. 325 // Deinitialize the video post processing context.
326 void DeinitializeVpp(); 326 void DeinitializeVpp();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 VAContextID va_vpp_context_id_; 386 VAContextID va_vpp_context_id_;
387 VABufferID va_vpp_buffer_id_; 387 VABufferID va_vpp_buffer_id_;
388 388
389 // Singleton variable to store supported profile information for encode and 389 // Singleton variable to store supported profile information for encode and
390 // decode. 390 // decode.
391 static base::LazyInstance<LazyProfileInfos> profile_infos_; 391 static base::LazyInstance<LazyProfileInfos> profile_infos_;
392 392
393 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); 393 DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
394 }; 394 };
395 395
396 } // namespace content 396 } // namespace media
397 397
398 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_WRAPPER_H_ 398 #endif // MEDIA_GPU_VAAPI_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698