Ejemplo n.º 1
0
        public RTPFactory(String RTPipAddress, int RTPport, String RTCPipAddress, int RTCPport, String forwardIP, int forwardPort)
        {
            //初始会话端
            Session = new RTPSession();
            //初始化发送者
            Sender = new RTPSender();
            //初始化接收者
            Receiver = new RTPReceiver();

            var senderEp = new IPEndPoint(IPAddress.Parse(forwardIP), forwardPort);

            //将发送参与者初始化绑定到目的端口
            senderParticipant = new RTPParticipant(senderEp);
            //将发送参与者添加到发送者中
            Sender.AddParticipant(senderParticipant);
            //将发送者添加到会话端中
            Session.AddSender(Sender);

            var rtpEp  = new IPEndPoint(IPAddress.Parse(RTPipAddress), RTPport);
            var rtcpEp = new IPEndPoint(IPAddress.Parse(RTCPipAddress), RTCPport);

            //将RTP参与者初始化绑定到RTP网络端点以及RTCP网络端点
            participant = new RTPParticipant(rtpEp, rtcpEp);
            //将RTP参与者添加到RTP接收者中
            Receiver.AddParticipant(participant);
            //将RTP接收者添加到会话端中
            Session.AddReceiver(Receiver);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// RTP工厂构造方法
        /// </summary>
        /// <param name="RTPipAddress">RTP发送ip地址</param>
        /// <param name="RTPport">RTP发送端口</param>
        /// <param name="RTCPipAddress">RTP接收端ip地址</param>
        /// <param name="RTCPport">RTP接收端口</param>
        /// <param name="forwardIP"></param>
        /// <param name="forwardPort"></param>
        public RtpFramer(String RTPipAddress, int RTPport, String RTCPipAddress, int RTCPport, String forwardIP, int forwardPort)
        {
            //实例化RTP会话端
            Session = new RTPSession();
            //实例化RTP发送端
            Sender = new RTPSender();
            //实例化RTP接收端
            Receiver = new RTPReceiver();
            //生成网络端点
            var senderEp = new IPEndPoint(IPAddress.Parse(forwardIP), forwardPort);

            //RTP参与者
            senderParticipant = new RTPParticipant(senderEp);
            //给RTP发送端添加RTP参与者
            Sender.AddParticipant(senderParticipant);
            //RTP会话端添加RTP发送端
            Session.AddSender(Sender);
            //生成RTP网络端点
            var rtpEp = new IPEndPoint(IPAddress.Parse(RTPipAddress), RTPport);
            //生成RTP接收端网络端点
            var rtcpEp = new IPEndPoint(IPAddress.Parse(RTCPipAddress), RTCPport);

            //新建RTP参与者绑定发送者端口以及接受者端口
            participant           = new RTPParticipant(rtpEp, rtcpEp);
            Session.NewRTPPacket  = NewRTPPacket;
            Session.NewRTCPPacket = NewRTCPPacket;
            Session.NewSSRC       = NewSSRC;
            Receiver.AddParticipant(participant);
            Session.AddReceiver(Receiver);
        }
Ejemplo n.º 3
0
        public RtpFramer(String RTPipAddress, int RTPport, String RTCPipAddress, int RTCPport, String forwardIP, int forwardPort)
        {
            Session  = new RTPSession();
            Sender   = new RTPSender();
            Receiver = new RTPReceiver();

            var senderEp = new IPEndPoint(IPAddress.Parse(forwardIP), forwardPort);

            senderParticipant = new RTPParticipant(senderEp);
            Sender.AddParticipant(senderParticipant);
            Session.AddSender(Sender);

            var rtpEp  = new IPEndPoint(IPAddress.Parse(RTPipAddress), RTPport);
            var rtcpEp = new IPEndPoint(IPAddress.Parse(RTCPipAddress), RTCPport);

            participant           = new RTPParticipant(rtpEp, rtcpEp);
            Session.NewRTPPacket  = NewRTPPacket;
            Session.NewRTCPPacket = NewRTCPPacket;
            Receiver.AddParticipant(participant);
            Session.AddReceiver(Receiver);
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            IPEndPoint localEP  = new IPEndPoint(IPAddress.Any, int.Parse(textBox3.Text));
            IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(textBox2.Text), int.Parse(textBox1.Text));

            participant = new RTPParticipant(localEP, remoteEP, null, null);

            rtp_sender = new RTPSender();
            rtp_sender.AddParticipant(participant);

            rtp_receiver = new RTPReceiver();
            rtp_receiver.AddParticipant(participant);



            //win = new WaveInput();
            //win.BitsPerSample = 16;
            //win.Channels = 1;
            //win.SampleRate = 8000;
            //win.TransferBufferSize = 320;
            //win.Init();
            //win.OpenDevice();

            WaveInThreadProc = new Thread(new ThreadStart(() =>
            {
                while (IsRunning)
                {
                    //if (win.WaitSamplesAvailable(100))
                    Thread.Sleep(1000);
                    {
                        //byte[] pcm = win.GetNextData();
                        //var frame = encoder.EncodeToFrame(pcm);
                        //if (frame != null)
                        {
                            var data = new byte[200];
                            for (int i = 0; i < 200; i++)
                            {
                                data[i] = Convert.ToByte(packetsSent + i);
                            }
                            ;
                            session.Send(new RTPPacket(data));

                            packetsSent++;
                        }
                    }
                }
            }))
            {
                Name = "WaveInputThread"
            };


            //wout = new WaveOutput();
            //wout.BitsPerSample = 16;
            //wout.Channels = 1;
            //wout.SampleRate = 8000;
            //wout.Init();
            //wout.OpenDevice();

            //encoder = new SpeechEncoder();
            //encoder.InputBitsPerSample = 16;
            //encoder.InputChannels = 1;
            //encoder.InputSampleRate = 8000;
            //encoder.OutputBitrate = 64000;
            //encoder.SetCodec(SpeechCodecs.G711A);
            //encoder.Init();

            //decoder = new SpeechDecoder();
            //decoder.Bitrate = 64000;

            //decoder.SetCodec(SpeechCodecs.G711A);
            //bool res = decoder.Init();

            // Set up last to avoid conflicts

            session = new RTPSession();
            session.AddReceiver(rtp_receiver);
            session.AddSender(rtp_sender);
            session.NewRTPPacket = OnNewPacket;

            IsRunning = true;
            //win.Start();
            WaveInThreadProc.Start();


            updateTimer.Interval = 500;
            updateTimer.Tick    += new EventHandler(updateTimer_Tick);
            updateTimer.Start();
        }