ptolemy.actor.lib.jmf
Class MovieWriter

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.Sink
                              extended by ptolemy.actor.lib.jmf.MovieWriter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, javax.media.ControllerListener, javax.media.datasink.DataSinkListener, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class MovieWriter
extends Sink
implements javax.media.ControllerListener, javax.media.datasink.DataSinkListener

This actor writes a video file (MPEG, AVI, or Quicktime). It receives JMFImageTokens at the input, and queues them up for writing.

The file is specified by the fileName attribute using any form acceptable to FileParameter.

If the confirmOverwrite parameter has value false, then this actor will overwrite the specified file if it exists without asking. If true (the default), then if the file exists, then this actor will ask for confirmation before overwriting.

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

Nested Class Summary
private  class MovieWriter.ImageDataSource
           
private  class MovieWriter.ImageSourceStream
           
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private static int _AVI
           
private  java.util.ArrayList _bufferArrayList
           
private  java.util.Iterator _bufferIterator
           
private  boolean _confirmOverwrite
           
private  boolean _ended
           
private  java.io.File _file
           
private  boolean _fileDone
           
private  java.lang.String _fileRoot
           
private  boolean _fileSuccess
           
private  int _fileType
           
private  MovieWriter.ImageSourceStream[] _imageSourceStream
           
private  JMFImageToken _jmfImageToken
           
private static int _MPEG
           
private static int _QUICKTIME
           
private  boolean _stateTransitionOK
           
private  javax.media.format.VideoFormat _videoFormat
           
private  java.lang.Object _waitFileSync
           
private  java.lang.Object _waitSync
           
 Parameter confirmOverwrite
          If false, then overwrite the specified file if it exists without asking.
 FileParameter fileOrURL
          The file name or URL from which to read.
 StringAttribute fileType
          The type of file to write.
 
Fields inherited from class ptolemy.actor.lib.Sink
input
 
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
MovieWriter(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
protected  boolean _waitForFileDone()
          Wait for the file to be written.
protected  boolean _waitForState(javax.media.Processor processor, 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 dataSinkUpdate(javax.media.datasink.DataSinkEvent event)
          The data sink listener.
 void initialize()
          Initialize this actor.
 boolean postfire()
          Fire this actor.
 void wrapup()
          Save the file.
 
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, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
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
fire, isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
 
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

confirmOverwrite

public Parameter confirmOverwrite
If false, then overwrite the specified file if it exists without asking. If true (the default), then if the file exists, ask for confirmation before overwriting.


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 initial default value is the string "$TMPDIR/movieOut.mov";

See Also:
FileParameter

fileType

public StringAttribute fileType
The type of file to write. There are three different file types that this actor can write. They are AVI, MPEG, and QUICKTIME.


_bufferArrayList

private java.util.ArrayList _bufferArrayList

_bufferIterator

private java.util.Iterator _bufferIterator

_confirmOverwrite

private boolean _confirmOverwrite

_ended

private boolean _ended

_file

private java.io.File _file

_fileDone

private boolean _fileDone

_fileRoot

private java.lang.String _fileRoot

_fileSuccess

private boolean _fileSuccess

_fileType

private int _fileType

_imageSourceStream

private MovieWriter.ImageSourceStream[] _imageSourceStream

_jmfImageToken

private JMFImageToken _jmfImageToken

_stateTransitionOK

private boolean _stateTransitionOK

_videoFormat

private javax.media.format.VideoFormat _videoFormat

_waitFileSync

private java.lang.Object _waitFileSync

_waitSync

private java.lang.Object _waitSync

_AVI

private static final int _AVI
See Also:
Constant Field Values

_MPEG

private static final int _MPEG
See Also:
Constant Field Values

_QUICKTIME

private static final int _QUICKTIME
See Also:
Constant Field Values
Constructor Detail

MovieWriter

public MovieWriter(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 processor.

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

dataSinkUpdate

public void dataSinkUpdate(javax.media.datasink.DataSinkEvent event)
The data sink listener. This method controls the closing of the data sink. It closes the data sink when it detects that the stream has ended.

Specified by:
dataSinkUpdate in interface javax.media.datasink.DataSinkListener
Parameters:
event - The controller event.

initialize

public void initialize()
                throws IllegalActionException
Initialize this actor. Create a new ArrayList to store the Buffers that the incoming JMFImageTokens contain.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If a contained method throws it.

postfire

public boolean postfire()
                 throws IllegalActionException
Fire this actor. Accept JMFImageTokens, and queue them up for saving.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
true
Throws:
IllegalActionException - If a contained method throws it, or if the buffer of the incoming JMFImageToken cannot be added to the queue.

wrapup

public void wrapup()
            throws IllegalActionException
Save the file.

Specified by:
wrapup in interface Initializable
Overrides:
wrapup in class AtomicActor
Throws:
IllegalActionException - If a contained method throws it.

_waitForFileDone

protected boolean _waitForFileDone()
                            throws IllegalActionException
Wait for the file to be written.

Returns:
true if the file was successfully written.
Throws:
IllegalActionException - If there is a problem blocking the processor until the state transition is completed.

_waitForState

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

Parameters:
processor - The processor .
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.