DvdTime.cs 927 B

123456789101112131415161718192021222324252627282930313233
  1. #pragma warning disable CS1591
  2. using System;
  3. namespace DvdLib.Ifo
  4. {
  5. public class DvdTime
  6. {
  7. public readonly byte Hour, Minute, Second, Frames, FrameRate;
  8. public DvdTime(byte[] data)
  9. {
  10. Hour = GetBCDValue(data[0]);
  11. Minute = GetBCDValue(data[1]);
  12. Second = GetBCDValue(data[2]);
  13. Frames = GetBCDValue((byte)(data[3] & 0x3F));
  14. if ((data[3] & 0x80) != 0) FrameRate = 30;
  15. else if ((data[3] & 0x40) != 0) FrameRate = 25;
  16. }
  17. private static byte GetBCDValue(byte data)
  18. {
  19. return (byte)((((data & 0xF0) >> 4) * 10) + (data & 0x0F));
  20. }
  21. public static explicit operator TimeSpan(DvdTime time)
  22. {
  23. int ms = (int)(((1.0 / (double)time.FrameRate) * time.Frames) * 1000.0);
  24. return new TimeSpan(0, time.Hour, time.Minute, time.Second, ms);
  25. }
  26. }
  27. }