Code:
import javax.media.*;
import javax.media.protocol.*;
import javax.media.control.*;
public class DKRTPServer implements ControllerListener {
private String serverURL;
private DataSource ds = null;
private MediaLocator destination;
private Processor p = null;
DKRTPServer (String _serverURL, DataSource _ds){
serverURL = _serverURL;
ds = _ds;
try {
p = Manager.createProcessor(ds);
p.addControllerListener(this);
p.configure();
}
catch (Exception e){
System.out.println(e);
}
String destinationURL = serverURL;
destination = new MediaLocator(destinationURL);
}
public synchronized void controllerUpdate(ControllerEvent evt){
if (evt instanceof ConfigureCompleteEvent) {
setTrackFormat(p);
p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW_RTP));
p.realize();
}
else if (evt instanceof RealizeCompleteEvent) {
transmit(p);
}
else if (evt instanceof EndOfMediaEvent) {
// System.exit(0);
}
else {
}
}
private void setTrackFormat(Processor p) {
// Get the tracks from the processor
TrackControl [] tracks = p.getTrackControls();
// Do we have atleast one track?
if (tracks == null || tracks.length < 1) {
System.out.println("Couldn't find tracks in processor");
System.exit(1);
}
// 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);
p.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()) {
supported = tracks[i].getSupportedFormats();
for (int n = 0; n < supported.length; n++)
System.out.println("Supported format: " + supported[n]);
// 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) {
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);
}
}
private void transmit(Processor p) {
try {
DataSource output = p.getDataOutput();
DataSink rtpSink;
rtpSink = Manager.createDataSink(output, destination);
System.out.println("Sink content type: " + rtpSink.getContentType());
System.out.println("Sink media type: " + rtpSink.getOutputLocator().toString());
rtpSink.open();
rtpSink.start();
p.start();
} catch(Exception e) {
e.printStackTrace();
}
}
}
[Ovu poruku je menjao hyle dana 18.01.2007. u 00:46 GMT+1]