Esempio n. 1
0
 internal void PacketIn(ref OggPacket packet)
 {
     if (SafeNativeMethods.OggStreamPacketIn(_state, ref packet) != 0)
     {
         throw new IOException(Resources.NativeOggStreamPacketInError);
     }
 }
Esempio n. 2
0
        internal void HeaderOut(ref VorbisComment comment, out OggPacket first, out OggPacket second, out OggPacket third)
        {
            Result result = SafeNativeMethods.VorbisAnalysisHeaderOut(_dspState, ref comment,
                                                                      out first, out second, out third);

            if (result != Result.Ok)
            {
                throw new IOException(string.Format(CultureInfo.CurrentCulture,
                                                    Resources.NativeVorbisEncoderHeaderOutError, result));
            }
        }
        internal void HeaderIn(ref VorbisComment comment, ref OggPacket packet)
        {
            Result result = SafeNativeMethods.VorbisSynthesisHeaderIn(_info, ref comment, ref packet);

            switch (result)
            {
            case Result.Ok:
                return;

            case Result.NotVorbisError:
                throw new UnsupportedAudioException(Resources.NativeVorbisDecoderNotVorbisError);

            default:
                throw new IOException(string.Format(CultureInfo.CurrentCulture, Resources.NativeVorbisDecoderHeaderInError, result));
            }
        }
Esempio n. 4
0
        internal bool FlushPacket(out OggPacket packet)
        {
            Result result = SafeNativeMethods.VorbisBitrateFlushPacket(_dspState, out packet);

            switch (result)
            {
            case Result.Ok:
                return(false);

            case Result.OkMoreAvailable:
                return(true);

            default:
                throw new IOException(string.Format(CultureInfo.CurrentCulture,
                                                    Resources.NativeVorbisEncoderFlushPacketError, result));
            }
        }
Esempio n. 5
0
 internal int PacketOut(out OggPacket packet)
 {
     return(SafeNativeMethods.OggStreamPacketOut(_state, out packet));
 }
        public void WriteMetadata(Stream stream, MetadataDictionary metadata, SettingsDictionary settings)
        {
            // This buffer is used for both reading and writing:
            var buffer = new byte[4096];

            using (var tempStream = new MemoryStream())
            {
                NativeOggStream inputOggStream  = null;
                NativeOggStream outputOggStream = null;

                try
                {
                    using (var sync = new NativeOggSync())
                    {
                        OggPage inPage;

                        do
                        {
                            // Read from the buffer into a page:
                            while (sync.PageOut(out inPage) != 1)
                            {
                                int bytesRead = stream.Read(buffer, 0, buffer.Length);
                                if (bytesRead == 0)
                                {
                                    throw new IOException(Resources.ReadError);
                                }

                                IntPtr nativeBuffer = sync.Buffer(bytesRead);
                                Marshal.Copy(buffer, 0, nativeBuffer, bytesRead);

                                sync.Wrote(bytesRead);
                            }

                            // Initialize the input and output streams, if necessary:
                            if (inputOggStream == null)
                            {
                                inputOggStream = new NativeOggStream(SafeNativeMethods.OggPageGetSerialNumber(ref inPage));
                            }
                            if (outputOggStream == null)
                            {
                                outputOggStream = new NativeOggStream(inputOggStream.SerialNumber);
                            }

                            inputOggStream.PageIn(ref inPage);

                            OggPacket packet;
                            while (inputOggStream.PacketOut(out packet) == 1)
                            {
                                // Substitute the new comment packet:
                                if (packet.PacketNumber == 1)
                                {
                                    OggPacket commentPacket = GetCommentPacket(metadata);
                                    outputOggStream.PacketIn(ref commentPacket);
                                }
                                else
                                {
                                    outputOggStream.PacketIn(ref packet);
                                }

                                // Page out each packet, flushing at the end of the header:
                                OggPage outPage;
                                if (packet.PacketNumber == 2)
                                {
                                    while (outputOggStream.Flush(out outPage))
                                    {
                                        WritePage(outPage, tempStream, buffer);
                                    }
                                }
                                else
                                {
                                    while (outputOggStream.PageOut(out outPage))
                                    {
                                        WritePage(outPage, tempStream, buffer);
                                    }
                                }
                            }
                        } while (SafeNativeMethods.OggPageEndOfStream(ref inPage) == 0);

                        // If the end of the stream is reached, overwrite the original file and return:
                        Overwrite(stream, tempStream);
                    }
                }
                finally
                {
                    inputOggStream?.Dispose();
                    outputOggStream?.Dispose();
                }
            }
        }
Esempio n. 7
0
 internal static extern int OggStreamPacketOut(IntPtr streamState, out OggPacket packet);
Esempio n. 8
0
 internal static extern int OggStreamPacketIn(IntPtr streamState, ref OggPacket packet);
Esempio n. 9
0
 internal static extern Result VorbisBitrateFlushPacket(IntPtr dspState, out OggPacket packet);
Esempio n. 10
0
 internal static extern Result VorbisAnalysisHeaderOut(IntPtr dspState, ref VorbisComment comment, out OggPacket first, out OggPacket second, out OggPacket third);
Esempio n. 11
0
 internal static extern Result VorbisSynthesisHeaderIn(IntPtr info, ref VorbisComment comment, ref OggPacket packet);
Esempio n. 12
0
 internal static extern int VorbisCommentHeaderOut(ref VorbisComment comment, out OggPacket packet);