Ejemplo n.º 1
0
        public static ASFHeader Read(ASFChunk chunk)
        {
            var streams = new List <StreamType>();
            int bitrate = 0;
            var s       = new MemoryStream(chunk.Data, false);

            ASFObject.ReadHeader(s); //root_obj
            var sub_headers = BinaryReader.ReadUInt32LE(s);

            s.Seek(2, SeekOrigin.Current); //2 bytes padding?
            for (var i = 0; i < sub_headers; i++)
            {
                var obj = ASFObject.Read(s);
                switch (obj.Type)
                {
                case ASFObject.KnownType.FileProperty: {
                    var objdata = new MemoryStream(obj.Data, false);
                    objdata.Seek(32, SeekOrigin.Current);
                    BinaryReader.ReadInt64LE(objdata); //packets
                    objdata.Seek(28, SeekOrigin.Current);
                    BinaryReader.ReadInt32LE(objdata); //packetsize_min
                    BinaryReader.ReadInt32LE(objdata); //packetsize_max
                    bitrate = (BinaryReader.ReadInt32LE(objdata) + 999) / 1000;
                }
                break;

                case ASFObject.KnownType.StreamProperty: {
                    var objdata     = new MemoryStream(obj.Data, false);
                    var stream_type = new Guid(BinaryReader.ReadBytes(objdata, 16));
                    if (stream_type == ASFObject.StreamIDAudio)
                    {
                        streams.Add(StreamType.Audio);
                    }
                    else if (stream_type == ASFObject.StreamIDVideo)
                    {
                        streams.Add(StreamType.Video);
                    }
                    else
                    {
                        streams.Add(StreamType.Unknown);
                    }
                }
                break;

                default:
                    break;
                }
            }
            return(new ASFHeader(bitrate, streams.ToArray()));
        }
Ejemplo n.º 2
0
        public TopLevelHeaderObjectData(ReadOnlyMemory <byte> rawData)
        {
            RawData = rawData;
            var count   = BinaryPrimitives.ReadInt32LittleEndian(RawData.Span);
            var mem     = RawData.Slice(6);
            var objects = new ASFObject[count];

            for (int i = 0; i < count; i++)
            {
                var(obj, nxt) = ASFObject.ReadFromMemory(mem);
                objects[i]    = obj;
                mem           = nxt;
            }
            Objects = objects;
        }