Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework build system #1

Merged
merged 9 commits into from
Mar 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CI
on: [push]

jobs:
build-binaries:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]

name: ${{ matrix.os }} build
runs-on: ${{ matrix.os }}

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Install java
uses: actions/setup-java@v1
with:
java-version: 8
- name: Make gradlew executable (Unix)
run: "chmod +x gradlew"
if: runner.os != 'Windows'
- name: Build native with gradle (Unix)
run: "./gradlew -PCI=true opus-jni-native:build"
if: runner.os != 'Windows'
- name: Build native with gradle (Windows)
run: "gradlew -PCI=true opus-jni-native:build"
shell: cmd
if: runner.os == 'Windows'
- name: Prepare artifacts
shell: bash
run: |
mkdir artifacts
for file in $(cat ci/binaries); do # File generated by gradle
echo "Found binary artifact ${file}"
cp "${file}" artifacts
done
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: native-binaries
path: artifacts

build-jar:
needs: build-binaries
runs-on: ubuntu-latest # Doesn't matter, but linux tends to be the fastest

name: Build final jar

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: Install java
uses: actions/setup-java@v1
with:
java-version: 8
- name: Download existing artifacts
uses: actions/download-artifact@v1
with:
name: native-binaries
path: native-binaries
- name: Make gradlew executable
run: "chmod +x gradlew"
- name: Build final jar with gradle
run: "./gradlew -PCI=true -PnativeBinaryExternalDir=native-binaries opus-jni-java:build"
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: Final artifacts
path: opus-jni-java/build/libs/
126 changes: 3 additions & 123 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,124 +1,4 @@
# Created by .ignore support plugin (hsz.mobi)
### Gradle template
.gradle
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.gradle/
.idea/.gitignore
.idea/.name
.idea/google-java-format.xml
.idea/gradle.xml
.idea/jarRepositories.xml
.idea/misc.xml
.idea/modules/
.idea/uiDesigner.xml
.idea/vcs.xml
.idea/
build/
cmake-build*/
.gradle/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "opus-jni-native/3rdparty/opus"]
path = opus-jni-native/3rdparty/opus
url = https://github.com/xiph/opus
10 changes: 0 additions & 10 deletions .idea/modules.xml

This file was deleted.

63 changes: 47 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,60 @@
# opus-jni

opus-jni is a very simple and comfortable to use JNI wrapper for the [Opus codec](https://opus-codec.org/),
created for [LabyMod](https://github.com/LabyMod)
It might lack a few functions of the original Opus codec specifications but should be perfectly fine for most usecases.
opus-jni is a very simple and comfortable to use JNI wrapper for the
[Opus codec](https://opus-codec.org/), created for [LabyMod](https://github.com/LabyMod).
It might lack a few functions of the original Opus codec specifications but should be perfectly
fine for most usecases.

See [here](./src/test/java/net/labymod/opus/MinimalEchoExample.java) for a very simple and complete echo example.
See [here](./opus-jni-java/src/test/java/net/labymod/opus/MinimalEchoExample.java) for a very
simple and complete echo example.
## How to use:
### Cloning
This repository uses submodules, so you need to clone with `--recurse-submodules` or after
cloning run `git submodule update --init`

### Building
Building is slightly more complex than a normal Java project and only required if you want
to change the way the library works.

#### Building for your platform (development)
Install [CMake](https://cmake.org/download/) and make sure it is on the path. You will also need
a compiler (not a Java compiler, but a C one). For windows you should install Visual Studio.
For Linux and OSX choose your favorite method of installing the compiler (gcc and clang should
both work).

After this is done, the project might be used like every other gradle project. Note that the
resulting jar will be in `opus-jni-java/build/libs` and **will just work on the platform it
was built on!**. For instructions on how to build for all target platforms, see below.

#### Building for all platforms (production)
You will need a machine for every platform you want to build on. This means, if you want to
produce a jar which works on Linux, Windows and OSX, you will need an installation of each of
the operating systems (it might be possible to just use Linux and cross compile, but that is
not officially supported by us).

All 3 machines will need CMake and a compiler installed (refer to
[Building for your platform](#building-for-your-platform-development)). Then you need to run
the gradle task `opus-jni-native:build` on each machine, which will result in the following
binaries in `build/nativeBinaries`:
- `libopus-jni-native.dylib` (OSX)
- `libopus-jni-native.so` (Linux)
- `opus-jni-native.dll` (Windows)

Copy all of those binaries to one machine to one directory. On that machine invoke
`gradlew -PnativeBinaryExternalDir=/path/to/your/directory opus-jni-java:build`, where
`/path/to/your/directory` is the directory containing all 3 of the binaries above.
The final jar in `opus-jni-java/build/libs` will support all platforms you have built the
binaries for. You may leave the ones out you don't need to support.

For further details, refer to the [Github workflow](./.github/workflows/ci.yml).

### Important to know:
- Every audio stream requires its own codec instance, because Opus is not stateless.
- Only the following sample rates are supported: 8khz, 12khz, 16khz, 24khz, 48khz
- Recommended bitrates for your purpose found [here](https://wiki.xiph.org/index.php?title=Opus_Recommended_Settings&mobileaction=toggle_view_desktop)
- Recommended bitrates for your purpose found
[here](https://wiki.xiph.org/index.php?title=Opus_Recommended_Settings&mobileaction=toggle_view_desktop)
- The default codec settings should be fine for every simple VoIP communication

#### Native libraries:
The native libraries _**CAN**_ be loaded with :
```java
OpusCodec.loadNativesFromJar()
```

However this is not recommended, because it uses a hack to modify `java.library.path`, so it might break in some JVMs.
So if you want to use this little comfortable native library initialization method, be sure to know which JVM you are using.

If you want to get sure, place the [native libraries](./src/main/resources/native) in the path before launching the JVM. (Download link following)

#### Create a codec instance:
###### Default settings
```java
Expand Down
Loading