Commit c9250afc authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/v4l2VEA: Configure framerate and bitrate only if they vary

The original V4L2VideoEncodeAccelerator execute IOCTLs to configure
framerate and bitrate every RequestEncodingParametersChange() even
though they are the same as the last configured values.

This CL have V4L2VEA reconfigure the framerate and bitrate only
if they vary. This also fixes the flood of the parameter change
logging in chrome log.

Bug: None
Test: run VEA test on scarlet
Test: appr.tc/?vsc=h264&debug=loopback
Change-Id: Ibe830797436a05d31f516af0845211f5da707fc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082739
Auto-Submit: Hirokazu Honda <hiroh@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748523}
parent 74c15592
...@@ -160,6 +160,8 @@ V4L2VideoEncodeAccelerator::V4L2VideoEncodeAccelerator( ...@@ -160,6 +160,8 @@ V4L2VideoEncodeAccelerator::V4L2VideoEncodeAccelerator(
native_input_mode_(false), native_input_mode_(false),
output_buffer_byte_size_(0), output_buffer_byte_size_(0),
output_format_fourcc_(0), output_format_fourcc_(0),
current_bitrate_(0),
current_framerate_(0),
encoder_state_(kUninitialized), encoder_state_(kUninitialized),
device_(std::move(device)), device_(std::move(device)),
input_memory_type_(V4L2_MEMORY_USERPTR), input_memory_type_(V4L2_MEMORY_USERPTR),
...@@ -506,7 +508,6 @@ void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer( ...@@ -506,7 +508,6 @@ void V4L2VideoEncodeAccelerator::UseOutputBitstreamBuffer(
void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange( void V4L2VideoEncodeAccelerator::RequestEncodingParametersChange(
uint32_t bitrate, uint32_t bitrate,
uint32_t framerate) { uint32_t framerate) {
VLOGF(2) << "bitrate=" << bitrate << ", framerate=" << framerate;
DCHECK_CALLED_ON_VALID_SEQUENCE(child_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(child_sequence_checker_);
encoder_task_runner_->PostTask( encoder_task_runner_->PostTask(
...@@ -722,7 +723,9 @@ bool V4L2VideoEncodeAccelerator::ReconfigureFormatIfNeeded( ...@@ -722,7 +723,9 @@ bool V4L2VideoEncodeAccelerator::ReconfigureFormatIfNeeded(
if (!input_buffer_map_.empty()) { if (!input_buffer_map_.empty()) {
if (frame.coded_size() != input_frame_size_) { if (frame.coded_size() != input_frame_size_) {
VLOGF(1) << "Input frame size is changed during encoding"; VLOGF(1) << "Input frame size is changed during encoding"
<< ", frame.coded_size()=" << frame.coded_size().ToString()
<< ", input_frame_size=" << input_frame_size_.ToString();
return false; return false;
} }
return true; return true;
...@@ -1288,6 +1291,9 @@ void V4L2VideoEncodeAccelerator::SetErrorState(Error error) { ...@@ -1288,6 +1291,9 @@ void V4L2VideoEncodeAccelerator::SetErrorState(Error error) {
void V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask( void V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask(
uint32_t bitrate, uint32_t bitrate,
uint32_t framerate) { uint32_t framerate) {
if (current_bitrate_ == bitrate && current_framerate_ == framerate)
return;
VLOGF(2) << "bitrate=" << bitrate << ", framerate=" << framerate; VLOGF(2) << "bitrate=" << bitrate << ", framerate=" << framerate;
DCHECK_CALLED_ON_VALID_SEQUENCE(encoder_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(encoder_sequence_checker_);
TRACE_EVENT2("media,gpu", "V4L2VEA::RequestEncodingParametersChangeTask", TRACE_EVENT2("media,gpu", "V4L2VEA::RequestEncodingParametersChangeTask",
...@@ -1296,7 +1302,8 @@ void V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask( ...@@ -1296,7 +1302,8 @@ void V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask(
DCHECK_GT(bitrate, 0u); DCHECK_GT(bitrate, 0u);
DCHECK_GT(framerate, 0u); DCHECK_GT(framerate, 0u);
if (!device_->SetExtCtrls( if (current_bitrate_ != bitrate &&
!device_->SetExtCtrls(
V4L2_CTRL_CLASS_MPEG, V4L2_CTRL_CLASS_MPEG,
{V4L2ExtCtrl(V4L2_CID_MPEG_VIDEO_BITRATE, bitrate)})) { {V4L2ExtCtrl(V4L2_CID_MPEG_VIDEO_BITRATE, bitrate)})) {
VLOGF(1) << "Failed changing bitrate"; VLOGF(1) << "Failed changing bitrate";
...@@ -1304,13 +1311,18 @@ void V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask( ...@@ -1304,13 +1311,18 @@ void V4L2VideoEncodeAccelerator::RequestEncodingParametersChangeTask(
return; return;
} }
struct v4l2_streamparm parms{}; if (current_framerate_ != framerate) {
parms.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; struct v4l2_streamparm parms {};
// Note that we are provided "frames per second" but V4L2 expects "time per parms.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
// frame"; hence we provide the reciprocal of the framerate here. // Note that we are provided "frames per second" but V4L2 expects "time per
parms.parm.output.timeperframe.numerator = 1; // frame"; hence we provide the reciprocal of the framerate here.
parms.parm.output.timeperframe.denominator = framerate; parms.parm.output.timeperframe.numerator = 1;
IOCTL_OR_ERROR_RETURN(VIDIOC_S_PARM, &parms); parms.parm.output.timeperframe.denominator = framerate;
IOCTL_OR_ERROR_RETURN(VIDIOC_S_PARM, &parms);
}
current_bitrate_ = bitrate;
current_framerate_ = framerate;
} }
bool V4L2VideoEncodeAccelerator::SetOutputFormat( bool V4L2VideoEncodeAccelerator::SetOutputFormat(
......
...@@ -268,6 +268,9 @@ class MEDIA_GPU_EXPORT V4L2VideoEncodeAccelerator ...@@ -268,6 +268,9 @@ class MEDIA_GPU_EXPORT V4L2VideoEncodeAccelerator
size_t output_buffer_byte_size_; size_t output_buffer_byte_size_;
uint32_t output_format_fourcc_; uint32_t output_format_fourcc_;
size_t current_bitrate_;
size_t current_framerate_;
// Encoder state, owned and operated by |encoder_task_runner_|. // Encoder state, owned and operated by |encoder_task_runner_|.
State encoder_state_; State encoder_state_;
......
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