[vlc-devel] [RFC PATCH 1/7] lib: change libvlc_media_discoverer_t creation

Rémi Denis-Courmont remi at remlab.net
Thu Jan 8 15:12:36 CET 2015


Le 2015-01-07 14:06, Thomas Guillem a écrit :
> libvlc_media_discoverer_new_from_name was creating a 
> services_discovery_t and
> was starting it, so libvlc_MediaDiscovererStarted event (or any other 
> events)
> could not be received.
>
> To fix that, Split libvlc_media_discoverer_new_from_name into
> libvlc_media_discoverer_new and libvlc_media_discoverer_start. That
> way, we can
> attach events between create and start.
>
> libvlc_media_discoverer_new_from_name is now deprecated, but it still 
> works
> like before.
> ---
>  include/vlc/libvlc_media_discoverer.h | 30 ++++++++++++++++++--
>  lib/libvlc.sym                        |  3 ++
>  lib/media_discoverer.c                | 53
> +++++++++++++++++++++++++++--------
>  3 files changed, 72 insertions(+), 14 deletions(-)
>
> diff --git a/include/vlc/libvlc_media_discoverer.h
> b/include/vlc/libvlc_media_discoverer.h
> index cf263b0..0f3b379 100644
> --- a/include/vlc/libvlc_media_discoverer.h
> +++ b/include/vlc/libvlc_media_discoverer.h
> @@ -48,15 +48,39 @@ extern "C" {
>  typedef struct libvlc_media_discoverer_t libvlc_media_discoverer_t;
>
>  /**
> - * Discover media service by name.
> + * \deprecated Use libvlc_media_discoverer_new and
> libvlc_media_discoverer_start.

Not sure if Doxygen will cross-reference properly without "()".

> + */
> +LIBVLC_DEPRECATED LIBVLC_API libvlc_media_discoverer_t *
> +libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
> +                                       const char * psz_name );
> +
> +/**
> + * Create a media discoverer object by name.
>   *
>   * \param p_inst libvlc instance
>   * \param psz_name service name
>   * \return media discover object or NULL in case of error
>   */

Missing \version. Ditto below.

>  LIBVLC_API libvlc_media_discoverer_t *
> -libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
> -                                       const char * psz_name );
> +libvlc_media_discoverer_new( libvlc_instance_t * p_inst,
> +                             const char * psz_name );
> +
> +/**
> + * Start media discovery.
> + *
> + * \param p_mdis media discover object
> + * \return -1 in case of error, 0 otherwise
> + */

This really needs to mention event handling. Otherwise the seperation 
of start and new is pointless IIUC.

> +LIBVLC_API int
> +libvlc_media_discoverer_start( libvlc_media_discoverer_t * p_mdis );
> +
> +/**
> + * Stop media discovery.
> + *
> + * \param p_mdis media discover object
> + */
> +LIBVLC_API void
> +libvlc_media_discoverer_stop( libvlc_media_discoverer_t * p_mdis );
>
>  /**
>   * Release media discover object. If the reference count reaches 0, 
> then
> diff --git a/lib/libvlc.sym b/lib/libvlc.sym
> index c0c66dd..f0512c6 100644
> --- a/lib/libvlc.sym
> +++ b/lib/libvlc.sym
> @@ -76,8 +76,11 @@ libvlc_media_discoverer_event_manager
>  libvlc_media_discoverer_is_running
>  libvlc_media_discoverer_localized_name
>  libvlc_media_discoverer_media_list
> +libvlc_media_discoverer_new
>  libvlc_media_discoverer_new_from_name
>  libvlc_media_discoverer_release
> +libvlc_media_discoverer_start
> +libvlc_media_discoverer_stop
>  libvlc_media_duplicate
>  libvlc_media_event_manager
>  libvlc_media_get_duration
> diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
> index b126c95..a2532cb 100644
> --- a/lib/media_discoverer.c
> +++ b/lib/media_discoverer.c
> @@ -181,12 +181,9 @@ static void services_discovery_ended( const
> vlc_event_t * p_event,
>
>  
> /**************************************************************************
>   *       new (Public)
> - *
> - * Init an object.
>   
> **************************************************************************/
>  libvlc_media_discoverer_t *
> -libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
> -                                       const char * psz_name )
> +libvlc_media_discoverer_new( libvlc_instance_t * p_inst, const char
> * psz_name )
>  {
>      /* podcast SD is a hack and only works with custom playlist
> callbacks. */
>      if( !strncasecmp( psz_name, "podcast", 7 ) )
> @@ -250,14 +247,45 @@ libvlc_media_discoverer_new_from_name(
> libvlc_instance_t * p_inst,
>                        services_discovery_removeall,
>                        p_mdis );
>
> +    return p_mdis;
> +}
> +
> 
> +/**************************************************************************
> + *       start (Public)
> + 
> **************************************************************************/
> +LIBVLC_API int
> +libvlc_media_discoverer_start( libvlc_media_discoverer_t * p_mdis )
> +{
>      /* Here we go */
> -    if( !vlc_sd_Start( p_mdis->p_sd ) )
> +    return vlc_sd_Start( p_mdis->p_sd ) ? 0 : -1;
> +}
> +
> 
> +/**************************************************************************
> + *       stop (Public)
> + 
> **************************************************************************/
> +LIBVLC_API void
> +libvlc_media_discoverer_stop( libvlc_media_discoverer_t * p_mdis )
> +{
> +    return vlc_sd_Stop( p_mdis->p_sd );
> +}
> +
> 
> +/**************************************************************************
> + *       new_from_name (Public)
> + *
> + * \deprecated Use libvlc_media_discoverer_new and
> libvlc_media_discoverer_start
> + 
> **************************************************************************/
> +libvlc_media_discoverer_t *
> +libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
> +                                       const char * psz_name )
> +{
> +    libvlc_media_discoverer_t *p_mdis = libvlc_media_discoverer_new(
> p_inst, psz_name );
> +
> +    if( !p_mdis )
> +        return NULL;
> +
> +    if( libvlc_media_discoverer_start( p_mdis ) != 0)
>      {
> -        libvlc_printerr( "%s: internal module error",
> -                         p_mdis->p_sd->psz_name );
> -        libvlc_media_list_release( p_mdis->p_mlist );
> -        libvlc_event_manager_release( p_mdis->p_event_manager );
> -        free( p_mdis );
> +        libvlc_media_discoverer_release( p_mdis );
>          return NULL;
>      }
>
> @@ -295,7 +323,10 @@ libvlc_media_discoverer_release(
> libvlc_media_discoverer_t * p_mdis )
>
>      libvlc_media_list_release( p_mdis->p_mlist );
>
> -    vlc_sd_StopAndDestroy( p_mdis->p_sd );
> +    if( p_mdis->running )
> +        vlc_sd_Stop( p_mdis->p_sd );
> +
> +    vlc_sd_Destroy( p_mdis->p_sd );
>
>      /* Free catname_to_submedialist and all the mlist */
>      char ** all_keys = vlc_dictionary_all_keys(
> &p_mdis->catname_to_submedialist );

-- 
Rémi Denis-Courmont



More information about the vlc-devel mailing list