Commit 02b026de authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/video_encode_accelerator_tests: Settle target bitrate by the video...

media/gpu/video_encode_accelerator_tests: Settle target bitrate by the video resolution and framerate

Originally video_encode_accelerator_tests tests a fixed bitrate
with any video. This enables to settle a good bitrate for testing
by determining it by the resolution and frame rate of a test
video.

Bug: 1045825
Test: video_encode_accelerator_tests on atlas
Change-Id: I129158cf0e877a0d06ce304f201c01969abd3be0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2325671
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796876}
parent f16fa327
......@@ -44,8 +44,10 @@ void CallbackThunk(
VideoEncoderClientConfig::VideoEncoderClientConfig(
const Video* video,
VideoCodecProfile output_profile)
VideoCodecProfile output_profile,
uint32_t bitrate)
: output_profile(output_profile),
bitrate(bitrate),
framerate(video->FrameRate()),
num_frames_to_encode(video->NumFrames()) {}
......
......@@ -34,8 +34,10 @@ class AlignedDataHelper;
// Video encoder client configuration.
// TODO(dstaessens): Add extra parameters (e.g. h264 output level)
struct VideoEncoderClientConfig {
static constexpr uint32_t kDefaultBitrate = 200000;
VideoEncoderClientConfig(const Video* video,
VideoCodecProfile output_profile);
VideoCodecProfile output_profile,
uint32_t bitrate = kDefaultBitrate);
VideoEncoderClientConfig(const VideoEncoderClientConfig&);
// The output output profile to be used.
......@@ -44,7 +46,7 @@ struct VideoEncoderClientConfig {
// without waiting for the result of the previous encodes requests.
size_t max_outstanding_encode_requests = 1;
// The desired bitrate in bits/second.
uint32_t bitrate = 200000;
uint32_t bitrate = kDefaultBitrate;
// The desired framerate in frames/second.
uint32_t framerate = 30.0;
// The number of frames to be encoded. This can be more than the number of
......
......@@ -46,6 +46,39 @@ const std::vector<base::Feature> kDisabledFeaturesForVideoEncoderTest = {
// decode any vp8 stream in BitstreamValidator.
kFFmpegDecodeOpaqueVP8,
};
uint32_t GetDefaultTargetBitrate(const gfx::Size& resolution,
const uint32_t framerate) {
constexpr uint32_t Mbps = 1000 * 1000;
// The half of video bitrates recommended by YouTube for 16:9 SDR 30fps video.
// (https://support.google.com/youtube/answer/1722171). Dividing them by 2 is
// to tune for video call apps, which are most frequent use scenarios of video
// encoders.
// The bitrates don't scale linearly so we use the following lookup table as a
// base for computing a reasonable bitrate for the specified resolution and
// framerate.
constexpr struct {
gfx::Size resolution;
uint32_t bitrate;
} kDefaultTargetBitrates[] = {
{gfx::Size(640, 360), 0.5 * Mbps}, {gfx::Size(854, 480), 1.25 * Mbps},
{gfx::Size(1280, 720), 2.5 * Mbps}, {gfx::Size(1920, 1080), 4 * Mbps},
{gfx::Size(2560, 1440), 8 * Mbps}, {gfx::Size(3840, 2160), 18 * Mbps},
};
const auto* it = std::find_if(
std::cbegin(kDefaultTargetBitrates), std::cend(kDefaultTargetBitrates),
[resolution](const auto& target_bitrate) {
return resolution.GetArea() <= target_bitrate.resolution.GetArea();
});
LOG_ASSERT(it != std::cend(kDefaultTargetBitrates))
<< "Target bitrate for the resolution is not found, resolution="
<< resolution.ToString();
const double resolution_ratio =
(resolution.GetArea() / static_cast<double>(it->resolution.GetArea()));
const double framerate_ratio = framerate > 30 ? 1.5 : 1.0;
return it->bitrate * resolution_ratio * framerate_ratio;
}
} // namespace
// static
......@@ -94,10 +127,12 @@ VideoEncoderTestEnvironment* VideoEncoderTestEnvironment::Create(
return nullptr;
}
const uint32_t bitrate =
GetDefaultTargetBitrate(video->Resolution(), video->FrameRate());
VideoCodecProfile profile = it->profile;
return new VideoEncoderTestEnvironment(
std::move(video), enable_bitstream_validator, output_folder, profile,
save_output_bitstream, frame_output_config);
bitrate, save_output_bitstream, frame_output_config);
}
VideoEncoderTestEnvironment::VideoEncoderTestEnvironment(
......@@ -105,6 +140,7 @@ VideoEncoderTestEnvironment::VideoEncoderTestEnvironment(
bool enable_bitstream_validator,
const base::FilePath& output_folder,
VideoCodecProfile profile,
uint32_t bitrate,
bool save_output_bitstream,
const FrameOutputConfig& frame_output_config)
: VideoTestEnvironment(kEnabledFeaturesForVideoEncoderTest,
......@@ -113,6 +149,7 @@ VideoEncoderTestEnvironment::VideoEncoderTestEnvironment(
enable_bitstream_validator_(enable_bitstream_validator),
output_folder_(output_folder),
profile_(profile),
bitrate_(bitrate),
save_output_bitstream_(save_output_bitstream),
frame_output_config_(frame_output_config),
gpu_memory_buffer_factory_(
......@@ -136,6 +173,10 @@ VideoCodecProfile VideoEncoderTestEnvironment::Profile() const {
return profile_;
}
uint32_t VideoEncoderTestEnvironment::Bitrate() const {
return bitrate_;
}
bool VideoEncoderTestEnvironment::SaveOutputBitstream() const {
return save_output_bitstream_;
}
......
......@@ -45,6 +45,8 @@ class VideoEncoderTestEnvironment : public VideoTestEnvironment {
const base::FilePath& OutputFolder() const;
// Get the output codec profile.
VideoCodecProfile Profile() const;
// Get the target bitrate (bits/second).
uint32_t Bitrate() const;
// Whether the encoded bitstream is saved to disk.
bool SaveOutputBitstream() const;
base::Optional<base::FilePath> OutputBitstreamFilePath() const;
......@@ -62,6 +64,7 @@ class VideoEncoderTestEnvironment : public VideoTestEnvironment {
bool enable_bitstream_validator,
const base::FilePath& output_folder,
VideoCodecProfile profile,
uint32_t bitrate,
bool save_output_bitstream,
const FrameOutputConfig& frame_output_config);
......@@ -73,6 +76,8 @@ class VideoEncoderTestEnvironment : public VideoTestEnvironment {
const base::FilePath output_folder_;
// VideoCodecProfile to be produced by VideoEncoder.
const VideoCodecProfile profile_;
// Targeted bitrate (bits/second) of the stream produced by VideoEncoder.
const uint32_t bitrate_;
// Whether the bitstream produced by VideoEncoder is saved to disk.
const bool save_output_bitstream_;
// The configuration about saving decoded images of bitstream encoded by
......
......@@ -223,7 +223,8 @@ class VideoEncoderTest : public ::testing::Test {
// Encode video from start to end. Wait for the kFlushDone event at the end of
// the stream, that notifies us all frames have been encoded.
TEST_F(VideoEncoderTest, FlushAtEndOfStream) {
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile());
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile(),
g_env->Bitrate());
auto encoder = CreateVideoEncoder(g_env->Video(), config);
encoder->Encode();
......@@ -239,7 +240,8 @@ TEST_F(VideoEncoderTest, FlushAtEndOfStream) {
// resolution. The test only verifies initialization and doesn't do any
// encoding.
TEST_F(VideoEncoderTest, Initialize) {
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile());
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile(),
g_env->Bitrate());
auto encoder = CreateVideoEncoder(g_env->Video(), config);
EXPECT_EQ(encoder->GetEventCount(VideoEncoder::kInitialized), 1u);
......@@ -250,7 +252,8 @@ TEST_F(VideoEncoderTest, Initialize) {
// of scope at the end of the test. The test will pass if no asserts or crashes
// are triggered upon destroying.
TEST_F(VideoEncoderTest, DestroyBeforeInitialize) {
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile());
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile(),
g_env->Bitrate());
auto video_encoder =
VideoEncoder::Create(config, g_env->GetGpuMemoryBufferFactory());
......@@ -277,7 +280,8 @@ TEST_F(VideoEncoderTest, FlushAtEndOfStream_MultipleConcurrentEncodes) {
// The minimal number of concurrent encoders we expect to be supported.
constexpr size_t kMinSupportedConcurrentEncoders = 3;
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile());
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile(),
g_env->Bitrate());
std::vector<std::unique_ptr<VideoEncoder>> encoders(
kMinSupportedConcurrentEncoders);
for (size_t i = 0; i < kMinSupportedConcurrentEncoders; ++i)
......@@ -296,7 +300,8 @@ TEST_F(VideoEncoderTest, FlushAtEndOfStream_MultipleConcurrentEncodes) {
}
TEST_F(VideoEncoderTest, BitrateCheck) {
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile());
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile(),
g_env->Bitrate());
config.num_frames_to_encode = kNumFramesToEncodeForBitrateCheck;
auto encoder = CreateVideoEncoder(g_env->Video(), config);
......@@ -311,7 +316,8 @@ TEST_F(VideoEncoderTest, BitrateCheck) {
}
TEST_F(VideoEncoderTest, DynamicBitrateChange) {
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile());
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile(),
g_env->Bitrate());
config.num_frames_to_encode = kNumFramesToEncodeForBitrateCheck * 2;
auto encoder = CreateVideoEncoder(g_env->Video(), config);
......@@ -339,7 +345,8 @@ TEST_F(VideoEncoderTest, DynamicBitrateChange) {
}
TEST_F(VideoEncoderTest, DynamicFramerateChange) {
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile());
VideoEncoderClientConfig config(g_env->Video(), g_env->Profile(),
g_env->Bitrate());
config.num_frames_to_encode = kNumFramesToEncodeForBitrateCheck * 2;
auto encoder = CreateVideoEncoder(g_env->Video(), config);
......@@ -371,7 +378,8 @@ TEST_F(VideoEncoderTest, FlushAtEndOfStream_NV12Dmabuf) {
auto nv12_video = g_env->Video()->ConvertToNV12();
ASSERT_TRUE(nv12_video);
VideoEncoderClientConfig config(nv12_video.get(), g_env->Profile());
VideoEncoderClientConfig config(nv12_video.get(), g_env->Profile(),
g_env->Bitrate());
config.input_storage_type =
VideoEncodeAccelerator::Config::StorageType::kDmabuf;
......
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