<div dir="ltr">Hi, no it is not necessary, you are right, I will remove them !Thanks for reporting this.<br></div><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 9, 2020 at 11:21 AM Zhao Zhili <<a href="mailto:quinkblack@foxmail.com" target="_blank">quinkblack@foxmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
> On Apr 6, 2020, at 5:51 PM, Louis Regnier <<a href="mailto:louis.videolabs@gmail.com" target="_blank">louis.videolabs@gmail.com</a>> wrote:<br>
> <br>
> Implement a new Android NDK API library to manage surfacetexture natively.<br>
> If device is not recent enough to support this API it will fallback to the<br>
> previous JNI API.<br>
> <br>
> To avoid JNI, we need an access to the SurfaceTexture which is<br>
> initialized in the AWindow.java class in the Android bindings.<br>
> <br>
> Currently only a Surface (weak reference to the producer side)<br>
> is returned by the AWindow JNI API preventing using the NDK API<br>
> directly.<br>
> <br>
> First, add those new method bindings from the AWindow object.<br>
> <br>
> Then, if method exist, dynamically bind the NDK SurfaceTexture API<br>
> to a pointer structure to determine whether it is available.<br>
> Fallback to JNI behaviour if they are not available.<br>
> <br>
> refs videolan/vlc#20344<br>
> ---<br>
> modules/video_output/android/utils.c | 99 ++++++++++++++++++++++++----<br>
> modules/video_output/android/utils.h |  1 +<br>
> 2 files changed, 86 insertions(+), 14 deletions(-)<br>
> <br>
> diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c<br>
> index 2010f13976..7158ec6658 100644<br>
> --- a/modules/video_output/android/utils.c<br>
> +++ b/modules/video_output/android/utils.c<br>
> @@ -25,11 +25,39 @@<br>
> #include <jni.h><br>
> #include <pthread.h><br>
> #include <assert.h><br>
> +#include <android/surface_texture.h><br>
> +#include <android/surface_texture_jni.h><br>
<br>
Is it necessary to include these header files?<br>
<br>
> <br>
> typedef ANativeWindow* (*ptr_ANativeWindow_fromSurface)(JNIEnv*, jobject);<br>
> typedef ANativeWindow* (*ptr_ANativeWindow_fromSurfaceTexture)(JNIEnv*, jobject);<br>
> typedef void (*ptr_ANativeWindow_release)(ANativeWindow*);<br>
> <br>
> +typedef void (*ptr_ASurfaceTexture_getTransformMatrix)<br>
> +                                        (ASurfaceTexture *st, float mtx[16]);<br>
> +typedef ASurfaceTexture* (*ptr_ASurfaceTexture_fromSurfaceTexture)<br>
> +                                        (JNIEnv* env, jobject surfacetexture);<br>
> +typedef int (*ptr_ASurfaceTexture_updateTexImage)(ASurfaceTexture* st);<br>
> +typedef int (*ptr_ASurfaceTexture_detachFromGLContext)<br>
> +                                        (ASurfaceTexture *st);<br>
> +typedef int (*ptr_ASurfaceTexture_attachToGLContext)<br>
> +                                        (ASurfaceTexture *st, uint32_t texName);<br>
> +typedef void (*ptr_ASurfaceTexture_release)(ASurfaceTexture *st);<br>
> +<br>
> +struct ASurfaceTextureAPI<br>
> +{<br>
> +    float   transMat[16];<br>
> +<br>
> +    jobject surfacetexture;<br>
> +    ASurfaceTexture *p_ast;<br>
> +<br>
> +    ptr_ASurfaceTexture_updateTexImage pf_updateTexImage;<br>
> +    ptr_ASurfaceTexture_fromSurfaceTexture pf_astFromst;<br>
> +    ptr_ASurfaceTexture_attachToGLContext pf_attachToGL;<br>
> +    ptr_ASurfaceTexture_detachFromGLContext pf_detachFromGL;<br>
> +    ptr_ASurfaceTexture_getTransformMatrix pf_getTransMatrix;<br>
> +    ptr_ASurfaceTexture_release pf_releaseAst;<br>
> +};<br>
> +<br>
> struct AWindowHandler<br>
> {<br>
>     JavaVM *p_jvm;<br>
> @@ -46,6 +74,9 @@ struct AWindowHandler<br>
>     ptr_ANativeWindow_release pf_winRelease;<br>
>     native_window_api_t anw_api;<br>
> <br>
> +    struct SurfaceTextureHandler st;<br>
> +    struct ASurfaceTextureAPI ast_api;<br>
> +<br>
>     struct {<br>
>         awh_events_t cb;<br>
>     } event;<br>
> @@ -57,20 +88,6 @@ struct AWindowHandler<br>
>     } stex;<br>
> };<br>
> <br>
> -struct SurfaceTexture<br>
> -{<br>
> -    JavaVM *p_jvm;<br>
> -<br>
> -    void *p_anw_dl;<br>
> -    ptr_ANativeWindow_fromSurface pf_winFromSurface;<br>
> -    ptr_ANativeWindow_release pf_winRelease;<br>
> -<br>
> -    jobject thiz;<br>
> -    jobject jsurface;<br>
> -    ANativeWindow *p_anw;<br>
> -<br>
> -};<br>
> -<br>
> static struct<br>
> {<br>
>     struct {<br>
> @@ -86,6 +103,8 @@ static struct<br>
>         jmethodID detachFromGLContext;<br>
>         jmethodID waitAndUpdateTexImage;<br>
>         jmethodID getSurface;<br>
> +        jmethodID getSurfaceTexture;<br>
> +        jmethodID removeFrameAvailableListener;<br>
>     } SurfaceTexture;<br>
> } jfields;<br>
> <br>
> @@ -262,6 +281,53 @@ LoadNativeSurfaceAPI(AWindowHandler *p_awh)<br>
>     p_awh->anw_api.setBuffersGeometry = NULL;<br>
> }<br>
> <br>
> +/*<br>
> + * Android ASurfaceTexture Android NDK<br>
> + */<br>
> +<br>
> +static int<br>
> +ASurfaceTexture_attachToGLContext(AWindowHandler *p_awh, uint32_t texName);<br>
> +static int<br>
> +ASurfaceTexture_updateTexImage(AWindowHandler *p_awh, const float **pp_transform_mtx);<br>
> +static void<br>
> +ASurfaceTexture_detachFromGLContext(AWindowHandler *p_awh);<br>
> +static int<br>
> +JNISurfaceTexture_waitAndUpdateTexImage(AWindowHandler *p_awh,<br>
> +                                            const float **pp_transform_mtx);<br>
> +static void<br>
> +JNISurfaceTexture_detachFromGLContext(AWindowHandler *p_awh);<br>
> +static int<br>
> +JNISurfaceTexture_attachToGLContext(AWindowHandler *p_awh, uint32_t tex_name);<br>
> +<br>
> +static int<br>
> +LoadSurfaceTextureAPI(AWindowHandler *p_awh, void *p_library)<br>
> +{<br>
> +    if (jfields.SurfaceTexture.removeFrameAvailableListener<br>
> +            && jfields.SurfaceTexture.getSurfaceTexture)<br>
> +    {<br>
> +        p_awh->ast_api.pf_astFromst = (ptr_ASurfaceTexture_fromSurfaceTexture)<br>
> +            dlsym(p_library, "ASurfaceTexture_fromSurfaceTexture");<br>
> +        p_awh->ast_api.pf_updateTexImage = (ptr_ASurfaceTexture_updateTexImage)<br>
> +            dlsym(p_library, "ASurfaceTexture_updateTexImage");<br>
> +        p_awh->ast_api.pf_attachToGL = (ptr_ASurfaceTexture_attachToGLContext)<br>
> +            dlsym(p_library, "ASurfaceTexture_attachToGLContext");<br>
> +        p_awh->ast_api.pf_detachFromGL = (ptr_ASurfaceTexture_detachFromGLContext)<br>
> +            dlsym(p_library, "ASurfaceTexture_detachFromGLContext");<br>
> +        p_awh->ast_api.pf_getTransMatrix = (ptr_ASurfaceTexture_getTransformMatrix)<br>
> +            dlsym(p_library, "ASurfaceTexture_getTransformMatrix");<br>
> +        p_awh->ast_api.pf_releaseAst = (ptr_ASurfaceTexture_release)<br>
> +            dlsym(p_library, "ASurfaceTexture_release");<br>
> +<br>
> +        if (p_awh->ast_api.pf_astFromst && p_awh->ast_api.pf_updateTexImage<br>
> +                && p_awh->ast_api.pf_attachToGL && p_awh->ast_api.pf_detachFromGL<br>
> +                && p_awh->ast_api.pf_getTransMatrix && p_awh->ast_api.pf_releaseAst)<br>
> +        {<br>
> +            return VLC_SUCCESS;<br>
> +        }<br>
> +    }<br>
> +    return VLC_EGENERIC;<br>
> +}<br>
> +<br>
> /*<br>
>  * Android NativeWindow (post android 2.3)<br>
>  */<br>
> @@ -286,6 +352,7 @@ LoadNativeWindowAPI(AWindowHandler *p_awh)<br>
>      && p_awh->anw_api.winLock && p_awh->anw_api.unlockAndPost<br>
>      && p_awh->anw_api.setBuffersGeometry)<br>
>     {<br>
> +        LoadSurfaceTextureAPI(p_awh, p_library);<br>
>         p_awh->p_anw_dl = p_library;<br>
>     }<br>
>     else<br>
> @@ -435,6 +502,10 @@ InitJNIFields(JNIEnv *env, vlc_object_t *p_obj, jobject *jobj)<br>
>                true);<br>
>     GET_METHOD(SurfaceTexture.getSurface,<br>
>                "SurfaceTexture_getSurface", "()Landroid/view/Surface;", true);<br>
> +    GET_METHOD(SurfaceTexture.getSurfaceTexture,<br>
> +               "SurfaceTexture_getSurfaceTexture", "()Landroid/graphics/SurfaceTexture;", true);<br>
> +    GET_METHOD(SurfaceTexture.removeFrameAvailableListener,<br>
> +               "SurfaceTexture_removeFrameAvailableListener", "()V", true);<br>
> <br>
>     if ((*env)->RegisterNatives(env, clazz, jni_callbacks, 2) < 0)<br>
>     {<br>
> diff --git a/modules/video_output/android/utils.h b/modules/video_output/android/utils.h<br>
> index 35ccc41906..28aed6c6a1 100644<br>
> --- a/modules/video_output/android/utils.h<br>
> +++ b/modules/video_output/android/utils.h<br>
> @@ -34,6 +34,7 @@<br>
> #include <vlc_common.h><br>
> <br>
> typedef struct AWindowHandler AWindowHandler;<br>
> +typedef struct ASurfaceTexture ASurfaceTexture;<br>
> <br>
> enum AWindow_ID {<br>
>     AWindow_Video,<br>
> -- <br>
> 2.26.0<br>
> <br>
> _______________________________________________<br>
> vlc-devel mailing list<br>
> To unsubscribe or modify your subscription options:<br>
> <a href="https://mailman.videolan.org/listinfo/vlc-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a><br>
<br>
_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a></blockquote></div></div>