コード例 #1
0
ファイル: Vorbis.cs プロジェクト: windygu/alexandrialibrary
        public override bool ReadPacket(ByteVector packet, int index)
        {
            int type = PacketType(packet);

            if (type != 1 && index == 0)
            {
                throw new CorruptFileException("Stream does not begin with vorbis identifier");
            }

            if (comment_data == null)
            {
                if (type == 1)
                {
                    header = new HeaderPacket(packet);
                }
                else if (type == 3)
                {
                    comment_data = packet.Mid(7);
                }
                else
                {
                    return(true);
                }
            }

            return(comment_data != null);
        }
コード例 #2
0
        public override bool ReadPacket(ByteVector packet, int index)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "index must be at least zero.");
            }
            ByteVector signature = MagicSignature(packet);

            if (signature != magic_signature_header && index == 0)
            {
                throw new CorruptFileException("Stream does not begin with opus header.");
            }
            if (comment_data == null)
            {
                if (signature == magic_signature_header)
                {
                    header = new HeaderPacket(packet);
                }
                else if (signature == magic_signature_comment)
                {
                    comment_data = packet.Mid(magic_signature_length);
                }
                else
                {
                    return(true);
                }
            }
            return(comment_data != null);
        }
コード例 #3
0
        public override bool ReadPacket(ByteVector packet, int index)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "index must be at least zero.");
            }
            int num = PacketType(packet);
            if ((num != 0x80) && (index == 0))
            {
                throw new CorruptFileException("Stream does not begin with theora header.");
            }
            if (this.comment_data == null)
            {
                switch (num)
                {
                    case 0x80:
                        this.header = new HeaderPacket(packet);
                        goto Label_009D;

                    case 0x81:
                        this.comment_data = packet.Mid(7);
                        goto Label_009D;
                }
                return true;
            }
        Label_009D:
            return (this.comment_data != null);
        }
コード例 #4
0
        public override bool ReadPacket(ByteVector packet, int index)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", "index must be at least zero.");
            }
            int type = PacketType(packet);

            if (type != 0x80 && index == 0)
            {
                throw new CorruptFileException("Stream does not begin with theora header.");
            }
            if (comment_data == null)
            {
                if (type == 0x80)
                {
                    header = new HeaderPacket(packet);
                }
                else if (type == 0x81)
                {
                    comment_data = packet.Mid(7);
                }
                else
                {
                    return(true);
                }
            }
            return(comment_data != null);
        }
コード例 #5
0
        private static byte[] HeaderPacktToByteArray(HeaderPacket header)
        {
            byte[]   buff   = new byte[HeaderPacketSize];                //Create Buffer
            GCHandle handle = GCHandle.Alloc(buff, GCHandleType.Pinned); //Hands off GC

            try
            {
                Marshal.StructureToPtr(header, handle.AddrOfPinnedObject(), false);
                return(buff);
            }
            finally
            {
                handle.Free();
            }
        }
コード例 #6
0
ファイル: Vorbis.cs プロジェクト: bossaia/alexandrialibrary
 public override bool ReadPacket (ByteVector packet, int index)
 {
    int type = PacketType (packet);
    if (type != 1 && index == 0)
       throw new CorruptFileException ("Stream does not begin with vorbis identifier");
    
    if (comment_data == null)
    {
       if (type == 1)
          header = new HeaderPacket (packet);
       else if (type == 3)
          comment_data = packet.Mid (7);
       else
          return true;
    }
    
    return comment_data != null;
 }
コード例 #7
0
ファイル: Vorbis.cs プロジェクト: androidhacker/DotNetProjs
		/// <summary>
		///    Reads a Ogg packet that has been encountered in the
		///    stream.
		/// </summary>
		/// <param name="packet">
		///    A <see cref="ByteVector" /> object containing a packet to
		///    be read by the current instance.
		/// </param>
		/// <param name="index">
		///    A <see cref="int" /> value containing the index of the
		///    packet in the stream.
		/// </param>
		/// <returns>
		///    <see langword="true" /> if the codec has read all the
		///    necessary packets for the stream and does not need to be
		///    called again, typically once the Xiph comment has been
		///    found. Otherwise <see langword="false" />.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="packet" /> is <see langword="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="index" /> is less than zero.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The data does not conform to the specificiation for the
		///    codec represented by the current instance.
		/// </exception>
		public override bool ReadPacket (ByteVector packet, int index)
		{
			if (packet == null)
				throw new ArgumentNullException ("packet");
			
			if (index < 0)
				throw new ArgumentOutOfRangeException ("index",
					"index must be at least zero.");
			
			int type = PacketType (packet);
			if (type != 1 && index == 0)
				throw new CorruptFileException (
					"Stream does not begin with vorbis header.");
			
			if (comment_data == null) {
				if (type == 1)
					header = new HeaderPacket (packet);
				else if (type == 3)
					comment_data = packet.Mid (7);
				else
					return true;
			}
			
			return comment_data != null;
		}
