[vlc-devel] [RFC PATCH 7/7] player: test loudness_meter API

Thomas Guillem thomas at gllm.fr
Fri Aug 14 15:18:07 CEST 2020


---
 test/src/player/player.c | 58 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/test/src/player/player.c b/test/src/player/player.c
index 0870e5ef620..b4f8b83da08 100644
--- a/test/src/player/player.c
+++ b/test/src/player/player.c
@@ -26,6 +26,7 @@
 #include <vlc_common.h>
 #include <vlc_player.h>
 #include <vlc_vector.h>
+#include <vlc_modules.h>
 
 #if defined(ZVBI_COMPILED)
 # define TELETEXT_DECODER "zvbi,"
@@ -2734,6 +2735,62 @@ test_teletext(struct ctx *ctx)
 #endif
 }
 
+static void
+test_audio_loudness_meter_cb(audio_output_t *aout,
+                             const struct vlc_audio_loudness_meter *meter,
+                             void *data)
+{
+    (void) aout;
+    assert(meter->loudness_momentary >= -23 -0.1 && meter->loudness_momentary <= -23 +0.1);
+
+    bool *loudness_meter_received = data;
+    *loudness_meter_received = true;
+}
+
+static void
+test_audio_loudness_meter(struct ctx *ctx)
+{
+    vlc_player_t *player = ctx->player;
+
+    static const struct vlc_player_aout_loudness_cbs cbs = {
+        test_audio_loudness_meter_cb,
+    };
+
+    if (!module_exists("ebur128"))
+    {
+        assert(vlc_player_aout_AddLoudnessMeter(player,
+            VLC_PLAYER_AOUT_LOUDNESS_METER_BEST_PERFS, &cbs, NULL) == NULL);
+        test_log("audio loudness meter test skipped\n");
+        return;
+    }
+
+    struct media_params params = DEFAULT_MEDIA_PARAMS(VLC_TICK_FROM_SEC(1));
+    params.track_count[AUDIO_ES] = 1;
+    params.track_count[VIDEO_ES] = 0;
+    params.track_count[SPU_ES] = 0;
+
+    /* cf. EBU TECH 3341, Table 1. A 1000Hz stereo sine wave, with an amplitude
+     * of -23dbFS (0.0707) should have a momentary loudness of -23LUFS */
+    params.config = "audio[0]{sinewave=true,sinewave_frequency=1000"
+                    ",sinewave_amplitude=0.0707}";
+    player_set_next_mock_media(ctx, "media1", &params);
+
+    bool loudness_meter_received = false;
+    vlc_player_aout_loudness_meter_id *meter_id =
+        vlc_player_aout_AddLoudnessMeter(player, VLC_PLAYER_AOUT_LOUDNESS_METER_BEST_PERFS,
+                                         &cbs, &loudness_meter_received);
+    assert(meter_id);
+
+    player_start(ctx);
+    wait_state(ctx, VLC_PLAYER_STATE_STARTED);
+    wait_state(ctx, VLC_PLAYER_STATE_STOPPED);
+
+    assert(loudness_meter_received);
+
+    vlc_player_aout_RemoveLoudnessMeter(player, meter_id);
+    test_end(ctx);
+}
+
 static void
 test_es_selection_override(struct ctx *ctx)
 {
@@ -2824,6 +2881,7 @@ main(void)
     test_programs(&ctx);
     test_timers(&ctx);
     test_teletext(&ctx);
+    test_audio_loudness_meter(&ctx);
 
     test_delete_while_playback(VLC_OBJECT(ctx.vlc->p_libvlc_int), true);
     test_delete_while_playback(VLC_OBJECT(ctx.vlc->p_libvlc_int), false);
-- 
2.28.0



More information about the vlc-devel mailing list