TimeToSampleBox.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. namespace MatrixIO.IO.Bmff.Boxes
  7. {
  8. /// <summary>
  9. /// Time To Sample Box ("stts")
  10. /// </summary>
  11. [Box("stts", "Time To Sample Box")]
  12. public class TimeToSampleBox : FullBox, ITableBox<TimeToSampleBox.TimeToSampleEntry>
  13. {
  14. public TimeToSampleBox() : base() { }
  15. public TimeToSampleBox(Stream stream) : base(stream) { }
  16. internal override ulong CalculateSize()
  17. {
  18. return base.CalculateSize() + 4 + ((ulong)_Entries.Count * (4 + 4));
  19. }
  20. protected override void LoadFromStream(Stream stream)
  21. {
  22. base.LoadFromStream(stream);
  23. uint entryCount = stream.ReadBEUInt32();
  24. for (uint i = 0; i < entryCount; i++)
  25. {
  26. _Entries.Add(new TimeToSampleEntry() {
  27. SampleCount = stream.ReadBEUInt32(),
  28. SampleDelta = stream.ReadBEUInt32(),
  29. });
  30. }
  31. }
  32. protected override void SaveToStream(Stream stream)
  33. {
  34. base.SaveToStream(stream);
  35. stream.WriteBEUInt32((uint)_Entries.Count);
  36. foreach (TimeToSampleEntry TimeToSampleEntry in _Entries)
  37. {
  38. stream.WriteBEUInt32(TimeToSampleEntry.SampleCount);
  39. stream.WriteBEUInt32(TimeToSampleEntry.SampleDelta);
  40. }
  41. }
  42. private IList<TimeToSampleEntry> _Entries = Portability.CreateList<TimeToSampleEntry>();
  43. public IList<TimeToSampleEntry> Entries
  44. {
  45. get
  46. {
  47. return _Entries;
  48. }
  49. }
  50. public int EntryCount { get { return _Entries.Count; } }
  51. public class TimeToSampleEntry
  52. {
  53. public uint SampleCount { get; set; }
  54. public uint SampleDelta { get; set; }
  55. public TimeToSampleEntry() { }
  56. public TimeToSampleEntry(uint sampleCount, uint sampleDelta)
  57. {
  58. SampleCount = sampleCount;
  59. SampleDelta = sampleDelta;
  60. }
  61. }
  62. }
  63. }