Files
Aaru/Aaru.Core/Devices/Dumping/CompactDisc/Subchannel.cs

124 lines
5.2 KiB
C#
Raw Normal View History

// /***************************************************************************
2020-02-27 12:31:25 +00:00
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
2020-03-11 21:56:55 +00:00
// Filename : Subchannel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
2020-03-11 21:56:55 +00:00
// Component : CompactDisc dumping.
//
// --[ Description ] ----------------------------------------------------------
//
2020-03-11 21:56:55 +00:00
// Handles CompactDisc subchannel data.
//
// --[ 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/>.
//
// ----------------------------------------------------------------------------
2020-01-03 17:51:30 +00:00
// Copyright © 2011-2020 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
using Aaru.Checksums;
using Aaru.CommonTypes.Enums;
2020-02-27 00:33:26 +00:00
using Aaru.Core.Logging;
using Aaru.Decoders.CD;
2020-02-27 00:33:26 +00:00
using Aaru.Devices;
// ReSharper disable JoinDeclarationAndInitializer
// ReSharper disable InlineOutVariableDeclaration
// ReSharper disable TooWideLocalVariableScope
2020-02-27 00:33:26 +00:00
namespace Aaru.Core.Devices.Dumping
{
partial class Dump
{
public static bool SupportsRwSubchannel(Device dev, DumpLog dumpLog, UpdateStatusHandler updateStatus)
{
dumpLog?.WriteLine("Checking if drive supports full raw subchannel reading...");
updateStatus?.Invoke("Checking if drive supports full raw subchannel reading...");
2020-02-29 18:03:35 +00:00
return !dev.ReadCd(out _, out _, 0, 2352 + 96, 1, MmcSectorTypes.AllTypes, false, false, true,
MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.Raw,
dev.Timeout, out _);
}
public static bool SupportsPqSubchannel(Device dev, DumpLog dumpLog, UpdateStatusHandler updateStatus)
{
dumpLog?.WriteLine("Checking if drive supports PQ subchannel reading...");
updateStatus?.Invoke("Checking if drive supports PQ subchannel reading...");
2020-02-29 18:03:35 +00:00
return !dev.ReadCd(out _, out _, 0, 2352 + 16, 1, MmcSectorTypes.AllTypes, false, false, true,
MmcHeaderCodes.AllHeaders, true, true, MmcErrorField.None, MmcSubchannel.Q16,
dev.Timeout, out _);
}
void WriteSubchannelToImage(MmcSubchannel supportedSubchannel, MmcSubchannel desiredSubchannel, byte[] sub,
ulong sectorAddress, uint length, SubchannelLog subLog,
Dictionary<byte, string> isrcs, byte currentTrack)
{
if(supportedSubchannel == MmcSubchannel.Q16)
sub = Subchannel.ConvertQToRaw(sub);
if(desiredSubchannel != MmcSubchannel.None)
2020-05-05 20:37:25 +01:00
_outputPlugin.WriteSectorsTag(sub, sectorAddress, length, SectorTagType.CdSectorSubchannel);
2020-05-05 20:37:25 +01:00
subLog?.WriteEntry(sub, supportedSubchannel == MmcSubchannel.Raw, (long)sectorAddress, length);
byte[] deSub = Subchannel.Deinterleave(sub);
// Check subchannel
for(int subPos = 0; subPos < deSub.Length; subPos += 96)
{
// ISRC
if((deSub[subPos + 12] & 0x3) == 3)
{
byte[] q = new byte[12];
Array.Copy(deSub, subPos + 12, q, 0, 12);
string isrc = Subchannel.DecodeIsrc(q);
if(isrc == null ||
isrc == "000000000000")
continue;
if(!isrcs.ContainsKey(currentTrack))
{
_dumpLog?.WriteLine($"Found new ISRC {isrc} for track {currentTrack}.");
UpdateStatus?.Invoke($"Found new ISRC {isrc} for track {currentTrack}.");
}
else if(isrcs[currentTrack] != isrc)
{
CRC16CCITTContext.Data(q, 10, out byte[] crc);
if(crc[0] != q[10] ||
crc[1] != q[11])
{
continue;
}
_dumpLog?.
WriteLine($"ISRC for track {currentTrack} changed from {isrcs[currentTrack]} to {isrc}.");
UpdateStatus?.
Invoke($"ISRC for track {currentTrack} changed from {isrcs[currentTrack]} to {isrc}.");
}
isrcs[currentTrack] = isrc;
}
}
}
}
}