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); }
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); }
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); }
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); }
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(); } }
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; }
/// <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; }
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); } } }
/// <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; }
protected PacketWithHeaderPacket(HeaderPacket header) { Header = header; }
/// <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; }
public HandshakeInitializationPacket(HeaderPacket header) : base(header) { }