SampleToChunkBox.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. /// Sample To Chunk Box ("stsc")
  10. /// </summary>
  11. [Box("stsc", "Sample To Chunk Box")]
  12. public class SampleToChunkBox : FullBox, ITableBox<SampleToChunkBox.SampleToChunkEntry>
  13. {
  14. public SampleToChunkBox() : base() { }
  15. public SampleToChunkBox(Stream stream) : base(stream) { }
  16. internal override ulong CalculateSize()
  17. {
  18. return base.CalculateSize() + 4 + ((ulong)_Entries.Count * (4 + 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 SampleToChunkEntry()
  27. {
  28. FirstChunk = stream.ReadBEUInt32(),
  29. SamplesPerChunk = stream.ReadBEUInt32(),
  30. SampleDescriptionIndex = stream.ReadBEUInt32(),
  31. });
  32. }
  33. }
  34. protected override void SaveToStream(Stream stream)
  35. {
  36. base.SaveToStream(stream);
  37. stream.WriteBEUInt32((uint)_Entries.Count);
  38. foreach (SampleToChunkEntry SampleToChunkEntry in _Entries)
  39. {
  40. stream.WriteBEUInt32(SampleToChunkEntry.FirstChunk);
  41. stream.WriteBEUInt32(SampleToChunkEntry.SamplesPerChunk);
  42. stream.WriteBEUInt32(SampleToChunkEntry.SampleDescriptionIndex);
  43. }
  44. }
  45. private IList<SampleToChunkEntry> _Entries = Portability.CreateList<SampleToChunkEntry>();
  46. public IList<SampleToChunkEntry> Entries
  47. {
  48. get
  49. {
  50. return _Entries;
  51. }
  52. }
  53. public int EntryCount { get { return _Entries.Count; } }
  54. public class SampleToChunkEntry
  55. {
  56. public uint FirstChunk { get; set; }
  57. public uint SamplesPerChunk { get; set; }
  58. public uint SampleDescriptionIndex { get; set; }
  59. public SampleToChunkEntry() { }
  60. public SampleToChunkEntry(uint firstChunk, uint samplesPerChunk, uint sampleDescriptionIndex)
  61. {
  62. FirstChunk = firstChunk;
  63. SamplesPerChunk = samplesPerChunk;
  64. SampleDescriptionIndex = sampleDescriptionIndex;
  65. }
  66. }
  67. }
  68. }