[vlc-devel] [PATCH v3 1/3] vgl: provide a module to allow rendering in a user defined opengl context

Rémi Denis-Courmont remi at remlab.net
Wed Jul 25 21:39:02 CEST 2018


Le keskiviikkona 25. heinäkuuta 2018, 16.41.07 EEST Pierre Lamot a écrit :
>   This module aims to provide the same kind of functionnality as vmem but
> for opengl rendering.
> 
>   Users will have to provide different callbacks:
> 
>   * vgl-setup-cb to setup resources
>   * vgl-cleanup-cb to release resources
>   * vgl-resize-cb will be called when video size changes
>   * vgl-swap-cb that will be called once the current frame has been rendered
> * vgl-make-current-cb to enter/leave the opengl context
>   * vgl-get-proc-address-cb to provide opengl functions
> 
>   Note that users will have to ensure synchronisation on their side since
>   VLC will run and render OpenGL in its own thread.
> ---
>  modules/video_output/Makefile.am |   2 +
>  modules/video_output/vgl.c       | 168 +++++++++++++++++++++++++++++++
>  2 files changed, 170 insertions(+)
>  create mode 100644 modules/video_output/vgl.c
> 
> diff --git a/modules/video_output/Makefile.am
> b/modules/video_output/Makefile.am index 8dab932b30..a843882816 100644
> --- a/modules/video_output/Makefile.am
> +++ b/modules/video_output/Makefile.am
> @@ -454,10 +454,12 @@ libvdummy_plugin_la_SOURCES = video_output/vdummy.c
>  libvmem_plugin_la_SOURCES = video_output/vmem.c
>  libwdummy_plugin_la_SOURCES = video_output/wdummy.c
>  libyuv_plugin_la_SOURCES = video_output/yuv.c
> +libvgl_plugin_la_SOURCES = video_output/vgl.c
> 
>  vout_LTLIBRARIES += \
>  	libflaschen_plugin.la \
>  	libvdummy_plugin.la \
>  	libvmem_plugin.la \
>  	libwdummy_plugin.la \
> +	libvgl_plugin.la \
>  	libyuv_plugin.la
> diff --git a/modules/video_output/vgl.c b/modules/video_output/vgl.c
> new file mode 100644
> index 0000000000..a2272f9eab
> --- /dev/null
> +++ b/modules/video_output/vgl.c
> @@ -0,0 +1,168 @@
> +/**************************************************************************
> *** + * vgl.c: virtual LibVLC OpenGL extension
> +
> ***************************************************************************
> ** + * Copyright (c) 2018 VLC authors and VideoLAN
> + *
> + * Authors: Pierre Lamot <pierre at videolabs.io>
> + *
> + * 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 <vlc_common.h>
> +#include <vlc_plugin.h>
> +#include <vlc_vout_display.h>
> +#include <vlc_opengl.h>
> +
> +
> +struct vout_display_sys_t
> +{
> +    vlc_gl_t              *gl;
> +
> +    void (*cleanupCb)(void* opaque);
> +    bool (*setupCb)(void* opaque);
> +    void (*resizeCb)(void* opaque, unsigned, unsigned);
> +    void (*swapCb)(void* opaque);
> +    bool (*makeCurrentCb)(void* opaque, bool);
> +    void* (*getProcAddressCb)(void* opaque, const char *name);
> +
> +    void* opaque;
> +    unsigned width;
> +    unsigned height;
> +};
> +
> +
> +static void *OurGetProcAddress(vlc_gl_t *gl, const char *name)
> +{
> +    vout_display_sys_t *sys = gl->sys;
> +    return sys->getProcAddressCb(sys->opaque, name);
> +}
> +
> +static int MakeCurrent(vlc_gl_t *gl)
> +{
> +    vout_display_sys_t *sys = gl->sys;
> +    bool success = sys->makeCurrentCb(sys->opaque, true);
> +    return success ? VLC_SUCCESS : VLC_EGENERIC;
> +}
> +
> +static void ReleaseCurrent(vlc_gl_t *gl)
> +{
> +    vout_display_sys_t *sys = gl->sys;
> +    sys->makeCurrentCb(sys->opaque, false);
> +}
> +
> +static void SwapBuffers(vlc_gl_t *gl)
> +{
> +    vout_display_sys_t *sys = gl->sys;
> +    sys->swapCb(sys->opaque);
> +}
> +
> +static void Resize(vlc_gl_t * gl, unsigned w, unsigned h)
> +{
> +    vout_display_sys_t *sys = gl->sys;
> +    if( sys->width == w && sys->height == h )
> +        return;
> +
> +    if( !sys->resizeCb )
> +        return;
> +
> +    MakeCurrent(gl);
> +    sys->resizeCb(sys->opaque, w, h);
> +    ReleaseCurrent(gl);
> +    sys->width = w;
> +    sys->height = h;
> +}
> +
> +static void Close(vlc_object_t *object)
> +{
> +    vlc_gl_t *gl = (vlc_gl_t *)object;
> +    vout_display_sys_t *sys = gl->sys;
> +    if( sys && sys->cleanupCb )

sys cannot be false here.

> +        sys->cleanupCb(sys->opaque);
> +    free(sys);
> +}
> +
> +
> +#define SET_CALLBACK_ADDR(var, varname) \
> +    do {                                                           \
> +        var = var_InheritAddress(gl, varname);                     \
> +        if( !var ) {                                               \
> +            msg_Err( gl, varname " address is missing" );          \

%s

> +            goto error;                                            \
> +        }                                                          \
> +    } while( 0 )
> +
> +static int Open(vlc_object_t *object)
> +{
> +    vlc_gl_t *gl = (vlc_gl_t *)object;
> +
> +    /* Allocate structure */
> +    vout_display_sys_t *sys = calloc(1, sizeof(*sys));

