Skip to content

Commit

Permalink
Version 2.0.2 adaptations
Browse files Browse the repository at this point in the history
Working on Linux
  • Loading branch information
sheinbergon committed Nov 23, 2023
1 parent 44bbbd8 commit c320bdb
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 45 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,24 @@ Artifacts are available on maven central:
<dependency>
<groupId>org.sheinbergon</groupId>
<artifactId>jna-aac-encoder</artifactId>
<version>0.1.9</version>
<version>2.0.0</version>
</dependency>
```

**_Gradle_**
```groovy
compile 'org.sheinbergon:jna-aac-encoder:0.1.9'
compile 'org.sheinbergon:jna-aac-encoder:2.0.0'
```

#### Additional information
* Single artifact containing _libfdk-aac_ shared libraries cross-compiled for:
* Linux (64-bit)
* Windows (32-bit and 64-bit)
* OSX (64-bit, compiled with Xcode 9.4.1 SDK)
* Windows (64-bit)
* OSX (Intel 64-bit, compiled with Xcode 9.4.1 SDK)

* Provided fdk-aac version is 0.1.6
* Both 0.1.5 and 0.1.6 versions were tested and found to comply with this bridge.
* Provided fdk-aac version is 2.0.2
* Lower `2.0.x` of FDK-AAC might work, but haven't been tested.
* For `0.1.6`/`0.1.5` FDK-AAC support and Windows 32 bit support, please use version `0.1.9` of this library

### Encoding using the JVM AudioSystem
```java
Expand All @@ -65,11 +66,11 @@ AudioSystem.write(input, AACFileTypes.AAC_LC, output);
## Performance
Performance benchmarks comparing JNA to a BINARY application(`aac-enc`) are available using [JMH](http://openjdk.java.net/projects/code-tools/jmh/) and [JMH Visualizer](https://github.com/jzillmann/jmh-visualizer):

![alt text](assets/jmh-results-22102022.png)
![alt text](assets/jmh-results-23112023.png)

To run the benchmarks locally:
* Clone this repository onto a Linux host
* Ensure that you have `libfdk-aac.so` __0.1.x__ library installed (either from an external repository or manually compiled)
* Ensure that you have `libfdk-aac.so` __2.0.2__ library installed (either from an external repository or manually compiled)
* Ensure that you have the `aac-enc` binary installed (either from an external repository or manually compiled)
* Run the following command (from within the cloned repository)
```groovy
Expand All @@ -96,7 +97,6 @@ Additional restrictions:
* Only the AAC-LC/HE-AAC/HE-AACv2 encoding profiles are supported

## Roadmap
* Upgrade to fdk-aac 2.0.x
* Improved lower-level interface (with examples).
* Support for 24 bit WAV input (via conversion).
* M4A encoding.
Expand Down
29 changes: 15 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ plugins {
id 'java-library'
id 'maven-publish'
id "io.morethan.jmhreport" version "0.9.0"
id 'com.github.kt3k.coveralls' version '2.12.0'
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
id 'com.github.kt3k.coveralls' version '2.12.2'
id "io.github.gradle-nexus.publish-plugin" version "1.3.0"
id 'io.franzbecker.gradle-lombok' version '5.0.0'
}

ext {
depVersions = [
lombok : '1.18.24',
lombok : '1.18.30',
jna : '5.12.1',
commonsLang3: '3.12.0',
commonsLang3: '3.14.0',
jsr305 : '3.0.2'
]
testDepVersions = [
junitPlatform: '1.9.1',
junit : '5.9.1'
junitPlatform: '1.10.1',
junit : '5.10.1'
]
benchmarkDepVersions = [
commonsIO: '2.11.0',
jmh : '1.35'
commonsIO: '2.15.0',
jmh : '1.37'
]
nexus = [
target : project.findProperty("nexus.target") ?: System.getenv("NEXUS_TARGET") ?: 'SNAPSHOT',
Expand All @@ -40,7 +40,7 @@ ext {
}

group 'org.sheinbergon'
version '0.1.9'
version '2.0.0'

repositories {
mavenCentral()
Expand Down Expand Up @@ -78,6 +78,7 @@ sourceCompatibility = JavaVersion.VERSION_1_8

test {

systemProperties = ['jna.debug_load': true]
afterSuite { desc, result ->
if (!desc.parent) {
println ""
Expand All @@ -99,7 +100,7 @@ test {
}

jacoco {
toolVersion = '0.8.8'
toolVersion = '0.8.9'
}

checkstyle {
Expand All @@ -110,9 +111,9 @@ checkstyle {
jacocoTestReport {
dependsOn test
reports {
xml.enabled true
csv.enabled false
html.enabled true
xml.required = true
csv.required = false
html.required = true
}
}

Expand Down Expand Up @@ -239,7 +240,7 @@ publishing {
}

wrapper {
gradleVersion = '7.5.1'
gradleVersion = '8.4'
}

nexusPublishing {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ public class AACEncodingBenchmark {
}
};

private static final String WAV_EXT = "." + AudioFileFormat.Type.WAVE.getExtension();
private static final AudioFileFormat.Type WAV = AudioFileFormat.Type.WAVE;
private static final String WAV_EXT = "." + WAV.getExtension();
private static final String AAC_EXT = "." + AACFileTypes.AAC_LC.getExtension();
private static final String PREFIX = "benchmark";

private static final int DURATION = 500;
private static final int FORKS = 1;
private static final int FORKS = 0;
private static final int ITERATIONS = 12;
private static final int WARMUPS = 3;

Expand Down Expand Up @@ -113,7 +114,7 @@ private File truncatedInput() throws IOException, UnsupportedAudioFileException
AudioInputStream truncatedAudioInputStream =
new AudioInputStream(bytesInputStream, fullAudioInputStream.getFormat(), AudioSystem.NOT_SPECIFIED);
File tmpFile = File.createTempFile(PREFIX, WAV_EXT);
AudioSystem.write(truncatedAudioInputStream, AudioFileFormat.Type.WAVE, tmpFile);
AudioSystem.write(truncatedAudioInputStream, WAV, tmpFile);
return tmpFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Maps to AACENC_BufDesc struct.
*
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libAACenc/include/aacenc_lib.h">fdk-aac/libAACenc/include/aacenc_lib.h</a>
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACenc/include/aacenc_lib.h">fdk-aac/libAACenc/include/aacenc_lib.h</a>
*/
@SuppressWarnings({"JavadocVariable", "VisibilityModifier"})
public final class AACEncBufDesc extends Structure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Maps to AACENC_CONFIG struct.
*
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libAACenc/src/aacenc.h">fdk-aac/libAACenc/src/aacenc.h</a>
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACenc/src/aacenc.h">fdk-aac/libAACenc/src/aacenc.h</a>
*/
@SuppressWarnings({"JavadocVariable", "VisibilityModifier", "MemberName"})
public class AACEncConfig extends Structure {
Expand All @@ -33,13 +33,14 @@ public class AACEncConfig extends Structure {
public int maxAncBytesPerAU;
public int minBitsPerFrame;
public int maxBitsPerFrame;
public int bitreservoir;
public int audioMuxVersion;
public int sbrRatio;
public byte useTns;
public byte usePns;
public byte useIS;
public byte useMS;
public byte useRequant;
public int downscaleFactor;

@Override
protected final List<String> getFieldOrder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Maps to AACENC_EXT_PAYLOAD struct.
*
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libAACenc/src/aacenc.h">fdk-aac/libAACenc/src/aacenc.h</a>
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACenc/src/aacenc.h">fdk-aac/libAACenc/src/aacenc.h</a>
*/
@SuppressWarnings({"JavadocVariable", "VisibilityModifier"})
public class AACEncExtPayload extends Structure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Maps to AACENC_InArgs struct.
*
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libAACenc/include/aacenc_lib.h">fdk-aac/libAACenc/include/aacenc_lib.h</a>
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACenc/include/aacenc_lib.h">fdk-aac/libAACenc/include/aacenc_lib.h</a>
*/
@SuppressWarnings({"JavadocVariable", "VisibilityModifier"})
public class AACEncInArgs extends Structure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class AACEncInfo extends Structure {
public int inBufFillLevel;
public int inputChannels;
public int frameLength;
public int encoderDelay;
public int nDelay;
public int nDelayCore;
public byte[] confBuf = new byte[CONF_BUF_SIZE];
public int confSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Maps to AACENC_OutArgs struct.
*
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libAACenc/include/aacenc_lib.h">fdk-aac/libAACenc/include/aacenc_lib.h</a>
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACenc/include/aacenc_lib.h">fdk-aac/libAACenc/include/aacenc_lib.h</a>
*/
@SuppressWarnings({"JavadocVariable", "VisibilityModifier"})
public class AACEncOutArgs extends Structure {
Expand All @@ -18,6 +18,7 @@ public class AACEncOutArgs extends Structure {
public int numOutBytes;
public int numInSamples;
public int numAncBytes;
public int bitResState;

@Override
protected final List<String> getFieldOrder() {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/sheinbergon/aac/jna/structure/AACEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import java.util.List;

/**
* Maps to AACENCODER struct.
* Maps to AACENCODER struct.
*
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libAACenc/src/aacenc_lib.cpp">fdk-aac/libAACenc/src/aacenc_lib.cpp</a>
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACenc/src/aacenc_lib.cpp">fdk-aac/libAACenc/src/aacenc_lib.cpp</a>
*/
@SuppressWarnings({
"JavadocVariable",
Expand All @@ -25,7 +25,6 @@
public final class AACEncoder extends Structure {

private static final int MAX_TOTAL_EXT_PAYLOADS = 12;
private static final int MAX_PAYLOAD_SIZE = 256;

private static final List<String> FIELD_ORDER = JNASupport.structureFieldOrder(AACEncoder.class);

Expand All @@ -47,30 +46,31 @@ private AACEncoder(final @Nonnull Pointer pointer) {
public Pointer hEnvEnc;
public Pointer hMetadataEnc;
public int metaDataAllowed;
public Pointer hMpsEnc;
public Pointer hTpEnc;
public ShortByReference inputBuffer;
public ByteByReference outBuffer;
public int inputBufferSize;
public int inputBufferSizePerChannel;
public int outBufferInBytes;
public ShortByReference inputBuffer;
public int inputBufferOffset;
public int nSamplesToRead;
public int nSamplesRead;
public int nZerosAppended;
public int nDelay;
public int nDelayCore;
/*
Arrays - 1D, 2D or even 3D, are initialized as 1D to accommodate for size allocation.
This is due to the fact JNA doesn't support mapping multi-dimensional array inside structs with simple
This is due to the fact JNA doesn't support mapping multidimensional array inside structs with simple
preservation of size/memory allocation for primitives. As we won't be using these values, I'm
perfectly fine with it
*/
public AACEncExtPayload[] extPayload = new AACEncExtPayload[MAX_TOTAL_EXT_PAYLOADS];
public byte[] extPayloadData = new byte[8 * MAX_PAYLOAD_SIZE];
public int[] extPayloadSize = new int[8];
public long InitFlags;
public int nMaxAacElements;
public int nMaxAacChannels;
public int nMaxSbrElements;
public int nMaxSbrChannels;
public int nMaxSubFrames;
public int encoder_modis;
public int CAPF_tpEnc;

Expand Down
30 changes: 28 additions & 2 deletions src/main/java/org/sheinbergon/aac/jna/structure/CoderConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@
/**
* Maps to CODER_CONFIG struct.
*
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libSYS/include/FDK_audio.h">fdk-aac/libSYS/include/FDK_audio.h</a>
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libSYS/include/FDK_audio.h">fdk-aac/libSYS/include/FDK_audio.h</a>
*/
@SuppressWarnings({"JavadocVariable", "VisibilityModifier", "MemberName"})
public class CoderConfig extends Structure {
public final class CoderConfig extends Structure {

private static final int RAW_CONFIG_SIZE = 64;

private static final List<String> FIELD_ORDER = JNASupport.structureFieldOrder(CoderConfig.class);

/**
* AAC Coder Config instantiation, disabling memory allocation alignment.
*/
public CoderConfig() {
setAlignType(Structure.ALIGN_NONE); // Make sure field size alignments are as expected
read(); // Read once after initialize from provided pointer
}

/**
* Audio Object Type (AOT).
*/
Expand All @@ -27,6 +37,10 @@ public class CoderConfig extends Structure {
* Channel mode.
*/
public int channelMode;
/**
* Use channel config zero + pce although a standard channel config could be signaled.
*/
public byte channelConfigZero;
/**
* Sampling rate.
*/
Expand All @@ -35,6 +49,10 @@ public class CoderConfig extends Structure {
* Extended samplerate (SBR).
*/
public int extSamplingRate;
/**
* Downscale sampling rate (ELD downscaled mode).
*/
public int downscaleSamplingRate;
/**
* Average bitRate.
*/
Expand Down Expand Up @@ -85,6 +103,14 @@ public class CoderConfig extends Structure {
* 0: implicit signaling, 1: backwards compatible explicit signaling, 2: hierarcical explicit signaling.
*/
public int sbrSignaling;
/**
* Raw codec specific config as bit stream.
*/
public byte[] rawConfig = new byte[RAW_CONFIG_SIZE];
/**
* Size of rawConfig in bits.
*/
public int rawConfigBits;
public byte sbrPresent;
public byte psPresent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Maps to USER_PARAM struct.
*
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v0.1.6/libAACenc/src/aacenc_lib.cpp">fdk-aac/libAACenc/src/aacenc_lib.cpp</a>
* @see <a href="https://github.com/mstorsjo/fdk-aac/blob/v2.0.2/libAACenc/src/aacenc_lib.cpp">fdk-aac/libAACenc/src/aacenc_lib.cpp</a>
*/
@SuppressWarnings({"JavadocVariable", "VisibilityModifier"})
public class UserParam extends Structure {
Expand Down Expand Up @@ -40,6 +40,7 @@ public class UserParam extends Structure {
public byte userMetaDataMode;
public byte userSbrEnabled;
public int userSbrRatio;
public int userDownscaleFactor;

@Override
protected final List<String> getFieldOrder() {
Expand Down
Binary file removed src/main/resources/linux-x86-64/libfdk-aac.so
Binary file not shown.
Binary file not shown.
Binary file removed src/main/resources/win32-x86/fdk-aac.dll
Binary file not shown.

0 comments on commit c320bdb

Please sign in to comment.