protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); if (Version == 1) { _CreationTime = stream.ReadBEUInt64(); _ModificationTime = stream.ReadBEUInt64(); TimeScale = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt64(); } else // if(Version == 0) { _CreationTime = stream.ReadBEUInt32(); _ModificationTime = stream.ReadBEUInt32(); TimeScale = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt32(); } _Rate = stream.ReadBEInt32(); _Volume = stream.ReadBEInt16(); Reserved = stream.ReadBytes(2 + (2 * 4)); for (int i = 0; i < 9; i++) { Matrix[i] = stream.ReadBEInt32(); } PreDefined = stream.ReadBytes(6 * 4); NextTrackID = stream.ReadBEUInt32(); }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); if (Version == 1) { CreationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt64()); ModificationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt64()); TrackID = stream.ReadBEUInt32(); Reserved1 = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt64(); } else // if (Version == 0) { CreationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt32()); ModificationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt32()); TrackID = stream.ReadBEUInt32(); Reserved1 = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt32(); } Reserved2 = stream.ReadBEUInt64(); Layer = stream.ReadBEInt16(); AlternateGroup = stream.ReadBEInt16(); Volume = stream.ReadBEInt16(); Reserved3 = stream.ReadBEUInt16(); for (int i = 0; i < 9; i++) { Matrix[i] = stream.ReadBEInt32(); } Width = stream.ReadBEUInt32(); Height = stream.ReadBEUInt32(); }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); ReferenceId = stream.ReadBEUInt32(); Timescale = stream.ReadBEUInt32(); if (Version == 1) { EarliestPresentationTime = stream.ReadBEUInt64(); FirstOffset = stream.ReadBEUInt64(); } else // v0 { EarliestPresentationTime = stream.ReadBEUInt32(); FirstOffset = stream.ReadBEUInt32(); } Reserved1 = stream.ReadBEUInt16(); ReferenceCount = stream.ReadBEUInt16(); Entries = new SegmentIndexEntry[ReferenceCount]; for (int i = 0; i < ReferenceCount; i++) { uint referenceValue = stream.ReadBEUInt32(); uint duration = stream.ReadBEUInt32(); uint sapValue = stream.ReadBEUInt32(); Entries[i] = new SegmentIndexEntry(referenceValue, duration, sapValue); } }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); if (Version == 1) { _CreationTime = stream.ReadBEUInt64(); _ModificationTime = stream.ReadBEUInt64(); TimeScale = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt64(); } else // if(Version == 0) { _CreationTime = stream.ReadBEUInt32(); _ModificationTime = stream.ReadBEUInt32(); TimeScale = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt32(); } _Rate = stream.ReadBEInt32(); _Volume = stream.ReadBEInt16(); Reserved = stream.ReadBytes(2 + (2 * 4)); for (int i = 0; i < 9; i++) Matrix[i] = stream.ReadBEInt32(); PreDefined = stream.ReadBytes(6 * 4); NextTrackID = stream.ReadBEUInt32(); }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); if (Version == 1) { CreationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt64()); ModificationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt64()); TrackID = stream.ReadBEUInt32(); _Reserved1 = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt64(); } else // if (Version == 0) { CreationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt32()); ModificationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt32()); TrackID = stream.ReadBEUInt32(); _Reserved1 = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt32(); } for (int i = 0; i < 2; i++) _Reserved2[0] = stream.ReadBEUInt32(); Layer = stream.ReadBEInt16(); AlternateGroup = stream.ReadBEInt16(); Volume = stream.ReadBEInt16(); _Reserved3 = stream.ReadBEUInt16(); for (int i = 0; i < 9; i++) _Matrix[i] = stream.ReadBEInt32(); Width = stream.ReadBEUInt32(); Height = stream.ReadBEUInt32(); }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); if (Version == 1) FragmentDuration = stream.ReadBEUInt64(); else FragmentDuration = (ulong)stream.ReadBEInt32(); }
public static Box FromStream(Stream stream, BaseMediaOptions options = BaseMediaOptions.LoadChildren) { Box box = null; try { ulong offset = (ulong)stream.Position; uint size = stream.ReadBEUInt32(); uint type = stream.ReadBEUInt32(); ulong?largeSize = null; if (size == 1) { largeSize = stream.ReadBEUInt64(); } BoxType boxType = (type == uuidType) ? new BoxType(new Guid(stream.ReadBytes(16))) : new BoxType(type); AvailableBoxTypes.TryGetValue(boxType, out Type t); box = t != null ? (Box)Activator.CreateInstance(t) : new Boxes.UnknownBox(boxType); box.Size = size; box.LargeSize = largeSize; box.Offset = offset; box.Initialize(ConstrainedStream.WrapStream(stream), options); } catch (EndOfStreamException) { } return(box); }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); uint entryCount = stream.ReadBEUInt32(); this.Entries = new EditListEntry[entryCount]; for (uint i = 0; i < entryCount; i++) { ulong segmentDuration; long mediaTime; short mediaRateInteger; short mediaRateFraction; if (Version == 1) { segmentDuration = stream.ReadBEUInt64(); mediaTime = stream.ReadBEInt64(); } else { segmentDuration = stream.ReadBEUInt32(); mediaTime = stream.ReadBEInt32(); } mediaRateInteger = stream.ReadBEInt16(); mediaRateFraction = stream.ReadBEInt16(); Entries[i] = new EditListEntry(segmentDuration, mediaTime, mediaRateInteger, mediaRateFraction); } }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); TrackID = stream.ReadBEUInt32(); if ((Flags & TrackFragmentFlags.BaseDataOffsetPresent) == TrackFragmentFlags.BaseDataOffsetPresent) { BaseDataOffset = stream.ReadBEUInt64(); } if ((Flags & TrackFragmentFlags.SampleDrescriptionIndexPresent) == TrackFragmentFlags.SampleDrescriptionIndexPresent) { SampleDescriptionIndex = stream.ReadBEUInt32(); } if ((Flags & TrackFragmentFlags.DefaultSampleDurationPresent) == TrackFragmentFlags.DefaultSampleDurationPresent) { DefaultSampleDuration = stream.ReadBEUInt32(); } if ((Flags & TrackFragmentFlags.DefaultSampleSizePresent) == TrackFragmentFlags.DefaultSampleSizePresent) { DefaultSampleSize = stream.ReadBEUInt32(); } if ((Flags & TrackFragmentFlags.DefaultSampleFlagsPresent) == TrackFragmentFlags.DefaultSampleFlagsPresent) { DefaultSampleFlags = new SampleFlags(stream.ReadBEUInt32()); } if ((Flags & TrackFragmentFlags.DurationIsEmpty) == TrackFragmentFlags.DurationIsEmpty) { DurationIsEmpty = true; } }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); uint entryCount = stream.ReadBEUInt32(); for (uint i = 0; i < entryCount; i++) { _Entries.Add(new ChunkLargeOffsetEntry(stream.ReadBEUInt64())); } }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); if (Version == 1) { CreationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt64()); ModificationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt64()); TimeScale = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt64(); } else // if (Version == 0) { CreationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt32()); ModificationTime = MovieHeaderBox.Convert1904Time(stream.ReadBEUInt32()); TimeScale = stream.ReadBEUInt32(); Duration = stream.ReadBEUInt32(); } Language = ConvertThreeLetterLanguageCode(stream.ReadBEUInt16()); Predefined = stream.ReadBEUInt16(); }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); if (Version == 1) { FragmentDuration = stream.ReadBEUInt64(); } else { FragmentDuration = (ulong)stream.ReadBEInt32(); } }
/// <summary> /// Reconstruct (deserializes) frame from the stream. May throw on error /// </summary> public WireFrame(Stream stream) : this() { //MAGIC var magic = stream.ReadBEUShort(); if (magic != MAGIC) { throw new ProtocolException( StringConsts.GLUE_BAD_PROTOCOL_FRAME_ERROR + "bag magic: expected '{0}' but got '{1}'".Args(MAGIC, magic)); } //VERSION var ver = stream.ReadByte(); if (ver != VERSION) { throw new ProtocolException( StringConsts.GLUE_BAD_PROTOCOL_FRAME_ERROR + "version mismatch: expected '{0}' but got '{1}'".Args(VERSION, ver)); } //TYPE m_Type = (FrameType)stream.ReadByte(); //FORMAT m_Format = stream.ReadBEInt32(); //ONEWAY m_OneWay = stream.ReadByte() != 0; //REQUESTID m_RequestID = new FID(stream.ReadBEUInt64()); //HEADERSCONTENT var len = stream.ReadBEInt32(); if (len > 0) { if (len > MAX_HEADERS_BYTE_LENGTH) { throw new ProtocolException( StringConsts.GLUE_BAD_PROTOCOL_FRAME_ERROR + "arrived headers length of {0} bytes exceeds the limit of {1} bytes".Args(len, MAX_HEADERS_BYTE_LENGTH)); } m_HeadersContentLength = len; var hbuf = new byte[len]; stream.Read(hbuf, 0, len); m_HeadersContent = HEADERS_ENCODING.GetString(hbuf); } m_Length = FRAME_LENGTH + m_HeadersContentLength; }
public static PageHeaderReadStatus TryReadPageHeader(Stream stream, ref DateTime current) { try { var h = stream.ReadBEUInt64(); if (h != PAGE_HEADER) { return(PageHeaderReadStatus.Corruption); } var nix = (long)stream.ReadBEUInt64(); var sts = nix.FromMicrosecondsSinceUnixEpochStart(); if (sts < current) { return(PageHeaderReadStatus.Corruption); } current = sts; } catch { return(PageHeaderReadStatus.EOF); } return(PageHeaderReadStatus.OK); }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); TrackID = stream.ReadBEUInt32(); if ((Flags & TrackFragmentFlags.BaseDataOffsetPresent) == TrackFragmentFlags.BaseDataOffsetPresent) BaseDataOffset = stream.ReadBEUInt64(); if ((Flags & TrackFragmentFlags.SampleDrescriptionIndexPresent) == TrackFragmentFlags.SampleDrescriptionIndexPresent) SampleDescriptionIndex = stream.ReadBEUInt32(); if ((Flags & TrackFragmentFlags.DefaultSampleDurationPresent) == TrackFragmentFlags.DefaultSampleDurationPresent) DefaultSampleDuration = stream.ReadBEUInt32(); if ((Flags & TrackFragmentFlags.DefaultSampleSizePresent) == TrackFragmentFlags.DefaultSampleSizePresent) DefaultSampleSize = stream.ReadBEUInt32(); if ((Flags & TrackFragmentFlags.DefaultSampleFlagsPresent) == TrackFragmentFlags.DefaultSampleFlagsPresent) DefaultSampleFlags = new SampleFlags(stream.ReadBEUInt32()); if ((Flags & TrackFragmentFlags.DurationIsEmpty) == TrackFragmentFlags.DurationIsEmpty) DurationIsEmpty = true; }
/// <summary> /// Deserializes a specific box type from the stream. /// </summary> /// <exception cref="System.FormatException">Thrown when the next box in the stream is not the expected type.</exception> /// <param name="stream">Stream containing the box to be deserialized at the current position.</param> protected Box(Stream stream) { Offset = (ulong)stream.Position; Size = stream.ReadBEUInt32(); uint type = stream.ReadBEUInt32(); if (Size == 1) { LargeSize = stream.ReadBEUInt64(); } if (type == 0x75756964) // 'uuid' { Type = new BoxType(new Guid(stream.ReadBytes(16))); } else { Type = new BoxType(type); } bool foundMatchingAttribute = false; object[] boxAttributes = this.GetType().GetCustomAttributes(typeof(BoxAttribute), true); foreach (BoxAttribute boxAttribute in boxAttributes) { if (boxAttribute.Type == Type) { foundMatchingAttribute = true; } } if (!foundMatchingAttribute) { throw new FormatException("Unexpected BMFF Box Type."); } Initialize(stream); }
/// <summary> /// Deserializes a specific box type from the stream. /// </summary> /// <exception cref="FormatException">Thrown when the next box in the stream is not the expected type.</exception> /// <param name="stream">Stream containing the box to be deserialized at the current position.</param> protected Box(Stream stream) { Offset = (ulong)stream.Position; Size = stream.ReadBEUInt32(); uint type = stream.ReadBEUInt32(); if (Size == 1) { LargeSize = stream.ReadBEUInt64(); } Type = (type == uuidType) ? new BoxType(new Guid(stream.ReadBytes(16))) : new BoxType(type); bool foundMatchingAttribute = false; var boxAttributes = this.GetType().GetCustomAttributes <BoxAttribute>(inherit: true); foreach (BoxAttribute boxAttribute in boxAttributes) { if (boxAttribute.Type == Type) { foundMatchingAttribute = true; } } if (!foundMatchingAttribute) { throw new FormatException("Unexpected BMFF Box Type."); } Initialize(stream); }
public static DateTime ReadTimeStamp(Stream stream) { var nix = (long)stream.ReadBEUInt64(); return nix.FromMicrosecondsSinceUnixEpochStart(); }
public static DateTime ReadTimeStamp(Stream stream) { var nix = (long)stream.ReadBEUInt64(); return(nix.FromMicrosecondsSinceUnixEpochStart()); }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); TrackID = stream.ReadBEUInt32(); _reserved = stream.ReadBytes(3); _sizeOf = stream.ReadOneByte(); uint entryCount = stream.ReadBEUInt32(); Entries = new TrackFragmentEntry[entryCount]; for (uint i = 0; i < entryCount; i++) { ulong time; ulong moofOffset; uint trafNumber; uint trunNumber; uint sampleNumber; if (Version == 0x01) { time = stream.ReadBEUInt64(); moofOffset = stream.ReadBEUInt64(); } else { time = stream.ReadBEUInt32(); moofOffset = stream.ReadBEUInt32(); } switch (SizeOfTrafNumber) { case 1: trafNumber = stream.ReadOneByte(); break; case 2: trafNumber = stream.ReadBEUInt16(); break; case 3: trafNumber = stream.ReadBEUInt24(); break; default: trafNumber = stream.ReadBEUInt32(); break; } switch (SizeOfTrunNumber) { case 1: trunNumber = stream.ReadOneByte(); break; case 2: trunNumber = stream.ReadBEUInt16(); break; case 3: trunNumber = stream.ReadBEUInt24(); break; default: trunNumber = stream.ReadBEUInt32(); break; } switch (SizeOfSampleNumber) { case 1: sampleNumber = stream.ReadOneByte(); break; case 2: sampleNumber = stream.ReadBEUInt16(); break; case 3: sampleNumber = stream.ReadBEUInt24(); break; default: sampleNumber = stream.ReadBEUInt32(); break; } Entries[i] = new TrackFragmentEntry(time, moofOffset, trafNumber, trunNumber, sampleNumber); } }
/// <summary> /// Reconstruct (deserializes) frame from the stream. May throw on error /// </summary> public WireFrame(Stream stream) : this() { //MAGIC var magic = stream.ReadBEUShort(); if (magic != MAGIC) throw new ProtocolException( StringConsts.GLUE_BAD_PROTOCOL_FRAME_ERROR + "bag magic: expected '{0}' but got '{1}'".Args(MAGIC, magic)); //VERSION var ver = stream.ReadByte(); if (ver != VERSION) throw new ProtocolException( StringConsts.GLUE_BAD_PROTOCOL_FRAME_ERROR + "version mismatch: expected '{0}' but got '{1}'".Args(VERSION, ver)); //TYPE m_Type = (FrameType)stream.ReadByte(); //FORMAT m_Format = stream.ReadBEInt32(); //ONEWAY m_OneWay = stream.ReadByte() != 0; //REQUESTID m_RequestID = new FID( stream.ReadBEUInt64() ); //HEADERSCONTENT var len = stream.ReadBEInt32(); if (len>0) { if (len>MAX_HEADERS_BYTE_LENGTH) throw new ProtocolException( StringConsts.GLUE_BAD_PROTOCOL_FRAME_ERROR + "arrived headers length of {0} bytes exceeds the limit of {1} bytes".Args(len, MAX_HEADERS_BYTE_LENGTH)); m_HeadersContentLength = len; var hbuf = new byte[len]; stream.Read(hbuf, 0, len); m_HeadersContent = HEADERS_ENCODING.GetString( hbuf ); } m_Length = FRAME_LENGTH + m_HeadersContentLength; }
protected override void LoadFromStream(Stream stream) { base.LoadFromStream(stream); TrackID = stream.ReadBEUInt32(); Reserved = stream.ReadBytes(3); _SizeOf = stream.ReadOneByte(); uint NumberOfEntries = stream.ReadBEUInt32(); for (uint i = 0; i < NumberOfEntries; i++) { TrackFragmentEntry entry = new TrackFragmentEntry(); if (Version == 0x01) { entry.Time = stream.ReadBEUInt64(); entry.MoofOffset = stream.ReadBEUInt64(); } else { entry.Time = stream.ReadBEUInt32(); entry.MoofOffset = stream.ReadBEUInt32(); } if (SizeOfTrafNumber == 1) { entry.TrafNumber = stream.ReadOneByte(); } else if (SizeOfTrafNumber == 2) { entry.TrafNumber = stream.ReadBEUInt16(); } else if (SizeOfTrafNumber == 3) { entry.TrafNumber = stream.ReadBEUInt24(); } else { entry.TrafNumber = stream.ReadBEUInt32(); } if (SizeOfTrunNumber == 1) { entry.TrunNumber = stream.ReadOneByte(); } else if (SizeOfTrunNumber == 2) { entry.TrunNumber = stream.ReadBEUInt16(); } else if (SizeOfTrunNumber == 3) { entry.TrunNumber = stream.ReadBEUInt24(); } else { entry.TrunNumber = stream.ReadBEUInt32(); } if (SizeOfSampleNumber == 1) { entry.SampleNumber = stream.ReadOneByte(); } else if (SizeOfSampleNumber == 2) { entry.SampleNumber = stream.ReadBEUInt16(); } else if (SizeOfSampleNumber == 3) { entry.SampleNumber = stream.ReadBEUInt24(); } else { entry.SampleNumber = stream.ReadBEUInt32(); } _Entries.Add(entry); } }
public static PageHeaderReadStatus TryReadPageHeader(Stream stream, ref DateTime current) { try { var h = stream.ReadBEUInt64(); if (h!=PAGE_HEADER) return PageHeaderReadStatus.Corruption; var nix = (long)stream.ReadBEUInt64(); var sts = nix.FromMicrosecondsSinceUnixEpochStart(); if (sts<current) return PageHeaderReadStatus.Corruption; current = sts; } catch { return PageHeaderReadStatus.EOF; } return PageHeaderReadStatus.OK; }