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); }
public BaseMediaReader(Stream stream, BaseMediaOptions options = BaseMediaOptions.None) { if (stream.CanSeek && stream.Position != 0) { stream.Seek(0, SeekOrigin.Begin); } BaseStream = stream; Options = options; }
internal void Initialize(Stream stream, BaseMediaOptions options = BaseMediaOptions.LoadChildren) { Trace.WriteLine(Type, "Loading"); _SourceStream = stream; ConstrainedStream constrainedStream = ConstrainedStream.WrapStream(stream); constrainedStream.PushConstraint((long)Offset.Value, (long)EffectiveSize); LoadFromStream(stream); ContentOffset = (ulong)stream.Position; if (((options & BaseMediaOptions.LoadChildren) == BaseMediaOptions.LoadChildren) && this is ISuperBox) { LoadChildrenFromStream(stream); } Sync(stream, !(this is IContentBox)); constrainedStream.PopConstraint(); }
public BaseMediaReader(Stream stream, BaseMediaOptions options = BaseMediaOptions.None) { if (stream.CanSeek && stream.Position!=0) stream.Seek(0, SeekOrigin.Begin); BaseStream = stream; Options = options; }