mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-29 19:15:38 +00:00
CDImage: Add Precache() method
This commit is contained in:
parent
ec9411c0a7
commit
9ab64ecdb3
|
@ -324,6 +324,11 @@ std::string CDImage::GetSubImageMetadata(u32 index, const std::string_view& type
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDImage::PrecacheResult CDImage::Precache(ProgressCallback* progress /*= ProgressCallback::NullProgressCallback*/)
|
||||||
|
{
|
||||||
|
return PrecacheResult::Unsupported;
|
||||||
|
}
|
||||||
|
|
||||||
void CDImage::ClearTOC()
|
void CDImage::ClearTOC()
|
||||||
{
|
{
|
||||||
m_lba_count = 0;
|
m_lba_count = 0;
|
||||||
|
|
|
@ -57,6 +57,13 @@ public:
|
||||||
Mode2Raw // 2352 bytes per sector
|
Mode2Raw // 2352 bytes per sector
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class PrecacheResult : u8
|
||||||
|
{
|
||||||
|
Unsupported,
|
||||||
|
ReadError,
|
||||||
|
Success,
|
||||||
|
};
|
||||||
|
|
||||||
struct SectorHeader
|
struct SectorHeader
|
||||||
{
|
{
|
||||||
u8 minute;
|
u8 minute;
|
||||||
|
@ -294,6 +301,9 @@ public:
|
||||||
// Retrieve sub-image metadata.
|
// Retrieve sub-image metadata.
|
||||||
virtual std::string GetSubImageMetadata(u32 index, const std::string_view& type) const;
|
virtual std::string GetSubImageMetadata(u32 index, const std::string_view& type) const;
|
||||||
|
|
||||||
|
// Returns true if the source supports precaching, which may be more optimal than an in-memory copy.
|
||||||
|
virtual PrecacheResult Precache(ProgressCallback* progress = ProgressCallback::NullProgressCallback);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ClearTOC();
|
void ClearTOC();
|
||||||
void CopyTOC(const CDImage* image);
|
void CopyTOC(const CDImage* image);
|
||||||
|
|
|
@ -683,11 +683,22 @@ std::unique_ptr<CDImage> OpenCDImage(const char* path, Common::Error* error, boo
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HostInterfaceProgressCallback callback;
|
HostInterfaceProgressCallback callback;
|
||||||
std::unique_ptr<CDImage> memory_image = CDImage::CreateMemoryImage(media.get(), &callback);
|
const CDImage::PrecacheResult res = media->Precache(&callback);
|
||||||
if (memory_image)
|
if (res == CDImage::PrecacheResult::Unsupported)
|
||||||
media = std::move(memory_image);
|
{
|
||||||
else
|
// fall back to copy precaching
|
||||||
Log_WarningPrintf("Failed to preload image '%s' to RAM", path);
|
std::unique_ptr<CDImage> memory_image = CDImage::CreateMemoryImage(media.get(), &callback);
|
||||||
|
if (memory_image)
|
||||||
|
media = std::move(memory_image);
|
||||||
|
else
|
||||||
|
Log_WarningPrintf("Failed to preload image '%s' to RAM", path);
|
||||||
|
}
|
||||||
|
else if (res != CDImage::PrecacheResult::Success)
|
||||||
|
{
|
||||||
|
g_host_interface->AddOSDMessage(
|
||||||
|
g_host_interface->TranslateStdString("OSDMessage", "Precaching CD image failed, it may be unreliable."),
|
||||||
|
15.0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue