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
| /*-----BEGINNING CLASSES IMPORTATION -----*/
import java.awt.*;
import java.io.IOException;
import java.net.InetAddress;
import javax.swing.*;
import javax.media.control.TrackControl;
import javax.media.format.VideoFormat;
import javax.media.protocol.* ;
import javax.media.rtp.*;
import javax.media.* ;
import jmapps.util.StateHelper;
import javax.media.format.* ;
import java.util.*;
/*-----END CLASSES IMPORTATION-----*/
/*-----BEGINNING PREVIEW_WINDOW CLASS-----*/
@SuppressWarnings("serial")
public class previewWindow extends JInternalFrame
{
private JPanel panneauBas ;
private JCheckBox muet ;
private JPanel panneauHaut ;
private Processor processeur ;
private Player play ;
private DataSource sourceCamera ;
private CaptureDeviceInfo info ;
private MediaLocator ml ;
private VideoFormat formatVideo ;
private Vector peri ;
/*-----BEGINNING PREVIEW_WINDOW CONSTRUC TOR-----*/
public previewWindow()
{
super("Webcam locale",true, true) ;
System.out.println("Camera loading ...") ;
panneauBas = new JPanel() ;
muet = new JCheckBox("Micro muet") ;
panneauHaut = new JPanel() ;
//panneauHaut.setPreferredSize(new Dimension(50,50)) ;
panneauBas.add(muet, BorderLayout.WEST) ;
initCam() ;
this.getContentPane().add(panneauBas, BorderLayout.SOUTH);
this.pack() ;
this.resize(350,300);
this.setVisible(false);
System.out.println("Camera loading done") ;
}
/*-----END PREVIEW_WINDOW CONSTRUCTOR-----*/
//METHOD WICH ENABLES TO GET THE PLAYER
public Player getPlayer()
{
return this.play ;
}
//METHOD WHICH ENABLES TO INITIALIZE THE CAMERA
void initCam()
{
DataSource copieSourceCamera ;
Format[] formats ;
try
{
peri = CaptureDeviceManager.getDeviceList(new VideoFormat(VideoFormat.YUV));
info = (CaptureDeviceInfo) peri.elementAt(0) ;
ml = info.getLocator();
formats = info.getFormats() ;
formatVideo = (VideoFormat) formats[3] ;
sourceCamera = Manager.createDataSource(new MediaLocator("vfw://0"));
sourceCamera = Manager.createCloneableDataSource(sourceCamera);
copieSourceCamera = ((SourceCloneable)sourceCamera).createClone();
processeur = Manager.createProcessor(sourceCamera) ;
StateHelper playhelper = new StateHelper(processeur);
playhelper.configure();
play = Manager.createPlayer(copieSourceCamera) ;
play.start() ;
TrackControl [] tracks = processeur.getTrackControls();
for (int i = 0; i < tracks.length; i++)
{
Format format = tracks[i].getFormat();
if ( tracks[i].isEnabled() &&
format instanceof VideoFormat) {
//Dimension size = ((VideoFormat)format).getSize();
//float frameRate = ((VideoFormat)format).getFrameRate();
VideoFormat h263 = new VideoFormat(VideoFormat.H263_RTP, new Dimension(160,120),Format.NOT_SPECIFIED,Format.byteArray,Format.NOT_SPECIFIED) ; ;
tracks[i].setFormat(h263);
}}
ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
processeur.setContentDescriptor(cd);
playhelper.realize();
Dimension videoSize = play.getVisualComponent().getPreferredSize();
int videoWidth = videoSize.width;
int videoHeight = videoSize.height;
play.getVisualComponent().setSize(100,100) ;
this.getContentPane().add(play.getVisualComponent(), BorderLayout.NORTH) ;
this.pack() ;
processeur.start() ;
}
catch(IOException e)
{
System.out.println("No camera found") ;
}
catch(NoDataSourceException e)
{
System.out.println("No camera data source found") ;
}
catch(NoPlayerException e)
{
System.out.println("NoPlayerException") ;
}
}
//METHOD WHICH ENABLES TO START STREAMING
void startStreaming(String s)
{
try
{
DataSource OutputSource = this.processeur.getDataOutput();
System.out.println("Streaming loading ...");
RTPManager rtpm = RTPManager.newInstance();
SessionAddress localaddr = new SessionAddress(InetAddress.getLocalHost(),40000);
rtpm.initialize(localaddr);
SessionAddress destaddr = new SessionAddress(InetAddress.getByName(s),22222);
rtpm.addTarget(destaddr);
SendStream ss2 = rtpm.createSendStream(OutputSource,0);
ss2.start();
System.out.println("Streaming loading done") ;
}
catch(IOException e)
{
System.out.println("IOException");
}
catch(InvalidSessionAddressException e)
{
System.out.println("InvalidSessionAddressException");
}
catch(UnsupportedFormatException e)
{
System.out.println("UnsupportedFormatException");
}
}
}
/*-----END PREVIEW_WINDOW CLASS-----*/ |
Partager