[vlc-devel] [PATCH 13/14] android: utils: remove AWindow_SurfaceTexture

Alexandre Janniaux ajanni at videolabs.io
Fri Jun 12 11:40:56 CEST 2020


The AWindow_ID is not used anymore since we moved the creation of
SurfaceTexture to the usage site. We also don't need to store the
SurfaceTexture in the AWindowHandler anymore.

This finally makes the SurfaceTexture independant of the AWindowHandler
and cleanup previous patches.
---
 modules/codec/omxil/mediacodec.c              | 18 ++++-----
 modules/video_output/android/display.c        |  2 +-
 modules/video_output/android/utils.c          | 40 ++-----------------
 modules/video_output/android/utils.h          | 25 ------------
 modules/video_output/opengl/interop_android.c |  4 +-
 5 files changed, 12 insertions(+), 77 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 5dca517dd9b..95ecbce19e0 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -634,7 +634,6 @@ CreateVideoContext(decoder_t *p_dec)
 
     assert(dec_dev->opaque);
     AWindowHandler *awh = dec_dev->opaque;
-    enum AWindow_ID id;
 
     const bool has_subtitle_surface =
         AWindowHandler_getANativeWindow(awh, AWindow_Subtitles) != NULL;
@@ -643,15 +642,13 @@ CreateVideoContext(decoder_t *p_dec)
      * projection or an orientation to handle, if the Surface owner is not able
      * to modify its layout, or if there is no external subtitle surfaces. */
 
-    if (p_dec->fmt_out.video.projection_mode != PROJECTION_MODE_RECTANGULAR
+    bool use_surfacetexture =
+        p_dec->fmt_out.video.projection_mode != PROJECTION_MODE_RECTANGULAR
      || (!p_sys->api.b_support_rotation && p_dec->fmt_out.video.orientation != ORIENT_NORMAL)
      || !AWindowHandler_canSetVideoLayout(awh)
-     || !has_subtitle_surface)
-        id = AWindow_SurfaceTexture;
-    else
-        id = AWindow_Video;
+     || !has_subtitle_surface;
 
