Exemple #1
0
        /// <summary>
        /// When a AudioProperty in the fed packets is found this callback is called
        /// </summary>
        void AudioPropertyFound(object sender, PropertyFoundEventArgs args)
        {
            switch (args.Property)
            {
            case AudioFileStreamProperty.ReadyToProducePackets:
                Started = false;


                if (OutputQueue != null)
                {
                    OutputQueue.Dispose();
                }

                OutputQueue = new OutputAudioQueue(fileStream.StreamBasicDescription);
                if (OutputReady != null)
                {
                    OutputReady(OutputQueue);
                }

                currentByteCount             = 0;
                OutputQueue.OutputCompleted += HandleOutputQueueOutputCompleted;
                outputBuffers = new List <AudioBuffer>();

                for (int i = 0; i < MaxBufferCount; i++)
                {
                    IntPtr outBuffer;
                    OutputQueue.AllocateBuffer(BufferSize, out outBuffer);
                    outputBuffers.Add(new AudioBuffer()
                    {
                        Buffer = outBuffer, PacketDescriptions = new List <AudioStreamPacketDescription>()
                    });
                }

                currentBuffer = outputBuffers.First();

                OutputQueue.MagicCookie = fileStream.MagicCookie;
                break;
            }
        }
        /// <summary>
        /// Wait until a buffer is freed up
        /// </summary>
        void WaitForBuffer()
        {
            int curIndex = outputBuffers.IndexOf (currentBuffer);
            currentBuffer = outputBuffers [curIndex < outputBuffers.Count - 1 ? curIndex + 1 : 0];

            lock (currentBuffer) {
                while (currentBuffer.IsInUse)
                    Monitor.Wait (currentBuffer);
            }
        }
        /// <summary>
        /// When a AudioProperty in the fed packets is found this callback is called
        /// </summary>
        void AudioPropertyFound(object sender, PropertyFoundEventArgs args)
        {
            if (args.Property == AudioFileStreamProperty.ReadyToProducePackets) {
                Started = false;

                if (OutputQueue != null)
                    OutputQueue.Dispose ();

                OutputQueue = new OutputAudioQueue (fileStream.StreamBasicDescription);
                if (OutputReady != null)
                    OutputReady (OutputQueue);

                currentByteCount = 0;
                OutputQueue.BufferCompleted += HandleBufferCompleted;
                outputBuffers = new List<AudioBuffer> ();

                for (int i = 0; i < MaxBufferCount; i++) {
                    IntPtr outBuffer;
                    OutputQueue.AllocateBuffer (BufferSize, out outBuffer);
                    outputBuffers.Add (new AudioBuffer () {
                        Buffer = outBuffer,
                        PacketDescriptions = new List<AudioStreamPacketDescription> ()
                    });
                }

                currentBuffer = outputBuffers.First ();

                OutputQueue.MagicCookie = fileStream.MagicCookie;
            }
        }