[vlc-commits] [Git][videolan/vlc][master] 2 commits: test: move event helpers to test.h

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Jun 9 16:07:29 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
14d99102 by Alexandre Janniaux at 2023-06-09T17:28:00+02:00
test: move event helpers to test.h

Those helpers are generic and can be used by any test code for libvlc.
Make them inline since test size doesn't really matter and they are
pretty simple.

- - - - -
3ecfdc5d by Alexandre Janniaux at 2023-06-09T17:28:00+02:00
test: media_player: check that record event is signalled

Also check that the path given is correctly used. The test is only
checking the es_out recording, since mock:// doesn't initialize the
recording when can_record=1 is used.

- - - - -


4 changed files:

- test/Makefile.am
- test/libvlc/media_player.c
- + test/libvlc/media_player_record.c
- test/libvlc/test.h


Changes:

=====================================
test/Makefile.am
=====================================
@@ -19,6 +19,7 @@ check_PROGRAMS = \
 	test_libvlc_media \
 	test_libvlc_media_list \
 	test_libvlc_media_player \
+	test_libvlc_media_player_record \
 	test_libvlc_media_discoverer \
 	test_libvlc_renderer_discoverer \
 	test_libvlc_slaves \
@@ -109,6 +110,8 @@ test_libvlc_media_list_SOURCES = libvlc/media_list.c
 test_libvlc_media_list_LDADD = $(LIBVLC)
 test_libvlc_media_player_SOURCES = libvlc/media_player.c
 test_libvlc_media_player_LDADD = $(LIBVLCCORE) $(LIBVLC)
+test_libvlc_media_player_record_SOURCES = libvlc/media_player_record.c
+test_libvlc_media_player_record_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_libvlc_media_discoverer_SOURCES = libvlc/media_discoverer.c
 test_libvlc_media_discoverer_LDADD = $(LIBVLC)
 test_libvlc_renderer_discoverer_SOURCES = libvlc/renderer_discoverer.c


=====================================
test/libvlc/media_player.c
=====================================
@@ -23,54 +23,6 @@
 #include "test.h"
 #include <vlc_common.h>
 
-struct event_ctx
-{
-    vlc_sem_t sem_ev;
-    vlc_sem_t sem_done;
-    const struct libvlc_event_t *ev;
-};
-
-static void event_ctx_init(struct event_ctx *ctx)
-{
-    vlc_sem_init(&ctx->sem_ev, 0);
-    vlc_sem_init(&ctx->sem_done, 0);
-    ctx->ev = NULL;
-}
-
-static const struct libvlc_event_t *event_ctx_wait_event(struct event_ctx *ctx)
-{
-    vlc_sem_wait(&ctx->sem_ev);
-    assert(ctx->ev != NULL);
-    return ctx->ev;
-}
-
-static void event_ctx_release(struct event_ctx *ctx)
-{
-    assert(ctx->ev != NULL);
-    ctx->ev = NULL;
-    vlc_sem_post(&ctx->sem_done);
-}
-
-static void event_ctx_wait(struct event_ctx *ctx)
-{
-    event_ctx_wait_event(ctx);
-    event_ctx_release(ctx);
-}
-
-static void on_event(const struct libvlc_event_t *event, void *data)
-{
-    struct event_ctx *ctx = data;
-
-    assert(ctx->ev == NULL);
-    ctx->ev = event;
-
-    vlc_sem_post(&ctx->sem_ev);
-
-    vlc_sem_wait(&ctx->sem_done);
-
-    assert(ctx->ev == NULL);
-}
-
 static void play_and_wait(libvlc_media_player_t *mp)
 {
     libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
@@ -79,7 +31,7 @@ static void play_and_wait(libvlc_media_player_t *mp)
     event_ctx_init(&ctx);
 
     int res;
-    res = libvlc_event_attach(em, libvlc_MediaPlayerPlaying, on_event, &ctx);
+    res = libvlc_event_attach(em, libvlc_MediaPlayerPlaying, event_ctx_on_event, &ctx);
     assert(!res);
 
     libvlc_media_player_play(mp);
@@ -87,7 +39,7 @@ static void play_and_wait(libvlc_media_player_t *mp)
     test_log("Waiting for playing\n");
     event_ctx_wait(&ctx);
 
-    libvlc_event_detach(em, libvlc_MediaPlayerPlaying, on_event, &ctx);
+    libvlc_event_detach(em, libvlc_MediaPlayerPlaying, event_ctx_on_event, &ctx);
 }
 
 static void pause_and_wait(libvlc_media_player_t *mp)
