Binary file libs/jlibrtp.jar has changed
--- a/src/com/beem/project/beem/jingle/PCMTransmitter.java Sun Sep 06 15:23:12 2009 +0200
+++ b/src/com/beem/project/beem/jingle/PCMTransmitter.java Sun Sep 06 17:08:10 2009 +0200
@@ -12,11 +12,11 @@
/**
* Constructor.
- * @param remoteIP destinataire ip.
- * @param port destinataire port.
+ * @param remoteIP receiver IP.
+ * @param remotePort receiver port.
*/
- public PCMTransmitter(final String remoteIP, final int port) {
- super(remoteIP, port);
+ public PCMTransmitter(final String remoteIP, final int remotePort) {
+ super(remoteIP, remotePort);
}
@Override
@@ -26,18 +26,16 @@
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT));
byte[] audioData = new byte[1024];
int byteReaded = 0;
- while (!mKillme) {
+ while (!isKillme()) {
byteReaded = audRec.read(audioData, byteReaded, 1024);
System.out.println("readed " + byteReaded);
- mRtpSession.sendData(audioData);
+ getRtpSession().sendData(audioData);
}
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
- this.mRtpSession.endSession();
-
+ this.getRtpSession().endSession();
}
-
}
--- a/src/com/beem/project/beem/jingle/RTPReceiver.java Sun Sep 06 15:23:12 2009 +0200
+++ b/src/com/beem/project/beem/jingle/RTPReceiver.java Sun Sep 06 17:08:10 2009 +0200
@@ -1,21 +1,27 @@
package com.beem.project.beem.jingle;
-import java.io.IOException;
import java.net.DatagramSocket;
-import java.net.ServerSocket;
import java.net.SocketException;
-import org.jlibrtp.jlibrtp.DataFrame;
import org.jlibrtp.jlibrtp.Participant;
import org.jlibrtp.jlibrtp.RTPAppIntf;
import org.jlibrtp.jlibrtp.RTPSession;
-public class RTPReceiver implements Runnable, RTPAppIntf {
+/**
+ * abstract RTP receiver class.
+ * @author nikita
+ *
+ */
+public abstract class RTPReceiver implements Runnable, RTPAppIntf {
+ private boolean mKillme;
private RTPSession mRtpSession;
- private boolean mKillme;
- public RTPReceiver(int rtpPort) {
+ /**
+ * constructor.
+ * @param rtpPort local or distant?.
+ */
+ public RTPReceiver(final int rtpPort) {
DatagramSocket rtpSocket = null;
try {
@@ -34,68 +40,42 @@
return 1;
}
- protected int getFreePort() {
- ServerSocket ss;
- int freePort = 0;
-
- for (int i = 0; i < 10; i++) {
- freePort = (int) (10000 + Math.round(Math.random() * 10000));
- try {
- ss = new ServerSocket(freePort);
- freePort = ss.getLocalPort();
- ss.close();
- return freePort;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- try {
- ss = new ServerSocket(0);
- freePort = ss.getLocalPort();
- ss.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return freePort;
- }
-
- @Override
- public void receiveData(DataFrame frame, Participant participant) {
- // byte[] data = frame.getConcatenatedData();
- }
-
@Override
public void run() {
start();
+ this.mRtpSession.endSession();
}
- private void start() {
- while (!mKillme) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ /**
+ * main reception loop.
+ */
+ protected abstract void start();
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- this.mRtpSession.endSession();
-
- }
-
+ /**
+ * Stop the reception.
+ */
public void stop() {
- this.mKillme = true;
+ this.setKillme(true);
}
@Override
public void userEvent(int arg0, Participant[] arg1) {
// TODO Auto-generated method stub
+ }
+ /**
+ * mKillme setter.
+ * @param killme the mKillme to set
+ */
+ public void setKillme(final boolean killme) {
+ this.mKillme = killme;
+ }
+
+ /**
+ * mKillme getter.
+ * @return the mKillme
+ */
+ public boolean isKillme() {
+ return mKillme;
}
}
--- a/src/com/beem/project/beem/jingle/RTPTransmitter.java Sun Sep 06 15:23:12 2009 +0200
+++ b/src/com/beem/project/beem/jingle/RTPTransmitter.java Sun Sep 06 17:08:10 2009 +0200
@@ -1,8 +1,6 @@
package com.beem.project.beem.jingle;
-import java.io.IOException;
import java.net.DatagramSocket;
-import java.net.ServerSocket;
import java.net.SocketException;
import org.jlibrtp.jlibrtp.DataFrame;
@@ -10,25 +8,42 @@
import org.jlibrtp.jlibrtp.RTPAppIntf;
import org.jlibrtp.jlibrtp.RTPSession;
+import com.beem.project.beem.utils.FreePort;
+
+/**
+ * abstract RTP transmitter class.
+ * @author nikita
+ */
public abstract class RTPTransmitter implements Runnable, RTPAppIntf {
- protected RTPSession mRtpSession = null;
- protected boolean mKillme = false;
+ /**
+ * RTPSession instance.
+ */
+ private RTPSession mRtpSession;
+ /**
+ * process status manipulation.
+ */
+ private boolean mKillme;
- public RTPTransmitter(String remoteIP, int port) {
+ /**
+ * constructor.
+ * @param remoteIP receiver IP.
+ * @param remotePort receiver port.
+ */
+ public RTPTransmitter(final String remoteIP, final int remotePort) {
DatagramSocket rtpSocket = null;
int rtpPort = 0;
-
+
try {
- rtpPort = getFreePort();
+ rtpPort = FreePort.getFreePort();
rtpSocket = new DatagramSocket(rtpPort);
} catch (SocketException e) {
e.printStackTrace();
return;
}
- mRtpSession = new RTPSession(rtpSocket, null);
- mRtpSession.naivePktReception(true);
- mRtpSession.RTPSessionRegister(this, null, null);
- mRtpSession.addParticipant(new Participant(remoteIP, rtpPort, 0));
+ setRtpSession(new RTPSession(rtpSocket, null));
+ getRtpSession().naivePktReception(true);
+ getRtpSession().RTPSessionRegister(this, null, null);
+ getRtpSession().addParticipant(new Participant(remoteIP, remotePort, 0));
}
@Override
@@ -36,31 +51,6 @@
return 1;
}
- protected int getFreePort() {
- ServerSocket ss;
- int freePort = 0;
-
- for (int i = 0; i < 10; i++) {
- freePort = (int) (10000 + Math.round(Math.random() * 10000));
- try {
- ss = new ServerSocket(freePort);
- freePort = ss.getLocalPort();
- ss.close();
- return freePort;
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- try {
- ss = new ServerSocket(0);
- freePort = ss.getLocalPort();
- ss.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return freePort;
- }
-
@Override
public void receiveData(DataFrame frame, Participant participant) {
// On envoie uniquement
@@ -76,8 +66,11 @@
*/
abstract void start();
+ /**
+ * Stop the transmission.
+ */
public void stop() {
- this.mKillme = true;
+ mKillme = true;
}
@Override
@@ -86,4 +79,36 @@
}
+ /**
+ * mKillme setter.
+ * @param killme the mKillme to set
+ */
+ public void setKillme(final boolean killme) {
+ this.mKillme = killme;
+ }
+
+ /**
+ * mKillme getter.
+ * @return the mKillme.
+ */
+ public boolean isKillme() {
+ return mKillme;
+ }
+
+ /**
+ * mRtpSession setter.
+ * @param rtpSession the mRtpSession to set.
+ */
+ public void setRtpSession(RTPSession rtpSession) {
+ this.mRtpSession = rtpSession;
+ }
+
+ /**
+ * mRtpSession getter.
+ * @return the mRtpSession
+ */
+ public RTPSession getRtpSession() {
+ return mRtpSession;
+ }
+
}
--- a/src/com/beem/project/beem/ui/Login.java Sun Sep 06 15:23:12 2009 +0200
+++ b/src/com/beem/project/beem/ui/Login.java Sun Sep 06 17:08:10 2009 +0200
@@ -31,7 +31,7 @@
*/
public class Login extends Activity {
- private static final String TAG = "LOG_AS";
+ //private static final String TAG = "LOG_AS";
private static final Intent SERVICE_INTENT = new Intent();
static {
SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/utils/FreePort.java Sun Sep 06 17:08:10 2009 +0200
@@ -0,0 +1,46 @@
+package com.beem.project.beem.utils;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+/**
+ * Utility class to get a free port.
+ * @author nikita
+ */
+public final class FreePort {
+
+ /**
+ * Private default constructor.
+ */
+ private FreePort() {
+ }
+
+ /**
+ * return a free port.
+ * @return free socket port.
+ */
+ public static int getFreePort() {
+ ServerSocket ss;
+ int freePort = 0;
+
+ for (int i = 0; i < 10; i++) {
+ freePort = (int) (10000 + Math.round(Math.random() * 10000));
+ try {
+ ss = new ServerSocket(freePort);
+ freePort = ss.getLocalPort();
+ ss.close();
+ return freePort;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ ss = new ServerSocket(0);
+ freePort = ss.getLocalPort();
+ ss.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return freePort;
+ }
+}