• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Lecture14Slides.ppt
 

Lecture14Slides.ppt

on

  • 843 views

 

Statistics

Views

Total Views
843
Views on SlideShare
843
Embed Views
0

Actions

Likes
0
Downloads
18
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Lecture14Slides.ppt Lecture14Slides.ppt Presentation Transcript

    • Lecture14 Java Media Framework III – Some JMF Applications
    • Transcoding
      • In transcoding, all we need to do is to set the output content descriptor of the processor to the one we want and then send the output of a processor to a DataSink.
    • Transcoding Algorithm
      • Things to do in this transcoding example program :
      • 1. Create a Processor using input MediaLocator and add a ControlerListener to it.
      • 2. Get the Processor to the Configured state.
      • 3. Set the output ContentDescriptor of the processor to the one we want.
      • 4. Get the Processor to the Realized state.
      • 5. Get the Processor output as a DataSource object.
      • 6. Create a DataSink object from this DataSource object and a output MediaLocator.
      • 7. Open the DataSink object.
      • 8. Add a DataSink listener.
      • 9. Start the Processor, DataSource, and the DataSink.
    • Transcoding Algorithm – Step 1
      • MediaLocator sourceFile = new MediaLocator("file://c:omp311avakiing.avi");
      • Processor p = Manager.createProcessor(sourceFile);
      • p.addControllerListener(new ControllerListener() {
      • public void controllerUpdate(ControllerEvent e) {
      • if (e instanceof StopEvent) {
      • p.close();
      • }
      • }
      • } );
    • Transcoding Algorithm – Step 2
      • We will write a class called ProcessorWait which can wait until a given Processor object reaches a given state.
      • ProcessorWait pw = new ProcessorWait(p);
      • pw.waitForState(Processor.Configured);
    • Transcoding Algorithm – Steps 3,4,5,6,7
      • FileTypeDescriptor ot = new FileTypeDescriptor("video.quicktime");
      • p.setContentDescriptor(ot);
      • pw.waitForState(Processor.Realized);
      • DataSource ds = p.getDataOutput();
      • MediaLocator sinkFile = new MediaLocator("file://c:omp311avakiing.mov");
      • DataSink dsink = Manager.createDataSink(ds, sinkFile);
      • dsink.open();
    • ContentDescriptor
      • The following code segment could be used to obtain the corresponding FileTypeDescriptor object for a particular file extention.
      • String ext = "mov";
      • String type = com.sun.media.MimeManager.getMimeType(ext);
      • type = ContentDescriptor.mimeTypeToPackageName(type);
      • Note that the FileTypeDescriptor class is a subclass of ContentDescriptor class.
    • Transcoding Algorithm – Step 8
      • DataSink also has a event model.
      • Objects which implement DataSinkListener interface can register with the DataSink object as listeners.
      • The DataSinkListener interface has the following method:
      • public void dataSinkUpdate(DataSinkEvent e)
    • Transcoding Algorithm – Step 8
      • dsink.addDataSinkListener(new DataSinkListener() {
      • public void dataSinkUpdate(DataSinkEvent e) {
      • if (e instanceof EndOfStreamEvent) {
      • dsink.close();
      • ds.disconnect();
      • System.out.println("Done");
      • System.exit(0);
      • } else if (e instanceof DataSinkErrorEvent) {
      • System.out.println("Error in datasink");
      • }
      • }
      • });
    • Transcoding Algorithm – Step 9
      • By now we have constructed the processing chain and it is time to start streaming from the source file to the final destination file.
      • p.start();
      • ds.start();
      • dsink.start();
    • ProcessorWait class
      • class ProcessorWait implements ControllerListener {
      • Processor p;
      • boolean error = false;
      • public ProcessorWait(Processor p) {
      • this.p = p;
      • p.addControllerListener(this);
      • }
      • // public boolean waitForState(int state)
      • // public void controllerUpdate(ControllerEvent ce)
      • }
    • ProcessorWait class
      • public boolean waitForState(int state) {
      • switch (state) {
      • case Processor.Configured: p.configure(); break;
      • case Processor.Realized: p.realize(); break;
      • case Processor.Prefetched: p.prefetch(); break;
      • case Processor.Started: p.start(); break;
      • }
      • while (p.getState() < state && !error) {
      • try {
      • wait(1000);
      • } catch (Exception e) {}
      • }
      • return !(error);
      • }
    • ProcessorWait class
      • public void controllerUpdate(ControllerEvent ce) {
      • if (ce instanceof ControllerErrorEvent) {
      • error = true;
      • }
      • synchronized (this) {
      • notifyAll();
      • }
      • }
    • Extending the DataSource Class
      • Extending the DataSource class is useful in processing tasks such as:
        • Splitting the tracks of media into different files.
        • Cutting different time segments from the media.
      • we will look at how Buffer objects can be used in these tasks.
      • There are two types of Buffer based data source classes:
        • PushBufferDataSource - abstracts a data source that manages data in the form of push streams. The streams, i.e. PushBufferStreams, from this data source contain Buffer objects.
        • PullBufferDataSource - Abstracts a media data-source that contains one or more PullBufferStreams and delivers data as Buffer objects. We will not talk about this!
    • PushBufferStream
      • PushBufferStream abstracts a read interface that pushes data in the form of Buffer objects. This interface allows a source stream to transfer data in the form of an entire media chunk to the user of this source stream. The media object or chunk transferred is the Buffer object as defined in javax.media.Buffer.
      • The user of the stream will allocate an empty Buffer object and pass this over to the source stream by calling the read() method.
      • The interested user of a particular PushBufferStream registers with the PushBufferStream by it with a BufferTransferHandler object by calling the setTransferHandler() method.
        • The object implementing this BufferTransferHandler interface will be notified when the PushBufferStream has any new media data available in the form of a Buffer. This is done by calling the transferData() method of the BufferTransferHandler interface.
        • It is upto the user to take any action when it is notified via transferData() method. Usually the user reads the media chunk by providing an empty Buffer object via the read() method of the source stream.
    • BufferTransferHandler interface
      • Usually BufferTransferHandler interface is implemented by the class which implement the PushBufferStream itself.
      • The object implementing the BufferTransferHandler interface must implement the transferData(PushBufferStream pbs) method which usually does the following:
        • Wait for the Buffer object to be available for this thread.
        • Read into the Buffer from the PushBufferStream.
        • Process the Buffer.
        • Make the Buffer available for other threads.
        • Call transferData of the BufferTransferHandler registered with this stream.
    • read(Buffer b) method of PushBufferStream
      • The read(Buffer b) method of PushBufferStream usually does the following:
        • Wait for the Buffer object of this stream to be available for the current thread.
        • Process the contents of the specified Buffer object parameter of the read() method using the Buffer object this stream. It is usually a copy.
        • Make the Buffer object of this stream available for other threads.
    • Extending the PushBufferDataSource
      • The PushBufferDataSource need to implement its constructor, connect(), disconnect(), getContentType(), getControl(), getControls, getDuration(), start(), stop(), and getStreams() methods.
      • Most of these methods are not used by our intended task and hence we don't need to properly implement them.
    • Extending the PushBufferDataSource
      • The PushBufferStream need to implement its constructor, endOfStream(), getContentDescriptor(), getContentLength(), getControl, getControls, getFormat(), read(), and setTransferHandler() methods.
    • Example
      • We will write a very basic program which process Buffer objects.
      • We extend the PushBufferDataSource for this purpose. This new objects reads Buffer objects from a source and simply pass it on to other objects which are interested of reading from this source.
      • Please read the given source code SourceToSink.java