Optimize speed when reading subchannels.

This commit is contained in:
2020-06-14 18:42:33 +01:00
parent c1d9ce5aea
commit 1f52389048
6 changed files with 13 additions and 35 deletions

View File

@@ -86,7 +86,7 @@ namespace Aaru.Core.Devices.Dumping
bool read12, bool read16, bool readcd, int sectorsForOffset, uint subSize, bool read12, bool read16, bool readcd, int sectorsForOffset, uint subSize,
MmcSubchannel supportedSubchannel, bool supportsLongSectors, ref double totalDuration, MmcSubchannel supportedSubchannel, bool supportsLongSectors, ref double totalDuration,
Track[] tracks, SubchannelLog subLog, MmcSubchannel desiredSubchannel, Track[] tracks, SubchannelLog subLog, MmcSubchannel desiredSubchannel,
Dictionary<byte, string> isrcs, ref string mcn, ExtentsInt subchannelExtents) Dictionary<byte, string> isrcs, ref string mcn, HashSet<int> subchannelExtents)
{ {
ulong sectorSpeedStart = 0; // Used to calculate correct speed ulong sectorSpeedStart = 0; // Used to calculate correct speed
DateTime timeSpeedStart = DateTime.UtcNow; // Time of start for speed calculation DateTime timeSpeedStart = DateTime.UtcNow; // Time of start for speed calculation

View File

@@ -115,7 +115,7 @@ namespace Aaru.Core.Devices.Dumping
bool bcdSubchannel = false; // Subchannel positioning is in BCD bool bcdSubchannel = false; // Subchannel positioning is in BCD
Dictionary<byte, string> isrcs = new Dictionary<byte, string>(); Dictionary<byte, string> isrcs = new Dictionary<byte, string>();
string mcn = null; string mcn = null;
var subchannelExtents = new ExtentsInt(); HashSet<int> subchannelExtents = new HashSet<int>();
Dictionary<MediaTagType, byte[]> mediaTags = new Dictionary<MediaTagType, byte[]>(); // Media tags Dictionary<MediaTagType, byte[]> mediaTags = new Dictionary<MediaTagType, byte[]>(); // Media tags
@@ -852,7 +852,7 @@ namespace Aaru.Core.Devices.Dumping
if(supportedSubchannel != MmcSubchannel.None && if(supportedSubchannel != MmcSubchannel.None &&
desiredSubchannel != MmcSubchannel.None) desiredSubchannel != MmcSubchannel.None)
{ {
subchannelExtents = new ExtentsInt(); subchannelExtents = new HashSet<int>();
_resume.BadSubchannels ??= new List<int>(); _resume.BadSubchannels ??= new List<int>();
@@ -860,7 +860,8 @@ namespace Aaru.Core.Devices.Dumping
subchannelExtents.Add(sub); subchannelExtents.Add(sub);
if(_resume.NextBlock < blocks) if(_resume.NextBlock < blocks)
subchannelExtents.Add((int)_resume.NextBlock, (int)(blocks - 1)); for(ulong i = _resume.NextBlock; i < blocks; i++)
subchannelExtents.Add((int)i);
} }
if(_resume.NextBlock > 0) if(_resume.NextBlock > 0)
@@ -1106,18 +1107,7 @@ namespace Aaru.Core.Devices.Dumping
currentTry.Extents = ExtentsConverter.ToMetadata(extents); currentTry.Extents = ExtentsConverter.ToMetadata(extents);
_resume.BadSubchannels = new List<int>(); _resume.BadSubchannels = new List<int>();
_resume.BadSubchannels.AddRange(subchannelExtents);
foreach(Tuple<int, int> extent in subchannelExtents.ToArray())
{
for(int sub = extent.Item1; sub <= extent.Item2; sub++)
{
if(sub >= (int)_resume.NextBlock)
continue;
_resume.BadSubchannels.Add(sub);
}
}
_resume.BadSubchannels.Sort(); _resume.BadSubchannels.Sort();
// TODO: Disc ID // TODO: Disc ID

View File

@@ -55,7 +55,7 @@ namespace Aaru.Core.Devices.Dumping
ExtentsULong extents, int offsetBytes, bool readcd, int sectorsForOffset, uint subSize, ExtentsULong extents, int offsetBytes, bool readcd, int sectorsForOffset, uint subSize,
MmcSubchannel supportedSubchannel, ref double totalDuration, SubchannelLog subLog, MmcSubchannel supportedSubchannel, ref double totalDuration, SubchannelLog subLog,
MmcSubchannel desiredSubchannel, Track[] tracks, Dictionary<byte, string> isrcs, MmcSubchannel desiredSubchannel, Track[] tracks, Dictionary<byte, string> isrcs,
ref string mcn, ExtentsInt subchannelExtents) ref string mcn, HashSet<int> subchannelExtents)
{ {
bool sense = true; // Sense indicator bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer byte[] cmdBuf = null; // Data buffer
@@ -447,7 +447,7 @@ namespace Aaru.Core.Devices.Dumping
void RetrySubchannel(bool readcd, uint subSize, MmcSubchannel supportedSubchannel, ref double totalDuration, void RetrySubchannel(bool readcd, uint subSize, MmcSubchannel supportedSubchannel, ref double totalDuration,
SubchannelLog subLog, MmcSubchannel desiredSubchannel, Track[] tracks, SubchannelLog subLog, MmcSubchannel desiredSubchannel, Track[] tracks,
Dictionary<byte, string> isrcs, ref string mcn, ExtentsInt subchannelExtents) Dictionary<byte, string> isrcs, ref string mcn, HashSet<int> subchannelExtents)
{ {
bool sense = true; // Sense indicator bool sense = true; // Sense indicator
byte[] cmdBuf = null; // Data buffer byte[] cmdBuf = null; // Data buffer
@@ -495,18 +495,7 @@ namespace Aaru.Core.Devices.Dumping
cdRepeatRetry: cdRepeatRetry:
_resume.BadSubchannels = new List<int>(); _resume.BadSubchannels = new List<int>();
_resume.BadSubchannels.AddRange(subchannelExtents);
foreach(Tuple<int, int> extent in subchannelExtents.ToArray())
{
for(int sub = extent.Item1; sub <= extent.Item2; sub++)
{
if(sub >= (int)_resume.NextBlock)
continue;
_resume.BadSubchannels.Add(sub);
}
}
_resume.BadSubchannels.Sort(); _resume.BadSubchannels.Sort();
if(!forward) if(!forward)

View File

@@ -75,7 +75,7 @@ namespace Aaru.Core.Devices.Dumping
bool read6, bool read10, bool read12, bool read16, bool readcd, bool read6, bool read10, bool read12, bool read16, bool readcd,
MmcSubchannel supportedSubchannel, uint subSize, ref double totalDuration, MmcSubchannel supportedSubchannel, uint subSize, ref double totalDuration,
SubchannelLog subLog, MmcSubchannel desiredSubchannel, Dictionary<byte, string> isrcs, SubchannelLog subLog, MmcSubchannel desiredSubchannel, Dictionary<byte, string> isrcs,
ref string mcn, Track[] tracks, ExtentsInt subchannelExtents) ref string mcn, Track[] tracks, HashSet<int> subchannelExtents)
{ {
byte[] cmdBuf = null; // Data buffer byte[] cmdBuf = null; // Data buffer
const uint sectorSize = 2352; // Full sector size const uint sectorSize = 2352; // Full sector size
@@ -239,7 +239,7 @@ namespace Aaru.Core.Devices.Dumping
bool read6, bool read10, bool read12, bool read16, bool readcd, bool read6, bool read10, bool read12, bool read16, bool readcd,
MmcSubchannel supportedSubchannel, uint subSize, ref double totalDuration, MmcSubchannel supportedSubchannel, uint subSize, ref double totalDuration,
SubchannelLog subLog, MmcSubchannel desiredSubchannel, Dictionary<byte, string> isrcs, SubchannelLog subLog, MmcSubchannel desiredSubchannel, Dictionary<byte, string> isrcs,
ref string mcn, Track[] tracks, ExtentsInt subchannelExtents) ref string mcn, Track[] tracks, HashSet<int> subchannelExtents)
{ {
byte[] cmdBuf = null; // Data buffer byte[] cmdBuf = null; // Data buffer
const uint sectorSize = 2352; // Full sector size const uint sectorSize = 2352; // Full sector size

View File

@@ -34,7 +34,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Aaru.Checksums; using Aaru.Checksums;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Extents;
using Aaru.CommonTypes.Structs; using Aaru.CommonTypes.Structs;
using Aaru.Core.Logging; using Aaru.Core.Logging;
using Aaru.Decoders.CD; using Aaru.Decoders.CD;
@@ -72,7 +71,7 @@ namespace Aaru.Core.Devices.Dumping
bool WriteSubchannelToImage(MmcSubchannel supportedSubchannel, MmcSubchannel desiredSubchannel, byte[] sub, bool WriteSubchannelToImage(MmcSubchannel supportedSubchannel, MmcSubchannel desiredSubchannel, byte[] sub,
ulong sectorAddress, uint length, SubchannelLog subLog, ulong sectorAddress, uint length, SubchannelLog subLog,
Dictionary<byte, string> isrcs, byte currentTrack, ref string mcn, Track[] tracks, Dictionary<byte, string> isrcs, byte currentTrack, ref string mcn, Track[] tracks,
ExtentsInt subchannelExtents) HashSet<int> subchannelExtents)
{ {
if(supportedSubchannel == MmcSubchannel.Q16) if(supportedSubchannel == MmcSubchannel.Q16)
sub = Subchannel.ConvertQToRaw(sub); sub = Subchannel.ConvertQToRaw(sub);

View File

@@ -53,7 +53,7 @@ namespace Aaru.Core.Devices.Dumping
bool read16, bool readcd, int sectorsForOffset, uint subSize, bool read16, bool readcd, int sectorsForOffset, uint subSize,
MmcSubchannel supportedSubchannel, bool supportsLongSectors, ref double totalDuration, MmcSubchannel supportedSubchannel, bool supportsLongSectors, ref double totalDuration,
SubchannelLog subLog, MmcSubchannel desiredSubchannel, Track[] tracks, SubchannelLog subLog, MmcSubchannel desiredSubchannel, Track[] tracks,
Dictionary<byte, string> isrcs, ref string mcn, ExtentsInt subchannelExtents) Dictionary<byte, string> isrcs, ref string mcn, HashSet<int> subchannelExtents)
{ {
DateTime start; DateTime start;
DateTime end; DateTime end;