Skip to content
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
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ jobs:
common:
uses: TokTok/ci-tools/.github/workflows/common-ci.yml@master

docker-jvm:
docker:
strategy:
matrix:
target: [jvm, native]
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build toxchat/jvm-toxcore-c:jvm
- name: Build toxchat/jvm-toxcore-c:${{ matrix.target }}
uses: docker/build-push-action@v5
with:
file: docker/jvm.Dockerfile
tags: toxchat/jvm-toxcore-c:jvm
file: docker/${{ matrix.target }}.Dockerfile
tags: toxchat/jvm-toxcore-c:${{ matrix.target }}

ktlint:
runs-on: ubuntu-22.04
Expand Down
32 changes: 16 additions & 16 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ genrule(
"//tools/config:osx": ["@bazel_tools//tools/jdk:jni_md_header-darwin"],
"//tools/config:windows": ["@bazel_tools//tools/jdk:jni_md_header-windows"],
}),
outs = ["lib/src/main/cpp/jni_md.h"],
outs = ["lib/src/jvmMain/cpp/jni_md.h"],
cmd = "cp -f $< $@",
)

genrule(
name = "copy_link_jni_header",
srcs = ["@bazel_tools//tools/jdk:jni_header"],
outs = ["lib/src/main/cpp/jni.h"],
outs = ["lib/src/jvmMain/cpp/jni.h"],
cmd = "cp -f $< $@",
)

proto_library(
name = "jni_proto",
srcs = [
"lib/src/main/proto/Av.proto",
"lib/src/main/proto/Core.proto",
"lib/src/jvmMain/proto/Av.proto",
"lib/src/jvmMain/proto/Core.proto",
],
)

