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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ext {
}

compileJava {
options.headerOutputDirectory = file(project(":roc_jni").projectDir.absolutePath + "/src/main/public")
options.headerOutputDirectory = file(project(":roc_jni").projectDir.absolutePath + "/src/main/export")
}

tasks.register('copyNativeDebugDeps') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void apply(final Project project) {
// Add a CMake extension to the Gradle model
final CMakeExtension extension = project.getExtensions().create("cmake", CMakeExtension.class,
project.getLayout(), project.getObjects());
extension.getSrcDirs().convention(Arrays.asList("src/main/cpp", "src/main/public", "src/main/headers"));
extension.getSrcDirs().convention(Arrays.asList("src/main/export", "src/main/impl"));

/*
* Create some tasks to drive the CMake build
Expand Down
43 changes: 24 additions & 19 deletions roc_jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.4.1)

project(RocJni)

set(CMAKE_CXX_STANDARD 11)
project(RocJni C)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand All @@ -14,22 +12,29 @@ if(APPLE)
endif()

add_library(roc_jni SHARED
src/main/cpp/channel_set.cpp
src/main/cpp/clock_source.cpp
src/main/cpp/common.cpp
src/main/cpp/context.cpp
src/main/cpp/endpoint.cpp
src/main/cpp/fec_encoding.cpp
src/main/cpp/frame_encoding.cpp
src/main/cpp/logger.cpp
src/main/cpp/packet_encoding.cpp
src/main/cpp/protocol.cpp
src/main/cpp/receiver.cpp
src/main/cpp/resampler_backend.cpp
src/main/cpp/resampler_profile.cpp
src/main/cpp/sender.cpp
src/main/impl/channel_set.c
src/main/impl/clock_source.c
src/main/impl/common.c
src/main/impl/context.c
src/main/impl/endpoint.c
src/main/impl/fec_encoding.c
src/main/impl/frame_encoding.c
src/main/impl/logger.c
src/main/impl/packet_encoding.c
src/main/impl/protocol.c
src/main/impl/receiver.c
src/main/impl/resampler_backend.c
src/main/impl/resampler_profile.c
src/main/impl/sender.c
)

target_compile_options(roc_jni PRIVATE
-Wall
-Wextra
-Wno-system-headers
-Wno-unused-parameter
)

if(NOT ANDROID)
if (NOT CMAKE_CROSSCOMPILING)
find_package(JNI REQUIRED)
Expand All @@ -39,8 +44,8 @@ if(NOT ANDROID)
endif()

target_include_directories(roc_jni
PRIVATE src/main/headers/
PUBLIC src/main/public/
PRIVATE src/main/impl/
PUBLIC src/main/export/
)

if(ANDROID)
Expand Down
1 change: 0 additions & 1 deletion roc_jni/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ cmake {
platform System.getProperty("platform")
}

//srcDirs "src/main/cpp", "src/main/public", "src/main/headers"
generator System.getProperty("generator")

arguments "-DROC_INCLUDE_PATH=" + System.getProperty("ROC_INCLUDE_PATH"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
roc_channel_set get_channel_set(JNIEnv* env, jobject jchannel_set) {
jclass channelSetClass = NULL;

channelSetClass = env->FindClass(CHANNEL_SET_CLASS);
channelSetClass = (*env)->FindClass(env, CHANNEL_SET_CLASS);
assert(channelSetClass != NULL);

return (roc_channel_set) get_enum_value(env, channelSetClass, jchannel_set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
roc_clock_source get_clock_source(JNIEnv* env, jobject jclock_source) {
jclass clockSourceClass = NULL;

clockSourceClass = env->FindClass(CLOCK_SOURCE_CLASS);
clockSourceClass = (*env)->FindClass(env, CLOCK_SOURCE_CLASS);
assert(clockSourceClass != NULL);

return (roc_clock_source) get_enum_value(env, clockSourceClass, jclock_source);
Expand Down
30 changes: 15 additions & 15 deletions roc_jni/src/main/cpp/common.cpp → roc_jni/src/main/impl/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

int get_boolean_field_value(
JNIEnv* env, jclass clazz, jobject obj, const char* attr_name, int* error) {
jfieldID attrId = env->GetFieldID(clazz, attr_name, "Z");
jfieldID attrId = (*env)->GetFieldID(env, clazz, attr_name, "Z");
assert(attrId != NULL);
return env->GetBooleanField(obj, attrId) == JNI_TRUE;
return (*env)->GetBooleanField(env, obj, attrId) == JNI_TRUE;
}

int get_int_field_value(JNIEnv* env, jclass clazz, jobject obj, const char* attr_name, int* error) {
jfieldID attrId = env->GetFieldID(clazz, attr_name, "I");
jfieldID attrId = (*env)->GetFieldID(env, clazz, attr_name, "I");
assert(attrId != NULL);
jint ret = env->GetIntField(obj, attrId);
jint ret = (*env)->GetIntField(env, obj, attrId);
if (ret < INT_MIN || ret > INT_MAX) {
*error = -1;
return 0;
Expand All @@ -22,10 +22,10 @@ int get_int_field_value(JNIEnv* env, jclass clazz, jobject obj, const char* attr

unsigned int get_uint_field_value(
JNIEnv* env, jclass clazz, jobject obj, const char* attr_name, int* error) {
jfieldID attrId = env->GetFieldID(clazz, attr_name, "I");
jfieldID attrId = (*env)->GetFieldID(env, clazz, attr_name, "I");
assert(attrId != NULL);
jint ret = env->GetIntField(obj, attrId);
if (ret < 0 || ret > UINT_MAX) {
jint ret = (*env)->GetIntField(env, obj, attrId);
if (ret < 0 || (unsigned int) ret > UINT_MAX) {
*error = -1;
return 0;
}
Expand All @@ -34,18 +34,18 @@ unsigned int get_uint_field_value(

long long get_llong_field_value(
JNIEnv* env, jclass clazz, jobject obj, const char* attr_name, int* error) {
jfieldID attrId = env->GetFieldID(clazz, attr_name, "J");
jfieldID attrId = (*env)->GetFieldID(env, clazz, attr_name, "J");
assert(attrId != NULL);
jlong ret = env->GetLongField(obj, attrId);
jlong ret = (*env)->GetLongField(env, obj, attrId);
assert(sizeof(long long) == sizeof(jlong));
return (long long) ret;
}

unsigned long long get_ullong_field_value(
JNIEnv* env, jclass clazz, jobject obj, const char* attr_name, int* error) {
jfieldID attrId = env->GetFieldID(clazz, attr_name, "J");
jfieldID attrId = (*env)->GetFieldID(env, clazz, attr_name, "J");
assert(attrId != NULL);
jlong ret = env->GetLongField(obj, attrId);
jlong ret = (*env)->GetLongField(env, obj, attrId);
if (ret < 0) {
*error = -1;
return 0LL;
Expand All @@ -55,15 +55,15 @@ unsigned long long get_ullong_field_value(

int get_enum_value(JNIEnv* env, jclass clazz, jobject enumObj) {
if (enumObj != NULL) {
jfieldID attrId = env->GetFieldID(clazz, "value", "I");
return env->GetIntField(enumObj, attrId);
jfieldID attrId = (*env)->GetFieldID(env, clazz, "value", "I");
return (*env)->GetIntField(env, enumObj, attrId);
}
return 0;
}

jobject get_object_field(
JNIEnv* env, jclass clazz, jobject obj, const char* attr_name, const char* attr_class_name) {
jfieldID attrId = env->GetFieldID(clazz, attr_name, attr_class_name);
jfieldID attrId = (*env)->GetFieldID(env, clazz, attr_name, attr_class_name);
assert(attrId != NULL);
return env->GetObjectField(obj, attrId);
return (*env)->GetObjectField(env, obj, attrId);
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

#include <roc/context.h>

#define CONTEXT_CLASS PACKAGE_BASE_NAME "/Context"
#define CONTEXT_CONFIG_CLASS PACKAGE_BASE_NAME "/ContextConfig"

static int context_config_unmarshal(JNIEnv* env, roc_context_config* conf, jobject jconfig) {
jclass contextConfigClass = NULL;
int err = 0;

contextConfigClass = env->FindClass(CONTEXT_CONFIG_CLASS);
contextConfigClass = (*env)->FindClass(env, CONTEXT_CONFIG_CLASS);
assert(contextConfigClass != NULL);

memset(conf, 0, sizeof(roc_context_config));
Expand All @@ -33,14 +32,14 @@ JNIEXPORT jlong JNICALL Java_org_rocstreaming_roctoolkit_Context_open(
roc_context_config context_config = {};

if (context_config_unmarshal(env, &context_config, config) != 0) {
jclass exceptionClass = env->FindClass(ILLEGAL_ARGUMENTS_EXCEPTION);
env->ThrowNew(exceptionClass, "Wrong context configuration values");
jclass exceptionClass = (*env)->FindClass(env, ILLEGAL_ARGUMENTS_EXCEPTION);
(*env)->ThrowNew(env, exceptionClass, "Wrong context configuration values");
return (jlong) NULL;
}

if (roc_context_open(&context_config, &context) != 0) {
jclass exceptionClass = env->FindClass(EXCEPTION);
env->ThrowNew(exceptionClass, "Error opening context");
jclass exceptionClass = (*env)->FindClass(env, EXCEPTION);
(*env)->ThrowNew(env, exceptionClass, "Error opening context");
return (jlong) NULL;
}

Expand All @@ -53,7 +52,7 @@ JNIEXPORT void JNICALL Java_org_rocstreaming_roctoolkit_Context_close(
roc_context* context = (roc_context*) nativePtr;

if (roc_context_close(context) != 0) {
jclass exceptionClass = env->FindClass(EXCEPTION);
env->ThrowNew(exceptionClass, "Error closing context");
jclass exceptionClass = (*env)->FindClass(env, EXCEPTION);
(*env)->ThrowNew(env, exceptionClass, "Error closing context");
}
}
Loading