Skip to content

Commit

Permalink
media/gpu/vaapi: follow some ClangTidy suggestions
Browse files Browse the repository at this point in the history
ClangTidy suggested some changes during previous CLs. This CL addresses
those, namely s/1/true/ for booleans and use for-range loop in one
location.  I had a quick look for constness opportunities, a few {}
missing, a comment, and removed unnecessary forward decls.

Absolutely no new functionality intended.

Bug: b:172224547
Change-Id: Ib34fe1cd2204f85f1ee47548898113259e49e52e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2924105
Auto-Submit: Miguel Casas <mcasas@chromium.org>
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#891090}
  • Loading branch information
yell0wd0g authored and Chromium LUCI CQ committed Jun 10, 2021
1 parent 0ada81f commit a53a941
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 39 deletions.
16 changes: 8 additions & 8 deletions media/gpu/vaapi/h264_vaapi_video_encoder_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ H264VaapiVideoEncoderDelegate::EncodeParams::EncodeParams()
max_ref_pic_list1_size(kMaxRefIdxL1Size) {}

H264VaapiVideoEncoderDelegate::H264VaapiVideoEncoderDelegate(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
scoped_refptr<VaapiWrapper> vaapi_wrapper,
base::RepeatingClosure error_cb)
: VaapiVideoEncoderDelegate(vaapi_wrapper, error_cb),
: VaapiVideoEncoderDelegate(std::move(vaapi_wrapper), error_cb),
packed_sps_(new H264BitstreamBuffer()),
packed_pps_(new H264BitstreamBuffer()) {}

