[vlc-devel] [PATCH 05/14] android: utils: load Surface JNI API
Romain Vimont
rom1v at videolabs.io
Mon Jun 15 12:02:21 CEST 2020
On Mon, Jun 15, 2020 at 10:24:34AM +0200, Alexandre Janniaux wrote:
> Hi,
>
> Indeed, but that's unfortunately a preexisting issues with
> everything related to jfields.
>
> This will be solved in latter patchset when removing the
> dependency to AWindowHandler for JNI classes.
OK LGTM
> Regards,
> --
> Alexandre Janniaux
> Videolabs
>
> On Fri, Jun 12, 2020 at 03:23:14PM +0200, Romain Vimont wrote:
> > On Fri, Jun 12, 2020 at 11:40:48AM +0200, Alexandre Janniaux wrote:
> > > When creating a SurfaceTexture JNI object, we can, with recent API,
> > > transform the SurfaceTexture into an ASurfaceTexture NDK object.
> > > However, with previous Android version, the only way is to create the
> > > Surface JNI object directly from the SurfaceTexture JNI object, and then
> > > convert the Surface into a ANativeWindow NDK object for the producer
> > > side.
> > >
> > > This patch loads the class and the constructor taking a reference to
> > > SurfaceTexture.
> > > ---
> > > modules/video_output/android/utils.c | 25 +++++++++++++++++++++++++
> > > 1 file changed, 25 insertions(+)
> > >
> > > diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
> > > index 7818f1e5e7b..92ed9aca1d2 100644
> > > --- a/modules/video_output/android/utils.c
> > > +++ b/modules/video_output/android/utils.c
> > > @@ -133,6 +133,10 @@ static struct
> > > jmethodID init_iz;
> > > jmethodID init_z;
> > > } SurfaceTexture;
> > > + struct {
> > > + jclass clazz;
> > > + jmethodID init_st;
> > > + } Surface;
> > > } jfields;
> > >
> > > #define JNI_CALL(what, obj, method, ...) \
> > > @@ -630,6 +634,7 @@ LoadNativeWindowAPI(AWindowHandler *p_awh, JNIEnv *p_env)
> > > LoadNativeSurfaceAPI(p_awh);
> > > }
> > > jfields.SurfaceTexture.clazz = NULL;
> > > + jfields.Surface.clazz = NULL;
> > >
> > > jclass surfacetexture_class = (*p_env)->FindClass(p_env,
> > > "android/graphics/SurfaceTexture");
> > > @@ -656,11 +661,28 @@ LoadNativeWindowAPI(AWindowHandler *p_awh, JNIEnv *p_env)
> > > !jfields.SurfaceTexture.init_z)
> > > goto error;
> > >
> > > + jclass surface_class = (*p_env)->FindClass(p_env, "android/view/Surface");
> > > + if (surface_class == NULL)
> > > + goto error;
> > > +
> > > + jfields.Surface.clazz = (*p_env)->NewGlobalRef(p_env, surface_class);
> > > + (*p_env)->DeleteLocalRef(p_env, surface_class);
> > > + if (jfields.Surface.clazz == NULL)
> > > + goto error;
> > > +
> > > + jfields.Surface.init_st = (*p_env)->GetMethodID(p_env,
> > > + jfields.Surface.clazz, "<init>", "(Landroid/graphics/SurfaceTexture;)V");
> > > + if (jfields.Surface.init_st == NULL)
> > > + goto error;
> > > +
> > > return;
> > >
> > > error:
> > > if (jfields.SurfaceTexture.clazz != NULL)
> > > (*p_env)->DeleteGlobalRef(p_env, jfields.SurfaceTexture.clazz);
> > > +
> > > + if (jfields.Surface.clazz != NULL)
> > > + (*p_env)->DeleteGlobalRef(p_env, jfields.SurfaceTexture.clazz);
> > > }
> > >
> > > static void
> > > @@ -871,6 +893,9 @@ AWindowHandler_destroy(AWindowHandler *p_awh)
> > > if (jfields.SurfaceTexture.clazz)
> > > (*p_env)->DeleteGlobalRef(p_env, jfields.SurfaceTexture.clazz);
> > >
> > > + if (jfields.Surface.clazz)
> > > + (*p_env)->DeleteGlobalRef(p_env, jfields.Surface.clazz);
> >
> > It seems weird to delete a global variable on destroying a
> > AWindowHandler instance.
> >
> > > +
> > > JNI_ANWCALL(CallVoidMethod, unregisterNative);
> > > AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Video);
> > > AWindowHandler_releaseANativeWindowEnv(p_awh, p_env, AWindow_Subtitles);
> > > --
> > > 2.27.0
> > >
> > > _______________________________________________
> > > vlc-devel mailing list
> > > To unsubscribe or modify your subscription options:
> > > https://mailman.videolan.org/listinfo/vlc-devel
> > _______________________________________________
> > vlc-devel mailing list
> > To unsubscribe or modify your subscription options:
> > https://mailman.videolan.org/listinfo/vlc-devel
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
More information about the vlc-devel
mailing list