From d50467ecd6da533f51368fb60f077139eb63b6e9 Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Mon, 14 Dec 2009 18:52:30 +0000 Subject: [PATCH] - rename things - don't close socket too early when quitting as we get IOException when trying to receive RTP packets git-svn-id: http://bigbluebutton.googlecode.com/svn/trunk@3094 af16638f-c34d-0410-8cfa-b39d5352b314 --- .../java/org/red5/app/sip/CallStream.java | 28 ++++--------------- ...ava => ConnectionClientMethodInvoker.java} | 11 ++++++-- .../main/java/org/red5/app/sip/SipUser.java | 4 +-- .../java/org/red5/app/sip/SipUserManager.java | 2 +- .../sip/registration/SipRegisterAgent.java | 3 ++ ...pReceiver2.java => RtpStreamReceiver.java} | 6 ++-- .../{RtpSender2.java => RtpStreamSender.java} | 18 +++--------- .../org/red5/app/sip/stream/TalkStream.java | 4 +-- .../sip/trancoders/NellyToPcmTranscoder2.java | 4 +-- .../sip/trancoders/PcmToNellyTranscoder2.java | 4 +-- .../trancoders/SpeexToSpeexTranscoder.java | 4 +-- .../trancoders/TranscodedPcmAudioBuffer.java | 6 ++-- .../red5/app/sip/trancoders/Transcoder.java | 4 +-- .../sip/VoiceConferenceApplication.java | 4 +-- 14 files changed, 42 insertions(+), 60 deletions(-) rename bbb-voice/src/main/java/org/red5/app/sip/{RtmpConnection.java => ConnectionClientMethodInvoker.java} (82%) rename bbb-voice/src/main/java/org/red5/app/sip/stream/{RtpReceiver2.java => RtpStreamReceiver.java} (93%) rename bbb-voice/src/main/java/org/red5/app/sip/stream/{RtpSender2.java => RtpStreamSender.java} (86%) diff --git a/bbb-voice/src/main/java/org/red5/app/sip/CallStream.java b/bbb-voice/src/main/java/org/red5/app/sip/CallStream.java index 5906abb0c3..4cad373b77 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/CallStream.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/CallStream.java @@ -6,8 +6,8 @@ import java.net.SocketException; import org.red5.app.sip.codecs.Codec; import org.red5.app.sip.codecs.SpeexCodec; import org.red5.app.sip.stream.ListenStream; -import org.red5.app.sip.stream.RtpReceiver2; -import org.red5.app.sip.stream.RtpSender2; +import org.red5.app.sip.stream.RtpStreamReceiver; +import org.red5.app.sip.stream.RtpStreamSender; import org.red5.app.sip.stream.TalkStream; import org.red5.app.sip.trancoders.NellyToPcmTranscoder2; import org.red5.app.sip.trancoders.PcmToNellyTranscoder2; @@ -22,8 +22,8 @@ public class CallStream { private final static Logger log = Red5LoggerFactory.getLogger(CallStream.class, "sip"); private DatagramSocket socket = null; - private final RtpReceiver2 rtpReceiver; - private final RtpSender2 rtpSender; + private final RtpStreamReceiver rtpReceiver; + private final RtpStreamSender rtpSender; private final TalkStream talkStream; private final ListenStream listenStream; @@ -35,19 +35,6 @@ public class CallStream { throw new Exception("Exception while initializing CallStream"); } -/* - - NellyToPcmTranscoder2 pTranscoder = new NellyToPcmTranscoder2(sipCodec); - rtpSender = new RtpSender2(pTranscoder, socket, connInfo.getRemoteAddr(), connInfo.getRemotePort()); - printLog( "SIPAudioLauncher", "New audio receiver on " + connInfo.getLocalPort() + "." ); - rtpSender.start(); - talkStream = new TalkStream(pTranscoder, rtpSender); - listenStream = new ListenStream(scopeProvider.getScope()); - - PcmToNellyTranscoder2 transcoder = new PcmToNellyTranscoder2(sipCodec, listenStream); - rtpReceiver = new RtpReceiver2(transcoder, socket); -*/ - listenStream = new ListenStream(scopeProvider.getScope()); Transcoder rtmpToRtpTranscoder, rtpToRtmpTranscoder; @@ -60,11 +47,10 @@ public class CallStream { } - rtpReceiver = new RtpReceiver2(rtpToRtmpTranscoder, socket); - rtpSender = new RtpSender2(rtmpToRtpTranscoder, socket, connInfo.getRemoteAddr(), connInfo.getRemotePort()); + rtpReceiver = new RtpStreamReceiver(rtpToRtmpTranscoder, socket); + rtpSender = new RtpStreamSender(rtmpToRtpTranscoder, socket, connInfo.getRemoteAddr(), connInfo.getRemotePort()); talkStream = new TalkStream(rtmpToRtpTranscoder, rtpSender); rtpSender.start(); -// listenStream.start(); rtpReceiver.start(); } @@ -95,8 +81,6 @@ public class CallStream { printLog( "stopMedia", "Halting sip audio..." ); talkStream.stop(); listenStream.stop(); - - socket.close(); return true; } diff --git a/bbb-voice/src/main/java/org/red5/app/sip/RtmpConnection.java b/bbb-voice/src/main/java/org/red5/app/sip/ConnectionClientMethodInvoker.java similarity index 82% rename from bbb-voice/src/main/java/org/red5/app/sip/RtmpConnection.java rename to bbb-voice/src/main/java/org/red5/app/sip/ConnectionClientMethodInvoker.java index 86f7e67d91..fec3ab6632 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/RtmpConnection.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/ConnectionClientMethodInvoker.java @@ -6,13 +6,18 @@ import org.red5.server.api.IScope; import org.red5.server.api.service.IServiceCapableConnection; import org.slf4j.Logger; -public class RtmpConnection implements ScopeProvider, SipUserAgentListener, SipRegisterAgentListener { - private static Logger log = Red5LoggerFactory.getLogger( RtmpConnection.class, "sip" ); +/** + * Invokes methods on the client through the RTMPConnection. + * @author Richard Alam + * + */ +public class ConnectionClientMethodInvoker implements ScopeProvider, SipUserAgentListener, SipRegisterAgentListener { + private static Logger log = Red5LoggerFactory.getLogger( ConnectionClientMethodInvoker.class, "sip" ); private final IServiceCapableConnection connection; private final IScope scope; - public RtmpConnection(IServiceCapableConnection connection, IScope scope) { + public ConnectionClientMethodInvoker(IServiceCapableConnection connection, IScope scope) { this.connection = connection; this.scope = scope; } diff --git a/bbb-voice/src/main/java/org/red5/app/sip/SipUser.java b/bbb-voice/src/main/java/org/red5/app/sip/SipUser.java index e505bd4ae6..e2d04e6385 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/SipUser.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/SipUser.java @@ -11,7 +11,7 @@ import org.red5.app.sip.registration.SipRegisterAgent; public class SipUser { private static Logger log = Red5LoggerFactory.getLogger(SipUser.class, "sip"); - private RtmpConnection rtmpConnection; + private ConnectionClientMethodInvoker rtmpConnection; private String userid; private SipUserAgentProfile userProfile; private SipProvider sipProvider; @@ -20,7 +20,7 @@ public class SipUser { private SipRegisterAgent registerAgent; private String proxy; - public SipUser(String userid, RtmpConnection connection, int sipPort, int rtpPort) { + public SipUser(String userid, ConnectionClientMethodInvoker connection, int sipPort, int rtpPort) { log.debug( "SIPUser Constructor: sip port " + sipPort + " rtp port:" + rtpPort ); this.userid = userid; this.rtmpConnection = connection; diff --git a/bbb-voice/src/main/java/org/red5/app/sip/SipUserManager.java b/bbb-voice/src/main/java/org/red5/app/sip/SipUserManager.java index 0630b0f816..2f65eca951 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/SipUserManager.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/SipUserManager.java @@ -18,7 +18,7 @@ public final class SipUserManager { sessions = Collections.synchronizedMap(new HashMap()); } - public void createSipUser(String userid, RtmpConnection connection, int sipPort, int rtpPort) { + public void createSipUser(String userid, ConnectionClientMethodInvoker connection, int sipPort, int rtpPort) { SipUser sipUser = new SipUser(userid, connection, sipPort, rtpPort); sessions.put(userid, sipUser); } diff --git a/bbb-voice/src/main/java/org/red5/app/sip/registration/SipRegisterAgent.java b/bbb-voice/src/main/java/org/red5/app/sip/registration/SipRegisterAgent.java index e3c8a212c0..c4919dd35f 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/registration/SipRegisterAgent.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/registration/SipRegisterAgent.java @@ -341,14 +341,17 @@ public class SipRegisterAgent implements TransactionClientListener { regInprocess = false; if (request == Request.REGISTERING) { + printLog("Notifying listeners of REGISTRATION success"); agentStatus = Status.REGISTERED; notifyListenersOfRegistrationSuccess("REGISTERED"); } else if (request == Request.UNREGISTERING){ + printLog("Notifying listeners of UNREGISTRATION success"); agentStatus = Status.UNREGISTERED; notifyListenersOfRegistrationSuccess("UNREGISTERED"); } else if (request == Request.RENEWING) { agentStatus = Status.REGISTERED; // Don't notify the listeners. + printLog("NOT Notifying listeners of RENEW success"); } } } diff --git a/bbb-voice/src/main/java/org/red5/app/sip/stream/RtpReceiver2.java b/bbb-voice/src/main/java/org/red5/app/sip/stream/RtpStreamReceiver.java similarity index 93% rename from bbb-voice/src/main/java/org/red5/app/sip/stream/RtpReceiver2.java rename to bbb-voice/src/main/java/org/red5/app/sip/stream/RtpStreamReceiver.java index 2862a8401a..b9e1de936b 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/stream/RtpReceiver2.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/stream/RtpStreamReceiver.java @@ -13,8 +13,8 @@ import org.slf4j.Logger; import org.red5.app.sip.trancoders.Transcoder; import org.red5.logging.Red5LoggerFactory; -public class RtpReceiver2 { - protected static Logger log = Red5LoggerFactory.getLogger(RtpReceiver2.class, "sip"); +public class RtpStreamReceiver { + protected static Logger log = Red5LoggerFactory.getLogger(RtpStreamReceiver.class, "sip"); // Maximum blocking time, spent waiting for reading new bytes [milliseconds] private static final int SO_TIMEOUT = 200; @@ -30,7 +30,7 @@ public class RtpReceiver2 { private Transcoder transcoder; - public RtpReceiver2(Transcoder transcoder, DatagramSocket socket) { + public RtpStreamReceiver(Transcoder transcoder, DatagramSocket socket) { this.transcoder = transcoder; if (socket != null) { rtpSocket = new RtpSocket(socket); diff --git a/bbb-voice/src/main/java/org/red5/app/sip/stream/RtpSender2.java b/bbb-voice/src/main/java/org/red5/app/sip/stream/RtpStreamSender.java similarity index 86% rename from bbb-voice/src/main/java/org/red5/app/sip/stream/RtpSender2.java rename to bbb-voice/src/main/java/org/red5/app/sip/stream/RtpStreamSender.java index c44ccd94e6..c3adc06f79 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/stream/RtpSender2.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/stream/RtpStreamSender.java @@ -6,23 +6,13 @@ import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingQueue; import org.slf4j.Logger; -import org.red5.app.sip.RtmpAudioData; import org.red5.app.sip.trancoders.Transcoder; import org.red5.logging.Red5LoggerFactory; -public class RtpSender2 { - private static Logger log = Red5LoggerFactory.getLogger( RtpSender2.class, "sip" ); - - private BlockingQueue packets = new LinkedBlockingQueue(); - private final Executor exec = Executors.newSingleThreadExecutor(); - private Runnable audioProcessor; - private volatile boolean processAudio = false; +public class RtpStreamSender { + private static Logger log = Red5LoggerFactory.getLogger( RtpStreamSender.class, "sip" ); private static final int RTP_HEADER_SIZE = 12; private RtpSocket rtpSocket = null; @@ -36,7 +26,7 @@ public class RtpSender2 { private long timestamp = 0; private Transcoder transcoder; - public RtpSender2(Transcoder transcoder, DatagramSocket srcSocket, String destAddr, int destPort) throws UnknownHostException { + public RtpStreamSender(Transcoder transcoder, DatagramSocket srcSocket, String destAddr, int destPort) throws UnknownHostException { this.transcoder = transcoder; if (srcSocket == null) { try { @@ -118,7 +108,7 @@ public class RtpSender2 { blankpacket.setSequenceNumber(sequenceNum++); blankpacket.setTimestamp(transcoder.getOutgoingEncodedFrameSize()); doRtpDelay(); - rtpSocketSend( blankpacket ); + rtpSocketSend(blankpacket); } } catch (Exception e) { diff --git a/bbb-voice/src/main/java/org/red5/app/sip/stream/TalkStream.java b/bbb-voice/src/main/java/org/red5/app/sip/stream/TalkStream.java index c32f128bec..0c0049dd85 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/stream/TalkStream.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/stream/TalkStream.java @@ -21,7 +21,7 @@ public class TalkStream { private final static Logger log = Red5LoggerFactory.getLogger(TalkStream.class, "sip"); private final Transcoder transcoder; - private final RtpSender2 rtpSender; + private final RtpStreamSender rtpSender; private final IStreamListener mInputListener; private BlockingQueue packets = new LinkedBlockingQueue(); @@ -31,7 +31,7 @@ public class TalkStream { private final String talkStreamName; - public TalkStream(final Transcoder transcoder, final RtpSender2 rtpSender) { + public TalkStream(final Transcoder transcoder, final RtpStreamSender rtpSender) { this.transcoder = transcoder; this.rtpSender = rtpSender; talkStreamName = "microphone_" + System.currentTimeMillis(); diff --git a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/NellyToPcmTranscoder2.java b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/NellyToPcmTranscoder2.java index 86eafbe714..5aadcc0e29 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/NellyToPcmTranscoder2.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/NellyToPcmTranscoder2.java @@ -6,7 +6,7 @@ import org.red5.app.sip.codecs.Codec; import org.red5.app.sip.codecs.asao.ByteStream; import org.red5.app.sip.codecs.asao.Decoder; import org.red5.app.sip.codecs.asao.DecoderMap; -import org.red5.app.sip.stream.RtpSender2; +import org.red5.app.sip.stream.RtpStreamSender; public class NellyToPcmTranscoder2 implements Transcoder { protected static Logger log = Red5LoggerFactory.getLogger( NellyToPcmTranscoder2.class, "sip" ); @@ -115,7 +115,7 @@ public class NellyToPcmTranscoder2 implements Transcoder { return finalCopySize; } - public void transcode(byte[] asaoBuffer, int offset, int num, byte[] transcodedData, int dataOffset, RtpSender2 rtpSender) { + public void transcode(byte[] asaoBuffer, int offset, int num, byte[] transcodedData, int dataOffset, RtpStreamSender rtpSender) { asao_buffer_processed = false; if (!hasInitilializedBuffers) { diff --git a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/PcmToNellyTranscoder2.java b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/PcmToNellyTranscoder2.java index a3ab81a7ac..6dbbc7dc5f 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/PcmToNellyTranscoder2.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/PcmToNellyTranscoder2.java @@ -8,7 +8,7 @@ import org.red5.server.net.rtmp.event.AudioData; import org.red5.app.sip.codecs.Codec; import org.red5.app.sip.codecs.asao.ByteStream; import org.red5.app.sip.codecs.asao.CodecImpl; -import org.red5.app.sip.stream.RtpSender2; +import org.red5.app.sip.stream.RtpStreamSender; public class PcmToNellyTranscoder2 implements Transcoder { protected static Logger log = Red5LoggerFactory.getLogger(PcmToNellyTranscoder2.class, "sip"); @@ -110,7 +110,7 @@ public class PcmToNellyTranscoder2 implements Transcoder { } public void transcode(byte[] asaoBuffer, int offset, int num, - byte[] transcodedData, int dataOffset, RtpSender2 rtpSender) { + byte[] transcodedData, int dataOffset, RtpStreamSender rtpSender) { // TODO Auto-generated method stub } diff --git a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/SpeexToSpeexTranscoder.java b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/SpeexToSpeexTranscoder.java index c53b006492..97ad09952b 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/SpeexToSpeexTranscoder.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/SpeexToSpeexTranscoder.java @@ -2,7 +2,7 @@ package org.red5.app.sip.trancoders; import org.apache.mina.core.buffer.IoBuffer; import org.red5.app.sip.codecs.Codec; -import org.red5.app.sip.stream.RtpSender2; +import org.red5.app.sip.stream.RtpStreamSender; import org.red5.server.net.rtmp.event.AudioData; public class SpeexToSpeexTranscoder implements Transcoder { @@ -23,7 +23,7 @@ public class SpeexToSpeexTranscoder implements Transcoder { } public void transcode(byte[] asaoBuffer, int offset, int num, - byte[] transcodedData, int dataOffset, RtpSender2 rtpSender) { + byte[] transcodedData, int dataOffset, RtpStreamSender rtpSender) { System.arraycopy(asaoBuffer, offset, transcodedData, dataOffset, num); rtpSender.sendTranscodedData(); } diff --git a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/TranscodedPcmAudioBuffer.java b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/TranscodedPcmAudioBuffer.java index 8d6ca63696..591d32c82b 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/TranscodedPcmAudioBuffer.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/TranscodedPcmAudioBuffer.java @@ -1,14 +1,14 @@ package org.red5.app.sip.trancoders; -import org.red5.app.sip.stream.RtpSender2; +import org.red5.app.sip.stream.RtpStreamSender; public class TranscodedPcmAudioBuffer { private byte[] buffer; private int offset; - private RtpSender2 sender; + private RtpStreamSender sender; - TranscodedPcmAudioBuffer(byte[] data, int offset, RtpSender2 sender) { + TranscodedPcmAudioBuffer(byte[] data, int offset, RtpStreamSender sender) { buffer = data; this.offset = offset; } diff --git a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/Transcoder.java b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/Transcoder.java index 59b852f991..17328cc9ec 100644 --- a/bbb-voice/src/main/java/org/red5/app/sip/trancoders/Transcoder.java +++ b/bbb-voice/src/main/java/org/red5/app/sip/trancoders/Transcoder.java @@ -1,9 +1,9 @@ package org.red5.app.sip.trancoders; -import org.red5.app.sip.stream.RtpSender2; +import org.red5.app.sip.stream.RtpStreamSender; public interface Transcoder { - void transcode(byte[] asaoBuffer, int offset, int num, byte[] transcodedData, int dataOffset, RtpSender2 rtpSender); + void transcode(byte[] asaoBuffer, int offset, int num, byte[] transcodedData, int dataOffset, RtpStreamSender rtpSender); void transcode(byte[] codedBuffer); int getOutgoingEncodedFrameSize(); diff --git a/bbb-voice/src/main/java/org/red5/server/webapp/sip/VoiceConferenceApplication.java b/bbb-voice/src/main/java/org/red5/server/webapp/sip/VoiceConferenceApplication.java index 79db8fe414..6e811e002e 100644 --- a/bbb-voice/src/main/java/org/red5/server/webapp/sip/VoiceConferenceApplication.java +++ b/bbb-voice/src/main/java/org/red5/server/webapp/sip/VoiceConferenceApplication.java @@ -3,7 +3,7 @@ package org.red5.server.webapp.sip; import java.text.MessageFormat; import java.util.List; import org.slf4j.Logger; -import org.red5.app.sip.RtmpConnection; +import org.red5.app.sip.ConnectionClientMethodInvoker; import org.red5.app.sip.SipUserManager; import org.red5.logging.Red5LoggerFactory; import org.red5.server.adapter.MultiThreadedApplicationAdapter; @@ -104,7 +104,7 @@ public class VoiceConferenceApplication extends MultiThreadedApplicationAdapter IConnection conn = Red5.getConnectionLocal(); IServiceCapableConnection service = (IServiceCapableConnection) conn; - RtmpConnection rtmpConnection = new RtmpConnection(service, conn.getScope()); + ConnectionClientMethodInvoker rtmpConnection = new ConnectionClientMethodInvoker(service, conn.getScope()); String userid = getSipUserId(); sipManager.createSipUser(userid, rtmpConnection, sipPort, rtpPort);