[Android] New OpenGL ES 2.0 vout for the Android port

Rafaël Carré funman at videolan.org
Tue Nov 5 17:41:38 CET 2013


Hi,

Le 05/11/2013 17:04, Adrien Maglo a écrit :
> Hey all,
> 
> 
> Here are a new series of patches (cleaner than the first ones) to add an 
> OpenGL ES 2.0 vout to the Android port. They should apply to latest 
> vlc-android.git and vlc.git. I tested them on a Galaxy S3 and a Nexus 7 
> 2nd version.
> I had to create a new vindow provider in VLC in order to handle Android 
> native windows. I also added an option in the app debug section to 
> select between the androidsurface (default) and new OpenGL ES 2.0 vout.
> 
> In order to compile with the patches you may

rather *must* :)

> have to add the following
> lines to the files:
> 
> * vlc/contrib/arm-linux-androideabi/lib/pkgconfig/egl.pc
> Name: EGL
> Description: EGL
> Version: 1.1
> Libs: -lEGL
> Cflags:
> 
> * vlc/contrib/arm-linux-androideabi/lib/pkgconfig/glesv2.pc
> Name: GLESv2
> Description: GLESv2
> Version: 2
> Libs: -lGLESv2
> Cflags:
> 
> I would be interested by a better solution from someone who understand 
> the build system...

The only thing to understand here is that Google can't be bothered to
create a .pc file.

Since those 2 .pc files describe what is already available in the NDK we
should create them in compile.sh just before the line:
echo "Building the contribs"

> Your reviews would be of course very much welcomed.
> 
> Best regards,
> 
> 
> -- MagSoft
> 
> 
> 0001-Preferences-add-an-option-to-select-the-OpenGL-ES-2..patch
> 
> 
> From d7e13588ea794a53ee1e6989b4332029138f4add Mon Sep 17 00:00:00 2001
> From: Adrien Maglo <magsoft at videolan.org>
> Date: Tue, 5 Nov 2013 16:13:30 +0100
> Subject: [PATCH 1/2] Preferences: add an option to select the OpenGL ES 2.0
>  vout.
> 
> ---
>  vlc-android/jni/libvlcjni.c                            |  7 +++++++
>  vlc-android/res/values/strings.xml                     | 18 ++++++++++++++++++
>  vlc-android/res/xml/preferences.xml                    |  5 +++++
>  vlc-android/src/org/videolan/libvlc/LibVLC.java        | 15 +++++++++++++++
>  vlc-android/src/org/videolan/vlc/Util.java             |  8 ++++++++
>  .../src/org/videolan/vlc/gui/PreferencesActivity.java  |  9 +++++++++
>  6 files changed, 62 insertions(+)
> 
> diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
> index 7b244e6..29ffcb9 100644
> --- a/vlc-android/jni/libvlcjni.c
> +++ b/vlc-android/jni/libvlcjni.c
> @@ -38,6 +38,9 @@
>  #include "aout.h"
>  #include "utils.h"
>  
> +#define VOUT_ANDROID_SURFACE 0
> +#define VOUT_OPENGLES2       1
> +
>  #define LOG_TAG "VLC/JNI/main"
>  #include "log.h"
>  
> @@ -209,6 +212,9 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
>      jmethodID methodId = (*env)->GetMethodID(env, cls, "getAout", "()I");
>      bool use_opensles = (*env)->CallIntMethod(env, thiz, methodId) == AOUT_OPENSLES;
>  
> +    methodId = (*env)->GetMethodID(env, cls, "getVout", "()I");
> +    bool use_opengles2 = (*env)->CallIntMethod(env, thiz, methodId) == VOUT_OPENGLES2;
> +
>      methodId = (*env)->GetMethodID(env, cls, "timeStretchingEnabled", "()Z");
>      bool enable_time_stretch = (*env)->CallBooleanMethod(env, thiz, methodId);
>  
> @@ -263,6 +269,7 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
>          "--avcodec-skip-idct", enable_frame_skip ? "2" : "0",
>          (networkCaching > 0) ? networkCachingstr : "",
>          use_opensles ? "--aout=opensles" : "--aout=android_audiotrack",
> +        use_opengles2 ? "--vout=gles2" : "--vout=androidsurface",
>          "--androidsurface-chroma", chromastr != NULL && chromastr[0] != 0 ? chromastr : "RV32",
>      };
>      libvlc_instance_t *instance = libvlc_new(sizeof(argv) / sizeof(*argv), argv);
> diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
> index 8c32c56..7f43874 100644
> --- a/vlc-android/res/values/strings.xml
> +++ b/vlc-android/res/values/strings.xml
> @@ -385,5 +385,23 @@
>          <item>RGB 16-bit</item>
>          <item>YUV</item>
>      </string-array>
> +    <string-array name="vouts_values">
> +        <item >0</item>
> +        <item >1</item>
> +    </string-array>
> +    <string-array name="vouts_values_froyo">
> +        <item >0</item>
> +    </string-array>
> +    <string-array name="vouts">
> +        <item >@string/vout_android_surface</item>
> +        <item >@string/vout_opengles2</item>
> +    </string-array>
> +    <string-array name="vouts_froyo">
> +        <item >@string/vout_android_surface</item>
> +    </string-array>
> +    <string name="vout">Video output</string>
> +    <string name="vout_summary">Change the method that VLC uses to output video.</string>
> +    <string name="vout_android_surface">Android surface (native)</string>
> +    <string name="vout_opengles2">OpenGL ES 2.0 (native)</string>

