Commit a598f3ad authored by henryhsu's avatar henryhsu Committed by Commit bot

VaapiVEA: Get maximum resolution from libva

Add GetMaxResolutionForVAConfigID function to get hardware supported maximum
resolution for video encode and decode. This is also the preparation of
removing --ignore-resolution-limits-for-accelerated-video-decode flag.
Because this function uses va_config_id as parameter, we refactor
vaapi_wrapper and add LazyInstance to initialize supported profile
infos once and reuse it in Initialize and GetSupportedEncodeProfiles
functions.

BUG=350197
TEST=Test on squawks, and lumpy. Make sure this function works well.

Review URL: https://codereview.chromium.org/872623002

Cr-Commit-Position: refs/heads/master@{#319842}
parent 9088980b
...@@ -28,6 +28,7 @@ int vaMaxNumEntrypoints (VADisplay dpy); ...@@ -28,6 +28,7 @@ int vaMaxNumEntrypoints (VADisplay dpy);
int vaMaxNumProfiles(VADisplay dpy); int vaMaxNumProfiles(VADisplay dpy);
VAStatus vaQueryConfigEntrypoints (VADisplay dpy, VAProfile profile, VAEntrypoint *entrypoint_list, int *num_entrypoints); VAStatus vaQueryConfigEntrypoints (VADisplay dpy, VAProfile profile, VAEntrypoint *entrypoint_list, int *num_entrypoints);
VAStatus vaQueryConfigProfiles(VADisplay dpy, VAProfile *profile_list, int *num_profiles); VAStatus vaQueryConfigProfiles(VADisplay dpy, VAProfile *profile_list, int *num_profiles);
VAStatus vaQuerySurfaceAttributes(VADisplay dpy, VAConfigID config, VASurfaceAttrib *attrib_list, unsigned int *num_attribs);
VAStatus vaRenderPicture(VADisplay dpy, VAContextID context, VABufferID *buffers, int num_buffers); VAStatus vaRenderPicture(VADisplay dpy, VAContextID context, VABufferID *buffers, int num_buffers);
VAStatus vaSetDisplayAttributes(VADisplay dpy, VADisplayAttribute *attr_list, int num_attributes); VAStatus vaSetDisplayAttributes(VADisplay dpy, VADisplayAttribute *attr_list, int num_attributes);
VAStatus vaSyncSurface(VADisplay dpy, VASurfaceID render_target); VAStatus vaSyncSurface(VADisplay dpy, VASurfaceID render_target);
......
...@@ -6,12 +6,10 @@ ...@@ -6,12 +6,10 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "content/common/gpu/media/h264_dpb.h" #include "content/common/gpu/media/h264_dpb.h"
#include "content/public/common/content_switches.h"
#include "media/base/bind_to_current_loop.h" #include "media/base/bind_to_current_loop.h"
#include "third_party/libva/va/va_enc_h264.h" #include "third_party/libva/va/va_enc_h264.h"
...@@ -107,24 +105,8 @@ struct VaapiVideoEncodeAccelerator::BitstreamBufferRef { ...@@ -107,24 +105,8 @@ struct VaapiVideoEncodeAccelerator::BitstreamBufferRef {
std::vector<media::VideoEncodeAccelerator::SupportedProfile> std::vector<media::VideoEncodeAccelerator::SupportedProfile>
VaapiVideoEncodeAccelerator::GetSupportedProfiles() { VaapiVideoEncodeAccelerator::GetSupportedProfiles() {
std::vector<SupportedProfile> profiles;
return VaapiWrapper::GetSupportedEncodeProfiles();
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode))
return profiles;
std::vector<media::VideoCodecProfile> hw_profiles =
VaapiWrapper::GetSupportedEncodeProfiles(base::Bind(&base::DoNothing));
media::VideoEncodeAccelerator::SupportedProfile profile;
profile.max_resolution.SetSize(1920, 1088);
profile.max_framerate_numerator = kDefaultFramerate;
profile.max_framerate_denominator = 1;
for (size_t i = 0; i < hw_profiles.size(); i++) {
profile.profile = hw_profiles[i];
profiles.push_back(profile);
}
return profiles;
} }
static unsigned int Log2OfPowerOf2(unsigned int x) { static unsigned int Log2OfPowerOf2(unsigned int x) {
......
This diff is collapsed.
...@@ -13,12 +13,14 @@ ...@@ -13,12 +13,14 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include "base/lazy_instance.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/gpu/media/va_surface.h" #include "content/common/gpu/media/va_surface.h"
#include "media/base/video_decoder_config.h" #include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "media/video/video_encode_accelerator.h"
#include "third_party/libva/va/va.h" #include "third_party/libva/va/va.h"
#include "third_party/libva/va/va_vpp.h" #include "third_party/libva/va/va_vpp.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -43,14 +45,15 @@ class CONTENT_EXPORT VaapiWrapper { ...@@ -43,14 +45,15 @@ class CONTENT_EXPORT VaapiWrapper {
enum CodecMode { enum CodecMode {
kDecode, kDecode,
kEncode, kEncode,
kCodecModeMax,
}; };
// Create VaapiWrapper for VAProfile. // Return an instance of VaapiWrapper initialized for |va_profile| and
// |report_error_to_uma_cb| will be called independently from reporting // |mode|. |report_error_to_uma_cb| will be called independently from
// errors to clients via method return values. // reporting errors to clients via method return values.
static scoped_ptr<VaapiWrapper> Create( static scoped_ptr<VaapiWrapper> Create(
CodecMode mode, CodecMode mode,
VAProfile profile, VAProfile va_profile,
const base::Closure& report_error_to_uma_cb); const base::Closure& report_error_to_uma_cb);
// Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile // Create VaapiWrapper for VideoCodecProfile. It maps VideoCodecProfile
...@@ -63,8 +66,8 @@ class CONTENT_EXPORT VaapiWrapper { ...@@ -63,8 +66,8 @@ class CONTENT_EXPORT VaapiWrapper {
const base::Closure& report_error_to_uma_cb); const base::Closure& report_error_to_uma_cb);
// Return the supported encode profiles. // Return the supported encode profiles.
static std::vector<media::VideoCodecProfile> GetSupportedEncodeProfiles( static std::vector<media::VideoEncodeAccelerator::SupportedProfile>
const base::Closure& report_error_to_uma_cb); GetSupportedEncodeProfiles();
~VaapiWrapper(); ~VaapiWrapper();
...@@ -183,16 +186,50 @@ class CONTENT_EXPORT VaapiWrapper { ...@@ -183,16 +186,50 @@ class CONTENT_EXPORT VaapiWrapper {
const gfx::Size& dest_size); const gfx::Size& dest_size);
private: private:
struct ProfileInfo {
VAProfile va_profile;
gfx::Size max_resolution;
};
class LazyProfileInfos {
public:
LazyProfileInfos();
~LazyProfileInfos();
std::vector<ProfileInfo> GetSupportedProfileInfosForCodecMode(
CodecMode mode);
bool IsProfileSupported(CodecMode mode, VAProfile va_profile);
private:
std::vector<ProfileInfo> supported_profiles_[kCodecModeMax];
};
VaapiWrapper(); VaapiWrapper();
bool Initialize(CodecMode mode, VAProfile va_profile); bool Initialize(CodecMode mode, VAProfile va_profile);
void Deinitialize(); void Deinitialize();
bool VaInitialize(const base::Closure& report_error_to_uma_cb); bool VaInitialize(const base::Closure& report_error_to_uma_cb);
bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles); bool GetSupportedVaProfiles(std::vector<VAProfile>* profiles);
bool IsEntrypointSupported(VAProfile va_profile, VAEntrypoint entrypoint);
bool AreAttribsSupported(VAProfile va_profile, // Check if |va_profile| supports |entrypoint| or not. |va_lock_| must be
VAEntrypoint entrypoint, // held on entry.
const std::vector<VAConfigAttrib>& required_attribs); bool IsEntrypointSupported_Locked(VAProfile va_profile,
VAEntrypoint entrypoint);
// Return true if |va_profile| for |entrypoint| with |required_attribs| is
// supported. |va_lock_| must be held on entry.
bool AreAttribsSupported_Locked(
VAProfile va_profile,
VAEntrypoint entrypoint,
const std::vector<VAConfigAttrib>& required_attribs);
// Get maximum resolution for |va_profile| and |entrypoint| with
// |required_attribs|. If return value is true, |resolution| is the maximum
// resolution. |va_lock_| must be held on entry.
bool GetMaxResolution_Locked(
VAProfile va_profile,
VAEntrypoint entrypoint,
std::vector<VAConfigAttrib>& required_attribs,
gfx::Size* resolution);
// Destroys a |va_surface| created using CreateUnownedSurface. // Destroys a |va_surface| created using CreateUnownedSurface.
void DestroyUnownedSurface(VASurfaceID va_surface_id); void DestroyUnownedSurface(VASurfaceID va_surface_id);
...@@ -212,10 +249,20 @@ class CONTENT_EXPORT VaapiWrapper { ...@@ -212,10 +249,20 @@ class CONTENT_EXPORT VaapiWrapper {
// Attempt to set render mode to "render to texture.". Failure is non-fatal. // Attempt to set render mode to "render to texture.". Failure is non-fatal.
void TryToSetVADisplayAttributeToLocalGPU(); void TryToSetVADisplayAttributeToLocalGPU();
// Get supported profile infos for |mode|.
std::vector<ProfileInfo> GetSupportedProfileInfosForCodecModeInternal(
CodecMode mode);
// Lazily initialize static data after sandbox is enabled. Return false on // Lazily initialize static data after sandbox is enabled. Return false on
// init failure. // init failure.
static bool PostSandboxInitialization(); static bool PostSandboxInitialization();
// Map VideoCodecProfile enum values to VaProfile values. This function
// includes a workaround for crbug.com/345569. If va_profile is h264 baseline
// and it is not supported, we try constrained baseline.
static VAProfile ProfileToVAProfile(media::VideoCodecProfile profile,
CodecMode mode);
// Libva is not thread safe, so we have to do locking for it ourselves. // Libva is not thread safe, so we have to do locking for it ourselves.
// This lock is to be taken for the duration of all VA-API calls and for // This lock is to be taken for the duration of all VA-API calls and for
// the entire job submission sequence in ExecuteAndDestroyPendingBuffers(). // the entire job submission sequence in ExecuteAndDestroyPendingBuffers().
...@@ -255,6 +302,10 @@ class CONTENT_EXPORT VaapiWrapper { ...@@ -255,6 +302,10 @@ class CONTENT_EXPORT VaapiWrapper {
VAContextID va_vpp_context_id_; VAContextID va_vpp_context_id_;
VABufferID va_vpp_buffer_id_; VABufferID va_vpp_buffer_id_;
// Singleton variable to store supported profile information for encode and
// decode.
static base::LazyInstance<LazyProfileInfos> profile_infos_;
DISALLOW_COPY_AND_ASSIGN(VaapiWrapper); DISALLOW_COPY_AND_ASSIGN(VaapiWrapper);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment