Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);

            Width = stream.ReadBEUInt32();
            Height = stream.ReadBEUInt32();
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            Width  = stream.ReadBEUInt32();
            Height = stream.ReadBEUInt32();
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            _Predefined = stream.ReadBEUInt32();
            HandlerType = new FourCC(stream.ReadBytes(4));
            for (int i = 0; i < _Reserved.Length; i++) _Reserved[i] = stream.ReadBEUInt32();
            Name = stream.ReadNullTerminatedUTF8String();
        }
Exemplo n.º 9
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            MaxProtocolDataUnitSize     = stream.ReadBEUInt16();
            AverageProtocolDataUnitSize = stream.ReadBEUInt16();
            MaxBitrate     = stream.ReadBEUInt32();
            AverageBitrate = stream.ReadBEUInt32();
            _Reserved      = stream.ReadBEUInt32();
        }
Exemplo n.º 10
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            TrackID = stream.ReadBEUInt32();
            DefaultSampleDescriptionIndex = stream.ReadBEUInt32();
            DefaultSampleDuration         = stream.ReadBEUInt32();
            DefaultSampleSize             = stream.ReadBEUInt32();
            DefaultSampleFlags._flags     = stream.ReadBEUInt32();
        }
Exemplo n.º 11
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            TrackID = stream.ReadBEUInt32();
            DefaultSampleDescriptionIndex = stream.ReadBEUInt32();
            DefaultSampleDuration = stream.ReadBEUInt32();
            DefaultSampleSize = stream.ReadBEUInt32();
            DefaultSampleFlags._flags = stream.ReadBEUInt32();
        }
Exemplo n.º 12
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            MaxProtocolDataUnitSize = stream.ReadBEUInt16();
            AverageProtocolDataUnitSize = stream.ReadBEUInt16();
            MaxBitrate = stream.ReadBEUInt32();
            AverageBitrate = stream.ReadBEUInt32();
            _Reserved = stream.ReadBEUInt32();
        }
Exemplo n.º 13
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            uint entryCount = stream.ReadBEUInt32();

            for (uint i = 0; i < entryCount; i++)
            {
                _Entries.Add(new SyncSampleEntry(stream.ReadBEUInt32()));
            }
        }
Exemplo n.º 14
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            _Predefined = stream.ReadBEUInt32();
            HandlerType = new FourCC(stream.ReadBytes(4));
            for (int i = 0; i < _Reserved.Length; i++)
            {
                _Reserved[i] = stream.ReadBEUInt32();
            }
            Name = stream.ReadNullTerminatedUTF8String();
        }
Exemplo n.º 15
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            _Height                 = stream.ReadBEUInt32();
            _Width                  = stream.ReadBEUInt32();
            _NumberOfComponents     = stream.ReadBEUInt16();
            BitsPerComponent        = stream.ReadOneByte();
            _CompressionType        = stream.ReadOneByte();
            _IsUnknownColorspace    = stream.ReadOneByte();
            _IsIntellectualProperty = stream.ReadOneByte();
        }
Exemplo n.º 16
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            _Height = stream.ReadBEUInt32();
            _Width = stream.ReadBEUInt32();
            _NumberOfComponents = stream.ReadBEUInt16();
            BitsPerComponent = stream.ReadOneByte();
            _CompressionType = stream.ReadOneByte();
            _IsUnknownColorspace = stream.ReadOneByte();
            _IsIntellectualProperty = stream.ReadOneByte();
        }
Exemplo n.º 17
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            uint entryCount = stream.ReadBEUInt32();

            Entries = new ChunkOffsetEntry[entryCount];

            for (uint i = 0; i < entryCount; i++)
            {
                Entries[i] = new ChunkOffsetEntry(stream.ReadBEUInt32());
            }
        }
Exemplo n.º 18
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            MajorBrand = new FourCC(stream.ReadBEUInt32());
            MinorVersion = stream.ReadBEUInt32();

            ulong remainingBytes = EffectiveSize - CalculateSize();
            ulong numBrands =  remainingBytes / 4;
            for (ulong i = 0; i < numBrands ; i++)
            {
                _CompatibleBrands.Add(new FourCC(stream.ReadBEUInt32()));
            }
        }
