From c9e3abe2060760d71c83a1574559b6e479e637d2 Mon Sep 17 00:00:00 2001 From: ameerj Date: Thu, 26 Nov 2020 00:18:26 -0500 Subject: [PATCH] Address PR feedback remove some redundant moves, make deleter match naming guidelines. Co-Authored-By: LC <712067+lioncash@users.noreply.github.com> --- .../command_classes/codecs/codec.cpp | 15 ++++--- src/video_core/command_classes/codecs/codec.h | 4 +- src/video_core/command_classes/codecs/vp9.cpp | 2 +- .../command_classes/codecs/vp9_types.h | 44 +++++++++---------- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/video_core/command_classes/codecs/codec.cpp b/src/video_core/command_classes/codecs/codec.cpp index 1a19341c85..412e1e41cc 100644 --- a/src/video_core/command_classes/codecs/codec.cpp +++ b/src/video_core/command_classes/codecs/codec.cpp @@ -18,7 +18,7 @@ extern "C" { namespace Tegra { -void av_frame_deleter(AVFrame* ptr) { +void AVFrameDeleter(AVFrame* ptr) { av_frame_unref(ptr); av_free(ptr); } @@ -101,7 +101,7 @@ void Codec::Decode() { if (!vp9_hidden_frame) { // Only receive/store visible frames - AVFramePtr frame = AVFramePtr{av_frame_alloc(), av_frame_deleter}; + AVFramePtr frame = AVFramePtr{av_frame_alloc(), AVFrameDeleter}; avcodec_receive_frame(av_codec_ctx, frame.get()); av_frames.push(std::move(frame)); } @@ -110,12 +110,13 @@ void Codec::Decode() { AVFramePtr Codec::GetCurrentFrame() { // Sometimes VIC will request more frames than have been decoded. // in this case, return a nullptr and don't overwrite previous frame data - if (av_frames.size() > 0) { - AVFramePtr frame = std::move(av_frames.front()); - av_frames.pop(); - return frame; + if (av_frames.empty()) { + return AVFramePtr{nullptr, AVFrameDeleter}; } - return AVFramePtr{nullptr, av_frame_deleter}; + + AVFramePtr frame = std::move(av_frames.front()); + av_frames.pop(); + return frame; } NvdecCommon::VideoCodec Codec::GetCurrentCodec() const { diff --git a/src/video_core/command_classes/codecs/codec.h b/src/video_core/command_classes/codecs/codec.h index c26b59fdec..0c6dde4058 100644 --- a/src/video_core/command_classes/codecs/codec.h +++ b/src/video_core/command_classes/codecs/codec.h @@ -23,8 +23,8 @@ namespace Tegra { class GPU; struct VicRegisters; -void av_frame_deleter(AVFrame* ptr); -using AVFramePtr = std::unique_ptr; +void AVFrameDeleter(AVFrame* ptr); +using AVFramePtr = std::unique_ptr; namespace Decoder { class H264; diff --git a/src/video_core/command_classes/codecs/vp9.cpp b/src/video_core/command_classes/codecs/vp9.cpp index 31e00c27d7..b1d675cdbc 100644 --- a/src/video_core/command_classes/codecs/vp9.cpp +++ b/src/video_core/command_classes/codecs/vp9.cpp @@ -306,7 +306,7 @@ void VP9::WriteCoefProbabilityUpdate(VpxRangeEncoder& writer, s32 tx_mode, const std::array& old_prob) { constexpr u32 block_bytes = 2 * 2 * 6 * 6 * 3; - const auto needs_update = [&](u32 base_index) -> bool { + const auto needs_update = [&](u32 base_index) { return !std::equal(new_prob.begin() + base_index, new_prob.begin() + base_index + block_bytes, old_prob.begin() + base_index); diff --git a/src/video_core/command_classes/codecs/vp9_types.h b/src/video_core/command_classes/codecs/vp9_types.h index 5ca944f2ac..139501a1c6 100644 --- a/src/video_core/command_classes/codecs/vp9_types.h +++ b/src/video_core/command_classes/codecs/vp9_types.h @@ -245,33 +245,33 @@ struct EntropyProbs { std::array coef_probs{}; void Convert(Vp9EntropyProbs& fc) { - fc.inter_mode_prob = std::move(inter_mode_prob); - fc.intra_inter_prob = std::move(intra_inter_prob); - fc.tx_8x8_prob = std::move(tx_8x8_prob); - fc.tx_16x16_prob = std::move(tx_16x16_prob); - fc.tx_32x32_prob = std::move(tx_32x32_prob); + fc.inter_mode_prob = inter_mode_prob; + fc.intra_inter_prob = intra_inter_prob; + fc.tx_8x8_prob = tx_8x8_prob; + fc.tx_16x16_prob = tx_16x16_prob; + fc.tx_32x32_prob = tx_32x32_prob; - for (s32 i = 0; i < 4; i++) { - for (s32 j = 0; j < 9; j++) { + for (std::size_t i = 0; i < 4; i++) { + for (std::size_t j = 0; j < 9; j++) { fc.y_mode_prob[j + 9 * i] = j < 8 ? y_mode_prob_e0e7[i][j] : y_mode_prob_e8[i]; } } - fc.partition_prob = std::move(partition_prob); - fc.switchable_interp_prob = std::move(switchable_interp_prob); - fc.comp_inter_prob = std::move(comp_inter_prob); - fc.skip_probs = std::move(skip_probs); - fc.joints = std::move(joints); - fc.sign = std::move(sign); - fc.class_0 = std::move(class_0); - fc.fr = std::move(fr); - fc.class_0_hp = std::move(class_0_hp); - fc.high_precision = std::move(high_precision); - fc.classes = std::move(classes); - fc.class_0_fr = std::move(class_0_fr); - fc.prob_bits = std::move(pred_bits); - fc.single_ref_prob = std::move(single_ref_prob); - fc.comp_ref_prob = std::move(comp_ref_prob); + fc.partition_prob = partition_prob; + fc.switchable_interp_prob = switchable_interp_prob; + fc.comp_inter_prob = comp_inter_prob; + fc.skip_probs = skip_probs; + fc.joints = joints; + fc.sign = sign; + fc.class_0 = class_0; + fc.fr = fr; + fc.class_0_hp = class_0_hp; + fc.high_precision = high_precision; + fc.classes = classes; + fc.class_0_fr = class_0_fr; + fc.prob_bits = pred_bits; + fc.single_ref_prob = single_ref_prob; + fc.comp_ref_prob = comp_ref_prob; // Skip the 4th element as it goes unused for (std::size_t i = 0; i < coef_probs.size(); i += 4) {