1
0
Fork 0
forked from suyu/suyu

nvdec: Make use of [[nodiscard]] where applicable

Prevents bugs from occurring where the results of a function are
accidentally discarded
This commit is contained in:
Lioncash 2020-10-30 16:13:29 -04:00
parent 14a97d082e
commit 4f0f481f63
7 changed files with 16 additions and 16 deletions

View file

@ -42,11 +42,11 @@ public:
void Decode(); void Decode();
/// Returns most recently decoded frame /// Returns most recently decoded frame
AVFrame* GetCurrentFrame(); [[nodiscard]] AVFrame* GetCurrentFrame();
const AVFrame* GetCurrentFrame() const; [[nodiscard]] const AVFrame* GetCurrentFrame() const;
/// Returns the value of current_codec /// Returns the value of current_codec
NvdecCommon::VideoCodec GetCurrentCodec() const; [[nodiscard]] NvdecCommon::VideoCodec GetCurrentCodec() const;
private: private:
bool initialized{}; bool initialized{};

View file

@ -43,7 +43,8 @@ H264::H264(GPU& gpu_) : gpu(gpu_) {}
H264::~H264() = default; H264::~H264() = default;
std::vector<u8>& H264::ComposeFrameHeader(NvdecCommon::NvdecRegisters& state, bool is_first_frame) { const std::vector<u8>& H264::ComposeFrameHeader(NvdecCommon::NvdecRegisters& state,
bool is_first_frame) {
H264DecoderContext context{}; H264DecoderContext context{};
gpu.MemoryManager().ReadBlock(state.picture_info_offset, &context, sizeof(H264DecoderContext)); gpu.MemoryManager().ReadBlock(state.picture_info_offset, &context, sizeof(H264DecoderContext));

View file

@ -51,14 +51,14 @@ public:
void WriteScalingList(const std::vector<u8>& list, s32 start, s32 count); void WriteScalingList(const std::vector<u8>& list, s32 start, s32 count);
/// Return the bitstream as a vector. /// Return the bitstream as a vector.
std::vector<u8>& GetByteArray(); [[nodiscard]] std::vector<u8>& GetByteArray();
const std::vector<u8>& GetByteArray() const; [[nodiscard]] const std::vector<u8>& GetByteArray() const;
private: private:
void WriteBits(s32 value, s32 bit_count); void WriteBits(s32 value, s32 bit_count);
void WriteExpGolombCodedInt(s32 value); void WriteExpGolombCodedInt(s32 value);
void WriteExpGolombCodedUInt(u32 value); void WriteExpGolombCodedUInt(u32 value);
s32 GetFreeBufferBits(); [[nodiscard]] s32 GetFreeBufferBits();
void Flush(); void Flush();
s32 buffer_size{8}; s32 buffer_size{8};
@ -74,8 +74,8 @@ public:
~H264(); ~H264();
/// Compose the H264 header of the frame for FFmpeg decoding /// Compose the H264 header of the frame for FFmpeg decoding
std::vector<u8>& ComposeFrameHeader(NvdecCommon::NvdecRegisters& state, [[nodiscard]] const std::vector<u8>& ComposeFrameHeader(NvdecCommon::NvdecRegisters& state,
bool is_first_frame = false); bool is_first_frame = false);
private: private:
struct H264ParameterSet { struct H264ParameterSet {

View file

@ -854,7 +854,7 @@ VpxBitStreamWriter VP9::ComposeUncompressedHeader() {
return uncomp_writer; return uncomp_writer;
} }
std::vector<u8>& VP9::ComposeFrameHeader(NvdecCommon::NvdecRegisters& state) { const std::vector<u8>& VP9::ComposeFrameHeader(NvdecCommon::NvdecRegisters& state) {
std::vector<u8> bitstream; std::vector<u8> bitstream;
{ {
Vp9FrameContainer curr_frame = GetCurrentFrame(state); Vp9FrameContainer curr_frame = GetCurrentFrame(state);

View file

@ -119,7 +119,7 @@ public:
/// Composes the VP9 frame from the GPU state information. Based on the official VP9 spec /// Composes the VP9 frame from the GPU state information. Based on the official VP9 spec
/// documentation /// documentation
std::vector<u8>& ComposeFrameHeader(NvdecCommon::NvdecRegisters& state); [[nodiscard]] const std::vector<u8>& ComposeFrameHeader(NvdecCommon::NvdecRegisters& state);
/// Returns true if the most recent frame was a hidden frame. /// Returns true if the most recent frame was a hidden frame.
[[nodiscard]] bool WasFrameHidden() const { [[nodiscard]] bool WasFrameHidden() const {

View file

@ -231,9 +231,8 @@ struct PictureInfo {
u32 surface_params{}; u32 surface_params{};
INSERT_PADDING_WORDS(3); INSERT_PADDING_WORDS(3);
Vp9PictureInfo Convert() const { [[nodiscard]] Vp9PictureInfo Convert() const {
return {
return Vp9PictureInfo{
.is_key_frame = (vp9_flags & FrameFlags::IsKeyFrame) != 0, .is_key_frame = (vp9_flags & FrameFlags::IsKeyFrame) != 0,
.intra_only = (vp9_flags & FrameFlags::IntraOnly) != 0, .intra_only = (vp9_flags & FrameFlags::IntraOnly) != 0,
.last_frame_was_key = (vp9_flags & FrameFlags::LastFrameIsKeyFrame) != 0, .last_frame_was_key = (vp9_flags & FrameFlags::LastFrameIsKeyFrame) != 0,

View file

@ -26,8 +26,8 @@ public:
void ProcessMethod(Method method, const std::vector<u32>& arguments); void ProcessMethod(Method method, const std::vector<u32>& arguments);
/// Return most recently decoded frame /// Return most recently decoded frame
AVFrame* GetFrame(); [[nodiscard]] AVFrame* GetFrame();
const AVFrame* GetFrame() const; [[nodiscard]] const AVFrame* GetFrame() const;
private: private:
/// Invoke codec to decode a frame /// Invoke codec to decode a frame