Do we really need to add "(native)" ?
I think "Android surface" and "OpenGL ES 2.0" are descriptive enough.
In fact I don't know what "native" means, although I can guess from the
mess of audio output options we have...

> 0002-Build-add-the-compilation-options-to-build-the-OpenG.patch
> 
> 
> From f891c68c16bc9332cef3157b8a04609ff140249c Mon Sep 17 00:00:00 2001
> From: Adrien Maglo <magsoft at videolan.org>
> Date: Tue, 5 Nov 2013 16:14:40 +0100
> Subject: [PATCH 2/2] Build: add the compilation options to build the OpenGL ES
>  2.0 vout.

OK

> 0001-Vout-add-a-new-vout_window-type-for-android-native-w.patch
> 
> 
> From 8d83b8da5449584670fbbed3f0f13ca56dc3283c Mon Sep 17 00:00:00 2001
> From: Adrien Maglo <magsoft at videolan.org>
> Date: Tue, 5 Nov 2013 16:27:59 +0100
> Subject: [PATCH 1/3] Vout: add a new vout_window type for android native
>  windows
> 
> ---
>  include/vlc_vout_window.h | 8 +++++---
>  src/video_output/window.c | 4 ++++
>  2 files changed, 9 insertions(+), 3 deletions(-)

OK

> 
> 0002-Vout-add-a-new-window-provider-to-create-android-nat.patch
> 
> 
> From 758b4d5ed8a089b8fd4f2d66b2d1300af0f520e5 Mon Sep 17 00:00:00 2001
> From: Adrien Maglo <magsoft at videolan.org>
> Date: Tue, 5 Nov 2013 16:31:02 +0100
> Subject: [PATCH 2/3] Vout: add a new window provider to create android native
>  windows.
> 
> ---
>  modules/video_output/Modules.am            |   9 ++
>  modules/video_output/androidnativewindow.c | 174 +++++++++++++++++++++++++++++
>  2 files changed, 183 insertions(+)
>  create mode 100644 modules/video_output/androidnativewindow.c
> 
> diff --git a/modules/video_output/Modules.am b/modules/video_output/Modules.am
> index 041dc29..1dc760e 100644
> --- a/modules/video_output/Modules.am
> +++ b/modules/video_output/Modules.am
> @@ -180,6 +180,15 @@ if HAVE_KVA
>  vout_LTLIBRARIES += libkva_plugin.la
>  endif
>  
> +### Android ###
> +
> +libandroid_native_window_plugin_la_SOURCES = androidnativewindow.c
> +libandroid_native_window_plugin_la_CFLAGS = $(AM_CFLAGS)

Missing -ldl

