-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea4819c
commit f55eefa
Showing
11 changed files
with
498 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,68 @@ | ||
package org.sheinbergon.aac.jna; | ||
|
||
import com.sun.jna.Native; | ||
import com.sun.jna.Pointer; | ||
import com.sun.jna.ptr.IntByReference; | ||
import com.sun.jna.ptr.PointerByReference; | ||
import com.sun.jna.ptr.ShortByReference; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.Accessors; | ||
import org.sheinbergon.aac.jna.structure.AACEncBufDesc; | ||
import org.sheinbergon.aac.jna.structure.AACEncInArgs; | ||
import org.sheinbergon.aac.jna.structure.AACEncInfo; | ||
import org.sheinbergon.aac.jna.structure.AACEncOutArgs; | ||
import org.sheinbergon.aac.jna.structure.AACEncoder; | ||
import org.sheinbergon.aac.jna.structure.*; | ||
|
||
@SuppressWarnings("MethodName") | ||
public final class FdkAACLib { | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@RequiredArgsConstructor | ||
enum Functions { | ||
INFO("aacEncInfo"), | ||
SET_PARAM("aacEncoder_SetParam"), | ||
OPEN("accEncOpen"), | ||
CLOSE("accEncClose"), | ||
ENCODE("aacEncEncode"); | ||
@Getter | ||
@Accessors(fluent = true) | ||
@RequiredArgsConstructor | ||
enum Functions { | ||
ENCODER_INFO("aacEncInfo"), | ||
ENCODER_SET_PARAM("aacEncoder_SetParam"), | ||
ENCODER_OPEN("accEncOpen"), | ||
ENCODER_CLOSE("accEncClose"), | ||
ENCODER_ENCODE("aacEncEncode"); | ||
|
||
private final String libraryFunctionName; | ||
} | ||
private final String libraryFunctionName; | ||
} | ||
|
||
private static final String FDK_AAC = "fdk-aac"; | ||
private static final String FDK_AAC = "fdk-aac"; | ||
|
||
static { | ||
Native.register(FDK_AAC); | ||
} | ||
static { | ||
Native.register(FDK_AAC); | ||
} | ||
|
||
static native int aacEncOpen(PointerByReference handle, int encModules, int maxChannels); | ||
static native int aacEncOpen(PointerByReference handle, int encModules, int maxChannels); | ||
|
||
static native int aacEncClose(PointerByReference handle); | ||
static native int aacEncClose(PointerByReference handle); | ||
|
||
static native int aacEncEncode( | ||
AACEncoder hAacEncoder, | ||
AACEncBufDesc inBufDesc, | ||
AACEncBufDesc outBufDesc, | ||
AACEncInArgs inargs, | ||
AACEncOutArgs outargs); | ||
static native int aacEncEncode( | ||
AACEncoder hAacEncoder, | ||
AACEncBufDesc inBufDesc, | ||
AACEncBufDesc outBufDesc, | ||
AACEncInArgs inargs, | ||
AACEncOutArgs outargs); | ||
|
||
static native int aacEncInfo(AACEncoder hAacEncoder, AACEncInfo pInfo); | ||
static native int aacEncInfo(AACEncoder hAacEncoder, AACEncInfo pInfo); | ||
|
||
static native int aacEncoder_SetParam(AACEncoder encoder, int param, int value); | ||
static native int aacEncoder_SetParam(AACEncoder encoder, int param, int value); | ||
|
||
private FdkAACLib() { | ||
} | ||
static native Pointer aacDecoder_Open(int transportFmt, int nrOfLayers); | ||
|
||
static native void aacDecoder_Close(AACDecoder self); | ||
|
||
static native int aacDecoder_Fill( | ||
AACDecoder self, | ||
Pointer[] Buffer, | ||
int[] bufferSize, | ||
IntByReference bytesValid); | ||
|
||
static native int aacDecoder_DecodeFrame( | ||
AACDecoder self, | ||
ShortByReference pTimeData, | ||
int timeDataSize, | ||
int flags); | ||
|
||
private FdkAACLib() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
src/main/java/org/sheinbergon/aac/jna/structure/AACDecoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package org.sheinbergon.aac.jna.structure; | ||
|
||
import com.sun.jna.Pointer; | ||
import com.sun.jna.Structure; | ||
import com.sun.jna.ptr.ByteByReference; | ||
import com.sun.jna.ptr.PointerByReference; | ||
import org.sheinbergon.aac.jna.util.JNASupport; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.List; | ||
|
||
/** | ||
* Maps to AAC_DECODER_INSTANCE struct. | ||
* | ||
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACdec/src/aacdecoder.h">fdk-aac/libAACdec/src/aacdecoder.h</a> | ||
*/ | ||
@SuppressWarnings({ | ||
"JavadocVariable", | ||
"VisibilityModifier", | ||
"MissingJavadocMethod", | ||
"MagicNumber", | ||
"MemberName", | ||
"PointlessArithmeticExpression", | ||
"unused"}) | ||
public final class AACDecoder extends Structure { | ||
|
||
private static final int AACDEC_MAX_NUM_PREROLL_AU = 3; | ||
private static final List<String> FIELD_ORDER = JNASupport.structureFieldOrder(AACDecoder.class); | ||
|
||
public static AACDecoder of(final @Nonnull PointerByReference pointerReference) { | ||
return new AACDecoder(pointerReference.getValue()); | ||
} | ||
|
||
private AACDecoder(final @Nonnull Pointer pointer) { | ||
super(pointer); | ||
setAlignType(Structure.ALIGN_NONE); // Make sure field size alignments are as expected | ||
read(); // Read once after initialize from provided pointer | ||
} | ||
|
||
public int aacChannels; | ||
public int[] ascChannels = new int[1]; | ||
public int blockNumber; | ||
public int nrOfLayers; | ||
public int outputInterleaved; | ||
public int aacOutDataHeadroom; | ||
public Pointer hInput; | ||
public AACDecoderSamplingRateInfo[] samplingRateInfo = new AACDecoderSamplingRateInfo[1]; | ||
public byte frameOK; | ||
public int[] flags = new int[1]; | ||
public int[] elFlags = new int[(3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1)]; | ||
|
||
public int[] elements = new int[(3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1)]; | ||
|
||
public byte[] elTags = new byte[(3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1)]; | ||
public byte[] chMapping = new byte[((8) * 2)]; | ||
public int[] channelType = new int[(8)]; | ||
public byte[] channelIndices = new byte[(8)]; | ||
public FDKChannelMapDescription mapDescr; | ||
public byte chMapIndex; | ||
public int sbrDataLen; | ||
public DecoderCProgramConfig pce; | ||
CStreamInfo | ||
streamInfo; /*!< Pointer to StreamInfo data (read from the bitstream) */ | ||
CAacDecoderChannelInfo | ||
*pAacDecoderChannelInfo[(8)]; /*!< Temporal channel memory */ | ||
CAacDecoderStaticChannelInfo | ||
*pAacDecoderStaticChannelInfo[(8)]; /*!< Persistent channel memory */ | ||
|
||
public Pointer workBufferCore1; | ||
public Pointer workBufferCore2; | ||
public Pointer pTimeData2; | ||
public int timeData2Size; | ||
|
||
CpePersistentData *cpeStaticData[( | ||
3*((8)*2)+(((8)*2))/2+4*(1)+ | ||
1)]; /*!< Pointer to persistent data shared by both channels of a CPE. | ||
This structure is allocated once for each CPE. */ | ||
|
||
CConcealParams concealCommonData; | ||
CConcealmentMethod concealMethodUser; | ||
|
||
CUsacCoreExtensions usacCoreExt; /*!< Data and handles to extend USAC FD/LPD | ||
core decoder (SBR, MPS, ...) */ | ||
public int[] numUsacElements = new int[(1 * 1)]; | ||
public byte[] usacStereoConfigIndex = new byte[(3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1)]; | ||
public Pointer[] pUsacConfig = new Pointer[(1 * 1)]; | ||
public int nbDiv; | ||
public byte useLdQmfTimeAlign; | ||
public int aacChannelsPrev; | ||
public int[] channelTypePrev = new int[(8)]; | ||
public byte[] channelIndicesPrev = new byte[(8)]; | ||
public byte downscaleFactor; | ||
public byte downscaleFactorInBS; | ||
public Pointer hSbrDecoder; | ||
public byte sbrEnabled; | ||
public byte sbrEnabledPrev; | ||
public byte psPossible; | ||
public AACDecoderSBRParams sbrParams; | ||
public ByteByReference pDrmBsBuffer; | ||
public short drmBsBufferSize; | ||
FDK_QMF_DOMAIN | ||
qmfDomain; /*!< Instance of module for QMF domain data handling */ | ||
public int qmfModeCurr; | ||
public int qmfModeUser; | ||
public Pointer hDrcInfo; | ||
public int metadataExpiry; | ||
public Pointer pMpegSurroundDecoder; | ||
public byte mpsEnableUser; | ||
public byte mpsEnableCurr; | ||
public byte mpsApplicable; | ||
public byte mpsOutputMode; | ||
public int mpsOutChannelsLast; | ||
public int mpsFrameSizeLast; | ||
public AACDecoderCAncData ancData; | ||
public Pointer hPcmUtils; | ||
public Pointer hLimiter; | ||
public byte limiterEnableUser; | ||
public byte limiterEnableCurr; | ||
// TODO - This might need to use smarter size of types, as signed long is 32BIT in windows platforms | ||
public long[] extGain = new long[1]; | ||
public int extGainDelay; | ||
public Pointer hUniDrcDecoder; | ||
public byte multibandDrcPresent; | ||
public byte numTimeSlots; | ||
public int[] loudnessInfoSetPosition = new int[3]; | ||
public byte defaultTargetLoudness; | ||
public Pointer[] pTimeDataFlush = new Pointer[((8) * 2)]; | ||
public byte flushStatus; | ||
public byte flushCnt; | ||
public byte buildUpStatus; | ||
public byte buildUpCnt; | ||
public byte hasAudioPreRoll; | ||
public int[] prerollAULength = new int[AACDEC_MAX_NUM_PREROLL_AU + 1]; | ||
public int accessUnit; | ||
public byte applyCrossfade; | ||
public AACDecoderFDKSignalDelay usacResidualDelay; | ||
|
||
@Override | ||
protected List<String> getFieldOrder() { | ||
return FIELD_ORDER; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/sheinbergon/aac/jna/structure/AACDecoderCAncData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.sheinbergon.aac.jna.structure; | ||
|
||
import com.sun.jna.Pointer; | ||
import com.sun.jna.Structure; | ||
import org.sheinbergon.aac.jna.util.JNASupport; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Maps to CAncData struct. | ||
* | ||
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACdec/src/aacdecoder.h">fdk-aac/libAACdec/src/aacdecoder.h</a> | ||
*/ | ||
@SuppressWarnings("MagicNumber") | ||
public class AACDecoderCAncData extends Structure { | ||
|
||
private static final List<String> FIELD_ORDER = JNASupport.structureFieldOrder(AACDecoderCAncData.class); | ||
|
||
public Pointer buffer; | ||
public int bufferSize; | ||
public int[] offset = new int[8]; | ||
public int nrElements; | ||
|
||
protected List<String> getFieldOrder() { | ||
return FIELD_ORDER; | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
src/main/java/org/sheinbergon/aac/jna/structure/AACDecoderFDKSignalDelay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.sheinbergon.aac.jna.structure; | ||
|
||
import com.sun.jna.Pointer; | ||
import com.sun.jna.Structure; | ||
import org.sheinbergon.aac.jna.util.JNASupport; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Maps to FDK_SignalDelay struct. | ||
* | ||
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACdec/src/FDK_delay.h">fdk-aac/libAACdec/src/FDK_delay.h</a> | ||
*/ | ||
@SuppressWarnings({"JavadocVariable", "VisibilityModifier"}) | ||
public class AACDecoderFDKSignalDelay extends Structure { | ||
|
||
private static final List<String> FIELD_ORDER = JNASupport.structureFieldOrder(AACDecoderFDKSignalDelay.class); | ||
public Pointer delay_line; | ||
public short delay; | ||
public byte num_channels; | ||
|
||
@Override | ||
protected List<String> getFieldOrder() { | ||
return FIELD_ORDER; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/sheinbergon/aac/jna/structure/AACDecoderSBRParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.sheinbergon.aac.jna.structure; | ||
|
||
import com.sun.jna.Structure; | ||
import com.sun.jna.ptr.ShortByReference; | ||
import org.sheinbergon.aac.jna.util.JNASupport; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Maps to SamplingRateInfo struct. | ||
* | ||
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACdec/src/aacdecoder.h">fdk-aac/libAACdec/src/aacdecoder.h</a> | ||
*/ | ||
@SuppressWarnings({"JavadocVariable", "VisibilityModifier"}) | ||
public class AACDecoderSBRParams extends Structure { | ||
|
||
private static final List<String> FIELD_ORDER = JNASupport.structureFieldOrder(AACDecoderSBRParams.class); | ||
public int nsDelay; | ||
|
||
@Override | ||
protected List<String> getFieldOrder() { | ||
return FIELD_ORDER; | ||
} | ||
} |
Oops, something went wrong.