FileDocCategorySizeDatePackage
ACMCodec.javaAPI DocJMF 2.1.1e9515Mon May 12 12:21:22 BST 2003com.ibm.media.codec.audio

ACMCodec

public class ACMCodec extends Object implements Codec, DynamicPlugIn

Fields Summary
private Vector
supportedInputFormats
Holds the supported input formats
private Vector
supportedOutputFormats
Holds the supported output formats
private AudioFormat[]
inputFormats
The actual input formats array to be returned
private AudioFormat[]
outputFormats
The actual output formats array to be returned
private AudioFormat
inputFormat
The input format for the codec
private AudioFormat
outputFormat
The output format for the codec
private long
nativeHandle
This hold the native handle for this instance's ACM codec
Constructors Summary
Methods Summary
private native booleanACMProcess(long nativeHandle, byte[] input, int inputOffset, int inputLength, javax.media.Buffer inputBuffer, byte[] output, int outputLength, javax.media.Buffer outputBuffer)
Does the ACM codec processing

param
nativeHandle the native handle of the ACM codec
param
input the input data
param
inputLength the length of the input data
param
inputBuffer the input Buffer object, passed for offset update
param
output the output data
param
outputLength the length of the output data
param
outputBuffer the output Buffer object, passed for length update
return
false if an error has occur

public voidclose()
Closes the plug-in component and releases resources. No more data will be accepted by the plug-in after a call to this method. The plug-in can be reinstated after being closed by calling open.


    closeACMStream(nativeHandle);
  
private native voidcloseACMStream(long nativeHandle)
Closes the ACM stream used for transcoding.

param
nativeHandle the native handle of the ACM codec

private native voidfillSupportedInputFormats()
Fills the supportedInputFormat Vector with the ACM supported input formats.

private native voidfillSupportedOutputFormats(javax.media.format.AudioFormat input)
Fills the supportedOutputFormat Vector with the ACM supported output formats.

public javax.media.Format[]getBaseInputFormats()
An array of format objects that cover the generic input formats that this plugin supports. For example, a VideoRenderer may not know the exact RGBFormat it supports, so it returns a dummy RGBFormat with mostly unspecified values.

    
    Format[] formats = new Format[1];
    formats[0] = new AudioFormat(null);

    return formats;
  
public javax.media.Format[]getBaseOutputFormats()
An array of format objects that cover the generic output formats that this plugin supports. For example, a Codec may not know the exact output RGBFormat it supports, so it returns a dummy RGBFormat with mostly unspecified values.

    
    return getBaseInputFormats();
  
public java.lang.ObjectgetControl(java.lang.String controlType)
Obtain the object that implements the specified Class or Interface The full class or interface name must be used.

If the control is not supported then null is returned.

return
the object that implements the control, or null.

    // no controls implemented
    return null;
  
public java.lang.Object[]getControls()
Obtain the collection of objects that control the object that implements this interface.

If no controls are supported, a zero length array is returned.

return
the collection of object controls


   
    com.sun.media.JMFSecurityManager.loadLibrary("jmacm");
  
    // no controls implemented
    return new Control[0];
  
private native intgetDestinationBufferSize(long nativeHandle, int input)
Gets the estimated size of the destination data.

param
nativeHandle the native handle of the ACM codec
param
inputSize the size of the input data
return
the size of the destination data

public java.lang.StringgetName()
Returns a descriptive name for the plug-in. This is a user readable string.

    return "ACM Wrapper Codec";
  
public javax.media.Format[]getSupportedInputFormats()
Lists the possible input formats supported by this plug-in.

    if (inputFormats != null) 
      return inputFormats;
    else {
      supportedInputFormats = new Vector();
      fillSupportedInputFormats();
      int size = supportedInputFormats.size();
      inputFormats = new AudioFormat[size];
      for (int index = 0; index < size; index++) {
	inputFormats[index] = (AudioFormat)supportedInputFormats.elementAt(index);
      }
      return inputFormats;
    }
  
