CDROM: Revamp/improve preload image procedure

This commit is contained in:
Connor McLaughlin
2022-07-23 13:23:54 +10:00
parent 8d7fdae683
commit a1edddc59d
9 changed files with 130 additions and 64 deletions

View File

@ -330,6 +330,11 @@ CDImage::PrecacheResult CDImage::Precache(ProgressCallback* progress /*= Progres
return PrecacheResult::Unsupported;
}
bool CDImage::IsPrecached() const
{
return false;
}
void CDImage::ClearTOC()
{
m_lba_count = 0;

View File

@ -303,6 +303,7 @@ public:
// Returns true if the source supports precaching, which may be more optimal than an in-memory copy.
virtual PrecacheResult Precache(ProgressCallback* progress = ProgressCallback::NullProgressCallback);
virtual bool IsPrecached() const;
protected:
void ClearTOC();

View File

@ -10,6 +10,7 @@
#include "common/file_system.h"
#include "common/log.h"
#include "common/platform.h"
#include "fmt/format.h"
#include "libchdr/chd.h"
#include <algorithm>
#include <cerrno>
@ -53,6 +54,7 @@ public:
bool ReadSubChannelQ(SubChannelQ* subq, const Index& index, LBA lba_in_index) override;
bool HasNonStandardSubchannel() const override;
PrecacheResult Precache(ProgressCallback* progress) override;
bool IsPrecached() const override;
protected:
bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override;
@ -73,6 +75,7 @@ private:
std::vector<u8> m_hunk_buffer;
u32 m_current_hunk_index = static_cast<u32>(-1);
bool m_precached = false;
CDSubChannelReplacement m_sbi;
};
@ -303,16 +306,27 @@ bool CDImageCHD::HasNonStandardSubchannel() const
CDImage::PrecacheResult CDImageCHD::Precache(ProgressCallback* progress)
{
const std::string_view title(FileSystem::GetDisplayNameFromPath(m_filename));
progress->SetFormattedStatusText("Precaching %.*s...", static_cast<int>(title.size()), title.data());
if (m_precached)
return CDImage::PrecacheResult::Success;
progress->SetStatusText(fmt::format("Precaching {}...", FileSystem::GetDisplayNameFromPath(m_filename)).c_str());
progress->SetProgressRange(100);
auto callback = [](size_t pos, size_t total, void* param) {
const u32 percent = static_cast<u32>((pos * 100) / total);
static_cast<ProgressCallback*>(param)->SetProgressValue(std::min<u32>(percent, 100));
};
return (chd_precache_progress(m_chd, callback, progress) == CHDERR_NONE) ? CDImage::PrecacheResult::Success :
CDImage::PrecacheResult::ReadError;
if (chd_precache_progress(m_chd, callback, progress) != CHDERR_NONE)
return CDImage::PrecacheResult::ReadError;
m_precached = true;
return CDImage::PrecacheResult::Success;
}
bool CDImageCHD::IsPrecached() const
{
return m_precached;
}
// There's probably a more efficient way of doing this with vectorization...

View File

@ -19,6 +19,8 @@ public:
bool ReadSubChannelQ(SubChannelQ* subq, const Index& index, LBA lba_in_index) override;
bool HasNonStandardSubchannel() const override;
bool IsPrecached() const override;
protected:
bool ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index) override;
@ -128,6 +130,11 @@ bool CDImageMemory::HasNonStandardSubchannel() const
return (m_sbi.GetReplacementSectorCount() > 0);
}
bool CDImageMemory::IsPrecached() const
{
return true;
}
bool CDImageMemory::ReadSectorFromIndex(void* buffer, const Index& index, LBA lba_in_index)
{
DebugAssert(index.file_index == 0);