vlc_obj_malloc

> +    if( !sys )
> +        return VLC_ENOMEM;
> +
> +    sys->opaque = var_InheritAddress(gl, "vgl-opaque");
> +    sys->setupCb = var_InheritAddress(gl, "vgl-setup-cb");
> +    sys->cleanupCb = var_InheritAddress(gl, "vgl-cleanup-cb");
> +    sys->resizeCb = var_InheritAddress(gl, "vgl-resize-cb");
> +    SET_CALLBACK_ADDR(sys->swapCb, "vgl-swap-cb");
> +    SET_CALLBACK_ADDR(sys->makeCurrentCb, "vgl-make-current-cb");
> +    SET_CALLBACK_ADDR(sys->getProcAddressCb, "vgl-get-proc-address-cb");
> +
> +    gl->makeCurrent = MakeCurrent;
> +    gl->releaseCurrent = ReleaseCurrent;
> +    gl->resize = Resize;
> +    gl->swap = SwapBuffers;
> +    gl->getProcAddress = OurGetProcAddress;
> +
> +    if( sys->setupCb )
> +        if( !sys->setupCb(sys->opaque) )
> +        {
> +            msg_Err( gl, "user setup failed" );
> +            goto error;
> +        }
> +
> +    gl->sys = sys;
> +
> +    return VLC_SUCCESS;
> +
> +error:
> +    free(sys);
> +    return VLC_EGENERIC;
> +}
> +
> +#undef SET_CALLBACK_ADDR
> +
> +/**************************************************************************
> *** + * Module descriptor
> +
> ***************************************************************************
> **/ +
> +vlc_module_begin()
> +    set_shortname(N_("GL texture"))
> +    set_description(N_("GL texture output"))

Missing POTFILES

> +    set_category(CAT_VIDEO)
> +    set_subcategory(SUBCAT_VIDEO_VOUT)
> +
> +    set_capability("opengl", 0)
> +    set_callbacks(Open, Close)
> +    add_shortcut("vglmem")
> +
> +    add_submodule()
> +    set_capability("opengl es2", 0)
> +    set_callbacks(Open, Close)
> +    add_shortcut("vglmem")
> +vlc_module_end()


-- 
Rémi Denis-Courmont
http://www.remlab.net/





More information about the vlc-devel mailing list