diff --git a/src/android/CMakeLists.txt b/src/android/CMakeLists.txt index 9ad4618041..45250af3d6 100644 --- a/src/android/CMakeLists.txt +++ b/src/android/CMakeLists.txt @@ -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})") diff --git a/src/android/jni/advanced_mode.cpp b/src/android/jni/advanced_mode.cpp new file mode 100644 index 0000000000..11214524df --- /dev/null +++ b/src/android/jni/advanced_mode.cpp @@ -0,0 +1,51 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + +#include +#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(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(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(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 raw_data_buffer( + rs2_serialize_json(reinterpret_cast(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(raw_data_buffer->buffer.data())); + return rv; +} diff --git a/src/android/jni/config.c b/src/android/jni/config.c deleted file mode 100644 index bb6fe376bf..0000000000 --- a/src/android/jni/config.c +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include "error.h" - -#include "../../../include/librealsense2/rs.h" -#include "../../../include/librealsense2/h/rs_config.h" - -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; -} - -JNIEXPORT void JNICALL -Java_com_intel_realsense_librealsense_Config_nDelete(JNIEnv *env, jclass type, jlong handle) { - rs2_delete_config((rs2_config *) handle); -} - -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((rs2_config *) handle, type, index, width, height, format, framerate, &e); - handle_error(env, e); -} - -JNIEXPORT void JNICALL -Java_com_intel_realsense_librealsense_Config_nEnableDeviceFromFile(JNIEnv *env, jclass type, - jlong handle, - jstring filePath_) { - const char *filePath = (*env)->GetStringUTFChars(env, filePath_, 0); - - rs2_error *e = NULL; - rs2_config_enable_device_from_file((rs2_config *) handle, filePath, &e); - handle_error(env, e); - - (*env)->ReleaseStringUTFChars(env, filePath_, filePath); -} - -JNIEXPORT void JNICALL -Java_com_intel_realsense_librealsense_Config_nEnableRecordToFile(JNIEnv *env, jclass type, - jlong handle, jstring filePath_) { - const char *filePath = (*env)->GetStringUTFChars(env, filePath_, 0); - - rs2_error *e = NULL; - rs2_config_enable_record_to_file((rs2_config *) handle, filePath, &e); - handle_error(env, e); - - (*env)->ReleaseStringUTFChars(env, filePath_, filePath); -} - -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((rs2_config *) handle, streamType, &e); - handle_error(env, e); -} - -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((rs2_config *) handle, &e); - handle_error(env, e); -} - -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((rs2_config *) handle, &e); - handle_error(env, e); -} diff --git a/src/android/jni/config.cpp b/src/android/jni/config.cpp new file mode 100644 index 0000000000..d0fab4a9f8 --- /dev/null +++ b/src/android/jni/config.cpp @@ -0,0 +1,104 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + +#include +#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(handle), static_cast(type), index, width, height, + static_cast(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(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(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(handle), + static_cast(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(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(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(handle), + reinterpret_cast(pipelineHandle), &e); + handle_error(env, e); + return reinterpret_cast(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(handle), + reinterpret_cast(pipelineHandle), &e); + handle_error(env, e); + return rv > 0; +} diff --git a/src/android/jni/context.c b/src/android/jni/context.cpp similarity index 78% rename from src/android/jni/context.c rename to src/android/jni/context.cpp index f5d895f84b..aa30b7b0e9 100644 --- a/src/android/jni/context.c +++ b/src/android/jni/context.cpp @@ -1,8 +1,11 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include #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); @@ -10,12 +13,12 @@ Java_com_intel_realsense_librealsense_RsContext_nCreate(JNIEnv *env, jclass type 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; diff --git a/src/android/jni/device.c b/src/android/jni/device.c deleted file mode 100644 index f1dbce7318..0000000000 --- a/src/android/jni/device.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include "error.h" - -#include "../../../include/librealsense2/rs.h" - - - -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(handle, info, &e); - handle_error(env, e); - return rv > 0; -} - -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(handle, info, &e); - handle_error(env, e); - if(NULL == rv) - rv = ""; - return (*env)->NewStringUTF(env, rv); -} - -JNIEXPORT void JNICALL -Java_com_intel_realsense_librealsense_Device_nRelease(JNIEnv *env, jclass type, jlong handle) { - rs2_delete_device((rs2_device *) handle); -} diff --git a/src/android/jni/device.cpp b/src/android/jni/device.cpp new file mode 100644 index 0000000000..5077753d4b --- /dev/null +++ b/src/android/jni/device.cpp @@ -0,0 +1,63 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + +#include +#include +#include +#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(handle), + static_cast(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(handle), + static_cast(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(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 list( + rs2_query_sensors(reinterpret_cast(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 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(sensors.data())); + return rv; + +} diff --git a/src/android/jni/device_list.c b/src/android/jni/device_list.cpp similarity index 61% rename from src/android/jni/device_list.c rename to src/android/jni/device_list.cpp index 7a14c1301b..f9f97313a3 100644 --- a/src/android/jni/device_list.c +++ b/src/android/jni/device_list.cpp @@ -1,36 +1,40 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include #include "error.h" #include "../../../include/librealsense2/rs.h" -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_DeviceList_nGetDeviceCount(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - auto rv = rs2_get_device_count(handle, &e); + auto rv = rs2_get_device_count(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_DeviceList_nCreateDevice(JNIEnv *env, jclass type, jlong handle, jint index) { rs2_error *e = NULL; - rs2_device* rv = rs2_create_device(handle, index, &e); + rs2_device* rv = rs2_create_device(reinterpret_cast(handle), index, &e); handle_error(env, e); return (jlong)rv; } -JNIEXPORT jboolean JNICALL +extern "C" JNIEXPORT jboolean JNICALL Java_com_intel_realsense_librealsense_DeviceList_nContainsDevice(JNIEnv *env, jclass type, jlong handle, jlong deviceHandle) { rs2_error *e = NULL; - auto rv = rs2_device_list_contains(handle, deviceHandle, &e); + auto rv = rs2_device_list_contains(reinterpret_cast(handle), + reinterpret_cast(deviceHandle), &e); handle_error(env, e); return rv > 1; } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_DeviceList_nRelease(JNIEnv *env, jclass type, jlong handle) { rs2_delete_device_list((rs2_device_list *) handle); } diff --git a/src/android/jni/error.c b/src/android/jni/error.cpp similarity index 82% rename from src/android/jni/error.c rename to src/android/jni/error.cpp index 69a71e6b0e..bf5c7abd5a 100644 --- a/src/android/jni/error.c +++ b/src/android/jni/error.cpp @@ -1,3 +1,6 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include "error.h" void handle_error(JNIEnv *env, rs2_error* error){ @@ -14,6 +17,6 @@ void handle_error(JNIEnv *env, rs2_error* error){ case RS2_EXCEPTION_TYPE_DEVICE_IN_RECOVERY_MODE: message = "RS2_EXCEPTION_TYPE_DEVICE_IN_RECOVERY_MODE"; break; default: message = "UNKNOWN_ERROR"; break; } - (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/RuntimeException"), message); + env->ThrowNew(env->FindClass("java/lang/RuntimeException"), message); } } diff --git a/src/android/jni/error.h b/src/android/jni/error.h index d0b83b6be9..6286503558 100644 --- a/src/android/jni/error.h +++ b/src/android/jni/error.h @@ -1,5 +1,6 @@ /* License: Apache 2.0. See LICENSE file in root directory. */ /* Copyright(c) 2019 Intel Corporation. All Rights Reserved. */ + #ifndef LIBREALSENSE_JNI_ERROR_H #define LIBREALSENSE_JNI_ERROR_H diff --git a/src/android/jni/frame.c b/src/android/jni/frame.cpp similarity index 60% rename from src/android/jni/frame.c rename to src/android/jni/frame.cpp index a4d828b670..b326445d2c 100644 --- a/src/android/jni/frame.c +++ b/src/android/jni/frame.cpp @@ -1,126 +1,133 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include #include "error.h" #include "../../../include/librealsense2/rs.h" -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Frame_nAddRef(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; rs2_frame_add_ref((rs2_frame *) handle, &e); handle_error(env, e); } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Frame_nRelease(JNIEnv *env, jclass type, jlong handle) { rs2_release_frame((rs2_frame *) handle); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_Frame_nGetStreamProfile(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - const rs2_stream_profile *rv = rs2_get_frame_stream_profile((const rs2_frame *) handle, &e); + const rs2_stream_profile *rv = rs2_get_frame_stream_profile( + reinterpret_cast(handle), &e); handle_error(env, e); - return rv; + return (jlong) rv; } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Frame_nGetData(JNIEnv *env, jclass type, jlong handle, jbyteArray data_) { - jsize length = (*env)->GetArrayLength(env, data_); + jsize length = env->GetArrayLength(data_); rs2_error *e = NULL; - (*env)->SetByteArrayRegion(env, data_, 0, length, rs2_get_frame_data((const rs2_frame *) handle, &e)); + env->SetByteArrayRegion(data_, 0, length, static_cast(rs2_get_frame_data( + reinterpret_cast(handle), &e))); handle_error(env, e); } -JNIEXPORT jboolean JNICALL +extern "C" JNIEXPORT jboolean JNICALL Java_com_intel_realsense_librealsense_Frame_nIsFrameExtendableTo(JNIEnv *env, jclass type, jlong handle, jint extension) { rs2_error *e = NULL; - int rv = rs2_is_frame_extendable_to(handle, extension, &e); + int rv = rs2_is_frame_extendable_to(reinterpret_cast(handle), + static_cast(extension), &e); handle_error(env, e); return rv; } -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_VideoFrame_nGetWidth(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - int rv = rs2_get_frame_width(handle, &e); + int rv = rs2_get_frame_width(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_VideoFrame_nGetHeight(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - int rv = rs2_get_frame_height(handle, &e); + int rv = rs2_get_frame_height(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_VideoFrame_nGetStride(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - int rv = rs2_get_frame_stride_in_bytes((const rs2_frame *) handle, &e); + int rv = rs2_get_frame_stride_in_bytes(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_VideoFrame_nGetBitsPerPixel(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - int rv = rs2_get_frame_bits_per_pixel((const rs2_frame *) handle, &e); + int rv = rs2_get_frame_bits_per_pixel(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_Frame_nGetNumber(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - unsigned long long rv = rs2_get_frame_number((const rs2_frame *) handle, &e); + unsigned long long rv = rs2_get_frame_number(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jfloat JNICALL +extern "C" JNIEXPORT jfloat JNICALL Java_com_intel_realsense_librealsense_DepthFrame_nGetDistance(JNIEnv *env, jclass type, jlong handle, jint x, jint y) { rs2_error *e = NULL; - float rv = rs2_depth_frame_get_distance((const rs2_frame *) handle, x, y, &e); + float rv = rs2_depth_frame_get_distance(reinterpret_cast(handle), x, y, &e); handle_error(env, e); return rv; } -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_Points_nGetCount(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - int rv = rs2_get_frame_points_count((const rs2_frame *) handle, &e); + int rv = rs2_get_frame_points_count(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jdouble JNICALL +extern "C" JNIEXPORT jdouble JNICALL Java_com_intel_realsense_librealsense_Frame_nGetTimestamp(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - double rv = rs2_get_frame_timestamp((const rs2_frame *) handle, &e); + double rv = rs2_get_frame_timestamp(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_Frame_nGetTimestampDomain(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - int rv = rs2_get_frame_timestamp_domain((const rs2_frame *) handle, &e); + int rv = rs2_get_frame_timestamp_domain(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_Frame_nGetMetadata(JNIEnv *env, jclass type, jlong handle, jint metadata_type) { rs2_error *e = NULL; - long rv = rs2_get_frame_metadata((const rs2_frame *) handle, metadata_type, &e); + long rv = rs2_get_frame_metadata(reinterpret_cast(handle), + static_cast(metadata_type), &e); handle_error(env, e); return rv; } diff --git a/src/android/jni/frame_queue.c b/src/android/jni/frame_queue.cpp similarity index 84% rename from src/android/jni/frame_queue.c rename to src/android/jni/frame_queue.cpp index c8e3a31875..9c88b3081b 100644 --- a/src/android/jni/frame_queue.c +++ b/src/android/jni/frame_queue.cpp @@ -1,9 +1,12 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include #include "error.h" #include "../../../include/librealsense2/rs.h" -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_FrameQueue_nCreate(JNIEnv *env, jclass type, jint capacity) { rs2_error *e = NULL; rs2_frame_queue *rv = rs2_create_frame_queue(capacity, &e); @@ -11,12 +14,12 @@ Java_com_intel_realsense_librealsense_FrameQueue_nCreate(JNIEnv *env, jclass typ return (jlong) rv; } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_FrameQueue_nDelete(JNIEnv *env, jclass type, jlong handle) { rs2_delete_frame_queue((rs2_frame_queue *) handle); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_FrameQueue_nPollForFrame(JNIEnv *env, jclass type, jlong handle) { rs2_frame *output_frame = NULL; @@ -26,7 +29,7 @@ Java_com_intel_realsense_librealsense_FrameQueue_nPollForFrame(JNIEnv *env, jcla return (jlong) (rv ? output_frame : 0); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_FrameQueue_nWaitForFrames(JNIEnv *env, jclass type, jlong handle, jint timeout) { rs2_error *e = NULL; @@ -35,7 +38,7 @@ Java_com_intel_realsense_librealsense_FrameQueue_nWaitForFrames(JNIEnv *env, jcl return (jlong) rv; } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_FrameQueue_nEnqueue(JNIEnv *env, jclass type, jlong handle, jlong frameHandle) { rs2_error *e = NULL; diff --git a/src/android/jni/frameset.c b/src/android/jni/frameset.cpp similarity index 62% rename from src/android/jni/frameset.c rename to src/android/jni/frameset.cpp index edfdfa6e67..354d81a8f7 100644 --- a/src/android/jni/frameset.c +++ b/src/android/jni/frameset.cpp @@ -1,34 +1,37 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include #include "error.h" #include "../../../include/librealsense2/rs.h" -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_FrameSet_nAddRef(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; rs2_frame_add_ref((rs2_frame *) handle, &e); handle_error(env, e); } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_FrameSet_nRelease(JNIEnv *env, jclass type, jlong handle) { - rs2_release_frame((rs2_frame *) handle); + rs2_release_frame(reinterpret_cast(handle)); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_FrameSet_nExtractFrame(JNIEnv *env, jclass type, jlong handle, jint index) { rs2_error *e = NULL; - rs2_frame *rv = rs2_extract_frame((rs2_frame *) handle, index, &e); + rs2_frame *rv = rs2_extract_frame(reinterpret_cast(handle), index, &e); handle_error(env, e); - return rv; + return reinterpret_cast(rv); } -JNIEXPORT jint JNICALL +extern "C" JNIEXPORT jint JNICALL Java_com_intel_realsense_librealsense_FrameSet_nFrameCount(JNIEnv *env, jclass type, jlong handle) { rs2_error *e = NULL; - int rv = rs2_embedded_frames_count((rs2_frame *) handle, &e); + int rv = rs2_embedded_frames_count(reinterpret_cast(handle), &e); handle_error(env, e); return rv; } \ No newline at end of file diff --git a/src/android/jni/options.c b/src/android/jni/options.cpp similarity index 50% rename from src/android/jni/options.c rename to src/android/jni/options.cpp index 1e5ce74777..ad3f5c34e0 100644 --- a/src/android/jni/options.c +++ b/src/android/jni/options.cpp @@ -1,9 +1,12 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include #include "error.h" #include "../../../include/librealsense2/rs.h" -JNIEXPORT jboolean JNICALL +extern "C" JNIEXPORT jboolean JNICALL Java_com_intel_realsense_librealsense_Options_nSupports(JNIEnv *env, jclass type, jlong handle, jint option) { rs2_error* e = NULL; auto rv = rs2_supports_option((const rs2_options *) handle, (rs2_option) option, &e); @@ -11,24 +14,25 @@ Java_com_intel_realsense_librealsense_Options_nSupports(JNIEnv *env, jclass type return rv > 0; } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Options_nSetValue(JNIEnv *env, jclass type, jlong handle, jint option, jfloat value) { rs2_error* e = NULL; - rs2_set_option((const rs2_options *) handle, (rs2_option) option, value, &e); + rs2_set_option(reinterpret_cast(handle), static_cast(option), value, &e); handle_error(env, e); } -JNIEXPORT jfloat JNICALL +extern "C" JNIEXPORT jfloat JNICALL Java_com_intel_realsense_librealsense_Options_nGetValue(JNIEnv *env, jclass type, jlong handle, jint option) { rs2_error* e = NULL; - float rv = rs2_get_option((const rs2_options *) handle, (rs2_option) option, &e); + float rv = rs2_get_option(reinterpret_cast(handle), + static_cast(option), &e); handle_error(env, e); return rv; } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Options_nGetRange(JNIEnv *env, jclass type, jlong handle, jint option, jobject outParams) { float min = -1; @@ -37,46 +41,50 @@ Java_com_intel_realsense_librealsense_Options_nGetRange(JNIEnv *env, jclass type float def = -1; rs2_error *e = NULL; - rs2_get_option_range((const rs2_options *) handle, (rs2_option) option, &min, &max, &step, &def, &e); + rs2_get_option_range(reinterpret_cast(handle), + static_cast(option), &min, &max, &step, &def, &e); handle_error(env, e); - jclass clazz = (*env)->GetObjectClass(env, outParams); + jclass clazz = env->GetObjectClass(outParams); - jfieldID minField = (*env)->GetFieldID(env, clazz, "min", "F"); - jfieldID maxField = (*env)->GetFieldID(env, clazz, "max", "F"); - jfieldID stepField = (*env)->GetFieldID(env, clazz, "step", "F"); - jfieldID defField = (*env)->GetFieldID(env, clazz, "def", "F"); + jfieldID minField = env->GetFieldID(clazz, "min", "F"); + jfieldID maxField = env->GetFieldID(clazz, "max", "F"); + jfieldID stepField = env->GetFieldID(clazz, "step", "F"); + jfieldID defField = env->GetFieldID(clazz, "def", "F"); - (*env)->SetFloatField(env, outParams, minField, min); - (*env)->SetFloatField(env, outParams, maxField, max); - (*env)->SetFloatField(env, outParams, stepField, step); - (*env)->SetFloatField(env, outParams, defField, def); + env->SetFloatField(outParams, minField, min); + env->SetFloatField(outParams, maxField, max); + env->SetFloatField(outParams, stepField, step); + env->SetFloatField(outParams, defField, def); } -JNIEXPORT jboolean JNICALL +extern "C" JNIEXPORT jboolean JNICALL Java_com_intel_realsense_librealsense_Options_nIsReadOnly(JNIEnv *env, jclass type, jlong handle, jint option) { rs2_error* e = NULL; - int rv = rs2_is_option_read_only((const rs2_options *) handle, (rs2_option) option, &e); + int rv = rs2_is_option_read_only(reinterpret_cast(handle), + static_cast(option), &e); handle_error(env, e); return rv > 0; } -JNIEXPORT jstring JNICALL +extern "C" JNIEXPORT jstring JNICALL Java_com_intel_realsense_librealsense_Options_nGetDescription(JNIEnv *env, jclass type, jlong handle, jint option) { rs2_error* e = NULL; - const char *rv = rs2_get_option_description((const rs2_options *) handle, (rs2_option) option, &e); + const char *rv = rs2_get_option_description(reinterpret_cast(handle), + static_cast(option), &e); handle_error(env, e); - return (*env)->NewStringUTF(env, rv); + return env->NewStringUTF(rv); } -JNIEXPORT jstring JNICALL +extern "C" JNIEXPORT jstring JNICALL Java_com_intel_realsense_librealsense_Options_nGetValueDescription(JNIEnv *env, jclass type, jlong handle, jint option, jfloat value) { rs2_error* e = NULL; - const char *rv = rs2_get_option_value_description((const rs2_options *) handle, (rs2_option) option, value, &e); + const char *rv = rs2_get_option_value_description(reinterpret_cast(handle), + static_cast(option), value, &e); handle_error(env, e); - return (*env)->NewStringUTF(env, rv); + return env->NewStringUTF(rv); } diff --git a/src/android/jni/pipeline.c b/src/android/jni/pipeline.cpp similarity index 54% rename from src/android/jni/pipeline.c rename to src/android/jni/pipeline.cpp index 18edce985e..507e1225cf 100644 --- a/src/android/jni/pipeline.c +++ b/src/android/jni/pipeline.cpp @@ -1,58 +1,62 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include #include "error.h" #include "../../../include/librealsense2/rs.h" #include "../../../include/librealsense2/h/rs_pipeline.h" -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_Pipeline_nCreate(JNIEnv *env, jclass type, jlong context) { rs2_error* e = NULL; - rs2_pipeline* rv = rs2_create_pipeline(context, &e); + rs2_pipeline* rv = rs2_create_pipeline(reinterpret_cast(context), &e); handle_error(env, e); - return rv; + return reinterpret_cast(rv); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_Pipeline_nStart(JNIEnv *env, jclass type, jlong handle) { rs2_error* e = NULL; - long rv = rs2_pipeline_start(handle, &e); + auto rv = rs2_pipeline_start(reinterpret_cast(handle), &e); handle_error(env, e); - return rv; + return reinterpret_cast(rv); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_Pipeline_nStartWithConfig(JNIEnv *env, jclass type, jlong handle, jlong configHandle) { rs2_error *e = NULL; - long rv = rs2_pipeline_start_with_config((rs2_pipeline *) handle, configHandle, &e); + auto rv = rs2_pipeline_start_with_config(reinterpret_cast(handle), + reinterpret_cast(configHandle), &e); handle_error(env, e); - return rv; + return reinterpret_cast(rv); } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Pipeline_nStop(JNIEnv *env, jclass type, jlong handle) { rs2_error* e = NULL; - rs2_pipeline_stop((rs2_pipeline *) handle, &e); + rs2_pipeline_stop(reinterpret_cast(handle), &e); handle_error(env, e); } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_Pipeline_nDelete(JNIEnv *env, jclass type, jlong handle) { - rs2_delete_pipeline((rs2_pipeline *) handle); + rs2_delete_pipeline(reinterpret_cast(handle)); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_Pipeline_nWaitForFrames(JNIEnv *env, jclass type, jlong handle, jint timeout) { rs2_error* e = NULL; - rs2_frame *rv = rs2_pipeline_wait_for_frames((rs2_pipeline *) handle, timeout, &e); + rs2_frame *rv = rs2_pipeline_wait_for_frames(reinterpret_cast(handle), timeout, &e); handle_error(env, e); - return rv; + return reinterpret_cast(rv); } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_PipelineProfile_nDelete(JNIEnv *env, jclass type, jlong handle) { - rs2_delete_pipeline_profile(handle); + rs2_delete_pipeline_profile(reinterpret_cast(handle)); } diff --git a/src/android/jni/processing.c b/src/android/jni/processing.cpp similarity index 56% rename from src/android/jni/processing.c rename to src/android/jni/processing.cpp index f936ee684d..b2bdf43e3d 100644 --- a/src/android/jni/processing.c +++ b/src/android/jni/processing.cpp @@ -1,41 +1,45 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + #include #include "error.h" #include "../../../include/librealsense2/rs.h" -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_ProcessingBlock_nDelete(JNIEnv *env, jclass type, jlong handle) { - rs2_delete_processing_block(handle); + rs2_delete_processing_block(reinterpret_cast(handle)); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_Colorizer_nCreate(JNIEnv *env, jclass type, jlong queueHandle) { rs2_error *e = NULL; rs2_processing_block *rv = rs2_create_colorizer(&e); handle_error(env, e); - rs2_start_processing_queue(rv, queueHandle, &e); + rs2_start_processing_queue(rv, reinterpret_cast(queueHandle), &e); handle_error(env, e); - return (jlong) rv; + return reinterpret_cast(rv); } -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_com_intel_realsense_librealsense_Decimation_nCreate(JNIEnv *env, jclass type, jlong queueHandle) { rs2_error *e = NULL; rs2_processing_block *rv = rs2_create_decimation_filter_block(&e); handle_error(env, e); - rs2_start_processing_queue(rv, queueHandle, &e); + rs2_start_processing_queue(rv, reinterpret_cast(queueHandle), &e); handle_error(env, e); - return (jlong) rv; + return reinterpret_cast(rv); } -JNIEXPORT void JNICALL +extern "C" JNIEXPORT void JNICALL Java_com_intel_realsense_librealsense_ProcessingBlock_nInvoke(JNIEnv *env, jclass type, jlong handle, jlong frameHandle) { rs2_error *e = NULL; - rs2_frame_add_ref((rs2_frame *) frameHandle, &e); + rs2_frame_add_ref(reinterpret_cast(frameHandle), &e); handle_error(env, e); - rs2_process_frame((rs2_processing_block *) handle, (rs2_frame *) frameHandle, &e); + rs2_process_frame(reinterpret_cast(handle), + reinterpret_cast(frameHandle), &e); handle_error(env, e); } diff --git a/src/android/jni/sensor.cpp b/src/android/jni/sensor.cpp new file mode 100644 index 0000000000..6e227e7eee --- /dev/null +++ b/src/android/jni/sensor.cpp @@ -0,0 +1,42 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + +#include +#include +#include +#include "error.h" + +#include "../../../include/librealsense2/rs.h" + +extern "C" +JNIEXPORT void JNICALL +Java_com_intel_realsense_librealsense_Sensor_nRelease(JNIEnv *env, jclass type, jlong handle) { + rs2_delete_sensor(reinterpret_cast(handle)); +} + +extern "C" +JNIEXPORT jlongArray JNICALL +Java_com_intel_realsense_librealsense_Sensor_nGetStreamProfiles(JNIEnv *env, jclass type, + jlong handle) { + rs2_error* e = nullptr; + std::shared_ptr list( + rs2_get_stream_profiles(reinterpret_cast(handle), &e), + rs2_delete_stream_profiles_list); + handle_error(env, e); + + auto size = rs2_get_stream_profiles_count(list.get(), &e); + handle_error(env, e); + + std::vector profiles; + + for (auto i = 0; i < size; i++) + { + auto sp = rs2_get_stream_profile(list.get(), i, &e); + handle_error(env, e); + profiles.push_back(sp); + } + + jlongArray rv = env->NewLongArray(profiles.size()); + env->SetLongArrayRegion(rv, 0, profiles.size(), reinterpret_cast(profiles.data())); + return rv; +} diff --git a/src/android/jni/stream_profile.c b/src/android/jni/stream_profile.c deleted file mode 100644 index 28d0db0bda..0000000000 --- a/src/android/jni/stream_profile.c +++ /dev/null @@ -1,57 +0,0 @@ -#include -#include "error.h" -#include "../../../include/librealsense2/rs.h" - -JNIEXPORT void JNICALL -Java_com_intel_realsense_librealsense_StreamProfile_nGetProfile(JNIEnv *env, jclass type, - jlong handle, jobject params) { - rs2_stream stream_type = RS2_STREAM_ANY; - rs2_format format = RS2_FORMAT_ANY; - int index = -1; - int uniqueId = -1; - int frameRate = -1; - rs2_error *e = NULL; - - rs2_get_stream_profile_data((const rs2_stream_profile *) handle, &stream_type, &format, &index, &uniqueId, &frameRate, &e); - handle_error(env, e); - - jclass clazz = (*env)->GetObjectClass(env, params); - - jfieldID typeField = (*env)->GetFieldID(env, clazz, "type", "I"); - jfieldID formatField = (*env)->GetFieldID(env, clazz, "format", "I"); - jfieldID indexField = (*env)->GetFieldID(env, clazz, "index", "I"); - jfieldID uniqueIdField = (*env)->GetFieldID(env, clazz, "uniqueId", "I"); - jfieldID frameRateField = (*env)->GetFieldID(env, clazz, "frameRate", "I"); - - (*env)->SetIntField(env, params, typeField, stream_type); - (*env)->SetIntField(env, params, formatField, format); - (*env)->SetIntField(env, params, indexField, index); - (*env)->SetIntField(env, params, uniqueIdField, uniqueId); - (*env)->SetIntField(env, params, frameRateField, frameRate); -} - -JNIEXPORT void JNICALL -Java_com_intel_realsense_librealsense_VideoStreamProfile_nGetResolution(JNIEnv *env, jclass type, - jlong handle, - jobject params) { - int width = -1; - int height = -1; - rs2_error *e = NULL; - - rs2_get_video_stream_resolution((const rs2_stream_profile *) handle, &width, &height, &e); - handle_error(env, e); - - jclass clazz = (*env)->GetObjectClass(env, params); - - jfieldID widthField = (*env)->GetFieldID(env, clazz, "width", "I"); - jfieldID heightField = (*env)->GetFieldID(env, clazz, "height", "I"); - - (*env)->SetIntField(env, params, widthField, width); - (*env)->SetIntField(env, params, heightField, height); -} - -JNIEXPORT void JNICALL -Java_com_intel_realsense_librealsense_StreamProfile_nDelete(JNIEnv *env, jclass type, - jlong handle) { - rs2_delete_stream_profile((rs2_stream_profile *) handle); -} \ No newline at end of file diff --git a/src/android/jni/stream_profile.cpp b/src/android/jni/stream_profile.cpp new file mode 100644 index 0000000000..155e972550 --- /dev/null +++ b/src/android/jni/stream_profile.cpp @@ -0,0 +1,72 @@ +// License: Apache 2.0. See LICENSE file in root directory. +// Copyright(c) 2019 Intel Corporation. All Rights Reserved. + +#include +#include "error.h" +#include "../../../include/librealsense2/rs.h" + +extern "C" JNIEXPORT void JNICALL +Java_com_intel_realsense_librealsense_StreamProfile_nGetProfile(JNIEnv *env, jclass type, + jlong handle, jobject params) { + rs2_stream stream_type = RS2_STREAM_ANY; + rs2_format format = RS2_FORMAT_ANY; + int index = -1; + int uniqueId = -1; + int frameRate = -1; + rs2_error *e = NULL; + + rs2_get_stream_profile_data((const rs2_stream_profile *) handle, &stream_type, &format, &index, &uniqueId, &frameRate, &e); + handle_error(env, e); + + jclass clazz = env->GetObjectClass(params); + + jfieldID typeField = env->GetFieldID(clazz, "type", "I"); + jfieldID formatField = env->GetFieldID(clazz, "format", "I"); + jfieldID indexField = env->GetFieldID(clazz, "index", "I"); + jfieldID uniqueIdField = env->GetFieldID(clazz, "uniqueId", "I"); + jfieldID frameRateField = env->GetFieldID(clazz, "frameRate", "I"); + + env->SetIntField(params, typeField, stream_type); + env->SetIntField(params, formatField, format); + env->SetIntField(params, indexField, index); + env->SetIntField(params, uniqueIdField, uniqueId); + env->SetIntField(params, frameRateField, frameRate); +} + +extern "C" JNIEXPORT void JNICALL +Java_com_intel_realsense_librealsense_VideoStreamProfile_nGetResolution(JNIEnv *env, jclass type, + jlong handle, + jobject params) { + int width = -1; + int height = -1; + rs2_error *e = NULL; + + rs2_get_video_stream_resolution((const rs2_stream_profile *) handle, &width, &height, &e); + handle_error(env, e); + + jclass clazz = env->GetObjectClass(params); + + jfieldID widthField = env->GetFieldID(clazz, "width", "I"); + jfieldID heightField = env->GetFieldID(clazz, "height", "I"); + + env->SetIntField(params, widthField, width); + env->SetIntField(params, heightField, height); +} + +extern "C" JNIEXPORT void JNICALL +Java_com_intel_realsense_librealsense_StreamProfile_nDelete(JNIEnv *env, jclass type, + jlong handle) { + rs2_delete_stream_profile((rs2_stream_profile *) handle); +} + +extern "C" +JNIEXPORT jboolean JNICALL +Java_com_intel_realsense_librealsense_StreamProfile_nIsProfileExtendableTo(JNIEnv *env, jclass type, + jlong handle, + jint extension) { + rs2_error *e = NULL; + int rv = rs2_stream_profile_is(reinterpret_cast(handle), + static_cast(extension), &e); + handle_error(env, e); + return rv; +} diff --git a/src/android/usb_host/usb_pipe.cpp b/src/android/usb_host/usb_pipe.cpp index d4c0d9c504..0aa6e0592d 100644 --- a/src/android/usb_host/usb_pipe.cpp +++ b/src/android/usb_host/usb_pipe.cpp @@ -13,6 +13,12 @@ #include "../../types.h" #define INTERRUPT_BUFFER_SIZE 1024 +#define CLEAR_FEATURE 0x01 +#define UVC_FEATURE 0x02 +#define INTERRUPT_PACKET_SIZE 6 +#define INTERRUPT_NOTIFICATION_INDEX 5 +#define DEPTH_SENSOR_OVERFLOW_NOTIFICATION 11 +#define COLOR_SENSOR_OVERFLOW_NOTIFICATION 13 using namespace librealsense::usb_host; @@ -30,10 +36,15 @@ usb_pipe::~usb_pipe() bool usb_pipe::reset() { - bool rv = usb_device_control_transfer(_device, - 0x02, //UVC_FEATURE, - 0x01, //CLEAR_FEATURE - 0, _endpoint.get_endpoint_address(), NULL, 0, 10) == UVC_SUCCESS; + int requestType = UVC_FEATURE; + int request = CLEAR_FEATURE; + int value = 0; + int index = _endpoint.get_endpoint_address(); + void* buffer = NULL; + int length = 0; + unsigned int timeout = 10; + bool rv = usb_device_control_transfer(_device, requestType, request, value, + index, buffer, length, timeout) == UVC_SUCCESS; if(rv) LOG_DEBUG("USB pipe " << (int)_endpoint.get_endpoint_address() << " reset successfully"); else @@ -42,24 +53,7 @@ bool usb_pipe::reset() } size_t usb_pipe::read_pipe(uint8_t *buffer, size_t buffer_len, unsigned int timeout_ms) { - using namespace std::chrono; - int bytes_copied = -1; - // Wait until pipe gets data - std::unique_lock lk(_mutex); - submit_request(buffer, buffer_len); - - auto res = _cv.wait_for(lk, std::chrono::milliseconds(timeout_ms), [&] { return _received; }); - _received = false; - if (res == true) { - bytes_copied = _request->actual_length; - } - else { - LOG_WARNING("Timeout reached waiting for response!"); - usb_request_cancel(_request.get()); - } - lk.unlock(); - - return bytes_copied; + return usb_device_bulk_transfer(_device, _endpoint.get_endpoint_address(), buffer, buffer_len, timeout_ms); } void usb_pipe::queue_finished_request(usb_request* response) { @@ -69,8 +63,22 @@ void usb_pipe::queue_finished_request(usb_request* response) { _received = true; lk.unlock(); _cv.notify_all(); - if(_interrupt_buffer.size() > 0) + if(_interrupt_buffer.size() > 0) { + //Log fatal notifications, this is currently handles only D4xx devices. + //TODO push HW notifications to librealsense + if(response->actual_length > 0){ + std::string buff = ""; + for(int i = 0; i < response->actual_length; i++) + buff += std::to_string(((uint8_t*)response->buffer)[i]) + ", "; + LOG_DEBUG("interrupt_request: " << buff.c_str()); + if(response->actual_length == INTERRUPT_PACKET_SIZE){ + auto sts = ((uint8_t*)response->buffer)[INTERRUPT_NOTIFICATION_INDEX]; + if(sts == DEPTH_SENSOR_OVERFLOW_NOTIFICATION || sts == COLOR_SENSOR_OVERFLOW_NOTIFICATION) + LOG_ERROR("overflow status sent from the device"); + } + } queue_interrupt_request(); + } } void usb_pipe::submit_request(uint8_t *buffer, size_t buffer_len) { @@ -96,4 +104,4 @@ void usb_pipe::listen_to_interrupts() _interrupt_buffer = std::vector(INTERRUPT_BUFFER_SIZE); queue_interrupt_request(); } -} \ No newline at end of file +} diff --git a/wrappers/android/librealsense/.gitignore b/wrappers/android/librealsense/.gitignore index 432dcbfeef..37e9eccca3 100644 --- a/wrappers/android/librealsense/.gitignore +++ b/wrappers/android/librealsense/.gitignore @@ -4,6 +4,7 @@ *.iml *.user +!*.json !gradle-wrapper.jar .externalNativ diff --git a/wrappers/android/librealsense/src/main/assets/presets/BodyScanPreset.json b/wrappers/android/librealsense/src/main/assets/presets/BodyScanPreset.json new file mode 100644 index 0000000000..b9b709c974 --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/BodyScanPreset.json @@ -0,0 +1,47 @@ +{ + "param-censususize": "9", + "param-censusvsize": "9", + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 0, + "param-disableslorightcolor": 0, + "param-lambdaad": 833.00, + "param-lambdacensus": 26.0, + "param-leftrightthreshold": 11, + "param-maxscorethreshb": 632, + "param-medianthreshold": 554, + "param-minscorethresha": 1, + "param-neighborthresh": 126, + "param-raumine": 7, + "param-rauminn": 1, + "param-rauminnssum": 7, + "param-raumins": 3, + "param-rauminw": 5, + "param-rauminwesum": 12, + "param-regioncolorthresholdb": 0.26379450841061053, + "param-regioncolorthresholdg": 0.9806201235330119, + "param-regioncolorthresholdr": 0.013826660558426103, + "param-regionshrinku": 4, + "param-regionshrinkv": 1, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 4, + "param-robbinsmonroincrement": 19, + "param-rsmdiffthreshold": 1.0367311077984247, + "param-rsmrauslodiffthreshold": 0.8955340364089305, + "param-rsmremovethreshold": 0.7604262237190709, + "param-scanlineedgetaub": 105, + "param-scanlineedgetaug": 442, + "param-scanlineedgetaur": 46, + "param-scanlinep1": 93, + "param-scanlinep1onediscon": 70, + "param-scanlinep1twodiscon": 92, + "param-scanlinep2": 473, + "param-scanlinep2onediscon": 123, + "param-scanlinep2twodiscon": 409, + "param-secondpeakdelta": 665, + "param-texturecountthresh": 28, + "param-texturedifferencethresh": 0, + "param-usersm": 1 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/D415_RemoveIR.json b/wrappers/android/librealsense/src/main/assets/presets/D415_RemoveIR.json new file mode 100644 index 0000000000..d53d40d1f6 --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/D415_RemoveIR.json @@ -0,0 +1,14 @@ +{ + "aux-param-colorcorrection1": "0.520508", + "aux-param-colorcorrection10": "-2.000000", + "aux-param-colorcorrection11": "0.575195", + "aux-param-colorcorrection12": "-0.411133", + "aux-param-colorcorrection2": "1.990234", + "aux-param-colorcorrection3": "1.506836", + "aux-param-colorcorrection4": "-2.000000", + "aux-param-colorcorrection5": "-2.000000", + "aux-param-colorcorrection6": "-0.082031", + "aux-param-colorcorrection7": "1.123047", + "aux-param-colorcorrection8": "1.013672", + "aux-param-colorcorrection9": "1.698242" +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/DefaultPreset_D415.json b/wrappers/android/librealsense/src/main/assets/presets/DefaultPreset_D415.json new file mode 100644 index 0000000000..b31ad880d9 --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/DefaultPreset_D415.json @@ -0,0 +1,68 @@ +{ + "param-disableraucolor": "0", + "param-disablesadcolor": "0", + "param-disablesadnormalize": "0", + "param-disablesloleftcolor": "0", + "param-disableslorightcolor": "0", + "param-lambdaad": "800", + "param-lambdacensus": "26", + "param-leftrightthreshold": "24", + "param-maxscorethreshb": "2047", + "param-medianthreshold": "500", + "param-minscorethresha": "1", + "param-neighborthresh": "7", + "param-robbinsmonrodecrement": "10", + "param-robbinsmonroincrement": "10", + "param-secondpeakdelta": "325", + "param-texturecountthresh": "0", + "param-texturedifferencethresh": "0", + "param-raumine": "1", + "param-rauminn": "1", + "param-rauminnssum": "3", + "param-raumins": "1", + "param-rauminw": "1", + "param-rauminwesum": "3", + "param-regionshrinku": "3", + "param-regionshrinkv": "1", + "param-regioncolorthresholdr": "0.05", + "param-regioncolorthresholdg": "0.05", + "param-regioncolorthresholdb": "0.05", + "param-rsmdiffthreshold": "4", + "param-rsmrauslodiffthreshold": "1", + "param-rsmremovethreshold": "0.375", + "param-usersm": "1", + "param-scanlineedgetaub": "72", + "param-scanlineedgetaug": "72", + "param-scanlineedgetaur": "72", + "param-scanlinep1": "60", + "param-scanlinep1onediscon": "105", + "param-scanlinep1twodiscon": "70", + "param-scanlinep2": "342", + "param-scanlinep2onediscon": "190", + "param-scanlinep2twodiscon": "130", + "param-censususize": "9", + "param-censusvsize": "9", + "param-zunits": "1000", + "aux-param-depthclampmin": "0", + "aux-param-depthclampmax": "65536", + "param-disparitymode": "0", + "aux-param-disparityshift": "0", + "aux-param-autoexposure-setpoint": "400", + "aux-param-colorcorrection1": "0.462", + "aux-param-colorcorrection2": "0.540", + "aux-param-colorcorrection3": "0.540", + "aux-param-colorcorrection4": "0.208", + "aux-param-colorcorrection5": "-0.332", + "aux-param-colorcorrection6": "-0.213", + "aux-param-colorcorrection7": "-0.213", + "aux-param-colorcorrection8": "0.685", + "aux-param-colorcorrection9": "0.931", + "aux-param-colorcorrection10": "-0.554", + "aux-param-colorcorrection11": "-0.554", + "aux-param-colorcorrection12": "0.046", + "controls-laserstate": "on", + "controls-laserpower": "150", + "controls-autoexposure-auto": "True", + "controls-autoexposure-manual": "33000", + "controls-depth-gain": "16" +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/DefaultPreset_D435.json b/wrappers/android/librealsense/src/main/assets/presets/DefaultPreset_D435.json new file mode 100644 index 0000000000..24774cda1f --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/DefaultPreset_D435.json @@ -0,0 +1,69 @@ +{ + "aux-param-autoexposure-setpoint": "1536", + "aux-param-colorcorrection1": "0.299", + "aux-param-colorcorrection2": "0.294", + "aux-param-colorcorrection3": "0.294", + "aux-param-colorcorrection4": "0.114", + "aux-param-colorcorrection5": "0.000", + "aux-param-colorcorrection6": "0.000", + "aux-param-colorcorrection7": "0.000", + "aux-param-colorcorrection8": "0.000", + "aux-param-colorcorrection9": "0.000", + "aux-param-colorcorrection10": "0.000", + "aux-param-colorcorrection11": "0.000", + "aux-param-colorcorrection12": "0.000", + "aux-param-depthclampmax": "65536", + "aux-param-depthclampmin": "0", + "aux-param-disparityshift": "0", + + "param-disableraucolor": "0", + "param-disablesadcolor": "0", + "param-disablesadnormalize": "0", + "param-disablesloleftcolor": "0", + "param-disableslorightcolor": "0", + "param-lambdaad": "800", + "param-lambdacensus": "26", + "param-leftrightthreshold": "24", + "param-maxscorethreshb": "2047", + "param-medianthreshold": "500", + "param-minscorethresha": "1", + "param-neighborthresh": "7", + "param-robbinsmonrodecrement": "10", + "param-robbinsmonroincrement": "10", + "param-secondpeakdelta": "325", + "param-texturecountthresh": "0", + "param-texturedifferencethresh": "0", + "param-raumine": "1", + "param-rauminn": "1", + "param-rauminnssum": "3", + "param-raumins": "1", + "param-rauminw": "1", + "param-rauminwesum": "3", + "param-regionshrinku": "3", + "param-regionshrinkv": "1", + "param-regioncolorthresholdr": "0.05", + "param-regioncolorthresholdg": "0.05", + "param-regioncolorthresholdb": "0.05", + "param-rsmdiffthreshold": "4", + "param-rsmrauslodiffthreshold": "1", + "param-rsmremovethreshold": "0.375", + "param-usersm": "1", + "param-scanlineedgetaub": "72", + "param-scanlineedgetaug": "72", + "param-scanlineedgetaur": "72", + "param-scanlinep1": "60", + "param-scanlinep1onediscon": "105", + "param-scanlinep1twodiscon": "70", + "param-scanlinep2": "342", + "param-scanlinep2onediscon": "190", + "param-scanlinep2twodiscon": "130", + "param-censususize": "9", + "param-censusvsize": "9", + "param-zunits": "1000", + + "controls-laserstate": "on", + "controls-laserpower": "150", + "controls-autoexposure-auto": "True", + "controls-autoexposure-manual": "8500", + "controls-depth-gain": "16" +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/HandGesturePreset.json b/wrappers/android/librealsense/src/main/assets/presets/HandGesturePreset.json new file mode 100644 index 0000000000..6ebba091ba --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/HandGesturePreset.json @@ -0,0 +1,52 @@ +{ + "ignoreSAD": "0", + "param-censususize": "9", + "param-censusvsize": "3", + "param-depthclampmax": "65535", + "param-depthclampmin": "0", + "param-depthunits": "1000", + "param-disableraucolor": "0", + "param-disablesadcolor": "0", + "param-disablesadnormalize": "0", + "param-disablesloleftcolor": "0", + "param-disableslorightcolor": "1", + "param-disparitymode": "0", + "param-disparityshift": "0", + "param-lambdaad": "1001", + "param-lambdacensus": "7", + "param-leftrightthreshold": "20", + "param-maxscorethreshb": "791", + "param-medianthreshold": "240", + "param-minscorethresha": "24", + "param-neighborthresh": "110", + "param-raumine": "3", + "param-rauminn": "1", + "param-rauminnssum": "4", + "param-raumins": "3", + "param-rauminw": "1", + "param-rauminwesum": "14", + "param-regioncolorthresholdb": "0.0489237", + "param-regioncolorthresholdg": "0.072407", + "param-regioncolorthresholdr": "0.137965", + "param-regionshrinku": "3", + "param-regionshrinkv": "1", + "param-robbinsmonrodecrement": "20", + "param-robbinsmonroincrement": "3", + "param-rsmdiffthreshold": "3.8125", + "param-rsmrauslodiffthreshold": "0.46875", + "param-rsmremovethreshold": "0.553571", + "param-scanlineedgetaub": "130", + "param-scanlineedgetaug": "244", + "param-scanlineedgetaur": "618", + "param-scanlinep1": "63", + "param-scanlinep1onediscon": "14", + "param-scanlinep1twodiscon": "119", + "param-scanlinep2": "45", + "param-scanlinep2onediscon": "21", + "param-scanlinep2twodiscon": "12", + "param-secondpeakdelta": "31", + "param-texturecountthresh": "0", + "param-texturedifferencethresh": "783", + "param-usersm": "1", + "param-zunits": "1000" +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/HighResHighAccuracyPreset.json b/wrappers/android/librealsense/src/main/assets/presets/HighResHighAccuracyPreset.json new file mode 100644 index 0000000000..5a80efd681 --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/HighResHighAccuracyPreset.json @@ -0,0 +1,45 @@ +{ + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 0, + "param-disableslorightcolor": 1, + "param-lambdaad": 751, + "param-lambdacensus": 6, + "param-leftrightthreshold": 10, + "param-maxscorethreshb": 2893, + "param-medianthreshold": 796, + "param-minscorethresha": 4, + "param-neighborthresh": 108, + "param-raumine": 6, + "param-rauminn": 3, + "param-rauminnssum": 7, + "param-raumins": 2, + "param-rauminw": 2, + "param-rauminwesum": 12, + "param-regioncolorthresholdb": 0.786380709066072, + "param-regioncolorthresholdg": 0.5664810046339115, + "param-regioncolorthresholdr": 0.9857413557742051, + "param-regionshrinku": 3, + "param-regionshrinkv": 0, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 25, + "param-robbinsmonroincrement": 2, + "param-rsmdiffthreshold": 1.6605679586483368, + "param-rsmrauslodiffthreshold": 0.7269914923801174, + "param-rsmremovethreshold": 0.8150280066589434, + "param-scanlineedgetaub": 13, + "param-scanlineedgetaug": 15, + "param-scanlineedgetaur": 30, + "param-scanlinep1": 155, + "param-scanlinep1onediscon": 160, + "param-scanlinep1twodiscon": 59, + "param-scanlinep2": 190, + "param-scanlinep2onediscon": 507, + "param-scanlinep2twodiscon": 493, + "param-secondpeakdelta": 647, + "param-texturecountthresh": 0, + "param-texturedifferencethresh": 1722, + "param-usersm": 1 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/HighResHighDensityPreset.json b/wrappers/android/librealsense/src/main/assets/presets/HighResHighDensityPreset.json new file mode 100644 index 0000000000..e0fa5b070a --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/HighResHighDensityPreset.json @@ -0,0 +1,45 @@ +{ + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 0, + "param-disableslorightcolor": 0, + "param-lambdaad": 618, + "param-lambdacensus": 15, + "param-leftrightthreshold": 18, + "param-maxscorethreshb": 1443, + "param-medianthreshold": 789, + "param-minscorethresha": 96, + "param-neighborthresh": 12, + "param-raumine": 2, + "param-rauminn": 1, + "param-rauminnssum": 6, + "param-raumins": 3, + "param-rauminw": 3, + "param-rauminwesum": 7, + "param-regioncolorthresholdb": 0.11028557924300367, + "param-regioncolorthresholdg": 0.5729592245318832, + "param-regioncolorthresholdr": 0.017746482533836073, + "param-regionshrinku": 4, + "param-regionshrinkv": 0, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 6, + "param-robbinsmonroincrement": 21, + "param-rsmdiffthreshold": 1.228300048811172, + "param-rsmrauslodiffthreshold": 0.26648832912881404, + "param-rsmremovethreshold": 0.4935489490398768, + "param-scanlineedgetaub": 8, + "param-scanlineedgetaug": 200, + "param-scanlineedgetaur": 279, + "param-scanlinep1": 55, + "param-scanlinep1onediscon": 326, + "param-scanlinep1twodiscon": 134, + "param-scanlinep2": 235, + "param-scanlinep2onediscon": 506, + "param-scanlinep2twodiscon": 206, + "param-secondpeakdelta": 222, + "param-texturecountthresh": 0, + "param-texturedifferencethresh": 2466, + "param-usersm": 1 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/HighResMidDensityPreset.json b/wrappers/android/librealsense/src/main/assets/presets/HighResMidDensityPreset.json new file mode 100644 index 0000000000..42eaf4177d --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/HighResMidDensityPreset.json @@ -0,0 +1,45 @@ +{ + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 0, + "param-disableslorightcolor": 1, + "param-lambdaad": 935, + "param-lambdacensus": 26, + "param-leftrightthreshold": 19, + "param-maxscorethreshb": 887, + "param-medianthreshold": 1021, + "param-minscorethresha": 54, + "param-neighborthresh": 97, + "param-raumine": 3, + "param-rauminn": 1, + "param-rauminnssum": 6, + "param-raumins": 3, + "param-rauminw": 5, + "param-rauminwesum": 11, + "param-regioncolorthresholdb": 0.014525116743001514, + "param-regioncolorthresholdg": 0.7081795895730004, + "param-regioncolorthresholdr": 0.18219370378688518, + "param-regionshrinku": 3, + "param-regionshrinkv": 1, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 23, + "param-robbinsmonroincrement": 3, + "param-rsmdiffthreshold": 1.816745640601172, + "param-rsmrauslodiffthreshold": 1.0, + "param-rsmremovethreshold": 0.48617561168925416, + "param-scanlineedgetaub": 16, + "param-scanlineedgetaug": 259, + "param-scanlineedgetaur": 896, + "param-scanlinep1": 132, + "param-scanlinep1onediscon": 77, + "param-scanlinep1twodiscon": 234, + "param-scanlinep2": 342, + "param-scanlinep2onediscon": 390, + "param-scanlinep2twodiscon": 151, + "param-secondpeakdelta": 600, + "param-texturecountthresh": 0, + "param-texturedifferencethresh": 0, + "param-usersm": 1 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/LowResHighAccuracyPreset.json b/wrappers/android/librealsense/src/main/assets/presets/LowResHighAccuracyPreset.json new file mode 100644 index 0000000000..909ce124bb --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/LowResHighAccuracyPreset.json @@ -0,0 +1,48 @@ +{ + "param-censususize": 8, + "param-censusvsize": 9, + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 0, + "param-disableslorightcolor": 0, + "param-lambdaad": 74, + "param-lambdacensus": 26, + "param-leftrightthreshold": 28, + "param-maxscorethreshb": 1890, + "param-medianthreshold": 871, + "param-minscorethresha": 70, + "param-neighborthresh": 113, + "param-raumine": 1, + "param-rauminn": 1, + "param-rauminnssum": 5, + "param-raumins": 3, + "param-rauminw": 7, + "param-rauminwesum": 7, + "param-regioncolorthresholdb": 0.023324522891323397, + "param-regioncolorthresholdg": 0.2913015808210784, + "param-regioncolorthresholdr": 0.09389134817320013, + "param-regionshrinku": 4, + "param-regionshrinkv": 0, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 1, + "param-robbinsmonroincrement": 1, + "param-rsmdiffthreshold": 5.20603417754079, + "param-rsmrauslodiffthreshold": 0.7110940140756449, + "param-rsmremovethreshold": 0.5174833124815498, + "param-scanlineedgetaub": 72, + "param-scanlineedgetaug": 72, + "param-scanlineedgetaur": 72, + "param-scanlinep1": 176, + "param-scanlinep1onediscon": 196, + "param-scanlinep1twodiscon": 36, + "param-scanlinep2": 414, + "param-scanlinep2onediscon": 96, + "param-scanlinep2twodiscon": 57, + "param-secondpeakdelta": 310, + "param-texturecountthresh": 8, + "param-texturedifferencethresh": 0, + "param-usersm": 1, + "result": -67.58874334573693 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/LowResHighDensityPreset.json b/wrappers/android/librealsense/src/main/assets/presets/LowResHighDensityPreset.json new file mode 100644 index 0000000000..60427ccfc8 --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/LowResHighDensityPreset.json @@ -0,0 +1,48 @@ +{ + "param-censususize": 9, + "param-censusvsize": 9, + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 1, + "param-disableslorightcolor": 0, + "param-lambdaad": 686, + "param-lambdacensus": 26, + "param-leftrightthreshold": 20, + "param-maxscorethreshb": 3440, + "param-medianthreshold": 973, + "param-minscorethresha": 90, + "param-neighborthresh": 91, + "param-raumine": 1, + "param-rauminn": 1, + "param-rauminnssum": 5, + "param-raumins": 2, + "param-rauminw": 6, + "param-rauminwesum": 4, + "param-regioncolorthresholdb": 0.29367143700253656, + "param-regioncolorthresholdg": 0.012504143377510591, + "param-regioncolorthresholdr": 0.05893324447962866, + "param-regionshrinku": 4, + "param-regionshrinkv": 1, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 2, + "param-robbinsmonroincrement": 18, + "param-rsmdiffthreshold": 5.89083925111254, + "param-rsmrauslodiffthreshold": 0.421688050845725, + "param-rsmremovethreshold": 0.4062114741986549, + "param-scanlineedgetaub": 105, + "param-scanlineedgetaug": 60, + "param-scanlineedgetaur": 64, + "param-scanlinep1": 170, + "param-scanlinep1onediscon": 67, + "param-scanlinep1twodiscon": 59, + "param-scanlinep2": 386, + "param-scanlinep2onediscon": 86, + "param-scanlinep2twodiscon": 60, + "param-secondpeakdelta": 463, + "param-texturecountthresh": 0, + "param-texturedifferencethresh": 3639, + "param-usersm": 1, + "result": -69.05536699602217 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/LowResMidDensityPreset.json b/wrappers/android/librealsense/src/main/assets/presets/LowResMidDensityPreset.json new file mode 100644 index 0000000000..6464e6410c --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/LowResMidDensityPreset.json @@ -0,0 +1,48 @@ +{ + "param-censususize": 9, + "param-censusvsize": 9, + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 0, + "param-disableslorightcolor": 0, + "param-lambdaad": 183, + "param-lambdacensus": 26, + "param-leftrightthreshold": 30, + "param-maxscorethreshb": 1885, + "param-medianthreshold": 696, + "param-minscorethresha": 43, + "param-neighborthresh": 43, + "param-raumine": 6, + "param-rauminn": 1, + "param-rauminnssum": 2, + "param-raumins": 3, + "param-rauminw": 7, + "param-rauminwesum": 7, + "param-regioncolorthresholdb": 0.05, + "param-regioncolorthresholdg": 0.03092604847265814, + "param-regioncolorthresholdr": 0.41507045973435736, + "param-regionshrinku": 4, + "param-regionshrinkv": 1, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 9, + "param-robbinsmonroincrement": 16, + "param-rsmdiffthreshold": 6.447234381771916, + "param-rsmrauslodiffthreshold": 0.2744664270016177, + "param-rsmremovethreshold": 0.5661915140248058, + "param-scanlineedgetaub": 69, + "param-scanlineedgetaug": 72, + "param-scanlineedgetaur": 124, + "param-scanlinep1": 117, + "param-scanlinep1onediscon": 33, + "param-scanlinep1twodiscon": 64, + "param-scanlinep2": 410, + "param-scanlinep2onediscon": 80, + "param-scanlinep2twodiscon": 74, + "param-secondpeakdelta": 476, + "param-texturecountthresh": 0, + "param-texturedifferencethresh": 2817, + "param-usersm": 1, + "result": -71.79800597031867 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/MidResHighAccuracyPreset.json b/wrappers/android/librealsense/src/main/assets/presets/MidResHighAccuracyPreset.json new file mode 100644 index 0000000000..1b294d0190 --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/MidResHighAccuracyPreset.json @@ -0,0 +1,47 @@ +{ + "param-censususize": 6, + "param-censusvsize": 7, + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 0, + "param-disableslorightcolor": 0, + "param-lambdaad": 630, + "param-lambdacensus": 26, + "param-leftrightthreshold": 18, + "param-maxscorethreshb": 2047, + "param-medianthreshold": 347, + "param-minscorethresha": 80, + "param-neighborthresh": 82, + "param-raumine": 3, + "param-rauminn": 1, + "param-rauminnssum": 6, + "param-raumins": 2, + "param-rauminw": 2, + "param-rauminwesum": 3, + "param-regioncolorthresholdb": 0.02575965041840711, + "param-regioncolorthresholdg": 0.9545065192180644, + "param-regioncolorthresholdr": 0.028804875070092176, + "param-regionshrinku": 4, + "param-regionshrinkv": 1, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 15, + "param-robbinsmonroincrement": 5, + "param-rsmdiffthreshold": 3.3293430127414756, + "param-rsmrauslodiffthreshold": 0.9618657668112696, + "param-rsmremovethreshold": 0.6703910858723563, + "param-scanlineedgetaub": 442, + "param-scanlineedgetaug": 16, + "param-scanlineedgetaur": 770, + "param-scanlinep1": 21, + "param-scanlinep1onediscon": 3, + "param-scanlinep1twodiscon": 27, + "param-scanlinep2": 182, + "param-scanlinep2onediscon": 41, + "param-scanlinep2twodiscon": 63, + "param-secondpeakdelta": 205, + "param-texturecountthresh": 0, + "param-texturedifferencethresh": 3474, + "param-usersm": 1 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/MidResHighDensityPreset.json b/wrappers/android/librealsense/src/main/assets/presets/MidResHighDensityPreset.json new file mode 100644 index 0000000000..9033b21b0a --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/MidResHighDensityPreset.json @@ -0,0 +1,47 @@ +{ + "param-censususize": 8, + "param-censusvsize": 5, + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 1, + "param-disableslorightcolor": 0, + "param-lambdaad": 978, + "param-lambdacensus": 21, + "param-leftrightthreshold": 32, + "param-maxscorethreshb": 972, + "param-medianthreshold": 175, + "param-minscorethresha": 3, + "param-neighborthresh": 1, + "param-raumine": 3, + "param-rauminn": 1, + "param-rauminnssum": 6, + "param-raumins": 2, + "param-rauminw": 1, + "param-rauminwesum": 5, + "param-regioncolorthresholdb": 0.6774716242429242, + "param-regioncolorthresholdg": 0.012306832764202736, + "param-regioncolorthresholdr": 0.07908179523435015, + "param-regionshrinku": 4, + "param-regionshrinkv": 1, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 14, + "param-robbinsmonroincrement": 22, + "param-rsmdiffthreshold": 5.859616082943054, + "param-rsmrauslodiffthreshold": 1.0, + "param-rsmremovethreshold": 0.4213190644069522, + "param-scanlineedgetaub": 18, + "param-scanlineedgetaug": 493, + "param-scanlineedgetaur": 390, + "param-scanlinep1": 134, + "param-scanlinep1onediscon": 10, + "param-scanlinep1twodiscon": 70, + "param-scanlinep2": 397, + "param-scanlinep2onediscon": 21, + "param-scanlinep2twodiscon": 226, + "param-secondpeakdelta": 3, + "param-texturecountthresh": 6, + "param-texturedifferencethresh": 0, + "param-usersm": 1 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/MidResMidDensityPreset.json b/wrappers/android/librealsense/src/main/assets/presets/MidResMidDensityPreset.json new file mode 100644 index 0000000000..b34cbe9e8a --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/MidResMidDensityPreset.json @@ -0,0 +1,47 @@ +{ + "param-censususize": 9, + "param-censusvsize": 3, + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 1, + "param-disableslorightcolor": 0, + "param-lambdaad": 850, + "param-lambdacensus": 19, + "param-leftrightthreshold": 32, + "param-maxscorethreshb": 1949, + "param-medianthreshold": 276, + "param-minscorethresha": 68, + "param-neighborthresh": 4, + "param-raumine": 7, + "param-rauminn": 1, + "param-rauminnssum": 6, + "param-raumins": 3, + "param-rauminw": 6, + "param-rauminwesum": 14, + "param-regioncolorthresholdb": 0.011669743090467342, + "param-regioncolorthresholdg": 0.6462791871946363, + "param-regioncolorthresholdr": 0.017414829649508693, + "param-regionshrinku": 4, + "param-regionshrinkv": 1, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 1, + "param-robbinsmonroincrement": 4, + "param-rsmdiffthreshold": 5.06979466489835, + "param-rsmrauslodiffthreshold": 1.0, + "param-rsmremovethreshold": 0.4474719403505988, + "param-scanlineedgetaub": 4, + "param-scanlineedgetaug": 542, + "param-scanlineedgetaur": 982, + "param-scanlinep1": 479, + "param-scanlinep1onediscon": 4, + "param-scanlinep1twodiscon": 25, + "param-scanlinep2": 342, + "param-scanlinep2onediscon": 69, + "param-scanlinep2twodiscon": 225, + "param-secondpeakdelta": 6, + "param-texturecountthresh": 1, + "param-texturedifferencethresh": 0, + "param-usersm": 1 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/assets/presets/ShortRangePreset.json b/wrappers/android/librealsense/src/main/assets/presets/ShortRangePreset.json new file mode 100644 index 0000000000..76579154e5 --- /dev/null +++ b/wrappers/android/librealsense/src/main/assets/presets/ShortRangePreset.json @@ -0,0 +1,47 @@ +{ + "param-censususize": 9, + "param-censusvsize": 3, + "param-disableraucolor": 0, + "param-disablesadcolor": 0, + "param-disablesadnormalize": 0, + "param-disablesloleftcolor": 0, + "param-disableslorightcolor": 0, + "param-lambdaad": 2000.0, + "param-lambdacensus": 39, + "param-leftrightthreshold": 52, + "param-maxscorethreshb": 2000, + "param-medianthreshold": 100, + "param-minscorethresha": 13, + "param-neighborthresh": 1, + "param-raumine": 6, + "param-rauminn": 1, + "param-rauminnssum": 1, + "param-raumins": 1, + "param-rauminw": 4, + "param-rauminwesum": 8, + "param-regioncolorthresholdb": 0.02404790738643174, + "param-regioncolorthresholdg": 0.05924149629687343, + "param-regioncolorthresholdr": 0.1693732549608611, + "param-regionshrinku": 4, + "param-regionshrinkv": 1, + "param-regionspatialthresholdu": 7, + "param-regionspatialthresholdv": 3, + "param-robbinsmonrodecrement": 11, + "param-robbinsmonroincrement": 1, + "param-rsmdiffthreshold": 4.707440954582961, + "param-rsmrauslodiffthreshold": 0.007420896027247603, + "param-rsmremovethreshold": 0.31771802714889097, + "param-scanlineedgetaub": 849, + "param-scanlineedgetaug": 515, + "param-scanlineedgetaur": 736, + "param-scanlinep1": 5, + "param-scanlinep1onediscon": 341, + "param-scanlinep1twodiscon": 248, + "param-scanlinep2": 56, + "param-scanlinep2onediscon": 28, + "param-scanlinep2twodiscon": 415, + "param-secondpeakdelta": 26, + "param-texturecountthresh": 0, + "param-texturedifferencethresh": 500, + "param-usersm": 1 +} \ No newline at end of file diff --git a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Config.java b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Config.java index cbcb6f6bc1..6e19e572ec 100644 --- a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Config.java +++ b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Config.java @@ -40,6 +40,16 @@ public void enableDeviceFromFile(String filePath) { nEnableDeviceFromFile(mHandle, filePath); } + public boolean canResolve(Pipeline pipeline){ + return nCanResolve(mHandle, pipeline.mHandle); + } + + public void resolve(Pipeline pipeline) { + long pipeHandle = nResolve(mHandle, pipeline.mHandle); + PipelineProfile rv = new PipelineProfile(pipeHandle); + rv.close();//TODO: enable when PipelineProfile is implemented + } + @Override public void close() { nDelete(mHandle); @@ -53,4 +63,6 @@ public void close() { private static native void nDisableAllStreams(long handle); private static native void nEnableDeviceFromFile(long handle, String filePath); private static native void nEnableRecordToFile(long handle, String filePath); + private static native boolean nCanResolve(long handle, long pipelineHandle); + private static native long nResolve(long handle, long pipelineHandle); } diff --git a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Device.java b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Device.java index cfd4d58f83..d73ff32a08 100644 --- a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Device.java +++ b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Device.java @@ -1,11 +1,23 @@ package com.intel.realsense.librealsense; +import java.util.ArrayList; +import java.util.List; + public class Device extends LrsClass { public Device(long handle){ mHandle = handle; } + public List querySensors(){ + long[] sensorsHandles = nQuerySensors(mHandle); + List rv = new ArrayList<>(); + for(long h : sensorsHandles){ + rv.add(new Sensor(h)); + } + return rv; + } + public boolean supportsInfo(CameraInfo info){ return nSupportsInfo(mHandle, info.value()); } @@ -14,6 +26,22 @@ public String getInfo(CameraInfo info){ return nGetInfo(mHandle, info.value()); } + public void toggleAdvancedMode(boolean enable){ + nToggleAdvancedMode(mHandle, enable); + } + + public boolean isInAdvancedMode(){ + return nIsInAdvancedMode(mHandle); + } + + public void loadPresetFromJson(byte[] data){ + nLoadPresetFromJson(mHandle, data); + } + + public byte[] serializePresetToJson(){ + return nSerializePresetToJson(mHandle); + } + @Override public void close() { nRelease(mHandle); @@ -21,5 +49,10 @@ public void close() { private static native boolean nSupportsInfo(long handle, int info); private static native String nGetInfo(long handle, int info); + private static native void nToggleAdvancedMode(long handle, boolean enable); + private static native boolean nIsInAdvancedMode(long handle); + private static native void nLoadPresetFromJson(long handle, byte[] data); + private static native byte[] nSerializePresetToJson(long handle); + private static native long[] nQuerySensors(long handle); private static native void nRelease(long handle); } diff --git a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Pipeline.java b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Pipeline.java index bf3dd191c3..38647a92ea 100644 --- a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Pipeline.java +++ b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Pipeline.java @@ -13,7 +13,8 @@ public void start() throws Exception{ } public void start(Config config) throws Exception { - PipelineProfile rv = new PipelineProfile(nStartWithConfig(mHandle, config.getHandle())); + long h = nStartWithConfig(mHandle, config.getHandle()); + PipelineProfile rv = new PipelineProfile(h); rv.close();//TODO: enable when PipelineProfile is implemented } public void stop() { diff --git a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/PipelineProfile.java b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/PipelineProfile.java index 06ba61c9d0..3f0cc2a26e 100644 --- a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/PipelineProfile.java +++ b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/PipelineProfile.java @@ -7,7 +7,7 @@ class PipelineProfile extends LrsClass { } @Override - public void close() throws Exception { + public void close() { nDelete(mHandle); } diff --git a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Sensor.java b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Sensor.java new file mode 100644 index 0000000000..0e1ed40655 --- /dev/null +++ b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/Sensor.java @@ -0,0 +1,28 @@ +package com.intel.realsense.librealsense; + +import java.util.ArrayList; +import java.util.List; + +public class Sensor extends LrsClass { + + Sensor(long h) { + mHandle = h; + } + + public List getStreamProfiles(){ + long[] streamProfilesHandles = nGetStreamProfiles(mHandle); + List rv = new ArrayList<>(); + for(long h : streamProfilesHandles){ + rv.add(StreamProfile.create(h)); + } + return rv; + } + + @Override + public void close() { + nRelease(mHandle); + } + + private static native long[] nGetStreamProfiles(long handle); + private static native void nRelease(long handle); +} diff --git a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/StreamProfile.java b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/StreamProfile.java index 29d3cd560d..79c7a2ee9d 100644 --- a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/StreamProfile.java +++ b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/StreamProfile.java @@ -14,6 +14,12 @@ private class ProfileParams { public int frameRate; } + static StreamProfile create(long handle){ + if (nIsProfileExtendableTo(handle, Extension.VIDEO_PROFILE.value())) + return new VideoStreamProfile(handle); + return new StreamProfile(handle); + } + protected StreamProfile(long handle){ mHandle = handle; mPp = new ProfileParams(); @@ -51,6 +57,7 @@ public void close() { // nDelete(mHandle); } + private static native boolean nIsProfileExtendableTo(long handle, int extension); private static native void nGetProfile(long handle, ProfileParams params); private static native void nDelete(long handle); } diff --git a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/StreamType.java b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/StreamType.java index c26cc0dde2..786d0595db 100644 --- a/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/StreamType.java +++ b/wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/StreamType.java @@ -5,7 +5,12 @@ public enum StreamType { DEPTH(1), COLOR(2), INFRARED(3), - FISHEYE(4); + FISHEYE(4), + GYRO(5), + ACCEL(6), + GPIO(7), + POSE(8), + CONFIDENCE(9); private final int mValue; diff --git a/wrappers/android/tools/camera/src/main/AndroidManifest.xml b/wrappers/android/tools/camera/src/main/AndroidManifest.xml index 393abd1985..d7403858d0 100644 --- a/wrappers/android/tools/camera/src/main/AndroidManifest.xml +++ b/wrappers/android/tools/camera/src/main/AndroidManifest.xml @@ -24,20 +24,26 @@ + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + android:theme="@style/AppTheme.NoActionBar" /> + + \ No newline at end of file diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/CheckableTwoLinesListCell.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/CheckableTwoLinesListCell.java deleted file mode 100644 index bae96f60fc..0000000000 --- a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/CheckableTwoLinesListCell.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.intel.realsense.camera; - -public class CheckableTwoLinesListCell { - private final String mMainString; - private final String mSecondaryString; - protected boolean mIsEnabled; - - public String getMainString() { return mMainString; } - public String getSecondaryString() { return mSecondaryString; } - - public CheckableTwoLinesListCell(String mainString, String secondaryString, boolean isEnabled) { - mMainString = mainString; - mSecondaryString = secondaryString; - mIsEnabled = isEnabled; - } - - public boolean isEnabled() { return mIsEnabled; } - public void setEnabled(boolean enabled) { mIsEnabled = enabled; } -} diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/CheckableTwoLinesListCellAdapter.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/CheckableTwoLinesListCellAdapter.java deleted file mode 100644 index 2aab01f80f..0000000000 --- a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/CheckableTwoLinesListCellAdapter.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.intel.realsense.camera; - -import android.app.Activity; -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.TextView; - -public class CheckableTwoLinesListCellAdapter extends ArrayAdapter { - private static final int mLayoutResourceId = R.layout.checkable_list_view; - private final CheckableTwoLinesListCell mCheckableTwoLinesListCells[]; - private final LayoutInflater mLayoutInflater; - private final Listener mListener; - - public CheckableTwoLinesListCellAdapter(Context context, CheckableTwoLinesListCell[] data, Listener listener){ - super(context, mLayoutResourceId, data); - mLayoutInflater = ((Activity) context).getLayoutInflater(); - mCheckableTwoLinesListCells = data; - mListener = listener; - } - - public class Holder { - TextView first; - TextView second; - CheckBox checkBox; - } - - @Override - public View getView(int position, View rawView, final ViewGroup parent){ - rawView = mLayoutInflater.inflate(mLayoutResourceId, parent, false); - CheckableTwoLinesListCell settingsListViewLine = mCheckableTwoLinesListCells[position]; - - final Holder holder; - holder = new Holder(); - holder.first = rawView.findViewById(R.id.stream_device); - holder.second = rawView.findViewById(R.id.stream_type); - holder.checkBox = rawView.findViewById(R.id.stream_enable); - holder.first.setText(settingsListViewLine.getMainString()); - holder.second.setText(settingsListViewLine.getSecondaryString()); - holder.checkBox.setTag(position); - holder.checkBox.setChecked(settingsListViewLine.isEnabled()); - holder.checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - int position = (int) buttonView.getTag(); - CheckableTwoLinesListCell curr = mCheckableTwoLinesListCells[position]; - curr.setEnabled(isChecked); - mListener.onCheckedChanged(curr); - } - }); - return rawView; - } - - interface Listener{ - void onCheckedChanged(CheckableTwoLinesListCell holder); - } -} diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/FileBrowserActivity.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/FileBrowserActivity.java index 2cf92d7324..72f5f65ba5 100644 --- a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/FileBrowserActivity.java +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/FileBrowserActivity.java @@ -64,6 +64,8 @@ protected void onResume() { return; } + message.setText("Select a file to play from:"); + String[] filesNames = new String[files.length]; final ListView listview = findViewById(R.id.list_view); diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/InfoActivity.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/InfoActivity.java new file mode 100644 index 0000000000..7338e470ff --- /dev/null +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/InfoActivity.java @@ -0,0 +1,60 @@ +package com.intel.realsense.camera; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import com.intel.realsense.librealsense.CameraInfo; +import com.intel.realsense.librealsense.Device; +import com.intel.realsense.librealsense.DeviceList; +import com.intel.realsense.librealsense.RsContext; + +import java.util.Map; +import java.util.TreeMap; + +public class InfoActivity extends AppCompatActivity { + private static final String TAG = "librs camera info"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_list_view); + } + + @Override + protected void onResume() { + super.onResume(); + + TextView message = findViewById(R.id.list_view_title); + + RsContext ctx = new RsContext(); + DeviceList devices = ctx.queryDevices(); + if(devices.getDeviceCount() == 0){ + finish(); + } + + message.setText("Device info:"); + + Map infoMap = new TreeMap<>(); + + final Device device = ctx.queryDevices().createDevice(0); + for(CameraInfo ci : CameraInfo.values()){ + if(device.supportsInfo(ci)) + infoMap.put(ci, device.getInfo(ci)); + } + + final String[] info = new String[infoMap.size()]; + int i = 0; + for(Map.Entry e : infoMap.entrySet()){ + info[i++] = e.getKey().toString() + ": " + e.getValue(); + } + + + final ListView listview = findViewById(R.id.list_view); + + final ArrayAdapter adapter = new ArrayAdapter<>(this, R.layout.files_list_view, info); + listview.setAdapter(adapter);; + } +} diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PlaybackActivity.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PlaybackActivity.java index fbeed67906..bc71e0bff1 100644 --- a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PlaybackActivity.java +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PlaybackActivity.java @@ -5,7 +5,9 @@ import android.support.v7.app.AppCompatActivity; import android.view.WindowManager; +import com.intel.realsense.librealsense.Colorizer; import com.intel.realsense.librealsense.Config; +import com.intel.realsense.librealsense.FrameSet; import com.intel.realsense.librealsense.GLRsSurfaceView; public class PlaybackActivity extends AppCompatActivity { @@ -16,12 +18,16 @@ public class PlaybackActivity extends AppCompatActivity { private String mFilePath; private Streamer mStreamer; + private GLRsSurfaceView mGLSurfaceView; + private Colorizer mColorizer = new Colorizer(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_playback); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + + mGLSurfaceView = findViewById(R.id.playbackGlSurfaceView); } @Override @@ -33,14 +39,26 @@ protected void onResume() { startActivityForResult(intent, OPEN_FILE_REQUEST_CODE); } else{ - mStreamer = new Streamer(this, (GLRsSurfaceView) findViewById(R.id.playbackGlSurfaceView), new Streamer.Listener() { + mStreamer = new Streamer(this,false, new Streamer.Listener() { @Override public void config(Config config) { config.enableAllStreams(); config.enableDeviceFromFile(mFilePath); } + + @Override + public void onFrameset(FrameSet frameSet) { + try (FrameSet processed = frameSet.applyFilter(mColorizer)) { + mGLSurfaceView.upload(processed); + } + } }); - mStreamer.start(); + try { + mGLSurfaceView.clear(); + mStreamer.start(); + } catch (Exception e) { + finish(); + } } } diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PresetsActivity.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PresetsActivity.java new file mode 100644 index 0000000000..5f26c5e338 --- /dev/null +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PresetsActivity.java @@ -0,0 +1,90 @@ +package com.intel.realsense.camera; + +import android.content.res.Resources; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; + +import com.intel.realsense.librealsense.Device; +import com.intel.realsense.librealsense.DeviceList; +import com.intel.realsense.librealsense.RsContext; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +public class PresetsActivity extends AppCompatActivity { + private static final String TAG = "librs camera presets"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_list_view); + } + + @Override + protected void onResume() { + super.onResume(); + + TextView message = findViewById(R.id.list_view_title); + final Resources resources = getResources(); + String[] presets; + try { + presets = resources.getAssets().list("presets"); + } catch (IOException e) { + message.setText("No presets found"); + return; + } + + if(presets.length == 0) { + message.setText("No presets found"); + return; + } + message.setText("Select a preset:"); + + final ListView listview = findViewById(R.id.list_view); + + final ArrayAdapter adapter = new ArrayAdapter<>(this, R.layout.files_list_view, presets); + listview.setAdapter(adapter); + + final String[] finalPresets = presets; + listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, final View view, + int position, long id) { + RsContext ctx = new RsContext(); + DeviceList devices = ctx.queryDevices(); + if(devices.getDeviceCount() == 0){ + Log.e(TAG, "failed to set preset, no device found"); + finish(); + } + Device device = ctx.queryDevices().createDevice(0); + if(!device.isInAdvancedMode()){ + Log.e(TAG, "failed to set preset, device not in advanced mode"); + finish(); + } + final String item = finalPresets[position]; + try { + InputStream is = resources.getAssets().open("presets/" + item); + byte[] buffer = new byte[is.available()]; + is.read(buffer); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + baos.write(buffer); + baos.close(); + is.close(); + device.loadPresetFromJson(buffer); + } catch (IOException e) { + Log.e(TAG, "failed to set preset, failed to open preset file, error: " + e.getMessage()); + }finally { + finish(); + } + } + }); + } +} diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PreviewActivity.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PreviewActivity.java index 8ea0dc2d95..594ccc0c9e 100644 --- a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PreviewActivity.java +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PreviewActivity.java @@ -4,9 +4,15 @@ import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; +import android.util.Log; import android.view.View; import android.view.WindowManager; +import android.widget.TextView; +import android.widget.Toast; +import com.intel.realsense.librealsense.Colorizer; +import com.intel.realsense.librealsense.Config; +import com.intel.realsense.librealsense.FrameSet; import com.intel.realsense.librealsense.GLRsSurfaceView; public class PreviewActivity extends AppCompatActivity { @@ -15,11 +21,34 @@ public class PreviewActivity extends AppCompatActivity { private static final int PLAYBACK_REQUEST_CODE = 0; private static final int SETTINGS_REQUEST_CODE = 1; + private GLRsSurfaceView mGLSurfaceView; private FloatingActionButton mStartRecordFab; - private FloatingActionButton mPlaybackFab; - private FloatingActionButton mSettingsFab; + private TextView mPlaybackButton; + private TextView mSettingsButton; + private TextView mStatisticsButton; + + private TextView mStatsView; private Streamer mStreamer; + private Colorizer mColorizer = new Colorizer(); + + private StreamingStats mStreamingStats = new StreamingStats(); + + private boolean statsToggle = false; + + public synchronized void toggleStats(){ + statsToggle = !statsToggle; + if(statsToggle){ + mGLSurfaceView.setVisibility(View.GONE); + mStatsView.setVisibility(View.VISIBLE); + mStatisticsButton.setText("Preview"); + } + else { + mGLSurfaceView.setVisibility(View.VISIBLE); + mStatsView.setVisibility(View.GONE); + mStatisticsButton.setText("Statistics"); + } + } @Override protected void onCreate(Bundle savedInstanceState) { @@ -27,9 +56,12 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_preview); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - mStartRecordFab = findViewById(R.id.startRecordFab); - mPlaybackFab = findViewById(R.id.playbackFab); - mSettingsFab = findViewById(R.id.settingsFab); + mGLSurfaceView = findViewById(R.id.glSurfaceView); + mStatsView = findViewById(R.id.streaming_stats_text); + mStartRecordFab = findViewById(R.id.start_record_fab); + mPlaybackButton = findViewById(R.id.preview_playback_button); + mSettingsButton = findViewById(R.id.preview_settings_button); + mStatisticsButton = findViewById(R.id.preview_stats_button); mStartRecordFab.setOnClickListener(new View.OnClickListener() { @Override @@ -39,28 +71,69 @@ public void onClick(View view) { finish(); } }); - mPlaybackFab.setOnClickListener(new View.OnClickListener() { + mPlaybackButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(PreviewActivity.this, PlaybackActivity.class); startActivityForResult(intent, PLAYBACK_REQUEST_CODE); } }); - mSettingsFab.setOnClickListener(new View.OnClickListener() { + mSettingsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(PreviewActivity.this, SettingsActivity.class); startActivityForResult(intent, SETTINGS_REQUEST_CODE); } }); + mStatisticsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + toggleStats(); + } + }); } @Override protected void onResume() { super.onResume(); - mStreamer = new Streamer(this, (GLRsSurfaceView) findViewById(R.id.glSurfaceView), null); - mStreamer.start(); + mStreamer = new Streamer(this, true, new Streamer.Listener() { + @Override + public void config(Config config) { + + } + + @Override + public void onFrameset(FrameSet frameSet) { + mStreamingStats.onFrameset(frameSet); + if(statsToggle){ + runOnUiThread(new Runnable() { + @Override + public void run() { + mStatsView.setText(mStreamingStats.prettyPrint()); + } + }); + } + else{ + try (FrameSet processed = frameSet.applyFilter(mColorizer)) { + mGLSurfaceView.upload(processed); + } + } + } + }); + + try { + mGLSurfaceView.clear(); + mStreamer.start(); + } + catch (Exception e){ + if(mStreamer != null) + mStreamer.stop(); + Log.e(TAG, e.getMessage()); + Toast.makeText(this, "Invalid configuration selected", Toast.LENGTH_LONG).show(); + Intent intent = new Intent(PreviewActivity.this, SettingsActivity.class); + startActivityForResult(intent, SETTINGS_REQUEST_CODE); + } } @Override diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/RecordingActivity.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/RecordingActivity.java index 3cd29d9227..9fcf9f912e 100644 --- a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/RecordingActivity.java +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/RecordingActivity.java @@ -12,7 +12,9 @@ import android.view.View; import android.view.WindowManager; +import com.intel.realsense.librealsense.Colorizer; import com.intel.realsense.librealsense.Config; +import com.intel.realsense.librealsense.FrameSet; import com.intel.realsense.librealsense.GLRsSurfaceView; import java.io.File; @@ -24,6 +26,8 @@ public class RecordingActivity extends AppCompatActivity { private static final int PERMISSIONS_REQUEST_WRITE = 0; private Streamer mStreamer; + private GLRsSurfaceView mGLSurfaceView; + private Colorizer mColorizer = new Colorizer(); private boolean mPermissionsGrunted = false; @@ -35,6 +39,8 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_recording); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + mGLSurfaceView = findViewById(R.id.recordingGlSurfaceView); + mStopRecordFab = findViewById(R.id.stopRecordFab); mStopRecordFab.setOnClickListener(new View.OnClickListener() { @Override @@ -68,13 +74,25 @@ protected void onResume() { super.onResume(); if(mPermissionsGrunted){ - mStreamer = new Streamer(this, (GLRsSurfaceView) findViewById(R.id.recordingGlSurfaceView), new Streamer.Listener() { + mStreamer = new Streamer(this,true, new Streamer.Listener() { @Override public void config(Config config) { config.enableRecordToFile(getFilePath()); } + + @Override + public void onFrameset(FrameSet frameSet) { + try (FrameSet processed = frameSet.applyFilter(mColorizer)) { + mGLSurfaceView.upload(processed); + } + } }); - mStreamer.start(); + try { + mGLSurfaceView.clear(); + mStreamer.start(); + } catch (Exception e) { + finish(); + } } } diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/SettingsActivity.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/SettingsActivity.java index 86ba4b2135..3eb7084982 100644 --- a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/SettingsActivity.java +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/SettingsActivity.java @@ -1,67 +1,173 @@ package com.intel.realsense.camera; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.util.Pair; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.ListView; -import android.widget.TextView; +import android.widget.Toast; +import com.intel.realsense.librealsense.CameraInfo; +import com.intel.realsense.librealsense.Device; +import com.intel.realsense.librealsense.DeviceList; +import com.intel.realsense.librealsense.RsContext; +import com.intel.realsense.librealsense.Sensor; +import com.intel.realsense.librealsense.StreamProfile; import com.intel.realsense.librealsense.StreamType; +import com.intel.realsense.librealsense.VideoStreamProfile; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.TreeMap; public class SettingsActivity extends AppCompatActivity { private static final String TAG = "librs camera settings"; + private static final int INDEX_DEVICE_INFO = 0; + private static final int INDEX_ADVANCE_MODE = 1; + private static final int INDEX_PRESETS = 2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_list_view); + setContentView(R.layout.activity_settings); } @Override protected void onResume() { super.onResume(); - TextView message = findViewById(R.id.list_view_title); - message.setText("Streams:\n (disable all for default)"); + RsContext ctx = new RsContext(); + try(DeviceList devices = ctx.queryDevices()) { + if (devices.getDeviceCount() == 0) { + return; + } + Device device = ctx.queryDevices().createDevice(0); + loadSettingsList(device); + StreamProfileSelector[] profilesList = createSettingList(device); + loadStreamList(device, profilesList); + } catch(Exception e){ + Log.e(TAG, "failed to load settings, error: " + e.getMessage()); + Toast.makeText(this, "Failed to load settings", Toast.LENGTH_LONG).show(); + finish(); + } + } + + private void loadSettingsList(final Device device){ + final ListView listview = findViewById(R.id.settings_list_view); + + Map settingsMap = new TreeMap<>(); + settingsMap.put(INDEX_DEVICE_INFO,"Device info"); + settingsMap.put(INDEX_ADVANCE_MODE,"Enable advanced mode"); + + if(device.supportsInfo(CameraInfo.ADVANCED_MODE) && device.isInAdvancedMode()){ + settingsMap.put(INDEX_ADVANCE_MODE,"Disable advanced mode"); + settingsMap.put(INDEX_PRESETS,"Presets"); + } + final String[] settings = new String[settingsMap.values().size()]; + settingsMap.values().toArray(settings); + final ArrayAdapter adapter = new ArrayAdapter<>(this, R.layout.files_list_view, settings); + listview.setAdapter(adapter); + + listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { + + @Override + public void onItemClick(AdapterView parent, final View view, + int position, long id) { + switch (position){ + case INDEX_DEVICE_INFO: { + Intent intent = new Intent(SettingsActivity.this, InfoActivity.class); + startActivity(intent); + break; + } + case INDEX_ADVANCE_MODE: device.toggleAdvancedMode(!device.isInAdvancedMode()); + break; + case INDEX_PRESETS: { + Intent intent = new Intent(SettingsActivity.this, PresetsActivity.class); + startActivity(intent); + break; + } + default: + break; + } + } + }); + } - loadStreamList(createSettingList()); + private static String getDeviceConfig(String pid, StreamType streamType, int streamIndex){ + return pid + "_" + streamType.name() + "_" + streamIndex; } - private void loadStreamList(CheckableTwoLinesListCell[] lines){ + public static String getEnabledDeviceConfigString(String pid, StreamType streamType, int streamIndex){ + return getDeviceConfig(pid, streamType, streamIndex) + "_enabled"; + } + + public static String getIndexdDeviceConfigString(String pid, StreamType streamType, int streamIndex){ + return getDeviceConfig(pid, streamType, streamIndex) + "_index"; + } + + public static Map> createProfilesMap(Device device){ + Map> rv = new HashMap<>(); + List sensors = device.querySensors(); + for (Sensor s : sensors){ + List profiles = s.getStreamProfiles(); + for (StreamProfile p : profiles){ + Pair pair = new Pair<>(p.getType(), p.getIndex()); + if(!rv.containsKey(pair.hashCode())) + rv.put(pair.hashCode(), new ArrayList()); + VideoStreamProfile vsp = p.as(VideoStreamProfile.class); + rv.get(pair.hashCode()).add(vsp); + } + } + return rv; + } + + private void loadStreamList(Device device, StreamProfileSelector[] lines){ if(lines == null) return; - final CheckableTwoLinesListCellAdapter adapter = new CheckableTwoLinesListCellAdapter(this, lines, new CheckableTwoLinesListCellAdapter.Listener() { + final String pid = device.getInfo(CameraInfo.PRODUCT_ID); + final StreamProfileAdapter adapter = new StreamProfileAdapter(this, lines, new StreamProfileAdapter.Listener() { @Override - public void onCheckedChanged(CheckableTwoLinesListCell holder) { + public void onCheckedChanged(StreamProfileSelector holder) { SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); - editor.putBoolean(holder.getMainString(), holder.isEnabled()); + VideoStreamProfile p = holder.getProfile(); + editor.putBoolean(getEnabledDeviceConfigString(pid, p.getType(), p.getIndex()), holder.isEnabled()); + editor.putInt(getIndexdDeviceConfigString(pid, p.getType(), p.getIndex()), holder.getIndex()); editor.commit(); } }); - ListView streamListView = findViewById(R.id.list_view); + ListView streamListView = findViewById(R.id.configuration_list_view); streamListView.setAdapter(adapter); adapter.notifyDataSetChanged(); } - private CheckableTwoLinesListCell[] createSettingList(){ + private StreamProfileSelector[] createSettingList(final Device device){ + Map> profilesMap = createProfilesMap(device); - List settingsLines = new ArrayList<>(); - settingsLines.add(createLine(StreamType.COLOR)); - settingsLines.add(createLine(StreamType.DEPTH)); - settingsLines.add(createLine(StreamType.INFRARED)); + SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE); + String pid = device.getInfo(CameraInfo.PRODUCT_ID); - return settingsLines.toArray(new CheckableTwoLinesListCell[settingsLines.size()]); - } + List lines = new ArrayList<>(); + for(Map.Entry e : profilesMap.entrySet()){ + List list = (List) e.getValue(); + VideoStreamProfile p = list.get(0); + boolean enabled = sharedPref.getBoolean(getEnabledDeviceConfigString(pid, p.getType(), p.getIndex()), false); + int index = sharedPref.getInt(getIndexdDeviceConfigString(pid, p.getType(), p.getIndex()), 0); + lines.add(new StreamProfileSelector(enabled, index, list)); + } - private CheckableTwoLinesListCell createLine(StreamType streamType){ - SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE); + Collections.sort(lines); - return new CheckableTwoLinesListCell(streamType.name(), "", sharedPref.getBoolean(streamType.name(), false)); + return lines.toArray(new StreamProfileSelector[lines.size()]); } } diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamProfileAdapter.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamProfileAdapter.java new file mode 100644 index 0000000000..f459b6fe3a --- /dev/null +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamProfileAdapter.java @@ -0,0 +1,146 @@ +package com.intel.realsense.camera; + +import android.app.Activity; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CompoundButton; +import android.widget.Spinner; +import android.widget.Switch; + +import com.intel.realsense.librealsense.VideoStreamProfile; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; + +public class StreamProfileAdapter extends ArrayAdapter { + private static final int mLayoutResourceId = R.layout.stream_profile_list_view; + private final StreamProfileSelector mStreamProfileCells[]; + private final LayoutInflater mLayoutInflater; + private final Listener mListener; + private Context mContext; + + public StreamProfileAdapter(Context context, StreamProfileSelector[] data, Listener listener){ + super(context, mLayoutResourceId, data); + mLayoutInflater = ((Activity) context).getLayoutInflater(); + mStreamProfileCells = data; + mListener = listener; + mContext = context; + } + + public class Holder { + private Switch type; + private Spinner index; + private Spinner resolution; + private Spinner fps; + private Spinner format; + } + + @Override + public View getView(int position, View rawView, final ViewGroup parent){ + rawView = mLayoutInflater.inflate(mLayoutResourceId, parent, false); + StreamProfileSelector listViewLine = mStreamProfileCells[position]; + + final Holder holder; + holder = new Holder(); + holder.type = rawView.findViewById(R.id.stream_type_switch); + holder.resolution = rawView.findViewById(R.id.resolution_spinner); + holder.fps = rawView.findViewById(R.id.fps_spinner); + holder.format = rawView.findViewById(R.id.format_spinner); + + holder.type.setText(listViewLine.getName()); + holder.type.setChecked(listViewLine.isEnabled()); + holder.type.setTag(position); + + createSpinners(holder, position, listViewLine); + + return rawView; + } + + interface Listener{ + void onCheckedChanged(StreamProfileSelector holder); + } + + void createSpinners(final Holder holder, final int position, StreamProfileSelector sps){ + Set formatsSet = new HashSet<>(); + Set frameRatesSet = new HashSet<>(); + Set resolutionsSet = new HashSet<>(); + + for(VideoStreamProfile sp : sps.getProfiles()){ + formatsSet.add(sp.getFormat().name()); + frameRatesSet.add(String.valueOf(sp.getFrameRate())); + resolutionsSet.add(String.valueOf(sp.getWidth()) + "x" + String.valueOf(sp.getHeight())); + } + + ArrayList formats = new ArrayList<>(formatsSet); + ArrayList frameRates = new ArrayList<>(frameRatesSet); + ArrayList resolutions = new ArrayList<>(resolutionsSet); + + //formats + ArrayAdapter formatsAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, formats); + formatsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + holder.format.setAdapter(formatsAdapter); + holder.format.setSelection(formats.indexOf(sps.getProfile().getFormat().name())); + holder.format.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + StreamProfileSelector s = mStreamProfileCells[position]; + String str = (String) adapterView.getItemAtPosition(i); + s.updateFormat(str); + mListener.onCheckedChanged(s); + } + @Override + public void onNothingSelected(AdapterView adapterView) { } + }); + + //frame rates + ArrayAdapter frameRatesAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, frameRates); + frameRatesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + holder.fps.setAdapter(frameRatesAdapter); + holder.fps.setSelection(frameRates.indexOf(String.valueOf(sps.getProfile().getFrameRate()))); + holder.fps.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + StreamProfileSelector s = mStreamProfileCells[position]; + String str = (String) adapterView.getItemAtPosition(i); + s.updateFrameRate(str); + mListener.onCheckedChanged(s); + } + @Override + public void onNothingSelected(AdapterView adapterView) { } + }); + + //resolutions + ArrayAdapter resolutionsAdapter = new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, resolutions); + resolutionsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + holder.resolution.setAdapter(resolutionsAdapter); + holder.resolution.setSelection(resolutions.indexOf(sps.getResolutionString())); + holder.resolution.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + StreamProfileSelector s = mStreamProfileCells[position]; + String str = (String) adapterView.getItemAtPosition(i); + s.updateResolution(str); + mListener.onCheckedChanged(s); + } + @Override + public void onNothingSelected(AdapterView adapterView) { } + }); + + holder.type.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { + int position = (int) compoundButton.getTag(); + StreamProfileSelector s = mStreamProfileCells[position]; + s.updateEnabled(b); + mListener.onCheckedChanged(s); + + } + }); + } +} + diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamProfileSelector.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamProfileSelector.java new file mode 100644 index 0000000000..f0334a553d --- /dev/null +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamProfileSelector.java @@ -0,0 +1,87 @@ +package com.intel.realsense.camera; + +import android.support.annotation.NonNull; + +import com.intel.realsense.librealsense.StreamFormat; +import com.intel.realsense.librealsense.StreamType; +import com.intel.realsense.librealsense.VideoStreamProfile; + +import java.util.List; + +public class StreamProfileSelector implements Comparable { + private StreamFormat mFormat = StreamFormat.ANY; + private int mWidth = 0; + private int mHeight = 0; + private int mFps = 0; + private boolean mEnabled; + private int mIndex; + private List mProfiles; + + public StreamProfileSelector(boolean enable, int index, List profiles) + { + mIndex = index < profiles.size() ? index : 0; + mEnabled = enable; + mProfiles = profiles; + } + + public boolean isEnabled() { return mEnabled; } + + public List getProfiles() { return mProfiles; } + + public int getIndex() { return mIndex; } + + public String getName(){ + VideoStreamProfile p = getProfile(); + if(p.getType() == StreamType.INFRARED) + return p.getType().name() + "-" + p.getIndex(); + return p.getType().name(); + } + + public VideoStreamProfile getProfile() { + if(mIndex < 0 || mIndex >= mProfiles.size()) + return mProfiles.get(0); + return mProfiles.get(mIndex); + } + + public String getResolutionString() { return String.valueOf(getProfile().getWidth()) + "x" + String.valueOf(getProfile().getHeight()); } + + private int findIndex(StreamFormat format, int fps, int width, int height){ + int currIndex = 0; + for(VideoStreamProfile vsp : mProfiles){ + if(vsp.getFormat() == format && + vsp.getWidth() == width && + vsp.getHeight() == height && + vsp.getFrameRate() == fps){ + return currIndex; + } + currIndex++; + } + return -1; + } + + public void updateFormat(String str) { + mFormat = StreamFormat.valueOf(str); + mIndex = findIndex(mFormat, mFps, mWidth, mHeight); + } + + public void updateResolution(String str) { + mWidth = Integer.parseInt(str.split("x")[0]); + mHeight = Integer.parseInt(str.split("x")[1]); + mIndex = findIndex(mFormat, mFps, mWidth, mHeight); + } + + public void updateFrameRate(String str) { + mFps = Integer.parseInt(str); + mIndex = findIndex(mFormat, mFps, mWidth, mHeight); + } + + public void updateEnabled(boolean state) { + mEnabled = state; + mIndex = findIndex(mFormat, mFps, mWidth, mHeight); + } + + @Override + public int compareTo(@NonNull StreamProfileSelector streamProfileSelector) { + return getName().compareTo(streamProfileSelector.getName()); + } +} diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/Streamer.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/Streamer.java index b208eac7fb..4709ade9ad 100644 --- a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/Streamer.java +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/Streamer.java @@ -5,34 +5,39 @@ import android.os.Handler; import android.util.Log; -import com.intel.realsense.librealsense.Colorizer; +import com.intel.realsense.librealsense.CameraInfo; import com.intel.realsense.librealsense.Config; +import com.intel.realsense.librealsense.Device; +import com.intel.realsense.librealsense.DeviceList; import com.intel.realsense.librealsense.FrameSet; -import com.intel.realsense.librealsense.GLRsSurfaceView; import com.intel.realsense.librealsense.Pipeline; -import com.intel.realsense.librealsense.StreamType; +import com.intel.realsense.librealsense.RsContext; +import com.intel.realsense.librealsense.VideoStreamProfile; + +import java.util.List; +import java.util.Map; public class Streamer { private static final String TAG = "librs camera streamer"; interface Listener{ void config(Config config); + void onFrameset(FrameSet frameSet); } private final Context mContext; - private final GLRsSurfaceView mGLSurfaceView; + private final boolean mLoadConfig; private boolean mIsStreaming = false; private final Handler mHandler = new Handler(); private final Listener mListener; private Pipeline mPipeline; - private Colorizer mColorizer = new Colorizer(); - public Streamer(Context context,GLRsSurfaceView view, Listener listener){ - mGLSurfaceView = view; + public Streamer(Context context, boolean loadConfig, Listener listener){ mContext = context; mListener = listener; + mLoadConfig = loadConfig; } private Runnable mStreaming = new Runnable() { @@ -40,9 +45,7 @@ public Streamer(Context context,GLRsSurfaceView view, Listener listener){ public void run() { try { try(FrameSet frames = mPipeline.waitForFrames(1000)) { - try (FrameSet processed = frames.applyFilter(mColorizer)) { - mGLSurfaceView.upload(processed); - } + mListener.onFrameset(frames); } mHandler.post(mStreaming); } @@ -52,37 +55,62 @@ public void run() { } }; - void configStream(Config config, StreamType streamType){ + private void configStream(Config config){ + config.disableAllStreams(); + RsContext ctx = new RsContext(); + try(DeviceList devices = ctx.queryDevices()) { + if (devices.getDeviceCount() == 0) { + return; + } + } + String pid; + Map> profilesMap; + try(Device device = ctx.queryDevices().createDevice(0)){ + pid = device.getInfo(CameraInfo.PRODUCT_ID); + profilesMap = SettingsActivity.createProfilesMap(device); + } + SharedPreferences sharedPref = mContext.getSharedPreferences(mContext.getString(R.string.app_settings), Context.MODE_PRIVATE); - if(sharedPref.getBoolean(streamType.name(), false)) - config.enableStream(streamType); + + for(Map.Entry e : profilesMap.entrySet()){ + List profiles = (List) e.getValue(); + VideoStreamProfile p = profiles.get(0); + if(!sharedPref.getBoolean(SettingsActivity.getEnabledDeviceConfigString(pid, p.getType(), p.getIndex()), false)) + continue; + int index = sharedPref.getInt(SettingsActivity.getIndexdDeviceConfigString(pid, p.getType(), p.getIndex()), 0); + if(index == -1 || index >= profiles.size()) + throw new IllegalArgumentException("Failed to resolve config"); + VideoStreamProfile sp = profiles.get(index); + VideoStreamProfile vsp = sp.as(VideoStreamProfile.class); + config.enableStream(vsp.getType(), vsp.getIndex(), vsp.getWidth(), vsp.getHeight(), vsp.getFormat(), vsp.getFrameRate()); + } } void configAndStart() throws Exception { try(Config config = new Config()){ - configStream(config, StreamType.COLOR); - configStream(config, StreamType.DEPTH); - configStream(config, StreamType.INFRARED); + if(mLoadConfig) + configStream(config); if(mListener != null) mListener.config(config); mPipeline.start(config); - try(FrameSet frames = mPipeline.waitForFrames(15000)){} // w/a for l500 } } - public synchronized void start() { + public synchronized void start() throws Exception { if(mIsStreaming) return; try{ mPipeline = new Pipeline(); - mGLSurfaceView.clear(); Log.d(TAG, "try start streaming"); configAndStart(); + try(FrameSet frames = mPipeline.waitForFrames(15000)){} // w/a for l500 mIsStreaming = true; mHandler.post(mStreaming); Log.d(TAG, "streaming started successfully"); } catch (Exception e) { - Log.d(TAG, "failed to start streaming"); + Log.e(TAG, "failed to start streaming"); + mPipeline.close(); + throw e; } } @@ -97,7 +125,7 @@ public synchronized void stop() { mPipeline.close(); Log.d(TAG, "streaming stopped successfully"); } catch (Exception e) { - Log.d(TAG, "failed to stop streaming"); + Log.w(TAG, "failed to stop streaming"); mPipeline = null; } } diff --git a/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamingStats.java b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamingStats.java new file mode 100644 index 0000000000..3f8dfcaa71 --- /dev/null +++ b/wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/StreamingStats.java @@ -0,0 +1,117 @@ +package com.intel.realsense.camera; + +import com.intel.realsense.librealsense.Frame; +import com.intel.realsense.librealsense.FrameCallback; +import com.intel.realsense.librealsense.FrameSet; +import com.intel.realsense.librealsense.StreamProfile; +import com.intel.realsense.librealsense.VideoStreamProfile; + +import java.util.HashMap; +import java.util.Map; + +public class StreamingStats { + private static final String TAG = "librs camera streamer"; + + private Map mStreamsMap = new HashMap<>(); + private Map mLastFrames = new HashMap<>(); + + private void initStream(StreamProfile profile){ + VideoStreamProfile vsp = profile.as(VideoStreamProfile.class); + String name = vsp.getType().name() + " | " + + vsp.getFormat().name() + " | " + + vsp.getWidth() + "x" + vsp.getHeight() + " | " + + vsp.getFrameRate(); + mStreamsMap.put(profile.getUniqueId(), new Statistics(name)); + mLastFrames.put(profile.getUniqueId(), 0); + } + + private FrameCallback mFrameCallback = new FrameCallback() { + @Override + public void onFrame(Frame f) { + try(StreamProfile profile = f.getProfile()) { + if (!mLastFrames.containsKey(f.getProfile().getUniqueId())) + initStream(profile); + if (mLastFrames.get(f.getProfile().getUniqueId()) != f.getNumber()) { + mLastFrames.put(f.getProfile().getUniqueId(), f.getNumber()); + mStreamsMap.get(f.getProfile().getUniqueId()).onFrame(); + } + else + mStreamsMap.get(f.getProfile().getUniqueId()).kick(); + } + } + }; + + public void onFrameset(FrameSet frames){ + frames.foreach(mFrameCallback); + } + + public String prettyPrint(){ + String rv = ""; + for(Map.Entry e : mStreamsMap.entrySet()){ + rv += ((Statistics)e.getValue()).prettyPrint() + "\n\n"; + } + return rv; + } + + private class Statistics{ + private final String mName; + private long mStartTime; + private long mBaseTime; + private float mFps; + private long mFrameCount; + private long mTotalFrameCount; + private long mFirstFrameLatency; + + public void reset(){ + mStartTime = mBaseTime = System.currentTimeMillis(); + mFirstFrameLatency = 0; + } + + public Statistics(String name) { + mName = name; + reset(); + } + + public float getFps(){ + return mFps; + } + public float getFrameCount(){ + return mTotalFrameCount; + } + public String prettyPrint(){ + long curr = System.currentTimeMillis(); + int diffInSeconds = (int) ((curr - mStartTime) * 0.001); + return mName + + "\nFrame Rate: " + mFps + + "\nFrame Count: " + mTotalFrameCount + + "\nRun Time: " + diffInSeconds + " [sec]"; + } + + public synchronized void kick(){ + long curr = System.currentTimeMillis(); + float diffInSeconds = (float) ((curr - mBaseTime) * 0.001); + if(diffInSeconds > 2){ + mFps = mFrameCount / diffInSeconds; + mFrameCount = 0; + mBaseTime = curr; + } + } + + public synchronized void onFrame(){ + mFrameCount++; + mTotalFrameCount++; + long curr = System.currentTimeMillis(); + float diffInSeconds = (float) ((curr - mBaseTime) * 0.001); + if(mFirstFrameLatency == 0){ + mFirstFrameLatency = curr - mBaseTime; + } + if(diffInSeconds > 2){ + mFps = mFrameCount / diffInSeconds; + mFrameCount = 0; + mBaseTime = curr; + } + } + } + + +} diff --git a/wrappers/android/tools/camera/src/main/res/layout-land/activity_preview.xml b/wrappers/android/tools/camera/src/main/res/layout-land/activity_preview.xml new file mode 100644 index 0000000000..e2a10af0f1 --- /dev/null +++ b/wrappers/android/tools/camera/src/main/res/layout-land/activity_preview.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wrappers/android/tools/camera/src/main/res/layout-land/activity_recording.xml b/wrappers/android/tools/camera/src/main/res/layout-land/activity_recording.xml new file mode 100644 index 0000000000..a88ac23f83 --- /dev/null +++ b/wrappers/android/tools/camera/src/main/res/layout-land/activity_recording.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/wrappers/android/tools/camera/src/main/res/layout/activity_info.xml b/wrappers/android/tools/camera/src/main/res/layout/activity_info.xml new file mode 100644 index 0000000000..39ead0d426 --- /dev/null +++ b/wrappers/android/tools/camera/src/main/res/layout/activity_info.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/wrappers/android/tools/camera/src/main/res/layout/activity_list_view.xml b/wrappers/android/tools/camera/src/main/res/layout/activity_list_view.xml index 1f422b0e1c..66c098a945 100644 --- a/wrappers/android/tools/camera/src/main/res/layout/activity_list_view.xml +++ b/wrappers/android/tools/camera/src/main/res/layout/activity_list_view.xml @@ -14,7 +14,7 @@ android:layout_gravity="left|top" android:background="@color/black" android:textSize="20dp" - android:text="Select a file to play from:" + android:text="" android:textColor="#ffffff"/> + + + \ No newline at end of file diff --git a/wrappers/android/tools/camera/src/main/res/layout/activity_preview.xml b/wrappers/android/tools/camera/src/main/res/layout/activity_preview.xml index e446043511..3e470ab642 100644 --- a/wrappers/android/tools/camera/src/main/res/layout/activity_preview.xml +++ b/wrappers/android/tools/camera/src/main/res/layout/activity_preview.xml @@ -12,47 +12,84 @@ android:layout_height="match_parent" android:id="@+id/glSurfaceView"/> - - - - - + android:background="@color/black" + android:textSize="20dp" + android:text="Show stats" + android:textColor="#ffffff" + android:visibility="gone"/> - + android:layout_marginBottom="100dp"> + + + + + + + + + + + + + + + + + android:backgroundTint="#ffffff" + app:srcCompat="@android:drawable/ic_notification_overlay" /> \ No newline at end of file diff --git a/wrappers/android/tools/camera/src/main/res/layout/activity_recording.xml b/wrappers/android/tools/camera/src/main/res/layout/activity_recording.xml index 06a5f9a234..95a5bd2336 100644 --- a/wrappers/android/tools/camera/src/main/res/layout/activity_recording.xml +++ b/wrappers/android/tools/camera/src/main/res/layout/activity_recording.xml @@ -27,7 +27,7 @@ android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" - android:layout_marginBottom="40dp" + android:layout_marginBottom="20dp" android:clickable="true" android:backgroundTint="#000000" app:srcCompat="@android:drawable/ic_media_pause" /> diff --git a/wrappers/android/tools/camera/src/main/res/layout/activity_settings.xml b/wrappers/android/tools/camera/src/main/res/layout/activity_settings.xml new file mode 100644 index 0000000000..ff31a7c3e9 --- /dev/null +++ b/wrappers/android/tools/camera/src/main/res/layout/activity_settings.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + diff --git a/wrappers/android/tools/camera/src/main/res/layout/checkable_list_view.xml b/wrappers/android/tools/camera/src/main/res/layout/checkable_list_view.xml deleted file mode 100644 index 2b0a44b26d..0000000000 --- a/wrappers/android/tools/camera/src/main/res/layout/checkable_list_view.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/wrappers/android/tools/camera/src/main/res/layout/stream_profile_list_view.xml b/wrappers/android/tools/camera/src/main/res/layout/stream_profile_list_view.xml new file mode 100644 index 0000000000..a61679dcda --- /dev/null +++ b/wrappers/android/tools/camera/src/main/res/layout/stream_profile_list_view.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file