Java Video Streaming

Hello
I try to get an overview of what's possible according to video streaming in sun's wonderland. The goal is to stream prerecorded videos, stored on a webserver (not necessarily on the same machine like the wl-server ) into our wonderland embedded swing application.
My first investigation shows me, that I have the following possibilities to stream videos in Java:
- Java Media Framework (JMF)
- JVLC (VideoLAN Java API)
- Quicktime Streaming API (only quicktime movies)
-> http://www.onjava.com/pub/a/onjava/2005/01/12/strmng_qtj.html
- Red5 Java Client (only flash movies):
-> http://www.actionscript.org/resources/articles/617/1/Streaming-and-database-connection-with-red5-media-server/Page1.html
- Mplayer Java Client:
-> http://beradrian.wordpress.com/2008/01/30/jmplayer/
So what do you suggest me? What's the best way? Are there any code-examples for streaming videos from a webserver to a local java-client using JMF?
Thanks for your help.
Kind regards,
Peter
Edited by: blood_on_ice on Mar 23, 2009 12:44 AM

Thanks for your answer...
>
The "best" way? Considering you're using a Swing application, your best bet is probably going to be JMF. JavaFX has support for playing videos, but I'm not sure if they have support for RTP streams or progressive downloads or anything.
If you wanted to go the extra mile, you could look into embedding a Silverlight or Flash player into your Swing application. Silverlight is pretty cool because it's HD capable...>
Yes I have to develop the video streaming in a swing non-top-level Swing JComponent (such as a JPanel) because this is a wonderland restriction...I don't know JavaFX yet, is it possible to build a JavaFX app inside such a non-top-level Swing component? Embedding silverlight in a java-app isn't a really good idea I think...
Further recherches shows me, that I need on-demand video streaming with the ability to start, stop, play, pause etc. the video which is stored for example on a webserver. This is possible throught RTSP or HTTP according to: [http://www.remlab.net/op/vod.shtml|http://www.remlab.net/op/vod.shtml] ...when I use rtsp, I need a streaming-server like vlc, for http i just need my video stored on a webserver.
So what do I have for possibilities to stream such a video in a java client (non-top-level Swing JComponent) with RTSP or HTTP?
I've tried following rtp-code-example: [http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/AVReceive.html|http://java.sun.com/javase/technologies/desktop/media/jmf/2.1.1/solutions/AVReceive.html]
but it didn't work...I started my vlc-streaming server this way:
cvlc -vvv movie.mpg --sout '#rtp{dst=192.168.1.33,port=1234,sdp=http://localhost:8080}'but the output of the rtp-code-example shows the following:
run:
- Open RTP session for: addr: 127.0.0.1 port: 8080 ttl: 1
  - Waiting for RTP data to arrive...
  - Waiting for RTP data to arrive...
  - Waiting for RTP data to arrive...
  - Waiting for RTP data to arrive...
  - Waiting for RTP data to arrive...
With vlc http://127.0.0.1:8080 i receive the stream...
But I couldn't find an example of how I can get an rtsp-stream or a http-stream in jmf...
Thanks for your help.
Kind regards,
Peter
Edited by: blood_on_ice on Mar 23, 2009 8:59 AM
Edited by: blood_on_ice on Mar 23, 2009 9:00 AM

Similar Messages

  • Finding a java video streaming player

    I recently use FreePastry to implement a p2p video streaming system.
    But now i have a new challege, which bother me several days.
    In Splitstream, which uses Byte[] to send the data to other peer.
    I want find a java video player. It would be best to receive Byte[] as input.
    I try JMF, but it use RTP as the input.
    Is there any other video players suited about my case.

    There is a function in LiveStream.java called read. Read passes in a buffer object. The goal is to write all of the data you have available into the buffer object.
    What you want to do is something along the lines of the following pseudocode...
    public void read(Buffer buffer) throws IOException {
        synchronized (this) {
            /* Get the data */
            byte[] data = FunctionThatGetsByteArrayFromTheNetwork();
            /* Write the data to the buffer object */
            buffer.setData(data);
    }As for using the PushBufferDataSource, you just create one like you would a normal class (just use the new operator) and give it to a processor or a player like you would a normal data source.
    You need to include the DataSource.java code like the example does, modify it to use your modified LiveStream.java (you'll probably change the names of classes, so update the DataSource.java class to reflect those changes) and then just use it to create your DataSource.
        /* From DataSource.java */
        DataSource ds = new DataSource();
        /* Normal way of doing this */
        Processor p = Manager.createProcessor(ds);

  • DirectShow - Java  Video Streaming

    Is there any available information on how to stream a video across a newtwork through dsj without JMF?
    Thanks a lot

    The demo does that and it is described in the javadocs for WMNetSink.
    nils
    P.S. Please use the DirectShow<>java thread for questions on dsj

  • Really need Help! - Java Video Streaming

    Hi,
    I bought a 'Creative' web-cam today and I want to be able to display real-time video in a Java applet. Could someone please help me to do this.
    What classes do I need to capture the video, and use a server to either broadcast or stream the video to a client( applet ).
    I have JMF 1.2.1 installed with jdk1.3.1
    I'm kindof new to Java and really need to know where to start.
    F

    You should use JMF 2.0 or above version because they provide capturing ability.And also see the page. http://java.sun.com/products/java-media/jmf/2.1.1/solutions/
    I think you will find some useful material on this page.

  • Video stream java code

    hey
    i am trying to find how to obtian a video stream from a webcam using java code
    if u can help me please.

    ars_03 wrote:
    i am trying to find how to obtian a video stream from a webcam using java code
    if u can help me please.General questions usually stimulate general answers, such as "google it". If you truly want help, you will put more effort into your question such as answering these questions:
    * What do you know already about doing this?
    * What sources have you looked up and studied?
    * Of this, what specifically do you not understand?
    * What is the current state of your program?
    * Is it running? compiling?
    * Are there errors? if so, post them.
    etc...
    The bottom line here is usually the more thought and effort you put into creating your question, the better your chances are of a volunteer here taking the time and effort to consider it and give you a helpful answer. You would benefit greatly by reading this link (one I try to re-study at least every other week as it helps me):
    [http://www.catb.org/~esr/faqs/smart-questions.html]

  • Storing that Video stream into our local disk in java

    Hi frendz,
    I want to know how to, Connect to a remote online webcam and store that Video stream into our local disk.
    Any java interface tools are there, or can we use java api to do so.
    Anybody Please share your valuable suggestions.
    thanx,
    [email protected]

    Hi frendz,
    I want to know how to, Connect to a remote online
    webcam and store that Video stream into our local
    disk. The jennicam is no longer online.

  • Java Playerless Streamed video

    Hi all,
    We are not java developers but content providers and we would like to use java technology in use for video streaming re providing playerless video to our clients via IE browswer or email.
    Is it possible and where do you start?
    Would anybody be familiar with this technology?...could help us testing some examples for clients?
    Any response is welcome.
    We are based in UK

    Try the Java Media framework
    http://java.sun.com/products/java-media/jmf/2.1.1/

  • CTD bug in simple video streaming applet.

    I'm trying to write a simple applet to use JMF to allow an end-user to view a video stream that's being served up by VLC. It doesn't have to look immensely pretty (in fact, streamlined is what I want most). I swiped some code from the jicyshout project (http://jicyshout.sourceforge.net) which handles streaming MP3s, and borrowed a framework for an applet from one of Sun's example applets for the JMF.
    Here's my code so far:
    ** begin file SimpleVideoDataSource.java **
    import java.lang.String;
    import java.net.*;
    import java.io.*;
    import java.util.Properties;
    import javax.media.*;
    import javax.media.protocol.*;
    /* The SeekableStream and DataSource tweaks are based on the code from
    * jicyshout (jicyshout.sourcefourge.net), which was written by Chris Adamson.
    * The code was simplified (no need for mp3 metadata here), cleaned up, then
    * extended for our puposes.
    * This is a DataSource using a SeekableStream suitable for
    * streaming video using the default parser supplied by JMF.
    public class SimpleVideoDataSource extends PullDataSource {
    protected MediaLocator myML;
    protected SeekableInputStream[] seekStreams;
    protected URLConnection urlConnection;
    // Constructor (trivial).
    public SimpleVideoDataSource (MediaLocator ml) throws MalformedURLException {
    super ();
    myML = ml;
    URL url = ml.getURL();
    public void connect () throws IOException {
    try {
    URL url = myML.getURL();
    urlConnection = url.openConnection();
    // Make the stream seekable, so that the JMF parser can try to parse it (instead
    // of throwing up).
    InputStream videoStream = urlConnection.getInputStream();
    seekStreams = new SeekableInputStream[1];
    seekStreams[0] = new SeekableInputStream(videoStream);
    } catch (MalformedURLException murle) {
    throw new IOException ("Malformed URL: " + murle.getMessage());
    } catch (ArrayIndexOutOfBoundsException aioobe) {
    fatalError("Array Index OOB: " + aioobe);
    // Closes up InputStream.
    public void disconnect () {
    try {
    seekStreams[0].close();
    } catch (IOException ioe) {
    System.out.println ("Can't close stream. Ew?");
    ioe.printStackTrace();
    // Returns just what it says.
    public String getContentType () {
    return "video.mpeg";
    // Does nothing, since this is a stream pulled from PullSourceStream.
    public void start () {
    // Ditto.
    public void stop () {
    // Returns a one-member array with the SeekableInputStream.
    public PullSourceStream[] getStreams () {
    try {
    // **** This seems to be the problem. ****
    if (seekStreams != null) {
    return seekStreams;
    } else {
    fatalError("sourceStreams was null! Bad kitty!");
    return seekStreams;
    } catch (Exception e) {
    fatalError("Error in getStreams(): " + e);
    return seekStreams;
    // Duration abstract stuff. Since this is a theoretically endless stream...
    public Time getDuration () {
    return DataSource.DURATION_UNBOUNDED;
    // Controls abstract stuff. No controls supported here!
    public Object getControl (String controlName) {
    return null;
    public Object[] getControls () {
    return null;
    void fatalError (String deathKnell) {
    System.err.println(":[ Fatal Error ]: - " + deathKnell);
    throw new Error(deathKnell);
    ** end file SimpleVideoDataSource.java **
    ** begin file SeekableInputStream.java **
    import java.lang.String;
    import java.net.*;
    import java.io.*;
    import java.util.Properties;
    import javax.media.*;
    import javax.media.protocol.*;
    /* The SeekableStream and DataSource tweaks are based on the code from
    * jicyshout (jicyshout.sourcefourge.net), which was written by Chris Adamson.
    * The code was simplified (no need for mp3 metadata here), cleaned up, then
    * extended for our puposes.
    /* This is an implementation of a SeekableStream which extends a
    * BufferedInputStream to basically fake JMF into thinking that
    * the stream is seekable, when in fact it's not. Basically, this
    * will keep JMF from puking over something it expects but can't
    * actually get.
    public class SeekableInputStream extends BufferedInputStream implements PullSourceStream, Seekable {
    protected int tellPoint;
    public final static int MAX_MARK = 131072; // Give JMF 128k of data to "play" with.
    protected ContentDescriptor unknownCD;
    // Constructor. Effectively trivial.
    public SeekableInputStream (InputStream in) {
    super (in, MAX_MARK);
    tellPoint = 0;
    mark (MAX_MARK);
    unknownCD = new ContentDescriptor ("unknown");
    // Specified size constructor.
    public SeekableInputStream (InputStream in, int size) {
    super (in, Math.max(size, MAX_MARK));
    tellPoint = 0;
    mark(Math.max(size, MAX_MARK));
    unknownCD = new ContentDescriptor ("unknown");
    // Reads a byte and increments tellPoint.
    public int read () throws IOException {
    int readByte = super.read();
    tellPoint++;
    return readByte;
    // Reads bytes (specified by PullSourceStream).
    public int read (byte[] buf, int off, int len) throws IOException {
    int bytesRead = super.read (buf, off, len);
    tellPoint += bytesRead;
    return bytesRead;
    public int read (byte[] buf) throws IOException {
    int bytesRead = super.read (buf);
    tellPoint += bytesRead;
    return bytesRead;
    // Returns true if in.available() <= 0 (that is, if there are no bytes to
    // read without blocking or end-of-stream).
    public boolean willReadBlock () {
    try {
    return (in.available() <= 0);
    } catch (IOException ioe) {
    // Stick a fork in it...
    return true;
    // Resets the tellPoint to 0 (meaningless after you've read one buffer length).
    public void reset () throws IOException {
    super.reset();
    tellPoint = 0;
    // Skips bytes as expected.
    public long skip (long n) throws IOException {
    long skipped = super.skip(n);
    tellPoint += skipped;
    return skipped;
    // Trivial.
    public void mark (int readLimit) {
    super.mark (readLimit);
    // Returns the "unknown" ContentDescriptor.
    public ContentDescriptor getContentDescriptor () {
    return unknownCD;
    // Lengths? We don't need no stinkin' lengths!
    public long getContentLength () {
    return SourceStream.LENGTH_UNKNOWN;
    // Theoretically, this is always false.
    public boolean endOfStream () {
    return false;
    // We don't provide any controls, either.
    public Object getControl (String controlName) {
    return null;
    public Object[] getControls () {
    return null;
    // Not really... but...
    public boolean isRandomAccess () {
    return true;
    // This only works for the first bits of the stream, while JMF is attempting
    // to figure out what the stream is. If it tries to seek after that, bad
    // things are going to happen (invalid-mark exception).
    public long seek (long where) {
    try {
    reset();
    mark(MAX_MARK);
    skip(where);
    } catch (IOException ioe) {
    ioe.printStackTrace();
    return tell();
    // Tells where in the stream we are, adjusted for seeks, resets, skips, etc.
    public long tell () {
    return tellPoint;
    void fatalError (String deathKnell) {
    System.err.println(":[ Fatal Error ]: - " + deathKnell);
    throw new Error(deathKnell);
    ** end file SeekableInputStream.java **
    ** begin file StreamingViewerApplet.java **
    * This Java Applet will take a streaming video passed to it via the applet
    * command in the embedded object and attempt to play it. No fuss, no muss.
    * Based on the SimplePlayerApplet from Sun, and uses a modified version of
    * jicyshout's (jicyshout.sourceforge.net) tweaks to get JMF to play streams.
    * Use it like this:
    * <!-- Sample HTML
    * <APPLET CODE="StreamingViewerApplet.class" WIDTH="320" HEIGHT="240">
    * <PARAM NAME="code" VALUE="StreamingViewerApplet.class">
    * <PARAM NAME="type" VALUE="application/x-java-applet;version=1.1">
    * <PARAM NAME="streamwidth" VALUE="width (defaults to 320, but will resize as per video size)">
    * <PARAM NAME="streamheight" VALUE="height (defaults to 240, but will resize as per video size)">
    * <PARAM NAME="stream" VALUE="insert://your.stream.address.and:port/here/">
    * </APPLET>
    * -->
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.String;
    import java.lang.ArrayIndexOutOfBoundsException;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.net.*;
    import java.io.*;
    import java.io.IOException;
    import java.util.Properties;
    import javax.media.*;
    import javax.media.protocol.*;
    public class StreamingViewerApplet extends Applet implements ControllerListener {
    Player player = null;
    Component visualComponent = null;
    SimpleVideoDataSource dataSource;
    URL url;
    MediaLocator ml;
    Panel panel = null;
    int width = 0;
    static int DEFAULT_VIDEO_WIDTH = 320;
    int height = 0;
    static int DEFAULT_VIDEO_HEIGHT = 240;
    String readParameter = null;
    // Initialize applet, read parameters, create media player.
    public void init () {
    try {
    setLayout(null);
    setBackground(Color.white);
    panel = new Panel();
    panel.setLayout(null);
    add(panel);
    // Attempt to read width from applet parameters. If not given, use default.
    if ((readParameter = getParameter("streamwidth")) == null) {
    width = DEFAULT_VIDEO_WIDTH;
    } else {
    width = Integer.parseInt(readParameter);
    // Ditto for height.
    if ((readParameter = getParameter("streamheight")) == null) {
    height = DEFAULT_VIDEO_HEIGHT;
    } else {
    height = Integer.parseInt(readParameter);
    panel.setBounds(0, 0, width, height);
    // Unfortunately, this we can't default.
    if ((readParameter = getParameter("stream")) == null) {
    fatalError("You must provide a stream parameter!");
    try {
    url = new URL(readParameter);
    ml = new MediaLocator(url);
    dataSource = new SimpleVideoDataSource(ml);
    } catch (MalformedURLException murle) {
    fatalError("Malformed URL Exception: " + murle);
    try {
    dataSource.connect();
    player = Manager.createPlayer(dataSource);
    } catch (IOException ioe) {
    fatalError("IO Exception: " + ioe);
    } catch (NoPlayerException npe) {
    fatalError("No Player Exception: " + npe);
    if (player != null) {
    player.addControllerListener(this);
    } else {
    fatalError("Failed to init() player!");
    } catch (Exception e) {
    fatalError("Error opening player. Details: " + e);
    // Start stream playback. This function is called the
    // first time that the applet runs, and every time the user
    // re-enters the page.
    public void start () {
    try {
    if (player != null) {
    player.realize();
    while (player.getState() != Controller.Realized) {
    Thread.sleep(100);
    // Crashes... here?
    player.start();
    } catch (Exception e) {
    fatalError("Exception thrown: " + e);
    public void stop () {
    if (player != null) {
    player.stop();
    player.deallocate();
    } else {
    fatalError("stop() called on a null player!");
    public void destroy () {
    // player.close();
    // This controllerUpdate function is defined to implement a ControllerListener
    // interface. It will be called whenever there is a media event.
    public synchronized void controllerUpdate(ControllerEvent event) {
    // If the player is dead, just leave.
    if (player == null)
    return;
    // When the player is Realized, get the visual component and add it to the Applet.
    if (event instanceof RealizeCompleteEvent) {
    if (visualComponent == null) {
    if ((visualComponent = player.getVisualComponent()) != null) {
    panel.add(visualComponent);
    Dimension videoSize = visualComponent.getPreferredSize();
    width = videoSize.width;
    height = videoSize.height;
    visualComponent.setBounds(0, 0, width, height);
    } else if (event instanceof CachingControlEvent) {
    // With streaming, this doesn't really matter much, does it?
    // Without, a progress bar of some sort would be appropriate.
    } else if (event instanceof EndOfMediaEvent) {
    // We should never see this... but...
    player.stop();
    fatalError("EndOfMediaEvent reached for streaming media. ewe ewe tea eff?");
    } else if (event instanceof ControllerErrorEvent) {
    player = null;
    fatalError(((ControllerErrorEvent)event).getMessage());
    } else if (event instanceof ControllerClosedEvent) {
    panel.removeAll();
    void fatalError (String deathKnell) {
    System.err.println(":[ Fatal Error ]: - " + deathKnell);
    throw new Error(deathKnell);
    ** end file StreamingViewerApplet.java **
    Now, I'm still new to the JMF, so this might be obvious to some of you... but it's exploding on me, and crashing to desktop (both in IE and Firefox) with some very fun errors:
    # An unexpected error has been detected by HotSpot Virtual Machine:
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x21217921, pid=3200, tid=3160
    # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
    # Problematic frame:
    # C 0x21217921
    --------------- T H R E A D ---------------
    Current thread (0x058f7280): JavaThread "JMF thread: com.sun.media.amovie.AMController@506411[ com.sun.media.amovie.AMController@506411 ] ( realizeThread)" [_thread_in_native, id=3160]
    siginfo: ExceptionCode=0xc0000005, writing address 0x034e6360
    (plenty more here, I can post the rest if necessary)
    The problem seems to be coming from the "return seekStreams" statement in the first file; when I have execution aborted before that (with a fatalError call), it doesn't crash.
    Any tips/hints/suggestions?

    You should write your own Applet, where you can easily get the visual component (getVisualComponent())and show it directly in your Applet (you call it "embedded"). As far as I know, all examples (AVReceive* etc.) use the component which opens a new window.
    Best regards from Germany,
    r.v.

  • How to acess a PTC camera video stream from DVR card/PCI-slot

    I have a security camera which i connected to PC using PCISLOT/DVR Card.
    My requirement is to get the video stream from this camera and show in my program using java
    if it is possible using java and how to do this.
    Thanks in advance

    Believe it or not, this isn't really a Java question. You should begin by looking around your camera manufacturer's website for Java APIs, then their forums if they have any, contacting support and so on. Hoping that a general Java community will know exactly what is required here is a bit pie-in-the-sky.

  • Saving video stream from webcam periodically!!!

    Hi there, I want to catch every 1 minute video stream from the webcam, or video file, and save it into separate files. Of course I woudl like to have possibility to save many streams simultaneously. Any idea?
    Best regards

    Hi,
    I want to do the same thing ... I was able to stream audio through the socket but could not stream video.
    I posted my question at http://forum.java.sun.com/thread.jspa?threadID=674676&tstart=15
    and presented a sketch of my implementation design. But until now no one has answered my question.
    This is how you should hook up the components on the transmitter side
    Webcam --> Processor --> Custom DataSink --> PushBufferStream --> PushBufferHandler --> Socket --> Network.
    You can implement the transferData() method of the PushBufferHandler to write to a socket.
    And on the Receiver side the components should be hooked up like this
    Network --> Socket --> PullBufferStream --> custom DataSource --> Player
    Now as I mentioned in
    http://forum.java.sun.com/thread.jspa?threadID=674676&tstart=15
    the audio works fine but the video does not. The video does not render on the receiver side.
    Note: I tried TCP sockets with audio and it is terrible (not practical at all) so I reverted to UDP datagrams and the result was better than I expected. I didn't take care of the ordering of received packet at the receiver but it still worked fine.
    I am still looking waiting for some help in why video is not rendering and how can I sovle this problem.
    I am workning on a project and time is running out.
    Any help?
    -Adel

  • Display a video stream (successives images)

    Hello!
    Thanks for looking after my post.
    I try to display a video stream (successives images) in Java component.
    With a simple swing component, it's not possible to display 25 fps for a 640x480 resolution.
    With SWT, we arrive to display about 15 fps for a resolution 640x480 but the use of the CPU is very important.
    Do you know an efficient system to display video stream?
    Thanks.

    Firstly if you're loading images with Toolkit you'll nbeed to use MediaTracker (see the Javadoc for full and clear instructions).
    Secondly, be aware of how long it takes to load image data, allocate the memory for it, and decode it. This is where you're going to suffer and it's the fundamental flaw in the plan of simulating video by flipping single frames: it's highly unlikely you'll manage it quickly enough. As above, 50ms is quite optimistic.
    You could do your loading up-front and buffer a load of images - there are a few strategies you could use for this. But bear in mind that (a) this is going to be very memory hungry, and (b) if your image load time is greater than your frame display time you're always going to be fighting a losing battle. But it should work for very small animations.
    Run yourself some tests: write yourself a simple test class which just loads an image in its main() method using a MediaTracker. It'll tell you how long loading the image takes. Of course, if you're doing it in an applet then you've got all sorts of other factors to consider and the load times will be high.

  • Windows Media Player & Video Streaming

    Hi, there!
    Is it possible to send Video Streaming (using JMF) to
    Windows Media Player? If so, how could I do that???
    Thank You very much!!
    Cesar

    Hi Jupiter,
    Yes, JMF supports streaming media using the public standard RTP and RTSP protocols.
    JMF supports both transmission and reception of media over RTP for a variety of media formats. For a list of the default formats supported, check:
    http://java.sun.com/products/java-media/jmf/2.1.1/support-rtp.html
    It also fully supports RTCP. Besides, JMF implements the "RTP Profile for Audio and Video Conferences with Minamal Control", RTP/AVP.
    The front end GUI application, JMStudio can be used as a standalone application to transmit and receive RTP streams. To implement custom RTP applications using JMF as a framework, check out the RTP samples
    on the solutions page: http://java.sun.com/products/java-media/jmf/2.1.1/solutions/index.html
    OR you can refer this URL.
    http://java.sun.com/products/java-media/jmf/2.1.1/faq-jmf.html#jmf2-rtp-features
    I hope this will help you.
    Thanks
    Bakrudeen
    Technical Support Engineer
    Sun MicroSystems Inc, India

  • Rtp video streaming issue from linux to windows

    i am currently running a windows machine and linux machine on the same network connected by a linksy wrt45g router. i am trying to use avtransmit2.java and avreceive2.java to stream a video from one computer to the other and i can't get it to go from either win to linux or linux to win.
    i am able to send information from one computer to the other through an objectoutputstream, but i have been unsuccessful in getting video to go through rtp from one computer to the other.
    anyone have any ideas? it is starting to get really frustrating. i have been able to do something similar using vlc, but the avreceive and avtransmit won't work. i am using a new configuration, and have been successfull with the same code previous times
    thanks
    bd

    You can use MediaPlayerLauncher or MediaElement control
    https://msdn.microsoft.com/en-us/library/windows/apps/hh394004%28v=vs.105%29.aspx
    https://msdn.microsoft.com/en-us/library/windows/apps/ff769551(v=vs.105).aspx
    Gaurav Khanna | Microsoft .NET MVP | Microsoft Community Contributor

  • Using sockets to relay video stream

    Hi there,
    I've been working with java for 4 years now, and I never had troubles making the applications I wanted with it...since my last project :(
    I hope you, gurus from the java community forum, can help me sort this out, but let me explain it to you:
    I'd like to stream video content (let's say from a webcam) to several spectators. But my upload bandwidth (ADSL line) is limited to 512kbps, which is far from enough to send a video streaming (with a bitrate of ~400kbps) to 10 or more viewers.
    That's why I decided to rent a distant server (with a bandwidth of 5Mbps download/upload), and make a java application run on it, which would be able to broadcast the stream to all the viewers.
    So my computer (connected to adsl) captures the video from the webcam, sends it via socket to the rented server, which broadcasts the video to all the spectators. If no video is sent to the rented server, then it should broadcast local files to the spectators.
    Here is a schema of the project so you understand easily (my english is not as good as I'd like it to be, so you may not understand with words only):
    http://www.bf-stream.com/schema1.gif
    My application runs quite well with 5 spectators, but as soon as more viewers come to see the video, it starts hanging, and all the viewers suffer lags and buffering, which is not exactly what I expected...
    Of course, I checked the administration interface on the rented server to see if this was due to a cpu/ram/bandwitdh problem. With no success: with 10 viewers connected, the app uses less than 1% of the cpu power, something like 200kb of RAM, and a bandwidth of 3-4Mbps (which is still under the actual bandwidth capacity of the server).
    That's why I came to the conclusion that my java app was not as good as I thought, and decided to show it to you, so you can help me make it better.
    So here is a schema showing the classes and their interactions:
    http://www.bf-stream.com/schema2.gif
    And here are the sources of the classes:
    StreamRelay.java:
    package com.RR4;
    import java.net.Socket;
    import java.util.Vector;
    import java.util.Observable;
    import java.util.Observer;
    * StreamRelay:
    *  Main class controlling every aspects of the stream
    *  (live content, or files read from hard disk)
    public class StreamRelay extends Observable implements Observer  {
         static public String VERSION = "0.5";
         static public int BUFFER_SIZE = 16;
         private StreamServer streamServer;
         private LiveServer liveServer;
         LocalFile localFile;
         Vector clients;
         boolean streamFromSocket;
         public StreamRelay(int livePort, int relayPort) {
              streamFromSocket = false;
              // clients: vector containing every StreamClient connected
              clients = new Vector();
              // localFile: class reading local files when no live is sent to the relay
              localFile = new LocalFile(this);
              new Thread(localFile).start();
              // streamServer: server listening for new StreamClient
              streamServer = new StreamServer(this, relayPort);
              new Thread(streamServer).start();
              // liveServer: server listening for new sources for live content
              liveServer = new LiveServer(this, livePort);
              new Thread(liveServer).start();
         * addClient: adds new StreamClient to 'clients' vector (a StreamClient is a 'spectator')
         public void addClient(Socket clientSocket) {
             StreamClient client = new StreamClient(this, clientSocket);
         * removeClient: removes a StreamClient from 'clients' vector
         public void removeClient(int index) {
              clients.remove(index);
         * update: updates every StreamClient (which are all Observers of StreamRelay)
         public void update(Observable observable, Object obj) {
              if ((observable.getClass().toString().indexOf("LocalFile")!=-1&&!streamFromSocket)||(observable.getClass().toString().indexOf("LiveStream")!=-1)) {
                   this.notifyObservers( (byte[]) obj);
                   this.setChanged();
         public static void main(String[] args) {
              new StreamRelay(8000, 8080);
    LocalFile.java:
    package com.RR4;
    import java.util.Observable;
    import java.io.*;
    * LocalFile: class reading local file when no live content is sent to the relay
    public class LocalFile extends Observable implements Runnable {
         // filenames is an array containing a list of files to be read when no live content is sent
         private String[] filenames = {
              "file1",
              "file2"
         private InputStream stream;
         boolean streamOpened;
         private StreamRelay parent;
         int fileIndex;
         // Constructor: initialises LocalFile
         //  sets fileIndex to 0, and sets main StreamRelay as Observer
         public LocalFile(StreamRelay parent) {
              this.parent = parent;
              fileIndex = 0;
              this.addObserver(parent);
              initStream();
          * initStream: initialises stream to read the next file in 'filenames' array
         public void initStream() {
              try {
                   stream = new BufferedInputStream(new FileInputStream(filenames[fileIndex]), StreamRelay.BUFFER_SIZE);
                   streamOpened = true;
                   fileIndex++;
                   if (fileIndex==filenames.length)
                        fileIndex = 0;
              } catch (Exception exp) {
                   exp.printStackTrace();
                   streamOpened = false;
          * run: main loop of the class.
          *     the file is actually read: a buffer of BUFFER_SIZE is filled and sent to
          *     the observer (StreamRelay)
         public void run() {
              byte[] buffer = new byte[StreamRelay.BUFFER_SIZE];
              byte[] bufferToSend;
              boolean quit = false;
              int actualBufferSize = 0;
              while (!quit) {
                   try {
                        this.setChanged();
                        // Bytes are read until the buffer is actually filled with BUFFER_SIZE bytes
                        // Only then is it sent to the observer...
                        while (streamOpened && ((actualBufferSize = stream.read(buffer, 0, StreamRelay.BUFFER_SIZE)) > 0)) {
                             if (parent.clients.size()>0 && (!parent.streamFromSocket)) {
                                  if (actualBufferSize<StreamRelay.BUFFER_SIZE) {
                                       bufferToSend = new byte[actualBufferSize];
                                       System.arraycopy(buffer, 0, bufferToSend, 0, actualBufferSize);
                                       this.notifyObservers(bufferToSend);
                                  } else
                                       this.notifyObservers(buffer);
                                  this.setChanged();
                             } else {
                                  try { Thread.sleep(100); } catch (Exception exp) {}
                   } catch (Exception exp) {
                        exp.printStackTrace();
                   try { stream.close(); } catch (Exception exp) {}
                   initStream();
    StreamServer.java:
    package com.RR4;
    import java.net.ServerSocket;
    public class StreamServer extends Thread {
         private ServerSocket serverSocket;
         private boolean socketOpened;
         private StreamRelay parent;
         * StreamServer: server listening for new StreamClient
         public StreamServer(StreamRelay parent, int relayPort) {
              this.parent = parent;
              try {
                   serverSocket = new ServerSocket(relayPort);
                   socketOpened = true;
              } catch (Exception exp) {
                   exp.printStackTrace();
                   socketOpened = false;
         public void run() {
              try {
                   while (socketOpened) {
                        parent.addClient(serverSocket.accept());
              } catch (Exception exp) {
                   exp.printStackTrace();
    StreamClient.java:
    package com.RR4;
    import java.net.Socket;
    import java.util.Observer;
    import java.util.Observable;
    import java.io.*;
    * StreamClient: class representing spectators connected to view the video content
    *     whether it is live content, or local files
    public class StreamClient implements Observer {
         private Socket socket;
         private OutputStream outStream;
         private boolean connected = true;
         private StreamRelay parent;
         public StreamClient(StreamRelay parent, Socket socket) {
              this.parent = parent;
              this.socket = socket;
              try {
                   // initialises OutputStream from socket
                   outStream = socket.getOutputStream();
              } catch (Exception exp) {
                   try { outStream.close(); } catch (Exception e) {}
                   try { socket.close(); } catch (Exception e) {}
                   exp.printStackTrace();
                   connected = false;
              if (connected) {
                   // if initializing of OutputStream didn't fail
                   // add this class to StreamBroadcast 'clients' vector
                   // and add this class to StreamRelay observers
                   parent.clients.add(this);
                   parent.addObserver(this);
          * update: actually send read bytes to the client
         public void update(Observable observable, Object obj) {
             try {
                   outStream.write( (byte[]) obj);
                   outStream.flush();
              } catch (Exception exp) {
                   // if read bytes couldn't be sent
                   // remove this client from clients list and observers of StreamRelay
                   // and try to close OutputStream and Socket
                   connected = false;
                   try { parent.deleteObserver(this); } catch (Exception e) {}
                   try { parent.clients.remove(this); } catch (Exception e) {}
                   try { outStream.close(); } catch (Exception e) {}
                   try { socket.close(); } catch (Exception e) {}
    LiveServer.java:
    package com.RR4;
    import java.net.ServerSocket;
    * LiveServer:
    *     SocketServer listening to new 'Live streams'
    public class LiveServer extends Thread {
         private ServerSocket liveSocket;
         private boolean liveServerOpened;
         private StreamRelay parent;
         public LiveServer(StreamRelay parent, int livePort) {
              this.parent = parent;
              try {
                   liveSocket = new ServerSocket(livePort);
                   liveServerOpened = true;
              } catch (Exception exp) {
                   exp.printStackTrace();
                   liveServerOpened = false;
         public void run() {
              LiveStream liveStream;
              try {
                   while (liveServerOpened) {
                        liveStream = new LiveStream(parent, liveSocket.accept());
                        new Thread(liveStream).start();
              } catch (Exception exp) {
                   exp.printStackTrace();
    LiveStream.java:
    package com.RR4;
    import java.util.Observable;
    import java.io.*;
    import java.net.Socket;
    *     LiveStream:
    *          Socket receiving live content from another distant computer
    *          to display it instead of the local files.
    public class LiveStream extends Observable implements Runnable {
         private InputStream stream;
         boolean streamOpened;
         private StreamRelay parent;
         public LiveStream(StreamRelay parent, Socket socket) {
              this.parent = parent;
              this.addObserver(parent);
              try {
                   stream = new BufferedInputStream(socket.getInputStream(), StreamRelay.BUFFER_SIZE);
                   streamOpened = true;
              } catch (Exception exp) {
                   exp.printStackTrace();
                   streamOpened = false;
         public void run() {
              byte[] buffer = new byte[StreamRelay.BUFFER_SIZE];
              byte[] bufferToSend;
              int actualBufferSize = 0;
              try {
                   this.setChanged();
                   // Bytes are read until the buffer is actually filled with BUFFER_SIZE bytes
                   // Only then is it sent to the observer...
                   while (streamOpened && ((actualBufferSize = stream.read(buffer, 0, StreamRelay.BUFFER_SIZE)) > 0)) {
                        if (!parent.streamFromSocket)
                             parent.streamFromSocket = true;
                        if (parent.clients.size() > 0) {
                             if (actualBufferSize<StreamRelay.BUFFER_SIZE) {
                                  bufferToSend = new byte[actualBufferSize];
                                  System.arraycopy(buffer, 0, bufferToSend, 0, actualBufferSize);
                                  this.notifyObservers(bufferToSend);
                             } else
                                  this.notifyObservers(buffer);
                             this.setChanged();
                        } else
                             try { Thread.sleep(100); } catch (Exception exp) {}
              } catch (Exception exp) {
                   exp.printStackTrace();
              } finally {
                   try { stream.close(); } catch (Exception exp) {}
                   this.deleteObserver(parent);
                   parent.streamFromSocket = false;
    }For your information, I uses NSV/VP6 vbr as video codec (but this should have no incidence on it, since the app only takes the video stream from a socket and broadcasts it to other sockets, without analysing it or modifying it). And the java app is hosted on a Celeron 2.6 GHz, 128MB RAM.
    I really hope you'll be able to help me with this project, as it is really important to me...
    I've been trying several Stream types available with the JDK but I hadn't any success... I've also been playing with the BUFFER_SIZE parameter, unsuccessfully too...
    Anyway, thanks in advance for reading me so far... and I hope, for helping me... I know the java community is strong, and I hope I won't have to make it with C or C++ :(

    Hi again :)
    I've been focusing on the local part of the stream (no live video, just playing local files and sending them to clients) using NIO.
    NIOStreamRelay.java:
    package com.RR4;
    import java.io.*;
    import java.nio.*;
    import java.nio.channels.*;
    import java.nio.channels.spi.*;
    import java.net.*;
    import java.util.*;
    public class NIOStreamRelay {
         static int BUFFER_SIZE = 1024;
         LocalFile localFile;
         Vector clients;
         public NIOStreamRelay() throws IOException {
              localFile = new LocalFile(this);
              new Thread(localFile).start();
              clients = new Vector();
              acceptConnections();
         public void acceptConnections() throws IOException {          
              // Selector for incoming requests
              Selector acceptSelector = SelectorProvider.provider().openSelector();
              // Create a new server socket and set to non blocking mode
              ServerSocketChannel ssc = ServerSocketChannel.open();
              ssc.configureBlocking(false);
              // Bind the server socket to the local host and port
              InetAddress lh = InetAddress.getLocalHost();
              InetSocketAddress isa = new InetSocketAddress(lh, 8080);
              ssc.socket().bind(isa);
              // Register accepts on the server socket with the selector. This
              // step tells the selector that the socket wants to be put on the
              // ready list when accept operations occur, so allowing multiplexed
              // non-blocking I/O to take place.
              SelectionKey acceptKey = ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
              int keysAdded = 0;
              // Here's where everything happens. The select method will
              // return when any operations registered above have occurred, the
              // thread has been interrupted, etc.
              while ((keysAdded = acceptSelector.select()) > 0) {
                  // Someone is ready for I/O, get the ready keys
                  Set readyKeys = acceptSelector.selectedKeys();
                  Iterator i = readyKeys.iterator();
                  // Walk through the ready keys collection and process date requests.
                  while (i.hasNext()) {
                        SelectionKey sk = (SelectionKey)i.next();
                        i.remove();
                        // The key indexes into the selector so you
                        // can retrieve the socket that's ready for I/O
                        ServerSocketChannel nextReady = (ServerSocketChannel)sk.channel();
                        // Accept the date request and send back the date string
                        Socket s = nextReady.accept().socket();
                        OutputStream socketStream = s.getOutputStream();
                        StreamClient newClient = new StreamClient(socketStream, this);
                        localFile.addObserver(newClient);
                        clients.add(newClient);
         public static void main(String[] args) {
              try {
                   NIOStreamRelay streamRelay = new NIOStreamRelay();
              } catch (Exception e) {
                   e.printStackTrace();
    LocalFile.java:
    package com.RR4;
    import java.util.Observable;
    import java.io.*;
    * LocalFile: class reading local file when no live content is sent to the relay
    public class LocalFile extends Observable implements Runnable {
         // filenames is an array containing a list of files to be read when no live content is sent
         private String[] filenames = {
              "test.nsv",
              "test2.nsv"
         private InputStream stream;
         boolean streamOpened;
         int fileIndex;
         NIOStreamRelay parent;
         // Constructor: initialises LocalFile
         //  sets fileIndex to 0, and sets main StreamRelay as Observer
         public LocalFile(NIOStreamRelay parent) {
              this.parent = parent;
              fileIndex = 0;
              initStream();
          * initStream: initialises stream to read the next file in 'filenames' array
         public void initStream() {
              try {
                   stream = new BufferedInputStream(new FileInputStream(filenames[fileIndex]), NIOStreamRelay.BUFFER_SIZE);
                   streamOpened = true;
                   fileIndex++;
                   if (fileIndex==filenames.length)
                        fileIndex = 0;
              } catch (Exception exp) {
                   exp.printStackTrace();
                   streamOpened = false;
          * run: main loop of the class.
          *     the file is actually read: a buffer of BUFFER_SIZE is filled and sent to
          *     the observer (StreamRelay)
         public void run() {
              byte[] buffer = new byte[NIOStreamRelay.BUFFER_SIZE];
              byte[] bufferToSend;
              boolean quit = false;
              int actualBufferSize = 0;
              while (!quit) {
                   try {
                        this.setChanged();
                        // Bytes are read until the buffer is actually filled with BUFFER_SIZE bytes
                        // Only then is it sent to the observer...
                        while (streamOpened && ((actualBufferSize = stream.read(buffer, 0, NIOStreamRelay.BUFFER_SIZE)) > 0)) {
                             if (parent.clients.size() > 0) {
                                  if (actualBufferSize<NIOStreamRelay.BUFFER_SIZE) {
                                       bufferToSend = new byte[actualBufferSize];
                                       System.arraycopy(buffer, 0, bufferToSend, 0, actualBufferSize);
                                       this.notifyObservers(bufferToSend);
                                  } else
                                       this.notifyObservers(buffer);
                                  this.setChanged();
                             } else {
                                  try { Thread.sleep(100); } catch (Exception exp) {}
                   } catch (Exception exp) {
                        exp.printStackTrace();
                   try { stream.close(); } catch (Exception exp) {}
                   initStream();
    StreamClient.java:
    package com.RR4;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class StreamClient implements Observer {
         OutputStream out;
         NIOStreamRelay parent;
         public StreamClient(OutputStream out, NIOStreamRelay parent) {
              this.out = out;
              this.parent = parent;
         public void update(Observable observable, Object obj) {
             try {
                   out.write( (byte[]) obj);
                   out.flush();
              } catch (Exception exp) {
                   // if read bytes couldn't be sent
                   // remove this client from clients list and observers of StreamRelay
                   // and try to close OutputStream and Socket
                   try { parent.localFile.deleteObserver(this); } catch (Exception e) {}
                   try { parent.clients.remove(this); } catch (Exception e) {}
                   try { out.close(); } catch (Exception e) {}
    }Does it look better to you?
    I know I'm still using single threading, but as the IO should be non-blocking, I guess it should be better.
    Furthermore, I tried it locally, and was able to launch 30+ clients without buffering problems (huh, ok, my cpu here is only a 1.6GHz, so the display was a bit lagguy, but it didn't seem to buffer at all)

  • Capturing Video stream with JMF under LINUX??

    Ok, i am confused! I have read lots of info over this subject, but at some sites and forums i read that some people did not succeed in capturing ( and displaying) a live video stream with Java under Linux.
    Is it possible? and if so, can someone give me a sample code or a link to a sample code? thankz a lot!!

    Cross-posted
    http://forum.java.sun.com/post.jsp?forum=54&thread=456420&message=2083138&reply=true

Maybe you are looking for

  • Evoluent Vertical Mouse 3 & Snow Leopard - Match made in ****

    Been happily using an Evoluent Vertical Mouse for some time now with Leopard. Today I set up Snow Leopard as well as installing USB Overdrive as I'd done previously and while I can program buttons on the Evoluent, it will not work at all with Expose.

  • SOAP or HTTP call in XSLT

    Hi, I tried to make a SOAP or HTTP call in XSLT who send an xml and receive an xml. The recieved xml will be changed. I didn't find simple call in XSLT. So I decided to make this call with java. You can use java in XSLT. I tried this but i get this e

  • Palm desktop software 6.4.0.0

    Dear All, I have the above software installed on my laptop with windows 7 to support my original palm v and later my tungsten e2, I need to format my laptop and failed to find where on the internet I can find the above software, your help is apprecia

  • Can't install Final Cut Express 4

    My FCE 4 was no longer loading, so I uninstalled it and tried reinstalling it. When I get to the "Custom Install" page, Final Cut Express is unchecked and greyed out. Only LiveType is available for installation. What's going on? Thanks.

  • VL10D - Data selection User Role

    Hi, i've used the Tcode VL10D and the "User role" tab is greyed. How can i select the Data selection (ex. flag "with delivery")? How can i mantain VL10CUA and VL10CUV? Thank you. Antonio