diff --git a/src/org/jitsi/impl/neomedia/MediaStreamImpl.java b/src/org/jitsi/impl/neomedia/MediaStreamImpl.java index 92ff5dc6600b1953db0a064d7e5d8c1d307e840c..ddb4dbff219b553041a6f969a0d16b7609ed8c7c 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); } } }