[vlc-commits] test: media: use a sem
Thomas Guillem
git at videolan.org
Thu Nov 5 09:40:51 CET 2015
vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Nov 5 09:40:00 2015 +0100| [341e98d348d5a42730b80f92ff272e3b549efcf4] | committer: Thomas Guillem
test: media: use a sem
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=341e98d348d5a42730b80f92ff272e3b549efcf4
---
test/libvlc/media.c | 33 +++++++--------------------------
1 file changed, 7 insertions(+), 26 deletions(-)
diff --git a/test/libvlc/media.c b/test/libvlc/media.c
index 2a6e13f..aceba84 100644
--- a/test/libvlc/media.c
+++ b/test/libvlc/media.c
@@ -26,23 +26,11 @@
#include <vlc_common.h>
#include <vlc_threads.h>
-struct test_media_preparsed_sys
-{
- vlc_mutex_t lock;
- vlc_cond_t wait;
- bool preparsed;
-};
-
static void preparsed_changed(const libvlc_event_t *event, void *user_data)
{
(void)event;
-
- struct test_media_preparsed_sys *sys = user_data;
-
- vlc_mutex_lock (&sys->lock);
- sys->preparsed = true;
- vlc_cond_signal (&sys->wait);
- vlc_mutex_unlock (&sys->lock);
+ vlc_sem_t *sem = user_data;
+ vlc_sem_post (sem);
}
static void test_media_preparsed(const char** argv, int argc)
@@ -58,23 +46,19 @@ static void test_media_preparsed(const char** argv, int argc)
libvlc_media_t *media = libvlc_media_new_path (vlc, file);
assert (media != NULL);
- struct test_media_preparsed_sys preparsed_sys, *sys = &preparsed_sys;
- sys->preparsed = false;
- vlc_mutex_init (&sys->lock);
- vlc_cond_init (&sys->wait);
+ vlc_sem_t sem;
+ vlc_sem_init (&sem, 0);
// Check to see if we are properly receiving the event.
libvlc_event_manager_t *em = libvlc_media_event_manager (media);
- libvlc_event_attach (em, libvlc_MediaParsedChanged, preparsed_changed, sys);
+ libvlc_event_attach (em, libvlc_MediaParsedChanged, preparsed_changed, &sem);
// Parse the media. This is synchronous.
libvlc_media_parse_async(media);
// Wait for preparsed event
- vlc_mutex_lock (&sys->lock);
- while (!sys->preparsed)
- vlc_cond_wait (&sys->wait, &sys->lock);
- vlc_mutex_unlock (&sys->lock);
+ vlc_sem_wait (&sem);
+ vlc_sem_destroy (&sem);
// We are good, now check Elementary Stream info.
libvlc_media_track_t **tracks;
@@ -83,9 +67,6 @@ static void test_media_preparsed(const char** argv, int argc)
assert (tracks[0]->i_type == libvlc_track_video);
libvlc_media_tracks_release (tracks, nb_tracks);
- vlc_mutex_destroy (&sys->lock);
- vlc_cond_destroy (&sys->wait);
-
libvlc_media_release (media);
libvlc_release (vlc);
}
More information about the vlc-commits
mailing list