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

Steve Lhomme robux4 at ycbcr.xyz
Tue May 7 10:35:10 CEST 2019



On 2019-05-06 16:39, Rémi Denis-Courmont wrote:
> Le maanantaina 6. toukokuuta 2019, 16.01.36 EEST Steve Lhomme a écrit :
>> 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");
>> +    vout_window_ReportSize( wnd, width, height);
> This races against Resize callback. Events are not reentrant - it wouldn't
> make sense.

Actually I don't understand the issue. Resize and WindowSize are indeed 
called by different threads but the doc of vout_window_ReportSize() says:

"Thisfunctionisthread-safe.Incaseofconcurrentcall,itisundefinedwhichoneistakenintoaccount(butatleastoneis)."

So it sounds like it's OK to call it from different threads. If not I 
can always add a lock but I'd like to understand.


More information about the vlc-devel mailing list