diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-10-26 15:29:56 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-10-26 15:29:56 -0400 |
| commit | 3d7f75eea3465a34b443cf90d0affe5a637faf5d (patch) | |
| tree | 47be26c509373d62c560f65b2721c3185ba0e78d /DvdLib/Ifo/DvdTime.cs | |
| parent | 0189f4c49dc89654e6aa10c5dd0fc50a0984bfec (diff) | |
more steps to make provider project portable
Diffstat (limited to 'DvdLib/Ifo/DvdTime.cs')
| -rw-r--r-- | DvdLib/Ifo/DvdTime.cs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/DvdLib/Ifo/DvdTime.cs b/DvdLib/Ifo/DvdTime.cs new file mode 100644 index 000000000..f565f5fdf --- /dev/null +++ b/DvdLib/Ifo/DvdTime.cs @@ -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); + } + } +} |
