[vlc-commits] [Git][videolan/vlc][master] test: media_player: move event_ctx to media_player.h and rename to mp_event_ctx
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Fri Jul 7 12:21:27 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
812aa244 by Thomas Guillem at 2023-07-07T12:21:16+00:00
test: media_player: move event_ctx to media_player.h and rename to mp_event_ctx
- - - - -
5 changed files:
- test/Makefile.am
- test/libvlc/media_player.c
- + test/libvlc/media_player.h
- test/libvlc/media_player_record.c
- test/libvlc/test.h
Changes:
=====================================
test/Makefile.am
=====================================
@@ -95,7 +95,8 @@ EXTRA_DIST = \
samples/slaves \
$(check_SCRIPTS)
-check_HEADERS = libvlc/test.h libvlc/libvlc_additions.h libvlc/media_utils.h
+check_HEADERS = libvlc/test.h libvlc/libvlc_additions.h libvlc/media_utils.h \
+ libvlc/media_player.h
TESTS = $(check_PROGRAMS) check_POTFILES.sh
=====================================
test/libvlc/media_player.c
=====================================
@@ -21,36 +21,37 @@
**********************************************************************/
#include "test.h"
+#include "media_player.h"
#include <vlc_common.h>
static void play_and_wait(libvlc_media_player_t *mp)
{
libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
- struct event_ctx ctx;
- event_ctx_init(&ctx);
+ struct mp_event_ctx ctx;
+ mp_event_ctx_init(&ctx);
int res;
- res = libvlc_event_attach(em, libvlc_MediaPlayerPlaying, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerPlaying, mp_event_ctx_on_event, &ctx);
assert(!res);
libvlc_media_player_play(mp);
test_log("Waiting for playing\n");
- event_ctx_wait(&ctx);
+ mp_event_ctx_wait(&ctx);
- libvlc_event_detach(em, libvlc_MediaPlayerPlaying, event_ctx_on_event, &ctx);
+ libvlc_event_detach(em, libvlc_MediaPlayerPlaying, mp_event_ctx_on_event, &ctx);
}
static void pause_and_wait(libvlc_media_player_t *mp)
{
libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
- struct event_ctx ctx;
- event_ctx_init(&ctx);
+ struct mp_event_ctx ctx;
+ mp_event_ctx_init(&ctx);
int res;
- res = libvlc_event_attach(em, libvlc_MediaPlayerPaused, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerPaused, mp_event_ctx_on_event, &ctx);
assert(!res);
assert(libvlc_media_player_get_state(mp) == libvlc_Playing);
@@ -58,11 +59,11 @@ static void pause_and_wait(libvlc_media_player_t *mp)
libvlc_media_player_set_pause(mp, true);
test_log("Waiting for pause\n");
- event_ctx_wait(&ctx);
+ mp_event_ctx_wait(&ctx);
assert(libvlc_media_player_get_state(mp) == libvlc_Paused);
- libvlc_event_detach(em, libvlc_MediaPlayerPaused, event_ctx_on_event, &ctx);
+ libvlc_event_detach(em, libvlc_MediaPlayerPaused, mp_event_ctx_on_event, &ctx);
}
/* Test a bunch of A/V properties. This most does nothing since the current
@@ -312,15 +313,15 @@ static void test_media_player_tracks(const char** argv, int argc)
libvlc_media_track_t *libtrack;
libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
- struct event_ctx ctx;
- event_ctx_init(&ctx);
+ struct mp_event_ctx ctx;
+ mp_event_ctx_init(&ctx);
int res;
- res = libvlc_event_attach(em, libvlc_MediaPlayerESAdded, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerESAdded, mp_event_ctx_on_event, &ctx);
assert(!res);
- res = libvlc_event_attach(em, libvlc_MediaPlayerESDeleted, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerESDeleted, mp_event_ctx_on_event, &ctx);
assert(!res);
- res = libvlc_event_attach(em, libvlc_MediaPlayerESSelected, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerESSelected, mp_event_ctx_on_event, &ctx);
assert(!res);
libvlc_media_player_play (mp);
@@ -329,7 +330,7 @@ static void test_media_player_tracks(const char** argv, int argc)
* libvlc_media_player_select_tracks_by_ids */
while (!tracks_check_all_events(alltracks, false))
{
- const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+ const struct libvlc_event_t *ev = mp_event_ctx_wait_event(&ctx);
switch (ev->type)
{
case libvlc_MediaPlayerESAdded:
@@ -364,7 +365,7 @@ static void test_media_player_tracks(const char** argv, int argc)
assert(!"Event not expected");
}
- event_ctx_release(&ctx);
+ mp_event_ctx_release(&ctx);
}
/* Compare with the tracklists */
@@ -441,7 +442,7 @@ static void test_media_player_tracks(const char** argv, int argc)
* changes. */
while (!tracks_check_all_events(alltracks, false))
{
- const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+ const struct libvlc_event_t *ev = mp_event_ctx_wait_event(&ctx);
assert(ev->type == libvlc_MediaPlayerESSelected);
libvlc_track_type_t type = ev->u.media_player_es_selection_changed.i_type;
@@ -468,7 +469,7 @@ static void test_media_player_tracks(const char** argv, int argc)
track->selected = true;
}
- event_ctx_release(&ctx);
+ mp_event_ctx_release(&ctx);
}
libvlc_media_player_stop_async (mp);
@@ -476,7 +477,7 @@ static void test_media_player_tracks(const char** argv, int argc)
/* Check that all tracks are removed */
while (!tracks_check_all_events(alltracks, true))
{
- const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+ const struct libvlc_event_t *ev = mp_event_ctx_wait_event(&ctx);
if (ev->type == libvlc_MediaPlayerESDeleted)
{
@@ -487,12 +488,12 @@ static void test_media_player_tracks(const char** argv, int argc)
assert(track);
track->removed = true;
}
- event_ctx_release(&ctx);
+ mp_event_ctx_release(&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_event_detach(em, libvlc_MediaPlayerESAdded, mp_event_ctx_on_event, &ctx);
+ libvlc_event_detach(em, libvlc_MediaPlayerESDeleted, mp_event_ctx_on_event, &ctx);
+ libvlc_event_detach(em, libvlc_MediaPlayerESSelected, mp_event_ctx_on_event, &ctx);
libvlc_media_player_release (mp);
libvlc_release (vlc);
@@ -523,15 +524,15 @@ static void test_media_player_programs(const char** argv, int argc)
libvlc_media_release (md);
libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
- struct event_ctx ctx;
- event_ctx_init(&ctx);
+ struct mp_event_ctx ctx;
+ mp_event_ctx_init(&ctx);
int res;
- res = libvlc_event_attach(em, libvlc_MediaPlayerProgramAdded, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerProgramAdded, mp_event_ctx_on_event, &ctx);
assert(!res);
- res = libvlc_event_attach(em, libvlc_MediaPlayerProgramDeleted, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerProgramDeleted, mp_event_ctx_on_event, &ctx);
assert(!res);
- res = libvlc_event_attach(em, libvlc_MediaPlayerProgramSelected, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerProgramSelected, mp_event_ctx_on_event, &ctx);
assert(!res);
libvlc_media_player_select_program_id(mp, 2);
@@ -542,7 +543,7 @@ static void test_media_player_programs(const char** argv, int argc)
for (int nb_added = 0, nb_selected = 0;
nb_added != PROGRAM_COUNT || nb_selected != 1;)
{
- const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+ const struct libvlc_event_t *ev = mp_event_ctx_wait_event(&ctx);
switch (ev->type)
{
case libvlc_MediaPlayerProgramAdded:
@@ -558,7 +559,7 @@ static void test_media_player_programs(const char** argv, int argc)
default:
assert(!"Event not expected");
}
- event_ctx_release(&ctx);
+ mp_event_ctx_release(&ctx);
}
libvlc_player_program_t *program;
@@ -573,11 +574,11 @@ static void test_media_player_programs(const char** argv, int argc)
/* Wait for the program selection event */
{
- const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+ const struct libvlc_event_t *ev = mp_event_ctx_wait_event(&ctx);
assert(ev->type == libvlc_MediaPlayerProgramSelected);
assert(ev->u.media_player_program_selection_changed.i_unselected_id == 2);
assert(ev->u.media_player_program_selection_changed.i_selected_id == 8);
- event_ctx_release(&ctx);
+ mp_event_ctx_release(&ctx);
}
/* Ensure that the new program was selected */
@@ -609,7 +610,7 @@ static void test_media_player_programs(const char** argv, int argc)
/* Check that all programs are removed and unselected */
for (int nb_deleted = 0; nb_deleted != PROGRAM_COUNT;)
{
- const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+ const struct libvlc_event_t *ev = mp_event_ctx_wait_event(&ctx);
switch (ev->type)
{
case libvlc_MediaPlayerProgramDeleted:
@@ -619,12 +620,12 @@ static void test_media_player_programs(const char** argv, int argc)
default:
assert(!"Event not expected");
}
- event_ctx_release(&ctx);
+ mp_event_ctx_release(&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_event_detach(em, libvlc_MediaPlayerProgramAdded, mp_event_ctx_on_event, &ctx);
+ libvlc_event_detach(em, libvlc_MediaPlayerProgramDeleted, mp_event_ctx_on_event, &ctx);
+ libvlc_event_detach(em, libvlc_MediaPlayerProgramSelected, mp_event_ctx_on_event, &ctx);
libvlc_media_player_release (mp);
libvlc_release (vlc);
=====================================
test/libvlc/media_player.h
=====================================
@@ -0,0 +1,73 @@
+/*
+ * media_player.h - media player test common definitions
+ *
+ */
+
+/**********************************************************************
+ * Copyright (C) 2023 VideoLAN and its authors *
+ * *
+ * This program is free software; you can redistribute and/or modify *
+ * it under the terms of the GNU General Public License as published *
+ * by the Free Software Foundation; version 2 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, you can get it from: *
+ * http://www.gnu.org/copyleft/gpl.html *
+ **********************************************************************/
+
+#ifndef TEST_MEDIA_PLAYER_H
+#define TEST_MEDIA_PLAYER_H
+
+struct mp_event_ctx
+{
+ vlc_sem_t sem_ev;
+ vlc_sem_t sem_done;
+ const struct libvlc_event_t *ev;
+};
+
+static inline void mp_event_ctx_init(struct mp_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 *mp_event_ctx_wait_event(struct mp_event_ctx *ctx)
+{
+ vlc_sem_wait(&ctx->sem_ev);
+ assert(ctx->ev != NULL);
+ return ctx->ev;
+}
+
+static inline void mp_event_ctx_release(struct mp_event_ctx *ctx)
+{
+ assert(ctx->ev != NULL);
+ ctx->ev = NULL;
+ vlc_sem_post(&ctx->sem_done);
+}
+
+static inline void mp_event_ctx_wait(struct mp_event_ctx *ctx)
+{
+ mp_event_ctx_wait_event(ctx);
+ mp_event_ctx_release(ctx);
+}
+
+static inline void mp_event_ctx_on_event(const struct libvlc_event_t *event, void *data)
+{
+ struct mp_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_MEDIA_PLAYER_H */
=====================================
test/libvlc/media_player_record.c
=====================================
@@ -21,6 +21,7 @@
*****************************************************************************/
#include "test.h"
+#include "media_player.h"
#include <vlc_common.h>
static void test_media_player_record(const char** argv, int argc)
@@ -46,11 +47,11 @@ static void test_media_player_record(const char** argv, int argc)
libvlc_media_release (md);
libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp);
- struct event_ctx ctx;
- event_ctx_init(&ctx);
+ struct mp_event_ctx ctx;
+ mp_event_ctx_init(&ctx);
int res;
- res = libvlc_event_attach(em, libvlc_MediaPlayerRecordChanged, event_ctx_on_event, &ctx);
+ res = libvlc_event_attach(em, libvlc_MediaPlayerRecordChanged, mp_event_ctx_on_event, &ctx);
assert(!res);
libvlc_media_player_play (mp);
@@ -62,20 +63,20 @@ static void test_media_player_record(const char** argv, int argc)
/* Enabling */
{
- const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+ const struct libvlc_event_t *ev = mp_event_ctx_wait_event(&ctx);
assert(ev->u.media_player_record_changed.recording);
- event_ctx_release(&ctx);
+ mp_event_ctx_release(&ctx);
}
/* Disabling */
{
libvlc_media_player_record(mp, false, path);
- const struct libvlc_event_t *ev = event_ctx_wait_event(&ctx);
+ const struct libvlc_event_t *ev = mp_event_ctx_wait_event(&ctx);
assert(!ev->u.media_player_record_changed.recording);
assert(ev->u.media_player_record_changed.recorded_file_path != NULL);
filepath = strdup(ev->u.media_player_record_changed.recorded_file_path);
assert(filepath != NULL);
- event_ctx_release(&ctx);
+ mp_event_ctx_release(&ctx);
}
libvlc_media_player_stop_async (mp);
=====================================
test/libvlc/test.h
=====================================
@@ -99,50 +99,4 @@ 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/-/commit/812aa244bd40eb5218cd2711f4d11ee8a6ca6a03
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/812aa244bd40eb5218cd2711f4d11ee8a6ca6a03
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