[vlc-commits] mediacodec: create SurfaceTexture in decoder

Alexandre Janniaux git at videolan.org
Wed Jul 8 17:52:54 CEST 2020


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Wed Jun 24 15:14:35 2020 +0200| [14be780df420c4ac5e873dc14e5ade412d3b6e29] | committer: Alexandre Janniaux

mediacodec: create SurfaceTexture in decoder

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.

Signed-off-by: Alexandre Janniaux <ajanni at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=14be780df420c4ac5e873dc14e5ade412d3b6e29
---

 modules/codec/omxil/mediacodec.c     | 32 +++++++++++++++++++++++++++-----
 modules/video_output/android/utils.h |  1 +
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 145752eb3b..16758fa17b 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,24 @@ 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);
+        if (p_sys->video.surfacetexture == NULL)
+            goto error;
+        p_sys->video.p_surface = p_sys->video.surfacetexture->window;
+        p_sys->video.p_jsurface = p_sys->video.surfacetexture->jsurface;
+    }
+    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");
+            goto error;
+        }
     }
 
     static const struct vlc_video_context_operations ops =
@@ -673,6 +686,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;
@@ -690,6 +704,10 @@ CreateVideoContext(decoder_t *p_dec)
     }
 
     return VLC_SUCCESS;
+
+error:
+    vlc_decoder_device_Release(dec_dev);
+    return VLC_EGENERIC;
 }
 
 static void CleanInputVideo(decoder_t *p_dec)
@@ -811,6 +829,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 +1028,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 b042df695d..dfec53f589 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);



More information about the vlc-commits mailing list