Ejemplo n.º 1
0
        /// <summary>
        /// Init for a call
        /// </summary>
        private void InitCall()
        {
            callUdp    = new UdpClient(CALL_PORT);
            callActive = true;
            pcmCodec   = new UncompressedPcmCodec();

            Thread tRecording = new Thread(new ThreadStart(() =>
            {
                voip              = new VoIPBase();
                voip.OnRecording += new VoIPBase.RecordEventHandler(VoIP_OnRecording);

                while (callActive)
                {
                    ;                //Keep thread running and take "voip" far away from "NullReferenceException"
                }
            }));

            tRecording.IsBackground = true;

            Thread tReceive = new Thread(new ThreadStart(() => {
                while (callActive)
                {
                    try
                    {
                        byte[] receivedData = callUdp.Receive(ref remoteCallIpEndp);

                        PLAY_AGAIN:
                        try
                        {
                            voip.AsyncPlaying(receivedData, 0, receivedData.Length);
                        }
                        catch (NullReferenceException) //Fix strangle error by BufferedWaveProvider.AsyncPlaying
                        {
                            goto PLAY_AGAIN;
                        }
                    }
                    catch (SocketException ex)
                    {
                        if (ex.SocketErrorCode == SocketError.ConnectionReset)
                        {
                        }                                                          //Igrone "An existing connection was forcibly closed by the remote host" excetion

                        MessageBox.Show(ex.Message);
                    }
                }
            }));

            tReceive.IsBackground = true;

            tReceive.Start();
            tRecording.Start();
        }
Ejemplo n.º 2
0
        public VoIPBase()
        {
            pcmCodec = new UncompressedPcmCodec();

            waveInEvent = new WaveInEvent();
            waveInEvent.BufferMilliseconds = 100;
            waveInEvent.WaveFormat         = pcmCodec.RecordFormat;
            waveInEvent.DataAvailable     += new EventHandler <WaveInEventArgs>(waveInEvent_DataAvailable);
            waveInEvent.StartRecording();

            waveProvider = new BufferedWaveProvider(pcmCodec.RecordFormat);
            waveProvider.BufferDuration = TimeSpan.FromSeconds(5);

            waveOut = new WaveOut();
            waveOut.Init(waveProvider);
            waveOut.Play();
        }