[vlc-devel] [PATCHv2 10/14] android: utils: expose vlc_surfacetexture API

Alexandre Janniaux ajanni at videolabs.io
Wed Jun 24 15:14:34 CEST 2020


Expose public functions to create and destroy the vlc_asurfacetexture
objects from an AWindowHandler object. It will be used in particular by
Mediacodec to output to OpenGL textures.
---
 modules/video_output/android/utils.c | 18 ++++++++++++++++++
 modules/video_output/android/utils.h | 19 +++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index e6c5da61ea5..a5471b8d5d0 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -462,6 +462,7 @@ static void NDKSurfaceTexture_destroy(
     handle->awh->ndk_ast_api.pf_releaseAst(handle->texture);
     (*p_env)->DeleteGlobalRef(p_env, handle->jtexture);
 
+    handle->awh->st = NULL;
     free(handle);
 }
 
@@ -562,6 +563,7 @@ static void JNISurfaceTexture_destroy(
     if (handle->surface.jsurface)
         (*p_env)->DeleteGlobalRef(p_env, handle->surface.jsurface);
 
+    handle->awh->st = NULL;
     free(handle);
 }
 
@@ -1149,6 +1151,22 @@ error:
     return NULL;
 }
 
+struct vlc_asurfacetexture *
+vlc_asurfacetexture_New(AWindowHandler *p_awh)
+{
+    if (p_awh->st == NULL)
+    {
+        JNIEnv *p_env = android_getEnvCommon(NULL, p_awh->p_jvm, "SurfaceTexture");
+        struct vlc_asurfacetexture_priv *surfacetexture =
+            CreateSurfaceTexture(p_awh, p_env);
+        if (surfacetexture == NULL)
+            return NULL;
+        return &surfacetexture->surface;
+    }
+
+    return p_awh->st;
+}
+
 static int
 WindowHandler_NewSurfaceEnv(AWindowHandler *p_awh, JNIEnv *p_env,
                             enum AWindow_ID id)
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index 0f11de77eec..b042df695d5 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -192,6 +192,25 @@ SurfaceTexture_attachToGLContext(AWindowHandler *p_awh, uint32_t tex_name);
 void
 SurfaceTexture_detachFromGLContext(AWindowHandler *p_awh);
 
+/**
+ * Create a new SurfaceTexture object.
+ *
+ * See Android SurfaceTexture
+ */
+struct vlc_asurfacetexture *
+vlc_asurfacetexture_New(AWindowHandler *p_awh);
+
+/**
+ * Delete a SurfaceTexture object created with SurfaceTexture_New.
+ */
+static inline void
+vlc_asurfacetexture_Delete(struct vlc_asurfacetexture *st)
+{
+    if (st->ops->destroy)
+        st->ops->destroy(st);
+}
+
+
 /**
  * Get a Java Surface from the attached SurfaceTexture
  *
-- 
2.27.0



More information about the vlc-devel mailing list