[vlc-devel] [PATCH 5/6] plugin: move config choice enum callbacks

Steve Lhomme robux4 at ycbcr.xyz
Fri Jul 19 09:17:59 CEST 2019


On 2019-07-18 21:29, RĂ©mi Denis-Courmont wrote:
> ...out of the descriptor, to some new place with better type safety.
> ---
>   include/vlc_plugin.h                   | 34 ++++++++++++++++++++------
>   modules/access/dshow/dshow.cpp         |  5 ++--
>   modules/audio_output/alsa.c            |  3 ++-
>   modules/audio_output/directsound.c     |  4 +--
>   modules/audio_output/mmdevice.c        |  3 ++-
>   modules/audio_output/waveout.c         |  4 +--
>   modules/video_output/win32/direct3d9.c |  5 ++--
>   src/config/core.c                      | 24 ++++++++----------
>   8 files changed, 48 insertions(+), 34 deletions(-)
> 
> diff --git a/include/vlc_plugin.h b/include/vlc_plugin.h
> index 4ff6e86348..d8a7fcb65b 100644
> --- a/include/vlc_plugin.h
> +++ b/include/vlc_plugin.h
> @@ -244,6 +244,15 @@ EXTERN_SYMBOL typedef int (*vlc_set_cb) (void *, void *, int, ...);
>   #define vlc_module_set(...) vlc_set (opaque, module, __VA_ARGS__)
>   #define vlc_config_set(...) vlc_set (opaque, config, __VA_ARGS__)
>   
> +EXTERN_SYMBOL DLL_SYMBOL
> +int CDECL_SYMBOL VLC_SYMBOL(vlc_entry)(vlc_set_cb, void *);
> +EXTERN_SYMBOL DLL_SYMBOL
> +int CDECL_SYMBOL VLC_SYMBOL(vlc_entry_cfg_int_enum)(const char *name,
> +    int64_t **values, char ***descs);
> +EXTERN_SYMBOL DLL_SYMBOL
> +int CDECL_SYMBOL VLC_SYMBOL(vlc_entry_cfg_str_enum)(const char *name,
> +    char ***values, char ***descs);
> +
>   /*
>    * InitModule: this function is called once and only once, when the module
>    * is looked at for the first time. We get the useful data from it, for
> @@ -252,8 +261,6 @@ EXTERN_SYMBOL typedef int (*vlc_set_cb) (void *, void *, int, ...);
>    */
>   #define vlc_module_begin() \
>   EXTERN_SYMBOL DLL_SYMBOL \
> -int CDECL_SYMBOL VLC_SYMBOL(vlc_entry)(vlc_set_cb, void *); \
> -EXTERN_SYMBOL DLL_SYMBOL \
>   int CDECL_SYMBOL VLC_SYMBOL(vlc_entry)(vlc_set_cb vlc_set, void *opaque) \
>   { \
>       module_t *module; \
> @@ -464,18 +471,12 @@ VLC_METADATA_EXPORTS
>                       (const char *const *)(list), \
>                       (const char *const *)(list_text));
>   
> -#define change_string_cb( cb ) \
> -    vlc_config_set (VLC_CONFIG_LIST_CB, #cb, (void *)(cb));
> -
>   #define change_integer_list( list, list_text ) \
>       vlc_config_set (VLC_CONFIG_LIST, \
>                       (size_t)(sizeof (list) / sizeof (int)), \
>                       (const int *)(list), \
>                       (const char *const *)(list_text));
>   
> -#define change_integer_cb( cb ) \
> -    vlc_config_set (VLC_CONFIG_LIST_CB, #cb, (cb));
> -
>   #define change_integer_range( minv, maxv ) \
>       vlc_config_set (VLC_CONFIG_RANGE, (int64_t)(minv), (int64_t)(maxv));
>   
> @@ -494,6 +495,23 @@ VLC_METADATA_EXPORTS
>   #define change_safe() \
>       vlc_config_set (VLC_CONFIG_SAFE);
>   
> +/* Configuration item choice enumerators */
> +#define VLC_CONFIG_INTEGER_ENUM(cb) \
> +EXTERN_SYMBOL DLL_SYMBOL \
> +int CDECL_SYMBOL VLC_SYMBOL(vlc_entry_cfg_int_enum)(const char *name, \
> +    int64_t **values, char ***descs) \
> +{ \
> +    return (cb)(name, values, descs); \
> +}
> +
> +#define VLC_CONFIG_STRING_ENUM(cb) \
> +EXTERN_SYMBOL DLL_SYMBOL \
> +int CDECL_SYMBOL VLC_SYMBOL(vlc_entry_cfg_str_enum)(const char *name, \
> +    char ***values, char ***descs) \
> +{ \
> +    return (cb)(name, values, descs); \
> +}
> +
>   /* Meta data plugin exports */
>   #define VLC_META_EXPORT( name, value ) \
>       EXTERN_SYMBOL DLL_SYMBOL const char * CDECL_SYMBOL \
> diff --git a/modules/access/dshow/dshow.cpp b/modules/access/dshow/dshow.cpp
> index 1076e64085..f5a6604d6a 100644
> --- a/modules/access/dshow/dshow.cpp
> +++ b/modules/access/dshow/dshow.cpp
> @@ -70,7 +70,6 @@ static size_t EnumDeviceCaps( vlc_object_t *, IBaseFilter *,
>                                 AM_MEDIA_TYPE *mt, size_t, bool );
>   static bool ConnectFilters( vlc_object_t *, access_sys_t *,
>                               IBaseFilter *, CaptureFilter * );
> -static int FindDevices( const char *, char ***, char *** );
>   
>   static void ShowPropertyPage( IUnknown * );
>   static void ShowDeviceProperties( vlc_object_t *, ICaptureGraphBuilder2 *,
> @@ -193,10 +192,8 @@ vlc_module_begin ()
>       set_category( CAT_INPUT )
>       set_subcategory( SUBCAT_INPUT_ACCESS )
>       add_string( "dshow-vdev", NULL, VDEV_TEXT, VDEV_LONGTEXT, false)
> -        change_string_cb( FindDevices )
>   
>       add_string( "dshow-adev", NULL, ADEV_TEXT, ADEV_LONGTEXT, false)
> -        change_string_cb( FindDevices )
>   
>       add_string( "dshow-size", NULL, SIZE_TEXT, SIZE_LONGTEXT, false)
>           change_safe()
> @@ -2077,6 +2074,8 @@ static int FindDevices( const char *psz_name, char ***vp, char ***tp )
>       return count;
>   }
>   
> +VLC_CONFIG_STRING_ENUM(FindDevices)
> +
>   /*****************************************************************************
>    * Properties
>    *****************************************************************************/
> diff --git a/modules/audio_output/alsa.c b/modules/audio_output/alsa.c
> index ccf9435b1d..63056de522 100644
> --- a/modules/audio_output/alsa.c
> +++ b/modules/audio_output/alsa.c
> @@ -98,7 +98,6 @@ vlc_module_begin ()
>       set_subcategory( SUBCAT_AUDIO_AOUT )
>       add_string ("alsa-audio-device", "default",
>                   AUDIO_DEV_TEXT, AUDIO_DEV_LONGTEXT, false)
> -        change_string_cb (EnumDevices)
>       add_integer ("alsa-audio-channels", AOUT_CHANS_FRONT,
>                    AUDIO_CHAN_TEXT, AUDIO_CHAN_LONGTEXT, false)
>           change_integer_list (channels, channels_text)
> @@ -804,6 +803,8 @@ static int EnumDevices(char const *varname,
>       return n;
>   }
>   
> +VLC_CONFIG_STRING_ENUM(EnumDevices)
> +
>   static int DeviceSelect (audio_output_t *aout, const char *id)
>   {
>       aout_sys_t *sys = aout->sys;
> diff --git a/modules/audio_output/directsound.c b/modules/audio_output/directsound.c
> index 9c55b34727..45f5885734 100644
> --- a/modules/audio_output/directsound.c
> +++ b/modules/audio_output/directsound.c
> @@ -46,7 +46,6 @@ static int  Open( vlc_object_t * );
>   static void Close( vlc_object_t * );
>   static HRESULT StreamStart( aout_stream_t *, audio_sample_format_t *,
>                               const GUID * );
> -static int ReloadDirectXDevices( const char *, char ***, char *** );
>   static void * PlayedDataEraser( void * );
>   /* Speaker setup override options list */
>   static const char *const speaker_list[] = { "Windows default", "Mono", "Stereo",
> @@ -75,7 +74,6 @@ vlc_module_begin ()
>   
>       add_string( "directx-audio-device", NULL,
>                DEVICE_TEXT, DEVICE_LONGTEXT, false )
> -        change_string_cb( ReloadDirectXDevices )
>       add_obsolete_string( "directx-audio-device-name")
>       add_bool( "directx-audio-float32", true, FLOAT_TEXT,
>                 FLOAT_LONGTEXT, true )
> @@ -1045,6 +1043,8 @@ static int ReloadDirectXDevices( char const *psz_name,
>       return list.count;
>   }
>   
> +VLC_CONFIG_STRING_ENUM(ReloadDirectXDevices)
> +
>   static int DeviceSelect (audio_output_t *aout, const char *id)
>   {
>       var_SetString(aout, "directx-audio-device", (id != NULL) ? id : "");
> diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
> index de42ffd6a4..cb05f46597 100644
> --- a/modules/audio_output/mmdevice.c
> +++ b/modules/audio_output/mmdevice.c
> @@ -1443,6 +1443,8 @@ error:
>       return list.count;
>   }
>   
> +VLC_CONFIG_STRING_ENUM(ReloadAudioDevices)
> +
>   #define MM_PASSTHROUGH_TEXT N_( \
>       "HDMI/SPDIF audio passthrough")
>   #define MM_PASSTHROUGH_LONGTEXT N_( \
> @@ -1478,7 +1480,6 @@ vlc_module_begin()
>           change_integer_list( pi_mmdevice_passthrough_values,
>                                ppsz_mmdevice_passthrough_texts )
>       add_string("mmdevice-audio-device", NULL, DEVICE_TEXT, DEVICE_LONGTEXT, false)
> -        change_string_cb(ReloadAudioDevices)
>       add_float("mmdevice-volume", 1.f, VOLUME_TEXT, VOLUME_LONGTEXT, true)
>           change_float_range( 0.f, 1.25f )
>   vlc_module_end()
> diff --git a/modules/audio_output/waveout.c b/modules/audio_output/waveout.c
> index 736a5f016c..990b1e8b8d 100644
> --- a/modules/audio_output/waveout.c
> +++ b/modules/audio_output/waveout.c
> @@ -76,7 +76,6 @@ static void WaveOutClean( aout_sys_t * p_sys );
>   
>   static void WaveOutClearBuffer( HWAVEOUT, WAVEHDR *);
>   
> -static int ReloadWaveoutDevices( const char *, char ***, char *** );
>   static uint32_t findDeviceID(char *);
>   static int WaveOutTimeGet(audio_output_t * , vlc_tick_t *);
>   static void WaveOutFlush( audio_output_t *);
> @@ -154,7 +153,6 @@ vlc_module_begin ()
>       set_subcategory( SUBCAT_AUDIO_AOUT )
>       add_string( "waveout-audio-device", "wavemapper",
>                    DEVICE_TEXT, DEVICE_LONG, false )
> -       change_string_cb( ReloadWaveoutDevices )
>       add_float( "waveout-volume", 1.0f, VOLUME_TEXT, NULL, true )
>            change_float_range(0.0f, 2.0f)
>       add_bool( "waveout-float32", true, FLOAT_TEXT, FLOAT_LONGTEXT, true )
> @@ -718,6 +716,8 @@ static int ReloadWaveoutDevices( char const *psz_name,
>       return n;
>   }
>   
> +VLC_CONFIG_STRING_ENUM(ReloadWaveoutDevices)
> +
>   /*
>     convert devicename to device ID for output
>     if device not found return WAVE_MAPPER, so let
> diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
> index a411e705cd..5372ffd465 100644
> --- a/modules/video_output/win32/direct3d9.c
> +++ b/modules/video_output/win32/direct3d9.c
> @@ -96,8 +96,6 @@ static void GLConvClose(vlc_object_t *);
>   
>   #define D3D9_HELP N_("Recommended video output for Windows Vista and later versions")
>   
> -static int FindShadersCallback(const char *, char ***, char ***);
> -
>   vlc_module_begin ()
>       set_shortname("Direct3D9")
>       set_description(N_("Direct3D9 video output"))
> @@ -109,7 +107,6 @@ vlc_module_begin ()
>       add_bool("directx-hw-yuv", true, HW_YUV_TEXT, HW_YUV_LONGTEXT, true)
>   
>       add_string("direct3d9-shader", "", PIXEL_SHADER_TEXT, PIXEL_SHADER_LONGTEXT, true)
> -        change_string_cb(FindShadersCallback)
>       add_loadfile("direct3d9-shader-file", NULL,
>                    PIXEL_SHADER_FILE_TEXT, PIXEL_SHADER_FILE_LONGTEXT)
>   
> @@ -1599,6 +1596,8 @@ static int FindShadersCallback(const char *name, char ***values, char ***descs)
>   
>   }
>   
> +VLC_CONFIG_STRING_ENUM(FindShadersCallback)
> +
>   static bool LocalSwapchainSetupDevice( void **opaque, const libvlc_video_direct3d_device_cfg_t *cfg, libvlc_video_direct3d_device_setup_t *out )
>   {
>       vout_display_t *vd = *opaque;
> diff --git a/src/config/core.c b/src/config/core.c
> index e2767e371c..8fb7d82fee 100644
> --- a/src/config/core.c
> +++ b/src/config/core.c
> @@ -205,15 +205,13 @@ ssize_t config_GetIntChoices(const char *name,
>       size_t count = cfg->list_count;
>       if (count == 0)
>       {
> -        if (module_Map(NULL, cfg->owner))
> -        {
> -            errno = EIO;
> -            return -1;
> -        }
> +        int (*cb)(const char *, int64_t **, char ***);
>   
> -        if (cfg->list.i_cb == NULL)
> +        cb = module_Symbol(NULL, cfg->owner, "vlc_entry_cfg_int_enum");
> +        if (cb == NULL)
>               return 0;
> -        return cfg->list.i_cb(name, values, texts);
> +
> +        return cb(name, values, texts);

It seems the 'name' parameter is never used in any of the callbacks, so 
we could just remove it.

And why not use vlc_integer_list_cb which already exist ?

>       }
>   
>       int64_t *vals = vlc_alloc (count, sizeof (*vals));
> @@ -338,15 +336,13 @@ ssize_t config_GetPszChoices(const char *name,
>       size_t count = cfg->list_count;
>       if (count == 0)
>       {
> -        if (module_Map(NULL, cfg->owner))
> -        {
> -            errno = EIO;
> -            return -1;
> -        }
> +        int (*cb)(const char *, char ***, char ***);

Same question for vlc_string_list_cb.

> -        if (cfg->list.psz_cb == NULL)
> +        cb = module_Symbol(NULL, cfg->owner, "vlc_entry_cfg_str_enum");
> +        if (cb == NULL)
>               return 0;
> -        return cfg->list.psz_cb(name, values, texts);
> +
> +        return cb(name, values, texts);
>       }
>   
>       char **vals = malloc (sizeof (*vals) * count);
> -- 
> 2.22.0
> 
> _______________________________________________
> 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