@@ -98,7 +50,7 @@ static void pause_and_wait(libvlc_media_player_t *mp)
     event_ctx_init(&ctx);
 
     int res;
-    res = libvlc_event_attach(em, libvlc_MediaPlayerPaused, on_event, &ctx);
+    res = libvlc_event_attach(em, libvlc_MediaPlayerPaused, event_ctx_on_event, &ctx);
     assert(!res);
 
     assert(libvlc_media_player_get_state(mp) == libvlc_Playing);
@@ -110,7 +62,7 @@ static void pause_and_wait(libvlc_media_player_t *mp)
 
     assert(libvlc_media_player_get_state(mp) == libvlc_Paused);
 
-    libvlc_event_detach(em, libvlc_MediaPlayerPaused, on_event, &ctx);
+    libvlc_event_detach(em, libvlc_MediaPlayerPaused, event_ctx_on_event, &ctx);
 }
 
 /* Test a bunch of A/V properties. This most does nothing since the current
@@ -364,11 +316,11 @@ static void test_media_player_tracks(const char** argv, int argc)
     event_ctx_init(&ctx);
 
     int res;
-    res = libvlc_event_attach(em, libvlc_MediaPlayerESAdded, on_event, &ctx);
+    res = libvlc_event_attach(em, libvlc_MediaPlayerESAdded, event_ctx_on_event, &ctx);
     assert(!res);
-    res = libvlc_event_attach(em, libvlc_MediaPlayerESDeleted, on_event, &ctx);
+    res = libvlc_event_attach(em, libvlc_MediaPlayerESDeleted, event_ctx_on_event, &ctx);
     assert(!res);
-    res = libvlc_event_attach(em, libvlc_MediaPlayerESSelected, on_event, &ctx);
+    res = libvlc_event_attach(em, libvlc_MediaPlayerESSelected, event_ctx_on_event, &ctx);
     assert(!res);
 
     libvlc_media_player_play (mp);
@@ -538,9 +490,9 @@ static void test_media_player_tracks(const char** argv, int argc)
         event_ctx_release(&ctx);
     }
 
-    libvlc_event_detach(em, libvlc_MediaPlayerESAdded, on_event, &ctx);
-    libvlc_event_detach(em, libvlc_MediaPlayerESDeleted, on_event, &ctx);
-    libvlc_event_detach(em, libvlc_MediaPlayerESSelected, on_event, &ctx);
+    libvlc_event_detach(em, libvlc_MediaPlayerESAdded, event_ctx_on_event, &ctx);
+    libvlc_event_detach(em, libvlc_MediaPlayerESDeleted, event_ctx_on_event, &ctx);
+    libvlc_event_detach(em, libvlc_MediaPlayerESSelected, event_ctx_on_event, &ctx);
 
     libvlc_media_player_release (mp);
     libvlc_release (vlc);
@@ -575,11 +527,11 @@ static void test_media_player_programs(const char** argv, int argc)
     event_ctx_init(&ctx);
 
     int res;
-    res = libvlc_event_attach(em, libvlc_MediaPlayerProgramAdded, on_event, &ctx);
+    res = libvlc_event_attach(em, libvlc_MediaPlayerProgramAdded, event_ctx_on_event, &ctx);
     assert(!res);
-    res = libvlc_event_attach(em, libvlc_MediaPlayerProgramDeleted, on_event, &ctx);
+    res = libvlc_event_attach(em, libvlc_MediaPlayerProgramDeleted, event_ctx_on_event, &ctx);
     assert(!res);
-    res = libvlc_event_attach(em, libvlc_MediaPlayerProgramSelected, on_event, &ctx);
+    res = libvlc_event_attach(em, libvlc_MediaPlayerProgramSelected, event_ctx_on_event, &ctx);
     assert(!res);
 
     libvlc_media_player_select_program_id(mp, 2);
@@ -670,9 +622,9 @@ static void test_media_player_programs(const char** argv, int argc)
         event_ctx_release(&ctx);
     }
 
-    libvlc_event_detach(em, libvlc_MediaPlayerProgramAdded, on_event, &ctx);
-    libvlc_event_detach(em, libvlc_MediaPlayerProgramDeleted, on_event, &ctx);
-    libvlc_event_detach(em, libvlc_MediaPlayerProgramSelected, on_event, &ctx);
+    libvlc_event_detach(em, libvlc_MediaPlayerProgramAdded, event_ctx_on_event, &ctx);
+    libvlc_event_detach(em, libvlc_MediaPlayerProgramDeleted, event_ctx_on_event, &ctx);
+    libvlc_event_detach(em, libvlc_MediaPlayerProgramSelected, event_ctx_on_event, &ctx);
 
     libvlc_media_player_release (mp);
     libvlc_release (vlc);


=====================================
test/libvlc/media_player_record.c
=====================================
@@ -0,0 +1,93 @@
+/*****************************************************************************
+ * media_player_record.c - libvlc record test with ENABLE_SOUT
+ **********************************************************************
+ * Copyright (C) 2023 Videolabs
+ *
+ * Authors: Alexandre Janniaux <ajanni at videolabs.io>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "test.h"
+#include <vlc_common.h>
+
+static void test_media_player_record(const char** argv, int argc)
+{
+    test_log ("Testing record\n");
+
+    const char file[] = "mock://video_track_count=1;audio_track_count=1;can_record=0";
+
+    /* Avoid leaks from various dlopen... */
+    const char *new_argv[argc+1];
+    for (int i = 0; i < argc; ++i)
+        new_argv[i] = argv[i];
+    new_argv[argc++] = "--codec=araw,rawvideo,subsdec,none";
+
+    /* Load the mock media */
+    libvlc_instance_t *vlc = libvlc_new (argc, new_argv);
+    assert (vlc != NULL);
+    libvlc_media_t *md = libvlc_media_new_location(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);
+
+    libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
+    struct event_ctx ctx;
+    event_ctx_init(&ctx);
+
+    int res;
+    res = libvlc_event_attach(em, libvlc_MediaPlayerRecordChanged, event_ctx_on_event, &ctx);
+    assert(!res);
+
+    libvlc_media_player_play (mp);
+
+    const char path[] = "./";
+
+    libvlc_media_player_record(mp, true, path);
+
+    /* Enabling */
+    {
+        const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+        assert(ev->u.media_player_record_changed.recording);
+        event_ctx_release(&ctx);
+    }
+
+    /* Disabling */
+    {
+        libvlc_media_player_record(mp, false, path);
+        const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+        assert(!ev->u.media_player_record_changed.recording);
+        assert(ev->u.media_player_record_changed.recorded_file_path != NULL);
+        event_ctx_release(&ctx);
+    }
+
+    libvlc_media_player_stop_async (mp);
+    libvlc_media_player_release (mp);
+    libvlc_release (vlc);
+}
+
+int main(void)
+{
+#ifndef ENABLE_SOUT
+    (void)test_media_player_record;
+    return 77;
+#endif
+
+    test_init();
+    test_media_player_record (test_defaults_args, test_defaults_nargs);
+    return 0;
+}


