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

android - add presets support, enable camera stream configuration #3771

Merged
merged 5 commits into from
Apr 18, 2019
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
26 changes: 14 additions & 12 deletions src/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ target_sources(${LRS_TARGET}
"${CMAKE_CURRENT_LIST_DIR}/usb_host/device_watcher.cpp"

"${CMAKE_CURRENT_LIST_DIR}/jni/error.h"
"${CMAKE_CURRENT_LIST_DIR}/jni/error.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/context.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/device.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/device_list.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/pipeline.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/config.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/stream_profile.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/frame.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/frameset.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/frame_queue.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/processing.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/options.c"
"${CMAKE_CURRENT_LIST_DIR}/jni/error.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/context.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/device.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/sensor.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/device_list.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/pipeline.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/config.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/stream_profile.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/frame.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/frameset.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/frame_queue.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/processing.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/options.cpp"
"${CMAKE_CURRENT_LIST_DIR}/jni/advanced_mode.cpp"
)

message(STATUS "Prepare RealSense SDK for Android OS (${ANDROID_NDK_ABI_NAME})")
Expand Down
51 changes: 51 additions & 0 deletions src/android/jni/advanced_mode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.

#include <jni.h>
#include "error.h"
#include "../../../include/librealsense2/rs.h"
#include "../../../include/librealsense2/rs_advanced_mode.h"
#include "../../api.h"

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Device_nToggleAdvancedMode(JNIEnv *env, jclass type,
jlong handle, jboolean enable) {
rs2_error* e = NULL;
rs2_toggle_advanced_mode(reinterpret_cast<rs2_device *>(handle), enable, &e);
handle_error(env, e);
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_intel_realsense_librealsense_Device_nIsInAdvancedMode(JNIEnv *env, jclass type,
jlong handle) {
rs2_error* e = NULL;
int rv = -1;
rs2_is_enabled(reinterpret_cast<rs2_device *>(handle), &rv, &e);
handle_error(env, e);
return rv > 0;
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Device_nLoadPresetFromJson(JNIEnv *env, jclass type,
jlong handle, jbyteArray data_) {
jbyte *data = env->GetByteArrayElements(data_, NULL);
jsize length = env->GetArrayLength(data_);
rs2_error* e = NULL;
rs2_load_json(reinterpret_cast<rs2_device *>(handle), data, length, &e);
handle_error(env, e);
env->ReleaseByteArrayElements(data_, data, 0);
}

extern "C" JNIEXPORT jbyteArray JNICALL
Java_com_intel_realsense_librealsense_Device_nSerializePresetToJson(JNIEnv *env, jclass type,
jlong handle) {
rs2_error* e = NULL;
std::shared_ptr<rs2_raw_data_buffer> raw_data_buffer(
rs2_serialize_json(reinterpret_cast<rs2_device *>(handle), &e),
[](rs2_raw_data_buffer* buff){ if(buff) delete buff;});
handle_error(env, e);
jbyteArray rv = env->NewByteArray(raw_data_buffer->buffer.size());
env->SetByteArrayRegion(rv, 0, raw_data_buffer->buffer.size(),
reinterpret_cast<const jbyte *>(raw_data_buffer->buffer.data()));
return rv;
}
77 changes: 0 additions & 77 deletions src/android/jni/config.c

This file was deleted.

104 changes: 104 additions & 0 deletions src/android/jni/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.

#include <jni.h>
#include "error.h"

#include "../../../include/librealsense2/rs.h"
#include "../../../include/librealsense2/h/rs_config.h"

extern "C" JNIEXPORT jlong JNICALL
Java_com_intel_realsense_librealsense_Config_nCreate(JNIEnv *env, jclass type) {
rs2_error *e = NULL;
rs2_config *rv = rs2_create_config(&e);
handle_error(env, e);
return (jlong) rv;
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Config_nDelete(JNIEnv *env, jclass type, jlong handle) {
rs2_delete_config((rs2_config *) handle);
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Config_nEnableStream(JNIEnv *env, jclass type_, jlong handle,
jint type, jint index, jint width,
jint height, jint format,
jint framerate) {
rs2_error *e = NULL;
rs2_config_enable_stream(reinterpret_cast<rs2_config *>(handle), static_cast<rs2_stream>(type), index, width, height,
static_cast<rs2_format>(format), framerate, &e);
handle_error(env, e);
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Config_nEnableDeviceFromFile(JNIEnv *env, jclass type,
jlong handle,
jstring filePath_) {
const char *filePath = env->GetStringUTFChars(filePath_, 0);

rs2_error *e = NULL;
rs2_config_enable_device_from_file(reinterpret_cast<rs2_config *>(handle), filePath, &e);
handle_error(env, e);

env->ReleaseStringUTFChars(filePath_, filePath);
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Config_nEnableRecordToFile(JNIEnv *env, jclass type,
jlong handle, jstring filePath_) {
const char *filePath = env->GetStringUTFChars(filePath_, 0);

rs2_error *e = NULL;
rs2_config_enable_record_to_file(reinterpret_cast<rs2_config *>(handle), filePath, &e);
handle_error(env, e);

env->ReleaseStringUTFChars(filePath_, filePath);
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Config_nDisableStream(JNIEnv *env, jclass type, jlong handle,
jint streamType) {
rs2_error *e = NULL;
rs2_config_disable_stream(reinterpret_cast<rs2_config *>(handle),
static_cast<rs2_stream>(streamType), &e);
handle_error(env, e);
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Config_nEnableAllStreams(JNIEnv *env, jclass type,
jlong handle) {
rs2_error *e = NULL;
rs2_config_enable_all_stream(reinterpret_cast<rs2_config *>(handle), &e);
handle_error(env, e);
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Config_nDisableAllStreams(JNIEnv *env, jclass type,
jlong handle) {
rs2_error *e = NULL;
rs2_config_disable_all_streams(reinterpret_cast<rs2_config *>(handle), &e);
handle_error(env, e);
}

extern "C"
JNIEXPORT jlong JNICALL
Java_com_intel_realsense_librealsense_Config_nResolve(JNIEnv *env, jclass type, jlong handle,
jlong pipelineHandle) {
rs2_error *e = NULL;
rs2_pipeline_profile* rv = rs2_config_resolve(reinterpret_cast<rs2_config *>(handle),
reinterpret_cast<rs2_pipeline *>(pipelineHandle), &e);
handle_error(env, e);
return reinterpret_cast<jlong>(rv);
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_intel_realsense_librealsense_Config_nCanResolve(JNIEnv *env, jclass type, jlong handle,
jlong pipelineHandle) {
rs2_error *e = NULL;
auto rv = rs2_config_can_resolve(reinterpret_cast<rs2_config *>(handle),
reinterpret_cast<rs2_pipeline *>(pipelineHandle), &e);
handle_error(env, e);
return rv > 0;
}
9 changes: 6 additions & 3 deletions src/android/jni/context.c → src/android/jni/context.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.

#include <jni.h>
#include "error.h"
#include "../../../include/librealsense2/rs.h"

JNIEXPORT jlong JNICALL
extern "C" JNIEXPORT jlong JNICALL
Java_com_intel_realsense_librealsense_RsContext_nCreate(JNIEnv *env, jclass type) {
rs2_error* e = NULL;
rs2_context* handle = rs2_create_context(RS2_API_VERSION, &e);
handle_error(env, e);
return (jlong) handle;
}

JNIEXPORT void JNICALL
extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_RsContext_nDelete(JNIEnv *env, jclass type, jlong handle) {
rs2_delete_context((rs2_context *) handle);
}

JNIEXPORT jlong JNICALL
extern "C" JNIEXPORT jlong JNICALL
Java_com_intel_realsense_librealsense_RsContext_nQueryDevices(JNIEnv *env, jclass type,
jlong handle) {
rs2_error* e = NULL;
Expand Down
31 changes: 0 additions & 31 deletions src/android/jni/device.c

This file was deleted.

63 changes: 63 additions & 0 deletions src/android/jni/device.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.

#include <jni.h>
#include <memory>
#include <vector>
#include "error.h"

#include "../../../include/librealsense2/rs.h"



extern "C" JNIEXPORT jboolean JNICALL
Java_com_intel_realsense_librealsense_Device_nSupportsInfo(JNIEnv *env, jclass type, jlong handle,
jint info) {
rs2_error *e = NULL;
auto rv = rs2_supports_device_info(reinterpret_cast<const rs2_device *>(handle),
static_cast<rs2_camera_info>(info), &e);
handle_error(env, e);
return rv > 0;
}

extern "C" JNIEXPORT jstring JNICALL
Java_com_intel_realsense_librealsense_Device_nGetInfo(JNIEnv *env, jclass type, jlong handle,
jint info) {
rs2_error *e = NULL;
const char* rv = rs2_get_device_info(reinterpret_cast<const rs2_device *>(handle),
static_cast<rs2_camera_info>(info), &e);
handle_error(env, e);
if (NULL == rv)
rv = "";
return env->NewStringUTF(rv);
}

extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_Device_nRelease(JNIEnv *env, jclass type, jlong handle) {
rs2_delete_device(reinterpret_cast<rs2_device *>(handle));
}

extern "C"
JNIEXPORT jlongArray JNICALL
Java_com_intel_realsense_librealsense_Device_nQuerySensors(JNIEnv *env, jclass type, jlong handle) {
rs2_error* e = nullptr;
std::shared_ptr<rs2_sensor_list> list(
rs2_query_sensors(reinterpret_cast<const rs2_device *>(handle), &e),
rs2_delete_sensor_list);
handle_error(env, e);

auto size = rs2_get_sensors_count(list.get(), &e);
handle_error(env, e);

std::vector<rs2_sensor*> sensors;
for (auto i = 0; i < size; i++)
{
auto s = rs2_create_sensor(list.get(), i, &e);
handle_error(env, e);
sensors.push_back(s);
}
jlongArray rv = env->NewLongArray(sensors.size());
env->SetLongArrayRegion(rv, 0, sensors.size(), reinterpret_cast<const jlong *>(sensors.data()));
return rv;

}
Loading