Ejemplo n.º 1
0
        public static async Task <SampleDescriptionBox> CreateAsync(IBinaryStream stream, Box box)
        {
            var stsdBox = new SampleDescriptionBox();

            stream.Position = box.Offset + 8;
            stsdBox.Version = await stream.ReadByteAsync().ConfigureAwait(false);

            stsdBox.Flags = await stream.ReadInt32Async(3, ByteOrder.BigEndian).ConfigureAwait(false);

            var entriesAmount = await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

            for (var i = 0; i < entriesAmount; i++)
            {
                var sampleDescriptionSize = await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

                var dataFormat = await stream.ReadStringAsync(4).ConfigureAwait(false);

                stream.Position += 6;
                var dataReferenceIndex = await stream.ReadUInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);

                stsdBox.Table.Add(new TableEntry(sampleDescriptionSize, dataFormat, dataReferenceIndex));

                /*var version = await stream.ReadUInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);
                 * var revision = await stream.ReadUInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);
                 * var vendor = await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);
                 * var channels = await stream.ReadUInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);
                 * var sampleSize = await stream.ReadUInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);
                 * var compressionId = await stream.ReadUInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);
                 * var packetSize = await stream.ReadUInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);
                 * var sampleRate = await stream.ReadUInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);*/
            }
            return(stsdBox);
        }
Ejemplo n.º 2
0
        internal static async Task <Box> ReadBoxAsync(IBinaryStream stream, UInt32 maxPosition)
        {
            var boxes  = new List <Box>();
            var offset = stream.Position;
            var length = await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

            if ((length < 8) || (stream.Position + length - 4 > maxPosition))
            {
                return(null);
            }

            var name = await stream.ReadStringAsync(4).ConfigureAwait(false);

            if (name == "meta")
            {
                var version = await stream.ReadByteAsync().ConfigureAwait(false);

                var flags = await stream.ReadInt32Async(3, ByteOrder.BigEndian).ConfigureAwait(false);
            }
            var thisBoxMaxPosition = offset + length;

            while (stream.Position < thisBoxMaxPosition)
            {
                var box = await ReadBoxAsync(stream, thisBoxMaxPosition).ConfigureAwait(false);

                if (box == null)
                {
                    boxes.Clear();
                    stream.Position = thisBoxMaxPosition;
                    break;
                }
                boxes.Add(box);
            }
            return(new Box(offset, length, name, boxes));
        }
Ejemplo n.º 3
0
        public static async Task <SampleSizeBox> CreateAsync(IBinaryStream stream, Box box)
        {
            var stcoBox = new SampleSizeBox();

            stream.Position = box.Offset + 8;
            stcoBox.Version = await stream.ReadByteAsync().ConfigureAwait(false);

            stcoBox.Flags = await stream.ReadInt32Async(3, ByteOrder.BigEndian).ConfigureAwait(false);

            var uniformSizeOfSample = await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

            var entriesAmount = await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

            for (var i = 0; i < entriesAmount; i++)
            {
                stcoBox.Table.Add(await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false));
            }
            return(stcoBox);
        }
Ejemplo n.º 4
0
        public static async Task <TimeToSampleBox> CreateAsync(IBinaryStream stream, Box box)
        {
            var sttsBox = new TimeToSampleBox();

            stream.Position = box.Offset + 8;
            sttsBox.Version = await stream.ReadByteAsync().ConfigureAwait(false);

            sttsBox.Flags = await stream.ReadInt32Async(3, ByteOrder.BigEndian).ConfigureAwait(false);

            var entriesAmount = await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

            for (var i = 0; i < entriesAmount; i++)
            {
                var sampleCount = await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

                var sampleDuration = await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

                sttsBox.Table.Add(new TableEntry(sampleCount, sampleDuration));
            }
            return(sttsBox);
        }
Ejemplo n.º 5
0
        public static async Task <MediaHeaderBox> CreateAsync(IBinaryStream stream, Box box)
        {
            var mdhdBox = new MediaHeaderBox();

            stream.Position = box.Offset + 8;
            mdhdBox.Version = await stream.ReadByteAsync().ConfigureAwait(false);

            mdhdBox.Flags = await stream.ReadInt32Async(3, ByteOrder.BigEndian).ConfigureAwait(false);

            mdhdBox.CreationTime     = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false)).ToLocalTime();
            mdhdBox.ModificationTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false)).ToLocalTime();
            mdhdBox.TimeScale        = await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

            mdhdBox.Duration = await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

            mdhdBox.Language = await stream.ReadInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);

            mdhdBox.Quality = await stream.ReadInt16Async(ByteOrder.BigEndian).ConfigureAwait(false);

            return(mdhdBox);
        }
Ejemplo n.º 6
0
        public static async Task <SampleToChunkBox> CreateAsync(IBinaryStream stream, Box box)
        {
            var stscBox = new SampleToChunkBox();

            stream.Position = box.Offset + 8;
            stscBox.Version = await stream.ReadByteAsync().ConfigureAwait(false);

            stscBox.Flags = await stream.ReadInt32Async(3, ByteOrder.BigEndian).ConfigureAwait(false);

            var entriesAmount = await stream.ReadInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

            for (var i = 0; i < entriesAmount; i++)
            {
                var firstChunk = await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

                var samplesPerChunk = await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

                var sampleDescriptionId = await stream.ReadUInt32Async(ByteOrder.BigEndian).ConfigureAwait(false);

                stscBox.Table.Add(new TableEntry(firstChunk, samplesPerChunk, sampleDescriptionId));
            }
            return(stscBox);
        }
Ejemplo n.º 7
0
        public static async Task <MetadataBox> CreateAsync(IBinaryStream stream, Box box)
        {
            var metadataBox = new MetadataBox();

            stream.Position     = box.Offset + 8;
            metadataBox.Version = await stream.ReadByteAsync().ConfigureAwait(false);

            metadataBox.Flags = await stream.ReadInt32Async(3, ByteOrder.BigEndian).ConfigureAwait(false);

            var boxes = new List <Box>();

            while (stream.Position < box.Offset + box.Length)
            {
                var subBox = await Mpeg4File.ReadBoxAsync(stream, box.Offset + box.Length).ConfigureAwait(false);

                if (subBox != null)
                {
                    metadataBox.Boxes.Add(subBox);
                }
            }
            return(metadataBox);
        }