CDVD: Purge AsyncFileReader interface

Everything goes through ThreadedFileReader now.
This commit is contained in:
Stenzek 2024-05-16 21:14:31 +10:00 committed by Connor McLaughlin
parent 7587bb8a07
commit d099f7afd6
13 changed files with 37 additions and 75 deletions

View File

@ -1,43 +0,0 @@
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-3.0+
#pragma once
#include "common/Pcsx2Defs.h"
#include <memory>
#include <string>
class Error;
class AsyncFileReader
{
protected:
AsyncFileReader() = default;
std::string m_filename;
u32 m_dataoffset = 0;
u32 m_blocksize = 2048;
public:
virtual ~AsyncFileReader(){};
virtual bool Open(std::string filename, Error* error) = 0;
virtual int ReadSync(void* pBuffer, u32 sector, u32 count) = 0;
virtual void BeginRead(void* pBuffer, u32 sector, u32 count) = 0;
virtual int FinishRead() = 0;
virtual void CancelRead() = 0;
virtual void Close() = 0;
virtual u32 GetBlockCount() const = 0;
virtual void SetBlockSize(u32 bytes) {}
virtual void SetDataOffset(u32 bytes) {}
const std::string& GetFilename() const { return m_filename; }
u32 GetBlockSize() const { return m_blocksize; }
};

View File

@ -20,7 +20,7 @@ enum isoFlags
static constexpr u32 BlockDumpHeaderSize = 16;
bool BlockdumpFileReader::DetectBlockdump(AsyncFileReader* reader)
bool BlockdumpFileReader::DetectBlockdump(ThreadedFileReader* reader)
{
u32 oldbs = reader->GetBlockSize();

View File

@ -33,7 +33,7 @@ public:
u32 GetBlockCount() const override;
static bool DetectBlockdump(AsyncFileReader* reader);
static bool DetectBlockdump(ThreadedFileReader* reader);
s32 GetBlockOffset() { return m_blockofs; }
};

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: LGPL-3.0+
#include "IsoFileFormats.h"
#include "AsyncFileReader.h"
#include "CDVD/CDVD.h"
#include "common/Assertions.h"

View File

@ -1,7 +1,6 @@
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-3.0+
#include "AsyncFileReader.h"
#include "CompressedFileReader.h"
#include "ChdFileReader.h"
#include "CsoFileReader.h"
@ -14,7 +13,7 @@
#include <algorithm>
#include <cctype>
AsyncFileReader* CompressedFileReader::GetNewReader(const std::string& fileName)
ThreadedFileReader* CompressedFileReader::GetNewReader(const std::string& fileName)
{
if (!FileSystem::FileExists(fileName.c_str()))
return nullptr;

View File

@ -4,6 +4,8 @@
#pragma once
#include <string>
class ThreadedFileReader;
// Factory - creates an AsyncFileReader derived instance which can read a compressed file
class CompressedFileReader
{
@ -12,7 +14,7 @@ public:
// If no matching handler is found, NULL is returned.
// The returned instance still needs ->Open(filename) before usage.
// Open(filename) may still fail.
static AsyncFileReader* GetNewReader(const std::string& fileName);
static ThreadedFileReader* GetNewReader(const std::string& fileName);
private:
virtual ~CompressedFileReader() = 0;

View File

@ -1,8 +1,7 @@
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-3.0+
#include "AsyncFileReader.h"
#include "CsoFileReader.h"
#include "CDVD/CsoFileReader.h"
#include "common/Assertions.h"
#include "common/Console.h"

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0+
#include "CDVD/BlockdumpFileReader.h"
#include "CDVD/CompressedFileReader.h"
#include "CDVD/FlatFileReader.h"
#include "CDVD/IsoFileFormats.h"
#include "Config.h"
@ -316,13 +317,11 @@ bool InputIsoFile::Detect(bool readType)
{
m_type = ISOTYPE_ILLEGAL;
AsyncFileReader* headpart = m_reader;
// First sanity check: no sane CD image has less than 16 sectors, since that's what
// we need simply to contain a TOC. So if the file size is not large enough to
// accommodate that, it is NOT a CD image --->
int sectors = headpart->GetBlockCount();
int sectors = m_reader->GetBlockCount();
if (sectors < 17)
return false;

View File

@ -3,9 +3,8 @@
#pragma once
#include "CDVD.h"
#include "AsyncFileReader.h"
#include "CompressedFileReader.h"
#include "CDVD/CDVD.h"
#include "CDVD/ThreadedFileReader.h"
#include <memory>
#include <string>
#include <vector>
@ -37,7 +36,7 @@ protected:
protected:
std::string m_filename;
AsyncFileReader* m_reader;
ThreadedFileReader* m_reader;
u32 m_current_lsn;

View File

@ -1,21 +1,28 @@
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-3.0+
#pragma once
#include "AsyncFileReader.h"
#include "common/Pcsx2Defs.h"
#include <thread>
#include <mutex>
#include <atomic>
#include <condition_variable>
class Error;
/// A file reader for use with compressed formats
/// Calls decompression code on a separate thread to make a synchronous decompression API async
class ThreadedFileReader : public AsyncFileReader
class ThreadedFileReader
{
ThreadedFileReader(ThreadedFileReader&&) = delete;
protected:
std::string m_filename;
u32 m_dataoffset = 0;
u32 m_blocksize = 2048;
struct Chunk
{
/// Negative block IDs indicate invalid blocks
@ -39,7 +46,6 @@ protected:
virtual void Close2() = 0;
ThreadedFileReader();
~ThreadedFileReader();
private:
int m_amtRead;
@ -96,12 +102,19 @@ private:
bool TryCachedRead(void*& buffer, u64& offset, u32& size, const std::lock_guard<std::mutex>&);
public:
bool Open(std::string filename, Error* error) final override;
int ReadSync(void* pBuffer, u32 sector, u32 count) final override;
void BeginRead(void* pBuffer, u32 sector, u32 count) final override;
int FinishRead() final override;
void CancelRead() final override;
void Close() final override;
void SetBlockSize(u32 bytes) final override;
void SetDataOffset(u32 bytes) final override;
virtual ~ThreadedFileReader();
const std::string& GetFilename() const { return m_filename; }
u32 GetBlockSize() const { return m_blocksize; }
virtual u32 GetBlockCount() const = 0;
bool Open(std::string filename, Error* error);
int ReadSync(void* pBuffer, u32 sector, u32 count);
void BeginRead(void* pBuffer, u32 sector, u32 count);
int FinishRead();
void CancelRead();
void Close();
void SetBlockSize(u32 bytes);
void SetDataOffset(u32 bytes);
};

View File

@ -140,7 +140,6 @@ set(pcsx2Sources
# Main pcsx2 header
set(pcsx2Headers
Achievements.h
AsyncFileReader.h
Cache.h
Common.h
Config.h

View File

@ -460,7 +460,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="Achievements.h" />
<ClInclude Include="AsyncFileReader.h" />
<ClInclude Include="CDVD\BlockdumpFileReader.h" />
<ClInclude Include="CDVD\CDVDdiscReader.h" />
<ClInclude Include="CDVD\CompressedFileReader.h" />

View File

@ -1628,9 +1628,6 @@
<ClInclude Include="x86\microVU_Profiler.h">
<Filter>System\Ps2\EmotionEngine\VU\Dynarec\microVU</Filter>
</ClInclude>
<ClInclude Include="AsyncFileReader.h">
<Filter>System\ISO</Filter>
</ClInclude>
<ClInclude Include="DebugTools\SymbolMap.h">
<Filter>System\Ps2\Debug</Filter>
</ClInclude>