Expand All @@ -46,28 +46,28 @@ java_proto_library(
cc_binary(
name = "libtox4j-c.so",
srcs = glob([
"lib/src/main/cpp/**/*.cpp",
"lib/src/main/cpp/**/*.h",
"lib/src/jvmMain/cpp/**/*.cpp",
"lib/src/jvmMain/cpp/**/*.h",
]) + [
":lib/src/main/cpp/jni.h",
":lib/src/main/cpp/jni_md.h",
":lib/src/jvmMain/cpp/jni.h",
":lib/src/jvmMain/cpp/jni_md.h",
],
copts = [
"-DHAVE_TO_STRING",
],
includes = [
"lib/src/main/cpp",
"lib/src/main/proto",
"lib/src/jvmMain/cpp",
"lib/src/jvmMain/proto",
],
linkopts = select({
"//tools/config:freebsd": ["-Wl,--version-script,$(location lib/src/main/cpp/libtox4j-c.ld)"],
"//tools/config:linux": ["-Wl,--version-script,$(location lib/src/main/cpp/libtox4j-c.ld)"],
"//tools/config:freebsd": ["-Wl,--version-script,$(location lib/src/jvmMain/cpp/libtox4j-c.ld)"],
"//tools/config:linux": ["-Wl,--version-script,$(location lib/src/jvmMain/cpp/libtox4j-c.ld)"],
"//tools/config:osx": [],
"//tools/config:windows": [],
}),
linkshared = True,
deps = [
"lib/src/main/cpp/libtox4j-c.ld",
"lib/src/jvmMain/cpp/libtox4j-c.ld",
":jni_cc_proto",
"//c-toxcore",
],
Expand All @@ -76,8 +76,8 @@ cc_binary(
kt_jvm_library(
name = "jvm-toxcore-c",
srcs = glob([
"lib/src/main/java/**/*.java",
"lib/src/main/java/**/*.kt",
"lib/src/*Main/**/*.java",
"lib/src/*Main/**/*.kt",
]),
data = ["libtox4j-c.so"],
deps = [":jni_java_proto"],
Expand All @@ -86,7 +86,7 @@ kt_jvm_library(
kt_jvm_test(
name = "ToxCoreTest",
size = "small",
srcs = ["lib/src/test/java/im/tox/tox4j/core/ToxCoreTest.kt"],
srcs = ["lib/src/jvmTest/java/im/tox/tox4j/core/ToxCoreTest.kt"],
jvm_flags = ["-Djava.library.path=jvm-toxcore-c"],
test_class = "im.tox.tox4j.core.ToxCoreTest",
deps = [
Expand Down
13 changes: 13 additions & 0 deletions docker/build-native
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -eux

cat <<EOF >native.txt
-p
library
EOF

find lib/src/commonMain -name '*.kt' -exec printf '{}\n-Xcommon-sources={}\n' ';' >>native.txt

kotlinc-native @native.txt
ls
19 changes: 10 additions & 9 deletions docker/jvm.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN apt-get update \
build-essential \
ca-certificates \
cmake \
curl \
default-jdk \
git \
libtool \
Expand All @@ -23,8 +24,8 @@ RUN scripts/build-host "$PWD/_install/host/protobuf.stamp" "-j$(nproc)"
RUN scripts/build-host "$PWD/_install/host/toxcore.stamp" "-j$(nproc)"

# Native code, changes less frequently.
COPY lib/src/main/cpp/ /work/jvm-toxcore-c/lib/src/main/cpp/
COPY lib/src/main/proto/ /work/jvm-toxcore-c/lib/src/main/proto/
COPY lib/src/jvmMain/cpp/ /work/jvm-toxcore-c/lib/src/jvmMain/cpp/
COPY lib/src/jvmMain/proto/ /work/jvm-toxcore-c/lib/src/jvmMain/proto/
RUN touch "$PWD/_install/host/.stamp" \
&& touch "$PWD/_install/host/libsodium.stamp" \
&& touch "$PWD/_install/host/libvpx.stamp" \
Expand All @@ -42,10 +43,10 @@ ENV LD_LIBRARY_PATH=/work/jvm-toxcore-c/_install/host/lib
ENV PATH=/work/jvm-toxcore-c/_install/host/bin:$PATH
RUN ./gradlew build

RUN javac -h . -cp /work/jvm-toxcore-c/lib/build/classes/kotlin/main:/work/jvm-toxcore-c/lib/build/classes/java/main \
lib/src/main/java/im/tox/tox4j/impl/jni/ToxAvJni.java \
lib/src/main/java/im/tox/tox4j/impl/jni/ToxCoreJni.java \
lib/src/main/java/im/tox/tox4j/impl/jni/ToxCryptoJni.java
RUN diff -u lib/src/main/cpp/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h im_tox_tox4j_impl_jni_ToxCoreJni.h \
&& diff -u lib/src/main/cpp/ToxAv/generated/im_tox_tox4j_impl_jni_ToxAvJni.h im_tox_tox4j_impl_jni_ToxAvJni.h \
&& diff -u lib/src/main/cpp/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h im_tox_tox4j_impl_jni_ToxCryptoJni.h
RUN javac -h . -cp /work/jvm-toxcore-c/lib/build/classes/kotlin/jvm/main:/work/jvm-toxcore-c/lib/build/classes/java/jvm/main \
lib/src/jvmMain/java/im/tox/tox4j/impl/jni/ToxAvJni.java \
lib/src/jvmMain/java/im/tox/tox4j/impl/jni/ToxCoreJni.java \
lib/src/jvmMain/java/im/tox/tox4j/impl/jni/ToxCryptoJni.java
RUN diff -u lib/src/jvmMain/cpp/ToxCore/generated/im_tox_tox4j_impl_jni_ToxCoreJni.h im_tox_tox4j_impl_jni_ToxCoreJni.h \
&& diff -u lib/src/jvmMain/cpp/ToxAv/generated/im_tox_tox4j_impl_jni_ToxAvJni.h im_tox_tox4j_impl_jni_ToxAvJni.h \
&& diff -u lib/src/jvmMain/cpp/ToxCrypto/generated/im_tox_tox4j_impl_jni_ToxCryptoJni.h im_tox_tox4j_impl_jni_ToxCryptoJni.h
33 changes: 33 additions & 0 deletions docker/native.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:22.04

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
autoconf \
automake \
build-essential \
ca-certificates \
cmake \
curl \
default-jdk \
git \
libtool \
make \
pkg-config \
yasm \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /opt
RUN curl -L -o kotlin-native.tar.gz https://github.com/JetBrains/kotlin/releases/download/v1.9.22/kotlin-native-linux-x86_64-1.9.22.tar.gz \
&& tar zxf kotlin-native.tar.gz \
&& mv kotlin-native-linux-x86_64-1.9.22 kotlin \
&& rm kotlin-native.tar.gz
ENV PATH=$PATH:/opt/kotlin/bin

RUN ["touch", "Boot.kt"]
RUN ["kotlinc-native", "-p", "library", "Boot.kt"]

WORKDIR /work/jvm-toxcore-c
COPY lib/ /work/jvm-toxcore-c/lib/
COPY docker/build-native /work/jvm-toxcore-c/docker/
RUN ["docker/build-native"]
24 changes: 13 additions & 11 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Kotlin library project to get you started.
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.4/userguide/building_java_projects.html in the Gradle documentation.
* This project uses @Incubating APIs which are subject to change.
*/

plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id("org.jetbrains.kotlin.jvm") version "1.9.22"
kotlin("multiplatform") version "1.9.22"
id("com.google.protobuf") version "0.9.4"

// Apply the java-library plugin for API and implementation separation.
Expand All @@ -21,10 +12,21 @@ repositories {
}

dependencies {
implementation("com.google.protobuf:protobuf-java:3.24.4")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0")
}

kotlin {
jvm()

sourceSets {
val jvmMain by getting {
dependencies {
implementation("com.google.protobuf:protobuf-java:3.24.4")
}
}
}
}

testing {
suites {
// Configure the built-in test suite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import im.tox.tox4j.av.data.SamplingRate
import im.tox.tox4j.av.enums.ToxavCallControl
import im.tox.tox4j.core.ToxCore
import im.tox.tox4j.core.data.ToxFriendNumber
import java.io.Closeable

/**
* Public audio/video API for Tox clients.
Expand All @@ -28,7 +27,8 @@ import java.io.Closeable
* otherwise undefined behaviour occurs. Upon closing of ToxAv instance, all active calls will be
* forcibly terminated without notifying peers.
*/
interface ToxAv : Closeable {
@kotlin.ExperimentalStdlibApi
interface ToxAv : AutoCloseable {
/**
* Start new A/V session. There can only be only one session per Tox instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package im.tox.tox4j.av.callbacks

import im.tox.tox4j.av.enums.ToxavFriendCallState
import im.tox.tox4j.core.data.ToxFriendNumber
import java.util.EnumSet

/** Called when the call state changes. */
interface CallStateCallback<ToxCoreState> {
Expand All @@ -14,7 +13,7 @@ interface CallStateCallback<ToxCoreState> {
*/
fun callState(
friendNumber: ToxFriendNumber,
callState: EnumSet<ToxavFriendCallState>,
callState: Set<ToxavFriendCallState>,
state: ToxCoreState,
): ToxCoreState = state
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package im.tox.tox4j.av.data

import kotlin.jvm.JvmInline

@JvmInline
value class BitRate(val value: Int) {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package im.tox.tox4j.av.data

import kotlin.jvm.JvmInline

@JvmInline value class Height(val value: Int)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package im.tox.tox4j.av.data

import kotlin.jvm.JvmInline

@JvmInline
value class SampleCount(val value: Int) {
constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package im.tox.tox4j.av.data

import kotlin.jvm.JvmInline

@JvmInline value class Width(val value: Int)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package im.tox.tox4j.av.enums

/**
* Call control.
*/
enum class ToxavCallControl {
/**
* Resume a previously paused call. Only valid if the pause was caused by this
* client, if not, this control is ignored. Not valid before the call is
* accepted.
*/
RESUME,

/**
* Put a call on hold. Not valid before the call is accepted.
*/
PAUSE,

/**
* Reject a call if it was not answered, yet. Cancel a call after it was
* answered.
*/
CANCEL,

/**
* Request that the friend stops sending audio. Regardless of the friend's
* compliance, this will cause the {@link
* im.tox.tox4j.av.callbacks.AudioReceiveFrameCallback} event to stop being
* triggered on receiving an audio frame from the friend.
*/
MUTE_AUDIO,

/**
* Calling this control will notify client to start sending audio again.
*/
UNMUTE_AUDIO,

/**
* Request that the friend stops sending video. Regardless of the friend's
* compliance, this will cause the {@link
* im.tox.tox4j.av.callbacks.VideoReceiveFrameCallback} event to stop being
* triggered on receiving an video frame from the friend.
*/
HIDE_VIDEO,

/**
* Calling this control will notify client to start sending video again.
*/
SHOW_VIDEO,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package im.tox.tox4j.av.enums

/**
* Call state graph.
*/
enum class ToxavFriendCallState {
/**
* Set by the AV core if an error occurred on the remote end or if friend
* timed out. This is the final state after which no more state
* transitions can occur for the call. This call state will never be triggered
* in combination with other call states.
*/
ERROR,

/**
* The call has finished. This is the final state after which no more state
* transitions can occur for the call. This call state will never be
* triggered in combination with other call states.
*/
FINISHED,

/**
* The flag that marks that friend is sending audio.
*/
SENDING_A,

/**
* The flag that marks that friend is sending video.
*/
SENDING_V,

/**
* The flag that marks that friend is receiving audio.
*/
ACCEPTING_A,

/**
* The flag that marks that friend is receiving video.
*/
ACCEPTING_V,
}
Loading