[vlc-devel] [PATCH 10/14] mediacodec: create SurfaceTexture in decoder

Thomas Guillem thomas at gllm.fr
Mon Jun 15 13:28:10 CEST 2020



On Fri, Jun 12, 2020, at 11:40, Alexandre Janniaux wrote:
> Initially, the SurfaceTexture reference was created through
> AWindowHandler and typically was obtained through a TextureView. By
> creating the SurfaceTexture ourselves, we can avoid requesting Android
> libVLC user to use libvlc_media_player_set_android_context even if the
> user doesn't need any display.
> 
> In addition, it means that we don't rely on code that is in the JNI
> android binding instead of vlc core when using MediaCodec, which helps
> other bindings like C# one to provide support for Android.
> ---
>  modules/codec/omxil/mediacodec.c     | 26 +++++++++++++++++++++-----
>  modules/video_output/android/utils.h |  1 +
>  2 files changed, 22 insertions(+), 5 deletions(-)
> 
> diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
> index 145752eb3b1..5dca517dd9b 100644
> --- a/modules/codec/omxil/mediacodec.c
> +++ b/modules/codec/omxil/mediacodec.c
> @@ -131,6 +131,7 @@ typedef struct
>              struct hxxx_helper hh;
>              timestamp_fifo_t *timestamp_fifo;
>              int i_mpeg_dar_num, i_mpeg_dar_den;
> +            struct vlc_asurfacetexture *surfacetexture;
>          } video;
>          struct {
>              date_t i_end_date;
> @@ -650,12 +651,22 @@ CreateVideoContext(decoder_t *p_dec)
>      else
>          id = AWindow_Video;
>  
> -    p_sys->video.p_surface = AWindowHandler_getANativeWindow(awh, id);
> -    p_sys->video.p_jsurface = AWindowHandler_getSurface(awh, id);
> -    if (!p_sys->video.p_surface)
> +    if (id == AWindow_SurfaceTexture)
>      {
> -        msg_Err(p_dec, "Could not find a valid ANativeWindow");
> -        return VLC_EGENERIC;
> +        p_sys->video.surfacetexture = vlc_asurfacetexture_New(awh);
> +        p_sys->video.p_surface = p_sys->video.surfacetexture->window;
> +        p_sys->video.p_jsurface = p_sys->video.surfacetexture->jsurface;

Missing pointer check, possible NULL-deref.

> +    }
> +    else
> +    {
> +        p_sys->video.p_surface = AWindowHandler_getANativeWindow(awh, id);
> +        p_sys->video.p_jsurface = AWindowHandler_getSurface(awh, id);
> +        assert (p_sys->video.p_surface);
> +        if (!p_sys->video.p_surface)
> +        {
> +            msg_Err(p_dec, "Could not find a valid ANativeWindow");
> +            return VLC_EGENERIC;
> +        }
>      }
>  
>      static const struct vlc_video_context_operations ops =
> @@ -673,6 +684,7 @@ 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;
>      avctx->render_ts = p_sys->api.release_out_ts ? 
> PictureContextRenderPicTs : NULL;
> @@ -811,6 +823,7 @@ static int OpenDecoder(vlc_object_t *p_this, 
> pf_MediaCodecApi_init pf_init)
>      p_sys->api.psz_mime = mime;
>      p_sys->video.i_mpeg_dar_num = 0;
>      p_sys->video.i_mpeg_dar_den = 0;
> +    p_sys->video.surfacetexture = NULL;
>  
>      if (pf_init(&p_sys->api) != 0)
>      {
> @@ -1009,6 +1022,9 @@ static void CleanDecoder(decoder_sys_t *p_sys)
>      CSDFree(p_sys);
>      p_sys->api.clean(&p_sys->api);
>  
> +    if (p_sys->video.surfacetexture)
> +        vlc_asurfacetexture_Delete(p_sys->video.surfacetexture);
> +
>      free(p_sys);
>  }
>  
> diff --git a/modules/video_output/android/utils.h 
> b/modules/video_output/android/utils.h
> index 15b22c43c52..a92ca55d1f2 100644
> --- a/modules/video_output/android/utils.h
> +++ b/modules/video_output/android/utils.h
> @@ -74,6 +74,7 @@ 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);
>      bool (*render_ts)(struct picture_context_t *ctx, vlc_tick_t ts);
> -- 
> 2.27.0
> 
> _______________________________________________
> 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