mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Move CD first track pregap reading to a separate file.
This commit is contained in:
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
1
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
@@ -238,6 +238,7 @@
|
|||||||
<e p="Dump.cs" t="Include" />
|
<e p="Dump.cs" t="Include" />
|
||||||
<e p="Error.cs" t="Include" />
|
<e p="Error.cs" t="Include" />
|
||||||
<e p="LeadOuts.cs" t="Include" />
|
<e p="LeadOuts.cs" t="Include" />
|
||||||
|
<e p="Pregap.cs" t="Include" />
|
||||||
<e p="Subchannel.cs" t="Include" />
|
<e p="Subchannel.cs" t="Include" />
|
||||||
<e p="Tags.cs" t="Include" />
|
<e p="Tags.cs" t="Include" />
|
||||||
<e p="Tracks.cs" t="Include" />
|
<e p="Tracks.cs" t="Include" />
|
||||||
|
|||||||
@@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using DiscImageChef.CommonTypes;
|
using DiscImageChef.CommonTypes;
|
||||||
@@ -70,7 +69,6 @@ namespace DiscImageChef.Core.Devices.Dumping
|
|||||||
uint blockSize; // Size of the read sector in bytes
|
uint blockSize; // Size of the read sector in bytes
|
||||||
CdOffset cdOffset; // Read offset from database
|
CdOffset cdOffset; // Read offset from database
|
||||||
byte[] cmdBuf; // Data buffer
|
byte[] cmdBuf; // Data buffer
|
||||||
double cmdDuration; // Command execution time
|
|
||||||
DumpHardwareType currentTry = null; // Current dump hardware try
|
DumpHardwareType currentTry = null; // Current dump hardware try
|
||||||
double currentSpeed = 0; // Current read speed
|
double currentSpeed = 0; // Current read speed
|
||||||
DateTime dumpStart = DateTime.UtcNow; // Time of dump start
|
DateTime dumpStart = DateTime.UtcNow; // Time of dump start
|
||||||
@@ -95,7 +93,6 @@ namespace DiscImageChef.Core.Devices.Dumping
|
|||||||
bool ret; // Image writing return status
|
bool ret; // Image writing return status
|
||||||
const uint sectorSize = 2352; // Full sector size
|
const uint sectorSize = 2352; // Full sector size
|
||||||
int sectorsForOffset = 0; // Sectors needed to fix offset
|
int sectorsForOffset = 0; // Sectors needed to fix offset
|
||||||
ulong sectorSpeedStart = 0; // Used to calculate correct speed
|
|
||||||
bool sense = true; // Sense indicator
|
bool sense = true; // Sense indicator
|
||||||
int sessions; // Number of sessions in disc
|
int sessions; // Number of sessions in disc
|
||||||
DateTime start; // Start of operation
|
DateTime start; // Start of operation
|
||||||
@@ -113,7 +110,6 @@ namespace DiscImageChef.Core.Devices.Dumping
|
|||||||
int firstTrackLastSession; // Number of first track in last session
|
int firstTrackLastSession; // Number of first track in last session
|
||||||
bool hiddenTrack; // Disc has a hidden track before track 1
|
bool hiddenTrack; // Disc has a hidden track before track 1
|
||||||
MmcSubchannel supportedSubchannel; // Drive's maximum supported subchannel
|
MmcSubchannel supportedSubchannel; // Drive's maximum supported subchannel
|
||||||
DateTime timeSpeedStart; // Time of start for speed calculation
|
|
||||||
|
|
||||||
Dictionary<MediaTagType, byte[]> mediaTags = new Dictionary<MediaTagType, byte[]>(); // Media tags
|
Dictionary<MediaTagType, byte[]> mediaTags = new Dictionary<MediaTagType, byte[]>(); // Media tags
|
||||||
|
|
||||||
@@ -603,70 +599,7 @@ namespace DiscImageChef.Core.Devices.Dumping
|
|||||||
|
|
||||||
// Try to read the first track pregap
|
// Try to read the first track pregap
|
||||||
if(_dumpFirstTrackPregap && readcd)
|
if(_dumpFirstTrackPregap && readcd)
|
||||||
{
|
ReadCdFirstTrackPregap(blockSize, ref currentSpeed, mediaTags, supportedSubchannel, ref totalDuration);
|
||||||
bool gotFirstTrackPregap = false;
|
|
||||||
int firstTrackPregapSectorsGood = 0;
|
|
||||||
var firstTrackPregapMs = new MemoryStream();
|
|
||||||
|
|
||||||
_dumpLog.WriteLine("Reading first track pregap");
|
|
||||||
UpdateStatus?.Invoke("Reading first track pregap");
|
|
||||||
InitProgress?.Invoke();
|
|
||||||
timeSpeedStart = DateTime.UtcNow;
|
|
||||||
|
|
||||||
for(int firstTrackPregapBlock = -150; firstTrackPregapBlock < 0 && _resume.NextBlock == 0;
|
|
||||||
firstTrackPregapBlock++)
|
|
||||||
{
|
|
||||||
if(_aborted)
|
|
||||||
{
|
|
||||||
_dumpLog.WriteLine("Aborted!");
|
|
||||||
UpdateStatus?.Invoke("Aborted!");
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
PulseProgress?.
|
|
||||||
Invoke($"Trying to read first track pregap sector {firstTrackPregapBlock} ({currentSpeed:F3} MiB/sec.)");
|
|
||||||
|
|
||||||
sense = _dev.ReadCd(out cmdBuf, out _, (uint)firstTrackPregapBlock, blockSize, 1,
|
|
||||||
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true,
|
|
||||||
true, MmcErrorField.None, supportedSubchannel, _dev.Timeout, out cmdDuration);
|
|
||||||
|
|
||||||
if(!sense &&
|
|
||||||
!_dev.Error)
|
|
||||||
{
|
|
||||||
firstTrackPregapMs.Write(cmdBuf, 0, (int)blockSize);
|
|
||||||
gotFirstTrackPregap = true;
|
|
||||||
firstTrackPregapSectorsGood++;
|
|
||||||
totalDuration += cmdDuration;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Write empty data
|
|
||||||
if(gotFirstTrackPregap)
|
|
||||||
firstTrackPregapMs.Write(new byte[blockSize], 0, (int)blockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
sectorSpeedStart++;
|
|
||||||
|
|
||||||
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
|
||||||
|
|
||||||
if(elapsed < 1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
currentSpeed = (sectorSpeedStart * blockSize) / (1048576 * elapsed);
|
|
||||||
sectorSpeedStart = 0;
|
|
||||||
timeSpeedStart = DateTime.UtcNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(firstTrackPregapSectorsGood > 0)
|
|
||||||
mediaTags.Add(MediaTagType.CD_FirstTrackPregap, firstTrackPregapMs.ToArray());
|
|
||||||
|
|
||||||
EndProgress?.Invoke();
|
|
||||||
UpdateStatus?.Invoke($"Got {firstTrackPregapSectorsGood} first track pregap sectors.");
|
|
||||||
_dumpLog.WriteLine("Got {0} first track pregap sectors.", firstTrackPregapSectorsGood);
|
|
||||||
|
|
||||||
firstTrackPregapMs.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try how many blocks are readable at once
|
// Try how many blocks are readable at once
|
||||||
while(true)
|
while(true)
|
||||||
|
|||||||
120
DiscImageChef.Core/Devices/Dumping/CompactDisc/Pregap.cs
Normal file
120
DiscImageChef.Core/Devices/Dumping/CompactDisc/Pregap.cs
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
// /***************************************************************************
|
||||||
|
// The Disc Image Chef
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Filename : CompactDisc.cs
|
||||||
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||||
|
//
|
||||||
|
// Component : Core algorithms.
|
||||||
|
//
|
||||||
|
// --[ Description ] ----------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Dumps CDs and DDCDs.
|
||||||
|
//
|
||||||
|
// --[ License ] --------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Copyright © 2011-2019 Natalia Portillo
|
||||||
|
// ****************************************************************************/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using DiscImageChef.CommonTypes.Enums;
|
||||||
|
using DiscImageChef.Devices;
|
||||||
|
|
||||||
|
// ReSharper disable JoinDeclarationAndInitializer
|
||||||
|
// ReSharper disable InlineOutVariableDeclaration
|
||||||
|
// ReSharper disable TooWideLocalVariableScope
|
||||||
|
|
||||||
|
namespace DiscImageChef.Core.Devices.Dumping
|
||||||
|
{
|
||||||
|
partial class Dump
|
||||||
|
{
|
||||||
|
// TODO: Fix offset
|
||||||
|
void ReadCdFirstTrackPregap(uint blockSize, ref double currentSpeed, Dictionary<MediaTagType, byte[]> mediaTags,
|
||||||
|
MmcSubchannel supportedSubchannel, ref double totalDuration)
|
||||||
|
{
|
||||||
|
bool sense; // Sense indicator
|
||||||
|
byte[] cmdBuf; // Data buffer
|
||||||
|
double cmdDuration; // Command execution time
|
||||||
|
DateTime timeSpeedStart; // Time of start for speed calculation
|
||||||
|
ulong sectorSpeedStart = 0; // Used to calculate correct speed
|
||||||
|
bool gotFirstTrackPregap = false;
|
||||||
|
int firstTrackPregapSectorsGood = 0;
|
||||||
|
var firstTrackPregapMs = new MemoryStream();
|
||||||
|
|
||||||
|
_dumpLog.WriteLine("Reading first track pregap");
|
||||||
|
UpdateStatus?.Invoke("Reading first track pregap");
|
||||||
|
InitProgress?.Invoke();
|
||||||
|
timeSpeedStart = DateTime.UtcNow;
|
||||||
|
|
||||||
|
for(int firstTrackPregapBlock = -150; firstTrackPregapBlock < 0 && _resume.NextBlock == 0;
|
||||||
|
firstTrackPregapBlock++)
|
||||||
|
{
|
||||||
|
if(_aborted)
|
||||||
|
{
|
||||||
|
_dumpLog.WriteLine("Aborted!");
|
||||||
|
UpdateStatus?.Invoke("Aborted!");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
PulseProgress?.
|
||||||
|
Invoke($"Trying to read first track pregap sector {firstTrackPregapBlock} ({currentSpeed:F3} MiB/sec.)");
|
||||||
|
|
||||||
|
sense = _dev.ReadCd(out cmdBuf, out _, (uint)firstTrackPregapBlock, blockSize, 1,
|
||||||
|
MmcSectorTypes.AllTypes, false, false, true, MmcHeaderCodes.AllHeaders, true, true,
|
||||||
|
MmcErrorField.None, supportedSubchannel, _dev.Timeout, out cmdDuration);
|
||||||
|
|
||||||
|
if(!sense &&
|
||||||
|
!_dev.Error)
|
||||||
|
{
|
||||||
|
firstTrackPregapMs.Write(cmdBuf, 0, (int)blockSize);
|
||||||
|
gotFirstTrackPregap = true;
|
||||||
|
firstTrackPregapSectorsGood++;
|
||||||
|
totalDuration += cmdDuration;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Write empty data
|
||||||
|
if(gotFirstTrackPregap)
|
||||||
|
firstTrackPregapMs.Write(new byte[blockSize], 0, (int)blockSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
sectorSpeedStart++;
|
||||||
|
|
||||||
|
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
||||||
|
|
||||||
|
if(elapsed < 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
currentSpeed = (sectorSpeedStart * blockSize) / (1048576 * elapsed);
|
||||||
|
sectorSpeedStart = 0;
|
||||||
|
timeSpeedStart = DateTime.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(firstTrackPregapSectorsGood > 0)
|
||||||
|
mediaTags.Add(MediaTagType.CD_FirstTrackPregap, firstTrackPregapMs.ToArray());
|
||||||
|
|
||||||
|
EndProgress?.Invoke();
|
||||||
|
UpdateStatus?.Invoke($"Got {firstTrackPregapSectorsGood} first track pregap sectors.");
|
||||||
|
_dumpLog.WriteLine("Got {0} first track pregap sectors.", firstTrackPregapSectorsGood);
|
||||||
|
|
||||||
|
firstTrackPregapMs.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,6 +51,7 @@
|
|||||||
<Compile Include="Devices\Dumping\CompactDisc\Dump.cs" />
|
<Compile Include="Devices\Dumping\CompactDisc\Dump.cs" />
|
||||||
<Compile Include="Devices\Dumping\CompactDisc\Error.cs" />
|
<Compile Include="Devices\Dumping\CompactDisc\Error.cs" />
|
||||||
<Compile Include="Devices\Dumping\CompactDisc\LeadOuts.cs" />
|
<Compile Include="Devices\Dumping\CompactDisc\LeadOuts.cs" />
|
||||||
|
<Compile Include="Devices\Dumping\CompactDisc\Pregap.cs" />
|
||||||
<Compile Include="Devices\Dumping\CompactDisc\Subchannel.cs" />
|
<Compile Include="Devices\Dumping\CompactDisc\Subchannel.cs" />
|
||||||
<Compile Include="Devices\Dumping\CompactDisc\Tags.cs" />
|
<Compile Include="Devices\Dumping\CompactDisc\Tags.cs" />
|
||||||
<Compile Include="Devices\Dumping\CompactDisc\Tracks.cs" />
|
<Compile Include="Devices\Dumping\CompactDisc\Tracks.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user