Renamed CUETools.Codecs.BLDLPCM into CUETools.Codecs.MPEG

This commit is contained in:
Grigory Chudov
2018-04-07 21:09:28 -04:00
parent bfcbd825b2
commit 513ab1c64e
14 changed files with 1689 additions and 1691 deletions

View File

@@ -1,45 +1,45 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Newtonsoft.Json;
namespace CUETools.Codecs.BDLPCM
{
[JsonObject(MemberSerialization.OptIn)]
public class DecoderSettings : IAudioDecoderSettings
{
#region IAudioDecoderSettings implementation
[Browsable(false)]
public string Extension => "m2ts";
[Browsable(false)]
public string Name => "cuetools";
[Browsable(false)]
public Type DecoderType => typeof(AudioDecoder);
[Browsable(false)]
public int Priority => 2;
public IAudioDecoderSettings Clone()
{
return MemberwiseClone() as IAudioDecoderSettings;
}
#endregion
public DecoderSettings()
{
this.Init();
}
[DefaultValue(true)]
public bool IgnoreShortItems { get; set; }
[Browsable(false)]
public int? Stream { get; set; }
[Browsable(false)]
public int? StreamId { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using Newtonsoft.Json;
namespace CUETools.Codecs.MPEG.BDLPCM
{
[JsonObject(MemberSerialization.OptIn)]
public class DecoderSettings : IAudioDecoderSettings
{
#region IAudioDecoderSettings implementation
[Browsable(false)]
public string Extension => "m2ts";
[Browsable(false)]
public string Name => "cuetools";
[Browsable(false)]
public Type DecoderType => typeof(AudioDecoder);
[Browsable(false)]
public int Priority => 2;
public IAudioDecoderSettings Clone()
{
return MemberwiseClone() as IAudioDecoderSettings;
}
#endregion
public DecoderSettings()
{
this.Init();
}
[DefaultValue(true)]
public bool IgnoreShortItems { get; set; }
[Browsable(false)]
public int? Stream { get; set; }
[Browsable(false)]
public int? StreamId { get; set; }
}
}

View File

@@ -1,29 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net40;net20;netstandard2.0</TargetFrameworks>
<Version>2.1.7.0</Version>
<AssemblyName>CUETools.Codecs.BDLPCM</AssemblyName>
<RootNamespace>CUETools.Codecs</RootNamespace>
<Product>CUETools</Product>
<Description>A library for encoding and decoding BluRay Disc LPCM audio.</Description>
<Copyright>Copyright (c) 2008-2018 Grigory Chudov</Copyright>
<Authors>Grigory Chudov</Authors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>..\bin\$(Configuration)\plugins</OutputPath>
<RepositoryUrl>https://github.com/gchudov/cuetools.net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Company />
</PropertyGroup>
<ItemDefinitionGroup>
<ProjectReference>
<Private>False</Private>
</ProjectReference>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\CUETools.Codecs\CUETools.Codecs.csproj" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net40;net20;netstandard2.0</TargetFrameworks>
<Version>2.1.7.0</Version>
<AssemblyName>CUETools.Codecs.MPEG</AssemblyName>
<RootNamespace>CUETools.Codecs.MPEG</RootNamespace>
<Product>CUETools</Product>
<Description>A library for encoding and decoding BluRay Disc LPCM audio.</Description>
<Copyright>Copyright (c) 2008-2018 Grigory Chudov</Copyright>
<Authors>Grigory Chudov</Authors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>..\bin\$(Configuration)\plugins</OutputPath>
<RepositoryUrl>https://github.com/gchudov/cuetools.net</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Company />
</PropertyGroup>
<ItemDefinitionGroup>
<ProjectReference>
<Private>False</Private>
</ProjectReference>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\CUETools.Codecs\CUETools.Codecs.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,116 +1,116 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CUETools.Codecs.BDLPCM
{
internal unsafe class FrameReader
{
internal FrameReader(byte* ptr, byte* end)
{
ptr_m = ptr;
end_m = end;
}
internal FrameReader(byte* ptr, long len)
{
ptr_m = ptr;
end_m = ptr + len;
}
internal FrameReader(FrameReader src, long len)
{
if (src.ptr_m + len > src.end_m) throw new IndexOutOfRangeException();
ptr_m = src.ptr_m;
end_m = src.ptr_m + len;
}
internal void read_bytes(byte* dst, int len)
{
if (ptr_m + len > end_m) throw new IndexOutOfRangeException();
AudioSamples.MemCpy(dst, ptr_m, len);
ptr_m += len;
}
internal byte[] read_bytes(int len)
{
var res = new byte[len];
fixed (byte* ptr = &res[0])
read_bytes(ptr, len);
return res;
}
internal string read_string(int len)
{
var res = new byte[len];
fixed (byte* ptr = &res[0])
read_bytes(ptr, len);
return Encoding.UTF8.GetString(res, 0, res.Length);;
}
internal byte read_byte()
{
if (ptr_m + 1 > end_m) throw new IndexOutOfRangeException();
return *(ptr_m++);
}
internal ushort read_ushort()
{
if (ptr_m + 2 > end_m) throw new IndexOutOfRangeException();
ushort n = (ushort)(*(ptr_m++));
n <<= 8; n += (ushort)(*(ptr_m++));
return n;
}
internal uint read_uint()
{
if (ptr_m + 4 > end_m) throw new IndexOutOfRangeException();
uint n = (uint)(*(ptr_m++));
n <<= 8; n += (uint)(*(ptr_m++));
n <<= 8; n += (uint)(*(ptr_m++));
n <<= 8; n += (uint)(*(ptr_m++));
return n;
}
internal ulong read_pts()
{
if (ptr_m + 5 > end_m) throw new IndexOutOfRangeException();
ulong pts
= ((ulong)(*(ptr_m++) & 0x0e) << 29);
pts |= ((ulong)(*(ptr_m++) & 0xff) << 22);
pts |= ((ulong)(*(ptr_m++) & 0xfe) << 14);
pts |= ((ulong)(*(ptr_m++) & 0xff) << 7);
pts |= ((ulong)(*(ptr_m++) & 0xfe) >> 1);
return pts;
}
internal void skip(long bytes)
{
if (ptr_m + bytes > end_m) throw new IndexOutOfRangeException();
ptr_m += bytes;
}
internal long Length
{
get
{
return end_m - ptr_m;
}
set
{
end_m = ptr_m + value;
}
}
internal byte* Ptr
{
get
{
return ptr_m;
}
}
byte* ptr_m;
byte* end_m;
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace CUETools.Codecs.MPEG
{
internal unsafe class FrameReader
{
internal FrameReader(byte* ptr, byte* end)
{
ptr_m = ptr;
end_m = end;
}
internal FrameReader(byte* ptr, long len)
{
ptr_m = ptr;
end_m = ptr + len;
}
internal FrameReader(FrameReader src, long len)
{
if (src.ptr_m + len > src.end_m) throw new IndexOutOfRangeException();
ptr_m = src.ptr_m;
end_m = src.ptr_m + len;
}
internal void read_bytes(byte* dst, int len)
{
if (ptr_m + len > end_m) throw new IndexOutOfRangeException();
AudioSamples.MemCpy(dst, ptr_m, len);
ptr_m += len;
}
internal byte[] read_bytes(int len)
{
var res = new byte[len];
fixed (byte* ptr = &res[0])
read_bytes(ptr, len);
return res;
}
internal string read_string(int len)
{
var res = new byte[len];
fixed (byte* ptr = &res[0])
read_bytes(ptr, len);
return Encoding.UTF8.GetString(res, 0, res.Length);;
}
internal byte read_byte()
{
if (ptr_m + 1 > end_m) throw new IndexOutOfRangeException();
return *(ptr_m++);
}
internal ushort read_ushort()
{
if (ptr_m + 2 > end_m) throw new IndexOutOfRangeException();
ushort n = (ushort)(*(ptr_m++));
n <<= 8; n += (ushort)(*(ptr_m++));
return n;
}
internal uint read_uint()
{
if (ptr_m + 4 > end_m) throw new IndexOutOfRangeException();
uint n = (uint)(*(ptr_m++));
n <<= 8; n += (uint)(*(ptr_m++));
n <<= 8; n += (uint)(*(ptr_m++));
n <<= 8; n += (uint)(*(ptr_m++));
return n;
}
internal ulong read_pts()
{
if (ptr_m + 5 > end_m) throw new IndexOutOfRangeException();
ulong pts
= ((ulong)(*(ptr_m++) & 0x0e) << 29);
pts |= ((ulong)(*(ptr_m++) & 0xff) << 22);
pts |= ((ulong)(*(ptr_m++) & 0xfe) << 14);
pts |= ((ulong)(*(ptr_m++) & 0xff) << 7);
pts |= ((ulong)(*(ptr_m++) & 0xfe) >> 1);
return pts;
}
internal void skip(long bytes)
{
if (ptr_m + bytes > end_m) throw new IndexOutOfRangeException();
ptr_m += bytes;
}
internal long Length
{
get
{
return end_m - ptr_m;
}
set
{
end_m = ptr_m + value;
}
}
internal byte* Ptr
{
get
{
return ptr_m;
}
}
byte* ptr_m;
byte* end_m;
}
}

View File

@@ -4,7 +4,7 @@ using System.ComponentModel;
using System.Text;
using Newtonsoft.Json;
namespace CUETools.Codecs.MPLS
namespace CUETools.Codecs.MPEG.MPLS
{
[JsonObject(MemberSerialization.OptIn)]
public class DecoderSettings : IAudioDecoderSettings
@@ -17,7 +17,7 @@ namespace CUETools.Codecs.MPLS
public string Name => "cuetools";
[Browsable(false)]
public Type DecoderType => typeof(BDLPCM.MPLSDecoder);
public Type DecoderType => typeof(AudioDecoder);
[Browsable(false)]
public int Priority => 2;

View File

@@ -1,59 +1,59 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CUETools.Codecs.BDLPCM
{
internal class TsStream
{
internal UInt16 channel; // channel number (1,2 ...)
internal int streamId; // stream number in channel
internal byte type; // 0xff - not ES
internal AudioPCMConfig pcm;
internal byte[] savedBuffer;
internal int savedBufferOffset;
internal int savedBufferSize;
internal byte[] psi; // PAT,PMT cache (only for PSI streams)
internal int psi_len;
internal int psi_offset;
internal int psi_table;
internal bool at_packet_header;
internal byte ts_stream_id; // MPEG stream id
internal bool is_opened;
internal UInt64 dts; // current MPEG stream DTS (presentation time for audio, decode time for video)
internal UInt64 first_dts;
internal UInt64 first_pts;
internal UInt64 last_pts;
internal UInt32 frame_length; // frame length in ticks (90 ticks = 1 ms, 90000/frame_length=fps)
internal UInt32 frame_size; // frame size in bytes
internal UInt64 frame_num; // frame counter
internal TsStream()
{
is_opened = false;
psi = new byte[512];
psi_len = 0;
psi_offset = 0;
psi_table = 0;
channel = 0xffff;
streamId = 0;
type = 0xff;
ts_stream_id = 0;
dts = 0;
first_dts = 0;
first_pts = 0;
last_pts = 0;
frame_length = 0;
frame_size = 0;
frame_num = 0;
pcm = null;
savedBuffer = new byte[192];
savedBufferOffset = 0;
savedBufferSize = 0;
}
};
}
using System;
using System.Collections.Generic;
using System.Text;
namespace CUETools.Codecs.MPEG
{
internal class TsStream
{
internal UInt16 channel; // channel number (1,2 ...)
internal int streamId; // stream number in channel
internal byte type; // 0xff - not ES
internal AudioPCMConfig pcm;
internal byte[] savedBuffer;
internal int savedBufferOffset;
internal int savedBufferSize;
internal byte[] psi; // PAT,PMT cache (only for PSI streams)
internal int psi_len;
internal int psi_offset;
internal int psi_table;
internal bool at_packet_header;
internal byte ts_stream_id; // MPEG stream id
internal bool is_opened;
internal UInt64 dts; // current MPEG stream DTS (presentation time for audio, decode time for video)
internal UInt64 first_dts;
internal UInt64 first_pts;
internal UInt64 last_pts;
internal UInt32 frame_length; // frame length in ticks (90 ticks = 1 ms, 90000/frame_length=fps)
internal UInt32 frame_size; // frame size in bytes
internal UInt64 frame_num; // frame counter
internal TsStream()
{
is_opened = false;
psi = new byte[512];
psi_len = 0;
psi_offset = 0;
psi_table = 0;
channel = 0xffff;
streamId = 0;
type = 0xff;
ts_stream_id = 0;
dts = 0;
first_dts = 0;
first_pts = 0;
last_pts = 0;
frame_length = 0;
frame_size = 0;
frame_num = 0;
pcm = null;
savedBuffer = new byte[192];
savedBufferOffset = 0;
savedBufferSize = 0;
}
};
}

View File

@@ -111,4 +111,13 @@ namespace CUETools.Codecs.ffmpegdll
this.Init();
}
}
public class MpegDecoderSettings : DecoderSettings, IAudioDecoderSettings
{
public override string Extension => "aob";
public override string Format => "mpeg";
public MpegDecoderSettings()
{
this.Init();
}
}
}

View File

@@ -88,6 +88,7 @@ namespace CUETools.Codecs
formats.Add("ogg", new CUEToolsFormat("ogg", CUEToolsTagger.TagLibSharp, false, true, false, true, null, encodersViewModel.GetDefault("ogg", false), null));
formats.Add("opus", new CUEToolsFormat("opus", CUEToolsTagger.TagLibSharp, false, true, false, true, null, encodersViewModel.GetDefault("opus", false), null));
formats.Add("mlp", new CUEToolsFormat("mlp", CUEToolsTagger.APEv2, true, false, false, false, null, null, decodersViewModel.GetDefault("mlp")));
formats.Add("aob", new CUEToolsFormat("aob", CUEToolsTagger.APEv2, true, false, false, false, null, null, decodersViewModel.GetDefault("aob")));
}
}
}

