我底层传输使用JxtaMulticastSocket,以便能在JXTA平台使用JMF的RTP支持。
在RTPConnector的实现类中有
/**
* An inner class to implement an PushSourceStream based on UDP sockets.
*/
class SockInputStream extends Thread implements PushSourceStream {
JxtaMulticastSocket sock;
// ... other declariation
public SockInputStream(JxtaMulticastSocket sock) {
this.sock = sock;
}
@Override
public int read(byte buffer[], int offset, int length) {
byte[] buf = new byte[length];
DatagramPacket p = new DatagramPacket(buf, offset, length);
try {
sock.receive(p);
byte[] data = p.getData();
System.arraycopy(data, 0, buffer, offset, p.getLength());
} catch (IOException e) {
return -1;
}
synchronized (this) {
dataRead = true;
notify();
}
return p.getLength();
}
// ... other function ...
}
* An inner class to implement an PushSourceStream based on UDP sockets.
*/
class SockInputStream extends Thread implements PushSourceStream {
JxtaMulticastSocket sock;
// ... other declariation
public SockInputStream(JxtaMulticastSocket sock) {
this.sock = sock;
}
@Override
public int read(byte buffer[], int offset, int length) {
byte[] buf = new byte[length];
DatagramPacket p = new DatagramPacket(buf, offset, length);
try {
sock.receive(p);
byte[] data = p.getData();
System.arraycopy(data, 0, buffer, offset, p.getLength());
} catch (IOException e) {
return -1;
}
synchronized (this) {
dataRead = true;
notify();
}
return p.getLength();
}
// ... other function ...
}
上面是正常的代码,下面贴的是不正常的代码,是我参考其他资料写出的
/**
* An inner class to implement an PushSourceStream based on UDP sockets.
*/
class SockInputStream extends Thread implements PushSourceStream {
DatagramSocket sock;
// ... other declaration ...
public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
this.sock = sock;
// ...
}
public int read(byte buffer[], int offset, int length) {
DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
try {
sock.receive(p);
} catch (IOException e) {
return -1;
}
synchronized (this) {
dataRead = true;
notify();
}
return p.getLength();
}
// ... other function ...
}
* An inner class to implement an PushSourceStream based on UDP sockets.
*/
class SockInputStream extends Thread implements PushSourceStream {
DatagramSocket sock;
// ... other declaration ...
public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
this.sock = sock;
// ...
}
public int read(byte buffer[], int offset, int length) {
DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
try {
sock.receive(p);
} catch (IOException e) {
return -1;
}
synchronized (this) {
dataRead = true;
notify();
}
return p.getLength();
}
// ... other function ...
}
比较一下可以发现不同之处。
这个问题让我头疼了2天
——————————————————————————————————
傲轩游戏网
傲轩游戏网