Beispiel #1
0
  public void startProcessing() {

    try {
      processor = Manager.createProcessor(getMainCamSource());
    } catch (IOException e) {
      //            JOptionPane.showMessageDialog(parent,
      //               "IO Exception creating processor: " + e.getMessage(), "Error",
      // JOptionPane.WARNING_MESSAGE);
      return;
    } catch (NoProcessorException e) {
      //            JOptionPane.showMessageDialog(parent,
      //               "Exception creating processor: " + e.getMessage(), "Error",
      // JOptionPane.WARNING_MESSAGE);
      return;
    }

    CamStateHelper playhelper = new CamStateHelper(processor);
    if (!playhelper.configure(10000)) {
      JOptionPane.showMessageDialog(
          parent, "cannot configure processor", "Error", JOptionPane.WARNING_MESSAGE);
      return;
    }
    processor.setContentDescriptor(null);
    if (!playhelper.realize(10000)) {
      JOptionPane.showMessageDialog(
          parent, "cannot realize processor", "Error", JOptionPane.WARNING_MESSAGE);
      return;
    }
    // In order for or your clones to start, you must start the original source
    processor.start();
    setProcessing(true);
  }
 /**
  * Initializes the decoder. The file will be opened, decoding will start, and the first frame of
  * the movie will be sent to the handlers.
  *
  * @param mediaFile - the URL of the media file to be loaded
  */
 public void init(String mediaFile) {
   try {
     java.net.URL url = new java.net.URL(mediaFile);
     processor = Manager.createProcessor(url);
     processor.addControllerListener(this);
     processor.configure();
   } catch (Exception e) {
     // Debug.trace("Movie player exception "+e);
   }
 }
