Ejemplo n.º 1
0
        //Battery Monitor
        //AUDIO STREAM OLD
        private void m_pToggleRun_Click(object sender, EventArgs e)
        {
            if (m_IsRunning)
            {
                m_IsRunning = false;
                m_IsSendingTest = false;

                m_pRtpSession.Dispose();
                m_pRtpSession = null;

                m_pWaveOut.Dispose();
                m_pWaveOut = null;

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

                m_pOutDevices.Enabled = true;
                m_pToggleRun.Text = "Start";
                m_pRecord.Enabled = true;
                m_pRecordFile.Enabled = true;
                m_pRecordFileBrowse.Enabled = true;
                m_pRemoteIP.Enabled = false;
                m_pRemotePort.Enabled = false;
                m_pCodec.Enabled = false;
                m_pToggleMic.Text = "Send";
                m_pToggleMic.Enabled = false;
                m_pSendTestSound.Enabled = false;
                m_pSendTestSound.Text = "Send";
                m_pPlayTestSound.Enabled = false;
                m_pPlayTestSound.Text = "Play";
            }
            else
            {
                if (m_pOutDevices.SelectedIndex == -1)
                {
                    MessageBox.Show(this, "Please select output device !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (m_pRecord.Checked && m_pRecordFile.Text == "")
                {
                    MessageBox.Show(this, "Please specify record file !", "Error:", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (m_pRecord.Checked)
                {
                    m_pRecordStream = File.Create(m_pRecordFile.Text);
                }

                m_IsRunning = true;

                m_pWaveOut = new AudioOut(AudioOut.Devices[m_pOutDevices.SelectedIndex], 8000, 16, 1);

                m_pRtpSession = new RTP_MultimediaSession(RTP_Utils.GenerateCNAME());
                // --- Debug -----
                //wfrm_RTP_Debug frmRtpDebug = new wfrm_RTP_Debug(m_pRtpSession);
                //frmRtpDebug.Show();
                //-----------------
                m_pRtpSession.CreateSession(new RTP_Address(IPAddress.Parse(m_pLocalIP.Text), (int)m_pLocalPort.Value, (int)m_pLocalPort.Value + 1), new RTP_Clock(0, 8000));
                m_pRtpSession.Sessions[0].AddTarget(new RTP_Address(IPAddress.Parse(m_pRemoteIP.Text), (int)m_pRemotePort.Value, (int)m_pRemotePort.Value + 1));
                m_pRtpSession.Sessions[0].NewSendStream += new EventHandler<RTP_SendStreamEventArgs>(m_pRtpSession_NewSendStream);
                m_pRtpSession.Sessions[0].NewReceiveStream += new EventHandler<RTP_ReceiveStreamEventArgs>(m_pRtpSession_NewReceiveStream);
                m_pRtpSession.Sessions[0].Payload = 8;
                m_pRtpSession.Sessions[0].Start();

                m_pOutDevices.Enabled = false;
                m_pToggleRun.Text = "Stop";
                m_pRecord.Enabled = false;
                m_pRecordFile.Enabled = false;
                m_pRecordFileBrowse.Enabled = false;
                m_pRemoteIP.Enabled = true;
                m_pRemotePort.Enabled = true;
                m_pCodec.Enabled = true;
                m_pToggleMic.Enabled = true;
                m_pSendTestSound.Enabled = true;
                m_pSendTestSound.Text = "Send";
                m_pPlayTestSound.Enabled = true;
                m_pPlayTestSound.Text = "Play";
            }
            m_pCodec.SelectedIndex = 0;
        }
Ejemplo n.º 2
0
        private RTP_Session CreateRtpSession(RTP_MultimediaSession rtpMultimediaSession)
        {
            if (rtpMultimediaSession == null)
            {
                throw new ArgumentNullException("rtpMultimediaSession");
            }

            //--- Search RTP IP -------------------------------------------------------//
            IPAddress rtpIP = null;
            foreach (IPAddress ip in Dns.GetHostAddresses(""))
            {
                if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    rtpIP = ip;
                    break;
                }
            }
            if (rtpIP == null)
            {
                throw new Exception("None of the network connection is available.");
            }
            //------------------------------------------------------------------------//

            // Search free ports for RTP session.
            for (int i = 0; i < 100; i += 2)
            {
                try
                {
                    return rtpMultimediaSession.CreateSession(new RTP_Address(rtpIP, m_RtpBasePort, m_RtpBasePort + 1), new RTP_Clock(1, 8000));
                }
                catch
                {
                    m_RtpBasePort += 2;
                }
            }

            return null;
        }
Ejemplo n.º 3
0
        private void btnRestartConnection_Click_1(object sender, RoutedEventArgs e)
        {
            if (cbLocalIp.SelectedIndex < 0)
            {
                MessageBox.Show("Choose local IP");
                return;
            }

            IsConnected = true;
            InitializeClient();
            InitializeServer();
            /*InitializeSoundSender();
            InitializeSoundReceiver();*/
            if (m_IsRunning)
            {
                m_IsRunning = false;
                m_IsSendingTest = false;

                m_pRtpSession.Dispose();
                m_pRtpSession = null;

                m_pWaveOut.Dispose();
                m_pWaveOut = null;
            }
            else
            {
                m_IsRunning = true;

                switch (_selectedCodec)
                {
                    case "PCMU":
                        m_pActiveCodec = new PCMU();
                        break;
                    case "PCMA":
                    default:
                        m_pActiveCodec = new PCMA();
                        break;
                }

                var selectedOutDevice = cbAudioOutDevices.SelectedItem as AudioOutDevice;
                m_pWaveOut = new AudioOut(selectedOutDevice, _samplesPerSecond, _bitsPerSample, 1); // 1 - one channel (mono)
                m_pRtpSession = new RTP_MultimediaSession(RTP_Utils.GenerateCNAME());

                string localIp = cbLocalIp.SelectedItem.ToString();
                string partnerIp = tbxPartnerIp.Text;
                int k = string.Compare(localIp, partnerIp);

                m_pRtpSession.CreateSession(new RTP_Address(IPAddress.Parse(cbLocalIp.SelectedItem.ToString()), (int)10000 + k * 500/*m_pLocalPort.Value*/, (int)/*m_pLocalPort.Value*/10000 + k * 500 + 1), new RTP_Clock(0, _samplesPerSecond));
                m_pRtpSession.Sessions[0].AddTarget(new RTP_Address(IPAddress.Parse(tbxPartnerIp.Text), (int)/*m_pRemotePort.Value*/10000 - k * 500, (int)/*m_pRemotePort.Value*/10000 - k * 500 + 1));
                m_pRtpSession.Sessions[0].NewSendStream += new EventHandler<RTP_SendStreamEventArgs>(m_pRtpSession_NewSendStream);
                m_pRtpSession.Sessions[0].NewReceiveStream += new EventHandler<RTP_ReceiveStreamEventArgs>(m_pRtpSession_NewReceiveStream);
                m_pRtpSession.Sessions[0].Payload = 0;
                m_pRtpSession.Sessions[0].Start();

                m_pAudioCodecs = new Dictionary<int, AudioCodec>();
                m_pAudioCodecs.Add(0, new PCMU());
                m_pAudioCodecs.Add(8, new PCMA());
            }
        }