Exemple #1
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>
        ///
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="volume">The supplied value is a percentage of the maximum volume level of the device and must be in the range 0-100.</param>
        /// <returns></returns>
        static public Status Play(Execute execute, bool multicast, IPAddress source_ip, int port, uint?volume100 = null)
        {
            if (session != null)
            {
                if (!Message.YesNo("Would you like to drop the previous stream?"))
                {
                    return(Status.BUSY);
                }
                session.Stop();
                session.Dispose();
            }

            Rtp.execute   = execute;
            Rtp.source_ip = source_ip;
            Rtp.volume100 = volume100;
            Rtp.multicast = multicast;
            session       = new RTP_MultimediaSession(RTP_Utils.GenerateCNAME());
            if (multicast)
            {
                session.CreateMulticastSession(null, new RTP_Clock(0, 8000), new RTP_Address(source_ip, port, port + 1));
            }
            else
            {
                session.CreateSession(new RTP_Address(IPAddress.Any, port, port + 1), new RTP_Clock(0, 8000));
            }
            session.Sessions[0].NewReceiveStream += NewReceiveStream;
            session.Sessions[0].Payload           = payload;
            session.Sessions[0].Start();

            return(Status.ACCEPTED);
        }
Exemple #3
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();
        }
        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());
            }
        }