-    if (id == AWindow_SurfaceTexture)
+    if (use_surfacetexture)
     {
         p_sys->video.surfacetexture = vlc_asurfacetexture_New(awh);
         p_sys->video.p_surface = p_sys->video.surfacetexture->window;
@@ -659,8 +656,8 @@ CreateVideoContext(decoder_t *p_dec)
     }
     else
     {
-        p_sys->video.p_surface = AWindowHandler_getANativeWindow(awh, id);
-        p_sys->video.p_jsurface = AWindowHandler_getSurface(awh, id);
+        p_sys->video.p_surface = AWindowHandler_getANativeWindow(awh, AWindow_Video);
+        p_sys->video.p_jsurface = AWindowHandler_getSurface(awh, AWindow_Video);
         assert (p_sys->video.p_surface);
         if (!p_sys->video.p_surface)
         {
@@ -683,7 +680,6 @@ CreateVideoContext(decoder_t *p_dec)
 
     android_video_context_t *avctx =
         vlc_video_context_GetPrivate(p_sys->video.ctx, VLC_VIDEO_CONTEXT_AWINDOW);
-    avctx->id = id;
     avctx->texture = p_sys->video.surfacetexture;
     avctx->dec_opaque = p_dec->p_sys;
     avctx->render = PictureContextRenderPic;
@@ -904,7 +900,7 @@ static int OpenDecoder(vlc_object_t *p_this, pf_MediaCodecApi_init pf_init)
                 vlc_video_context_GetPrivate(p_sys->video.ctx,
                                              VLC_VIDEO_CONTEXT_AWINDOW);
 
-            if (p_sys->api.b_support_rotation && avctx->id == AWindow_Video)
+            if (p_sys->api.b_support_rotation && avctx->texture == NULL)
             {
                 switch (p_dec->fmt_in.video.orientation)
                 {
diff --git a/modules/video_output/android/display.c b/modules/video_output/android/display.c
index 3ad9aeb4520..e412bd75bb0 100644
--- a/modules/video_output/android/display.c
+++ b/modules/video_output/android/display.c
@@ -538,7 +538,7 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
             goto error;
         sys->avctx = vlc_video_context_GetPrivate(context, VLC_VIDEO_CONTEXT_AWINDOW);
         assert(sys->avctx);
-        if (sys->avctx->id != AWindow_Video)
+        if (sys->avctx->texture != NULL)
         {
             /* video context configured for opengl */
             goto error;
diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
index 4272883a18d..58669dc00c9 100644
--- a/modules/video_output/android/utils.c
+++ b/modules/video_output/android/utils.c
@@ -100,9 +100,6 @@ struct AWindowHandler
     ptr_ANativeWindow_release pf_winRelease;
     native_window_api_t anw_api;
 
-    /* Store the surfacetexture that AWindowHandler will use. */
-    struct vlc_asurfacetexture *st;
-
     struct ASurfaceTextureAPI ndk_ast_api;
     bool b_has_ndk_ast_api;
 
@@ -455,7 +452,6 @@ 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);
 }
 
@@ -554,7 +550,6 @@ static void JNISurfaceTexture_destroy(
     handle->awh->pf_winRelease(handle->surface.window);
     (*p_env)->DeleteGlobalRef(p_env, handle->surface.jsurface);
 
-    handle->awh->st = NULL;
     free(handle);
 }
 
@@ -848,8 +843,7 @@ AWindowHandler_new(vout_window_t *wnd, awh_events_t *p_events)
     {
         /* XXX: HACK: force mediacodec to setup an OpenGL surface when the vout
          * is forced to gles2. Indeed, setting b_has_video_layout_listener to
-         * false will result in mediacodec using the AWindow_SurfaceTexture
-         * surface.
+         * false will result in mediacodec using a SurfaceTexture for output.
          */
         char *vout_modules = var_InheritString(wnd, "vout");
         if (vout_modules
@@ -888,9 +882,6 @@ AWindowHandler_destroy(AWindowHandler *p_awh)
 
     if (p_env)
     {
-        if (p_awh->st)
-            p_awh->st->ops->destroy(p_awh->st);
-
         if (jfields.SurfaceTexture.clazz)
             (*p_env)->DeleteGlobalRef(p_env, jfields.SurfaceTexture.clazz);
 
@@ -1127,13 +1118,8 @@ error:
 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");
-        p_awh->st = &SurfaceTextureHandle_Create(p_awh, p_env)->surface;
-    }
-
-    return p_awh->st;
+    JNIEnv *p_env = android_getEnvCommon(NULL, p_awh->p_jvm, "SurfaceTexture");
+    return &SurfaceTextureHandle_Create(p_awh, p_env)->surface;
 }
 
 static int
@@ -1150,26 +1136,6 @@ WindowHandler_NewSurfaceEnv(AWindowHandler *p_awh, JNIEnv *p_env,
         case AWindow_Subtitles:
             jsurface = JNI_ANWCALL(CallObjectMethod, getSubtitlesSurface);
             break;
-        case AWindow_SurfaceTexture:
-        {
-            struct SurfaceTextureHandle *surfacetexture =
-                SurfaceTextureHandle_Create(p_awh, p_env);
-
-            if (surfacetexture == NULL)
-                return VLC_EGENERIC;
-
-            p_awh->views[id].p_anw = surfacetexture->surface.window;
-            p_awh->views[id].jsurface = surfacetexture->surface.jsurface;
-            p_awh->ndk_ast_api.p_ast = surfacetexture->texture;
-            p_awh->ndk_ast_api.surfacetexture = surfacetexture->jtexture;
-
-            assert(surfacetexture->surface.window);
-            assert(surfacetexture->surface.jsurface);
-
-            /* Store the vlc_asurfacetexture pointer for current AWH wrapper */
-            p_awh->st = &surfacetexture->surface;
-            return VLC_SUCCESS;
-        }
         default:
             vlc_assert_unreachable();
     }
diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h
index f877b7945be..3e764c96719 100644
--- a/modules/video_output/android/utils.h
+++ b/modules/video_output/android/utils.h
@@ -39,7 +39,6 @@ typedef struct ASurfaceTexture ASurfaceTexture;
 enum AWindow_ID {
     AWindow_Video,
     AWindow_Subtitles,
-    AWindow_SurfaceTexture,
     AWindow_Max,
 };
 
@@ -73,7 +72,6 @@ typedef struct android_video_context_t android_video_context_t;
 
 struct android_video_context_t
 {
-    enum AWindow_ID id;
     struct vlc_asurfacetexture *texture;
     void *dec_opaque;
     bool (*render)(struct picture_context_t *ctx);
@@ -211,29 +209,6 @@ vlc_asurfacetexture_Delete(struct vlc_asurfacetexture *st)
         st->ops->destroy(st);
 }
 
-
-/**
- * Get a Java Surface from the attached SurfaceTexture
- *
- * This object can be used with mediacodec_jni.
- */
-static inline jobject
-SurfaceTexture_getSurface(AWindowHandler *p_awh)
-{
-    return AWindowHandler_getSurface(p_awh, AWindow_SurfaceTexture);
-}
-
-/**
- * Get a ANativeWindow from the attached SurfaceTexture
- *
- * This pointer can be used with mediacodec_ndk.
- */
-static inline ANativeWindow *
-SurfaceTexture_getANativeWindow(AWindowHandler *p_awh)
-{
-    return AWindowHandler_getANativeWindow(p_awh, AWindow_SurfaceTexture);
-}
-
 /**
  * Update the SurfaceTexture to the most recent frame.
  *
diff --git a/modules/video_output/opengl/interop_android.c b/modules/video_output/opengl/interop_android.c
index 6fe18575cf1..dc280a4b00e 100644
--- a/modules/video_output/opengl/interop_android.c
+++ b/modules/video_output/opengl/interop_android.c
@@ -34,7 +34,6 @@
 struct priv
 {
     android_video_context_t *avctx;
-    AWindowHandler *awh;
     const float *transform_mtx;
     bool stex_attached;
 };
@@ -117,7 +116,7 @@ Open(vlc_object_t *obj)
     android_video_context_t *avctx =
         vlc_video_context_GetPrivate(interop->vctx, VLC_VIDEO_CONTEXT_AWINDOW);
 
-    if (avctx->id != AWindow_SurfaceTexture)
+    if (avctx == NULL || avctx->texture == NULL)
         return VLC_EGENERIC;
 
     interop->priv = malloc(sizeof(struct priv));
@@ -126,7 +125,6 @@ Open(vlc_object_t *obj)
 
     struct priv *priv = interop->priv;
     priv->avctx = avctx;
-    priv->awh = interop->gl->surface->handle.anativewindow;
     priv->transform_mtx = NULL;
     priv->stex_attached = false;
 
-- 
2.27.0



More information about the vlc-devel mailing list