Search in sources :

Example 1 with RtcpReceiver

use of com.sun.voip.RtcpReceiver in project Openfire by igniterealtime.

the class ConferenceMember method initializeChannel.

private void initializeChannel() throws IOException {
    datagramChannel = conferenceManager.getConferenceReceiver().getChannel(cp);
    if (datagramChannel != null) {
        synchronized (datagramChannel) {
            if (loneRtcpReceiver == null) {
                int rtcpPort = datagramChannel.socket().getLocalPort() + 1;
                Logger.println("Starting lone RtcpReceiver on port " + rtcpPort);
                loneRtcpReceiver = new RtcpReceiver(new DatagramSocket(rtcpPort), true);
            }
            rtcpReceiver = loneRtcpReceiver;
        }
        return;
    }
    /*
	 * We are trying to find a pair of sockets with consecutive port nums.
	 * The first socket must have an even port.
	 *
	 * If we find a socket that we don't like, we have to keep it open
	 * otherwise when we try to find another socket, we may get the same
	 * one as before.
	 *
	 * So we make a list of the bad sockets and close them all
	 * after we're done.
	 */
    ArrayList badChannels = new ArrayList();
    int nextRtpPort = firstRtpPort;
    try {
        while (true) {
            datagramChannel = DatagramChannel.open();
            if (Logger.logLevel >= Logger.LOG_DETAIL) {
                Logger.println("Call " + cp + " Opened datagram channel " + datagramChannel);
            }
            datagramChannel.configureBlocking(false);
            DatagramSocket socket = datagramChannel.socket();
            socket.setReceiveBufferSize(RtpSocket.MAX_RECEIVE_BUFFER);
            socket.setSoTimeout(0);
            InetSocketAddress bridgeAddress = Bridge.getLocalBridgeAddress();
            InetSocketAddress isa = new InetSocketAddress(bridgeAddress.getAddress(), nextRtpPort);
            if (nextRtpPort > 0) {
                nextRtpPort += 2;
                if (lastRtpPort != 0 && (nextRtpPort + 1) > lastRtpPort) {
                    Logger.println("No more RTP ports available, last is " + lastRtpPort);
                    closeBadChannels(badChannels);
                    throw new IOException("No more RTP ports available, last is " + lastRtpPort);
                }
            }
            try {
                socket.bind(isa);
                int localPort = socket.getLocalPort();
                if ((localPort & 1) != 0) {
                    /*
			 * Port is odd, can't use this datagramSocket
			 */
                    if (Logger.logLevel >= Logger.LOG_INFO) {
                        Logger.println("Call " + cp + " skipping DatagramSocket with odd port " + localPort);
                    }
                    badChannels.add(datagramChannel);
                    continue;
                }
                Logger.writeFile("Call " + cp + " RTCP Port " + (localPort + 1));
                rtcpReceiver = new RtcpReceiver(new DatagramSocket(localPort + 1), false);
                break;
            } catch (SocketException e) {
                /*
		     * Couldn't bind, can't use this DatagramSocket.
		     */
                if (Logger.logLevel >= Logger.LOG_INFO) {
                    Logger.println("Call " + cp + " skipping DatagramSocket " + e.getMessage());
                }
                badChannels.add(datagramChannel);
                continue;
            }
        }
    } catch (Exception e) {
        closeBadChannels(badChannels);
        throw new IOException("Call " + cp + " MemberReceiver exception! " + e.getMessage());
    }
    closeBadChannels(badChannels);
    if (Logger.logLevel >= Logger.LOG_INFO) {
        Logger.println("Call " + cp + " port " + datagramChannel.socket().getLocalPort());
    }
}
Also used : SocketException(java.net.SocketException) DatagramSocket(java.net.DatagramSocket) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) RtcpReceiver(com.sun.voip.RtcpReceiver) IOException(java.io.IOException) IOException(java.io.IOException) SocketException(java.net.SocketException) ParseException(java.text.ParseException)

Aggregations

RtcpReceiver (com.sun.voip.RtcpReceiver)1 IOException (java.io.IOException)1 DatagramSocket (java.net.DatagramSocket)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketException (java.net.SocketException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1