ChunkOffsetBox.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /// Chunk Offset Box ("stco")
  10. /// </summary>
  11. [Box("stco", "Chunk Offset Box")]
  12. public class ChunkOffsetBox : FullBox, ITableBox<ChunkOffsetBox.ChunkOffsetEntry>
  13. {
  14. public ChunkOffsetBox() : base() { }
  15. public ChunkOffsetBox(Stream stream) : base(stream) { }
  16. internal override ulong CalculateSize()
  17. {
  18. return base.CalculateSize() + 4 + ((ulong)_Entries.Count * 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 ChunkOffsetEntry(stream.ReadBEUInt32()));
  27. }
  28. }
  29. protected override void SaveToStream(Stream stream)
  30. {
  31. base.SaveToStream(stream);
  32. stream.WriteBEUInt32((uint)_Entries.Count);
  33. foreach (ChunkOffsetEntry chunkOffsetEntry in _Entries)
  34. {
  35. stream.WriteBEUInt32(chunkOffsetEntry.ChunkOffset);
  36. }
  37. }
  38. private IList<ChunkOffsetEntry> _Entries = Portability.CreateList<ChunkOffsetEntry>();
  39. public IList<ChunkOffsetEntry> Entries
  40. {
  41. get
  42. {
  43. return _Entries;
  44. }
  45. }
  46. public int EntryCount { get { return _Entries.Count; } }
  47. public class ChunkOffsetEntry
  48. {
  49. public uint ChunkOffset { get; set; }
  50. public ChunkOffsetEntry() { }
  51. public ChunkOffsetEntry(uint chunkOffset)
  52. {
  53. ChunkOffset = chunkOffset;
  54. }
  55. public static implicit operator uint(ChunkOffsetEntry entry)
  56. {
  57. return entry.ChunkOffset;
  58. }
  59. public static implicit operator ChunkOffsetEntry(uint chunkOffset)
  60. {
  61. return new ChunkOffsetEntry(chunkOffset);
  62. }
  63. }
  64. }
  65. }