Class AacDecoder


  • public class AacDecoder
    extends com.sedmelluq.lava.common.natives.NativeResourceHolder
    A wrapper around the native methods of AacDecoder, which uses fdk-aac native library. Supports data with no transport layer. The only AAC type verified to work with this is AAC_LC.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  AacDecoder.StreamInfo
      AAC stream information.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int AAC_LC  
      static int PS  
      static int SBR  
    • Constructor Summary

      Constructors 
      Constructor Description
      AacDecoder()
      Create a new decoder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int configure​(byte[] config)
      Configure the decoder.
      int configure​(int objectType, int frequency, int channels)
      Configure the decoder.
      boolean decode​(java.nio.ShortBuffer buffer, boolean flush)
      Decode a frame of audio into the given buffer.
      int fill​(java.nio.ByteBuffer buffer)
      Fill the internal decoding buffer with the bytes from the buffer.
      protected void freeResources()  
      AacDecoder.StreamInfo resolveStreamInfo()  
      • Methods inherited from class com.sedmelluq.lava.common.natives.NativeResourceHolder

        checkNotReleased, close, finalize
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AacDecoder

        public AacDecoder()
        Create a new decoder.
    • Method Detail

      • configure

        public int configure​(int objectType,
                             int frequency,
                             int channels)
        Configure the decoder. Must be called before the first decoding.
        Parameters:
        objectType - Audio object type as defined for Audio Specific Config: https://wiki.multimedia.cx/index.php?title=MPEG-4_Audio
        frequency - Frequency of samples in Hz
        channels - Number of channels.
        Throws:
        java.lang.IllegalStateException - If the decoder has already been closed.
      • configure

        public int configure​(byte[] config)
        Configure the decoder. Must be called before the first decoding.
        Parameters:
        config - Raw ASC format configuration
        Throws:
        java.lang.IllegalStateException - If the decoder has already been closed.
      • fill

        public int fill​(java.nio.ByteBuffer buffer)
        Fill the internal decoding buffer with the bytes from the buffer. May consume less bytes than the buffer provides.
        Parameters:
        buffer - DirectBuffer which contains the bytes to be added. Position and limit are respected and position is updated as a result of this operation.
        Returns:
        The number of bytes consumed from the provided buffer.
        Throws:
        java.lang.IllegalArgumentException - If the buffer is not a DirectBuffer.
        java.lang.IllegalStateException - If the decoder has already been closed.
      • decode

        public boolean decode​(java.nio.ShortBuffer buffer,
                              boolean flush)
        Decode a frame of audio into the given buffer.
        Parameters:
        buffer - DirectBuffer of signed PCM samples where the decoded frame will be stored. The buffer size must be at least of size frameSize * channels * 2. Buffer position and limit are ignored and not updated.
        flush - Whether all the buffered data should be flushed, set to true if no more input is expected.
        Returns:
        True if the frame buffer was filled, false if there was not enough input for decoding a full frame.
        Throws:
        java.lang.IllegalArgumentException - If the buffer is not a DirectBuffer.
        java.lang.IllegalStateException - If the decoding library returns an error other than running out of input data.
        java.lang.IllegalStateException - If the decoder has already been closed.
      • resolveStreamInfo

        public AacDecoder.StreamInfo resolveStreamInfo()
        Returns:
        Correct stream info. The values passed to configure method do not account for SBR and PS and detecting these is a part of the decoding process. If there was not enough input for decoding a full frame, null is returned.
        Throws:
        java.lang.IllegalStateException - If the decoder result produced an unexpected error.
      • freeResources

        protected void freeResources()
        Specified by:
        freeResources in class com.sedmelluq.lava.common.natives.NativeResourceHolder