<html><head></head><body>since there is anyway a ToCToU situation now, I don't see the point of the helper, and even less of the unlocked function.<br><br><div class="gmail_quote">Le 28 novembre 2018 16:47:22 GMT+02:00, Victorien Le Couviour--Tuffet <victorien.lecouviour.tuffet@gmail.com> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail"><hr> include/vlc_aout.h        |  1 +<br> src/audio_output/output.c | 94 ++++++++++++++++++++++++++++++++-------<br> src/libvlccore.sym        |  1 +<br> 3 files changed, 81 insertions(+), 15 deletions(-)<br><br>diff --git a/include/vlc_aout.h b/include/vlc_aout.h<br>index aa49884001..ef78127c13 100644<br>--- a/include/vlc_aout.h<br>+++ b/include/vlc_aout.h<br>@@ -373,6 +373,7 @@ VLC_API int aout_MuteGet (audio_output_t *);<br> VLC_API int aout_MuteSet (audio_output_t *, bool);<br> VLC_API char *aout_DeviceGet (audio_output_t *);<br> VLC_API int aout_DeviceSet (audio_output_t *, const char *);<br>+VLC_API int aout_DeviceNext (audio_output_t *, char **);<br> VLC_API int aout_DevicesList (audio_output_t *, char ***, char ***);<br> <br> /**<br>diff --git a/src/audio_output/output.c b/src/audio_output/output.c<br>index 019797c5ef..ef643260b0 100644<br>--- a/src/audio_output/output.c<br>+++ b/src/audio_output/output.c<br>@@ -701,24 +701,15 @@ int aout_DeviceSet (audio_output_t *aout, const char *id)<br>     return ret ? -1 : 0;<br> }<br> <br>-/**<br>- * Enumerates possible audio output devices.<br>- *<br>- * The function will heap-allocate two tables of heap-allocated strings;<br>- * the caller is responsible for freeing all strings and both tables.<br>- *<br>- * \param ids pointer to a table of device identifiers [OUT]<br>- * \param names pointer to a table of device human-readable descriptions [OUT]<br>- * \return the number of devices, or negative on error.<br>- * \note In case of error, *ids and *names are undefined.<br>- */<br>-int aout_DevicesList (audio_output_t *aout, char ***ids, char ***names)<br>+static int aout_DevicesListLocked(audio_output_t *aout,<br>+                                  char ***ids, char ***names)<br> {<br>     aout_owner_t *owner = aout_owner (aout);<br>+    vlc_mutex_assert(&owner->lock);<br>+    vlc_mutex_assert(&owner->dev.lock);<br>     char **tabid, **tabname;<br>     unsigned i = 0;<br> <br>-    vlc_mutex_lock (&owner->dev.lock);<br>     tabid = vlc_alloc (owner->dev.count, sizeof (*tabid));<br>     tabname = vlc_alloc (owner->dev.count, sizeof (*tabname));<br> <br>@@ -743,12 +734,10 @@ int aout_DevicesList (audio_output_t *aout, char ***ids, char ***names)<br> <br>         i++;<br>     }<br>-    vlc_mutex_unlock (&owner->dev.lock);<br> <br>     return i;<br> <br> error:<br>-    vlc_mutex_unlock(&owner->dev.lock);<br>     while (i > 0)<br>     {<br>         i--;<br>@@ -760,6 +749,81 @@ error:<br>     return -1;<br> }<br> <br>+/**<br>+ * Enumerates possible audio output devices.<br>+ *<br>+ * The function will heap-allocate two tables of heap-allocated strings;<br>+ * the caller is responsible for freeing all strings and both tables.<br>+ *<br>+ * \param ids pointer to a table of device identifiers [OUT]<br>+ * \param names pointer to a table of device human-readable descriptions [OUT]<br>+ * \return the number of devices, or negative on error.<br>+ * \note In case of error, *ids and *names are undefined.<br>+ */<br>+int aout_DevicesList (audio_output_t *aout, char ***ids, char ***names)<br>+{<br>+    aout_OutputLock(aout);<br>+    vlc_mutex_t *lock = &aout_owner(aout)->dev.lock;<br>+    vlc_mutex_lock(lock);<br>+    int ret = aout_DevicesListLocked(aout, ids, names);<br>+    vlc_mutex_unlock(lock);<br>+    aout_OutputUnlock(aout);<br>+    return ret;<br>+}<br>+<br>+/**<br>+ * Cycle through audio output devices.<br>+ * \param p_name pointer to the selected device human-readable description [OUT]<br>+ * \return zero on success, non-zero on error.<br>+ */<br>+int aout_DeviceNext (audio_output_t *aout, char **p_name)<br>+{<br>+    int ret = -1;<br>+    aout_owner_t *owner = aout_owner(aout);<br>+    aout_OutputLock(aout);<br>+    vlc_mutex_lock(&owner->dev.lock);<br>+    bool locked = true;<br>+<br>+    char **ids, **names;<br>+    int n = aout_DevicesListLocked(aout, &ids, &names);<br>+    if (n == -1)<br>+        goto end;<br>+    char *device = aout_DeviceGet(aout);<br>+    if (!device)<br>+        goto no_dev;<br>+<br>+    int index;<br>+    for (index = 0; index < n; ++index)<br>+        if (!strcmp(ids[index], device))<br>+        {<br>+            index = (index + 1) % n;<br>+            break;<br>+        }<br>+    vlc_mutex_unlock(&owner->dev.lock);<br>+    aout_OutputUnlock(aout);<br>+    locked = false;<br>+    ret = aout_DeviceSet(aout, ids[index]);<br>+    if (p_name != NULL)<br>+        *p_name = strdup(names[index]);<br>+<br>+    free(device);<br>+no_dev:<br>+    for (int i = 0; i < n; ++i)<br>+    {<br>+        free(ids[i]);<br>+        free(names[i]);<br>+    }<br>+    free(ids);<br>+    free(names);<br>+end:<br>+    if (locked)<br>+    {<br>+        vlc_mutex_unlock(&owner->dev.lock);<br>+        aout_OutputUnlock(aout);<br>+    }<br>+    return ret;<br>+}<br>+<br> static void aout_ChangeViewpoint(audio_output_t *aout,<br>                                  const vlc_viewpoint_t *p_viewpoint)<br> {<br>diff --git a/src/libvlccore.sym b/src/libvlccore.sym<br>index d4db4ccc51..41af4b48db 100644<br>--- a/src/libvlccore.sym<br>+++ b/src/libvlccore.sym<br>@@ -20,6 +20,7 @@ aout_MuteSet<br> aout_MuteGet<br> aout_DeviceGet<br> aout_DeviceSet<br>+aout_DeviceNext<br> aout_DevicesList<br> aout_FiltersNew<br> aout_FiltersChangeViewpoint</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>