mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-22 01:54:42 +01:00
more steps to make provider project portable
This commit is contained in:
33
DvdLib/BigEndianBinaryReader.cs
Normal file
33
DvdLib/BigEndianBinaryReader.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace DvdLib
|
||||
{
|
||||
public class BigEndianBinaryReader : BinaryReader
|
||||
{
|
||||
public BigEndianBinaryReader(Stream input)
|
||||
: base(input)
|
||||
{
|
||||
}
|
||||
|
||||
public override ushort ReadUInt16()
|
||||
{
|
||||
return BitConverter.ToUInt16(ReadAndReverseBytes(2), 0);
|
||||
}
|
||||
|
||||
public override uint ReadUInt32()
|
||||
{
|
||||
return BitConverter.ToUInt32(ReadAndReverseBytes(4), 0);
|
||||
}
|
||||
|
||||
private byte[] ReadAndReverseBytes(int count)
|
||||
{
|
||||
byte[] val = base.ReadBytes(count);
|
||||
Array.Reverse(val, 0, count);
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
76
DvdLib/DvdLib.csproj
Normal file
76
DvdLib/DvdLib.csproj
Normal file
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{713F42B5-878E-499D-A878-E4C652B1D5E8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DvdLib</RootNamespace>
|
||||
<AssemblyName>DvdLib</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="project.json" />
|
||||
<!-- A reference to the entire .NET Framework is automatically included -->
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BigEndianBinaryReader.cs" />
|
||||
<Compile Include="Ifo\AudioAttributes.cs" />
|
||||
<Compile Include="Ifo\Cell.cs" />
|
||||
<Compile Include="Ifo\CellPlaybackInfo.cs" />
|
||||
<Compile Include="Ifo\CellPositionInfo.cs" />
|
||||
<Compile Include="Ifo\Chapter.cs" />
|
||||
<Compile Include="Ifo\Dvd.cs" />
|
||||
<Compile Include="Ifo\DvdTime.cs" />
|
||||
<Compile Include="Ifo\PgcCommandTable.cs" />
|
||||
<Compile Include="Ifo\Program.cs" />
|
||||
<Compile Include="Ifo\ProgramChain.cs" />
|
||||
<Compile Include="Ifo\Title.cs" />
|
||||
<Compile Include="Ifo\UserOperation.cs" />
|
||||
<Compile Include="Ifo\VideoAttributes.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj">
|
||||
<Project>{7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b}</Project>
|
||||
<Name>MediaBrowser.Model</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>if $(ConfigurationName) == Release (
|
||||
xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i
|
||||
)</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
6
DvdLib/DvdLib.nuget.targets
Normal file
6
DvdLib/DvdLib.nuget.targets
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Target Name="EmitMSBuildWarning" BeforeTargets="Build">
|
||||
<Warning Text="Packages containing MSBuild targets and props files cannot be fully installed in projects targeting multiple frameworks. The MSBuild targets and props files have been ignored." />
|
||||
</Target>
|
||||
</Project>
|
||||
41
DvdLib/Ifo/AudioAttributes.cs
Normal file
41
DvdLib/Ifo/AudioAttributes.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public enum AudioCodec
|
||||
{
|
||||
AC3 = 0,
|
||||
MPEG1 = 2,
|
||||
MPEG2ext = 3,
|
||||
LPCM = 4,
|
||||
DTS = 6,
|
||||
}
|
||||
|
||||
public enum ApplicationMode
|
||||
{
|
||||
Unspecified = 0,
|
||||
Karaoke = 1,
|
||||
Surround = 2,
|
||||
}
|
||||
|
||||
public class AudioAttributes
|
||||
{
|
||||
public readonly AudioCodec Codec;
|
||||
public readonly bool MultichannelExtensionPresent;
|
||||
public readonly ApplicationMode Mode;
|
||||
public readonly byte QuantDRC;
|
||||
public readonly byte SampleRate;
|
||||
public readonly byte Channels;
|
||||
public readonly ushort LanguageCode;
|
||||
public readonly byte LanguageExtension;
|
||||
public readonly byte CodeExtension;
|
||||
}
|
||||
|
||||
public class MultiChannelExtension
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
24
DvdLib/Ifo/Cell.cs
Normal file
24
DvdLib/Ifo/Cell.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public class Cell
|
||||
{
|
||||
public CellPlaybackInfo PlaybackInfo { get; private set; }
|
||||
public CellPositionInfo PositionInfo { get; private set; }
|
||||
|
||||
internal void ParsePlayback(BinaryReader br)
|
||||
{
|
||||
PlaybackInfo = new CellPlaybackInfo(br);
|
||||
}
|
||||
|
||||
internal void ParsePosition(BinaryReader br)
|
||||
{
|
||||
PositionInfo = new CellPositionInfo(br);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
DvdLib/Ifo/CellPlaybackInfo.cs
Normal file
54
DvdLib/Ifo/CellPlaybackInfo.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public enum BlockMode
|
||||
{
|
||||
NotInBlock = 0,
|
||||
FirstCell = 1,
|
||||
InBlock = 2,
|
||||
LastCell = 3,
|
||||
}
|
||||
|
||||
public enum BlockType
|
||||
{
|
||||
Normal = 0,
|
||||
Angle = 1,
|
||||
}
|
||||
|
||||
public enum PlaybackMode
|
||||
{
|
||||
Normal = 0,
|
||||
StillAfterEachVOBU = 1,
|
||||
}
|
||||
|
||||
public class CellPlaybackInfo
|
||||
{
|
||||
public readonly BlockMode Mode;
|
||||
public readonly BlockType Type;
|
||||
public readonly bool SeamlessPlay;
|
||||
public readonly bool Interleaved;
|
||||
public readonly bool STCDiscontinuity;
|
||||
public readonly bool SeamlessAngle;
|
||||
public readonly PlaybackMode PlaybackMode;
|
||||
public readonly bool Restricted;
|
||||
public readonly byte StillTime;
|
||||
public readonly byte CommandNumber;
|
||||
public readonly DvdTime PlaybackTime;
|
||||
public readonly uint FirstSector;
|
||||
public readonly uint FirstILVUEndSector;
|
||||
public readonly uint LastVOBUStartSector;
|
||||
public readonly uint LastSector;
|
||||
|
||||
internal CellPlaybackInfo(BinaryReader br)
|
||||
{
|
||||
br.BaseStream.Seek(0x4, SeekOrigin.Current);
|
||||
PlaybackTime = new DvdTime(br.ReadBytes(4));
|
||||
br.BaseStream.Seek(0x10, SeekOrigin.Current);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
DvdLib/Ifo/CellPositionInfo.cs
Normal file
21
DvdLib/Ifo/CellPositionInfo.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public class CellPositionInfo
|
||||
{
|
||||
public readonly ushort VOBId;
|
||||
public readonly byte CellId;
|
||||
|
||||
internal CellPositionInfo(BinaryReader br)
|
||||
{
|
||||
VOBId = br.ReadUInt16();
|
||||
br.ReadByte();
|
||||
CellId = br.ReadByte();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
DvdLib/Ifo/Chapter.cs
Normal file
21
DvdLib/Ifo/Chapter.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public class Chapter
|
||||
{
|
||||
public ushort ProgramChainNumber { get; private set; }
|
||||
public ushort ProgramNumber { get; private set; }
|
||||
public uint ChapterNumber { get; private set; }
|
||||
|
||||
public Chapter(ushort pgcNum, ushort programNum, uint chapterNum)
|
||||
{
|
||||
ProgramChainNumber = pgcNum;
|
||||
ProgramNumber = programNum;
|
||||
ChapterNumber = chapterNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
161
DvdLib/Ifo/Dvd.cs
Normal file
161
DvdLib/Ifo/Dvd.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using MediaBrowser.Model.IO;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public class Dvd
|
||||
{
|
||||
private readonly ushort _titleSetCount;
|
||||
public readonly List<Title> Titles;
|
||||
|
||||
private ushort _titleCount;
|
||||
public readonly Dictionary<ushort, string> VTSPaths = new Dictionary<ushort, string>();
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
public Dvd(string path, IFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
Titles = new List<Title>();
|
||||
var allFiles = _fileSystem.GetFiles(path, true).ToList();
|
||||
|
||||
var vmgPath = allFiles.FirstOrDefault(i => string.Equals(i.Name, "VIDEO_TS.IFO", StringComparison.OrdinalIgnoreCase)) ??
|
||||
allFiles.FirstOrDefault(i => string.Equals(i.Name, "VIDEO_TS.BUP", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (vmgPath == null)
|
||||
{
|
||||
var allIfos = allFiles.Where(i => string.Equals(i.Extension, ".ifo", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
foreach (var ifo in allIfos)
|
||||
{
|
||||
var num = ifo.Name.Split('_').ElementAtOrDefault(1);
|
||||
ushort ifoNumber;
|
||||
var numbersRead = new List<ushort>();
|
||||
|
||||
if (!string.IsNullOrEmpty(num) && ushort.TryParse(num, out ifoNumber) && !numbersRead.Contains(ifoNumber))
|
||||
{
|
||||
ReadVTS(ifoNumber, ifo.FullName);
|
||||
numbersRead.Add(ifoNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var vmgFs = _fileSystem.GetFileStream(vmgPath.FullName, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
|
||||
{
|
||||
using (BigEndianBinaryReader vmgRead = new BigEndianBinaryReader(vmgFs))
|
||||
{
|
||||
vmgFs.Seek(0x3E, SeekOrigin.Begin);
|
||||
_titleSetCount = vmgRead.ReadUInt16();
|
||||
|
||||
// read address of TT_SRPT
|
||||
vmgFs.Seek(0xC4, SeekOrigin.Begin);
|
||||
uint ttSectorPtr = vmgRead.ReadUInt32();
|
||||
vmgFs.Seek(ttSectorPtr * 2048, SeekOrigin.Begin);
|
||||
ReadTT_SRPT(vmgRead);
|
||||
}
|
||||
}
|
||||
|
||||
for (ushort titleSetNum = 1; titleSetNum <= _titleSetCount; titleSetNum++)
|
||||
{
|
||||
ReadVTS(titleSetNum, allFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadTT_SRPT(BinaryReader read)
|
||||
{
|
||||
_titleCount = read.ReadUInt16();
|
||||
read.BaseStream.Seek(6, SeekOrigin.Current);
|
||||
for (uint titleNum = 1; titleNum <= _titleCount; titleNum++)
|
||||
{
|
||||
Title t = new Title(titleNum);
|
||||
t.ParseTT_SRPT(read);
|
||||
Titles.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadVTS(ushort vtsNum, List<FileSystemMetadata> allFiles)
|
||||
{
|
||||
var filename = String.Format("VTS_{0:00}_0.IFO", vtsNum);
|
||||
|
||||
var vtsPath = allFiles.FirstOrDefault(i => string.Equals(i.Name, filename, StringComparison.OrdinalIgnoreCase)) ??
|
||||
allFiles.FirstOrDefault(i => string.Equals(i.Name, Path.ChangeExtension(filename, ".bup"), StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (vtsPath == null)
|
||||
{
|
||||
throw new FileNotFoundException("Unable to find VTS IFO file");
|
||||
}
|
||||
|
||||
ReadVTS(vtsNum, vtsPath.FullName);
|
||||
}
|
||||
|
||||
private void ReadVTS(ushort vtsNum, string vtsPath)
|
||||
{
|
||||
VTSPaths[vtsNum] = vtsPath;
|
||||
|
||||
using (var vtsFs = _fileSystem.GetFileStream(vtsPath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read))
|
||||
{
|
||||
using (BigEndianBinaryReader vtsRead = new BigEndianBinaryReader(vtsFs))
|
||||
{
|
||||
// Read VTS_PTT_SRPT
|
||||
vtsFs.Seek(0xC8, SeekOrigin.Begin);
|
||||
uint vtsPttSrptSecPtr = vtsRead.ReadUInt32();
|
||||
uint baseAddr = (vtsPttSrptSecPtr * 2048);
|
||||
vtsFs.Seek(baseAddr, SeekOrigin.Begin);
|
||||
|
||||
ushort numTitles = vtsRead.ReadUInt16();
|
||||
vtsRead.ReadUInt16();
|
||||
uint endaddr = vtsRead.ReadUInt32();
|
||||
uint[] offsets = new uint[numTitles];
|
||||
for (ushort titleNum = 0; titleNum < numTitles; titleNum++)
|
||||
{
|
||||
offsets[titleNum] = vtsRead.ReadUInt32();
|
||||
}
|
||||
|
||||
for (uint titleNum = 0; titleNum < numTitles; titleNum++)
|
||||
{
|
||||
uint chapNum = 1;
|
||||
vtsFs.Seek(baseAddr + offsets[titleNum], SeekOrigin.Begin);
|
||||
Title t = Titles.FirstOrDefault(vtst => vtst.IsVTSTitle(vtsNum, titleNum + 1));
|
||||
if (t == null) continue;
|
||||
|
||||
do
|
||||
{
|
||||
t.Chapters.Add(new Chapter(vtsRead.ReadUInt16(), vtsRead.ReadUInt16(), chapNum));
|
||||
if (titleNum + 1 < numTitles && vtsFs.Position == (baseAddr + offsets[titleNum + 1])) break;
|
||||
chapNum++;
|
||||
}
|
||||
while (vtsFs.Position < (baseAddr + endaddr));
|
||||
}
|
||||
|
||||
// Read VTS_PGCI
|
||||
vtsFs.Seek(0xCC, SeekOrigin.Begin);
|
||||
uint vtsPgciSecPtr = vtsRead.ReadUInt32();
|
||||
vtsFs.Seek(vtsPgciSecPtr * 2048, SeekOrigin.Begin);
|
||||
|
||||
long startByte = vtsFs.Position;
|
||||
|
||||
ushort numPgcs = vtsRead.ReadUInt16();
|
||||
vtsFs.Seek(6, SeekOrigin.Current);
|
||||
for (ushort pgcNum = 1; pgcNum <= numPgcs; pgcNum++)
|
||||
{
|
||||
byte pgcCat = vtsRead.ReadByte();
|
||||
bool entryPgc = (pgcCat & 0x80) != 0;
|
||||
uint titleNum = (uint)(pgcCat & 0x7F);
|
||||
|
||||
vtsFs.Seek(3, SeekOrigin.Current);
|
||||
uint vtsPgcOffset = vtsRead.ReadUInt32();
|
||||
|
||||
Title t = Titles.FirstOrDefault(vtst => vtst.IsVTSTitle(vtsNum, titleNum));
|
||||
if (t != null) t.AddPgc(vtsRead, startByte + vtsPgcOffset, entryPgc, pgcNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
DvdLib/Ifo/DvdTime.cs
Normal file
34
DvdLib/Ifo/DvdTime.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public class DvdTime
|
||||
{
|
||||
public readonly byte Hour, Minute, Second, Frames, FrameRate;
|
||||
|
||||
public DvdTime(byte[] data)
|
||||
{
|
||||
Hour = GetBCDValue(data[0]);
|
||||
Minute = GetBCDValue(data[1]);
|
||||
Second = GetBCDValue(data[2]);
|
||||
Frames = GetBCDValue((byte)(data[3] & 0x3F));
|
||||
|
||||
if ((data[3] & 0x80) != 0) FrameRate = 30;
|
||||
else if ((data[3] & 0x40) != 0) FrameRate = 25;
|
||||
}
|
||||
|
||||
private byte GetBCDValue(byte data)
|
||||
{
|
||||
return (byte)((((data & 0xF0) >> 4) * 10) + (data & 0x0F));
|
||||
}
|
||||
|
||||
public static explicit operator TimeSpan(DvdTime time)
|
||||
{
|
||||
int ms = (int)(((1.0 / (double)time.FrameRate) * time.Frames) * 1000.0);
|
||||
return new TimeSpan(0, time.Hour, time.Minute, time.Second, ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
DvdLib/Ifo/PgcCommandTable.cs
Normal file
20
DvdLib/Ifo/PgcCommandTable.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public class ProgramChainCommandTable
|
||||
{
|
||||
public readonly ushort LastByteAddress;
|
||||
public readonly List<VirtualMachineCommand> PreCommands;
|
||||
public readonly List<VirtualMachineCommand> PostCommands;
|
||||
public readonly List<VirtualMachineCommand> CellCommands;
|
||||
}
|
||||
|
||||
public class VirtualMachineCommand
|
||||
{
|
||||
public readonly byte[] Command;
|
||||
}
|
||||
}
|
||||
17
DvdLib/Ifo/Program.cs
Normal file
17
DvdLib/Ifo/Program.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public readonly List<Cell> Cells;
|
||||
|
||||
public Program(List<Cell> cells)
|
||||
{
|
||||
Cells = cells;
|
||||
}
|
||||
}
|
||||
}
|
||||
117
DvdLib/Ifo/ProgramChain.cs
Normal file
117
DvdLib/Ifo/ProgramChain.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public enum ProgramPlaybackMode
|
||||
{
|
||||
Sequential,
|
||||
Random,
|
||||
Shuffle
|
||||
}
|
||||
|
||||
public class ProgramChain
|
||||
{
|
||||
private ushort _unknown1;
|
||||
|
||||
private byte _programCount;
|
||||
public readonly List<Program> Programs;
|
||||
|
||||
private byte _cellCount;
|
||||
public readonly List<Cell> Cells;
|
||||
|
||||
public DvdTime PlaybackTime { get; private set; }
|
||||
public UserOperation ProhibitedUserOperations { get; private set; }
|
||||
public byte[] AudioStreamControl { get; private set; } // 8*2 entries
|
||||
public byte[] SubpictureStreamControl { get; private set; } // 32*4 entries
|
||||
|
||||
private ushort _nextProgramNumber;
|
||||
public readonly ProgramChain Next;
|
||||
|
||||
private ushort _prevProgramNumber;
|
||||
public readonly ProgramChain Previous;
|
||||
|
||||
private ushort _goupProgramNumber;
|
||||
public readonly ProgramChain Goup; // ?? maybe Group
|
||||
|
||||
private byte _playbackMode;
|
||||
public ProgramPlaybackMode PlaybackMode { get; private set; }
|
||||
public uint ProgramCount { get; private set; }
|
||||
|
||||
public byte StillTime { get; private set; }
|
||||
public byte[] Palette { get; private set; } // 16*4 entries
|
||||
|
||||
private ushort _commandTableOffset;
|
||||
public readonly ProgramChainCommandTable CommandTable;
|
||||
|
||||
private ushort _programMapOffset;
|
||||
private ushort _cellPlaybackOffset;
|
||||
private ushort _cellPositionOffset;
|
||||
|
||||
public readonly uint VideoTitleSetIndex;
|
||||
|
||||
internal ProgramChain(uint vtsPgcNum)
|
||||
{
|
||||
VideoTitleSetIndex = vtsPgcNum;
|
||||
Cells = new List<Cell>();
|
||||
Programs = new List<Program>();
|
||||
}
|
||||
|
||||
internal void ParseHeader(BinaryReader br)
|
||||
{
|
||||
long startPos = br.BaseStream.Position;
|
||||
|
||||
br.ReadUInt16();
|
||||
_programCount = br.ReadByte();
|
||||
_cellCount = br.ReadByte();
|
||||
PlaybackTime = new DvdTime(br.ReadBytes(4));
|
||||
ProhibitedUserOperations = (UserOperation)br.ReadUInt32();
|
||||
AudioStreamControl = br.ReadBytes(16);
|
||||
SubpictureStreamControl = br.ReadBytes(128);
|
||||
|
||||
_nextProgramNumber = br.ReadUInt16();
|
||||
_prevProgramNumber = br.ReadUInt16();
|
||||
_goupProgramNumber = br.ReadUInt16();
|
||||
|
||||
StillTime = br.ReadByte();
|
||||
byte pbMode = br.ReadByte();
|
||||
if (pbMode == 0) PlaybackMode = ProgramPlaybackMode.Sequential;
|
||||
else PlaybackMode = ((pbMode & 0x80) == 0) ? ProgramPlaybackMode.Random : ProgramPlaybackMode.Shuffle;
|
||||
ProgramCount = (uint)(pbMode & 0x7F);
|
||||
|
||||
Palette = br.ReadBytes(64);
|
||||
_commandTableOffset = br.ReadUInt16();
|
||||
_programMapOffset = br.ReadUInt16();
|
||||
_cellPlaybackOffset = br.ReadUInt16();
|
||||
_cellPositionOffset = br.ReadUInt16();
|
||||
|
||||
// read position info
|
||||
br.BaseStream.Seek(startPos + _cellPositionOffset, SeekOrigin.Begin);
|
||||
for (int cellNum = 0; cellNum < _cellCount; cellNum++)
|
||||
{
|
||||
Cell c = new Cell();
|
||||
c.ParsePosition(br);
|
||||
Cells.Add(c);
|
||||
}
|
||||
|
||||
br.BaseStream.Seek(startPos + _cellPlaybackOffset, SeekOrigin.Begin);
|
||||
for (int cellNum = 0; cellNum < _cellCount; cellNum++)
|
||||
{
|
||||
Cells[cellNum].ParsePlayback(br);
|
||||
}
|
||||
|
||||
br.BaseStream.Seek(startPos + _programMapOffset, SeekOrigin.Begin);
|
||||
List<int> cellNumbers = new List<int>();
|
||||
for (int progNum = 0; progNum < _programCount; progNum++) cellNumbers.Add(br.ReadByte() - 1);
|
||||
|
||||
for (int i = 0; i < cellNumbers.Count; i++)
|
||||
{
|
||||
int max = (i + 1 == cellNumbers.Count) ? _cellCount : cellNumbers[i+1];
|
||||
Programs.Add(new Program(Cells.Where((c, idx) => idx >= cellNumbers[i] && idx < max).ToList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
64
DvdLib/Ifo/Title.cs
Normal file
64
DvdLib/Ifo/Title.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public class Title
|
||||
{
|
||||
public uint TitleNumber { get; private set; }
|
||||
public uint AngleCount { get; private set; }
|
||||
public ushort ChapterCount { get; private set; }
|
||||
public byte VideoTitleSetNumber { get; private set; }
|
||||
|
||||
private ushort _parentalManagementMask;
|
||||
private byte _titleNumberInVTS;
|
||||
private uint _vtsStartSector; // relative to start of entire disk
|
||||
|
||||
public ProgramChain EntryProgramChain { get; private set; }
|
||||
public readonly List<ProgramChain> ProgramChains;
|
||||
|
||||
public readonly List<Chapter> Chapters;
|
||||
|
||||
public Title(uint titleNum)
|
||||
{
|
||||
ProgramChains = new List<ProgramChain>();
|
||||
Chapters = new List<Chapter>();
|
||||
Chapters = new List<Chapter>();
|
||||
TitleNumber = titleNum;
|
||||
}
|
||||
|
||||
public bool IsVTSTitle(uint vtsNum, uint vtsTitleNum)
|
||||
{
|
||||
return (vtsNum == VideoTitleSetNumber && vtsTitleNum == _titleNumberInVTS);
|
||||
}
|
||||
|
||||
internal void ParseTT_SRPT(BinaryReader br)
|
||||
{
|
||||
byte titleType = br.ReadByte();
|
||||
// TODO parse Title Type
|
||||
|
||||
AngleCount = br.ReadByte();
|
||||
ChapterCount = br.ReadUInt16();
|
||||
_parentalManagementMask = br.ReadUInt16();
|
||||
VideoTitleSetNumber = br.ReadByte();
|
||||
_titleNumberInVTS = br.ReadByte();
|
||||
_vtsStartSector = br.ReadUInt32();
|
||||
}
|
||||
|
||||
internal void AddPgc(BinaryReader br, long startByte, bool entryPgc, uint pgcNum)
|
||||
{
|
||||
long curPos = br.BaseStream.Position;
|
||||
br.BaseStream.Seek(startByte, SeekOrigin.Begin);
|
||||
|
||||
ProgramChain pgc = new ProgramChain(pgcNum);
|
||||
pgc.ParseHeader(br);
|
||||
ProgramChains.Add(pgc);
|
||||
if (entryPgc) EntryProgramChain = pgc;
|
||||
|
||||
br.BaseStream.Seek(curPos, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
DvdLib/Ifo/UserOperation.cs
Normal file
38
DvdLib/Ifo/UserOperation.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
[Flags]
|
||||
public enum UserOperation
|
||||
{
|
||||
None = 0,
|
||||
TitleOrTimePlay = 1,
|
||||
ChapterSearchOrPlay = 2,
|
||||
TitlePlay = 4,
|
||||
Stop = 8,
|
||||
GoUp = 16,
|
||||
TimeOrChapterSearch = 32,
|
||||
PrevOrTopProgramSearch = 64,
|
||||
NextProgramSearch = 128,
|
||||
ForwardScan = 256,
|
||||
BackwardScan = 512,
|
||||
TitleMenuCall = 1024,
|
||||
RootMenuCall = 2048,
|
||||
SubpictureMenuCall = 4096,
|
||||
AudioMenuCall = 8192,
|
||||
AngleMenuCall = 16384,
|
||||
ChapterMenuCall = 32768,
|
||||
Resume = 65536,
|
||||
ButtonSelectOrActive = 131072,
|
||||
StillOff = 262144,
|
||||
PauseOn = 524288,
|
||||
AudioStreamChange = 1048576,
|
||||
SubpictureStreamChange = 2097152,
|
||||
AngleChange = 4194304,
|
||||
KaraokeAudioPresentationModeChange = 8388608,
|
||||
VideoPresentationModeChange = 16777216,
|
||||
}
|
||||
}
|
||||
51
DvdLib/Ifo/VideoAttributes.cs
Normal file
51
DvdLib/Ifo/VideoAttributes.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DvdLib.Ifo
|
||||
{
|
||||
public enum VideoCodec
|
||||
{
|
||||
MPEG1 = 0,
|
||||
MPEG2 = 1,
|
||||
}
|
||||
|
||||
public enum VideoFormat
|
||||
{
|
||||
NTSC = 0,
|
||||
PAL = 1,
|
||||
}
|
||||
|
||||
public enum AspectRatio
|
||||
{
|
||||
ar4to3 = 0,
|
||||
ar16to9 = 3
|
||||
}
|
||||
|
||||
public enum FilmMode
|
||||
{
|
||||
None = -1,
|
||||
Camera = 0,
|
||||
Film = 1,
|
||||
}
|
||||
|
||||
public class VideoAttributes
|
||||
{
|
||||
public readonly VideoCodec Codec;
|
||||
public readonly VideoFormat Format;
|
||||
public readonly AspectRatio Aspect;
|
||||
public readonly bool AutomaticPanScan;
|
||||
public readonly bool AutomaticLetterBox;
|
||||
public readonly bool Line21CCField1;
|
||||
public readonly bool Line21CCField2;
|
||||
public readonly int Width;
|
||||
public readonly int Height;
|
||||
public readonly bool Letterboxed;
|
||||
public readonly FilmMode FilmMode;
|
||||
|
||||
public VideoAttributes()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
29
DvdLib/Properties/AssemblyInfo.cs
Normal file
29
DvdLib/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Resources;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DvdLib")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DvdLib")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: NeutralResourcesLanguage("en")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.1")]
|
||||
16
DvdLib/project.json
Normal file
16
DvdLib/project.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"frameworks": {
|
||||
"netstandard1.6": {
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.0"
|
||||
}
|
||||
},
|
||||
".NETPortable,Version=v4.5,Profile=Profile7": {
|
||||
"buildOptions": {
|
||||
"define": []
|
||||
},
|
||||
"frameworkAssemblies": {}
|
||||
}
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
3965
DvdLib/project.lock.json
Normal file
3965
DvdLib/project.lock.json
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user