向数据包添加序列号(标头) - VoIP - Java
我正在致力于用 java 开发一个基本的 IP 语音系统。音频可以使用线程与发送者和接收者来回发送。然而,当使用不同的数据报包时,它们会出现一些数据包丢失。因此,我尝试为每个发送的数据包添加一个标头,以便更容易识别接收时丢失的确切数据包,因此我们可以开发一些补偿方法。
我已经开始了一些事情,但我不确定它是否是一个丰富的想法,总体想法是向数组添加 2 个字节,并将这 2 个额外字节分配给标头信息,即每个数据包的序列号。 ?
Vector<byte[]> voiceVector = new Vector<byte[]>();
int recordTime = 30;
System.out.println("Recording Audio...");
for (int i = 0; i < Math.ceil(recordTime / 0.032); i++)
byte[] block = recorder.getBlock();
DatagramPacket packet = new DatagramPacket(fPacket, fPacket.length, clientIP, PORT);
//Send it
sending_socket.send(packet);
voiceVector.add(block);
有人有什么想法吗 我知道需要创建一个包含语音向量和 2 个额外字节的新数组,但我不确定如何执行此操作,因为我有一段时间没有使用过 java...
干杯
Im working on developing a basic voice over IP system in java. Where audio can be sent back n forth with a sender and receiver using threads. However, their is some packet loss when using different datagram packets. Therefore i am trying add a header for each packet that is sent so that is easier to identify which exact packet is lost when receiving, so we can develop some compensation methods.
I've started something but I'm not sure if its the rich idea, the general idea was to add 2 bytes to the array, and allocated those 2 extra bytes to the header information, that being a sequential number for each packet...
Vector<byte[]> voiceVector = new Vector<byte[]>();
int recordTime = 30;
System.out.println("Recording Audio...");
for (int i = 0; i < Math.ceil(recordTime / 0.032); i++)
byte[] block = recorder.getBlock();
DatagramPacket packet = new DatagramPacket(fPacket, fPacket.length, clientIP, PORT);
//Send it
sending_socket.send(packet);
voiceVector.add(block);
Anyone got any ideas? I know ill beed to create a new array that contains the voice vector and the 2 extra bytes but am unsure how to do this as I havnt used java in some time...
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您首先使用 TCP 实现此操作,并且只有当此操作有效时才尝试使用 UDP。可靠的 UDP 是一个复杂的主题,检测丢弃的数据包只是一个开始。
即使您必须向许多接收器发送相同的音频,使用 TCP 仍然会更简单。 (如果有必要的话,也许还有更快的网卡)
I would suggest you implement this using TCP first and only when this is working attempt it using UDP. Reliable UDP is a complex subject and detecting dropped packets is just the start.
Even if you have to send the same audio to many receivers, it can still be simpler to use TCP. (And perhaps a faster network card if you have to)
不要使用 TCP - 由于其确认,它会增加延迟开销。
您可能应该做的是使用 RTP 的实现作为数据包的传输。它通过 UDP 运行,并添加时间戳和其他您会发现有用和需要的东西。
看看这个:http://en.wikipedia.org/wiki/Real-time_Transport_Protocol
不要自己实现它 - 找到一个已经在这样做的现成库。
Don't use TCP - it will add overheads on latency due to its acknowledgments.
What you should probably do is use an implementation of RTP as your transport of packets. It runs over UDP and adds timestamps and other things you will find useful and needed.
Check this out: http://en.wikipedia.org/wiki/Real-time_Transport_Protocol
Don't implement it on your own - find a ready-made library that is already doing that.