来自 Streamcoders 的 RTP.NET

发布于 2024-09-27 16:17:18 字数 204 浏览 6 评论 0原文

我正在尝试使用 http://www.streamcoders.com 中的 RTP.NET 产品来发送/接收音频/视频数据。不幸的是,该网站上的小样本仅用于接收代码,但无法正常工作。 有人使用过 RTP.NET 程序集并成功发送/接收数据吗?

任何帮助表示赞赏。

I'm trying to use RTP.NET product from http://www.streamcoders.com in order to send/receive audio/video data. Unfortunately the small sample from the site which has code only for receiving doesn't work.
Has anyone used the RTP.NET assembly and managed to send/receive data?

Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒废 2024-10-04 16:17:18

请参阅 Stream 编码器站点上的此示例。它包含更多使用完整 MediaSuite.Net 库的内容(RTP.Net 是它),但这里有一个快速过滤器(使用垃圾数据......):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using StreamCoders.Network;
//using StreamCoders.Wave;
//using StreamCoders.Encoder;
//using StreamCoders.Decoder;
using System.Threading;
using StreamCoders;
using System.IO;

namespace SpeechSendReceive
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        RTPParticipant participant;
        RTPSender rtp_sender;
        RTPReceiver rtp_receiver;
        RTPSession session;
        //WaveOutput wout;
        //WaveInput win;

        //SpeechEncoder encoder;
        //SpeechDecoder decoder;

        Thread WaveInThreadProc;

        bool IsRunning = false;

        long packetsReceived;
        long packetsSent;

        System.Windows.Forms.Timer updateTimer = new System.Windows.Forms.Timer();

        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();

        }

        void updateTimer_Tick(object sender, EventArgs e)
        {
            sentLabel.Text = packetsSent.ToString();
            receivedLabel.Text = packetsReceived.ToString();


        }

        private string fn = string.Format(@"c:\temp\rtp{0}.snd", DateTime.Now.Millisecond);

        public bool OnNewPacket(RTPPacket packet, byte[] rawBuffer)
        {
            packetsReceived++;

            using (Stream fileStream = new FileStream(fn, FileMode.Append, FileAccess.Write, FileShare.None))
            {
                using (BinaryWriter bw = new BinaryWriter(fileStream))
                {
                    bw.Write(rawBuffer);
                }
            }

            //var pcm = decoder.Decode(packet);

            //if (pcm != null)
            //{
            //    wout.Enqueue(pcm);
            //}
            return false;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            IsRunning = false;
        }
    }
}

See this example at Stream coders site. It contains more stuff using the full MediaSuite.Net library (RTP.Net is a subset of it), but here's a quick filter (using garbage data...):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using StreamCoders.Network;
//using StreamCoders.Wave;
//using StreamCoders.Encoder;
//using StreamCoders.Decoder;
using System.Threading;
using StreamCoders;
using System.IO;

namespace SpeechSendReceive
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        RTPParticipant participant;
        RTPSender rtp_sender;
        RTPReceiver rtp_receiver;
        RTPSession session;
        //WaveOutput wout;
        //WaveInput win;

        //SpeechEncoder encoder;
        //SpeechDecoder decoder;

        Thread WaveInThreadProc;

        bool IsRunning = false;

        long packetsReceived;
        long packetsSent;

        System.Windows.Forms.Timer updateTimer = new System.Windows.Forms.Timer();

        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();

        }

        void updateTimer_Tick(object sender, EventArgs e)
        {
            sentLabel.Text = packetsSent.ToString();
            receivedLabel.Text = packetsReceived.ToString();


        }

        private string fn = string.Format(@"c:\temp\rtp{0}.snd", DateTime.Now.Millisecond);

        public bool OnNewPacket(RTPPacket packet, byte[] rawBuffer)
        {
            packetsReceived++;

            using (Stream fileStream = new FileStream(fn, FileMode.Append, FileAccess.Write, FileShare.None))
            {
                using (BinaryWriter bw = new BinaryWriter(fileStream))
                {
                    bw.Write(rawBuffer);
                }
            }

            //var pcm = decoder.Decode(packet);

            //if (pcm != null)
            //{
            //    wout.Enqueue(pcm);
            //}
            return false;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            IsRunning = false;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文