Skip to content

Commit 8fd01c4

Browse files
authored
Merge pull request #9602 from gwen2018/android_fix_dso_16584_partb
[Android] - fix resource issue handling issue
2 parents 5f885f5 + 5e42040 commit 8fd01c4

File tree

6 files changed

+63
-23
lines changed

6 files changed

+63
-23
lines changed

src/android/jni/frameset.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Java_com_intel_realsense_librealsense_FrameSet_nAddRef(JNIEnv *env, jclass type,
1515
extern "C" JNIEXPORT void JNICALL
1616
Java_com_intel_realsense_librealsense_FrameSet_nRelease(JNIEnv *env, jclass type,
1717
jlong handle) {
18+
if(handle)
1819
rs2_release_frame(reinterpret_cast<rs2_frame *>(handle));
1920
}
2021

src/archive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ namespace librealsense
190190

191191
void frame::release()
192192
{
193-
if (ref_count.fetch_sub(1) == 1)
193+
if (ref_count.fetch_sub(1) == 1 && owner)
194194
{
195195
unpublish();
196196
on_release();

src/source.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ namespace librealsense
112112
}
113113
void frame_source::invoke_callback(frame_holder frame) const
114114
{
115-
if (frame)
115+
if (frame && frame.frame && frame.frame->get_owner())
116116
{
117117
auto callback = frame.frame->get_owner()->begin_callback();
118118
try

wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/GLPointsFrame.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ public byte[] createTexture(Points points){
121121
public synchronized void close() {
122122
if(mFrame != null)
123123
mFrame.close();
124+
125+
if (mTexture != null) {
126+
mTexture.close();
127+
mTexture = null;
128+
}
129+
124130
if(mGlTexture != null)
125131
GLES10.glDeleteTextures(1, mGlTexture);
126132
mGlTexture = null;

wrappers/android/librealsense/src/main/java/com/intel/realsense/librealsense/GLRenderer.java

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,23 @@ public class GLRenderer implements GLSurfaceView.Renderer, AutoCloseable{
2626
private Colorizer mColorizer = new Colorizer();
2727
private Map<StreamType,Pointcloud> mPointcloud = null;
2828
private boolean mHasColorizedDepth = false;
29+
private boolean mHasDepth = false;
2930

3031
private boolean mHasColorYuy = false;
3132
private YuyDecoder mYuyDecoder = new YuyDecoder();
33+
private boolean mShowPoints = false;
3234

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

3739
private boolean showPoints(){
38-
return mPointcloud != null;
40+
return mShowPoints;
3941
}
4042

4143
private List<FilterInterface> createProcessingPipe(){
4244
List<FilterInterface> rv = new ArrayList<>();
43-
if(!mHasColorizedDepth && !showPoints())
45+
if(mHasDepth && !mHasColorizedDepth && !showPoints())
4446
rv.add(mColorizer);
4547

4648
// convert yuyv into rgb8 for display and uv mapping
@@ -50,14 +52,15 @@ private List<FilterInterface> createProcessingPipe(){
5052
if(showPoints()){
5153
if(mHasColorRbg8 || mHasColorYuy)
5254
rv.add(mPointcloud.get(StreamType.COLOR));
53-
else
55+
else if (mHasDepth)
5456
rv.add(mPointcloud.get(StreamType.DEPTH));
5557
}
5658
return rv;
5759
}
5860

5961
private FrameSet applyFilters(FrameSet frameSet, List<FilterInterface> filters){
6062
frameSet = frameSet.clone();
63+
6164
for(FilterInterface f : filters){
6265
FrameSet newSet = frameSet.applyFilter(f);
6366
frameSet.close();
@@ -67,7 +70,8 @@ private FrameSet applyFilters(FrameSet frameSet, List<FilterInterface> filters){
6770
}
6871

6972
public void upload(FrameSet frameSet) {
70-
mHasColorRbg8 = mHasColorizedDepth = mHasColorYuy = false;
73+
mHasColorRbg8 = mHasColorizedDepth = mHasColorYuy = mHasDepth = false;
74+
7175
frameSet.foreach(new FrameCallback() {
7276
@Override
7377
public void onFrame(Frame f) {
@@ -76,27 +80,36 @@ public void onFrame(Frame f) {
7680
});
7781

7882
List<FilterInterface> filters = createProcessingPipe();
79-
try(FrameSet processed = applyFilters(frameSet, filters)){
80-
choosePointsTexture(processed);
81-
processed.foreach(new FrameCallback() {
82-
@Override
83-
public void onFrame(Frame f) {
84-
addFrame(f);
85-
upload(f);
86-
}
87-
});
83+
84+
if (!showPoints() || (showPoints() && filters.size() > 0 && mHasDepth)) {
85+
try (FrameSet processed = applyFilters(frameSet, filters)) {
86+
choosePointsTexture(processed);
87+
processed.foreach(new FrameCallback() {
88+
@Override
89+
public void onFrame(Frame f) {
90+
upload(f);
91+
}
92+
});
93+
}
8894
}
8995
}
9096

9197
private void choosePointsTexture(FrameSet frameSet){
92-
if(!showPoints())
98+
if(mPointsTexture != null) mPointsTexture.close();
99+
mPointsTexture = null;
100+
101+
if(!showPoints()) {
93102
return;
103+
}
104+
94105
if(mHasColorRbg8 || mHasColorYuy)
95106
mPointsTexture = frameSet.first(StreamType.COLOR, StreamFormat.RGB8);
96107
else{
97108
try (Frame d = frameSet.first(StreamType.DEPTH, StreamFormat.Z16)) {
98-
if(d != null)
109+
if(d != null) {
99110
mPointsTexture = mColorizer.process(d);
111+
d.close();
112+
}
100113
}
101114
}
102115
}
@@ -111,8 +124,12 @@ private void getTexture(Frame f){
111124
mHasColorYuy = true;
112125
}
113126

114-
if(sp.getType() == StreamType.DEPTH && sp.getFormat() == StreamFormat.RGB8) {
115-
mHasColorizedDepth = true;
127+
if(sp.getType() == StreamType.DEPTH) {
128+
mHasDepth = true;
129+
130+
if (sp.getFormat() == StreamFormat.RGB8) {
131+
mHasColorizedDepth = true;
132+
}
116133
}
117134
}
118135
}
@@ -122,13 +139,14 @@ private void addFrame(Frame f){
122139
if(!isFormatSupported(sp.getFormat()))
123140
return;
124141
int uid = sp.getUniqueId();
142+
125143
if(!mFrames.containsKey(uid)){
126144
synchronized (mFrames) {
127145
if(f.is(Extension.VIDEO_FRAME) && !showPoints())
128146
mFrames.put(uid, new GLVideoFrame());
129-
if(f.is(Extension.MOTION_FRAME) && !showPoints())
147+
else if (f.is(Extension.MOTION_FRAME) && !showPoints())
130148
mFrames.put(uid, new GLMotionFrame());
131-
if(f.is(Extension.POINTS))
149+
else if (f.is(Extension.POINTS))
132150
mFrames.put(uid, new GLPointsFrame());
133151
}
134152
}
@@ -149,6 +167,7 @@ public void upload(Frame f) {
149167
GLFrame curr = mFrames.get(uid);
150168
if(curr == null)
151169
return;
170+
152171
curr.setFrame(f);
153172

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

162181
public void clear() {
163182
synchronized (mFrames) {
164-
for(Map.Entry<Integer,GLFrame> f : mFrames.entrySet())
165-
f.getValue().close();
183+
for(Map.Entry<Integer,GLFrame> f : mFrames.entrySet()) {
184+
GLFrame frame = f.getValue();
185+
if (frame instanceof GLPointsFrame)
186+
((GLPointsFrame) frame).close();
187+
else
188+
frame.close();
189+
}
166190
mFrames.clear();
167191
mDeltaX = 0;
168192
mDeltaY = 0;
@@ -178,6 +202,8 @@ public void clear() {
178202

179203
if(mPointsTexture != null) mPointsTexture.close();
180204
mPointsTexture = null;
205+
206+
mHasColorRbg8 = mHasColorizedDepth = mHasColorYuy = mHasDepth = false;
181207
}
182208
}
183209

@@ -257,6 +283,8 @@ public void onTouchEvent(float dx, float dy) {
257283
}
258284

259285
public void showPointcloud(boolean showPoints) {
286+
mShowPoints = showPoints;
287+
260288
if(showPoints){
261289
if(mPointcloud != null)
262290
return;
@@ -271,6 +299,9 @@ public void showPointcloud(boolean showPoints) {
271299
pc.close();
272300
}
273301
mPointcloud = null;
302+
303+
if(mPointsTexture != null) mPointsTexture.close();
304+
mPointsTexture = null;
274305
}
275306
}
276307

wrappers/android/tools/camera/src/main/java/com/intel/realsense/camera/PreviewActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ public void onClick(View view) {
121121
mGLSurfaceView.clear();
122122
clearLables();
123123
mShow3D = !mShow3D;
124+
mGLSurfaceView.showPointcloud(mShow3D);
125+
124126
m3dButton.setTextColor(mShow3D ? Color.YELLOW : Color.WHITE);
125127
mGLSurfaceView.setVisibility(View.VISIBLE);
126128
SharedPreferences sharedPref = getSharedPreferences(getString(R.string.app_settings), Context.MODE_PRIVATE);

0 commit comments

Comments
 (0)