Change timing of video initialization to prevent an ICMP port unreachable message on start that could tear down a NAT hole

This commit is contained in:
Cameron Gutman 2014-11-20 19:04:58 -08:00
parent ff4570abac
commit 3a3ac83ab5

View File

@ -94,16 +94,19 @@ public class VideoStream {
threads.clear(); threads.clear();
} }
private void connectFirstFrame() throws IOException
{
firstFrameSocket = new Socket();
firstFrameSocket.setSoTimeout(FIRST_FRAME_TIMEOUT);
firstFrameSocket.connect(new InetSocketAddress(host, FIRST_FRAME_PORT), FIRST_FRAME_TIMEOUT);
}
private void readFirstFrame() throws IOException private void readFirstFrame() throws IOException
{ {
byte[] firstFrame = new byte[streamConfig.getMaxPacketSize()]; byte[] firstFrame = new byte[streamConfig.getMaxPacketSize()];
firstFrameSocket = new Socket();
firstFrameSocket.setSoTimeout(FIRST_FRAME_TIMEOUT);
try { try {
firstFrameSocket.connect(new InetSocketAddress(host, FIRST_FRAME_PORT), FIRST_FRAME_TIMEOUT);
InputStream firstFrameStream = firstFrameSocket.getInputStream(); InputStream firstFrameStream = firstFrameSocket.getInputStream();
int offset = 0; int offset = 0;
@ -170,19 +173,20 @@ public class VideoStream {
// Open RTP sockets and start session // Open RTP sockets and start session
setupRtpSession(); setupRtpSession();
// Start pinging before reading the first frame
// so Shield Proxy knows we're here and sends us
// the reference frame
startUdpPingThread();
if (decRend != null) { if (decRend != null) {
// Start the receive thread early to avoid missing // Start the receive thread early to avoid missing
// early packets that are part of the IDR frame // early packets that are part of the IDR frame
startReceiveThread(); startReceiveThread();
} }
// Now that we're ready, read the first frame to start the // Connect to the first frame port to open UDP 47998
// UDP video stream connectFirstFrame();
// Start pinging before reading the first frame
// so GFE knows where to send UDP data
startUdpPingThread();
// Read the first frame to start the flow of video
readFirstFrame(); readFirstFrame();
return true; return true;