Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android streamer start time increase fix #5792

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public void config(Config config) {

}


@Override
public void onFrameset(final FrameSet frameSet) {
mStreamingStats.onFrameset(frameSet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ private void loadSettingsList(final Device device){
settingsMap.put(INDEX_ADVANCE_MODE,"Enable advanced mode");
if(device.is(Extension.UPDATABLE)){
settingsMap.put(INDEX_UPDATE,"Firmware update");
Updatable fwud = device.as(Extension.UPDATABLE);
if(fwud != null && fwud.supportsInfo(CameraInfo.CAMERA_LOCKED) && fwud.getInfo(CameraInfo.CAMERA_LOCKED).equals("NO"))
settingsMap.put(INDEX_UPDATE_UNSIGNED,"Firmware update (unsigned)");
try(Updatable fwud = device.as(Extension.UPDATABLE)){
ev-mp marked this conversation as resolved.
Show resolved Hide resolved
if(fwud != null && fwud.supportsInfo(CameraInfo.CAMERA_LOCKED) && fwud.getInfo(CameraInfo.CAMERA_LOCKED).equals("NO"))
settingsMap.put(INDEX_UPDATE_UNSIGNED,"Firmware update (unsigned)");
}
}

if(device.supportsInfo(CameraInfo.ADVANCED_MODE) && device.isInAdvancedMode()){
Expand Down Expand Up @@ -222,9 +223,10 @@ public FlashBackupTask(Device mDevice) {

@Override
protected Void doInBackground(Void... voids) {
final Updatable upd = mDevice.as(Extension.UPDATABLE);
FileUtilities.saveFileToExternalDir(mBackupFileName, upd.createFlashBackup());
return null;
try(final Updatable upd = mDevice.as(Extension.UPDATABLE)){
FileUtilities.saveFileToExternalDir(mBackupFileName, upd.createFlashBackup());
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ private void send() {
return;
}
try(Device device = devices.createDevice(0)){
DebugProtocol dp = device.as(Extension.DEBUG);
String content = mInputText.getText().toString();
String res = dp.SendAndReceiveRawData(mFilePath, content);
mOutputText.setText("command: " + mInputText.getText() + "\n\n" + res);
mInputText.setText("");
try(DebugProtocol dp = device.as(Extension.DEBUG)){
String content = mInputText.getText().toString();
String res = dp.SendAndReceiveRawData(mFilePath, content);
mOutputText.setText("command: " + mInputText.getText() + "\n\n" + res);
mInputText.setText("");
}
}
catch(Exception e){
mOutputText.setText("Error: " + e.getMessage());
Expand Down