You can subscribe to this list here.
| 2003 |
Jan
|
Feb
(29) |
Mar
(109) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <car...@us...> - 2003-03-18 03:20:34
|
Update of /cvsroot/madsserv/madsserv/src/server/streaming In directory sc8-pr-cvs1:/tmp/cvs-serv11418/streaming Modified Files: Streaming.java Log Message: on approche des transitions Index: Streaming.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/streaming/Streaming.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Streaming.java 14 Mar 2003 03:26:19 -0000 1.2 --- Streaming.java 18 Mar 2003 03:20:27 -0000 1.3 *************** *** 1,248 **** ! // La classe Streaming met en place le module Streaming RTP du projet Madsserv ! // Elle reçoit en entrée une DataSource à diffuser vers une adresse client ! // Elle utilise les RTPManager de JMF pour la diffusion ! ! import java.awt.*; ! import java.io.*; ! import java.util.Vector; ! import java.net.InetAddress; ! import javax.media.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.*; ! import javax.media.control.TrackControl; ! import javax.media.control.QualityControl; ! import javax.media.rtp.*; ! import javax.media.rtp.rtcp.*; ! import com.sun.media.rtp.*; ! import javax.media.rtp.event.*; ! ! public class Streaming ! implements SendStreamListener { ! ! // Adresse IP et port du client ! private String clientIPAddress; ! private int clientPort; ! private int clientID; ! ! private ServerInit serverInit; ! ! // Variables de controle ! private int nbManager = 2; ! private Boolean alreadyStarted = null; ! ! // Tableau des RTPManager ! private RTPManager rtpMgrs[]; ! // Tableau des vectors contenant chacun les SendStream d'un RTPManager ! private Vector[] sendStreamVectors = new Vector[nbManager]; ! // La DataSource en entrée du module de streaming RTP ! private DataSource dataInput = null; ! ! private Reencode reencode=null; ! private Transition transition=null; ! ! // Constructeur sans arguments ! public Streaming(int _clientID, ServerInit _serverInit) { ! serverInit = _serverInit; ! clientID = _clientID; ! clientIPAddress = ""; ! clientPort = 40000; ! alreadyStarted = Boolean.valueOf(false); ! } ! ! // Constructeur avec l'adresse IP et le port du client ! public Streaming(int _clientID, String _clientIPAddress, String _clientPort, ! ServerInit _serverInit) { ! serverInit = _serverInit; ! clientID = _clientID; ! clientIPAddress = _clientIPAddress; ! Integer integer = Integer.valueOf(_clientPort); ! if (integer != null) { ! clientPort = integer.intValue(); ! } ! } ! ! public void setReencode(Reencode _reencode) { ! reencode = _reencode; ! } ! ! public void setTransition(Transition _transition) { ! transition = _transition; ! } ! ! public void initialize() { ! rtpMgrs = new RTPManager[nbManager]; ! SessionAddress localAddr, destAddr; ! InetAddress ipAddr; ! int port; ! String cname = SourceDescription.generateCNAME(); ! SourceDescription sourceDesc; ! ! // Initialisation des vectors de SendStreams ! for (int i = 0; i < nbManager; i++) { ! sendStreamVectors[i] = new Vector(); ! } ! ! // Creation des RTPManager (on passe les adresses locale et destination) ! for (int i = 0; i < nbManager; i++) { ! try { ! rtpMgrs[i] = RTPManager.newInstance(); ! rtpMgrs[i].addSendStreamListener(this); ! ! port = clientPort + 2 * i; ! ipAddr = InetAddress.getByName(clientIPAddress); ! localAddr = new SessionAddress(InetAddress.getLocalHost(), ! port); ! destAddr = new SessionAddress(ipAddr, port); ! sourceDesc = new SourceDescription(SourceDescription ! .SOURCE_DESC_CNAME, ! cname, ! 1, ! false); ! rtpMgrs[i].initialize(localAddr /*, sourceDesc, 0.05, 0.25*/); ! rtpMgrs[i].addTarget(destAddr); ! System.err.println("Created RTP session: " + clientIPAddress + " " + ! port); ! } ! catch (Exception e) { ! System.err.println(e.getMessage()); ! } ! } ! } ! ! // Méthode publique pour modifier la DataSource en cours de diffusion ! public synchronized void setNewStreams(DataSource _dataInput) { ! ! SendStream sendStream; ! ! PushBufferDataSource ds = null; ! PushBufferStream ss[]; ! ! int nbStreams, vectSize; ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream " + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! } ! ! // Mise à jour de la DataSource à diffuser ! dataInput = _dataInput; ! ! // Identification des Streams contenus dans la DataSource ! ds = (PushBufferDataSource) dataInput; ! if (ds == null) { ! System.err.println("source vide"); ! } ! ss = ds.getStreams(); ! System.err.println("Nombre de streams " + ss.length); ! ! // Lancer la diffusion des nouveaux Streams ! for (int i = 0; i < ss.length; i++) { ! try { ! sendStream = rtpMgrs[i].createSendStream(dataInput, i); ! sendStreamVectors[i].add(sendStream); ! sendStream.start(); ! alreadyStarted = Boolean.valueOf(true); ! } ! catch (Exception e) { ! System.err.println("message erreur sendstreams " + e.getMessage()); ! } ! } ! } ! ! public void setClientIP(String _clientIPAddress) { ! clientIPAddress = _clientIPAddress; ! } ! ! public void setClientPort(int _clientPort) { ! clientPort = _clientPort; ! } ! ! public boolean isInitialized() { ! return alreadyStarted.booleanValue(); ! } ! ! public void endOfMedia() { ! int nbStreams, vectSize; ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream n°" + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! serverInit.endConnexion(clientID); ! //stop(); ! System.err.println("Je fais un stop sur streaming"); ! synchronized (alreadyStarted) { ! alreadyStarted = Boolean.valueOf(false); ! } ! } ! ! } ! ! // Méthode permettant de stopper la diffusion et de détruire la seesion RTP ! public void stop() { ! synchronized (this) { ! for (int i = 0; i < rtpMgrs.length; i++) { ! rtpMgrs[i].removeTargets("Session ended."); ! rtpMgrs[i].dispose(); ! rtpMgrs[i] = null; ! } ! System.err.println("J'ai supprime les rtpmanager"); ! } ! } ! ! /** ! * SendStreamListener ! */ ! public synchronized void update(SendStreamEvent evt) { ! ! int nbStreams, vectSize; ! //System.out.println("Evenement SendStream : " + evt.toString()); ! /* RTPManager mgr = (RTPManager)evt.getSource(); ! Participant participant = evt.getParticipant(); // could be null. ! ReceiveStream stream = evt.getReceiveStream(); // could be null. ! */ ! if (evt instanceof InactiveSendStreamEvent) { ! System.out.println("J'ai un evenement Inactive"); ! ! // Annuler la diffusion des SendStreams en cours (alreadyStarted permet de savoir si une diffusion est deja commencee ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream " + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! } ! ! /* System.err.println(" - Received an RTP PayloadChangeEvent."); ! System.err.println("Sorry, cannot handle payload change."); ! System.exit(0);*/ ! ! } ! } ! ! } --- 1,270 ---- ! // La classe Streaming met en place le module Streaming RTP du projet Madsserv ! // Elle recoit en entree une DataSource a diffuser vers une adresse client ! // Elle utilise les RTPManager de JMF pour la diffusion ! ! import java.awt.*; ! import java.io.*; ! import java.util.Vector; ! import java.net.InetAddress; ! import javax.media.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.*; ! import javax.media.control.TrackControl; ! import javax.media.control.QualityControl; ! import javax.media.rtp.*; ! import javax.media.rtp.rtcp.*; ! import com.sun.media.rtp.*; ! import javax.media.rtp.event.*; ! ! public class Streaming ! implements SendStreamListener { ! ! // Adresse IP et port du client ! private String clientIPAddress; ! private int clientPort; ! private int clientID; ! ! private ServerInit serverInit; ! ! // Variables de controle ! private int nbManager = 2; ! private Boolean alreadyStarted = null; ! ! // Tableau des RTPManager ! private RTPManager rtpMgrs[]; ! // Tableau des vectors contenant chacun les SendStream d'un RTPManager ! private Vector[] sendStreamVectors = new Vector[nbManager]; ! // La DataSource en entree du module de streaming RTP ! private DataSource dataInput = null; ! ! private Reencode reencode = null; ! private Transition transition = null; ! ! // Constructeur sans arguments ! public Streaming(int _clientID, ServerInit _serverInit) { ! serverInit = _serverInit; ! clientID = _clientID; ! clientIPAddress = ""; ! clientPort = 40000; ! alreadyStarted = Boolean.valueOf(false); ! } ! ! // Constructeur avec l'adresse IP et le port du client ! public Streaming(int _clientID, String _clientIPAddress, String _clientPort, ! ServerInit _serverInit) { ! serverInit = _serverInit; ! clientID = _clientID; ! clientIPAddress = _clientIPAddress; ! Integer integer = Integer.valueOf(_clientPort); ! if (integer != null) { ! clientPort = integer.intValue(); ! } ! } ! ! public void setReencode(Reencode _reencode) { ! reencode = _reencode; ! } ! ! public void setTransition(Transition _transition) { ! transition = _transition; ! } ! ! public void initialize() { ! rtpMgrs = new RTPManager[nbManager]; ! SessionAddress localAddr, destAddr; ! InetAddress ipAddr; ! int port; ! String cname = SourceDescription.generateCNAME(); ! SourceDescription sourceDesc; ! ! // Initialisation des vectors de SendStreams ! for (int i = 0; i < nbManager; i++) { ! sendStreamVectors[i] = new Vector(); ! } ! ! // Creation des RTPManager (on passe les adresses locale et destination) ! for (int i = 0; i < nbManager; i++) { ! try { ! rtpMgrs[i] = RTPManager.newInstance(); ! rtpMgrs[i].addSendStreamListener(this); ! ! port = clientPort + 2 * i; ! ipAddr = InetAddress.getByName(clientIPAddress); ! localAddr = new SessionAddress(InetAddress.getLocalHost(), ! port); ! destAddr = new SessionAddress(ipAddr, port); ! sourceDesc = new SourceDescription(SourceDescription ! .SOURCE_DESC_CNAME, ! cname, ! 1, ! false); ! rtpMgrs[i].initialize(localAddr /*, sourceDesc, 0.05, 0.25*/); ! rtpMgrs[i].addTarget(destAddr); ! System.err.println("Created RTP session: " + clientIPAddress + " " + ! port); ! } ! catch (Exception e) { ! System.err.println(e.getMessage()); ! } ! } ! } ! ! // Methode publique pour modifier la DataSource en cours de diffusion ! public synchronized void setNewStreams(DataSource _dataInput) { ! SendStream sendStream; ! ! PushBufferDataSource ds = null; ! PushBufferStream ss[]; ! int nbStreams, vectSize; ! ! System.out.println("Le streaming a recu les nouveaux streams"); ! ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream " + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! } ! ! // Mise a jour de la DataSource a diffuser ! dataInput = _dataInput; ! ! // Identification des Streams contenus dans la DataSource ! ds = (PushBufferDataSource) dataInput; ! if (ds == null) { ! System.err.println("source vide"); ! } ! ss = ds.getStreams(); ! System.err.println("Nombre de streams " + ss.length); ! try { ! Thread.sleep(2000); ! } ! catch (Exception e) { ! ! } ! String[] messageToSend = new String[2]; ! messageToSend[0] = "Connexion du client " + String.valueOf(clientID); ! messageToSend[1] = String.valueOf(ss.length); ! serverInit.sendMessage(clientID, 3, messageToSend); ! ! try { ! Thread.sleep(2000); ! } ! catch (Exception e) { ! ! } ! ! // Lancer la diffusion des nouveaux Streams ! for (int i = 0; i < ss.length; i++) { ! try { ! System.err.println("Streaming : j'envoie le stream " + i); ! sendStream = rtpMgrs[i].createSendStream(dataInput, i); ! sendStreamVectors[i].add(sendStream); ! sendStream.start(); ! System.err.println("Streaming : stream envoye " + i); ! alreadyStarted = Boolean.valueOf(true); ! serverInit.setStatus(clientID, "Diffusion"); ! } ! catch (Exception e) { ! System.err.println("message erreur sendstreams " + e.getMessage()); ! } ! } ! } ! ! public void setClientIP(String _clientIPAddress) { ! clientIPAddress = _clientIPAddress; ! } ! ! public void setClientPort(int _clientPort) { ! clientPort = _clientPort; ! } ! ! public boolean isInitialized() { ! return alreadyStarted.booleanValue(); ! } ! ! public void endOfMedia() { ! int nbStreams, vectSize; ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream num" + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! serverInit.endConnexionClient(clientID); ! //stop(); ! System.err.println("Je fais un stop sur streaming"); ! synchronized (alreadyStarted) { ! alreadyStarted = Boolean.valueOf(false); ! } ! } ! ! } ! ! // Methode permettant de stopper la diffusion et de detruire la seesion RTP ! public void stop() { ! synchronized (this) { ! for (int i = 0; i < rtpMgrs.length; i++) { ! rtpMgrs[i].removeTargets("Session ended."); ! rtpMgrs[i].dispose(); ! rtpMgrs[i] = null; ! alreadyStarted = Boolean.valueOf(false); ! } ! System.err.println("J'ai supprime les rtpmanager"); ! } ! } ! ! /** ! * SendStreamListener ! */ ! public synchronized void update(SendStreamEvent evt) { ! ! int nbStreams, vectSize; ! //System.out.println("Evenement SendStream : " + evt.toString()); ! /* RTPManager mgr = (RTPManager)evt.getSource(); ! Participant participant = evt.getParticipant(); // could be null. ! ReceiveStream stream = evt.getReceiveStream(); // could be null. ! */ ! if (evt instanceof InactiveSendStreamEvent) { ! System.out.println("J'ai un evenement Inactive"); ! ! // Annuler la diffusion des SendStreams en cours (alreadyStarted permet de savoir si une diffusion est deja commencee ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream " + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! } ! ! /* System.err.println(" - Received an RTP PayloadChangeEvent."); ! System.err.println("Sorry, cannot handle payload change."); ! System.exit(0);*/ ! ! } ! } ! ! } \ No newline at end of file |
|
From: <mar...@us...> - 2003-03-18 02:11:35
|
Update of /cvsroot/madsserv/madsserv/src/server/processor
In directory sc8-pr-cvs1:/tmp/cvs-serv10102
Modified Files:
Reencode.java ThreadReencode.java
Log Message:
elimination de la vermine qui bloquait le lancement du nouveau thread
Index: Reencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/Reencode.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Reencode.java 17 Mar 2003 02:57:02 -0000 1.13
--- Reencode.java 18 Mar 2003 02:11:32 -0000 1.14
***************
*** 190,201 ****
currentThreadReencode.run();
- // On attend que le Processor du nouveau thread soit started
Processor currentProcessor = null;
currentProcessor = currentThreadReencode.processor;
stateTransitionOK = true;
- waitForState(currentProcessor, currentProcessor.Started);
// On transmet au module Streaming l'adresse du DataSource de sortie
streamingRef.setNewStreams(currentThreadReencode.getOutput());
}
}
--- 190,200 ----
currentThreadReencode.run();
Processor currentProcessor = null;
currentProcessor = currentThreadReencode.processor;
stateTransitionOK = true;
// On transmet au module Streaming l'adresse du DataSource de sortie
streamingRef.setNewStreams(currentThreadReencode.getOutput());
+ System.out.println("Le nouveau stream est transfere a streamingRef");
}
}
***************
*** 428,437 ****
}
else { // on arrete le processor et met la reference du ThreadReencode precedent a null
formerThreadReencode.stopProcessing();
formerThreadReencode = null;
}
! currentThreadReencode.stopProcessing();
! currentThreadReencode = null;
! return 0;
}
--- 427,446 ----
}
else { // on arrete le processor et met la reference du ThreadReencode precedent a null
+ System.out.println("Le precedent ThreadReencode n'est pas arrete.");
formerThreadReencode.stopProcessing();
+ System.out.println("Le precedent ThreadReencode est maintenant arrete.");
formerThreadReencode = null;
}
! if (currentThreadReencode != null) {
! System.out.println("Le ThreadReencode courant n'est pas arrete.");
! currentThreadReencode.stopProcessing();
! System.out.println("Le ThreadReencode courant est maintenant arrete.");
! currentThreadReencode = null;
! return 0;
! }
! else {
! System.out.println("Le ThreadReencode est deja arrete.");
! return 0;
! }
}
Index: ThreadReencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/ThreadReencode.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** ThreadReencode.java 17 Mar 2003 02:57:03 -0000 1.7
--- ThreadReencode.java 18 Mar 2003 02:11:32 -0000 1.8
***************
*** 194,197 ****
--- 194,198 ----
// Start the transmission
processor.start();
+ System.out.println("processor started");
return null;
|
|
From: <dep...@us...> - 2003-03-17 10:25:16
|
Update of /cvsroot/madsserv/madsserv/src/server/transition In directory sc8-pr-cvs1:/tmp/cvs-serv25729 Modified Files: Transition.java Log Message: Trnasition adaptee aux autres modules Index: Transition.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/transition/Transition.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Transition.java 15 Mar 2003 22:40:54 -0000 1.6 --- Transition.java 17 Mar 2003 10:25:11 -0000 1.7 *************** *** 1,201 **** ! import java.awt.*; ! import java.io.*; ! import java.lang.Object.*; ! import javax.media.Time.*; ! import javax.media.*; ! import javax.media.format.*; ! import javax.media.format.AudioFormat.*; ! import javax.media.format.VideoFormat.*; ! ! /** ! * La classe Transition assure la transition la plus rapide lors d'un changement de niveau de qualite. Des que le gestionnaire des Connexions lui transmet un changement de niveau de qualite, il collecte les informations sur les diffusions en cours, fixe les parametres de l'encodage a effectuer et les transmet au module de traitement de la conversion. ! * @author Xavier Deplancq ! */ ! ! public class Transition { ! ! /*On declare ici le numero du client, le numero de frame courant et le niveau de qualite*/ ! ! private int numClient; ! private int qualityLevel; ! Reencode reencodeRef; ! GestionAdapta gestionAdaptaRef; ! Streaming streamingRef; ! ! /** ! * Constructeur vide, il initialise le numero du client a 0, il met le niveau de qualite a 1 par defaut et le numero de Frame a 0. Il ne peut etre utiliser que la premiere fois, sinon il y a des risques de colision. ! */ ! ! public Transition() ! ! { ! numClient = 0; ! qualityLevel = 1; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le numero du client, le niveau de qualite a 1 par defaut et le numero de frame a 0. ! *@param _nmclient le numero du client ! */ ! ! public Transition(int _numClient) ! ! { ! numClient = _numClient; ! qualityLevel = 1; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le numero de client et le niveau de qualite et met le numero de Frame a 0 par defaut. ! *@param _nmclient le numero du client ! *@param _qualitylevel le niveau de qualite demande ! */ ! ! public Transition(int _numClient, int _qualityLevel) ! ! { ! numClient = _numClient; ! qualityLevel = _qualityLevel; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le numero de client et le niveau de qualite et met le numero de Frame. ! *@param _nmclient le numero du client ! *@param _qualitylevel le niveau de qualite demande ! *@param _numFrame le numero de frame ! public Transition(int _numClient, int _qualityLevel, float _numFrame) ! { ! numClient = _numClient; ! qualityLevel = _qualityLevel; ! numFrame = _numFrame; ! */ ! ! /** ! *findNewNumberFrame : Cette methode calcule le nouveau numero de Frame a partir duquel il faut reencoder le fichier multimedia diffuse. ! *@param oldNumFrame le numero de frame qui vient d'etre envoye au client ! *@param reencodingVideoFor le nouveau format video de reencodage. ! *@param reencodingAudioFor le nouveau format audio de reencodage. ! */ ! ! public Time findNewMediaTime(double oldMediaTime, ! VideoFormat reencodingVideoFor, ! AudioFormat reencodingAudioFor, ! double VideoMediaLength, double AudioMediaLength) { ! double newAuxMediaTime = 0; ! Time newMediaTime; ! ! if (reencodeRef.multiMedia) { ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! if (reencodingVideoFor.getEncoding() == "MPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! ! } ! ! else { ! if (reencodingAudioFor.getEncoding() == "WAV") { ! newAuxMediaTime = oldMediaTime + 2; ! } ! if (reencodingAudioFor.getEncoding() == "MP3") { ! newAuxMediaTime = oldMediaTime + 2; ! } ! ! } ! newMediaTime = new Time(newAuxMediaTime); ! //on retourne le numero de Frame a partir duquel il faut reencoder. ! return (newMediaTime); ! ! } ! ! /** ! *setQualityLevel Cette methode lance tout le processus de transition entre deux niveau de qualites. ! *@param _qualityLevel le niveau de qualite demande par le simulateur ! **/ ! ! public void setQualityLevel(int _qualityLevel) ! ! { ! int i = 2; ! double currentMediaTime = 0; ! double videoMediaLength = 0; ! double audioMediaLength = 0; ! Time startTime; ! Time auxMediaTime; ! ! //variables qui vont stockees le format original Video et Audio ! VideoFormat[] origVideoFor; ! AudioFormat[] origAudioFor; ! ! //variables qui vont stockees le format de reencodage Video et Audio ! VideoFormat reencodingVideoFor = null; ! AudioFormat reencodingAudioFor = null; ! ! qualityLevel = _qualityLevel; ! ! //On obtient ici les formats Video et Audio Originaux. ! if (reencodeRef.multiMedia) ! origVideoFor = reencodeRef.getOriginalVideoFormat(); ! origAudioFor = reencodeRef.getOriginalAudioFormat(); ! ! //On obtient ici les formats Video et Audio de reencodage. ! if (reencodeRef.multiMedia) ! reencodingVideoFor = gestionAdaptaRef.getVideoStreamingFormat(qualityLevel, ! origVideoFor); ! reencodingAudioFor = gestionAdaptaRef.getAudioStreamingFormat(qualityLevel, ! origAudioFor); ! ! ! //auxMediaTime = streamingRef.getCurrentFrame(); ! //videoMediaLength = streamingRef.getVideoMediaLength(); ! //audioMediaLength = strealingRef.gatAudioMediaLength(); ! ! startTime = findNewMediaTime(currentMediaTime, reencodingVideoFor, ! reencodingAudioFor, videoMediaLength, ! audioMediaLength); ! ! //on Transmet ici les formats Audio et Video de reencodage ! if (reencodeRef.multiMedia) ! reencodeRef.setReencodingVideoFormat(reencodingVideoFor); ! reencodeRef.setReencodingAudioFormat(reencodingAudioFor); ! ! //On Transmet ici le numero de Frame a partir de laquelle il faut reencoder le fichier. ! reencodeRef.setReencodingTime(startTime); ! ! } ! ! /** ! * setStreaming donne une referrence sur un objet Streaming ! * @param streamingRef un objet de type Streaming ! */ ! public void setStreaming(Streaming streamingRef) { ! this.streamingRef = streamingRef; ! } ! ! /** ! * setStreaming donne une referrence sur un objet gestionAdapta ! * @param gestionAdptaRef un objet de type Streaming ! */ ! public void setGestionAdapta(GestionAdapta gestionAdaptaRef) { ! this.gestionAdaptaRef = gestionAdaptaRef; ! } ! ! /** ! * setStreaming donne une referrence sur un objet Reencode ! * @param reencodeRef un objet de type Reencode ! */ ! public void setReencode(Reencode reencodeRef) { ! this.reencodeRef = reencodeRef; ! } ! ! } --- 1,240 ---- ! import java.awt.*; ! import java.io.*; ! import java.lang.Object.*; ! import javax.media.Time.*; ! import javax.media.*; ! import javax.media.format.*; ! import javax.media.format.AudioFormat.*; ! import javax.media.format.VideoFormat.*; ! ! /** ! * La classe Transition assure la transition la plus rapide lors d'un changement de niveau de qualite. Des que le gestionnaire des Connexions lui transmet un changement de niveau de qualite, il collecte les informations sur les diffusions en cours, fixe les parametres de l'encodage a effectuer et les transmet au module de traitement de la conversion. ! * @author Xavier Deplancq ! */ ! ! public class Transition { ! ! /*On declare ici le numero du client, le numero de frame courant et le niveau de qualite*/ ! ! private int numClient; ! private int qualityLevel; ! protected ServerInit serverInit; ! protected boolean mediaTimeReceived; ! protected double currentMediaTime = 0; ! protected Reencode reencodeRef; ! protected GestionAdapta gestionAdaptaRef; ! protected Streaming streamingRef; ! ! //rustine pour la premiere diffusion juste apres la demande du client ! protected boolean rustine=false; ! ! ! /** ! * Constructeur de la classe Transition qui initialise le numero de client et le niveau de qualite et met le numero de Frame a 0 par defaut. ! *@param _nmclient le numero du client ! *@param _serverInit une reference sur l'objet serVerInit ! */ ! ! public Transition(int _numClient, ServerInit _serverInit) ! ! { ! numClient = _numClient; ! serverInit = _serverInit; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le numero de client et le niveau de qualite et met le numero de Frame. ! *@param _nmclient le numero du client ! *@param _qualitylevel le niveau de qualite demande ! *@param _numFrame le numero de frame ! public Transition(int _numClient, int _qualityLevel, float _numFrame) ! { ! numClient = _numClient; ! qualityLevel = _qualityLevel; ! numFrame = _numFrame; ! */ ! ! /** ! *findNewNumberFrame : Cette methode calcule le nouveau numero de Frame a partir duquel il faut reencoder le fichier multimedia diffuse. ! *@param oldNumFrame le numero de frame qui vient d'etre envoye au client ! *@param reencodingVideoFor le nouveau format video de reencodage. ! *@param reencodingAudioFor le nouveau format audio de reencodage. ! */ ! ! public Time findNewMediaTime(double oldMediaTime, ! VideoFormat _reencodingVideoFor, ! AudioFormat _reencodingAudioFor, ! double _mediaLength) { ! ! double newAuxVMediaTime = 0; ! double newAuxAMediaTime = 0; ! Time newMediaTime; ! ! if (reencodeRef.multiMedia) { ! if (_reencodingVideoFor.getEncoding() == "celB") { ! newAuxVMediaTime = oldMediaTime + 1; ! } ! if (_reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxVMediaTime = oldMediaTime + 1; ! } ! if (_reencodingVideoFor.getEncoding() == "nv") { ! newAuxVMediaTime = oldMediaTime + 1; ! } ! if (_reencodingVideoFor.getEncoding() == "H261") { ! newAuxVMediaTime = oldMediaTime + 1; ! } ! if (_reencodingVideoFor.getEncoding() == "MPV") { ! newAuxVMediaTime = oldMediaTime + 1; ! } ! if (_reencodingVideoFor.getEncoding() == "MP2T") { ! newAuxVMediaTime = oldMediaTime + 1; ! } ! if (_reencodingVideoFor.getEncoding() == "H263") { ! newAuxVMediaTime = oldMediaTime + 1; ! } ! } ! ! if (_reencodingAudioFor.getEncoding() == "PCMU") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "1016") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "G726-32") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "G723") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "DVI4") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "LPG") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "PCMA") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "G722") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "L16") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "QCELP") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "CN") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "MPA") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "G728") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! if (_reencodingAudioFor.getEncoding() == "G729") { ! newAuxAMediaTime = oldMediaTime + 1; ! } ! ! if (newAuxAMediaTime > newAuxVMediaTime) { ! newMediaTime = new Time(newAuxAMediaTime); ! } ! else { ! newMediaTime = new Time(newAuxVMediaTime); ! } ! ! //on retourne le numero de Frame a partir duquel il faut reencoder. ! return (newMediaTime); ! ! } ! ! /** ! *setQualityLevel Cette methode lance tout le processus de transition entre deux niveau de qualites. ! *@param _qualityLevel le niveau de qualite demande par le simulateur ! **/ ! ! public void setQualityLevel(int _qualityLevel) ! ! { ! double mediaLength = 0; ! Time startTime = new Time(0); ! Time auxMediaTime; ! VideoFormat reencodingVideoFor=null; ! AudioFormat reencodingAudioFor=null; ! ! //variables qui vont stockees le format original Video et Audio ! Format[][] lesFormats; ! /* Format[][] origVideoFor; ! Format[][] origAudioFor;*/ ! ! qualityLevel = _qualityLevel; ! ! //On obtient ici les formats Video et Audio Supportes. ! lesFormats = reencodeRef.getSupportedFormats(); ! ! //On obtient ici les formats Video et Audio de reencodage. ! if (reencodeRef.multiMedia) { ! reencodingVideoFor = gestionAdaptaRef.getVideoStreamingFormat( ! lesFormats, qualityLevel); ! } ! ! reencodingAudioFor = gestionAdaptaRef.getAudioStreamingFormat(lesFormats, qualityLevel); ! ! if (rustine) { ! mediaTimeReceived = false; ! mediaLength = reencodeRef.getMediaLength(); ! serverInit.requestCurrentMediaTime(numClient); ! while (!mediaTimeReceived) {} ! ! startTime = findNewMediaTime(currentMediaTime, reencodingVideoFor, ! reencodingAudioFor, mediaLength); ! } ! else { ! rustine = true; ! } ! //on Transmet ici les formats Audio et Video de reencodage ! if (reencodeRef.multiMedia) { ! reencodeRef.setReencodingVideoFormat(reencodingVideoFor); ! } ! reencodeRef.setReencodingAudioFormat(reencodingAudioFor); ! ! ! //On Transmet ici le numero de Frame a partir de laquelle il faut reencoder le fichier. ! reencodeRef.setReencodingTime(startTime); ! ! reencodeRef.start(); ! ! } ! public void setCurrentMediaTime(double _currentMediaTime) ! { ! currentMediaTime = _currentMediaTime; ! mediaTimeReceived = true; ! ! } ! ! /** ! * setStreaming donne une referrence sur un objet Streaming ! * @param streamingRef un objet de type Streaming ! */ ! public void setStreaming(Streaming streamingRef) { ! this.streamingRef = streamingRef; ! } ! ! /** ! * setStreaming donne une referrence sur un objet gestionAdapta ! * @param gestionAdptaRef un objet de type Streaming ! */ ! public void setGestionAdapta(GestionAdapta gestionAdaptaRef) { ! this.gestionAdaptaRef = gestionAdaptaRef; ! } ! ! /** ! * setStreaming donne une referrence sur un objet Reencode ! * @param reencodeRef un objet de type Reencode ! */ ! public void setReencode(Reencode reencodeRef) { ! this.reencodeRef = reencodeRef; ! } ! ! } |
|
From: <dep...@us...> - 2003-03-17 10:20:55
|
Update of /cvsroot/madsserv/madsserv/src/client In directory sc8-pr-cvs1:/tmp/cvs-serv23643 Modified Files: Client.java ClientRTPManager.java DialogServer.java DialogSocket.java ErrorPopUp.java MadsservClient.java PlayerPanel.java ThreadRTPManager.java ThreadRead.java ThreadWrite.java Log Message: synchronisation des players et gestion de la demande de currentTime Index: Client.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/Client.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Client.java 15 Mar 2003 22:47:30 -0000 1.8 --- Client.java 17 Mar 2003 10:20:29 -0000 1.9 *************** *** 1,383 **** ! //package madsserv_planification; ! ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.Checkbox.*; ! import java.awt.CheckboxGroup.*; ! import javax.swing.*; ! ! /** ! * <p>Title: Client </p> ! * <p>Description: La Classe Client est l'interface graphique du client</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! */ ! ! public class Client ! extends Frame { ! /** ! * Champs de la Classe Reencode ! */ ! ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelCenter = new Panel(); ! private Panel panelSouth = new Panel(); ! private Panel panelEmpty = new Panel(); ! private MenuBar menuBar1 = new MenuBar(); ! private Menu menuFile = new Menu(); ! private MenuItem menuOpenURL = new MenuItem(); ! private MenuItem menuFileExit = new MenuItem(); ! private Label statusBar = new Label(); ! private Label URLLabel = new Label(); ! private Label AdLabel = new Label(); ! ! private TextField URLChoice; ! private TextField AdServer; ! private CheckboxGroup cbg = new CheckboxGroup(); ! private Checkbox formatMPEG; ! private Checkbox formatJPEG; ! private Button go; ! ! private PlayerPanel playerPanel = null; ! ! private BorderLayout borderLayout1 = new BorderLayout(); ! private GridBagLayout gridBagLayoutNorth = new GridBagLayout(); ! private GridBagLayout gridBagLayoutSouth = new GridBagLayout(); ! ! private boolean insVideo = false; ! ! private Socket mySocket = null; ! private DialogServer dialogServer; ! ! ! ! /** ! * Contructeur de la Classe Client ! */ ! ! public Client() { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! try { ! jbInit(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * setPlayerPanel crée l'interface graphique du Client ! * @param pp il s'agit d'un PlayerPanel qui est une classe que nous avons crée ! * @vid est un booleen qui nous dit si le player a cree est de la video ou de l'audio ! */ ! ! public void setPlayerPanel(PlayerPanel pp, boolean vid) { ! Panel panelTemp; ! ! if (playerPanel == null) { ! panelTemp = panelEmpty; ! } ! else ! ! { ! panelTemp = playerPanel; ! } ! System.out.println("video :" + vid); ! System.out.println("insvideo :" + insVideo); ! ! // on teste ici pour savoir si on doit cree un player video ou un player audio ! if (vid) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! insVideo = true; ! } ! ! else if (!insVideo) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! } ! } ! ! /** ! * jbinit lance la creation de l'interface graphique. ! */ ! private void jbInit() throws Exception { ! ! contentPane = this; ! contentPane.setLayout(borderLayout1); ! this.setSize(new Dimension(240, 320)); ! this.setTitle("Madsserv Client"); ! setAfficheStatusBar("coucou"); ! URLChoice = new TextField("file:///c:\\temp\\kiss_cool_1.mpeg"); ! AdServer = new TextField("dronej.rezel.com:5001"); ! menuFile.setLabel("File"); ! menuOpenURL.setLabel("Open URL"); ! menuOpenURL.addActionListener(new Client_Menu_OpenURL_ActionAdapter(this)); ! menuFileExit.setLabel("Exit"); ! menuFileExit.addActionListener(new Client_menuFileExit_ActionAdapter(this)); ! menuFile.add(menuOpenURL); ! menuFile.add(menuFileExit); ! menuBar1.add(menuFile); ! this.setMenuBar(menuBar1); ! ! formatMPEG = new Checkbox("MPEG", cbg, true); ! ! formatJPEG = new Checkbox("JPEG", cbg, false); ! ! go = new Button("Go!"); ! go.setSize(new Dimension(60, 15)); ! go.addActionListener(new Client_boutongo_ActionAdapter(this)); ! ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! panelSouth.setLayout(gridBagLayoutSouth); ! GridBagConstraints c = new GridBagConstraints(); ! c.fill = GridBagConstraints.BOTH; ! c.insets = new Insets(1, 5, 1, 5); ! c.weightx = 1.0; ! c.weighty = 1.0; ! panelSouth.add(formatMPEG, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelSouth.add(formatJPEG, c); ! c.weightx = 0.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelSouth.add(go, c); ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.weightx = 0.0; ! c.gridwidth = 2; ! panelSouth.add(statusBar, c); ! ! URLLabel.setText("URL :"); ! AdLabel.setText("Serv:"); ! URLLabel.setSize(new Dimension(30, 15)); ! URLChoice.setSize(new Dimension(30, 15)); ! AdLabel.setSize(new Dimension(30, 15)); ! AdServer.setSize(new Dimension(30, 15)); ! ! panelNorth.setLayout(gridBagLayoutNorth); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.gridwidth = 1; ! c.weightx = 0.0; ! c.weighty = 1.0; ! panelNorth.add(URLLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelNorth.add(URLChoice, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.weightx = 0.0; ! panelNorth.add(AdLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelNorth.add(AdServer, c); ! ! contentPane.add(panelSouth, BorderLayout.SOUTH); ! contentPane.add(panelNorth, BorderLayout.NORTH); ! ! contentPane.add(panelEmpty, BorderLayout.CENTER); ! ! } ! ! /** ! * menuFileExit_actionPerformed est à l'ecoute d'un evenement signifiant l'arret du client ! * @param e c'est l'evenemet qui met fin au client ! */ ! public void menuFileExit_actionPerformed(ActionEvent e) { ! try { ! String messageToSend[] = new String[1]; ! messageToSend[0] = "fin de la connexion"; ! dialogServer.sendMessage(4, messageToSend); ! System.exit(0); ! } ! catch (Exception ex) { ! System.exit(0); ! } ! } ! ! /** ! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre ! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre ! */ ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! menuFileExit_actionPerformed(null); ! } ! } ! ! /** ! * boutongo_actionPerformed Methode qui permet de lancer la connexion lorsque l'on clique sur le bouton go ! * @param evt c'est l'evenement qui indique que l'on a clique sur le bouton go ! */ ! public void boutongo_actionPerformed(ActionEvent evt) { ! ! String[] messageToSend; ! ! if (mySocket == null) { ! try { ! mySocket = new Socket(getAddressServer(), getServerPort()); ! } ! catch (Exception e) { ! showError("serveur ou port incorrect"); ! } ! ! dialogServer = new DialogServer(mySocket, this); ! dialogServer.start(); ! } ! ! else { ! // if ( (mySocket.isClosed()) == false) { ! messageToSend = new String[2]; ! messageToSend[0] = getURL(); ! messageToSend[1] = getFormatPrefere(); ! ! dialogServer.sendMessage(2, messageToSend); ! /*} ! else { ! try { ! mySocket.connect(new InetSocketAddress(getAddressServer(), ! getServerPort())); ! } ! catch (Exception e) { ! } ! }*/ ! } ! } ! ! public void endConnexion() { ! dialogServer.stop(); ! mySocket = null; ! } ! ! public void showError(String messageErreur) ! { ! ErrorPopUp errorPopUp = new ErrorPopUp(messageErreur,this); ! } ! ! /** ! * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client ! * @return InetAddress du server ! */ ! public InetAddress getAddressServer() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! try { ! return (InetAddress.getByName(host.substring(0, columnPosition))); ! } ! ! catch (UnknownHostException e) { ! return (null); ! } ! } ! ! /** ! * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client ! * @return int le numero du port sur lequel, on doit se connecter au serveur ! */ ! public int getServerPort() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! ! return (Integer.parseInt(host.substring(columnPosition + 1))); ! ! } ! ! /** ! * getURL permet d'obtenir l'URL du fichier multimedia que l'on souhaite visionner, cet URL est rentre dans une zone de texte sur l'interface graphique du client ! * @return String l'adresse du media demande ! */ ! public String getURL() { ! ! return (URLChoice.getText()); ! } ! ! public String getFormatPrefere() { ! ! if (formatMPEG.getState()) { ! return ("MPEG"); ! } ! ! else { ! if (formatJPEG.getState()) { ! return ("JPEG"); ! } ! else { ! return (""); ! } ! } ! ! } ! ! /** ! * setAfficheStatusBar est une methode qui permet d'afficher en bas du client un message envoye par le server ! * @param _message un message envoye sous forme de String envoye par le serveur ! */ ! public void setAfficheStatusBar(String _message) { ! statusBar.setText(_message); ! } ! ! /** ! * Client_menuFileExit_ActionAdapter, classe qui ecoute pour savoir si on clique sur le menu exit et envoie alors l'evenement ! */ ! class Client_menuFileExit_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_menuFileExit_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.menuFileExit_actionPerformed(e); ! } ! } ! ! /** ! * Client_boutongo_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton go et envoie alors l'evenement ! */ ! class Client_boutongo_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_boutongo_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! ! /** ! * Client_Menu_OpenURL_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton OpenURL et envoie alors l'evenement ! */ ! class Client_Menu_OpenURL_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_Menu_OpenURL_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! } --- 1,380 ---- ! //package madsserv_planification; ! ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.Checkbox.*; ! import java.awt.CheckboxGroup.*; ! import javax.swing.*; ! ! /** ! * <p>Title: Client </p> ! * <p>Description: La Classe Client est l'interface graphique du client</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! */ ! ! public class Client ! extends Frame { ! /** ! * Champs de la Classe Reencode ! */ ! ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelCenter = new Panel(); ! private Panel panelSouth = new Panel(); ! private Panel panelEmpty = new Panel(); ! private MenuBar menuBar1 = new MenuBar(); ! private Menu menuFile = new Menu(); ! private MenuItem menuOpenURL = new MenuItem(); ! private MenuItem menuFileExit = new MenuItem(); ! private Label statusBar = new Label(); ! private Label URLLabel = new Label(); ! private Label AdLabel = new Label(); ! ! private TextField URLChoice; ! private TextField AdServer; ! private CheckboxGroup cbg = new CheckboxGroup(); ! private Checkbox formatMPEG; ! private Checkbox formatJPEG; ! private Button go; ! ! private PlayerPanel playerPanel = null; ! ! private BorderLayout borderLayout1 = new BorderLayout(); ! private GridBagLayout gridBagLayoutNorth = new GridBagLayout(); ! private GridBagLayout gridBagLayoutSouth = new GridBagLayout(); ! ! private boolean insVideo = false; ! ! private Socket mySocket = null; ! private DialogServer dialogServer; ! ! /** ! * Contructeur de la Classe Client ! */ ! ! public Client() { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! try { ! jbInit(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * setPlayerPanel crée l'interface graphique du Client ! * @param pp il s'agit d'un PlayerPanel qui est une classe que nous avons crée ! * @vid est un booleen qui nous dit si le player a cree est de la video ou de l'audio ! */ ! ! public void setPlayerPanel(PlayerPanel pp, boolean vid) { ! Panel panelTemp; ! ! if (playerPanel == null) { ! panelTemp = panelEmpty; ! } ! else ! ! { ! panelTemp = playerPanel; ! } ! System.out.println("video :" + vid); ! System.out.println("insvideo :" + insVideo); ! ! // on teste ici pour savoir si on doit cree un player video ou un player audio ! if (vid) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! insVideo = true; ! } ! ! else if (!insVideo) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! } ! } ! ! /** ! * jbinit lance la creation de l'interface graphique. ! */ ! private void jbInit() throws Exception { ! ! contentPane = this; ! contentPane.setLayout(borderLayout1); ! this.setSize(new Dimension(240, 320)); ! this.setTitle("Madsserv Client"); ! setAfficheStatusBar("Bienvenue"); ! URLChoice = new TextField("file:///c:\\temp\\kiss_cool_1.mpeg"); ! AdServer = new TextField("dronej.rezel.com:5001"); ! menuFile.setLabel("File"); ! menuOpenURL.setLabel("Open URL"); ! menuOpenURL.addActionListener(new Client_Menu_OpenURL_ActionAdapter(this)); ! menuFileExit.setLabel("Exit"); ! menuFileExit.addActionListener(new Client_menuFileExit_ActionAdapter(this)); ! menuFile.add(menuOpenURL); ! menuFile.add(menuFileExit); ! menuBar1.add(menuFile); ! this.setMenuBar(menuBar1); ! ! formatMPEG = new Checkbox("MPEG", cbg, true); ! ! formatJPEG = new Checkbox("JPEG", cbg, false); ! ! go = new Button("Go!"); ! go.setSize(new Dimension(60, 15)); ! go.addActionListener(new Client_boutongo_ActionAdapter(this)); ! ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! panelSouth.setLayout(gridBagLayoutSouth); ! GridBagConstraints c = new GridBagConstraints(); ! c.fill = GridBagConstraints.BOTH; ! c.insets = new Insets(1, 5, 1, 5); ! c.weightx = 1.0; ! c.weighty = 1.0; ! panelSouth.add(formatMPEG, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelSouth.add(formatJPEG, c); ! c.weightx = 0.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelSouth.add(go, c); ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.weightx = 0.0; ! c.gridwidth = 2; ! panelSouth.add(statusBar, c); ! ! URLLabel.setText("URL :"); ! AdLabel.setText("Serv:"); ! URLLabel.setSize(new Dimension(30, 15)); ! URLChoice.setSize(new Dimension(30, 15)); ! AdLabel.setSize(new Dimension(30, 15)); ! AdServer.setSize(new Dimension(30, 15)); ! ! panelNorth.setLayout(gridBagLayoutNorth); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.gridwidth = 1; ! c.weightx = 0.0; ! c.weighty = 1.0; ! panelNorth.add(URLLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelNorth.add(URLChoice, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.weightx = 0.0; ! panelNorth.add(AdLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelNorth.add(AdServer, c); ! ! contentPane.add(panelSouth, BorderLayout.SOUTH); ! contentPane.add(panelNorth, BorderLayout.NORTH); ! ! contentPane.add(panelEmpty, BorderLayout.CENTER); ! ! } ! ! /** ! * menuFileExit_actionPerformed est à l'ecoute d'un evenement signifiant l'arret du client ! * @param e c'est l'evenemet qui met fin au client ! */ ! public void menuFileExit_actionPerformed(ActionEvent e) { ! try { ! String messageToSend[] = new String[1]; ! messageToSend[0] = "fin de la connexion"; ! dialogServer.sendMessage(4, messageToSend); ! System.exit(0); ! } ! catch (Exception ex) { ! System.exit(0); ! } ! } ! ! /** ! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre ! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre ! */ ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! menuFileExit_actionPerformed(null); ! } ! } ! ! /** ! * boutongo_actionPerformed Methode qui permet de lancer la connexion lorsque l'on clique sur le bouton go ! * @param evt c'est l'evenement qui indique que l'on a clique sur le bouton go ! */ ! public void boutongo_actionPerformed(ActionEvent evt) { ! ! String[] messageToSend; ! ! if (mySocket == null) { ! try { ! mySocket = new Socket(getAddressServer(), getServerPort()); ! } ! catch (Exception e) { ! showError("serveur ou port incorrect"); ! } ! ! dialogServer = new DialogServer(mySocket, this); ! dialogServer.start(); ! } ! ! else { ! // if ( (mySocket.isClosed()) == false) { ! messageToSend = new String[2]; ! messageToSend[0] = getURL(); ! messageToSend[1] = getFormatPrefere(); ! ! dialogServer.sendMessage(2, messageToSend); ! /*} ! else { ! try { ! mySocket.connect(new InetSocketAddress(getAddressServer(), ! getServerPort())); ! } ! catch (Exception e) { ! } ! }*/ ! } ! } ! ! public void endConnexion() { ! dialogServer.stop(); ! mySocket = null; ! } ! ! public void showError(String messageErreur) { ! ErrorPopUp errorPopUp = new ErrorPopUp(messageErreur, this); ! } ! ! /** ! * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client ! * @return InetAddress du server ! */ ! public InetAddress getAddressServer() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! try { ! return (InetAddress.getByName(host.substring(0, columnPosition))); ! } ! ! catch (UnknownHostException e) { ! return (null); ! } ! } ! ! /** ! * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client ! * @return int le numero du port sur lequel, on doit se connecter au serveur ! */ ! public int getServerPort() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! ! return (Integer.parseInt(host.substring(columnPosition + 1))); ! ! } ! ! /** ! * getURL permet d'obtenir l'URL du fichier multimedia que l'on souhaite visionner, cet URL est rentre dans une zone de texte sur l'interface graphique du client ! * @return String l'adresse du media demande ! */ ! public String getURL() { ! ! return (URLChoice.getText()); ! } ! ! public String getFormatPrefere() { ! ! if (formatMPEG.getState()) { ! return ("MPEG"); ! } ! ! else { ! if (formatJPEG.getState()) { ! return ("JPEG"); ! } ! else { ! return (""); ! } ! } ! ! } ! ! /** ! * setAfficheStatusBar est une methode qui permet d'afficher en bas du client un message envoye par le server ! * @param _message un message envoye sous forme de String envoye par le serveur ! */ ! public void setAfficheStatusBar(String _message) { ! statusBar.setText(_message); ! } ! ! /** ! * Client_menuFileExit_ActionAdapter, classe qui ecoute pour savoir si on clique sur le menu exit et envoie alors l'evenement ! */ ! class Client_menuFileExit_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_menuFileExit_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.menuFileExit_actionPerformed(e); ! } ! } ! ! /** ! * Client_boutongo_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton go et envoie alors l'evenement ! */ ! class Client_boutongo_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_boutongo_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! ! /** ! * Client_Menu_OpenURL_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton OpenURL et envoie alors l'evenement ! */ ! class Client_Menu_OpenURL_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_Menu_OpenURL_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! } Index: ClientRTPManager.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ClientRTPManager.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ClientRTPManager.java 15 Mar 2003 22:47:30 -0000 1.6 --- ClientRTPManager.java 17 Mar 2003 10:20:32 -0000 1.7 *************** *** 1,604 **** ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; [...1140 lines suppressed...] ! ReceiveStream stream; ! public MyPlayer(Player p, ReceiveStream strm) ! ! { ! player = p; ! stream = strm; ! } ! ! public void close() { ! player.close(); ! } ! ! public void initialize() { ! PlayerPanel pp = new PlayerPanel(player); ! client.setPlayerPanel(pp, pp.video); ! } ! ! } ! ! } // end of ClientRTPManager Index: DialogServer.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/DialogServer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** DialogServer.java 15 Mar 2003 22:47:30 -0000 1.7 --- DialogServer.java 17 Mar 2003 10:20:34 -0000 1.8 *************** *** 1,169 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! import java.lang.Object.*; ! import java.lang.System.*; ! ! /** ! * DialogServer c'est la classe qui herite de la classe dialogSocket et qui gere les dialogues avec le serveur ! */ ! public class DialogServer ! extends DialogSocket { ! ! private Client client; ! private ThreadRTPManager threadRTPManager; ! private String[] sessions = new String[2]; ! /** ! * C'est le constructeur de la classe ! */ ! public DialogServer(Socket _socketServer, Client _client) { ! super(_socketServer); ! client = _client; ! clientID = -1; ! } ! ! /** ! * incomingMessage methode qui a ete declare abstraite dans DialogSocket et qui gere l'arivee de nouveaux messages du serveur ! * @param _type type de message qui arrive (c'est un entier) ! * @param _message tableau de chaine de characteres qui contient les messages du serveur ! */ ! public void incomingMessage(int _type, String[] _message) { ! int lgth = _message.length; ! int portBase = 40000; ! String[] messageToSend; ! String sessionTemp; ! Integer port1, port2; ! ! switch (_type) { ! ! case 9: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! try { ! client.setAfficheStatusBar(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! break; ! } ! ! case 7: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! client.showError(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 5: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! System.out.println(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 3: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! /** ! *on regarde si le threadRTPManager existe, si il n'existe pas on le cree, sinon on le detruit et on en cree un nouveau ! */ ! if (threadRTPManager == null) { ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! else { ! ! threadRTPManager.Fermer(); ! threadRTPManager = null; ! System.gc(); ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! break; ! ! } ! case 1: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! // lecture du troisieme champ du message : portBase ! try { ! portBase = Integer.parseInt(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! ! /** ! * On stocke dans le variable sessions, l'adresse du server et les ports pour les diffusions audio et video ! */ ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port1 = new Integer(portBase); ! sessionTemp = sessionTemp.concat(port1.toString()); ! sessions[0] = sessionTemp; ! sessionTemp = ""; ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port2 = new Integer(portBase + 2); ! sessionTemp = sessionTemp.concat(port2.toString()); ! sessions[1] = sessionTemp; ! ! System.out.println(sessions[0]); ! System.out.println(sessions[1]); ! ! messageToSend = new String[2]; ! ! messageToSend[0] = client.getURL(); ! messageToSend[1] = client.getFormatPrefere(); ! ! sendMessage(2, messageToSend); ! } ! } ! } } --- 1,196 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! import java.lang.Object.*; ! import java.lang.System.*; ! ! /** ! * DialogServer c'est la classe qui herite de la classe dialogSocket et qui gere les dialogues avec le serveur ! */ ! public class DialogServer ! extends DialogSocket { ! ! private Client client; ! private ThreadRTPManager threadRTPManager; ! private String[] sessions = new String[2]; ! /** ! * C'est le constructeur de la classe ! */ ! public DialogServer(Socket _socketServer, Client _client) { ! super(_socketServer); ! client = _client; ! clientID = -1; ! } ! ! /** ! * incomingMessage methode qui a ete declare abstraite dans DialogSocket et qui gere l'arrivee de nouveaux messages du serveur ! * @param _type type de message qui arrive (c'est un entier) ! * @param _message tableau de chaine de characteres qui contient les messages du serveur ! */ ! public void incomingMessage(int _type, String[] _message) { ! int lgth = _message.length; ! int portBase = 40000; ! double mediaTime; ! String messageTime; ! String[] messageToSend; ! String sessionTemp; ! Integer port1, port2; ! ! switch (_type) { ! ! case 11: { ! ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! try { ! client.setAfficheStatusBar(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! break; ! } ! ! case 9: { ! ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! client.showError(_message[1]); ! break; ! } ! ! case 7: { ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! mediaTime = threadRTPManager.getCurrentMediaTime(); ! messageTime = String.valueOf(mediaTime); ! messageToSend = new String[1]; ! messageToSend[0] = messageTime; ! ! sendMessage(8, messageToSend); ! break; ! } ! ! case 5: { ! ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! try { ! client.setAfficheStatusBar(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! ! if (clientID != -1) { ! threadRTPManager.Fermer(); ! client.endConnexion(); ! } ! break; ! } ! ! case 3: { ! ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! try { ! client.setAfficheStatusBar(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! ! /** ! *on regarde si le threadRTPManager existe, si il n'existe pas on le cree, sinon on le detruit et on en cree un nouveau ! */ ! if (threadRTPManager == null) { ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! else { ! ! threadRTPManager.Fermer(); ! threadRTPManager = null; ! System.gc(); ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! break; ! ! } ! case 1: { ! ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! // lecture du troisieme champ du message : portBase ! try { ! portBase = Integer.parseInt(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! ! /** ! * On stocke dans le variable sessions, l'adresse du server et les ports pour les diffusions audio et video ! */ ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port1 = new Integer(portBase); ! sessionTemp = sessionTemp.concat(port1.toString()); ! sessions[0] = sessionTemp; ! sessionTemp = ""; ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port2 = new Integer(portBase + 2); ! sessionTemp = sessionTemp.concat(port2.toString()); ! sessions[1] = sessionTemp; ! ! System.out.println(sessions[0]); ! System.out.println(sessions[1]); ! ! messageToSend = new String[2]; ! ! messageToSend[0] = client.getURL(); ! messageToSend[1] = client.getFormatPrefere(); ! ! sendMessage(2, messageToSend); ! } ! } ! } } Index: DialogSocket.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/DialogSocket.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DialogSocket.java 13 Mar 2003 23:27:36 -0000 1.2 --- DialogSocket.java 17 Mar 2003 10:20:37 -0000 1.3 *************** *** 57,61 **** /*catch (SocketException e) { System.out.println(e.getMessage()); ! }*/ } --- 57,61 ---- /*catch (SocketException e) { System.out.println(e.getMessage()); ! }*/ } *************** *** 131,136 **** //binput.close(); //System.err.println("le binput est mort"); ! if (!mySocket.isClosed()) mySocket.close(); System.err.println("le socket est mort"); //System.err.println("le socket est ferme " + mySocket.isClosed()); --- 131,137 ---- //binput.close(); //System.err.println("le binput est mort"); ! if (!mySocket.isClosed()) { mySocket.close(); + } System.err.println("le socket est mort"); //System.err.println("le socket est ferme " + mySocket.isClosed()); Index: ErrorPopUp.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ErrorPopUp.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ErrorPopUp.java 15 Mar 2003 22:47:30 -0000 1.3 --- ErrorPopUp.java 17 Mar 2003 10:20:38 -0000 1.4 *************** *** 1,112 **** ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.geom.Point2D.*; ! import java.awt.Point.*; ! ! /** ! * <code>ErrorPopUp</code> est une popup qui apparait lorsque des erreurs apparaissent. ! * @author Xavier Deplancq ! */ ! ! public class ErrorPopUp ! extends Frame { ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelSouth = new Panel(); ! private Label errorMessage = new Label(); ! private BorderLayout borderLayout1 = new BorderLayout(); ! private Button OK; ! ! /** ! * Constructeur de la classe ErrorPopUp ! * @param errMessage le Message qui doit etre affiche ! * @param _client la reference du client ! */ ! ! public ErrorPopUp(String errMessage, Client _client) { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! errorMessage.setText(errMessage); ! panelNorth.add(errorMessage); ! OK = new Button("OK"); ! OK.setSize(new Dimension(60, 15)); ! OK.addActionListener(new ErrorPopUp_OK_ActionAdapter(this)); ! panelSouth.add(OK); ! contentPane = this; ! this.setSize(240, 120); ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! contentPane.setLayout(borderLayout1); ! contentPane.add(panelNorth, borderLayout1.CENTER); ! contentPane.add(panelSouth, borderLayout1.SOUTH); ! ! //On place la boite de dialogue ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension clientSize = _client.getSize(); ! Dimension popupSize = this.getSize(); ! double clientPlaceX = _client.getX(); ! double clientPlaceY = _client.getY(); ! if (popupSize.height > clientSize.height) { ! popupSize.height = clientSize.height; ! } ! if (popupSize.width > clientSize.width) { ! popupSize.width = clientSize.width; ! } ! this.setLocation( (int) (clientPlaceX), ! (int) (clientPlaceY) + clientSize.width / 2); ! ! showWindow(); ! ! } ! ! /** ! * OK_actionPerformed qui sert lorsque l'on appuie sur le bouton OK ! * @param e l'evenement ! */ ! ! public void OK_actionPerformed(ActionEvent e) { ! setVisible(false); ! } ! ! /** ! * processWindowEvent c est une methode qui est appele lorsque l'on ferme la boite de dialogue ! * @param l evenement qui indique que l'on ferme la fenetre ! */ ! ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! OK_actionPerformed(null); ! } ! } ! ! /** ! * Methode qui affiche la boite de dialogue ! */ ! ! public void showWindow() { ! setVisible(true); ! } ! ! /** ! * Classe qui ecoute si l'on appui sur le bouton OK ! */ ! ! class ErrorPopUp_OK_ActionAdapter ! implements ActionListener { ! ErrorPopUp adaptee; ! ! ErrorPopUp_OK_ActionAdapter(ErrorPopUp adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.OK_actionPerformed(e); ! } ! } ! ! } --- 1,112 ---- ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.geom.Point2D.*; ! import java.awt.Point.*; ! ! /** ! * <code>ErrorPopUp</code> est une popup qui apparait lorsque des erreurs apparaissent. ! * @author Xavier Deplancq ! */ ! ! public class ErrorPopUp ! extends Frame { ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelSouth = new Panel(); ! private Label errorMessage = new Label(); ! private BorderLayout borderLayout1 = new BorderLayout(); ! private Button OK; ! ! /** ! * Constructeur de la classe ErrorPopUp ! * @param errMessage le Message qui doit etre affiche ! * @param _client la reference du client ! */ ! ! public ErrorPopUp(String errMessage, Client _client) { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! errorMessage.setText(errMessage); ! panelNorth.add(errorMessage); ! OK = new Button("OK"); ! OK.setSize(new Dimension(60, 15)); ! OK.addActionListener(new ErrorPopUp_OK_ActionAdapter(this)); ! panelSouth.add(OK); ! contentPane = this; ! this.setSize(240, 120); ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! contentPane.setLayout(borderLayout1); ! contentPane.add(panelNorth, borderLayout1.CENTER); ! contentPane.add(panelSouth, borderLayout1.SOUTH); ! ! //On place la boite de dialogue ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension clientSize = _client.getSize(); ! Dimension popupSize = this.getSize(); ! double clientPlaceX = _client.getX(); ! double clientPlaceY = _client.getY(); ! if (popupSize.height > clientSize.height) { ! popupSize.height = clientSize.height; ! } ! if (popupSize.width > clientSize.width) { ! popupSize.width = clientSize.width; ! } ! this.setLocation( (int) (clientPlaceX), ! (int) (clientPlaceY) + clientSize.width / 2); ! ! showWindow(); ! ! } ! ! /** ! * OK_actionPerformed qui sert lorsque l'on appuie sur le bouton OK ! * @param e l'evenement ! */ ! ! public void OK_actionPerformed(ActionEvent e) { ! setVisible(false); ! } ! ! /** ! * processWindowEvent c est une methode qui est appele lorsque l'on ferme la boite de dialogue ! * @param l evenement qui indique que l'on ferme la fenetre ! */ ! ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! OK_actionPerformed(null); ! } ! } ! ! /** ! * Methode qui affiche la boite de dialogue ! */ ! ! public void showWindow() { ! setVisible(true); ! } ! ! /** ! * Classe qui ecoute si l'on appui sur le bouton OK ! */ ! ! class ErrorPopUp_OK_ActionAdapter ! implements ActionListener { ! ErrorPopUp adaptee; ! ! ErrorPopUp_OK_ActionAdapter(ErrorPopUp adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.OK_actionPerformed(e); ! } ! } ! ! } Index: MadsservClient.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/MadsservClient.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MadsservClient.java 15 Mar 2003 22:47:30 -0000 1.6 --- MadsservClient.java 17 Mar 2003 10:20:39 -0000 1.7 *************** *** 1,75 **** ! //package madsserv_planification; ! ! import javax.swing.UIManager; ! import java.awt.*; ! import java.net.*; ! ! /** ! * <p>Title: MadsservClient</p> ! * <p>Description: La Classe MadsservClient contient la classe main du client du projet, c'est lui qui le lance</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! **/ ! ! /** ! * MadsservClient c'est la classe MadsservClient ! */ ! public class MadsservClient { ! /** ! * champs de la classe MadsservClient ! */ ! private boolean packFrame = false; ! ! /** ! * MadsservClient constructeur de la calsse ! */ ! public MadsservClient() { ! ! Client frame = new Client(); ! ! //Validate frames that have preset sizes ! //Pack frames that have useful preferred size info, e.g. from their layout ! if (packFrame) { ! frame.pack(); ! } ! else { ! frame.validate(); ! } ! ! //on centre ici la fenetre ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension frameSize = frame.getSize(); ! if (frameSize.height > screenSize.height) { ! frameSize.height = screenSize.height; ! } ! if (frameSize.width > screenSize.width) { ! frameSize.width = screenSize.width; ! } ! frame.setLocation( (screenSize.width - frameSize.width) / 2, ! (screenSize.height - frameSize.height) / 2); ! frame.setVisible(true); ! } ! ! /** ! * Methode main de MadsservClient ! */ ! ! public static void main(String[] args) { ! try { ! UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! new MadsservClient(); ! } ! ! static void prUsage() { ! System.err.println("Usage: ClientRTPManager <session> <session> ..."); ! System.err.println(" <session>: <address>/<port>/<ttl>"); ! System.exit(0); ! } ! } --- 1,75 ---- ! //package madsserv_planification; ! ! import javax.swing.UIManager; ! import java.awt.*; ! import java.net.*; ! ! /** ! * <p>Title: MadsservClient</p> ! * <p>Description: La Classe MadsservClient contient la classe main du client du projet, c'est lui qui le lance</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! **/ ! ! /** ! * MadsservClient c'est la classe MadsservClient ! */ ! public class MadsservClient { ! /** ! * champs de la classe MadsservClient ! */ ! private boolean packFrame = false; ! ! /** ! * MadsservClient constructeur de la calsse ! */ ! public MadsservClient() { ! ! Client frame = new Client(); ! ! //Validate frames that have preset sizes ! //Pack frames that have useful preferred size info, e.g. from their layout ! if (packFrame) { ! frame.pack(); ! } ! else { ! frame.validate(); ! } ! ! //on centre ici la fenetre ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension frameSize = frame.getSize(); ! if (frameSize.height > screenSize.height) { ! frameSize.height = screenSize.height; ! } ! if (frameSize.width > screenSize.width) { ! frameSize.width = screenSize.width; ! } ! frame.setLocation( (screenSize.width - frameSize.width) / 2, ! (screenSize.height - frameSize.height) / 2); ! frame.setVisible(true); ! } ! ! /** ! * Methode main de MadsservClient ! */ ! ! public static void main(String[] args) { ! try { ! UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! new MadsservClient(); ! } ! ! static void prUsage() { ! System.err.println("Usage: ClientRTPManager <session> <session> ..."); ! System.err.println(" <session>: <address>/<port>/<ttl>"); ! System.exit(0); ! } ! } Index: PlayerPanel.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/PlayerPanel.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PlayerPanel.java 15 Mar 2003 22:47:30 -0000 1.5 --- PlayerPanel.java 17 Mar 2003 10:20:41 -0000 1.6 *************** *** 1,66 **** ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.AudioFormat; ! import javax.media.format.VideoFormat; ! import javax.media.Format; ! import javax.media.format.FormatChangeEvent; ! import javax.media.control.BufferControl; ! ! /** ! * Classe playerpanel qui crée l'interphace graphique des players ! * @author : Xavier Deplancq ! */ ! public class PlayerPanel ! extends Panel { ! /** ! * champs de la classe ! */ ! private Component vc, cc; ! // champs qui est mis à true lorsque l'on doit crée l'interface du player video ! boolean video = false; ! ! PlayerPanel(Player p) { ! setLayout(new BorderLayout()); ! //on regarde si c'est un flux video qui arrive ! if ( (vc = p.getVisualComponent()) != null) { ! add("Center", vc); ! video = true; ! } ! if ( (cc = p.getControlPanelComponent()) != null) { ! add("South", cc); ! } ! } ! /** ! * getPrefferedSize methode qui retourne les dimensions du player ! * @return Dimension, celles du player ! */ ! public Dimension getPreferredSize() { ! int w = 0, h = 0; ! if (vc != null) { ! Dimension size = vc.getPreferredSize(); ! w = size.width; ! h = size.height; ! } ! if (cc != null) { ! Dimension size = cc.getPreferredSize(); ! if (w == 0) { ! w = size.width; ! } ! h += size.height; ! } ! if (w < 160) { ! w = 160; ! } ! return new Dimension(w, h); ! } ! } --- 1,67 ---- ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.AudioFormat; ! import javax.media.format.VideoFormat; ! import javax.media.Format; ! import javax.media.format.FormatChangeEvent; ! import javax.media.control.BufferControl; ! ! /** ! * Classe playerpanel qui crée l'interphace graphique des players ! * @author : Xavier Deplancq ! */ ! public class PlayerPanel ! extends Panel { ! /** ! * champs de la classe ! */ ! private Component vc, cc; ! // champs qui est mis à true lorsque l'on doit crée l'interface du player video ! boolean video = false; ! ! PlayerPanel(Player p) { ! setLayout(new BorderLayout()); ! //on regarde si c'est un flux video qui arrive ! if ( (vc = p.getVisualComponent()) != null) { ! add("Center", vc); ! video = true; ! } ! if ( (cc = p.getControlPanelComponent()) != null) { ! add("South", cc); ! } ! } ! ! /** ! * getPrefferedSize methode qui retourne les dimensions du player ! * @return Dimension, celles du player ! */ ! public Dimension getPreferredSize() { ! int w = 0, h = 0; ! if (vc != null) { ! Dimension size = vc.getPreferredSize(); ! w = size.width; ! h = size.height; ! } ! if (cc != null) { ! Dimension size = cc.getPreferredSize(); ! if (w == 0) { ! w = size.width; ! } ! h += size.height; ! } ! if (w < 160) { ! w = 160; ! } ! return new Dimension(w, h); ! } ! } Index: ThreadRTPManager.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRTPManager.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ThreadRTPManager.java 15 Mar 2003 22:47:30 -0000 1.7 --- ThreadRTPManager.java 17 Mar 2003 10:20:43 -0000 1.8 *************** *** 1,51 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * ThreadRTPManager est une methode qui cree un clientRTPManager ! * @author : Xavier Deplancq ! */ ! public class ThreadRTPManager extends Thread { ! ! /** ! * champs de la classe ClientRTPManager ! */ ! private ClientRTPManager clientRTPManager; ! private Client cl; ! ! public ThreadRTPManager(String sessionServer[], Client cl) ! { ! clientRTPManager = new ClientRTPManager(sessionServer, cl); ! } ! ! /** ! * methode run de ce thread ! */ ! public void Fermer() ! { ! clientRTPManager.close(); ! } ! ! public void run() ! { ! if (!clientRTPManager.initialize()) { ! System.err.println("Failed to initialize the sessions."); ! System.exit( -1); ! } ! ! try { ! while (!clientRTPManager.isDone()) ! Thread.sleep(1000); ! } ! catch (Exception e) { ! cl.showError("La connexion n'a pas pu etre initialise"); ! } ! ! finally { ! ! System.err.println("Exiting ThreadRTPManager"); ! System.out.println(Thread.currentThread()); ! } ! } ! } --- 1,54 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * ThreadRTPManager est une methode qui cree un clientRTPManager ! * @author : Xavier Deplancq ! */ ! public class ThreadRTPManager ! extends Thread { ! ! /** ! * champs de la classe ClientRTPManager ! */ ! private ClientRTPManager clientRTPManager; ! private Client cl; ! ! public ThreadRTPManager(String sessionServer[], Client cl) { ! clientRTPManager = new ClientRTPManager(sessionServer, cl); ! } ! ! /** ! * methode run de ce thread ! */ ! public void Fermer() { ! clientRTPManager.close(); ! } ! ! public double getCurrentMediaTime() { ! return clientRTPManager.currentMediaTime(); ! } ! ! public void run() { ! if (!clientRTPManager.initialize()) { ! System.err.println("Failed to initialize the sessions."); ! System.exit( -1); ! } ! ! try { ! while (!clientRTPManager.isDone()) { ! Thread.sleep(1000); ! } ! } ! catch (Exception e) { ! cl.showError("La connexion n'a pas pu etre initialise"); ! } ! ! finally { ! ! System.err.println("Exiting ThreadRTPManager"); ! System.out.println(Thread.currentThread()); ! } ! } ! } Index: ThreadRead.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRead.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ThreadRead.java 15 Mar 2003 22:47:30 -0000 1.4 --- ThreadRead.java 17 Mar 2003 10:20:43 -0000 1.5 *************** *** 1,98 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. ! * Il effectue une ecoute permanente. ! * <p> ! * Il gere l'extraction du message en isolant les elements protocolaires de la ! * transmission du message. ! * @see ThreadWrite ! * @see DialogSocket ! * @author Julien Carbonell ! */ ! ! public class ThreadRead ! extends Thread { ! ! boolean end = false; ! ! // objet parent qui gere les entrees-sorties sur le socket ! protected DialogSocket parent; ! ! // BufferedReader sur lequel sont lus les messages ! protected BufferedReader binput; ! ! protected String temp = ""; ! protected String message = ""; ! protected boolean waitingMessage = true; ! protected int messageType = -1; ! ! /** ! * Constructeur de <code>ThreadRead</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. ! */ ! public ThreadRead(String _name, BufferedReader _binput, ! DialogSocket _parent) { ! super(_name + _parent.getClientID()); ! parent = _parent; ! binput = _binput; ! } ! ! /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. ! */ ! public void run() { ! try { ! while ( (temp = binput.readLine()) != null) { ! if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; ! } ! else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; ! } ! else { ! message = message.concat(temp + "\n"); ! } ! } ! } ! ! } ! } ! /* catch (SocketTimeoutException e) { ! System.out.println(e.getMessage()); ! }*/ ! catch (Exception e) { ! e.printStackTrace(); ! } ! finally { ! try { ! // binput.close(); ! System.out.println(getName() + Thread.currentThread() + ! " : Stopped !!! "); ! } ! catch (Exception e) { ! System.out.println(e.getMessage()); ! } ! } ! ! } ! ! protected String[] parseMessage(String _message) { ! return _message.split("\n"); ! } ! } --- 1,98 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. ! * Il effectue une ecoute permanente. ! * <p> ! * Il gere l'extraction du message en isolant les elements protocolaires de la ! * transmission du message. ! * @see ThreadWrite ! * @see DialogSocket ! * @author Julien Carbonell ! */ ! ! public class ThreadRead ! extends Thread { ! ! boolean end = false; ! ! // objet parent qui gere les entrees-sorties sur le socket ! protected DialogSocket parent; ! ! // BufferedReader sur lequel sont lus les messages ! protected BufferedReader binput; ! ! protected String temp = ""; ! protected String message = ""; ! protected boolean waitingMessage = true; ! protected int messageType = -1; ! ! /** ! * Constructeur de <code>ThreadRead</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. ! */ ! public ThreadRead(String _name, BufferedReader _binput, ! DialogSocket _parent) { ! super(_name + _parent.getClientID()); ! parent = _parent; ! binput = _binput; ! } ! ! /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. ! */ ! public void run() { ! try { ! while ( (temp = binput.readLine()) != null) { ! if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; ! } ! else { ! if (!waitingMessage && (temp... [truncated message content] |
|
From: <car...@us...> - 2003-03-17 03:55:20
|
Update of /cvsroot/madsserv/madsserv/src/server
In directory sc8-pr-cvs1:/tmp/cvs-serv31263
Modified Files:
DialogClient.java DialogSocket.java ServerFrame.java
ServerInit.java ThreadListenClients.java
Log Message:
amelioration de l'interface graphique et prise en compte du nouveau reencode
Index: DialogClient.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/DialogClient.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DialogClient.java 14 Mar 2003 03:26:18 -0000 1.5
--- DialogClient.java 17 Mar 2003 03:55:17 -0000 1.6
***************
*** 47,50 ****
--- 47,64 ----
mySocket.getInetAddress().getHostAddress().toString());
}
+ else {
+ String[] warning = new String[1];
+
+ warning[0] = "Trop de clients connectés au serveur.";
+ System.out.println("Envoi du message " + warning[0]);
+ sendMessage(9, warning);
+ try {
+ Thread.sleep(1000);
+ }
+ catch (Exception e) {
+
+ }
+ this.stop();
+ }
}
***************
*** 55,59 ****
* @param _type le type du message.
* @param _message le tableau de <code>String</code> contenant les champs du
! * message reçu.
*/
--- 69,73 ----
* @param _type le type du message.
* @param _message le tableau de <code>String</code> contenant les champs du
! * message recu.
*/
***************
*** 66,69 ****
--- 80,84 ----
switch (_type) {
case 2: {
+ String[] messageToSend = new String[1];
// if (lgth < 3) raise exception;
serverInit.setMediaAddress(clientID, _message[1]);
***************
*** 74,83 ****
System.out.println("Nouveau format prefere pour le client " +
clientID + ": " + _message[2]);
! sendMessage(3, null);
serverInit.startStreaming(clientID);
break;
}
case 4: {
! serverInit.endConnexion(clientID);
break;
}
--- 89,106 ----
System.out.println("Nouveau format prefere pour le client " +
clientID + ": " + _message[2]);
! messageToSend[0] = "Connexion du client " + String.valueOf(clientID);
! sendMessage(3, messageToSend);
serverInit.startStreaming(clientID);
break;
}
case 4: {
! serverInit.endConnexionClient(clientID);
! break;
! }
! case 8: {
! double currentMediaTime;
! //clientID = Integer.parseInt(_message[0]);
! currentMediaTime = Double.parseDouble(_message[1]);
! serverInit.setCurrentMediaTime(clientID, currentMediaTime);
break;
}
Index: DialogSocket.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/DialogSocket.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** DialogSocket.java 13 Mar 2003 02:38:49 -0000 1.2
--- DialogSocket.java 17 Mar 2003 03:55:17 -0000 1.3
***************
*** 19,23 ****
public abstract class DialogSocket {
! private final int TIME_OUT = 1000;
// identite du client
--- 19,23 ----
public abstract class DialogSocket {
! // private final int TIME_OUT = 1000;
// identite du client
***************
*** 65,69 ****
* @param _type le type du message.
* @param _message le tableau de <code>String</code> contenant les champs du
! * message reçu.
*/
--- 65,69 ----
* @param _type le type du message.
* @param _message le tableau de <code>String</code> contenant les champs du
! * message reçu.
*/
***************
*** 128,132 ****
//threadInput.setEnd();
System.err.println("le thread est mort");
! Thread.sleep(1000);
//binput.close();
//System.err.println("le binput est mort");
--- 128,132 ----
//threadInput.setEnd();
System.err.println("le thread est mort");
! //Thread.sleep(1000);
//binput.close();
//System.err.println("le binput est mort");
Index: ServerFrame.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/ServerFrame.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ServerFrame.java 14 Mar 2003 03:27:20 -0000 1.1
--- ServerFrame.java 17 Mar 2003 03:55:17 -0000 1.2
***************
*** 1,353 ****
! import javax.swing.*;
! import java.awt.*;
! import java.net.*;
! import java.awt.event.*;
! import java.awt.Component.*;
! import java.awt.TextComponent.*;
! import java.awt.Checkbox.*;
! import java.awt.CheckboxGroup.*;
! import java.util.*;
!
! public class ServerFrame
! extends JFrame {
!
! Container contentPane = null;
! ServerInit serverInit = null;
!
! BorderLayout borderLayout1 = new BorderLayout();
! GridLayout gridLayout1 = new GridLayout(4, 2, 5, 5);
! GridLayout gridLayout2 = new GridLayout(1, 1);
! GridBagLayout gridBagLayout2 = new GridBagLayout();
! GridBagConstraints c;
!
! Vector clientReports;
! JPanel jPanelTitles = new JPanel();
! JLabel jLabelID = new JLabel();
! JLabel jLabelIP = new JLabel();
! JLabel jLabelStatus = new JLabel();
! JLabel jLabelMedia = new JLabel();
! JLabel jLabelBitRate = new JLabel();
! JLabel jLabelQuality = new JLabel();
!
! JTabbedPane jTabbedPane = new JTabbedPane();
! JPanel jPanelConfig = new JPanel();
! JPanel jPanelReport = new JPanel();
! JPanel jPanelFormats = new JPanel();
! JPanel jPanelQuality = new JPanel();
!
! JPanel jPanelSouth = new JPanel();
!
! JLabel jLabelPort = new JLabel();
! JLabel jLabelPortRTP = new JLabel();
! JLabel jLabelNbMax = new JLabel();
! JLabel jLabelDebit = new JLabel();
! JTextField jTextFieldPort = new JTextField();
! JTextField jTextFieldPortRTP = new JTextField();
! JTextField jTextFieldNbMax = new JTextField();
! JTextField jTextFieldDebit = new JTextField();
!
! JButton jButtonStart = new JButton();
! JButton jButtonStop = new JButton();
! JButton jButtonQuit = new JButton();
!
! public ServerFrame( /*ServerInit _parent*/) {
! //parent = _parent;
! contentPane = getContentPane();
! contentPane.setLayout(borderLayout1);
! this.setSize(new Dimension(600, 500));
! this.setTitle("Madsserv Serveur");
!
! clientReports = new Vector();
! jPanelReport.setLayout(gridBagLayout2);
! jPanelReport.setBackground(Color.black);
! c = new GridBagConstraints();
! c.weightx = 0.0;
! jLabelID.setText("ID Client");
! jLabelID.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelID, c);
! jLabelIP.setText("IP Client");
! jLabelIP.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelIP, c);
! jLabelStatus.setText("Statut");
! jLabelStatus.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelStatus, c);
! jLabelMedia.setText("Media demandé");
! jLabelMedia.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelMedia, c);
! jLabelBitRate.setText("Débit");
! jLabelBitRate.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelTitles.add(jLabelBitRate, c);
! jLabelQuality.setText("Niveau de qualité");
! jLabelQuality.setHorizontalAlignment(SwingConstants.CENTER);
! c.gridwidth = GridBagConstraints.REMAINDER;
! jPanelTitles.add(jLabelQuality, c);
! jPanelReport.add(jPanelTitles);
!
! jTabbedPane.addTab("Configuration", null, jPanelConfig,
! "Configure le serveur");
! jTabbedPane.addTab("Rapports", null, jPanelReport, "Affiche les connexions");
! jTabbedPane.addTab("Formats", null, jPanelFormats,
! "Affiche les formats supportés par le serveur");
! jTabbedPane.addTab("Qualité", null, jPanelQuality,
! "Affiche l'association format/niveau de qualité");
! contentPane.add(jTabbedPane, BorderLayout.CENTER);
!
! jLabelPort.setText("Port d'écoute :");
! jTextFieldPort.setText("5000");
! jLabelPortRTP.setText("Port de base pour RTP :");
! jTextFieldPortRTP.setText("40000");
! jLabelNbMax.setText("Nombre maximum de clients :");
! jTextFieldNbMax.setText("10");
! jLabelDebit.setText("Debit minimum en Ko/s :");
! jTextFieldDebit.setText("20");
!
! jPanelConfig.setLayout(gridLayout1);
! jPanelConfig.add(jLabelPort);
! jPanelConfig.add(jTextFieldPort);
! jPanelConfig.add(jLabelPortRTP);
! jPanelConfig.add(jTextFieldPortRTP);
! jPanelConfig.add(jLabelNbMax);
! jPanelConfig.add(jTextFieldNbMax);
! jPanelConfig.add(jLabelDebit);
! jPanelConfig.add(jTextFieldDebit);
!
! jButtonStart.setText("Démarrer");
! jButtonStart.setEnabled(true);
! jButtonStart.addActionListener(new ServerFrame_Button_Start_ActionAdapter(this));
! jPanelSouth.add(jButtonStart);
! jButtonStop.setText("Arrêter");
! jButtonStop.setEnabled(false);
! jButtonStop.addActionListener(new ServerFrame_Button_Stop_ActionAdapter(this));
! jPanelSouth.add(jButtonStop);
! jButtonQuit.setText("Quitter");
! jButtonQuit.addActionListener(new ServerFrame_Button_Quit_ActionAdapter(this));
! jPanelSouth.add(jButtonQuit);
! contentPane.add(jPanelSouth, BorderLayout.SOUTH);
! }
!
! public void Button_Start_actionPerformed(ActionEvent evt) {
! int port = 5000;
! int portBaseRTP = 40000;
! int nbClients = 10;
! int debit = 20;
! Integer integer1 = null;
! Integer integer2 = null;
! Integer integer3 = null;
! Integer integer4 = null;
!
! try {
! integer1 = Integer.valueOf(jTextFieldPort.getText());
! integer2 = Integer.valueOf(jTextFieldPortRTP.getText());
! integer3 = Integer.valueOf(jTextFieldNbMax.getText());
! integer4 = Integer.valueOf(jTextFieldDebit.getText());
! if (integer1 == null || integer2 == null || integer3 == null || integer3 == null) {
! System.err.println("il y a une erreur");
! displayError("Erreur de saisie",
! "La valeur d'un champ est incorrecte.\nVeuillez la modifier");
! }
! else {
! port = integer1.intValue();
! portBaseRTP = integer2.intValue();
! nbClients = integer3.intValue();
! debit = integer4.intValue();
! }
! }
! catch (NumberFormatException e) {
! displayError("Erreur de saisie",
! "La valeur d'un champ est incorrecte.\nVeuillez la modifier");
! }
! if (serverInit == null) {
! try {
! serverInit = new ServerInit(port, portBaseRTP, nbClients, debit, this);
! serverInit.start();
! jButtonStart.setEnabled(false);
! jButtonStop.setEnabled(true);
! }
! catch (ErrNoListen e) {
! serverInit = null;
! // lancer erreur popup
! jButtonStart.setEnabled(true);
! jButtonStop.setEnabled(false);
! }
! }
! else {
! System.err.println("ServerInit est deja cree");
! }
!
! }
!
! public void displayError(String _name, String _message) {
! JOptionPane.showMessageDialog(this, _message, _name,
! JOptionPane.WARNING_MESSAGE);
! }
!
! public void addClientReport(ClientReport _clientReport) {
! int rows, columns;
! rows = gridLayout2.getRows() + 1;
! gridLayout2.setRows(rows);
! jPanelReport.add(_clientReport.getGraphics());
! }
!
! public void Button_Stop_actionPerformed(ActionEvent evt) {
! serverInit.stop();
! }
!
! public void Button_Quit_actionPerformed(ActionEvent evt) {
! System.exit(0);
! }
!
! /**
! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre
! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre
! */
! protected void processWindowEvent(WindowEvent e) {
! super.processWindowEvent(e);
! if (e.getID() == WindowEvent.WINDOW_CLOSING) {
! Button_Quit_actionPerformed(null);
! }
! }
!
! public static void main(String[] args) {
! ServerFrame serverFrame = new ServerFrame();
! serverFrame.pack();
! //Center the window
! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
! Dimension frameSize = serverFrame.getSize();
! if (frameSize.height > screenSize.height) {
! frameSize.height = screenSize.height;
! }
! if (frameSize.width > screenSize.width) {
! frameSize.width = screenSize.width;
! }
! serverFrame.setLocation( (screenSize.width - frameSize.width) / 2,
! (screenSize.height - frameSize.height) / 2);
!
! serverFrame.show();
! }
!
! }
!
! class ServerFrame_Button_Start_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Start_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Start_actionPerformed(evt);
! }
! }
!
! class ServerFrame_Button_Stop_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Stop_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Stop_actionPerformed(evt);
! }
! }
!
! class ServerFrame_Button_Quit_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Quit_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Quit_actionPerformed(evt);
! }
! }
!
! class ClientReport {
!
! private int clientID = -1;
! private String clientIP = "";
! private String status = "";
! private String media = "";
! private float debit = 0.0f;
! private int qualityLevel = -1;
!
! private JLabel jLabelID = new JLabel();
! private JLabel jLabelIP = new JLabel();
! private JLabel jLabelStatus = new JLabel();
! private JLabel jLabelMedia = new JLabel();
! private JLabel jLabelDebit = new JLabel();
! private JLabel jLabelQuality = new JLabel();
!
! // constructeurs
! public ClientReport(int _clientID, String _IP, String _status) {
! clientID = _clientID;
! clientIP = _IP;
! status = _status;
! }
!
! public ClientReport(int _clientID, String _IP, String _status, String _media,
! int _qualityLevel) {
! clientID = _clientID;
! clientIP = _IP;
! status = _status;
! media = _media;
! qualityLevel = _qualityLevel;
! }
!
! public synchronized void setStatus(String _status) {
! status = _status;
! }
!
! public synchronized void setMedia(String _media) {
! media = _media;
! }
!
! public synchronized void setDebit(float _debit) {
! debit = _debit;
! }
!
! public synchronized void setQualityLevel(int _quality) {
! qualityLevel = _quality;
! }
!
! public JPanel getGraphics() {
! JPanel jPanelReturn = new JPanel();
! GridBagLayout gridBagLayout = new GridBagLayout();
! GridBagConstraints c = new GridBagConstraints();
! c.weightx = 1.0;
!
! jLabelID.setText(String.valueOf(clientID));
! jLabelID.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelID, c);
! jLabelIP.setText(clientIP);
! jLabelIP.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelIP, c);
! jLabelStatus.setText(status);
! jLabelStatus.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelStatus, c);
! jLabelMedia.setText(media);
! jLabelMedia.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelMedia, c);
! jLabelDebit.setText(String.valueOf(debit));
! jLabelDebit.setHorizontalAlignment(SwingConstants.CENTER);
! jPanelReturn.add(jLabelDebit, c);
! jLabelQuality.setText(String.valueOf(qualityLevel));
! jLabelQuality.setHorizontalAlignment(SwingConstants.CENTER);
! c.gridwidth = GridBagConstraints.REMAINDER;
! jPanelReturn.add(jLabelQuality);
!
! return jPanelReturn;
! }
!
! public void removeClientReport() {
!
! }
!
! public void updateClientReport() {
!
! }
! }
--- 1,456 ----
! import javax.swing.*;
! import java.awt.*;
! import java.net.*;
! import java.awt.event.*;
! import java.awt.Component.*;
! import java.awt.TextComponent.*;
! import java.awt.Checkbox.*;
! import java.awt.CheckboxGroup.*;
! import java.util.*;
! import javax.swing.table.*;
! import javax.swing.border.*;
!
! public class ServerFrame
! extends JFrame {
!
! protected ServerInit serverInit = null;
!
! // Table graphique pour l'etat des connexions
! TableClients tableClients = new TableClients();
!
! Container contentPane = null;
!
! // Declaration et instanciation des Layouts.
! BorderLayout borderLayout1 = new BorderLayout();
! // GridLayout gridLayout1 = new GridLayout(5, 2, 5, 5);
! // GridLayout gridLayout2 = new GridLayout(1, 1);
! GridBagLayout gridBagLayout1 = new GridBagLayout();
! //GridBagLayout gridBagLayout2 = new GridBagLayout();
! GridBagConstraints c = new GridBagConstraints();
!
! /*
! JPanel jPanelTitles = new JPanel();
! JLabel jLabelID = new JLabel();
! JLabel jLabelIP = new JLabel();
! JLabel jLabelStatus = new JLabel();
! JLabel jLabelMedia = new JLabel();
! JLabel jLabelBitRate = new JLabel();
! JLabel jLabelQuality = new JLabel();*/
!
! // Declaration et instanciation du JTabbedPane;
! JTabbedPane jTabbedPane = new JTabbedPane();
! JPanel jPanelConfig = new JPanel();
! JPanel jPanelReport = new JPanel();
! JPanel jPanelFormats = new JPanel();
! JPanel jPanelQuality = new JPanel();
!
! // Declaration et instanciation du JPanel destine aux boutons
! JPanel jPanelSouth = new JPanel();
!
! // Declaration et instanciation des elements graphiques de l'onglet Configuration
! JLabel jLabelPort = new JLabel();
! JLabel jLabelPortRTP = new JLabel();
! JLabel jLabelPortSim = new JLabel();
! JLabel jLabelNbMax = new JLabel();
! JLabel jLabelDebit = new JLabel();
! JTextField jTextFieldPort = new JTextField();
! JTextField jTextFieldPortSim = new JTextField();
! JTextField jTextFieldPortRTP = new JTextField();
! JTextField jTextFieldNbMax = new JTextField();
! JTextField jTextFieldDebit = new JTextField();
!
! // Declaration et instanciation des elements graphiques de jPanelSouth
! JButton jButtonStart = new JButton();
! JButton jButtonStop = new JButton();
! JButton jButtonQuit = new JButton();
!
! public ServerFrame() {
!
! contentPane = getContentPane();
! contentPane.setLayout(borderLayout1);
! this.setSize(new Dimension(750, 350));
! this.setTitle("Madsserv Serveur");
!
! // Construction des onglets
! jTabbedPane.addTab("Configuration", null, jPanelConfig,
! "Configure le serveur");
! jTabbedPane.addTab("Rapports", null, jPanelReport, "Affiche les connexions");
! jTabbedPane.addTab("Formats", null, jPanelFormats,
! "Affiche les formats supporté par le serveur");
! jTabbedPane.addTab("Qualité", null, jPanelQuality,
! "Affiche l'association format/niveau de qualité");
! contentPane.add(jTabbedPane, BorderLayout.CENTER);
!
! // Construction de l'onglet Configuration
! jLabelPort.setText("Port d'écoute clients :");
! jTextFieldPort.setText("5001");
! jTextFieldPort.setPreferredSize(new Dimension(100, 25));
! jLabelPortSim.setText("Port d'écoute simulateur :");
! jTextFieldPortSim.setText("4998");
! jTextFieldPortSim.setPreferredSize(new Dimension(100, 25));
! jLabelPortRTP.setText("Port de base pour RTP :");
! jTextFieldPortRTP.setText("40000");
! jTextFieldPortRTP.setPreferredSize(new Dimension(100, 25));
! jLabelNbMax.setText("Nombre maximum de clients :");
! jTextFieldNbMax.setText("10");
! jTextFieldNbMax.setPreferredSize(new Dimension(100, 25));
! jLabelDebit.setText("Debit minimum en Ko/s :");
! jTextFieldDebit.setText("20");
! jTextFieldDebit.setPreferredSize(new Dimension(100, 25));
!
! jPanelConfig.setLayout(gridBagLayout1);
! c.insets = new Insets(5, 5, 5, 5);
! c.fill = GridBagConstraints.NONE;
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.weightx = 1.0;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelPort, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldPort, c);
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelPortSim, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldPortSim, c);
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelPortRTP, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldPortRTP, c);
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelNbMax, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldNbMax, c);
! c.gridwidth = GridBagConstraints.RELATIVE;
! c.anchor = GridBagConstraints.EAST;
! jPanelConfig.add(jLabelDebit, c);
! c.gridwidth = GridBagConstraints.REMAINDER;
! c.anchor = GridBagConstraints.WEST;
! jPanelConfig.add(jTextFieldDebit, c);
!
! // Insertion de la table graphique
! tableClients.insertGraphics(jPanelReport);
!
! // Construction du panel des boutons
! jButtonStart.setText("Démarrer");
! jButtonStart.setEnabled(true);
! jButtonStart.addActionListener(new ServerFrame_Button_Start_ActionAdapter(this));
! jPanelSouth.add(jButtonStart);
! jButtonStop.setText("Arrêter");
! jButtonStop.setEnabled(false);
! jButtonStop.addActionListener(new ServerFrame_Button_Stop_ActionAdapter(this));
! jPanelSouth.add(jButtonStop);
! jButtonQuit.setText("Quitter");
! jButtonQuit.addActionListener(new ServerFrame_Button_Quit_ActionAdapter(this));
! jPanelSouth.add(jButtonQuit);
! contentPane.add(jPanelSouth, BorderLayout.SOUTH);
! }
!
! public void Button_Start_actionPerformed(ActionEvent evt) {
! int port = 5000;
! int portSim = 4998;
! int portBaseRTP = 40000;
! int nbClients = 10;
! int debit = 20;
! Integer integer1 = null;
! Integer integer2 = null;
! Integer integer3 = null;
! Integer integer4 = null;
! Integer integer5 = null;
!
! try {
! integer1 = Integer.valueOf(jTextFieldPort.getText());
! integer2 = Integer.valueOf(jTextFieldPortSim.getText());
! integer3 = Integer.valueOf(jTextFieldPortRTP.getText());
! integer4 = Integer.valueOf(jTextFieldNbMax.getText());
! integer5 = Integer.valueOf(jTextFieldDebit.getText());
! if (integer1 == null || integer2 == null || integer3 == null || integer3 == null) {
! System.err.println("il y a une erreur");
! displayError("Erreur de saisie",
! "La valeur d'un champ est incorrecte.\nVeuillez la modifier");
! }
! else {
! port = integer1.intValue();
! portSim = integer2.intValue();
! portBaseRTP = integer3.intValue();
! nbClients = integer4.intValue();
! debit = integer5.intValue();
! }
! }
! catch (NumberFormatException e) {
! displayError("Erreur de saisie",
! "La valeur d'un champ est incorrecte.\nVeuillez la modifier");
! }
! if (serverInit == null) {
! try {
! serverInit = new ServerInit(port, portSim, portBaseRTP, nbClients,
! debit, this);
! serverInit.start();
! jButtonStart.setEnabled(false);
! jButtonStop.setEnabled(true);
! }
! catch (ErrNoListen e) {
! serverInit = null;
! // lancer erreur popup
! jButtonStart.setEnabled(true);
! jButtonStop.setEnabled(false);
! }
! }
! else {
! try {
! System.err.println("ServerInit est deja cree");
! serverInit.start();
! }
! catch (ErrNoListen e) {
! serverInit = null;
! // lancer erreur popup
! jButtonStart.setEnabled(true);
! jButtonStop.setEnabled(false);
! }
! }
! }
!
! public void displayError(String _name, String _message) {
! JOptionPane.showMessageDialog(this, _message, _name,
! JOptionPane.WARNING_MESSAGE);
! }
!
! public void Button_Stop_actionPerformed(ActionEvent evt) {
! serverInit.stop();
! serverInit = null;
! System.gc();
! jButtonStart.setEnabled(true);
! jButtonStop.setEnabled(false);
! }
!
! public void Button_Quit_actionPerformed(ActionEvent evt) {
! System.exit(0);
! }
!
! /**
! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre
! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre
! */
! protected void processWindowEvent(WindowEvent e) {
! super.processWindowEvent(e);
! if (e.getID() == WindowEvent.WINDOW_CLOSING) {
! Button_Quit_actionPerformed(null);
! }
! }
!
! public static void main(String[] args) {
! ServerFrame serverFrame = new ServerFrame();
! serverFrame.pack();
! //Center the window
! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
! Dimension frameSize = serverFrame.getSize();
! if (frameSize.height > screenSize.height) {
! frameSize.height = screenSize.height;
! }
! if (frameSize.width > screenSize.width) {
! frameSize.width = screenSize.width;
! }
! serverFrame.setLocation( (screenSize.width - frameSize.width) / 2,
! (screenSize.height - frameSize.height) / 2);
!
! serverFrame.show();
! }
! }
!
! class ServerFrame_Button_Start_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Start_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Start_actionPerformed(evt);
! }
! }
!
! class ServerFrame_Button_Stop_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Stop_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Stop_actionPerformed(evt);
! }
! }
!
! class ServerFrame_Button_Quit_ActionAdapter
! implements ActionListener {
! ServerFrame adaptee;
!
! ServerFrame_Button_Quit_ActionAdapter(ServerFrame adaptee) {
! this.adaptee = adaptee;
! }
!
! public void actionPerformed(ActionEvent evt) {
! adaptee.Button_Quit_actionPerformed(evt);
! }
! }
!
! class TableClients
! extends JTable {
! private boolean DEBUG = false;
! private String[] columnNames = {
! "ID",
! "IP Client",
! "Port RTP",
! "Statut",
! "Media demande",
! "Debit",
! "Niveau de qualite"};
! private Object[][] data;
! private MyTableModel myModel = null;
!
! public TableClients() {
! super();
! myModel = new MyTableModel(data, columnNames);
! setModel(myModel);
! }
!
! public int getRowForClient(int _clientID) {
! for (int i = 0; i < myModel.getRowCount(); i++) {
! if (_clientID == ( (Integer) myModel.getValueAt(i, 0)).intValue()) {
! return i;
! }
! }
! return -1;
! }
!
! public void setValue(Object value, int row, int col) {
! myModel.setValueAt(value, row, col);
! }
!
! public void insertGraphics(JPanel jp) {
! JScrollPane sc = new JScrollPane(this);
! sc.setPreferredSize(new Dimension(750, 350));
! jp.add(sc);
! }
!
! public void newClientRecord(int _clientID, int _portRTP, String _IP,
! String _status) {
! Object[] newRow = {
! new Integer(_clientID), _IP, new Integer(_portRTP), _status, "nomedia",
! new Float(0.0), new Integer(1)};
! myModel.insertRow(0, newRow);
! }
!
! public void updateClientRecord(int _clientID, String _IP, int _portRTP,
! String _status,
! String _media, float _debit,
! int _qualityLevel) {
! int row = getRowForClient(_clientID);
!
! if (_IP != null) {
! setValue(_IP, row, 1);
! }
! if (_portRTP != 0) {
! setValue(new Integer(_portRTP), row, 2);
! }
! if (_status != null) {
! setValue(_status, row, 3);
! }
! if (_media != null) {
! setValue(_media, row, 4);
! }
! if (_debit != -1.0) {
! setValue(new Float(_debit), row, 5);
! }
! if (_qualityLevel != -1) {
! setValue(new Integer(_qualityLevel), row, 6);
! }
! }
!
!
! public void removeClientRecord(int _clientID) {
! ( (DefaultTableModel) getModel()).removeRow(getRowForClient(
! _clientID));
! }
!
! public synchronized void setIP(int _clientID, String _IP) {
!
! int row = getRowForClient(_clientID);
! setValue(_IP, row, 1);
! }
!
! public synchronized void setPortRTP(int _clientID, int _portRTP) {
!
! int row = getRowForClient(_clientID);
! setValue(new Integer(_portRTP), row, 2);
! }
!
! public synchronized void setStatus(int _clientID, String _status) {
!
! int row = getRowForClient(_clientID);
! setValue(_status, row, 3);
! }
!
! public synchronized void setMedia(int _clientID, String _media) {
! int row = getRowForClient(_clientID);
! setValue(_media, row, 4);
! }
!
! public synchronized void setDebit(int _clientID, float _debit) {
! int row = getRowForClient(_clientID);
! setValue(new Float(_debit), row, 5);
! }
!
! public synchronized void setQualityLevel(int _clientID, int _quality) {
! int row = getRowForClient(_clientID);
! setValue(new Integer(_quality), row, 6);
! }
!
! class MyTableModel
! extends DefaultTableModel {
!
! public MyTableModel() {
! super();
! }
!
! public MyTableModel(Object[][] data, Object[] columnNames) {
! super(data, columnNames);
! }
!
! /*
! * JTable uses this method to determine the default renderer/
! * editor for each cell. If we didn't implement this method,
! * then the last column would contain text ("true"/"false"),
! * rather than a check box.
! */
! public Class getColumnClass(int c) {
! return getValueAt(0, c).getClass();
! }
!
! public boolean isCellEditable(int row, int column) {
! return false;
! }
!
! private void printDebugData() {
! int numRows = getRowCount();
! int numCols = getColumnCount();
!
! for (int i = 0; i < numRows; i++) {
! System.out.print(" row " + i + ":");
! for (int j = 0; j < numCols; j++) {
! System.out.print(" " + data[i][j]);
! }
! System.out.println();
! }
! System.out.println("--------------------------");
! }
! }
!
! }
\ No newline at end of file
Index: ServerInit.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/ServerInit.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ServerInit.java 14 Mar 2003 03:26:18 -0000 1.6
--- ServerInit.java 17 Mar 2003 03:55:17 -0000 1.7
***************
*** 1,429 ****
! import java.util.*;
! import java.io.*;
! import java.net.*;
! import java.awt.*;
! import javax.media.rtp.*;
! import javax.media.*;
!
! ///////////////////////////////////////////////////////
! //
! // Server constitue la classe principale du serveur
! // Madsserv. Elle fera appel � des threads pour gerer
! // la communication par sockets avec les clients et le
! // simulateur.
! //
! //////////////////////////////////////////////////////
!
! /**
! * <code>ServerInit</code> constitue la classe de demarrage du serveur Madsserv.
! * Elle gere les connexions multiples de clients ainsi que l'instanciation des
! * modules necessaires au traitement des requetes de diffusion media.
! * @see Streaming
! * @see Reencode
! * @see Transition
! * @see GestionAdapta
! * @see DialogClient
! * @author Julien Carbonell
! */
!
! public class ServerInit {
!
! // ProcessorTest processor;
!
! // tabClients enregistre l'ensemble des clients connectes
! private ClientRecord[] tabClients;
! // tabDialog enregistre les objets de gestion des clients lances par Server a chaque nouvelle connexion
! private DialogClient[] tabDialogs;
! // tabStreaming enregistre les objets Streaming associes aux clients
! private Streaming[] tabStreaming;
! // tabReencode enregistre les objets Reencode associes aux clients
! private Reencode[] tabReencode;
! // tabTransition enregistre les objets Transition associes aux clients
! private Transition[] tabTransition;
!
! // Reference sur le gestionnnaire d'adaptabilite
! //private GestionAdapta gestionAdapta;
!
! // Reference sur le thread d'ecoute des clients
! private ThreadListenClients threadListenClients = null;
!
! // Parametres de connexion du serveur
! private int portListen;
! private int portBaseRTP;
! private int debitMin;
! private int nbMaxClients;
!
! // Socket d'ecoute clients
! private ServerSocket sockListen = null;
!
! // Interface graphique
! private ServerFrame serverFrame = null;
!
! /**
! * Constructeur de <code>ServerInit</code>.
! * @param _portListen le port d'ecoute du serveur.
! * @param _portBaseRTP le port de base a partir duquel sont deduits l'ensemble des ports necessaires a la creation des connexions RTP.
! * @param _nbMaxCliens le nombre maximum de clients acceptes par le serveur.
! * @param _debitMin le debit minimum en-dessous duquel le client est deconnecte.
! */
! public ServerInit(int _portListen, int _portBaseRTP, int _nbMaxClients,
! int _debitMin, ServerFrame _serverFrame) {
! portListen = _portListen;
! portBaseRTP = _portBaseRTP;
! nbMaxClients = _nbMaxClients;
! debitMin = _debitMin;
! serverFrame = _serverFrame;
!
! tabClients = new ClientRecord[nbMaxClients];
! tabDialogs = new DialogClient[nbMaxClients];
! tabStreaming = new Streaming[nbMaxClients];
! tabReencode = new Reencode[nbMaxClients];
! tabTransition = new Transition[nbMaxClients];
!
! //gestionAdapta = new GestionAdapta(......);
!
! //frame = new MainFrame(......);
! //frame.show();
! }
!
! /**
! * Ouvre le socket d'ecoute et demarre l'attente de connexions.
! */
! public void start() throws ErrNoListen {
!
! try {
! sockListen = new ServerSocket(portListen);
! threadListenClients = new ThreadListenClients(this, sockListen, portListen);
! threadListenClients.start();
! }
! catch (Exception e) {
! sockListen=null;
! threadListenClients = null;
! throw new ErrNoListen();
! }
! }
!
! /**
! * Arrete le serveur.
! */
! public void stop() {
! threadListenClients.close();
! }
!
! /**
! * Deconnecte un client en effaçant tous les objets relatifs au traitement de sa connexion.
! * @param _clientID l'ID du client a deconnecter.
! */
! public void endConnexion(int _clientID) {
! String[] warning = new String[1];
!
! warning[0] = "Attention je detruis la connexion du client 0";
! System.out.println("Envoi du message " + warning[0]);
! tabDialogs[_clientID].sendMessage(5, warning);
!
! tabStreaming[_clientID].stop();
! tabStreaming[_clientID] = null;
! /*tabReencode[_clientID].stop();
! tabTransition[_clientID].stop();
! tabReencode[_clientID] = null;
! tabReencode[_clientID] = null;*/
! System.out.println("Suppression du client " + _clientID);
! tabClients[_clientID] = null;
! tabDialogs[_clientID].stop();
! System.out.println("le client " + _clientID + " est mort -ref=" +
! tabClients[_clientID]);
! tabDialogs[_clientID] = null;
! System.err.println("Garbage collecting de endConnexion");
! System.gc();
! }
!
! /**
! * Renvoie l'IP d'un client.
! * @param _clientID l'ID du client.
! * @return l'adresse IP du client.
! */
! public String getIP(int _clientID) {
! return (tabClients[_clientID].getIP());
! }
!
! /**
! * Renvoie le port RTP de base affecte au client.
! * @param _clientID l'ID du client.
! * @return le port RTP de base affecte au client.
! */
! public int getPortRTP(int _clientID) {
! return (tabClients[_clientID].getPortRTP());
! }
!
! /**
! * Renvoie l'adresse du media demande par le client.
! * @param _clientID l'ID du client.
! * @return l'adresse du media demande par le client.
! */
! public String getMediaAddress(int _clientID) {
! return (tabClients[_clientID].getMediaAddress());
! }
!
! /**
! * Renvoie le format de diffusion prefere par le client.
! * @param _clientID l'ID du client.
! * @return le format de diffusion prefere par le client.
! */
! public String getPreferredFormat(int _clientID) {
! return (tabClients[_clientID].getPreferredFormat());
! }
!
! /**
! * Renvoie le niveau de qualité courant associé au client.
! * @param _clientID l'ID du client.
! * @return le niveau de qualite courant associe au client.
! */
! public int getQualityLevel(int _clientID) {
! return (tabClients[_clientID].getQualityLevel());
! }
!
! /**
! * Modifie l'IP d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle IP.
! */
! public synchronized void setIP(int _clientID, String _IP) {
! tabClients[_clientID].setIP(_IP);
! }
!
! /**
! * Modifie le port RTP de base d'un client.
! * @param _clientID l'ID du client.
! * @param _IP le nouveau port RTP de base.
! */
! public synchronized void setPortRTP(int _clientID, int _portBaseRTP) {
! tabClients[_clientID].setPortRTP(_portBaseRTP);
! }
!
! /**
! * Modifie l'adresse du media demande par le client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle adresse du media demande par le client.
! */
! public synchronized void setMediaAddress(int _clientID, String _mediaAddress) {
! tabClients[_clientID].setMediaAddress(_mediaAddress);
! }
!
! /**
! * Modifie le format prefere d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle IP.
! */
! public synchronized void setPreferredFormat(int _clientID,
! String _preferredFormat) {
! tabClients[_clientID].setPreferredFormat(_preferredFormat);
! }
!
! /**
! * Modifie le niveau de qualite courant d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouveau niveau de qualite.
! */
! public synchronized void setQualityLevel(int _clientID, int _qualityLevel) {
! tabClients[_clientID].setQualityLevel(_qualityLevel);
! }
!
! // cree un nouveau client dans la table et retourne le clientID affect�
! // retourne (-1) si trop de clients
!
! /**
! * Cree un nouveau client avec une ID et un numero de port RTP. La creation d'un
! * client est accompagnee par la creation des 3 modules de traitement des
! * requetes client ({@link Streaming}, {@link Reencode} et {@link Transiton}).
! * @return l'ID du client. Vaut <code>-1</code> si le nombre maximum de clients
! * est deja atteint (creation d'un nouveau client impossible).
! */
! public synchronized int createClient() {
! boolean inserted = false;
! int i = 0;
! while ( (inserted == false) && (i < nbMaxClients)) {
! if (tabClients[i] == null) {
! tabClients[i] = new ClientRecord();
! tabClients[i].setClientID(i);
! inserted = true;
! }
! i++;
! }
! if (inserted) {
! tabClients[i - 1].setPortRTP(portBaseRTP + 4 * (i - 1));
! tabStreaming[i - 1] = new Streaming(i - 1, this);
! return (i - 1);
! }
! else {
! return ( -1);
! }
! }
!
! /**
! * Cree un nouveau client a partir des arguments fournis. La creation d'un
! * client est accompagnee par la creation des 3 modules de traitement des
! * requetes client ({@link Streaming}, {@link Reencode} et {@link Transiton}).
! * @return l'ID du client. Vaut <code>-1</code> si le nombre maximum de clients
! * est deja atteint (creation d'un nouveau client impossible).
! */
! /* public synchronized int createClient(String _IP, int _portBaseRTP,
! String _mediaAddress,
! String _preferredFormat,
! int _qualityLevel) {
! boolean inserted = false;
! int i = 0;
! while ( (inserted == false) && (i < nbMaxClients)) {
! if (tabClients[i] == null) {
! tabClients[i] = new ClientRecord(i, _IP, _portBaseRTP, _mediaAddress,
! _preferredFormat, _qualityLevel);
! inserted = true;
! }
! i++;
! }
! if (inserted) {
! return (i - 1);
! }
! else {
! return ( -1);
! }
! }*/
!
! /**
! * Cree un nouveau <code>DialogClient</code> pour gerer la communication avec
! * un client.
! * @param _clientID l'ID du client.
! * @param _socketClient le {@link Socket} dedie a la communication avec le client.
! * @return le <code>DialogClient</code> cree.
! */
! public synchronized DialogClient createDialogClient(int _clientID,
! Socket _sockClient) {
! if (_clientID == -1) {
! DialogClient tempDialog = new DialogClient(_clientID, _sockClient, this);
! return tempDialog;
! }
! else {
! tabDialogs[_clientID] = new DialogClient(_clientID, _sockClient, this);
! return tabDialogs[_clientID];
! }
! }
!
! public void createReencode(int _clientID, String _URL) {
! if (tabReencode[_clientID] != null) {
! tabReencode[_clientID].stop();
! tabReencode[_clientID] = null;
! }
! tabReencode[_clientID] = new Reencode(_clientID, _URL);
! //tabReencode[_clientID].start();
! }
!
! /**
! * Demarre la diffusion du media demande pour un client donne.
! * @param _clientID l'ID du client.
! */
! public synchronized void startStreaming(int _clientID) {
! Streaming streamingTemp = tabStreaming[_clientID];
!
! streamingTemp.setClientIP(getIP(_clientID));
! streamingTemp.setClientPort(getPortRTP(_clientID));
! System.out.println("Le streaming a recu " + getIP(_clientID) + " et " +
! getPortRTP(_clientID));
! //streamingTemp.setMediaAddress(getMediaAddress(_clientID));
! if (!streamingTemp.isInitialized()) {
! streamingTemp.initialize();
! }
! System.out.println("Le streaming est initialise");
! //processor = new ProcessorTest(new MediaLocator(getMediaAddress(_clientID)),
! // streamingTemp);
! // System.out.println("Le processor est cree");
! // D�marrage du ProcessorTest
! // processor.start();
! tabReencode[_clientID].setStreamingRef(streamingTemp);
! tabReencode[_clientID].start();
! System.out.println("Le processeur a demarre");
!
! // On fournit la DataSource � diffuser
! //streamingTemp.setNewStreams(processor.getOutput());
! System.out.println("Le streaming a recu les nouveaux streams");
!
! }
!
! }
!
! class ClientRecord {
!
! private int clientID;
! private String IP;
! private int portRTP;
! private String mediaAddress;
! private String preferredFormat;
! private int qualityLevel;
!
! public ClientRecord() {
! clientID = -1;
! IP = "";
! portRTP = 40000;
! mediaAddress = "";
! preferredFormat = "";
! qualityLevel = 1;
! }
!
! public ClientRecord(int _clientID, String _IP, int _portRTP,
! String _mediaAddress, String _preferredFormat,
! int _qualityLevel) {
!
! clientID = _clientID;
! IP = _IP;
! portRTP = _portRTP;
! mediaAddress = _mediaAddress;
! preferredFormat = _preferredFormat;
! qualityLevel = _qualityLevel;
! }
!
! public int getClientID() {
! return clientID;
! }
!
! public String getIP() {
! return IP;
! }
!
! public int getPortRTP() {
! return portRTP;
! }
!
! public String getMediaAddress() {
! return mediaAddress;
! }
!
! public String getPreferredFormat() {
! return preferredFormat;
! }
!
! public int getQualityLevel() {
! return qualityLevel;
! }
!
! public void setClientID(int _clientID) {
! clientID = _clientID;
! }
!
! public void setIP(String _IP) {
! IP = _IP;
! }
!
! public void setPortRTP(int _portRTP) {
! portRTP = _portRTP;
! }
!
! public void setMediaAddress(String _mediaAddress) {
! mediaAddress = _mediaAddress;
! }
!
! public void setPreferredFormat(String _preferredFormat) {
! preferredFormat = _preferredFormat;
! }
!
! public void setQualityLevel(int _qualityLevel) {
! qualityLevel = _qualityLevel;
! }
! }
--- 1,503 ----
! import java.util.*;
! import java.io.*;
! import java.net.*;
! import java.awt.*;
! import javax.media.rtp.*;
! import javax.media.*;
!
! ///////////////////////////////////////////////////////
! //
! // Server constitue la classe principale du serveur
! // Madsserv. Elle fera appel ? des threads pour gerer
! // la communication par sockets avec les clients et le
! // simulateur.
! //
! //////////////////////////////////////////////////////
!
! /**
! * <code>ServerInit</code> constitue la classe de demarrage du serveur Madsserv.
! * Elle gere les connexions multiples de clients ainsi que l'instanciation des
! * modules necessaires au traitement des requetes de diffusion media.
! * @see Streaming
! * @see Reencode
! * @see Transition
! * @see GestionAdapta
! * @see DialogClient
! * @author Julien Carbonell
! */
!
! public class ServerInit {
!
! // ProcessorTest processor;
!
! // tabClients enregistre l'ensemble des clients connectes
! private ClientRecord[] tabClients;
! // tabDialog enregistre les objets de gestion des clients lances par Server a chaque nouvelle connexion
! private DialogClient[] tabDialogs;
! // tabStreaming enregistre les objets Streaming associes aux clients
! private Streaming[] tabStreaming;
! // tabReencode enregistre les objets Reencode associes aux clients
! private Reencode[] tabReencode;
! // tabTransition enregistre les objets Transition associes aux clients
! private Transition[] tabTransition;
!
! // Reference sur le gestionnnaire d'adaptabilite
! private GestionAdapta gestionAdapta;
!
! // Reference sur le thread d'ecoute des clients
! private ThreadListenClients threadListenClients = null;
!
! private ThreadListenSimulator threadListenSimulator = null;
! private DialogSimulator dialogSimulator = null;
!
! // Parametres de connexion du serveur
! private int portListenClients;
! private int portListenSimulator;
! private int portBaseRTP;
! private int debitMin;
! private int nbMaxClients;
!
! // indique si il y a deja un simulateur connecte
! private boolean simulatorConnected = false;
!
! // Socket d'ecoute clients
! private ServerSocket sockListenClients = null;
! private ServerSocket sockListenSimulator = null;
!
! // Interface graphique
! private ServerFrame serverFrame = null;
!
! /**
! * Constructeur de <code>ServerInit</code>.
! * @param _portListen le port d'ecoute du serveur.
! * @param _portBaseRTP le port de base a partir duquel sont deduits l'ensemble des ports necessaires a la creation des connexions RTP.
! * @param _nbMaxCliens le nombre maximum de clients acceptes par le serveur.
! * @param _debitMin le debit minimum en-dessous duquel le client est deconnecte.
! */
! public ServerInit(int _portListenClients, int _portListenSimulator,
! int _portBaseRTP, int _nbMaxClients,
! int _debitMin, ServerFrame _serverFrame) {
! portListenClients = _portListenClients;
! portListenSimulator = _portListenSimulator;
! portBaseRTP = _portBaseRTP;
! nbMaxClients = _nbMaxClients;
! debitMin = _debitMin;
! serverFrame = _serverFrame;
!
! tabClients = new ClientRecord[nbMaxClients];
! tabDialogs = new DialogClient[nbMaxClients];
! tabStreaming = new Streaming[nbMaxClients];
! tabReencode = new Reencode[nbMaxClients];
! tabTransition = new Transition[nbMaxClients];
!
! gestionAdapta = new GestionAdapta();
! }
!
! /**
! * Ouvre le socket d'ecoute et demarre l'attente de connexions.
! */
! public void start() throws ErrNoListen {
!
! try {
! sockListenClients = new ServerSocket(portListenClients);
! threadListenClients = new ThreadListenClients(this, sockListenClients,
! portListenClients);
! threadListenClients.start();
! }
! catch (Exception e) {
! sockListenClients = null;
! threadListenClients = null;
! throw new ErrNoListen();
! }
!
! try {
! sockListenSimulator = new ServerSocket(portListenSimulator);
! threadListenSimulator = new ThreadListenSimulator(this,
! sockListenSimulator, portListenSimulator);
! threadListenSimulator.start();
! }
! catch (Exception e) {
! sockListenSimulator = null;
! threadListenSimulator = null;
! throw new ErrNoListen();
! }
! }
!
! /**
! * Arrete le serveur.
! */
! public void stop() {
!
! for (int i = 0; i < nbMaxClients; i++) {
! if (tabClients[i] != null) {
! serverFrame.tableClients.removeClientRecord(i);
! endConnexionClient(i);
! }
! }
!
! threadListenSimulator.close();
! threadListenSimulator = null;
! threadListenClients.close();
! threadListenClients = null;
! System.gc();
! }
!
! /**
! * Deconnecte un client en effa�ant tous les objets relatifs au traitement de sa connexion.
! * @param _clientID l'ID du client a deconnecter.
! */
! public void endConnexionClient(int _clientID) {
! String[] warning = new String[1];
!
! if (_clientID == -1) {
! warning[0] = "Trop de clients connect?au serveur.";
! }
! else {
! warning[0] = "D?nnexion du client " + String.valueOf(_clientID);
! }
! System.out.println("Envoi du message " + warning[0]);
! tabDialogs[_clientID].sendMessage(5, warning);
!
! if (dialogSimulator != null) {
! warning[0] = String.valueOf(_clientID);
! dialogSimulator.sendMessage(3, warning);
!
! }
! try {
! Thread.sleep(500);
! }
! catch (Exception e) {
!
! }
! tabStreaming[_clientID].stop();
! tabStreaming[_clientID] = null;
! tabReencode[_clientID].stop();
! tabReencode[_clientID] = null;
! /* tabTransition[_clientID].stop();*/
! tabTransition[_clientID] = null;
! System.out.println("Suppression du client " + _clientID);
! tabClients[_clientID] = null;
! tabDialogs[_clientID].stop();
! System.out.println("le client " + _clientID + " est mort -ref=" +
! tabClients[_clientID]);
! tabDialogs[_clientID] = null;
! serverFrame.tableClients.removeClientRecord(_clientID);
! System.err.println("Garbage collecting de endConnexion");
! System.gc();
! }
!
! public void endConnexionSimulator(String _message) {
! String[] messageToSend = new String[1];
! messageToSend[0] = _message;
! if (simulatorConnected) {
! dialogSimulator.sendMessage(5, messageToSend);
! dialogSimulator.stop();
! simulatorConnected = false;
! dialogSimulator = null;
! System.gc();
! }
! else {
! System.err.println("Il n'y a pas de simulateur connecte");
! }
! }
!
! public void requestCurrentMediaTime(int _clientID) {
! tabDialogs[_clientID].sendMessage(7, null);
! }
!
! public void setCurrentMediaTime(int _clientID, double currentMediaTime) {
! tabTransition[_clientID].setCurrentMediaTime(currentMediaTime);
! }
!
! /**
! * Renvoie l'IP d'un client.
! * @param _clientID l'ID du client.
! * @return l'adresse IP du client.
! */
! public String getIP(int _clientID) {
! return (tabClients[_clientID].getIP());
! }
!
! /**
! * Renvoie le port RTP de base affecte au client.
! * @param _clientID l'ID du client.
! * @return le port RTP de base affecte au client.
! */
! public int getPortRTP(int _clientID) {
! return (tabClients[_clientID].getPortRTP());
! }
!
! /**
! * Renvoie l'adresse du media demande par le client.
! * @param _clientID l'ID du client.
! * @return l'adresse du media demande par le client.
! */
! public String getMediaAddress(int _clientID) {
! return (tabClients[_clientID].getMediaAddress());
! }
!
! /**
! * Renvoie le format de diffusion prefere par le client.
! * @param _clientID l'ID du client.
! * @return le format de diffusion prefere par le client.
! */
! public String getPreferredFormat(int _clientID) {
! return (tabClients[_clientID].getPreferredFormat());
! }
!
! /**
! * Renvoie le niveau de qualit� courant associ� au client.
! * @param _clientID l'ID du client.
! * @return le niveau de qualite courant associe au client.
! */
! public int getQualityLevel(int _clientID) {
! return (tabClients[_clientID].getQualityLevel());
! }
!
! /**
! * Modifie l'IP d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle IP.
! */
! public synchronized void setIP(int _clientID, String _IP) {
! tabClients[_clientID].setIP(_IP);
! }
!
! /**
! * Modifie le port RTP de base d'un client.
! * @param _clientID l'ID du client.
! * @param _IP le nouveau port RTP de base.
! */
! public synchronized void setPortRTP(int _clientID, int _portBaseRTP) {
! tabClients[_clientID].setPortRTP(_portBaseRTP);
! }
!
! public synchronized void setStatus(int _clientID, String _status) {
! tabClients[_clientID].setStatus(_status);
! }
!
! /**
! * Modifie l'adresse du media demande par le client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle adresse du media demande par le client.
! */
! public synchronized void setMediaAddress(int _clientID, String _mediaAddress) {
! tabClients[_clientID].setMediaAddress(_mediaAddress);
! }
!
! /**
! * Modifie le format prefere d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouvelle IP.
! */
! public synchronized void setPreferredFormat(int _clientID,
! String _preferredFormat) {
! tabClients[_clientID].setPreferredFormat(_preferredFormat);
! }
!
! /**
! * Modifie le niveau de qualite courant d'un client.
! * @param _clientID l'ID du client.
! * @param _IP la nouveau niveau de qualite.
! */
! public synchronized void setQualityLevel(int _clientID, int _qualityLevel) {
! tabClients[_clientID].setQualityLevel(_qualityLevel);
! tabTransition[_clientID].setQualityLevel(_qualityLevel);
!
! }
!
! // cree un nouveau client dans la table et retourne le clientID affect?
! // retourne (-1) si trop de clients
!
! /**
! * Cree un nouveau client avec une ID et un numero de port RTP. La creation d'un
! * client est accompagnee par la creation des 3 modules de traitement des
! * requetes client ({@link Streaming}, {@link Reencode} et {@link Transiton}).
! * @return l'ID du client. Vaut <code>-1</code> si le nombre maximum de clients
! * est deja atteint (creation d'un nouveau client impossible).
! */
! public synchronized int createClient() {
! boolean inserted = false;
! int i = 0;
! while (i < nbMaxClients) {
! if (tabClients[i] == null) {
! tabClients[i] = new ClientRecord(i);
! tabClients[i].setPortRTP(portBaseRTP + 4 * i);
! tabStreaming[i] = new Streaming(i, this);
! tabTransition[i] = new Transition(i, this);
! tabTransition[i].setStreaming(tabStreaming[i]);
! tabTransition[i].setGestionAdapta(gestionAdapta);
! if (dialogSimulator != null) {
! String[] messageToSend = new String[2];
! messageToSend[0] = String.valueOf(i);
! messageToSend[1] = String.valueOf(getQualityLevel(i));
! dialogSimulator.sendMessage(1, messageToSend);
! }
! return i;
! }
! i++;
! }
! return -1;
! }
!
! public void createDialogSimulator(Socket _socketSimulator) {
!
! if (simulatorConnected) {
! DialogSimulator dialogSimulatorTemp = new DialogSimulator(
! _socketSimulator, this);
! dialogSimulator.start();
! endConnexionSimulator("Un simulateur est deja connecte -> deconnexion");
! }
! else {
! dialogSimulator = new DialogSimulator(_socketSimulator, this);
! dialogSimulator.start();
! updateSimulator();
! }
! }
!
! public void updateSimulator() {
! String[] messageToSend;
! messageToSend = new String[2];
! for (int i = 0; i < nbMaxClients; i++) {
! if (tabClients[i] != null) {
! messageToSend[0] = String.valueOf(i);
! messageToSend[1] = String.valueOf(getQualityLevel(i));
! dialogSimulator.sendMessage(1, messageToSend);
! }
! }
!
! }
!
! /**
! * Cree un nouveau <code>DialogClient</code> pour gerer la communication avec
! * un client.
! * @param _clientID l'ID du client.
! * @param _socketClient le {@link Socket} dedie a la communication avec le client.
! * @return le <code>DialogClient</code> cree.
! */
! public synchronized DialogClient createDialogClient(int _clientID,
! Socket _sockClient) {
! if (_clientID == -1) {
! DialogClient tempDialog = new DialogClient(_clientID, _sockClient, this);
! return tempDialog;
! }
! else {
! tabDialogs[_clientID] = new DialogClient(_clientID, _sockClient, this);
! return tabDialogs[_clientID];
! }
! }
!
! public void createReencode(int _clientID, String _URL) {
! if (tabReencode[_clientID] != null) {
! tabReencode[_clientID].stop();
! tabReencode[_clientID] = null;
! System.gc();
! }
! tabReencode[_clientID] = new Reencode(_clientID, _URL);
! tabTransition[_clientID].setReencode(tabReencode[_clientID]);
! //tabReencode[_clientID].start();
!
! }
!
! /**
! * Demarre la diffusion du media demande pour un client donne.
! * @param _clientID l'ID du client.
! */
! public synchronized void startStreaming(int _clientID) {
! Streaming streamingTemp = tabStreaming[_clientID];
!
! streamingTemp.setClientIP(getIP(_clientID));
! streamingTemp.setClientPort(getPortRTP(_clientID));
! System.out.println("Le streaming a recu " + getIP(_clientID) + " et " +
! getPortRTP(_clientID));
! if (!streamingTemp.isInitialized()) {
! streamingTemp.initialize();
! }
! System.out.println("Le streaming est initialise");
! tabReencode[_clientID].setStreamingRef(streamingTemp);
! tabTransition[_clientID].setQualityLevel(getQualityLevel(_clientID));
! }
!
! class ClientRecord {
!
! private int clientID;
! private String IP;
! private int portRTP;
! private String status;
! private String mediaAddress;
! private String preferredFormat;
! private int qualityLevel;
!
! publi...
[truncated message content] |
|
From: <mar...@us...> - 2003-03-17 02:57:06
|
Update of /cvsroot/madsserv/madsserv/src/server/processor
In directory sc8-pr-cvs1:/tmp/cvs-serv14897
Modified Files:
Reencode.java ThreadReencode.java
Log Message:
nouveau mode de choix des formats implemente
Index: Reencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/Reencode.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** Reencode.java 14 Mar 2003 03:26:19 -0000 1.12
--- Reencode.java 17 Mar 2003 02:57:02 -0000 1.13
***************
*** 22,26 ****
* Classe Reencode
*/
! public class Reencode implements ControllerListener {
/**
--- 22,27 ----
* Classe Reencode
*/
! public class Reencode
! implements ControllerListener {
/**
***************
*** 37,41 ****
private int clientId = -1; // Numero du client demandeur.
private MediaLocator inputML = null; // MediaLocator du fichier a convertir.
- private DataSource inputDS = null; // DataSource contenant le fichier a convertir.
private TrackControl[] inputTC = null; // TrackControl permettant d'acceder aux differentes pistes du media.
private Format[] inputFormat = null; // Vecteur de Format pour stocker les formats des pistes.
--- 38,41 ----
***************
*** 44,49 ****
private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage du fichier.
private VideoFormat reencodingVideoFormat = null; // Format video de reencodage du fichier.
private Time startTime = new Time(0); // Instant de debut de conversion.
!
/**
--- 44,50 ----
private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage du fichier.
private VideoFormat reencodingVideoFormat = null; // Format video de reencodage du fichier.
+ private Time duration = new Time(1); // Duree du fichier.
private Time startTime = new Time(0); // Instant de debut de conversion.
! private Format[][] supportedFormats = null; // Formats de reencodage suppportes par le processor.
/**
***************
*** 52,61 ****
* @param inputURL l'URL demande par le client
*/
! Reencode(int clientId, String inputURL)
! {
// Stockage de l'ID du client correspondant a l'instantiation.
this.clientId = clientId;
! if(this.clientId < 0)
! {
System.err.println("L'ID du client n'a pas ete transmis correctement.");
System.exit(0);
--- 53,60 ----
* @param inputURL l'URL demande par le client
*/
! Reencode(int clientId, String inputURL) {
// Stockage de l'ID du client correspondant a l'instantiation.
this.clientId = clientId;
! if (this.clientId < 0) {
System.err.println("L'ID du client n'a pas ete transmis correctement.");
System.exit(0);
***************
*** 63,68 ****
// Stockage de l'URL demande correspondant a l'instantiation.
this.inputURL = inputURL;
! if(this.inputURL == null)
! {
System.err.println("L'URL a lire n'a pas ete transmis correctement.");
System.exit(0);
--- 62,66 ----
// Stockage de l'URL demande correspondant a l'instantiation.
this.inputURL = inputURL;
! if (this.inputURL == null) {
System.err.println("L'URL a lire n'a pas ete transmis correctement.");
System.exit(0);
***************
*** 71,94 ****
// Conversion de l'URL en MediaLocator.
! if((inputML = createMediaLocator(inputURL)) == null)
! {
! System.err.println("Impossible de construire le MediaLocator a partir de : " + inputURL);
System.exit(0);
}
// Determination des formats d'origine du fichier demande.
// Pour cela, on cree un Processor que l'on place dans l'etat configure.
- // Source inspire de la classe Transcode publiee par Sun.
- // http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
Processor p = null;
! try
! {
p = Manager.createProcessor(inputML);
System.err.println("- create processor for: " + inputML);
}
! catch (Exception e)
! {
! System.err.println("Yikes! Cannot create a processor from the given url: " + e);
}
--- 69,98 ----
// Conversion de l'URL en MediaLocator.
! if ( (inputML = createMediaLocator(inputURL)) == null) {
! System.err.println(
! "Impossible de construire le MediaLocator a partir de : " + inputURL);
System.exit(0);
}
+ }
+ /**
+ * Methode retournant les formats de reencodage supportes par le processor.
+ * On en profite aussi pour recuperer les formats originaux et la duree du media.
+ * Source inspire de la classe Transcode publiee par Sun.
+ * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
+ * @return les formats de reencodage supportes par le processor
+ */
+ public Format[][] getSupportedFormats() {
// Determination des formats d'origine du fichier demande.
// Pour cela, on cree un Processor que l'on place dans l'etat configure.
Processor p = null;
! try {
p = Manager.createProcessor(inputML);
System.err.println("- create processor for: " + inputML);
}
! catch (Exception e) {
! System.err.println(
! "Yikes! Cannot create a processor from the given url: " + e);
}
***************
*** 97,136 ****
// Put the Processor into configured state.
p.configure();
! if (!waitForState(p, p.Configured))
! {
System.err.println("Failed to configure the processor.");
}
// A l'aide de TrackControl, on accede aux differentes pistes du media.
! try
! {
! if ( (inputTC = p.getTrackControls()) == null)
! {
System.err.println("Il n'y a aucune piste dans le fichier !");
}
! else
! {
! if(inputTC.length > 2)
! {
System.err.println("Il y a trop de pistes dans le fichier !");
}
! else
! {
inputFormat = new Format[inputTC.length];
! if(inputTC.length == 1)
! {
inputFormat[0] = inputTC[0].getFormat();
! System.err.println("Il n'y a qu'une seule piste");
! setOriginalAudioFormat( (AudioFormat) inputFormat[0]); //FIXME si video sans son
}
! else // Il y a deux pistes, la video est la premiere
! {
inputFormat[0] = inputTC[0].getFormat();
- System.err.println("Format piste n 1 : " + inputFormat[0].toString());
setOriginalVideoFormat( (VideoFormat) inputFormat[0]);
inputFormat[1] = inputTC[1].getFormat();
- System.err.println("Format piste n 2 : " + inputFormat[1].toString());
setOriginalAudioFormat( (AudioFormat) inputFormat[1]);
! multiMedia = true;
}
}
--- 101,145 ----
// Put the Processor into configured state.
p.configure();
! if (!waitForState(p, p.Configured)) {
System.err.println("Failed to configure the processor.");
}
// A l'aide de TrackControl, on accede aux differentes pistes du media.
! try {
! inputTC = p.getTrackControls();
! ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
! p.setContentDescriptor(cd);
!
! if (inputTC == null) {
System.err.println("Il n'y a aucune piste dans le fichier !");
}
! else {
! if (inputTC.length > 2) {
System.err.println("Il y a trop de pistes dans le fichier !");
}
! else {
inputFormat = new Format[inputTC.length];
! if (inputTC.length == 1) {
inputFormat[0] = inputTC[0].getFormat();
! setOriginalAudioFormat( (AudioFormat) inputFormat[0]);
}
! else { // Il y a deux pistes, la video est la premiere
inputFormat[0] = inputTC[0].getFormat();
setOriginalVideoFormat( (VideoFormat) inputFormat[0]);
inputFormat[1] = inputTC[1].getFormat();
setOriginalAudioFormat( (AudioFormat) inputFormat[1]);
! }
!
! // Les formats supportes sont stockes dans supportedFormat[][]
! supportedFormats = new Format[inputTC.length][];
! for (int i = 0; i < inputTC.length; i++) {
! if (i == 1) {
! multiMedia = true;
! }
! supportedFormats[i] = inputTC[i].getSupportedFormats();
! for (int j = 0; j < supportedFormats[i].length; j++) {
! System.out.println("Piste " + i + ", format supporte " + j +
! " : " + supportedFormats[i][j].toString());
! }
}
}
***************
*** 139,143 ****
--- 148,161 ----
catch (NotConfiguredError e) {}
+ // On recupere la duree du media (il faut que le processor soit started)
+ p.start();
+ duration = p.getDuration();
+ p.stop();
+
p.removeControllerListener(this);
+ p.close();
+ p = null;
+
+ return (supportedFormats);
}
***************
*** 145,152 ****
* Lancement de la conversion
*/
! public void start()
! {
! if(!reencoding)
! {
if (multiMedia) { // Fichier audio et video
currentThreadReencode = new ThreadReencode(inputML,
--- 163,168 ----
* Lancement de la conversion
*/
! public void start() {
! if (!reencoding) {
if (multiMedia) { // Fichier audio et video
currentThreadReencode = new ThreadReencode(inputML,
***************
*** 161,166 ****
streamingRef.setNewStreams(currentThreadReencode.getOutput());
}
! else
! {
formerThreadReencode = currentThreadReencode;
if (multiMedia) { // Fichier audio et video
--- 177,181 ----
streamingRef.setNewStreams(currentThreadReencode.getOutput());
}
! else {
formerThreadReencode = currentThreadReencode;
if (multiMedia) { // Fichier audio et video
***************
*** 191,203 ****
* @return 0 si arret du precedent thread
*/
! public int stopFormerThreadReencode()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
return -1;
}
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
formerThreadReencode.stopProcessing();
formerThreadReencode = null;
--- 206,216 ----
* @return 0 si arret du precedent thread
*/
! public int stopFormerThreadReencode() {
! if (formerThreadReencode == null) {
! System.err.println(
! "Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
return -1;
}
! else { // on arrete le processor et met la reference du ThreadReencode precedent a null
formerThreadReencode.stopProcessing();
formerThreadReencode = null;
***************
*** 210,215 ****
* @return l'ID du client correspondant au module instancie
*/
! public int getClientId()
! {
return this.clientId;
}
--- 223,227 ----
* @return l'ID du client correspondant au module instancie
*/
! public int getClientId() {
return this.clientId;
}
***************
*** 219,224 ****
* @return le format video original du fichier
*/
! public VideoFormat getOriginalVideoFormat()
! {
return this.originalVideoFormat;
}
--- 231,235 ----
* @return le format video original du fichier
*/
! public VideoFormat getOriginalVideoFormat() {
return this.originalVideoFormat;
}
***************
*** 228,233 ****
* @return le format audio original du fichier
*/
! public AudioFormat getOriginalAudioFormat()
! {
return this.originalAudioFormat;
}
--- 239,243 ----
* @return le format audio original du fichier
*/
! public AudioFormat getOriginalAudioFormat() {
return this.originalAudioFormat;
}
***************
*** 237,244 ****
* @param originalVideoFormat le format video original du fichier
*/
! private void setOriginalVideoFormat(VideoFormat originalVideoFormat)
! {
this.originalVideoFormat = originalVideoFormat;
! System.out.println("Format video original du fichier : " + this.originalVideoFormat.toString());
}
--- 247,254 ----
* @param originalVideoFormat le format video original du fichier
*/
! private void setOriginalVideoFormat(VideoFormat originalVideoFormat) {
this.originalVideoFormat = originalVideoFormat;
! System.out.println("Format video original du fichier : " +
! this.originalVideoFormat.toString());
}
***************
*** 247,272 ****
* @param originalAudioFormat le format audio original du fichier
*/
! private void setOriginalAudioFormat(AudioFormat originalAudioFormat)
! {
this.originalAudioFormat = originalAudioFormat;
! System.out.println("Format audio original du fichier : " + this.originalAudioFormat.toString());
}
/**
! * Definit le format vidéo de reencodage du fichier demande.
! * @param reencodingVideoFormat le nouveau format vidéo de réencodage
* @return 0 si mise a jour effectuee
* @return -1 si erreur
*/
! public int setReencodingVideoFormat(VideoFormat reencodingVideoFormat)
! {
! if(reencodingVideoFormat != null)
! {
this.reencodingVideoFormat = reencodingVideoFormat;
! System.err.println("Nouveau format video recu : " + reencodingVideoFormat.toString());
return 0;
}
! else
! {
System.err.println("Pas de nouveau format video recu !");
return -1;
--- 257,288 ----
* @param originalAudioFormat le format audio original du fichier
*/
! private void setOriginalAudioFormat(AudioFormat originalAudioFormat) {
this.originalAudioFormat = originalAudioFormat;
! System.out.println("Format audio original du fichier : " +
! this.originalAudioFormat.toString());
}
/**
! * Methode retournant la duree du fichier.
! * @return duree du fichier en secondes
! */
! public double getMediaLength() {
! return (duration.getSeconds());
! }
!
! /**
! * Definit le format video de reencodage du fichier demande.
! * @param reencodingVideoFormat le nouveau format video de reencodage
* @return 0 si mise a jour effectuee
* @return -1 si erreur
*/
! public int setReencodingVideoFormat(VideoFormat reencodingVideoFormat) {
! if (reencodingVideoFormat != null) {
this.reencodingVideoFormat = reencodingVideoFormat;
! System.err.println("Nouveau format video recu : " +
! reencodingVideoFormat.toString());
return 0;
}
! else {
System.err.println("Pas de nouveau format video recu !");
return -1;
***************
*** 276,293 ****
/**
* Definit le format audio de reencodage du fichier demande.
! * @param reencodingAudioFormat le nouveau format audio de réencodage
* @return 0 si mise a jour effectuee
* @return -1 si erreur
*/
! public int setReencodingAudioFormat(AudioFormat reencodingAudioFormat)
! {
! if(reencodingAudioFormat != null)
! {
this.reencodingAudioFormat = reencodingAudioFormat;
! System.err.println("Nouveau format audio recu : " + reencodingAudioFormat.toString());
return 0;
}
! else
! {
System.err.println("Pas de nouveau format audio recu !");
return -1;
--- 292,307 ----
/**
* Definit le format audio de reencodage du fichier demande.
! * @param reencodingAudioFormat le nouveau format audio de reencodage
* @return 0 si mise a jour effectuee
* @return -1 si erreur
*/
! public int setReencodingAudioFormat(AudioFormat reencodingAudioFormat) {
! if (reencodingAudioFormat != null) {
this.reencodingAudioFormat = reencodingAudioFormat;
! System.err.println("Nouveau format audio recu : " +
! reencodingAudioFormat.toString());
return 0;
}
! else {
System.err.println("Pas de nouveau format audio recu !");
return -1;
***************
*** 299,304 ****
* @param startTime l'instant du changement de conversion
*/
! public void setReencodingTime(Time startTime)
! {
this.startTime = startTime;
}
--- 313,317 ----
* @param startTime l'instant du changement de conversion
*/
! public void setReencodingTime(Time startTime) {
this.startTime = startTime;
}
***************
*** 308,314 ****
* @param streamingRef la reference du module Streaming correspondant au meme client
*/
! public void setStreamingRef(Streaming streamingRef)
! {
! this.streamingRef = streamingRef;
}
--- 321,326 ----
* @param streamingRef la reference du module Streaming correspondant au meme client
*/
! public void setStreamingRef(Streaming streamingRef) {
! this.streamingRef = streamingRef;
}
***************
*** 317,326 ****
* @param transitionRef la reference du module Transition correspondant au meme client
*/
! public void setTransitionRef(Transition transitionRef)
! {
! this.transitionRef = transitionRef;
}
-
/**
* Cree un media locator a partir de l'URL (String) demandee.
--- 329,336 ----
* @param transitionRef la reference du module Transition correspondant au meme client
*/
! public void setTransitionRef(Transition transitionRef) {
! this.transitionRef = transitionRef;
}
/**
* Cree un media locator a partir de l'URL (String) demandee.
***************
*** 330,347 ****
* @return un MediaLocator
*/
! static MediaLocator createMediaLocator(String url)
! {
MediaLocator ml;
! if (url.indexOf(":") > 0 && (ml = new MediaLocator(url)) != null)
return ml;
if (url.startsWith(File.separator)) {
! if ((ml = new MediaLocator("file:" + url)) != null)
return ml;
! } else {
! String file = "file:" + System.getProperty("user.dir") + File.separator + url;
! if ((ml = new MediaLocator(file)) != null)
return ml;
}
--- 340,361 ----
* @return un MediaLocator
*/
! static MediaLocator createMediaLocator(String url) {
MediaLocator ml;
! if (url.indexOf(":") > 0 && (ml = new MediaLocator(url)) != null) {
return ml;
+ }
if (url.startsWith(File.separator)) {
! if ( (ml = new MediaLocator("file:" + url)) != null) {
return ml;
! }
! }
! else {
! String file = "file:" + System.getProperty("user.dir") + File.separator +
! url;
! if ( (ml = new MediaLocator(file)) != null) {
return ml;
+ }
}
***************
*** 364,370 ****
synchronized (waitSync) {
try {
! while (p.getState() < state && stateTransitionOK)
waitSync.wait();
! } catch (Exception e) {}
}
return stateTransitionOK;
--- 378,386 ----
synchronized (waitSync) {
try {
! while (p.getState() < state && stateTransitionOK) {
waitSync.wait();
! }
! }
! catch (Exception e) {}
}
return stateTransitionOK;
***************
*** 385,413 ****
waitSync.notifyAll();
}
! } else if (evt instanceof ResourceUnavailableEvent) {
synchronized (waitSync) {
stateTransitionOK = false;
waitSync.notifyAll();
}
! } else if (evt instanceof EndOfMediaEvent) {
evt.getSourceController().close();
! } else if (evt instanceof MediaTimeSetEvent) {
System.err.println("- mediaTime set: " +
! ((MediaTimeSetEvent)evt).getMediaTime().getSeconds());
! } else if (evt instanceof StopAtTimeEvent) {
System.err.println("- stop at time: " +
! ((StopAtTimeEvent)evt).getMediaTime().getSeconds());
evt.getSourceController().close();
}
}
! public int stop()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
}
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
formerThreadReencode.stopProcessing();
formerThreadReencode = null;
--- 401,431 ----
waitSync.notifyAll();
}
! }
! else if (evt instanceof ResourceUnavailableEvent) {
synchronized (waitSync) {
stateTransitionOK = false;
waitSync.notifyAll();
}
! }
! else if (evt instanceof EndOfMediaEvent) {
evt.getSourceController().close();
! }
! else if (evt instanceof MediaTimeSetEvent) {
System.err.println("- mediaTime set: " +
! ( (MediaTimeSetEvent) evt).getMediaTime().getSeconds());
! }
! else if (evt instanceof StopAtTimeEvent) {
System.err.println("- stop at time: " +
! ( (StopAtTimeEvent) evt).getMediaTime().getSeconds());
evt.getSourceController().close();
}
}
! public int stop() {
! if (formerThreadReencode == null) {
! System.err.println(
! "Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
}
! else { // on arrete le processor et met la reference du ThreadReencode precedent a null
formerThreadReencode.stopProcessing();
formerThreadReencode = null;
***************
*** 418,420 ****
}
! }
--- 436,438 ----
}
! }
\ No newline at end of file
Index: ThreadReencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/ThreadReencode.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ThreadReencode.java 14 Mar 2003 03:26:19 -0000 1.6
--- ThreadReencode.java 17 Mar 2003 02:57:03 -0000 1.7
***************
*** 22,31 ****
import com.sun.media.rtp.*;
-
/**
* Classe ThreadReencode
*/
! class ThreadReencode extends Thread
! {
/**
* Champs de la classe ThreadReencode
--- 22,30 ----
import com.sun.media.rtp.*;
/**
* Classe ThreadReencode
*/
! class ThreadReencode
! extends Thread {
/**
* Champs de la classe ThreadReencode
***************
*** 47,53 ****
* @param reencodeRef reference du module Reencode pere
*/
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! Time startTime, Reencode reencodeRef)
! {
this.inputML = inputML;
this.reencodingAudioFormat = reencodingAudioFormat;
--- 46,51 ----
* @param reencodeRef reference du module Reencode pere
*/
! public ThreadReencode(MediaLocator inputML, AudioFormat reencodingAudioFormat,
! Time startTime, Reencode reencodeRef) {
this.inputML = inputML;
this.reencodingAudioFormat = reencodingAudioFormat;
***************
*** 65,72 ****
* @param reencodeRef reference du module Reencode pere
*/
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! VideoFormat reencodingVideoFormat, Time startTime,
! Reencode reencodeRef)
! {
this.inputML = inputML;
this.reencodingAudioFormat = reencodingAudioFormat;
--- 63,69 ----
* @param reencodeRef reference du module Reencode pere
*/
! public ThreadReencode(MediaLocator inputML, AudioFormat reencodingAudioFormat,
! VideoFormat reencodingVideoFormat, Time startTime,
! Reencode reencodeRef) {
this.inputML = inputML;
this.reencodingAudioFormat = reencodingAudioFormat;
***************
*** 83,88 ****
* http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
*/
! public void run()
! {
String resultat;
--- 80,84 ----
* http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
*/
! public void run() {
String resultat;
***************
*** 101,106 ****
private String createProcessor() {
! if (inputML == null)
return "Locator is null";
DataSource ds;
--- 97,103 ----
private String createProcessor() {
! if (inputML == null) {
return "Locator is null";
+ }
DataSource ds;
***************
*** 109,113 ****
try {
ds = javax.media.Manager.createDataSource(inputML);
! } catch (Exception e) {
return "Couldn't create DataSource";
}
--- 106,111 ----
try {
ds = javax.media.Manager.createDataSource(inputML);
! }
! catch (Exception e) {
return "Couldn't create DataSource";
}
***************
*** 116,122 ****
try {
processor = javax.media.Manager.createProcessor(ds);
! } catch (NoProcessorException npe) {
return "Couldn't create processor";
! } catch (IOException ioe) {
return "IOException creating processor";
}
--- 114,122 ----
try {
processor = javax.media.Manager.createProcessor(ds);
! }
! catch (NoProcessorException npe) {
return "Couldn't create processor";
! }
! catch (IOException ioe) {
return "IOException creating processor";
}
***************
*** 124,136 ****
// Wait for it to configure
boolean result = waitForState(processor, Processor.Configured);
! if (result == false)
return "Couldn't configure processor";
// Get the tracks from the processor
! TrackControl [] tracks = processor.getTrackControls();
// Do we have atleast one track?
! if (tracks == null || tracks.length < 1)
return "Couldn't find tracks in processor";
// Set the output content descriptor to RAW_RTP
--- 124,138 ----
// Wait for it to configure
boolean result = waitForState(processor, Processor.Configured);
! if (result == false) {
return "Couldn't configure processor";
+ }
// Get the tracks from the processor
! TrackControl[] tracks = processor.getTrackControls();
// Do we have atleast one track?
! if (tracks == null || tracks.length < 1) {
return "Couldn't find tracks in processor";
+ }
// Set the output content descriptor to RAW_RTP
***************
*** 141,184 ****
Format supported[];
! Format chosen;
! Format finalchosen;
! boolean atLeastOneTrack = false;
!
! // Program the tracks.
! for (int i = 0; i < tracks.length; i++) {
! Format format = tracks[i].getFormat();
! if (tracks[i].isEnabled()) {
! System.out.println("Track " + i + " is enabled");
! supported = tracks[i].getSupportedFormats();
!
! // We've set the output content to the RAW_RTP.
! // So all the supported formats should work with RTP.
! // We'll just pick the first one.
! if (supported.length > 0) {
! for(int j=0;j<supported.length;j++)
! System.out.println("Format supporte n" + j + " : " + supported[j].toString());
! if (supported[0] instanceof VideoFormat) {
! // For video formats, we should double check the
! // sizes since not all formats work in all sizes.
! chosen = checkForVideoSizes(tracks[i].getFormat(),
! supported[0]);
! } else {
! chosen = supported[0];
! }
! tracks[i].setFormat(chosen);
! System.err.println("Track " + i + " is set to transmit as:");
! System.err.println(" " + chosen);
! atLeastOneTrack = true;
! } else
! tracks[i].setEnabled(false);
! } else {
! tracks[i].setEnabled(false);
! System.out.println("Track " + i + " isn't enabled");
! }
}
-
- if (!atLeastOneTrack)
- return "Couldn't set any of the tracks to a valid RTP format";
// Realize the processor. This will internally create a flow
--- 143,158 ----
Format supported[];
! Format finalReencodingVideoFormat;
! // On indique au processor les formats de reencodage.
! if (!reencodeRef.multiMedia) {
! tracks[0].setFormat(reencodingAudioFormat); // 1 piste audio
! }
! else { // Le fichier est multimedia
! finalReencodingVideoFormat = checkForVideoSizes(tracks[0].getFormat(),
! reencodingVideoFormat);
! tracks[0].setFormat(finalReencodingVideoFormat);
! tracks[1].setFormat(reencodingAudioFormat);
}
// Realize the processor. This will internally create a flow
***************
*** 186,191 ****
// audio frames.
result = waitForState(processor, Controller.Realized);
! if (result == false)
return "Couldn't realize processor";
// Set the JPEG quality to .5.
--- 160,166 ----
// audio frames.
result = waitForState(processor, Controller.Realized);
! if (result == false) {
return "Couldn't realize processor";
+ }
// Set the JPEG quality to .5.
***************
*** 193,198 ****
// Commencer a encoder a partir de l'instant voulu
! if (startTime.getSeconds() > 0)
! {
processor.setMediaTime(startTime);
}
--- 168,172 ----
// Commencer a encoder a partir de l'instant voulu
! if (startTime.getSeconds() > 0) {
processor.setMediaTime(startTime);
}
***************
*** 214,219 ****
// and program it to output JPEG/RTP
result = createProcessor();
! if (result != null)
return result;
// Start the transmission
--- 188,194 ----
// and program it to output JPEG/RTP
result = createProcessor();
! if (result != null) {
return result;
+ }
// Start the transmission
***************
*** 244,248 ****
int width, height;
! Dimension size = ((VideoFormat)original).getSize();
Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
Format h263Fmt = new Format(VideoFormat.H263_RTP);
--- 219,223 ----
int width, height;
! Dimension size = ( (VideoFormat) original).getSize();
Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
Format h263Fmt = new Format(VideoFormat.H263_RTP);
***************
*** 251,270 ****
// For JPEG, make sure width and height are divisible by 8.
width = (size.width % 8 == 0 ? size.width :
! (int)(size.width / 8) * 8);
height = (size.height % 8 == 0 ? size.height :
! (int)(size.height / 8) * 8);
! } else if (supported.matches(h263Fmt)) {
// For H.263, we only support some specific sizes.
if (size.width < 128) {
width = 128;
height = 96;
! } else if (size.width < 176) {
width = 176;
height = 144;
! } else {
width = 352;
height = 288;
}
! } else {
// We don't know this particular format. We'll just
// leave it alone then.
--- 226,249 ----
// For JPEG, make sure width and height are divisible by 8.
width = (size.width % 8 == 0 ? size.width :
! (int) (size.width / 8) * 8);
height = (size.height % 8 == 0 ? size.height :
! (int) (size.height / 8) * 8);
! }
! else if (supported.matches(h263Fmt)) {
// For H.263, we only support some specific sizes.
if (size.width < 128) {
width = 128;
height = 96;
! }
! else if (size.width < 176) {
width = 176;
height = 144;
! }
! else {
width = 352;
height = 288;
}
! }
! else {
// We don't know this particular format. We'll just
// leave it alone then.
***************
*** 279,283 ****
}
-
/**
* Setting the encoding quality to the specified value on the JPEG encoder.
--- 258,261 ----
***************
*** 296,308 ****
if (cs[i] instanceof QualityControl &&
cs[i] instanceof Owned) {
! Object owner = ((Owned)cs[i]).getOwner();
// Check to see if the owner is a Codec.
// Then check for the output format.
if (owner instanceof Codec) {
! Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);
for (int j = 0; j < fmts.length; j++) {
if (fmts[j].matches(jpegFmt)) {
! qc = (QualityControl)cs[i];
qc.setQuality(val);
System.err.println("- Setting quality to " +
--- 274,286 ----
if (cs[i] instanceof QualityControl &&
cs[i] instanceof Owned) {
! Object owner = ( (Owned) cs[i]).getOwner();
// Check to see if the owner is a Codec.
// Then check for the output format.
if (owner instanceof Codec) {
! Format fmts[] = ( (Codec) owner).getSupportedOutputFormats(null);
for (int j = 0; j < fmts.length; j++) {
if (fmts[j].matches(jpegFmt)) {
! qc = (QualityControl) cs[i];
qc.setQuality(val);
System.err.println("- Setting quality to " +
***************
*** 312,322 ****
}
}
! if (qc != null)
break;
}
}
}
-
/****************************************************************
* Convenience methods to handle processor's state changes.
--- 290,300 ----
}
}
! if (qc != null) {
break;
+ }
}
}
}
/****************************************************************
* Convenience methods to handle processor's state changes.
***************
*** 341,348 ****
if (state == Processor.Configured) {
p.configure();
! } else if (state == Processor.Realized) {
System.out.println("On va realiser le processor");
p.realize();
- System.out.println("Le processor est realized");
}
--- 319,326 ----
if (state == Processor.Configured) {
p.configure();
! }
! else if (state == Processor.Realized) {
System.out.println("On va realiser le processor");
p.realize();
}
***************
*** 354,358 ****
try {
getStateLock().wait();
! } catch (InterruptedException ie) {
return false;
}
--- 332,337 ----
try {
getStateLock().wait();
! }
! catch (InterruptedException ie) {
return false;
}
***************
*** 360,367 ****
}
! if (failed)
return false;
! else
return true;
}
--- 339,348 ----
}
! if (failed) {
return false;
! }
! else {
return true;
+ }
}
***************
*** 370,374 ****
****************************************************************/
! class StateListener implements ControllerListener {
public void controllerUpdate(ControllerEvent ce) {
--- 351,356 ----
****************************************************************/
! class StateListener
! implements ControllerListener {
public void controllerUpdate(ControllerEvent ce) {
***************
*** 376,384 ****
// If there was an error during configure or
// realize, the processor will be closed
! if (ce instanceof ControllerClosedEvent)
setFailed();
// All controller events, send a notification
// to the waiting thread in waitForState method.
if (ce instanceof ControllerEvent) {
synchronized (getStateLock()) {
--- 358,367 ----
// If there was an error during configure or
// realize, the processor will be closed
! if (ce instanceof ControllerClosedEvent) {
setFailed();
// All controller events, send a notification
// to the waiting thread in waitForState method.
+ }
if (ce instanceof ControllerEvent) {
synchronized (getStateLock()) {
***************
*** 390,395 ****
synchronized (endOfMediaSent) {
System.out.println("Evenement DataStarved traite");
! if (!endOfMediaSent.booleanValue())
endOfMediaSent = Boolean.valueOf(true);
try {
Thread.sleep(4000);
--- 373,379 ----
synchronized (endOfMediaSent) {
System.out.println("Evenement DataStarved traite");
! if (!endOfMediaSent.booleanValue()) {
endOfMediaSent = Boolean.valueOf(true);
+ }
try {
Thread.sleep(4000);
|
Update of /cvsroot/madsserv/madsserv/src/simulator In directory sc8-pr-cvs1:/tmp/cvs-serv32599 Added Files: DialogServer.java DialogSocket.java ErrorPopUp.java MadsservSimulator.java Simulator.java ThreadRead.java ThreadWrite.java Log Message: ajout du simulateur qui ne gere pas encore les scripts --- NEW FILE: DialogServer.java --- import java.util.*; import java.io.*; import java.net.*; import java.lang.Object.*; import java.lang.System.*; /** * DialogServer c'est la classe qui herite de la classe dialogSocket et qui gere les dialogues avec le serveur */ public class DialogServer extends DialogSocket { private Simulator simulator; /** * C'est le constructeur de la classe */ public DialogServer(Socket _socketServer, Simulator _simulator) { super(_socketServer); simulator = _simulator; clientID = -1; } /** * incomingMessage methode qui a ete declare abstraite dans DialogSocket et qui gere l'arivee de nouveaux messages du serveur * @param _type type de message qui arrive (c'est un entier) * @param _message tableau de chaine de characteres qui contient les messages du serveur */ public void incomingMessage(int _type, String[] _message) { int lgth = _message.length; int qualityLevel = 0; switch (_type) { case 5: { // if (lgth < 2) raise exception; //lecture du deuxieme champ : ClientID try { clientID = Integer.parseInt(_message[0]); } catch (NumberFormatException e) { System.out.println("Le deuxieme champ du message est incorrect"); } simulator.showError(_message[1]); simulator.endConnexion(); break; } //message d'effacement d'un client de la table; case 3: { // if (lgth < 2) raise exception; //lecture du deuxieme champ : ClientID try { clientID = Integer.parseInt(_message[0]); } catch (NumberFormatException e) { System.out.println("Le deuxieme champ du message est incorrect"); } System.out.println("On efface le client : " + clientID); // table.effacerClient(clientID); simulator.tableClients.removeClientReport(clientID); break; } case 1: { // if (lgth < 2) raise exception; //lecture du deuxieme champ : ClientID try { clientID = Integer.parseInt(_message[0]); } catch (NumberFormatException e) { System.out.println("Le deuxieme champ du message est incorrect"); } // lecture du troisieme champ du message : portBase try { qualityLevel = Integer.parseInt(_message[1]); } catch (NumberFormatException e) { System.out.println("Le troisieme champ du message est incorrect"); } // table.ajoutElement(clientID,qualityLevel); System.out.println("ClientID : " + clientID); System.out.println("Niveau Qualite : " + qualityLevel); if (simulator.tableClients.getRowForClient(clientID) == -1) simulator.tableClients.newClientRecord(clientID,qualityLevel); else { simulator.tableClients.updateClientReport(clientID,qualityLevel); } } } } } --- NEW FILE: DialogSocket.java --- import java.util.*; import java.io.*; import java.net.*; /** * <code>DialogServer</code> fournit le modele d'objet permettant la gestion * de la communication par socket entre deux stations grace a deux threads * (lecture et ecriture). <code>DialogSocket</code> assure une communication * dediee. * <p> * <code>DialogServer</code> fournit une methode d'envoi de messages sur le * socket (par l'intermediaire de {@link ThreadWrite} et declare la methode * abstraite de reception des messages. * @see ThreadRead * @see ThreadWrite * @author Julien Carbonell */ public abstract class DialogSocket { private final int TIME_OUT = 1000; // identite du client protected int clientID; // socket gere par DialogSocket protected Socket mySocket; // streams d'entree et de sortie protected PrintWriter output; protected InputStreamReader input; protected BufferedReader binput; // Thread d'entree et thread de sortie protected ThreadRead threadInput; protected ThreadWrite threadOutput; /** * Constructeur de <code>DialogSocket</code>. * @param _mySocket le {@link Socket} de communication. */ public DialogSocket(Socket _mySocket) { mySocket = _mySocket; try { //mySocket.setSoTimeout(TIME_OUT); output = new PrintWriter(mySocket.getOutputStream()); input = new InputStreamReader(mySocket.getInputStream()); binput = new BufferedReader(input); threadInput = new ThreadRead("Thread d'ecoute ID", binput, this); } catch (IOException e) { System.out.println(e.getMessage()); } /*catch (SocketException e) { System.out.println(e.getMessage()); }*/ } /** * Traite l'arrivee d'un nouveau message sur le socket. * @param _type le type du message. * @param _message le tableau de <code>String</code> contenant les champs du * message reçu. */ public abstract void incomingMessage(int _type, String[] _message); /** * Traite la demande d'envoi d'un message sur le socket. Le message a envoyer * est fourni sous la forme d'un tableau de {@link String} contenant les * champs du message * @param _type le type du message. * @param _message le tableau de <code>String</code> contenant les champs du * message a envoyer. */ public void sendMessage(int _type, String[] _message) { threadOutput = new ThreadWrite("Thread d'ecriture ID", output, this); /* String[] messageToSend; if (_message == null) { messageToSend = new String[1]; messageToSend[0] = String.valueOf(clientID); } else { messageToSend = new String[_message.length + 1]; messageToSend[0] = String.valueOf(clientID); for (int i = 0; i < _message.length; i++) { messageToSend[i + 1] = _message[i]; } }*/ threadOutput.setMessageToSend(_type, _message); threadOutput.start(); } /** * Renvoie l'ID du client. * @return ID du client. */ public int getClientID() { return clientID; } /** * Demarre l'ecoute du socket */ public void start() { threadInput.start(); } /** * Stoppe le gestion de la communication et ferme le socket. */ public synchronized void stop() { try { System.err.println("j'entre dans le stop de dialog socket"); //threadInput = null; //System.gc(); //threadInput.interrupt(); //threadInput.setEnd(); System.err.println("le thread est mort"); Thread.sleep(1000); //binput.close(); //System.err.println("le binput est mort"); if (!mySocket.isClosed()) mySocket.close(); System.err.println("le socket est mort"); //System.err.println("le socket est ferme " + mySocket.isClosed()); System.out.println("Fin DialogServer "); } catch (Exception e) {} } } --- NEW FILE: ErrorPopUp.java --- import java.awt.*; import java.net.*; import java.awt.event.*; import java.awt.Component.*; import java.awt.TextComponent.*; import java.awt.geom.Point2D.*; import java.awt.Point.*; /** * <code>ErrorPopUp</code> est une popup qui apparait lorsque des erreurs apparaissent. * @author Xavier Deplancq */ public class ErrorPopUp extends Frame { private Container contentPane; private Panel panelNorth = new Panel(); private Panel panelSouth = new Panel(); private Label errorMessage = new Label(); private BorderLayout borderLayout1 = new BorderLayout(); private Button OK; /** * Constructeur de la classe ErrorPopUp * @param errMessage le Message qui doit etre affiche * @param _client la reference du client */ public ErrorPopUp(String errMessage, Simulator _simulator) { enableEvents(AWTEvent.WINDOW_EVENT_MASK); errorMessage.setText(errMessage); panelNorth.add(errorMessage); OK = new Button("OK"); OK.setSize(new Dimension(60, 15)); OK.addActionListener(new ErrorPopUp_OK_ActionAdapter(this)); panelSouth.add(OK); contentPane = this; this.setSize(260, 120); panelNorth.setBackground(new Color(236, 233, 216)); panelSouth.setBackground(new Color(236, 233, 216)); contentPane.setLayout(borderLayout1); contentPane.add(panelNorth, borderLayout1.CENTER); contentPane.add(panelSouth, borderLayout1.SOUTH); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension simulatorSize = _simulator.getSize(); Dimension popupSize = this.getSize(); double simulatorPlaceX = _simulator.getX(); double simulatorPlaceY = _simulator.getY(); if (popupSize.height > simulatorSize.height) { popupSize.height = simulatorSize.height; } if (popupSize.width > simulatorSize.width) { popupSize.width = simulatorSize.width; } this.setLocation( (int) (simulatorPlaceX) + (popupSize.height) / 2, (int) (simulatorPlaceY) + simulatorSize.width / 2); showWindow(); } /** * OK_actionPerformed qui sert lorsque l'on appuie sur le bouton OK * @param e l'evenement */ public void OK_actionPerformed(ActionEvent e) { setVisible(false); } /** * processWindowEvent c est une methode qui est appele lorsque l'on ferme la boite de dialogue * @param l evenement qui indique que l'on ferme la fenetre */ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { OK_actionPerformed(null); } } /** * Methode qui affiche la boite de dialogue */ public void showWindow() { setVisible(true); } /** * Classe qui ecoute si l'on appui sur le bouton OK */ class ErrorPopUp_OK_ActionAdapter implements ActionListener { ErrorPopUp adaptee; ErrorPopUp_OK_ActionAdapter(ErrorPopUp adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.OK_actionPerformed(e); } } } --- NEW FILE: MadsservSimulator.java --- //package madsserv_planification; import javax.swing.UIManager; import java.awt.*; import java.net.*; /** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author Christele Champagnat et Xavier Deplancq * @version 1.0 **/ /** * MadsservSimulator c'est la classe MadsservSimulator */ public class MadsservSimulator { /** * champs de la classe MadsservSimulator */ private boolean packFrame = false; //private Socket mySocket; /** * MadsservSimulator constructeur de la calsse */ public MadsservSimulator() { Simulator simulator = new Simulator(); //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) { simulator.pack(); } else { // String[] request = new String[1]; // request[0] = ""; simulator.validate(); // dialogServer.start(); // dialogServer.sendMessage(0,request); } //on centre ici la fenetre Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension simulatorSize = simulator.getSize(); if (simulatorSize.height > screenSize.height) { simulatorSize.height = screenSize.height; } if (simulatorSize.width > screenSize.width) { simulatorSize.width = screenSize.width; } simulator.setLocation( (screenSize.width - simulatorSize.width) / 2, (screenSize.height - simulatorSize.height) / 2); simulator.setVisible(true); } /** * Methode main du Simulateur */ public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } new MadsservSimulator(); } /* static void prUsage() { System.err.println("Usage: ClientRTPManager <session> <session> ..."); System.err.println(" <session>: <address>/<port>/<ttl>"); System.exit(0); }*/ } --- NEW FILE: Simulator.java --- //package madsserv_planification; import java.awt.*; import java.net.*; import java.awt.event.*; import java.awt.Component.*; import java.awt.TextComponent.*; import java.awt.Checkbox.*; import java.awt.CheckboxGroup.*; import javax.swing.UIManager; import javax.swing.*; import javax.swing.JComponent.*; import javax.swing.JTable.*; import javax.swing.table.*; import javax.swing.border.*; import java.util.Vector.*; public class Simulator extends Frame { private Container contentPane; //Declaration de la fenetre private Panel panelSouth = new Panel(); private Panel panelNorth = new Panel(); private Panel panelEmpty = new Panel(); private JPanel jPanelReport = new JPanel(); //Declaration des types de menu private MenuBar menuBar1 = new MenuBar(); private Menu menuFile = new Menu(); private MenuItem itemOpenClient = new MenuItem(); private MenuItem itemExit = new MenuItem(); private Button go; //Declaration de la zone de texte private TextField qualityChoice; private TextField clientId; private TextField script; private TextField AdServer; private Label qualityLabel = new Label( /*"qualité client"*/); private Label clientIDLabel = new Label( /*"identite client"*/); private Label erreurLabel = new Label( /*"erreur"*/); private Label AdLabel = new Label(); private Label nivQualiteLabel = new Label(); private Label tabClientIdLabel = new Label(); //graphique private GridLayout gridLayout2 = new GridLayout(1, 1); private BorderLayout borderLayout1 = new BorderLayout(); private GridBagLayout gridBagLayoutNorth = new GridBagLayout(); private GridBagLayout gridBagLayoutSouth = new GridBagLayout(); //Socket private Socket mySocket = null; private DialogServer dialogServer; TableClients tableClients = new TableClients(); /* public static void main(String[] args) { Simulator simulator; boolean packFrame=false; try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); } simulator = new Simulator(); if (packFrame) { simulator.pack(); } else { simulator.validate(); } //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = simulator.getSize(); if (frameSize.height > screenSize.height) { frameSize.height = screenSize.height; } if (frameSize.width > screenSize.width) { frameSize.width = screenSize.width; } simulator.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); simulator.setVisible(true); }*/ // Construction du simulateur public Simulator() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); // afficheTable(); } catch (Exception e) { e.printStackTrace(); } } //initialisation de la fenetre private void jbInit() throws Exception { contentPane = this; contentPane.setLayout(borderLayout1); this.setSize(new Dimension(480, 640)); this.setTitle("Madsserv Simulator"); jPanelReport.setLayout(gridLayout2); tableClients.setgraph(jPanelReport); //création de la zone de texte qualityChoice = new TextField(""); clientId = new TextField(""); script = new TextField(""); //nommage des menus menuFile.setLabel("File"); itemExit.setLabel("Exit"); itemOpenClient.setLabel("open client"); itemExit.addActionListener(new Simulator_itemExit_ActionAdapter(this)); //construction des menus menuFile.add(itemOpenClient); menuFile.add(itemExit); menuBar1.add(menuFile); this.setMenuBar(menuBar1); //création du boutton GO go = new Button("Start!"); go.setSize(new Dimension(60, 15)); go.addActionListener(new Simulator_boutongo_ActionAdapter(this)); qualityLabel.setText("qualité client :"); clientIDLabel.setText("Identité client:"); erreurLabel.setText("script:"); AdLabel.setText("Serv :"); tabClientIdLabel.setText("Client"); nivQualiteLabel.setText("Qualite "); AdServer = new TextField("Dronej.rezel.com:4998"); qualityLabel.setSize(new Dimension(50, 15)); clientIDLabel.setSize(new Dimension(50, 15)); erreurLabel.setSize(new Dimension(50, 15)); AdLabel.setSize(new Dimension(50, 15)); panelNorth.setBackground(new Color(236, 230, 230)); panelSouth.setBackground(new Color(236, 230, 230)); panelSouth.setLayout(gridBagLayoutSouth); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(1, 5, 1, 5); c.weightx = 0.0; c.weighty = 1.0; panelSouth.add(clientIDLabel, c); c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; panelSouth.add(clientId, c); c.gridwidth = GridBagConstraints.RELATIVE; c.weightx = 0.0; panelSouth.add(qualityLabel, c); c.weightx = 1.0; panelSouth.add(qualityChoice, c); c.gridwidth = GridBagConstraints.RELATIVE; panelNorth.setLayout(gridBagLayoutNorth); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(1, 5, 1, 5); c.weightx = 0.0; c.weighty = 1.0; panelNorth.add(erreurLabel, c); c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1.0; panelNorth.add(script, c); c.gridwidth = GridBagConstraints.RELATIVE; c.weightx = 0.0; panelNorth.add(AdLabel, c); c.weightx = 1.0; c.gridwidth = GridBagConstraints.REMAINDER; panelNorth.add(AdServer, c); c.weightx = 0.0; //c.gridwidth = GridBagConstraints.REMAINDER; panelNorth.add(go, c); contentPane.add(panelSouth, BorderLayout.SOUTH); contentPane.add(panelNorth, BorderLayout.NORTH); contentPane.add(jPanelReport, BorderLayout.CENTER); } public void itemExit_actionPerformed(ActionEvent e) { try { String messageToSend[] = new String[1]; messageToSend[0] = "fin de la connexion"; dialogServer.sendMessage(4, messageToSend); System.exit(0); } catch (Exception ex) { System.exit(0); } } protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { itemExit_actionPerformed(null); } } public void boutongo_actionPerformed(ActionEvent evt) { String q, clId; String fo1 = "", fo2 = ""; String[] messageToSend; q = qualityChoice.getText(); clId = clientId.getText(); System.out.println(q); System.out.println(clId); if (mySocket == null) { try { mySocket = new Socket(getAddressServer(), getServerPort()); System.out.println("Simulateur demarre"); } catch (Exception e) { showError("serveur ou port incorrect"); } dialogServer = new DialogServer(mySocket, this); dialogServer.start(); } else { if (((getClientId().compareTo("")) != 0) && ((getqualityClient().compareTo("")) != 0)) { messageToSend = new String[2]; messageToSend[0] = getClientId(); messageToSend[1] = getqualityClient(); dialogServer.sendMessage(2, messageToSend); } } } /** * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client * @return InetAddress du server */ public InetAddress getAddressServer() { String host; int columnPosition; host = AdServer.getText(); columnPosition = host.indexOf(':'); try { return (InetAddress.getByName(host.substring(0, columnPosition))); } catch (UnknownHostException e) { return (null); } } /** * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client * @return int le numero du port sur lequel, on doit se connecter au serveur */ public int getServerPort() { String host; int columnPosition; host = AdServer.getText(); columnPosition = host.indexOf(':'); return (Integer.parseInt(host.substring(columnPosition + 1))); } public String getqualityClient() { String q; q = qualityChoice.getText(); return q; } public String getClientId() { String clId; clId = clientId.getText(); return clId; } public void endConnexion() { dialogServer.stop(); mySocket = null; } public void showError(String messageErreur) { ErrorPopUp errorPopUp = new ErrorPopUp(messageErreur, this); } } class Simulator_itemExit_ActionAdapter implements ActionListener { Simulator adaptee; Simulator_itemExit_ActionAdapter(Simulator adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.itemExit_actionPerformed(e); } } class Simulator_boutongo_ActionAdapter implements ActionListener { Simulator adaptee; Simulator_boutongo_ActionAdapter(Simulator adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent evt) { adaptee.boutongo_actionPerformed(evt); } } class TableClients extends JTable { private boolean DEBUG = false; private String[] columnNames = { "ID Client", "Niveau de qualite"}; private Object[][] data = { { new Integer(-2), new Integer(-2)} }; private MyTableModel myModel = null; public TableClients() { super(); myModel = new MyTableModel(data, columnNames); setModel(myModel); // setPreferredScrollableViewportSize(new Dimension(500, 70)); } public void newClientRecord(int _clientID, int _quality) { Object[] newRow = { new Integer(_clientID), new Integer(_quality)}; myModel.insertRow(0, newRow); } public int getRowForClient(int _clientID) { for (int i = 0; i < myModel.getRowCount(); i++) { if (_clientID == ( (Integer) myModel.getValueAt(i, 0)).intValue()) { return i; } } return -1; } public void removeClientReport(int _clientID) { ( (DefaultTableModel) getModel()).removeRow(getRowForClient( _clientID)); } public void updateClientReport(int _clientID, int _qualityLevel) { int row = getRowForClient(_clientID); if (_qualityLevel != -1) { setValue(new Integer(_qualityLevel), row, 5); ; } } public void setValue(Object value, int row, int col) { myModel.setValueAt(value, row, col); } public void setgraph(JPanel jp) { JScrollPane sc = new JScrollPane(this); jp.add(sc); } /* public void modifyValue(Object _value, int _row, int _col) { setValueAt(_value, _row, _col); }*/ class MyTableModel extends DefaultTableModel { public MyTableModel() { super(); } public MyTableModel(Object[][] data, Object[] columnNames) { super(data, columnNames); } /* * JTable uses this method to determine the default renderer/ * editor for each cell. If we didn't implement this method, * then the last column would contain text ("true"/"false"), * rather than a check box. */ public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } public boolean isCellEditable(int row, int column) { return false; } private void printDebugData() { int numRows = getRowCount(); int numCols = getColumnCount(); for (int i = 0; i < numRows; i++) { System.out.print(" row " + i + ":"); for (int j = 0; j < numCols; j++) { System.out.print(" " + data[i][j]); } System.out.println(); } System.out.println("--------------------------"); } } } --- NEW FILE: ThreadRead.java --- import java.util.*; import java.io.*; import java.net.*; /** * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. * Il effectue une ecoute permanente. * <p> * Il gere l'extraction du message en isolant les elements protocolaires de la * transmission du message. * @see ThreadWrite * @see DialogSocket * @author Julien Carbonell */ public class ThreadRead extends Thread { boolean end = false; // objet parent qui gere les entrees-sorties sur le socket protected DialogSocket parent; // BufferedReader sur lequel sont lus les messages protected BufferedReader binput; protected String temp = ""; protected String message = ""; protected boolean waitingMessage = true; protected int messageType = -1; /** * Constructeur de <code>ThreadRead</code>. * @param _name le nom du thread. * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. */ public ThreadRead(String _name, BufferedReader _binput, DialogSocket _parent) { super(_name + _parent.getClientID()); parent = _parent; binput = _binput; } /** * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. */ public void run() { try { while ( (temp = binput.readLine()) != null) { if (temp != null) { if (waitingMessage && (temp.charAt(0) == '#')) { // un nouveau message commence waitingMessage = false; } else { if (!waitingMessage && (temp.charAt(0) == '#')) { waitingMessage = true; messageType = Integer.parseInt(message.substring(0, message.indexOf('\n'))); System.out.println("Le Thread Read a recu\n" + message); message = message.substring(message.indexOf('\n') + 1, message.length() - 1); parent.incomingMessage(messageType, parseMessage(message)); message = ""; } else { message = message.concat(temp + "\n"); } } } } } /* catch (SocketTimeoutException e) { System.out.println(e.getMessage()); }*/ catch (Exception e) { e.printStackTrace(); } finally { try { // binput.close(); System.out.println(getName() + Thread.currentThread() + " : Stopped !!! "); } catch (Exception e) { System.out.println(e.getMessage()); } } } protected String[] parseMessage(String _message) { return _message.split("\n"); } } --- NEW FILE: ThreadWrite.java --- import java.util.*; import java.io.*; import java.net.*; /** * <code>ThreadWrite</code> definit un thread d'ecriture sur un {@link PrintWriter}. * Sa duree d'execution est celle de l'envoi d'un message. * <p> * Il gere l'encapsulation du message en ajoutant les elements protocolaires de la * transmission du message. * @see ThreadRead * @see DialogSocket * @author Julien Carbonell */ public class ThreadWrite extends Thread { // objet parent qui gere les entrees-sorties sur le socket protected DialogSocket parent; // objet sur lequel sont dirigees les ecritures protected PrintWriter output; protected String messageToSend = ""; /** * Constructeur de <code>ThreadWrite</code>. * @param _name le nom du thread. * @param _binput le {@link PrinterWriter} sur lequel ecrit <code>ThreadWrite</code>. * @param _parent le {@link DialogSocket} qui gere le <code>ThreadWrite</code>. */ public ThreadWrite(String _name, PrintWriter _output, DialogSocket _parent) { super(_name + _parent.getClientID()); parent = _parent; output = _output; } // met a jour le message a envoyer public synchronized void setMessageToSend(int _type, String[] _message) { messageToSend=""; messageToSend = _type + "\n"; for(int i = 0; i< _message.length; i++) { messageToSend = messageToSend.concat(_message[i] + "\n"); } } /** * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. */ public void run() { try { if (messageToSend.compareTo("") != 0) { System.out.println("Message envoye par le thread output " + "#\n" + messageToSend + "#"); output.println("#\n" + messageToSend + "#"); output.flush(); } } catch (Exception e) { e.printStackTrace(); } finally { try { System.out.println(getName() + Thread.currentThread() + " : Stopped !!! "); } catch (Exception e) { } } } } |
|
From: <dep...@us...> - 2003-03-15 22:47:33
|
Update of /cvsroot/madsserv/madsserv/src/client In directory sc8-pr-cvs1:/tmp/cvs-serv31465 Modified Files: Client.java ClientRTPManager.java DialogServer.java ErrorPopUp.java MadsservClient.java PlayerPanel.java ThreadRTPManager.java ThreadRead.java ThreadWrite.java Log Message: le client qui marche pas mal Index: Client.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/Client.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Client.java 14 Mar 2003 03:26:17 -0000 1.7 --- Client.java 15 Mar 2003 22:47:30 -0000 1.8 *************** *** 1,383 **** ! //package madsserv_planification; ! ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.Checkbox.*; ! import java.awt.CheckboxGroup.*; ! import javax.swing.*; ! ! /** ! * <p>Title: Client </p> ! * <p>Description: La Classe Client est l'interface graphique du client</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! */ ! ! public class Client ! extends Frame { ! /** ! * Champs de la Classe Reencode ! */ ! ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelCenter = new Panel(); ! private Panel panelSouth = new Panel(); ! private Panel panelEmpty = new Panel(); ! private MenuBar menuBar1 = new MenuBar(); ! private Menu menuFile = new Menu(); ! private MenuItem menuOpenURL = new MenuItem(); ! private MenuItem menuFileExit = new MenuItem(); ! private Label statusBar = new Label(); ! private Label URLLabel = new Label(); ! private Label AdLabel = new Label(); ! ! private TextField URLChoice; ! private TextField AdServer; ! private CheckboxGroup cbg = new CheckboxGroup(); ! private Checkbox formatMPEG; ! private Checkbox formatJPEG; ! private Button go; ! ! private PlayerPanel playerPanel = null; ! ! private BorderLayout borderLayout1 = new BorderLayout(); ! private GridBagLayout gridBagLayoutNorth = new GridBagLayout(); ! private GridBagLayout gridBagLayoutSouth = new GridBagLayout(); ! ! private boolean insVideo = false; ! ! private Socket mySocket = null; ! private DialogServer dialogServer; ! ! ! ! /** ! * Contructeur de la Classe Client ! */ ! ! public Client() { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! try { ! jbInit(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * setPlayerPanel crée l'interface graphique du Client ! * @param pp il s'agit d'un PlayerPanel qui est une classe que nous avons crée ! * @vid est un booleen qui nous dit si le player a cree est de la video ou de l'audio ! */ ! ! public void setPlayerPanel(PlayerPanel pp, boolean vid) { ! Panel panelTemp; ! ! if (playerPanel == null) { ! panelTemp = panelEmpty; ! } ! else ! ! { ! panelTemp = playerPanel; ! } ! System.out.println("video :" + vid); ! System.out.println("insvideo :" + insVideo); ! ! // on teste ici pour savoir si on doit cree un player video ou un player audio ! if (vid) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! insVideo = true; ! } ! ! else if (!insVideo) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! } ! } ! ! /** ! * jbinit lance la creation de l'interface graphique. ! */ ! private void jbInit() throws Exception { ! ! contentPane = this; ! contentPane.setLayout(borderLayout1); ! this.setSize(new Dimension(240, 320)); ! this.setTitle("Madsserv Client"); ! setAfficheStatusBar("coucou"); ! URLChoice = new TextField("file:/stud/users/promo04/carbonel/tmp/video/kiss_cool_1.mpeg"); ! AdServer = new TextField("fresnel.enst.fr:5000"); ! menuFile.setLabel("File"); ! menuOpenURL.setLabel("Open URL"); ! menuOpenURL.addActionListener(new Client_Menu_OpenURL_ActionAdapter(this)); ! menuFileExit.setLabel("Exit"); ! menuFileExit.addActionListener(new Client_menuFileExit_ActionAdapter(this)); ! menuFile.add(menuOpenURL); ! menuFile.add(menuFileExit); ! menuBar1.add(menuFile); ! this.setMenuBar(menuBar1); ! ! formatMPEG = new Checkbox("MPEG", cbg, true); ! ! formatJPEG = new Checkbox("JPEG", cbg, false); ! ! go = new Button("Go!"); ! go.setSize(new Dimension(60, 15)); ! go.addActionListener(new Client_boutongo_ActionAdapter(this)); ! ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! panelSouth.setLayout(gridBagLayoutSouth); ! GridBagConstraints c = new GridBagConstraints(); ! c.fill = GridBagConstraints.BOTH; ! c.insets = new Insets(1, 5, 1, 5); ! c.weightx = 1.0; ! c.weighty = 1.0; ! panelSouth.add(formatMPEG, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelSouth.add(formatJPEG, c); ! c.weightx = 0.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelSouth.add(go, c); ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.weightx = 0.0; ! c.gridwidth = 2; ! panelSouth.add(statusBar, c); ! ! URLLabel.setText("URL :"); ! AdLabel.setText("Serv:"); ! URLLabel.setSize(new Dimension(30, 15)); ! URLChoice.setSize(new Dimension(30, 15)); ! AdLabel.setSize(new Dimension(30, 15)); ! AdServer.setSize(new Dimension(30, 15)); ! ! panelNorth.setLayout(gridBagLayoutNorth); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.gridwidth = 1; ! c.weightx = 0.0; ! c.weighty = 1.0; ! panelNorth.add(URLLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelNorth.add(URLChoice, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.weightx = 0.0; ! panelNorth.add(AdLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelNorth.add(AdServer, c); ! ! contentPane.add(panelSouth, BorderLayout.SOUTH); ! contentPane.add(panelNorth, BorderLayout.NORTH); ! ! contentPane.add(panelEmpty, BorderLayout.CENTER); ! ! } ! ! /** ! * menuFileExit_actionPerformed est à l'ecoute d'un evenement signifiant l'arret du client ! * @param e c'est l'evenemet qui met fin au client ! */ ! public void menuFileExit_actionPerformed(ActionEvent e) { ! try { ! String messageToSend[] = new String[1]; ! messageToSend[0] = "fin de la connexion"; ! dialogServer.sendMessage(4, messageToSend); ! System.exit(0); ! } ! catch (Exception ex) { ! System.exit(0); ! } ! } ! ! /** ! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre ! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre ! */ ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! menuFileExit_actionPerformed(null); ! } ! } ! ! /** ! * boutongo_actionPerformed Methode qui permet de lancer la connexion lorsque l'on clique sur le bouton go ! * @param evt c'est l'evenement qui indique que l'on a clique sur le bouton go ! */ ! public void boutongo_actionPerformed(ActionEvent evt) { ! ! String[] messageToSend; ! ! if (mySocket == null) { ! try { ! mySocket = new Socket(getAddressServer(), getServerPort()); ! } ! catch (Exception e) { ! showError("Le serveur ou le port n'est pas correct"); ! } ! ! dialogServer = new DialogServer(mySocket, this); ! dialogServer.start(); ! } ! ! else { ! // if ( (mySocket.isClosed()) == false) { ! messageToSend = new String[2]; ! messageToSend[0] = getURL(); ! messageToSend[1] = getFormatPrefere(); ! ! dialogServer.sendMessage(2, messageToSend); ! /*} ! else { ! try { ! mySocket.connect(new InetSocketAddress(getAddressServer(), ! getServerPort())); ! } ! catch (Exception e) { ! } ! }*/ ! } ! } ! ! public void endConnexion() { ! dialogServer.stop(); ! mySocket = null; ! } ! ! public void showError(String messageErreur) ! { ! ErrorPopUp errorPopUp = new ErrorPopUp(messageErreur,this); ! } ! ! /** ! * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client ! * @return InetAddress du server ! */ ! public InetAddress getAddressServer() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! try { ! return (InetAddress.getByName(host.substring(0, columnPosition))); ! } ! ! catch (UnknownHostException e) { ! return (null); ! } ! } ! ! /** ! * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client ! * @return int le numero du port sur lequel, on doit se connecter au serveur ! */ ! public int getServerPort() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! ! return (Integer.parseInt(host.substring(columnPosition + 1))); ! ! } ! ! /** ! * getURL permet d'obtenir l'URL du fichier multimedia que l'on souhaite visionner, cet URL est rentre dans une zone de texte sur l'interface graphique du client ! * @return String l'adresse du media demande ! */ ! public String getURL() { ! ! return (URLChoice.getText()); ! } ! ! public String getFormatPrefere() { ! ! if (formatMPEG.getState()) { ! return ("MPEG"); ! } ! ! else { ! if (formatJPEG.getState()) { ! return ("JPEG"); ! } ! else { ! return (""); ! } ! } ! ! } ! ! /** ! * setAfficheStatusBar est une methode qui permet d'afficher en bas du client un message envoye par le server ! * @param _message un message envoye sous forme de String envoye par le serveur ! */ ! public void setAfficheStatusBar(String _message) { ! statusBar.setText(_message); ! } ! ! /** ! * Client_menuFileExit_ActionAdapter, classe qui ecoute pour savoir si on clique sur le menu exit et envoie alors l'evenement ! */ ! class Client_menuFileExit_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_menuFileExit_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.menuFileExit_actionPerformed(e); ! } ! } ! ! /** ! * Client_boutongo_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton go et envoie alors l'evenement ! */ ! class Client_boutongo_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_boutongo_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! ! /** ! * Client_Menu_OpenURL_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton OpenURL et envoie alors l'evenement ! */ ! class Client_Menu_OpenURL_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_Menu_OpenURL_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! } --- 1,383 ---- ! //package madsserv_planification; ! ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.Checkbox.*; ! import java.awt.CheckboxGroup.*; ! import javax.swing.*; ! ! /** ! * <p>Title: Client </p> ! * <p>Description: La Classe Client est l'interface graphique du client</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! */ ! ! public class Client ! extends Frame { ! /** ! * Champs de la Classe Reencode ! */ ! ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelCenter = new Panel(); ! private Panel panelSouth = new Panel(); ! private Panel panelEmpty = new Panel(); ! private MenuBar menuBar1 = new MenuBar(); ! private Menu menuFile = new Menu(); ! private MenuItem menuOpenURL = new MenuItem(); ! private MenuItem menuFileExit = new MenuItem(); ! private Label statusBar = new Label(); ! private Label URLLabel = new Label(); ! private Label AdLabel = new Label(); ! ! private TextField URLChoice; ! private TextField AdServer; ! private CheckboxGroup cbg = new CheckboxGroup(); ! private Checkbox formatMPEG; ! private Checkbox formatJPEG; ! private Button go; ! ! private PlayerPanel playerPanel = null; ! ! private BorderLayout borderLayout1 = new BorderLayout(); ! private GridBagLayout gridBagLayoutNorth = new GridBagLayout(); ! private GridBagLayout gridBagLayoutSouth = new GridBagLayout(); ! ! private boolean insVideo = false; ! ! private Socket mySocket = null; ! private DialogServer dialogServer; ! ! ! ! /** ! * Contructeur de la Classe Client ! */ ! ! public Client() { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! try { ! jbInit(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * setPlayerPanel crée l'interface graphique du Client ! * @param pp il s'agit d'un PlayerPanel qui est une classe que nous avons crée ! * @vid est un booleen qui nous dit si le player a cree est de la video ou de l'audio ! */ ! ! public void setPlayerPanel(PlayerPanel pp, boolean vid) { ! Panel panelTemp; ! ! if (playerPanel == null) { ! panelTemp = panelEmpty; ! } ! else ! ! { ! panelTemp = playerPanel; ! } ! System.out.println("video :" + vid); ! System.out.println("insvideo :" + insVideo); ! ! // on teste ici pour savoir si on doit cree un player video ou un player audio ! if (vid) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! insVideo = true; ! } ! ! else if (!insVideo) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! } ! } ! ! /** ! * jbinit lance la creation de l'interface graphique. ! */ ! private void jbInit() throws Exception { ! ! contentPane = this; ! contentPane.setLayout(borderLayout1); ! this.setSize(new Dimension(240, 320)); ! this.setTitle("Madsserv Client"); ! setAfficheStatusBar("coucou"); ! URLChoice = new TextField("file:///c:\\temp\\kiss_cool_1.mpeg"); ! AdServer = new TextField("dronej.rezel.com:5001"); ! menuFile.setLabel("File"); ! menuOpenURL.setLabel("Open URL"); ! menuOpenURL.addActionListener(new Client_Menu_OpenURL_ActionAdapter(this)); ! menuFileExit.setLabel("Exit"); ! menuFileExit.addActionListener(new Client_menuFileExit_ActionAdapter(this)); ! menuFile.add(menuOpenURL); ! menuFile.add(menuFileExit); ! menuBar1.add(menuFile); ! this.setMenuBar(menuBar1); ! ! formatMPEG = new Checkbox("MPEG", cbg, true); ! ! formatJPEG = new Checkbox("JPEG", cbg, false); ! ! go = new Button("Go!"); ! go.setSize(new Dimension(60, 15)); ! go.addActionListener(new Client_boutongo_ActionAdapter(this)); ! ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! panelSouth.setLayout(gridBagLayoutSouth); ! GridBagConstraints c = new GridBagConstraints(); ! c.fill = GridBagConstraints.BOTH; ! c.insets = new Insets(1, 5, 1, 5); ! c.weightx = 1.0; ! c.weighty = 1.0; ! panelSouth.add(formatMPEG, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelSouth.add(formatJPEG, c); ! c.weightx = 0.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelSouth.add(go, c); ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.weightx = 0.0; ! c.gridwidth = 2; ! panelSouth.add(statusBar, c); ! ! URLLabel.setText("URL :"); ! AdLabel.setText("Serv:"); ! URLLabel.setSize(new Dimension(30, 15)); ! URLChoice.setSize(new Dimension(30, 15)); ! AdLabel.setSize(new Dimension(30, 15)); ! AdServer.setSize(new Dimension(30, 15)); ! ! panelNorth.setLayout(gridBagLayoutNorth); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.gridwidth = 1; ! c.weightx = 0.0; ! c.weighty = 1.0; ! panelNorth.add(URLLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelNorth.add(URLChoice, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.weightx = 0.0; ! panelNorth.add(AdLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelNorth.add(AdServer, c); ! ! contentPane.add(panelSouth, BorderLayout.SOUTH); ! contentPane.add(panelNorth, BorderLayout.NORTH); ! ! contentPane.add(panelEmpty, BorderLayout.CENTER); ! ! } ! ! /** ! * menuFileExit_actionPerformed est à l'ecoute d'un evenement signifiant l'arret du client ! * @param e c'est l'evenemet qui met fin au client ! */ ! public void menuFileExit_actionPerformed(ActionEvent e) { ! try { ! String messageToSend[] = new String[1]; ! messageToSend[0] = "fin de la connexion"; ! dialogServer.sendMessage(4, messageToSend); ! System.exit(0); ! } ! catch (Exception ex) { ! System.exit(0); ! } ! } ! ! /** ! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre ! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre ! */ ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! menuFileExit_actionPerformed(null); ! } ! } ! ! /** ! * boutongo_actionPerformed Methode qui permet de lancer la connexion lorsque l'on clique sur le bouton go ! * @param evt c'est l'evenement qui indique que l'on a clique sur le bouton go ! */ ! public void boutongo_actionPerformed(ActionEvent evt) { ! ! String[] messageToSend; ! ! if (mySocket == null) { ! try { ! mySocket = new Socket(getAddressServer(), getServerPort()); ! } ! catch (Exception e) { ! showError("serveur ou port incorrect"); ! } ! ! dialogServer = new DialogServer(mySocket, this); ! dialogServer.start(); ! } ! ! else { ! // if ( (mySocket.isClosed()) == false) { ! messageToSend = new String[2]; ! messageToSend[0] = getURL(); ! messageToSend[1] = getFormatPrefere(); ! ! dialogServer.sendMessage(2, messageToSend); ! /*} ! else { ! try { ! mySocket.connect(new InetSocketAddress(getAddressServer(), ! getServerPort())); ! } ! catch (Exception e) { ! } ! }*/ ! } ! } ! ! public void endConnexion() { ! dialogServer.stop(); ! mySocket = null; ! } ! ! public void showError(String messageErreur) ! { ! ErrorPopUp errorPopUp = new ErrorPopUp(messageErreur,this); ! } ! ! /** ! * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client ! * @return InetAddress du server ! */ ! public InetAddress getAddressServer() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! try { ! return (InetAddress.getByName(host.substring(0, columnPosition))); ! } ! ! catch (UnknownHostException e) { ! return (null); ! } ! } ! ! /** ! * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client ! * @return int le numero du port sur lequel, on doit se connecter au serveur ! */ ! public int getServerPort() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! ! return (Integer.parseInt(host.substring(columnPosition + 1))); ! ! } ! ! /** ! * getURL permet d'obtenir l'URL du fichier multimedia que l'on souhaite visionner, cet URL est rentre dans une zone de texte sur l'interface graphique du client ! * @return String l'adresse du media demande ! */ ! public String getURL() { ! ! return (URLChoice.getText()); ! } ! ! public String getFormatPrefere() { ! ! if (formatMPEG.getState()) { ! return ("MPEG"); ! } ! ! else { ! if (formatJPEG.getState()) { ! return ("JPEG"); ! } ! else { ! return (""); ! } ! } ! ! } ! ! /** ! * setAfficheStatusBar est une methode qui permet d'afficher en bas du client un message envoye par le server ! * @param _message un message envoye sous forme de String envoye par le serveur ! */ ! public void setAfficheStatusBar(String _message) { ! statusBar.setText(_message); ! } ! ! /** ! * Client_menuFileExit_ActionAdapter, classe qui ecoute pour savoir si on clique sur le menu exit et envoie alors l'evenement ! */ ! class Client_menuFileExit_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_menuFileExit_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.menuFileExit_actionPerformed(e); ! } ! } ! ! /** ! * Client_boutongo_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton go et envoie alors l'evenement ! */ ! class Client_boutongo_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_boutongo_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! ! /** ! * Client_Menu_OpenURL_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton OpenURL et envoie alors l'evenement ! */ ! class Client_Menu_OpenURL_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_Menu_OpenURL_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! } Index: ClientRTPManager.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ClientRTPManager.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ClientRTPManager.java 14 Mar 2003 03:26:18 -0000 1.5 --- ClientRTPManager.java 15 Mar 2003 22:47:30 -0000 1.6 *************** *** 1,604 **** ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; [...1179 lines suppressed...] ! prUsage(); ! ClientRTPManager avReceive = new ClientRTPManager(argv); ! if (!avReceive.initialize()) { ! System.err.println("Failed to initialize the sessions."); ! System.exit(-1); ! } ! // Check to see if ClientRTPManager is done. ! try { ! while (!avReceive.isDone()) ! Thread.sleep(1000); ! } catch (Exception e) {} ! System.err.println("Exiting AVReceive2"); ! } ! static void prUsage() { ! System.err.println("Usage: AVReceive2 <session> <session> ..."); ! System.err.println(" <session>: <address>/<port>/<ttl>"); ! System.exit(0); ! } ! */ ! } // end of ClientRTPManager Index: DialogServer.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/DialogServer.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DialogServer.java 14 Mar 2003 03:26:18 -0000 1.6 --- DialogServer.java 15 Mar 2003 22:47:30 -0000 1.7 *************** *** 1,169 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! import java.lang.Object.*; ! import java.lang.System.*; ! ! /** ! * DialogServer c'est la classe qui herite de la classe dialogSocket et qui gere les dialogues avec le serveur ! */ ! public class DialogServer ! extends DialogSocket { ! ! private Client client; ! private ThreadRTPManager threadRTPManager; ! private String[] sessions = new String[2]; ! /** ! * C'est le constructeur de la classe ! */ ! public DialogServer(Socket _socketServer, Client _client) { ! super(_socketServer); ! client = _client; ! clientID = -1; ! } ! ! /** ! * incomingMessage methode qui a ete declare abstraite dans DialogSocket et qui gere l'arivee de nouveaux messages du serveur ! * @param _type type de message qui arrive (c'est un entier) ! * @param _message tableau de chaine de characteres qui contient les messages du serveur ! */ ! public void incomingMessage(int _type, String[] _message) { ! int lgth = _message.length; ! int portBase = 40000; ! String[] messageToSend; ! String sessionTemp; ! Integer port1, port2; ! ! switch (_type) { ! ! case 9: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! try { ! client.setAfficheStatusBar(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! break; ! } ! ! case 7: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! client.showError(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 5: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! System.out.println(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 3: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! /** ! *on regarde si le threadRTPManager existe, si il n'existe pas on le cree, sinon on le detruit et on en cree un nouveau ! */ ! if (threadRTPManager == null) { ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! else { ! ! threadRTPManager.Fermer(); ! threadRTPManager = null; ! System.gc(); ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! break; ! ! } ! case 1: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! // lecture du troisieme champ du message : portBase ! try { ! portBase = Integer.parseInt(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! ! /** ! * On stocke dans le variable sessions, l'adresse du server et les ports pour les diffusions audio et video ! */ ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port1 = new Integer(portBase); ! sessionTemp = sessionTemp.concat(port1.toString()); ! sessions[0] = sessionTemp; ! sessionTemp = ""; ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port2 = new Integer(portBase + 2); ! sessionTemp = sessionTemp.concat(port2.toString()); ! sessions[1] = sessionTemp; ! ! System.out.println(sessions[0]); ! System.out.println(sessions[1]); ! ! messageToSend = new String[2]; ! ! messageToSend[0] = client.getURL(); ! messageToSend[1] = client.getFormatPrefere(); ! ! sendMessage(2, messageToSend); ! } ! } ! } } --- 1,169 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! import java.lang.Object.*; ! import java.lang.System.*; ! ! /** ! * DialogServer c'est la classe qui herite de la classe dialogSocket et qui gere les dialogues avec le serveur ! */ ! public class DialogServer ! extends DialogSocket { ! ! private Client client; ! private ThreadRTPManager threadRTPManager; ! private String[] sessions = new String[2]; ! /** ! * C'est le constructeur de la classe ! */ ! public DialogServer(Socket _socketServer, Client _client) { ! super(_socketServer); ! client = _client; ! clientID = -1; ! } ! ! /** ! * incomingMessage methode qui a ete declare abstraite dans DialogSocket et qui gere l'arivee de nouveaux messages du serveur ! * @param _type type de message qui arrive (c'est un entier) ! * @param _message tableau de chaine de characteres qui contient les messages du serveur ! */ ! public void incomingMessage(int _type, String[] _message) { ! int lgth = _message.length; ! int portBase = 40000; ! String[] messageToSend; ! String sessionTemp; ! Integer port1, port2; ! ! switch (_type) { ! ! case 9: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! try { ! client.setAfficheStatusBar(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! break; ! } ! ! case 7: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! client.showError(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 5: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! System.out.println(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 3: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! /** ! *on regarde si le threadRTPManager existe, si il n'existe pas on le cree, sinon on le detruit et on en cree un nouveau ! */ ! if (threadRTPManager == null) { ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! else { ! ! threadRTPManager.Fermer(); ! threadRTPManager = null; ! System.gc(); ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! break; ! ! } ! case 1: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! // lecture du troisieme champ du message : portBase ! try { ! portBase = Integer.parseInt(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! ! /** ! * On stocke dans le variable sessions, l'adresse du server et les ports pour les diffusions audio et video ! */ ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port1 = new Integer(portBase); ! sessionTemp = sessionTemp.concat(port1.toString()); ! sessions[0] = sessionTemp; ! sessionTemp = ""; ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port2 = new Integer(portBase + 2); ! sessionTemp = sessionTemp.concat(port2.toString()); ! sessions[1] = sessionTemp; ! ! System.out.println(sessions[0]); ! System.out.println(sessions[1]); ! ! messageToSend = new String[2]; ! ! messageToSend[0] = client.getURL(); ! messageToSend[1] = client.getFormatPrefere(); ! ! sendMessage(2, messageToSend); ! } ! } ! } } Index: ErrorPopUp.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ErrorPopUp.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ErrorPopUp.java 14 Mar 2003 03:26:18 -0000 1.2 --- ErrorPopUp.java 15 Mar 2003 22:47:30 -0000 1.3 *************** *** 1,114 **** ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.geom.Point2D.*; ! import java.awt.Point.*; ! ! /** ! * <code>ErrorPopUp</code> est une popup qui apparait lorsque des erreurs apparaissent. ! * @author Xavier Deplancq ! */ ! ! public class ErrorPopUp ! extends Frame { ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelSouth = new Panel(); ! private Label errorMessage = new Label(); ! private BorderLayout borderLayout1 = new BorderLayout(); ! private Button OK; ! ! /** ! * Constructeur de la classe ErrorPopUp ! * @param errMessage le Message qui doit etre affiche ! * @param _client la reference du client ! */ ! ! public ErrorPopUp(String errMessage, Client _client) { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! errorMessage.setText(errMessage); ! panelNorth.add(errorMessage); ! OK = new Button("OK"); ! OK.setSize(new Dimension(60, 15)); ! OK.addActionListener(new ErrorPopUp_OK_ActionAdapter(this)); ! panelSouth.add(OK); ! contentPane = this; ! this.setSize(220, 90); ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! contentPane.setLayout(borderLayout1); ! contentPane.add(panelNorth, borderLayout1.CENTER); ! contentPane.add(panelSouth, borderLayout1.SOUTH); ! ! //On place la boite de dialogue ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension clientSize = _client.getSize(); ! Dimension popupSize = this.getSize(); ! double clientPlaceX = _client.getX(); ! double clientPlaceY = _client.getY(); ! if (popupSize.height > clientSize.height) { ! popupSize.height = clientSize.height; ! } ! if (popupSize.width > clientSize.width) { ! popupSize.width = clientSize.width; ! } ! this.setLocation( (int) (clientPlaceX) /*+ ! ( ! clientSize.height - popupSize.height) / 2*/, ! (int) (clientPlaceY) + clientSize.width / 2); ! ! showWindow(); ! ! } ! ! /** ! * OK_actionPerformed qui sert lorsque l'on appuie sur le bouton OK ! * @param e l'evenement ! */ ! ! public void OK_actionPerformed(ActionEvent e) { ! setVisible(false); ! } ! ! /** ! * processWindowEvent c est une methode qui est appele lorsque l'on ferme la boite de dialogue ! * @param l evenement qui indique que l'on ferme la fenetre ! */ ! ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! OK_actionPerformed(null); ! } ! } ! ! /** ! * Methode qui affiche la boite de dialogue ! */ ! ! public void showWindow() { ! setVisible(true); ! } ! ! /** ! * Classe qui ecoute si l'on appui sur le bouton OK ! */ ! ! class ErrorPopUp_OK_ActionAdapter ! implements ActionListener { ! ErrorPopUp adaptee; ! ! ErrorPopUp_OK_ActionAdapter(ErrorPopUp adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.OK_actionPerformed(e); ! } ! } ! ! } \ No newline at end of file --- 1,112 ---- ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.geom.Point2D.*; ! import java.awt.Point.*; ! ! /** ! * <code>ErrorPopUp</code> est une popup qui apparait lorsque des erreurs apparaissent. ! * @author Xavier Deplancq ! */ ! ! public class ErrorPopUp ! extends Frame { ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelSouth = new Panel(); ! private Label errorMessage = new Label(); ! private BorderLayout borderLayout1 = new BorderLayout(); ! private Button OK; ! ! /** ! * Constructeur de la classe ErrorPopUp ! * @param errMessage le Message qui doit etre affiche ! * @param _client la reference du client ! */ ! ! public ErrorPopUp(String errMessage, Client _client) { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! errorMessage.setText(errMessage); ! panelNorth.add(errorMessage); ! OK = new Button("OK"); ! OK.setSize(new Dimension(60, 15)); ! OK.addActionListener(new ErrorPopUp_OK_ActionAdapter(this)); ! panelSouth.add(OK); ! contentPane = this; ! this.setSize(240, 120); ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! contentPane.setLayout(borderLayout1); ! contentPane.add(panelNorth, borderLayout1.CENTER); ! contentPane.add(panelSouth, borderLayout1.SOUTH); ! ! //On place la boite de dialogue ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension clientSize = _client.getSize(); ! Dimension popupSize = this.getSize(); ! double clientPlaceX = _client.getX(); ! double clientPlaceY = _client.getY(); ! if (popupSize.height > clientSize.height) { ! popupSize.height = clientSize.height; ! } ! if (popupSize.width > clientSize.width) { ! popupSize.width = clientSize.width; ! } ! this.setLocation( (int) (clientPlaceX), ! (int) (clientPlaceY) + clientSize.width / 2); ! ! showWindow(); ! ! } ! ! /** ! * OK_actionPerformed qui sert lorsque l'on appuie sur le bouton OK ! * @param e l'evenement ! */ ! ! public void OK_actionPerformed(ActionEvent e) { ! setVisible(false); ! } ! ! /** ! * processWindowEvent c est une methode qui est appele lorsque l'on ferme la boite de dialogue ! * @param l evenement qui indique que l'on ferme la fenetre ! */ ! ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! OK_actionPerformed(null); ! } ! } ! ! /** ! * Methode qui affiche la boite de dialogue ! */ ! ! public void showWindow() { ! setVisible(true); ! } ! ! /** ! * Classe qui ecoute si l'on appui sur le bouton OK ! */ ! ! class ErrorPopUp_OK_ActionAdapter ! implements ActionListener { ! ErrorPopUp adaptee; ! ! ErrorPopUp_OK_ActionAdapter(ErrorPopUp adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.OK_actionPerformed(e); ! } ! } ! ! } Index: MadsservClient.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/MadsservClient.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MadsservClient.java 14 Mar 2003 03:26:18 -0000 1.5 --- MadsservClient.java 15 Mar 2003 22:47:30 -0000 1.6 *************** *** 1,75 **** ! //package madsserv_planification; ! ! import javax.swing.UIManager; ! import java.awt.*; ! import java.net.*; ! ! /** ! * <p>Title: MadsservClient</p> ! * <p>Description: La Classe MadsservClient contient la classe main du client du projet, c'est lui qui le lance</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! **/ ! ! /** ! * MadsservClient c'est la classe MadsservClient ! */ ! public class MadsservClient { ! /** ! * champs de la classe MadsservClient ! */ ! private boolean packFrame = false; ! ! /** ! * MadsservClient constructeur de la calsse ! */ ! public MadsservClient() { ! ! Client frame = new Client(); ! ! //Validate frames that have preset sizes ! //Pack frames that have useful preferred size info, e.g. from their layout ! if (packFrame) { ! frame.pack(); ! } ! else { ! frame.validate(); ! } ! ! //on centre ici la fenetre ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension frameSize = frame.getSize(); ! if (frameSize.height > screenSize.height) { ! frameSize.height = screenSize.height; ! } ! if (frameSize.width > screenSize.width) { ! frameSize.width = screenSize.width; ! } ! frame.setLocation( (screenSize.width - frameSize.width) / 2, ! (screenSize.height - frameSize.height) / 2); ! frame.setVisible(true); ! } ! ! /** ! * Methode main de MadsservClient ! */ ! ! public static void main(String[] args) { ! try { ! UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! new MadsservClient(); ! } ! ! static void prUsage() { ! System.err.println("Usage: ClientRTPManager <session> <session> ..."); ! System.err.println(" <session>: <address>/<port>/<ttl>"); ! System.exit(0); ! } ! } --- 1,75 ---- ! //package madsserv_planification; ! ! import javax.swing.UIManager; ! import java.awt.*; ! import java.net.*; ! ! /** ! * <p>Title: MadsservClient</p> ! * <p>Description: La Classe MadsservClient contient la classe main du client du projet, c'est lui qui le lance</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! **/ ! ! /** ! * MadsservClient c'est la classe MadsservClient ! */ ! public class MadsservClient { ! /** ! * champs de la classe MadsservClient ! */ ! private boolean packFrame = false; ! ! /** ! * MadsservClient constructeur de la calsse ! */ ! public MadsservClient() { ! ! Client frame = new Client(); ! ! //Validate frames that have preset sizes ! //Pack frames that have useful preferred size info, e.g. from their layout ! if (packFrame) { ! frame.pack(); ! } ! else { ! frame.validate(); ! } ! ! //on centre ici la fenetre ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension frameSize = frame.getSize(); ! if (frameSize.height > screenSize.height) { ! frameSize.height = screenSize.height; ! } ! if (frameSize.width > screenSize.width) { ! frameSize.width = screenSize.width; ! } ! frame.setLocation( (screenSize.width - frameSize.width) / 2, ! (screenSize.height - frameSize.height) / 2); ! frame.setVisible(true); ! } ! ! /** ! * Methode main de MadsservClient ! */ ! ! public static void main(String[] args) { ! try { ! UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! new MadsservClient(); ! } ! ! static void prUsage() { ! System.err.println("Usage: ClientRTPManager <session> <session> ..."); ! System.err.println(" <session>: <address>/<port>/<ttl>"); ! System.exit(0); ! } ! } Index: PlayerPanel.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/PlayerPanel.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PlayerPanel.java 14 Mar 2003 03:26:18 -0000 1.4 --- PlayerPanel.java 15 Mar 2003 22:47:30 -0000 1.5 *************** *** 1,66 **** ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.AudioFormat; ! import javax.media.format.VideoFormat; ! import javax.media.Format; ! import javax.media.format.FormatChangeEvent; ! import javax.media.control.BufferControl; ! ! /** ! * Classe playerpanel qui crée l'interphace graphique des players ! * @author : Xavier Deplancq ! */ ! public class PlayerPanel ! extends Panel { ! /** ! * champs de la classe ! */ ! private Component vc, cc; ! // champs qui est mis à true lorsque l'on doit crée l'interface du player video ! boolean video = false; ! ! PlayerPanel(Player p) { ! setLayout(new BorderLayout()); ! //on regarde si c'est un flux video qui arrive ! if ( (vc = p.getVisualComponent()) != null) { ! add("Center", vc); ! video = true; ! } ! if ( (cc = p.getControlPanelComponent()) != null) { ! add("South", cc); ! } ! } ! /** ! * getPrefferedSize methode qui retourne les dimensions du player ! * @return Dimension, celles du player ! */ ! public Dimension getPreferredSize() { ! int w = 0, h = 0; ! if (vc != null) { ! Dimension size = vc.getPreferredSize(); ! w = size.width; ! h = size.height; ! } ! if (cc != null) { ! Dimension size = cc.getPreferredSize(); ! if (w == 0) { ! w = size.width; ! } ! h += size.height; ! } ! if (w < 160) { ! w = 160; ! } ! return new Dimension(w, h); ! } ! } --- 1,66 ---- ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.AudioFormat; ! import javax.media.format.VideoFormat; ! import javax.media.Format; ! import javax.media.format.FormatChangeEvent; ! import javax.media.control.BufferControl; ! ! /** ! * Classe playerpanel qui crée l'interphace graphique des players ! * @author : Xavier Deplancq ! */ ! public class PlayerPanel ! extends Panel { ! /** ! * champs de la classe ! */ ! private Component vc, cc; ! // champs qui est mis à true lorsque l'on doit crée l'interface du player video ! boolean video = false; ! ! PlayerPanel(Player p) { ! setLayout(new BorderLayout()); ! //on regarde si c'est un flux video qui arrive ! if ( (vc = p.getVisualComponent()) != null) { ! add("Center", vc); ! video = true; ! } ! if ( (cc = p.getControlPanelComponent()) != null) { ! add("South", cc); ! } ! } ! /** ! * getPrefferedSize methode qui retourne les dimensions du player ! * @return Dimension, celles du player ! */ ! public Dimension getPreferredSize() { ! int w = 0, h = 0; ! if (vc != null) { ! Dimension size = vc.getPreferredSize(); ! w = size.width; ! h = size.height; ! } ! if (cc != null) { ! Dimension size = cc.getPreferredSize(); ! if (w == 0) { ! w = size.width; ! } ! h += size.height; ! } ! if (w < 160) { ! w = 160; ! } ! return new Dimension(w, h); ! } ! } Index: ThreadRTPManager.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRTPManager.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ThreadRTPManager.java 14 Mar 2003 03:26:18 -0000 1.6 --- ThreadRTPManager.java 15 Mar 2003 22:47:30 -0000 1.7 *************** *** 1,51 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * ThreadRTPManager est une methode qui cree un clientRTPManager ! * @author : Xavier Deplancq ! */ ! public class ThreadRTPManager extends Thread { ! ! /** ! * champs de la classe ClientRTPManager ! */ ! private ClientRTPManager clientRTPManager; ! private Client cl; ! ! public ThreadRTPManager(String sessionServer[], Client cl) ! { ! clientRTPManager = new ClientRTPManager(sessionServer, cl); ! } ! ! /** ! * methode run de ce thread ! */ ! public void Fermer() ! { ! clientRTPManager.close(); ! } ! ! public void run() ! { ! if (!clientRTPManager.initialize()) { ! System.err.println("Failed to initialize the sessions."); ! System.exit( -1); ! } ! ! try { ! while (!clientRTPManager.isDone()) ! Thread.sleep(1000); ! } ! catch (Exception e) { ! cl.showError("La connexion n'a pas pu etre initialise"); ! } ! ! finally { ! ! System.err.println("Exiting ThreadRTPManager"); ! System.out.println(Thread.currentThread()); ! } ! } ! } --- 1,51 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * ThreadRTPManager est une methode qui cree un clientRTPManager ! * @author : Xavier Deplancq ! */ ! public class ThreadRTPManager extends Thread { ! ! /** ! * champs de la classe ClientRTPManager ! */ ! private ClientRTPManager clientRTPManager; ! private Client cl; ! ! public ThreadRTPManager(String sessionServer[], Client cl) ! { ! clientRTPManager = new ClientRTPManager(sessionServer, cl); ! } ! ! /** ! * methode run de ce thread ! */ ! public void Fermer() ! { ! clientRTPManager.close(); ! } ! ! public void run() ! { ! if (!clientRTPManager.initialize()) { ! System.err.println("Failed to initialize the sessions."); ! System.exit( -1); ! } ! ! try { ! while (!clientRTPManager.isDone()) ! Thread.sleep(1000); ! } ! catch (Exception e) { ! cl.showError("La connexion n'a pas pu etre initialise"); ! } ! ! finally { ! ! System.err.println("Exiting ThreadRTPManager"); ! System.out.println(Thread.currentThread()); ! } ! } ! } Index: ThreadRead.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRead.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ThreadRead.java 14 Mar 2003 03:26:18 -0000 1.3 --- ThreadRead.java 15 Mar 2003 22:47:30 -0000 1.4 *************** *** 1,98 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. ! * Il effectue une ecoute permanente. ! * <p> ! * Il gere l'extraction du message en isolant les elements protocolaires de la ! * transmission du message. ! * @see ThreadWrite ! * @see DialogSocket ! * @author Julien Carbonell ! */ ! ! public class ThreadRead ! extends Thread { ! ! boolean end = false; ! ! // objet parent qui gere les entrees-sorties sur le socket ! protected DialogSocket parent; ! ! // BufferedReader sur lequel sont lus les messages ! protected BufferedReader binput; ! ! protected String temp = ""; ! protected String message = ""; ! protected boolean waitingMessage = true; ! protected int messageType = -1; ! ! /** ! * Constructeur de <code>ThreadRead</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. ! */ ! public ThreadRead(String _name, BufferedReader _binput, ! DialogSocket _parent) { ! super(_name + _parent.getClientID()); ! parent = _parent; ! binput = _binput; ! } ! ! /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. ! */ ! public void run() { ! try { ! while ( (temp = binput.readLine()) != null) { ! if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; ! } ! else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; ! } ! else { ! message = message.concat(temp + "\n"); ! } ! } ! } ! ! } ! } ! /* catch (SocketTimeoutException e) { ! System.out.println(e.getMessage()); ! }*/ ! catch (Exception e) { ! e.printStackTrace(); ! } ! finally { ! try { ! // binput.close(); ! System.out.println(getName() + Thread.currentThread() + ! " : Stopped !!! "); ! } ! catch (Exception e) { ! System.out.println(e.getMessage()); ! } ! } ! ! } ! ! protected String[] parseMessage(String _message) { ! return _message.split("\n"); ! } ! } --- 1,98 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. ! * Il effectue une ecoute permanente. ! * <p> ! * Il gere l'extraction du message en isolant les elements protocolaires de la ! * transmission du message. ! * @see ThreadWrite ! * @see DialogSocket ! * @author Julien Carbonell ! */ ! ! public class ThreadRead ! extends Thread { ! ! boolean end = false; ! ! // objet parent qui gere les entrees-sorties sur le socket ! protected DialogSocket parent; ! ! // BufferedReader sur lequel sont lus les messages ! protected BufferedReader binput; ! ! protected String temp = ""; ! protected String message = ""; ! protected boolean waitingMessage = true; ! protected int messageType = -1; ! ! /** ! * Constructeur de <code>ThreadRead</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. ! */ ! public ThreadRead(String _name, BufferedReader _binput, ! DialogSocket _parent) { ! super(_name + _parent.getClientID()); ! parent = _parent; ! binput = _binput; ! } ! ! /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. ! */ ! public void run() { ! try { ! while ( (temp = binput.readLine()) != null) { ! if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; ! } ! else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; ! } ! else { ! message = message.concat(temp + "\n"); ! } ! } ! } ! ! } ! } ! /* catch (SocketTimeoutException e) { ! System.out.println(e.getMessage()); ! }*/ ! catch (Exception e) { ! e.printStackTrace(); ! } ! finally { ! try { ! // binput.close(); ! System.out.println(getName() + Thread.currentThread() + ! " : Stopped !!! "); ! } ! catch (Exception e) { ! System.out.println(e.getMessage()); ! } ! } ! ! } ! ! protected String[] parseMessage(String _message) { ! return _message.split("\n"); ! } ! } Index: ThreadWrite.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadWrite.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 ***... [truncated message content] |
|
From: <dep...@us...> - 2003-03-15 22:40:58
|
Update of /cvsroot/madsserv/madsserv/src/server/transition
In directory sc8-pr-cvs1:/tmp/cvs-serv29765
Modified Files:
Transition.java
Log Message:
nouvel version du gestionnaire de Transition avec les tableaux de foramts supporte
Index: Transition.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/transition/Transition.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Transition.java 13 Mar 2003 23:32:34 -0000 1.5
--- Transition.java 15 Mar 2003 22:40:54 -0000 1.6
***************
*** 9,13 ****
/**
! * La classe Transition assure la transition la plus rapide lors d'un changement de niveau de qualite. Des que le gestionnaire des Connexions lui transmet un changement de niveau de qualit�, il collecte les informations sur les diffusions en cours, fixe les param�tres de l'encodage � effectuer et les transmet au module de traitement de la conversion.
* @author Xavier Deplancq
*/
--- 9,13 ----
/**
! * La classe Transition assure la transition la plus rapide lors d'un changement de niveau de qualite. Des que le gestionnaire des Connexions lui transmet un changement de niveau de qualite, il collecte les informations sur les diffusions en cours, fixe les parametres de l'encodage a effectuer et les transmet au module de traitement de la conversion.
* @author Xavier Deplancq
*/
***************
*** 15,19 ****
public class Transition {
! /*On declare ici le num�ro du client, le num�ro de frame courant et le niveau de qualite*/
private int numClient;
--- 15,19 ----
public class Transition {
! /*On declare ici le numero du client, le numero de frame courant et le niveau de qualite*/
private int numClient;
***************
*** 24,28 ****
/**
! * Constructeur vide, il initialise le num�ro du client � 1, il met le niveau de quailt� � 1 par d�faut et le num�ro de FRame � 0. Il ne peut �tre utiliser que la premi�re fois, sinon il y a des risques de colision.
*/
--- 24,28 ----
/**
! * Constructeur vide, il initialise le numero du client a 0, il met le niveau de qualite a 1 par defaut et le numero de Frame a 0. Il ne peut etre utiliser que la premiere fois, sinon il y a des risques de colision.
*/
***************
*** 30,39 ****
{
! numClient = 1;
qualityLevel = 1;
}
/**
! * Constructeur de la classe Transition qui initialise le num�ro du client, le niveau de qualit� � 1 par d�faut et le num�ro de frame � 0.
*@param _nmclient le numero du client
*/
--- 30,39 ----
{
! numClient = 0;
qualityLevel = 1;
}
/**
! * Constructeur de la classe Transition qui initialise le numero du client, le niveau de qualite a 1 par defaut et le numero de frame a 0.
*@param _nmclient le numero du client
*/
***************
*** 47,51 ****
/**
! * Constructeur de la classe Transition qui initialise le num�ro de client et le niveau de qualit� et met le num�ro de Frame � 0 par d�faut.
*@param _nmclient le numero du client
*@param _qualitylevel le niveau de qualite demande
--- 47,51 ----
/**
! * Constructeur de la classe Transition qui initialise le numero de client et le niveau de qualite et met le numero de Frame a 0 par defaut.
*@param _nmclient le numero du client
*@param _qualitylevel le niveau de qualite demande
***************
*** 60,67 ****
/**
! * Constructeur de la classe Transition qui initialise le num�ro de client et le niveau de qualit� et met le num�ro de Frame.
*@param _nmclient le numero du client
*@param _qualitylevel le niveau de qualite demande
! *@param _numFrame le num�ro de frame
public Transition(int _numClient, int _qualityLevel, float _numFrame)
{
--- 60,67 ----
/**
! * Constructeur de la classe Transition qui initialise le numero de client et le niveau de qualite et met le numero de Frame.
*@param _nmclient le numero du client
*@param _qualitylevel le niveau de qualite demande
! *@param _numFrame le numero de frame
public Transition(int _numClient, int _qualityLevel, float _numFrame)
{
***************
*** 72,76 ****
/**
! *findNewNumberFrame : Cette methode calcule le nouveau numero de Frame a partir duquel il faut reencoder le fichier multimedia diffus�.
*@param oldNumFrame le numero de frame qui vient d'etre envoye au client
*@param reencodingVideoFor le nouveau format video de reencodage.
--- 72,76 ----
/**
! *findNewNumberFrame : Cette methode calcule le nouveau numero de Frame a partir duquel il faut reencoder le fichier multimedia diffuse.
*@param oldNumFrame le numero de frame qui vient d'etre envoye au client
*@param reencodingVideoFor le nouveau format video de reencodage.
***************
*** 92,96 ****
newAuxMediaTime = oldMediaTime + 3;
}
! if (reencodingVideoFor.getEncoding() == "JPEG") {
newAuxMediaTime = oldMediaTime + 3;
}
--- 92,96 ----
newAuxMediaTime = oldMediaTime + 3;
}
! if (reencodingVideoFor.getEncoding() == "MPEG") {
newAuxMediaTime = oldMediaTime + 3;
}
***************
*** 105,109 ****
else {
! if (reencodingAudioFor.getEncoding() == "MP3") {
newAuxMediaTime = oldMediaTime + 2;
}
--- 105,109 ----
else {
! if (reencodingAudioFor.getEncoding() == "WAV") {
newAuxMediaTime = oldMediaTime + 2;
}
***************
*** 114,118 ****
}
newMediaTime = new Time(newAuxMediaTime);
! //on retourne le numero de Frame a partir duquel il faut r�encoder.
return (newMediaTime);
--- 114,118 ----
}
newMediaTime = new Time(newAuxMediaTime);
! //on retourne le numero de Frame a partir duquel il faut reencoder.
return (newMediaTime);
***************
*** 135,142 ****
//variables qui vont stockees le format original Video et Audio
! VideoFormat origVideoFor;
! AudioFormat origAudioFor;
! //variables qui vont stockees le format de r�encodage Video et Audio
VideoFormat reencodingVideoFor = null;
AudioFormat reencodingAudioFor = null;
--- 135,142 ----
//variables qui vont stockees le format original Video et Audio
! VideoFormat[] origVideoFor;
! AudioFormat[] origAudioFor;
! //variables qui vont stockees le format de reencodage Video et Audio
VideoFormat reencodingVideoFor = null;
AudioFormat reencodingAudioFor = null;
***************
*** 145,154 ****
//On obtient ici les formats Video et Audio Originaux.
! if (reencodeRef.multimedia)
origVideoFor = reencodeRef.getOriginalVideoFormat();
origAudioFor = reencodeRef.getOriginalAudioFormat();
//On obtient ici les formats Video et Audio de reencodage.
! if (reencodeRef.multimedia)
reencodingVideoFor = gestionAdaptaRef.getVideoStreamingFormat(qualityLevel,
origVideoFor);
--- 145,154 ----
//On obtient ici les formats Video et Audio Originaux.
! if (reencodeRef.multiMedia)
origVideoFor = reencodeRef.getOriginalVideoFormat();
origAudioFor = reencodeRef.getOriginalAudioFormat();
//On obtient ici les formats Video et Audio de reencodage.
! if (reencodeRef.multiMedia)
reencodingVideoFor = gestionAdaptaRef.getVideoStreamingFormat(qualityLevel,
origVideoFor);
***************
*** 166,170 ****
//on Transmet ici les formats Audio et Video de reencodage
! if (reencodeRef.multimedia)
reencodeRef.setReencodingVideoFormat(reencodingVideoFor);
reencodeRef.setReencodingAudioFormat(reencodingAudioFor);
--- 166,170 ----
//on Transmet ici les formats Audio et Video de reencodage
! if (reencodeRef.multiMedia)
reencodeRef.setReencodingVideoFormat(reencodingVideoFor);
reencodeRef.setReencodingAudioFormat(reencodingAudioFor);
|
|
From: <si...@us...> - 2003-03-15 22:30:23
|
Update of /cvsroot/madsserv/madsserv/src/server/adaptability In directory sc8-pr-cvs1:/tmp/cvs-serv24232 Added Files: GestionAdapta.java Log Message: nouvelle version du gestionnaie d'adaptabilité... have fun !!! |
|
From: <si...@us...> - 2003-03-15 22:23:38
|
Update of /cvsroot/madsserv/madsserv/src/server/adaptability In directory sc8-pr-cvs1:/tmp/cvs-serv23740 Removed Files: GestionAdapta.java Log Message: --- GestionAdapta.java DELETED --- |
|
From: <si...@us...> - 2003-03-14 11:38:50
|
Update of /cvsroot/madsserv/madsserv/src/server/adaptability
In directory sc8-pr-cvs1:/tmp/cvs-serv21522
Modified Files:
GestionAdapta.java
Log Message:
Index: GestionAdapta.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/adaptability/GestionAdapta.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** GestionAdapta.java 12 Mar 2003 23:09:31 -0000 1.2
--- GestionAdapta.java 14 Mar 2003 11:38:47 -0000 1.3
***************
*** 15,20 ****
! (*) les arguments sont dans l'ordre: encodage, frame rate, quality level (de 0 � 100)
! (**) les argmunents sont dans l'ordre: encodage, sample rate, nombre de bit, channel (=monon ou st�r�o)
*/
--- 15,20 ----
! (*) les arguments sont dans l'ordre: encodage, frame rate, quality level (de 0 a 100)
! (**) les argmunents sont dans l'ordre: encodage, sample rate, nombre de bit, channel (=mono ou stereo)
*/
***************
*** 26,30 ****
import javax.media.format.VideoFormat.*;
import javax.media.format.AudioFormat.*;
! import javax.media.format.JPEGFormat.*;
import java.lang.*;
import java.awt.*;
--- 26,30 ----
import javax.media.format.VideoFormat.*;
import javax.media.format.AudioFormat.*;
! import javax.media.format.JPEGFormat;
import java.lang.*;
import java.awt.*;
***************
*** 34,38 ****
/****************************************************/
! /******* D�finition de la classe GestionAdapt *******/
/****************************************************/
--- 34,38 ----
/****************************************************/
! /******* Definition de la classe GestionAdapt *******/
/****************************************************/
***************
*** 40,46 ****
/***************************************************************/
! /* S�lectionne le bon format Audio en fct du niveau de qualit� */
/***************************************************************/
!
public static AudioFormat getAudioStreamingFormat(int nivQualite, AudioFormat f) {
String formatOriginal;
--- 40,46 ----
/***************************************************************/
! /* Selectionne le bon format Audio en fct du niveau de qualite */
/***************************************************************/
!
public static AudioFormat getAudioStreamingFormat(int nivQualite, AudioFormat f) {
String formatOriginal;
***************
*** 59,85 ****
/***************************************************************/
! /* S�lectionne le bon format Vid�o en fct du niveau de qualit� */
/***************************************************************/
! public static VideoFormat getVideoStreamingFormat(int nivQualite, VideoFormat f) {
! String formatOriginal;
! VideoFormat newVideoFormat;
/*********************************************************/
! /* Cr�ation du nouveau format selon le nuveau de qualit� */
/*********************************************************/
!
switch(nivQualite) {
! case 1: newVideoFormat = new JPEGFormat(f.getSize(),f.getMaxDataLength(),f.getDataType(),25,100,getDecimation());
! case 2: newVideoFormat = new JPEGFormat(f.getSize(),f.getMaxDataLength(),f.getDataType(),12,100,getDecimation());
! case 3: newVideoFormat = new JPEGFormat(f.getSize(),f.getMaxDataLength(),f.getDataType(),12,50,getDecimation());
! case 4: newVideoFormat = new JPEGFormat(f.getSize(),f.getMaxDataLength(),f.getDataType(),12,0,getDecimation());
! case 5: newVideoFormat = NULL;
! case 6: newVideoFormat = NULL;
! }
! if (newVideoFormat != NULL)
! newVideoFormat.setEncoding = "JPG_RTP"; // pour permettre le transfert via RTP
/**************************************/
--- 59,88 ----
/***************************************************************/
! /* Selectionne le bon format Video en fct du niveau de qualite */
/***************************************************************/
! public static VideoFormat getVideoStreamingFormat(int nivQualite, JPEGFormat f) {
! float fFR = 0,nFR = 0;
! int fq = 0,nq = 0;
!
! JPEGFormat newVideoFormat;
/*********************************************************/
! /* Creation du nouveau format selon le nuveau de qualite */
/*********************************************************/
!
! // on recupere les donnees utiles du format.
! fFR = f.getFrameRate();
! fq = f.getQFactor();
switch(nivQualite) {
! case 1: nFR = 25; nq = 100;
! case 2: nFR = 12; nq = 100;
! case 3: nFR = 12; nq = 50;
! case 4: nFR = 12; nq = 0;
! case 5: nFR = 0; nq = 0;
! case 6: nFR = 0; nq = 0;
! }
/**************************************/
***************
*** 87,104 ****
/**************************************/
! if (newVideoFormat != NULL) {
! newVideoFormat = takeMin(newVideoFormat.getFrameRate(),f.getFrameRate());
! newVideoFormat = takeMin(newVideoFormat.getQFactor(),f.getQFactor());
! }
! }
- /****************************************************/
- /* impl�mentation de la fonction min(int a, int b); */
- /****************************************************/
! int takeMin(int a, int b) {
return(a>b?b:a);
}
! }
\ No newline at end of file
--- 90,118 ----
/**************************************/
! nFR = takeMin(nFR, fFR);
! nq = takeMin(nq, fq);
! if (nFR == 0 && nq == 0)
! newVideoFormat = null;
! else
! newVideoFormat = new JPEGFormat(f.getSize(),f.getMaxDataLength(),f.getDataType(),nFR,nq,f.getDecimation());
+ return newVideoFormat;
+ }
+
+
+
! /***************************************************************************/
! /* implementation de la fonction min(int a, int b); et min(float a,float b)*/
! /***************************************************************************/
!
! static int takeMin(int a, int b) {
return(a>b?b:a);
}
!
! static float takeMin(float a,float b) {
! return(a>b?b:a);
! }
! }
|
|
From: <car...@us...> - 2003-03-14 03:27:24
|
Update of /cvsroot/madsserv/madsserv/src/server
In directory sc8-pr-cvs1:/tmp/cvs-serv3022
Added Files:
ErrNoListen.java ServerFrame.java
Log Message:
ajout de classes
--- NEW FILE: ErrNoListen.java ---
import java.lang.Exception;
class ErrNoListen extends Exception {
public String getMessage() {
return ("Impossible de creer le ThreadListenClients");
}
}
--- NEW FILE: ServerFrame.java ---
import javax.swing.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;
import java.awt.Component.*;
import java.awt.TextComponent.*;
import java.awt.Checkbox.*;
import java.awt.CheckboxGroup.*;
import java.util.*;
public class ServerFrame
extends JFrame {
Container contentPane = null;
ServerInit serverInit = null;
BorderLayout borderLayout1 = new BorderLayout();
GridLayout gridLayout1 = new GridLayout(4, 2, 5, 5);
GridLayout gridLayout2 = new GridLayout(1, 1);
GridBagLayout gridBagLayout2 = new GridBagLayout();
GridBagConstraints c;
Vector clientReports;
JPanel jPanelTitles = new JPanel();
JLabel jLabelID = new JLabel();
JLabel jLabelIP = new JLabel();
JLabel jLabelStatus = new JLabel();
JLabel jLabelMedia = new JLabel();
JLabel jLabelBitRate = new JLabel();
JLabel jLabelQuality = new JLabel();
JTabbedPane jTabbedPane = new JTabbedPane();
JPanel jPanelConfig = new JPanel();
JPanel jPanelReport = new JPanel();
JPanel jPanelFormats = new JPanel();
JPanel jPanelQuality = new JPanel();
JPanel jPanelSouth = new JPanel();
JLabel jLabelPort = new JLabel();
JLabel jLabelPortRTP = new JLabel();
JLabel jLabelNbMax = new JLabel();
JLabel jLabelDebit = new JLabel();
JTextField jTextFieldPort = new JTextField();
JTextField jTextFieldPortRTP = new JTextField();
JTextField jTextFieldNbMax = new JTextField();
JTextField jTextFieldDebit = new JTextField();
JButton jButtonStart = new JButton();
JButton jButtonStop = new JButton();
JButton jButtonQuit = new JButton();
public ServerFrame( /*ServerInit _parent*/) {
//parent = _parent;
contentPane = getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(600, 500));
this.setTitle("Madsserv Serveur");
clientReports = new Vector();
jPanelReport.setLayout(gridBagLayout2);
jPanelReport.setBackground(Color.black);
c = new GridBagConstraints();
c.weightx = 0.0;
jLabelID.setText("ID Client");
jLabelID.setHorizontalAlignment(SwingConstants.CENTER);
jPanelTitles.add(jLabelID, c);
jLabelIP.setText("IP Client");
jLabelIP.setHorizontalAlignment(SwingConstants.CENTER);
jPanelTitles.add(jLabelIP, c);
jLabelStatus.setText("Statut");
jLabelStatus.setHorizontalAlignment(SwingConstants.CENTER);
jPanelTitles.add(jLabelStatus, c);
jLabelMedia.setText("Media demandé");
jLabelMedia.setHorizontalAlignment(SwingConstants.CENTER);
jPanelTitles.add(jLabelMedia, c);
jLabelBitRate.setText("Débit");
jLabelBitRate.setHorizontalAlignment(SwingConstants.CENTER);
jPanelTitles.add(jLabelBitRate, c);
jLabelQuality.setText("Niveau de qualité");
jLabelQuality.setHorizontalAlignment(SwingConstants.CENTER);
c.gridwidth = GridBagConstraints.REMAINDER;
jPanelTitles.add(jLabelQuality, c);
jPanelReport.add(jPanelTitles);
jTabbedPane.addTab("Configuration", null, jPanelConfig,
"Configure le serveur");
jTabbedPane.addTab("Rapports", null, jPanelReport, "Affiche les connexions");
jTabbedPane.addTab("Formats", null, jPanelFormats,
"Affiche les formats supportés par le serveur");
jTabbedPane.addTab("Qualité", null, jPanelQuality,
"Affiche l'association format/niveau de qualité");
contentPane.add(jTabbedPane, BorderLayout.CENTER);
jLabelPort.setText("Port d'écoute :");
jTextFieldPort.setText("5000");
jLabelPortRTP.setText("Port de base pour RTP :");
jTextFieldPortRTP.setText("40000");
jLabelNbMax.setText("Nombre maximum de clients :");
jTextFieldNbMax.setText("10");
jLabelDebit.setText("Debit minimum en Ko/s :");
jTextFieldDebit.setText("20");
jPanelConfig.setLayout(gridLayout1);
jPanelConfig.add(jLabelPort);
jPanelConfig.add(jTextFieldPort);
jPanelConfig.add(jLabelPortRTP);
jPanelConfig.add(jTextFieldPortRTP);
jPanelConfig.add(jLabelNbMax);
jPanelConfig.add(jTextFieldNbMax);
jPanelConfig.add(jLabelDebit);
jPanelConfig.add(jTextFieldDebit);
jButtonStart.setText("Démarrer");
jButtonStart.setEnabled(true);
jButtonStart.addActionListener(new ServerFrame_Button_Start_ActionAdapter(this));
jPanelSouth.add(jButtonStart);
jButtonStop.setText("Arrêter");
jButtonStop.setEnabled(false);
jButtonStop.addActionListener(new ServerFrame_Button_Stop_ActionAdapter(this));
jPanelSouth.add(jButtonStop);
jButtonQuit.setText("Quitter");
jButtonQuit.addActionListener(new ServerFrame_Button_Quit_ActionAdapter(this));
jPanelSouth.add(jButtonQuit);
contentPane.add(jPanelSouth, BorderLayout.SOUTH);
}
public void Button_Start_actionPerformed(ActionEvent evt) {
int port = 5000;
int portBaseRTP = 40000;
int nbClients = 10;
int debit = 20;
Integer integer1 = null;
Integer integer2 = null;
Integer integer3 = null;
Integer integer4 = null;
try {
integer1 = Integer.valueOf(jTextFieldPort.getText());
integer2 = Integer.valueOf(jTextFieldPortRTP.getText());
integer3 = Integer.valueOf(jTextFieldNbMax.getText());
integer4 = Integer.valueOf(jTextFieldDebit.getText());
if (integer1 == null || integer2 == null || integer3 == null || integer3 == null) {
System.err.println("il y a une erreur");
displayError("Erreur de saisie",
"La valeur d'un champ est incorrecte.\nVeuillez la modifier");
}
else {
port = integer1.intValue();
portBaseRTP = integer2.intValue();
nbClients = integer3.intValue();
debit = integer4.intValue();
}
}
catch (NumberFormatException e) {
displayError("Erreur de saisie",
"La valeur d'un champ est incorrecte.\nVeuillez la modifier");
}
if (serverInit == null) {
try {
serverInit = new ServerInit(port, portBaseRTP, nbClients, debit, this);
serverInit.start();
jButtonStart.setEnabled(false);
jButtonStop.setEnabled(true);
}
catch (ErrNoListen e) {
serverInit = null;
// lancer erreur popup
jButtonStart.setEnabled(true);
jButtonStop.setEnabled(false);
}
}
else {
System.err.println("ServerInit est deja cree");
}
}
public void displayError(String _name, String _message) {
JOptionPane.showMessageDialog(this, _message, _name,
JOptionPane.WARNING_MESSAGE);
}
public void addClientReport(ClientReport _clientReport) {
int rows, columns;
rows = gridLayout2.getRows() + 1;
gridLayout2.setRows(rows);
jPanelReport.add(_clientReport.getGraphics());
}
public void Button_Stop_actionPerformed(ActionEvent evt) {
serverInit.stop();
}
public void Button_Quit_actionPerformed(ActionEvent evt) {
System.exit(0);
}
/**
* processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre
* @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre
*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
Button_Quit_actionPerformed(null);
}
}
public static void main(String[] args) {
ServerFrame serverFrame = new ServerFrame();
serverFrame.pack();
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = serverFrame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
serverFrame.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
serverFrame.show();
}
}
class ServerFrame_Button_Start_ActionAdapter
implements ActionListener {
ServerFrame adaptee;
ServerFrame_Button_Start_ActionAdapter(ServerFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent evt) {
adaptee.Button_Start_actionPerformed(evt);
}
}
class ServerFrame_Button_Stop_ActionAdapter
implements ActionListener {
ServerFrame adaptee;
ServerFrame_Button_Stop_ActionAdapter(ServerFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent evt) {
adaptee.Button_Stop_actionPerformed(evt);
}
}
class ServerFrame_Button_Quit_ActionAdapter
implements ActionListener {
ServerFrame adaptee;
ServerFrame_Button_Quit_ActionAdapter(ServerFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent evt) {
adaptee.Button_Quit_actionPerformed(evt);
}
}
class ClientReport {
private int clientID = -1;
private String clientIP = "";
private String status = "";
private String media = "";
private float debit = 0.0f;
private int qualityLevel = -1;
private JLabel jLabelID = new JLabel();
private JLabel jLabelIP = new JLabel();
private JLabel jLabelStatus = new JLabel();
private JLabel jLabelMedia = new JLabel();
private JLabel jLabelDebit = new JLabel();
private JLabel jLabelQuality = new JLabel();
// constructeurs
public ClientReport(int _clientID, String _IP, String _status) {
clientID = _clientID;
clientIP = _IP;
status = _status;
}
public ClientReport(int _clientID, String _IP, String _status, String _media,
int _qualityLevel) {
clientID = _clientID;
clientIP = _IP;
status = _status;
media = _media;
qualityLevel = _qualityLevel;
}
public synchronized void setStatus(String _status) {
status = _status;
}
public synchronized void setMedia(String _media) {
media = _media;
}
public synchronized void setDebit(float _debit) {
debit = _debit;
}
public synchronized void setQualityLevel(int _quality) {
qualityLevel = _quality;
}
public JPanel getGraphics() {
JPanel jPanelReturn = new JPanel();
GridBagLayout gridBagLayout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.weightx = 1.0;
jLabelID.setText(String.valueOf(clientID));
jLabelID.setHorizontalAlignment(SwingConstants.CENTER);
jPanelReturn.add(jLabelID, c);
jLabelIP.setText(clientIP);
jLabelIP.setHorizontalAlignment(SwingConstants.CENTER);
jPanelReturn.add(jLabelIP, c);
jLabelStatus.setText(status);
jLabelStatus.setHorizontalAlignment(SwingConstants.CENTER);
jPanelReturn.add(jLabelStatus, c);
jLabelMedia.setText(media);
jLabelMedia.setHorizontalAlignment(SwingConstants.CENTER);
jPanelReturn.add(jLabelMedia, c);
jLabelDebit.setText(String.valueOf(debit));
jLabelDebit.setHorizontalAlignment(SwingConstants.CENTER);
jPanelReturn.add(jLabelDebit, c);
jLabelQuality.setText(String.valueOf(qualityLevel));
jLabelQuality.setHorizontalAlignment(SwingConstants.CENTER);
c.gridwidth = GridBagConstraints.REMAINDER;
jPanelReturn.add(jLabelQuality);
return jPanelReturn;
}
public void removeClientReport() {
}
public void updateClientReport() {
}
}
|
|
From: <car...@us...> - 2003-03-14 03:26:22
|
Update of /cvsroot/madsserv/madsserv/src/client In directory sc8-pr-cvs1:/tmp/cvs-serv2431/src/client Modified Files: Client.java ClientRTPManager.java DialogServer.java ErrorPopUp.java MadsservClient.java PlayerPanel.java ThreadRTPManager.java ThreadRead.java ThreadWrite.java Log Message: premiere version test Index: Client.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/Client.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Client.java 13 Mar 2003 23:27:35 -0000 1.6 --- Client.java 14 Mar 2003 03:26:17 -0000 1.7 *************** *** 1,383 **** ! //package madsserv_planification; ! ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.Checkbox.*; ! import java.awt.CheckboxGroup.*; ! import javax.swing.*; ! ! /** ! * <p>Title: Client </p> ! * <p>Description: La Classe Client est l'interface graphique du client</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! */ ! ! public class Client ! extends Frame { ! /** ! * Champs de la Classe Reencode ! */ ! ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelCenter = new Panel(); ! private Panel panelSouth = new Panel(); ! private Panel panelEmpty = new Panel(); ! private MenuBar menuBar1 = new MenuBar(); ! private Menu menuFile = new Menu(); ! private MenuItem menuOpenURL = new MenuItem(); ! private MenuItem menuFileExit = new MenuItem(); ! private Label statusBar = new Label(); ! private Label URLLabel = new Label(); ! private Label AdLabel = new Label(); ! ! private TextField URLChoice; ! private TextField AdServer; ! private CheckboxGroup cbg = new CheckboxGroup(); ! private Checkbox formatMPEG; ! private Checkbox formatJPEG; ! private Button go; ! ! private PlayerPanel playerPanel = null; ! ! private BorderLayout borderLayout1 = new BorderLayout(); ! private GridBagLayout gridBagLayoutNorth = new GridBagLayout(); ! private GridBagLayout gridBagLayoutSouth = new GridBagLayout(); ! ! private boolean insVideo = false; ! ! private Socket mySocket = null; ! private DialogServer dialogServer; ! ! ! ! /** ! * Contructeur de la Classe Client ! */ ! ! public Client() { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! try { ! jbInit(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * setPlayerPanel crée l'interface graphique du Client ! * @param pp il s'agit d'un PlayerPanel qui est une classe que nous avons crée ! * @vid est un booleen qui nous dit si le player a cree est de la video ou de l'audio ! */ ! ! public void setPlayerPanel(PlayerPanel pp, boolean vid) { ! Panel panelTemp; ! ! if (playerPanel == null) { ! panelTemp = panelEmpty; ! } ! else ! ! { ! panelTemp = playerPanel; ! } ! System.out.println("video :" + vid); ! System.out.println("insvideo :" + insVideo); ! ! // on teste ici pour savoir si on doit cree un player video ou un player audio ! if (vid) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! insVideo = true; ! } ! ! else if (!insVideo) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! } ! } ! ! /** ! * jbinit lance la creation de l'interface graphique. ! */ ! private void jbInit() throws Exception { ! ! contentPane = this; ! contentPane.setLayout(borderLayout1); ! this.setSize(new Dimension(240, 320)); ! this.setTitle("Madsserv Client"); ! setAfficheStatusBar("coucou"); ! URLChoice = new TextField("file:///c:\\temp\\kiss_cool_1.mpeg"); ! AdServer = new TextField("dronej.rezel.com:5100"); ! menuFile.setLabel("File"); ! menuOpenURL.setLabel("Open URL"); ! menuOpenURL.addActionListener(new Client_Menu_OpenURL_ActionAdapter(this)); ! menuFileExit.setLabel("Exit"); ! menuFileExit.addActionListener(new Client_menuFileExit_ActionAdapter(this)); ! menuFile.add(menuOpenURL); ! menuFile.add(menuFileExit); ! menuBar1.add(menuFile); ! this.setMenuBar(menuBar1); ! ! formatMPEG = new Checkbox("MPEG", cbg, true); ! ! formatJPEG = new Checkbox("JPEG", cbg, false); ! ! go = new Button("Go!"); ! go.setSize(new Dimension(60, 15)); ! go.addActionListener(new Client_boutongo_ActionAdapter(this)); ! ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! panelSouth.setLayout(gridBagLayoutSouth); ! GridBagConstraints c = new GridBagConstraints(); ! c.fill = GridBagConstraints.BOTH; ! c.insets = new Insets(1, 5, 1, 5); ! c.weightx = 1.0; ! c.weighty = 1.0; ! panelSouth.add(formatMPEG, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelSouth.add(formatJPEG, c); ! c.weightx = 0.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelSouth.add(go, c); ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.weightx = 0.0; ! c.gridwidth = 2; ! panelSouth.add(statusBar, c); ! ! URLLabel.setText("URL :"); ! AdLabel.setText("Serv:"); ! URLLabel.setSize(new Dimension(30, 15)); ! URLChoice.setSize(new Dimension(30, 15)); ! AdLabel.setSize(new Dimension(30, 15)); ! AdServer.setSize(new Dimension(30, 15)); ! ! panelNorth.setLayout(gridBagLayoutNorth); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.gridwidth = 1; ! c.weightx = 0.0; ! c.weighty = 1.0; ! panelNorth.add(URLLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelNorth.add(URLChoice, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.weightx = 0.0; ! panelNorth.add(AdLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelNorth.add(AdServer, c); ! ! contentPane.add(panelSouth, BorderLayout.SOUTH); ! contentPane.add(panelNorth, BorderLayout.NORTH); ! ! contentPane.add(panelEmpty, BorderLayout.CENTER); ! ! } ! ! /** ! * menuFileExit_actionPerformed est à l'ecoute d'un evenement signifiant l'arret du client ! * @param e c'est l'evenemet qui met fin au client ! */ ! public void menuFileExit_actionPerformed(ActionEvent e) { ! try { ! String messageToSend[] = new String[1]; ! messageToSend[0] = "fin de la connexion"; ! dialogServer.sendMessage(4, messageToSend); ! System.exit(0); ! } ! catch (Exception ex) { ! System.exit(0); ! } ! } ! ! /** ! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre ! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre ! */ ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! menuFileExit_actionPerformed(null); ! } ! } ! ! /** ! * boutongo_actionPerformed Methode qui permet de lancer la connexion lorsque l'on clique sur le bouton go ! * @param evt c'est l'evenement qui indique que l'on a clique sur le bouton go ! */ ! public void boutongo_actionPerformed(ActionEvent evt) { ! ! String[] messageToSend; ! ! if (mySocket == null) { ! try { ! mySocket = new Socket(getAddressServer(), getServerPort()); ! } ! catch (Exception e) { ! showError("Le serveur ou le port n'est pas correct"); ! } ! ! dialogServer = new DialogServer(mySocket, this); ! dialogServer.start(); ! } ! ! else { ! // if ( (mySocket.isClosed()) == false) { ! messageToSend = new String[2]; ! messageToSend[0] = getURL(); ! messageToSend[1] = getFormatPrefere(); ! ! dialogServer.sendMessage(2, messageToSend); ! /*} ! else { ! try { ! mySocket.connect(new InetSocketAddress(getAddressServer(), ! getServerPort())); ! } ! catch (Exception e) { ! } ! }*/ ! } ! } ! ! public void endConnexion() { ! dialogServer.stop(); ! mySocket = null; ! } ! ! public void showError(String messageErreur) ! { ! ErrorPopUp errorPopUp = new ErrorPopUp(messageErreur,this); ! } ! ! /** ! * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client ! * @return InetAddress du server ! */ ! public InetAddress getAddressServer() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! try { ! return (InetAddress.getByName(host.substring(0, columnPosition))); ! } ! ! catch (UnknownHostException e) { ! return (null); ! } ! } ! ! /** ! * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client ! * @return int le numero du port sur lequel, on doit se connecter au serveur ! */ ! public int getServerPort() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! ! return (Integer.parseInt(host.substring(columnPosition + 1))); ! ! } ! ! /** ! * getURL permet d'obtenir l'URL du fichier multimedia que l'on souhaite visionner, cet URL est rentre dans une zone de texte sur l'interface graphique du client ! * @return String l'adresse du media demande ! */ ! public String getURL() { ! ! return (URLChoice.getText()); ! } ! ! public String getFormatPrefere() { ! ! if (formatMPEG.getState()) { ! return ("MPEG"); ! } ! ! else { ! if (formatJPEG.getState()) { ! return ("JPEG"); ! } ! else { ! return (""); ! } ! } ! ! } ! ! /** ! * setAfficheStatusBar est une methode qui permet d'afficher en bas du client un message envoye par le server ! * @param _message un message envoye sous forme de String envoye par le serveur ! */ ! public void setAfficheStatusBar(String _message) { ! statusBar.setText(_message); ! } ! ! /** ! * Client_menuFileExit_ActionAdapter, classe qui ecoute pour savoir si on clique sur le menu exit et envoie alors l'evenement ! */ ! class Client_menuFileExit_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_menuFileExit_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.menuFileExit_actionPerformed(e); ! } ! } ! ! /** ! * Client_boutongo_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton go et envoie alors l'evenement ! */ ! class Client_boutongo_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_boutongo_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! ! /** ! * Client_Menu_OpenURL_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton OpenURL et envoie alors l'evenement ! */ ! class Client_Menu_OpenURL_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_Menu_OpenURL_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! } --- 1,383 ---- ! //package madsserv_planification; ! ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.Checkbox.*; ! import java.awt.CheckboxGroup.*; ! import javax.swing.*; ! ! /** ! * <p>Title: Client </p> ! * <p>Description: La Classe Client est l'interface graphique du client</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! */ ! ! public class Client ! extends Frame { ! /** ! * Champs de la Classe Reencode ! */ ! ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelCenter = new Panel(); ! private Panel panelSouth = new Panel(); ! private Panel panelEmpty = new Panel(); ! private MenuBar menuBar1 = new MenuBar(); ! private Menu menuFile = new Menu(); ! private MenuItem menuOpenURL = new MenuItem(); ! private MenuItem menuFileExit = new MenuItem(); ! private Label statusBar = new Label(); ! private Label URLLabel = new Label(); ! private Label AdLabel = new Label(); ! ! private TextField URLChoice; ! private TextField AdServer; ! private CheckboxGroup cbg = new CheckboxGroup(); ! private Checkbox formatMPEG; ! private Checkbox formatJPEG; ! private Button go; ! ! private PlayerPanel playerPanel = null; ! ! private BorderLayout borderLayout1 = new BorderLayout(); ! private GridBagLayout gridBagLayoutNorth = new GridBagLayout(); ! private GridBagLayout gridBagLayoutSouth = new GridBagLayout(); ! ! private boolean insVideo = false; ! ! private Socket mySocket = null; ! private DialogServer dialogServer; ! ! ! ! /** ! * Contructeur de la Classe Client ! */ ! ! public Client() { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! try { ! jbInit(); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! } ! ! /** ! * setPlayerPanel crée l'interface graphique du Client ! * @param pp il s'agit d'un PlayerPanel qui est une classe que nous avons crée ! * @vid est un booleen qui nous dit si le player a cree est de la video ou de l'audio ! */ ! ! public void setPlayerPanel(PlayerPanel pp, boolean vid) { ! Panel panelTemp; ! ! if (playerPanel == null) { ! panelTemp = panelEmpty; ! } ! else ! ! { ! panelTemp = playerPanel; ! } ! System.out.println("video :" + vid); ! System.out.println("insvideo :" + insVideo); ! ! // on teste ici pour savoir si on doit cree un player video ou un player audio ! if (vid) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! insVideo = true; ! } ! ! else if (!insVideo) { ! playerPanel = pp; ! contentPane.remove(panelTemp); ! contentPane.add(playerPanel, BorderLayout.CENTER); ! validate(); ! } ! } ! ! /** ! * jbinit lance la creation de l'interface graphique. ! */ ! private void jbInit() throws Exception { ! ! contentPane = this; ! contentPane.setLayout(borderLayout1); ! this.setSize(new Dimension(240, 320)); ! this.setTitle("Madsserv Client"); ! setAfficheStatusBar("coucou"); ! URLChoice = new TextField("file:/stud/users/promo04/carbonel/tmp/video/kiss_cool_1.mpeg"); ! AdServer = new TextField("fresnel.enst.fr:5000"); ! menuFile.setLabel("File"); ! menuOpenURL.setLabel("Open URL"); ! menuOpenURL.addActionListener(new Client_Menu_OpenURL_ActionAdapter(this)); ! menuFileExit.setLabel("Exit"); ! menuFileExit.addActionListener(new Client_menuFileExit_ActionAdapter(this)); ! menuFile.add(menuOpenURL); ! menuFile.add(menuFileExit); ! menuBar1.add(menuFile); ! this.setMenuBar(menuBar1); ! ! formatMPEG = new Checkbox("MPEG", cbg, true); ! ! formatJPEG = new Checkbox("JPEG", cbg, false); ! ! go = new Button("Go!"); ! go.setSize(new Dimension(60, 15)); ! go.addActionListener(new Client_boutongo_ActionAdapter(this)); ! ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! panelSouth.setLayout(gridBagLayoutSouth); ! GridBagConstraints c = new GridBagConstraints(); ! c.fill = GridBagConstraints.BOTH; ! c.insets = new Insets(1, 5, 1, 5); ! c.weightx = 1.0; ! c.weighty = 1.0; ! panelSouth.add(formatMPEG, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelSouth.add(formatJPEG, c); ! c.weightx = 0.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelSouth.add(go, c); ! c.gridwidth = GridBagConstraints.REMAINDER; ! c.weightx = 0.0; ! c.gridwidth = 2; ! panelSouth.add(statusBar, c); ! ! URLLabel.setText("URL :"); ! AdLabel.setText("Serv:"); ! URLLabel.setSize(new Dimension(30, 15)); ! URLChoice.setSize(new Dimension(30, 15)); ! AdLabel.setSize(new Dimension(30, 15)); ! AdServer.setSize(new Dimension(30, 15)); ! ! panelNorth.setLayout(gridBagLayoutNorth); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.gridwidth = 1; ! c.weightx = 0.0; ! c.weighty = 1.0; ! panelNorth.add(URLLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.REMAINDER; ! panelNorth.add(URLChoice, c); ! c.gridwidth = GridBagConstraints.RELATIVE; ! c.weightx = 0.0; ! panelNorth.add(AdLabel, c); ! c.weightx = 1.0; ! c.gridwidth = GridBagConstraints.RELATIVE; ! panelNorth.add(AdServer, c); ! ! contentPane.add(panelSouth, BorderLayout.SOUTH); ! contentPane.add(panelNorth, BorderLayout.NORTH); ! ! contentPane.add(panelEmpty, BorderLayout.CENTER); ! ! } ! ! /** ! * menuFileExit_actionPerformed est à l'ecoute d'un evenement signifiant l'arret du client ! * @param e c'est l'evenemet qui met fin au client ! */ ! public void menuFileExit_actionPerformed(ActionEvent e) { ! try { ! String messageToSend[] = new String[1]; ! messageToSend[0] = "fin de la connexion"; ! dialogServer.sendMessage(4, messageToSend); ! System.exit(0); ! } ! catch (Exception ex) { ! System.exit(0); ! } ! } ! ! /** ! * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre ! * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre ! */ ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! menuFileExit_actionPerformed(null); ! } ! } ! ! /** ! * boutongo_actionPerformed Methode qui permet de lancer la connexion lorsque l'on clique sur le bouton go ! * @param evt c'est l'evenement qui indique que l'on a clique sur le bouton go ! */ ! public void boutongo_actionPerformed(ActionEvent evt) { ! ! String[] messageToSend; ! ! if (mySocket == null) { ! try { ! mySocket = new Socket(getAddressServer(), getServerPort()); ! } ! catch (Exception e) { ! showError("Le serveur ou le port n'est pas correct"); ! } ! ! dialogServer = new DialogServer(mySocket, this); ! dialogServer.start(); ! } ! ! else { ! // if ( (mySocket.isClosed()) == false) { ! messageToSend = new String[2]; ! messageToSend[0] = getURL(); ! messageToSend[1] = getFormatPrefere(); ! ! dialogServer.sendMessage(2, messageToSend); ! /*} ! else { ! try { ! mySocket.connect(new InetSocketAddress(getAddressServer(), ! getServerPort())); ! } ! catch (Exception e) { ! } ! }*/ ! } ! } ! ! public void endConnexion() { ! dialogServer.stop(); ! mySocket = null; ! } ! ! public void showError(String messageErreur) ! { ! ErrorPopUp errorPopUp = new ErrorPopUp(messageErreur,this); ! } ! ! /** ! * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client ! * @return InetAddress du server ! */ ! public InetAddress getAddressServer() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! try { ! return (InetAddress.getByName(host.substring(0, columnPosition))); ! } ! ! catch (UnknownHostException e) { ! return (null); ! } ! } ! ! /** ! * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client ! * @return int le numero du port sur lequel, on doit se connecter au serveur ! */ ! public int getServerPort() { ! String host; ! int columnPosition; ! ! host = AdServer.getText(); ! columnPosition = host.indexOf(':'); ! ! return (Integer.parseInt(host.substring(columnPosition + 1))); ! ! } ! ! /** ! * getURL permet d'obtenir l'URL du fichier multimedia que l'on souhaite visionner, cet URL est rentre dans une zone de texte sur l'interface graphique du client ! * @return String l'adresse du media demande ! */ ! public String getURL() { ! ! return (URLChoice.getText()); ! } ! ! public String getFormatPrefere() { ! ! if (formatMPEG.getState()) { ! return ("MPEG"); ! } ! ! else { ! if (formatJPEG.getState()) { ! return ("JPEG"); ! } ! else { ! return (""); ! } ! } ! ! } ! ! /** ! * setAfficheStatusBar est une methode qui permet d'afficher en bas du client un message envoye par le server ! * @param _message un message envoye sous forme de String envoye par le serveur ! */ ! public void setAfficheStatusBar(String _message) { ! statusBar.setText(_message); ! } ! ! /** ! * Client_menuFileExit_ActionAdapter, classe qui ecoute pour savoir si on clique sur le menu exit et envoie alors l'evenement ! */ ! class Client_menuFileExit_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_menuFileExit_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.menuFileExit_actionPerformed(e); ! } ! } ! ! /** ! * Client_boutongo_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton go et envoie alors l'evenement ! */ ! class Client_boutongo_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_boutongo_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! ! /** ! * Client_Menu_OpenURL_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton OpenURL et envoie alors l'evenement ! */ ! class Client_Menu_OpenURL_ActionAdapter ! implements ActionListener { ! Client adaptee; ! ! Client_Menu_OpenURL_ActionAdapter(Client adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent evt) { ! adaptee.boutongo_actionPerformed(evt); ! } ! } ! } Index: ClientRTPManager.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ClientRTPManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ClientRTPManager.java 13 Mar 2003 02:38:49 -0000 1.4 --- ClientRTPManager.java 14 Mar 2003 03:26:18 -0000 1.5 *************** *** 1,604 **** ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; [...1179 lines suppressed...] ! prUsage(); ! ClientRTPManager avReceive = new ClientRTPManager(argv); ! if (!avReceive.initialize()) { ! System.err.println("Failed to initialize the sessions."); ! System.exit(-1); ! } ! // Check to see if ClientRTPManager is done. ! try { ! while (!avReceive.isDone()) ! Thread.sleep(1000); ! } catch (Exception e) {} ! System.err.println("Exiting AVReceive2"); ! } ! static void prUsage() { ! System.err.println("Usage: AVReceive2 <session> <session> ..."); ! System.err.println(" <session>: <address>/<port>/<ttl>"); ! System.exit(0); ! } ! */ ! } // end of ClientRTPManager Index: DialogServer.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/DialogServer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DialogServer.java 13 Mar 2003 23:27:35 -0000 1.5 --- DialogServer.java 14 Mar 2003 03:26:18 -0000 1.6 *************** *** 1,162 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! import java.lang.Object.*; ! import java.lang.System.*; ! ! /** ! * DialogServer c'est la classe qui herite de la classe dialogSocket et qui gere les dialogues avec le serveur ! */ ! public class DialogServer ! extends DialogSocket { ! ! private Client client; ! private ThreadRTPManager threadRTPManager; ! private String[] sessions = new String[2]; ! /** ! * C'est le constructeur de la classe ! */ ! public DialogServer(Socket _socketServer, Client _client) { ! super(_socketServer); ! client = _client; ! clientID = -1; ! } ! ! /** ! * incomingMessage methode qui a ete declare abstraite dans DialogSocket et qui gere l'arivee de nouveaux messages du serveur ! * @param _type type de message qui arrive (c'est un entier) ! * @param _message tableau de chaine de characteres qui contient les messages du serveur ! */ ! public void incomingMessage(int _type, String[] _message) { ! int lgth = _message.length; ! int portBase = 40000; ! String[] messageToSend; ! String sessionTemp; ! Integer port1, port2; ! ! switch (_type) { ! case 9: { ! ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! break; ! } ! ! case 7: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! try { ! client.setAfficheStatusBar(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! break; ! } ! case 5: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! client.showError(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 3: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! /** ! *on regarde si le threadRTPManager existe, si il n'existe pas on le cree, sinon on le detruit et on en cree un nouveau ! */ ! if (threadRTPManager == null) { ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! else { ! ! threadRTPManager.Fermer(); ! threadRTPManager = null; ! System.gc(); ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! break; ! ! } ! case 1: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! // lecture du troisieme champ du message : portBase ! try { ! portBase = Integer.parseInt(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! ! /** ! * On stocke dans le variable sessions, l'adresse du server et les ports pour les diffusions audio et video ! */ ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port1 = new Integer(portBase); ! sessionTemp = sessionTemp.concat(port1.toString()); ! sessions[0] = sessionTemp; ! sessionTemp = ""; ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port2 = new Integer(portBase + 2); ! sessionTemp = sessionTemp.concat(port2.toString()); ! sessions[1] = sessionTemp; ! ! System.out.println(sessions[0]); ! System.out.println(sessions[1]); ! ! messageToSend = new String[2]; ! ! messageToSend[0] = client.getURL(); ! messageToSend[1] = client.getFormatPrefere(); ! ! sendMessage(2, messageToSend); ! } ! } ! } } --- 1,169 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! import java.lang.Object.*; ! import java.lang.System.*; ! ! /** ! * DialogServer c'est la classe qui herite de la classe dialogSocket et qui gere les dialogues avec le serveur ! */ ! public class DialogServer ! extends DialogSocket { ! ! private Client client; ! private ThreadRTPManager threadRTPManager; ! private String[] sessions = new String[2]; ! /** ! * C'est le constructeur de la classe ! */ ! public DialogServer(Socket _socketServer, Client _client) { ! super(_socketServer); ! client = _client; ! clientID = -1; ! } ! ! /** ! * incomingMessage methode qui a ete declare abstraite dans DialogSocket et qui gere l'arivee de nouveaux messages du serveur ! * @param _type type de message qui arrive (c'est un entier) ! * @param _message tableau de chaine de characteres qui contient les messages du serveur ! */ ! public void incomingMessage(int _type, String[] _message) { ! int lgth = _message.length; ! int portBase = 40000; ! String[] messageToSend; ! String sessionTemp; ! Integer port1, port2; ! ! switch (_type) { ! ! case 9: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! try { ! client.setAfficheStatusBar(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! break; ! } ! ! case 7: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! client.showError(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 5: { ! //if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! System.out.println(_message[1]); ! ! threadRTPManager.Fermer(); ! client.endConnexion(); ! System.out.println("coucou de fin"); ! break; ! } ! ! case 3: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! /** ! *on regarde si le threadRTPManager existe, si il n'existe pas on le cree, sinon on le detruit et on en cree un nouveau ! */ ! if (threadRTPManager == null) { ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! else { ! ! threadRTPManager.Fermer(); ! threadRTPManager = null; ! System.gc(); ! threadRTPManager = new ThreadRTPManager(sessions, client); ! threadRTPManager.start(); ! } ! ! break; ! ! } ! case 1: { ! // if (lgth < 2) raise exception; ! //lecture du deuxieme champ : ClientID ! try { ! clientID = Integer.parseInt(_message[0]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le deuxieme champ du message est incorrect"); ! } ! ! // lecture du troisieme champ du message : portBase ! try { ! portBase = Integer.parseInt(_message[1]); ! } ! catch (NumberFormatException e) { ! System.out.println("Le troisieme champ du message est incorrect"); ! } ! ! /** ! * On stocke dans le variable sessions, l'adresse du server et les ports pour les diffusions audio et video ! */ ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port1 = new Integer(portBase); ! sessionTemp = sessionTemp.concat(port1.toString()); ! sessions[0] = sessionTemp; ! sessionTemp = ""; ! sessionTemp = client.getAddressServer().getHostAddress().toString(); ! sessionTemp = sessionTemp.concat("/"); ! port2 = new Integer(portBase + 2); ! sessionTemp = sessionTemp.concat(port2.toString()); ! sessions[1] = sessionTemp; ! ! System.out.println(sessions[0]); ! System.out.println(sessions[1]); ! ! messageToSend = new String[2]; ! ! messageToSend[0] = client.getURL(); ! messageToSend[1] = client.getFormatPrefere(); ! ! sendMessage(2, messageToSend); ! } ! } ! } } Index: ErrorPopUp.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ErrorPopUp.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ErrorPopUp.java 13 Mar 2003 23:27:36 -0000 1.1 --- ErrorPopUp.java 14 Mar 2003 03:26:18 -0000 1.2 *************** *** 1,114 **** ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.geom.Point2D.*; ! import java.awt.Point.*; ! ! /** ! * <code>ErrorPopUp</code> est une popup qui apparait lorsque des erreurs apparaissent. ! * @author Xavier Deplancq ! */ ! ! public class ErrorPopUp ! extends Frame { ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelSouth = new Panel(); ! private Label errorMessage = new Label(); ! private BorderLayout borderLayout1 = new BorderLayout(); ! private Button OK; ! ! /** ! * Constructeur de la classe ErrorPopUp ! * @param errMessage le Message qui doit etre affiche ! * @param _client la reference du client ! */ ! ! public ErrorPopUp(String errMessage, Client _client) { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! errorMessage.setText(errMessage); ! panelNorth.add(errorMessage); ! OK = new Button("OK"); ! OK.setSize(new Dimension(60, 15)); ! OK.addActionListener(new ErrorPopUp_OK_ActionAdapter(this)); ! panelSouth.add(OK); ! contentPane = this; ! this.setSize(220, 90); ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! contentPane.setLayout(borderLayout1); ! contentPane.add(panelNorth, borderLayout1.CENTER); ! contentPane.add(panelSouth, borderLayout1.SOUTH); ! ! //On place la boite de dialogue ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension clientSize = _client.getSize(); ! Dimension popupSize = this.getSize(); ! double clientPlaceX = _client.getX(); ! double clientPlaceY = _client.getY(); ! if (popupSize.height > clientSize.height) { ! popupSize.height = clientSize.height; ! } ! if (popupSize.width > clientSize.width) { ! popupSize.width = clientSize.width; ! } ! this.setLocation( (int) (clientPlaceX) /*+ ! ( ! clientSize.height - popupSize.height) / 2*/, ! (int) (clientPlaceY) + clientSize.width / 2); ! ! showWindow(); ! ! } ! ! /** ! * OK_actionPerformed qui sert lorsque l'on appuie sur le bouton OK ! * @param e l'evenement ! */ ! ! public void OK_actionPerformed(ActionEvent e) { ! setVisible(false); ! } ! ! /** ! * processWindowEvent c est une methode qui est appele lorsque l'on ferme la boite de dialogue ! * @param l evenement qui indique que l'on ferme la fenetre ! */ ! ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! OK_actionPerformed(null); ! } ! } ! ! /** ! * Methode qui affiche la boite de dialogue ! */ ! ! public void showWindow() { ! setVisible(true); ! } ! ! /** ! * Classe qui ecoute si l'on appui sur le bouton OK ! */ ! ! class ErrorPopUp_OK_ActionAdapter ! implements ActionListener { ! ErrorPopUp adaptee; ! ! ErrorPopUp_OK_ActionAdapter(ErrorPopUp adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.OK_actionPerformed(e); ! } ! } ! } --- 1,114 ---- ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.awt.Component.*; ! import java.awt.TextComponent.*; ! import java.awt.geom.Point2D.*; ! import java.awt.Point.*; ! ! /** ! * <code>ErrorPopUp</code> est une popup qui apparait lorsque des erreurs apparaissent. ! * @author Xavier Deplancq ! */ ! ! public class ErrorPopUp ! extends Frame { ! private Container contentPane; ! private Panel panelNorth = new Panel(); ! private Panel panelSouth = new Panel(); ! private Label errorMessage = new Label(); ! private BorderLayout borderLayout1 = new BorderLayout(); ! private Button OK; ! ! /** ! * Constructeur de la classe ErrorPopUp ! * @param errMessage le Message qui doit etre affiche ! * @param _client la reference du client ! */ ! ! public ErrorPopUp(String errMessage, Client _client) { ! enableEvents(AWTEvent.WINDOW_EVENT_MASK); ! ! errorMessage.setText(errMessage); ! panelNorth.add(errorMessage); ! OK = new Button("OK"); ! OK.setSize(new Dimension(60, 15)); ! OK.addActionListener(new ErrorPopUp_OK_ActionAdapter(this)); ! panelSouth.add(OK); ! contentPane = this; ! this.setSize(220, 90); ! panelNorth.setBackground(new Color(236, 233, 216)); ! panelSouth.setBackground(new Color(236, 233, 216)); ! ! contentPane.setLayout(borderLayout1); ! contentPane.add(panelNorth, borderLayout1.CENTER); ! contentPane.add(panelSouth, borderLayout1.SOUTH); ! ! //On place la boite de dialogue ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension clientSize = _client.getSize(); ! Dimension popupSize = this.getSize(); ! double clientPlaceX = _client.getX(); ! double clientPlaceY = _client.getY(); ! if (popupSize.height > clientSize.height) { ! popupSize.height = clientSize.height; ! } ! if (popupSize.width > clientSize.width) { ! popupSize.width = clientSize.width; ! } ! this.setLocation( (int) (clientPlaceX) /*+ ! ( ! clientSize.height - popupSize.height) / 2*/, ! (int) (clientPlaceY) + clientSize.width / 2); ! ! showWindow(); ! ! } ! ! /** ! * OK_actionPerformed qui sert lorsque l'on appuie sur le bouton OK ! * @param e l'evenement ! */ ! ! public void OK_actionPerformed(ActionEvent e) { ! setVisible(false); ! } ! ! /** ! * processWindowEvent c est une methode qui est appele lorsque l'on ferme la boite de dialogue ! * @param l evenement qui indique que l'on ferme la fenetre ! */ ! ! protected void processWindowEvent(WindowEvent e) { ! super.processWindowEvent(e); ! if (e.getID() == WindowEvent.WINDOW_CLOSING) { ! OK_actionPerformed(null); ! } ! } ! ! /** ! * Methode qui affiche la boite de dialogue ! */ ! ! public void showWindow() { ! setVisible(true); ! } ! ! /** ! * Classe qui ecoute si l'on appui sur le bouton OK ! */ ! ! class ErrorPopUp_OK_ActionAdapter ! implements ActionListener { ! ErrorPopUp adaptee; ! ! ErrorPopUp_OK_ActionAdapter(ErrorPopUp adaptee) { ! this.adaptee = adaptee; ! } ! ! public void actionPerformed(ActionEvent e) { ! adaptee.OK_actionPerformed(e); ! } ! } ! } Index: MadsservClient.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/MadsservClient.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MadsservClient.java 13 Mar 2003 23:27:36 -0000 1.4 --- MadsservClient.java 14 Mar 2003 03:26:18 -0000 1.5 *************** *** 1,75 **** ! //package madsserv_planification; ! ! import javax.swing.UIManager; ! import java.awt.*; ! import java.net.*; ! ! /** ! * <p>Title: MadsservClient</p> ! * <p>Description: La Classe MadsservClient contient la classe main du client du projet, c'est lui qui le lance</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! **/ ! ! /** ! * MadsservClient c'est la classe MadsservClient ! */ ! public class MadsservClient { ! /** ! * champs de la classe MadsservClient ! */ ! private boolean packFrame = false; ! ! /** ! * MadsservClient constructeur de la calsse ! */ ! public MadsservClient() { ! ! Client frame = new Client(); ! ! //Validate frames that have preset sizes ! //Pack frames that have useful preferred size info, e.g. from their layout ! if (packFrame) { ! frame.pack(); ! } ! else { ! frame.validate(); ! } ! ! //on centre ici la fenetre ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension frameSize = frame.getSize(); ! if (frameSize.height > screenSize.height) { ! frameSize.height = screenSize.height; ! } ! if (frameSize.width > screenSize.width) { ! frameSize.width = screenSize.width; ! } ! frame.setLocation( (screenSize.width - frameSize.width) / 2, ! (screenSize.height - frameSize.height) / 2); ! frame.setVisible(true); ! } ! ! /** ! * Methode main de MadsservClient ! */ ! ! public static void main(String[] args) { ! try { ! UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! new MadsservClient(); ! } ! ! static void prUsage() { ! System.err.println("Usage: ClientRTPManager <session> <session> ..."); ! System.err.println(" <session>: <address>/<port>/<ttl>"); ! System.exit(0); ! } ! } --- 1,75 ---- ! //package madsserv_planification; ! ! import javax.swing.UIManager; ! import java.awt.*; ! import java.net.*; ! ! /** ! * <p>Title: MadsservClient</p> ! * <p>Description: La Classe MadsservClient contient la classe main du client du projet, c'est lui qui le lance</p> ! * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq ! * @version 1.0 ! **/ ! ! /** ! * MadsservClient c'est la classe MadsservClient ! */ ! public class MadsservClient { ! /** ! * champs de la classe MadsservClient ! */ ! private boolean packFrame = false; ! ! /** ! * MadsservClient constructeur de la calsse ! */ ! public MadsservClient() { ! ! Client frame = new Client(); ! ! //Validate frames that have preset sizes ! //Pack frames that have useful preferred size info, e.g. from their layout ! if (packFrame) { ! frame.pack(); ! } ! else { ! frame.validate(); ! } ! ! //on centre ici la fenetre ! Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); ! Dimension frameSize = frame.getSize(); ! if (frameSize.height > screenSize.height) { ! frameSize.height = screenSize.height; ! } ! if (frameSize.width > screenSize.width) { ! frameSize.width = screenSize.width; ! } ! frame.setLocation( (screenSize.width - frameSize.width) / 2, ! (screenSize.height - frameSize.height) / 2); ! frame.setVisible(true); ! } ! ! /** ! * Methode main de MadsservClient ! */ ! ! public static void main(String[] args) { ! try { ! UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! new MadsservClient(); ! } ! ! static void prUsage() { ! System.err.println("Usage: ClientRTPManager <session> <session> ..."); ! System.err.println(" <session>: <address>/<port>/<ttl>"); ! System.exit(0); ! } ! } Index: PlayerPanel.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/PlayerPanel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PlayerPanel.java 11 Mar 2003 20:06:53 -0000 1.3 --- PlayerPanel.java 14 Mar 2003 03:26:18 -0000 1.4 *************** *** 1,65 **** ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.AudioFormat; ! import javax.media.format.VideoFormat; ! import javax.media.Format; ! import javax.media.format.FormatChangeEvent; ! import javax.media.control.BufferControl; ! ! /** ! * Classe playerpanel qui crée l'interphace graphique des players ! */ ! public class PlayerPanel ! extends Panel { ! /** ! * champs de la classe ! */ ! private Component vc, cc; ! // champs qui est mis à true lorsque l'on doit crée l'interface du player video ! boolean video = false; ! ! PlayerPanel(Player p) { ! setLayout(new BorderLayout()); ! //on regarde si c'est un flux video qui arrive ! if ( (vc = p.getVisualComponent()) != null) { ! add("Center", vc); ! video = true; ! } ! if ( (cc = p.getControlPanelComponent()) != null) { ! add("South", cc); ! } ! } ! /** ! * getPrefferedSize methode qui retourne les dimensions du player ! * @return Dimension, celles du player ! */ ! public Dimension getPreferredSize() { ! int w = 0, h = 0; ! if (vc != null) { ! Dimension size = vc.getPreferredSize(); ! w = size.width; ! h = size.height; ! } ! if (cc != null) { ! Dimension size = cc.getPreferredSize(); ! if (w == 0) { ! w = size.width; ! } ! h += size.height; ! } ! if (w < 160) { ! w = 160; ! } ! return new Dimension(w, h); ! } ! } --- 1,66 ---- ! import java.io.*; ! import java.awt.*; ! import java.net.*; ! import java.awt.event.*; ! import java.util.Vector; ! ! import javax.media.*; ! import javax.media.rtp.*; ! import javax.media.rtp.event.*; ! import javax.media.rtp.rtcp.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.AudioFormat; ! import javax.media.format.VideoFormat; ! import javax.media.Format; ! import javax.media.format.FormatChangeEvent; ! import javax.media.control.BufferControl; ! ! /** ! * Classe playerpanel qui crée l'interphace graphique des players ! * @author : Xavier Deplancq ! */ ! public class PlayerPanel ! extends Panel { ! /** ! * champs de la classe ! */ ! private Component vc, cc; ! // champs qui est mis à true lorsque l'on doit crée l'interface du player video ! boolean video = false; ! ! PlayerPanel(Player p) { ! setLayout(new BorderLayout()); ! //on regarde si c'est un flux video qui arrive ! if ( (vc = p.getVisualComponent()) != null) { ! add("Center", vc); ! video = true; ! } ! if ( (cc = p.getControlPanelComponent()) != null) { ! add("South", cc); ! } ! } ! /** ! * getPrefferedSize methode qui retourne les dimensions du player ! * @return Dimension, celles du player ! */ ! public Dimension getPreferredSize() { ! int w = 0, h = 0; ! if (vc != null) { ! Dimension size = vc.getPreferredSize(); ! w = size.width; ! h = size.height; ! } ! if (cc != null) { ! Dimension size = cc.getPreferredSize(); ! if (w == 0) { ! w = size.width; ! } ! h += size.height; ! } ! if (w < 160) { ! w = 160; ! } ! return new Dimension(w, h); ! } ! } Index: ThreadRTPManager.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRTPManager.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ThreadRTPManager.java 13 Mar 2003 23:27:36 -0000 1.5 --- ThreadRTPManager.java 14 Mar 2003 03:26:18 -0000 1.6 *************** *** 1,50 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * ThreadRTPManager est une methode qui cree un clientRTPManager ! */ ! public class ThreadRTPManager extends Thread { ! ! /** ! * champs de la classe ClientRTPManager ! */ ! private ClientRTPManager clientRTPManager; ! private Client cl; ! ! public ThreadRTPManager(String sessionServer[], Client cl) ! { ! clientRTPManager = new ClientRTPManager(sessionServer, cl); ! } ! ! /** ! * methode run de ce thread ! */ ! public void Fermer() ! { ! clientRTPManager.close(); ! } ! ! public void run() ! { ! if (!clientRTPManager.initialize()) { ! System.err.println("Failed to initialize the sessions."); ! System.exit( -1); ! } ! ! try { ! while (!clientRTPManager.isDone()) ! Thread.sleep(1000); ! } ! catch (Exception e) { ! cl.showError("La connexion n'a pas pu etre initialise"); ! } ! ! finally { ! ! System.err.println("Exiting ThreadRTPManager"); ! System.out.println(Thread.currentThread()); ! } ! } ! } --- 1,51 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * ThreadRTPManager est une methode qui cree un clientRTPManager ! * @author : Xavier Deplancq ! */ ! public class ThreadRTPManager extends Thread { ! ! /** ! * champs de la classe ClientRTPManager ! */ ! private ClientRTPManager clientRTPManager; ! private Client cl; ! ! public ThreadRTPManager(String sessionServer[], Client cl) ! { ! clientRTPManager = new ClientRTPManager(sessionServer, cl); ! } ! ! /** ! * methode run de ce thread ! */ ! public void Fermer() ! { ! clientRTPManager.close(); ! } ! ! public void run() ! { ! if (!clientRTPManager.initialize()) { ! System.err.println("Failed to initialize the sessions."); ! System.exit( -1); ! } ! ! try { ! while (!clientRTPManager.isDone()) ! Thread.sleep(1000); ! } ! catch (Exception e) { ! cl.showError("La connexion n'a pas pu etre initialise"); ! } ! ! finally { ! ! System.err.println("Exiting ThreadRTPManager"); ! System.out.println(Thread.currentThread()); ! } ! } ! } Index: ThreadRead.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRead.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ThreadRead.java 13 Mar 2003 23:27:36 -0000 1.2 --- ThreadRead.java 14 Mar 2003 03:26:18 -0000 1.3 *************** *** 1,98 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. ! * Il effectue une ecoute permanente. ! * <p> ! * Il gere l'extraction du message en isolant les elements protocolaires de la ! * transmission du message. ! * @see ThreadWrite ! * @see DialogSocket ! * @author Julien Carbonell ! */ ! ! public class ThreadRead ! extends Thread { ! ! boolean end = false; ! ! // objet parent qui gere les entrees-sorties sur le socket ! protected DialogSocket parent; ! ! // BufferedReader sur lequel sont lus les messages ! protected BufferedReader binput; ! ! protected String temp = ""; ! protected String message = ""; ! protected boolean waitingMessage = true; ! protected int messageType = -1; ! ! /** ! * Constructeur de <code>ThreadRead</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. ! */ ! public ThreadRead(String _name, BufferedReader _binput, ! DialogSocket _parent) { ! super(_name + _parent.getClientID()); ! parent = _parent; ! binput = _binput; ! } ! ! /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. ! */ ! public void run() { ! try { ! while ( (temp = binput.readLine()) != null) { ! if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; ! } ! else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; ! } ! else { ! message = message.concat(temp + "\n"); ! } ! } ! } ! ! } ! } ! /* catch (SocketTimeoutException e) { ! System.out.println(e.getMessage()); ! }*/ ! catch (Exception e) { ! e.printStackTrace(); ! } ! finally { ! try { ! // binput.close(); ! System.out.println(getName() + Thread.currentThread() + ! " : Stopped !!! "); ! } ! catch (Exception e) { ! System.out.println(e.getMessage()); ! } ! } ! ! } ! ! protected String[] parseMessage(String _message) { ! return _message.split("\n"); ! } ! } --- 1,98 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. ! * Il effectue une ecoute permanente. ! * <p> ! * Il gere l'extraction du message en isolant les elements protocolaires de la ! * transmission du message. ! * @see ThreadWrite ! * @see DialogSocket ! * @author Julien Carbonell ! */ ! ! public class ThreadRead ! extends Thread { ! ! boolean end = false; ! ! // objet parent qui gere les entrees-sorties sur le socket ! protected DialogSocket parent; ! ! // BufferedReader sur lequel sont lus les messages ! protected BufferedReader binput; ! ! protected String temp = ""; ! protected String message = ""; ! protected boolean waitingMessage = true; ! protected int messageType = -1; ! ! /** ! * Constructeur de <code>ThreadRead</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. ! */ ! public ThreadRead(String _name, BufferedReader _binput, ! DialogSocket _parent) { ! super(_name + _parent.getClientID()); ! parent = _parent; ! binput = _binput; ! } ! ! /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. ! */ ! public void run() { ! try { ! while ( (temp = binput.readLine()) != null) { ! if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; ! } ! else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; ! } ! else { ! message = message.concat(temp + "\n"); ! } ! } ! } ! ! } ! } ! /* catch (SocketTimeoutException e) { ! System.out.println(e.getMessage()); ! }*/ ! catch (Exception e) { ! e.printStackTrace(); ! } ! finally { ! try { ! // binput.close(); ! System.out.println(getName() + Thread.currentThread() + ! " : Stopped !!! "); ! } ! catch (Exception e) { ! System.out.println(e.getMessage()); ! } ! } ! ! } ! ! protected String[] parseMessage(String _message) { ! return _message.split("\n"); ! } ! } Index: ThreadWrite.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadWrite.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ThreadWrite.java 13 Mar 2003 23:27:37 -0000 1.2 --- ThreadWrite.java 14 Mar 2003 03:26:18 -0000 1.3 ***************... [truncated message content] |
|
From: <car...@us...> - 2003-03-14 03:26:22
|
Update of /cvsroot/madsserv/madsserv/src/server/processor
In directory sc8-pr-cvs1:/tmp/cvs-serv2431/src/server/processor
Modified Files:
Reencode.java ThreadReencode.java
Log Message:
premiere version test
Index: Reencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/Reencode.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Reencode.java 14 Mar 2003 02:17:33 -0000 1.11
--- Reencode.java 14 Mar 2003 03:26:19 -0000 1.12
***************
*** 1,420 ****
! /**
! * Projet Madsserv
! * Reencode.java
! *
! * Module de conversion des fichiers multimedia.
! * Reencode un fichier multimedia dans un format choisi.
! *
! * @author Jean-Baptiste Mariotte
! */
!
! import java.awt.*;
! import java.io.File;
! import javax.media.*;
! import javax.media.Format;
! import javax.media.format.*;
! import javax.media.protocol.*;
! import javax.media.protocol.DataSource;
! import javax.media.control.*;
! import java.io.IOException;
!
! /**
! * Classe Reencode
! */
! public class Reencode implements ControllerListener {
!
! /**
! * Champs de la classe Reencode
! */
! public Streaming streamingRef; // Reference du module Streaming frere.
! public Transition transitionRef; //Reference du module Transition frere.
! public boolean multiMedia = false; // Indique si le fichier est mulimedia.
! public boolean reencoding = false; // Indique s'il y a conversion en cours.
! public ThreadReencode formerThreadReencode = null; // Precedent thread de conversion.
! public ThreadReencode currentThreadReencode = null; // Thread de conversion actuel.
!
! private String inputURL = null; // Adresse du fichier demande.
! private int clientId = -1; // Numero du client demandeur.
! private MediaLocator inputML = null; // MediaLocator du fichier a convertir.
! private DataSource inputDS = null; // DataSource contenant le fichier a convertir.
! private TrackControl[] inputTC = null; // TrackControl permettant d'acceder aux differentes pistes du media.
! private Format[] inputFormat = null; // Vecteur de Format pour stocker les formats des pistes.
! private AudioFormat originalAudioFormat = null; // Format audio original du fichier a convertir.
! private VideoFormat originalVideoFormat = null; // Format video original du fichier a convertir.
! private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage du fichier.
! private VideoFormat reencodingVideoFormat = null; // Format video de reencodage du fichier.
! private Time startTime = new Time(0); // Instant de debut de conversion.
!
!
! /**
! * Constructeur de la classe Reencode.
! * @param clientId l'ID du client associe au module
! * @param inputURL l'URL demande par le client
! */
! Reencode(int clientId, String inputURL)
! {
! // Stockage de l'ID du client correspondant a l'instantiation.
! this.clientId = clientId;
! if(this.clientId < 0)
! {
! System.err.println("L'ID du client n'a pas ete transmis correctement.");
! System.exit(0);
! }
! // Stockage de l'URL demande correspondant a l'instantiation.
! this.inputURL = inputURL;
! if(this.inputURL == null)
! {
! System.err.println("L'URL a lire n'a pas ete transmis correctement.");
! System.exit(0);
! }
! System.err.println("Module de conversion construit\n");
!
! // Conversion de l'URL en MediaLocator.
! if((inputML = createMediaLocator(inputURL)) == null)
! {
! System.err.println("Impossible de construire le MediaLocator a partir de : " + inputURL);
! System.exit(0);
! }
!
! // Determination des formats d'origine du fichier demande.
! // Pour cela, on cree un Processor que l'on place dans l'etat configure.
! // Source inspire de la classe Transcode publiee par Sun.
! // http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! Processor p = null;
!
! try
! {
! p = Manager.createProcessor(inputML);
! System.err.println("- create processor for: " + inputML);
! }
! catch (Exception e)
! {
! System.err.println("Yikes! Cannot create a processor from the given url: " + e);
! }
!
! p.addControllerListener(this);
!
! // Put the Processor into configured state.
! p.configure();
! if (!waitForState(p, p.Configured))
! {
! System.err.println("Failed to configure the processor.");
! }
!
! // A l'aide de TrackControl, on accede aux differentes pistes du media.
! try
! {
! if ( (inputTC = p.getTrackControls()) == null)
! {
! System.err.println("Il n'y a aucune piste dans le fichier !");
! }
! else
! {
! if(inputTC.length > 2)
! {
! System.err.println("Il y a trop de pistes dans le fichier !");
! }
! else
! {
! inputFormat = new Format[inputTC.length];
! if(inputTC.length == 1)
! {
! inputFormat[0] = inputTC[0].getFormat();
! System.err.println("Il n'y a qu'une seule piste");
! setOriginalAudioFormat( (AudioFormat) inputFormat[0]); //FIXME si video sans son
! }
! else // Il y a deux pistes, la video est la premiere
! {
! inputFormat[0] = inputTC[0].getFormat();
! System.err.println("Format piste n 1 : " + inputFormat[0].toString());
! setOriginalVideoFormat( (VideoFormat) inputFormat[0]);
! inputFormat[1] = inputTC[1].getFormat();
! System.err.println("Format piste n 2 : " + inputFormat[1].toString());
! setOriginalAudioFormat( (AudioFormat) inputFormat[1]);
! multiMedia = true;
! }
! }
! }
! }
! catch (NotConfiguredError e) {}
!
! p.removeControllerListener(this);
! }
!
! /**
! * Lancement de la conversion
! */
! public void start()
! {
! if(!reencoding)
! {
! if (multiMedia) { // Fichier audio et video
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat,
! reencodingVideoFormat, startTime, this);
! }
! else { // Fichier audio simple
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat, startTime, this);
! }
! currentThreadReencode.run();
! streamingRef.setNewStreams(currentThreadReencode.getOutput());
! }
! else
! {
! formerThreadReencode = currentThreadReencode;
! if (multiMedia) { // Fichier audio et video
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat,
! reencodingVideoFormat, startTime, this);
! }
! else { // Fichier audio simple
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat, startTime, this);
! }
! currentThreadReencode.run();
!
! // On attend que le Processor du nouveau thread soit started
! Processor currentProcessor = null;
! currentProcessor = currentThreadReencode.processor;
! stateTransitionOK = true;
! waitForState(currentProcessor, currentProcessor.Started);
!
! // On transmet au module Streaming l'adresse du DataSource de sortie
! streamingRef.setNewStreams(currentThreadReencode.getOutput());
! }
! }
!
! /**
! * Arret du ThreadReencode precedent
! * @return -1 si erreur
! * @return 0 si arret du precedent thread
! */
! public int stopFormerThreadReencode()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
! return -1;
! }
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
! formerThreadReencode.stopProcessing();
! formerThreadReencode = null;
! return 0;
! }
! }
!
! /**
! * Retourne l'ID du client correspondant au module instancie
! * @return l'ID du client correspondant au module instancie
! */
! public int getClientId()
! {
! return this.clientId;
! }
!
! /**
! * Retourne le format video original du fichier demande.
! * @return le format video original du fichier
! */
! public VideoFormat getOriginalVideoFormat()
! {
! return this.originalVideoFormat;
! }
!
! /**
! * Retourne le format audio original du fichier demande.
! * @return le format audio original du fichier
! */
! public AudioFormat getOriginalAudioFormat()
! {
! return this.originalAudioFormat;
! }
!
! /**
! * Definit le format video original du fichier demande.
! * @param originalVideoFormat le format video original du fichier
! */
! private void setOriginalVideoFormat(VideoFormat originalVideoFormat)
! {
! this.originalVideoFormat = originalVideoFormat;
! System.out.println("Format video original du fichier : " + this.originalVideoFormat.toString());
! }
!
! /**
! * Definit le format audio original du fichier demande.
! * @param originalAudioFormat le format audio original du fichier
! */
! private void setOriginalAudioFormat(AudioFormat originalAudioFormat)
! {
! this.originalAudioFormat = originalAudioFormat;
! System.out.println("Format audio original du fichier : " + this.originalAudioFormat.toString());
! }
!
! /**
! * Definit le format vidéo de reencodage du fichier demande.
! * @param reencodingVideoFormat le nouveau format vidéo de réencodage
! * @return 0 si mise a jour effectuee
! * @return -1 si erreur
! */
! public int setReencodingVideoFormat(VideoFormat reencodingVideoFormat)
! {
! if(reencodingVideoFormat != null)
! {
! this.reencodingVideoFormat = reencodingVideoFormat;
! System.err.println("Nouveau format video recu : " + reencodingVideoFormat.toString());
! return 0;
! }
! else
! {
! System.err.println("Pas de nouveau format video recu !");
! return -1;
! }
! }
!
! /**
! * Definit le format audio de reencodage du fichier demande.
! * @param reencodingAudioFormat le nouveau format audio de réencodage
! * @return 0 si mise a jour effectuee
! * @return -1 si erreur
! */
! public int setReencodingAudioFormat(AudioFormat reencodingAudioFormat)
! {
! if(reencodingAudioFormat != null)
! {
! this.reencodingAudioFormat = reencodingAudioFormat;
! System.err.println("Nouveau format audio recu : " + reencodingAudioFormat.toString());
! return 0;
! }
! else
! {
! System.err.println("Pas de nouveau format audio recu !");
! return -1;
! }
! }
!
! /**
! * Definit le numero de l'image du changement de conversion.
! * @param startTime l'instant du changement de conversion
! */
! public void setReencodingTime(Time startTime)
! {
! this.startTime = startTime;
! }
!
! /**
! * Definit la reference du module Streaming correspondant au clientId.
! * @param streamingRef la reference du module Streaming correspondant au meme client
! */
! public void setStreamingRef(Streaming streamingRef)
! {
! this.streamingRef = streamingRef;
! }
!
! /**
! * Definit la reference du module Transition correspondant au clientId.
! * @param transitionRef la reference du module Transition correspondant au meme client
! */
! public void setTransitionRef(Transition transitionRef)
! {
! this.transitionRef = transitionRef;
! }
!
!
! /**
! * Cree un media locator a partir de l'URL (String) demandee.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! * @param url une url de fichier multimedia
! * @return un MediaLocator
! */
! static MediaLocator createMediaLocator(String url)
! {
! MediaLocator ml;
!
! if (url.indexOf(":") > 0 && (ml = new MediaLocator(url)) != null)
! return ml;
!
! if (url.startsWith(File.separator)) {
! if ((ml = new MediaLocator("file:" + url)) != null)
! return ml;
! } else {
! String file = "file:" + System.getProperty("user.dir") + File.separator + url;
! if ((ml = new MediaLocator(file)) != null)
! return ml;
! }
!
! return null;
! }
!
! Object waitSync = new Object();
! boolean stateTransitionOK = true;
!
! /**
! * Block until the processor has transitioned to the given state.
! * Return false if the transition failed.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! * @param p un Processor
! * @param state un int representant l'etat du Processor p
! * @return un booleen qui indique que le Processor est dans le bon etat
! */
! boolean waitForState(Processor p, int state) {
! synchronized (waitSync) {
! try {
! while (p.getState() < state && stateTransitionOK)
! waitSync.wait();
! } catch (Exception e) {}
! }
! return stateTransitionOK;
! }
!
! /**
! * Controller Listener.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! */
! public void controllerUpdate(ControllerEvent evt) {
!
! if (evt instanceof ConfigureCompleteEvent ||
! evt instanceof RealizeCompleteEvent ||
! evt instanceof PrefetchCompleteEvent) {
! synchronized (waitSync) {
! stateTransitionOK = true;
! waitSync.notifyAll();
! }
! } else if (evt instanceof ResourceUnavailableEvent) {
! synchronized (waitSync) {
! stateTransitionOK = false;
! waitSync.notifyAll();
! }
! } else if (evt instanceof EndOfMediaEvent) {
! evt.getSourceController().close();
! } else if (evt instanceof MediaTimeSetEvent) {
! System.err.println("- mediaTime set: " +
! ((MediaTimeSetEvent)evt).getMediaTime().getSeconds());
! } else if (evt instanceof StopAtTimeEvent) {
! System.err.println("- stop at time: " +
! ((StopAtTimeEvent)evt).getMediaTime().getSeconds());
! evt.getSourceController().close();
! }
! }
!
! public int stop()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
! }
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
! formerThreadReencode.stopProcessing();
! formerThreadReencode = null;
! }
! currentThreadReencode.stopProcessing();
! currentThreadReencode = null;
! return 0;
! }
!
! }
--- 1,420 ----
! /**
! * Projet Madsserv
! * Reencode.java
! *
! * Module de conversion des fichiers multimedia.
! * Reencode un fichier multimedia dans un format choisi.
! *
! * @author Jean-Baptiste Mariotte
! */
!
! import java.awt.*;
! import java.io.File;
! import javax.media.*;
! import javax.media.Format;
! import javax.media.format.*;
! import javax.media.protocol.*;
! import javax.media.protocol.DataSource;
! import javax.media.control.*;
! import java.io.IOException;
!
! /**
! * Classe Reencode
! */
! public class Reencode implements ControllerListener {
!
! /**
! * Champs de la classe Reencode
! */
! public Streaming streamingRef; // Reference du module Streaming frere.
! public Transition transitionRef; //Reference du module Transition frere.
! public boolean multiMedia = false; // Indique si le fichier est mulimedia.
! public boolean reencoding = false; // Indique s'il y a conversion en cours.
! public ThreadReencode formerThreadReencode = null; // Precedent thread de conversion.
! public ThreadReencode currentThreadReencode = null; // Thread de conversion actuel.
!
! private String inputURL = null; // Adresse du fichier demande.
! private int clientId = -1; // Numero du client demandeur.
! private MediaLocator inputML = null; // MediaLocator du fichier a convertir.
! private DataSource inputDS = null; // DataSource contenant le fichier a convertir.
! private TrackControl[] inputTC = null; // TrackControl permettant d'acceder aux differentes pistes du media.
! private Format[] inputFormat = null; // Vecteur de Format pour stocker les formats des pistes.
! private AudioFormat originalAudioFormat = null; // Format audio original du fichier a convertir.
! private VideoFormat originalVideoFormat = null; // Format video original du fichier a convertir.
! private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage du fichier.
! private VideoFormat reencodingVideoFormat = null; // Format video de reencodage du fichier.
! private Time startTime = new Time(0); // Instant de debut de conversion.
!
!
! /**
! * Constructeur de la classe Reencode.
! * @param clientId l'ID du client associe au module
! * @param inputURL l'URL demande par le client
! */
! Reencode(int clientId, String inputURL)
! {
! // Stockage de l'ID du client correspondant a l'instantiation.
! this.clientId = clientId;
! if(this.clientId < 0)
! {
! System.err.println("L'ID du client n'a pas ete transmis correctement.");
! System.exit(0);
! }
! // Stockage de l'URL demande correspondant a l'instantiation.
! this.inputURL = inputURL;
! if(this.inputURL == null)
! {
! System.err.println("L'URL a lire n'a pas ete transmis correctement.");
! System.exit(0);
! }
! System.err.println("Module de conversion construit\n");
!
! // Conversion de l'URL en MediaLocator.
! if((inputML = createMediaLocator(inputURL)) == null)
! {
! System.err.println("Impossible de construire le MediaLocator a partir de : " + inputURL);
! System.exit(0);
! }
!
! // Determination des formats d'origine du fichier demande.
! // Pour cela, on cree un Processor que l'on place dans l'etat configure.
! // Source inspire de la classe Transcode publiee par Sun.
! // http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! Processor p = null;
!
! try
! {
! p = Manager.createProcessor(inputML);
! System.err.println("- create processor for: " + inputML);
! }
! catch (Exception e)
! {
! System.err.println("Yikes! Cannot create a processor from the given url: " + e);
! }
!
! p.addControllerListener(this);
!
! // Put the Processor into configured state.
! p.configure();
! if (!waitForState(p, p.Configured))
! {
! System.err.println("Failed to configure the processor.");
! }
!
! // A l'aide de TrackControl, on accede aux differentes pistes du media.
! try
! {
! if ( (inputTC = p.getTrackControls()) == null)
! {
! System.err.println("Il n'y a aucune piste dans le fichier !");
! }
! else
! {
! if(inputTC.length > 2)
! {
! System.err.println("Il y a trop de pistes dans le fichier !");
! }
! else
! {
! inputFormat = new Format[inputTC.length];
! if(inputTC.length == 1)
! {
! inputFormat[0] = inputTC[0].getFormat();
! System.err.println("Il n'y a qu'une seule piste");
! setOriginalAudioFormat( (AudioFormat) inputFormat[0]); //FIXME si video sans son
! }
! else // Il y a deux pistes, la video est la premiere
! {
! inputFormat[0] = inputTC[0].getFormat();
! System.err.println("Format piste n 1 : " + inputFormat[0].toString());
! setOriginalVideoFormat( (VideoFormat) inputFormat[0]);
! inputFormat[1] = inputTC[1].getFormat();
! System.err.println("Format piste n 2 : " + inputFormat[1].toString());
! setOriginalAudioFormat( (AudioFormat) inputFormat[1]);
! multiMedia = true;
! }
! }
! }
! }
! catch (NotConfiguredError e) {}
!
! p.removeControllerListener(this);
! }
!
! /**
! * Lancement de la conversion
! */
! public void start()
! {
! if(!reencoding)
! {
! if (multiMedia) { // Fichier audio et video
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat,
! reencodingVideoFormat, startTime, this);
! }
! else { // Fichier audio simple
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat, startTime, this);
! }
! currentThreadReencode.run();
! streamingRef.setNewStreams(currentThreadReencode.getOutput());
! }
! else
! {
! formerThreadReencode = currentThreadReencode;
! if (multiMedia) { // Fichier audio et video
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat,
! reencodingVideoFormat, startTime, this);
! }
! else { // Fichier audio simple
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat, startTime, this);
! }
! currentThreadReencode.run();
!
! // On attend que le Processor du nouveau thread soit started
! Processor currentProcessor = null;
! currentProcessor = currentThreadReencode.processor;
! stateTransitionOK = true;
! waitForState(currentProcessor, currentProcessor.Started);
!
! // On transmet au module Streaming l'adresse du DataSource de sortie
! streamingRef.setNewStreams(currentThreadReencode.getOutput());
! }
! }
!
! /**
! * Arret du ThreadReencode precedent
! * @return -1 si erreur
! * @return 0 si arret du precedent thread
! */
! public int stopFormerThreadReencode()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
! return -1;
! }
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
! formerThreadReencode.stopProcessing();
! formerThreadReencode = null;
! return 0;
! }
! }
!
! /**
! * Retourne l'ID du client correspondant au module instancie
! * @return l'ID du client correspondant au module instancie
! */
! public int getClientId()
! {
! return this.clientId;
! }
!
! /**
! * Retourne le format video original du fichier demande.
! * @return le format video original du fichier
! */
! public VideoFormat getOriginalVideoFormat()
! {
! return this.originalVideoFormat;
! }
!
! /**
! * Retourne le format audio original du fichier demande.
! * @return le format audio original du fichier
! */
! public AudioFormat getOriginalAudioFormat()
! {
! return this.originalAudioFormat;
! }
!
! /**
! * Definit le format video original du fichier demande.
! * @param originalVideoFormat le format video original du fichier
! */
! private void setOriginalVideoFormat(VideoFormat originalVideoFormat)
! {
! this.originalVideoFormat = originalVideoFormat;
! System.out.println("Format video original du fichier : " + this.originalVideoFormat.toString());
! }
!
! /**
! * Definit le format audio original du fichier demande.
! * @param originalAudioFormat le format audio original du fichier
! */
! private void setOriginalAudioFormat(AudioFormat originalAudioFormat)
! {
! this.originalAudioFormat = originalAudioFormat;
! System.out.println("Format audio original du fichier : " + this.originalAudioFormat.toString());
! }
!
! /**
! * Definit le format vidéo de reencodage du fichier demande.
! * @param reencodingVideoFormat le nouveau format vidéo de réencodage
! * @return 0 si mise a jour effectuee
! * @return -1 si erreur
! */
! public int setReencodingVideoFormat(VideoFormat reencodingVideoFormat)
! {
! if(reencodingVideoFormat != null)
! {
! this.reencodingVideoFormat = reencodingVideoFormat;
! System.err.println("Nouveau format video recu : " + reencodingVideoFormat.toString());
! return 0;
! }
! else
! {
! System.err.println("Pas de nouveau format video recu !");
! return -1;
! }
! }
!
! /**
! * Definit le format audio de reencodage du fichier demande.
! * @param reencodingAudioFormat le nouveau format audio de réencodage
! * @return 0 si mise a jour effectuee
! * @return -1 si erreur
! */
! public int setReencodingAudioFormat(AudioFormat reencodingAudioFormat)
! {
! if(reencodingAudioFormat != null)
! {
! this.reencodingAudioFormat = reencodingAudioFormat;
! System.err.println("Nouveau format audio recu : " + reencodingAudioFormat.toString());
! return 0;
! }
! else
! {
! System.err.println("Pas de nouveau format audio recu !");
! return -1;
! }
! }
!
! /**
! * Definit le numero de l'image du changement de conversion.
! * @param startTime l'instant du changement de conversion
! */
! public void setReencodingTime(Time startTime)
! {
! this.startTime = startTime;
! }
!
! /**
! * Definit la reference du module Streaming correspondant au clientId.
! * @param streamingRef la reference du module Streaming correspondant au meme client
! */
! public void setStreamingRef(Streaming streamingRef)
! {
! this.streamingRef = streamingRef;
! }
!
! /**
! * Definit la reference du module Transition correspondant au clientId.
! * @param transitionRef la reference du module Transition correspondant au meme client
! */
! public void setTransitionRef(Transition transitionRef)
! {
! this.transitionRef = transitionRef;
! }
!
!
! /**
! * Cree un media locator a partir de l'URL (String) demandee.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! * @param url une url de fichier multimedia
! * @return un MediaLocator
! */
! static MediaLocator createMediaLocator(String url)
! {
! MediaLocator ml;
!
! if (url.indexOf(":") > 0 && (ml = new MediaLocator(url)) != null)
! return ml;
!
! if (url.startsWith(File.separator)) {
! if ((ml = new MediaLocator("file:" + url)) != null)
! return ml;
! } else {
! String file = "file:" + System.getProperty("user.dir") + File.separator + url;
! if ((ml = new MediaLocator(file)) != null)
! return ml;
! }
!
! return null;
! }
!
! Object waitSync = new Object();
! boolean stateTransitionOK = true;
!
! /**
! * Block until the processor has transitioned to the given state.
! * Return false if the transition failed.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! * @param p un Processor
! * @param state un int representant l'etat du Processor p
! * @return un booleen qui indique que le Processor est dans le bon etat
! */
! boolean waitForState(Processor p, int state) {
! synchronized (waitSync) {
! try {
! while (p.getState() < state && stateTransitionOK)
! waitSync.wait();
! } catch (Exception e) {}
! }
! return stateTransitionOK;
! }
!
! /**
! * Controller Listener.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! */
! public void controllerUpdate(ControllerEvent evt) {
!
! if (evt instanceof ConfigureCompleteEvent ||
! evt instanceof RealizeCompleteEvent ||
! evt instanceof PrefetchCompleteEvent) {
! synchronized (waitSync) {
! stateTransitionOK = true;
! waitSync.notifyAll();
! }
! } else if (evt instanceof ResourceUnavailableEvent) {
! synchronized (waitSync) {
! stateTransitionOK = false;
! waitSync.notifyAll();
! }
! } else if (evt instanceof EndOfMediaEvent) {
! evt.getSourceController().close();
! } else if (evt instanceof MediaTimeSetEvent) {
! System.err.println("- mediaTime set: " +
! ((MediaTimeSetEvent)evt).getMediaTime().getSeconds());
! } else if (evt instanceof StopAtTimeEvent) {
! System.err.println("- stop at time: " +
! ((StopAtTimeEvent)evt).getMediaTime().getSeconds());
! evt.getSourceController().close();
! }
! }
!
! public int stop()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
! }
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
! formerThreadReencode.stopProcessing();
! formerThreadReencode = null;
! }
! currentThreadReencode.stopProcessing();
! currentThreadReencode = null;
! return 0;
! }
!
! }
Index: ThreadReencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/ThreadReencode.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ThreadReencode.java 14 Mar 2003 02:17:55 -0000 1.5
--- ThreadReencode.java 14 Mar 2003 03:26:19 -0000 1.6
***************
*** 1,403 ****
! /**
! * Projet Madsserv
! * ThreadReencode.java
! *
! * Thread de conversion du fichier multimedia.
! *
! * @author Jean-Baptiste Mariotte
! */
!
! import java.awt.*;
! import java.io.File;
! import java.io.IOException;
! import java.util.Vector;
! import javax.media.*;
! import javax.media.Format;
! import javax.media.format.*;
! import javax.media.protocol.*;
! import javax.media.protocol.DataSource;
! import javax.media.control.*;
! import javax.media.rtp.*;
! import javax.media.rtp.rtcp.*;
! import com.sun.media.rtp.*;
!
!
! /**
! * Classe ThreadReencode
! */
! class ThreadReencode extends Thread
! {
! /**
! * Champs de la classe ThreadReencode
! */
! public Processor processor = null; // Processor qui execute le reencodage.
! private Reencode reencodeRef = null; // Reference du module Reencode pere.
! private MediaLocator inputML = null; // MediaLocator du fichier a reencoder.
! private DataSource dataOutput; // DataSource de sortie.
! private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage.
! private VideoFormat reencodingVideoFormat = null; // Format video de reencodage.
! private Time startTime; // Instant de debut du reencodage.
! private Boolean endOfMediaSent = null; // Indique que le fichier est termine.
!
! /**
! * Constructeur du thread de reencodage pour un media sonore uniquement.
! * @param inputML MediaLocator du fichier a reencoder
! * @param reencodingAudioFormat format audio de reencodage du fichier
! * @param startTime instant de debut du reencodage
! * @param reencodeRef reference du module Reencode pere
! */
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! Time startTime, Reencode reencodeRef)
! {
! this.inputML = inputML;
! this.reencodingAudioFormat = reencodingAudioFormat;
! this.startTime = startTime;
! this.reencodeRef = reencodeRef;
! endOfMediaSent = Boolean.valueOf(false);
! }
!
! /**
! * Constructeur du thread de reencodage pour un media audio et video.
! * @param inputML MediaLocator du fichier a reencoder
! * @param reencodingAudioFormat format audio de reencodage du fichier
! * @param reencodingVideoFormat format video de reencodage du fichier
! * @param startTime instant de debut du reencodage
! * @param reencodeRef reference du module Reencode pere
! */
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! VideoFormat reencodingVideoFormat, Time startTime,
! Reencode reencodeRef)
! {
! this.inputML = inputML;
! this.reencodingAudioFormat = reencodingAudioFormat;
! this.reencodingVideoFormat = reencodingVideoFormat;
! this.startTime = startTime;
! this.reencodeRef = reencodeRef;
! endOfMediaSent = Boolean.valueOf(false);
! }
!
! /**
! * Methode run lancant le thread de conversion.
! * Pour cela, on cree un Processor que l'on place dans l'etat configure.
! * Source inspire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! */
! public void run()
! {
! String resultat;
!
! resultat = this.startProcessing();
! reencodeRef.reencoding = true;
! System.err.println("Resultat : " + resultat);
! }
!
! /**
! * Source inspire de la classe AVTransmit2 publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/AVTransmit.html
! */
! public DataSource getOutput() {
! return dataOutput;
! }
!
! private String createProcessor() {
! if (inputML == null)
! return "Locator is null";
!
! DataSource ds;
! DataSource clone;
!
! try {
! ds = javax.media.Manager.createDataSource(inputML);
! } catch (Exception e) {
! return "Couldn't create DataSource";
! }
!
! // Try to create a processor to handle the input media locator
! try {
! processor = javax.media.Manager.createProcessor(ds);
! } catch (NoProcessorException npe) {
! return "Couldn't create processor";
! } catch (IOException ioe) {
! return "IOException creating processor";
! }
!
! // Wait for it to configure
! boolean result = waitForState(processor, Processor.Configured);
! if (result == false)
! return "Couldn't configure processor";
!
! // Get the tracks from the processor
! TrackControl [] tracks = processor.getTrackControls();
!
! // Do we have atleast one track?
! if (tracks == null || tracks.length < 1)
! return "Couldn't find tracks in processor";
!
! // Set the output content descriptor to RAW_RTP
! // This will limit the supported formats reported from
! // Track.getSupportedFormats to only valid RTP formats.
! ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
! processor.setContentDescriptor(cd);
!
! Format supported[];
! Format chosen;
! Format finalchosen;
! boolean atLeastOneTrack = false;
!
! // Program the tracks.
! for (int i = 0; i < tracks.length; i++) {
! Format format = tracks[i].getFormat();
! if (tracks[i].isEnabled()) {
! System.out.println("Track " + i + " is enabled");
! supported = tracks[i].getSupportedFormats();
!
! // We've set the output content to the RAW_RTP.
! // So all the supported formats should work with RTP.
! // We'll just pick the first one.
!
! if (supported.length > 0) {
! for(int j=0;j<supported.length;j++)
! System.out.println("Format supporte n" + j + " : " + supported[j].toString());
! if (supported[0] instanceof VideoFormat) {
! // For video formats, we should double check the
! // sizes since not all formats work in all sizes.
! chosen = checkForVideoSizes(tracks[i].getFormat(),
! supported[0]);
! } else {
! chosen = supported[0];
! }
! tracks[i].setFormat(chosen);
! System.err.println("Track " + i + " is set to transmit as:");
! System.err.println(" " + chosen);
! atLeastOneTrack = true;
! } else
! tracks[i].setEnabled(false);
! } else {
! tracks[i].setEnabled(false);
! System.out.println("Track " + i + " isn't enabled");
! }
! }
!
! if (!atLeastOneTrack)
! return "Couldn't set any of the tracks to a valid RTP format";
!
! // Realize the processor. This will internally create a flow
! // graph and attempt to create an output datasource for JPEG/RTP
! // audio frames.
! result = waitForState(processor, Controller.Realized);
! if (result == false)
! return "Couldn't realize processor";
!
! // Set the JPEG quality to .5.
! setJPEGQuality(processor, 0.5f);
!
! // Commencer a encoder a partir de l'instant voulu
! if (startTime.getSeconds() > 0)
! {
! processor.setMediaTime(startTime);
! }
!
! // Get the output data source of the processor
! dataOutput = processor.getDataOutput();
!
! return null;
! }
!
! /**
! * Lance le Processor charge de la conversion
! * @return le message de creation du Processor
! */
! public synchronized String startProcessing() {
! String result;
!
! // Create a processor for the specified media locator
! // and program it to output JPEG/RTP
! result = createProcessor();
! if (result != null)
! return result;
!
! // Start the transmission
! processor.start();
!
! return null;
! }
!
! /**
! * Arrete le Processor en cours
! */
! public void stopProcessing() {
! synchronized (this) {
! if (processor != null) {
! processor.stop();
! processor.close();
! processor = null;
! }
! }
! }
!
! /**
! * For JPEG and H263, we know that they only work for particular
! * sizes. So we'll perform extra checking here to make sure they
! * are of the right sizes.
! */
! Format checkForVideoSizes(Format original, Format supported) {
!
! int width, height;
! Dimension size = ((VideoFormat)original).getSize();
! Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
! Format h263Fmt = new Format(VideoFormat.H263_RTP);
!
! if (supported.matches(jpegFmt)) {
! // For JPEG, make sure width and height are divisible by 8.
! width = (size.width % 8 == 0 ? size.width :
! (int)(size.width / 8) * 8);
! height = (size.height % 8 == 0 ? size.height :
! (int)(size.height / 8) * 8);
! } else if (supported.matches(h263Fmt)) {
! // For H.263, we only support some specific sizes.
! if (size.width < 128) {
! width = 128;
! height = 96;
! } else if (size.width < 176) {
! width = 176;
! height = 144;
! } else {
! width = 352;
! height = 288;
! }
! } else {
! // We don't know this particular format. We'll just
! // leave it alone then.
! return supported;
! }
!
! return (new VideoFormat(null,
! new Dimension(width, height),
! Format.NOT_SPECIFIED,
! null,
! Format.NOT_SPECIFIED)).intersects(supported);
! }
!
!
! /**
! * Setting the encoding quality to the specified value on the JPEG encoder.
! * 0.5 is a good default.
! */
! void setJPEGQuality(Player p, float val) {
!
! Control cs[] = p.getControls();
! QualityControl qc = null;
! VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);
!
! // Loop through the controls to find the Quality control for
! // the JPEG encoder.
! for (int i = 0; i < cs.length; i++) {
!
! if (cs[i] instanceof QualityControl &&
! cs[i] instanceof Owned) {
! Object owner = ((Owned)cs[i]).getOwner();
!
! // Check to see if the owner is a Codec.
! // Then check for the output format.
! if (owner instanceof Codec) {
! Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);
! for (int j = 0; j < fmts.length; j++) {
! if (fmts[j].matches(jpegFmt)) {
! qc = (QualityControl)cs[i];
! qc.setQuality(val);
! System.err.println("- Setting quality to " +
! val + " on " + qc);
! break;
! }
! }
! }
! if (qc != null)
! break;
! }
! }
! }
!
!
! /****************************************************************
! * Convenience methods to handle processor's state changes.
! ****************************************************************/
!
! private Integer stateLock = new Integer(0);
! private boolean failed = false;
!
! Integer getStateLock() {
! return stateLock;
! }
!
! void setFailed() {
! failed = true;
! }
!
! private synchronized boolean waitForState(Processor p, int state) {
! p.addControllerListener(new StateListener());
! failed = false;
!
! // Call the required method on the processor
! if (state == Processor.Configured) {
! p.configure();
! } else if (state == Processor.Realized) {
! System.out.println("On va realiser le processor");
! p.realize();
! System.out.println("Le processor est realized");
! }
!
! // Wait until we get an event that confirms the
! // success of the method, or a failure event.
! // See StateListener inner class
! while (p.getState() < state && !failed) {
! synchronized (getStateLock()) {
! try {
! getStateLock().wait();
! } catch (InterruptedException ie) {
! return false;
! }
! }
! }
!
! if (failed)
! return false;
! else
! return true;
! }
!
! /****************************************************************
! * Inner Classes
! ****************************************************************/
!
! class StateListener implements ControllerListener {
!
! public void controllerUpdate(ControllerEvent ce) {
!
! // If there was an error during configure or
! // realize, the processor will be closed
! if (ce instanceof ControllerClosedEvent)
! setFailed();
!
! // All controller events, send a notification
! // to the waiting thread in waitForState method.
! if (ce instanceof ControllerEvent) {
! synchronized (getStateLock()) {
! getStateLock().notifyAll();
! }
! }
! if (ce instanceof DataStarvedEvent || ce instanceof EndOfMediaEvent) {
! System.out.println("J'ai un evenement DataStarved");
! synchronized (endOfMediaSent) {
! System.out.println("Evenement DataStarved traite");
! if (!endOfMediaSent.booleanValue())
! endOfMediaSent = Boolean.valueOf(true);
! try {
! Thread.sleep(4000);
! reencodeRef.streamingRef.endOfMedia();
! }
! catch (Exception e) {}
! }
! }
! }
! }
}
--- 1,403 ----
! /**
! * Projet Madsserv
! * ThreadReencode.java
! *
! * Thread de conversion du fichier multimedia.
! *
! * @author Jean-Baptiste Mariotte
! */
!
! import java.awt.*;
! import java.io.File;
! import java.io.IOException;
! import java.util.Vector;
! import javax.media.*;
! import javax.media.Format;
! import javax.media.format.*;
! import javax.media.protocol.*;
! import javax.media.protocol.DataSource;
! import javax.media.control.*;
! import javax.media.rtp.*;
! import javax.media.rtp.rtcp.*;
! import com.sun.media.rtp.*;
!
!
! /**
! * Classe ThreadReencode
! */
! class ThreadReencode extends Thread
! {
! /**
! * Champs de la classe ThreadReencode
! */
! public Processor processor = null; // Processor qui execute le reencodage.
! private Reencode reencodeRef = null; // Reference du module Reencode pere.
! private MediaLocator inputML = null; // MediaLocator du fichier a reencoder.
! private DataSource dataOutput; // DataSource de sortie.
! private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage.
! private VideoFormat reencodingVideoFormat = null; // Format video de reencodage.
! private Time startTime; // Instant de debut du reencodage.
! private Boolean endOfMediaSent = null; // Indique que le fichier est termine.
!
! /**
! * Constructeur du thread de reencodage pour un media sonore uniquement.
! * @param inputML MediaLocator du fichier a reencoder
! * @param reencodingAudioFormat format audio de reencodage du fichier
! * @param startTime instant de debut du reencodage
! * @param reencodeRef reference du module Reencode pere
! */
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! Time startTime, Reencode reencodeRef)
! {
! this.inputML = inputML;
! this.reencodingAudioFormat = reencodingAudioFormat;
! this.startTime = startTime;
! this.reencodeRef = reencodeRef;
! endOfMediaSent = Boolean.valueOf(false);
! }
!
! /**
! * Constructeur du thread de reencodage pour un media audio et video.
! * @param inputML MediaLocator du fichier a reencoder
! * @param reencodingAudioFormat format audio de reencodage du fichier
! * @param reencodingVideoFormat format video de reencodage du fichier
! * @param startTime instant de debut du reencodage
! * @param reencodeRef reference du module Reencode pere
! */
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! VideoFormat reencodingVideoFormat, Time startTime,
! Reencode reencodeRef)
! {
! this.inputML = inputML;
! this.reencodingAudioFormat = reencodingAudioFormat;
! this.reencodingVideoFormat = reencodingVideoFormat;
! this.startTime = startTime;
! this.reencodeRef = reencodeRef;
! endOfMediaSent = Boolean.valueOf(false);
! }
!
! /**
! * Methode run lancant le thread de conversion.
! * Pour cela, on cree un Processor que l'on place dans l'etat configure.
! * Source inspire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! */
! public void run()
! {
! String resultat;
!
! resultat = this.startProcessing();
! reencodeRef.reencoding = true;
! System.err.println("Resultat : " + resultat);
! }
!
! /**
! * Source inspire de la classe AVTransmit2 publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/AVTransmit.html
! */
! public DataSource getOutput() {
! return dataOutput;
! }
!
! private String createProcessor() {
! if (inputML == null)
! return "Locator is null";
!
! DataSource ds;
! DataSource clone;
!
! try {
! ds = javax.media.Manager.createDataSource(inputML);
! } catch (Exception e) {
! return "Couldn't create DataSource";
! }
!
! // Try to create a processor to handle the input media locator
! try {
! processor = javax.media.Manager.createProcessor(ds);
! } catch (NoProcessorException npe) {
! return "Couldn't create processor";
! } catch (IOException ioe) {
! return "IOException creating processor";
! }
!
! // Wait for it to configure
! boolean result = waitForState(processor, Processor.Configured);
! if (result == false)
! return "Couldn't configure processor";
!
! // Get the tracks from the processor
! TrackControl [] tracks = processor.getTrackControls();
!
! // Do we have atleast one track?
! if (tracks == null || tracks.length < 1)
! return "Couldn't find tracks in processor";
!
! // Set the output content descriptor to RAW_RTP
! // This will limit the supported formats reported from
! // Track.getSupportedFormats to only valid RTP formats.
! ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
! processor.setContentDescriptor(cd);
!
! Format supported[];
! Format chosen;
! Format finalchosen;
! boolean atLeastOneTrack = false;
!
! // Program the tracks.
! for (int i = 0; i < tracks.length; i++) {
! Format format = tracks[i].getFormat();
! if (tracks[i].isEnabled()) {
! System.out.println("Track " + i + " is enabled");
! supported = tracks[i].getSupportedFormats();
!
! // We've set the output content to the RAW_RTP.
! // So all the supported formats should work with RTP.
! // We'll just pick the first one.
!
! if (supported.length > 0) {
! for(int j=0;j<supported.length;j++)
! System.out.println("Format supporte n" + j + " : " + supported[j].toString());
! if (supported[0] instanceof VideoFormat) {
! // For video formats, we should double check the
! // sizes since not all formats work in all sizes.
! chosen = checkForVideoSizes(tracks[i].getFormat(),
! supported[0]);
! } else {
! chosen = supported[0];
! }
! tracks[i].setFormat(chosen);
! System.err.println("Track " + i + " is set to transmit as:");
! System.err.println(" " + chosen);
! atLeastOneTrack = true;
! } else
! tracks[i].setEnabled(false);
! } else {
! tracks[i].setEnabled(false);
! System.out.println("Track " + i + " isn't enabled");
! }
! }
!
! if (!atLeastOneTrack)
! return "Couldn't set any of the tracks to a valid RTP format";
!
! // Realize the processor. This will internally create a flow
! // graph and attempt to create an output datasource for JPEG/RTP
! // audio frames.
! result = waitForState(processor, Controller.Realized);
! if (result == false)
! return "Couldn't realize processor";
!
! // Set the JPEG quality to .5.
! setJPEGQuality(processor, 0.5f);
!
! // Commencer a encoder a partir de l'instant voulu
! if (startTime.getSeconds() > 0)
! {
! processor.setMediaTime(startTime);
! }
!
! // Get the output data source of the processor
! dataOutput = processor.getDataOutput();
!
! return null;
! }
!
! /**
! * Lance le Processor charge de la conversion
! * @return le message de creation du Processor
! */
! public synchronized String startProcessing() {
! String result;
!
! // Create a processor for the specified media locator
! // and program it to output JPEG/RTP
! result = createProcessor();
! if (result != null)
! return result;
!
! // Start the transmission
! processor.start();
!
! return null;
! }
!
! /**
! * Arrete le Processor en cours
! */
! public void stopProcessing() {
! synchronized (this) {
! if (processor != null) {
! processor.stop();
! processor.close();
! processor = null;
! }
! }
! }
!
! /**
! * For JPEG and H263, we know that they only work for particular
! * sizes. So we'll perform extra checking here to make sure they
! * are of the right sizes.
! */
! Format checkForVideoSizes(Format original, Format supported) {
!
! int width, height;
! Dimension size = ((VideoFormat)original).getSize();
! Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
! Format h263Fmt = new Format(VideoFormat.H263_RTP);
!
! if (supported.matches(jpegFmt)) {
! // For JPEG, make sure width and height are divisible by 8.
! width = (size.width % 8 == 0 ? size.width :
! (int)(size.width / 8) * 8);
! height = (size.height % 8 == 0 ? size.height :
! (int)(size.height / 8) * 8);
! } else if (supported.matches(h263Fmt)) {
! // For H.263, we only support some specific sizes.
! if (size.width < 128) {
! width = 128;
! height = 96;
! } else if (size.width < 176) {
! width = 176;
! height = 144;
! } else {
! width = 352;
! height = 288;
! }
! } else {
! // We don't know this particular format. We'll just
! // leave it alone then.
! return supported;
! }
!
! return (new VideoFormat(null,
! new Dimension(width, height),
! Format.NOT_SPECIFIED,
! null,
! Format.NOT_SPECIFIED)).intersects(supported);
! }
!
!
! /**
! * Setting the encoding quality to the specified value on the JPEG encoder.
! * 0.5 is a good default.
! */
! void setJPEGQuality(Player p, float val) {
!
! Control cs[] = p.getControls();
! QualityControl qc = null;
! VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);
!
! // Loop through the controls to find the Quality control for
! // the JPEG encoder.
! for (int i = 0; i < cs.length; i++) {
!
! if (cs[i] instanceof QualityControl &&
! cs[i] instanceof Owned) {
! Object owner = ((Owned)cs[i]).getOwner();
!
! // Check to see if the owner is a Codec.
! // Then check for the output format.
! if (owner instanceof Codec) {
! Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);
! for (int j = 0; j < fmts.length; j++) {
! if (fmts[j].matches(jpegFmt)) {
! qc = (QualityControl)cs[i];
! qc.setQuality(val);
! System.err.println("- Setting quality to " +
! val + " on " + qc);
! break;
! }
! }
! }
! if (qc != null)
! break;
! }
! }
! }
!
!
! /****************************************************************
! * Convenience methods to handle processor's state changes.
! ****************************************************************/
!
! private Integer stateLock = new Integer(0);
! private boolean failed = false;
!
! Integer getStateLock() {
! return stateLock;
! }
!
! void setFailed() {
! failed = true;
! }
!
! private synchronized boolean waitForState(Processor p, int state) {
! p.addControllerListener(new StateListener());
! failed = false;
!
! // Call the required method on the processor
! if (state == Processor.Configured) {
! p.configure();
! } else if (state == Processor.Realized) {
! System.out.println("On va realiser le processor");
! p.realize();
! System.out.println("Le processor est realized");
! }
!
! // Wait until we get an event that confirms the
! // success of the method, or a failure event.
! // See StateListener inner class
! while (p.getState() < state && !failed) {
! synchronized (getStateLock()) {
! try {
! getStateLock().wait();
! } catch (InterruptedException ie) {
! return false;
! }
! }
! }
!
! if (failed)
! return false;
! else
! return true;
! }
!
! /****************************************************************
! * Inner Classes
! ****************************************************************/
!
! class StateListener implements ControllerListener {
!
! public void controllerUpdate(ControllerEvent ce) {
!
! // If there was an error during configure or
! // realize, the processor will be closed
! if (ce instanceof ControllerClosedEvent)
! setFailed();
!
! // All controller events, send a notification
! // to the waiting thread in waitForState method.
! if (ce instanceof ControllerEvent) {
! synchronized (getStateLock()) {
! getStateLock().notifyAll();
! }
! }
! if (ce instanceof DataStarvedEvent || ce instanceof EndOfMediaEvent) {
! System.out.println("J'ai un evenement DataStarved");
! synchronized (endOfMediaSent) {
! System.out.println("Evenement DataStarved traite");
! if (!endOfMediaSent.booleanValue())
! endOfMediaSent = Boolean.valueOf(true);
! try {
! Thread.sleep(4000);
! reencodeRef.streamingRef.endOfMedia();
! }
! catch (Exception e) {}
! }
! }
! }
! }
}
|
|
From: <car...@us...> - 2003-03-14 03:26:22
|
Update of /cvsroot/madsserv/madsserv/src/server/streaming In directory sc8-pr-cvs1:/tmp/cvs-serv2431/src/server/streaming Modified Files: Streaming.java Log Message: premiere version test Index: Streaming.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/streaming/Streaming.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Streaming.java 25 Feb 2003 00:56:34 -0000 1.1 --- Streaming.java 14 Mar 2003 03:26:19 -0000 1.2 *************** *** 1,138 **** ! // La classe Streaming met en place le module Streaming RTP du projet Madsserv ! // Elle reçoit en entrée une DataSource à diffuser vers une adresse client ! // Elle utilise les RTPManager de JMF pour la diffusion ! ! ! import java.awt.*; ! import java.io.*; ! import java.util.Vector; ! import java.net.InetAddress; ! import javax.media.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.*; ! import javax.media.control.TrackControl; ! import javax.media.control.QualityControl; ! import javax.media.rtp.*; ! import javax.media.rtp.rtcp.*; ! import com.sun.media.rtp.*; ! ! public class Streaming { ! ! // Adresse IP et port du client ! private String clientIpAddress; ! private int clientPort; ! ! // Variables de controle ! private int nbManager = 2; ! private boolean alreadyStarted = false; ! ! // Tableau des RTPManager ! private RTPManager rtpMgrs[]; ! // Tableau des vectors contenant chacun les SendStream d'un RTPManager ! private Vector [] sendStreamVectors = new Vector[nbManager]; ! // La DataSource en entrée du module de streaming RTP ! private DataSource dataInput = null; ! ! // Constructeur unique avec l'adresse IP et le port du client ! public Streaming(String _clientIpAddress,String _clientPort) { ! ! clientIpAddress = _clientIpAddress; ! Integer integer = Integer.valueOf(_clientPort); ! if (integer != null) ! clientPort = integer.intValue(); ! ! rtpMgrs = new RTPManager[nbManager]; ! SessionAddress localAddr, destAddr; ! InetAddress ipAddr; ! int port; ! ! // Initialisation des vectors de SendStreams ! for (int i = 0; i< nbManager; i++) { ! sendStreamVectors[i] = new Vector(); ! } ! ! // Creation des RTPManager (on passe les adresses locale et destination) ! for (int i = 0; i < nbManager; i++) { ! try { ! rtpMgrs[i] = RTPManager.newInstance(); ! ! port = clientPort + 2*i; ! ipAddr = InetAddress.getByName(clientIpAddress); ! ! localAddr = new SessionAddress( InetAddress.getLocalHost(), ! port); ! ! destAddr = new SessionAddress( ipAddr, port); ! ! rtpMgrs[i].initialize(localAddr); ! ! rtpMgrs[i].addTarget(destAddr); ! ! System.err.println( "Created RTP session: " + clientIpAddress + " " + port); ! } catch (Exception e) { ! System.err.println(e.getMessage()); ! } ! } ! } ! ! // Méthode publique pour modifier la DataSource en cours de diffusion ! public synchronized void setNewStreams(DataSource _dataInput) { ! ! int nbStreams, vectSize; ! ! SendStream sendStream; ! ! PushBufferDataSource ds = null; ! PushBufferStream ss[]; ! ! // Annuler la diffusion des SendStreams en cours (alreadyStarted permet de savoir si une diffusion est deja commencee) ! if (alreadyStarted) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream " + i + " : " + vectSize); ! if (vectSize > 0) { ! for(int j = 0; j < vectSize; j++) { ! ((SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream "+ i + "," + j); ! } ! } ! } ! } ! ! // Mise à jour de la DataSource à diffuser ! dataInput = _dataInput; ! ! // Identification des Streams contenus dans la DataSource ! ds = (PushBufferDataSource)dataInput; ! if (ds == null) System.err.println("source vide"); ! ss = ds.getStreams(); ! System.err.println("Nombre de streams " + ss.length); ! ! // Lancer la diffusion des nouveaux Streams ! for (int i = 0; i < ss.length; i++) { ! try { ! sendStream = rtpMgrs[i].createSendStream(dataInput, i); ! sendStreamVectors[i].add(sendStream); ! sendStream.start(); ! alreadyStarted = true; ! } catch (Exception e) { ! System.err.println("message erreur sendstreams " + e.getMessage()); ! } ! } ! } ! ! // Méthode permettant de stopper la diffusion et de détruire la seesion RTP ! public void stop() { ! synchronized (this) { ! for (int i = 0; i < rtpMgrs.length; i++) { ! rtpMgrs[i].removeTargets( "Session ended."); ! rtpMgrs[i].dispose(); ! } ! //endConnexion(); ! } ! } ! ! ! } --- 1,248 ---- ! // La classe Streaming met en place le module Streaming RTP du projet Madsserv ! // Elle reçoit en entrée une DataSource à diffuser vers une adresse client ! // Elle utilise les RTPManager de JMF pour la diffusion ! ! import java.awt.*; ! import java.io.*; ! import java.util.Vector; ! import java.net.InetAddress; ! import javax.media.*; ! import javax.media.protocol.*; ! import javax.media.protocol.DataSource; ! import javax.media.format.*; ! import javax.media.control.TrackControl; ! import javax.media.control.QualityControl; ! import javax.media.rtp.*; ! import javax.media.rtp.rtcp.*; ! import com.sun.media.rtp.*; ! import javax.media.rtp.event.*; ! ! public class Streaming ! implements SendStreamListener { ! ! // Adresse IP et port du client ! private String clientIPAddress; ! private int clientPort; ! private int clientID; ! ! private ServerInit serverInit; ! ! // Variables de controle ! private int nbManager = 2; ! private Boolean alreadyStarted = null; ! ! // Tableau des RTPManager ! private RTPManager rtpMgrs[]; ! // Tableau des vectors contenant chacun les SendStream d'un RTPManager ! private Vector[] sendStreamVectors = new Vector[nbManager]; ! // La DataSource en entrée du module de streaming RTP ! private DataSource dataInput = null; ! ! private Reencode reencode=null; ! private Transition transition=null; ! ! // Constructeur sans arguments ! public Streaming(int _clientID, ServerInit _serverInit) { ! serverInit = _serverInit; ! clientID = _clientID; ! clientIPAddress = ""; ! clientPort = 40000; ! alreadyStarted = Boolean.valueOf(false); ! } ! ! // Constructeur avec l'adresse IP et le port du client ! public Streaming(int _clientID, String _clientIPAddress, String _clientPort, ! ServerInit _serverInit) { ! serverInit = _serverInit; ! clientID = _clientID; ! clientIPAddress = _clientIPAddress; ! Integer integer = Integer.valueOf(_clientPort); ! if (integer != null) { ! clientPort = integer.intValue(); ! } ! } ! ! public void setReencode(Reencode _reencode) { ! reencode = _reencode; ! } ! ! public void setTransition(Transition _transition) { ! transition = _transition; ! } ! ! public void initialize() { ! rtpMgrs = new RTPManager[nbManager]; ! SessionAddress localAddr, destAddr; ! InetAddress ipAddr; ! int port; ! String cname = SourceDescription.generateCNAME(); ! SourceDescription sourceDesc; ! ! // Initialisation des vectors de SendStreams ! for (int i = 0; i < nbManager; i++) { ! sendStreamVectors[i] = new Vector(); ! } ! ! // Creation des RTPManager (on passe les adresses locale et destination) ! for (int i = 0; i < nbManager; i++) { ! try { ! rtpMgrs[i] = RTPManager.newInstance(); ! rtpMgrs[i].addSendStreamListener(this); ! ! port = clientPort + 2 * i; ! ipAddr = InetAddress.getByName(clientIPAddress); ! localAddr = new SessionAddress(InetAddress.getLocalHost(), ! port); ! destAddr = new SessionAddress(ipAddr, port); ! sourceDesc = new SourceDescription(SourceDescription ! .SOURCE_DESC_CNAME, ! cname, ! 1, ! false); ! rtpMgrs[i].initialize(localAddr /*, sourceDesc, 0.05, 0.25*/); ! rtpMgrs[i].addTarget(destAddr); ! System.err.println("Created RTP session: " + clientIPAddress + " " + ! port); ! } ! catch (Exception e) { ! System.err.println(e.getMessage()); ! } ! } ! } ! ! // Méthode publique pour modifier la DataSource en cours de diffusion ! public synchronized void setNewStreams(DataSource _dataInput) { ! ! SendStream sendStream; ! ! PushBufferDataSource ds = null; ! PushBufferStream ss[]; ! ! int nbStreams, vectSize; ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream " + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! } ! ! // Mise à jour de la DataSource à diffuser ! dataInput = _dataInput; ! ! // Identification des Streams contenus dans la DataSource ! ds = (PushBufferDataSource) dataInput; ! if (ds == null) { ! System.err.println("source vide"); ! } ! ss = ds.getStreams(); ! System.err.println("Nombre de streams " + ss.length); ! ! // Lancer la diffusion des nouveaux Streams ! for (int i = 0; i < ss.length; i++) { ! try { ! sendStream = rtpMgrs[i].createSendStream(dataInput, i); ! sendStreamVectors[i].add(sendStream); ! sendStream.start(); ! alreadyStarted = Boolean.valueOf(true); ! } ! catch (Exception e) { ! System.err.println("message erreur sendstreams " + e.getMessage()); ! } ! } ! } ! ! public void setClientIP(String _clientIPAddress) { ! clientIPAddress = _clientIPAddress; ! } ! ! public void setClientPort(int _clientPort) { ! clientPort = _clientPort; ! } ! ! public boolean isInitialized() { ! return alreadyStarted.booleanValue(); ! } ! ! public void endOfMedia() { ! int nbStreams, vectSize; ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream n°" + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! serverInit.endConnexion(clientID); ! //stop(); ! System.err.println("Je fais un stop sur streaming"); ! synchronized (alreadyStarted) { ! alreadyStarted = Boolean.valueOf(false); ! } ! } ! ! } ! ! // Méthode permettant de stopper la diffusion et de détruire la seesion RTP ! public void stop() { ! synchronized (this) { ! for (int i = 0; i < rtpMgrs.length; i++) { ! rtpMgrs[i].removeTargets("Session ended."); ! rtpMgrs[i].dispose(); ! rtpMgrs[i] = null; ! } ! System.err.println("J'ai supprime les rtpmanager"); ! } ! } ! ! /** ! * SendStreamListener ! */ ! public synchronized void update(SendStreamEvent evt) { ! ! int nbStreams, vectSize; ! //System.out.println("Evenement SendStream : " + evt.toString()); ! /* RTPManager mgr = (RTPManager)evt.getSource(); ! Participant participant = evt.getParticipant(); // could be null. ! ReceiveStream stream = evt.getReceiveStream(); // could be null. ! */ ! if (evt instanceof InactiveSendStreamEvent) { ! System.out.println("J'ai un evenement Inactive"); ! ! // Annuler la diffusion des SendStreams en cours (alreadyStarted permet de savoir si une diffusion est deja commencee ! if (alreadyStarted.booleanValue()) { ! for (int i = 0; i < nbManager; i++) { ! vectSize = sendStreamVectors[i].size(); ! System.err.println("Taille du vecteur sendStream " + i + " : " + ! vectSize); ! if (vectSize > 0) { ! for (int j = 0; j < vectSize; j++) { ! ( (SendStream) sendStreamVectors[i].get(j)).close(); ! sendStreamVectors[i].remove(j); ! System.err.println("suppression du sendstream " + i + "," + j); ! } ! } ! } ! } ! ! /* System.err.println(" - Received an RTP PayloadChangeEvent."); ! System.err.println("Sorry, cannot handle payload change."); ! System.exit(0);*/ ! ! } ! } ! ! } |
|
From: <car...@us...> - 2003-03-14 03:26:22
|
Update of /cvsroot/madsserv/madsserv/src/server
In directory sc8-pr-cvs1:/tmp/cvs-serv2431/src/server
Modified Files:
DialogClient.java ServerInit.java
Log Message:
premiere version test
Index: DialogClient.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/DialogClient.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** DialogClient.java 13 Mar 2003 02:38:49 -0000 1.4
--- DialogClient.java 14 Mar 2003 03:26:18 -0000 1.5
***************
*** 70,74 ****
System.out.println("Nouvelle URL pour le client " + clientID + ": " +
_message[1]);
!
serverInit.setPreferredFormat(clientID, _message[2]);
System.out.println("Nouveau format prefere pour le client " +
--- 70,74 ----
System.out.println("Nouvelle URL pour le client " + clientID + ": " +
_message[1]);
! serverInit.createReencode(clientID, _message[1]);
serverInit.setPreferredFormat(clientID, _message[2]);
System.out.println("Nouveau format prefere pour le client " +
Index: ServerInit.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/ServerInit.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ServerInit.java 13 Mar 2003 02:38:49 -0000 1.5
--- ServerInit.java 14 Mar 2003 03:26:18 -0000 1.6
***************
*** 29,33 ****
public class ServerInit {
! ProcessorTest processor;
// tabClients enregistre l'ensemble des clients connectes
--- 29,33 ----
public class ServerInit {
! // ProcessorTest processor;
// tabClients enregistre l'ensemble des clients connectes
***************
*** 251,255 ****
}
if (inserted) {
! tabClients[i - 1].setPortRTP(portBaseRTP + 2 * (i - 1));
tabStreaming[i - 1] = new Streaming(i - 1, this);
return (i - 1);
--- 251,255 ----
}
if (inserted) {
! tabClients[i - 1].setPortRTP(portBaseRTP + 4 * (i - 1));
tabStreaming[i - 1] = new Streaming(i - 1, this);
return (i - 1);
***************
*** 267,271 ****
* est deja atteint (creation d'un nouveau client impossible).
*/
! public synchronized int createClient(String _IP, int _portBaseRTP,
String _mediaAddress,
String _preferredFormat,
--- 267,271 ----
* est deja atteint (creation d'un nouveau client impossible).
*/
! /* public synchronized int createClient(String _IP, int _portBaseRTP,
String _mediaAddress,
String _preferredFormat,
***************
*** 287,291 ****
return ( -1);
}
! }
/**
--- 287,291 ----
return ( -1);
}
! }*/
/**
***************
*** 308,311 ****
--- 308,320 ----
}
+ public void createReencode(int _clientID, String _URL) {
+ if (tabReencode[_clientID] != null) {
+ tabReencode[_clientID].stop();
+ tabReencode[_clientID] = null;
+ }
+ tabReencode[_clientID] = new Reencode(_clientID, _URL);
+ //tabReencode[_clientID].start();
+ }
+
/**
* Demarre la diffusion du media demande pour un client donne.
***************
*** 324,336 ****
}
System.out.println("Le streaming est initialise");
! processor = new ProcessorTest(new MediaLocator(getMediaAddress(_clientID)),
! streamingTemp);
! System.out.println("Le processor est cree");
// D�marrage du ProcessorTest
! processor.start();
System.out.println("Le processeur a demarre");
// On fournit la DataSource � diffuser
! streamingTemp.setNewStreams(processor.getOutput());
System.out.println("Le streaming a recu les nouveaux streams");
--- 333,347 ----
}
System.out.println("Le streaming est initialise");
! //processor = new ProcessorTest(new MediaLocator(getMediaAddress(_clientID)),
! // streamingTemp);
! // System.out.println("Le processor est cree");
// D�marrage du ProcessorTest
! // processor.start();
! tabReencode[_clientID].setStreamingRef(streamingTemp);
! tabReencode[_clientID].start();
System.out.println("Le processeur a demarre");
// On fournit la DataSource � diffuser
! //streamingTemp.setNewStreams(processor.getOutput());
System.out.println("Le streaming a recu les nouveaux streams");
|
|
From: <mar...@us...> - 2003-03-14 02:17:58
|
Update of /cvsroot/madsserv/madsserv/src/server/processor
In directory sc8-pr-cvs1:/tmp/cvs-serv12458
Modified Files:
ThreadReencode.java
Log Message:
Fin des fichiers implementee
Index: ThreadReencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/ThreadReencode.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** ThreadReencode.java 13 Mar 2003 23:47:26 -0000 1.4
--- ThreadReencode.java 14 Mar 2003 02:17:55 -0000 1.5
***************
*** 38,41 ****
--- 38,42 ----
private VideoFormat reencodingVideoFormat = null; // Format video de reencodage.
private Time startTime; // Instant de debut du reencodage.
+ private Boolean endOfMediaSent = null; // Indique que le fichier est termine.
/**
***************
*** 53,56 ****
--- 54,58 ----
this.startTime = startTime;
this.reencodeRef = reencodeRef;
+ endOfMediaSent = Boolean.valueOf(false);
}
***************
*** 72,75 ****
--- 74,78 ----
this.startTime = startTime;
this.reencodeRef = reencodeRef;
+ endOfMediaSent = Boolean.valueOf(false);
}
***************
*** 86,90 ****
resultat = this.startProcessing();
reencodeRef.reencoding = true;
! System.err.println("Résultat : " + resultat);
}
--- 89,93 ----
resultat = this.startProcessing();
reencodeRef.reencoding = true;
! System.err.println("Resultat : " + resultat);
}
***************
*** 139,142 ****
--- 142,146 ----
Format supported[];
Format chosen;
+ Format finalchosen;
boolean atLeastOneTrack = false;
***************
*** 153,164 ****
if (supported.length > 0) {
if (supported[0] instanceof VideoFormat) {
// For video formats, we should double check the
// sizes since not all formats work in all sizes.
chosen = checkForVideoSizes(tracks[i].getFormat(),
! supported[0]); //FIXME mettre reencodingVideoFormat
! } else
! //chosen = reencodingAudioFormat;
chosen = supported[0];
tracks[i].setFormat(chosen);
System.err.println("Track " + i + " is set to transmit as:");
--- 157,170 ----
if (supported.length > 0) {
+ for(int j=0;j<supported.length;j++)
+ System.out.println("Format supporte n" + j + " : " + supported[j].toString());
if (supported[0] instanceof VideoFormat) {
// For video formats, we should double check the
// sizes since not all formats work in all sizes.
chosen = checkForVideoSizes(tracks[i].getFormat(),
! supported[0]);
! } else {
chosen = supported[0];
+ }
tracks[i].setFormat(chosen);
System.err.println("Track " + i + " is set to transmit as:");
***************
*** 175,179 ****
if (!atLeastOneTrack)
return "Couldn't set any of the tracks to a valid RTP format";
! System.out.println("C'est pas encore planté ! l. 176");
// Realize the processor. This will internally create a flow
// graph and attempt to create an output datasource for JPEG/RTP
--- 181,185 ----
if (!atLeastOneTrack)
return "Couldn't set any of the tracks to a valid RTP format";
!
// Realize the processor. This will internally create a flow
// graph and attempt to create an output datasource for JPEG/RTP
***************
*** 336,340 ****
p.configure();
} else if (state == Processor.Realized) {
! System.out.println("On va réaliser le processor");
p.realize();
System.out.println("Le processor est realized");
--- 342,346 ----
p.configure();
} else if (state == Processor.Realized) {
! System.out.println("On va realiser le processor");
p.realize();
System.out.println("Le processor est realized");
***************
*** 380,385 ****
}
}
}
}
!
! }
--- 386,403 ----
}
}
+ if (ce instanceof DataStarvedEvent || ce instanceof EndOfMediaEvent) {
+ System.out.println("J'ai un evenement DataStarved");
+ synchronized (endOfMediaSent) {
+ System.out.println("Evenement DataStarved traite");
+ if (!endOfMediaSent.booleanValue())
+ endOfMediaSent = Boolean.valueOf(true);
+ try {
+ Thread.sleep(4000);
+ reencodeRef.streamingRef.endOfMedia();
+ }
+ catch (Exception e) {}
+ }
+ }
}
}
! }
\ No newline at end of file
|
|
From: <mar...@us...> - 2003-03-14 02:17:37
|
Update of /cvsroot/madsserv/madsserv/src/server/processor
In directory sc8-pr-cvs1:/tmp/cvs-serv12353
Modified Files:
Reencode.java
Log Message:
Fin des fichiers implementee
Index: Reencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/Reencode.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** Reencode.java 14 Mar 2003 00:10:57 -0000 1.10
--- Reencode.java 14 Mar 2003 02:17:33 -0000 1.11
***************
*** 58,62 ****
if(this.clientId < 0)
{
! System.err.println("L'ID du client n'a pas été transmis correctement.");
System.exit(0);
}
--- 58,62 ----
if(this.clientId < 0)
{
! System.err.println("L'ID du client n'a pas ete transmis correctement.");
System.exit(0);
}
***************
*** 65,69 ****
if(this.inputURL == null)
{
! System.err.println("L'URL à lire n'a pas été transmis correctement.");
System.exit(0);
}
--- 65,69 ----
if(this.inputURL == null)
{
! System.err.println("L'URL a lire n'a pas ete transmis correctement.");
System.exit(0);
}
***************
*** 73,77 ****
if((inputML = createMediaLocator(inputURL)) == null)
{
! System.err.println("Impossible de construire le MediaLocator à partir de : " + inputURL);
System.exit(0);
}
--- 73,77 ----
if((inputML = createMediaLocator(inputURL)) == null)
{
! System.err.println("Impossible de construire le MediaLocator a partir de : " + inputURL);
System.exit(0);
}
***************
*** 240,244 ****
{
this.originalVideoFormat = originalVideoFormat;
! System.out.println("Format vidéo original du fichier : " + this.originalVideoFormat.toString());
}
--- 240,244 ----
{
this.originalVideoFormat = originalVideoFormat;
! System.out.println("Format video original du fichier : " + this.originalVideoFormat.toString());
}
|
|
From: <mar...@us...> - 2003-03-14 00:11:07
|
Update of /cvsroot/madsserv/madsserv/src/server/processor
In directory sc8-pr-cvs1:/tmp/cvs-serv3465
Modified Files:
Reencode.java
Log Message:
Codage de la methode publique stop
Index: Reencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/Reencode.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Reencode.java 13 Mar 2003 23:47:25 -0000 1.9
--- Reencode.java 14 Mar 2003 00:10:57 -0000 1.10
***************
*** 159,163 ****
}
currentThreadReencode.run();
! streamingRef.setNewStream(currentThreadReencode.getOutput());
}
else
--- 159,163 ----
}
currentThreadReencode.run();
! streamingRef.setNewStreams(currentThreadReencode.getOutput());
}
else
***************
*** 182,186 ****
// On transmet au module Streaming l'adresse du DataSource de sortie
! streamingRef.setNewStream(currentThreadReencode.getOutput());
}
}
--- 182,186 ----
// On transmet au module Streaming l'adresse du DataSource de sortie
! streamingRef.setNewStreams(currentThreadReencode.getOutput());
}
}
***************
*** 195,199 ****
if(formerThreadReencode == null)
{
! System.err.println("Le précédent ThreadReencode est déjà arrêté ou n'a pas encore été affecté.");
return -1;
}
--- 195,199 ----
if(formerThreadReencode == null)
{
! System.err.println("Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
return -1;
}
***************
*** 402,406 ****
}
! public void stop() {}; //FIXME
}
--- 402,420 ----
}
! public int stop()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le precedent ThreadReencode est deja arrete ou n'a jamais ete affecte.");
! }
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
! formerThreadReencode.stopProcessing();
! formerThreadReencode = null;
! }
! currentThreadReencode.stopProcessing();
! currentThreadReencode = null;
! return 0;
! }
}
|
|
From: <mar...@us...> - 2003-03-13 23:47:39
|
Update of /cvsroot/madsserv/madsserv/src/server/processor
In directory sc8-pr-cvs1:/tmp/cvs-serv28323
Modified Files:
Reencode.java ThreadReencode.java
Log Message:
Module utilisable mais l_encodage dans un format voulu n_est pas encore implemente
Index: Reencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/Reencode.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Reencode.java 13 Mar 2003 01:53:00 -0000 1.8
--- Reencode.java 13 Mar 2003 23:47:25 -0000 1.9
***************
*** 1,405 ****
! /**
! * Projet Madsserv
! * Reencode.java
! *
! * Module de conversion des fichiers multimedia.
! * Reencode un fichier multimedia dans un format choisi.
! *
! * @author Jean-Baptiste Mariotte
! */
!
! import java.awt.*;
! import java.io.File;
! import javax.media.*;
! import javax.media.Format;
! import javax.media.format.*;
! import javax.media.protocol.*;
! import javax.media.protocol.DataSource;
! import javax.media.control.*;
! import java.io.IOException;
!
! /**
! * Classe Reencode
! */
! public class Reencode implements ControllerListener {
!
! /**
! * Champs de la classe Reencode
! */
! public Streaming streamingRef; // Reference du module Streaming frere.
! public Transition transitionRef; //Reference du module Transition frere.
! public boolean multiMedia = false; // Indique si le fichier est mulimedia.
! public boolean reencoding = false; // Indique s'il y a conversion en cours.
! public ThreadReencode formerThreadReencode = null; // Precedent thread de conversion.
! public ThreadReencode currentThreadReencode = null; // Thread de conversion actuel.
!
! private String inputURL = null; // Adresse du fichier demande.
! private int clientId = -1; // Numero du client demandeur.
! private MediaLocator inputML = null; // MediaLocator du fichier a convertir.
! private DataSource inputDS = null; // DataSource contenant le fichier a convertir.
! private TrackControl[] inputTC = null; // TrackControl permettant d'acceder aux differentes pistes du media.
! private Format[] inputFormat = null; // Vecteur de Format pour stocker les formats des pistes.
! private AudioFormat originalAudioFormat = null; // Format audio original du fichier a convertir.
! private VideoFormat originalVideoFormat = null; // Format video original du fichier a convertir.
! private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage du fichier.
! private VideoFormat reencodingVideoFormat = null; // Format video de reencodage du fichier.
! private Time startTime; // Instant de debut de conversion.
!
!
! /**
! * Constructeur de la classe Reencode.
! * @param clientId l'ID du client associe au module
! * @param inputURL l'URL demande par le client
! */
! Reencode(int clientId, String inputURL)
! {
! // Stockage de l'ID du client correspondant a l'instantiation.
! this.clientId = clientId;
! if(this.clientId < 0)
! {
! System.err.println("L'ID du client n'a pas été transmis correctement.");
! System.exit(0);
! }
! // Stockage de l'URL demande correspondant a l'instantiation.
! this.inputURL = inputURL;
! if(this.inputURL == null)
! {
! System.err.println("L'URL à lire n'a pas été transmis correctement.");
! System.exit(0);
! }
! System.err.println("Module de conversion construit\n");
!
! // Conversion de l'URL en MediaLocator.
! if((inputML = createMediaLocator(inputURL)) == null)
! {
! System.err.println("Impossible de construire le MediaLocator à partir de : " + inputURL);
! System.exit(0);
! }
!
! // Determination des formats d'origine du fichier demande.
! // Pour cela, on cree un Processor que l'on place dans l'etat configure.
! // Source inspire de la classe Transcode publiee par Sun.
! // http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! Processor p = null;
!
! try
! {
! p = Manager.createProcessor(inputML);
! System.err.println("- create processor for: " + inputML);
! }
! catch (Exception e)
! {
! System.err.println("Yikes! Cannot create a processor from the given url: " + e);
! }
!
! p.addControllerListener(this);
!
! // Put the Processor into configured state.
! p.configure();
! if (!waitForState(p, p.Configured))
! {
! System.err.println("Failed to configure the processor.");
! }
!
! // A l'aide de TrackControl, on accede aux differentes pistes du media.
! try
! {
! if ( (inputTC = p.getTrackControls()) == null)
! {
! System.err.println("Il n'y a aucune piste dans le fichier !");
! }
! else
! {
! if(inputTC.length > 2)
! {
! System.err.println("Il y a trop de pistes dans le fichier !");
! }
! else
! {
! inputFormat = new Format[inputTC.length];
! if(inputTC.length == 1)
! {
! System.err.println("Il n'y a qu'une seule piste");
! setOriginalAudioFormat( (AudioFormat) inputFormat[0]); //FIXME si video sans son
! }
! else //FIXME si pistes video et son dans un autre ordre
! {
! inputFormat[0] = inputTC[0].getFormat();
! System.err.println("Format piste n 1 : " + inputFormat[0].toString());
! setOriginalVideoFormat( (VideoFormat) inputFormat[0]);
! inputFormat[1] = inputTC[1].getFormat();
! System.err.println("Format piste n 2 : " + inputFormat[1].toString());
! setOriginalAudioFormat( (AudioFormat) inputFormat[1]);
! multiMedia = true;
! }
! }
! }
! }
! catch (NotConfiguredError e) {}
!
! p.removeControllerListener(this);
! }
!
! /**
! * Lancement de la conversion
! */
! public void start()
! {
! if(!reencoding)
! {
! if (multiMedia) { // Fichier audio et video
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat,
! reencodingVideoFormat, startTime, this);
! }
! else { // Fichier audio simple
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat, startTime, this);
! }
! currentThreadReencode.run();
! streamingRef.setNewStream(currentThreadReencode.getOutput());
! }
! else
! {
! formerThreadReencode = currentThreadReencode;
! if (multiMedia) { // Fichier audio et video
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat,
! reencodingVideoFormat, startTime, this);
! }
! else { // Fichier audio simple
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat, startTime, this);
! }
! currentThreadReencode.run();
!
! // On attend que le Processor du nouveau thread soit started
! Processor currentProcessor = null;
! currentProcessor = currentThreadReencode.processor;
! stateTransitionOK = true;
! waitForState(currentProcessor, currentProcessor.Started);
!
! // On transmet au module Streaming l'adresse du DataSource de sortie
! streamingRef.setNewStream(currentThreadReencode.getOutput());
! }
! }
!
! /**
! * Arret du ThreadReencode precedent
! * @return -1 si erreur
! * @return 0 si arret du precedent thread
! */
! public int stopFormerThreadReencode()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le précédent ThreadReencode est déjà arrêté ou n'a pas encore été affecté.");
! return -1;
! }
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
! formerThreadReencode.stopProcessing();
! formerThreadReencode = null;
! return 0;
! }
! }
!
! /**
! * Retourne l'ID du client correspondant au module instancie
! * @return l'ID du client correspondant au module instancie
! */
! public int getClientId()
! {
! return this.clientId;
! }
!
! /**
! * Retourne le format video original du fichier demande.
! * @return le format video original du fichier
! */
! public VideoFormat getOriginalVideoFormat()
! {
! return this.originalVideoFormat;
! }
!
! /**
! * Retourne le format audio original du fichier demande.
! * @return le format audio original du fichier
! */
! public AudioFormat getOriginalAudioFormat()
! {
! return this.originalAudioFormat;
! }
!
! /**
! * Definit le format video original du fichier demande.
! * @param originalVideoFormat le format video original du fichier
! */
! private void setOriginalVideoFormat(VideoFormat originalVideoFormat)
! {
! this.originalVideoFormat = originalVideoFormat;
! System.out.println("Format vidéo original du fichier : " + this.originalVideoFormat.toString());
! }
!
! /**
! * Definit le format audio original du fichier demande.
! * @param originalAudioFormat le format audio original du fichier
! */
! private void setOriginalAudioFormat(AudioFormat originalAudioFormat)
! {
! this.originalAudioFormat = originalAudioFormat;
! System.out.println("Format audio original du fichier : " + this.originalAudioFormat.toString());
! }
!
! /**
! * Definit le format vidéo de reencodage du fichier demande.
! * @param reencodingVideoFormat le nouveau format vidéo de réencodage
! * @return 0 si mise a jour effectuee
! * @return -1 si erreur
! */
! public int setReencodingVideoFormat(VideoFormat reencodingVideoFormat)
! {
! if(reencodingVideoFormat != null)
! {
! this.reencodingVideoFormat = reencodingVideoFormat;
! System.err.println("Nouveau format video recu : " + reencodingVideoFormat.toString());
! return 0;
! }
! else
! {
! System.err.println("Pas de nouveau format video recu !");
! return -1;
! }
! }
!
! /**
! * Definit le format audio de reencodage du fichier demande.
! * @param reencodingAudioFormat le nouveau format audio de réencodage
! * @return 0 si mise a jour effectuee
! * @return -1 si erreur
! */
! public int setReencodingAudioFormat(AudioFormat reencodingAudioFormat)
! {
! if(reencodingAudioFormat != null)
! {
! this.reencodingAudioFormat = reencodingAudioFormat;
! System.err.println("Nouveau format video recu : " + reencodingAudioFormat.toString());
! return 0;
! }
! else
! {
! System.err.println("Pas de nouveau format audio recu !");
! return -1;
! }
! }
!
! /**
! * Definit le numero de l'image du changement de conversion.
! * @param startTime l'instant du changement de conversion
! */
! public void setReencodingTime(Time startTime)
! {
! this.startTime = startTime;
! }
!
! /**
! * Definit la reference du module Streaming correspondant au clientId.
! * @param streamingRef la reference du module Streaming correspondant au meme client
! */
! public void setStreamingRef(Streaming streamingRef)
! {
! this.streamingRef = streamingRef;
! }
!
! /**
! * Definit la reference du module Transition correspondant au clientId.
! * @param transitionRef la reference du module Transition correspondant au meme client
! */
! public void setTransitionRef(Transition transitionRef)
! {
! this.transitionRef = transitionRef;
! }
!
!
! /**
! * Cree un media locator a partir de l'URL (String) demandee.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! * @param url une url de fichier multimedia
! * @return un MediaLocator
! */
! static MediaLocator createMediaLocator(String url)
! {
! MediaLocator ml;
!
! if (url.indexOf(":") > 0 && (ml = new MediaLocator(url)) != null)
! return ml;
!
! if (url.startsWith(File.separator)) {
! if ((ml = new MediaLocator("file:" + url)) != null)
! return ml;
! } else {
! String file = "file:" + System.getProperty("user.dir") + File.separator + url;
! if ((ml = new MediaLocator(file)) != null)
! return ml;
! }
!
! return null;
! }
!
! Object waitSync = new Object();
! boolean stateTransitionOK = true;
!
! /**
! * Block until the processor has transitioned to the given state.
! * Return false if the transition failed.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! * @param p un Processor
! * @param state un int representant l'etat du Processor p
! * @return un booleen qui indique que le Processor est dans le bon etat
! */
! boolean waitForState(Processor p, int state) {
! synchronized (waitSync) {
! try {
! while (p.getState() < state && stateTransitionOK)
! waitSync.wait();
! } catch (Exception e) {}
! }
! return stateTransitionOK;
! }
!
! /**
! * Controller Listener.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! */
! public void controllerUpdate(ControllerEvent evt) {
!
! if (evt instanceof ConfigureCompleteEvent ||
! evt instanceof RealizeCompleteEvent ||
! evt instanceof PrefetchCompleteEvent) {
! synchronized (waitSync) {
! stateTransitionOK = true;
! waitSync.notifyAll();
! }
! } else if (evt instanceof ResourceUnavailableEvent) {
! synchronized (waitSync) {
! stateTransitionOK = false;
! waitSync.notifyAll();
! }
! } else if (evt instanceof EndOfMediaEvent) {
! evt.getSourceController().close();
! } else if (evt instanceof MediaTimeSetEvent) {
! System.err.println("- mediaTime set: " +
! ((MediaTimeSetEvent)evt).getMediaTime().getSeconds());
! } else if (evt instanceof StopAtTimeEvent) {
! System.err.println("- stop at time: " +
! ((StopAtTimeEvent)evt).getMediaTime().getSeconds());
! evt.getSourceController().close();
! }
! }
!
! public void stop() {}; //FIXME
!
! }
\ No newline at end of file
--- 1,406 ----
! /**
! * Projet Madsserv
! * Reencode.java
! *
! * Module de conversion des fichiers multimedia.
! * Reencode un fichier multimedia dans un format choisi.
! *
! * @author Jean-Baptiste Mariotte
! */
!
! import java.awt.*;
! import java.io.File;
! import javax.media.*;
! import javax.media.Format;
! import javax.media.format.*;
! import javax.media.protocol.*;
! import javax.media.protocol.DataSource;
! import javax.media.control.*;
! import java.io.IOException;
!
! /**
! * Classe Reencode
! */
! public class Reencode implements ControllerListener {
!
! /**
! * Champs de la classe Reencode
! */
! public Streaming streamingRef; // Reference du module Streaming frere.
! public Transition transitionRef; //Reference du module Transition frere.
! public boolean multiMedia = false; // Indique si le fichier est mulimedia.
! public boolean reencoding = false; // Indique s'il y a conversion en cours.
! public ThreadReencode formerThreadReencode = null; // Precedent thread de conversion.
! public ThreadReencode currentThreadReencode = null; // Thread de conversion actuel.
!
! private String inputURL = null; // Adresse du fichier demande.
! private int clientId = -1; // Numero du client demandeur.
! private MediaLocator inputML = null; // MediaLocator du fichier a convertir.
! private DataSource inputDS = null; // DataSource contenant le fichier a convertir.
! private TrackControl[] inputTC = null; // TrackControl permettant d'acceder aux differentes pistes du media.
! private Format[] inputFormat = null; // Vecteur de Format pour stocker les formats des pistes.
! private AudioFormat originalAudioFormat = null; // Format audio original du fichier a convertir.
! private VideoFormat originalVideoFormat = null; // Format video original du fichier a convertir.
! private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage du fichier.
! private VideoFormat reencodingVideoFormat = null; // Format video de reencodage du fichier.
! private Time startTime = new Time(0); // Instant de debut de conversion.
!
!
! /**
! * Constructeur de la classe Reencode.
! * @param clientId l'ID du client associe au module
! * @param inputURL l'URL demande par le client
! */
! Reencode(int clientId, String inputURL)
! {
! // Stockage de l'ID du client correspondant a l'instantiation.
! this.clientId = clientId;
! if(this.clientId < 0)
! {
! System.err.println("L'ID du client n'a pas été transmis correctement.");
! System.exit(0);
! }
! // Stockage de l'URL demande correspondant a l'instantiation.
! this.inputURL = inputURL;
! if(this.inputURL == null)
! {
! System.err.println("L'URL à lire n'a pas été transmis correctement.");
! System.exit(0);
! }
! System.err.println("Module de conversion construit\n");
!
! // Conversion de l'URL en MediaLocator.
! if((inputML = createMediaLocator(inputURL)) == null)
! {
! System.err.println("Impossible de construire le MediaLocator à partir de : " + inputURL);
! System.exit(0);
! }
!
! // Determination des formats d'origine du fichier demande.
! // Pour cela, on cree un Processor que l'on place dans l'etat configure.
! // Source inspire de la classe Transcode publiee par Sun.
! // http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! Processor p = null;
!
! try
! {
! p = Manager.createProcessor(inputML);
! System.err.println("- create processor for: " + inputML);
! }
! catch (Exception e)
! {
! System.err.println("Yikes! Cannot create a processor from the given url: " + e);
! }
!
! p.addControllerListener(this);
!
! // Put the Processor into configured state.
! p.configure();
! if (!waitForState(p, p.Configured))
! {
! System.err.println("Failed to configure the processor.");
! }
!
! // A l'aide de TrackControl, on accede aux differentes pistes du media.
! try
! {
! if ( (inputTC = p.getTrackControls()) == null)
! {
! System.err.println("Il n'y a aucune piste dans le fichier !");
! }
! else
! {
! if(inputTC.length > 2)
! {
! System.err.println("Il y a trop de pistes dans le fichier !");
! }
! else
! {
! inputFormat = new Format[inputTC.length];
! if(inputTC.length == 1)
! {
! inputFormat[0] = inputTC[0].getFormat();
! System.err.println("Il n'y a qu'une seule piste");
! setOriginalAudioFormat( (AudioFormat) inputFormat[0]); //FIXME si video sans son
! }
! else // Il y a deux pistes, la video est la premiere
! {
! inputFormat[0] = inputTC[0].getFormat();
! System.err.println("Format piste n 1 : " + inputFormat[0].toString());
! setOriginalVideoFormat( (VideoFormat) inputFormat[0]);
! inputFormat[1] = inputTC[1].getFormat();
! System.err.println("Format piste n 2 : " + inputFormat[1].toString());
! setOriginalAudioFormat( (AudioFormat) inputFormat[1]);
! multiMedia = true;
! }
! }
! }
! }
! catch (NotConfiguredError e) {}
!
! p.removeControllerListener(this);
! }
!
! /**
! * Lancement de la conversion
! */
! public void start()
! {
! if(!reencoding)
! {
! if (multiMedia) { // Fichier audio et video
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat,
! reencodingVideoFormat, startTime, this);
! }
! else { // Fichier audio simple
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat, startTime, this);
! }
! currentThreadReencode.run();
! streamingRef.setNewStream(currentThreadReencode.getOutput());
! }
! else
! {
! formerThreadReencode = currentThreadReencode;
! if (multiMedia) { // Fichier audio et video
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat,
! reencodingVideoFormat, startTime, this);
! }
! else { // Fichier audio simple
! currentThreadReencode = new ThreadReencode(inputML,
! reencodingAudioFormat, startTime, this);
! }
! currentThreadReencode.run();
!
! // On attend que le Processor du nouveau thread soit started
! Processor currentProcessor = null;
! currentProcessor = currentThreadReencode.processor;
! stateTransitionOK = true;
! waitForState(currentProcessor, currentProcessor.Started);
!
! // On transmet au module Streaming l'adresse du DataSource de sortie
! streamingRef.setNewStream(currentThreadReencode.getOutput());
! }
! }
!
! /**
! * Arret du ThreadReencode precedent
! * @return -1 si erreur
! * @return 0 si arret du precedent thread
! */
! public int stopFormerThreadReencode()
! {
! if(formerThreadReencode == null)
! {
! System.err.println("Le précédent ThreadReencode est déjà arrêté ou n'a pas encore été affecté.");
! return -1;
! }
! else // on arrete le processor et met la reference du ThreadReencode precedent a null
! {
! formerThreadReencode.stopProcessing();
! formerThreadReencode = null;
! return 0;
! }
! }
!
! /**
! * Retourne l'ID du client correspondant au module instancie
! * @return l'ID du client correspondant au module instancie
! */
! public int getClientId()
! {
! return this.clientId;
! }
!
! /**
! * Retourne le format video original du fichier demande.
! * @return le format video original du fichier
! */
! public VideoFormat getOriginalVideoFormat()
! {
! return this.originalVideoFormat;
! }
!
! /**
! * Retourne le format audio original du fichier demande.
! * @return le format audio original du fichier
! */
! public AudioFormat getOriginalAudioFormat()
! {
! return this.originalAudioFormat;
! }
!
! /**
! * Definit le format video original du fichier demande.
! * @param originalVideoFormat le format video original du fichier
! */
! private void setOriginalVideoFormat(VideoFormat originalVideoFormat)
! {
! this.originalVideoFormat = originalVideoFormat;
! System.out.println("Format vidéo original du fichier : " + this.originalVideoFormat.toString());
! }
!
! /**
! * Definit le format audio original du fichier demande.
! * @param originalAudioFormat le format audio original du fichier
! */
! private void setOriginalAudioFormat(AudioFormat originalAudioFormat)
! {
! this.originalAudioFormat = originalAudioFormat;
! System.out.println("Format audio original du fichier : " + this.originalAudioFormat.toString());
! }
!
! /**
! * Definit le format vidéo de reencodage du fichier demande.
! * @param reencodingVideoFormat le nouveau format vidéo de réencodage
! * @return 0 si mise a jour effectuee
! * @return -1 si erreur
! */
! public int setReencodingVideoFormat(VideoFormat reencodingVideoFormat)
! {
! if(reencodingVideoFormat != null)
! {
! this.reencodingVideoFormat = reencodingVideoFormat;
! System.err.println("Nouveau format video recu : " + reencodingVideoFormat.toString());
! return 0;
! }
! else
! {
! System.err.println("Pas de nouveau format video recu !");
! return -1;
! }
! }
!
! /**
! * Definit le format audio de reencodage du fichier demande.
! * @param reencodingAudioFormat le nouveau format audio de réencodage
! * @return 0 si mise a jour effectuee
! * @return -1 si erreur
! */
! public int setReencodingAudioFormat(AudioFormat reencodingAudioFormat)
! {
! if(reencodingAudioFormat != null)
! {
! this.reencodingAudioFormat = reencodingAudioFormat;
! System.err.println("Nouveau format audio recu : " + reencodingAudioFormat.toString());
! return 0;
! }
! else
! {
! System.err.println("Pas de nouveau format audio recu !");
! return -1;
! }
! }
!
! /**
! * Definit le numero de l'image du changement de conversion.
! * @param startTime l'instant du changement de conversion
! */
! public void setReencodingTime(Time startTime)
! {
! this.startTime = startTime;
! }
!
! /**
! * Definit la reference du module Streaming correspondant au clientId.
! * @param streamingRef la reference du module Streaming correspondant au meme client
! */
! public void setStreamingRef(Streaming streamingRef)
! {
! this.streamingRef = streamingRef;
! }
!
! /**
! * Definit la reference du module Transition correspondant au clientId.
! * @param transitionRef la reference du module Transition correspondant au meme client
! */
! public void setTransitionRef(Transition transitionRef)
! {
! this.transitionRef = transitionRef;
! }
!
!
! /**
! * Cree un media locator a partir de l'URL (String) demandee.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! * @param url une url de fichier multimedia
! * @return un MediaLocator
! */
! static MediaLocator createMediaLocator(String url)
! {
! MediaLocator ml;
!
! if (url.indexOf(":") > 0 && (ml = new MediaLocator(url)) != null)
! return ml;
!
! if (url.startsWith(File.separator)) {
! if ((ml = new MediaLocator("file:" + url)) != null)
! return ml;
! } else {
! String file = "file:" + System.getProperty("user.dir") + File.separator + url;
! if ((ml = new MediaLocator(file)) != null)
! return ml;
! }
!
! return null;
! }
!
! Object waitSync = new Object();
! boolean stateTransitionOK = true;
!
! /**
! * Block until the processor has transitioned to the given state.
! * Return false if the transition failed.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! * @param p un Processor
! * @param state un int representant l'etat du Processor p
! * @return un booleen qui indique que le Processor est dans le bon etat
! */
! boolean waitForState(Processor p, int state) {
! synchronized (waitSync) {
! try {
! while (p.getState() < state && stateTransitionOK)
! waitSync.wait();
! } catch (Exception e) {}
! }
! return stateTransitionOK;
! }
!
! /**
! * Controller Listener.
! * Source tire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! */
! public void controllerUpdate(ControllerEvent evt) {
!
! if (evt instanceof ConfigureCompleteEvent ||
! evt instanceof RealizeCompleteEvent ||
! evt instanceof PrefetchCompleteEvent) {
! synchronized (waitSync) {
! stateTransitionOK = true;
! waitSync.notifyAll();
! }
! } else if (evt instanceof ResourceUnavailableEvent) {
! synchronized (waitSync) {
! stateTransitionOK = false;
! waitSync.notifyAll();
! }
! } else if (evt instanceof EndOfMediaEvent) {
! evt.getSourceController().close();
! } else if (evt instanceof MediaTimeSetEvent) {
! System.err.println("- mediaTime set: " +
! ((MediaTimeSetEvent)evt).getMediaTime().getSeconds());
! } else if (evt instanceof StopAtTimeEvent) {
! System.err.println("- stop at time: " +
! ((StopAtTimeEvent)evt).getMediaTime().getSeconds());
! evt.getSourceController().close();
! }
! }
!
! public void stop() {}; //FIXME
!
! }
Index: ThreadReencode.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/processor/ThreadReencode.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ThreadReencode.java 13 Mar 2003 01:53:00 -0000 1.3
--- ThreadReencode.java 13 Mar 2003 23:47:26 -0000 1.4
***************
*** 1,376 ****
! /**
! * Projet Madsserv
! * ThreadReencode.java
! *
! * Thread de conversion du fichier multimedia.
! *
! * @author Jean-Baptiste Mariotte
! */
!
! import java.awt.*;
! import java.io.File;
! import java.io.IOException;
! import java.util.Vector;
! import javax.media.*;
! import javax.media.Format;
! import javax.media.format.*;
! import javax.media.protocol.*;
! import javax.media.protocol.DataSource;
! import javax.media.control.*;
! import javax.media.rtp.*;
! import javax.media.rtp.rtcp.*;
! import com.sun.media.rtp.*;
!
!
! /**
! * Classe ThreadReencode
! */
! class ThreadReencode extends Thread
! {
! /**
! * Champs de la classe ThreadReencode
! */
! public Processor processor = null; // Processor qui execute le reencodage.
! private Reencode reencodeRef = null; // Reference du module Reencode pere.
! private MediaLocator inputML = null; // MediaLocator du fichier a reencoder.
! private DataSource dataOutput; // DataSource de sortie.
! private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage.
! private VideoFormat reencodingVideoFormat = null; // Format video de reencodage.
! private Time startTime; // Instant de debut du reencodage.
!
! /**
! * Constructeur du thread de reencodage pour un media sonore uniquement.
! * @param inputML MediaLocator du fichier a reencoder
! * @param reencodingAudioFormat format audio de reencodage du fichier
! * @param startTime instant de debut du reencodage
! * @param reencodeRef reference du module Reencode pere
! */
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! Time startTime, Reencode reencodeRef)
! {
! this.inputML = inputML;
! this.reencodingAudioFormat = reencodingAudioFormat;
! this.startTime = startTime;
! this.reencodeRef = reencodeRef;
! }
!
! /**
! * Constructeur du thread de reencodage pour un media audio et video.
! * @param inputML MediaLocator du fichier a reencoder
! * @param reencodingAudioFormat format audio de reencodage du fichier
! * @param reencodingVideoFormat format video de reencodage du fichier
! * @param startTime instant de debut du reencodage
! * @param reencodeRef reference du module Reencode pere
! */
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! VideoFormat reencodingVideoFormat, Time startTime,
! Reencode reencodeRef)
! {
! this.inputML = inputML;
! this.reencodingAudioFormat = reencodingAudioFormat;
! this.reencodingVideoFormat = reencodingVideoFormat;
! this.startTime = startTime;
! this.reencodeRef = reencodeRef;
! }
!
! /**
! * Methode run lancant le thread de conversion.
! * Pour cela, on cree un Processor que l'on place dans l'etat configure.
! * Source inspire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! */
! public void run()
! {
! String resultat;
!
! resultat = this.startProcessing();
! reencodeRef.reencoding = true;
! System.err.println("Résultat : " + resultat);
! }
!
! /**
! * Source inspire de la classe AVTransmit2 publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/AVTransmit.html
! */
! public DataSource getOutput() {
! return dataOutput;
! }
!
! private String createProcessor() {
! if (inputML == null)
! return "Locator is null";
!
! DataSource ds;
! DataSource clone;
!
! try {
! ds = javax.media.Manager.createDataSource(inputML);
! } catch (Exception e) {
! return "Couldn't create DataSource";
! }
!
! // Try to create a processor to handle the input media locator
! try {
! processor = javax.media.Manager.createProcessor(ds);
! } catch (NoProcessorException npe) {
! return "Couldn't create processor";
! } catch (IOException ioe) {
! return "IOException creating processor";
! }
!
! // Wait for it to configure
! boolean result = waitForState(processor, Processor.Configured);
! if (result == false)
! return "Couldn't configure processor";
!
! // Get the tracks from the processor
! TrackControl [] tracks = processor.getTrackControls();
!
! // Do we have atleast one track?
! if (tracks == null || tracks.length < 1)
! return "Couldn't find tracks in processor";
!
! // Set the output content descriptor to RAW_RTP
! // This will limit the supported formats reported from
! // Track.getSupportedFormats to only valid RTP formats.
! ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
! processor.setContentDescriptor(cd);
!
! Format supported[];
! Format chosen;
! boolean atLeastOneTrack = false;
!
! // Program the tracks.
! for (int i = 0; i < tracks.length; i++) {
! Format format = tracks[i].getFormat();
! if (tracks[i].isEnabled()) {
! System.out.println("Track " + i + " is enabled");
! supported = tracks[i].getSupportedFormats();
!
! // We've set the output content to the RAW_RTP.
! // So all the supported formats should work with RTP.
! // We'll just pick the first one.
!
! if (supported.length > 0) {
! if (supported[0] instanceof VideoFormat) {
! // For video formats, we should double check the
! // sizes since not all formats work in all sizes.
! chosen = checkForVideoSizes(tracks[i].getFormat(),
! supported[0]); //FIXME mettre reencodingVideoFormat
! } else
! chosen = reencodingAudioFormat;
! tracks[i].setFormat(chosen);
! System.err.println("Track " + i + " is set to transmit as:");
! System.err.println(" " + chosen);
! atLeastOneTrack = true;
! } else
! tracks[i].setEnabled(false);
! } else {
! tracks[i].setEnabled(false);
! System.out.println("Track " + i + " isn't enabled");
! }
! }
!
! if (!atLeastOneTrack)
! return "Couldn't set any of the tracks to a valid RTP format";
!
! // Realize the processor. This will internally create a flow
! // graph and attempt to create an output datasource for JPEG/RTP
! // audio frames.
! result = waitForState(processor, Controller.Realized);
! if (result == false)
! return "Couldn't realize processor";
!
! // Set the JPEG quality to .5.
! setJPEGQuality(processor, 0.5f);
!
! // Get the output data source of the processor
! dataOutput = processor.getDataOutput();
!
! return null;
! }
!
! /**
! * Lance le Processor charge de la conversion
! * @return le message de creation du Processor
! */
! public synchronized String startProcessing() {
! String result;
!
! // Create a processor for the specified media locator
! // and program it to output JPEG/RTP
! result = createProcessor();
! if (result != null)
! return result;
!
! // Start the transmission
! processor.start();
!
! return null;
! }
!
! /**
! * Arrete le Processor en cours
! */
! public void stopProcessing() {
! synchronized (this) {
! if (processor != null) {
! processor.stop();
! processor.close();
! processor = null;
! }
! }
! }
!
! /**
! * For JPEG and H263, we know that they only work for particular
! * sizes. So we'll perform extra checking here to make sure they
! * are of the right sizes.
! */
! Format checkForVideoSizes(Format original, Format supported) {
!
! int width, height;
! Dimension size = ((VideoFormat)original).getSize();
! Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
! Format h263Fmt = new Format(VideoFormat.H263_RTP);
!
! if (supported.matches(jpegFmt)) {
! // For JPEG, make sure width and height are divisible by 8.
! width = (size.width % 8 == 0 ? size.width :
! (int)(size.width / 8) * 8);
! height = (size.height % 8 == 0 ? size.height :
! (int)(size.height / 8) * 8);
! } else if (supported.matches(h263Fmt)) {
! // For H.263, we only support some specific sizes.
! if (size.width < 128) {
! width = 128;
! height = 96;
! } else if (size.width < 176) {
! width = 176;
! height = 144;
! } else {
! width = 352;
! height = 288;
! }
! } else {
! // We don't know this particular format. We'll just
! // leave it alone then.
! return supported;
! }
!
! return (new VideoFormat(null,
! new Dimension(width, height),
! Format.NOT_SPECIFIED,
! null,
! Format.NOT_SPECIFIED)).intersects(supported);
! }
!
!
! /**
! * Setting the encoding quality to the specified value on the JPEG encoder.
! * 0.5 is a good default.
! */
! void setJPEGQuality(Player p, float val) {
!
! Control cs[] = p.getControls();
! QualityControl qc = null;
! VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);
!
! // Loop through the controls to find the Quality control for
! // the JPEG encoder.
! for (int i = 0; i < cs.length; i++) {
!
! if (cs[i] instanceof QualityControl &&
! cs[i] instanceof Owned) {
! Object owner = ((Owned)cs[i]).getOwner();
!
! // Check to see if the owner is a Codec.
! // Then check for the output format.
! if (owner instanceof Codec) {
! Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);
! for (int j = 0; j < fmts.length; j++) {
! if (fmts[j].matches(jpegFmt)) {
! qc = (QualityControl)cs[i];
! qc.setQuality(val);
! System.err.println("- Setting quality to " +
! val + " on " + qc);
! break;
! }
! }
! }
! if (qc != null)
! break;
! }
! }
! }
!
!
! /****************************************************************
! * Convenience methods to handle processor's state changes.
! ****************************************************************/
!
! private Integer stateLock = new Integer(0);
! private boolean failed = false;
!
! Integer getStateLock() {
! return stateLock;
! }
!
! void setFailed() {
! failed = true;
! }
!
! private synchronized boolean waitForState(Processor p, int state) {
! p.addControllerListener(new StateListener());
! failed = false;
!
! // Call the required method on the processor
! if (state == Processor.Configured) {
! p.configure();
! } else if (state == Processor.Realized) {
! p.realize();
! }
!
! // Wait until we get an event that confirms the
! // success of the method, or a failure event.
! // See StateListener inner class
! while (p.getState() < state && !failed) {
! synchronized (getStateLock()) {
! try {
! getStateLock().wait();
! } catch (InterruptedException ie) {
! return false;
! }
! }
! }
!
! if (failed)
! return false;
! else
! return true;
! }
!
! /****************************************************************
! * Inner Classes
! ****************************************************************/
!
! class StateListener implements ControllerListener {
!
! public void controllerUpdate(ControllerEvent ce) {
!
! // If there was an error during configure or
! // realize, the processor will be closed
! if (ce instanceof ControllerClosedEvent)
! setFailed();
!
! // All controller events, send a notification
! // to the waiting thread in waitForState method.
! if (ce instanceof ControllerEvent) {
! synchronized (getStateLock()) {
! getStateLock().notifyAll();
! }
! }
! }
! }
!
! }
\ No newline at end of file
--- 1,385 ----
! /**
! * Projet Madsserv
! * ThreadReencode.java
! *
! * Thread de conversion du fichier multimedia.
! *
! * @author Jean-Baptiste Mariotte
! */
!
! import java.awt.*;
! import java.io.File;
! import java.io.IOException;
! import java.util.Vector;
! import javax.media.*;
! import javax.media.Format;
! import javax.media.format.*;
! import javax.media.protocol.*;
! import javax.media.protocol.DataSource;
! import javax.media.control.*;
! import javax.media.rtp.*;
! import javax.media.rtp.rtcp.*;
! import com.sun.media.rtp.*;
!
!
! /**
! * Classe ThreadReencode
! */
! class ThreadReencode extends Thread
! {
! /**
! * Champs de la classe ThreadReencode
! */
! public Processor processor = null; // Processor qui execute le reencodage.
! private Reencode reencodeRef = null; // Reference du module Reencode pere.
! private MediaLocator inputML = null; // MediaLocator du fichier a reencoder.
! private DataSource dataOutput; // DataSource de sortie.
! private AudioFormat reencodingAudioFormat = null; // Format audio de reencodage.
! private VideoFormat reencodingVideoFormat = null; // Format video de reencodage.
! private Time startTime; // Instant de debut du reencodage.
!
! /**
! * Constructeur du thread de reencodage pour un media sonore uniquement.
! * @param inputML MediaLocator du fichier a reencoder
! * @param reencodingAudioFormat format audio de reencodage du fichier
! * @param startTime instant de debut du reencodage
! * @param reencodeRef reference du module Reencode pere
! */
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! Time startTime, Reencode reencodeRef)
! {
! this.inputML = inputML;
! this.reencodingAudioFormat = reencodingAudioFormat;
! this.startTime = startTime;
! this.reencodeRef = reencodeRef;
! }
!
! /**
! * Constructeur du thread de reencodage pour un media audio et video.
! * @param inputML MediaLocator du fichier a reencoder
! * @param reencodingAudioFormat format audio de reencodage du fichier
! * @param reencodingVideoFormat format video de reencodage du fichier
! * @param startTime instant de debut du reencodage
! * @param reencodeRef reference du module Reencode pere
! */
! public ThreadReencode (MediaLocator inputML, AudioFormat reencodingAudioFormat,
! VideoFormat reencodingVideoFormat, Time startTime,
! Reencode reencodeRef)
! {
! this.inputML = inputML;
! this.reencodingAudioFormat = reencodingAudioFormat;
! this.reencodingVideoFormat = reencodingVideoFormat;
! this.startTime = startTime;
! this.reencodeRef = reencodeRef;
! }
!
! /**
! * Methode run lancant le thread de conversion.
! * Pour cela, on cree un Processor que l'on place dans l'etat configure.
! * Source inspire de la classe Transcode publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Transcode.html
! */
! public void run()
! {
! String resultat;
!
! resultat = this.startProcessing();
! reencodeRef.reencoding = true;
! System.err.println("Résultat : " + resultat);
! }
!
! /**
! * Source inspire de la classe AVTransmit2 publiee par Sun.
! * http://java.sun.com/products/java-media/jmf/2.1.1/solutions/AVTransmit.html
! */
! public DataSource getOutput() {
! return dataOutput;
! }
!
! private String createProcessor() {
! if (inputML == null)
! return "Locator is null";
!
! DataSource ds;
! DataSource clone;
!
! try {
! ds = javax.media.Manager.createDataSource(inputML);
! } catch (Exception e) {
! return "Couldn't create DataSource";
! }
!
! // Try to create a processor to handle the input media locator
! try {
! processor = javax.media.Manager.createProcessor(ds);
! } catch (NoProcessorException npe) {
! return "Couldn't create processor";
! } catch (IOException ioe) {
! return "IOException creating processor";
! }
!
! // Wait for it to configure
! boolean result = waitForState(processor, Processor.Configured);
! if (result == false)
! return "Couldn't configure processor";
!
! // Get the tracks from the processor
! TrackControl [] tracks = processor.getTrackControls();
!
! // Do we have atleast one track?
! if (tracks == null || tracks.length < 1)
! return "Couldn't find tracks in processor";
!
! // Set the output content descriptor to RAW_RTP
! // This will limit the supported formats reported from
! // Track.getSupportedFormats to only valid RTP formats.
! ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
! processor.setContentDescriptor(cd);
!
! Format supported[];
! Format chosen;
! boolean atLeastOneTrack = false;
!
! // Program the tracks.
! for (int i = 0; i < tracks.length; i++) {
! Format format = tracks[i].getFormat();
! if (tracks[i].isEnabled()) {
! System.out.println("Track " + i + " is enabled");
! supported = tracks[i].getSupportedFormats();
!
! // We've set the output content to the RAW_RTP.
! // So all the supported formats should work with RTP.
! // We'll just pick the first one.
!
! if (supported.length > 0) {
! if (supported[0] instanceof VideoFormat) {
! // For video formats, we should double check the
! // sizes since not all formats work in all sizes.
! chosen = checkForVideoSizes(tracks[i].getFormat(),
! supported[0]); //FIXME mettre reencodingVideoFormat
! } else
! //chosen = reencodingAudioFormat;
! chosen = supported[0];
! tracks[i].setFormat(chosen);
! System.err.println("Track " + i + " is set to transmit as:");
! System.err.println(" " + chosen);
! atLeastOneTrack = true;
! } else
! tracks[i].setEnabled(false);
! } else {
! tracks[i].setEnabled(false);
! System.out.println("Track " + i + " isn't enabled");
! }
! }
!
! if (!atLeastOneTrack)
! return "Couldn't set any of the tracks to a valid RTP format";
! System.out.println("C'est pas encore planté ! l. 176");
! // Realize the processor. This will internally create a flow
! // graph and attempt to create an output datasource for JPEG/RTP
! // audio frames.
! result = waitForState(processor, Controller.Realized);
! if (result == false)
! return "Couldn't realize processor";
!
! // Set the JPEG quality to .5.
! setJPEGQuality(processor, 0.5f);
!
! // Commencer a encoder a partir de l'instant voulu
! if (startTime.getSeconds() > 0)
! {
! processor.setMediaTime(startTime);
! }
!
! // Get the output data source of the processor
! dataOutput = processor.getDataOutput();
!
! return null;
! }
!
! /**
! * Lance le Processor charge de la conversion
! * @return le message de creation du Processor
! */
! public synchronized String startProcessing() {
! String result;
!
! // Create a processor for the specified media locator
! // and program it to output JPEG/RTP
! result = createProcessor();
! if (result != null)
! return result;
!
! // Start the transmission
! processor.start();
!
! return null;
! }
!
! /**
! * Arrete le Processor en cours
! */
! public void stopProcessing() {
! synchronized (this) {
! if (processor != null) {
! processor.stop();
! processor.close();
! processor = null;
! }
! }
! }
!
! /**
! * For JPEG and H263, we know that they only work for particular
! * sizes. So we'll perform extra checking here to make sure they
! * are of the right sizes.
! */
! Format checkForVideoSizes(Format original, Format supported) {
!
! int width, height;
! Dimension size = ((VideoFormat)original).getSize();
! Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
! Format h263Fmt = new Format(VideoFormat.H263_RTP);
!
! if (supported.matches(jpegFmt)) {
! // For JPEG, make sure width and height are divisible by 8.
! width = (size.width % 8 == 0 ? size.width :
! (int)(size.width / 8) * 8);
! height = (size.height % 8 == 0 ? size.height :
! (int)(size.height / 8) * 8);
! } else if (supported.matches(h263Fmt)) {
! // For H.263, we only support some specific sizes.
! if (size.width < 128) {
! width = 128;
! height = 96;
! } else if (size.width < 176) {
! width = 176;
! height = 144;
! } else {
! width = 352;
! height = 288;
! }
! } else {
! // We don't know this particular format. We'll just
! // leave it alone then.
! return supported;
! }
!
! return (new VideoFormat(null,
! new Dimension(width, height),
! Format.NOT_SPECIFIED,
! null,
! Format.NOT_SPECIFIED)).intersects(supported);
! }
!
!
! /**
! * Setting the encoding quality to the specified value on the JPEG encoder.
! * 0.5 is a good default.
! */
! void setJPEGQuality(Player p, float val) {
!
! Control cs[] = p.getControls();
! QualityControl qc = null;
! VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);
!
! // Loop through the controls to find the Quality control for
! // the JPEG encoder.
! for (int i = 0; i < cs.length; i++) {
!
! if (cs[i] instanceof QualityControl &&
! cs[i] instanceof Owned) {
! Object owner = ((Owned)cs[i]).getOwner();
!
! // Check to see if the owner is a Codec.
! // Then check for the output format.
! if (owner instanceof Codec) {
! Format fmts[] = ((Codec)owner).getSupportedOutputFormats(null);
! for (int j = 0; j < fmts.length; j++) {
! if (fmts[j].matches(jpegFmt)) {
! qc = (QualityControl)cs[i];
! qc.setQuality(val);
! System.err.println("- Setting quality to " +
! val + " on " + qc);
! break;
! }
! }
! }
! if (qc != null)
! break;
! }
! }
! }
!
!
! /****************************************************************
! * Convenience methods to handle processor's state changes.
! ****************************************************************/
!
! private Integer stateLock = new Integer(0);
! private boolean failed = false;
!
! Integer getStateLock() {
! return stateLock;
! }
!
! void setFailed() {
! failed = true;
! }
!
! private synchronized boolean waitForState(Processor p, int state) {
! p.addControllerListener(new StateListener());
! failed = false;
!
! // Call the required method on the processor
! if (state == Processor.Configured) {
! p.configure();
! } else if (state == Processor.Realized) {
! System.out.println("On va réaliser le processor");
! p.realize();
! System.out.println("Le processor est realized");
! }
!
! // Wait until we get an event that confirms the
! // success of the method, or a failure event.
! // See StateListener inner class
! while (p.getState() < state && !failed) {
! synchronized (getStateLock()) {
! try {
! getStateLock().wait();
! } catch (InterruptedException ie) {
! return false;
! }
! }
! }
!
! if (failed)
! return false;
! else
! return true;
! }
!
! /****************************************************************
! * Inner Classes
! ****************************************************************/
!
! class StateListener implements ControllerListener {
!
! public void controllerUpdate(ControllerEvent ce) {
!
! // If there was an error during configure or
! // realize, the processor will be closed
! if (ce instanceof ControllerClosedEvent)
! setFailed();
!
! // All controller events, send a notification
! // to the waiting thread in waitForState method.
! if (ce instanceof ControllerEvent) {
! synchronized (getStateLock()) {
! getStateLock().notifyAll();
! }
! }
! }
! }
!
! }
|
|
From: <dep...@us...> - 2003-03-13 23:32:47
|
Update of /cvsroot/madsserv/madsserv/src/server/transition In directory sc8-pr-cvs1:/tmp/cvs-serv23111 Modified Files: Transition.java Log Message: quelques modif de transition Index: Transition.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/transition/Transition.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Transition.java 12 Mar 2003 23:07:11 -0000 1.4 --- Transition.java 13 Mar 2003 23:32:34 -0000 1.5 *************** *** 1,188 **** ! import java.awt.*; ! import java.io.*; ! import java.lang.Object.*; ! import javax.media.Time.*; ! import javax.media.*; ! import javax.media.format.*; ! import javax.media.format.AudioFormat.*; ! import javax.media.format.VideoFormat.*; ! ! /** ! * La classe Transition assure la transition la plus rapide lors d'un changement de niveau de qualit�. D�s que le gestionnaire des Connexions lui transmet un changement de niveau de qualit�, il collecte les informations sur les diffusions en cours, fixe les param�tres de l'encodage � effectuer et les transmet au module de traitement de la conversion. ! */ ! ! public class Transition ! { ! ! /*On d�clare ici le num�ro du client, le num�ro de frame courant et le niveau de qualit�*/ ! ! private int numClient; ! private int qualityLevel; ! Reencode reencodeRef; ! GestionAdapta gestionAdaptaRef; ! Streaming streamingRef; ! ! ! /** ! * Constructeur vide, il initialise le num�ro du client � 1, il met le niveau de quailt� � 1 par d�faut et le num�ro de FRame � 0. Il ne peut �tre utiliser que la premi�re fois, sinon il y a des risques de colision. ! */ ! ! public Transition () ! ! { ! numClient = 1; ! qualityLevel = 1; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le num�ro du client, le niveau de qualit� � 1 par d�faut et le num�ro de frame � 0. ! *@param _nmclient le numero du client ! */ ! ! public Transition(int _numClient) ! ! { ! numClient = _numClient; ! qualityLevel = 1; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le num�ro de client et le niveau de qualit� et met le num�ro de Frame � 0 par d�faut. ! *@param _nmclient le numero du client ! *@param _qualitylevel le niveau de qualite demande ! */ ! ! public Transition(int _numClient, int _qualityLevel) ! ! { ! numClient = _numClient; ! qualityLevel = _qualityLevel; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le num�ro de client et le niveau de qualit� et met le num�ro de Frame. ! *@param _nmclient le numero du client ! *@param _qualitylevel le niveau de qualite demande ! *@param _numFrame le num�ro de frame ! ! ! public Transition(int _numClient, int _qualityLevel, float _numFrame) ! ! { ! numClient = _numClient; ! qualityLevel = _qualityLevel; ! numFrame = _numFrame; ! */ ! ! /** ! *findNewNumberFrame : Cette m�thode calcule le nouveau num�ro de Frame � partir duquel il faut reencoder le fichier multimedia diffus�. ! *@param oldNumFrame le numero de frame qui vient d'etre envoye au client ! *@param reencodingVideoFor le nouveau format video de reencodage. ! *@param reencodingAudioFor le nouveau format audio de reencodage. ! */ ! ! public Time findNewMediaTime(double oldMediaTime, VideoFormat reencodingVideoFor, AudioFormat reencodingAudioFor) ! { ! double newAuxMediaTime = 0; ! double VideoMediaLength = 0; ! double AudioMediaLength = 0; ! Time newMediaTime; ! ! if (reencodeRef.multiMedia) ! { ! ! //frameRateVideo = reencodingVideoFor.getFrameRate(); ! newAuxMediaTime = oldMediaTime + 60; ! } ! ! else ! { ! //frameRateAudio = reencodingAudioFor.getFrameRate(); ! newAuxMediaTime = oldMediaTime + 60; ! ! } ! newMediaTime = new Time(newAuxMediaTime); ! //on retourne le num�ro de Frame � partir duquel il faut r�encoder. ! return(newMediaTime); ! ! } ! ! /** ! *setQualityLevel Cette m�thode lance tout le processus de transition entre deux niveau de qualit�s. ! *@param _qualityLevel le niveau de qualit� demande par le simulateur ! **/ ! ! public void setQualityLevel(int _qualityLevel) ! ! { ! int i = 2; ! double currentMediaTime = 0; ! Time startTime; ! Time auxMediaTime; ! String str = "coucou"; ! ! //variables qui vont stock�es le format original Video et Audio ! VideoFormat origVideoFor; ! AudioFormat origAudioFor; ! ! //variables qui vont stock�es le format de r�encodage Video et Audio ! VideoFormat reencodingVideoFor = null; ! AudioFormat reencodingAudioFor = null; ! ! ! qualityLevel = _qualityLevel; ! ! ! ! //On obtient ici les formats Vid�o et Audio Originaux. ! ! origVideoFor = reencodeRef.getOriginalVideoFormat(); ! origAudioFor = reencodeRef.getOriginalAudioFormat(); ! ! //On obtient ici les formats Vid�o et Audio de r�encodage. ! reencodingVideoFor = gestionAdaptaRef.getVideoStreamingFormat(qualityLevel, origVideoFor); ! reencodingAudioFor = gestionAdaptaRef.getAudioStreamingFormat(qualityLevel, origAudioFor); ! ! //auxMediaTime = getCurrentFrame(); ! ! startTime = findNewMediaTime(currentMediaTime, reencodingVideoFor, reencodingAudioFor); ! ! //on Transmet ici les formats Audio et Vid�o de r�encodage ! reencodeRef.setReencodingVideoFormat(reencodingVideoFor); ! reencodeRef.setReencodingAudioFormat(reencodingAudioFor); ! ! ! //On Transmet ici le num�ro de Frame � partir de laquelle il faut r�encoder le fichier. ! reencodeRef.setReencodingTime(startTime); ! ! } ! /** ! * setStreaming donne une referrence sur un objet Streaming ! * @param streamingRef un objet de type Streaming ! */ ! public void setStreaming(Streaming streamingRef) ! { ! this.streamingRef = streamingRef; ! } ! ! /** ! * setStreaming donne une referrence sur un objet gestionAdapta ! * @param gestionAdptaRef un objet de type Streaming ! */ ! public void setGestionAdapta(GestionAdapta gestionAdaptaRef) ! { ! this.gestionAdaptaRef = gestionAdaptaRef; ! } ! ! /** ! * setStreaming donne une referrence sur un objet Reencode ! * @param reencodeRef un objet de type Reencode ! */ ! public void setReencode(Reencode reencodeRef) ! { ! this.reencodeRef = reencodeRef; ! } ! ! } ! ! --- 1,201 ---- ! import java.awt.*; ! import java.io.*; ! import java.lang.Object.*; ! import javax.media.Time.*; ! import javax.media.*; ! import javax.media.format.*; ! import javax.media.format.AudioFormat.*; ! import javax.media.format.VideoFormat.*; ! ! /** ! * La classe Transition assure la transition la plus rapide lors d'un changement de niveau de qualite. Des que le gestionnaire des Connexions lui transmet un changement de niveau de qualit�, il collecte les informations sur les diffusions en cours, fixe les param�tres de l'encodage � effectuer et les transmet au module de traitement de la conversion. ! * @author Xavier Deplancq ! */ ! ! public class Transition { ! ! /*On declare ici le num�ro du client, le num�ro de frame courant et le niveau de qualite*/ ! ! private int numClient; ! private int qualityLevel; ! Reencode reencodeRef; ! GestionAdapta gestionAdaptaRef; ! Streaming streamingRef; ! ! /** ! * Constructeur vide, il initialise le num�ro du client � 1, il met le niveau de quailt� � 1 par d�faut et le num�ro de FRame � 0. Il ne peut �tre utiliser que la premi�re fois, sinon il y a des risques de colision. ! */ ! ! public Transition() ! ! { ! numClient = 1; ! qualityLevel = 1; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le num�ro du client, le niveau de qualit� � 1 par d�faut et le num�ro de frame � 0. ! *@param _nmclient le numero du client ! */ ! ! public Transition(int _numClient) ! ! { ! numClient = _numClient; ! qualityLevel = 1; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le num�ro de client et le niveau de qualit� et met le num�ro de Frame � 0 par d�faut. ! *@param _nmclient le numero du client ! *@param _qualitylevel le niveau de qualite demande ! */ ! ! public Transition(int _numClient, int _qualityLevel) ! ! { ! numClient = _numClient; ! qualityLevel = _qualityLevel; ! } ! ! /** ! * Constructeur de la classe Transition qui initialise le num�ro de client et le niveau de qualit� et met le num�ro de Frame. ! *@param _nmclient le numero du client ! *@param _qualitylevel le niveau de qualite demande ! *@param _numFrame le num�ro de frame ! public Transition(int _numClient, int _qualityLevel, float _numFrame) ! { ! numClient = _numClient; ! qualityLevel = _qualityLevel; ! numFrame = _numFrame; ! */ ! ! /** ! *findNewNumberFrame : Cette methode calcule le nouveau numero de Frame a partir duquel il faut reencoder le fichier multimedia diffus�. ! *@param oldNumFrame le numero de frame qui vient d'etre envoye au client ! *@param reencodingVideoFor le nouveau format video de reencodage. ! *@param reencodingAudioFor le nouveau format audio de reencodage. ! */ ! ! public Time findNewMediaTime(double oldMediaTime, ! VideoFormat reencodingVideoFor, ! AudioFormat reencodingAudioFor, ! double VideoMediaLength, double AudioMediaLength) { ! double newAuxMediaTime = 0; ! Time newMediaTime; ! ! if (reencodeRef.multiMedia) { ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! if (reencodingVideoFor.getEncoding() == "JPEG") { ! newAuxMediaTime = oldMediaTime + 3; ! } ! ! } ! ! else { ! if (reencodingAudioFor.getEncoding() == "MP3") { ! newAuxMediaTime = oldMediaTime + 2; ! } ! if (reencodingAudioFor.getEncoding() == "MP3") { ! newAuxMediaTime = oldMediaTime + 2; ! } ! ! } ! newMediaTime = new Time(newAuxMediaTime); ! //on retourne le numero de Frame a partir duquel il faut r�encoder. ! return (newMediaTime); ! ! } ! ! /** ! *setQualityLevel Cette methode lance tout le processus de transition entre deux niveau de qualites. ! *@param _qualityLevel le niveau de qualite demande par le simulateur ! **/ ! ! public void setQualityLevel(int _qualityLevel) ! ! { ! int i = 2; ! double currentMediaTime = 0; ! double videoMediaLength = 0; ! double audioMediaLength = 0; ! Time startTime; ! Time auxMediaTime; ! ! //variables qui vont stockees le format original Video et Audio ! VideoFormat origVideoFor; ! AudioFormat origAudioFor; ! ! //variables qui vont stockees le format de r�encodage Video et Audio ! VideoFormat reencodingVideoFor = null; ! AudioFormat reencodingAudioFor = null; ! ! qualityLevel = _qualityLevel; ! ! //On obtient ici les formats Video et Audio Originaux. ! if (reencodeRef.multimedia) ! origVideoFor = reencodeRef.getOriginalVideoFormat(); ! origAudioFor = reencodeRef.getOriginalAudioFormat(); ! ! //On obtient ici les formats Video et Audio de reencodage. ! if (reencodeRef.multimedia) ! reencodingVideoFor = gestionAdaptaRef.getVideoStreamingFormat(qualityLevel, ! origVideoFor); ! reencodingAudioFor = gestionAdaptaRef.getAudioStreamingFormat(qualityLevel, ! origAudioFor); ! ! ! //auxMediaTime = streamingRef.getCurrentFrame(); ! //videoMediaLength = streamingRef.getVideoMediaLength(); ! //audioMediaLength = strealingRef.gatAudioMediaLength(); ! ! startTime = findNewMediaTime(currentMediaTime, reencodingVideoFor, ! reencodingAudioFor, videoMediaLength, ! audioMediaLength); ! ! //on Transmet ici les formats Audio et Video de reencodage ! if (reencodeRef.multimedia) ! reencodeRef.setReencodingVideoFormat(reencodingVideoFor); ! reencodeRef.setReencodingAudioFormat(reencodingAudioFor); ! ! //On Transmet ici le numero de Frame a partir de laquelle il faut reencoder le fichier. ! reencodeRef.setReencodingTime(startTime); ! ! } ! ! /** ! * setStreaming donne une referrence sur un objet Streaming ! * @param streamingRef un objet de type Streaming ! */ ! public void setStreaming(Streaming streamingRef) { ! this.streamingRef = streamingRef; ! } ! ! /** ! * setStreaming donne une referrence sur un objet gestionAdapta ! * @param gestionAdptaRef un objet de type Streaming ! */ ! public void setGestionAdapta(GestionAdapta gestionAdaptaRef) { ! this.gestionAdaptaRef = gestionAdaptaRef; ! } ! ! /** ! * setStreaming donne une referrence sur un objet Reencode ! * @param reencodeRef un objet de type Reencode ! */ ! public void setReencode(Reencode reencodeRef) { ! this.reencodeRef = reencodeRef; ! } ! ! } |
Update of /cvsroot/madsserv/madsserv/src/client In directory sc8-pr-cvs1:/tmp/cvs-serv21455 Modified Files: Client.java DialogServer.java DialogSocket.java MadsservClient.java ThreadRTPManager.java ThreadRead.java ThreadWrite.java Added Files: ErrorPopUp.java Log Message: Ajout d'une classe popup --- NEW FILE: ErrorPopUp.java --- import java.awt.*; import java.net.*; import java.awt.event.*; import java.awt.Component.*; import java.awt.TextComponent.*; import java.awt.geom.Point2D.*; import java.awt.Point.*; /** * <code>ErrorPopUp</code> est une popup qui apparait lorsque des erreurs apparaissent. * @author Xavier Deplancq */ public class ErrorPopUp extends Frame { private Container contentPane; private Panel panelNorth = new Panel(); private Panel panelSouth = new Panel(); private Label errorMessage = new Label(); private BorderLayout borderLayout1 = new BorderLayout(); private Button OK; /** * Constructeur de la classe ErrorPopUp * @param errMessage le Message qui doit etre affiche * @param _client la reference du client */ public ErrorPopUp(String errMessage, Client _client) { enableEvents(AWTEvent.WINDOW_EVENT_MASK); errorMessage.setText(errMessage); panelNorth.add(errorMessage); OK = new Button("OK"); OK.setSize(new Dimension(60, 15)); OK.addActionListener(new ErrorPopUp_OK_ActionAdapter(this)); panelSouth.add(OK); contentPane = this; this.setSize(220, 90); panelNorth.setBackground(new Color(236, 233, 216)); panelSouth.setBackground(new Color(236, 233, 216)); contentPane.setLayout(borderLayout1); contentPane.add(panelNorth, borderLayout1.CENTER); contentPane.add(panelSouth, borderLayout1.SOUTH); //On place la boite de dialogue Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension clientSize = _client.getSize(); Dimension popupSize = this.getSize(); double clientPlaceX = _client.getX(); double clientPlaceY = _client.getY(); if (popupSize.height > clientSize.height) { popupSize.height = clientSize.height; } if (popupSize.width > clientSize.width) { popupSize.width = clientSize.width; } this.setLocation( (int) (clientPlaceX) /*+ ( clientSize.height - popupSize.height) / 2*/, (int) (clientPlaceY) + clientSize.width / 2); showWindow(); } /** * OK_actionPerformed qui sert lorsque l'on appuie sur le bouton OK * @param e l'evenement */ public void OK_actionPerformed(ActionEvent e) { setVisible(false); } /** * processWindowEvent c est une methode qui est appele lorsque l'on ferme la boite de dialogue * @param l evenement qui indique que l'on ferme la fenetre */ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { OK_actionPerformed(null); } } /** * Methode qui affiche la boite de dialogue */ public void showWindow() { setVisible(true); } /** * Classe qui ecoute si l'on appui sur le bouton OK */ class ErrorPopUp_OK_ActionAdapter implements ActionListener { ErrorPopUp adaptee; ErrorPopUp_OK_ActionAdapter(ErrorPopUp adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.OK_actionPerformed(e); } } } Index: Client.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/Client.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Client.java 13 Mar 2003 02:38:49 -0000 1.5 --- Client.java 13 Mar 2003 23:27:35 -0000 1.6 *************** *** 11,29 **** /** ! * <p>Title: </p> ! * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: </p> ! * @author not attributable * @version 1.0 */ - /** - * <code>Client</code> permet de creer la fenetre principale du client Madsserv. - */ - - public class Client extends Frame { private Container contentPane; --- 11,27 ---- /** ! * <p>Title: Client </p> ! * <p>Description: La Classe Client est l'interface graphique du client</p> * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq * @version 1.0 */ public class Client extends Frame { + /** + * Champs de la Classe Reencode + */ private Container contentPane; *************** *** 58,63 **** private DialogServer dialogServer; /** ! * Contructeur de la classe <code>Client</code>. */ --- 56,63 ---- private DialogServer dialogServer; + + /** ! * Contructeur de la Classe Client */ *************** *** 74,81 **** /** ! * Insere un <code>PlayerPanel</code> dans l'interface graphique de <code>Client</code>. ! * @param pp le PlayerPanel insere. ! * @param vid un booleen caracterisant le caractere audio ou video du player insere par le <code>PlayerPanel</code>. */ public void setPlayerPanel(PlayerPanel pp, boolean vid) { Panel panelTemp; --- 74,82 ---- /** ! * setPlayerPanel crée l'interface graphique du Client ! * @param pp il s'agit d'un PlayerPanel qui est une classe que nous avons crée ! * @vid est un booleen qui nous dit si le player a cree est de la video ou de l'audio */ + public void setPlayerPanel(PlayerPanel pp, boolean vid) { Panel panelTemp; *************** *** 110,114 **** /** ! * Cree l'interface graphique. */ private void jbInit() throws Exception { --- 111,115 ---- /** ! * jbinit lance la creation de l'interface graphique. */ private void jbInit() throws Exception { *************** *** 119,124 **** this.setTitle("Madsserv Client"); setAfficheStatusBar("coucou"); ! URLChoice = new TextField("file:/stud/users/promo04/carbonel/tmp/video/kiss_cool_1.mpeg"); ! AdServer = new TextField("laplace.enst.fr:5100"); menuFile.setLabel("File"); menuOpenURL.setLabel("Open URL"); --- 120,125 ---- this.setTitle("Madsserv Client"); setAfficheStatusBar("coucou"); ! URLChoice = new TextField("file:///c:\\temp\\kiss_cool_1.mpeg"); ! AdServer = new TextField("dronej.rezel.com:5100"); menuFile.setLabel("File"); menuOpenURL.setLabel("Open URL"); *************** *** 165,171 **** AdLabel.setSize(new Dimension(30, 15)); AdServer.setSize(new Dimension(30, 15)); - go = new Button("Go!"); - go.setSize(new Dimension(60, 15)); - go.addActionListener(new Client_boutongo_ActionAdapter(this)); panelNorth.setLayout(gridBagLayoutNorth); --- 166,169 ---- *************** *** 193,198 **** /** ! * Traite l'evenement cree par le clic sur le menu Quitter. ! * @param l'evenement associe au clic sur le menu Quitter. */ public void menuFileExit_actionPerformed(ActionEvent e) { --- 191,196 ---- /** ! * menuFileExit_actionPerformed est à l'ecoute d'un evenement signifiant l'arret du client ! * @param e c'est l'evenemet qui met fin au client */ public void menuFileExit_actionPerformed(ActionEvent e) { *************** *** 208,211 **** --- 206,213 ---- } + /** + * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre + * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre + */ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); *************** *** 216,221 **** /** ! * Traite l'evenement cree par le clic sur le bouton Go. ! * @param evt l'evenement associe au clic sur le bouton Go. */ public void boutongo_actionPerformed(ActionEvent evt) { --- 218,223 ---- /** ! * boutongo_actionPerformed Methode qui permet de lancer la connexion lorsque l'on clique sur le bouton go ! * @param evt c'est l'evenement qui indique que l'on a clique sur le bouton go */ public void boutongo_actionPerformed(ActionEvent evt) { *************** *** 225,234 **** if (mySocket == null) { try { ! mySocket = new Socket(getAddressServer(), getServerPort() ! /*,InetAddress.getLocalHost(), 5020*/); } catch (Exception e) { ! System.out.println("Le serveur ou le port n'est pas correct"); ! System.exit(0); } --- 227,234 ---- if (mySocket == null) { try { ! mySocket = new Socket(getAddressServer(), getServerPort()); } catch (Exception e) { ! showError("Le serveur ou le port n'est pas correct"); } *************** *** 256,262 **** } - /** - * Supprime la connexion au serveur en stoppant le module <code>DialogServer</code>. - */ public void endConnexion() { dialogServer.stop(); --- 256,259 ---- *************** *** 264,270 **** } /** ! * Renvoie l'InetAddress du serveur. ! * @return l'InetAddress du serveur. */ public InetAddress getAddressServer() { --- 261,272 ---- } + public void showError(String messageErreur) + { + ErrorPopUp errorPopUp = new ErrorPopUp(messageErreur,this); + } + /** ! * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client ! * @return InetAddress du server */ public InetAddress getAddressServer() { *************** *** 284,289 **** /** ! * Renvoie le numero de port du serveur sur lequel il attends les connexions clients. ! * @return int le numero du port. */ public int getServerPort() { --- 286,291 ---- /** ! * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client ! * @return int le numero du port sur lequel, on doit se connecter au serveur */ public int getServerPort() { *************** *** 299,305 **** /** ! * Renvoie l'URL du fichier multimedia demande par l'utilisateur. ! * Cette URL est entree par l'intermediaire d'une zone de texte. ! * @return String l'adresse du media demande. */ public String getURL() { --- 301,306 ---- /** ! * getURL permet d'obtenir l'URL du fichier multimedia que l'on souhaite visionner, cet URL est rentre dans une zone de texte sur l'interface graphique du client ! * @return String l'adresse du media demande */ public String getURL() { *************** *** 308,316 **** } - /** - * Renvoie le format de diffusion prefere de l'utilisateur. - * Cete format est precise via l'interface graphique. - * @return String le format prefere. - */ public String getFormatPrefere() { --- 309,312 ---- *************** *** 331,336 **** /** ! * Met a jour la barre d'etats du client. ! * @param _message le message a afficher dans la barre d'etats. */ public void setAfficheStatusBar(String _message) { --- 327,332 ---- /** ! * setAfficheStatusBar est une methode qui permet d'afficher en bas du client un message envoye par le server ! * @param _message un message envoye sous forme de String envoye par le serveur */ public void setAfficheStatusBar(String _message) { *************** *** 338,341 **** --- 334,340 ---- } + /** + * Client_menuFileExit_ActionAdapter, classe qui ecoute pour savoir si on clique sur le menu exit et envoie alors l'evenement + */ class Client_menuFileExit_ActionAdapter implements ActionListener { *************** *** 351,354 **** --- 350,356 ---- } + /** + * Client_boutongo_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton go et envoie alors l'evenement + */ class Client_boutongo_ActionAdapter implements ActionListener { *************** *** 364,367 **** --- 366,372 ---- } + /** + * Client_Menu_OpenURL_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton OpenURL et envoie alors l'evenement + */ class Client_Menu_OpenURL_ActionAdapter implements ActionListener { Index: DialogServer.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/DialogServer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DialogServer.java 13 Mar 2003 02:38:49 -0000 1.4 --- DialogServer.java 13 Mar 2003 23:27:35 -0000 1.5 *************** *** 14,18 **** private ThreadRTPManager threadRTPManager; private String[] sessions = new String[2]; - ; /** * C'est le constructeur de la classe --- 14,17 ---- *************** *** 58,62 **** catch (NumberFormatException e) { System.out.println("Le deuxieme champ du message est incorrect"); - } --- 57,60 ---- *************** *** 70,74 **** } case 5: { ! // if (lgth < 2) raise exception; //lecture du deuxieme champ : ClientID try { --- 68,72 ---- } case 5: { ! //if (lgth < 2) raise exception; //lecture du deuxieme champ : ClientID try { *************** *** 77,93 **** catch (NumberFormatException e) { System.out.println("Le deuxieme champ du message est incorrect"); - - // try{ - System.out.println(_message[1]); - /*} - catch (NumberFormatException e) - { - System.out.println("Le troisieme champ du message est incorrect"); - }*/ } threadRTPManager.Fermer(); client.endConnexion(); System.out.println("coucou de fin"); - //System.out.println(mySocket.isClosed()); break; } --- 75,85 ---- catch (NumberFormatException e) { System.out.println("Le deuxieme champ du message est incorrect"); } + + client.showError(_message[1]); + threadRTPManager.Fermer(); client.endConnexion(); System.out.println("coucou de fin"); break; } *************** *** 104,108 **** /** ! *on regarde si le threadRTPManager existe, si iln'existe pas on le cree, sinon on le detruit et on en cree un nouveau */ if (threadRTPManager == null) { --- 96,100 ---- /** ! *on regarde si le threadRTPManager existe, si il n'existe pas on le cree, sinon on le detruit et on en cree un nouveau */ if (threadRTPManager == null) { *************** *** 140,145 **** System.out.println("Le troisieme champ du message est incorrect"); } /** ! * On stocke dans le variable sessions, l'adresse du server et les ports pour les diffusions audio et vdeo */ sessionTemp = client.getAddressServer().getHostAddress().toString(); --- 132,138 ---- System.out.println("Le troisieme champ du message est incorrect"); } + /** ! * On stocke dans le variable sessions, l'adresse du server et les ports pour les diffusions audio et video */ sessionTemp = client.getAddressServer().getHostAddress().toString(); Index: DialogSocket.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/DialogSocket.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DialogSocket.java 11 Mar 2003 20:06:53 -0000 1.1 --- DialogSocket.java 13 Mar 2003 23:27:36 -0000 1.2 *************** *** 1,94 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * C'est la classe DialogSocket ! */ ! public abstract class DialogSocket { ! ! // identite du client ! protected int clientID; ! ! // socket gere par DialogSocket ! protected Socket mySocket; ! ! // streams d'entree et de sortie ! protected PrintWriter output; ! protected InputStreamReader input; ! protected BufferedReader binput; ! ! ! // Thread d'entree et thread de sortie ! ThreadRead threadInput; ! ThreadWrite threadOutput; ! ! /** ! * Contructeur de la classe DialogSocket ! * @param _mySocket, c'est le socket qui vient juste d'etre cree ! */ ! public DialogSocket(Socket _mySocket) { ! mySocket = _mySocket; ! ! try { ! output = new PrintWriter(mySocket.getOutputStream()); ! input = new InputStreamReader(mySocket.getInputStream()); ! binput = new BufferedReader(input); ! ! threadInput = new ThreadRead("Thread d'ecoute ID", binput, this); ! } ! catch (IOException e) { ! System.out.println(e.getMessage()); ! } ! ! } ! /** ! * incomingMessage methode abstraite qui gere l'arrive de nouveau message ! * @param _type, c'est le type du message qui arrive ! * @param _message, c'est un tableau de String de messages qui arrivent ! */ ! public abstract void incomingMessage(int _type, String[] _message); ! ! /** ! * sendMessage methode qui gere l'envoie de messages vers le server ! * @param _type, c'est le type du message a envoye ! * @param _message, c'est un tableau de String contenant les messages pour le server ! */ ! public void sendMessage(int _type, String[] _message) { ! threadOutput = new ThreadWrite("Thread d'ecriture ID", output, this); ! String messageToSend[] = new String[_message.length + 1]; ! messageToSend[0] = String.valueOf(clientID); ! for (int i = 0; i < _message.length; i++) { ! messageToSend[i + 1] = _message[i]; ! } ! threadOutput.setMessageToSend(_type, messageToSend); ! threadOutput.start(); ! } ! ! /** ! * getClientID methode qui retourne le numero du client qui se connecte ! */ ! public int getClientID() { ! return clientID; ! } ! /** ! * start methode qui demarre le thread ! */ ! public void start() { ! threadInput.start(); ! } ! /** ! * stop methode qui mets fin au dialogue avec le serveur ! */ ! public synchronized void stop() { ! try { ! threadInput = null; ! System.gc(); ! binput.close(); ! mySocket.close(); ! System.out.println("Fin DialogServer " + clientID); ! } ! catch (Exception e) {} ! } ! } --- 1,142 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>DialogServer</code> fournit le modele d'objet permettant la gestion ! * de la communication par socket entre deux stations grace a deux threads ! * (lecture et ecriture). <code>DialogSocket</code> assure une communication ! * dediee. ! * <p> ! * <code>DialogServer</code> fournit une methode d'envoi de messages sur le ! * socket (par l'intermediaire de {@link ThreadWrite} et declare la methode ! * abstraite de reception des messages. ! * @see ThreadRead ! * @see ThreadWrite ! * @author Julien Carbonell ! */ ! ! public abstract class DialogSocket { ! ! private final int TIME_OUT = 1000; ! ! // identite du client ! protected int clientID; ! ! // socket gere par DialogSocket ! protected Socket mySocket; ! ! // streams d'entree et de sortie ! protected PrintWriter output; ! protected InputStreamReader input; ! protected BufferedReader binput; ! ! // Thread d'entree et thread de sortie ! protected ThreadRead threadInput; ! protected ThreadWrite threadOutput; ! ! /** ! * Constructeur de <code>DialogSocket</code>. ! * @param _mySocket le {@link Socket} de communication. ! */ ! ! public DialogSocket(Socket _mySocket) { ! mySocket = _mySocket; ! ! try { ! //mySocket.setSoTimeout(TIME_OUT); ! output = new PrintWriter(mySocket.getOutputStream()); ! input = new InputStreamReader(mySocket.getInputStream()); ! binput = new BufferedReader(input); ! ! threadInput = new ThreadRead("Thread d'ecoute ID", binput, this); ! } ! catch (IOException e) { ! System.out.println(e.getMessage()); ! } ! /*catch (SocketException e) { ! System.out.println(e.getMessage()); ! }*/ ! ! } ! ! /** ! * Traite l'arrivee d'un nouveau message sur le socket. ! * @param _type le type du message. ! * @param _message le tableau de <code>String</code> contenant les champs du ! * message reçu. ! */ ! ! public abstract void incomingMessage(int _type, String[] _message); ! ! /** ! * Traite la demande d'envoi d'un message sur le socket. Le message a envoyer ! * est fourni sous la forme d'un tableau de {@link String} contenant les ! * champs du message ! * @param _type le type du message. ! * @param _message le tableau de <code>String</code> contenant les champs du ! * message a envoyer. ! */ ! ! public void sendMessage(int _type, String[] _message) { ! threadOutput = new ThreadWrite("Thread d'ecriture ID", output, this); ! String[] messageToSend; ! if (_message == null) { ! messageToSend = new String[1]; ! messageToSend[0] = String.valueOf(clientID); ! } ! else { ! messageToSend = new String[_message.length + 1]; ! messageToSend[0] = String.valueOf(clientID); ! for (int i = 0; i < _message.length; i++) { ! messageToSend[i + 1] = _message[i]; ! } ! } ! threadOutput.setMessageToSend(_type, messageToSend); ! threadOutput.start(); ! ! } ! ! /** ! * Renvoie l'ID du client. ! * @return ID du client. ! */ ! ! public int getClientID() { ! return clientID; ! } ! ! /** ! * Demarre l'ecoute du socket ! */ ! ! public void start() { ! threadInput.start(); ! } ! ! /** ! * Stoppe le gestion de la communication et ferme le socket. ! */ ! ! public synchronized void stop() { ! try { ! System.err.println("j'entre dans le stop de dialog socket"); ! //threadInput = null; ! //System.gc(); ! ! //threadInput.interrupt(); ! //threadInput.setEnd(); ! System.err.println("le thread est mort"); ! Thread.sleep(1000); ! //binput.close(); ! //System.err.println("le binput est mort"); ! if (!mySocket.isClosed()) ! mySocket.close(); ! System.err.println("le socket est mort"); ! //System.err.println("le socket est ferme " + mySocket.isClosed()); ! System.out.println("Fin DialogServer " + clientID); ! } ! catch (Exception e) {} ! } ! } Index: MadsservClient.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/MadsservClient.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MadsservClient.java 11 Mar 2003 20:06:53 -0000 1.3 --- MadsservClient.java 13 Mar 2003 23:27:36 -0000 1.4 *************** *** 6,14 **** /** ! * <p>Title: </p> ! * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: </p> ! * @author not attributable * @version 1.0 **/ --- 6,14 ---- /** ! * <p>Title: MadsservClient</p> ! * <p>Description: La Classe MadsservClient contient la classe main du client du projet, c'est lui qui le lance</p> * <p>Copyright: Copyright (c) 2003</p> ! * <p>Company: Madsserv Corporation</p> ! * @author Xavier Deplancq * @version 1.0 **/ *************** *** 22,31 **** */ private boolean packFrame = false; - //private Socket mySocket; /** * MadsservClient constructeur de la calsse */ ! public MadsservClient( /*String sessions[]*/) { Client frame = new Client(); --- 22,30 ---- */ private boolean packFrame = false; /** * MadsservClient constructeur de la calsse */ ! public MadsservClient() { Client frame = new Client(); *************** *** 37,46 **** } else { - // String[] request = new String[1]; - // request[0] = ""; frame.validate(); - // dialogServer.start(); - // dialogServer.sendMessage(0,request); - // threadRTPManager.start(); } --- 36,40 ---- *************** *** 60,64 **** /** ! * Methode main du client */ --- 54,58 ---- /** ! * Methode main de MadsservClient */ Index: ThreadRTPManager.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRTPManager.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ThreadRTPManager.java 13 Mar 2003 02:38:49 -0000 1.4 --- ThreadRTPManager.java 13 Mar 2003 23:27:36 -0000 1.5 *************** *** 38,42 **** Thread.sleep(1000); } ! catch (Exception e) {} finally { --- 38,44 ---- Thread.sleep(1000); } ! catch (Exception e) { ! cl.showError("La connexion n'a pas pu etre initialise"); ! } finally { *************** *** 44,48 **** System.err.println("Exiting ThreadRTPManager"); System.out.println(Thread.currentThread()); - } } --- 46,49 ---- Index: ThreadRead.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRead.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ThreadRead.java 11 Mar 2003 20:06:53 -0000 1.1 --- ThreadRead.java 13 Mar 2003 23:27:36 -0000 1.2 *************** *** 4,16 **** /** ! * classe ThreadRead qui permet de lire ce qui circule sur le socket */ public class ThreadRead extends Thread { // objet parent qui gere les entrees-sorties sur le socket protected DialogSocket parent; ! // inputstream sur lequel sont lus les messages protected BufferedReader binput; --- 4,26 ---- /** ! * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. ! * Il effectue une ecoute permanente. ! * <p> ! * Il gere l'extraction du message en isolant les elements protocolaires de la ! * transmission du message. ! * @see ThreadWrite ! * @see DialogSocket ! * @author Julien Carbonell */ + public class ThreadRead extends Thread { + boolean end = false; + // objet parent qui gere les entrees-sorties sur le socket protected DialogSocket parent; ! // BufferedReader sur lequel sont lus les messages protected BufferedReader binput; *************** *** 21,25 **** /** ! * Constructeur de la classe */ public ThreadRead(String _name, BufferedReader _binput, --- 31,38 ---- /** ! * Constructeur de <code>ThreadRead</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. */ public ThreadRead(String _name, BufferedReader _binput, *************** *** 29,34 **** binput = _binput; } /** ! * la methode run du thread */ public void run() { --- 42,48 ---- binput = _binput; } + /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. */ public void run() { *************** *** 36,61 **** while ( (temp = binput.readLine()) != null) { if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; ! } ! else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; } else { ! message = message.concat(temp + "\n"); } } } } ! } catch (Exception e) { e.printStackTrace(); --- 50,79 ---- while ( (temp = binput.readLine()) != null) { if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; } else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; ! } ! else { ! message = message.concat(temp + "\n"); ! } } } + } } ! /* catch (SocketTimeoutException e) { ! System.out.println(e.getMessage()); ! }*/ catch (Exception e) { e.printStackTrace(); *************** *** 63,79 **** finally { try { System.out.println(getName() + Thread.currentThread() + " : Stopped !!! "); } catch (Exception e) { } } } ! /** ! * parseMessage, methode qui retourne un tableau de String ! * @param _message qui est une chaine de characteres ! * @return String[] ! */ protected String[] parseMessage(String _message) { return _message.split("\n"); --- 81,95 ---- finally { try { + // binput.close(); System.out.println(getName() + Thread.currentThread() + " : Stopped !!! "); } catch (Exception e) { + System.out.println(e.getMessage()); } } } ! protected String[] parseMessage(String _message) { return _message.split("\n"); Index: ThreadWrite.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadWrite.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ThreadWrite.java 11 Mar 2003 20:06:53 -0000 1.1 --- ThreadWrite.java 13 Mar 2003 23:27:37 -0000 1.2 *************** *** 4,15 **** /** ! * classe ThreadWrite, cette classe permet d'ecrire sur le socket */ public class ThreadWrite extends Thread { - /** - * champs de cette classe - */ // objet parent qui gere les entrees-sorties sur le socket protected DialogSocket parent; --- 4,20 ---- /** ! * <code>ThreadWrite</code> definit un thread d'ecriture sur un {@link PrintWriter}. ! * Sa duree d'execution est celle de l'envoi d'un message. ! * <p> ! * Il gere l'encapsulation du message en ajoutant les elements protocolaires de la ! * transmission du message. ! * @see ThreadRead ! * @see DialogSocket ! * @author Julien Carbonell */ + public class ThreadWrite extends Thread { // objet parent qui gere les entrees-sorties sur le socket protected DialogSocket parent; *************** *** 21,25 **** /** ! * Constructeur de la classe */ public ThreadWrite(String _name, PrintWriter _output, --- 26,33 ---- /** ! * Constructeur de <code>ThreadWrite</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link PrinterWriter} sur lequel ecrit <code>ThreadWrite</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadWrite</code>. */ public ThreadWrite(String _name, PrintWriter _output, *************** *** 31,48 **** // met a jour le message a envoyer - /** - * setMessageToSend methode permettant de foramter le message a envoyer - * @param _type un entier donnant le type de message a envoyer - * @String[] _message un tableau de String[] qui contient les messages a envoyer au serveur - */ public synchronized void setMessageToSend(int _type, String[] _message) { ! messageToSend = ""; messageToSend = _type + "\n"; ! for (int i = 0; i < _message.length; i++) { messageToSend = messageToSend.concat(_message[i] + "\n"); } } /** ! * methode run de ce Thread */ public void run() { --- 39,52 ---- // met a jour le message a envoyer public synchronized void setMessageToSend(int _type, String[] _message) { ! messageToSend=""; messageToSend = _type + "\n"; ! for(int i = 0; i< _message.length; i++) { messageToSend = messageToSend.concat(_message[i] + "\n"); } } + /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. */ public void run() { *************** *** 50,70 **** if (messageToSend.compareTo("") != 0) { System.out.println("Message envoye par le thread output " + "#\n" + ! messageToSend + "#"); ! output.println("#\n" + messageToSend + "#"); ! output.flush(); ! } ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! finally { ! try { ! System.out.println(getName() + Thread.currentThread() + ! " : Stopped !!! "); ! } ! catch (Exception e) { ! } ! } ! } } --- 54,74 ---- if (messageToSend.compareTo("") != 0) { System.out.println("Message envoye par le thread output " + "#\n" + ! messageToSend + "#"); ! output.println("#\n" + messageToSend + "#"); ! output.flush(); ! } ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! finally { ! try { ! System.out.println(getName() + Thread.currentThread() + ! " : Stopped !!! "); ! } ! catch (Exception e) { ! } ! } ! } } |
Update of /cvsroot/madsserv/madsserv/src/server In directory sc8-pr-cvs1:/tmp/cvs-serv15336/src/server Modified Files: DialogClient.java DialogSocket.java ServerInit.java ThreadListenClients.java ThreadRead.java ThreadWrite.java Log Message: Probleme de fermeture des threads regle Index: DialogClient.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/DialogClient.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DialogClient.java 9 Mar 2003 23:52:30 -0000 1.3 --- DialogClient.java 13 Mar 2003 02:38:49 -0000 1.4 *************** *** 1,53 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! public class DialogClient ! extends DialogSocket { ! ! private ServerInit serverInit; ! ! public DialogClient(int _clientID, Socket _socketClient, ! ServerInit _serverInit) { ! super(_socketClient); ! serverInit = _serverInit; ! clientID = _clientID; ! ! if (clientID != -1) { ! serverInit.setIP(clientID, ! mySocket.getInetAddress().getHostAddress().toString()); ! ! } ! } ! ! public void incomingMessage(int _type, String[] _message) { ! int lgth = _message.length; ! ! // if (lgth == 0) raise exception; ! if (Integer.parseInt(_message[0]) == clientID) { ! ! switch (_type) { ! case 2: { ! // if (lgth < 3) raise exception; ! serverInit.setMediaAddress(clientID, _message[1]); ! System.out.println("Nouvelle URL pour le client " + clientID + ": " + ! _message[1]); ! ! serverInit.setPreferredFormat(clientID, _message[2]); ! System.out.println("Nouveau format prefere pour le client " + ! clientID + ": " + _message[2]); ! break; ! } ! case 4: { ! serverInit.endConnexion(clientID); ! break; ! } ! } ! ! } ! else { ! System.out.println("Le message recu ne correspond pas au bon client"); ! } ! } ! } --- 1,91 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>DialogClient</code> gere la communication par socket du serveur vers le ! * client grace a deux threads (lecture et ecriture). <code>DialogClient</code> ! * est dedie a un client. ! * <p> ! * <code>DialogClient</code> fournit des methodes d'envoi de message et de ! * reception de message en utilisant des threads de classe {@link ThreadRead} et ! * {@link ThreadWrite} pour acceder au socket. ! * @see DialogSocket ! * @see ThreadRead ! * @see ThreadWrite ! * @author Julien Carbonell ! */ ! ! public class DialogClient ! extends DialogSocket { ! ! // reference sur l'objet parent de classe ServerInit ! private ServerInit serverInit; ! ! /* Reference sur l'objet de classe ServerInit initialement lance ! private ServerInit serverInit; ! // References sur les trois modules de traitement de la requete ! private Streaming myStreaming; ! private Reencode myReencode; ! private Transition myTransition;*/ ! ! /** ! * Constructeur de <code>DialogClient</code> ! * @param _clientID ID du client auquel est dedie <code>DialogClient</code>. ! * @param _socketClient le {@link Socket} de communication avec le client. ! * @param _serverInit le {@link ServerInit} parent. ! */ ! ! public DialogClient(int _clientID, Socket _socketClient, ! ServerInit _serverInit) { ! super(_socketClient); ! serverInit = _serverInit; ! clientID = _clientID; ! ! if (clientID != -1) { ! serverInit.setIP(clientID, ! mySocket.getInetAddress().getHostAddress().toString()); ! } ! } ! ! /** ! * Traite l'arrivee d'un nouveau message sur le socket. Le message passe en ! * parametre de <code>incomingMessage</code> est deja pre-formate sous forme ! * d'un tableau de {@link String}. ! * @param _type le type du message. ! * @param _message le tableau de <code>String</code> contenant les champs du ! * message reçu. ! */ ! ! public void incomingMessage(int _type, String[] _message) { ! int lgth = _message.length; ! ! // if (lgth == 0) raise exception; ! if (Integer.parseInt(_message[0]) == clientID) { ! ! switch (_type) { ! case 2: { ! // if (lgth < 3) raise exception; ! serverInit.setMediaAddress(clientID, _message[1]); ! System.out.println("Nouvelle URL pour le client " + clientID + ": " + ! _message[1]); ! ! serverInit.setPreferredFormat(clientID, _message[2]); ! System.out.println("Nouveau format prefere pour le client " + ! clientID + ": " + _message[2]); ! sendMessage(3, null); ! serverInit.startStreaming(clientID); ! break; ! } ! case 4: { ! serverInit.endConnexion(clientID); ! break; ! } ! } ! ! } ! else { ! System.out.println("Le message recu ne correspond pas au bon client"); ! } ! } } Index: DialogSocket.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/DialogSocket.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DialogSocket.java 9 Mar 2003 23:52:30 -0000 1.1 --- DialogSocket.java 13 Mar 2003 02:38:49 -0000 1.2 *************** *** 1,77 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! public abstract class DialogSocket { ! ! // identite du client ! protected int clientID; ! ! // socket gere par DialogSocket ! protected Socket mySocket; ! ! // streams d'entree et de sortie ! protected PrintWriter output; ! protected InputStreamReader input; ! protected BufferedReader binput; ! ! /* Reference sur l'objet de classe ServerInit initialement lance ! private ServerInit serverInit; ! // References sur les trois modules de traitement de la requete ! private Streaming myStreaming; ! private Reencode myReencode; ! private Transition myTransition;*/ ! ! // Thread d'entree et thread de sortie ! ThreadRead threadInput; ! ThreadWrite threadOutput; ! ! public DialogSocket(Socket _mySocket) { ! mySocket = _mySocket; ! ! try { ! output = new PrintWriter(mySocket.getOutputStream()); ! input = new InputStreamReader(mySocket.getInputStream()); ! binput = new BufferedReader(input); ! ! threadInput = new ThreadRead("Thread d'ecoute ID", binput, this); ! } ! catch (IOException e) { ! System.out.println(e.getMessage()); ! } ! ! } ! ! public abstract void incomingMessage(int _type, String[] _message); ! ! public void sendMessage(int _type, String[] _message) { ! threadOutput = new ThreadWrite("Thread d'ecriture ID", output, this); ! String messageToSend[] = new String[_message.length + 1]; ! messageToSend[0] = String.valueOf(clientID); ! for (int i = 0; i < _message.length; i++) { ! messageToSend[i + 1] = _message[i]; ! } ! threadOutput.setMessageToSend(_type, messageToSend); ! threadOutput.start(); ! } ! ! public int getClientID() { ! return clientID; ! } ! ! public void start() { ! threadInput.start(); ! } ! ! public synchronized void stop() { ! try { ! threadInput = null; ! System.gc(); ! binput.close(); ! mySocket.close(); ! System.out.println("Fin DialogServer " + clientID); ! } ! catch (Exception e) {} ! } ! } --- 1,142 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * <code>DialogServer</code> fournit le modele d'objet permettant la gestion ! * de la communication par socket entre deux stations grace a deux threads ! * (lecture et ecriture). <code>DialogSocket</code> assure une communication ! * dediee. ! * <p> ! * <code>DialogServer</code> fournit une methode d'envoi de messages sur le ! * socket (par l'intermediaire de {@link ThreadWrite} et declare la methode ! * abstraite de reception des messages. ! * @see ThreadRead ! * @see ThreadWrite ! * @author Julien Carbonell ! */ ! ! public abstract class DialogSocket { ! ! private final int TIME_OUT = 1000; ! ! // identite du client ! protected int clientID; ! ! // socket gere par DialogSocket ! protected Socket mySocket; ! ! // streams d'entree et de sortie ! protected PrintWriter output; ! protected InputStreamReader input; ! protected BufferedReader binput; ! ! // Thread d'entree et thread de sortie ! protected ThreadRead threadInput; ! protected ThreadWrite threadOutput; ! ! /** ! * Constructeur de <code>DialogSocket</code>. ! * @param _mySocket le {@link Socket} de communication. ! */ ! ! public DialogSocket(Socket _mySocket) { ! mySocket = _mySocket; ! ! try { ! //mySocket.setSoTimeout(TIME_OUT); ! output = new PrintWriter(mySocket.getOutputStream()); ! input = new InputStreamReader(mySocket.getInputStream()); ! binput = new BufferedReader(input); ! ! threadInput = new ThreadRead("Thread d'ecoute ID", binput, this); ! } ! catch (IOException e) { ! System.out.println(e.getMessage()); ! } ! /*catch (SocketException e) { ! System.out.println(e.getMessage()); ! }*/ ! ! } ! ! /** ! * Traite l'arrivee d'un nouveau message sur le socket. ! * @param _type le type du message. ! * @param _message le tableau de <code>String</code> contenant les champs du ! * message reçu. ! */ ! ! public abstract void incomingMessage(int _type, String[] _message); ! ! /** ! * Traite la demande d'envoi d'un message sur le socket. Le message a envoyer ! * est fourni sous la forme d'un tableau de {@link String} contenant les ! * champs du message ! * @param _type le type du message. ! * @param _message le tableau de <code>String</code> contenant les champs du ! * message a envoyer. ! */ ! ! public void sendMessage(int _type, String[] _message) { ! threadOutput = new ThreadWrite("Thread d'ecriture ID", output, this); ! String[] messageToSend; ! if (_message == null) { ! messageToSend = new String[1]; ! messageToSend[0] = String.valueOf(clientID); ! } ! else { ! messageToSend = new String[_message.length + 1]; ! messageToSend[0] = String.valueOf(clientID); ! for (int i = 0; i < _message.length; i++) { ! messageToSend[i + 1] = _message[i]; ! } ! } ! threadOutput.setMessageToSend(_type, messageToSend); ! threadOutput.start(); ! ! } ! ! /** ! * Renvoie l'ID du client. ! * @return ID du client. ! */ ! ! public int getClientID() { ! return clientID; ! } ! ! /** ! * Demarre l'ecoute du socket ! */ ! ! public void start() { ! threadInput.start(); ! } ! ! /** ! * Stoppe le gestion de la communication et ferme le socket. ! */ ! ! public synchronized void stop() { ! try { ! System.err.println("j'entre dans le stop de dialog socket"); ! //threadInput = null; ! //System.gc(); ! ! //threadInput.interrupt(); ! //threadInput.setEnd(); ! System.err.println("le thread est mort"); ! Thread.sleep(1000); ! //binput.close(); ! //System.err.println("le binput est mort"); ! if (!mySocket.isClosed()) ! mySocket.close(); ! System.err.println("le socket est mort"); ! //System.err.println("le socket est ferme " + mySocket.isClosed()); ! System.out.println("Fin DialogServer " + clientID); ! } ! catch (Exception e) {} ! } ! } Index: ServerInit.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/ServerInit.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ServerInit.java 8 Mar 2003 23:58:19 -0000 1.4 --- ServerInit.java 13 Mar 2003 02:38:49 -0000 1.5 *************** *** 4,7 **** --- 4,8 ---- import java.awt.*; import javax.media.rtp.*; + import javax.media.*; /////////////////////////////////////////////////////// *************** *** 14,53 **** ////////////////////////////////////////////////////// public class ServerInit { // tabClients enregistre l'ensemble des clients connectes ! private ClientRecord [] tabClients; // tabDialog enregistre les objets de gestion des clients lances par Server a chaque nouvelle connexion ! private DialogClient [] tabDialogs; // tabStreaming enregistre les objets Streaming associes aux clients ! private Streaming [] tabStreaming; // tabReencode enregistre les objets Reencode associes aux clients ! private Reencode [] tabReencode; // tabTransition enregistre les objets Transition associes aux clients ! private Transition [] tabTransition; // Reference sur le gestionnnaire d'adaptabilite ! //private Adapt adapt; // Reference sur le thread d'ecoute des clients ! private ThreadListenClients threadListenClients; // Parametres de connexion du serveur private int portListen; ! private int debitMax; private int nbMaxClients; ! // Sockets ! private ServerSocket sockEcou; ! private Socket sockComm; // Interface graphique ! ! ! public ServerInit(int _portListen, int _nbMaxClients, int _debitMax) { portListen = _portListen; nbMaxClients = _nbMaxClients; ! debitMax = _debitMax; tabClients = new ClientRecord[nbMaxClients]; --- 15,77 ---- ////////////////////////////////////////////////////// + /** + * <code>ServerInit</code> constitue la classe de demarrage du serveur Madsserv. + * Elle gere les connexions multiples de clients ainsi que l'instanciation des + * modules necessaires au traitement des requetes de diffusion media. + * @see Streaming + * @see Reencode + * @see Transition + * @see GestionAdapta + * @see DialogClient + * @author Julien Carbonell + */ + public class ServerInit { + ProcessorTest processor; + // tabClients enregistre l'ensemble des clients connectes ! private ClientRecord[] tabClients; // tabDialog enregistre les objets de gestion des clients lances par Server a chaque nouvelle connexion ! private DialogClient[] tabDialogs; // tabStreaming enregistre les objets Streaming associes aux clients ! private Streaming[] tabStreaming; // tabReencode enregistre les objets Reencode associes aux clients ! private Reencode[] tabReencode; // tabTransition enregistre les objets Transition associes aux clients ! private Transition[] tabTransition; // Reference sur le gestionnnaire d'adaptabilite ! //private GestionAdapta gestionAdapta; // Reference sur le thread d'ecoute des clients ! private ThreadListenClients threadListenClients = null; // Parametres de connexion du serveur private int portListen; ! private int portBaseRTP; ! private int debitMin; private int nbMaxClients; ! // Socket d'ecoute clients ! private ServerSocket sockListen = null; // Interface graphique + private ServerFrame serverFrame = null; ! /** ! * Constructeur de <code>ServerInit</code>. ! * @param _portListen le port d'ecoute du serveur. ! * @param _portBaseRTP le port de base a partir duquel sont deduits l'ensemble des ports necessaires a la creation des connexions RTP. ! * @param _nbMaxCliens le nombre maximum de clients acceptes par le serveur. ! * @param _debitMin le debit minimum en-dessous duquel le client est deconnecte. ! */ ! public ServerInit(int _portListen, int _portBaseRTP, int _nbMaxClients, ! int _debitMin, ServerFrame _serverFrame) { portListen = _portListen; + portBaseRTP = _portBaseRTP; nbMaxClients = _nbMaxClients; ! debitMin = _debitMin; ! serverFrame = _serverFrame; tabClients = new ClientRecord[nbMaxClients]; *************** *** 57,61 **** tabTransition = new Transition[nbMaxClients]; ! //adapt = new Adapt(......); //frame = new MainFrame(......); --- 81,85 ---- tabTransition = new Transition[nbMaxClients]; ! //gestionAdapta = new GestionAdapta(......); //frame = new MainFrame(......); *************** *** 63,75 **** } ! public void start() { ! threadListenClients = new ThreadListenClients(this, portListen); ! threadListenClients.start(); } public void stop() { ! // threadListenClients.stop(); } public void endConnexion(int _clientID) { String[] warning = new String[1]; --- 87,118 ---- } ! /** ! * Ouvre le socket d'ecoute et demarre l'attente de connexions. ! */ ! public void start() throws ErrNoListen { ! ! try { ! sockListen = new ServerSocket(portListen); ! threadListenClients = new ThreadListenClients(this, sockListen, portListen); ! threadListenClients.start(); ! } ! catch (Exception e) { ! sockListen=null; ! threadListenClients = null; ! throw new ErrNoListen(); ! } } + /** + * Arrete le serveur. + */ public void stop() { ! threadListenClients.close(); } + /** + * Deconnecte un client en effaçant tous les objets relatifs au traitement de sa connexion. + * @param _clientID l'ID du client a deconnecter. + */ public void endConnexion(int _clientID) { String[] warning = new String[1]; *************** *** 77,144 **** warning[0] = "Attention je detruis la connexion du client 0"; System.out.println("Envoi du message " + warning[0]); ! tabDialogs[_clientID].sendMessage(3, warning); ! /* tabStreaming[_clientID].stop(); ! tabReencode[_clientID].stop(); ! tabTransition[_clientID].stop(); tabStreaming[_clientID] = null; ! tabReencode[_clientID] = null; ! tabReencode[_clientID] = null;*/ System.out.println("Suppression du client " + _clientID); tabClients[_clientID] = null; tabDialogs[_clientID].stop(); ! System.out.println("le client " + _clientID + " est mort -ref=" + tabClients[_clientID]); ! tabDialogs[_clientID]=null; } public String getIP(int _clientID) { return (tabClients[_clientID].getIP()); } ! public int getPortBaseRTP(int _clientID) { ! return(tabClients[_clientID].getPortBaseRTP()); ! } ! ! /*public SessionAddress getServerSA(int _clientID) { ! return (tabClients[_clientID].getServerSA()); } ! public SessionAddress getClientSA(int _clientID) { ! return (tabClients[_clientID].getClientSA()); ! }*/ ! public String getMediaAddress(int _clientID) { return (tabClients[_clientID].getMediaAddress()); } public int getQualityLevel(int _clientID) { return (tabClients[_clientID].getQualityLevel()); } public synchronized void setIP(int _clientID, String _IP) { tabClients[_clientID].setIP(_IP); } ! public synchronized void setPortBaseRTP(int _clientID, int _portBaseRTP) { ! tabClients[_clientID].setPortBaseRTP(_portBaseRTP); ! } ! ! /*public synchronized void setServerSA(int _clientID, SessionAddress _serverSA) { ! tabClients[_clientID].setServerSA(_serverSA); } ! public synchronized void setClientSA(int _clientID, SessionAddress _clientSA) { ! tabClients[_clientID].setClientSA(_clientSA); ! }*/ ! public synchronized void setMediaAddress(int _clientID, String _mediaAddress) { tabClients[_clientID].setMediaAddress(_mediaAddress); } ! public synchronized void setPreferredFormat(int _clientID, String _preferredFormat) { tabClients[_clientID].setPreferredFormat(_preferredFormat); } ! public synchronized void setQualityLevel(int _clientID, int _qualityLevel) { tabClients[_clientID].setQualityLevel(_qualityLevel); --- 120,228 ---- warning[0] = "Attention je detruis la connexion du client 0"; System.out.println("Envoi du message " + warning[0]); ! tabDialogs[_clientID].sendMessage(5, warning); ! tabStreaming[_clientID].stop(); tabStreaming[_clientID] = null; ! /*tabReencode[_clientID].stop(); ! tabTransition[_clientID].stop(); ! tabReencode[_clientID] = null; ! tabReencode[_clientID] = null;*/ System.out.println("Suppression du client " + _clientID); tabClients[_clientID] = null; tabDialogs[_clientID].stop(); ! System.out.println("le client " + _clientID + " est mort -ref=" + ! tabClients[_clientID]); ! tabDialogs[_clientID] = null; ! System.err.println("Garbage collecting de endConnexion"); ! System.gc(); } + /** + * Renvoie l'IP d'un client. + * @param _clientID l'ID du client. + * @return l'adresse IP du client. + */ public String getIP(int _clientID) { return (tabClients[_clientID].getIP()); } ! /** ! * Renvoie le port RTP de base affecte au client. ! * @param _clientID l'ID du client. ! * @return le port RTP de base affecte au client. ! */ ! public int getPortRTP(int _clientID) { ! return (tabClients[_clientID].getPortRTP()); } ! /** ! * Renvoie l'adresse du media demande par le client. ! * @param _clientID l'ID du client. ! * @return l'adresse du media demande par le client. ! */ public String getMediaAddress(int _clientID) { return (tabClients[_clientID].getMediaAddress()); } + /** + * Renvoie le format de diffusion prefere par le client. + * @param _clientID l'ID du client. + * @return le format de diffusion prefere par le client. + */ + public String getPreferredFormat(int _clientID) { + return (tabClients[_clientID].getPreferredFormat()); + } + + /** + * Renvoie le niveau de qualité courant associé au client. + * @param _clientID l'ID du client. + * @return le niveau de qualite courant associe au client. + */ public int getQualityLevel(int _clientID) { return (tabClients[_clientID].getQualityLevel()); } + /** + * Modifie l'IP d'un client. + * @param _clientID l'ID du client. + * @param _IP la nouvelle IP. + */ public synchronized void setIP(int _clientID, String _IP) { tabClients[_clientID].setIP(_IP); } ! /** ! * Modifie le port RTP de base d'un client. ! * @param _clientID l'ID du client. ! * @param _IP le nouveau port RTP de base. ! */ ! public synchronized void setPortRTP(int _clientID, int _portBaseRTP) { ! tabClients[_clientID].setPortRTP(_portBaseRTP); } ! /** ! * Modifie l'adresse du media demande par le client. ! * @param _clientID l'ID du client. ! * @param _IP la nouvelle adresse du media demande par le client. ! */ public synchronized void setMediaAddress(int _clientID, String _mediaAddress) { tabClients[_clientID].setMediaAddress(_mediaAddress); } ! /** ! * Modifie le format prefere d'un client. ! * @param _clientID l'ID du client. ! * @param _IP la nouvelle IP. ! */ ! public synchronized void setPreferredFormat(int _clientID, ! String _preferredFormat) { tabClients[_clientID].setPreferredFormat(_preferredFormat); } ! /** ! * Modifie le niveau de qualite courant d'un client. ! * @param _clientID l'ID du client. ! * @param _IP la nouveau niveau de qualite. ! */ public synchronized void setQualityLevel(int _clientID, int _qualityLevel) { tabClients[_clientID].setQualityLevel(_qualityLevel); *************** *** 148,183 **** // retourne (-1) si trop de clients public synchronized int createClient() { boolean inserted = false; int i = 0; ! while ((inserted==false) && (i<nbMaxClients)) { if (tabClients[i] == null) { ! tabClients[i] = new ClientRecord(); ! tabClients[i].setClientID(i); ! inserted = true; ! } ! i++; ! } ! if (inserted) return (i-1); ! else return (-1); ! } ! public synchronized int createClient(String _IP, /*SessionAddress _serverSA, ! SessionAddress _serverSA,*/ int _portBaseRTP, String _mediaAddress, ! String _preferredFormat, int _qualityLevel) { boolean inserted = false; int i = 0; ! while ((inserted==false) && (i<nbMaxClients)) { if (tabClients[i] == null) { ! tabClients[i] = new ClientRecord(i, _IP, _portBaseRTP, _mediaAddress, _preferredFormat, _qualityLevel); inserted = true; } i++; } ! if (inserted) return (i-1); ! else return (-1); } ! public synchronized DialogClient createDialogClient(int _clientID, Socket _sockClient) { if (_clientID == -1) { DialogClient tempDialog = new DialogClient(_clientID, _sockClient, this); --- 232,301 ---- // retourne (-1) si trop de clients + /** + * Cree un nouveau client avec une ID et un numero de port RTP. La creation d'un + * client est accompagnee par la creation des 3 modules de traitement des + * requetes client ({@link Streaming}, {@link Reencode} et {@link Transiton}). + * @return l'ID du client. Vaut <code>-1</code> si le nombre maximum de clients + * est deja atteint (creation d'un nouveau client impossible). + */ public synchronized int createClient() { boolean inserted = false; int i = 0; ! while ( (inserted == false) && (i < nbMaxClients)) { if (tabClients[i] == null) { ! tabClients[i] = new ClientRecord(); ! tabClients[i].setClientID(i); ! inserted = true; ! } ! i++; ! } ! if (inserted) { ! tabClients[i - 1].setPortRTP(portBaseRTP + 2 * (i - 1)); ! tabStreaming[i - 1] = new Streaming(i - 1, this); ! return (i - 1); ! } ! else { ! return ( -1); ! } ! } ! /** ! * Cree un nouveau client a partir des arguments fournis. La creation d'un ! * client est accompagnee par la creation des 3 modules de traitement des ! * requetes client ({@link Streaming}, {@link Reencode} et {@link Transiton}). ! * @return l'ID du client. Vaut <code>-1</code> si le nombre maximum de clients ! * est deja atteint (creation d'un nouveau client impossible). ! */ ! public synchronized int createClient(String _IP, int _portBaseRTP, ! String _mediaAddress, ! String _preferredFormat, ! int _qualityLevel) { boolean inserted = false; int i = 0; ! while ( (inserted == false) && (i < nbMaxClients)) { if (tabClients[i] == null) { ! tabClients[i] = new ClientRecord(i, _IP, _portBaseRTP, _mediaAddress, ! _preferredFormat, _qualityLevel); inserted = true; } i++; } ! if (inserted) { ! return (i - 1); ! } ! else { ! return ( -1); ! } } ! /** ! * Cree un nouveau <code>DialogClient</code> pour gerer la communication avec ! * un client. ! * @param _clientID l'ID du client. ! * @param _socketClient le {@link Socket} dedie a la communication avec le client. ! * @return le <code>DialogClient</code> cree. ! */ ! public synchronized DialogClient createDialogClient(int _clientID, ! Socket _sockClient) { if (_clientID == -1) { DialogClient tempDialog = new DialogClient(_clientID, _sockClient, this); *************** *** 190,193 **** --- 308,340 ---- } + /** + * Demarre la diffusion du media demande pour un client donne. + * @param _clientID l'ID du client. + */ + public synchronized void startStreaming(int _clientID) { + Streaming streamingTemp = tabStreaming[_clientID]; + + streamingTemp.setClientIP(getIP(_clientID)); + streamingTemp.setClientPort(getPortRTP(_clientID)); + System.out.println("Le streaming a recu " + getIP(_clientID) + " et " + + getPortRTP(_clientID)); + //streamingTemp.setMediaAddress(getMediaAddress(_clientID)); + if (!streamingTemp.isInitialized()) { + streamingTemp.initialize(); + } + System.out.println("Le streaming est initialise"); + processor = new ProcessorTest(new MediaLocator(getMediaAddress(_clientID)), + streamingTemp); + System.out.println("Le processor est cree"); + // D�marrage du ProcessorTest + processor.start(); + System.out.println("Le processeur a demarre"); + + // On fournit la DataSource � diffuser + streamingTemp.setNewStreams(processor.getOutput()); + System.out.println("Le streaming a recu les nouveaux streams"); + + } + } *************** *** 196,202 **** private int clientID; private String IP; ! // private SessionAddress serverSA; ! // private SessionAddress clientSA; ! private int portBaseRTP; private String mediaAddress; private String preferredFormat; --- 343,347 ---- private int clientID; private String IP; ! private int portRTP; private String mediaAddress; private String preferredFormat; *************** *** 206,218 **** clientID = -1; IP = ""; ! // serverSA = null; ! // clientSA = null; ! portBaseRTP = 40000; mediaAddress = ""; ! preferredFormat=""; qualityLevel = 1; } ! public ClientRecord(int _clientID, String _IP, int _portBaseRTP, String _mediaAddress, String _preferredFormat, int _qualityLevel) { --- 351,361 ---- clientID = -1; IP = ""; ! portRTP = 40000; mediaAddress = ""; ! preferredFormat = ""; qualityLevel = 1; } ! public ClientRecord(int _clientID, String _IP, int _portRTP, String _mediaAddress, String _preferredFormat, int _qualityLevel) { *************** *** 220,226 **** clientID = _clientID; IP = _IP; ! // serverSA = _serverSA; ! // clientSA = _clientSA; ! portBaseRTP = _portBaseRTP; mediaAddress = _mediaAddress; preferredFormat = _preferredFormat; --- 363,367 ---- clientID = _clientID; IP = _IP; ! portRTP = _portRTP; mediaAddress = _mediaAddress; preferredFormat = _preferredFormat; *************** *** 236,250 **** } ! /* public SessionAddress getServerSA() { ! return serverSA; ! } ! ! public SessionAddress getClientSA() { ! return clientSA; ! } ! */ ! ! public int getPortBaseRTP () { ! return portBaseRTP; } --- 377,382 ---- } ! public int getPortRTP() { ! return portRTP; } *************** *** 269,284 **** } ! public void setPortBaseRTP(int _portBaseRTP) { ! portBaseRTP = _portBaseRTP; ! } ! ! /*public void setServerSA(SessionAddress _serverSA) { ! serverSA = _serverSA; } - public void setClientSA(SessionAddress _clientSA) { - clientSA = _clientSA; - }*/ - public void setMediaAddress(String _mediaAddress) { mediaAddress = _mediaAddress; --- 401,408 ---- } ! public void setPortRTP(int _portRTP) { ! portRTP = _portRTP; } public void setMediaAddress(String _mediaAddress) { mediaAddress = _mediaAddress; *************** *** 289,295 **** } - public void setQualityLevel(int _qualityLevel) { qualityLevel = _qualityLevel; } ! } \ No newline at end of file --- 413,418 ---- } public void setQualityLevel(int _qualityLevel) { qualityLevel = _qualityLevel; } ! } Index: ThreadListenClients.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/ThreadListenClients.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ThreadListenClients.java 9 Mar 2003 23:52:30 -0000 1.3 --- ThreadListenClients.java 13 Mar 2003 02:38:49 -0000 1.4 *************** *** 1,96 **** ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * ThreadListenClients est un thread permettant de gerer un {@link ServerSocket} ! * en attente de requete de connexion client pour instancier un {@link ThreadDialogClient} ! * dedie au client. ! * <p> ! * Utilise la methode <code>accept</code> de la classe {@link ServerSocket} pour instancier ! * nouveau {@link Socket} et le transmettre en parametre du constructeur de la classe ! * @link ThreadDialogClients. ! * @see ServerInit ! * @see ThreadDialogClient ! * @author Julien Carbonell ! */ ! public class ThreadListenClients extends Thread { ! ! private int clientIDTemp; ! private int port; ! ! private ServerSocket sockListen; ! private ServerInit serverInit; ! ! private String[] welcome; ! ! /** ! * Instancie un nouvel objet <code>ThreadListenClients</code>. ! * @param _serverInit objet qui appelle ce constructeur. ! * @param _port port d'ecoute permettant de creer le <code>ServerSocket</code>. ! * @see ServerInit ! * @see ThreadDialogClient ! */ ! public ThreadListenClients (ServerInit _serverInit, int _port) { ! super("Listen-Clients"+ _port); ! serverInit = _serverInit; ! port = _port; ! } ! ! /** ! * Surcharge la methode <code>run</code> de la classe parent <code>Thread</code>. ! */ ! public void run() { ! Socket sockClient; ! DialogClient dialogClient; ! int portBaseRTP; ! ! welcome = new String[1]; ! ! ! /* output.println("#"); ! output.println(clientID); ! output.println(mySocket.getLocalAddress().toString() + '/' + mySocket.getLocalPort()); ! output.println(portBaseRTP); ! output.println("#"); ! output.flush();*/ ! ! ! ! try ! { ! sockListen = new ServerSocket(port); ! System.out.println("Serveur(" + Thread.currentThread() + ") attend sur " + port); ! while (true) ! { ! sockClient = sockListen.accept(); ! clientIDTemp = serverInit.createClient(); ! portBaseRTP = serverInit.getPortBaseRTP(clientIDTemp); ! //welcome[0] = String.valueOf(clientIDTemp); ! welcome[0] = String.valueOf(portBaseRTP); ! dialogClient = serverInit.createDialogClient(clientIDTemp, sockClient); ! dialogClient.start(); ! dialogClient.sendMessage(1, welcome); ! System.out.println("Envoi vers le client\n" + welcome[0] + "\nFin"); ! } ! } ! catch (Exception e) ! { ! e.printStackTrace(); ! } ! finally ! { ! try ! { ! sockListen.close(); ! System.out.println("Listen-Clients" + Thread.currentThread() + " : Stopped !!! "); ! } ! catch (IOException e) ! { ! } ! } ! ! ! } ! ! } \ No newline at end of file --- 1,92 ---- ! import java.util.*; ! import java.io.*; ! import java.net.*; ! ! /** ! * ThreadListenClients est un thread permettant de gerer un {@link ServerSocket} ! * en attente de requete de connexion client pour instancier un {@link ThreadDialogClient} ! * dedie au client. ! * <p> ! * Utilise la methode <code>accept</code> de la classe {@link ServerSocket} pour instancier ! * nouveau {@link Socket} et le transmettre en parametre du constructeur de la classe ! * @link ThreadDialogClients. ! * @see ServerInit ! * @see ThreadDialogClient ! * @author Julien Carbonell ! */ ! public class ThreadListenClients ! extends Thread { ! ! private int clientIDTemp; ! private int port; ! ! private ServerSocket sockListen = null; ! private ServerInit serverInit = null; ! ! private String[] welcome; ! ! /** ! * Instancie un nouvel objet <code>ThreadListenClients</code>. ! * @param _serverInit objet qui appelle ce constructeur. ! * @param _port port d'ecoute permettant de creer le <code>ServerSocket</code>. ! * @see ServerInit ! * @see ThreadDialogClient ! */ ! public ThreadListenClients(ServerInit _serverInit, ServerSocket _sockListen, int _port) { ! super("Listen-Clients" + _port); ! serverInit = _serverInit; ! sockListen = _sockListen; ! port = _port; ! } ! ! public void close() { ! if (sockListen != null) { ! try { ! sockListen.close(); ! } ! catch (IOException e) {} ! } ! } ! ! /** ! * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. ! */ ! public void run() { ! Socket sockClient = null; ! DialogClient dialogClient = null; ! int portRTP; ! ! welcome = new String[1]; ! ! ! try { ! while (true) { ! System.out.println("Serveur(" + Thread.currentThread() + ") attend sur " + ! port); ! sockClient = sockListen.accept(); ! clientIDTemp = serverInit.createClient(); ! portRTP = serverInit.getPortRTP(clientIDTemp); ! dialogClient = serverInit.createDialogClient(clientIDTemp, sockClient); ! dialogClient.start(); ! //if clientIDTemp = -1 ! welcome[0] = String.valueOf(portRTP); ! dialogClient.sendMessage(1, welcome); ! System.out.println("Envoi vers le client\n" + welcome[0] + "\nFin"); ! } ! } ! catch (Exception e) { ! e.printStackTrace(); ! } ! finally { ! try { ! if (sockListen != null) { ! sockListen.close(); ! } ! System.out.println("Listen-Clients" + Thread.currentThread() + ! " : Stopped !!! "); ! } ! catch (IOException e) { ! } ! } ! } ! } Index: ThreadRead.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/ThreadRead.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ThreadRead.java 9 Mar 2003 23:52:30 -0000 1.1 --- ThreadRead.java 13 Mar 2003 02:38:49 -0000 1.2 *************** *** 3,13 **** import java.net.*; public class ThreadRead extends Thread { // objet parent qui gere les entrees-sorties sur le socket protected DialogSocket parent; ! // inputstream sur lequel sont lus les messages protected BufferedReader binput; --- 3,26 ---- import java.net.*; + /** + * <code>ThreadRead</code> definit un thread d'ecoute sur un {@link BufferedReader}. + * Il effectue une ecoute permanente. + * <p> + * Il gere l'extraction du message en isolant les elements protocolaires de la + * transmission du message. + * @see ThreadWrite + * @see DialogSocket + * @author Julien Carbonell + */ + public class ThreadRead extends Thread { + boolean end = false; + // objet parent qui gere les entrees-sorties sur le socket protected DialogSocket parent; ! // BufferedReader sur lequel sont lus les messages protected BufferedReader binput; *************** *** 17,21 **** protected int messageType = -1; ! // constructeurs public ThreadRead(String _name, BufferedReader _binput, DialogSocket _parent) { --- 30,39 ---- protected int messageType = -1; ! /** ! * Constructeur de <code>ThreadRead</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link BufferedReader} sur lequel lit <code>ThreadRead</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadRead</code>. ! */ public ThreadRead(String _name, BufferedReader _binput, DialogSocket _parent) { *************** *** 25,54 **** } public void run() { try { while ( (temp = binput.readLine()) != null) { if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; ! } ! else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; } else { ! message = message.concat(temp + "\n"); } } } } ! } catch (Exception e) { e.printStackTrace(); --- 43,79 ---- } + /** + * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. + */ public void run() { try { while ( (temp = binput.readLine()) != null) { if (temp != null) { ! if (waitingMessage && (temp.charAt(0) == '#')) { ! // un nouveau message commence ! waitingMessage = false; } else { ! if (!waitingMessage && (temp.charAt(0) == '#')) { ! waitingMessage = true; ! messageType = Integer.parseInt(message.substring(0, ! message.indexOf('\n'))); ! System.out.println("Le Thread Read a recu\n" + message); ! message = message.substring(message.indexOf('\n') + 1, ! message.length() - 1); ! parent.incomingMessage(messageType, parseMessage(message)); ! message = ""; ! } ! else { ! message = message.concat(temp + "\n"); ! } } } + } } ! /* catch (SocketTimeoutException e) { ! System.out.println(e.getMessage()); ! }*/ catch (Exception e) { e.printStackTrace(); *************** *** 56,63 **** --- 81,90 ---- finally { try { + // binput.close(); System.out.println(getName() + Thread.currentThread() + " : Stopped !!! "); } catch (Exception e) { + System.out.println(e.getMessage()); } } Index: ThreadWrite.java =================================================================== RCS file: /cvsroot/madsserv/madsserv/src/server/ThreadWrite.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ThreadWrite.java 9 Mar 2003 23:52:30 -0000 1.1 --- ThreadWrite.java 13 Mar 2003 02:38:49 -0000 1.2 *************** *** 3,6 **** --- 3,17 ---- import java.net.*; + /** + * <code>ThreadWrite</code> definit un thread d'ecriture sur un {@link PrintWriter}. + * Sa duree d'execution est celle de l'envoi d'un message. + * <p> + * Il gere l'encapsulation du message en ajoutant les elements protocolaires de la + * transmission du message. + * @see ThreadRead + * @see DialogSocket + * @author Julien Carbonell + */ + public class ThreadWrite extends Thread { *************** *** 14,18 **** protected String messageToSend = ""; ! // constructeur public ThreadWrite(String _name, PrintWriter _output, DialogSocket _parent) { --- 25,34 ---- protected String messageToSend = ""; ! /** ! * Constructeur de <code>ThreadWrite</code>. ! * @param _name le nom du thread. ! * @param _binput le {@link PrinterWriter} sur lequel ecrit <code>ThreadWrite</code>. ! * @param _parent le {@link DialogSocket} qui gere le <code>ThreadWrite</code>. ! */ public ThreadWrite(String _name, PrintWriter _output, DialogSocket _parent) { *************** *** 31,34 **** --- 47,53 ---- } + /** + * Redefinit la methode <code>run</code> de la classe parent <code>Thread</code>. + */ public void run() { try { |
|
From: <car...@us...> - 2003-03-13 02:38:52
|
Update of /cvsroot/madsserv/madsserv/src/client
In directory sc8-pr-cvs1:/tmp/cvs-serv15336/src/client
Modified Files:
Client.java ClientRTPManager.java DialogServer.java
ThreadRTPManager.java
Log Message:
Probleme de fermeture des threads regle
Index: Client.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/client/Client.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Client.java 11 Mar 2003 20:06:52 -0000 1.4
--- Client.java 13 Mar 2003 02:38:49 -0000 1.5
***************
*** 19,27 ****
*/
public class Client
extends Frame {
- /**
- * Champs de la Classe Reencode
- */
private Container contentPane;
--- 19,29 ----
*/
+ /**
+ * <code>Client</code> permet de creer la fenetre principale du client Madsserv.
+ */
+
+
public class Client
extends Frame {
private Container contentPane;
***************
*** 57,61 ****
/**
! * Contructeur de la Classe Client
*/
--- 59,63 ----
/**
! * Contructeur de la classe <code>Client</code>.
*/
***************
*** 72,80 ****
/**
! * setPlayerPanel crée l'interface graphique du Client
! * @param pp il s'agit d'un PlayerPanel qui est une classe que nous avons crée
! * @vid est un booleen qui nous dit si le player a cree est de la video ou de l'audio
*/
-
public void setPlayerPanel(PlayerPanel pp, boolean vid) {
Panel panelTemp;
--- 74,81 ----
/**
! * Insere un <code>PlayerPanel</code> dans l'interface graphique de <code>Client</code>.
! * @param pp le PlayerPanel insere.
! * @param vid un booleen caracterisant le caractere audio ou video du player insere par le <code>PlayerPanel</code>.
*/
public void setPlayerPanel(PlayerPanel pp, boolean vid) {
Panel panelTemp;
***************
*** 109,113 ****
/**
! * jbinit lance la creation de l'interface graphique.
*/
private void jbInit() throws Exception {
--- 110,114 ----
/**
! * Cree l'interface graphique.
*/
private void jbInit() throws Exception {
***************
*** 118,123 ****
this.setTitle("Madsserv Client");
setAfficheStatusBar("coucou");
! URLChoice = new TextField("file:/mnt/win_c/temp/kiss_cool_1.mpeg");
! AdServer = new TextField("dronej.rezel.com:5200");
menuFile.setLabel("File");
menuOpenURL.setLabel("Open URL");
--- 119,124 ----
this.setTitle("Madsserv Client");
setAfficheStatusBar("coucou");
! URLChoice = new TextField("file:/stud/users/promo04/carbonel/tmp/video/kiss_cool_1.mpeg");
! AdServer = new TextField("laplace.enst.fr:5100");
menuFile.setLabel("File");
menuOpenURL.setLabel("Open URL");
***************
*** 192,209 ****
/**
! * menuFileExit_actionPerformed est à l'ecoute d'un evenement signifiant l'arret du client
! * @param e c'est l'evenemet qui met fin au client
*/
public void menuFileExit_actionPerformed(ActionEvent e) {
! String messageToSend[] = new String[1];
! messageToSend[0] = "fin de la connexion";
! dialogServer.sendMessage(4, messageToSend);
! System.exit(0);
}
- /**
- * processWindowEvent Methode qui permet de quitter le client quand on clique pour fermer la fenetre
- * @param e c'est l'evenement qui indique que l'on a clique sur le bouton pour fermer la fenetre
- */
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
--- 193,211 ----
/**
! * Traite l'evenement cree par le clic sur le menu Quitter.
! * @param l'evenement associe au clic sur le menu Quitter.
*/
public void menuFileExit_actionPerformed(ActionEvent e) {
! try {
! String messageToSend[] = new String[1];
! messageToSend[0] = "fin de la connexion";
! dialogServer.sendMessage(4, messageToSend);
! System.exit(0);
! }
! catch (Exception ex) {
! System.exit(0);
! }
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
***************
*** 214,219 ****
/**
! * boutongo_actionPerformed Methode qui permet de lancer la connexion lorsque l'on clique sur le bouton go
! * @param evt c'est l'evenement qui indique que l'on a clique sur le bouton go
*/
public void boutongo_actionPerformed(ActionEvent evt) {
--- 216,221 ----
/**
! * Traite l'evenement cree par le clic sur le bouton Go.
! * @param evt l'evenement associe au clic sur le bouton Go.
*/
public void boutongo_actionPerformed(ActionEvent evt) {
***************
*** 227,231 ****
}
catch (Exception e) {
! System.out.println("Socket pas la");
}
--- 229,234 ----
}
catch (Exception e) {
! System.out.println("Le serveur ou le port n'est pas correct");
! System.exit(0);
}
***************
*** 235,238 ****
--- 238,242 ----
else {
+ // if ( (mySocket.isClosed()) == false) {
messageToSend = new String[2];
messageToSend[0] = getURL();
***************
*** 240,249 ****
dialogServer.sendMessage(2, messageToSend);
}
}
/**
! * getAddressServer, cette methode permet d'obtenir l'InetAddress du serveur sur lequel il faut se connecter, cette adresse est rentré à la main dans une zone de texte sur l'interface graphique du client
! * @return InetAddress du server
*/
public InetAddress getAddressServer() {
--- 244,270 ----
dialogServer.sendMessage(2, messageToSend);
+ /*}
+ else {
+ try {
+ mySocket.connect(new InetSocketAddress(getAddressServer(),
+ getServerPort()));
+ }
+ catch (Exception e) {
+ }
+ }*/
}
}
/**
! * Supprime la connexion au serveur en stoppant le module <code>DialogServer</code>.
! */
! public void endConnexion() {
! dialogServer.stop();
! mySocket = null;
! }
!
! /**
! * Renvoie l'InetAddress du serveur.
! * @return l'InetAddress du serveur.
*/
public InetAddress getAddressServer() {
***************
*** 263,268 ****
/**
! * getServerPorrt est une methode qui permet d'obtenir le Numero de port du serveur, ce numero de port est rentre dans une zone de texte sur l'interface graphique du client
! * @return int le numero du port sur lequel, on doit se connecter au serveur
*/
public int getServerPort() {
--- 284,289 ----
/**
! * Renvoie le numero de port du serveur sur lequel il attends les connexions clients.
! * @return int le numero du port.
*/
public int getServerPort() {
***************
*** 278,283 ****
/**
! * getURL permet d'obtenir l'URL du fichier multimedia que l'on souhaite visionner, cet URL est rentre dans une zone de texte sur l'interface graphique du client
! * @return String l'adresse du media demande
*/
public String getURL() {
--- 299,305 ----
/**
! * Renvoie l'URL du fichier multimedia demande par l'utilisateur.
! * Cette URL est entree par l'intermediaire d'une zone de texte.
! * @return String l'adresse du media demande.
*/
public String getURL() {
***************
*** 286,289 ****
--- 308,316 ----
}
+ /**
+ * Renvoie le format de diffusion prefere de l'utilisateur.
+ * Cete format est precise via l'interface graphique.
+ * @return String le format prefere.
+ */
public String getFormatPrefere() {
***************
*** 304,309 ****
/**
! * setAfficheStatusBar est une methode qui permet d'afficher en bas du client un message envoye par le server
! * @param _message un message envoye sous forme de String envoye par le serveur
*/
public void setAfficheStatusBar(String _message) {
--- 331,336 ----
/**
! * Met a jour la barre d'etats du client.
! * @param _message le message a afficher dans la barre d'etats.
*/
public void setAfficheStatusBar(String _message) {
***************
*** 311,317 ****
}
- /**
- * Client_menuFileExit_ActionAdapter, classe qui ecoute pour savoir si on clique sur le menu exit et envoie alors l'evenement
- */
class Client_menuFileExit_ActionAdapter
implements ActionListener {
--- 338,341 ----
***************
*** 327,333 ****
}
- /**
- * Client_boutongo_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton go et envoie alors l'evenement
- */
class Client_boutongo_ActionAdapter
implements ActionListener {
--- 351,354 ----
***************
*** 343,349 ****
}
- /**
- * Client_Menu_OpenURL_ActionAdapter classe qui ecoute pour savoir si on clique sur le bouton OpenURL et envoie alors l'evenement
- */
class Client_Menu_OpenURL_ActionAdapter
implements ActionListener {
--- 364,367 ----
Index: ClientRTPManager.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/client/ClientRTPManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ClientRTPManager.java 11 Mar 2003 20:06:52 -0000 1.3
--- ClientRTPManager.java 13 Mar 2003 02:38:49 -0000 1.4
***************
*** 42,45 ****
--- 42,46 ----
this.client = client;
}
+
/**
* methode qui permet de demarrer l'attente de flux RTP
***************
*** 140,143 ****
--- 141,145 ----
return true;
}
+
/**
* isDone methode qui regarde si il y a des player qui sont crees
***************
*** 186,189 ****
--- 188,192 ----
return null;
}
+
/**
* find, methode qui
***************
*** 198,201 ****
--- 201,205 ----
return null;
}
+
/**
* findIntPlayer, methode qui retourne la position du player dans players
***************
*** 492,495 ****
--- 496,500 ----
}
}
+
/**
* la classe MyPlayer
Index: DialogServer.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/client/DialogServer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DialogServer.java 11 Mar 2003 20:06:53 -0000 1.3
--- DialogServer.java 13 Mar 2003 02:38:49 -0000 1.4
***************
*** 37,41 ****
switch (_type) {
! case 7: {
// if (lgth < 2) raise exception;
--- 37,41 ----
switch (_type) {
! case 9: {
// if (lgth < 2) raise exception;
***************
*** 50,54 ****
}
! case 5: {
// if (lgth < 2) raise exception;
//lecture du deuxieme champ : ClientID
--- 50,54 ----
}
! case 7: {
// if (lgth < 2) raise exception;
//lecture du deuxieme champ : ClientID
***************
*** 69,72 ****
--- 69,95 ----
break;
}
+ case 5: {
+ // if (lgth < 2) raise exception;
+ //lecture du deuxieme champ : ClientID
+ try {
+ clientID = Integer.parseInt(_message[0]);
+ }
+ catch (NumberFormatException e) {
+ System.out.println("Le deuxieme champ du message est incorrect");
+
+ // try{
+ System.out.println(_message[1]);
+ /*}
+ catch (NumberFormatException e)
+ {
+ System.out.println("Le troisieme champ du message est incorrect");
+ }*/
+ }
+ threadRTPManager.Fermer();
+ client.endConnexion();
+ System.out.println("coucou de fin");
+ //System.out.println(mySocket.isClosed());
+ break;
+ }
case 3: {
***************
*** 89,92 ****
--- 112,117 ----
else {
+
+ threadRTPManager.Fermer();
threadRTPManager = null;
System.gc();
Index: ThreadRTPManager.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/client/ThreadRTPManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ThreadRTPManager.java 11 Mar 2003 20:06:53 -0000 1.3
--- ThreadRTPManager.java 13 Mar 2003 02:38:49 -0000 1.4
***************
*** 22,25 ****
--- 22,30 ----
* methode run de ce thread
*/
+ public void Fermer()
+ {
+ clientRTPManager.close();
+ }
+
public void run()
{
|