From ac1380bd4c6c23117163cdc53e5a2bad97ebd37e Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 10 Nov 2013 05:49:00 -0500 Subject: [PATCH] Fix force-close if the stream is aborted before RTP is connected. Fix address already in use exception on RTCP socket. --- src/com/limelight/nvstream/NvAudioStream.java | 4 +++- src/com/limelight/nvstream/NvVideoStream.java | 15 ++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/com/limelight/nvstream/NvAudioStream.java b/src/com/limelight/nvstream/NvAudioStream.java index de33c0f7..44f7d65c 100644 --- a/src/com/limelight/nvstream/NvAudioStream.java +++ b/src/com/limelight/nvstream/NvAudioStream.java @@ -53,7 +53,9 @@ public class NvAudioStream { } // Close the socket to interrupt the receive thread - rtp.close(); + if (rtp != null) { + rtp.close(); + } // Wait for threads to terminate for (Thread t : threads) { diff --git a/src/com/limelight/nvstream/NvVideoStream.java b/src/com/limelight/nvstream/NvVideoStream.java index e63810bc..2f238d05 100644 --- a/src/com/limelight/nvstream/NvVideoStream.java +++ b/src/com/limelight/nvstream/NvVideoStream.java @@ -36,7 +36,7 @@ public class NvVideoStream { private LinkedBlockingQueue packets = new LinkedBlockingQueue(); private RTPSession session; - private DatagramSocket rtp; + private DatagramSocket rtp, rtcp; private LinkedList threads = new LinkedList(); @@ -58,7 +58,12 @@ public class NvVideoStream { } // Close the socket to interrupt the receive thread - rtp.close(); + if (rtp != null) { + rtp.close(); + } + if (rtcp != null) { + rtcp.close(); + } // Wait for threads to terminate for (Thread t : threads) { @@ -103,16 +108,12 @@ public class NvVideoStream { public void setupRtpSession(String host) throws SocketException { - DatagramSocket rtcp; - rtp = new DatagramSocket(RTP_PORT); + rtcp = new DatagramSocket(RTCP_PORT); rtp.setReceiveBufferSize(2097152); System.out.println("RECV BUF: "+rtp.getReceiveBufferSize()); System.out.println("SEND BUF: "+rtp.getSendBufferSize()); - - - rtcp = new DatagramSocket(RTCP_PORT); session = new RTPSession(rtp, rtcp); session.addParticipant(new Participant(host, RTP_PORT, RTCP_PORT));