2019-12-31 19:47:18 +00:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2019-12-31 19:47:18 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Filename : Subchannel.cs
|
2019-12-31 19:47:18 +00:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Component : CompactDisc dumping.
|
2019-12-31 19:47:18 +00:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Handles CompactDisc subchannel data.
|
2019-12-31 19:47:18 +00:00
|
|
|
//
|
|
|
|
|
// --[ 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
|
2019-12-31 19:47:18 +00:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
2020-05-05 20:26:18 +01:00
|
|
|
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;
|
2020-05-05 20:26:18 +01:00
|
|
|
using Aaru.Decoders.CD;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.Devices;
|
2019-12-31 19:47:18 +00:00
|
|
|
|
|
|
|
|
// ReSharper disable JoinDeclarationAndInitializer
|
|
|
|
|
// ReSharper disable InlineOutVariableDeclaration
|
|
|
|
|
// ReSharper disable TooWideLocalVariableScope
|
|
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
namespace Aaru.Core.Devices.Dumping
|
2019-12-31 19:47:18 +00:00
|
|
|
{
|
|
|
|
|
partial class Dump
|
|
|
|
|
{
|
2020-01-02 18:31:49 +00:00
|
|
|
public static bool SupportsRwSubchannel(Device dev, DumpLog dumpLog, UpdateStatusHandler updateStatus)
|
2019-12-31 19:47:18 +00:00
|
|
|
{
|
2020-01-02 18:31:49 +00:00
|
|
|
dumpLog?.WriteLine("Checking if drive supports full raw subchannel reading...");
|
|
|
|
|
updateStatus?.Invoke("Checking if drive supports full raw subchannel reading...");
|
2019-12-31 19:47:18 +00:00
|
|
|
|
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 _);
|
2019-12-31 19:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-02 18:31:49 +00:00
|
|
|
public static bool SupportsPqSubchannel(Device dev, DumpLog dumpLog, UpdateStatusHandler updateStatus)
|
2019-12-31 19:47:18 +00:00
|
|
|
{
|
2020-01-02 18:31:49 +00:00
|
|
|
dumpLog?.WriteLine("Checking if drive supports PQ subchannel reading...");
|
|
|
|
|
updateStatus?.Invoke("Checking if drive supports PQ subchannel reading...");
|
2019-12-31 19:47:18 +00:00
|
|
|
|
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 _);
|
2019-12-31 19:47:18 +00:00
|
|
|
}
|
2020-05-05 20:26:18 +01:00
|
|
|
|
|
|
|
|
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:26:18 +01:00
|
|
|
|
2020-05-05 20:37:25 +01:00
|
|
|
subLog?.WriteEntry(sub, supportedSubchannel == MmcSubchannel.Raw, (long)sectorAddress, length);
|
2020-05-05 20:26:18 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-31 19:47:18 +00:00
|
|
|
}
|
|
|
|
|
}
|