SlideShare a Scribd company logo
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:\\comp311\\java\\skiing.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:\\comp311\\javaguatda.com/cmx.p\\skiing.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

More Related Content

PPT
Content providers in Android
PPTX
05 content providers - Android
PPT
URL Class in JAVA
PPT
Java File I/O
PPT
Java Input Output and File Handling
PPTX
SCWCD : The servlet model : CHAP : 2
PPT
Chapter 12 - File Input and Output
PPT
Url Connection
Content providers in Android
05 content providers - Android
URL Class in JAVA
Java File I/O
Java Input Output and File Handling
SCWCD : The servlet model : CHAP : 2
Chapter 12 - File Input and Output
Url Connection

What's hot (20)

PPT
Url Connection
PPTX
Java file
PPT
7 streams and error handling in java
PPTX
Content provider in_android
PPTX
SCWCD : The servlet model CHAP : 2
ODP
Android App Development - 10 Content providers
PPT
Filehandlinging cp2
PPTX
Android content providers
PPTX
[Java] #7 - Input & Output Stream
PPT
Tech talk
PPTX
DOC
Servlet basics
PPT
Cpp file-handling
PDF
Input File dalam C++
PPT
working file handling in cpp overview
PDF
Filehadnling
PPT
17 files and streams
Url Connection
Java file
7 streams and error handling in java
Content provider in_android
SCWCD : The servlet model CHAP : 2
Android App Development - 10 Content providers
Filehandlinging cp2
Android content providers
[Java] #7 - Input & Output Stream
Tech talk
Servlet basics
Cpp file-handling
Input File dalam C++
working file handling in cpp overview
Filehadnling
17 files and streams
Ad

Viewers also liked (19)

PPTX
Lab safety rules ppp wiki
PPTX
The tools of science
PPTX
Scientific method presentation
PPT
Science Tools
PPTX
Science tools ppp wiki
PPTX
Scientific method
PPT
Science Equipment for Sixth Grade
PPTX
Science Tools
PPS
Laboratory Rules And Safety Guidelines For Students
PPTX
Lab tools
PPT
Lab Safety
PPT
Lab safety
PPT
Lab safety ppt
PPT
Lab safety rules and symbols Summary
PPTX
Lab+safety+rules+ppt
PPSX
Scientific tools measuring volume
PPT
Science Tools
KEY
Lab equipment
Lab safety rules ppp wiki
The tools of science
Scientific method presentation
Science Tools
Science tools ppp wiki
Scientific method
Science Equipment for Sixth Grade
Science Tools
Laboratory Rules And Safety Guidelines For Students
Lab tools
Lab Safety
Lab safety
Lab safety ppt
Lab safety rules and symbols Summary
Lab+safety+rules+ppt
Scientific tools measuring volume
Science Tools
Lab equipment
Ad

Similar to Lecture14Slides.ppt (20)

PPTX
Metadata Extraction and Content Transformation
PPT
Level 4
PPT
Introduction to objects and inputoutput
PDF
Android development training programme , Day 3
PPT
Chapter 11
PPTX
DOCX
Describe how the ProcessInput() method works- What does the heading lo.docx
PDF
INTRODUCTION TO CLIENT SIDE PROGRAMMING
DOCX
Struts notes
PDF
Working with Servlets
PDF
Android application architecture
PPTX
Android Application Components-BroadcastReceiver_Content Provider.pptx
PPTX
SCWCD : The servlet container : CHAP : 4
PDF
Data file handling
PPT
File handling in C++
PPT
Java stream
PPTX
Servlet session 9
PPT
File handling in_c
PPT
Jsr75 sup
PPTX
chapter 2(IO and stream)/chapter 2, IO and stream
Metadata Extraction and Content Transformation
Level 4
Introduction to objects and inputoutput
Android development training programme , Day 3
Chapter 11
Describe how the ProcessInput() method works- What does the heading lo.docx
INTRODUCTION TO CLIENT SIDE PROGRAMMING
Struts notes
Working with Servlets
Android application architecture
Android Application Components-BroadcastReceiver_Content Provider.pptx
SCWCD : The servlet container : CHAP : 4
Data file handling
File handling in C++
Java stream
Servlet session 9
File handling in_c
Jsr75 sup
chapter 2(IO and stream)/chapter 2, IO and stream

More from Videoguy (20)

PDF
Energy-Aware Wireless Video Streaming
PDF
Microsoft PowerPoint - WirelessCluster_Pres
PDF
Proxy Cache Management for Fine-Grained Scalable Video Streaming
PDF
Adobe
PDF
Free-riding Resilient Video Streaming in Peer-to-Peer Networks
PDF
Instant video streaming
PDF
Video Streaming over Bluetooth: A Survey
PDF
Video Streaming
PDF
Reaching a Broader Audience
PDF
Considerations for Creating Streamed Video Content over 3G ...
PDF
ADVANCES IN CHANNEL-ADAPTIVE VIDEO STREAMING
PDF
Impact of FEC Overhead on Scalable Video Streaming
PDF
Application Brief
PDF
Video Streaming Services – Stage 1
PDF
Streaming Video into Second Life
PDF
Flash Live Video Streaming Software
PDF
Videoconference Streaming Solutions Cookbook
PDF
Streaming Video Formaten
PDF
iPhone Live Video Streaming Software
PDF
Glow: Video streaming training guide - Firefox
Energy-Aware Wireless Video Streaming
Microsoft PowerPoint - WirelessCluster_Pres
Proxy Cache Management for Fine-Grained Scalable Video Streaming
Adobe
Free-riding Resilient Video Streaming in Peer-to-Peer Networks
Instant video streaming
Video Streaming over Bluetooth: A Survey
Video Streaming
Reaching a Broader Audience
Considerations for Creating Streamed Video Content over 3G ...
ADVANCES IN CHANNEL-ADAPTIVE VIDEO STREAMING
Impact of FEC Overhead on Scalable Video Streaming
Application Brief
Video Streaming Services – Stage 1
Streaming Video into Second Life
Flash Live Video Streaming Software
Videoconference Streaming Solutions Cookbook
Streaming Video Formaten
iPhone Live Video Streaming Software
Glow: Video streaming training guide - Firefox

Lecture14Slides.ppt

  • 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(&quot;file://c:\\comp311\\java\\skiing.avi&quot;); 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(&quot;video.quicktime&quot;); p.setContentDescriptor(ot); pw.waitForState(Processor.Realized); DataSource ds = p.getDataOutput(); MediaLocator sinkFile = new MediaLocator(&quot;file://c:\\comp311\\javaguatda.com/cmx.p\\skiing.mov&quot;); 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 = &quot;mov&quot;; 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(&quot;Done&quot;); System.exit(0); } else if (e instanceof DataSinkErrorEvent) { System.out.println(&quot;Error in datasink&quot;); } } });
  • 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