> +if HAVE_ANDROID
> +vout_LTLIBRARIES += libandroid_native_window_plugin.la
> +endif
> +
>  ### Coloured ASCII art ###
>  libcaca_plugin_la_SOURCES = caca.c
>  libcaca_plugin_la_CFLAGS = $(AM_CFLAGS) $(CACA_CFLAGS)
> diff --git a/modules/video_output/androidnativewindow.c b/modules/video_output/androidnativewindow.c
> new file mode 100644
> index 0000000..7b673f4
> --- /dev/null
> +++ b/modules/video_output/androidnativewindow.c
> @@ -0,0 +1,174 @@
> +/**
> + * @file androidnativewindow.c
> + * @brief Android native window provider module for VLC media player
> + */
> +/*****************************************************************************
> + * Copyright © 2013 VLC authors and VideoLAN
> + *
> + * Author: Adrien Maglo <magsoft at videolan.org>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as published by
> + * the Free Software Foundation; either version 2.1 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public License
> + * 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 <stdarg.h>
> +#include <assert.h>
> +
> +#include <vlc_common.h>
> +#include <vlc_plugin.h>
> +#include <vlc_vout_window.h>
> +
> +#include <dlfcn.h>
> +#include <android/native_window.h>
> +#include <jni.h>
> +#include <android/native_window_jni.h>
> +
> +
> +typedef ANativeWindow* (*ptr_ANativeWindow_fromSurface)(JNIEnv*, jobject);
> +typedef void (*ptr_ANativeWindow_release)(ANativeWindow*);
> +
> +extern JavaVM *myVm;
> +extern jobject jni_LockAndGetAndroidJavaSurface();
> +extern void jni_UnlockAndroidSurface();
> +extern void  jni_SetAndroidSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den);
> +
> +static int Open(vout_window_t *, const vout_window_cfg_t *);
> +static void Close(vout_window_t *);
> +static int Control(vout_window_t *, int, va_list ap);
> +
> +/*
> + * Module descriptor
> + */
> +vlc_module_begin()
> +    set_shortname(N_("ANativeWindow"))
> +    set_description(N_("Android native window"))
> +    set_category(CAT_VIDEO)
> +    set_subcategory(SUBCAT_VIDEO_VOUT)
> +    set_capability("vout window anativewindow", 10)
> +    set_callbacks(Open, Close)
> +vlc_module_end()
> +
> +
> +struct vout_window_sys_t
> +{
> +    void *p_library;
> +
> +    ptr_ANativeWindow_fromSurface s_winFromSurface;
> +    ptr_ANativeWindow_release s_winRelease;
> +
> +    ANativeWindow *window;
> +};
> +
> +
> +/**
> + * Dynamically load the libandroid library and the needed symbols.
> + */
> +static void *InitLibrary(vout_window_sys_t *p_sys)
> +{
> +    void *p_library = dlopen("libandroid.so", RTLD_NOW);
> +    if (!p_library)
> +        return NULL;
> +
> +    p_sys->s_winFromSurface =
> +        (ptr_ANativeWindow_fromSurface)(dlsym(p_library, "ANativeWindow_fromSurface"));
> +    p_sys->s_winRelease =
> +        (ptr_ANativeWindow_release)(dlsym(p_library, "ANativeWindow_release"));
> +
> +    if (p_sys->s_winFromSurface == NULL || p_sys->s_winRelease == NULL)

dlclose?

> +        return NULL;
> +
> +    return p_library;
> +}
> +
> +
> +/**
> + * Create an Android native window.
> + */
> +static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)
> +{
> +    vout_window_sys_t *p_sys = malloc (sizeof (*p_sys));
> +    if (p_sys == NULL)
> +        return VLC_ENOMEM;
> +
> +    p_sys->p_library = InitLibrary(p_sys);
> +    if (p_sys == NULL)
> +        goto error;
> +
> +    // Create the native window by first getting the Java surface.
> +    jobject javaSurface = jni_LockAndGetAndroidJavaSurface();
> +
> +    JNIEnv *p_env;
> +    (*myVm)->AttachCurrentThread(myVm, &p_env, NULL);
> +    p_sys->window = p_sys->s_winFromSurface(p_env, javaSurface); // ANativeWindow_fromSurface call.
> +    (*myVm)->DetachCurrentThread(myVm);
> +
> +    jni_UnlockAndroidSurface();
> +
> +    if (p_sys->window == NULL)
> +        goto error;
> +
> +    wnd->handle.anativewindow = p_sys->window;
> +    wnd->control = Control;
> +    wnd->sys = p_sys;
> +
> +    // Set the Java surface size.
> +    // TODO: get the visible size and sar from vout_window_cfg_t?in

Any insight on this?

> +    jni_SetAndroidSurfaceSize(cfg->width, cfg->height, cfg->width, cfg->height, 1, 1);
> +
> +    return VLC_SUCCESS;
> +
> +error:
> +    return VLC_EGENERIC;

No need for goto is there's no cleanup
s/goto error/return VLC_EGENERIC/

OTOH a dlclose would probably fit well here

> +}
> +
> +
> +/**
> + * Destroys the Android native window.
> + */
> +static void Close(vout_window_t *wnd)
> +{
> +    vout_window_sys_t *p_sys = wnd->sys;
> +    p_sys->s_winRelease(p_sys->window); // Release the native window.
> +    dlclose(p_sys->p_library); // Close the library.
> +    free (p_sys);
> +}
> +
> +
> +/**
> + * Window control.
> + */
> +static int Control(vout_window_t *wnd, int cmd, va_list ap)
> +{
> +    switch (cmd)
> +    {
> +        case VOUT_WINDOW_SET_SIZE:
> +        {
> +            unsigned width = va_arg(ap, unsigned);
> +            unsigned height = va_arg(ap, unsigned);
> +            jni_SetAndroidSurfaceSize(width, height, width, height, 1, 1);
> +            break;
> +        }
> +        case VOUT_WINDOW_SET_STATE:
> +        case VOUT_WINDOW_SET_FULLSCREEN:
> +            return VLC_EGENERIC;
> +        default:
> +            msg_Err (wnd, "request %d not implemented", cmd);
> +            return VLC_EGENERIC;
> +    }
> +    return VLC_SUCCESS;
> +}
> -- 1.8.1.2

> 0003-EGL-add-the-OpenGL-ES-2.0-support-for-android.patch
> 
> 
> From 9d87640b953ebbfca25497d5e7dcfe585854d947 Mon Sep 17 00:00:00 2001
> From: Adrien Maglo <magsoft at videolan.org>
> Date: Tue, 5 Nov 2013 16:36:01 +0100
> Subject: [PATCH 3/3] EGL: add the OpenGL ES 2.0 support for android

Probably OK


More information about the Android mailing list