ptolemy.actor.lib.jmf
Class MovieReader

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.Source
                              extended by ptolemy.actor.lib.jmf.MovieReader
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, javax.media.ControllerListener, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class MovieReader
extends Source
implements javax.media.ControllerListener

This actor loads a video file (MPEG, AVI, or Quicktime files only), and outputs each frame as a JMFImageToken.

Note that not all formats are supported, for details, see the JMF faq at: http://java.sun.com/products/java-media/jmf/reference/faqs/index.html

Since:
Ptolemy II 4.0
Version:
$Id: MovieReader.java 57040 2010-01-27 20:52:32Z cxh $
Author:
James Yeh
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  javax.media.protocol.DataSource _dataSource
           
private  javax.media.Buffer _frame
           
private  javax.media.control.FrameGrabbingControl _frameGrabbingControl
           
private  javax.media.control.FramePositioningControl _framePositioningControl
           
private  javax.media.Player _player
           
private  boolean _playerOpen
           
private  javax.media.ControllerEvent _stateTransitionEvent
           
private  boolean _stateTransitionOK
           
private  java.lang.Object _waitSync
           
 FileParameter fileOrURL
          The file name or URL from which to read.
 
Fields inherited from class ptolemy.actor.lib.Source
output, trigger
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
MovieReader(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
private  java.lang.String _controlNames()
           
protected  boolean _waitForState(int state)
          Block until the processor has transitioned to the given state.
 void attributeChanged(Attribute attribute)
          An attempt is made to acquire the file name.
 void controllerUpdate(javax.media.ControllerEvent event)
          The controller listener.
 void fire()
          Send a JMFImageToken out through the output port.
 void initialize()
          An attempt is made to acquire both the frame grabbing and frame positioning controls.
 boolean postfire()
          If the player is no longer open, then disconnect the datasource.
 
Methods inherited from class ptolemy.actor.lib.Source
prefire
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

fileOrURL

public FileParameter fileOrURL
The file name or URL from which to read. This is a string with any form accepted by File Attribute. The default value is the string "file:///C:/program%20files/quicktime/Sample.mov".

See Also:
FileParameter

_dataSource

private javax.media.protocol.DataSource _dataSource

_frame

private javax.media.Buffer _frame

_frameGrabbingControl

private javax.media.control.FrameGrabbingControl _frameGrabbingControl

_framePositioningControl

private javax.media.control.FramePositioningControl _framePositioningControl

_player

private javax.media.Player _player

_playerOpen

private boolean _playerOpen

_stateTransitionEvent

private javax.media.ControllerEvent _stateTransitionEvent

_stateTransitionOK

private boolean _stateTransitionOK

_waitSync

private java.lang.Object _waitSync
Constructor Detail

MovieReader

public MovieReader(CompositeEntity container,
                   java.lang.String name)
            throws IllegalActionException,
                   NameDuplicationException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
An attempt is made to acquire the file name. If it is successful, create the DataSource that encapsulates the file.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that changed.
Throws:
IllegalActionException - If the URL is null, or invalid.

controllerUpdate

public void controllerUpdate(javax.media.ControllerEvent event)
The controller listener. This method controls the initializing of the player. It also senses when the file is done playing, in which case it closes the player.

Specified by:
controllerUpdate in interface javax.media.ControllerListener
Parameters:
event - The controller event.

fire

public void fire()
          throws IllegalActionException
Send a JMFImageToken out through the output port.

Specified by:
fire in interface Executable
Overrides:
fire in class Source
Throws:
IllegalActionException - If there's no director.

initialize

public void initialize()
                throws IllegalActionException
An attempt is made to acquire both the frame grabbing and frame positioning controls. If both succeed, the first frame is acquired.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the either frame grabbing control or frame positioning control cannot be acquired, or if a contained method throws it.

postfire

public boolean postfire()
                 throws IllegalActionException
If the player is no longer open, then disconnect the datasource. If the player is still open, acquire the next frame.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
false if the player is no longer open, otherwise return super.postfire().
Throws:
IllegalActionException - If thrown by the super class.

_waitForState

protected boolean _waitForState(int state)
                         throws IllegalActionException
Block until the processor has transitioned to the given state.

Parameters:
state - The state.
Returns:
false if the transition failed.
Throws:
IllegalActionException - If there is a problem blocking the processor until the state transition is completed.

_controlNames

private java.lang.String _controlNames()