private void m_pToggleSend_Click(object sender,EventArgs e) { if(m_pAudioInRTP == null){ m_pSendStream = m_pSession.CreateSendStream(); m_pAudioInRTP = new AudioIn_RTP(AudioIn.Devices[m_pInDevices.SelectedIndex],20,m_pMainUI.AudioCodecs,m_pSendStream); m_pAudioInRTP.Start(); m_pTimer = new Timer(); m_pTimer.Interval = 500; m_pTimer.Tick += delegate(object s1,EventArgs e1){ m_pCodec.Text = m_pAudioInRTP.AudioCodec.Name; m_pPacketsSent.Text = m_pSendStream.RtpPacketsSent.ToString(); m_pKBSent.Text = Convert.ToString(m_pSendStream.RtpBytesSent / 1000); }; m_pTimer.Start(); m_pToggleSend.Text = "Stop"; } else{ m_pTimer.Dispose(); m_pTimer = null; m_pAudioInRTP.Dispose(); m_pAudioInRTP = null; m_pSendStream.Close(); m_pSendStream = null; m_pToggleSend.Text = "Send"; } }
private void btnCall_Click_1(object sender, RoutedEventArgs e) { IsConnected = false; m_pSession = m_pRtpSession.Sessions[0]; if (m_pAudioInRTP == null) { m_pSendStream = m_pSession.CreateSendStream(); } else { m_pAudioInRTP.Dispose(); m_pAudioInRTP = null; m_pSendStream.Close(); m_pSendStream = null; } // _soundSender.Start(); // _soundReceiver.Start(); }
/// <summary> /// Sends audio to RTP session target(s). /// </summary> private void SendAudio() { try{ using (FileStream fs = File.OpenRead(m_SendFile)){ RTP_SendStream sendStream = m_pSession.CreateSendStream(); byte[] buffer = new byte[400]; int readedCount = fs.Read(buffer, 0, buffer.Length); long lastSendTime = DateTime.Now.Ticks; long packetsSent = 0; long totalSent = 0; while (readedCount > 0) { if (m_pMainUI.ActiveCodec != null) { byte[] encodedData = m_pMainUI.ActiveCodec.Encode(buffer, 0, buffer.Length); // Send audio frame. RTP_Packet packet = new RTP_Packet(); packet.Timestamp = m_pSession.RtpClock.RtpTimestamp; packet.Data = encodedData; sendStream.Send(packet); // Read next audio frame. readedCount = fs.Read(buffer, 0, buffer.Length); totalSent += encodedData.Length; packetsSent++; this.BeginInvoke(new MethodInvoker(delegate(){ m_pCodec.Text = m_pMainUI.ActiveCodec.Name; m_pPacketsSent.Text = packetsSent.ToString(); m_pKBSent.Text = Convert.ToString(totalSent / 1000); })); } Thread.Sleep(25); lastSendTime = DateTime.Now.Ticks; } sendStream.Close(); } } catch (Exception x) { string dummy = x.Message; } }