1 Reply Latest reply: Aug 16, 2011 12:32 PM by chummer RSS

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

    882653
      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.NullPointerException
      Well I don't understand what's happening, is there something I need to do before I can use RTP?
      Hope you guys help :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
        • 1. Re: Help with RTP: Format of Stream not supported in RTP Session Manager
          chummer
          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 the
          ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
          part.