Exemplo n.º 19
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            uint entryCount = stream.ReadBEUInt32();

            for (uint i = 0; i < entryCount; i++)
            {
                _Entries.Add(new CompositionOffsetEntry()
                {
                    SampleCount  = stream.ReadBEUInt32(),
                    SampleOffset = stream.ReadBEUInt32(),
                });
            }
        }
Exemplo n.º 20
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            SampleSize   = stream.ReadBEUInt32();
            _SampleCount = stream.ReadBEUInt32();

            if (SampleSize == 0)
            {
                for (uint i = 0; i < _SampleCount; i++)
                {
                    _Entries.Add(new SampleSizeEntry(stream.ReadBEUInt32()));
                }
            }
        }
Exemplo n.º 21
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            MajorBrand   = new FourCC(stream.ReadBEUInt32());
            MinorVersion = stream.ReadBEUInt32();

            ulong remainingBytes = EffectiveSize - CalculateSize();
            ulong numBrands      = remainingBytes / 4;

            for (ulong i = 0; i < numBrands; i++)
            {
                CompatibleBrands.Add(new FourCC(stream.ReadBEUInt32()));
            }
        }
Exemplo n.º 22
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            uint entryCount = stream.ReadBEUInt32();

            for (uint i = 0; i < entryCount; i++)
            {
                _Entries.Add(new TimeToSampleEntry()
                {
                    SampleCount = stream.ReadBEUInt32(),
                    SampleDelta = stream.ReadBEUInt32(),
                });
            }
        }
Exemplo n.º 23
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            _Reserved  = stream.ReadBEUInt24();
            _FieldSize = stream.ReadOneByte();
            uint entryCount = stream.ReadBEUInt32();

            for (uint i = 0; i < entryCount; i++)
            {
                if (FieldSize == 4)
                {
                    byte twoFieldSizes = stream.ReadOneByte();
                    _Entries.Add(new CompactSampleSizeEntry((ushort)(twoFieldSizes & 0xFF00 >> 4)));
                    if (i < entryCount)
                    {
                        _Entries.Add(new CompactSampleSizeEntry((ushort)(twoFieldSizes & 0x00FF)));
                    }
                }
                else if (FieldSize == 8)
                {
                    _Entries.Add(new CompactSampleSizeEntry(stream.ReadOneByte()));
                }
                else if (FieldSize == 16)
                {
                    _Entries.Add(new CompactSampleSizeEntry(stream.ReadBEUInt16()));
                }
            }
        }
Exemplo n.º 24
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            uint entryCount = stream.ReadBEUInt32();

            for (uint i = 0; i < entryCount; i++)
            {
                _Entries.Add(new SampleToChunkEntry()
                {
                    FirstChunk             = stream.ReadBEUInt32(),
                    SamplesPerChunk        = stream.ReadBEUInt32(),
                    SampleDescriptionIndex = stream.ReadBEUInt32(),
                });
            }
        }
Exemplo n.º 25
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            uint entryCount = stream.ReadBEUInt32();

            this.Entries = new TimeToSampleEntry[entryCount];

            for (uint i = 0; i < entryCount; i++)
            {
                Entries[i] = new TimeToSampleEntry(
                    sampleCount: stream.ReadBEUInt32(),
                    sampleDelta: stream.ReadBEUInt32()
                    );
            }
        }
Exemplo n.º 26
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            uint entryCount = stream.ReadBEUInt32();

            Entries = new SampleToChunkEntry[entryCount];

            for (uint i = 0; i < entryCount; i++)
            {
                Entries[i] = new SampleToChunkEntry(
                    firstChunk: stream.ReadBEUInt32(),
                    samplesPerChunk: stream.ReadBEUInt32(),
                    sampleDescriptionIndex: stream.ReadBEUInt32()
                    );
            }
        }
Exemplo n.º 27
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            Alias = stream.ReadNullTerminatedUTF8String();
            ResourceType = stream.ReadBEUInt32();
            Id = stream.ReadBEInt16();
        }
