示例#1
0
        private FlacMetadata CreateFlacMetadataInstance(FlacMetaDataType flacMetadataType)
        {
            var flacMetadataTypeAsInt = (int)flacMetadataType;

            if (!_registeredmetadataTypes.TryGetValue(flacMetadataTypeAsInt, out var type))
            {
                return(new DefaultFlacMetadata(flacMetadataType));
            }

            return((FlacMetadata)Activator.CreateInstance(type));
        }
示例#2
0
        public unsafe static FlacMetadata FromStream(Stream stream)
        {
            bool             lastBlock = false;
            FlacMetaDataType type      = FlacMetaDataType.Undef;
            int length = 0;

            byte[] b = new byte[4];
            if (stream.Read(b, 0, 4) <= 0)
            {
                throw new FlacException(new EndOfStreamException("Could not read metadata"), FlacLayer.Metadata);

                fixed(byte *headerBytes = b)
                {
                    FlacBitReader bitReader = new FlacBitReader(headerBytes, 0);

                    lastBlock = bitReader.ReadBits(1) == 1;
                    type      = (FlacMetaDataType)bitReader.ReadBits(7);
                    length    = (int)bitReader.ReadBits(24);
                    ////1000 0000
                    //if (((b[0] & 0x80) >> 7) == 1)
                    //    lastBlock = true;
                    //type = (FlacMetaDataType)(b[0] & 0x7F);
                    //int length = (b[1] + (b[2] << 8) + (b[3] << 16));
                }

                FlacMetadata data;
                long streamStartPosition = stream.Position;
                if ((int)type < 0 || (int)type > 6)
                    return(null); }
                else
                {
                    switch (type)
                    {
                    case FlacMetaDataType.StreamInfo:
                        data = new FlacMetadataStreamInfo(stream, length, lastBlock);
                        break;

                    case FlacMetaDataType.Seektable:
                        data = new FlacMetadataSeekTable(stream, length, lastBlock);
                        break;

                    default:
                        data = new FlacMetadata(type, lastBlock, length);
                        break;
                    }
                }

                stream.Seek(length - (stream.Position - streamStartPosition), SeekOrigin.Current);
                return(data);
        }
 /// <summary>
 /// Registers a new <see cref="FlacMetaDataType"/>.
 /// </summary>
 /// <param name="metadataType">The <see cref="FlacMetaDataType"/>.</param>
 /// <typeparam name="T">The <see cref="FlacMetadata"/> object assigned to the <paramref name="metadataType"/>.</typeparam>
 public void RegistermetadataType <T>(FlacMetaDataType metadataType) where T : FlacMetadata
 {
     RegistermetadataType <T>((int)metadataType);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FlacMetadata"/> class.
 /// </summary>
 /// <param name="metadataType">The type of the metadata.</param>
 public DefaultFlacMetadata(FlacMetaDataType metadataType)
 {
     _metadataType = metadataType;
 }
示例#5
0
 protected FlacMetadata(FlacMetaDataType type, bool lastBlock, Int32 length)
 {
     MetaDataType = type;
     IsLastMetaBlock = lastBlock;
     Length = length;
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FlacMetadata"/> class.
 /// </summary>
 /// <param name="type">The type of the metadata.</param>
 /// <param name="lastBlock">A value which indicates whether this is the last <see cref="FlacMetadata"/> block inside of the stream. <c>true</c> means that this is the last <see cref="FlacMetadata"/> block inside of the stream.</param>
 /// <param name="length">The length of <see cref="FlacMetadata"/> block inside of the stream in bytes. Does not include the metadata header.</param>
 protected FlacMetadata(FlacMetaDataType type, bool lastBlock, int length)
 {
     MetaDataType    = type;
     IsLastMetaBlock = lastBlock;
     Length          = length;
 }