Пример #1
0
 /** Stops the transmission if already started */
 public void stop() {
   synchronized (this) {
     if (processor != null) {
       processor.stop();
       processor.close();
       processor = null;
       rtptransmitter.close();
       rtptransmitter = null;
     }
   }
 }
Пример #2
0
  /**
   * Starts the transmission. Returns null if transmission started ok. Otherwise it returns a string
   * with the reason why the setup failed.
   */
  public synchronized String start() {
    String result;

    // Create a processor for the specified media locator
    // and program it to output JPEG/RTP
    result = createProcessor();
    if (result != null) return result;

    // Create an RTP session to transmit the output of the
    // processor to the specified IP address and port no.
    result = createTransmitter();
    if (result != null) {
      processor.close();
      processor = null;
      return result;
    }

    // Start the transmission
    processor.start();

    return null;
  }
Пример #3
0
  @Override
  public void close() {
    super.close();

    synchronized (gate) {
      selector.wakeup();

      if (workersEnabled) {
        for (Worker w : workers) {
          w.end();
          try {
            w.join();
          } catch (InterruptedException e) {
          }
        }
      }

      try {
        for (SelectionKey key : keys) {
          if (key.isValid()) {
            Connection c = (Connection) key.attachment();

            key.attach(null);
            key.cancel();

            if (c.channel().keyFor(retrySelector) != null) {
              c.channel().keyFor(retrySelector).cancel();
            }

            c.close(true);
          }
        }
      } catch (CancelledKeyException e) {
      }

      keys.clear();
    }
  }
Пример #4
0
  public static void main(String[] args) {

    // ---------------- CUT HERE START ----------------- //

    Format formats[] = new Format[2];
    formats[0] = new AudioFormat(AudioFormat.IMA4);
    formats[1] = new VideoFormat(VideoFormat.CINEPAK);
    FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.QUICKTIME);
    Processor p = null;

    try {
      p = Manager.createRealizedProcessor(new ProcessorModel(formats, outputType));
    } catch (IOException e) {
      System.exit(-1);
    } catch (NoProcessorException e) {
      System.exit(-1);
    } catch (CannotRealizeException e) {
      System.exit(-1);
    }
    // get the output of the processor
    DataSource source = p.getDataOutput();
    // create a File protocol MediaLocator with the location of the file to
    // which bits are to be written
    MediaLocator dest = new MediaLocator("file://foo.mov");
    // create a datasink to do the file writing & open the sink to make sure
    // we can write to it.
    DataSink filewriter = null;
    try {
      filewriter = Manager.createDataSink(source, dest);
      filewriter.open();
    } catch (NoDataSinkException e) {
      System.exit(-1);
    } catch (IOException e) {
      System.exit(-1);
    } catch (SecurityException e) {
      System.exit(-1);
    }
    // now start the filewriter and processor
    try {
      filewriter.start();
    } catch (IOException e) {
      System.exit(-1);
    }
    p.start();
    // stop and close the processor when done capturing...
    // close the datasink when EndOfStream event is received...

    // ----------------- CUT HERE END ---------------- //
    try {
      Thread.currentThread().sleep(4000);
    } catch (InterruptedException ie) {
    }
    p.stop();
    p.close();
    try {
      Thread.currentThread().sleep(1000);
    } catch (InterruptedException ie) {
    }
    filewriter.close();
    try {
      Thread.currentThread().sleep(4000);
    } catch (InterruptedException ie) {
    }

    System.exit(0);
  }