Commit d001079e authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

cleanup style VaapiVP8Accelerator::SubmitDecode

This CL cleans up a bit said method VaapiVP8Accelerator::SubmitDecode():
- Adds {} where needed (either condition or body > 1 line).
- Removes memset() of a struct, instead using = {}, and moves the
 variable declaration closer to its use, in some cases.
- s/std::min(std::max())/base::ClampToRange()/

No new functionality intended.  This code is only used in ChromeOS.

Bug: 876810
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: If2fb903a427dea2424743217e569d09cdadefe22
Reviewed-on: https://chromium-review.googlesource.com/1188615Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586020}
parent 1b5129a4
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "media/gpu/vaapi/vaapi_vp8_accelerator.h" #include "media/gpu/vaapi/vaapi_vp8_accelerator.h"
#include "base/numerics/ranges.h"
#include "media/gpu/vaapi/vaapi_common.h" #include "media/gpu/vaapi/vaapi_common.h"
#include "media/gpu/vaapi/vaapi_video_decode_accelerator.h" #include "media/gpu/vaapi/vaapi_video_decode_accelerator.h"
#include "media/gpu/vaapi/vaapi_wrapper.h" #include "media/gpu/vaapi/vaapi_wrapper.h"
...@@ -45,12 +46,11 @@ bool VaapiVP8Accelerator::SubmitDecode( ...@@ -45,12 +46,11 @@ bool VaapiVP8Accelerator::SubmitDecode(
scoped_refptr<VP8Picture> pic, scoped_refptr<VP8Picture> pic,
const Vp8ReferenceFrameVector& reference_frames) { const Vp8ReferenceFrameVector& reference_frames) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
VAIQMatrixBufferVP8 iq_matrix_buf;
memset(&iq_matrix_buf, 0, sizeof(VAIQMatrixBufferVP8));
const auto& frame_hdr = pic->frame_hdr; const auto& frame_hdr = pic->frame_hdr;
const Vp8SegmentationHeader& sgmnt_hdr = frame_hdr->segmentation_hdr; const Vp8SegmentationHeader& sgmnt_hdr = frame_hdr->segmentation_hdr;
const Vp8QuantizationHeader& quant_hdr = frame_hdr->quantization_hdr; const Vp8QuantizationHeader& quant_hdr = frame_hdr->quantization_hdr;
VAIQMatrixBufferVP8 iq_matrix_buf{};
static_assert(arraysize(iq_matrix_buf.quantization_index) == kMaxMBSegments, static_assert(arraysize(iq_matrix_buf.quantization_index) == kMaxMBSegments,
"incorrect quantization matrix size"); "incorrect quantization matrix size");
for (size_t i = 0; i < kMaxMBSegments; ++i) { for (size_t i = 0; i < kMaxMBSegments; ++i) {
...@@ -64,7 +64,7 @@ bool VaapiVP8Accelerator::SubmitDecode( ...@@ -64,7 +64,7 @@ bool VaapiVP8Accelerator::SubmitDecode(
q += sgmnt_hdr.quantizer_update_value[i]; q += sgmnt_hdr.quantizer_update_value[i];
} }
#define CLAMP_Q(q) std::min(std::max(q, 0), 127) #define CLAMP_Q(q) base::ClampToRange(q, 0, 127)
static_assert(arraysize(iq_matrix_buf.quantization_index[i]) == 6, static_assert(arraysize(iq_matrix_buf.quantization_index[i]) == 6,
"incorrect quantization matrix size"); "incorrect quantization matrix size");
iq_matrix_buf.quantization_index[i][0] = CLAMP_Q(q); iq_matrix_buf.quantization_index[i][0] = CLAMP_Q(q);
...@@ -77,22 +77,21 @@ bool VaapiVP8Accelerator::SubmitDecode( ...@@ -77,22 +77,21 @@ bool VaapiVP8Accelerator::SubmitDecode(
} }
if (!vaapi_wrapper_->SubmitBuffer( if (!vaapi_wrapper_->SubmitBuffer(
VAIQMatrixBufferType, sizeof(VAIQMatrixBufferVP8), &iq_matrix_buf)) VAIQMatrixBufferType, sizeof(VAIQMatrixBufferVP8), &iq_matrix_buf)) {
return false; return false;
}
VAProbabilityDataBufferVP8 prob_buf;
memset(&prob_buf, 0, sizeof(VAProbabilityDataBufferVP8));
const Vp8EntropyHeader& entr_hdr = frame_hdr->entropy_hdr; const Vp8EntropyHeader& entr_hdr = frame_hdr->entropy_hdr;
VAProbabilityDataBufferVP8 prob_buf{};
ARRAY_MEMCPY_CHECKED(prob_buf.dct_coeff_probs, entr_hdr.coeff_probs); ARRAY_MEMCPY_CHECKED(prob_buf.dct_coeff_probs, entr_hdr.coeff_probs);
if (!vaapi_wrapper_->SubmitBuffer(VAProbabilityBufferType, if (!vaapi_wrapper_->SubmitBuffer(VAProbabilityBufferType,
sizeof(VAProbabilityDataBufferVP8), sizeof(VAProbabilityDataBufferVP8),
&prob_buf)) &prob_buf)) {
return false; return false;
}
VAPictureParameterBufferVP8 pic_param; VAPictureParameterBufferVP8 pic_param{};
memset(&pic_param, 0, sizeof(VAPictureParameterBufferVP8));
pic_param.frame_width = frame_hdr->width; pic_param.frame_width = frame_hdr->width;
pic_param.frame_height = frame_hdr->height; pic_param.frame_height = frame_hdr->height;
...@@ -191,11 +190,11 @@ bool VaapiVP8Accelerator::SubmitDecode( ...@@ -191,11 +190,11 @@ bool VaapiVP8Accelerator::SubmitDecode(
pic_param.bool_coder_ctx.count = frame_hdr->bool_dec_count; pic_param.bool_coder_ctx.count = frame_hdr->bool_dec_count;
if (!vaapi_wrapper_->SubmitBuffer(VAPictureParameterBufferType, if (!vaapi_wrapper_->SubmitBuffer(VAPictureParameterBufferType,
sizeof(pic_param), &pic_param)) sizeof(pic_param), &pic_param)) {
return false; return false;
}
VASliceParameterBufferVP8 slice_param; VASliceParameterBufferVP8 slice_param{};
memset(&slice_param, 0, sizeof(slice_param));
slice_param.slice_data_size = frame_hdr->frame_size; slice_param.slice_data_size = frame_hdr->frame_size;
slice_param.slice_data_offset = frame_hdr->first_part_offset; slice_param.slice_data_offset = frame_hdr->first_part_offset;
slice_param.slice_data_flag = VA_SLICE_DATA_FLAG_ALL; slice_param.slice_data_flag = VA_SLICE_DATA_FLAG_ALL;
...@@ -213,12 +212,14 @@ bool VaapiVP8Accelerator::SubmitDecode( ...@@ -213,12 +212,14 @@ bool VaapiVP8Accelerator::SubmitDecode(
if (!vaapi_wrapper_->SubmitBuffer(VASliceParameterBufferType, if (!vaapi_wrapper_->SubmitBuffer(VASliceParameterBufferType,
sizeof(VASliceParameterBufferVP8), sizeof(VASliceParameterBufferVP8),
&slice_param)) &slice_param)) {
return false; return false;
}
if (!vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType, if (!vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType,
frame_hdr->frame_size, frame_hdr->data)) frame_hdr->frame_size, frame_hdr->data)) {
return false; return false;
}
return vaapi_wrapper_->ExecuteAndDestroyPendingBuffers( return vaapi_wrapper_->ExecuteAndDestroyPendingBuffers(
pic->AsVaapiVP8Picture()->va_surface()->id()); pic->AsVaapiVP8Picture()->va_surface()->id());
......
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