Does not use instanceof on each and every RTP packet.
This commit is contained in:
parent
7b8d6b15a0
commit
872bf7e8ef
@ -18,6 +18,14 @@ import java.io.*;
|
|||||||
public class TCPOutputStream
|
public class TCPOutputStream
|
||||||
extends OutputStream
|
extends OutputStream
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* The indicator which determines whether this <tt>TCPOutputStream</tt> is
|
||||||
|
* to frame RTP and RTCP packets in accord with RFC 4571 "Framing
|
||||||
|
* Real-time Transport Protocol (RTP) and RTP Control Protocol (RTCP)
|
||||||
|
* Packets over Connection-Oriented Transport".
|
||||||
|
*/
|
||||||
|
private final boolean frame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Original <tt>OutputStream</tt> that this class wraps.
|
* Original <tt>OutputStream</tt> that this class wraps.
|
||||||
*/
|
*/
|
||||||
@ -31,6 +39,12 @@ public class TCPOutputStream
|
|||||||
public TCPOutputStream(OutputStream outputStream)
|
public TCPOutputStream(OutputStream outputStream)
|
||||||
{
|
{
|
||||||
this.outputStream = outputStream;
|
this.outputStream = outputStream;
|
||||||
|
|
||||||
|
// GoogleRelayedCandidateSocket will encapsulate data in TURN message so
|
||||||
|
// do not frame.
|
||||||
|
frame
|
||||||
|
= !(outputStream
|
||||||
|
instanceof GoogleRelayedCandidateSocket.TCPOutputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,16 +67,6 @@ public class TCPOutputStream
|
|||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void write(byte[] b)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
write(b, 0, b.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@ -70,22 +74,19 @@ public class TCPOutputStream
|
|||||||
public void write(byte[] b, int off, int len)
|
public void write(byte[] b, int off, int len)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// GoogleRelayedCandidateSocket will encapsulate data in TURN message so
|
if (frame)
|
||||||
// do not add framing here
|
|
||||||
if (outputStream
|
|
||||||
instanceof GoogleRelayedCandidateSocket.TCPOutputStream)
|
|
||||||
{
|
{
|
||||||
outputStream.write(b, off, len);
|
int newLen = len + 2;
|
||||||
|
byte newB[] = new byte[newLen];
|
||||||
|
|
||||||
|
newB[0] = (byte) ((len >> 8) & 0xFF);
|
||||||
|
newB[1] = (byte) (len & 0xFF);
|
||||||
|
System.arraycopy(b, off, newB, 2, len);
|
||||||
|
outputStream.write(newB, 0, newLen);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int dataLength = len + 2;
|
outputStream.write(b, off, len);
|
||||||
byte data[] = new byte[dataLength];
|
|
||||||
|
|
||||||
data[0] = (byte) ((len >> 8) & 0xFF);
|
|
||||||
data[1] = (byte) (len & 0xFF);
|
|
||||||
System.arraycopy(b, off, data, 2, len);
|
|
||||||
outputStream.write(data, 0, dataLength);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user