I’m working on a project that needs to implement live video streaming from webcam on server into applet on remote client.
I have a code for capturing live stream from webcam through JMF on server & deploy streaming on rtp & an applet that receive streaming from the rtp address then play it into it.
But the problem that it’s only working within my own pc (server) & doesn’t work over local network (it loads applet but doesn’t run the video player).
Server Code:
public class Streaming_Server {
/**
* @param args the command line arguments
*/
private static String PORT = "10000";
private static InetAddress addr;
static final Format[] FORMATS = { new VideoFormat("rgb") };
static final ContentDescriptor CONTENT_DESCRIPTOR = new ContentDescriptor("raw.rtp");
public static void main(String[] args) throws IOException, NoDataSourceException, NoProcessorException, CannotRealizeException, NoDataSinkException {
// TODO code application logic here
try
{
addr = InetAddress.getLocalHost();
String ipAddr = addr.getHostAddress();
String hostname = addr.getHostName();
System.out.println("Your IP is " + ipAddr);
System.out.println("Your Host Name is " + hostname);
}
catch (UnknownHostException e){}
CaptureDeviceInfo webcamInfooo = new CaptureDeviceInfo("Camera", new MediaLocator("vfw://0"), null);
MediaLocator camDeviceMediaLocator = webcamInfooo.getLocator();
DataSource source = Manager.createDataSource(camDeviceMediaLocator);
Processor mediaProcessor = Manager.createRealizedProcessor(new ProcessorModel(source, FORMATS, CONTENT_DESCRIPTOR));
//MediaLocator outputMediaLocator = new MediaLocator("rtp://" + addr.getHostAddress() + ":" + PORT + "/video");
MediaLocator outputMediaLocator = new MediaLocator("rtp://192.168.1.4:20000/video");
DataSink dataSink = Manager.createDataSink(mediaProcessor.getDataOutput(), outputMediaLocator);
mediaProcessor.start();
dataSink.open();
dataSink.start();
}
}
Client Code:
public class Streaming_Client extends Applet implements ControllerListener {
/**
* Initialization method that will be called after the applet is loaded into
* the browser.
*/
Player player = null;
private MediaLocator mediaLocator;
private static String PORT = "10000";
private static InetAddress addr;
public void init() {
// TODO start asynchronous download of heavy resources
//mediaLocator = new MediaLocator("rtp:/192.168.1.4:10000/video");
mediaLocator = new MediaLocator("rtp:/192.168.1.4:20000/video");
setLayout(new BorderLayout());
try {
player = Manager.createPlayer(mediaLocator);
player.addControllerListener(this);
} catch (IOException | NoPlayerException ex) {
Logger.getLogger(Streaming_Client.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void start(){
player.start();
}
public void stop(){
player.stop();
player.deallocate();
}
public void destroy(){
player.close();
}
// TODO overwrite start(), stop() and destroy() methods
@Override
public void controllerUpdate(ControllerEvent ce) {
if ((ce instanceof RealizeCompleteEvent))
{
Component comp;
if ((comp = this.player.getVisualComponent()) != null)
add("Center", comp);
if ((comp = this.player.getControlPanelComponent()) != null)
add("South", comp);
validate();
}
}
}
After some research, i found that MediaLocator in server takes the Destination IP not the source one.
It’s an annoying thing as you must know where you are streaming.
So, after this edit..
i can stream live video capturing from 192.168.1.4 to 192.168.1.6 over Intranet only.
but i can’t find till now how to stream over internet as i must assign remote pc ip.