|
From: <car...@us...> - 2003-03-24 02:54:29
|
Update of /cvsroot/madsserv/madsserv/src/server/adaptability
In directory sc8-pr-cvs1:/tmp/cvs-serv21811/server/adaptability
Modified Files:
GestionAdapta.java
Log Message:
Version stable et fonctionnelle
Index: GestionAdapta.java
===================================================================
RCS file: /cvsroot/madsserv/madsserv/src/server/adaptability/GestionAdapta.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** GestionAdapta.java 20 Mar 2003 01:03:28 -0000 1.8
--- GestionAdapta.java 24 Mar 2003 02:54:25 -0000 1.9
***************
*** 29,32 ****
--- 29,36 ----
public class GestionAdapta {
+ // Fait correspondre un niveau de qualite a une charge maximale.
+ private int[] qualityToPayload = {
+ 17, 14, 5,0};
+
/**
* Cette méthode retourne le ou les formats de diffusion du fichier
***************
*** 37,86 ****
* @param supported l'ensemble des formats supporté par le serveur.
* @param nivQualite le niveau de qualité demandé.
! * @return un vecteur de <code>Format</code> contenant les formats de diffusion
* optimaux en fonction des formats supportés par le serveur et le
* niveau de qualité requis.
*/
! public Format[] getStreamingFormat(Format[][] supported, int nivQualite)
! throws Exception {
Format[] choisi = null;
int optimal = 0;
int[] optimaux = null;
! if(supported.length == 1) // Fichier audio uniquement.
! {
// On cree un tableau contenant les charges RTP pour chaque format
// audio supporte.
int[] payLoad = new int[supported[0].length];
// On remplit ce tableau.
! for(int i = 0; i < supported[0].length; i++)
payLoad[i] = getPayLoadFromTable(supported[0][i]);
!
// On recupere la coordonnee du format optimal.
! optimal = getBestQuality(payLoad,nivQualite);
! return supported[optimal];
}
! else if(supported.length == 2) // Fichier multimedia.
! {
! // On cree un tableau contenant les charges RTP pour chaque couple de
! // format avec les formats video en abscisse et les formats audio en
! // ordonnee.
! int[][] payLoad = new int[supported[0].length][supported[1].length];
! // On remplit le tableau payLoad[][] en parcourant supported[][].
! for(int i = 0; i < supported[0].length; i++)
! for(int j = 0; j < supported[1].length; j++)
! payLoad[i][j] = getPayLoadFromTable(supported[0][i]) +
! getPayLoadFromTable(supported[1][j]);
! // On recupere les coordonnees du couple de formats optimal.
! optimaux = getBestQuality(payLoad,nivQualite);
! choisi[0] = supported[0][optimaux[0]];
! choisi[1] = supported[1][optimaux[1]];
return choisi;
}
! else throw new Exception("Probleme de transmission des formats supportes");
}
/**
--- 41,118 ----
* @param supported l'ensemble des formats supporté par le serveur.
* @param nivQualite le niveau de qualité demandé.
! * @return un vecteur de <code>Format</code> contenant les formats de diffusion
* optimaux en fonction des formats supportés par le serveur et le
* niveau de qualité requis.
*/
! public Format[] getStreamingFormat(Format[][] supported, int nivQualite) throws
! Exception {
Format[] choisi = null;
int optimal = 0;
int[] optimaux = null;
! if (supported.length == 1) { // Fichier audio uniquement.
// On cree un tableau contenant les charges RTP pour chaque format
// audio supporte.
int[] payLoad = new int[supported[0].length];
+ choisi = new Format[1];
// On remplit ce tableau.
! for (int i = 0; i < supported[0].length; i++) {
payLoad[i] = getPayLoadFromTable(supported[0][i]);
! }
// On recupere la coordonnee du format optimal.
! optimal = getBestQuality(payLoad, nivQualite);
! choisi[0] = supported[0][optimal];
! return choisi;
}
! else if (supported.length == 2) { // Fichier multimedia.
! choisi = new Format[2];
! optimaux = new int[2];
! // On cree un tableau contenant les charges RTP pour chaque format
! // audio supporte.
! int[] payLoad = new int[supported[1].length];
! // On remplit ce tableau.
! for (int i = 0; i < supported[1].length; i++) {
! payLoad[i] = getPayLoadFromTable(supported[1][i]);
! }
! // On recupere la coordonnee du format optimal.
! optimaux[0] = getBestQuality(payLoad, nivQualite);
!
! for (int i = 0; i < supported[0].length; i++) {
! // Si le JPEG_RTP est supporte on choisit ce format qui est le seul a
! // une degradation de la video (cf getJPEGQuality)
! if (supported[0][i].getEncoding().compareTo(VideoFormat.JPEG)==0 ||
! supported[0][i].getEncoding().compareTo(VideoFormat.JPEG_RTP)==0) {
! optimaux[1] = i;
! }
! }
!
! choisi[0] = supported[1][optimaux[0]];
! choisi[1] = supported[0][optimaux[1]];
return choisi;
}
! else {
! throw new Exception("Probleme de transmission des formats supportes");
! }
}
+ // Associe a chaque niveau de qualite un niveau de qualite JPEG utilise par Reencode.
+ private float getJPEGQuality(int nivQualite) {
+ if (nivQualite == 1) {
+ return 0.5f;
+ }
+ if (nivQualite == 2) {
+ return 0.25f;
+ }
+ if (nivQualite == 3) {
+ return 0.01f;
+ }
+ if (nivQualite == 4) {
+ return 0.001f;
+ }
+ return 0.5f;
+ }
/**
***************
*** 96,101 ****
String nomEncodage = new String(supported.getEncoding());
int splRate = 0;
! if(supported instanceof AudioFormat) {
! splRate = (int)((AudioFormat)supported).getSampleRate();
}
--- 128,133 ----
String nomEncodage = new String(supported.getEncoding());
int splRate = 0;
! if (supported instanceof AudioFormat) {
! splRate = (int) ( (AudioFormat) supported).getSampleRate();
}
***************
*** 115,119 ****
(nomEncodage.compareTo(AudioFormat.DVI_RTP)) == 0) {
switch (splRate) {
- // case 8000: return 5;
case 16000:
return 6;
--- 147,150 ----
***************
*** 163,169 ****
/**
! * Cette focntion retourne la coordonnée du format audio optimal de
! * réencodage. On ne tient pas encore compte du niveau de qualité
! * demandé.
* @param payLoad la liste des charges RTP de chaque format audio supporté.
* @param qualite niveau de qualité.
--- 194,199 ----
/**
! * Cette fonction retourne la coordonnée du format audio optimal de
! * réencodage en tenant compte du niveau de qualité.
* @param payLoad la liste des charges RTP de chaque format audio supporté.
* @param qualite niveau de qualité.
***************
*** 171,218 ****
*/
private int getBestQuality(int[] payLoad, int qualite) {
! int maxPL = 0;
!
! for(int i = 0; i < payLoad.length; i++)
! {
! if(payLoad[i] > maxPL)
! maxPL = payLoad[i];
! }
! for(int i = 0; i < payLoad.length; i++)
! {
! if(payLoad[i] == maxPL)
! return i;
! }
! return -1;
! }
!
! /**
! * Cette focntion retourne les coordonnées des formats audio et video
! * optimaux de réencodage. On ne tient pas encore compte du niveau de
! * qualité demandé.
! * @param payLoad le tableau des charges RTP de chaque couple possible de
! * formats supportés.
! * @param qualite niveau de qualité.
! * @return les coordonnées des formats audio et video optimaux choisis.
! */
! private int[] getBestQuality(int[][] payLoad, int qualite) {
! int maxPL = 0;
! int[] choix = new int[2];
! for(int i = 0; i < payLoad.length; i++) {
! for(int j = 0; j < payLoad[i].length; j++) {
! if (payLoad[i][j] > maxPL)
! maxPL = payLoad[i][j];
! }
! }
! for(int i = 0; i < payLoad.length; i++) {
! for (int j = 0; j < payLoad[i].length; j++) {
! if (payLoad[i][j] == maxPL) {
! choix[0] = i;
! choix[1] = j;
! return choix;
! }
}
}
! return null;
}
}
--- 201,215 ----
*/
private int getBestQuality(int[] payLoad, int qualite) {
! int maxPL = qualityToPayload[qualite - 1];
! int selected = 0;
! int payloadTmp = 0;
! for (int i = 0; i < payLoad.length; i++) {
! if (payLoad[i] >= payloadTmp && payLoad[i] <= maxPL) {
! payloadTmp = payLoad[i];
! selected = i;
}
}
! return selected;
}
}
|