[vlc-devel] [PATCH 14/17] android: utils: allow single-buffered vlc_asurfacetexture

Alexandre Janniaux ajanni at videolabs.io
Wed Jan 13 11:07:27 UTC 2021


Non single-buffered vlc_asurfacetexture are very expensive when you only
want to store a single buffer. When using multiple of them, it's
possible that the phone goes OOM, and especially on old phones that
don't support single-buffered SurfaceTexture so in that case just fail
the creation of the SurfaceTexture.
---
 modules/codec/omxil/mediacodec.c     |  2 +-
 modules/video_output/android/utils.c | 13 ++++++++-----
 modules/video_output/android/utils.h |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index b021f87afe..4469e73e33 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -665,7 +665,7 @@ CreateVideoContext(decoder_t *p_dec)
 
     if (use_surfacetexture)
     {
-        p_sys->video.surfacetexture = vlc_asurfacetexture_New(awh);
+        p_sys->video.surfacetexture = vlc_asurfacetexture_New(awh, false);
         assert(p_sys->video.surfacetexture);
         if (p_sys->video.surfacetexture == NULL)
             goto error;
diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 1172b6c16b..e46b8e004d 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -959,7 +959,7 @@ AWindowHandler_getANativeWindowAPI(AWindowHandler *p_awh)
 }
 
 static struct vlc_asurfacetexture_priv* CreateSurfaceTexture(
-        AWindowHandler *p_awh, JNIEnv *p_env)
+        AWindowHandler *p_awh, JNIEnv *p_env, bool single_buffer)
 {
     /* Needed in case of old API, see comments below. */
     EGLDisplay display = EGL_NO_DISPLAY;
@@ -990,7 +990,7 @@ static struct vlc_asurfacetexture_priv* CreateSurfaceTexture(
 
     /* We can create a SurfaceTexture in detached mode directly */
     surfacetexture = (*p_env)->NewObject(p_env,
-      p_awh->jfields.SurfaceTexture.clazz, p_awh->jfields.SurfaceTexture.init_z, false);
+      p_awh->jfields.SurfaceTexture.clazz, p_awh->jfields.SurfaceTexture.init_z, single_buffer);
 
     if (surfacetexture == NULL)
         goto error;
@@ -1060,7 +1060,7 @@ init_iz:
 
     msg_Dbg(p_awh->wnd, "Using SurfaceTexture constructor init_iz");
     surfacetexture = (*p_env)->NewObject(p_env,
-      p_awh->jfields.SurfaceTexture.clazz, p_awh->jfields.SurfaceTexture.init_iz, texture, false);
+      p_awh->jfields.SurfaceTexture.clazz, p_awh->jfields.SurfaceTexture.init_iz, texture, single_buffer);
 
     if (surfacetexture == NULL)
         goto error;
@@ -1072,6 +1072,9 @@ init_i:
     assert(p_awh->jfields.SurfaceTexture.init_i != NULL);
     msg_Dbg(p_awh->wnd, "Using SurfaceTexture constructor init_i");
 
+    if (single_buffer)
+        goto error;
+
     surfacetexture = (*p_env)->NewObject(p_env,
       p_awh->jfields.SurfaceTexture.clazz, p_awh->jfields.SurfaceTexture.init_i, texture);
 
@@ -1168,11 +1171,11 @@ error:
 }
 
 struct vlc_asurfacetexture *
-vlc_asurfacetexture_New(AWindowHandler *p_awh)
+vlc_asurfacetexture_New(AWindowHandler *p_awh, bool single_buffer)
 {
     JNIEnv *p_env = android_getEnvCommon(NULL, p_awh->p_jvm, "SurfaceTexture");
     struct vlc_asurfacetexture_priv *surfacetexture =
-        CreateSurfaceTexture(p_awh, p_env);
+        CreateSurfaceTexture(p_awh, p_env, single_buffer);
     if (surfacetexture == NULL)
         return NULL;
     return &surfacetexture->surface;
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index a9610545f3..ca5838b2f5 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -203,7 +203,7 @@ SurfaceTexture_detachFromGLContext(struct vlc_asurfacetexture *st);
  * See Android SurfaceTexture
  */
 struct vlc_asurfacetexture *
-vlc_asurfacetexture_New(AWindowHandler *p_awh);
+vlc_asurfacetexture_New(AWindowHandler *p_awh, bool single_buffer);
 
 /**
  * Delete a SurfaceTexture object created with SurfaceTexture_New.
-- 
2.30.0



More information about the vlc-devel mailing list