Пример #1
0
        internal void UnpackComment(OggBitStream input)
        {
            int vendor_len = input.ReadInt32();

            if (vendor_len < 0)
            {
                throw VorbisInfo.InvalidHeader();
            }
            var vendor = input.ReadBytes(vendor_len);

            int count = input.ReadInt32();

            if (count < 0)
            {
                throw VorbisInfo.InvalidHeader();
            }

            var comments = new List <byte[]> (count);

            for (int i = 0; i < count; ++i)
            {
                int len = input.ReadInt32();
                if (len < 0)
                {
                    throw VorbisInfo.InvalidHeader();
                }
                var bytes = input.ReadBytes(len);
                comments.Add(bytes);
            }
            if (input.ReadBits(1) != 1)
            {
                throw VorbisInfo.InvalidHeader();
            }

            this.Vendor   = vendor;
            this.Comments = comments;
        }
Пример #2
0
        // https://xiph.org/vorbis/doc/libvorbis/vorbis_synthesis_headerin.html
        public void SynthesisHeaderin(VorbisComment vc, OggPacket op)
        {
            using (var input = new OggBitStream(op))
            {
                int packtype = input.ReadUInt8();
                var buf      = input.ReadBytes(6);
                if (!buf.AsciiEqual("vorbis"))
                {
                    throw new InvalidDataException("Not an Ogg/Vorbis stream.");
                }
                switch (packtype)
                {
                case 1:
                    if (!op.BoS)
                    {
                        throw InvalidHeader();
                    }
                    if (Rate != 0)
                    {
                        throw InvalidHeader();
                    }
                    UnpackInfo(input);
                    break;

                case 3:
                    if (0 == Rate)
                    {
                        throw InvalidHeader();
                    }
                    vc.UnpackComment(input);
                    break;

                case 5:
                    if (0 == Rate || null == vc.Vendor)
                    {
                        throw InvalidHeader();
                    }
                    UnpackBooks(input);
                    break;

                default:
                    throw InvalidHeader();
                }
            }
        }