DvdTime.cs 1015 B

123456789101112131415161718192021222324252627282930313233343536373839
  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)
  15. {
  16. FrameRate = 30;
  17. }
  18. else if ((data[3] & 0x40) != 0)
  19. {
  20. FrameRate = 25;
  21. }
  22. }
  23. private static byte GetBCDValue(byte data)
  24. {
  25. return (byte)((((data & 0xF0) >> 4) * 10) + (data & 0x0F));
  26. }
  27. public static explicit operator TimeSpan(DvdTime time)
  28. {
  29. int ms = (int)(((1.0 / (double)time.FrameRate) * time.Frames) * 1000.0);
  30. return new TimeSpan(0, time.Hour, time.Minute, time.Second, ms);
  31. }
  32. }
  33. }