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";
            }
        }
Esempio n. 2
0
        public void Start()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if (!Started)
            {
                _hTrigger.Init();
                _multiSession = new RTP_MultimediaSession(RTP_Utils.GenerateCNAME());
                RTP_Session session = _multiSession.CreateSession(new RTP_Address(IPAddress.Parse(_localIP), _localPort, _localPort + 1), new RTP_Clock(0, VideoRate));
                session.Payload = RTP_PayloadTypes.H264;
                session.Start();
                _sendStream = session.CreateSendStream();

                _vSoure = VideoSourceCreator.Instance.GetVideoSource(_videoId);
                if (_targets.Count > 0)
                {
                    foreach (string key in _targets.Keys)
                    {
                        TargetItem ti = _targets[key];
                        session.AddTarget(new RTP_Address(ti.IP, ti.Port, ti.Port + 1));
                    }
                    startPlay();
                }
                Started = true;
            }
        }
        /// <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;
            }
        }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
        private void StartRtpSession(IPAddress remoteIp, IPAddress localIp, int rtpPort, int rtcpPort)
        {
            Dictionary <int, AudioCodec> m_pAudioCodecs = new Dictionary <int, AudioCodec>
            {
                { 0, new PCMU() }
            };

            RTP_MultimediaSession rtpMultimediaSession = new RTP_MultimediaSession(RTP_Utils.GenerateCNAME());

            sessionRtp = rtpMultimediaSession.CreateSession(new RTP_Address(localIp, rtpPort, rtcpPort), new RTP_Clock(1, 8000));
            sessionRtp.AddTarget(new RTP_Address(remoteIp, rtpPort, rtcpPort));
            sessionRtp.Payload    = 0;
            sessionRtp.StreamMode = RTP_StreamMode.SendReceive;

            sessionRtp.NewReceiveStream += delegate(object s, RTP_ReceiveStreamEventArgs e2)
            {
                if (audioOut != null)
                {
                    audioOutRtp = new AudioOut_RTP(audioOut, e2.Stream, m_pAudioCodecs);

                    if (speakerMute == false)
                    {
                        audioOutRtp.Start();
                    }
                }
            };

            if (audioIn != null)
            {
                audioInRtp = new AudioIn_RTP(audioIn, 10, m_pAudioCodecs, sessionRtp.CreateSendStream());

                if (micMute == false)
                {
                    audioInRtp.Start();
                }
            }

            sessionRtp.Start();
        }