CompositionOffsetBox.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /// Composition Offset Box ("ctts")
  10. /// </summary>
  11. [Box("ctts", "Composition Offset Box")]
  12. public class CompositionOffsetBox : FullBox, ITableBox<CompositionOffsetBox.CompositionOffsetEntry>
  13. {
  14. public CompositionOffsetBox() : base() { }
  15. public CompositionOffsetBox(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 CompositionOffsetEntry()
  27. {
  28. SampleCount = stream.ReadBEUInt32(),
  29. SampleOffset = stream.ReadBEUInt32(),
  30. });
  31. }
  32. }
  33. protected override void SaveToStream(Stream stream)
  34. {
  35. base.SaveToStream(stream);
  36. stream.WriteBEUInt32((uint)_Entries.Count);
  37. foreach (CompositionOffsetEntry CompositionOffsetEntry in _Entries)
  38. {
  39. stream.WriteBEUInt32(CompositionOffsetEntry.SampleCount);
  40. stream.WriteBEUInt32(CompositionOffsetEntry.SampleOffset);
  41. }
  42. }
  43. private IList<CompositionOffsetEntry> _Entries = Portability.CreateList<CompositionOffsetEntry>();
  44. public IList<CompositionOffsetEntry> Entries
  45. {
  46. get
  47. {
  48. return _Entries;
  49. }
  50. }
  51. public int EntryCount { get { return _Entries.Count; } }
  52. public class CompositionOffsetEntry
  53. {
  54. public uint SampleCount { get; set; }
  55. public uint SampleOffset { get; set; }
  56. public CompositionOffsetEntry() { }
  57. public CompositionOffsetEntry(uint sampleCount, uint sampleDelta)
  58. {
  59. SampleCount = sampleCount;
  60. SampleOffset = sampleDelta;
  61. }
  62. }
  63. }
  64. }