1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
package tvmobile;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.imageio.*;
/*
** Cette classe va servir pour l'insertion des erreurs suivant
* les simulations expérimentaux vues a la these*/
class Main extends JFrame implements ActionListener{
public Main(){
}
// Declarations des attributs
String inputFile;
String outputFile;
String receptor;
double SNR_dB;
int header = 4734;//entete MPEG
static int NIVEAU, SIZE;
static JButton b1 = new JButton(" simuler ");
static JButton b2 = new JButton("voir la vidéo d'entrée ");
static JButton b3 = new JButton("voir la vidéo de sortie ");
static JButton b4 = new JButton(" fermer ");
JLabel jl1 = new JLabel("inputFile ",SwingConstants.LEFT);
JTextField jtf1 = new JTextField(10);
JLabel jl2 = new JLabel("outputFile",SwingConstants.LEFT);
JTextField jtf2 = new JTextField(10);
JLabel jl3 = new JLabel("SNR_dB ",SwingConstants.LEFT);
JTextField jtf3 = new JTextField(10);
JLabel jl4 = new JLabel("récepteur",SwingConstants.LEFT);
static JProgressBar pb = new JProgressBar(0,100);
JLabel jl5 = new JLabel("avancement",SwingConstants.LEFT);
JRadioButton bouton1 = new JRadioButton("rake");
JRadioButton bouton2 = new JRadioButton("chase");
//fin de la déclaration
public void init(String title)throws IOException{
setTitle(title);
setSize(400, 400);
setResizable(false);
JPanel P = new JPanel();
GridLayout gl = new GridLayout(0,2);
GridLayout g2 = new GridLayout(0,1);
setLayout(gl);
P.add(jl1);
P.add(jtf1);
P.add(jl2);
P.add(jtf2);
P.add(jl3);
P.add(jtf3);
P.add(jl4);
ButtonGroup groupe = new ButtonGroup();
groupe.add(bouton1);
P.add(bouton1);
groupe.add(bouton2);
P.add(bouton2);
P.add(b1);
P.add(b2);
P.add(b3);
P.add(b4);
P.add(jl5);
P.add(pb);
getContentPane().add(P);
bouton1.addActionListener(this);
bouton2.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
}
public Main(String title) throws IOException{
init(title);
}
public static void main(String[]argv)throws IOException{
new Main("Insertion des erreurs").setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == bouton1)
receptor = "rake";
if(e.getSource() == bouton2)
receptor = "chase";
if(e.getSource() == b1)
try{
simulating();
}
catch(Exception ex){
System.out.println("Error");
}
if(e.getSource() == b2)
try{
openingInputFile();
}
catch(Exception ex){
}
if(e.getSource() == b3)
try{
openingOutputFile();
}
catch(Exception ex){
}
if(e.getSource() == b4)
System.exit(0);
}
void simulating()throws IOException{
readData();
NIVEAU = 0;
DataInputStream in = new DataInputStream(new FileInputStream(inputFile));
DataOutputStream out = new DataOutputStream(new FileOutputStream(outputFile));
double e = error();
SIZE = taille();
int etat = 0;
while(in.available() > 0){
int b = in.read();
header--;
double d = Math.random();
if(d < e || header > 0)
out.write(b);
else
out.write(0);
NIVEAU++;
pb.setValue(100*NIVEAU/SIZE);
}
out.close();
}
double error(){
if(receptor.equals("rake"))
return P_rake();
return P_chase();
}
double P_rake(){
double x = SNR_dB;
return 0.99995;
}
double P_chase(){
double x = SNR_dB;
return 0.99995;
}
void readData(){
inputFile = "C:/Program Files/EasyPHP1-8/www/Documents/docPFE/src/TVmobile/inputFiles/"+jtf1.getText();
outputFile = "C:/Program Files/EasyPHP1-8/www/Documents/docPFE/src/TVmobile/outputFiles/"+jtf2.getText();
SNR_dB = Double.parseDouble(jtf3.getText());
}
void openingInputFile()throws Exception{
readData();
System.out.println(inputFile);
Runtime runtime = Runtime.getRuntime();
runtime.exec(inputFile);
}
void openingOutputFile()throws Exception{
readData();
System.out.println(outputFile);
Runtime runtime = Runtime.getRuntime();
runtime.exec(outputFile);
}
int taille() throws IOException{
int c = 0;
DataInputStream in = new DataInputStream(new FileInputStream(inputFile));
while(in.available() > 0){
in.read();
c++;
}
return c;
}
} |