public javax.media.Format[]getSupportedOutputFormats(javax.media.Format input)
Lists the possible output formats of the processed data. If input is non-null, then it lists the possible output formats given that the input buffer is of the format specified by input. If input is null, then it lists all possible output formats that this plug-in advertises.


    if (input == null) {
      outputFormats= new AudioFormat[1];
      outputFormats[0] = new AudioFormat(null);
      return outputFormats;
    }
    if (!(input instanceof AudioFormat)) {
      outputFormats = new AudioFormat[0];
      return outputFormats;
    }
    else {
      /* fillSuppotedFormats(input) is called since each call to 
	 getSupportedOutputFoprmats(input) can have a different 
	 parameter and we wouldn't like to hold all supported formats
	 for all input possibilites ahead (will be a huge overhead */
      
      supportedOutputFormats = new Vector(); 
      fillSupportedOutputFormats((AudioFormat)input);
      int size = supportedOutputFormats.size();
      outputFormats = new AudioFormat[size];

      for (int index = 0; index < size; index++) 
	outputFormats[index] = (AudioFormat)supportedOutputFormats.elementAt(index);

      return outputFormats;
    }
  
public voidopen()
Opens the plug-in software or hardware component and acquires necessary resources. If all the needed resources could not be acquired, it throws a ResourceUnavailableException. Buffer should not be passed into the plug-in without first calling this method.


    nativeHandle = openACMStream(inputFormat, outputFormat);
    if (nativeHandle == 0)
      throw new ResourceUnavailableException("ACM stream coun't been opened");
  
private native longopenACMStream(javax.media.format.AudioFormat inputFormat, javax.media.format.AudioFormat outputFormat)
Opens an ACM stream to be used for transcoding

param
inputFormat the input format for this codec
param
outputFormat the ourpur format for this codec
return
the native handle of the ACM codec or 0 if codec couldn't be open

public intprocess(javax.media.Buffer input, javax.media.Buffer output)
Process the media

return
BUFFER_PROCESSED_OK if the processing is successful. Other possible return codes are defined in PlugIn.
see
PlugIn


    // shouldn't it be done in the module ?
    if (input.isEOM()) {
      output.setLength(0) ;
      output.setEOM(true);
      return BUFFER_PROCESSED_OK;
    }

    int oldInputOffset = input.getOffset();
    // preper destination data
    int destLength = getDestinationBufferSize(nativeHandle, input.getLength());
    if (output.getData() == null || 
	destLength > ((byte[])output.getData()).length) {
      byte[] destination = new byte[destLength];
      output.setData(destination);
    }
    output.setLength(destLength);
    output.setOffset(0);
    output.setFormat(outputFormat);

    if (!ACMProcess(nativeHandle, (byte[])input.getData(), input.getOffset(), 
		    input.getLength(), input, (byte[])output.getData(), 
		    output.getLength(), output)) 
      return BUFFER_PROCESSED_FAILED;

    if (oldInputOffset != input.getOffset()) 
      return BUFFER_PROCESSED_OK | INPUT_BUFFER_NOT_CONSUMED;
    else 
      return BUFFER_PROCESSED_OK;
  
public voidreset()
Resets the state of the plug-in. Typically at end of media or when media is repositioned.

    resetACMStream(nativeHandle);
  
private native voidresetACMStream(long nativeHandle)
Resets the ACM stream.

param
nativeHandle the native handle of the ACM codec

public javax.media.FormatsetInputFormat(javax.media.Format format)
Set the buffer input format.

return
false if the format is not supported.


      if (!(format instanceof AudioFormat)) {
	  return null;
      }
      inputFormat = (AudioFormat)format;

      return format;
  
public javax.media.FormatsetOutputFormat(javax.media.Format format)
Set the buffer output format.

return
false if the format is not supported.


    if (!(format instanceof AudioFormat)) 
      return null;
    outputFormat = (AudioFormat)format;
    
    return format;