2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:23 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2015-10-19 02:40:30 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Session.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Component : Device structures decoders.
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// Decodes CD session structures.
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
2015-10-19 02:40:30 +01:00
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// This library 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
|
|
|
|
|
// Lesser General Public License for more details.
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
2016-07-28 18:13:49 +01:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2015-10-19 02:40:30 +01:00
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-02-18 10:02:39 +00:00
|
|
|
// Copyright © 2011-2022 Natalia Portillo
|
2015-10-19 02:40:30 +01:00
|
|
|
// ****************************************************************************/
|
2016-07-28 18:13:49 +01:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2015-10-19 02:40:30 +01:00
|
|
|
using System.Text;
|
2020-02-27 00:33:24 +00:00
|
|
|
using Aaru.Console;
|
2020-07-20 15:43:51 +01:00
|
|
|
using Aaru.Helpers;
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2020-02-27 00:33:24 +00:00
|
|
|
namespace Aaru.Decoders.CD
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2020-03-11 22:31:09 +00:00
|
|
|
// Information from the following standards:
|
|
|
|
|
// ANSI X3.304-1997
|
|
|
|
|
// T10/1048-D revision 9.0
|
|
|
|
|
// T10/1048-D revision 10a
|
|
|
|
|
// T10/1228-D revision 7.0c
|
|
|
|
|
// T10/1228-D revision 11a
|
|
|
|
|
// T10/1363-D revision 10g
|
|
|
|
|
// T10/1545-D revision 1d
|
|
|
|
|
// T10/1545-D revision 5
|
|
|
|
|
// T10/1545-D revision 5a
|
|
|
|
|
// T10/1675-D revision 2c
|
|
|
|
|
// T10/1675-D revision 4 T10/1836-D revision 2g
|
2019-11-25 00:54:38 +00:00
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
|
|
|
|
|
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
2015-10-19 02:40:30 +01:00
|
|
|
public static class Session
|
|
|
|
|
{
|
2015-10-19 02:46:04 +01:00
|
|
|
public static CDSessionInfo? Decode(byte[] CDSessionInfoResponse)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2020-03-06 20:39:31 +00:00
|
|
|
if(CDSessionInfoResponse == null ||
|
|
|
|
|
CDSessionInfoResponse.Length <= 4)
|
2019-11-25 00:54:38 +00:00
|
|
|
return null;
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
var decoded = new CDSessionInfo
|
2019-05-11 20:49:32 +01:00
|
|
|
{
|
|
|
|
|
DataLength = BigEndianBitConverter.ToUInt16(CDSessionInfoResponse, 0),
|
2020-07-20 04:34:15 +01:00
|
|
|
FirstCompleteSession = CDSessionInfoResponse[2],
|
|
|
|
|
LastCompleteSession = CDSessionInfoResponse[3]
|
2019-05-11 20:49:32 +01:00
|
|
|
};
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2019-05-11 20:49:32 +01:00
|
|
|
decoded.TrackDescriptors = new TrackDataDescriptor[(decoded.DataLength - 2) / 8];
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
if(decoded.DataLength + 2 != CDSessionInfoResponse.Length)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2020-02-27 23:48:39 +00:00
|
|
|
AaruConsole.DebugWriteLine("CD Session Info decoder",
|
2020-02-29 18:03:33 +00:00
|
|
|
"Expected CDSessionInfo size ({0} bytes) is not received size ({1} bytes), not decoding",
|
|
|
|
|
decoded.DataLength + 2, CDSessionInfoResponse.Length);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
for(int i = 0; i < (decoded.DataLength - 2) / 8; i++)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2020-02-29 18:03:33 +00:00
|
|
|
decoded.TrackDescriptors[i].Reserved1 = CDSessionInfoResponse[0 + (i * 8) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].ADR = (byte)((CDSessionInfoResponse[1 + (i * 8) + 4] & 0xF0) >> 4);
|
|
|
|
|
decoded.TrackDescriptors[i].CONTROL = (byte)(CDSessionInfoResponse[1 + (i * 8) + 4] & 0x0F);
|
|
|
|
|
decoded.TrackDescriptors[i].TrackNumber = CDSessionInfoResponse[2 + (i * 8) + 4];
|
|
|
|
|
decoded.TrackDescriptors[i].Reserved2 = CDSessionInfoResponse[3 + (i * 8) + 4];
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
decoded.TrackDescriptors[i].TrackStartAddress =
|
2020-02-29 18:03:33 +00:00
|
|
|
BigEndianBitConverter.ToUInt32(CDSessionInfoResponse, 4 + (i * 8) + 4);
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 02:46:04 +01:00
|
|
|
public static string Prettify(CDSessionInfo? CDSessionInfoResponse)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
if(CDSessionInfoResponse == null)
|
|
|
|
|
return null;
|
2015-10-19 02:40:30 +01:00
|
|
|
|
|
|
|
|
CDSessionInfo response = CDSessionInfoResponse.Value;
|
|
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
var sb = new StringBuilder();
|
2015-10-19 02:40:30 +01:00
|
|
|
|
|
|
|
|
sb.AppendFormat("First complete session number: {0}", response.FirstCompleteSession).AppendLine();
|
|
|
|
|
sb.AppendFormat("Last complete session number: {0}", response.LastCompleteSession).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2016-04-19 02:11:47 +01:00
|
|
|
foreach(TrackDataDescriptor descriptor in response.TrackDescriptors)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2019-11-25 00:54:38 +00:00
|
|
|
sb.AppendFormat("First track number in last complete session: {0}", descriptor.TrackNumber).
|
|
|
|
|
AppendLine();
|
|
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendFormat("Track starts at LBA {0}, or MSF {1:X2}:{2:X2}:{3:X2}", descriptor.TrackStartAddress,
|
2017-12-19 20:33:03 +00:00
|
|
|
(descriptor.TrackStartAddress & 0x0000FF00) >> 8,
|
|
|
|
|
(descriptor.TrackStartAddress & 0x00FF0000) >> 16,
|
|
|
|
|
(descriptor.TrackStartAddress & 0xFF000000) >> 24).AppendLine();
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
switch((TocAdr)descriptor.ADR)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocAdr.NoInformation:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Q subchannel mode not given");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocAdr.CurrentPosition:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Q subchannel stores current position");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocAdr.ISRC:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Q subchannel stores ISRC");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocAdr.MediaCatalogNumber:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Q subchannel stores media catalog number");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
if((descriptor.CONTROL & (byte)TocControl.ReservedMask) == (byte)TocControl.ReservedMask)
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendFormat("Reserved flags 0x{0:X2} set", descriptor.CONTROL).AppendLine();
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-12-22 02:04:18 +00:00
|
|
|
switch((TocControl)(descriptor.CONTROL & 0x0D))
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.TwoChanNoPreEmph:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Stereo audio track with no pre-emphasis");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.TwoChanPreEmph:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Stereo audio track with 50/15 μs pre-emphasis");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.FourChanNoPreEmph:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Quadraphonic audio track with no pre-emphasis");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.FourChanPreEmph:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Stereo audio track with 50/15 μs pre-emphasis");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.DataTrack:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Data track, recorded uninterrupted");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
2017-12-22 02:04:18 +00:00
|
|
|
case TocControl.DataTrackIncremental:
|
2015-10-19 02:40:30 +01:00
|
|
|
sb.AppendLine("Data track, recorded incrementally");
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-22 02:04:18 +00:00
|
|
|
sb.AppendLine((descriptor.CONTROL & (byte)TocControl.CopyPermissionMask) ==
|
2019-11-25 00:54:38 +00:00
|
|
|
(byte)TocControl.CopyPermissionMask ? "Digital copy of track is permitted"
|
2017-12-22 02:04:18 +00:00
|
|
|
: "Digital copy of track is prohibited");
|
2015-10-19 02:40:30 +01:00
|
|
|
|
2019-11-25 00:54:38 +00:00
|
|
|
#if DEBUG
|
2015-10-19 02:40:30 +01:00
|
|
|
if(descriptor.Reserved1 != 0)
|
|
|
|
|
sb.AppendFormat("Reserved1 = 0x{0:X2}", descriptor.Reserved1).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:40:30 +01:00
|
|
|
if(descriptor.Reserved2 != 0)
|
|
|
|
|
sb.AppendFormat("Reserved2 = 0x{0:X2}", descriptor.Reserved2).AppendLine();
|
2019-11-25 00:54:38 +00:00
|
|
|
#endif
|
2015-10-19 02:40:30 +01:00
|
|
|
|
|
|
|
|
sb.AppendLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-19 02:46:04 +01:00
|
|
|
public static string Prettify(byte[] CDSessionInfoResponse)
|
2015-10-19 02:40:30 +01:00
|
|
|
{
|
2015-10-19 02:46:04 +01:00
|
|
|
CDSessionInfo? decoded = Decode(CDSessionInfoResponse);
|
2019-11-25 00:54:38 +00:00
|
|
|
|
2015-10-19 02:46:04 +01:00
|
|
|
return Prettify(decoded);
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
2019-11-25 00:54:38 +00:00
|
|
|
|
|
|
|
|
public struct CDSessionInfo
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Total size of returned session information minus this field</summary>
|
|
|
|
|
public ushort DataLength;
|
|
|
|
|
/// <summary>First track number in hex</summary>
|
|
|
|
|
public byte FirstCompleteSession;
|
|
|
|
|
/// <summary>Last track number in hex</summary>
|
|
|
|
|
public byte LastCompleteSession;
|
|
|
|
|
/// <summary>Track descriptors</summary>
|
|
|
|
|
public TrackDataDescriptor[] TrackDescriptors;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public struct TrackDataDescriptor
|
|
|
|
|
{
|
|
|
|
|
/// <summary>Byte 0 Reserved</summary>
|
|
|
|
|
public byte Reserved1;
|
|
|
|
|
/// <summary>Byte 1, bits 7 to 4 Type of information in Q subchannel of block where this TOC entry was found</summary>
|
|
|
|
|
public byte ADR;
|
|
|
|
|
/// <summary>Byte 1, bits 3 to 0 Track attributes</summary>
|
|
|
|
|
public byte CONTROL;
|
|
|
|
|
/// <summary>Byte 2 First track number in last complete session</summary>
|
|
|
|
|
public byte TrackNumber;
|
|
|
|
|
/// <summary>Byte 3 Reserved</summary>
|
|
|
|
|
public byte Reserved2;
|
|
|
|
|
/// <summary>Bytes 4 to 7 First track number in last complete session start address in LBA or in MSF</summary>
|
|
|
|
|
public uint TrackStartAddress;
|
|
|
|
|
}
|
2015-10-19 02:40:30 +01:00
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|