google-ai-edge / mediapipe

Cross-platform, customizable ML solutions for live and streaming media.
https://ai.google.dev/edge/mediapipe
Apache License 2.0
27.79k stars 5.18k forks source link

About the memory leaking problem on rk3399 #1090

Closed lovehuanhuan closed 3 years ago

lovehuanhuan commented 4 years ago

I doubt that function"teardownFrame" has memory leaking problem on rk3399,so I build a surfacetexture pool,then the memory leaking prolbem disappears.

chuoling commented 4 years ago

Related to #1060

chuoling commented 4 years ago

Could you help verify if the following fixes the problem?

--- a/mediapipe/java/com/google/mediapipe/components/ExternalTextureConverter.java
+++ b/mediapipe/java/com/google/mediapipe/components/ExternalTextureConverter.java
@@ -363,6 +363,7 @@ public class ExternalTextureConverter implements TextureFrameProducer {

     private static void teardownFrame(AppTextureFrame frame) {
       GLES20.glDeleteTextures(1, new int[] {frame.getTextureName()}, 0);
+      frame.release();
     }

     private PoolTextureFrame createFrame() {
@@ -372,7 +373,6 @@ public class ExternalTextureConverter implements TextureFrameProducer {
           String.format(
               "Created output texture: %d width: %d height: %d",
               destinationTextureId, destinationWidth, destinationHeight));
-      bindFramebuffer(destinationTextureId, destinationWidth, destinationHeight);
       return new PoolTextureFrame(destinationTextureId, destinationWidth, destinationHeight);
     }

@@ -431,6 +431,7 @@ public class ExternalTextureConverter implements TextureFrameProducer {
       // Copy surface texture's pixels to output frame
       bindFramebuffer(outputFrame.getTextureName(), destinationWidth, destinationHeight);
       renderer.render(surfaceTexture);
+      unbindFramebuffer();

       // Populate frame timestamp with surface texture timestamp after render() as renderer
       // ensures that surface texture has the up-to-date timestamp. (Also adjust
diff --git a/mediapipe/java/com/google/mediapipe/glutil/GlThread.java b/mediapipe/java/com/google/mediapipe/glutil/GlThread.java
index 24b8ca09..107fb669 100644
--- a/mediapipe/java/com/google/mediapipe/glutil/GlThread.java
+++ b/mediapipe/java/com/google/mediapipe/glutil/GlThread.java
@@ -117,6 +117,16 @@ public class GlThread extends Thread {
     ShaderUtil.checkGlError("glViewport");
   }

+  public void unbindFramebuffer() {
+    GLES20.glFramebufferTexture2D(
+        GLES20.GL_FRAMEBUFFER,
+        GLES20.GL_COLOR_ATTACHMENT0,
+        GLES20.GL_TEXTURE_2D,
+        0,
+        0);
+    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
+  }
+
   @Override
   public void run() {
     try {
sgowroji commented 3 years ago

Assuming the above comments resolved your query we are closing this issue now.

google-ml-butler[bot] commented 3 years ago

Are you satisfied with the resolution of your issue? Yes No