Commit 919a8970 authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/vaapi: Fill Fps allocation in VaapiVideoEncodeAccelerator

This CL fills VideoEncoderInfo::fps_allocation in
VaapiVideoEncodeAccelerator properly in temporal SVC.

Bug: 1030199
Test: vaapi_video_encode_accelerator_unittest
Change-Id: Iba020a26841d6ed35ad4b5bbf0d4cfc1442b282f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2425606
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810042}
parent 23555405
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "media/gpu/vaapi/vaapi_utils.h" #include "media/gpu/vaapi/vaapi_utils.h"
#include "media/gpu/vaapi/vp8_encoder.h" #include "media/gpu/vaapi/vp8_encoder.h"
#include "media/gpu/vaapi/vp9_encoder.h" #include "media/gpu/vaapi/vp9_encoder.h"
#include "media/gpu/vaapi/vp9_temporal_layers.h"
#include "media/gpu/vp8_reference_frame_vector.h" #include "media/gpu/vp8_reference_frame_vector.h"
#include "media/gpu/vp9_reference_frame_vector.h" #include "media/gpu/vp9_reference_frame_vector.h"
...@@ -470,12 +471,14 @@ void VaapiVideoEncodeAccelerator::InitializeTask(const Config& config) { ...@@ -470,12 +471,14 @@ void VaapiVideoEncodeAccelerator::InitializeTask(const Config& config) {
// Investigate and fix the issue. // Investigate and fix the issue.
// encoder_info_.scaling_settings = encoder_->GetScalingSettings(); // encoder_info_.scaling_settings = encoder_->GetScalingSettings();
// TODO(crbug.com/1030199): VaapiVideoEncodeAccelerator doesn't support either if (config.HasTemporalLayer()) {
// temporal-SVC or spatial-SVC. Update |fps_allocation| properly once they are DCHECK(!config.spatial_layers.empty());
// supported. encoder_info_.fps_allocation[0] = VP9TemporalLayers::GetFpsAllocation(
// A single stream shall be output at the desired FPS. config.spatial_layers[0].num_of_temporal_layers);
constexpr uint8_t kFullFramerate = 255; } else {
encoder_info_.fps_allocation[0] = {kFullFramerate}; constexpr uint8_t kFullFramerate = 255;
encoder_info_.fps_allocation[0] = {kFullFramerate};
}
// Notify VideoEncoderInfo after initialization. // Notify VideoEncoderInfo after initialization.
child_task_runner_->PostTask( child_task_runner_->PostTask(
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/test/gmock_callback_support.h" #include "base/test/gmock_callback_support.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "media/gpu/vaapi/vaapi_utils.h" #include "media/gpu/vaapi/vaapi_utils.h"
#include "media/gpu/vaapi/vp9_temporal_layers.h"
#include "media/gpu/vp9_picture.h" #include "media/gpu/vp9_picture.h"
#include "media/video/video_encode_accelerator.h" #include "media/video/video_encode_accelerator.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -53,6 +54,23 @@ MATCHER_P3(MatchesBitstreamBufferMetadata, ...@@ -53,6 +54,23 @@ MATCHER_P3(MatchesBitstreamBufferMetadata,
arg.key_frame == key_frame && arg.vp9.has_value() == has_vp9_metadata; arg.key_frame == key_frame && arg.vp9.has_value() == has_vp9_metadata;
} }
MATCHER_P(MatchesEncoderInfo, num_of_temporal_layers, "") {
const auto& fps_allocation = arg.fps_allocation[0];
if (fps_allocation.size() != num_of_temporal_layers)
return false;
constexpr uint8_t kFullFramerate = 255;
if (fps_allocation.back() != kFullFramerate)
return false;
if (fps_allocation.size() != 1 &&
fps_allocation !=
VP9TemporalLayers::GetFpsAllocation(num_of_temporal_layers)) {
return false;
}
return arg.implementation_name == "VaapiVideoEncodeAccelerator" &&
arg.supports_native_handle && arg.has_trusted_rate_controller &&
arg.is_hardware_accelerated && !arg.supports_simulcast;
}
class MockVideoEncodeAcceleratorClient : public VideoEncodeAccelerator::Client { class MockVideoEncodeAcceleratorClient : public VideoEncodeAccelerator::Client {
public: public:
MockVideoEncodeAcceleratorClient() = default; MockVideoEncodeAcceleratorClient() = default;
...@@ -185,10 +203,12 @@ class VaapiVideoEncodeAcceleratorTest ...@@ -185,10 +203,12 @@ class VaapiVideoEncodeAcceleratorTest
return true; return true;
})); }));
EXPECT_CALL(client_, RequireBitstreamBuffers(_, kDefaultEncodeSize, _)) EXPECT_CALL(client_, RequireBitstreamBuffers(_, kDefaultEncodeSize, _))
.WillOnce(WithArgs<2>([this, &quit_closure](size_t output_buffer_size) { .WillOnce(WithArgs<2>([this](size_t output_buffer_size) {
this->output_buffer_size_ = output_buffer_size; this->output_buffer_size_ = output_buffer_size;
quit_closure.Run();
})); }));
EXPECT_CALL(client_, NotifyEncoderInfoChange(MatchesEncoderInfo(
config.spatial_layers[0].num_of_temporal_layers)))
.WillOnce([&quit_closure]() { quit_closure.Run(); });
ASSERT_TRUE(InitializeVideoEncodeAccelerator(config)); ASSERT_TRUE(InitializeVideoEncodeAccelerator(config));
run_loop.Run(); run_loop.Run();
} }
......
...@@ -107,6 +107,31 @@ std::vector<VP9TemporalLayers::FrameConfig> GetTemporalLayersReferencePattern( ...@@ -107,6 +107,31 @@ std::vector<VP9TemporalLayers::FrameConfig> GetTemporalLayersReferencePattern(
} }
} // namespace } // namespace
// static
std::vector<uint8_t> VP9TemporalLayers::GetFpsAllocation(
size_t num_temporal_layers) {
DCHECK_GT(num_temporal_layers, 1u);
DCHECK_LT(num_temporal_layers, 4u);
// The frame rate fraction is given as an 8bit unsigned integer where 0 = 0%
// and 255 = 100%. VideoEncoderInfo::fps_allocation is filled in the
// cumulative manner. For example, if
// fps_allocation[0][0] = kFullFramerate / 4;
// fps_allocation[0][1] = kFullFramerate / 2;
// fps_allocation[0][2] = kFullFramerate;
// then fourth of the frames are in the base layer, fourth are in TL1 and half
// are in TL2.
constexpr uint8_t kFullFramerate = 255;
switch (num_temporal_layers) {
case 2:
return {kFullFramerate / 2, kFullFramerate};
case 3:
return {kFullFramerate / 4, kFullFramerate / 2, kFullFramerate};
default:
NOTREACHED() << "Unsupported temporal layers";
return {};
}
}
VP9TemporalLayers::VP9TemporalLayers(size_t number_of_temporal_layers) VP9TemporalLayers::VP9TemporalLayers(size_t number_of_temporal_layers)
: num_layers_(number_of_temporal_layers), : num_layers_(number_of_temporal_layers),
temporal_layers_reference_pattern_( temporal_layers_reference_pattern_(
......
...@@ -41,6 +41,8 @@ class VP9TemporalLayers { ...@@ -41,6 +41,8 @@ class VP9TemporalLayers {
explicit VP9TemporalLayers(size_t num_temporal_layers); explicit VP9TemporalLayers(size_t num_temporal_layers);
~VP9TemporalLayers(); ~VP9TemporalLayers();
static std::vector<uint8_t> GetFpsAllocation(size_t num_temporal_layers);
// Sets |picture|'s used reference frames and |ref_frames_used| so that they // Sets |picture|'s used reference frames and |ref_frames_used| so that they
// structure valid temporal layers. This also fills |picture|'s // structure valid temporal layers. This also fills |picture|'s
// |metadata_for_encoding|. // |metadata_for_encoding|.
......
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