- 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
This commit is contained in:
Richard Alam 2009-12-14 18:52:30 +00:00
parent 97df7e6ab8
commit d50467ecd6
14 changed files with 42 additions and 60 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -18,7 +18,7 @@ public final class SipUserManager {
sessions = Collections.synchronizedMap(new HashMap<String, SipUser>());
}
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);
}

View File

@ -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");
}
}
}

View File

@ -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);

View File

@ -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<RtmpAudioData> packets = new LinkedBlockingQueue<RtmpAudioData>();
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 {

View File

@ -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<RtmpAudioData> packets = new LinkedBlockingQueue<RtmpAudioData>();
@ -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();

View File

@ -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) {

View File

@ -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
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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);