[vlc-devel] [PATCH 2/2] test: media_player: test metadata listener API

Thomas Guillem thomas at gllm.fr
Mon Jan 18 16:32:15 UTC 2021


---
 test/libvlc/media_player.c | 64 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/test/libvlc/media_player.c b/test/libvlc/media_player.c
index 4906fb7bdd5..b34dd0d7ed5 100644
--- a/test/libvlc/media_player.c
+++ b/test/libvlc/media_player.c
@@ -22,6 +22,7 @@
 
 #include "test.h"
 #include <vlc_common.h>
+#include <vlc_modules.h>
 
 struct event_ctx
 {
@@ -665,6 +666,68 @@ static void test_media_player_programs(const char** argv, int argc)
     libvlc_release (vlc);
 }
 
+static void
+on_loudness_changed(libvlc_time_t date,
+                    const struct libvlc_audio_loudness *loudness,
+                    void *data)
+{
+    vlc_sem_t *wait = data;
+
+    int64_t delay = libvlc_delay(date);
+    assert(delay > 0 && delay <= 5000000LL);
+    assert(loudness->loudness_momentary < 0);
+    assert(loudness->loudness_shortterm < 0);
+    assert(loudness->loudness_integrated < 0);
+    assert(loudness->loudness_range == 0);
+    assert(loudness->truepeak > 0);
+    vlc_sem_post(wait);
+};
+
+static void test_media_player_metadata_listener(const char** argv, int argc)
+{
+    static const char file[] = "mock://audio_track_count=1";
+
+    /* Load the mock media */
+    libvlc_instance_t *vlc = libvlc_new (argc, argv);
+    assert (vlc != NULL);
+
+    if (!module_exists("ebur128"))
+    {
+        test_log("media_player metadata listener skipped\n");
+        libvlc_release (vlc);
+        return;
+    }
+
+    libvlc_media_t *md = libvlc_media_new_location (vlc, file);
+    assert (md != NULL);
+    libvlc_media_player_t *mp = libvlc_media_player_new (vlc);
+    assert (mp != NULL);
+    libvlc_media_player_set_media (mp, md);
+    libvlc_media_release (md);
+
+    const union libvlc_media_player_metadata_cbs cbs = {
+        .on_loudness_changed = on_loudness_changed,
+    };
+
+    vlc_sem_t wait;
+    vlc_sem_init(&wait, 0);
+
+    libvlc_media_player_metadata_listener_id *id =
+        libvlc_media_player_add_metadata_listener(mp,
+                LIBVLC_MEDIA_PLAYER_METADATA_LOUDNESS_FULL, &cbs, &wait);
+
+    assert(id != NULL);
+
+    libvlc_media_player_play (mp);
+
+    vlc_sem_wait(&wait);
+
+    libvlc_media_player_remove_metadata_listener(mp, id);
+
+    libvlc_media_player_release (mp);
+    libvlc_release (vlc);
+}
+
 /* Regression test when having multiple libvlc instances */
 static void test_media_player_multiple_instance(const char** argv, int argc)
 {
@@ -703,6 +766,7 @@ int main (void)
     test_media_player_tracks (test_defaults_args, test_defaults_nargs);
     test_media_player_programs (test_defaults_args, test_defaults_nargs);
     test_media_player_multiple_instance (test_defaults_args, test_defaults_nargs);
+    test_media_player_metadata_listener (test_defaults_args, test_defaults_nargs);
 
     return 0;
 }
-- 
2.29.2



More information about the vlc-devel mailing list