From 6c96d9f43d76d9747e5b7fe4227d807889b016c5 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 15 Sep 2026 07:59:31 +0000 Subject: [PATCH] 2026-09-15 07:59:31 Signed-off-by: lizzie --- src/common/CMakeLists.txt | 2 - src/common/stream.cpp | 46 ----------------------- src/common/stream.h | 55 ---------------------------- src/video_core/host1x/codecs/vp9.cpp | 24 ++++-------- src/video_core/host1x/codecs/vp9.h | 10 +++-- 5 files changed, 14 insertions(+), 123 deletions(-) delete mode 100644 src/common/stream.cpp delete mode 100644 src/common/stream.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 61e0e64aa8..6c2b83cfcd 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -115,8 +115,6 @@ add_library( stb.h steady_clock.cpp steady_clock.h - stream.cpp - stream.h string_util.cpp string_util.h swap.h diff --git a/src/common/stream.cpp b/src/common/stream.cpp deleted file mode 100644 index 80ddd68c81..0000000000 --- a/src/common/stream.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include -#include "common/common_types.h" -#include "common/stream.h" - -namespace Common { - -Stream::Stream() = default; -Stream::~Stream() = default; - -void Stream::Seek(s32 offset, SeekOrigin origin) { - if (origin == SeekOrigin::SetOrigin) { - if (offset < 0) { - position = 0; - } else if (position >= buffer.size()) { - position = buffer.size(); - } else { - position = offset; - } - } else if (origin == SeekOrigin::FromCurrentPos) { - Seek(static_cast(position) + offset, SeekOrigin::SetOrigin); - } else if (origin == SeekOrigin::FromEnd) { - Seek(static_cast(buffer.size()) - offset, SeekOrigin::SetOrigin); - } -} - -u8 Stream::ReadByte() { - if (position < buffer.size()) { - return buffer[position++]; - } else { - throw std::out_of_range("Attempting to read a byte not within the buffer range"); - } -} - -void Stream::WriteByte(u8 byte) { - if (position == buffer.size()) { - buffer.push_back(byte); - position++; - } else { - buffer.insert(buffer.begin() + position, byte); - } -} - -} // namespace Common diff --git a/src/common/stream.h b/src/common/stream.h deleted file mode 100644 index 5bb26e8835..0000000000 --- a/src/common/stream.h +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include "common/common_types.h" - -namespace Common { - -enum class SeekOrigin { - SetOrigin, - FromCurrentPos, - FromEnd, -}; - -class Stream { -public: - /// Stream creates a bitstream and provides common functionality on the stream. - explicit Stream(); - ~Stream(); - - Stream(const Stream&) = delete; - Stream& operator=(const Stream&) = delete; - - Stream(Stream&&) = default; - Stream& operator=(Stream&&) = default; - - /// Reposition bitstream "cursor" to the specified offset from origin - void Seek(s32 offset, SeekOrigin origin); - - /// Reads next byte in the stream buffer and increments position - u8 ReadByte(); - - /// Writes byte at current position - void WriteByte(u8 byte); - - [[nodiscard]] std::size_t GetPosition() const { - return position; - } - - [[nodiscard]] std::vector& GetBuffer() { - return buffer; - } - - [[nodiscard]] const std::vector& GetBuffer() const { - return buffer; - } - -private: - std::vector buffer; - std::size_t position{0}; -}; - -} // namespace Common diff --git a/src/video_core/host1x/codecs/vp9.cpp b/src/video_core/host1x/codecs/vp9.cpp index dcc6261e5c..f3fc369925 100644 --- a/src/video_core/host1x/codecs/vp9.cpp +++ b/src/video_core/host1x/codecs/vp9.cpp @@ -895,17 +895,16 @@ void VpxRangeEncoder::Write(bool bit, s32 probability) { const s32 offset = shift - count; if (((low_value << (offset - 1)) >> 31) != 0) { - const s32 current_pos = static_cast(base_stream.GetPosition()); - base_stream.Seek(-1, Common::SeekOrigin::FromCurrentPos); - while (PeekByte() == 0xff) { - base_stream.WriteByte(0); - - base_stream.Seek(-2, Common::SeekOrigin::FromCurrentPos); + auto const current_pos = s32(stream_pos); + --stream_pos; + while (stream_data[stream_pos] == 0xff) { + stream_data[stream_pos++] = 0; + stream_pos -= 2; } - base_stream.WriteByte(static_cast((PeekByte() + 1))); - base_stream.Seek(current_pos, Common::SeekOrigin::SetOrigin); + stream_data[stream_pos]++; + stream_pos = current_pos; } - base_stream.WriteByte(static_cast((low_value >> (24 - offset)))); + stream_data[stream_pos++] = u8((low_value >> (24 - offset))); low_value <<= offset; shift = count; @@ -923,13 +922,6 @@ void VpxRangeEncoder::End() { } } -u8 VpxRangeEncoder::PeekByte() { - const u8 value = base_stream.ReadByte(); - base_stream.Seek(-1, Common::SeekOrigin::FromCurrentPos); - - return value; -} - VpxBitStreamWriter::VpxBitStreamWriter() = default; VpxBitStreamWriter::~VpxBitStreamWriter() = default; diff --git a/src/video_core/host1x/codecs/vp9.h b/src/video_core/host1x/codecs/vp9.h index f0265669b8..f74eb79463 100644 --- a/src/video_core/host1x/codecs/vp9.h +++ b/src/video_core/host1x/codecs/vp9.h @@ -12,7 +12,6 @@ #include "common/common_types.h" #include "common/scratch_buffer.h" -#include "common/stream.h" #include "video_core/host1x/codecs/decoder.h" #include "video_core/host1x/codec_types.h" #include "video_core/host1x/nvdec_common.h" @@ -52,16 +51,19 @@ public: void End(); [[nodiscard]] std::vector& GetBuffer() { - return base_stream.GetBuffer(); + return stream_data; } [[nodiscard]] const std::vector& GetBuffer() const { - return base_stream.GetBuffer(); + return stream_data; } private: u8 PeekByte(); - Common::Stream base_stream{}; + + std::vector stream_data{}; + size_t stream_pos; + u32 low_value{}; u32 range{0xff}; s32 count{-24};