From b31af7f580816c770e725acb825a9165734a44db Mon Sep 17 00:00:00 2001 From: Boris Grozev <boris@jitsi.org> Date: Mon, 10 Mar 2014 21:46:02 +0100 Subject: [PATCH] Stops all receive streams (same reasoning as in the previous commit for starting them). --- .../jitsi/impl/neomedia/MediaStreamImpl.java | 65 +++++++++---------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/src/org/jitsi/impl/neomedia/MediaStreamImpl.java b/src/org/jitsi/impl/neomedia/MediaStreamImpl.java index 92ff5dc6..ddb4dbff 100644 --- a/src/org/jitsi/impl/neomedia/MediaStreamImpl.java +++ b/src/org/jitsi/impl/neomedia/MediaStreamImpl.java @@ -2237,11 +2237,11 @@ else if (MediaDirection.RECVONLY.equals(startedDirection)) @SuppressWarnings("unchecked") private void stopReceiveStreams() { - List<ReceiveStream> receiveStreams; + Set<ReceiveStream> streamsToStop = new HashSet<ReceiveStream>(); try { - receiveStreams = rtpManager.getReceiveStreams(); + streamsToStop.addAll(rtpManager.getReceiveStreams()); } catch (Exception ex) { @@ -2252,46 +2252,41 @@ private void stopReceiveStreams() */ if (logger.isTraceEnabled()) logger.trace("Failed to retrieve receive streams", ex); - receiveStreams = null; } - if (receiveStreams != null) - { - /* - * It turns out that the receiveStreams list of rtpManager can be - * empty. As a workaround, use the receiveStreams of this instance. - */ - if (receiveStreams.isEmpty()) - receiveStreams = getReceiveStreams(); + /* + * It has been observed that sometimes there are valid ReceiveStream-s + * in this.receiveStreams which are not returned by the RTP manager. + */ + streamsToStop.addAll(getReceiveStreams()); - for (ReceiveStream receiveStream : receiveStreams) + for (ReceiveStream receiveStream : streamsToStop) + { + try { - try + if (logger.isTraceEnabled()) { - if (logger.isTraceEnabled()) - { - logger.trace( - "Stopping receive stream with hashcode " - + receiveStream.hashCode()); - } + logger.trace( + "Stopping receive stream with hashcode " + + receiveStream.hashCode()); + } - DataSource receiveStreamDataSource - = receiveStream.getDataSource(); + DataSource receiveStreamDataSource + = receiveStream.getDataSource(); - /* - * For an unknown reason, the stream DataSource can be null - * at the end of the Call after re-INVITEs have been - * handled. - */ - if (receiveStreamDataSource != null) - receiveStreamDataSource.stop(); - } - catch (IOException ioex) - { - logger.warn( - "Failed to stop receive stream " + receiveStream, - ioex); - } + /* + * For an unknown reason, the stream DataSource can be null + * at the end of the Call after re-INVITEs have been + * handled. + */ + if (receiveStreamDataSource != null) + receiveStreamDataSource.stop(); + } + catch (IOException ioex) + { + logger.warn( + "Failed to stop receive stream " + receiveStream, + ioex); } } } -- GitLab