Lecture14 Java Media Framework III – Some JMF Applications.

Slides:



Advertisements
Similar presentations
Chapter 17 Failures and exceptions. This chapter discusses n Failure. n The meaning of system failure. n Causes of failure. n Handling failure. n Exception.
Advertisements

Processes Management.
Concurrency (p2) synchronized (this) { doLecture(part2); } synchronized (this) { doLecture(part2); }
Ch 7 B.
Written by: Dr. JJ Shepherd
Java Media Framework The Java Media Framework (JMF) is an application programming interface (API) for incorporating time- based media into Java applications.
Instructore: Tasneem Darwish1 University of Palestine Faculty of Applied Engineering and Urban Planning Software Engineering Department Concurrent and.
Lecture13 Java Media Framework II - Java Media Framework II - Processing and Controlling Media with JMF.
Lecture12 Java Media Framework I. Streaming Media Steaming media simply means we have a stream of media coming through some kind of a media channel. Some.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
CS2200 Software Development Lecture: Object class A. O’Riordan, 2008.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
Threads CSCI 444/544 Operating Systems Fall 2008.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
Io package as Java’s basic I/O system continue’d.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Threads and Multimedia Animation, Images, Sound. Animation nAnimation, displaying a sequence of frames to create the illusion of motion, is a typical.
The Java Media Framework: javax.media
CIS 644 Aug. 25, 1999 tour of Java. First … about the media lectures… we are experimenting with the media format please give feedback.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
1 Web Based Programming Section 8 James King 12 August 2003.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
JMF Introduction Yuqiang Liao Content What can JMF do What can JMF do Handling Time-Based Media Handling Time-Based Media JMF Architecture.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
UNIX Files File organization and a few primitives.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
Dynamic Architectures (Component Reconfiguration) with Fractal.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Advanced Concurrency Topics Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Java Thread and Memory Model
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 12 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/ George Koutsogiannakis 1.
Threads in Java Threads Introduction: After completing this chapter, you will be able to code your own thread, control them efficiently without.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 20.
COMP 110: Spring Announcements Program 5 Milestone 1 was due today Program 4 has been graded.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Li Tak Sing COMPS311F. Case study: a multithreaded chat server The source contains 3 files: ChatServer //the chat server ChatThread //the thread on the.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Section 3.3 Exceptional Situations. 3.3 Exceptional Situations Exceptional situation Associated with an unusual, sometimes unpredictable event, detectable.
1 Stacks Abstract Data Types (ADTs) Stacks Application to the analysis of a time series Java implementation of a stack Interfaces and exceptions.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
OBJECT ORIENTED PROGRAMMING II LECTURE 21 GEORGE KOUTSOGIANNAKIS
Threads in Java Two ways to start a thread
Lecture 14 Throwing Custom Exceptions
Exceptions, Interfaces & Generics
I/O Basics.
CS2102: Lecture on Abstract Classes and Inheritance
null, true, and false are also reserved.
Multithreaded Programming
Stacks Abstract Data Types (ADTs) Stacks
OBJECT ORIENTED PROGRAMMING II LECTURE 22 GEORGE KOUTSOGIANNAKIS
Java for Beginners University Greenwich Computing At School DASCO
NETWORK PROGRAMMING CNET 441
Flight Simulation Client/Server
CSE 153 Design of Operating Systems Winter 2019
A type is a collection of values
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:\\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. 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\\java\\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.PushBufferDataSource PullBufferDataSource - Abstracts a media data- source that contains one or more PullBufferStreams and delivers data as Buffer objects. We will not talk about this!PullBufferDataSource

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: 1. 1.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: 1. 1.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 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. 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 Please read the given source code SourceToSink.java