[英]RTP Server in Java with Xuggler
I am trying to write a RTP Server in Java and I am using Xuggler to decode mp3 files. 我正在尝试用Java编写RTP服务器,并且正在使用Xuggler解码mp3文件。
The decoding part looks like this: 解码部分如下所示:
while(container.readNextPacket(packet) >= 0) {
if(packet.getStreamIndex() == streamID) {
IAudioSamples samples = IAudioSamples.make(1,decoder.getChannels());
decoder.decodeAudio(samples, packet, 0);
IAudioSamples resampled_samples = IAudioSamples.make(1,2);
resampler.resample(resampled_samples, samples, samples.getNumSamples());
byte[] target = new byte[(int) (resampled_samples.getNumSamples() * resampled_samples.getSampleSize())];
resampled_samples.get(0, target, 0, target.length);
timestamp+=target.length;
s.sendData(target);
}
}
My problem is that the buffer on the client side is overflowing because the Server is sending to many packages. 我的问题是,由于服务器发送到许多程序包,因此客户端的缓冲区溢出。
So my question is: Is there any possibility to wait for the "next frame" other than "Thread.sleep()" because the waiting needs to be very precise. 所以我的问题是:除了“ Thread.sleep()”之外,是否有可能等待“下一帧”,因为等待需要非常精确。
Instead of working inside a while
loop you can do this with a javax.Swing.Timer
object that gets called repeatedly with a delay that you can specify. 可以在
javax.Swing.Timer
对象中执行此操作, while
不必在while
循环中进行操作,该对象会以指定的延迟重复调用。 You have to create a Timer(int delayInMilliseconds, ActionListener l)
and implement an ActionListener
object that will do the real work. 您必须创建一个
Timer(int delayInMilliseconds, ActionListener l)
并实现一个将执行实际工作的ActionListener
对象。 It will not be microsecond-accurate, but at least you can specify the right delay for your needs. 它不会精确到微秒,但是至少您可以根据需要指定正确的延迟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.