[vlc-devel] [PATCH] lib: change libvlc_media_discoverer_t creation

Jean-Baptiste Kempf jb at videolan.org
Mon Dec 1 18:20:16 CET 2014


Rémi?

Can we break the existing behavior or do we need a new function like
this?


On 28 Nov, Thomas Guillem wrote :
> 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.
> + */
> +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
>   */
>  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
> + */
> +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..8d1493a 100644
> --- a/lib/libvlc.sym
> +++ b/lib/libvlc.sym
> @@ -77,7 +77,10 @@ libvlc_media_discoverer_is_running
>  libvlc_media_discoverer_localized_name
>  libvlc_media_discoverer_media_list
>  libvlc_media_discoverer_new_from_name
> +libvlc_media_discoverer_new
>  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 );
> -- 
> 2.1.3
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel

-- 
With my kindest regards,

-- 
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device



More information about the vlc-devel mailing list