Beispiel #3
0
  /**
   * Implements {@link ReceiveStreamListener#update(ReceiveStreamEvent)}.
   *
   * <p>{@link #rtpManager} will use this to notify us of <tt>ReceiveStreamEvent</tt>s.
   */
  @Override
  public void update(ReceiveStreamEvent event) {
    if (event == null) return;
    ReceiveStream receiveStream = event.getReceiveStream();

    if (event instanceof NewReceiveStreamEvent) {
      if (receiveStream == null) {
        logger.warn("NewReceiveStreamEvent: null");
        return;
      }

      final long ssrc = getReceiveStreamSSRC(receiveStream);

      ReceiveStreamDesc receiveStreamDesc = findReceiveStream(ssrc);

      if (receiveStreamDesc != null) {
        String s = "NewReceiveStreamEvent for an existing SSRC. ";
        if (receiveStream != receiveStreamDesc.receiveStream)
          s += "(but different ReceiveStream object)";
        logger.warn(s);
        return;
      } else receiveStreamDesc = new ReceiveStreamDesc(receiveStream);

      if (logger.isInfoEnabled()) logger.info("New ReceiveStream, ssrc=" + ssrc);

      // Find the format of the ReceiveStream
      DataSource dataSource = receiveStream.getDataSource();
      if (dataSource instanceof PushBufferDataSource) {
        Format format = null;
        PushBufferDataSource pbds = (PushBufferDataSource) dataSource;
        for (PushBufferStream pbs : pbds.getStreams()) {
          if ((format = pbs.getFormat()) != null) break;
        }

        if (format == null) {
          logger.error("Failed to handle new ReceiveStream: " + "Failed to determine format");
          return;
        }

        receiveStreamDesc.format = format;
      } else {
        logger.error("Failed to handle new ReceiveStream: " + "Unsupported DataSource");
        return;
      }

      int rtpClockRate = -1;
      if (receiveStreamDesc.format instanceof AudioFormat)
        rtpClockRate = (int) ((AudioFormat) receiveStreamDesc.format).getSampleRate();
      else if (receiveStreamDesc.format instanceof VideoFormat) rtpClockRate = 90000;
      getSynchronizer().setRtpClockRate(ssrc, rtpClockRate);

      // create a Processor and configure it
      Processor processor = null;
      try {
        processor = Manager.createProcessor(receiveStream.getDataSource());
      } catch (NoProcessorException npe) {
        logger.error("Failed to create Processor: ", npe);
        return;
      } catch (IOException ioe) {
        logger.error("Failed to create Processor: ", ioe);
        return;
      }

      if (logger.isInfoEnabled()) logger.info("Created processor for SSRC=" + ssrc);

      processor.addControllerListener(this);
      receiveStreamDesc.processor = processor;

      final int streamCount;
      synchronized (receiveStreams) {
        receiveStreams.add(receiveStreamDesc);
        streamCount = receiveStreams.size();
      }

      /*
       * XXX TODO IRBABOON
       * This is a terrible hack which works around a failure to realize()
       * some of the Processor-s for audio streams, when multiple streams
       * start nearly simultaneously. The cause of the problem is currently
       * unknown (and synchronizing all FMJ calls in RecorderRtpImpl
       * does not help).
       * XXX TODO NOOBABRI
       */
      if (receiveStreamDesc.format instanceof AudioFormat) {
        final Processor p = processor;
        new Thread() {
          @Override
          public void run() {
            // delay configuring the processors for the different
            // audio streams to decrease the probability that they
            // run together.
            try {
              int ms = 450 * (streamCount - 1);
              logger.warn(
                  "Sleeping for "
                      + ms
                      + "ms before"
                      + " configuring processor for SSRC="
                      + ssrc
                      + " "
                      + System.currentTimeMillis());
              Thread.sleep(ms);
            } catch (Exception e) {
            }

            p.configure();
          }
        }.run();
      } else {
        processor.configure();
      }
    } else if (event instanceof TimeoutEvent) {
      if (receiveStream == null) {
        // TODO: we might want to get the list of ReceiveStream-s from
        // rtpManager and compare it to our list, to see if we should
        // remove a stream.
        logger.warn("TimeoutEvent: null.");
        return;
      }

      // FMJ silently creates new ReceiveStream instances, so we have to
      // recognize them by the SSRC.
      ReceiveStreamDesc receiveStreamDesc = findReceiveStream(getReceiveStreamSSRC(receiveStream));
      if (receiveStreamDesc != null) {
        if (logger.isInfoEnabled()) {
          logger.info("ReceiveStream timeout, ssrc=" + receiveStreamDesc.ssrc);
        }

        removeReceiveStream(receiveStreamDesc, true);
      }
    } else if (event != null && logger.isInfoEnabled()) {
      logger.info("Unhandled ReceiveStreamEvent (" + event.getClass().getName() + "): " + event);
    }
  }
  /**
   * Given an array of input media locators and an output locator, this method will concatenate the
   * input media files to generate a single concatentated output.
   */
  public boolean doIt(MediaLocator inML[], MediaLocator outML) {
    // Guess the output content descriptor from the file extension.
    ContentDescriptor cd;

    if ((cd = fileExtToCD(outML.getRemainder())) == null) {
      System.err.println("Couldn't figure out from the file extension the type of output needed!");
      return false;
    }

    // Build the ProcInfo data structure for each processor.
    ProcInfo pInfo[] = new ProcInfo[inML.length];

    for (int i = 0; i < inML.length; i++) {
      pInfo[i] = new ProcInfo();
      pInfo[i].ml = inML[i];

      try {
        System.err.println("- Create processor for: " + inML[i]);
        pInfo[i].p = Manager.createProcessor(inML[i]);
      } catch (Exception e) {
        System.err.println("Yikes!  Cannot create a processor from the given url: " + e);
        return false;
      }
    }

    // Try to match the tracks from different processors.
    if (!matchTracks(pInfo, cd)) {
      System.err.println("Failed to match the tracks.");
      return false;
    }

    // Program each processors to perform the necessary transcoding
    // to concatenate the tracks.
    if (!buildTracks(pInfo)) {
      System.err.println("Failed to build processors for the inputs.");
      return false;
    }

    // Generate a super glue data source from the processors.
    SuperGlueDataSource ds = new SuperGlueDataSource(pInfo);

    // Create the processor to generate the final output.
    Processor p;
    try {
      p = Manager.createProcessor(ds);
    } catch (Exception e) {
      System.err.println("Failed to create a processor to concatenate the inputs.");
      return false;
    }

    p.addControllerListener(this);

    // Put the Processor into configured state.
    if (!waitForState(p, Processor.Configured)) {
      System.err.println("Failed to configure the processor.");
      return false;
    }

    // Set the output content descriptor on the final processor.
    System.err.println("- Set output content descriptor to: " + cd);
    if ((p.setContentDescriptor(cd)) == null) {
      System.err.println("Failed to set the output content descriptor on the processor.");
      return false;
    }

    // We are done with programming the processor. Let's just
    // realize it.
    if (!waitForState(p, Controller.Realized)) {
      System.err.println("Failed to realize the processor.");
      return false;
    }

    // Now, we'll need to create a DataSink.
    DataSink dsink;
    if ((dsink = createDataSink(p, outML)) == null) {
      System.err.println("Failed to create a DataSink for the given output MediaLocator: " + outML);
      return false;
    }

    dsink.addDataSinkListener(this);
    fileDone = false;

    System.err.println("- Start concatenation...");

    // OK, we can now start the actual concatenation.
    try {
      p.start();
      dsink.start();
    } catch (IOException e) {
      System.err.println("IO error during concatenation");
      return false;
    }

    // Wait for EndOfStream event.
    waitForFileDone();

    // Cleanup.
    try {
      dsink.close();
    } catch (Exception e) {
    }
    p.removeControllerListener(this);

    System.err.println("  ...done concatenation.");

    return true;
  }
