un tres vieux commit pas fait sur du rtp.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/RTPMediaManager.java Thu Apr 02 15:56:12 2009 +0200
@@ -0,0 +1,53 @@
+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;
+
+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> payloads;
+
+ 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 List<PayloadType> getPayloads() {
+ // TODO Auto-generated method stub
+ return payloads;
+ }
+
+ private void setupPayloads() {
+ payloads = new ArrayList<PayloadType>();
+ payloads.add(new PayloadType.Audio(51, "BIDON1"));
+ payloads.add(new PayloadType.Audio(52, "BIDON2"));
+ payloads.add(new PayloadType.Audio(53, "BIDON3"));
+ }
+
+ public String getName() {
+ return MEDIA_NAME;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/RTPMediaSession.java Thu Apr 02 15:56:12 2009 +0200
@@ -0,0 +1,76 @@
+/**
+ *
+ */
+package com.beem.project.beem.jingle;
+
+import org.jivesoftware.smackx.jingle.JingleSession;
+import org.jivesoftware.smackx.jingle.SmackLogger;
+import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
+import org.jivesoftware.smackx.jingle.media.PayloadType;
+import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+
+/**
+ * @author darisk
+ *
+ */
+public class RTPMediaSession extends JingleMediaSession {
+
+ private static final SmackLogger LOGGER = SmackLogger
+ .getLogger(RTPMediaSession.class);
+ private RTPTransmitter transmitter;
+ private RTPReceiver receiver;
+
+ /**
+ * @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);
+ initialize();
+ LOGGER.info("Demarrage d'une session avec local: " + local
+ + " #remote: " + remote);
+
+ transmitter = new RTPTransmitter(remote.getIp(), getRemote().getPort());
+ receiver = new RTPReceiver(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 (receiver != null) {
+ receiver.stop();
+ }
+ }
+
+ @Override
+ public void stopTrasmit() {
+ if (transmitter != null) {
+ transmitter.stop();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/RTPReceiver.java Thu Apr 02 15:56:12 2009 +0200
@@ -0,0 +1,97 @@
+package com.beem.project.beem.jingle;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.ServerSocket;
+
+import org.jivesoftware.smackx.jingle.SmackLogger;
+
+import jlibrtp.DataFrame;
+import jlibrtp.Participant;
+import jlibrtp.RTPAppIntf;
+import jlibrtp.RTPSession;
+
+public class RTPReceiver implements Runnable, RTPAppIntf{
+
+ RTPSession rtpSession = null;
+ byte[] abData = null;
+ private boolean killme = false;
+
+ private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaManager.class);
+
+ public RTPReceiver(int rtpPort) {
+ DatagramSocket rtpSocket = null;
+
+ try {
+ rtpSocket = new DatagramSocket(rtpPort);
+ } catch (Exception e) {
+ System.out.println("RTPSession failed to obtain port");
+ return;
+ }
+ rtpSession = new RTPSession(rtpSocket, null);
+ rtpSession.naivePktReception(true);
+ rtpSession.RTPSessionRegister(this, null, null);
+ }
+
+ @Override
+ public void run() {
+ start();
+ }
+
+ private void start() {
+ LOGGER.info("Debut envoi de donnees par RTPTransmitter");
+ while (!killme) {
+ try { Thread.sleep(1000); } catch(Exception e) { }
+ }
+
+ try {Thread.sleep(200);} catch (Exception e) {}
+ this.rtpSession.endSession();
+
+ }
+
+ @Override
+ public int frameSize(int payloadType) {
+ return 1;
+ }
+
+ @Override
+ public void receiveData(DataFrame frame, Participant participant) {
+ byte[] data = frame.getConcatenatedData();
+ }
+
+ @Override
+ public void userEvent(int type, Participant[] participant) {
+ //rien
+
+ }
+
+ public void stop() {
+ this.killme = true;
+ }
+
+ protected int getFreePort() {
+ ServerSocket ss;
+ int freePort = 0;
+
+ 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();
+ 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;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/RTPTransmitter.java Thu Apr 02 15:56:12 2009 +0200
@@ -0,0 +1,100 @@
+package com.beem.project.beem.jingle;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.ServerSocket;
+
+import org.jivesoftware.smackx.jingle.SmackLogger;
+
+import jlibrtp.DataFrame;
+import jlibrtp.Participant;
+import jlibrtp.RTPAppIntf;
+import jlibrtp.RTPSession;
+
+public class RTPTransmitter implements Runnable, RTPAppIntf {
+
+ private static final SmackLogger LOGGER = SmackLogger
+ .getLogger(SenderMediaManager.class);
+ private RTPSession rtpSession;
+ private boolean killme = false;
+
+ public RTPTransmitter(String remoteIP, int port) {
+
+ DatagramSocket rtpSocket = null;
+ int rtpPort = 0;
+
+ try {
+ rtpPort = getFreePort();
+ rtpSocket = new DatagramSocket(rtpPort);
+ } catch (Exception e) {
+ System.out.println("RTPSession failed to obtain port");
+ return;
+ }
+ rtpSession = new RTPSession(rtpSocket, null);
+ rtpSession.naivePktReception(true);
+ rtpSession.RTPSessionRegister(this, null, null);
+ rtpSession.addParticipant(new Participant(remoteIP,rtpPort, 0));
+ }
+
+ private void start() {
+ LOGGER.info("Debut envoi de donnees par RTPTransmitter");
+ while (!killme) {
+ rtpSession.sendData(null);
+ }
+
+ try {Thread.sleep(200);} catch (Exception e) {}
+ this.rtpSession.endSession();
+ }
+
+ @Override
+ public void run() {
+ start();
+ }
+
+ @Override
+ public int frameSize(int payloadType) {
+ return 1;
+ }
+
+ @Override
+ public void receiveData(DataFrame frame, Participant participant) {
+ //On envoie uniquement
+ }
+
+ @Override
+ public void userEvent(int type, Participant[] participant) {
+ //je sais pas ce que c'est
+
+ }
+
+ protected int getFreePort() {
+ ServerSocket ss;
+ int freePort = 0;
+
+ 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();
+ 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;
+ }
+
+ public void stop() {
+ this.killme = true;
+ }
+
+}
--- a/src/com/beem/project/beem/jingle/Receiver.java Wed Apr 01 19:30:58 2009 +0200
+++ b/src/com/beem/project/beem/jingle/Receiver.java Thu Apr 02 15:56:12 2009 +0200
@@ -5,10 +5,12 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.JingleSessionRequest;
@@ -18,6 +20,7 @@
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.nat.BasicTransportManager;
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+import org.jivesoftware.smackx.packet.DiscoverInfo;
public class Receiver {
@@ -32,10 +35,26 @@
ConnectionConfiguration conf = new ConnectionConfiguration("nikita-rack");
conf.setRosterLoadedAtLogin(false);
con = new XMPPConnection(conf);
+
try {
+
con.connect();
- con.login(username, pass, "TEST");
+ JingleManager.setJingleServiceEnabled();
+ ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(con);
+ //NOTE Classe gerant le service discovery (ce qui permet aux autres de savoir ce qu'on sait faire)
+
+
+ //Pour rajouter une liste de feature supporter (de format : "http://jabber.org/protocol/disco#info")
+ sdm.addFeature("http://jabber.org/protocol/disco#info");
+ sdm.addFeature("TOTO");
+
+ con.login(username, pass, "TEST-JAVA");
initialize();
+ // Le client demande les services dispo en face a son roster
+ // il doit en suite fournir lui meme une liste de feature
+
+ DiscoverInfo di = sdm.discoverInfo("test@nikita-rack/pidgin");
+ DiscoverInfo di2 = sdm.discoverInfo("nikita@nikita-rack/Telepathy");
} catch (XMPPException e) {
// TODO Auto-generated catch block
@@ -43,11 +62,12 @@
}
}
- private void initialize()
- {
+ private void initialize() {
+ BasicTransportManager bt = new BasicTransportManager();
mediaManagers = new ArrayList<JingleMediaManager>();
- mediaManagers.add(new SenderMediaManager(new BasicTransportManager()));
- JingleManager.setJingleServiceEnabled();
+ mediaManagers.add(new RTPMediaManager(bt));
+ mediaManagers.add(new SenderMediaManager(bt));
+
jingleManager = new JingleManager(con, mediaManagers);
jingleManager.addJingleSessionRequestListener(new JingleSessionRequestListener() {
--- a/src/com/beem/project/beem/jingle/SenderMediaManager.java Wed Apr 01 19:30:58 2009 +0200
+++ b/src/com/beem/project/beem/jingle/SenderMediaManager.java Thu Apr 02 15:56:12 2009 +0200
@@ -12,39 +12,42 @@
public class SenderMediaManager extends JingleMediaManager {
- private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaManager.class);
+ private static final SmackLogger LOGGER = SmackLogger
+ .getLogger(SenderMediaManager.class);
- public static final String MEDIA_NAME = "42Test";
+ public static final String MEDIA_NAME = "42Test";
- private List<PayloadType> payloads;
+ private List<PayloadType> payloads;
- public SenderMediaManager(JingleTransportManager transportManager) {
- super(transportManager);
- // TODO Auto-generated constructor stub
- setupPayloads();
- LOGGER.info("A TestMedia Manager is created");
- }
+ public SenderMediaManager(JingleTransportManager transportManager) {
+ super(transportManager);
+ // TODO Auto-generated constructor stub
+ setupPayloads();
+ LOGGER.info("A TestMedia Manager is created(Sender)");
+ }
- @Override
- public JingleMediaSession createMediaSession(PayloadType payloadType,
- TransportCandidate remote, TransportCandidate local,
- JingleSession jingleSession) {
- // TODO Auto-generated method stub
- return new SenderMediaSession(payloadType, remote, local, null, jingleSession);
- }
+ @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 List<PayloadType> getPayloads() {
- return payloads;
- }
+ @Override
+ public List<PayloadType> getPayloads() {
+ return payloads;
+ }
- private void setupPayloads() {
- payloads = new ArrayList<PayloadType>();
- payloads.add(new PayloadType.Audio(42, "Test"));
- }
+ private void setupPayloads() {
+ payloads = new ArrayList<PayloadType>();
+ payloads.add(new PayloadType.Audio(42, "Test"));
+ payloads.add(new PayloadType.Audio(15, "Speex"));
+ }
- @Override
- public String getName() {
- return MEDIA_NAME;
- }
+ @Override
+ public String getName() {
+ return MEDIA_NAME;
+ }
}