コード例 #8
0
        private static void Listener(object args)
        {
            DuplexPipeChannel channel = (DuplexPipeChannel)args;

            IBus      bus      = channel.bus;
            Stream    stream   = channel.InStream;
            IHydrator hydrator = channel.settings.Hydrator;

            CancellationTokenSource cts   = channel.thrCancelTokens;
            CancellationToken       token = cts.Token;

            while (!token.IsCancellationRequested)
            {
                object payload;
                using (MemoryStream ms = new MemoryStream())
                {
                    bool final;
                    do
                    {
                        byte[] buffer = new byte[HeaderPacketSize];
                        var    handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                        try
                        {
                            ReadBytes(buffer, stream);
                            HeaderPacket header =
                                (HeaderPacket)
                                Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(HeaderPacket));
                            final = header.Final;

                            if (token.IsCancellationRequested)
                            {
                                break;
                            }

                            if (header.Size > 0)
                            {
                                byte[] dataBuffer = new byte[header.Size];
                                var    red        = ReadBytes(dataBuffer, stream);
                                ms.Write(dataBuffer, 0, red);
                            }
                        }
                        finally
                        {
                            handle.Free();
                        }
                    } while (!final && !token.IsCancellationRequested);

                    if (ms.Length == 0)
                    {
                        continue;
                    }
                    ms.Seek(0, SeekOrigin.Begin);

                    try
                    {
                        payload = hydrator.Hydrate(ms);
                    }
                    catch
                    {
                        payload = null;
                    }
                }

                if (payload != null)
                {
                    bus.Publish(payload);
                }
            }
        }
コード例 #9
0
ファイル: Opus.cs プロジェクト: tcHylmrX/taglib-sharp
		/// <summary>
		///    Reads a Ogg packet that has been encountered in the
		///    stream.
		/// </summary>
		/// <param name="packet">
		///    A <see cref="ByteVector" /> object containing a packet to
		///    be read by the current instance.
		/// </param>
		/// <param name="index">
		///    A <see cref="int" /> value containing the index of the
		///    packet in the stream.
		/// </param>
		/// <returns>
		///    <see langword="true" /> if the codec has read all the
		///    necessary packets for the stream and does not need to be
		///    called again, typically once the Xiph comment has been
		///    found. Otherwise <see langword="false" />.
		/// </returns>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="packet" /> is <see langword="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="index" /> is less than zero.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    The data does not conform to the specificiation for the
		///    codec represented by the current instance.
		/// </exception>
		public override bool ReadPacket (ByteVector packet, int index)
		{
			if (packet == null)
				throw new ArgumentNullException ("packet");

			if (index < 0)
				throw new ArgumentOutOfRangeException ("index",
					"index must be at least zero.");

			ByteVector signature = MagicSignature (packet);
			if (signature != magic_signature_header && index == 0)
				throw new CorruptFileException (
					"Stream does not begin with opus header.");

			if (comment_data == null) {
				if (signature == magic_signature_header)
					header = new HeaderPacket (packet);
				else if (signature == magic_signature_comment)
					comment_data =
						packet.Mid (magic_signature_length);
				else
					return true;
			}

			return comment_data != null;
		}
コード例 #10
0
 protected PacketWithHeaderPacket(HeaderPacket header)
 {
     Header = header;
 }
コード例 #11
0
ファイル: Theora.cs プロジェクト: secred/Tachycardia
        /// <summary>
        ///    Reads a Ogg packet that has been encountered in the
        ///    stream.
        /// </summary>
        /// <param name="packet">
        ///    A <see cref="ByteVector" /> object containing a packet to
        ///    be read by the current instance.
        /// </param>
        /// <param name="index">
        ///    A <see cref="int" /> value containing the index of the
        ///    packet in the stream.
        /// </param>
        /// <returns>
        ///    <see langword="true" /> if the codec has read all the
        ///    necessary packets for the stream and does not need to be
        ///    called again, typically once the Xiph comment has been
        ///    found. Otherwise <see langword="false" />.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="packet" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///    <paramref name="index" /> is less than zero.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    The data does not conform to the specificiation for the
        ///    codec represented by the current instance.
        /// </exception>
        public override bool ReadPacket(ByteVector packet, int index)
        {
            if (packet == null)
                System.Console.WriteLine("packet");

            if (index < 0)
                System.Console.WriteLine("index","index must be at least zero.");

            int type = PacketType (packet);
            if (type != 0x80 && index == 0)
                System.Console.WriteLine(
                    "Stream does not begin with theora header.");

            if (comment_data == null) {
                if (type == 0x80)
                    header = new HeaderPacket (packet);
                else if (type == 0x81)
                    comment_data = packet.Mid (7);
                else
                    return true;
            }

            return comment_data != null;
        }
コード例 #12
0
 public HandshakeInitializationPacket(HeaderPacket header)
     : base(header)
 {
 }