NoPlayerException in a RTP session

hi, I'm learning jmf and follow the jmf2_0-guide. However, when I run the following code, it always says "Error:javax.media.NoPlayerException: Cannot find a Player for :rtp://192.168.1.22:8080/jmfstudy/testMedia.avi". 192.168.1.22:8080 is my ip and port. Could anyone help me?Thanks.
String url = "rtp://192.168.1.22:8080/jmfstudy/testMedia.avi";
          MediaLocator mrl = new MediaLocator(url);
          if (mrl == null) {
               System.err.println("Can't build MRL for RTP");
               return false;
          // Create a player for this rtp session
          try {
               player = Manager.createPlayer(mrl);
          } catch (NoPlayerException e) {
               System.err.println("Error:" + e);
               return false;
          } catch (MalformedURLException e) {
               System.err.println("Error:" + e);
               return false;
          } catch (IOException e) {
               System.err.println("Error:" + e);
               return false;
          }

Thank you. I use Tomcat as my server and when I visit "http://192.168.1.22:8080/jmfstudy/testMedia.avi" my media player startup and play the movie. But it doesn't work in my programme.

Similar Messages

  • JMF error - Format of Stream not supported in RTP Session Manager

    java.io.IOException: Format of Stream not supported in RTP Session Manager
    at com.sun.media.datasink.rtp.Handler.open(Handler.java:139)
    why this erro occors?
    I already created the DataSink.
    When I try to do this...
    dsk.open(); //here the error got
    dsk.start();     Code of server of media
    I want to sent audio (wav) like a radio, but from file. Without stop to send streaming. PullBufered
    *Class Server that you offers Streaming of midia
    public class Servidor {
    private MediaLocator ml;
    private Processor pro;
    private javax.media.protocol.DataSource ds;
    private DataSink dsk;
    private boolean codificado = false;
    //start the server service, passing the adress of media
    // ex: d:\music\music.wav
    // pass the ip and port, to make a server works
    public void iniciarServicoServidor(String end,String ip, int porta)
    try {
    //capture media
    capturarMidia(end);
    //creates processor
    criarProcessor();
    // configure the processor
    configurarProcessor();
    //setContent RAW
    descreverConteudoEnviado();
    //format the media in right RTP format
    formatRTP();
    //creat the streaming
    criarStreaming();
    //configure the server
    configurarServidor(ip, porta);
    //in this method raise the excepition
    iniciarServidor();
    //when I try to open the DataSink.open() raises the exception
    //java.io.IOException: Format of Stream not supported in RTP Session //Manager
    // at com.sun.media.datasink.rtp.Handler.open(Handler.java:139)
    } catch (RuntimeException e) {
    System.out.println("Houve um erro em iniciarServicoServidor");
    e.printStackTrace();
    public void capturarMidia(String endereco)
    try {
    System.out.println("**************************************************************");
    System.out.println("Iniciando processo de servidor de multimidia em " + Calendar.getInstance().getTime().toString());
    ml = new MediaLocator("file:///" + endereco);
    System.out.println("Midia realizada com sucesso.");
    System.out.println ("[" + "file:///" + endereco +"]");
    } catch (RuntimeException e) {
    System.out.println("Houve um erro em capturarMidia");
    e.printStackTrace ();
    public void criarProcessor()
    try {
    System.out.println("**************************************************************");
    pro = Manager.createProcessor(ml);
    System.out.println("Processor criado com sucesso.");
    System.out.println("Midia com durcao:" + pro.getDuration().getSeconds());
    } catch (NoProcessorException e) {
    System.out.println("Houve um erro em criarProcessor");
    e.printStackTrace();
    } catch (IOException e) {
    System.out.println ("Houve um erro em criarProcessor");
    e.printStackTrace();
    public void configurarProcessor()
    try {
    System.out.println("**************************************************************");
    System.out.println("Processor em estado de configura��o.");
    pro.configure();
    System.out.println("Processor configurado.");
    } catch (RuntimeException e) {
    System.out.println("Houve um erro em configurarProcessor");
    e.printStackTrace();
    public void descreverConteudoEnviado()
    try {
    System.out.println("**************************************************************");
    pro.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW));
    System.out.println("Descritor de conteudo:" + pro.getContentDescriptor().toString());
    } catch (NotConfiguredError e) {
    System.out.println("Houve um erro em descreverConteudoEnviado");
    e.printStackTrace();
    private Format checkForVideoSizes(Format original, Format supported) {
    int width, height;
    Dimension size = ((VideoFormat)original).getSize();
    Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
    Format h263Fmt = new Format(VideoFormat.H263_RTP);
    if (supported.matches(jpegFmt)) {
    // For JPEG, make sure width and height are divisible by 8.
    width = (size.width % 8 == 0 ? size.width :
    (int)(size.width / 8) * 8);
    height = (size.height % 8 == 0 ? size.height :
    (int)(size.height / 8) * 8);
    } else if (supported.matches(h263Fmt)) {
    // For H.263, we only support some specific sizes.
    if (size.width < 128) {
    width = 128;
    height = 96;
    } else if ( size.width < 176) {
    width = 176;
    height = 144;
    } else {
    width = 352;
    height = 288;
    } else {
    // We don't know this particular format. We'll just
    // leave it alone then.
    return supported;
    return (new VideoFormat(null,
    new Dimension(width, height),
    Format.NOT_SPECIFIED ,
    null,
    Format.NOT_SPECIFIED)).intersects(supported);
    public void formatRTP()
    try {
    // Program the tracks.
    TrackControl tracks[] = pro.getTrackControls();
    Format supported[];
    Format chosen;
    for (int i = 0; i < tracks.length; i++) {
    Format format = tracks.getFormat();
    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.
    // We'll just pick the first one.
    if (supported.length > 0) {
    if (supported[0] instanceof VideoFormat) {
    // For video formats, we should double check the
    // sizes since not all formats work in all sizes.
    chosen = checkForVideoSizes(tracks[i].getFormat(),
    supported[0]);
    } else
    chosen = supported[0];
    tracks[i].setFormat(chosen);
    System.err.println("Track " + i + " is set to transmit as:");
    System.err.println(" " + chosen);
    codificado = true;
    } else
    tracks[i].setEnabled(false);
    } else
    tracks[i].setEnabled(false);
    } catch (RuntimeException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    public void tocar()
    pro.start();
    public void criarStreaming()
    try {
    System.out.println("**************************************************************");
    if (codificado)
    System.out.println("Midia codificada...");
    System.out.println("Processor entra em estado de realize.");
    pro.realize();
    System.out.println("Processor realized.");
    System.out.println("Adquirindo o streaming a ser enviado.");
    ds = pro.getDataOutput();
    System.out.println("Streaming adquirido pronto a ser enviado.");
    } catch (NotRealizedError e) {
    System.out.println("Houve um erro em criarStreaming");
    System.out.println(e.getMessage());
    e.printStackTrace();
    catch (Exception e) {
    System.out.println(e.getMessage());
    public void configurarServidor(String ip, int porta)
    System.out.println("**************************************************************");
    String url = "rtp://" + ip + ":" + porta + "/audio/1";
    System.out.println("Servidor ira atender em " + url);
    MediaLocator mml = new MediaLocator(url);
    System.out.println("Localizador de midia ja criado");
    try {
    System.out.println("Criando um DataSink a ser enviado.");
    dsk = Manager.createDataSink(ds, mml);
    System.out.println("DataSink criado.");
    } catch (NoDataSinkException e) {
    e.printStackTrace();
    public void iniciarServidor()
    try {
    System.out.println("**************************************************************");
    dsk.open();
    System.out.println("Servidor ligado.");
    dsk.start();
    System.out.println("Servidor iniciado.");
    } catch (SecurityException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    Gives that output console.
    All methods are executed but the last doesnt works.
    The method that open the DataSink.
    What can I do?
    Iniciando processo de servidor de multimidia em Sun May 13 22:37:02 BRT 2007
    Midia realizada com sucesso.
    [file:///c:\radio.wav ]
    Processor criado com sucesso.
    Midia com durcao:9.223372036854776E9
    Processor em estado de configura��o.
    Processor configurado.
    Descritor de conteudo:RAW
    Midia codificada...
    Processor entra em estado de realize.
    Processor realized.
    Adquirindo o streaming a ser enviado.
    Streaming adquirido pronto a ser enviado.
    Servidor ira atender em rtp://127.0.0.1:22000/audio/1
    Localizador de midia ja criado
    Criando um DataSink a ser enviado.
    streams is [Lcom.sun.media.multiplexer.RawBufferMux$RawBufferSourceStream;@a0dcd9 : 1
    sink: setOutputLocator rtp://127.0.0.1:22000/audio/1
    DataSink criado.
    Track 0 is set to transmit as:
    unknown, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 176400.0 frame rate, FrameSize=32 bits
    java.io.IOException: Format of Stream not supported in RTP Session Manager
    at com.sun.media.datasink.rtp.Handler.open(Handler.java:139)
    at br.org.multimidiasi.motor.Servidor.iniciarServidor(Servidor.java:291)
    at br.org.multimidiasi.motor.Servidor.iniciarServicoServidor(Servidor.java:43)
    at br.org.multimidiasi.motor.ConsoleServidor.main(ConsoleServidor.java:30)
    Since already thanks so much.
    Exactally in this method raises erros.
    Ive tried another formats (avi, mp3) but all with the same error, what I can do?
    [code] public void iniciarServidor()
    try {
    System.out.println("**************************************************************");
    dsk.open();
    System.out.println("Servidor ligado.");
    dsk.start();
    System.out.println("Servidor iniciado.");
    } catch (SecurityException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    Track 0 is set to transmit as:
    unknown, 44100.0 Hz, 16-bit, Stereo, LittleEndian, Signed, 176400.0 frame rate, FrameSize=32 bits
    java.io.IOException: Format of Stream not supported in RTP Session Manager
    at com.sun.media.datasink.rtp.Handler.open(Handler.java:139)
    at br.org.multimidiasi.motor.Servidor.iniciarServidor(Servidor.java:291)
    at br.org.multimidiasi.motor.Servidor.iniciarServicoServidor(Servidor.java:43)
    at br.org.multimidiasi.motor.ConsoleServidor.main(ConsoleServidor.java:30)

    unknown, 44100.0 Hz, 16-bit, Stereo,
    LittleEndian, Signed, 176400.0 frame rate,
    FrameSize=32 bits
    java.io.IOException: Format of Stream not supported
    in RTP Session Manager
    The fact that it doesn't know what the format is
    might have to do with the problem. I've had similar
    problems, and I've traced it back to missing jars and
    codecs. Have you tried running the same code locally
    without the transmission to see if you player will
    even play the file?Already and it works, I used Player to play it and play normally, I try to make it with the diferents codecs of audio and video, but no sucess.

  • Cannot create the RTP Session

    we have made multithread rtp streaming server and tried to transmit the mpg file in a applet on a web page using tom-cat server.
    we got the following error...
    Cannot create the RTP Session: Local Data AddressDoes not belong to any of this hosts local interfaces
    Failed to initialize the sessions.
    java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkExit(Unknown Source)
         at java.lang.Runtime.exit(Unknown Source)
         at java.lang.System.exit(Unknown Source)
         at Receive.start(MyPlayer.java:90)
         at MyPlayer.start(MyPlayer.java:30)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

    I am really surprised that no one has answer for my query?????

  • Help on RTP session!

    Actually, i'm currently testing a java program that can send voice through the network but i faced problem on only windows 2000. I had tested on windows 98, windows Xp and windows 2000 locally. But when i send voice over 2 windows 2000 PCs, this error come out - "Cannot create the RTP session: Can't open local data port: 12468". Can anybody tell me what is the error means? Thank you.

    Sorry by my english im from spain.
    The problem is in the transmiter because he send the stream by the same port that the receiver will go to receive.
    I change this code in AVTransmiter2
    private String createTransmitter() {
    int port,port2;
    port2 =portBase - 2*i -2;
    localAddr = new SessionAddress( InetAddress.getLocalHost(),port2);
    And now you can utilice in the same mahine AVTransmit2 and AVReceive2.
    PD: if you want have the sound in mpg archive you must put in AvReceive other sesion with the port + 2.

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Rtp session problem

    HI, I’m using a custom data source for jmf to send audio over a RTPManager using javasound for capturing live audio from a microphone and at the same time receiving audio from a RTP session using jmf, the code for the custom data Source is one posted in here a while ago which is working fine the problem is that when I start sending audio the incoming audio stop but the sound is send correctly to the other part, so if a don’t send audio I get the audio from the rtp session if I send audio I don’t listen the incoming audio, I’m only talking of one side of the call because the other part is sending the rtp session by a sip server that is connected to a regular phone line and I don’t know exactly how that work I only know that works. anyone know what can be wrong with this? Can it be a buffer problem? Or a blocking device or just a error on the code? Thanks in advance.

    Your question doesn't make a whole lot of sense, but I'd assume you've coded something incorrectly.

  • Cannot create the RTP Session: Can't open local data port

    Hi,
    I'm trying to connect to two webcams simultaneously in the order:
    MediaLocator inputLocator1 = new MediaLocator("rtp://hostname1:8000/video");
    MediaLocator inputLocator2 = new MediaLocator("rtp://hostname2:8000/video");
    But I get this during the second connection:
    Cannot create the RTP Session: Can't open local data port: 8000
    And I can't see the video from hostname2.
    I did a check via netstat, and it seems that both mycomputer is receiving the video from both hostname1 & hostname2:
    TCP mycomputer:3236 hostname1:8000 ESTABLISHED
    TCP mycomputer:3264 hostname2:8000 ESTABLISHED
    TCP connections to both host were established!! But why can't I see the video of hostname2???? I've thought of 2 possible reasons why I cannot see the video of hostname2:
    1. Is this set of local data port maintained by Java? i.e It's not the same as the TCP port 8000 that I see in mycomputer's netstat. If yes, Java has assigned its local data port 8000 to hostname1, so it fails to reassign that port 8000 to hostname2 while hostname1 is still connected. Any other way to fix this apart from changing the portnumber of hostname2?
    2. It has to do with the custom.jar? I've read in an article somewhere in the forum that the custom.jar has to be customized (using JFMCustomizer) to receive video from two hosts with the same portnumber. Can someone elaborate the necessary boxes to check in the JFMCustomizer?
    Thanks much,
    Rach

    After all this while, I finally figured out the problem. In my code, I use MediaLocator to code the receiver and the transmitter. E.g.:
    MediaLocator inputLocator1 = new MediaLocator("rtp://hostname1:8000/video");
    player1 = Manager.createPlayer(inputLocator1)
    MediaLocator inputLocator2 = new MediaLocator("rtp://hostname2:8000/video");
    player2 = Manager.createPlayer(inputLocator2)
    Manager would complain "Cannot create the RTP Session: Can't open local data port: 8000" because port 8000 is already used up by player1, i.e.:
    mycomputer:8000 maps to hostname1:8000
    mycomputer:8000 cannot re-map to hostname2:8000
    To work around this, I'll need to use SessionAddress. SessionAddress provides the flexibility to do an independent local port mapping, e.g.:
    mycomputer:5000 maps to hostname1:8000
    mycomputer:5002 maps to hostname2:8000
    Rach

  • How to close a jmf rtp session when the whole file is sent

    i am using jmf to Stream a video file from a one client to another, everything seems to be working fine except for the fact that i dont know how to close the prosessor and the session/datasink on the transmitting clients side when the clientis done streaming, i can close it lets say after 60 seconds of starting but i am not able to figure out how make it stop when the whole file is done streaming. i tried using the datasinklistner while sending the video and the following code
    public void dataSinkUpdate(DataSinkEvent event) {
             if (event instanceof javax.media.datasink.EndOfStreamEvent) {
                 endOfStream = true;
         }but the endofstream event is never received from the datasource.
    the problem is that it works fine if i using a 20 second video and i close the datasink and the processor in 60 seconds, the whole file does get streamed but if i have a file longer than 60 seconds then the file just gets cut at 60 seconds.
    i also tried to use a sessionmanager with a sessionlistener and a sendStreamListener and the following code
         * SessionListener.
        public synchronized void update(SessionEvent evt) {
         * SendStreamListener
        public synchronized void update( SendStreamEvent evt) {
            System.out.println(evt);
         if (evt instanceof InactiveSendStreamEvent) {
              flag=true;
              System.out.println("done");
         if (evt instanceof ActiveSendStreamEvent) {
             System.out.println("start");
        }i ran the whole code and sent files and everything but neither an activestreamevent nor a inactivestreamevent happens but the file is being streamed properly

    user13490676 wrote:
    could it be a problem with jmf itself that the endofstream doesnt get generated for the datasource being read from a fileIn this instance, that would be the problem... more than likely, there's something weird about the file, perhaps it doesn't have a duration set in the header and JMF treats it like a live stream.
    You could always write a custom DataSource that just passes through the input of a normal data source, and then generate the EndOfStream event yourself... maybe based on a timeout or failure counter? I haven't received any data in x seconds or after x attempts, so I'm assuming the file is done... Or when you've read enough data that the file can't possibly have any more (read >= file header + file data)...

  • Recording audio from rtp session

    Dear all;
    I am not sure that this is the right forum to post my question. I am new in jmf and i want to record calls from nortel Pbx for example and others like asterisk PBX which records all in and out calls.first of all is it possible to use jmf for recording ? if yes , Provide links can i refer to read more about the subject

    Can you define "from another source". I'll assume for now, you mean, from an external live source, like a vocal, or guitar.
    Yes, if you had saved the song using the "Save As Project" command, the audio path to that songs audio folder should have been set. and all audio files recorded into that song would reside in that location.
    The only thing that you might want to check, is hit "A" with the song open, and make sure "choose path" is set to "Song Recording Path" and not "Global Recording Path".

  • How to get the SSRC in RTP session

    Hi
    i am using RTPManager to send voice between two machine , how to get the SSRC of the receiver end , and how to get SSRC of the receiving end.
    with regards
    Rekha kailas

    To get SSRC of received stream: receiveStream.getSSRC();
    To get SSRC of send stream: sendStream.getSSRC();

  • Multiple RTP streams + local video Player - S.O.S.

    Hi guys,
    I ran out of ideas, so I need your help now. It's gonna be a long one...
    Given:
    MediaLocator(vfw://0) --> DataSource(video) --> Processor(video)
    Then I send processor's output (videoProcessor.getDataOutput()) over RTP to multiple destinations. Of course, I am using cloneable DataSources for this, cause there's no other way. So, now I also need to have a local video feed just for self-reference, but it seems to be a tough one! Let me go over what I've tried til now:
    1. Using DataSource clone from video processor, I tried to create a Player (i.e. Manager.createPlayer(clonedDS) ). BOOM!
    javax.media.NoPlayerException: Cannot find a Player for: com.ibm.media.protocol.SuperCloneableDataSource$PushBufferDataSourceSlave@126c6ea
         at javax.media.Manager.createPlayerForSource(Manager.java:1512)
         at javax.media.Manager.createPlayer(Manager.java:500)
         at org.interlab.mc.media.MediaManager.setVideoProcessorEnabled(MediaManager.java:2046)
         at org.interlab.mc.media.MediaManager.openVideoStreams(MediaManager.java:1807)
         at org.interlab.mc.UserAgent.callStateChanged(UserAgent.java:2516)
         at org.interlab.mc.call.Call.fireCallStateChangedEvent(Call.java:366)
         at org.interlab.mc.call.Call.setState(Call.java:244)
         at org.interlab.mc.call.CallManager.processInviteOK(CallManager.java:330)
         at org.interlab.mc.UserAgent.processResponse(UserAgent.java:1632)
         at gov.nist.javax.sip.EventScanner.deliverEvent(EventScanner.java:288)
         at gov.nist.javax.sip.EventScanner.run(EventScanner.java:489)
         at java.lang.Thread.run(Unknown Source)So i checked. If I create a clone from my DataSource(video) then Manager would return this instance:
    class com.sun.media.multiplexer.RawBufferMux$RawBufferDataSourceBut if, like now, I want to create a clone from DataSource from video processor (i.e. Processor.getDataOutput()) then I get this instance:
    com.ibm.media.protocol.SuperCloneableDataSource$PushBufferDataSourceSlaveHope you noticed the difference. :) Now, from the latter one neither I can create a Player nor can I create a Processor. Too bad. So, I tried another one.
    2. I took my DataSource(video), created a cloneable (just like in Clone.java) and from there I finally got my precious Player! Yes!! But not so fast.... Player was working, but the rest now wasn't. Once I have my DataSource(video) cloned, my Processor(video)'s data output got starved - i could not send video anymore. What a life?! Fine... Let's try another one.
    3. Just like I send video remote I decided to send the video locally in a loop, for instance, from 203.159.2.3:25000 to 203.159.2.3:25002. And what do you think? Still doesnt work!! This "loop" stream is not detected (i.e. controller's update doest sense anything). But if i open JMStudio, and start listening (i.e. open RTP session) on 203.159.2.3:25002, i get my stream showing nice and clear!
    Someone, anyone, please, help! Point my nose to some document, piece of code - anything to make this work.
    Kind regards.

    I'd better post here, so everyone else can get it too. so here it goes:
    That's RTPSocketAdapter
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.DatagramSocket;
    import java.net.MulticastSocket;
    import java.net.DatagramPacket;
    import java.net.SocketException;
    import javax.media.protocol.PushSourceStream;
    import javax.media.protocol.ContentDescriptor;
    import javax.media.protocol.SourceTransferHandler;
    import javax.media.rtp.RTPConnector;
    import javax.media.rtp.OutputDataStream;
    * An implementation of RTPConnector based on UDP sockets.
    public class RTPSocketAdapter implements RTPConnector {
        DatagramSocket dataSock=null;
        DatagramSocket ctrlSock=null;
        InetAddress remoteAddress=null;
        int remotePort=0;
        InetAddress localAddress=null;
        int localPort=0;
        SockInputStream dataInStrm = null, ctrlInStrm = null;
        SockOutputStream dataOutStrm = null, ctrlOutStrm = null;
        public RTPSocketAdapter(InetAddress localAddress, int localPort,
                                      InetAddress remoteAddress, int remotePort) throws IOException {
             this(localAddress, localPort, remoteAddress, remotePort, 1);
        public RTPSocketAdapter(InetAddress localAddress, int localPort,
                                       InetAddress remoteAddress, int remotePort, int ttl) throws IOException {
              try {
                  if (remoteAddress.isMulticastAddress()) {
                        dataSock = new MulticastSocket(localPort);
                        ctrlSock = new MulticastSocket(localPort+1);
                        ((MulticastSocket)dataSock).joinGroup(remoteAddress);
                        ((MulticastSocket)dataSock).setTimeToLive(ttl);
                        ((MulticastSocket)ctrlSock).joinGroup(remoteAddress);
                        ((MulticastSocket)ctrlSock).setTimeToLive(ttl);
                  else {
                        dataSock = new DatagramSocket(localPort, localAddress);
                        ctrlSock = new DatagramSocket(localPort+1, localAddress);
              catch (SocketException e) {
                  throw new IOException(e.getMessage());
              this.localAddress = localAddress;
              this.localPort = localPort;
              this.remoteAddress = remoteAddress;
              this.remotePort = remotePort;
         * Returns an input stream to receive the RTP data.
        public PushSourceStream getDataInputStream() throws IOException {
              if (dataInStrm == null) {
                  dataInStrm = new SockInputStream(dataSock, remoteAddress, remotePort);
                  dataInStrm.start();
              return dataInStrm;
         * Returns an output stream to send the RTP data.
        public OutputDataStream getDataOutputStream() throws IOException {
              if (dataOutStrm == null)
                  dataOutStrm = new SockOutputStream(dataSock, remoteAddress, remotePort);
              return dataOutStrm;
         * Returns an input stream to receive the RTCP data.
        public PushSourceStream getControlInputStream() throws IOException {
              if (ctrlInStrm == null) {
                  ctrlInStrm = new SockInputStream(ctrlSock, remoteAddress, remotePort+1);
                  ctrlInStrm.start();
              return ctrlInStrm;
         * Returns an output stream to send the RTCP data.
        public OutputDataStream getControlOutputStream() throws IOException {
              if (ctrlOutStrm == null)
                  ctrlOutStrm = new SockOutputStream(ctrlSock, remoteAddress, remotePort+1);
              return ctrlOutStrm;
         * Close all the RTP, RTCP streams.
        public void close() {
              if (dataInStrm != null)
                  dataInStrm.kill();
              if (ctrlInStrm != null)
                  ctrlInStrm.kill();
              dataSock.close();
              ctrlSock.close();
         * Set the receive buffer size of the RTP data channel.
         * This is only a hint to the implementation.  The actual implementation
         * may not be able to do anything to this.
        public void setReceiveBufferSize(int size) throws IOException {
             dataSock.setReceiveBufferSize(size);
         * Get the receive buffer size set on the RTP data channel.
         * Return -1 if the receive buffer size is not applicable for
         * the implementation.
        public int getReceiveBufferSize() {
              try {
                  return dataSock.getReceiveBufferSize();
              catch (Exception e) {
                  return -1;
         * Set the send buffer size of the RTP data channel.
         * This is only a hint to the implementation.  The actual implementation
         * may not be able to do anything to this.
        public void setSendBufferSize( int size) throws IOException {
             dataSock.setSendBufferSize(size);
         * Get the send buffer size set on the RTP data channel.
         * Return -1 if the send buffer size is not applicable for
         * the implementation.
        public int getSendBufferSize() {
              try {
                  return dataSock.getSendBufferSize();
              catch (Exception e) {
                  return -1;
         * Return the RTCP bandwidth fraction.  This value is used to
         * initialize the RTPManager.  Check RTPManager for more detauls.
         * Return -1 to use the default values.
        public double getRTCPBandwidthFraction() {
             return -1;
         * Return the RTCP sender bandwidth fraction.  This value is used to
         * initialize the RTPManager.  Check RTPManager for more detauls.
         * Return -1 to use the default values.
        public double getRTCPSenderBandwidthFraction() {
             return -1;
         * An inner class to implement an OutputDataStream based on UDP sockets.
        class SockOutputStream implements OutputDataStream {
              DatagramSocket sock;
              InetAddress addr;
              int port;
              public SockOutputStream(DatagramSocket sock, InetAddress addr, int port) {
                  this.sock = sock;
                  this.addr = addr;
                  this.port = port;
              public int write(byte data[], int offset, int len) {
                  try {
                       sock.send(new DatagramPacket(data, offset, len, addr, port));
                  catch (Exception e) {
                       return -1;
                  return len;
         * An inner class to implement an PushSourceStream based on UDP sockets.
        class SockInputStream extends Thread implements PushSourceStream {
              DatagramSocket sock;
              InetAddress addr;
              int port;
              boolean done = false;
              boolean dataRead = false;
              SourceTransferHandler sth = null;
              public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
                  this.sock = sock;
                  this.addr = addr;
                  this.port = port;
              public int read(byte buffer[], int offset, int length) {
                  DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
                  try {
                       sock.receive(p);
                  catch (IOException e) {
                       return -1;
                  synchronized (this) {
                       dataRead = true;
                       notify();
                  return p.getLength();
              public synchronized void start() {
                  super.start();
                  if (sth != null) {
                       dataRead = true;
                       notify();
              public synchronized void kill() {
                  done = true;
                  notify();
              public int getMinimumTransferSize() {
                  return 2 * 1024;     // twice the MTU size, just to be safe.
              public synchronized void setTransferHandler(SourceTransferHandler sth) {
                  this.sth = sth;
                  dataRead = true;
                  notify();
              // Not applicable.
              public ContentDescriptor getContentDescriptor() {
                  return null;
              // Not applicable.
              public long getContentLength() {
                  return LENGTH_UNKNOWN;
              // Not applicable.
              public boolean endOfStream() {
                  return false;
              // Not applicable.
              public Object[] getControls() {
                  return new Object[0];
              // Not applicable.
              public Object getControl(String type) {
                  return null;
          * Loop and notify the transfer handler of new data.
              public void run() {
                  while (!done) {
                        synchronized (this) {
                            while (!dataRead && !done) {
                                  try {
                                      wait();
                                  catch (InterruptedException e) { }
                            dataRead = false;
                        if (sth != null && !done) {
                            sth.transferData(this);
    }See, how to create RTPManager in next post

  • Cloning RTP DataSource

    I'm having difficulty making the Clone.java example (from JMF Solutions) clone an RTP transmission. The Clone program works fine with a video file, but when I attempt this:
    java Clone rtp://localhost:550/video 2
    where I have an RTP transmission from JMStudio on port 550, it complains:
    create player for: rtp
    Failed to create a player from the given DataSource: javax.media.NoPlayerException: Cannot find a Player for: com.ibm.media.protocol.CloneablePushBufferDataSour
    ce@551f60
    I must be missing something, and I'd be very appreciative for any pointers.
    Cheers,
    Frank

    You can see JMF guide. There're some helpful examples.
    Also, I have some problems when capture a RTP session to a file while playing it concurrently. I cloned the datatsource and use one for playing , one for capturing but the playback quality is very bad.
    What I have to do.

  • How to stream multiple audio files over a IP network in one session

    Hi everybody,
    i am going to build an internet radio application as my next project. I thought of taking JMF and the RTP streaming for this purpose. But the problem i faced during the development was it plays only one audio stream in a session. The thing is i want to send more than one audio stream in a given RTP session and using a single port. What my radio does is simply play mp3 music all day long. How can i do this and what other tools that i should take. please reply ASAP. thank u in advance,
    Thusira..

    You'll need to implement what I call a "jukebox" datasource... IE, the DataSource changes what file it's outputting, but the Processor and RTP DataSink associated with it are unaware of the change... so they keep right on transmitting like nothing happened, but the actual file being outputted has changed...
    http://web.archive.org/web/20080316203600/java.sun.com/products/java-media/jmf/2.1.1/solutions/Concat.html
    The concat example calls it a "superglue" datasource and uses it to concat outputs to a file... exact same concept, except you'll want to use a queue you can append to dynamically rather than an array created at compile time... and you'll want to output to RTP instead of to a file. You'll probably also want your DataSource to stay alive waiting for the next thing to be enqueued rather than shutting down when it reaches the end of the list.

  • JMF How to stream rtp from udp packet

    I implemented an rtsp client and use the client to setup two rtp session(audio, vedio). But when I use the example pramgram "AVReceive3" to stream the udp packet, it doesn't work.
    When the AVReceive3 receive the udp packet from the rtp port, it will call the update(ReceiveStreamEvent evt) function, and the event type is StreamMappedEvent, and the call to evt.getReceiveStream().getDataSource() return null.
    I thought the first event should be NewReceiveStreamEvent. Please help to solve the problem.
    What's rtp packet will cause the event StreamMappedEvent.
    Following is the code of AVReceive3.java:
    * AVReceive3.java
    * Created on 2007&#24180;10&#26376;30&#26085;, &#19979;&#21320;4:11
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package PlayerTest;
    import java.io.*;
    import java.awt.*;
    import java.net.*;
    import java.awt.event.*;
    import java.util.Vector;
    import javax.media.*;
    import javax.media.rtp.*;
    import javax.media.rtp.event.*;
    import javax.media.rtp.rtcp.*;
    import javax.media.protocol.*;
    import javax.media.protocol.DataSource;
    import javax.media.format.AudioFormat;
    import javax.media.format.VideoFormat;
    import javax.media.Format;
    import javax.media.format.FormatChangeEvent;
    import javax.media.control.BufferControl;
    * AVReceive3 to receive RTP transmission using the RTPConnector.
    public class AVReceive3 extends Thread implements ReceiveStreamListener, SessionListener,
    ControllerListener
    String sessions[] = null;
    RTPManager mgrs[] = null;
    Vector playerWindows = null;
    boolean dataReceived = false;
    Object dataSync = new Object();
    public AVReceive3(String sessions[])
    this.sessions = sessions;
    public void run()
    initialize();
    public boolean initialize() {
    try {
    mgrs = new RTPManager[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] = (RTPManager) RTPManager.newInstance();
    mgrs[i].addSessionListener(this);
    mgrs[i].addReceiveStreamListener(this);
    // Initialize the RTPManager with the RTPSocketAdapter
    mgrs[i].initialize(new RTPSocketAdapter(
    InetAddress.getByName(session.addr),
    session.port, session.ttl));
    // 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);
    } 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 = 30000; // 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;
    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].removeTargets( "Closing session from AVReceive3");
    mgrs[i].dispose();
    mgrs[i] = null;
    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;
    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) {
    System.out.println("\nReceive an receiveStreamEvent:"+evt.toString());
    RTPManager mgr = (RTPManager)evt.getSource();
    Participant participant = evt.getParticipant(); // could be null.
    ReceiveStream stream = evt.getReceiveStream(); // could be null.
    System.out.println("The RTPManager is:");
    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);
    pw.setVisible(true);
    // 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;
    else if (evt instanceof StreamMappedEvent) {
    if (stream != null)
    if(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);
    * 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("AVReceive3 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 argv[]) {
    //if (argv.length == 0)
    // prUsage();
    String sessions[]= new String[] {"127.0.0.1/6670","127.0.0.1/6672"};
    AVReceive3 avReceive = new AVReceive3(sessions);
    if (!avReceive.initialize()) {
    System.err.println("Failed to initialize the sessions.");
    System.exit(-1);
    // Check to see if AVReceive3 is done.
    try {
    while (!avReceive.isDone())
    Thread.sleep(1000);
    } catch (Exception e) {}
    System.err.println("Exiting AVReceive3");
    static void prUsage() {
    System.err.println("Usage: AVReceive3 <session> <session> ");
    System.err.println(" <session>: <address>/<port>/<ttl>");
    System.exit(0);
    }// end of AVReceive3
    Following is the code of RTPSocketAdapter.java:
    * RTPSocketAdapter.java
    * Created on 2007&#24180;10&#26376;30&#26085;, &#19979;&#21320;4:13
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package PlayerTest;
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.DatagramSocket;
    import java.net.MulticastSocket;
    import java.net.DatagramPacket;
    import java.net.SocketException;
    import javax.media.protocol.DataSource;
    import javax.media.protocol.PushSourceStream;
    import javax.media.protocol.ContentDescriptor;
    import javax.media.protocol.SourceTransferHandler;
    import javax.media.rtp.RTPConnector;
    import javax.media.rtp.OutputDataStream;
    * An implementation of RTPConnector based on UDP sockets.
    public class RTPSocketAdapter implements RTPConnector {
    DatagramSocket dataSock;
    DatagramSocket ctrlSock;
    InetAddress addr;
    int port;
    SockInputStream dataInStrm = null;
    SockInputStream ctrlInStrm = null;
    SockOutputStream dataOutStrm = null;
    SockOutputStream ctrlOutStrm = null;
    public RTPSocketAdapter(InetAddress addr, int port) throws IOException {
    this(addr, port, 1);
    public RTPSocketAdapter(InetAddress addr, int port, int ttl) throws IOException {
    try {
    if (addr.isMulticastAddress()) {
    dataSock = new MulticastSocket(port);
    ctrlSock = new MulticastSocket(port+1);
    ((MulticastSocket)dataSock).joinGroup(addr);
    ((MulticastSocket)dataSock).setTimeToLive(ttl);
    ((MulticastSocket)ctrlSock).joinGroup(addr);
    ((MulticastSocket)ctrlSock).setTimeToLive(ttl);
    } else {
    dataSock = new DatagramSocket(port, InetAddress.getLocalHost());
    ctrlSock = new DatagramSocket(port+1, InetAddress.getLocalHost());
    } catch (SocketException e) {
    throw new IOException(e.getMessage());
    this.addr = addr;
    this.port = port;
    * Returns an input stream to receive the RTP data.
    public PushSourceStream getDataInputStream() throws IOException {
    if (dataInStrm == null) {
    dataInStrm = new SockInputStream(dataSock, addr, port);
    dataInStrm.start();
    return dataInStrm;
    * Returns an output stream to send the RTP data.
    public OutputDataStream getDataOutputStream() throws IOException {
    if (dataOutStrm == null)
    dataOutStrm = new SockOutputStream(dataSock, addr, port);
    return dataOutStrm;
    * Returns an input stream to receive the RTCP data.
    public PushSourceStream getControlInputStream() throws IOException {
    if (ctrlInStrm == null) {
    ctrlInStrm = new SockInputStream(ctrlSock, addr, port+1);
    ctrlInStrm.start();
    return ctrlInStrm;
    * Returns an output stream to send the RTCP data.
    public OutputDataStream getControlOutputStream() throws IOException {
    if (ctrlOutStrm == null)
    ctrlOutStrm = new SockOutputStream(ctrlSock, addr, port+1);
    return ctrlOutStrm;
    * Close all the RTP, RTCP streams.
    public void close() {
    if (dataInStrm != null)
    dataInStrm.kill();
    if (ctrlInStrm != null)
    ctrlInStrm.kill();
    dataSock.close();
    ctrlSock.close();
    * Set the receive buffer size of the RTP data channel.
    * This is only a hint to the implementation. The actual implementation
    * may not be able to do anything to this.
    public void setReceiveBufferSize( int size) throws IOException {
    dataSock.setReceiveBufferSize(size);
    * Get the receive buffer size set on the RTP data channel.
    * Return -1 if the receive buffer size is not applicable for
    * the implementation.
    public int getReceiveBufferSize() {
    try {
    return dataSock.getReceiveBufferSize();
    } catch (Exception e) {
    return -1;
    * Set the send buffer size of the RTP data channel.
    * This is only a hint to the implementation. The actual implementation
    * may not be able to do anything to this.
    public void setSendBufferSize( int size) throws IOException {
    dataSock.setSendBufferSize(size);
    * Get the send buffer size set on the RTP data channel.
    * Return -1 if the send buffer size is not applicable for
    * the implementation.
    public int getSendBufferSize() {
    try {
    return dataSock.getSendBufferSize();
    } catch (Exception e) {
    return -1;
    * Return the RTCP bandwidth fraction. This value is used to
    * initialize the RTPManager. Check RTPManager for more detauls.
    * Return -1 to use the default values.
    public double getRTCPBandwidthFraction() {
    return -1;
    * Return the RTCP sender bandwidth fraction. This value is used to
    * initialize the RTPManager. Check RTPManager for more detauls.
    * Return -1 to use the default values.
    public double getRTCPSenderBandwidthFraction() {
    return -1;
    * An inner class to implement an OutputDataStream based on UDP sockets.
    class SockOutputStream implements OutputDataStream {
    DatagramSocket sock;
    InetAddress addr;
    int port;
    public SockOutputStream(DatagramSocket sock, InetAddress addr, int port) {
    this.sock = sock;
    this.addr = addr;
    this.port = port;
    public int write(byte data[], int offset, int len) {
    try {
    sock.send(new DatagramPacket(data, offset, len, addr, port));
    } catch (Exception e) {
    return -1;
    return len;
    * An inner class to implement an PushSourceStream based on UDP sockets.
    class SockInputStream extends Thread implements PushSourceStream {
    DatagramSocket sock;
    InetAddress addr;
    int port;
    boolean done = false;
    boolean dataRead = false;
    SourceTransferHandler sth = null;
    public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
    this.sock = sock;
    this.addr = addr;
    this.port = port;
    public int read(byte buffer[], int offset, int length) {
    DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
    try {
    sock.receive(p);
    } catch (IOException e) {
    return -1;
    synchronized (this) {
    dataRead = true;
    notify();
    System.out.println("RTPSocketAdapter receive RTP packet from port:"+port);
    System.out.println("The received RTP packet:"+new String(buffer));
    return p.getLength();
    public synchronized void start() {
    super.start();
    if (sth != null) {
    dataRead = true;
    notify();
    public synchronized void kill() {
    done = true;
    notify();
    public int getMinimumTransferSize() {
    return 2 * 1024; // twice the MTU size, just to be safe.
    public synchronized void setTransferHandler(SourceTransferHandler sth) {
    this.sth = sth;
    dataRead = true;
    notify();
    // Not applicable.
    public ContentDescriptor getContentDescriptor() {
    return null;
    // Not applicable.
    public long getContentLength() {
    return LENGTH_UNKNOWN;
    // Not applicable.
    public boolean endOfStream() {
    return false;
    // Not applicable.
    public Object[] getControls() {
    return new Object[0];
    // Not applicable.
    public Object getControl(String type) {
    return null;
    * Loop and notify the transfer handler of new data.
    public void run() {
    while (!done) {
    synchronized (this) {
    while (!dataRead && !done) {
    try {
    wait();
    } catch (InterruptedException e) { }
    dataRead = false;
    if (sth != null && !done) {
    sth.transferData(this);
    Thanks.

    The error of No format has been registered for RTP Payload type 96
    is caused by the dynamic payload mapping, when I add the dynamic mapping between dynamic payload and format. The Player cann't work yet. I think it because JMF doesn't support the format of my clips. For example:
    video: a=rtpmap:96 H263-2000/90000
    audio:a=rtpmap:97 MP4A-LATM/12000/1
    Is there some available plugin to support these format?
    Thanks

  • Writing a conference server for RTP streams

    Hello,
    I'm trying to write a conference server which accepts multiple RTP streams (one for each participant), creates a mixed RTP stream of all other participants and sends that stream back to each participant.
    For 2 participants, I was able to correctly receive and send the stream of the other participant to each party.
    For 3 participants, creating the merging data source does not seem to work - i.e. no data is received by the participants.
    I tried creating a cloneable data sources instead, thinking that this may be the root cause, but when creating cloneable data sources from incoming RTP sources, I am unable to get the Processor into Configured state, it seems to deadlock. Here's the code outline :
        Iterator pIt = participants.iterator();
        List dataSources = new ArrayList();
        while(pIt.hasNext()) {
          Party p = (Party) pIt.next();
          if(p!=dest) {
            DataSource ds = p.getDataSource();
            DataSource cds = Manager.createCloneableDataSource(ds);
            DataSource clone= ((SourceCloneable)cds).createClone();
            dataSources.add(clone);
        Object[] sources = dataSources.toArray(new DataSource[0]);
        DataSource dataSource =   Manager.createMergingDataSource((DataSource[])sources);
        Processor p = Manager.createProcessor(dataSource);
        MixControllerListener cl = new MixControllerListener();
        p.addControllerListener(cl);
        // Put the Processor into configured state.
        p.configure();
        if (!cl.waitForState(p, p.Configured)) {
            System.err.println("Failed to configure the processor.");
            assert false;
        }Here are couple of stack traces :
    "RTPEventHandler" daemon prio=1 tid=0x081d6828 nid=0x3ea6 in Object.wait() [98246000..98247238]
            at java.lang.Object.wait(Native Method)
            - waiting on <0x9f37e4a8> (a java.lang.Object)
            at java.lang.Object.wait(Object.java:429)
            at demo.Mixer$MixControllerListener.waitForState(Mixer.java:248)
            - locked <0x9f37e4a8> (a java.lang.Object)
            at demo.Mixer.createMergedDataSource(Mixer.java:202)
            at demo.Mixer.createSendStreams(Mixer.java:165)
            at demo.Mixer.createSendStreamsWhenAllJoined(Mixer.java:157)
            - locked <0x9f481840> (a demo.Mixer)
            at demo.Mixer.update(Mixer.java:123)
            at com.sun.media.rtp.RTPEventHandler.processEvent(RTPEventHandler.java:62)
            at com.sun.media.rtp.RTPEventHandler.dispatchEvents(RTPEventHandler.java:96)
            at com.sun.media.rtp.RTPEventHandler.run(RTPEventHandler.java:115)
    "JMF thread: com.sun.media.ProcessEngine@a3c5b6[ com.sun.media.ProcessEngine@a3c5b6 ] ( configureThread)" daemon prio=1 tid=0x082fe3c8 nid=0x3ea6 in Object.wait() [977e0000..977e1238]
            at java.lang.Object.wait(Native Method)
            - waiting on <0x9f387560> (a java.lang.Object)
            at java.lang.Object.wait(Object.java:429)
            at com.sun.media.parser.RawBufferParser$FrameTrack.parse(RawBufferParser.java:247)
            - locked <0x9f387560> (a java.lang.Object)
            at com.sun.media.parser.RawBufferParser.getTracks(RawBufferParser.java:112)
            at com.sun.media.BasicSourceModule.doRealize(BasicSourceModule.java:180)
            at com.sun.media.PlaybackEngine.doConfigure1(PlaybackEngine.java:229)
            at com.sun.media.ProcessEngine.doConfigure(ProcessEngine.java:43)
            at com.sun.media.ConfigureWorkThread.process(BasicController.java:1370)
            at com.sun.media.StateTransitionWorkThread.run(BasicController.java:1339)
    "JMF thread" daemon prio=1 tid=0x080db410 nid=0x3ea6 in Object.wait() [97f41000..97f41238]
            at java.lang.Object.wait(Native Method)
            - waiting on <0x9f480578> (a com.ibm.media.protocol.CloneableSourceStreamAdapter$PushBufferStreamSlave)
            at java.lang.Object.wait(Object.java:429)
            at com.ibm.media.protocol.CloneableSourceStreamAdapter$PushBufferStreamSlave.run(CloneableSourceStreamAdapter.java:375)
            - locked <0x9f480578> (a com.ibm.media.protocol.CloneableSourceStreamAdapter$PushBufferStreamSlave)
            at java.lang.Thread.run(Thread.java:534)Any ideas ?
    Thanks,
    Jarek

    bgl,
    I was able to get past the cloning issue by following the Clone.java example to the letter :)
    Turns out that the cloneable data source must be added as a send stream first, and then the clonet data source. Now for each party in the call the conf. server does the following :
    Party(RTPManager mgr,DataSource ds) {
          this.mgr=mgr;
          this.ds=Manager.createCloneableDataSource(ds);
       synchronized DataSource cloneDataSource() {
          DataSource retVal;
          if(getNeedsCloning()) {
            retVal = ((SourceCloneable) ds).createClone();
          } else {
            retVal = ds;
            setNeedsCloning();
          return retVal;
        private void setNeedsCloning() {
          needsCloning=true;
        private boolean getNeedsCloning() {
          return needsCloning;
         private synchronized void addSendStreamFromNewParticipant(Party newOne) throws UnsupportedFormatException, IOException {
        debug("*** - New one joined. Creating the send streams. Curr count :" + participants.size());
        Iterator pIt = participants.iterator();
        while(pIt.hasNext()) {
          Party p = (Party)pIt.next();
          assert p!=newOne;
          // update existing participant
          SendStream sendStream = p.getMgr().createSendStream(newOne.cloneDataSource(),0);
          sendStream.start();
          // send data from existing participant to the new one
          sendStream = newOne.getMgr().createSendStream(p.cloneDataSource(),0);
          sendStream.start();
        debug("*** - Done creating the streams.");So I made some progress, but I'm still not quite there.
    The RTP manager JavaDoc for createSendStream states the following :
    * This method is used to create a sending stream within the RTP
    * session. For each time the call is made, a new sending stream
    * will be created. This stream will use the SDES items as entered
    * in the initialize() call for all its RTCP messages. Each stream
    * is sent out with a new SSRC (Synchronisation SouRCe
    * identifier), but from the same participant i.e. local
    * participant. <BR>
    For 3 participants, my conf. server creates 2 send streams to every one of them, so I'd expect 2 SSRCs on the wire. Examining the RTP packets in Ethereal, I only see 1 SSRC, as if the 2nd createSendStream call failed. Consequently, each participany in the conference is able to receive voice from only 1 other participant, even though I create RTPManager instance for each participany, and add 2 send streams.
    Any ideas ?
    Thanks,
    Jarek

Maybe you are looking for