Commit 4f26c551 authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

media: add VEA SupportedProfile |min_resolution|, wire for VA-API CrOs.

This CL adds a |min_resolution| field to VideoEncodeAcceleratorSupportedProfile
and propagates it from its source(s) in the GPU process, via the |gpu_info|
mojom interface definition, to its ultimate users: MediaRecorder and
RTCVideoEncoder (the latter is used for WebRTC's PeerConnection).

This new field is populated from VaapiWrapper to indicate that we should not
use it for small resolutions (currently 320x240); software encoding should
be used instead.

This CL also wires this new field in the chrome:gpu informational UI.

TEST=https://codepen.io/miguelao/pen/wzVMJb on nocturne (pixel slate),
enable logging and verify that MediaRecorder doesn't use the encode accelerator,
e.g. for 320x240 camera capture.

Bug: 1008491
Change-Id: Ifb19232ca5a5bbbde0ba42e1c28de72e46dafc5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1828078
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704018}
parent 92cc2483
...@@ -475,8 +475,9 @@ std::unique_ptr<base::ListValue> GetVideoAcceleratorsInfo() { ...@@ -475,8 +475,9 @@ std::unique_ptr<base::ListValue> GetVideoAcceleratorsInfo() {
std::string codec_string = std::string codec_string =
base::StringPrintf("Decode %s", GetProfileName(profile.profile)); base::StringPrintf("Decode %s", GetProfileName(profile.profile));
std::string resolution_string = base::StringPrintf( std::string resolution_string = base::StringPrintf(
"up to %s pixels %s", profile.max_resolution.ToString().c_str(), "%s to %s pixels%s", profile.min_resolution.ToString().c_str(),
profile.encrypted_only ? "(encrypted)" : ""); profile.max_resolution.ToString().c_str(),
profile.encrypted_only ? " (encrypted)" : "");
info->Append(NewDescriptionValuePair(codec_string, resolution_string)); info->Append(NewDescriptionValuePair(codec_string, resolution_string));
} }
...@@ -485,7 +486,8 @@ std::unique_ptr<base::ListValue> GetVideoAcceleratorsInfo() { ...@@ -485,7 +486,8 @@ std::unique_ptr<base::ListValue> GetVideoAcceleratorsInfo() {
std::string codec_string = std::string codec_string =
base::StringPrintf("Encode %s", GetProfileName(profile.profile)); base::StringPrintf("Encode %s", GetProfileName(profile.profile));
std::string resolution_string = base::StringPrintf( std::string resolution_string = base::StringPrintf(
"up to %s pixels and/or %.3f fps", "%s to %s pixels, and/or %.3f fps",
profile.min_resolution.ToString().c_str(),
profile.max_resolution.ToString().c_str(), profile.max_resolution.ToString().c_str(),
static_cast<double>(profile.max_framerate_numerator) / static_cast<double>(profile.max_framerate_numerator) /
profile.max_framerate_denominator); profile.max_framerate_denominator);
......
...@@ -46,6 +46,8 @@ void EnumerateVideoEncodeAcceleratorSupportedProfile( ...@@ -46,6 +46,8 @@ void EnumerateVideoEncodeAcceleratorSupportedProfile(
gpu::GPUInfo::Enumerator* enumerator) { gpu::GPUInfo::Enumerator* enumerator) {
enumerator->BeginVideoEncodeAcceleratorSupportedProfile(); enumerator->BeginVideoEncodeAcceleratorSupportedProfile();
enumerator->AddInt("profile", profile.profile); enumerator->AddInt("profile", profile.profile);
enumerator->AddInt("minResolutionWidth", profile.min_resolution.width());
enumerator->AddInt("minResolutionHeight", profile.min_resolution.height());
enumerator->AddInt("maxResolutionWidth", profile.max_resolution.width()); enumerator->AddInt("maxResolutionWidth", profile.max_resolution.width());
enumerator->AddInt("maxResolutionHeight", profile.max_resolution.height()); enumerator->AddInt("maxResolutionHeight", profile.max_resolution.height());
enumerator->AddInt("maxFramerateNumerator", profile.max_framerate_numerator); enumerator->AddInt("maxFramerateNumerator", profile.max_framerate_numerator);
......
...@@ -114,6 +114,7 @@ struct GPU_EXPORT VideoDecodeAcceleratorCapabilities { ...@@ -114,6 +114,7 @@ struct GPU_EXPORT VideoDecodeAcceleratorCapabilities {
// Specification of an encoding profile supported by a hardware encoder. // Specification of an encoding profile supported by a hardware encoder.
struct GPU_EXPORT VideoEncodeAcceleratorSupportedProfile { struct GPU_EXPORT VideoEncodeAcceleratorSupportedProfile {
VideoCodecProfile profile; VideoCodecProfile profile;
gfx::Size min_resolution;
gfx::Size max_resolution; gfx::Size max_resolution;
uint32_t max_framerate_numerator; uint32_t max_framerate_numerator;
uint32_t max_framerate_denominator; uint32_t max_framerate_denominator;
......
...@@ -76,6 +76,7 @@ struct VideoDecodeAcceleratorCapabilities { ...@@ -76,6 +76,7 @@ struct VideoDecodeAcceleratorCapabilities {
// gpu::VideoEncodeAcceleratorSupportedProfile // gpu::VideoEncodeAcceleratorSupportedProfile
struct VideoEncodeAcceleratorSupportedProfile { struct VideoEncodeAcceleratorSupportedProfile {
VideoCodecProfile profile; VideoCodecProfile profile;
gfx.mojom.Size min_resolution;
gfx.mojom.Size max_resolution; gfx.mojom.Size max_resolution;
uint32 max_framerate_numerator; uint32 max_framerate_numerator;
uint32 max_framerate_denominator; uint32 max_framerate_denominator;
......
...@@ -228,8 +228,9 @@ bool StructTraits<gpu::mojom::VideoEncodeAcceleratorSupportedProfileDataView, ...@@ -228,8 +228,9 @@ bool StructTraits<gpu::mojom::VideoEncodeAcceleratorSupportedProfileDataView,
gpu::VideoEncodeAcceleratorSupportedProfile* out) { gpu::VideoEncodeAcceleratorSupportedProfile* out) {
out->max_framerate_numerator = data.max_framerate_numerator(); out->max_framerate_numerator = data.max_framerate_numerator();
out->max_framerate_denominator = data.max_framerate_denominator(); out->max_framerate_denominator = data.max_framerate_denominator();
return data.ReadProfile(&out->profile) && return data.ReadMinResolution(&out->min_resolution) &&
data.ReadMaxResolution(&out->max_resolution); data.ReadMaxResolution(&out->max_resolution) &&
data.ReadProfile(&out->profile);
} }
// static // static
......
...@@ -131,6 +131,11 @@ struct StructTraits<gpu::mojom::VideoEncodeAcceleratorSupportedProfileDataView, ...@@ -131,6 +131,11 @@ struct StructTraits<gpu::mojom::VideoEncodeAcceleratorSupportedProfileDataView,
return input.profile; return input.profile;
} }
static const gfx::Size& min_resolution(
const gpu::VideoEncodeAcceleratorSupportedProfile& input) {
return input.min_resolution;
}
static const gfx::Size& max_resolution( static const gfx::Size& max_resolution(
const gpu::VideoEncodeAcceleratorSupportedProfile& input) { const gpu::VideoEncodeAcceleratorSupportedProfile& input) {
return input.max_resolution; return input.max_resolution;
......
...@@ -415,14 +415,15 @@ TEST_F(StructTraitsTest, VideoDecodeAcceleratorCapabilities) { ...@@ -415,14 +415,15 @@ TEST_F(StructTraitsTest, VideoDecodeAcceleratorCapabilities) {
} }
TEST_F(StructTraitsTest, VideoEncodeAcceleratorSupportedProfile) { TEST_F(StructTraitsTest, VideoEncodeAcceleratorSupportedProfile) {
const gpu::VideoCodecProfile profile = const gpu::VideoCodecProfile profile = VideoCodecProfile::H264PROFILE_MAIN;
gpu::VideoCodecProfile::H264PROFILE_MAIN; const gfx::Size min_resolution(320, 180);
const gfx::Size max_resolution(1920, 1080); const gfx::Size max_resolution(1920, 1080);
const uint32_t max_framerate_numerator = 144; const uint32_t max_framerate_numerator = 144;
const uint32_t max_framerate_denominator = 12; const uint32_t max_framerate_denominator = 12;
gpu::VideoEncodeAcceleratorSupportedProfile input; gpu::VideoEncodeAcceleratorSupportedProfile input;
input.profile = profile; input.profile = profile;
input.min_resolution = min_resolution;
input.max_resolution = max_resolution; input.max_resolution = max_resolution;
input.max_framerate_numerator = max_framerate_numerator; input.max_framerate_numerator = max_framerate_numerator;
input.max_framerate_denominator = max_framerate_denominator; input.max_framerate_denominator = max_framerate_denominator;
...@@ -431,6 +432,7 @@ TEST_F(StructTraitsTest, VideoEncodeAcceleratorSupportedProfile) { ...@@ -431,6 +432,7 @@ TEST_F(StructTraitsTest, VideoEncodeAcceleratorSupportedProfile) {
gpu::VideoEncodeAcceleratorSupportedProfile output; gpu::VideoEncodeAcceleratorSupportedProfile output;
proxy->EchoVideoEncodeAcceleratorSupportedProfile(input, &output); proxy->EchoVideoEncodeAcceleratorSupportedProfile(input, &output);
EXPECT_EQ(profile, output.profile); EXPECT_EQ(profile, output.profile);
EXPECT_EQ(min_resolution, output.min_resolution);
EXPECT_EQ(max_resolution, output.max_resolution); EXPECT_EQ(max_resolution, output.max_resolution);
EXPECT_EQ(max_framerate_numerator, output.max_framerate_numerator); EXPECT_EQ(max_framerate_numerator, output.max_framerate_numerator);
EXPECT_EQ(max_framerate_denominator, output.max_framerate_denominator); EXPECT_EQ(max_framerate_denominator, output.max_framerate_denominator);
......
...@@ -101,6 +101,7 @@ GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles( ...@@ -101,6 +101,7 @@ GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles(
for (const auto& gpu_profile : gpu_profiles) { for (const auto& gpu_profile : gpu_profiles) {
VideoEncodeAccelerator::SupportedProfile profile; VideoEncodeAccelerator::SupportedProfile profile;
profile.profile = static_cast<VideoCodecProfile>(gpu_profile.profile); profile.profile = static_cast<VideoCodecProfile>(gpu_profile.profile);
profile.min_resolution = gpu_profile.min_resolution;
profile.max_resolution = gpu_profile.max_resolution; profile.max_resolution = gpu_profile.max_resolution;
profile.max_framerate_numerator = gpu_profile.max_framerate_numerator; profile.max_framerate_numerator = gpu_profile.max_framerate_numerator;
profile.max_framerate_denominator = gpu_profile.max_framerate_denominator; profile.max_framerate_denominator = gpu_profile.max_framerate_denominator;
...@@ -118,6 +119,7 @@ GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles( ...@@ -118,6 +119,7 @@ GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(
gpu::VideoEncodeAcceleratorSupportedProfile profile; gpu::VideoEncodeAcceleratorSupportedProfile profile;
profile.profile = profile.profile =
static_cast<gpu::VideoCodecProfile>(media_profile.profile); static_cast<gpu::VideoCodecProfile>(media_profile.profile);
profile.min_resolution = media_profile.min_resolution;
profile.max_resolution = media_profile.max_resolution; profile.max_resolution = media_profile.max_resolution;
profile.max_framerate_numerator = media_profile.max_framerate_numerator; profile.max_framerate_numerator = media_profile.max_framerate_numerator;
profile.max_framerate_denominator = media_profile.max_framerate_denominator; profile.max_framerate_denominator = media_profile.max_framerate_denominator;
......
...@@ -1094,6 +1094,10 @@ VaapiWrapper::GetSupportedEncodeProfiles() { ...@@ -1094,6 +1094,10 @@ VaapiWrapper::GetSupportedEncodeProfiles() {
if (profile_info.va_profile == va_profile) { if (profile_info.va_profile == va_profile) {
VideoEncodeAccelerator::SupportedProfile profile; VideoEncodeAccelerator::SupportedProfile profile;
profile.profile = kProfileMap[i].profile; profile.profile = kProfileMap[i].profile;
// Using VA-API for accelerated encoding frames smaller than a certain
// size is less efficient than using a software encoder.
const gfx::Size kMinEncodeResolution = gfx::Size(320 + 1, 240 + 1);
profile.min_resolution = kMinEncodeResolution;
profile.max_resolution = profile_info.max_resolution; profile.max_resolution = profile_info.max_resolution;
profile.max_framerate_numerator = kMaxEncoderFramerate; profile.max_framerate_numerator = kMaxEncoderFramerate;
profile.max_framerate_denominator = 1; profile.max_framerate_denominator = 1;
......
...@@ -77,6 +77,7 @@ class MEDIA_EXPORT VideoEncodeAccelerator { ...@@ -77,6 +77,7 @@ class MEDIA_EXPORT VideoEncodeAccelerator {
uint32_t max_framerate_denominator = 1u); uint32_t max_framerate_denominator = 1u);
~SupportedProfile(); ~SupportedProfile();
VideoCodecProfile profile; VideoCodecProfile profile;
gfx::Size min_resolution;
gfx::Size max_resolution; gfx::Size max_resolution;
uint32_t max_framerate_numerator; uint32_t max_framerate_numerator;
uint32_t max_framerate_denominator; uint32_t max_framerate_denominator;
......
...@@ -125,6 +125,8 @@ VideoTrackRecorder::CodecEnumerator::CodecEnumerator( ...@@ -125,6 +125,8 @@ VideoTrackRecorder::CodecEnumerator::CodecEnumerator(
if (codec >= codec_id_and_profile.min_profile && if (codec >= codec_id_and_profile.min_profile &&
codec <= codec_id_and_profile.max_profile) { codec <= codec_id_and_profile.max_profile) {
DVLOG(2) << "Accelerated codec found: " << media::GetProfileName(codec) DVLOG(2) << "Accelerated codec found: " << media::GetProfileName(codec)
<< ", min_resolution: "
<< supported_profile.min_resolution.ToString()
<< ", max_resolution: " << ", max_resolution: "
<< supported_profile.max_resolution.ToString() << supported_profile.max_resolution.ToString()
<< ", max_framerate: " << ", max_framerate: "
...@@ -414,16 +416,20 @@ bool VideoTrackRecorder::CanUseAcceleratedEncoder(CodecId codec, ...@@ -414,16 +416,20 @@ bool VideoTrackRecorder::CanUseAcceleratedEncoder(CodecId codec,
if (profile.profile == media::VIDEO_CODEC_PROFILE_UNKNOWN) if (profile.profile == media::VIDEO_CODEC_PROFILE_UNKNOWN)
return false; return false;
const gfx::Size& min_resolution = profile.min_resolution;
const size_t min_width = static_cast<size_t>(
std::max(kVEAEncoderMinResolutionWidth, min_resolution.width()));
const size_t min_height = static_cast<size_t>(
std::max(kVEAEncoderMinResolutionHeight, min_resolution.height()));
const gfx::Size& max_resolution = profile.max_resolution; const gfx::Size& max_resolution = profile.max_resolution;
DCHECK_GE(max_resolution.width(), 0); DCHECK_GE(max_resolution.width(), 0);
const size_t max_width = static_cast<size_t>(max_resolution.width()); const size_t max_width = static_cast<size_t>(max_resolution.width());
DCHECK_GE(max_resolution.height(), 0); DCHECK_GE(max_resolution.height(), 0);
const size_t max_height = static_cast<size_t>(max_resolution.height()); const size_t max_height = static_cast<size_t>(max_resolution.height());
const bool width_within_range = const bool width_within_range = max_width >= width && width >= min_width;
max_width >= width && width >= kVEAEncoderMinResolutionWidth; const bool height_within_range = max_height >= height && height >= min_height;
const bool height_within_range =
max_height >= height && height >= kVEAEncoderMinResolutionHeight;
const bool valid_framerate = framerate * profile.max_framerate_denominator <= const bool valid_framerate = framerate * profile.max_framerate_denominator <=
profile.max_framerate_numerator; profile.max_framerate_numerator;
return width_within_range && height_within_range && valid_framerate; return width_within_range && height_within_range && valid_framerate;
......
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