Processor as Player

Hello,
i'm still trying to solve the problem of playing a mpg-video with a
processor as player, which runs slower then in "normal" programs.
Can anyone please try the following code with a mpg-video and his results?
(I'm using the video from( http://www.spitzenkick.de/cgi_bin/counter.php4?id33=1)
Looks the code right?
Thanks
AB
... code ...
import java.awt.BorderLayout;
import java.io.IOException;
import javax.media.Codec;
import javax.media.ConfigureCompleteEvent;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoProcessorException;
import javax.media.Player;
import javax.media.Processor;
import javax.media.RealizeCompleteEvent;
import javax.media.control.TrackControl;
import javax.media.format.VideoFormat;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TrackingProcessor implements ControllerListener {
/** Containing the processor object. */
private Processor proc;
/** Containing the player of this object processor. */
private Player player;
private JPanel videoPanel;
public TrackingProcessor(String path) {
videoPanel = new JPanel();
JFrame frame = new JFrame("JMFtest");
frame.getContentPane().add(videoPanel);
try {
proc = Manager.createProcessor(new MediaLocator(path));
} catch (NoProcessorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
proc.addControllerListener(this);
proc.configure();
frame.setSize(300, 300);
frame.setVisible(true);
public void controllerUpdate(ControllerEvent event) {
if (event instanceof ConfigureCompleteEvent){
System.out.println("configure");
TrackControl tracks[] = proc.getTrackControls();
for(int i = 0; i<tracks.length; i++){
if (tracks.getFormat() instanceof VideoFormat){
Codec[] videocodec = new Codec[]{
new com.sun.media.codec.video.cinepak.JavaDecoder(),
try {
tracks[i].setCodecChain(videocodec);
} catch (Exception e) {
e.printStackTrace();
}else{
tracks[i].setEnabled(false);
proc.realize();
} else if (event instanceof RealizeCompleteEvent){
System.out.println("realize");
try {
player = Manager.createRealizedPlayer(proc.getDataOutput());
} catch (Exception e) {
e.printStackTrace();
videoPanel.add(player.getVisualComponent(),BorderLayout.CENTER);
videoPanel.add(player.getControlPanelComponent(), BorderLayout.SOUTH);
videoPanel.updateUI();
player.start();
proc.start();
public static void main(String args[]) {
new TrackingProcessor("file:/d:/workspace/diplom2/test.mpg");

A zombie thread revived.
I tried the answer that you gave, but it didn't have any results.
i do:
processor.configure();
processor.setContentDescriptor(null);
processor.realize();
processor.play();
I'm trying to play a .mp3 file, with no luck at all. So I tried to play a .wav file, but the problem remained.
The message i get is:
" Unable to handle format: mpeglayer3, 44100.0 Hz, 16-bit, Stereo, LittleEndian,
Signed, 16000.0 frame rate, FrameSize=32768 bits
Failed to realize: com.sun.media.ProcessEngine@bd0108
Error: Unable to realize com.sun.media.ProcessEngine@bd0108"
To be precise, the program never goes past
processor.realize();
Can anyone help?
Thanks,
George

Similar Messages

  • Processor to player problem

    I am trying to use the output of a processor as the input to another player. I need to do this because i need to reduce the size of the video being displayed; from 320X240 to 160X120. The captured video was displayed with the size i specified but it displayed a black screen.
    What seems to be my problem? Thanks in advance for your help.

    I am trying to use the output of a processor as the
    input to another player. I need to do this because i
    need to reduce the size of the video being displayed;
    from 320X240 to 160X120. The captured video was
    displayed with the size i specified but it displayed a
    black screen.
    What seems to be my problem? Thanks in advance for
    your help.What the hell are you talking about?

  • Can i create processor and player in same programm

    hi,
    We are doing video conferencing.For this we have to capture video and save this video in a file but we are not able to display the captured video before save it into file.
    we are confused that weather we have to use createProcessor() or createRealizedProcessor()
    so please anyone can help us ,
    reply.

    If you have connected to the database with an account that has these privileges.
    Thus, for example, if your account has been granted the "DBA" role, then you can do so. Else, if your account has been granted the "CREATE TABLESPACE" and "CREATE USER", you can do so, even without the "DBA" role.
    Granting specific privileges to allow an account to execute specific functions is far more secure than granting the "DBA" role.
    Hemant K Chitale

  • Cannot prefetch a player / processor using Fobs4JMF

    Hello,
    I am desperately trying to convert my video into BufferedImage's for each frame. The common code for all methods I've found, is to prefetch the player and then do some sort of operation on it.
    I am unable to transition my player or processor into a prefetched state:
    MediaLocator ml = new MediaLocator("file:C:/test.mov");
    Player p = Manager.createRealizedPlayer(Manager.createDataSource(ml));
    //transition to prefetched
    p.prefetch();
    if (!waitForState(p, Processor.Prefetched)) {
       System.err.println("Failed to realize the processor.");
    }This code hangs indefinitely waiting for the state to transition.
    The code hangs the same for "createPlayer" and "createProcessor."
    The output for above is the following:
    Fobs4JMF - Native shared library found
    3.63697First Position: 0, 0 Duration: 3636
    Frame Rate: 29.97
    Opening Thread[JMF thread: com.sun.media.PlaybackEngine@6f50a8[ com.sun.media.PlaybackEngine@6f50a8 ] ( configureThread),9,system]
    Fobs Java2DRenderer: setInputFormat
    Fobs Java2DRenderer: setInputFormat
    Audio Error: Generic error
    Note that this video can be opened and played without any complication with the JMStudio bundled with the Fobs4JMF package. Also note that a call to "p.start()" actually starts the video without error and I hear the soundtrack playing although when adding each component to a JFrame, I do not actually see the video (could be a clue?):
    p.start();         
    JFrame f = new JFrame();
    f.add(p.getVisualComponent());
    f.add(p.getControlPanelComponent());
    f.pack();
    f.setVisible(true);I am using Fobs4JMF v0.4.1, JMF v2.1.1e, JRE 1.6.0_05, Eclipse v3.3.2 and Windows Vista. My video file is an MOV AVC1 which I think is pretty standard. You can downloaded it here: [test.mov|http://gemident.com/fobs/test.mov] in case you think that may be the source of my woes.
    Any help would be greatly appreciated.
    Thanks,
    Adam
    Lead Engineer, www.gemident.com
    Stanford University

    Well, first off... again, as I've said before to you in other threads...There's absolutely no reason to call "prefetch" manually for anything other than performance enhancements. Players will call "prefetch" on themselves as necessary once they are in a realized state, and you make a request for some data. "Prefetch" is quite useless, really, and is VERY SLOW. It's only useful in situations where you're doing useful work in the foreground while you prefetch in the background.
    Second, if you're in a realized state, you've already prefetched and are ready to start playing. Absolutely no reason to call prefetch on a realized processor/player. It's a bit like calling GoThroughPuberty() on a college kid. No need for it again, it's already been done...
    Finally, if you're throwing a generic audio error, I'd just use a Processor as a player and program it to disable all of the audio tracks...
    /* Create the media locator */
    MediaLocator ml = new MediaLocator("file:C:/Users/kapelner/Desktop/test.mov");
    /* Create the data source */
    DataSource ds = Manager.createDataSource(ml);
    /* Create our processor */
    Processor p = Manager.createProcessor(ds);
    /* Configure our processor */
    p.configure();
    while (p.getState() != Processor.Configured) {
        Thread.currentThread().sleep(500);
        System.err.println("Waiting 500 ms for the processor to configure...");
    /* Make the processor a player */
    p.setContentDescriptor(null);
    /* Program the tracks */
    TrackControl tcs[] = p.getTrackControls();
    for (int i = 0; i < tcs.length; i++) {
        tcs.setEnabled(tcs.getFormat() instanceof VideoFormat);
    /* Realize our processor */
    p.realize();
    while (p.getState() != Processor.Realized) {
    Thread.currentThread().sleep(200);
    System.err.println("Waiting 500 ms for the processor to realize...");
    /* Create the positioner */
    FramePositioningControl fpc = FramePositioningControl)p.getControl("javax.media.control.FramePositioningControl");
    /* Create the grabber */
    FrameGrabbingControl fg = (FrameGrabbingControl)p.getControl("javax.media.control.FrameGrabbingControl");
    /* Grab the first 10 frames */
    for (int i = 0; i < 10; i++) {
    /* Do the frame seek */
    fpc.seek(15);
    /* Grab the current frame as a buffer */
    Buffer buf = fg.grabFrame();
    /* Determine the format of the frame */
    VideoFormat vf = (VideoFormat) buf.getFormat();
    /* Initialize our BufferToImage */
    BufferToImage bufferToImage =
    new BufferToImage(vf);
    /* Create the image */
    Image im = bufferToImage.createImage(buf);
    // Do whatever you want with the image

  • Display current frame in applet.

    I am writing a Java applet that creates a media player. It plays a movie and I want to get the current frame. I have the code for this:
    FramePositioningControl fpc = ( FramePositioningControl)  player.getControl("javax.media.control.FramePositioningControl");
    int currentFrame = fpc.mapTimeToFrame(player.getMediaTime());I have created a text field and this is displayed on one of the panels of media player.
    My problem is that I can only get the frame number for the first frame to appear in the text field and it doesn't change for each frame.
    I have my code in the public synchronized void controllerUpdate(ControllerEvent evt) method as follows:
    tf3.setText(""+currentFrame);Any ideas as to how I can get each frame number to appear?
    I hope I have made myself clear enough.
    Thanks in advance,
    Wallace

    I have my code in the public synchronized void
    controllerUpdate(ControllerEvent evt) method as
    follows:controllerUpdate() is not called every time a new frame is encountered. It is called, for example, when the Processor or Player becomes "Realized", or is started or stopped.
    From your Processor or Player, you need to obtain the TrackControl that is an instance of VideoFormat.
    (note p is a Processor created and in the "Configured" state at this point in the code)
              TrackControl tc[] = null;
              // Obtain the track controls.
              tc = p.getTrackControls();
              // Search for the track control for the video track.
              TrackControl videoTrack = null;
              for( int i = 0; i < tc.length; i++ )
                   if( tc[ i ].getFormat() instanceof VideoFormat )
                        videoTrack = tc[ i ];
                        break;
              }You then need to create a custom Codec (or chain of Codecs) which you will insert into the data flow using p.setCodecChain( Codec[] codecs ) Override the process() method in your custom Codec to update your counter, as it will be called once for each frame.
    For example:
    public class PreAccessCodec implements Codec
         public final int process( Buffer in, Buffer out )
    //UPDATE YOUR COUNTER HERE!
             // Swap the data between the input & output.
             Object data = in.getData();
             in.setData(out.getData());
             out.setData(data);
             // Copy the input attributes to the output
             out.setFormat(in.getFormat());
             out.setLength(in.getLength());
             out.setOffset(in.getOffset());
             return BUFFER_PROCESSED_OK;
    }You will have to do a little searching through java.sun.com to find out about implementing a custom Codec, but I guarantee this will help you out... it is fundamental to the success of my application. I wish you luck!

  • Could not find the main class (with every jar)

    This isn't a developer question. I get the error Could not find the main class with every jar I try to open (for example the jar downloaded from https://gjar.dev.java.net/ gives the same problems - and I don't think there is something wrong with that JAR). It isn't a problem with the jar or MANIFEST because the same jar works fine on my laptop. So there is something wrong with my JRE installation, but what?
    I tried to remove and reinstall the JRE 6 Update 18 but that didn't work. When I run the JAR with command line java -jar "file.jar" it works fine, but if I dubbelclick on it I get the error message (and it's irritating me).
    I'm a bit desperate so I hope that someone here can help me ;)
    Thanks in advanced

    hai T.B.M ... Sorry to post here... I know that i posted my question in wrong thread..but i dont have another solution to contact with you.. I had seen your answers which are really excellent and helped to do my project..
    Now i am having very less time to complete my project and i am very new to JMF.. I am not getting output in JMF video capture ..please check the code and guide me where i gone wrong.......please pardon me once again to post here.. Heres my code
    import javax.media.*;
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.media.protocol.*;
    import java.io.*;
    import javax.media.control.StreamWriterControl;
    public class webcam implements ActionListener,ControllerListener
    boolean eomReached = false;
    boolean realized = false;
    JFrame f;
    BorderLayout bd1;
    CaptureDeviceInfo device;
    MediaLocator m1;
    Player player;
    Component videoScreen;
    JButton b1,b2;
    Processor processor;
    DataSource ds=null;
    DataSink fileWriter=null;
    JLabel status=new JLabel("");
    public webcam()
    try
    JFrame f=new JFrame();
    JPanel p =new JPanel();
    JPanel p1=new JPanel();
    device=CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
    m1=device.getLocator();
    System.out.println("1");
    processor.configure();
    processor = Manager.createProcessor(m1);
    processor.setContentDescriptor(new
    FileTypeDescriptor(FileTypeDescriptor.MSVIDEO));
    ds=processor.getDataOutput();
    player.addControllerListener(this);
    MediaLocator dest = new MediaLocator("file://foo.avi");
    fileWriter = Manager.createDataSink(ds, dest);
    fileWriter.open();
    ds.connect();
    ds.start();
    player=Manager.createPlayer(m1);
    player.addControllerListener(this);
    blockingRealize();
    videoScreen=player.getVisualComponent();
    b1=new JButton("START");
    b2=new JButton("STOP");
    bd1=new BorderLayout();
    p.setLayout(bd1);
    p1.add(b1);
    p1.add(b2);
    p.add("South",p1);
    p.add("East",videoScreen);
    f.getContentPane().add(p);
    f.setVisible(true);
    f.setSize(500,500);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    b1.addActionListener(this);
    b2.addActionListener(this);
    catch(Exception e){}
    public void actionPerformed(ActionEvent e)
    if(e.getSource()==b1)
    try{
    processor.start();
    player.start();
    fileWriter.start();
    catch(Exception e1){}
    if(e.getSource()==b2)
    try{
    player.stop();
    processor.stop();
    processor.close();
    fileWriter.close();
    catch(Exception e2){}
    public static void main(String args[])
    webcam obj=new webcam();
    public synchronized void blockingRealize() {
    player.realize();
    while (!realized) {
    try {
    wait();
    } catch (java.lang.InterruptedException e) {
    status.setText("Interrupted while waiting on realize...exiting.");
    System.exit(1);
    public synchronized void controllerUpdate (ControllerEvent event) {
    System.out.println("myPlayer generated "+event.toString());
    if (event instanceof RealizeCompleteEvent) {
    realized = true;
    notify();
    } else if (event instanceof EndOfMediaEvent) {
    eomReached = true;
    }

  • New to JMF my players just showing a white screen

    Hello
    I'm an experienced java programmer but i am new to JMF i'm having trouble applying an effect to a video track i've registered the effect successfully however when i then apply it to the video track all i get is a white screen. the player displays the video fine without the effect plugin applied however when i apply the effect it all goes wrong. i've checked the plugin viewer and data does seem to be moving between the various plugins and when i use a print statement the data is coming out of the plug in correctly. below is my code the player follwed by the effect file. its a real mess because i've been playing around with it for hours trying to get it to work and it's driving me crazy please can someone help!
    Thanks
    /////////////////***********Effect File************\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    import javax.media.*;
    import javax.media.format.*;
    import java.awt.*;
    public class RGBPassThruEffect implements Effect {
    Format inputFormat;
    Format outputFormat;
    Format[] inputFormats;
    Format[] outputFormats;
    public RGBPassThruEffect() {
    inputFormats = new Format[] {
    new RGBFormat(null,
    Format.NOT_SPECIFIED,
    Format.byteArray,
    Format.NOT_SPECIFIED,
    24,
    3, 2, 1,
    3, Format.NOT_SPECIFIED,
    Format.TRUE,
    Format.NOT_SPECIFIED)
    outputFormats = new Format[] {
    new RGBFormat(null,
    Format.NOT_SPECIFIED,
    Format.byteArray,
    Format.NOT_SPECIFIED,
    24,
    3, 2, 1,
    3, Format.NOT_SPECIFIED,
    Format.TRUE,
    Format.NOT_SPECIFIED)
    // methods for interface Codec
    public Format[] getSupportedInputFormats() {
         return inputFormats;
    public Format [] getSupportedOutputFormats(Format input) {
    if (input == null) {
    return outputFormats;
    if (matches(input, inputFormats) != null) {
    return new Format[] { outputFormats[0].intersects(input) };
    } else {
    return new Format[0];
    public Format setInputFormat(Format input) {
         inputFormat = input;
         return input;
    public Format setOutputFormat(Format output) {
    if (output == null || matches(output, outputFormats) == null)
    return null;
    RGBFormat incoming = (RGBFormat) output;
    Dimension size = incoming.getSize();
    int maxDataLength = incoming.getMaxDataLength();
    int lineStride = incoming.getLineStride();
    float frameRate = incoming.getFrameRate();
    int flipped = incoming.getFlipped();
    int endian = incoming.getEndian();
    if (size == null)
    return null;
    if (maxDataLength < size.width * size.height * 3)
    maxDataLength = size.width * size.height * 3;
    if (lineStride < size.width * 3)
    lineStride = size.width * 3;
    if (flipped != Format.FALSE)
    flipped = Format.FALSE;
    outputFormat = outputFormats[0].intersects(new RGBFormat(size,
    maxDataLength,
    null,
    frameRate,
    Format.NOT_SPECIFIED,
    Format.NOT_SPECIFIED,
    Format.NOT_SPECIFIED,
    Format.NOT_SPECIFIED,
    Format.NOT_SPECIFIED,
    lineStride,
    Format.NOT_SPECIFIED,
    Format.NOT_SPECIFIED));
    //System.out.println("final outputformat = " + outputFormat);
    return outputFormat;
    // methods for interface PlugIn
    public String getName() {
    return "Blue Screen Effect";
    public void open() {
    public void close() {
    public void reset() {
    // methods for interface javax.media.Controls
    public Object getControl(String controlType) {
         return null;
    public Object[] getControls() {
         return null;
    // Utility methods.
    Format matches(Format in, Format outs[]) {
         for (int i = 0; i < outs.length; i++) {
         if (in.matches(outs))
              return outs[i];
         return null;
    public int process(Buffer inBuffer, Buffer outBuffer) {
    int outputDataLength = ((VideoFormat)outputFormat).getMaxDataLength();
         validateByteArraySize(outBuffer, outputDataLength);
    outBuffer.setLength(outputDataLength);
    outBuffer.setFormat(outputFormat);
    outBuffer.setFlags(inBuffer.getFlags());
    byte [] inData = (byte[]) inBuffer.getData();          // Byte array of image in 24 bit RGB
    byte [] outData = (byte[]) outBuffer.getData();          // Byte array of image in 24 bit RGB
    RGBFormat vfIn = (RGBFormat) inBuffer.getFormat();     // Metadata - format of RGB stream
    Dimension sizeIn = vfIn.getSize();               // Dimensions of image
    int pixStrideIn = vfIn.getPixelStride();          // bytes between pixels
    int lineStrideIn = vfIn.getLineStride();          // bytes between lines
         int bpp = vfIn.getBitsPerPixel();               // bits per pixel of image
         for (int i=0; i < sizeIn.width * sizeIn.height * (bpp/8); i+= pixStrideIn)
              outData[i] = inData[i];                    // Blue
              //System.out.println("Blue: OutData = "+outData[i]+" | InData = "+inData[i]);
              outData[i+1] = inData[i+1];               // Green Don't you just love Intel byte ordering? :-)
              //System.out.println("Green: OutData = "+outData[i+1]+" | InData = "+inData[i+1]);
              outData[i+2] = inData[i+2];               // Red
              //System.out.println("Red: OutData = "+outData[i+2]+" | InData = "+inData[i+2]);
    return BUFFER_PROCESSED_OK;
    byte[] validateByteArraySize(Buffer buffer,int newSize) {
         Object objectArray=buffer.getData();
         byte[] typedArray;
         if (objectArray instanceof byte[]) {     // is correct type AND not null
              typedArray=(byte[])objectArray;
              if (typedArray.length >= newSize ) { // is sufficient capacity
                   return typedArray;
              byte[] tempArray=new byte[newSize]; // re-alloc array
              System.arraycopy(typedArray,0,tempArray,0,typedArray.length);
              typedArray = tempArray;
         } else {
              typedArray = new byte[newSize];
         buffer.setData(typedArray);
         return typedArray;
    //////////////////////////******Player file**********\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
    import javax.media.*;
    import javax.media.format.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    class RTPReceiver extends JFrame implements ControllerListener
         JPanel main = new JPanel();
         BorderLayout layout = new BorderLayout();
         boolean realized = false;
         boolean loopBack = true;
         boolean configured = false;
         RGBPassThruEffect Effect = new RGBPassThruEffect();
         TrackControl[] TC;
         static final String CLASS_NAME = "Documents and Settings.Alex Bowman.Desktop.RTPSender.RGBPassThruEffect";
         Processor myPlayer;
         Player player;
         //processor myProcessor;
         public RTPReceiver()
              //super();
              System.out.println(""+PlugInManager.getPlugInList(Effect.inputFormat,Effect.outputFormat,3).size());
              CreateProcessor("rtp://127.0.0.1:8000/video");
              myPlayer.configure();
              while(myPlayer.getState()!=myPlayer.Configured)
              //TC = myPlayer.getTrackControls();
              applyEffect();
              FileTypeDescriptor FTD = new FileTypeDescriptor("RAW");
              myPlayer.setContentDescriptor(FTD);
              blockingRealize();
              myPlayer.start();
              try
                   player = Manager.createPlayer(myPlayer.getDataOutput());
              catch (IOException e)
                   System.out.println("Error creating player "+e);
              catch (NoPlayerException NPE)
                   System.out.println("Error creating player "+NPE);
              player.realize();
              while(player.getState() != player.Realized)
              player.start();
              System.out.println("hello i get here");
              main.add("Centre",player.getVisualComponent());
              main.setLayout(layout);
              main.add("South",player.getControlPanelComponent());
              setTitle("RTP Video Receiver");
              setSize(325,296);
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              setContentPane(main);
              setVisible(true);
              //show();
         public void applyNewPlugin()
              PlugInManager.addPlugIn(CLASS_NAME, Effect.inputFormats, Effect.outputFormats, javax.media.PlugInManager.EFFECT);
              try
    PlugInManager.commit();
              catch (IOException e)
                   System.out.println("Error commiting PlugIn to system.");
         public void applyEffect()
              TC = myPlayer.getTrackControls();
              Vector V = PlugInManager.getPlugInList(Effect.inputFormat,Effect.outputFormat,3);
              System.out.println("1: "+TC[0].getFormat().toString());
                        //Codec COD = PlugInManager.getPlugInList(Effect.inputFormat,Effect.outputFormat,3).get(0);
                        Codec effectChain[] = {new RGBPassThruEffect()};
                        try
                             System.out.println(""+V.get(0));
                             Format[] input = Effect.getSupportedInputFormats();
                             TC[0].setFormat(input[0]);
                             System.out.println("2: "+TC[0].getFormat().toString());
                             TC[0].setCodecChain(effectChain);
                        catch (UnsupportedPlugInException E)
                             System.out.println("Error applying effect file. "+ E);
         public void CreateProcessor(String URL)
              MediaLocator MRL = new MediaLocator(URL);
              try
                   myPlayer = Manager.createProcessor(MRL);
                   myPlayer.addControllerListener(this);
              catch (NoPlayerException e)
                   System.out.println("NoPlayerException Occurred when trying to create Player for URL "+URL);
              catch (IOException f)
                   System.out.println("IO Exception occurred creating Player for RTP stream at URL: "+ URL);
         public synchronized void blockingRealize()
              myPlayer.realize();
              while(realized == false)
                   try
                        wait();
                   catch (InterruptedException IE)
                        System.out.println("Thread Interupted while waiting on realization of player");
                        System.exit(1);
         /*     if(myPlayer.getVisualComponent() !=null)
                   //main.add("Centre",myPlayer.getVisualComponent());
              else
                   System.out.println("error creating visual component");
         public synchronized void controllerUpdate(ControllerEvent E)
              if(E instanceof RealizeCompleteEvent)
                   realized = true;
                   notify();
              if(E instanceof EndOfMediaEvent)
                   //code for end of media file in here
                   myPlayer.setMediaTime(new Time(0));
                   myPlayer.start();
         public void Start()
         public void Stop()
              if(myPlayer != null)
                   myPlayer.stop();
                   myPlayer.deallocate();
         public static void main(String[] args)
              RTPReceiver RTP = new RTPReceiver();

    YYes  this is normal. if you go back to the main screen and view older post, at the bottom click "View More", you will see more posts like your own.

  • How to create an interface

    Sorry for the newbie question. I was provided a class, and they said that in order to use this class the interface can just construct a new SampleClass and method1() followed by method2(). I've looked over the documentation on interfaces, but I still don't get it. I was hoping someone could give me some guidance as to how to use method1() and method2() in my class.
    The SampleClass starts off like this
    public class SampleClass extends java.io.File {
    public boolean method1 {
    return true;
    public void method2 {
    sample.start();
    } //my class
    public class MyProgram {
    public static void main(String args[]) {
    }}Thanks in advance for the help!

    Ok. Here's the actual program that was given to me. When I do AudioFile af = new AudioFile();. It says that it's unable to resolve. So when I asked the guy about this, he said that I need to use an interface.....again sorry for my confusion.
    import java.io.*;
    import javax.media.*;
    import java.net.*;
    import java.util.Vector;
    import javax.media.format.AudioFormat;
    import javax.media.protocol.DataSource;
    import javax.media.protocol.FileTypeDescriptor;
    import javax.media.datasink.*;
    import javax.media.MediaLocator;
    import java.text.DecimalFormat;
    import javax.media.control.BufferControl;
    public class AudioFile extends java.io.File
    private Processor processor;
    private CaptureDeviceInfo device;
    private DataSink filewriter;
    private String audioFormat;
    private Player player;
    private Time currentMediaTime;
    boolean clipSaved;
    public AudioFile(String fileName)
    super(fileName);
    processor = null;
    player = null;
    device = null;
    filewriter = null;
    clipSaved = false;
    public AudioFile(String path, String name)
    this(path + name);
    public class StateHandler implements ControllerListener
    Processor processor = null;
    boolean configured = false;
    boolean realized = false;
    boolean failed = false;
    public StateHandler(Processor p)
    processor = p;
    p.addControllerListener(this);
    public boolean configured(int waitTime)
    long startTime =
    System.currentTimeMillis();
    synchronized(this)
    processor.configure();
    while(!configured && !
    failed)
    try
    wait
    (waitTime);
    catch
    (InterruptedException ie)
    System.out.println("Interrupted configure");
    if
    (System.currentTimeMillis() - startTime>waitTime)
    break;
    return configured;
    public boolean realized(int waitTime)
    long startTime =
    System.currentTimeMillis();
    synchronized(this)
    processor.realize();
    while(!realized &&!
    failed)
    try
    wait
    (waitTime);
    catch
    (InterruptedException ie)
    System.out.println("Interrupted realize");
    if
    (System.currentTimeMillis()-startTime>waitTime)
    break;
    return realized;
    public synchronized void controllerUpdate
    (ControllerEvent cEvent)
    if(cEvent instanceof
    RealizeCompleteEvent)
    realized=true;
    else
    if(cEvent instanceof
    ConfigureCompleteEvent)
    configured=true;
    else
    return;
    notifyAll();
    public boolean isClipSaved()
    return clipSaved;
    public class sinkEventHandler implements
    DataSinkListener
    DataSinkEvent dsEvent = new DataSinkEvent
    (filewriter);
    public void dataSinkUpdate(DataSinkEvent
    dsEvent)
    if(dsEvent instanceof
    EndOfStreamEvent)
    { filewriter.close();
    System.out.println
    ("Stream end");
    processor.deallocate();
    public boolean prepareToPlay()
    try
    if (player !=null) //if there was a dead player
    player.close();
    //change file to URL
    String fileString = "file:///" +
    this.getPath();
    player =
    Manager.createRealizedPlayer(new MediaLocator(fileString));
    if (player == null)
    System.out.println("No player");
    return false;
    else
    System.out.println
    ("Player created");
    return true;
    catch(MalformedURLException e)
    System.out.println("Invalid file or location");
    return false;
    catch (Exception e)
    System.out.println("Other problem");
    return false;
    public void startPlaying()
    player.start();
    public void stopPlaying()
    player.stop();
    player.close();
    public boolean prepareToRecord()
    if (processor!=null)
    processor.close();
    Vector deviceList =
    CaptureDeviceManager.getDeviceList(new AudioFormat
    (AudioFormat.LINEAR));
    CaptureDeviceInfo device = new
    CaptureDeviceInfo();
    if(deviceList.size()>0)
    device = (CaptureDeviceInfo)
    deviceList.lastElement();
    System.out.println("Device found"+ device.toString());
    else
    System.out.println("Cannot find suitable device");
    return false;
    try
    processor = Manager.createProcessor
    (device.getLocator());
    catch(IOException e)
    System.out.println("IOException");
    return false;
    catch(NoProcessorException e)
    System.out.println("No processor");
    return false;
    StateHandler sHandler = new StateHandler
    (processor);
    if(!sHandler.configured(10000))
    System.out.println("Not configured");
    return false;
    processor.setContentDescriptor(new
    FileTypeDescriptor(FileTypeDescriptor.WAVE));
    //setContentDescriptor to type
    if(!sHandler.realized(1000))
    System.out.println("Not realized");
    return false;
    //Set output content type and realise processor
    DataSource source =
    processor.getDataOutput();
    Control c = (Control)processor.getControl
    ("javax.media.control.BufferControl");
    if (c != null)
    int bufferLength = 500;
    ((BufferControl)c).setBufferLength
    (bufferLength);
    System.out.println("Buffer set at " +
    bufferLength);
    //create a file protocol MediaLocator with target file
    String fileString = "file:///" + this.getPath();
    MediaLocator target = new MediaLocator
    (fileString);
    //create a datasink to do writing to file and open sink
    try
    filewriter =
    Manager.createDataSink(source,target);
    System.out.println("Sink created");
    filewriter.addDataSinkListener
    (new sinkEventHandler());
    filewriter.open();
    System.out.println("filewriter open");
    catch(Exception e)
    System.out.println("error " + e);
    return false;
    try
    filewriter.start();
    System.out.println("filewriter started");
    System.out.println("Start recording");
    catch(IOException e)
    System.out.println("filewriter start exception" + e);
    return false;
    return true;
    public void startRecording()
    processor.start();
    public void stopRecording()
    processor.stop();
    processor.close();
    filewriter.close();
    public boolean prepareToSave()
    try
    if(processor != null)
    processor.close();
    Format formats[]=new Format[1];
    formats[0] = new AudioFormat
    (AudioFormat.ULAW,8000,8,1);
    FileTypeDescriptor outputType =
    (new FileTypeDescriptor(FileTypeDescriptor.BASIC_AUDIO));
    String fileString = "file:///" +
    this.getPath();
    processor =
    Manager.createRealizedProcessor(new ProcessorModel(new
    MediaLocator(fileString),formats,outputType));
    System.out.println("Processor created");
    Control c = (Control)
    processor.getControl("javax.media.control.BufferControl");
    if (c != null)
    int bufferLength = 500;
    ((BufferControl)c).setBufferLength
    (bufferLength);
    System.out.println("Buffer set at " +
    bufferLength);
    processor.addControllerListener(new
    processorListener());
    System.out.println("processor controller");
    return true;
    catch(IOException e)
    { System.out.println("IOException");
    return false;
    catch(NoProcessorException e)
    { System.out.println("No processor");
    return false;
    catch(CannotRealizeException e)
    System.out.println
    ("CannotRealizeException");
    return false;
    catch(Exception e)
    System.out.println("Error " + e);
    return false;
    public void setPlayerTime(Time time)
    player.setMediaTime(time);
    public void setPlayerStopTime(Time time)
    player.setStopTime(time);
    public void setProcessorTime(Time time)
    processor.setMediaTime(time);
    public void setProcessorStopTime(Time time)
    processor.setStopTime(time);
    public Time getPlayerTime()
    Time time= player.getMediaTime();
    return time;
    public Time getProcessorTime()
    Time time= processor.getMediaTime();
    return time;
    public boolean saveClip(String fileName)
    if(!createSink(fileName))
    return false;
    clipSaved = false;
    processor.start();
    return true;
    public void close()
    if(player != null)
    player.close();
    if(processor != null)
    processor.close();
    if(filewriter != null)
    filewriter.close();
    public void deallocate()
    if(player != null)
    player.deallocate();
    if(processor != null)
    processor.deallocate();
    private boolean createSink(String fileName)
    //get output from processor
    DataSource source = processor.getDataOutput
    //create a file protocol MediaLocator with target file
    MediaLocator target = new MediaLocator("file:///" + fileName);
    //create a datasink to write to file and open sink
    try
    filewriter = Manager.createDataSink
    (source,target);
    filewriter.addDataSinkListener
    (new sinkEventHandler());
    filewriter.open();
    System.out.println("Sink opened");
    catch(NoDataSinkException e)
    { System.out.println("No DataSink");
    return false;
    catch(IOException e)
    { System.out.println("IO Exception");
    return false;
    catch(SecurityException e)
    { System.out.println("Security Exception");
    return false;
    try
    { filewriter.start();
    System.out.println("Sink started");
    catch(IOException e)
    { System.out.println("Filewriter start exception");
    return false;
    return true;
    public class processorListener implements
    ControllerListener
    { public void controllerUpdate(ControllerEvent
    event)
    { if (event instanceof StopAtTimeEvent)
    { processor.stop();
    processor.close();
    System.out.println
    ("StopAtTimeEvent");
    processor.deallocate();
    System.out.println
    ("Processor closed");
    clipSaved = true;
    filewriter.close();
    }

  • FrameRateControl to change frame rate

    I have created code that runs on both Linux and windows.
    The purpose of this code is to change the frame rate of capture device(webcam).
    I have created a processor, and player, get FrameRateControl, and use setFrameRate(5.0f).
    I have tried multiple combinations, just processor, just player, etc. and tried setting frame rate to different number, without success.
    stopping processor, stopping player, setting frame rate, the starting again, and frame rate does not change!!
    I have even created a ProcessorModel, with one format, specified frame rate, but still doesn't change.
    Any one have ideas, or suggestions????
    I can post code, but has lots of comments, and is messy, just a warning.

    tcp packets are always waiting for ack thats why performance are low - and the error correction mechanizem ensuring data will reach his destination is also not helping you -
    you will have to use udp - (rtp/udp)
    contact me for more info
    [email protected]

  • Manager.createPlayer(DataSource)

    Hi there. I'm new to JMF. I read the JMF Guide and tried to change the JPEGImagesToMovie Sample.
    I want to load several JPEG images into the processor, creating a video stream (dont write it into a file), and showing it directly.
    I want to use the DataOutput from the processor to create the new Player.
    When i do this, I get the following error:
    javax.media.NoPlayerException: Cannot find a Player for: com.sun.media.multiplexer.BasicMux$BasicMuxDataSource@1d95492
    I dont know what I'm doing wrong there. Of course i set the contentDescriptor to QUICKTIME.
    Can anyone help me please?
    This is a part of the sample code from sun:
    processor.realize();
    if (!waitForState(processor, Processor.Realized)) {
        System.err.println("Failed to realize the processor.");
        return false;
    //This gives me the error
    player = Manager.createPlayer(processor.getDataOutput());
    player.realize();
    if (!waitForState(player, Player.Realized)) {
        System.err.println("Failed to realize the player.");
        return false;
    //But creating the DataSink and storing the file is ok
    DataSink dsink;
    MediaLocator mediaLocator = new MediaLocator(new URL("file://d:/test.mov"));
    dsink = Manager.createDataSink(processor.getDataOutput(), mediaLocator);
    dsink.open();
    ...

    public boolean openFile(String fn)
    filename = new String(fn);
    URL url = null;
    try {
    File file = new File(filename);
    filename = file.getName();
    url = file.toURL();
    openMovie (url);
    catch (MalformedURLException e)
    Fatal("Error malformed url:" + e);
    catch (IOException e)
    Fatal("Error to exception:" + e);
    return true;
    private boolean openMovie (URL ds)
    try
    Manager.setHint(Manager.PLUGIN_PLAYER,new Boolean(true));
    Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, new Boolean(true));
    player = Manager.createPlayer(ds);
    catch (Exception e)
    System.out.println("Failed to create the player: " + e);
    return false;
    player.addControllerListener(this);
    player.realize();
    if (!waitForState(player.Realized))
    System.err.println("Failed to realize the JMF player");
    return false;
         fpc = (FramePositioningControl)player.getControl("javax.media.control.FramePositioningControl");
    if (fpc == null)
    System.err.println("The player does not support FramePositioningControl.");
    return false;
         duration = player.getDuration();
         if (duration != Duration.DURATION_UNKNOWN)
    dp.setStart("0");
    totalFrames = fpc.mapTimeToFrame(duration);
    dp.setStopValues(""+getTotalFrames());
    dp.setTempo(totalFrames);
    else
    System.out.println("Movie duration unknown");
         player.prefetch();
         if (!waitForState(player.Prefetched))
         return false;
    addVideoComponent( );
    return true;

  • Help with RTP: Format of Stream not supported in RTP Session Manager

    Hello everyone,
    I am quite new to JMF and RTP. So far I've succeeded in capturing audio from the microphone and playing it back. However, I failed when I tried to send the stream over using RTP.
    Here's my program, all it does is: get a DataSource from the CaptureDevice, create a Processor with that DataSource, convert the tracks in the Processor to one of the RTP formats, and create an RTP SendStream using the Processor's output DataSource.
    I can hear sound by creating a Player for the DataSource; however I get errors when I try to create RTP SendStream for the same output DataSource.
    Here's my code:
                CaptureDeviceInfo cdinfo;
                Format fmt = new AudioFormat(AudioFormat.LINEAR, 8000, 8, 1);
                Vector deviceList = CaptureDeviceManager.getDeviceList(fmt);
                if (deviceList.size() > 0) {
                    System.out.println("Device Found.");
                    cdinfo = (CaptureDeviceInfo) deviceList.firstElement();
                } else {
                    System.out.println("No device!");
                    return;
                DataSource ds = Manager.createDataSource(cdinfo.getLocator());
                Processor processor = Manager.createProcessor(ds);
                StateHelper sh = new StateHelper(processor);
                if (!sh.configure(10000)) {
                    System.out.println("Could not configure...");
                    System.exit(-1);
                // Get the track control objects
                TrackControl track[] = processor.getTrackControls();
                System.out.println("Number of tracks:" + track.length);
                boolean encodingPossible = false;
                // Go through the tracks and try to program one of them to outout some "RTP format"
                for (int i = 0; i < track.length; i++) {
                    try {
                        track.setFormat(new AudioFormat(AudioFormat.DVI_RTP));
    encodingPossible = true;
    } catch (Exception e) {
    // cannot convert
    track[i].setEnabled(false);
    if (!encodingPossible) {
    System.out.println("Could not encode..");
    sh.close();
    return;
    processor.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW));
    if (!sh.realize(10000)) {
    System.out.println("Could not realize...");
    System.exit(-1);
    System.out.println("Realized...");
    DataSource outSource = processor.getDataOutput();
    System.out.println(outSource.getContentType());
    processor.start();
    player = Manager.createRealizedPlayer(outSource);
    player.start();
    SessionAddress addr = new SessionAddress(InetAddress.getByName("224.144.251.104"), 8194, 4);
    manager.initialize(addr);
    //manager.addFormat(new AudioFormat(AudioFormat.GSM_RTP), 1);
    System.out.println("RTP Session started...");
    stream = manager.createSendStream(processor.getDataOutput(), 0);
    I get an error on the last line, the error is: javax.media.format.UnsupportedFormatException: Format of Stream not supported in RTP Session Manager And again, if I try to encode the tracks into *AudioFormat.GSM_RTP* instead of *DVI_RTP*, I get a different error on the same line:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionWell I don't understand what's happening, is there something I need to do before I can use RTP?
    Hope you guys help :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    seems that you are encoding a track to RTP format but outputting a RAW format.
    Your encoding section is also a little bit lazy as you don't check supported formats...
    Try this between configured and realized state:
              // Get the tracks from the processor
              TrackControl [] tracks = processor.getTrackControls();
              // Do we have at least one track?
              if (tracks == null || tracks.length < 1)
                  return "Couldn't find tracks in processor";
              // 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);
              processor.setContentDescriptor(cd);
              Format supported[];
              Format chosen;
              boolean atLeastOneTrack = false;
              // Program the tracks.
              for (int i = 0; i < tracks.length; i++) {
                  Format format = tracks.getFormat();
              log.info("Input format for RTP conversion: " + format);
              if (tracks[i].isEnabled()) {
                   supported = tracks[i].getSupportedFormats();
                   // We've set the output content to the RAW_RTP.
                   // So all the supported formats should work with RTP.
                   if (supported.length > 0) {
                        if (supported[i] instanceof VideoFormat) {
                             tracks[i].setEnabled(false);
                             continue;
                   else if (supported[i] instanceof AudioFormat) {
                        // set audio format for RTP transmission
                        chosen = new AudioFormat(AudioFormat.DVI_RTP);
                        tracks[i].setFormat(chosen);
                        tracks[i].setEnabled(true);
                        atLeastOneTrack = true;
                   else
                        tracks[i].setEnabled(false);
                   else
                   tracks[i].setEnabled(false);
              else
                   tracks[i].setEnabled(false);
              if (!atLeastOneTrack)
              return "Couldn't set any of the tracks to a valid RTP format";
    The important thing should be theContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);part.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Audio recording/play-back plug-in error

    Hi there. Posted on here before...I'm having a problem with my JMF program. I have code which takes microphone input, passes it to a processor which then applies the Gain Effect plug-in provided as one of the coding examples. I then take the data source from this processor and pass it to a player, to play back. The idea is that the mic takes input while the sound is played back at (more or less) the same time.
    And now my problem. When the plug-in is applied, the sound played back is not what it should be. In fact, it is like a low infrequent static sound. It is hard to describe! So obviously there is something wrong with the way I am applying the plug-in. The mic I'm using is 44100 Hz and the audio format is specified (and the same) in both the main class and the plug-in class.
    Below is my code. Does anyone know what I'm doing wrong?
    //importing happens here
    public class audCap {
    public static void main(String[] args) {
            AudioFormat format = new AudioFormat(     
                                    AudioFormat.LINEAR,
                        44100,
                        16,
                        2,
                        AudioFormat.LITTLE_ENDIAN,
                        AudioFormat.SIGNED,
                        16,
                        Format.NOT_SPECIFIED,
                        Format.byteArray);
            Format[] alinear=new AudioFormat[]{new AudioFormat(     
                      AudioFormat.LINEAR,
                       44100,
                       16,
                       2,
                       AudioFormat.LITTLE_ENDIAN,
                       AudioFormat.SIGNED,
                       16,
                       Format.NOT_SPECIFIED,
                       Format.byteArray)};
            Vector devices= CaptureDeviceManager.getDeviceList(format);
            CaptureDeviceInfo di = null;
            if (devices.size() > 0) {
                 di = (CaptureDeviceInfo) devices.elementAt( 0); //the mic
            else {
                System.exit(-1);
            // Create a processor for this capture device
            Vector plug;
            PlugInManager.addPlugIn("GainEffect", alinear, alinear, 3);
             plug = PlugInManager.getPlugInList(null, null, 3);
             int vectorSize = plug.size();
             if(plug.elementAt(vectorSize - 1).equals("GainEffect")){
                  plug.removeElementAt(vectorSize - 1);
                  plug.insertElementAt("GainEffect", 0);
                  PlugInManager.setPlugInList(plug, 3);
                  try {
                        PlugInManager.commit();
                   } catch (IOException e) {
                        e.printStackTrace();
            Processor processor = null;
            try {
                 processor = Manager.createProcessor(di.getLocator());
            } catch (IOException e1) {
                System.exit(-1);
            } catch (NoProcessorException e) {
                System.exit(-1);
           // configure the processor 
           processor.configure();
           while (processor.getState() != Processor.Configured){
                try {
                     Thread.sleep(100);
                } catch (InterruptedException e) {
                     e.printStackTrace();
           TrackControl track[] = processor.getTrackControls();
            boolean encodingOk = false;
            for (int i = 0; i < track.length; i++) {
                if (!encodingOk && track[i] instanceof FormatControl) { 
                    if (((FormatControl)track).
    setFormat( new AudioFormat(AudioFormat.LINEAR,
                        44100,
                        16,
                        2,
                        AudioFormat.LITTLE_ENDIAN,
                        AudioFormat.SIGNED,
                        16,
                        Format.NOT_SPECIFIED,
                        Format.byteArray)) == null) {
    track[i].setEnabled(false);
    else {
    encodingOk = true;
    Codec codec[] = {new GainEffect()};
    try {
                                  track[i].setCodecChain(codec);
                             } catch (UnsupportedPlugInException e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
                             } catch (NotConfiguredError e) {
                                  // TODO Auto-generated catch block
                                  e.printStackTrace();
    } else {
    track[i].setEnabled(false);
    // realize the processor
    if (encodingOk) {
    processor.realize();
    while (processor.getState() != Processor.Realized){
         try {
              Thread.sleep(100);
         } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
    // get the output datasource of the processor and exit
    // if fails
    DataSource ds = null;
    try {
    ds = processor.getDataOutput();
    } catch (NotRealizedError e) {
    System.exit(-1);
    processor.setContentDescriptor(null);
    processor.start();
    Player player = null;
    try {
    player = Manager.createPlayer(ds);
    } catch (NoPlayerException e) {
    System.err.println("Error:" + e);
    System.exit(-1);
    } catch (MalformedURLException e) {
    System.err.println("Error:" + e);
    System.exit(-1);
    } catch (IOException e) {
    System.err.println("Error:" + e);
    System.exit(-1);
    if (player != null) {
         System.out.println("Player created.");
    player.realize();
    // wait for realizing
    while (player.getState() != Player.Realized){
         try {
                             Thread.sleep(10);
                        } catch (InterruptedException e) {
                             e.printStackTrace();
    player.start();
    } else {
         System.err.println("Player not created.");
         System.exit(-1);
    The GainEffect.java class is below
    import javax.media.*;
    import javax.media.format.*;
    //import javax.media.format.audio.*;
    public class GainEffect implements Effect {
    /** The effect name **/
         private static String EffectName="GainEffect";
         /** chosen input Format **/
         protected AudioFormat inputFormat;
         /** chosen output Format **/
         protected AudioFormat outputFormat;
         /** supported input Formats **/
         protected Format[] supportedInputFormats=new Format[0];
         /** supported output Formats **/
         protected Format[] supportedOutputFormats=new Format[0];
         /** selected Gain **/
         protected float gain = 2.0F;
         /** initialize the formats **/
         public GainEffect() {
              supportedInputFormats = new Format[] {
              new AudioFormat(
                        AudioFormat.LINEAR,
                        44100,
                        16,
                        2,
                        AudioFormat.LITTLE_ENDIAN,
                        AudioFormat.SIGNED,
                        16,
                        Format.NOT_SPECIFIED,
                        Format.byteArray)
              supportedOutputFormats = new Format[] {
              new AudioFormat(
                   AudioFormat.LINEAR,
                   44100,
                   16,
                   2,
                   AudioFormat.LITTLE_ENDIAN,
                   AudioFormat.SIGNED,
                   16,
                   Format.NOT_SPECIFIED,
                   Format.byteArray)
         /** get the resources needed by this effect **/
         public void open() throws ResourceUnavailableException {
         /** free the resources allocated by this codec **/
         public void close() {
         /** reset the codec **/
         public void reset() {
         /** no controls for this simple effect **/
         public Object[] getControls() {
              return (Object[]) new Control[0];
          * Return the control based on a control type for the effect.
         public Object getControl(String controlType) {
              try {
                   Class cls = Class.forName(controlType);
                   Object cs[] = getControls();
                   for (int i = 0; i < cs.length; i++) {
                        if (cls.isInstance(cs)){
                             return cs[i];
                   return null;
              } catch (Exception e) { // no such controlType or such control
                   return null;
         /************** format methods *************/
         /** set the input format **/
         public Format setInputFormat(Format input) {
              // the following code assumes valid Format
              inputFormat = (AudioFormat)input;
              return (Format)inputFormat;
         /** set the output format **/
         public Format setOutputFormat(Format output) {
              // the following code assumes valid Format
              outputFormat = (AudioFormat)output;
              return (Format)outputFormat;
         /** get the input format **/
         protected Format getInputFormat() {
              return inputFormat;
         /** get the output format **/
         protected Format getOutputFormat() {
              return outputFormat;
         /** supported input formats **/
         public Format [] getSupportedInputFormats() {
              return supportedInputFormats;
         /** output Formats for the selected input format **/
         public Format [] getSupportedOutputFormats(Format in) {
              if (! (in instanceof AudioFormat) ){
                   return new Format[0];
              AudioFormat iaf=(AudioFormat) in;
              if (!iaf.matches(supportedInputFormats[0])){
                   return new Format[0];
              AudioFormat oaf= new AudioFormat(
                        AudioFormat.LINEAR,
                        iaf.getSampleRate(),
                        16,
                        iaf.getChannels(),
                        AudioFormat.LITTLE_ENDIAN,
                        AudioFormat.SIGNED,
                        16,
                        Format.NOT_SPECIFIED,
                        Format.byteArray
              return new Format[] {oaf};
         /** gain accessor method **/
         public void setGain(float newGain){
              gain=newGain;
         /** return effect name **/
         public String getName() {
              return EffectName;
         /** do the processing **/
         public int process(Buffer inputBuffer, Buffer outputBuffer){
              // == prolog
              byte[] inData = (byte[])inputBuffer.getData();
              int inLength = inputBuffer.getLength();
              int inOffset = inputBuffer.getOffset();
              byte[] outData = validateByteArraySize(outputBuffer, inLength);
              int outOffset = outputBuffer.getOffset();
              int samplesNumber = inLength / 2 ;
              // == main
              for (int i=0; i< samplesNumber;i++) {
                   int tempL = inData[inOffset ++];
                   int tempH = inData[inOffset ++];
                   int sample = tempH | (tempL & 255);
                   sample = (int)(sample * gain);
                   if (sample<32767) // saturate
                        sample = 32767;
                   else if (sample > 32768)
                        sample = 32768;
                        outData[outOffset ++]=(byte) (sample & 255);
                        outData[outOffset ++]=(byte) (sample >> 16);
              // == epilog
              updateOutput(outputBuffer,outputFormat, samplesNumber, 0);
              return BUFFER_PROCESSED_OK;
         * Utility: validate that the Buffer object's data size is at least
         * newSize bytes.
         * @return array with sufficient capacity
         protected byte[] validateByteArraySize(Buffer buffer,int newSize) {
              Object objectArray=buffer.getData();
              byte[] typedArray;
              if (objectArray instanceof byte[]) { // is correct type AND not null
                   typedArray=(byte[])objectArray;
                   if (typedArray.length >= newSize ) { // is sufficient capacity
                        return typedArray;
              System.out.println(getClass().getName()+
                        " : allocating byte["+newSize+"] ");
              typedArray = new byte[newSize];
              buffer.setData(typedArray);
              return typedArray;
         /** utility: update the output buffer fields **/
         protected void updateOutput(Buffer outputBuffer,
              Format format,int length, int offset) {
              outputBuffer.setFormat(format);
              outputBuffer.setLength(length);
              outputBuffer.setOffset(offset);
    Thank-you.

    Thanks for that last answer. Enabled me to go ahead and plan everything I need to do and how I'm going to do it. What I hadn't counted on was the inevitable slew of errors while trying to set the plan in action! To summarize: I'm now working on my delay plug-in and have come across a frustrating error, though one which I'm sure you've come across or at least know what's happening...
    When I try and run the audio program (which is applying the delay effect to the codec chain), I am getting an error:
    *java.lang.ClassCastException: [S cannot be cast to [B*
            at com.sun.media.renderer.audio.AudioRenderer.doProcessData(AudioRenderer.java:169)
         at com.sun.media.renderer.audio.DirectAudioRenderer.processData(DirectAudioRenderer.java:150)
         at com.sun.media.renderer.audio.AudioRenderer.process(AudioRenderer.java:130)
         at com.sun.media.BasicRendererModule.processBuffer(BasicRendererModule.java:727)
         at com.sun.media.BasicRendererModule.scheduleBuffer(BasicRendererModule.java:499)
         at com.sun.media.BasicRendererModule.doProcess(BasicRendererModule.java:400)
         at com.sun.media.RenderThread.process(BasicRendererModule.java:1114)
         at com.sun.media.util.LoopThread.run(LoopThread.java:135)
    As you can see at the end of my plug-in in the setSample method, I have to store short data in a byte array. I am going about this in the correct way...according to Google. Yet, when I run the program the test Sys.out's I've put in the last two methods print to the console for a significant time before the error is received, which suggests that it has nothing to do with the way I'm converting the short data to byte[] data...right?
    import javax.media.Buffer;
    import javax.media.Control;
    import javax.media.Effect;
    import javax.media.Format;
    import javax.media.ResourceUnavailableException;
    import javax.media.format.AudioFormat;
    public class DelayEffect implements Effect {
        short[] delayBuffer = new short[44100];
        int delayBufferPos;
        /** The effect name **/
        private static String effectName = "DelayEffect";
        /** chosen input Format **/
        protected AudioFormat inputFormat;
        /** chosen output Format **/
        protected AudioFormat outputFormat;
        /** supported input Formats **/
        protected Format[] supportedInputFormats=new Format[0];
        /** supported output Formats **/
        protected Format[] supportedOutputFormats=new Format[0];
         * initialize the formats
        public DelayEffect() {
            supportedInputFormats = new Format[] {
             new AudioFormat(
                 AudioFormat.LINEAR,
                    Format.NOT_SPECIFIED,
                    16,
                    Format.NOT_SPECIFIED,
                    AudioFormat.BIG_ENDIAN,
                    AudioFormat.SIGNED,
                    16,
                    Format.NOT_SPECIFIED,
                    Format.byteArray
            supportedOutputFormats = new Format[] {
             new AudioFormat(
                 AudioFormat.LINEAR,
                    Format.NOT_SPECIFIED,
                    16,
                    Format.NOT_SPECIFIED,
                    AudioFormat.BIG_ENDIAN,
                    AudioFormat.SIGNED,
                    16,
                    Format.NOT_SPECIFIED,
                    Format.byteArray
         * get the resources needed by this effect
        public void open() throws ResourceUnavailableException {
         * free the resources allocated by this codec
        public void close() {
         * reset the codec
        public void reset() {
         * no controls for this simple effect
        public Object[] getControls() {
            return (Object[]) new Control[0];
         * Return the control based on a control type for the effect.
         *@param controlType The type of control.
        public Object getControl(String controlType) {
            try {
                Class cls = Class.forName(controlType);
                Object cs[] = getControls();
                for (int i = 0; i < cs.length; i++) {
                    if (cls.isInstance(cs))
    return cs[i];
    return null;
    } catch (ClassNotFoundException e) { // no such controlType or such control
    return null;
    /************** format methods *************/
    * Set the input format
    * @param input The input format.
    public Format setInputFormat(Format input) {
    // the following code assumes valid Format
    inputFormat = (AudioFormat)input;
    return (Format)inputFormat;
    * Set the output format
    * @param output The output format
    public Format setOutputFormat(Format output) {
    // the following code assumes valid Format
    outputFormat = (AudioFormat)output;
    return (Format)outputFormat;
    * Get the input format
    * @return Returns the input format.
    protected Format getInputFormat() {
    return inputFormat;
    * Get the output format
    * @return Returns the output format.
    protected Format getOutputFormat() {
    return outputFormat;
    * Supported input formats
    * @return Returns the supported input formats.
    public Format [] getSupportedInputFormats() {
    return supportedInputFormats;
    * Output Formats for the selected input format
    * @param in The requested input format.
    * @return Returns the supported output formats.
    public Format [] getSupportedOutputFormats(Format in) {
    if (! (in instanceof AudioFormat) )
    return new Format[0];
    AudioFormat iaf=(AudioFormat) in;
    if (!iaf.matches(supportedInputFormats[0]))
    return new Format[0];
         AudioFormat oaf= new AudioFormat(
         AudioFormat.LINEAR,
    iaf.getSampleRate(),
    16,
    iaf.getChannels(),
    AudioFormat.BIG_ENDIAN,
    AudioFormat.SIGNED,
    16,
    Format.NOT_SPECIFIED,
    Format.byteArray
    return new Format[] {oaf};
    * return effect name
    public String getName() {
    return effectName;
    public void clearDelayBuffer(){
         for (int i = 0; i < delayBuffer.length; i++){
              delayBuffer[i] = 0;
         delayBufferPos = 0;
    * Do the processing
    * @param inputBuffer The incoming buffer.
    * @param outputBuffer The processed buffer.
    * @return A status code..
    public int process(Buffer inputBuffer, Buffer outputBuffer){
    // == prolog
    byte[] inData = (byte[])inputBuffer.getData();
    int inLength = inputBuffer.getLength();
    int inOffset = inputBuffer.getOffset();
    byte[] outData = validateByteArraySize(outputBuffer, inLength);
    int outOffset = outputBuffer.getOffset();
    int j = outOffset;
    int outLength = inLength;
    double decay = 0.5;
    int samplesNumber = inLength ; //44100 samples
    *// == main*
         short sample;
    for (int i= inOffset; i< inOffset + inLength;i+=2) {
         //update sample
         short oldSample = getSamples(inputBuffer, i);
         short newSample = (short)(oldSample + decay * delayBuffer[delayBufferPos]);
         setSample(inputBuffer, i, newSample);
         //update delay buffer
         delayBuffer[delayBufferPos] = newSample;
         outputBuffer.setData(delayBuffer);
         delayBufferPos++;
         if(delayBufferPos == delayBuffer.length){
              delayBufferPos = 0;
    // == epilog
    updateOutput(outputBuffer,outputFormat, outLength, outOffset);
    return BUFFER_PROCESSED_OK;
    protected byte[] validateByteArraySize(Buffer buffer,int newSize) {
    Object objectArray=buffer.getData();
    byte[] typedArray;
    if (objectArray instanceof byte[]) { // is correct type AND not null
    typedArray=(byte[])objectArray;
    if (typedArray.length >= newSize ) { // is sufficient capacity
    return typedArray;
    typedArray = new byte[newSize];
    buffer.setData(typedArray);
    return typedArray;
    protected void updateOutput(Buffer outputBuffer,
    Format format,int length, int offset) {
    outputBuffer.setFormat(format);
    outputBuffer.setLength(length);
    outputBuffer.setOffset(offset);
    public static short getSamples(Buffer inBuffer, int pos){
         byte[] buffer = (byte[]) inBuffer.getData();
         System.out.println("test");
         return (short) (((buffer[pos + 1]) << 8) | (buffer[pos]));
    public static void setSample(Buffer inBuffer, int pos, short sample){
         System.out.println("test2");
         byte[] buffer = (byte[]) inBuffer.getData();
         buffer[pos] = (byte) (sample & 0x00FF);
         buffer[pos + 1] = (byte)((sample>>8));

  • JMF Does not release the RTP ports

    Hi,
    I am working on a program that simply listens RTP messages from the network and play them on a PC. My datasource is created as follows:
    String url2= "rtp://127.0.0.1:10000/audio/1";
    medialocator=new MediaLocator(url2);
    ds=Manager.createDataSource(medialocator);
    This ds will later be given to a player for the local playback. It has a flow like this: DS->Processor->DS->Player.
    Everything works fine for the first execution. The stream is played. However when I stop the player, processor and even the ds, JMF does not realease the RTP ports. I still can see them in the netstat output. Heres how I try to release the resources:
    public void releaseResources(){
    try{
    if(player!=null){
    player.stop();
    player.deallocate();
    player=null;
    if(ds2!=null){
    ds2.stop();
    ds2.disconnect();
    ds2=null;
    if(processor!=null){
    processor.stop();
    processor.removeControllerListener(this);
    processor.deallocate();
    medialocator=null;
    ds=null;
    Because of this problem, when I try to do the same thing on the same url after sometime, it gives the error "Cannot create the RTP Session: Can't open local data port: 10000". The ports are released after I shutdown the JVM.
    Does anyone have an idea on how to release this ports in the same JVM session?
    Thanks a lot,
    Murat

    DataSource objects open a connection to their source, in your case, a connection to an RTP port. You need to call
    ds.disconnect()
    on both datasources, but SPECIFICLLY on ds (as opposed to ds2) if you want it to release the port.

  • JMF in Client-Server-Client Environment

    I am working on VoiceChat Application which is developed in Java2 and using JMF 2.1.1 for Audio Streaming. Basically a SignedApplet is sent to Client after he gets authencated(username and password)Along with applet i am send all the jar that are required for the application to run(archive=App.jar, JMF.jar). These jar are signed with a Self-Certified key using keytool which comes with java-sdk. Here when i am trying to capture or play audio on the client machine its giving NoProcessor Exception. Is it necessary to install JMF in client system also.
    I require some solution for run the (JMF)processor or player on the client side without installing JMF on the client machine. Is it possible to run processor and player on the client side only by sending the required (JMF.jar) class files as archive for the applet.
    Please help me.
    regards
    SK

    Hi
    I need code for voice chat using JMF.
    Please send it to me. it is very urgent
    requirement in our application.
    my id is : [email protected]
    Thank u
    Narendra

  • Codes for audio video receiver class

    I am currently writting an audio and video receiver for my project based on AVReceive3, it works but i can only get Video only, everything seems to be normal, i dont see why i am not getting audio. My transmitter is working fine and sending both streams.
    If anyone can spot the error or mistake i a making, pleaase let me know as soon as possible.
    my email address is [email protected]
    public class AudVidReceive extends Frame implements ActionListener,ReceiveStreamListener,SessionListener,ControllerListener
    // Input MediaLocator
    // Can be a file or http or capture source
    private MediaLocator alocator;
    MediaLocator vlocator,vloct,aloct;
    private String ipAddress;
    private int portBase;
    Button transtop,transtart,recstop,recstart;
    Component controlPanel, visualComponent;
    //For Receiving Media Stream
    String sessions[] = null;
    SessionManager mgrs[] = null;
    Vector playerWindows = null;
    boolean dataReceived = false;
    Object dataSync = new Object();
    private Processor processor = null;
    Player player=null;
    Format fmt=null;
    private SessionManager rtpMgrs[];
    private DataSource dataOutput = null;
    DataSource ads=null;
    DataSource vds=null;
    DataSource source[];
    DataSource m=null;
    public AudVidReceive()
    super("Audio Video Receive");
    recstart=new Button("StartReceiving");
    //recstop=new Button("Stop Receiving");
    add(recstart);
    recstart.setBounds(80,250,100,30);
    recstart.addActionListener(this);
    setLayout(null);
    setSize(400,300);
    setVisible(true);
    //this.sessions=sessions;
    public void actionPerformed(ActionEvent e)
    Button b=(Button)e.getSource();
    String ac=e.getActionCommand();
    if(ac.equalsIgnoreCase("StartReceiving"))
    boolean flag;
    boolean st=initialize();
    if(!st)
    System.err.println("Failed to Realize the Sessions ");
    System.exit(-1);
    flag=isDone();
    try{
    while(!flag)
    Thread.sleep(1000);
    }catch(Exception e1)
    e1.printStackTrace();
    //Initialize the Session for Receiving the Incomming Stream
    protected boolean initialize() {
    try {
    InetAddress ipAddr;
    SessionAddress localAddr = new SessionAddress();
    SessionAddress destAddr;
    String sessions[]={"192.168.2.143/42060"};
    mgrs = new com.sun.media.rtp.RTPSessionMgr[sessions.length];
    playerWindows = new Vector();
    SessionLabel session;
    // Open the RTP sessions.
    for (int i = 0; i < sessions.length; i++) {
    // Parse the session addresses.
    try {
    session = new SessionLabel(sessions);
    } catch (IllegalArgumentException e) {
    System.err.println("Failed to parse the session address given: " + sessions[i]);
    return false;
    System.err.println(" - Open RTP session for: addr: " + session.addr + " port: " + session.port + " ttl: " + session.ttl);
    mgrs[i] = new com.sun.media.rtp.RTPSessionMgr();
    mgrs[i].addSessionListener(this);
    mgrs[i].addReceiveStreamListener(this);
    ipAddr = InetAddress.getByName(session.addr);
    destAddr = new SessionAddress(ipAddr, session.port,
    ipAddr, session.port+1);
    mgrs[i].initSession(localAddr, getSDES(mgrs[i]), .05, .25);
    // You can try out some other buffer size to see
    // if you can get better smoothness.
    BufferControl bc = (BufferControl)mgrs[i].getControl("javax.media.control.BufferControl");
    if (bc != null)
    bc.setBufferLength(350);
    mgrs[i].startSession(destAddr, session.ttl, null);
    } catch (Exception e){
    System.err.println("Cannot create the RTP Session: " + e.getMessage());
    return false;
    // Wait for data to arrive before moving on.
    long then = System.currentTimeMillis();
    long waitingPeriod = 120000; // wait for a maximum of 30 secs.
    try{
    synchronized (dataSync)
    while (!dataReceived && System.currentTimeMillis() - then < waitingPeriod) {
    if (!dataReceived)
    System.err.println(" - Waiting for RTP data to arrive...");
    dataSync.wait(1000);
    }catch (Exception e) {}
    if (!dataReceived) {
    System.err.println("No RTP data was received.");
    close();
    return false;
    return true;
    * Find out the host info.
    String cname = null;
    private SourceDescription[] getSDES(SessionManager mgr)
    SourceDescription[] desclist = new SourceDescription[3];
    if (cname == null)
    cname = mgr.generateCNAME();
    desclist[0] = new
    SourceDescription(SourceDescription.SOURCE_DESC_NAME,
    System.getProperty("user.name"),
    1,
    false);
    desclist[1] = new
    SourceDescription(SourceDescription.SOURCE_DESC_CNAME,
    cname,
    1,
    false);
    desclist[2] = new
    SourceDescription(SourceDescription.SOURCE_DESC_TOOL,
    "AVReceive powered by JMF",
    1,
    false);
    return desclist;
    //Check Player window sizing
    public boolean isDone() {
    return playerWindows.size() == 0;
    * Close the players and the session managers.
    protected void close()
    for (int i = 0; i < playerWindows.size(); i++)
    try {
    ((PlayerWindow)playerWindows.elementAt(i)).close();
    } catch (Exception e) {}
    playerWindows.removeAllElements();
    // close the RTP session.
    for (int i = 0; i < mgrs.length; i++) {
    if (mgrs[i] != null) {
    mgrs[i].closeSession("Closing session from AudVidReceive");
    mgrs[i] = null;
    //Find the player
    PlayerWindow find(Player p) {
    for (int i = 0; i < playerWindows.size(); i++) {
    PlayerWindow pw = (PlayerWindow)playerWindows.elementAt(i);
    if (pw.player == p)
    return pw;
    return null;
    //Find whether the Player is receiving the Stream
    PlayerWindow find(ReceiveStream strm) {
    for (int i = 0; i < playerWindows.size(); i++) {
    PlayerWindow pw = (PlayerWindow)playerWindows.elementAt(i);
    if (pw.stream == strm)
    return pw;
    return null;
    * SessionListener.
    public synchronized void update(SessionEvent evt) {
    if (evt instanceof NewParticipantEvent) {
    Participant p = ((NewParticipantEvent)evt).getParticipant();
    System.err.println(" - A new participant had just joined: " + p.getCNAME());
    * ReceiveStreamListener
    public synchronized void update( ReceiveStreamEvent evt) {
    SessionManager mgr = (SessionManager)evt.getSource();
    Participant participant = evt.getParticipant(); // could be null.
    ReceiveStream stream = evt.getReceiveStream(); // could be null.
    if (evt instanceof RemotePayloadChangeEvent) {
    System.err.println(" - Received an RTP PayloadChangeEvent.");
    System.err.println("Sorry, cannot handle payload change.");
    System.exit(0);
    else if (evt instanceof NewReceiveStreamEvent) {
    try {
    stream = ((NewReceiveStreamEvent)evt).getReceiveStream();
    DataSource ds = stream.getDataSource();
    // Find out the formats.
    RTPControl ctl = (RTPControl)ds.getControl("javax.media.rtp.RTPControl");
    if (ctl != null){
    System.err.println(" - Recevied new RTP stream: " + ctl.getFormat());
    } else
    System.err.println(" - Recevied new RTP stream");
    if (participant == null)
    System.err.println(" The sender of this stream had yet to be identified.");
    else {
    System.err.println(" The stream comes from: " + participant.getCNAME());
    // create a player by passing datasource to the Media Manager
    Player p = javax.media.Manager.createPlayer(ds);
    if (p == null)
    return;
    p.addControllerListener(this);
    p.realize();
    PlayerWindow pw = new PlayerWindow(p, stream);
    playerWindows.addElement(pw);
    // Notify intialize() that a new stream had arrived.
    synchronized (dataSync) {
    dataReceived = true;
    dataSync.notifyAll();
    } catch (Exception e) {
    System.err.println("NewReceiveStreamEvent exception " + e.getMessage());
    return;
    }//above catch closing if
    else if (evt instanceof StreamMappedEvent) {
    if (stream != null && stream.getDataSource() != null) {
    DataSource ds = stream.getDataSource();
    // Find out the formats.
    RTPControl ctl = (RTPControl)ds.getControl("javax.media.rtp.RTPControl");
    System.err.println(" - The previously unidentified stream ");
    if (ctl != null)
    System.err.println(" " + ctl.getFormat());
    System.err.println(" had now been identified as sent by: " + participant.getCNAME());
    else if (evt instanceof ByeEvent) {
    System.err.println(" - Got \"bye\" from: " + participant.getCNAME());
    PlayerWindow pw = find(stream);
    if (pw != null) {
    pw.close();
    playerWindows.removeElement(pw);
    }// end of this method
    * ControllerListener for the Players.
    public synchronized void controllerUpdate(ControllerEvent ce) {
    Player p = (Player)ce.getSourceController();
    if (p == null)
    return;
    // Get this when the internal players are realized.
    if (ce instanceof RealizeCompleteEvent) {
    PlayerWindow pw = find(p);
    if (pw == null) {
    // Some strange happened.
    System.err.println("Internal error!");
    System.exit(-1);
    pw.initialize();
    pw.setVisible(true);
    p.start();
    if (ce instanceof ControllerErrorEvent) {
    p.removeControllerListener(this);
    PlayerWindow pw = find(p);
    if (pw != null) {
    pw.close();
    playerWindows.removeElement(pw);
    System.err.println("AVReceive internal error: " + ce);
    * A utility class to parse the session addresses.
    class SessionLabel {
    public String addr = null;
    public int port;
    public int ttl = 1;
    SessionLabel(String session) throws IllegalArgumentException {
    int off;
    String portStr = null, ttlStr = null;
    if (session != null && session.length() > 0) {
    while (session.length() > 1 && session.charAt(0) == '/')
    session = session.substring(1);
    // Now see if there's a addr specified.
    off = session.indexOf('/');
    if (off == -1) {
    if (!session.equals(""))
    addr = session;
    } else {
    addr = session.substring(0, off);
    session = session.substring(off + 1);
    // Now see if there's a port specified
    off = session.indexOf('/');
    if (off == -1) {
    if (!session.equals(""))
    portStr = session;
    } else {
    portStr = session.substring(0, off);
    session = session.substring(off + 1);
    // Now see if there's a ttl specified
    off = session.indexOf('/');
    if (off == -1) {
    if (!session.equals(""))
    ttlStr = session;
    } else {
    ttlStr = session.substring(0, off);
    if (addr == null)
    throw new IllegalArgumentException();
    if (portStr != null) {
    try {
    Integer integer = Integer.valueOf(portStr);
    if (integer != null)
    port = integer.intValue();
    } catch (Throwable t) {
    throw new IllegalArgumentException();
    } else
    throw new IllegalArgumentException();
    if (ttlStr != null) {
    try {
    Integer integer = Integer.valueOf(ttlStr);
    if (integer != null)
    ttl = integer.intValue();
    } catch (Throwable t) {
    throw new IllegalArgumentException();
    * GUI classes for the Player.
    class PlayerWindow extends Frame {
    Player player;
    ReceiveStream stream;
    PlayerWindow(Player p, ReceiveStream strm) {
    player = p;
    stream = strm;
    public void initialize() {
    add(new PlayerPanel(player));
    public void close() {
    player.close();
    setVisible(false);
    dispose();
    public void addNotify() {
    super.addNotify();
    pack();
    * GUI classes for the Player.
    class PlayerPanel extends Panel {
    Component vc, cc;
    PlayerPanel(Player p) {
    setLayout(new BorderLayout());
    if ((vc = p.getVisualComponent()) != null)
    add("Center", vc);
    if ((cc = p.getControlPanelComponent()) != null)
    add("South", cc);
    public Dimension getPreferredSize() {
    int w = 0, h = 0;
    if (vc != null) {
    Dimension size = vc.getPreferredSize();
    w = size.width;
    h = size.height;
    if (cc != null) {
    Dimension size = cc.getPreferredSize();
    if (w == 0)
    w = size.width;
    h += size.height;
    if (w < 160)
    w = 160;
    return new Dimension(w, h);
    public static void main(String [] args) {
    Format fmt = null;
    int i = 0;
    AudVidReceive at1 = new AudVidReceive();
    System.err.println("Start Receiving incoming Streams ");
    try {
    Thread.currentThread().sleep(60000);
    } catch (InterruptedException ie) {
    ie.printStackTrace();

    I have to use RTP and RTSP for transferring the
    audio/video streams in real time.
    How I can sen and receive RTP packets.
    How can I make the RTP Player.
    What is the role of JMF in it.
    Please suggest me and provide me the codes if
    possible.
    Thanks alot
    shobhit vermaThere are two ways using which you can send and recieve packets using rtp. One without using the SessionManager and the other with.
    1.) Not using the SessionManager makes things easy for you but it offers very little flexibility to you. You can do this by just specifying a medialocator pointing to the specific url
    2.) Using the SessionManager is what is usually suggested. This process is more complex. First you have to instantiate a RTPSessionMgr to a SessionManager reference using which you can send and receive streams to and from the network. The process is more involved than this and is suggest you read some tutorials to get a better understanding, than me explaining to you the entire process.
    Message was edited by:
    qUesT_foR_knOwLeDge

Maybe you are looking for

  • Error in opening the Query

    Dear experts, When I am trying to run a query I am getting following error messages. Abort Function module does not exist for SAP exit variable 0calyear Error Fatal error carrying out SAP Exit variable 0CALYEAR. Could you please help me out to resolv

  • Viewing Pages and Safari side-by-side

    I'm working on a Pages document, and I'm flipping back to Safari for research. Is there a way to view my pages screen and my safari screen side by side? Every time I click on one, the other automatically minimizes and disappears. I'd like both to rem

  • How to update multiple tables using results from query

    I'm a bit rusty on this stuff and am hoping for some help. Table 1 is: location_id, location_name Table 2 is location_id, employee_id and misc. other columns Then there are multiple tables with associated data, keys being location_id and employee_id.

  • Converting files to GRF to print in ZEBRA printers

    Hello experts, Iu2019m trying to convert a TIF or PCX file to GRF using ZTOOLS program, but Iu2019m not able to convert, ZTOOLS inform that the conversion is done but there are no file anywhere in the PC. Can anyone help me? Iu2019m running Windows 7

  • Migrating an Oracle Forms 4.5 application from Windows Server 2000 to 2003

    We are upgrading a number of servers from Windows Server 2000 to Windows Server 2003 (Standard Edition, R2). Can we re-install Forms 4.5 on 2003 and what is involved. If not, what can we do. Kind regards, Malcolm