View File

@@ -27,7 +27,7 @@
<ProjectReference Include="..\CUETools.Codecs\CUETools.Codecs.csproj" />
<ProjectReference Include="..\CUETools.Processor\CUETools.Processor.csproj" />
<ProjectReference Include="..\CUETools.CTDB\CUETools.CTDB.csproj" />
<ProjectReference Include="..\CUETools.Codecs.BDLPCM\CUETools.Codecs.BDLPCM.csproj" />
<ProjectReference Include="..\CUETools.Codecs.MPEG\CUETools.Codecs.MPEG.csproj" />
<ProjectReference Include="..\CUETools.CDImage\CUETools.CDImage.csproj" />
</ItemGroup>

View File

@@ -1,6 +1,5 @@
using CUETools.CDImage;
using CUETools.Codecs;
using CUETools.Codecs.BDLPCM;
using CUETools.CTDB;
using CUETools.Processor;
using System;
@@ -124,8 +123,8 @@ namespace CUETools.eac3to
{
IAudioSource audioSource = null;
IAudioDest audioDest = null;
var videos = new List<MPLSStream>();
var audios = new List<MPLSStream>();
var videos = new List<Codecs.MPEG.MPLS.MPLSStream>();
var audios = new List<Codecs.MPEG.MPLS.MPLSStream>();
List<uint> chapters;
TimeSpan duration;
TagLib.UserDefined.AdditionalFileTypes.Config = config;
@@ -136,7 +135,7 @@ namespace CUETools.eac3to
{
if (true)
{
var mpls = new MPLSDecoder(new Codecs.MPLS.DecoderSettings(), sourceFile, null);
var mpls = new Codecs.MPEG.MPLS.AudioDecoder(new Codecs.MPEG.MPLS.DecoderSettings(), sourceFile, null);
audioSource = mpls;
Console.ForegroundColor = ConsoleColor.White;
int frameRate = 0;
@@ -310,14 +309,14 @@ namespace CUETools.eac3to
throw new Exception("Unknown encoder format: " + destFile);
}
if (audioSource is MPLSDecoder)
if (audioSource is Codecs.MPEG.MPLS.AudioDecoder)
{
if (stream - chapterStreams <= videos.Count)
throw new Exception("Video extraction not supported.");
if (stream - chapterStreams - videos.Count > audios.Count)
throw new Exception(string.Format("The source file doesn't contain a track with the number {0}.", stream));
int pid = audios[stream - chapterStreams - videos.Count - 1].pid;
(audioSource.Settings as Codecs.MPLS.DecoderSettings).StreamId = pid;
(audioSource.Settings as Codecs.MPEG.MPLS.DecoderSettings).StreamId = pid;
}
}

View File

@@ -105,9 +105,9 @@
<Project>{1dd41038-d885-46c5-8dde-e0b82f066584}</Project>
<Name>CUETools.CDImage</Name>
</ProjectReference>
<ProjectReference Include="..\CUETools.Codecs.BDLPCM\CUETools.Codecs.BDLPCM.csproj">
<ProjectReference Include="..\CUETools.Codecs.MPEG\CUETools.Codecs.MPEG.csproj">
<Project>{e75f7ccd-4266-42e1-a039-dc7eb5edd8f6}</Project>
<Name>CUETools.Codecs.BDLPCM</Name>
<Name>CUETools.Codecs.MPEG</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\CUETools.Codecs.Flake\CUETools.Codecs.Flake.csproj">

View File

@@ -1,28 +1,17 @@
using System;
using System.IO;
using CUETools.CDImage;
using CUETools.Codecs;
using CUETools.CTDB;
using CUETools.Processor;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
//using System.Windows.Shapes;
using CUETools.Codecs.BDLPCM;
using CUETools.CDImage;
using CUETools.CTDB;
using System.ComponentModel;
using Krystalware.UploadHelper;
using CUETools.Codecs;
//using CUETools.Codecs.Flake;
using CUETools.Processor;
using System.Collections.ObjectModel;
//using Microsoft.Win32;
namespace BluTools
{
@@ -75,7 +64,7 @@ namespace BluTools
private void textBoxSource_TextChanged(object sender, TextChangedEventArgs e)
{
var titleSets = new List<MPLSDecoder>();
var titleSets = new List<CUETools.Codecs.MPEG.MPLS.AudioDecoder>();
IEnumerable<string> playlists = null;
try
{
@@ -87,7 +76,7 @@ namespace BluTools
if (playlists != null)
foreach (var playlist in playlists)
{
var title = new MPLSDecoder(new CUETools.Codecs.MPLS.DecoderSettings(), playlist, null);
var title = new CUETools.Codecs.MPEG.MPLS.AudioDecoder(new CUETools.Codecs.MPEG.MPLS.DecoderSettings(), playlist, null);
if (filterDups)
{
if (titleSets.Exists(title2 =>
@@ -125,10 +114,10 @@ namespace BluTools
cmbMetadata.ItemsSource = new List<CTDBResponseMeta>();
ctdb = null;
var audios = new List<MPLSStream>();
var audios = new List<CUETools.Codecs.MPEG.MPLS.MPLSStream>();
if (e.AddedItems.Count == 1)
{
MPLSDecoder rdr = e.AddedItems[0] as MPLSDecoder;
var rdr = e.AddedItems[0] as CUETools.Codecs.MPEG.MPLS.AudioDecoder;
rdr.MPLSHeader.play_item.ForEach(i => i.audio.ForEach(v => { if (!audios.Exists(v1 => v1.pid == v.pid)) audios.Add(v); }));
var chapters = rdr.Chapters;
@@ -190,7 +179,7 @@ namespace BluTools
{
if (e.AddedItems.Count == 1)
{
MPLSStream stream = (MPLSStream)(e.AddedItems[0]);
CUETools.Codecs.MPEG.MPLS.MPLSStream stream = (CUETools.Codecs.MPEG.MPLS.MPLSStream)(e.AddedItems[0]);
}
}
@@ -200,7 +189,7 @@ namespace BluTools
BackgroundWorker workerExtract;
CUEMetadataEntry metaresult;
ObservableCollection<CUEMetadataEntry> metaresults;
MPLSDecoder chosenReader;
CUETools.Codecs.MPEG.MPLS.AudioDecoder chosenReader;
ushort pid;
string outputFolderPath;
string outputAudioPath;
@@ -213,8 +202,8 @@ namespace BluTools
private void buttonExtract_Click(object sender, RoutedEventArgs e)
{
if (cmbTitleSet.SelectedItem == null) return;
pid = ((MPLSStream)cmbAudioTrack.SelectedItem).pid;
chosenReader = cmbTitleSet.SelectedItem as MPLSDecoder;
pid = ((CUETools.Codecs.MPEG.MPLS.MPLSStream)cmbAudioTrack.SelectedItem).pid;
chosenReader = cmbTitleSet.SelectedItem as CUETools.Codecs.MPEG.MPLS.AudioDecoder;
metaresult = cmbMetadata.SelectedItem as CUEMetadataEntry;
outputFolderPath = Path.Combine(textBoxDestination.Text, metaresult != null ?
metaresult.metadata.Artist + " - " + metaresult.metadata.Year + " - " + metaresult.metadata.Title :
@@ -239,10 +228,10 @@ namespace BluTools
void workerExtract_DoWork(object sender, DoWorkEventArgs e)
{
MPLSDecoder reader = null;
CUETools.Codecs.MPEG.MPLS.AudioDecoder reader = null;
try
{
reader = new MPLSDecoder(chosenReader.Path, null, pid);
reader = new CUETools.Codecs.MPEG.MPLS.AudioDecoder(chosenReader.Path, null, pid);
Directory.CreateDirectory(outputFolderPath);
if (File.Exists(outputCuePath)) throw new Exception(string.Format("File \"{0}\" already exists", outputCuePath));
if (File.Exists(outputAudioPath)) throw new Exception(string.Format("File \"{0}\" already exists", outputAudioPath));

View File

@@ -163,7 +163,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsMediaLib", "..\Third
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CUETools.Codecs.WMA", "..\CUETools.Codecs.WMA\CUETools.Codecs.WMA.csproj", "{082D6B9E-326E-4D15-9798-DE70A6EDAE9E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CUETools.Codecs.BDLPCM", "..\CUETools.Codecs.BDLPCM\CUETools.Codecs.BDLPCM.csproj", "{E75F7CCD-4266-42E1-A039-DC7EB5EDD8F6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CUETools.Codecs.BDLPCM", "..\CUETools.Codecs.MPEG\CUETools.Codecs.MPEG.csproj", "{E75F7CCD-4266-42E1-A039-DC7EB5EDD8F6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CUETools.eac3to", "..\CUETools.eac3to\CUETools.eac3to.csproj", "{E3FF7539-6B22-4922-8FEF-6D26F2C2E3CE}"
EndProject