Reorder video stream initialization to prevent a ICMP port unreachable message that could teardown our NAT hole

This commit is contained in:
Cameron Gutman 2015-01-09 00:22:29 -05:00
parent 6db4a4fc4e
commit d855742379

View File

@ -111,11 +111,6 @@ int readFirstFrame(void) {
SOCK_RET err; SOCK_RET err;
int offset = 0; int offset = 0;
firstFrameSocket = connectTcpSocket(remoteHost, FIRST_FRAME_PORT);
if (firstFrameSocket == INVALID_SOCKET) {
return LastSocketError();
}
firstFrame = (char*) malloc(FIRST_FRAME_MAX); firstFrame = (char*) malloc(FIRST_FRAME_MAX);
if (firstFrame == NULL) { if (firstFrame == NULL) {
return -1; return -1;
@ -132,8 +127,12 @@ int readFirstFrame(void) {
} }
Limelog("Read %d bytes\n", offset); Limelog("Read %d bytes\n", offset);
processRtpPayload((PNV_VIDEO_PACKET) firstFrame, offset); // We can just ignore this data for now. It's the act of reading
// it that matters. If this changes, we'll need to move this call before
// starting the receive thread to avoid state corruption in the depacketizer.
free(firstFrame);
return 0; return 0;
} }
@ -170,23 +169,13 @@ int startVideoStream(void* rendererContext, int drFlags) {
callbacks.setup(configuration.width, callbacks.setup(configuration.width,
configuration.height, 60, rendererContext, drFlags); configuration.height, 60, rendererContext, drFlags);
rtpSocket = bindUdpSocket();
if (rtpSocket == INVALID_SOCKET) {
return LastSocketError();
}
err = PltCreateThread(UdpPingThreadProc, NULL, &udpPingThread);
if (err != 0) {
return err;
}
// This must be called before the decoder thread starts submitting // This must be called before the decoder thread starts submitting
// decode units // decode units
callbacks.start(); callbacks.start();
err = readFirstFrame(); rtpSocket = bindUdpSocket();
if (err != 0) { if (rtpSocket == INVALID_SOCKET) {
return err; return LastSocketError();
} }
err = PltCreateThread(ReceiveThreadProc, NULL, &receiveThread); err = PltCreateThread(ReceiveThreadProc, NULL, &receiveThread);
@ -198,6 +187,25 @@ int startVideoStream(void* rendererContext, int drFlags) {
if (err != 0) { if (err != 0) {
return err; return err;
} }
// Connect this socket to open port 47998 for our ping thread
firstFrameSocket = connectTcpSocket(remoteHost, FIRST_FRAME_PORT);
if (firstFrameSocket == INVALID_SOCKET) {
return LastSocketError();
}
// Start pinging before reading the first frame so GFE knows where
// to send UDP data
err = PltCreateThread(UdpPingThreadProc, NULL, &udpPingThread);
if (err != 0) {
return err;
}
// Read the first frame to start the flow of video
err = readFirstFrame();
if (err != 0) {
return err;
}
return 0; return 0;
} }