[vlc-devel] [PATCH 03/14] android: utils: refactor SurfaceTexture handling

Alexandre Janniaux ajanni at videolabs.io
Fri Jun 12 15:12:01 CEST 2020


Hi,


On Fri, Jun 12, 2020 at 02:41:26PM +0200, Romain Vimont wrote:
> On Fri, Jun 12, 2020 at 11:40:46AM +0200, Alexandre Janniaux wrote:
> > Refactor SurfaceTexture related API into a structure with vtable, so as
> > to implement both NDK and JNI API as separate vtable.
> >
> > It will be exposed to modules and will allow creating SurfaceTexture
> > directly in the module needing them, instead of relying on an external
> > SurfaceTexture provided by the binding.
> >
> > jsurface and ANativeWindow are also both exposed to the user since we
> > don't expose the ANativeWindow/JNI functions.
> >
> > The object is made so that SurfaceTexture are always created in the
> > detached state.
> > ---
> >  modules/video_output/android/utils.c | 241 +++++++++++++++++++--------
> >  modules/video_output/android/utils.h |  30 ++++
> >  2 files changed, 202 insertions(+), 69 deletions(-)
> >
> > diff --git a/modules/video_output/android/utils.c b/modules/video_output/android/utils.c
> > index 45a30af455e..e4d407f560f 100644
> > --- a/modules/video_output/android/utils.c
> > +++ b/modules/video_output/android/utils.c
> > @@ -20,6 +20,11 @@
> >   * along with this program; if not, write to the Free Software Foundation,
> >   * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> >   *****************************************************************************/
> > +
> > +#ifdef HAVE_CONFIG_H
> > +# include <config.h>
> > +#endif
> > +
> >  #include "utils.h"
> >  #include <dlfcn.h>
> >  #include <jni.h>
> > @@ -30,20 +35,6 @@ typedef ANativeWindow* (*ptr_ANativeWindow_fromSurface)(JNIEnv*, jobject);
> >  typedef ANativeWindow* (*ptr_ANativeWindow_fromSurfaceTexture)(JNIEnv*, jobject);
> >  typedef void (*ptr_ANativeWindow_release)(ANativeWindow*);
> >
> > -typedef int (*ptr_SurfaceTexture_attachToGLContext)
> > -                                    (AWindowHandler *p_awh, uint32_t tex_name);
> > -typedef int (*ptr_SurfaceTexture_updateTexImage)(AWindowHandler *p_awh,
> > -                                    const float **pp_transform_mtx);
> > -typedef void (*ptr_SurfaceTexture_detachFromGLContext)
> > -                                    (AWindowHandler *p_awh, JNIEnv *p_env);
> > -
> > -struct SurfaceTextureHandler
> > -{
> > -    ptr_SurfaceTexture_attachToGLContext pf_attachToGL;
> > -    ptr_SurfaceTexture_updateTexImage pf_updateTexImage;
> > -    ptr_SurfaceTexture_detachFromGLContext pf_detachFromGL;
> > -};
> > -
> >  typedef void (*ptr_ASurfaceTexture_getTransformMatrix)
> >                                          (ASurfaceTexture *st, float mtx[16]);
> >  typedef ASurfaceTexture* (*ptr_ASurfaceTexture_fromSurfaceTexture)
> > @@ -58,6 +49,20 @@ typedef int (*ptr_ASurfaceTexture_updateTexImage)(ASurfaceTexture* st);
> >  typedef int (*ptr_ASurfaceTexture_detachFromGLContext)(ASurfaceTexture *st);
> >  typedef void (*ptr_ASurfaceTexture_release)(ASurfaceTexture *st);
> >
> > +/*
> > + * Android ASurfaceTexture Android NDK
> > + */
> > +struct SurfaceTextureHandle {
>
> Is it a vlc_asurfacetexture_priv? ;-)
>

There could be multiple vlc_asurfacetexture_priv, so having
this name as internal ease debugging. But I can rename if
needed. :)

> > @@ -857,11 +932,40 @@ WindowHandler_NewSurfaceEnv(AWindowHandler *p_awh, JNIEnv *p_env,
> >              break;
> >          case AWindow_SurfaceTexture:
> >          {
> > +            struct SurfaceTextureHandle *surfacetexture =
> > +                malloc(sizeof *surfacetexture);
> > +            if (surfacetexture == NULL)
> > +                return VLC_EGENERIC;
> > +
> >              if (p_awh->b_has_ndk_ast_api)
> > +            {
> >                  jsurface = InitNDKSurfaceTexture(p_awh, p_env, id);
> > +                surfacetexture->surface.ops = &NDKSurfaceAPI;
> > +                surfacetexture->surface.window = p_awh->views[id].p_anw;
> > +            }
> >              else
> > +            {
> >                  jsurface = JNI_STEXCALL(CallObjectMethod, getSurface);
> > -            break;
> > +                surfacetexture->surface.ops = &JNISurfaceAPI;
> > +                surfacetexture->surface.window
> > +                    = p_awh->views[id].p_anw
> > +                    = p_awh->pf_winFromSurface(p_env, jsurface);
> > +            }
> > +
> > +            surfacetexture->awh = p_awh;
> > +            surfacetexture->jtexture = p_awh->ndk_ast_api.surfacetexture;
> > +            surfacetexture->texture = p_awh->ndk_ast_api.p_ast;
>
> Not only when p_awh->b_has_ndk_ast_api is true (according to the field
> names)?

It would be NULL in the case p_awh->b_has_ndk_ast_api == false
so it doesn't really matter here.

Thanks for reviewing!

Regards,
--
Alexandre Janniaux
Videolabs


More information about the vlc-devel mailing list