FileDocCategorySizeDatePackage
JavaDecoder.javaAPI DocFobs4JMF API 0.4.18925Wed Jan 10 11:08:22 GMT 2007com.omnividea.media.codec.audio

JavaDecoder

public class JavaDecoder extends AudioCodec

Title:

Description:

Copyright: Copyright (c) 2004

Company:

author
not attributable
version
1.0

Fields Summary
private int
peer
private boolean
outputDone
private static final boolean
DEBUG
private static boolean
bigEndian
Constructors Summary
public JavaDecoder()


  ////////////////////////////////////////////////////////////////////////////
  // Variables

   
    try {
      //System.loadLibrary("fobs4jmf");
      NativeLibraryFinder.loadLibrary(JavaDecoder.class, "fobs4jmf");
      System.out.println("Fobs4JMF - Native shared library found");
      bigEndian = isBigEndian();

      if(bigEndian == false)
      {
        System.out.println("Little Endian");
      }
      else
      {
          System.out.println("Big Endian");
      }

    }
    catch (UnsatisfiedLinkError e) {
      System.out.println("Fobs4JMF - Native shared library NOT found");
      e.printStackTrace();
      throw new ExceptionInInitializerError(e.getMessage());
    }
  
    System.out.println("AVCODEC: Constructor");
    supportedInputFormats = new AudioFormat[] {
        new AudioFormat("twos"), 
        new AudioFormat("raw "), 
        new AudioFormat("ulaw"), 
        new AudioFormat("alaw"), 
        new AudioFormat("ima4"), 
        new AudioFormat("MAC3"), 
        new AudioFormat("MAC6"), 
        new AudioFormat(".mp3"), 
        new AudioFormat("mp4a"), 
        new AudioFormat("samr"), 
        new AudioFormat("sawb"), 
        new AudioFormat("alac")
    };
    defaultOutputFormats = new AudioFormat[] {
        new WavAudioFormat("")};
    PLUGIN_NAME = "Fobs Audio Decoder";

  
Methods Summary
public booleancheckFormat(javax.media.Format format)


        return super.checkFormat(format);
    
public voidclose()

      System.out.println("AVCODEC: close");
      close_codec( peer );
    
private native booleanclose_codec(int peer)

private native booleanconvert(int peer, java.lang.Object inData, long inDataBytes, int inOffset, java.lang.Object outData, long outDataBytes, long length, double dts)

booleandecodeData(javax.media.Buffer inputBuffer, javax.media.Buffer outputBuffer)


        int outMaxLength=131072;//outputFormat.getMaxDataLength();
        int inputLength = inputBuffer.getLength();
        //byte [] outData = (byte [])validateByteArraySize(outputBuffer,outMaxLength );//outputBuffer.getData();
        int [] outData = (int [])validateIntArraySize(outputBuffer,outMaxLength );
        long outDataBytes = getNativeData(outData);
        byte[] inputData = (byte [])inputBuffer.getData();
        long inDataBytes = getNativeData(inputData);


        if (inputLength <= 0) {
            return false;
        }

        boolean res = convert(peer, inputData, inDataBytes, inputBuffer.getOffset(), outData, outDataBytes, inputLength, inputBuffer.getTimeStamp()/1000000000.0);
        int size = lastAudioSize(peer);
        outputBuffer.setLength(size);
        return res;
    
public voidfinalize()

        close();
    
protected javax.media.Format[]getMatchingOutputFormats(javax.media.Format in)

    System.out.println("AVCODEC: getMatchingOutputFormats");

       if (in == null)
           return new Format[] { new AudioFormat(AudioFormat.LINEAR) };

       AudioFormat af =(AudioFormat) in;

       supportedOutputFormats = new AudioFormat[] {
           new WavAudioFormat(AudioFormat.LINEAR,
                              af.getSampleRate(),
                              af.getSampleSizeInBits(),
                              af.getChannels(),
                              af.getFrameSizeInBits(),
                              (int)(af.getFrameSizeInBits() * af.getSampleRate()/8.0),
                              af.getEndian(),
                              af.getSigned(),
                              (float)af.getFrameRate(), // No FRAME_RATE specified
                              af.getDataType(),
                              new byte[0])
       };

    
    return supportedOutputFormats;
  
private native voidinit()

private native voidinit_decoding(int peer, int width, int height)

private static native booleanisBigEndian()

private native intlastAudioSize(int peer)

public voidopen()

      System.out.println("AVCODEC: open");
      init();
      if (peer == 0)
          throw new ResourceUnavailableException("Unable to initialize");


      if (inputFormat == null)
          throw new ResourceUnavailableException("No input format selected");

      if (outputFormat == null)
          throw new ResourceUnavailableException("No output format selected");

//      init_decoding(peer, videoWidth, videoHeight);

      if (!open_codec(peer, inputFormat.getEncoding()))
          throw new ResourceUnavailableException("Couldn't open codec for " + inputFormat.toString());
    
private native booleanopen_codec(int peer, java.lang.String codec)

public intprocess(javax.media.Buffer inputBuffer, javax.media.Buffer outputBuffer)


      if (!checkInputBuffer(inputBuffer) ) {
         return BUFFER_PROCESSED_FAILED;
      }

      if (isEOM(inputBuffer) ) {
         propagateEOM(outputBuffer);
         return BUFFER_PROCESSED_OK;
      }

      int outMaxLength=131072;//outputFormat.getMaxDataLength();
      Object outDataTmp = getOutputData(outputBuffer);


      if ( outDataTmp == null || outputBuffer.getFormat() != outputFormat ||
           !outputBuffer.getFormat().equals(outputFormat) ) {
        outputBuffer.setLength(outMaxLength);
        outputBuffer.setFormat(outputFormat);
      }

      outDataTmp = validateData(outputBuffer, 0, true);
      boolean ret = decodeData(inputBuffer,outputBuffer);

      if (ret) {
           updateOutput(outputBuffer,outputFormat, outMaxLength, 0);
           return BUFFER_PROCESSED_OK;
       }
       else {
         if (DEBUG)
           System.out.println("[JavaDecoder] : returning OUTPUT_BUFFER_NOT_FILLED; ");
         return OUTPUT_BUFFER_NOT_FILLED;
       }


    
public voidreset()

      System.out.println("AVCODEC: reset");
      try {
          close();
          open();
      }
      catch(Exception e) {
          e.printStackTrace();
      }

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

return
false if the format is not supported.

    System.out.println("AVCODEC: setInputFormat");
      if (super.setInputFormat(format) != null) {

        AudioFormat af =(AudioFormat)format;

        outputFormat =            new WavAudioFormat(AudioFormat.LINEAR,
                              af.getSampleRate(),
                              af.getSampleSizeInBits(),
                              af.getChannels(),
                              af.getFrameSizeInBits(),
                              (int)(af.getFrameSizeInBits() * af.getSampleRate()/8.0),
                              af.getEndian(),
                              af.getSigned(),
                              (float)af.getFrameRate(), // No FRAME_RATE specified
                              af.getDataType(),
                              new byte[0]);

        return format;
    }
    else
      return null;