[vlc-commits] [Git][videolan/vlc][master] 4 commits: lib: remove libvlc_audio_output_device_list_get() (refs #26440)

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Thu Feb 3 10:46:40 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
e0ed4601 by Rémi Denis-Courmont at 2022-02-03T10:28:17+00:00
lib: remove libvlc_audio_output_device_list_get() (refs #26440)

This function does not work with MMDevice and PulseAudio, and does not
support hot-plug. To enumerate devices, the newer function
libvlc_audio_output_device_enum() ought to be used, which also works
with MMDevice and PulseAudio, and track audio device events.

No amount of documentational warnings will save developers from using
this broken function. It is better to remove it now that there is the
opportunity to do so in the form of the LibVLC 4.0 binary compatibility
break.

- - - - -
2be8d2d0 by Rémi Denis-Courmont at 2022-02-03T10:28:17+00:00
lib: return an error code when changing audio device

- - - - -
fd345221 by Rémi Denis-Courmont at 2022-02-03T10:28:17+00:00
lib: only change device of current output

Historically this function would set the device for a specified audio
output module. This required the application to somehow "know" what
audio output module it wanted to use, which is very suboptimal for
forward compatibility and portability.

Worse yet, this design failed outright in VLC 2.2 with the addition of
MMDevice and PulseAudio. This lead to the convention of leaving the
module parameter NULL to change the device of the currently active
audio output.

As with the removal of libvlc_audio_output_device_list_get(), it seems
saner to simply remove the old broken semantics.

- - - - -
ce7cc9dd by Rémi Denis-Courmont at 2022-02-03T10:28:17+00:00
lib: recreate aout when module is changed

libvlc_audio_output_set() had no practical effects as the audio output
was consistently created before the application had the opportunity to
select a non-default module. This fixes it.

An alternative would be to remove the function entirely. Exposing
module names to LibVLC applications is bad design.

- - - - -


5 changed files:

- include/vlc/libvlc_media_player.h
- lib/audio.c
- lib/libvlc.sym
- test/libvlc/core.c
- test/libvlc/media_player.c


Changes:

=====================================
include/vlc/libvlc_media_player.h
=====================================
@@ -2223,8 +2223,9 @@ LIBVLC_API int libvlc_audio_output_set( libvlc_media_player_t *p_mi,
                                         const char *psz_name );
 
 /**
- * Gets a list of potential audio output devices,
- * \see libvlc_audio_output_device_set().
+ * Gets a list of potential audio output devices.
+ *
+ * See also libvlc_audio_output_device_set().
  *
  * \note Not all audio outputs support enumerating devices.
  * The audio output may be functional even if the list is empty (NULL).
@@ -2243,30 +2244,18 @@ LIBVLC_API int libvlc_audio_output_set( libvlc_media_player_t *p_mi,
 LIBVLC_API libvlc_audio_output_device_t *
 libvlc_audio_output_device_enum( libvlc_media_player_t *mp );
 
-/**
- * Gets a list of audio output devices for a given audio output module,
- * \see libvlc_audio_output_device_set().
- *
- * \note Not all audio outputs support this. In particular, an empty (NULL)
- * list of devices does <b>not</b> imply that the specified audio output does
- * not work.
- *
- * \note The list might not be exhaustive.
- *
- * \warning Some audio output devices in the list might not actually work in
- * some circumstances. By default, it is recommended to not specify any
- * explicit audio device.
- *
- * \param p_instance libvlc instance
- * \param aout audio output name
- *                 (as returned by libvlc_audio_output_list_get())
- * \return A NULL-terminated linked list of potential audio output devices.
- * It must be freed with libvlc_audio_output_device_list_release()
- * \version LibVLC 2.1.0 or later.
- */
-LIBVLC_API libvlc_audio_output_device_t *
+#if defined (__GNUC__) && !defined (__clang__)
+__attribute__((unused))
+__attribute__((noinline))
+__attribute__((error("Use libvlc_audio_output_device_enum() instead")))
+static libvlc_audio_output_device_t *
 libvlc_audio_output_device_list_get( libvlc_instance_t *p_instance,
-                                     const char *aout );
+                                     const char *aout )
+{
+    (void) p_instance; (void) aout;
+    return NULL;
+}
+#endif
 
 /**
  * Frees a list of available audio output devices.
@@ -2280,25 +2269,9 @@ LIBVLC_API void libvlc_audio_output_device_list_release(
 /**
  * Configures an explicit audio output device.
  *
- * If the module parameter is NULL, audio output will be moved to the device
- * specified by the device identifier string immediately. This is the
- * recommended usage.
- *
  * A list of adequate potential device strings can be obtained with
  * libvlc_audio_output_device_enum().
  *
- * However passing NULL is supported in LibVLC version 2.2.0 and later only;
- * in earlier versions, this function would have no effects when the module
- * parameter was NULL.
- *
- * If the module parameter is not NULL, the device parameter of the
- * corresponding audio output, if it exists, will be set to the specified
- * string. Note that some audio output modules do not have such a parameter
- * (notably MMDevice and PulseAudio).
- *
- * A list of adequate potential device strings can be obtained with
- * libvlc_audio_output_device_list_get().
- *
  * \note This function does not select the specified audio output plugin..
  * libvlc_audio_output_set() is used for that purpose.
  *
@@ -2307,18 +2280,18 @@ LIBVLC_API void libvlc_audio_output_device_list_release(
  * Some audio output modules require further parameters (e.g. a channels map
  * in the case of ALSA).
  *
+ * \version This function originally expected three parameters.
+ * The middle parameter was removed from LibVLC 4.0 onward.
+  *
  * \param mp media player
- * \param module If NULL, current audio output module.
- *               if non-NULL, name of audio output module
-                 (see \ref libvlc_audio_output_t::psz_name)
  * \param device_id device identifier string
  *               (see \ref libvlc_audio_output_device_t::psz_device)
  *
- * \bug This function returns nothing. Errors are ignored (this is a
- * design bug).
+ * \return If the change of device was requested succesfully, zero is returned
+ * (the actual change is asynchronous and not guaranteed to succeed).
+ * On error, a non-zero value is returned.
  */
-LIBVLC_API void libvlc_audio_output_device_set( libvlc_media_player_t *mp,
-                                                const char *module,
+LIBVLC_API int libvlc_audio_output_device_set( libvlc_media_player_t *mp,
                                                 const char *device_id );
 
 /**
@@ -2329,8 +2302,8 @@ LIBVLC_API void libvlc_audio_output_device_set( libvlc_media_player_t *mp,
  * \warning The initial value for the current audio output device identifier
  * may not be set or may be some unknown value. A LibVLC application should
  * compare this value against the known device identifiers (e.g. those that
- * were previously retrieved by a call to libvlc_audio_output_device_enum or
- * libvlc_audio_output_device_list_get) to find the current audio output device.
+ * were previously retrieved by a call to libvlc_audio_output_device_enum) to
+ * find the current audio output device.
  *
  * It is possible that the selected audio output device changes (an external
  * change) without a call to libvlc_audio_output_device_set. That may make this


=====================================
lib/audio.c
=====================================
@@ -130,6 +130,7 @@ int libvlc_audio_output_set( libvlc_media_player_t *mp, const char *psz_name )
     var_SetString( mp, "aout", value );
     free( value );
 
+    vlc_player_aout_Reset(mp->player);
     return 0;
 }
 
@@ -171,40 +172,6 @@ err:
     return list;
 }
 
-libvlc_audio_output_device_t *
-libvlc_audio_output_device_list_get( libvlc_instance_t *p_instance,
-                                     const char *aout )
-{
-    char varname[32];
-    if( (size_t)snprintf( varname, sizeof(varname), "%s-audio-device", aout )
-                                                           >= sizeof(varname) )
-        return NULL;
-
-    if( config_GetType(varname) != VLC_VAR_STRING )
-        return NULL;
-
-    libvlc_audio_output_device_t *list = NULL, **pp = &list;
-    char **values, **texts;
-    ssize_t count = config_GetPszChoices( varname, &values, &texts );
-    for( ssize_t i = 0; i < count; i++ )
-    {
-        libvlc_audio_output_device_t *item = malloc( sizeof(*item) );
-        if( unlikely(item == NULL) )
-            break;
-
-        *pp = item;
-        pp = &item->p_next;
-        item->psz_device = values[i];
-        item->psz_description = texts[i];
-    }
-
-    *pp = NULL;
-    free( texts );
-    free( values );
-    (void) p_instance;
-    return list;
-}
-
 void libvlc_audio_output_device_list_release( libvlc_audio_output_device_t *l )
 {
     while( l != NULL )
@@ -221,33 +188,19 @@ void libvlc_audio_output_device_list_release( libvlc_audio_output_device_t *l )
 /*****************************
  * Set device for using
  *****************************/
-void libvlc_audio_output_device_set( libvlc_media_player_t *mp,
-                                     const char *module, const char *devid )
+int libvlc_audio_output_device_set( libvlc_media_player_t *mp,
+                                    const char *devid )
 {
     if( devid == NULL )
-        return;
-
-    if( module != NULL )
-    {
-        char *cfg_name;
-
-        if( asprintf( &cfg_name, "%s-audio-device", module ) == -1 )
-            return;
-
-        if( !var_Type( mp, cfg_name ) )
-            /* Don't recreate the same variable over and over and over... */
-            var_Create( mp, cfg_name, VLC_VAR_STRING );
-        var_SetString( mp, cfg_name, devid );
-        free( cfg_name );
-        return;
-    }
+        return -1;
 
     audio_output_t *aout = GetAOut( mp );
     if( aout == NULL )
-        return;
+        return -1;
 
-    aout_DeviceSet( aout, devid );
+    int ret = aout_DeviceSet( aout, devid );
     aout_Release(aout);
+    return ret;
 }
 
 char *libvlc_audio_output_device_get( libvlc_media_player_t *mp )


=====================================
lib/libvlc.sym
=====================================
@@ -16,7 +16,6 @@ libvlc_audio_equalizer_set_amp_at_index
 libvlc_audio_equalizer_set_preamp
 libvlc_audio_output_device_get
 libvlc_audio_output_device_enum
-libvlc_audio_output_device_list_get
 libvlc_audio_output_device_list_release
 libvlc_audio_output_device_set
 libvlc_audio_output_list_get


=====================================
test/libvlc/core.c
=====================================
@@ -77,21 +77,7 @@ static void test_audio_output (void)
 
     puts ("Audio outputs:");
     for (const libvlc_audio_output_t *o = mods; o != NULL; o = o->p_next)
-    {
-        libvlc_audio_output_device_t *devs;
-
         printf(" %s: %s\n", o->psz_name, o->psz_description);
-
-        devs = libvlc_audio_output_device_list_get (vlc, o->psz_name);
-        if (devs == NULL)
-            continue;
-        for (const libvlc_audio_output_device_t *d = devs;
-             d != NULL;
-             d = d->p_next)
-             printf("  %s: %s\n", d->psz_device, d->psz_description);
-
-        libvlc_audio_output_device_list_release (devs);
-    }
     libvlc_audio_output_list_release (mods);
     libvlc_release (vlc);
 }


=====================================
test/libvlc/media_player.c
=====================================
@@ -140,7 +140,7 @@ static void test_audio_video(libvlc_media_player_t *mp)
     libvlc_audio_output_device_t *aouts = libvlc_audio_output_device_enum(mp);
     for (libvlc_audio_output_device_t *e = aouts; e != NULL; e = e->p_next)
     {
-        libvlc_audio_output_device_set( mp, NULL, e->psz_device );
+        libvlc_audio_output_device_set( mp, e->psz_device );
     }
     libvlc_audio_output_device_list_release( aouts );
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ed4a5feb243a201b7890672f3d376b4586a16593...ce7cc9dd1ad98f41cd6b315e07c49eea2a991015

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ed4a5feb243a201b7890672f3d376b4586a16593...ce7cc9dd1ad98f41cd6b315e07c49eea2a991015
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list