Expand Down Expand Up @@ -709,14 +709,14 @@ bool H264VaapiVideoEncoderDelegate::SubmitFrameParameters(
slice_param.pic_order_cnt_lsb = pic->pic_order_cnt_lsb;
slice_param.num_ref_idx_active_override_flag = true;

for (size_t i = 0; i < base::size(pic_param.ReferenceFrames); ++i)
InitVAPictureH264(&pic_param.ReferenceFrames[i]);
for (VAPictureH264& picture : pic_param.ReferenceFrames)
InitVAPictureH264(&picture);

for (size_t i = 0; i < base::size(slice_param.RefPicList0); ++i)
InitVAPictureH264(&slice_param.RefPicList0[i]);
for (VAPictureH264& picture : slice_param.RefPicList0)
InitVAPictureH264(&picture);

for (size_t i = 0; i < base::size(slice_param.RefPicList1); ++i)
InitVAPictureH264(&slice_param.RefPicList1[i]);
for (VAPictureH264& picture : slice_param.RefPicList1)
InitVAPictureH264(&picture);

VAPictureH264* ref_frames_entry = pic_param.ReferenceFrames;
VAPictureH264* ref_list_entry = slice_param.RefPicList0;
Expand Down
5 changes: 2 additions & 3 deletions media/gpu/vaapi/h264_vaapi_video_encoder_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ class H264VaapiVideoEncoderDelegate : public VaapiVideoEncoderDelegate {
size_t max_ref_pic_list1_size;
};

H264VaapiVideoEncoderDelegate(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
base::RepeatingClosure error_cb);
H264VaapiVideoEncoderDelegate(scoped_refptr<VaapiWrapper> vaapi_wrapper,
base::RepeatingClosure error_cb);
~H264VaapiVideoEncoderDelegate() override;

// VaapiVideoEncoderDelegate implementation.
Expand Down
32 changes: 19 additions & 13 deletions media/gpu/vaapi/vaapi_video_encode_accelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool VaapiVideoEncodeAccelerator::Initialize(const Config& config,
client_ptr_factory_.reset(new base::WeakPtrFactory<Client>(client));
client_ = client_ptr_factory_->GetWeakPtr();

VideoCodec codec = VideoCodecProfileToVideoCodec(config.output_profile);
const VideoCodec codec = VideoCodecProfileToVideoCodec(config.output_profile);
if (codec != kCodecH264 && codec != kCodecVP8 && codec != kCodecVP9) {
VLOGF(1) << "Unsupported profile: "
<< GetProfileName(config.output_profile);
Expand Down Expand Up @@ -218,11 +218,11 @@ bool VaapiVideoEncodeAccelerator::Initialize(const Config& config,
}

const SupportedProfiles& profiles = GetSupportedProfiles();
auto profile = find_if(profiles.begin(), profiles.end(),
[output_profile = config.output_profile](
const SupportedProfile& profile) {
return profile.profile == output_profile;
});
const auto profile = find_if(profiles.begin(), profiles.end(),
[output_profile = config.output_profile](
const SupportedProfile& profile) {
return profile.profile == output_profile;
});
if (profile == profiles.end()) {
VLOGF(1) << "Unsupported output profile "
<< GetProfileName(config.output_profile);
Expand Down Expand Up @@ -281,25 +281,28 @@ void VaapiVideoEncodeAccelerator::InitializeTask(const Config& config) {
base::Unretained(this));
switch (output_codec_) {
case kCodecH264:
if (!IsConfiguredForTesting())
if (!IsConfiguredForTesting()) {
encoder_ = std::make_unique<H264VaapiVideoEncoderDelegate>(
vaapi_wrapper_, error_cb);
}

DCHECK_EQ(ave_config.bitrate_control,
VaapiVideoEncoderDelegate::BitrateControl::kConstantBitrate);
break;
case kCodecVP8:
if (!IsConfiguredForTesting())
if (!IsConfiguredForTesting()) {
encoder_ = std::make_unique<VP8VaapiVideoEncoderDelegate>(
vaapi_wrapper_, error_cb);
}

DCHECK_EQ(ave_config.bitrate_control,
VaapiVideoEncoderDelegate::BitrateControl::kConstantBitrate);
break;
case kCodecVP9:
if (!IsConfiguredForTesting())
if (!IsConfiguredForTesting()) {
encoder_ = std::make_unique<VP9VaapiVideoEncoderDelegate>(
vaapi_wrapper_, error_cb);
}

ave_config.bitrate_control = VaapiVideoEncoderDelegate::BitrateControl::
kConstantQuantizationParameter;
Expand Down Expand Up @@ -431,8 +434,9 @@ void VaapiVideoEncodeAccelerator::UploadFrame(

DVLOGF(4) << "frame is uploading: " << va_surface_id;
if (!vaapi_wrapper_->UploadVideoFrameToSurface(*frame, va_surface_id,
va_surface_size))
va_surface_size)) {
NOTIFY_ERROR(kPlatformFailureError, "Failed to upload frame");
}
}

void VaapiVideoEncodeAccelerator::TryToReturnBitstreamBuffer() {
Expand Down Expand Up @@ -518,7 +522,8 @@ VaapiVideoEncodeAccelerator::CreateEncodeJob(scoped_refptr<VideoFrame> frame,
frame->storage_type() != VideoFrame::STORAGE_DMABUFS &&
frame->storage_type() != VideoFrame::STORAGE_GPU_MEMORY_BUFFER) {
NOTIFY_ERROR(kPlatformFailureError,
"Unexpected storage: " << frame->storage_type());
"Unexpected storage: "
<< VideoFrame::StorageTypeToString(frame->storage_type()));
return nullptr;
}

Expand All @@ -538,8 +543,9 @@ VaapiVideoEncodeAccelerator::CreateEncodeJob(scoped_refptr<VideoFrame> frame,
scoped_refptr<VASurface> input_surface;
if (native_input_mode_) {
if (frame->format() != PIXEL_FORMAT_NV12) {
NOTIFY_ERROR(kPlatformFailureError,
"Expected NV12, got: " << frame->format());
NOTIFY_ERROR(
kPlatformFailureError,
"Expected NV12, got: " << VideoPixelFormatToString(frame->format()));
return nullptr;
}
DCHECK(frame);
Expand Down
3 changes: 0 additions & 3 deletions media/gpu/vaapi/vaapi_video_encode_accelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "base/memory/ref_counted_memory.h"
#include "base/sequence_checker.h"
#include "base/single_thread_task_runner.h"
#include "media/filters/h264_bitstream_buffer.h"
#include "media/gpu/media_gpu_export.h"
#include "media/gpu/vaapi/vaapi_utils.h"
#include "media/gpu/vaapi/vaapi_video_encoder_delegate.h"
Expand Down Expand Up @@ -48,8 +47,6 @@ class MEDIA_GPU_EXPORT VaapiVideoEncodeAccelerator

private:
friend class VaapiVideoEncodeAcceleratorTest;
class H264Accelerator;
class VP9Accelerator;

using EncodeJob = VaapiVideoEncoderDelegate::EncodeJob;

Expand Down
4 changes: 3 additions & 1 deletion media/gpu/vaapi/vaapi_video_encode_accelerator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MockVideoEncodeAcceleratorClient : public VideoEncodeAccelerator::Client {

class MockVaapiWrapper : public VaapiWrapper {
public:
MockVaapiWrapper(CodecMode mode) : VaapiWrapper(mode) {}
explicit MockVaapiWrapper(CodecMode mode) : VaapiWrapper(mode) {}

MOCK_METHOD2(GetVAEncMaxNumOfRefFrames, bool(VideoCodecProfile, size_t*));
MOCK_METHOD5(CreateContextAndSurfaces,
Expand Down Expand Up @@ -317,6 +317,8 @@ class VaapiVideoEncodeAcceleratorTest
std::vector<VASurfaceID> va_surfaces_;
base::test::TaskEnvironment task_environment_;
MockVideoEncodeAcceleratorClient client_;
// |encoder_| is a VideoEncodeAccelerator to use its specialized Deleter that
// calls Destroy() so that destruction threading is respected.
std::unique_ptr<VideoEncodeAccelerator> encoder_;
scoped_refptr<MockVaapiWrapper> mock_vaapi_wrapper_;
MockVP9VaapiVideoEncoderDelegate* mock_encoder_ = nullptr;
Expand Down
1 change: 1 addition & 0 deletions media/gpu/vaapi/vaapi_video_encoder_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const scoped_refptr<VASurface>&
VaapiVideoEncoderDelegate::EncodeJob::input_surface() const {
return input_surface_;
}

const scoped_refptr<CodecPicture>&
VaapiVideoEncoderDelegate::EncodeJob::picture() const {
return picture_;
Expand Down
14 changes: 7 additions & 7 deletions media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ void VP8VaapiVideoEncoderDelegate::Reset() {
}

VP8VaapiVideoEncoderDelegate::VP8VaapiVideoEncoderDelegate(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
scoped_refptr<VaapiWrapper> vaapi_wrapper,
base::RepeatingClosure error_cb)
: VaapiVideoEncoderDelegate(vaapi_wrapper, error_cb) {}
: VaapiVideoEncoderDelegate(std::move(vaapi_wrapper), error_cb) {}

VP8VaapiVideoEncoderDelegate::~VP8VaapiVideoEncoderDelegate() {
// VP8VaapiVideoEncoderDelegate can be destroyed on any thread.
Expand Down Expand Up @@ -185,7 +185,7 @@ bool VP8VaapiVideoEncoderDelegate::UpdateRates(
return true;
}
VLOGF(2) << "New bitrate: " << bitrate_allocation.GetSumBps()
<< ", New framerate: " << framerate;
<< ", new framerate: " << framerate;

current_params_.bitrate_allocation = bitrate_allocation;
current_params_.framerate = framerate;
Expand All @@ -212,12 +212,12 @@ void VP8VaapiVideoEncoderDelegate::InitializeFrameHeader() {
// A VA-API driver recommends to set forced_lf_adjustment on keyframe.
// Set loop_filter_adj_enable to 1 here because forced_lf_adjustment is read
// only when a macroblock level loop filter adjustment.
current_frame_hdr_.loopfilter_hdr.loop_filter_adj_enable = 1;
current_frame_hdr_.loopfilter_hdr.loop_filter_adj_enable = true;

// Set mb_no_skip_coeff to 1 that some decoders (e.g. kepler) could not decode
// correctly a stream encoded with mb_no_skip_coeff=0. It also enables an
// encoder to produce a more optimized stream than when mb_no_skip_coeff=0.
current_frame_hdr_.mb_no_skip_coeff = 1;
current_frame_hdr_.mb_no_skip_coeff = true;
}

void VP8VaapiVideoEncoderDelegate::UpdateFrameHeader(bool keyframe) {
Expand Down Expand Up @@ -366,8 +366,8 @@ bool VP8VaapiVideoEncoderDelegate::SubmitFrameParameters(
pic_param.clamp_qindex_low = encode_params.min_qp;

VAQMatrixBufferVP8 qmatrix_buf = {};
for (size_t i = 0; i < base::size(qmatrix_buf.quantization_index); ++i)
qmatrix_buf.quantization_index[i] = frame_header->quantization_hdr.y_ac_qi;
for (auto index : qmatrix_buf.quantization_index)
index = frame_header->quantization_hdr.y_ac_qi;

qmatrix_buf.quantization_index_delta[0] =
frame_header->quantization_hdr.y_dc_delta;
Expand Down
2 changes: 1 addition & 1 deletion media/gpu/vaapi/vp8_vaapi_video_encoder_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class VP8VaapiVideoEncoderDelegate : public VaapiVideoEncoderDelegate {
bool error_resilient_mode;
};

VP8VaapiVideoEncoderDelegate(const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
VP8VaapiVideoEncoderDelegate(scoped_refptr<VaapiWrapper> vaapi_wrapper,
base::RepeatingClosure error_cb);
~VP8VaapiVideoEncoderDelegate() override;

Expand Down
4 changes: 2 additions & 2 deletions media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ void VP9VaapiVideoEncoderDelegate::set_rate_ctrl_for_testing(
}

VP9VaapiVideoEncoderDelegate::VP9VaapiVideoEncoderDelegate(
const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
scoped_refptr<VaapiWrapper> vaapi_wrapper,
base::RepeatingClosure error_cb)
: VaapiVideoEncoderDelegate(vaapi_wrapper, error_cb) {}
: VaapiVideoEncoderDelegate(std::move(vaapi_wrapper), error_cb) {}

VP9VaapiVideoEncoderDelegate::~VP9VaapiVideoEncoderDelegate() {
// VP9VaapiVideoEncoderDelegate can be destroyed on any thread.
Expand Down
2 changes: 1 addition & 1 deletion media/gpu/vaapi/vp9_vaapi_video_encoder_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class VP9VaapiVideoEncoderDelegate : public VaapiVideoEncoderDelegate {
bool error_resilient_mode;
};

VP9VaapiVideoEncoderDelegate(const scoped_refptr<VaapiWrapper>& vaapi_wrapper,
VP9VaapiVideoEncoderDelegate(scoped_refptr<VaapiWrapper> vaapi_wrapper,
base::RepeatingClosure error_cb);
~VP9VaapiVideoEncoderDelegate() override;

Expand Down

0 comments on commit a53a941

Please sign in to comment.