Package javax.media

Examples of javax.media.DataSink


        }
      }
     
    };
    final PipedOutputStream out = new PipedOutputStream(in);
    final DataSink streamDataSink = new StreamDataSink(out);
    streamDataSinkHolder[0] = streamDataSink;
   
    streamDataSink.setSource(ds);
    streamDataSink.open();
    streamDataSink.start();
   
    logger.info("Starting processor");
    processor.start();
   
    // TODO: if there is an error, make sure we clean up.
View Full Code Here


      {
        String url = "rtp://192.168.1.4:8000/audio/16";

        MediaLocator m = new MediaLocator(url);

        DataSink d = Manager.createDataSink(ds, m);
        d.open();
        d.start();
       
        System.out.println("Starting processor");
        processor.start();
        Thread.sleep(30000);
      } catch (Exception e)
View Full Code Here

      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 processing...");

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

  // Wait for EndOfStream event.
  waitForFileDone();

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

  System.err.println("...done processing.");
View Full Code Here

  if ((ds = p.getDataOutput()) == null) {
      System.err.println("Something is really wrong: the processor does not have an output DataSource");
      return null;
  }

  DataSink dsink;

  try {
      System.err.println("- create DataSink for: " + outML);
      dsink = Manager.createDataSink(ds, outML);
      dsink.open();
  } catch (Exception e) {
      System.err.println("Cannot create the DataSink: " + e);
      return null;
  }
View Full Code Here

      // create a File protocol MediaLocator with the location of the
      // file to which the data is to be written
      MediaLocator dest = new MediaLocator(destUrl);
      // 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);
          System.out.println("DataSink: " + filewriter);
         System.out.println("DataSink content type: " + filewriter.getContentType());
          filewriter.open();
      } catch (NoDataSinkException e) {
        e.printStackTrace();
          System.exit(-1);
      } catch (IOException e) {
       e.printStackTrace();
          System.exit(-1);
      } catch (SecurityException e) {
       e.printStackTrace();
          System.exit(-1);
      }

      // if the Processor implements StreamWriterControl, we can
      // call setStreamSizeLimit
      // to set a limit on the size of the file that is written.
      StreamWriterControl swc = (StreamWriterControl)
          p.getControl("javax.media.control.StreamWriterControl");
      //set limit to 5MB
      if (swc != null)
          swc.setStreamSizeLimit(5000000);
  
      // now start the filewriter and processor
      try {
          filewriter.start();
      } catch (IOException e) {
       e.printStackTrace();
          System.exit(-1);
      }
      // Capture for 5 seconds
      sh.playToEndOfMedia(5000);
      sh.close();
      // Wait for an EndOfStream from the DataSink and close it...
    
      // TODO: if the writing takes a long time, and is happening asynchronously, as it does in FMJ,
      // the writing can theoretically get interrupted here.
     
//      System.out.println("Sleeping...");
//     try
//    {
//      Thread.sleep(5000);
//    } catch (InterruptedException e)
//    {
//      e.printStackTrace();
//    }
     
      filewriter.close();


      System.out.println("Done.");
  }
View Full Code Here

            }
          }
        }
      };
    Processor processor = null;
    DataSink dataSink = null;
    try {
      processor = Manager.createProcessor(dataSource);
      processor.addControllerListener(controllerListener);
      processor.configure();
      // Put the Processor into configured state so we can set
      // some processing options on the processor.
      if (!waitForState(processor, Processor.Configured)) {
        throw new IOException("Failed to configure the processor.");
      }

      // Set the output content descriptor to QuickTime.
      processor.setContentDescriptor(new ContentDescriptor(FileTypeDescriptor.QUICKTIME));

      // Query for the processor for supported formats.
      // Then set it on the processor.
      TrackControl trackControls[] = processor.getTrackControls();
      Format format[] = trackControls [0].getSupportedFormats();
      if (format == null || format.length <= 0) {
        throw new IOException("The mux does not support the input format: " + trackControls [0].getFormat());
      }

      trackControls [0].setFormat(format [0]);

      // We are done with programming the processor. Let's just realize it.
      processor.realize();
      if (!waitForState(processor, Controller.Realized)) {
        throw new IOException("Failed to realize the processor.");
      }

      // Now, we'll need to create a DataSink.
      // Caution: do not use file.toURI().toURL() with JMF
      dataSink = Manager.createDataSink(processor.getDataOutput(),
          new MediaLocator(file.toURL()));
      dataSink.open();
      dataSink.addDataSinkListener(dataSinkListener);
      this.fileDone = false;

      // Start the actual transcoding
      processor.start();
      dataSink.start();

      // Wait for EndOfStream event.
      synchronized (this.waitFileSync) {
        while (!this.fileDone) {
          this.waitFileSync.wait();
        }
      }
     
      if (this.fileError != null) {
        throw new IOException(this.fileError);
      }
    } catch (NoProcessorException ex) {
      IOException ex2 = new IOException(ex.getMessage());
      ex2.initCause(ex);
      throw ex2;
    } catch (NoDataSinkException ex) {
      IOException ex2 = new IOException("Failed to create a DataSink for the given output MediaLocator");
      ex2.initCause(ex);
      throw ex2;
    } catch (InterruptedException ex) {
      if (dataSink != null) {
        dataSink.stop();
      }
      throw new InterruptedIOException("Video creation interrupted");
    } finally {
      if (dataSink != null) {
        dataSink.close();
        dataSink.removeDataSinkListener(dataSinkListener);
      }
      if (processor != null) {
        processor.close();
        processor.removeControllerListener(controllerListener);
      }
View Full Code Here

            if (_debugging) {
                _debug(_fileRoot);
            }

            DataSink dataSink;

            try {
                dataSink = Manager.createDataSink(dataSource, mediaLocator);
                dataSink.open();
            } catch (Exception ex) {
                throw new IllegalActionException(this, ex,
                        "Couldn't create the data sink");
            }

            dataSink.addDataSinkListener(this);

            try {
                processor.start();
                dataSink.start();
            } catch (IOException ex) {
                throw new IllegalActionException(this, ex,
                        "Could not start processor and datasink");
            }

            if (!_waitForFileDone()) {
                throw new IllegalActionException("Could not write the file");
            }

            try {
                dataSink.close();
            } catch (Exception ex) {
                throw new IllegalActionException(this, ex,
                        "can't close data sink");
            }

            processor.stop();
            processor.removeControllerListener(this);
            dataSink.removeDataSinkListener(this);
            processor.close();
            dataSink.close();
        }
    }
View Full Code Here

      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.out.println("Generating the video : "+outML.getURL().toString());

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

    // Wait for EndOfStream event.
    waitForFileDone();

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

    //System.out.println("Video creation completed!!!!!");
View Full Code Here

      System.err
          .println("Something is really wrong: the processor does not have an output DataSource");
      return null;
    }

    DataSink dsink;

    try {
      //System.err.println("- create DataSink for: " + outML);
      dsink = Manager.createDataSink(ds, outML);
      dsink.open();
    } catch (Exception e) {
      System.err.println("Cannot create the DataSink: " + e);
      return null;
    }
View Full Code Here

TOP

Related Classes of javax.media.DataSink

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.