Your SlideShare is downloading. ×
Lecture14Slides.ppt
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Lecture14Slides.ppt

655

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
655
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Lecture14 Java Media Framework III – Some JMF Applications
  • 2. 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.
  • 3. 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.
  • 4. 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();
    • }
    • }
    • } );
  • 5. 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);
  • 6. 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();
  • 7. 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.
  • 8. 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)
  • 9. 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");
    • }
    • }
    • });
  • 10. 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();
  • 11. 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)
    • }
  • 12. 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);
    • }
  • 13. ProcessorWait class
    • public void controllerUpdate(ControllerEvent ce) {
    • if (ce instanceof ControllerErrorEvent) {
    • error = true;
    • }
    • synchronized (this) {
    • notifyAll();
    • }
    • }
  • 14. 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!
  • 15. 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.
  • 16. 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.
  • 17. 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.
  • 18. 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.
  • 19. Extending the PushBufferDataSource
    • The PushBufferStream need to implement its constructor, endOfStream(), getContentDescriptor(), getContentLength(), getControl, getControls, getFormat(), read(), and setTransferHandler() methods.
  • 20. 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

×