0 Replies Latest reply: Mar 29, 2012 8:09 AM by 927268 RSS

    RTP streaming from local file

    927268
      I've a problem with JMF, in particular when I transmit a stream from a local file updated from receveing process. The file is "uLaw 8Khz, 8Bit".

      It would seem that when the processor is running is made of a photo of current file size; this implies that is sent only part of the file accessed. The rest of the file is discarded and JMF raises the event EndOfStream.

      Here's the source:

                     // encoding = ULAW, sampleRate = 8000.0Hz, sampleSizeInBits = 8bit, channels = mono(1) or stereo(2)
                     this.format = new AudioFormat(this.audioFormat, 8000, 8, 1);

                     MediaLocator mlIn = null;
                     if (rtpFilename != null && rtpFilename.startsWith("file://"))
                          mlIn = new MediaLocator(rtpFilename);
                     else
                          mlIn = new MediaLocator("file://" + rtpFilename);
                     logger.debug("Input Media locator URL: " + mlIn);

                     if ((processor = createProcessor(mlIn)) != null) {
                          // configure the processor
                          stateHelper = new StateHelper(processor);
                          if (stateHelper.configure(10000)) {
                               processor.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW_RTP));

                               // Go through the tracks and try to program one of them to output gsm data
                               boolean encodingOk = false;
                               TrackControl track[] = processor.getTrackControls();
                               if (track != null) {
                                    logger.debug("Track found: " + track.length);
                                    for (int i = 0; i < track.length; i++) {
                                         if (!encodingOk && track[i] instanceof FormatControl) {
                                              if (((FormatControl) track).setFormat(format) == null) {
                                                   track[i].setEnabled(false);
                                              } else {
                                                   encodingOk = true;
                                              }
                                         } else {
                                              // we could not set this track to gsm, so disable it
                                              track[i].setEnabled(false);
                                         }
                                    }
                               }

                               // At this point, we have determined where we can send out format data or not
                               logger.debug("Encoding " + this.format.getEncoding() + " result: " + encodingOk);
                               if (encodingOk) {
                                    // realize the processor
                                    if (stateHelper.realize(10000)) {
                                         try {
                                              // hand this datasource to manager for creating an RTP
                                              // datasink our RTP datasink will multicast the audio
                                              String locator = "rtp://" + this.ip + ":" + this.port + "/audio/1";
                                              MediaLocator mlOut = new MediaLocator(locator);
                                              logger.error("Output Media locator URL: " + mlOut);

                                              // create a send stream for the output data source of a processor and start it
                                              dsource = processor.getDataOutput();

                                              dsink = Manager.createDataSink(dsource, mlOut);
                                              dsink.open();

                                              // now start the datasink
                                              dsink.start();
                                              logger.debug("Data sink created for Media locator: " + mlOut);

                                              if (stateHelper.prefetch(10000)) {
                                                   stateHelper.playToEndOfMedia(60000);
                                              } else {
                                                   logger.warn("Processor prefetch failed");
                                              }
                                         } catch (Exception e) {
                                              logger.error(e.getMessage(), e);
                                              running = false;
                                         } finally {
                                              if (stateHelper != null)
                                                   stateHelper.close();

                                              if (dsink != null) {
                                                   dsink.close();
                                                   logger.debug("Datasink closed");
                                              }

                                              try {
                                                   if (dsource != null)
                                                        dsource.stop();
                                              } catch (IOException e) {
                                                   logger.debug(e.getMessage(), e);
                                              }
                                         }
                                    } else {
                                         logger.warn("Processor realization failed");
                                    }
                               } else {
                                    logger.warn("Encoding failed");
                               }
                          } else {
                               logger.warn("Processor configuration failed");
                          }
                     } else {
                          logger.warn("Processor creation failed");
                     }

      Thanks in advance mariusv5.