--- a/src/com/beem/project/beem/jingle/JingleService.java Tue Aug 25 03:42:58 2009 +0200
+++ b/src/com/beem/project/beem/jingle/JingleService.java Thu Aug 27 01:21:14 2009 +0200
@@ -36,7 +36,7 @@
BasicTransportManager bt = new BasicTransportManager();
mMediaManagers = new ArrayList<JingleMediaManager>();
- mMediaManagers.add(new RTPMediaManager(bt));
+ mMediaManagers.add(new MicrophoneRTPManager(bt));
}
/**
@@ -86,33 +86,34 @@
@Override
public void sessionClosed(String reason, JingleSession jingleSession) {
- System.out.println("Session " + jingleSession.getResponder() + "closedd because " + reason);
+ //System.out.println("Session " + jingleSession.getResponder() + "closedd because " + reason);
}
@Override
public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
// TODO Auto-generated method stub
- System.out.println("Session " + jingleSession.getResponder() + " closed");
+ // System.out.println("Session " + jingleSession.getResponder() + " closed");
}
@Override
public void sessionDeclined(String reason, JingleSession jingleSession) {
// TODO Auto-generated method stub
- System.out.println("Session " + jingleSession.getResponder() + "declined because " + reason);
+ //System.out.println("Session " + jingleSession.getResponder() + "declined because " + reason);
}
@Override
public void sessionEstablished(PayloadType pt, TransportCandidate remoteCandidate,
TransportCandidate localCandidate, JingleSession jingleSession) {
- System.out.println("Session established");
- System.out.println("Je recois sur " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort());
- RTPReceiver rtpReceiver = new MicroRTPReceiver(remoteCandidate.getPort());
+ //System.out.println("Session established");
+ //System.out.println("Je recois sur " + remoteCandidate.getIp() + ":" + remoteCandidate.getPort());
+ // TODO choose the right RTPReceiver depending on the payload type
+ //RTPReceiver rtpReceiver = new MicroRTPReceiver(remoteCandidate.getPort());
}
@Override
public void sessionMediaReceived(JingleSession jingleSession, String participant) {
- System.out.println("Session Media received from " + participant);
+ //System.out.println("Session Media received from " + participant);
}
@Override
@@ -136,30 +137,30 @@
@Override
public void sessionClosed(final String reason, final JingleSession jingleSession) {
- System.out.println("Session " + jingleSession.getResponder() + "closed because " + reason);
+ // System.out.println("Session " + jingleSession.getResponder() + "closed because " + reason);
}
@Override
public void sessionClosedOnError(final XMPPException e, final JingleSession jingleSession) {
- System.out.println("Session " + jingleSession.getResponder() + " closed on error");
+ // System.out.println("Session " + jingleSession.getResponder() + " closed on error");
}
@Override
public void sessionDeclined(final String reason, final JingleSession jingleSession) {
- System.out.println("Session " + jingleSession.getResponder() + "declined because " + reason);
+ // System.out.println("Session " + jingleSession.getResponder() + "declined because " + reason);
}
@Override
public void sessionEstablished(final PayloadType pt, final TransportCandidate remoteCandidate,
final TransportCandidate localCandidate, final JingleSession jingleSession) {
- System.out.println("Session established");
+ // System.out.println("Session established");
// String name = localCandidate.getName();
String ip = localCandidate.getIp();
int port = localCandidate.getPort();
- System.out.println("Session established waiting connection on " + ip + ":" + port);
+ // System.out.println("Session established waiting connection on " + ip + ":" + port);
- RTPTransmitter transm = new MicroRTPTransmitter(ip, port);
+ RTPTransmitter transm = new PCMTransmitter(ip, port);
transm.run();
try {
@@ -169,7 +170,7 @@
e.printStackTrace();
}
transm.stop();
- System.out.println("End of transfer");
+ // System.out.println("End of transfer");
}
--- a/src/com/beem/project/beem/jingle/MicroRTPReceiver.java Tue Aug 25 03:42:58 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/**
- *
- */
-package com.beem.project.beem.jingle;
-
-import org.jlibrtp.jlibrtp.DataFrame;
-import org.jlibrtp.jlibrtp.Participant;
-
-import android.util.Log;
-
-/**
- *
- * @author nikita
- */
-public class MicroRTPReceiver extends RTPReceiver {
-
- private static final String TAG = "MicroRTPReceiver";
-
- public MicroRTPReceiver(int rtpPort) {
- super(rtpPort);
- }
-
- /*
- * (non-Javadoc)
- * @see org.jlibrtp.jlibrtp.RTPAppIntf#receiveData(org.jlibrtp.jlibrtp.DataFrame, org.jlibrtp.jlibrtp.Participant)
- */
- @Override
- public void receiveData(DataFrame frame, Participant participant) {
- Log.d(TAG, "data received " + frame.toString());
-
- }
-
-}
--- a/src/com/beem/project/beem/jingle/MicroRTPTransmitter.java Tue Aug 25 03:42:58 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/**
- *
- */
-package com.beem.project.beem.jingle;
-
-import android.media.AudioFormat;
-import android.media.AudioRecord;
-import android.media.MediaRecorder;
-
-/**
- * @author nikita
- */
-public class MicroRTPTransmitter extends RTPTransmitter {
-
- public MicroRTPTransmitter(String remoteIP, int port) {
- super(remoteIP, port);
- }
-
- @Override
- void start() {
- AudioRecord audRec = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, 8000,
- AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT, AudioRecord.getMinBufferSize(8000,
- AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT));
- byte[] audioData = new byte[1024];
- int byteReaded = 0;
- while (!mKillme) {
- byteReaded = audRec.read(audioData, byteReaded, 1024);
- System.out.println("readed " + byteReaded);
- mRtpSession.sendData(audioData);
- }
-
- try {
- Thread.sleep(200);
- } catch (Exception e) {
- }
- this.mRtpSession.endSession();
-
- }
-
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/MicrophoneRTPManager.java Thu Aug 27 01:21:14 2009 +0200
@@ -0,0 +1,62 @@
+package com.beem.project.beem.jingle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jivesoftware.smackx.jingle.JingleSession;
+import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
+import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
+import org.jivesoftware.smackx.jingle.media.PayloadType;
+import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
+import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+
+/**
+ * RTPMediaManager, gere les payloads et renvoie une session RTP.
+ * @author nikita
+ */
+public class MicrophoneRTPManager extends JingleMediaManager {
+ /**
+ * RTP media name.
+ */
+ public static final String MEDIA_NAME = "Microphone";
+
+ private List<PayloadType> mPayloads;
+
+ /**
+ * Manage Microphone data transmission trough RTP.
+ * @param transportManager current jingle transport manager(basic,upnp,ice...).
+ */
+ public MicrophoneRTPManager(final JingleTransportManager transportManager) {
+ super(transportManager);
+ // TODO Auto-generated constructor stub
+ setupPayloads();
+ }
+
+ @Override
+ public JingleMediaSession createMediaSession(PayloadType payloadType, TransportCandidate remote,
+ TransportCandidate local, JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ return new MicrophoneRTPSession(payloadType, remote, local, null, jingleSession);
+ }
+
+ @Override
+ public String getName() {
+ return MEDIA_NAME;
+ }
+
+ @Override
+ public List<PayloadType> getPayloads() {
+ // TODO Auto-generated method stub
+ return mPayloads;
+ }
+
+ /**
+ * Supported payload list.
+ */
+ private void setupPayloads() {
+ mPayloads = new ArrayList<PayloadType>();
+ mPayloads.add(new PayloadType.Audio(51, "BIDON1"));
+ mPayloads.add(new PayloadType.Audio(52, "BIDON2"));
+ mPayloads.add(new PayloadType.Audio(53, "BIDON3"));
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/MicrophoneRTPSession.java Thu Aug 27 01:21:14 2009 +0200
@@ -0,0 +1,67 @@
+package com.beem.project.beem.jingle;
+
+import org.jivesoftware.smackx.jingle.JingleSession;
+import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
+import org.jivesoftware.smackx.jingle.media.PayloadType;
+import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+
+/**
+ * Manage microphone RTP session.
+ * @author nikita
+ */
+public class MicrophoneRTPSession extends JingleMediaSession {
+
+ private RTPTransmitter mTransmitter;
+ private RTPReceiver mReceiver;
+
+ /**
+ * constructor.
+ * @param payloadType the payload typ used
+ * @param remote the remote transport info
+ * @param local the local tranport info
+ * @param mediaLocator don't know
+ * @param jingleSession the current jingle session
+ */
+ public MicrophoneRTPSession(final PayloadType payloadType, final TransportCandidate remote,
+ final TransportCandidate local, final String mediaLocator, final JingleSession jingleSession) {
+ super(payloadType, remote, local, mediaLocator, jingleSession);
+
+ // TODO le transmitter ne devrait peut etre pas etre init ici, c'est peut etre encore un peu tot, a voir.
+ mTransmitter = new PCMTransmitter(remote.getIp(), getRemote().getPort());
+ //mReceiver = new MicroRTPReceiver(getLocal().getPort());
+ }
+
+ @Override
+ public void initialize() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setTrasmit(boolean active) {
+ }
+
+ @Override
+ public void startReceive() {
+
+ }
+
+ @Override
+ public void startTrasmit() {
+
+ }
+
+ @Override
+ public void stopReceive() {
+ if (mReceiver != null) {
+ mReceiver.stop();
+ }
+ }
+
+ @Override
+ public void stopTrasmit() {
+ if (mTransmitter != null) {
+ mTransmitter.stop();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/PCMTransmitter.java Thu Aug 27 01:21:14 2009 +0200
@@ -0,0 +1,43 @@
+package com.beem.project.beem.jingle;
+
+import android.media.AudioFormat;
+import android.media.AudioRecord;
+import android.media.MediaRecorder;
+
+/**
+ * Transmit Microphone data through RTP.
+ * @author nikita
+ */
+public class PCMTransmitter extends RTPTransmitter {
+
+ /**
+ * Constructor.
+ * @param remoteIP destinataire ip.
+ * @param port destinataire port.
+ */
+ public PCMTransmitter(final String remoteIP, final int port) {
+ super(remoteIP, port);
+ }
+
+ @Override
+ void start() {
+ AudioRecord audRec = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, 8000,
+ AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT, AudioRecord.getMinBufferSize(8000,
+ AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_8BIT));
+ byte[] audioData = new byte[1024];
+ int byteReaded = 0;
+ while (!mKillme) {
+ byteReaded = audRec.read(audioData, byteReaded, 1024);
+ System.out.println("readed " + byteReaded);
+ mRtpSession.sendData(audioData);
+ }
+ try {
+ Thread.sleep(200);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ this.mRtpSession.endSession();
+
+ }
+
+}
--- a/src/com/beem/project/beem/jingle/RTPMediaManager.java Tue Aug 25 03:42:58 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-package com.beem.project.beem.jingle;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jivesoftware.smackx.jingle.JingleSession;
-import org.jivesoftware.smackx.jingle.SmackLogger;
-import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
-import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
-import org.jivesoftware.smackx.jingle.media.PayloadType;
-import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
-import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
-
-/**
- * RTPMediaManager, gere les payloads et renvoie une session RTP
- * @author nikita
- */
-public class RTPMediaManager extends JingleMediaManager {
-
- private static final SmackLogger LOGGER = SmackLogger.getLogger(RTPMediaManager.class);
-
- public static final String MEDIA_NAME = "RTP_BIDON";
-
- private List<PayloadType> mPayloads;
-
- public RTPMediaManager(JingleTransportManager transportManager) {
- super(transportManager);
- // TODO Auto-generated constructor stub
- setupPayloads();
- LOGGER.info("A TestMedia Manager is created(Receiver)");
- }
-
- @Override
- public JingleMediaSession createMediaSession(PayloadType payloadType, TransportCandidate remote,
- TransportCandidate local, JingleSession jingleSession) {
- // TODO Auto-generated method stub
- return new RTPMediaSession(payloadType, remote, local, null, jingleSession);
- }
-
- @Override
- public String getName() {
- return MEDIA_NAME;
- }
-
- @Override
- public List<PayloadType> getPayloads() {
- // TODO Auto-generated method stub
- return mPayloads;
- }
-
- private void setupPayloads() {
- mPayloads = new ArrayList<PayloadType>();
- mPayloads.add(new PayloadType.Audio(51, "BIDON1"));
- mPayloads.add(new PayloadType.Audio(52, "BIDON2"));
- mPayloads.add(new PayloadType.Audio(53, "BIDON3"));
- }
-}
--- a/src/com/beem/project/beem/jingle/RTPMediaSession.java Tue Aug 25 03:42:58 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-/**
- *
- */
-package com.beem.project.beem.jingle;
-
-import org.jivesoftware.smackx.jingle.JingleSession;
-import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
-import org.jivesoftware.smackx.jingle.media.PayloadType;
-import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
-
-/**
- * @author nikita
- */
-public class RTPMediaSession extends JingleMediaSession {
-
- private RTPTransmitter mTransmitter;
- private RTPReceiver mReceiver;
-
- /**
- * @param payloadType
- * @param remote
- * @param local
- * @param mediaLocator
- * @param jingleSession
- */
- public RTPMediaSession(PayloadType payloadType, TransportCandidate remote, TransportCandidate local,
- String mediaLocator, JingleSession jingleSession) {
- super(payloadType, remote, local, mediaLocator, jingleSession);
-
- mTransmitter = new MicroRTPTransmitter(remote.getIp(), getRemote().getPort());
- mReceiver = new MicroRTPReceiver(getLocal().getPort());
- }
-
- @Override
- public void initialize() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setTrasmit(boolean active) {
- }
-
- @Override
- public void startReceive() {
-
- }
-
- @Override
- public void startTrasmit() {
-
- }
-
- @Override
- public void stopReceive() {
- if (mReceiver != null) {
- mReceiver.stop();
- }
- }
-
- @Override
- public void stopTrasmit() {
- if (mTransmitter != null) {
- mTransmitter.stop();
- }
- }
-}
--- a/src/com/beem/project/beem/jingle/RTPReceiver.java Tue Aug 25 03:42:58 2009 +0200
+++ b/src/com/beem/project/beem/jingle/RTPReceiver.java Thu Aug 27 01:21:14 2009 +0200
@@ -3,6 +3,7 @@
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;
@@ -11,17 +12,16 @@
public class RTPReceiver implements Runnable, RTPAppIntf {
- RTPSession mRtpSession = null;
- byte[] mAbData = null;
- private boolean mKillme = false;
+ private RTPSession mRtpSession;
+ private boolean mKillme;
public RTPReceiver(int rtpPort) {
DatagramSocket rtpSocket = null;
try {
rtpSocket = new DatagramSocket(rtpPort);
- } catch (Exception e) {
- System.out.println("RTPSession failed to obtain port");
+ } catch (SocketException e) {
+ e.printStackTrace();
return;
}
mRtpSession = new RTPSession(rtpSocket, null);
@@ -40,7 +40,6 @@
for (int i = 0; i < 10; i++) {
freePort = (int) (10000 + Math.round(Math.random() * 10000));
- freePort = freePort % 2 == 0 ? freePort : freePort + 1;
try {
ss = new ServerSocket(freePort);
freePort = ss.getLocalPort();
@@ -74,13 +73,17 @@
while (!mKillme) {
try {
Thread.sleep(1000);
- } catch (Exception e) {
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
}
try {
Thread.sleep(200);
- } catch (Exception e) {
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
this.mRtpSession.endSession();
--- a/src/com/beem/project/beem/jingle/RTPTransmitter.java Tue Aug 25 03:42:58 2009 +0200
+++ b/src/com/beem/project/beem/jingle/RTPTransmitter.java Thu Aug 27 01:21:14 2009 +0200
@@ -3,6 +3,7 @@
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;
@@ -14,15 +15,13 @@
protected boolean mKillme = false;
public RTPTransmitter(String remoteIP, int port) {
-
DatagramSocket rtpSocket = null;
int rtpPort = 0;
-
+ rtpPort = getFreePort();
try {
- rtpPort = getFreePort();
rtpSocket = new DatagramSocket(rtpPort);
- } catch (Exception e) {
- System.out.println("RTPSession failed to obtain port");
+ } catch (SocketException e) {
+ e.printStackTrace();
return;
}
mRtpSession = new RTPSession(rtpSocket, null);
@@ -42,7 +41,6 @@
for (int i = 0; i < 10; i++) {
freePort = (int) (10000 + Math.round(Math.random() * 10000));
- freePort = freePort % 2 == 0 ? freePort : freePort + 1;
try {
ss = new ServerSocket(freePort);
freePort = ss.getLocalPort();
@@ -73,7 +71,7 @@
}
/**
- * A implementer pour chaque type d'envoi specifique
+ * A implementer pour chaque type d'envoi specifique.
*/
abstract void start();