Replace JNA with the FFM API (Panama) for the Opus binding

Bind libopus through java.lang.foreign downcall handles instead of JNA:
the ctl functions are linked with firstVariadicArg(2), and the encoder and
decoder each own a shared Arena holding the handle plus reusable native
PCM/packet buffers, so the hot path only allocates the returned packet.

The library is resolved by system SONAME first, falling back to a bundled
copy extracted from the JAR. Only the Windows x86-64 build is packaged by
default now (-Dnatives.all restores all platforms), since every other
platform ships libopus through its package manager.

Requires Java 26.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-13 23:35:57 +00:00
parent 022aef633b
commit 9d63522ef2
7 changed files with 381 additions and 100 deletions

View File

@@ -12,7 +12,7 @@
<artifactId>ts3-client-desktop</artifactId>
<name>TS3J Client Desktop Audio</name>
<description>Desktop audio backend: Java Sound capture/playback and native Opus via JNA</description>
<description>Desktop audio backend: Java Sound capture/playback and native Opus via the FFM API</description>
<dependencies>
<dependency>
@@ -23,9 +23,43 @@
<groupId>com.github.manevolent</groupId>
<artifactId>ts3j</artifactId>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
</dependency>
</dependencies>
<build>
<!--
Only the Windows x86-64 Opus build is packaged by default: every other
supported platform ships libopus through its package manager (or, on
macOS, Homebrew), and the FFM binding loads the system library first.
Build with -Dnatives.all to bundle the copies for all platforms.
-->
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>darwin/**</exclude>
<exclude>darwin-*/**</exclude>
<exclude>linux-*/**</exclude>
<exclude>win32-x86/**</exclude>
</excludes>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>all-natives</id>
<activation>
<property>
<name>natives.all</name>
</property>
</activation>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</profile>
</profiles>
</project>