=====================================
test/libvlc/test.h
=====================================
@@ -99,4 +99,50 @@ static inline void test_init (void)
     setenv( "VLC_PLUGIN_PATH", "../modules", 1 );
 }
 
+struct event_ctx
+{
+    vlc_sem_t sem_ev;
+    vlc_sem_t sem_done;
+    const struct libvlc_event_t *ev;
+};
+
+static inline void event_ctx_init(struct event_ctx *ctx)
+{
+    vlc_sem_init(&ctx->sem_ev, 0);
+    vlc_sem_init(&ctx->sem_done, 0);
+    ctx->ev = NULL;
+}
+
+static inline const struct libvlc_event_t *event_ctx_wait_event(struct event_ctx *ctx)
+{
+    vlc_sem_wait(&ctx->sem_ev);
+    assert(ctx->ev != NULL);
+    return ctx->ev;
+}
+
+static inline void event_ctx_release(struct event_ctx *ctx)
+{
+    assert(ctx->ev != NULL);
+    ctx->ev = NULL;
+    vlc_sem_post(&ctx->sem_done);
+}
+
+static inline void event_ctx_wait(struct event_ctx *ctx)
+{
+    event_ctx_wait_event(ctx);
+    event_ctx_release(ctx);
+}
+
+static inline void event_ctx_on_event(const struct libvlc_event_t *event, void *data)
+{
+    struct event_ctx *ctx = data;
+
+    assert(ctx->ev == NULL);
+    ctx->ev = event;
+
+    vlc_sem_post(&ctx->sem_ev);
+    vlc_sem_wait(&ctx->sem_done);
+    assert(ctx->ev == NULL);
+}
+
 #endif /* TEST_H */



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/9d3a12427f4a16e1318663a05ee46ba4d6088971...3ecfdc5deb966231cef613e6dda1f228cafb2c64

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


VideoLAN code repository instance


More information about the vlc-commits mailing list