[vlc-devel] [PATCH 7/8] libvlc:vout: add a custom vout window module that can change the display size

Thomas Guillem thomas at gllm.fr
Tue May 7 10:57:49 CEST 2019



On Mon, May 6, 2019, at 15:02, Steve Lhomme wrote:
> The libvlc_video_set_rendering_size() set the width/height and the host_window
> module receives the change and tell the display module about the new size to
> render into.
> ---
>  lib/media_player.c                 |   2 +-
>  modules/video_output/Makefile.am   |   2 +
>  modules/video_output/host_window.c | 105 +++++++++++++++++++++++++++++
>  3 files changed, 108 insertions(+), 1 deletion(-)
>  create mode 100644 modules/video_output/host_window.c
> 
> diff --git a/lib/media_player.c b/lib/media_player.c
> index 64d8a873fb..3e05d52fd9 100644
> --- a/lib/media_player.c
> +++ b/lib/media_player.c
> @@ -1214,7 +1214,7 @@ int libvlc_video_surface_set_callbacks( 
> libvlc_media_player_t *mp,
>                                          
> libvlc_video_surface_start_rendering_cb makeCurrent_cb,
>                                          void* opaque )
>  {
> -    var_SetString( mp, "window", "wdummy");
> +    var_SetString( mp, "window", "host_window");
>  
>      if ( engine == libvlc_video_rendering_direct3d11 )
>      {
> diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
> index ff3648e7cb..65913a3818 100644
> --- a/modules/video_output/Makefile.am
> +++ b/modules/video_output/Makefile.am
> @@ -465,6 +465,7 @@ vout_LTLIBRARIES += $(LTLIBcaca)
>  libflaschen_plugin_la_SOURCES = video_output/flaschen.c
>  libflaschen_plugin_la_LIBADD = $(SOCKET_LIBS)
>  
> +libhost_window_plugin_la_SOURCES = video_output/host_window.c
>  libvdummy_plugin_la_SOURCES = video_output/vdummy.c
>  libvideo_splitter_plugin_la_SOURCES = video_output/splitter.c
>  libvmem_plugin_la_SOURCES = video_output/vmem.c
> @@ -474,6 +475,7 @@ libvgl_plugin_la_SOURCES = video_output/vgl.c
>  
>  vout_LTLIBRARIES += \
>  	libflaschen_plugin.la \
> +	libhost_window_plugin.la \
>  	libvdummy_plugin.la \
>  	libvideo_splitter_plugin.la \
>  	libvmem_plugin.la \
> diff --git a/modules/video_output/host_window.c 
> b/modules/video_output/host_window.c
> new file mode 100644
> index 0000000000..48a72e90c4
> --- /dev/null
> +++ b/modules/video_output/host_window.c
> @@ -0,0 +1,105 @@
> +/**
> + * @file host_window.c
> + * @brief Video window provider that can be resized externally
> + */
> +/*****************************************************************************
> + * Copyright (C) 2019 VLC authors and VideoLAN
> + *
> + * 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_window.h>
> +
> +static int Open( vout_window_t * );
> +
> +vlc_module_begin()
> +    set_shortname(N_("Host window"))
> +    set_description(N_("Host window"))
> +    set_category(CAT_VIDEO)
> +    set_subcategory(SUBCAT_VIDEO_VOUT)
> +    set_capability("vout window", 0)
> +    set_callbacks(Open, NULL)
> +vlc_module_end()
> +
> +struct window_sys_t
> +{
> +    vlc_object_t *dimension_src;
> +};
> +
> +static int Enable(vout_window_t *wnd, const vout_window_cfg_t *cfg)
> +{
> +    vout_window_ReportSize(wnd, cfg->width, cfg->height);
> +    return VLC_SUCCESS;
> +}
> +
> +static void Resize(vout_window_t *window, unsigned width, unsigned 
> height)
> +{
> +    vout_window_ReportSize(window, width, height);
> +}
> +
> +static int WindowSize( vlc_object_t *obj, char const *name,
> +                        vlc_value_t oldvalue, vlc_value_t newvalue, 
> void *p_wnd )
> +{
> +    VLC_UNUSED(name);
> +    VLC_UNUSED(oldvalue);
> +    VLC_UNUSED(newvalue);
> +
> +    vout_window_t *wnd = p_wnd;
> +    int width  = var_GetInteger(obj, "width");
> +    int height = var_GetInteger(obj, "height");

getting the size is not atomic here. Why not using newvalue as coord here ?

> +    vout_window_ReportSize( wnd, width, height);
> +    return 0;
> +}
> +
> +static void Destroy(struct vout_window_t *wnd)
> +{
> +    struct window_sys_t *sys = wnd->sys;
> +    var_DelCallback( sys->dimension_src, "window-size", WindowSize, 
> wnd);
> +}
> +
> +static const struct vout_window_operations ops = {
> +    .enable = Enable,
> +    .resize = Resize,
> +    .destroy = Destroy,
> +};
> +
> +static int Open(vout_window_t *wnd)
> +{
> +    struct window_sys_t *sys = vlc_obj_malloc(VLC_OBJECT(wnd), 
> sizeof(struct window_sys_t));
> +    if (unlikely(sys==NULL))
> +        return VLC_ENOMEM;
> +
> +    sys->dimension_src = VLC_OBJECT(wnd);
> +    while (sys->dimension_src != NULL && var_Type( sys->dimension_src, 
> "window-size" ) == 0)
> +        sys->dimension_src = vlc_object_parent( sys->dimension_src );
> +
> +    if (sys->dimension_src == NULL )
> +    {
> +        msg_Err(wnd, "missing size trigger");
> +        return VLC_EGENERIC;
> +    }
> +
> +    var_AddCallback( sys->dimension_src, "window-size", WindowSize, 
> wnd);
> +    wnd->type = VOUT_WINDOW_TYPE_DUMMY;
> +    wnd->ops = &ops;
> +    wnd->sys = sys;
> +    return VLC_SUCCESS;
> +}
> -- 
> 2.17.1
> 
> _______________________________________________
> 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