| CONTENTS | PREV | NEXT | INDEX | JMF 2.0 API Guide |
A
Processorcan be used as a programmablePlayerthat enables you to control the decoding and rendering process. AProcessorcan also be used as a capture processor that enables you to control the encoding and multiplexing of the captured media data.You can control what processing is performed by a
Processorseveral different ways:
- Use a
ProcessorModelto construct aProcessorthat has certain input and output characteristics.- Use the
TrackControlsetFormatmethod to specify what format conversions are performed on individual tracks.- Use the
ProcessorsetOutputContentDescriptormethod to specify the multiplexed data format of theProcessorobject's output.- Use the
TrackControlsetCodecChainmethod to select theEffectorCodecplug-ins that are used by theProcessor.- Use the
TrackControlsetRenderermethod to select theRendererplug-in used by theProcessor.Note: Some high-performance or light-weight
Processorimplementations might choose not to support the selection of processing options so that they can provide a highly-optimized JMF presentation solution. The reference implementation of JMF 2.0 provided by Sun Microsystems, Inc. and IBM Corporation fully supports the selection of processing options throughTrackControlobjects andsetOutputContentDescriptor.In addition to the Realizing and Prefetching phases that any
Playermoves through as it prepares to start, aProcessoralso goes through a Configuring phase. You callconfigureto move an UnrealizedProcessorinto the Configuring state.While in the Configuring state, a
Processorgathers the information it needs to constructTrackControlobjects for each track. When it's finished, it moves into the Configured state and posts aConfigureCompleteEvent. Once aProcessoris Configured, you can set its output format andTrackControloptions. When you're finished specifying the processing options, you callrealizeto move theProcessorinto the Realizing state and begin the realization process.Once a
Processoris Realized, further attempts to modify its processing options are not guaranteed to work. In most cases, aFormatChangeExceptionwill be thrown.Selecting Track Processing Options
To select which plug-ins are used to process each track in the media stream, you:
- Call the
PlugInManager.getPlugInListmethod to determine what plug-ins are available. ThePlugInManagerreturns a list of plug-ins that match the specified input and output formats and plug-in type.- Call
getTrackControlson theProcessorto get aTrackControlfor each track in the media stream. TheProcessormust in the Configured state before you callgetTrackControls.- Call the
TrackControlsetCodecChainorsetRenderermethods to specify the plug-ins that you want to use for each track.When you use
setCodecChainto specify the codec and effect plug-ins for aProcessor, the order in which the plug-ins actually appear in the processing chain is determined by the input and output formats each plug-in supports.To control the transcoding that's performed on a track by a particular
Codec, you can use the codec controls associated with the track. To get the codec controls, you call theTrackControlgetControlsmethod. This returns all of theControlsassociated with the track, including codec controls such asH263Control,QualityControl, andMPEGAudioControl. (For a list of the codec controls defined by JMF, see Standard Controls.)Converting Media Data from One Format to Another
You can select the format for a particular track through the
TrackControlfor that track:
- Call
getTrackControlson theProcessorto get aTrackControlfor each track in the media stream. TheProcessormust be in the Configured state before you callgetTrackControls.- Use the
TrackControlsetFormatmethod to specify the format to which you want to convert the selected track.Specifying the Output Data Format
You can use the
ProcessorsetContentDescriptormethod to specify the format of the data output by theProcessor. You can get a list of supported data formats by callinggetSupportedContentDescriptors.You can also select the output format that you want by using a
ProcessorModelto create theProcessor. (See Using a ProcessorModel to Create a Processor for more information.)Specifying an output data format automatically selects the default processing options for this format, overriding the previous processing options selected through the
TrackControls. Setting the output data format tonullcauses the media data to be rendered instead of output to theProcessorobject's outputDataSource.Specifying the Media Destination
You can specify a destination for the media stream by selecting a particular
Rendererfor a track through itsTrackControl, or by using the output from aProcessoras the input to a particularDataSink. You can also use theProcessoroutput as the input to anotherPlayerorProcessorthat has a different destination.Selecting a Renderer
To select the
Rendererthat you want to use, you:
- Call
getTrackControlson theProcessorto get aTrackControlfor each track in the media stream. TheProcessormust in the Configured state before you callgetTrackControls.- Call the
TrackControlsetRenderermethod to specify theRendererplug-in.Writing Media Data to a File
You can use a
DataSinkto read media data fromProcessorobject's outputDataSourceand render the data to a file.
- Get the output
DataSourcefrom theProcessorby callinggetDataOutput.- Construct a file writer
DataSinkby callingManager.createDataSink.Pass in the outputDataSourceand aMediaLocatorthat specifies the location of the file to which you want to write.- Call
openon theDataSinkto open the file.- Call
starton theDataSinkto begin writing data.The format of the data written to the specified file is controlled through the
Processor. By default, aProcessoroutputs raw data. To change the content type of aProcessorobject's outputDataSource, you use thesetContentDescriptormethod.
A
Processorcan enable user control over the maximum number of bytes that it can write to its destination by implementing theStreamWriterControl. You find out if aProcessorprovides aStreamWriterControlby callinggetControl("javax.media.datasink.StreamWriterControl")on theProcessor.Connecting a Processor to another Player
The output from a
Processorcan be used as the input to anotherPlayer. To get the output from aProcessor, you callgetDataOutput, which returns aDataSource. ThisDataSourcecan in turn be used to construct aPlayerorProcessorthrough theManager.Using JMF Plug-Ins as Stand-alone Processing Modules
JMF Plug-ins can also be used outside of the JMF framework. You can instantiate the plug-in directly and call its processing method to perform the processing operation.
You might want to do this to encode or decode a media stream, or convert a stream from one format to another.