Exemplo n.º 28
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            SampleSize   = stream.ReadBEUInt32();
            _sampleCount = stream.ReadBEUInt32();

            Entries = new SampleSizeEntry[_sampleCount];

            if (SampleSize == 0)
            {
                for (int i = 0; i < _sampleCount; i++)
                {
                    Entries[i] = new SampleSizeEntry(stream.ReadBEUInt32());
                }
            }
        }
Exemplo n.º 29
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            Alias        = stream.ReadNullTerminatedUTF8String();
            ResourceType = stream.ReadBEUInt32();
            Id           = stream.ReadBEInt16();
        }
Exemplo n.º 30
0
        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);
            }
        }
Exemplo n.º 31
0
        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;
        }
Exemplo n.º 32
0
        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()));
            }
        }
Exemplo n.º 33
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            SpecificationMethod = (SpecificationMethods)stream.ReadOneByte();
            Precedence = stream.ReadOneByte();
            ColorspaceApproximation = stream.ReadOneByte();
            if(SpecificationMethod == SpecificationMethods.EnumeratedColorspace)
                EnumeratedColorspace = (EnumeratedColorspaces)stream.ReadBEUInt32();
            // TODO: Read Profile?
        }
Exemplo n.º 34
0
        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();
        }
Exemplo n.º 35
0
        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();
        }
Exemplo n.º 36
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            SpecificationMethod     = (SpecificationMethods)stream.ReadOneByte();
            Precedence              = stream.ReadOneByte();
            ColorspaceApproximation = stream.ReadOneByte();
            if (SpecificationMethod == SpecificationMethods.EnumeratedColorspace)
            {
                EnumeratedColorspace = (EnumeratedColorspaces)stream.ReadBEUInt32();
            }
            // TODO: Read Profile?
        }
Exemplo n.º 37
0
        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();
        }
Exemplo n.º 38
0
        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();
        }
Exemplo n.º 39
0
        /// <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);
        }
Exemplo n.º 40
0
        /// <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);
        }
Exemplo n.º 41
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            uint sampleCount = stream.ReadBEUInt32();

            if ((Flags & TrackRunFlags.DataOffsetPresent) == TrackRunFlags.DataOffsetPresent)
            {
                DataOffset = stream.ReadBEInt32();
            }

            if ((Flags & TrackRunFlags.FirstSampleFlagsPresent) == TrackRunFlags.FirstSampleFlagsPresent)
            {
                FirstSampleFlags = new SampleFlags(stream.ReadBEUInt32());
            }

            for (uint i = 0; i < sampleCount; i++)
            {
                TrackRunEntry entry = new TrackRunEntry();
                if ((Flags & TrackRunFlags.SampleDurationPresent) == TrackRunFlags.SampleDurationPresent)
                {
                    entry.SampleDuration = stream.ReadBEUInt32();
                }
                if ((Flags & TrackRunFlags.SampleSizePresent) == TrackRunFlags.SampleSizePresent)
                {
                    entry.SampleSize = stream.ReadBEUInt32();
                }
                if ((Flags & TrackRunFlags.SampleFlagsPresent) == TrackRunFlags.SampleFlagsPresent)
                {
                    entry.SampleFlags = new SampleFlags(stream.ReadBEUInt32());
                }
                if ((Flags & TrackRunFlags.SampleCompositionTimeOffsetsPresent) == TrackRunFlags.SampleCompositionTimeOffsetsPresent)
                {
                    entry.SampleCompositionTimeOffset = stream.ReadBEUInt32();
                }

                _Entries.Add(entry);
            }
        }
Exemplo n.º 42
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            SequenceNumber = stream.ReadBEUInt32();
        }
Exemplo n.º 43
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            UncompressedSize = stream.ReadBEUInt32();
        }
Exemplo n.º 44
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            DataFormat = new FourCC(stream.ReadBEUInt32());
        }
Exemplo n.º 45
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            _EntryCount = stream.ReadBEUInt32();
        }
Exemplo n.º 46
0
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            SequenceNumber = stream.ReadBEUInt32();
        }
        protected override void LoadFromStream(Stream stream)
        {
            base.LoadFromStream(stream);

            MfraSize = stream.ReadBEUInt32();
        }