net.sf.fmj.ejmf.toolkit.media
Class AbstractClock

java.lang.Object
  extended by net.sf.fmj.ejmf.toolkit.media.AbstractClock
All Implemented Interfaces:
Clock
Direct Known Subclasses:
AbstractController

public class AbstractClock
extends java.lang.Object
implements Clock

The AbstractClock provides an abstract implementation of the javax.media.Clock interface. All methods are implemented except for setStopTime() and getStopTime(). These methods will invariably require implementation-specific functionality and therefore are left to the subclasses to implement. From the book: Essential JMF, Gordon, Talley (ISBN 0130801046). Used with permission.

Author:
Steve Talley & Rob Gordon
See Also:
AbstractController, StopTimeMonitor

Field Summary
 
Fields inherited from interface javax.media.Clock
RESET
 
Constructor Summary
AbstractClock()
          Constructs an AbstractClock.
 
Method Summary
 long getMediaNanoseconds()
          Get the media time in nanoseconds.
protected  Time getMediaStartTime()
          Get the media time the media is scheduled to start (if the Clock is stopped), or the media time at which the Clock started (if the Clock is started).
 Time getMediaTime()
          Calculates the current media time based on the current time-base time, the time-base start time, the media start time, and the rate.
 float getRate()
          Get the current temporal scale factor.
 Time getStopTime()
          Get the last value successfully set by setStopTime.
 Time getSyncTime()
          Gets the time until the Clock's media synchronizes with its time-base.
 TimeBase getTimeBase()
          Get the TimeBase that this Clock is using.
protected  Time getTimeBaseStartTime()
          Get the time-base time the media is scheduled to start (if the Clock is stopped), or the time-base time at which the Clock started (if the Clock is started).
 Time mapToTimeBase(Time t)
          Given a media time, returns the corresponding time-base time.
 void setMediaTime(Time t)
          Sets the media time.
 float setRate(float rate)
          Set the temporal scale factor.
 void setStopTime(Time mediaStopTime)
          Set the media time at which you want the Clock to stop.
 void setTimeBase(TimeBase timebase)
          Set the TimeBase for this Clock.
 void stop()
          Stop the Clock.
 void syncStart(Time t)
          syncStart the AbstractClock at the previously- specified time-base start time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractClock

public AbstractClock()
Constructs an AbstractClock.

Method Detail

setTimeBase

public void setTimeBase(TimeBase timebase)
                 throws IncompatibleTimeBaseException
Set the TimeBase for this Clock. This method can only be called on a Stopped Clock. A ClockStartedError is thrown if setTimeBase is called on a Started Clock.

A Clock has a default TimeBase that is determined by the implementation. To reset a Clock to its default TimeBase, call setTimeBase(null).

Specified by:
setTimeBase in interface Clock
Parameters:
timebase - The new TimeBase or null to reset the Clock to its default TimeBase.
Throws:
IncompatibleTimeBaseException - Thrown if the Clock can't use the specified TimeBase.

getTimeBase

public TimeBase getTimeBase()
Get the TimeBase that this Clock is using.

Specified by:
getTimeBase in interface Clock

setMediaTime

public void setMediaTime(Time t)
Sets the media time.

Specified by:
setMediaTime in interface Clock
Parameters:
t - The media time to set
Throws:
ClockStartedError - If the Clock is Started.

getMediaStartTime

protected Time getMediaStartTime()
Get the media time the media is scheduled to start (if the Clock is stopped), or the media time at which the Clock started (if the Clock is started).


getTimeBaseStartTime

protected Time getTimeBaseStartTime()
Get the time-base time the media is scheduled to start (if the Clock is stopped), or the time-base time at which the Clock started (if the Clock is started).


getMediaTime

public Time getMediaTime()
Calculates the current media time based on the current time-base time, the time-base start time, the media start time, and the rate.

Specified by:
getMediaTime in interface Clock
Returns:
The current media time

getMediaNanoseconds

public long getMediaNanoseconds()
Get the media time in nanoseconds.

Specified by:
getMediaNanoseconds in interface Clock

getSyncTime

public Time getSyncTime()
Gets the time until the Clock's media synchronizes with its time-base.

Specified by:
getSyncTime in interface Clock
Returns:
The time remaining until the time-base start-time if this Clock is Started and the time-base start-time has not yet been reached, or the media time otherwise.

mapToTimeBase

public Time mapToTimeBase(Time t)
                   throws ClockStoppedException
Given a media time, returns the corresponding time-base time. Uses the current rate, the time-base start time, and the media start time to calculate.

Specified by:
mapToTimeBase in interface Clock
Parameters:
t - A media time to be mapped to a time-base time.
Returns:
A time-base time.
Throws:
ClockStoppedException - If the clock has not started.

setRate

public float setRate(float rate)
Set the temporal scale factor. The argument suggests the scale factor to use.

The setRate method returns the actual rate set by the Clock. Clocks should set their rate as close to the requested value as possible, but are not required to set the rate to the exact value of any argument other than 1.0. A Clock is only guaranteed to set its rate exactly to 1.0.

Specified by:
setRate in interface Clock
Parameters:
rate - The temporal scale factor (rate) to set.
Returns:
The actual rate set.
Throws:
ClockStartedError - If the Clock is Started.

getRate

public float getRate()
Get the current temporal scale factor. The scale factor defines the relationship between the Clock's media time and its TimeBase.

For example, a rate of 2.0 indicates that media time will pass twice as fast as the TimeBase time once the Clock starts. Similarly, a negative rate indicates that the Clock runs in the opposite direction of its TimeBase. All Clocks are guaranteed to support a rate of 1.0, the default rate. Clocks are not required to support any other rate.

Specified by:
getRate in interface Clock

setStopTime

public void setStopTime(Time mediaStopTime)
Set the media time at which you want the Clock to stop. The Clock will stop when its media time passes the stop-time. To clear the stop time, set it to: Clock.RESET.

You can always call setStopTime on a Stopped Clock.

On a Started Clock, the stop-time can only be set once. A StopTimeSetError is thrown if setStopTime is called and the media stop-time has already been set.

Specified by:
setStopTime in interface Clock
Parameters:
mediaStopTime - The time at which you want the Clock to stop, in media time.

getStopTime

public Time getStopTime()
Get the last value successfully set by setStopTime. Returns the constant Clock.RESET if no stop time is set

Specified by:
getStopTime in interface Clock
Returns:
The current stop time.

syncStart

public void syncStart(Time t)
syncStart the AbstractClock at the previously- specified time-base start time.

Synchronous method -- return when transition complete

Specified by:
syncStart in interface Clock

stop

public void stop()
Stop the Clock.

Specified by:
stop in interface Clock