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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/android/jni/frameset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Java_com_intel_realsense_librealsense_FrameSet_nAddRef(JNIEnv *env, jclass type,
extern "C" JNIEXPORT void JNICALL
Java_com_intel_realsense_librealsense_FrameSet_nRelease(JNIEnv *env, jclass type,
jlong handle) {
if(handle)
rs2_release_frame(reinterpret_cast<rs2_frame *>(handle));
}

Expand Down
2 changes: 1 addition & 1 deletion src/archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ namespace librealsense

void frame::release()
{
if (ref_count.fetch_sub(1) == 1)
if (ref_count.fetch_sub(1) == 1 && owner)
{
unpublish();
on_release();
Expand Down
2 changes: 1 addition & 1 deletion src/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ namespace librealsense
}
void frame_source::invoke_callback(frame_holder frame) const
{
if (frame)
if (frame && frame.frame && frame.frame->get_owner())
{
auto callback = frame.frame->get_owner()->begin_callback();
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public byte[] createTexture(Points points){
public synchronized void close() {
if(mFrame != null)
mFrame.close();

if (mTexture != null) {
mTexture.close();
mTexture = null;
}

if(mGlTexture != null)
GLES10.glDeleteTextures(1, mGlTexture);
mGlTexture = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@ public class GLRenderer implements GLSurfaceView.Renderer, AutoCloseable{
private Colorizer mColorizer = new Colorizer();
private Map<StreamType,Pointcloud> mPointcloud = null;
private boolean mHasColorizedDepth = false;
private boolean mHasDepth = false;

private boolean mHasColorYuy = false;
private YuyDecoder mYuyDecoder = new YuyDecoder();
private boolean mShowPoints = false;

public Map<Integer, Pair<String,Rect>> getRectangles() {
return calcRectangles();
}

private boolean showPoints(){
return mPointcloud != null;
return mShowPoints;
}

private List<FilterInterface> createProcessingPipe(){
List<FilterInterface> rv = new ArrayList<>();
if(!mHasColorizedDepth && !showPoints())
if(mHasDepth && !mHasColorizedDepth && !showPoints())
rv.add(mColorizer);

// convert yuyv into rgb8 for display and uv mapping
Expand All @@ -50,14 +52,15 @@ private List<FilterInterface> createProcessingPipe(){
if(showPoints()){
if(mHasColorRbg8 || mHasColorYuy)
rv.add(mPointcloud.get(StreamType.COLOR));
else
else if (mHasDepth)
rv.add(mPointcloud.get(StreamType.DEPTH));
}
return rv;
}

private FrameSet applyFilters(FrameSet frameSet, List<FilterInterface> filters){
frameSet = frameSet.clone();

for(FilterInterface f : filters){
FrameSet newSet = frameSet.applyFilter(f);
frameSet.close();
Expand All @@ -67,7 +70,8 @@ private FrameSet applyFilters(FrameSet frameSet, List<FilterInterface> filters){
}

public void upload(FrameSet frameSet) {
mHasColorRbg8 = mHasColorizedDepth = mHasColorYuy = false;
mHasColorRbg8 = mHasColorizedDepth = mHasColorYuy = mHasDepth = false;

frameSet.foreach(new FrameCallback() {
@Override
public void onFrame(Frame f) {
Expand All @@ -76,27 +80,36 @@ public void onFrame(Frame f) {
});

List<FilterInterface> filters = createProcessingPipe();
try(FrameSet processed = applyFilters(frameSet, filters)){
choosePointsTexture(processed);
processed.foreach(new FrameCallback() {
@Override
public void onFrame(Frame f) {
addFrame(f);
upload(f);
}
});

if (!showPoints() || (showPoints() && filters.size() > 0 && mHasDepth)) {
try (FrameSet processed = applyFilters(frameSet, filters)) {
choosePointsTexture(processed);
processed.foreach(new FrameCallback() {
@Override
public void onFrame(Frame f) {
upload(f);
}
});
}
}
}

private void choosePointsTexture(FrameSet frameSet){
if(!showPoints())
if(mPointsTexture != null) mPointsTexture.close();
mPointsTexture = null;

if(!showPoints()) {
return;
}

if(mHasColorRbg8 || mHasColorYuy)
mPointsTexture = frameSet.first(StreamType.COLOR, StreamFormat.RGB8);
else{
try (Frame d = frameSet.first(StreamType.DEPTH, StreamFormat.Z16)) {
if(d != null)
if(d != null) {
mPointsTexture = mColorizer.process(d);
d.close();
}
}
}
}
Expand All @@ -111,8 +124,12 @@ private void getTexture(Frame f){
mHasColorYuy = true;
}

if(sp.getType() == StreamType.DEPTH && sp.getFormat() == StreamFormat.RGB8) {
mHasColorizedDepth = true;
if(sp.getType() == StreamType.DEPTH) {
mHasDepth = true;

if (sp.getFormat() == StreamFormat.RGB8) {
mHasColorizedDepth = true;
}
}
}
}
Expand All @@ -122,13 +139,14 @@ private void addFrame(Frame f){
if(!isFormatSupported(sp.getFormat()))
return;
int uid = sp.getUniqueId();

if(!mFrames.containsKey(uid)){
synchronized (mFrames) {
if(f.is(Extension.VIDEO_FRAME) && !showPoints())
mFrames.put(uid, new GLVideoFrame());
if(f.is(Extension.MOTION_FRAME) && !showPoints())
else if (f.is(Extension.MOTION_FRAME) && !showPoints())
mFrames.put(uid, new GLMotionFrame());
if(f.is(Extension.POINTS))
else if (f.is(Extension.POINTS))
mFrames.put(uid, new GLPointsFrame());
}
}
Expand All @@ -149,6 +167,7 @@ public void upload(Frame f) {
GLFrame curr = mFrames.get(uid);
if(curr == null)
return;

curr.setFrame(f);

if(mPointsTexture != null && curr instanceof GLPointsFrame){
Expand All @@ -161,8 +180,13 @@ public void upload(Frame f) {

public void clear() {
synchronized (mFrames) {
for(Map.Entry<Integer,GLFrame> f : mFrames.entrySet())
f.getValue().close();
for(Map.Entry<Integer,GLFrame> f : mFrames.entrySet()) {
GLFrame frame = f.getValue();
if (frame instanceof GLPointsFrame)
((GLPointsFrame) frame).close();
else
frame.close();
}
mFrames.clear();
mDeltaX = 0;
mDeltaY = 0;
Expand All @@ -178,6 +202,8 @@ public void clear() {

if(mPointsTexture != null) mPointsTexture.close();
mPointsTexture = null;

mHasColorRbg8 = mHasColorizedDepth = mHasColorYuy = mHasDepth = false;
}
}

Expand Down Expand Up @@ -257,6 +283,8 @@ public void onTouchEvent(float dx, float dy) {
}

public void showPointcloud(boolean showPoints) {
mShowPoints = showPoints;

if(showPoints){
if(mPointcloud != null)
return;
Expand All @@ -271,6 +299,9 @@ public void showPointcloud(boolean showPoints) {
pc.close();
}
mPointcloud = null;

if(mPointsTexture != null) mPointsTexture.close();
mPointsTexture = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public void onClick(View view) {
mGLSurfaceView.clear();
clearLables();
mShow3D = !mShow3D;
mGLSurfaceView.showPointcloud(mShow3D);

m3dButton.setTextColor(mShow3D ? Color.YELLOW : Color.WHITE);
mGLSurfaceView.setVisibility(View.VISIBLE);
SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE);
Expand Down