MovieDataBox.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. /// Movie Data Box ("mdat")
  10. /// </summary>
  11. [Box("mdat", "Movie Data Box")]
  12. public class MovieDataBox : Box, IContentBox
  13. {
  14. public MovieDataBox() : base() { }
  15. /// <summary>
  16. /// Reads an 'mdat' box from a given stream
  17. /// </summary>
  18. /// <param name="stream"></param>
  19. public MovieDataBox(Stream stream) : base(stream) { }
  20. /// <summary>
  21. /// Constructs a new box with content from the given stream
  22. /// </summary>
  23. /// <param name="stream">Stream containing box content.</param>
  24. /// <param name="contentOffset">Offset of box content.</param>
  25. /// <param name="contentSize">Length of box content.</param>
  26. public MovieDataBox(Stream contentStream, ulong contentOffset, ulong? contentSize)
  27. {
  28. if (!contentStream.CanSeek) throw new NotSupportedException("The underlying Box.ToStream() does not presently support reading source content from an unseekable stream.");
  29. if (contentSize == null)
  30. {
  31. throw new NotSupportedException("The underlying Box.ToStream() does not presently support unknown length content.");
  32. //this.Size = 0;
  33. }
  34. else if (contentSize + 8 > uint.MaxValue)
  35. {
  36. this.Size = 1;
  37. this.LargeSize = (contentSize + 8);
  38. }
  39. else
  40. {
  41. this.Size = (uint)(contentSize + 16);
  42. }
  43. this.ContentOffset = contentOffset;
  44. this._SourceStream = contentStream;
  45. }
  46. }
  47. }