<html><head></head><body>Hi,<br><br>This looks way overkill. Presumably the app would add and remove the callback(s) with the meter, rather than separately.<br><br><div class="gmail_quote">Le 14 août 2020 15:18:04 GMT+02:00, Thomas Guillem <thomas@gllm.fr> 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_player.h |  76 +++++++++++++++++++++++++++++++<br> src/libvlccore.sym   |   2 +<br> src/player/aout.c    | 103 +++++++++++++++++++++++++++++++++++++++++++<br> src/player/player.c  |   3 ++<br> src/player/player.h  |   9 ++++<br> 5 files changed, 193 insertions(+)<br><br>diff --git a/include/vlc_player.h b/include/vlc_player.h<br>index ac5991982df..ad4d39536d4 100644<br>--- a/include/vlc_player.h<br>+++ b/include/vlc_player.h<br>@@ -2199,6 +2199,50 @@ struct vlc_player_aout_cbs<br>         void *data);<br> };<br> <br>+/**<br>+ * Player aout loudness meter opaque structure.<br>+ *<br>+ * This opaque structure is returned by vlc_player_aout_AddLoudnessMeter() and<br>+ * can be used to remove the listener via<br>+ * vlc_player_aout_RemoveLoudnessMeter().<br>+ */<br>+typedef struct vlc_player_aout_loudness_meter_id vlc_player_aout_loudness_meter_id;<br>+<br>+/**<br>+ * Loudness meter mode<br>+ */<br>+enum vlc_player_aout_loudness_meter_mode<br>+{<br>+    /** Very low CPU usage, only the Momentary Loudness will be processed */<br>+    VLC_PLAYER_AOUT_LOUDNESS_METER_BEST_PERFS,<br>+    /** High CPU usage, Momentary Loudness, Short Term Loudness Integrated<br>+     * Loudness, Loudness Range and True Peak will be processed. */<br>+    VLC_PLAYER_AOUT_LOUDNESS_METER_FULL,<br>+};<br>+<br>+/**<br>+ * Player aout loudness meter callbacks<br>+ *<br>+ * Can be registered with vlc_player_aout_AddLoudnessMeter().<br>+ */<br>+struct vlc_player_aout_loudness_cbs<br>+{<br>+<br>+    /**<br>+     * Called when loudness measurements have changed<br>+     *<br>+     * Only sent when audio is playing, approximately every 400ms (but can be<br>+     * higher, depending on the input sample size).<br>+     *<br>+     * @param aout the main aout of the player<br>+     * @param meter last loudness measurements<br>+     * @param data opaque pointer set by vlc_player_aout_AddLoudnessMeter()<br>+     */<br>+    void (*on_loudness_changed)(audio_output_t *aout,<br>+                                const struct vlc_audio_loudness_meter *meter,<br>+                                void *data);<br>+};<br>+<br> /**<br>  * Get the audio output<br>  *<br>@@ -2353,6 +2397,38 @@ vlc_player_aout_ToggleMute(vlc_player_t *player)<br> VLC_API int<br> vlc_player_aout_EnableFilter(vlc_player_t *player, const char *name, bool add);<br> <br>+<br>+/**<br>+ * Add an aout loudness meter<br>+ *<br>+ * @note The player instance doesn't need to be locked for vlc_player_aout_*()<br>+ * functions.<br>+ * @note Every registered loudness meter need to be removed by the caller with<br>+ * vlc_player_aout_RemoveLoudnessMeter().<br>+ *<br>+ * @param player player instance<br>+ * @param cbs pointer to a vlc_player_aout_loudness_cbs structure, the<br>+ * structure must be valid during the lifetime of the player<br>+ * @param cbs_data opaque pointer used by the callbacks<br>+ * @return a valid meter id, or NULL in case of error ("audio-meter" plugin<br>+ * missing)<br>+ */<br>+VLC_API vlc_player_aout_loudness_meter_id *<br>+vlc_player_aout_AddLoudnessMeter(vlc_player_t *player,<br>+                                 enum vlc_player_aout_loudness_meter_mode,<br>+                                 const struct vlc_player_aout_loudness_cbs *cbs,<br>+                                 void *cbs_data);<br>+<br>+/**<br>+ * Remove an aout loudness meter<br>+ *<br>+ * @param player player instance<br>+ * @param meter_id meter id returned by vlc_player_aout_AddLoudnessMeter()<br>+ */<br>+VLC_API void<br>+vlc_player_aout_RemoveLoudnessMeter(vlc_player_t *player,<br>+                                    vlc_player_aout_loudness_meter_id *meter_id);<br>+<br> /** @} vlc_player__aout */<br> <br> /**<br>diff --git a/src/libvlccore.sym b/src/libvlccore.sym<br>index ed43c17715c..cf1916fd92c 100644<br>--- a/src/libvlccore.sym<br>+++ b/src/libvlccore.sym<br>@@ -774,6 +774,7 @@ vlc_player_AddListener<br> vlc_player_AddSmpteTimer<br> vlc_player_AddTimer<br> vlc_player_aout_AddListener<br>+vlc_player_aout_AddLoudnessMeter<br> vlc_player_aout_EnableFilter<br> vlc_player_aout_GetVolume<br> vlc_player_aout_Hold<br>@@ -782,6 +783,7 @@ vlc_player_aout_IncrementVolume<br> vlc_player_aout_IsMuted<br> vlc_player_aout_Mute<br> vlc_player_aout_RemoveListener<br>+vlc_player_aout_RemoveLoudnessMeter<br> vlc_player_aout_SetVolume<br> vlc_player_ChangeRate<br> vlc_player_CondWait<br>diff --git a/src/player/aout.c b/src/player/aout.c<br>index 8674cc65359..f962b53329b 100644<br>--- a/src/player/aout.c<br>+++ b/src/player/aout.c<br>@@ -26,6 +26,7 @@<br> <br> #include <vlc_common.h><br> #include <vlc_decoder.h><br>+#include <vlc_modules.h><br> #include "player.h"<br> #include "input/resource.h"<br> <br>@@ -46,6 +47,106 @@ vlc_player_aout_Hold(vlc_player_t *player)<br>     return input_resource_HoldAout(player->resource);<br> }<br> <br>+VLC_API vlc_player_aout_loudness_meter_id *<br>+vlc_player_aout_AddLoudnessMeter(vlc_player_t *player,<br>+                                 enum vlc_player_aout_loudness_meter_mode mode,<br>+                                 const struct vlc_player_aout_loudness_cbs *cbs,<br>+                                 void *cbs_data)<br>+{<br>+    assert(cbs && cbs->on_loudness_changed);<br>+<br>+    if (!module_exists("ebur128"))<br>+        return NULL;<br>+<br>+    vlc_player_aout_loudness_meter_id *meter_id = malloc(sizeof(*meter_id));<br>+    if (meter_id == NULL)<br>+        return NULL;<br>+<br>+    meter_id->cbs = cbs;<br>+    meter_id->cbs_data = cbs_data;<br>+    meter_id->mode = mode;<br>+<br>+    vlc_mutex_lock(&player->aout_listeners_lock);<br>+<br>+    bool has_meter_module = !vlc_list_is_empty(&player->aout_loudness_meters);<br>+<br>+    enum vlc_player_aout_loudness_meter_mode prev_mode =<br>+        VLC_PLAYER_AOUT_LOUDNESS_METER_BEST_PERFS;<br>+    if (has_meter_module)<br>+    {<br>+        vlc_player_aout_loudness_meter_id *other_meter_id;<br>+        vlc_list_foreach(other_meter_id, &player->aout_loudness_meters, node)<br>+        {<br>+            if (other_meter_id->mode > prev_mode)<br>+                prev_mode = other_meter_id->mode;<br>+        }<br>+    }<br>+<br>+    vlc_list_append(&meter_id->node, &player->aout_loudness_meters);<br>+<br>+    vlc_mutex_unlock(&player->aout_listeners_lock);<br>+<br>+    if (!has_meter_module || mode > prev_mode)<br>+    {<br>+        audio_output_t *aout = vlc_player_aout_Hold(player);<br>+        if (aout != NULL)<br>+        {<br>+            var_SetBool(player, "ebur128-fullmeter",<br>+                        mode == VLC_PLAYER_AOUT_LOUDNESS_METER_FULL);<br>+            var_SetString(aout, "audio-meter", "ebur128");<br>+            aout_Release(aout);<br>+        }<br>+    }<br>+<br>+    return meter_id;<br>+}<br>+<br>+void<br>+vlc_player_aout_RemoveLoudnessMeter(vlc_player_t *player,<br>+                                    vlc_player_aout_loudness_meter_id *meter_id)<br>+{<br>+    assert(meter_id);<br>+<br>+    vlc_mutex_lock(&player->aout_listeners_lock);<br>+    vlc_list_remove(&meter_id->node);<br>+<br>+    bool has_meter_module = !vlc_list_is_empty(&player->aout_loudness_meters);<br>+<br>+    vlc_mutex_unlock(&player->aout_listeners_lock);<br>+    free(meter_id);<br>+<br>+    if (!has_meter_module)<br>+    {<br>+        audio_output_t *aout = vlc_player_aout_Hold(player);<br>+        if (aout != NULL)<br>+        {<br>+            var_SetString(aout, "audio-meter", NULL);<br>+            aout_Release(aout);<br>+        }<br>+    }<br>+}<br>+<br>+static int<br>+vlc_player_AoutLoudnessCallback(vlc_object_t *this, const char *var,<br>+                                vlc_value_t oldval, vlc_value_t newval, void *data)<br>+{<br>+    vlc_player_t *player = data;<br>+<br>+    struct vlc_audio_loudness_meter *meter = newval.p_address;<br>+<br>+    vlc_mutex_lock(&player->aout_listeners_lock);<br>+    vlc_player_aout_loudness_meter_id *meter_id;<br>+    vlc_list_foreach(meter_id, &player->aout_loudness_meters, node)<br>+    {<br>+        meter_id->cbs->on_loudness_changed((audio_output_t *)this,<br>+                                            meter, meter_id->cbs_data);<br>+    }<br>+    vlc_mutex_unlock(&player->aout_listeners_lock);<br>+<br>+    (void) var; (void) oldval;<br>+    return VLC_SUCCESS;<br>+}<br>+<br> vlc_player_aout_listener_id *<br> vlc_player_aout_AddListener(vlc_player_t *player,<br>                             const struct vlc_player_aout_cbs *cbs,<br>@@ -202,6 +303,7 @@ vlc_player_aout_AddCallbacks(vlc_player_t *player)<br>     var_AddCallback(aout, "volume", vlc_player_AoutCallback, player);<br>     var_AddCallback(aout, "mute", vlc_player_AoutCallback, player);<br>     var_AddCallback(aout, "device", vlc_player_AoutCallback, player);<br>+    var_AddCallback(aout, "loudness-meter", vlc_player_AoutLoudnessCallback, player);<br> <br>     aout_Release(aout);<br> }<br>@@ -216,6 +318,7 @@ vlc_player_aout_DelCallbacks(vlc_player_t *player)<br>     var_DelCallback(aout, "volume", vlc_player_AoutCallback, player);<br>     var_DelCallback(aout, "mute", vlc_player_AoutCallback, player);<br>     var_DelCallback(aout, "device", vlc_player_AoutCallback, player);<br>+    var_DelCallback(aout, "loudness-meter", vlc_player_AoutLoudnessCallback, player);<br> <br>     aout_Release(aout);<br> }<br>diff --git a/src/player/player.c b/src/player/player.c<br>index fd072e414b5..e74c29e6d9c 100644<br>--- a/src/player/player.c<br>+++ b/src/player/player.c<br>@@ -1893,6 +1893,7 @@ vlc_player_Delete(vlc_player_t *player)<br>     assert(vlc_list_is_empty(&player->listeners));<br>     assert(vlc_list_is_empty(&player->vout_listeners));<br>     assert(vlc_list_is_empty(&player->aout_listeners));<br>+    assert(vlc_list_is_empty(&player->aout_loudness_meters));<br> <br>     vlc_mutex_unlock(&player->lock);<br> <br>@@ -1934,6 +1935,7 @@ vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,<br>     vlc_list_init(&player->listeners);<br>     vlc_list_init(&player->vout_listeners);<br>     vlc_list_init(&player->aout_listeners);<br>+    vlc_list_init(&player->aout_loudness_meters);<br>     vlc_list_init(&player->destructor.inputs);<br>     vlc_list_init(&player->destructor.stopping_inputs);<br>     vlc_list_init(&player->destructor.joinable_inputs);<br>@@ -1973,6 +1975,7 @@ vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,<br>     VAR_CREATE("audio-filter", VLC_VAR_STRING | VLC_VAR_DOINHERIT);<br>     VAR_CREATE("mute", VLC_VAR_BOOL);<br>     VAR_CREATE("corks", VLC_VAR_INTEGER);<br>+    VAR_CREATE("ebur128-fullmeter", VLC_VAR_BOOL);<br> <br>     /* es_out variables */<br>     VAR_CREATE("sout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);<br>diff --git a/src/player/player.h b/src/player/player.h<br>index 87b9e430330..e4fafbab087 100644<br>--- a/src/player/player.h<br>+++ b/src/player/player.h<br>@@ -140,6 +140,14 @@ struct vlc_player_aout_listener_id<br>     struct vlc_list node;<br> };<br> <br>+struct vlc_player_aout_loudness_meter_id<br>+{<br>+    const struct vlc_player_aout_loudness_cbs *cbs;<br>+    void *cbs_data;<br>+    enum vlc_player_aout_loudness_meter_mode mode;<br>+    struct vlc_list node;<br>+};<br>+<br> enum vlc_player_timer_source_type<br> {<br>     VLC_PLAYER_TIMER_TYPE_BEST,<br>@@ -224,6 +232,7 @@ struct vlc_player_t<br> <br>     struct vlc_list listeners;<br>     struct vlc_list aout_listeners;<br>+    struct vlc_list aout_loudness_meters;<br>     struct vlc_list vout_listeners;<br> <br>     input_resource_t *resource;</pre></blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>