} else {
Image image = _jmfImageToken.asAWTImage();
int width = image.getWidth(null);
int height = image.getHeight(null);
ImageDataSource imageDataSource = new ImageDataSource(width, height);
Processor processor;
try {
processor = Manager.createProcessor(imageDataSource);
} catch (Exception ex) {
throw new IllegalActionException(this, ex,
"Can't create processor");
}
processor.addControllerListener(this);
processor.configure();
if (!_waitForState(processor, Processor.Configured)) {
throw new IllegalActionException(
"Failed to configure processor.");
}
if (_fileType == _QUICKTIME) {
processor.setContentDescriptor(new ContentDescriptor(
FileTypeDescriptor.QUICKTIME));
} else if (_fileType == _AVI) {
processor.setContentDescriptor(new ContentDescriptor(
FileTypeDescriptor.MSVIDEO));
} else if (_fileType == _MPEG) {
processor.setContentDescriptor(new ContentDescriptor(
FileTypeDescriptor.MPEG));
} else {
throw new InternalErrorException("type = " + _fileType
+ ", which is not one of " + _QUICKTIME
+ "(QUICKTIME), " + _AVI + "(AVI) or " + _MPEG
+ "(MPEG).");
}
TrackControl[] trackControl = processor.getTrackControls();
Format[] format = trackControl[0].getSupportedFormats();
if ((format == null) || (format.length <= 0)) {
throw new IllegalActionException("Cannot support input format");
}
trackControl[0].setFormat(format[0]);
processor.realize();
if (!_waitForState(processor, Controller.Realized)) {
throw new IllegalActionException("Failed to realize processor");
}
DataSource dataSource = processor.getDataOutput();
if (dataSource == null) {
throw new IllegalActionException("Processor does not have "
+ "output DataSource");
}
if (_debugging) {
_debug(_fileRoot);
}
DataSink dataSink;
try {
dataSink = Manager.createDataSink(dataSource, mediaLocator);
dataSink.open();
} catch (Exception ex) {
throw new IllegalActionException(this, ex,
"Couldn't create the data sink");
}
dataSink.addDataSinkListener(this);
try {
processor.start();
dataSink.start();
} catch (IOException ex) {
throw new IllegalActionException(this, ex,
"Could not start processor and datasink");
}
if (!_waitForFileDone()) {
throw new IllegalActionException("Could not write the file");
}
try {
dataSink.close();
} catch (Exception ex) {
throw new IllegalActionException(this, ex,
"can't close data sink");
}
processor.stop();
processor.removeControllerListener(this);
dataSink.removeDataSinkListener(this);
processor.close();
dataSink.close();
}
}