Beispiel #1
0
        public void Write(OggPacket packet, bool forceFlush = false)
        {
            var liboggPacket = new libogg.ogg_packet
            {
                packet     = Marshal.AllocHGlobal(packet.Data.Length),
                bytes      = packet.Data.Length,
                b_o_s      = packet.IsBeginOfStream ? 1 : 0,
                e_o_s      = packet.IsEndOfStream ? 1 : 0,
                granulepos = packet.GranulePosition,
                packetno   = packet.PacketNumber
            };

            Marshal.Copy(packet.Data, 0, liboggPacket.packet, packet.Data.Length);

            var result = libogg.ogg_stream_packetin(ref this.streamState, ref liboggPacket);

            Marshal.FreeHGlobal(liboggPacket.packet);

            if (result != 0)
            {
                throw new Exception("Internal error occurred when trying to submit a packet to the libogg stream.");
            }

            this.Flush(forceFlush);
        }
Beispiel #2
0
        public OggPacket(libogg.ogg_packet liboggPacket)
        {
            this.Data = new byte[liboggPacket.bytes];
            Marshal.Copy(liboggPacket.packet, this.Data, 0, liboggPacket.bytes);

            this.IsBeginOfStream = liboggPacket.b_o_s != 0;
            this.IsEndOfStream   = liboggPacket.e_o_s != 0;
            this.GranulePosition = liboggPacket.granulepos;
            this.PacketNumber    = liboggPacket.packetno;
        }
Beispiel #3
0
        /// <summary>
        /// Reads a packet from the stream.
        /// Internally this reads a page whenever no full packet can be read.
        /// Note that the granule position of the returned packet is -1 when it is not the last packet that ended on a page.
        /// </summary>
        /// <returns></returns>
        public OggPacket ReadPacket()
        {
            var liboggPacket = new libogg.ogg_packet();
            int packetOutResult;

            // Retry without new page if it is out of sync and has a gap (-1)
            do
            {
                packetOutResult = libogg.ogg_stream_packetout(ref this.streamState, ref liboggPacket);

                // Read a new page into the stream when there is insufficient data available
                if (packetOutResult == 0)
                {
                    this.BufferPage();
                }
            }while (packetOutResult != 1);

            return(new OggPacket(liboggPacket));
        }