Skip to content

Commit

Permalink
Merge pull request #5789 from remibettan/DSO-14133
Browse files Browse the repository at this point in the history
Android multicam fix
  • Loading branch information
dorodnic committed Feb 6, 2020
2 parents a2f4808 + d51f292 commit e863bd8
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/android/jni/sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ Java_com_intel_realsense_librealsense_Sensor_nGetStreamProfiles(JNIEnv *env, jcl
return rv;
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_com_intel_realsense_librealsense_Sensor_nIsSensorExtendableTo(JNIEnv *env, jclass type,
jlong handle, jint extension) {
rs2_error *e = NULL;
int rv = rs2_is_sensor_extendable_to(reinterpret_cast<const rs2_sensor *>(handle),
static_cast<rs2_extension>(extension), &e);
handle_error(env, e);
return rv > 0;
}


extern "C"
JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_RoiSensor_nSetRegionOfInterest(JNIEnv *env, jclass clazz,
Expand Down Expand Up @@ -75,4 +87,14 @@ Java_com_intel_realsense_librealsense_RoiSensor_nGetRegionOfInterest(JNIEnv *env
env->SetIntField(roi, min_y_field, min_y);
env->SetIntField(roi, max_x_field, max_x);
env->SetIntField(roi, max_y_field, max_y);
}

extern "C"
JNIEXPORT jfloat JNICALL
Java_com_intel_realsense_librealsense_DepthSensor_nGetDepthScale(JNIEnv *env, jclass clazz,
jlong handle) {
rs2_error* e = nullptr;
float depthScale = rs2_get_depth_scale(reinterpret_cast<rs2_sensor *>(handle), &e);
handle_error(env, e);
return depthScale;
}
24 changes: 22 additions & 2 deletions src/uvc/uvc-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ const int CONTROL_TRANSFER_TIMEOUT = 100;
const int INTERRUPT_BUFFER_SIZE = 1024;
const int FIRST_FRAME_MILLISECONDS_TIMEOUT = 2000;

class lock_singleton
{
public:
static lock_singleton& instance()
{
static lock_singleton inst;
return inst;
}
static void lock();
static void unlock();

private:
static std::recursive_mutex m;
};
std::recursive_mutex lock_singleton::m;
void lock_singleton::lock() { m.lock(); }
void lock_singleton::unlock() { m.unlock(); }


namespace librealsense
{
namespace platform
Expand Down Expand Up @@ -301,14 +320,15 @@ namespace librealsense
return results;
}


void rs_uvc_device::lock() const
{

lock_singleton::instance().lock();
}

void rs_uvc_device::unlock() const
{

lock_singleton::instance().unlock();
}

std::string rs_uvc_device::get_device_location() const
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.intel.realsense.librealsense;

public class ColorSensor extends Sensor {

ColorSensor(long handle) {
super(handle);
mOwner = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.intel.realsense.librealsense;

public class DepthSensor extends Sensor {

DepthSensor(long handle) {
super(handle);
mOwner = false;
}

public float getDepthScale() { return nGetDepthScale(mHandle); }


private static native float nGetDepthScale(long handle);
}

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ public enum Extension {
WHEEL_ODOMETER(35),
GLOBAL_TIMER(36),
UPDATABLE(37),
UPDATE_DEVICE(38);
UPDATE_DEVICE(38),
L500_DEPTH_SENSOR(39),
TM2_SENSOR(40),
AUTO_CALIBRATED_DEVICE(41),
COLOR_SENSOR(42),
MOTION_SENSOR(43),
FISHEYE_SENSOR(44),
DEPTH_HUFFMAN_DECODER(45);

private final int mValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public Pipeline(){
mHandle = nCreate(ctx.getHandle());
}

public Pipeline(RsContext ctx){
mHandle = nCreate(ctx.getHandle());
}

public PipelineProfile start() throws Exception{
return new PipelineProfile(nStart(mHandle));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ public List<StreamProfile> getStreamProfiles(){
return rv;
}

public <T extends Sensor> T as(Extension extension) {
switch (extension){
case ROI: return (T) new RoiSensor(mHandle);
public <T extends Sensor> T as(Extension extension) throws RuntimeException {
if (this.is(extension)) {
switch (extension){
case ROI: return (T) new RoiSensor(mHandle);
case DEPTH_SENSOR: return (T) new DepthSensor(mHandle);
case COLOR_SENSOR: return (T) new ColorSensor(mHandle);
default: throw new RuntimeException("this API version does not support " + extension.name());
}
} else{
throw new RuntimeException("this sensor is not extendable to " + extension.name());
}
throw new RuntimeException("this sensor is not extendable to " + extension.name());
}

public boolean is(Extension extension) {
return nIsSensorExtendableTo(mHandle, extension.value());
}

@Override
Expand All @@ -33,4 +43,5 @@ public void close() {

private static native long[] nGetStreamProfiles(long handle);
private static native void nRelease(long handle);
private static native boolean nIsSensorExtendableTo(long handle, int extension);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ public enum StreamFormat {
DISPARITY32(19),
Y10BPACK(20),
DISTANCE(21),
MJPEG(22);
MJPEG(22),
Y8I(23),
Y12I(24),
INZI(25),
INVI(26),
W10(27),
Z16H(28);
private final int mValue;

private StreamFormat(int value) { mValue = value; }
Expand Down

0 comments on commit e863bd8

Please sign in to comment.