Jmf on the server side, quicktime as a web client

The java media framework still rocks. As part of my final year project I had to build a streaming server that could stream live video and audio to online clients. I didn’t want to use jmf on the client side due to the ubiquitous applet “sand box”; yuk! I took a look at various embeddable players and settled on QuickTime for one thing: It can play streams when handed their descriptions in the SDP (Session Description Protocol) format.

Here is my workaround, for anyone who may face a similar challenge:

Assumptions:

  1. I assume you know the java media framework and can build an application to stream video and audio using the jmf APIs.
  2. I also assume you can comfortably code using the java servlet api
  3. I assume you want to stream to web clients (embedded QuickTime) from your jmf application

Now lets go …

  1. Check out how to describe the streams you’re sending out from your application in the SDP format (Session Description Protocol). Of course Google exists for such a time as this. Here is a sample from what I did :

    v= 0

    o=Solomons session IN IP4 192.168.1.2

    s=Test Session

    t=0 0

    c=IN IP4 224.124.100.100/2

    m=video 2222 RTP/AVP 26

  2. Put your version of the above description in a text file and name it whatever you want. It would help to end the name with a “.SDP” extension though.
  3. In your java web application, place this text file preferably in the web folder. I assume you are using netbeans here.
  4. The next step is this : You code a java servlet that simply sets it’s content type to “application/sdp;charset=UTF-8” and then spits out the content of your sdp file to whoever is calling.

    Here is something I did, in case you can read strange signs:


    protected void processRequest(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

    response.setContentType(“application/sdp;charset=UTF-8”); // setting
    content
    type to sdp

    File f = new File(getServletContext().getRealPath(“/lecturePage/test2.sdp”)); //getting the sdp file from the location I placed it

    BufferedReader reader = new BufferedReader(new FileReader(f));

    PrintWriter out = response.getWriter();

    try {

    String s = ” “;

    while(s.length() >=1){

    s=reader.readLine();

    out.println(s); //spitting out whatever is read from the file

    }

    reader.close();

    } finally {

    out.close();

    }

    5. Now you need to create the webpage that will have your embedded QuickTime player and set the parameters. As usual, Google exists for this task. But it is worth mentioning that the src parameter you give the embedded player should be the URL to the servlet mentioned above.

    6. Now start your streaming server, start your java web server containing that servlet and the sdp file. In my case, for demonstration purposes I accessed the web page from a different machine

    Note : As you stream from your application, QuickTime is able to decipher the contents of your sdp file and hook onto the appropriate ports etc and render the incoming packets ….

    VOILA ! …

    Here is my live streaming server, built on the netbeans platform. Boy, I love the netbeans platform!

    Here comes the client …

    That’s me sitting at the client machine with camera fixed on me capturing a screen shot

Advertisements