Beispiel #5
0
  private String createProcessor() {
    if (locator == null) return "Locator is null";

    DataSource ds;
    DataSource clone;

    try {
      ds = Manager.createDataSource(locator);
    } catch (Exception e) {
      return "Couldn't create DataSource";
    }

    // Try to create a processor to handle the input media locator
    try {
      processor = Manager.createProcessor(ds);
    } catch (NoProcessorException npe) {
      return "Couldn't create processor";
    } catch (IOException ioe) {
      return "IOException creating processor";
    }

    // Wait for it to configure
    boolean result = waitForState(processor, Processor.Configured);
    if (result == false) return "Couldn't configure processor";

    // Get the tracks from the processor
    TrackControl[] tracks = processor.getTrackControls();

    // Do we have atleast one track?
    if (tracks == null || tracks.length < 1) return "Couldn't find tracks in processor";

    boolean programmed = false;

    // Search through the tracks for a video track
    for (int i = 0; i < tracks.length; i++) {
      Format format = tracks[i].getFormat();
      if (tracks[i].isEnabled() && format instanceof VideoFormat && !programmed) {

        // Found a video track. Try to program it to output JPEG/RTP
        // Make sure the sizes are multiple of 8's.
        Dimension size = ((VideoFormat) format).getSize();
        float frameRate = ((VideoFormat) format).getFrameRate();
        int w = (size.width % 8 == 0 ? size.width : (int) (size.width / 8) * 8);
        int h = (size.height % 8 == 0 ? size.height : (int) (size.height / 8) * 8);
        VideoFormat jpegFormat =
            new VideoFormat(
                VideoFormat.JPEG_RTP,
                new Dimension(w, h),
                Format.NOT_SPECIFIED,
                Format.byteArray,
                frameRate);
        tracks[i].setFormat(jpegFormat);
        System.err.println("Video transmitted as:");
        System.err.println("  " + jpegFormat);
        // Assume succesful
        programmed = true;
      } else tracks[i].setEnabled(false);
    }

    if (!programmed) return "Couldn't find video track";

    // Set the output content descriptor to RAW_RTP
    ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
    processor.setContentDescriptor(cd);

    // Realize the processor. This will internally create a flow
    // graph and attempt to create an output datasource for JPEG/RTP
    // video frames.
    result = waitForState(processor, Controller.Realized);
    if (result == false) return "Couldn't realize processor";

    // Set the JPEG quality to .5.
    setJPEGQuality(processor, 0.5f);

    // Get the output data source of the processor
    dataOutput = processor.getDataOutput();
    return null;
  }