[vlc-devel] [PATCH 04/10] libvlc: keep the audio device string in the libvlc_media_player_t

Rémi Denis-Courmont remi at remlab.net
Mon May 27 17:35:09 CEST 2019


Le maanantaina 27. toukokuuta 2019, 16.38.16 EEST Steve Lhomme a écrit :
> It will be free'd with the media_player
> ---
>  include/vlc/libvlc_media_player.h | 3 +--
>  lib/audio.c                       | 8 +++++---
>  lib/media_player.c                | 2 ++
>  lib/media_player_internal.h       | 3 +++
>  4 files changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/include/vlc/libvlc_media_player.h
> b/include/vlc/libvlc_media_player.h index c4a2912ab2..72cc9d1d4b 100644
> --- a/include/vlc/libvlc_media_player.h
> +++ b/include/vlc/libvlc_media_player.h
> @@ -2086,10 +2086,9 @@ LIBVLC_API void libvlc_audio_output_device_set(
> libvlc_media_player_t *mp, * \param mp media player
>   * \return the current audio output device identifier
>   *         NULL if no device is selected or in case of error
> - *         (the result must be released with free()).
>   * \version LibVLC 3.0.0 or later.

Lifetime of the result should be documented.


>   */
> -LIBVLC_API char *libvlc_audio_output_device_get( libvlc_media_player_t *mp
> ); +LIBVLC_API const char *libvlc_audio_output_device_get(
> libvlc_media_player_t *mp );
> 
>  /**
>   * Toggle mute status.
> diff --git a/lib/audio.c b/lib/audio.c
> index f5e4493138..e0118c8b2c 100644
> --- a/lib/audio.c
> +++ b/lib/audio.c
> @@ -251,17 +251,19 @@ void libvlc_audio_output_device_set(
> libvlc_media_player_t *mp, aout_Release(aout);
>  }
> 
> -char *libvlc_audio_output_device_get( libvlc_media_player_t *mp )
> +const char *libvlc_audio_output_device_get( libvlc_media_player_t *mp )
>  {
>      audio_output_t *aout = GetAOut( mp );
>      if( aout == NULL )
>          return NULL;
> 
> -    char *devid = aout_DeviceGet( aout );
> +    free( mp->psz_audio_devid );
> +    mp->psz_audio_devid = aout_DeviceGet( aout );
> 
>      aout_Release(aout);
> 
> -    return devid;
> +
> +    return mp->psz_audio_devid;
>  }
> 
>  void libvlc_audio_toggle_mute( libvlc_media_player_t *mp )
> diff --git a/lib/media_player.c b/lib/media_player.c
> index fd085c3793..118bc26c36 100644
> --- a/lib/media_player.c
> +++ b/lib/media_player.c
> @@ -695,6 +695,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
>      }
> 
>      mp->p_md = NULL;
> +    mp->psz_audio_devid = NULL;
>      mp->p_libvlc_instance = instance;
>      /* use a reentrant lock to allow calling libvlc functions from
> callbacks */ mp->player = vlc_player_New(VLC_OBJECT(mp),
> VLC_PLAYER_LOCK_REENTRANT, @@ -796,6 +797,7 @@ static void
> libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
> libvlc_event_manager_destroy(&p_mi->event_manager);
>      libvlc_media_release( p_mi->p_md );
> 
> +    free( p_mi->psz_audio_devid );
>      vlc_http_cookie_jar_t *cookies = var_GetAddress( p_mi, "http-cookies"
> ); if ( cookies )
>      {
> diff --git a/lib/media_player_internal.h b/lib/media_player_internal.h
> index c2d5348e22..e0b2849b9a 100644
> --- a/lib/media_player_internal.h
> +++ b/lib/media_player_internal.h
> @@ -49,6 +49,9 @@ struct libvlc_media_player_t
>      struct libvlc_instance_t * p_libvlc_instance; /* Parent instance */
>      libvlc_media_t * p_md; /* current media descriptor */
>      libvlc_event_manager_t event_manager;
> +
> +    /* strings read by the host and released with the media_player */
> +    char *psz_audio_devid;
>  };
> 
>  libvlc_track_description_t * libvlc_get_track_description(


-- 
雷米‧德尼-库尔蒙
http://www.remlab.net/





More information about the vlc-devel mailing list