mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
check: port to the new GLib thread API
This commit is contained in:
parent
47e7c91ab5
commit
bb4860d961
5 changed files with 53 additions and 71 deletions
|
@ -30,8 +30,8 @@
|
||||||
|
|
||||||
#include "gstbufferstraw.h"
|
#include "gstbufferstraw.h"
|
||||||
|
|
||||||
static GCond *cond = NULL;
|
static GCond cond;
|
||||||
static GMutex *lock = NULL;
|
static GMutex lock;
|
||||||
static GstBuffer *buf = NULL;
|
static GstBuffer *buf = NULL;
|
||||||
static gulong id;
|
static gulong id;
|
||||||
|
|
||||||
|
@ -42,17 +42,17 @@ buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer unused)
|
||||||
{
|
{
|
||||||
GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
|
GstBuffer *buffer = GST_PAD_PROBE_INFO_BUFFER (info);
|
||||||
|
|
||||||
g_mutex_lock (lock);
|
g_mutex_lock (&lock);
|
||||||
|
|
||||||
while (buf != NULL)
|
while (buf != NULL)
|
||||||
g_cond_wait (cond, lock);
|
g_cond_wait (&cond, &lock);
|
||||||
|
|
||||||
/* increase the refcount because we store it globally for others to use */
|
/* increase the refcount because we store it globally for others to use */
|
||||||
buf = gst_buffer_ref (buffer);
|
buf = gst_buffer_ref (buffer);
|
||||||
|
|
||||||
g_cond_signal (cond);
|
g_cond_signal (&cond);
|
||||||
|
|
||||||
g_mutex_unlock (lock);
|
g_mutex_unlock (&lock);
|
||||||
|
|
||||||
return GST_PAD_PROBE_OK;
|
return GST_PAD_PROBE_OK;
|
||||||
}
|
}
|
||||||
|
@ -86,9 +86,6 @@ gst_buffer_straw_start_pipeline (GstElement * bin, GstPad * pad)
|
||||||
id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
|
id = gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BUFFER,
|
||||||
buffer_probe, NULL, NULL);
|
buffer_probe, NULL, NULL);
|
||||||
|
|
||||||
cond = g_cond_new ();
|
|
||||||
lock = g_mutex_new ();
|
|
||||||
|
|
||||||
ret = gst_element_set_state (bin, GST_STATE_PLAYING);
|
ret = gst_element_set_state (bin, GST_STATE_PLAYING);
|
||||||
fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not start test pipeline");
|
fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not start test pipeline");
|
||||||
if (ret == GST_STATE_CHANGE_ASYNC) {
|
if (ret == GST_STATE_CHANGE_ASYNC) {
|
||||||
|
@ -117,17 +114,17 @@ gst_buffer_straw_get_buffer (GstElement * bin, GstPad * pad)
|
||||||
{
|
{
|
||||||
GstBuffer *ret;
|
GstBuffer *ret;
|
||||||
|
|
||||||
g_mutex_lock (lock);
|
g_mutex_lock (&lock);
|
||||||
|
|
||||||
while (buf == NULL)
|
while (buf == NULL)
|
||||||
g_cond_wait (cond, lock);
|
g_cond_wait (&cond, &lock);
|
||||||
|
|
||||||
ret = buf;
|
ret = buf;
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
|
|
||||||
g_cond_signal (cond);
|
g_cond_signal (&cond);
|
||||||
|
|
||||||
g_mutex_unlock (lock);
|
g_mutex_unlock (&lock);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -148,14 +145,14 @@ gst_buffer_straw_stop_pipeline (GstElement * bin, GstPad * pad)
|
||||||
{
|
{
|
||||||
GstStateChangeReturn ret;
|
GstStateChangeReturn ret;
|
||||||
|
|
||||||
g_mutex_lock (lock);
|
g_mutex_lock (&lock);
|
||||||
if (buf)
|
if (buf)
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
gst_pad_remove_probe (pad, (guint) id);
|
gst_pad_remove_probe (pad, (guint) id);
|
||||||
id = 0;
|
id = 0;
|
||||||
g_cond_signal (cond);
|
g_cond_signal (&cond);
|
||||||
g_mutex_unlock (lock);
|
g_mutex_unlock (&lock);
|
||||||
|
|
||||||
ret = gst_element_set_state (bin, GST_STATE_NULL);
|
ret = gst_element_set_state (bin, GST_STATE_NULL);
|
||||||
fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not stop test pipeline");
|
fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not stop test pipeline");
|
||||||
|
@ -164,15 +161,9 @@ gst_buffer_straw_stop_pipeline (GstElement * bin, GstPad * pad)
|
||||||
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not stop test pipeline");
|
fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not stop test pipeline");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_mutex_lock (lock);
|
g_mutex_lock (&lock);
|
||||||
if (buf)
|
if (buf)
|
||||||
gst_buffer_unref (buf);
|
gst_buffer_unref (buf);
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
g_mutex_unlock (lock);
|
g_mutex_unlock (&lock);
|
||||||
|
|
||||||
g_mutex_free (lock);
|
|
||||||
g_cond_free (cond);
|
|
||||||
|
|
||||||
lock = NULL;
|
|
||||||
cond = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,13 +40,13 @@ GST_DEBUG_CATEGORY (check_debug);
|
||||||
|
|
||||||
gboolean _gst_check_threads_running = FALSE;
|
gboolean _gst_check_threads_running = FALSE;
|
||||||
GList *thread_list = NULL;
|
GList *thread_list = NULL;
|
||||||
GMutex *mutex;
|
GMutex mutex;
|
||||||
GCond *start_cond; /* used to notify main thread of thread startups */
|
GCond start_cond; /* used to notify main thread of thread startups */
|
||||||
GCond *sync_cond; /* used to synchronize all threads and main thread */
|
GCond sync_cond; /* used to synchronize all threads and main thread */
|
||||||
|
|
||||||
GList *buffers = NULL;
|
GList *buffers = NULL;
|
||||||
GMutex *check_mutex = NULL;
|
GMutex check_mutex;
|
||||||
GCond *check_cond = NULL;
|
GCond check_cond;
|
||||||
|
|
||||||
/* FIXME 0.11: shouldn't _gst_check_debug be static? Not used anywhere */
|
/* FIXME 0.11: shouldn't _gst_check_debug be static? Not used anywhere */
|
||||||
gboolean _gst_check_debug = FALSE;
|
gboolean _gst_check_debug = FALSE;
|
||||||
|
@ -136,9 +136,6 @@ gst_check_init (int *argc, char **argv[])
|
||||||
gst_check_log_critical_func, NULL);
|
gst_check_log_critical_func, NULL);
|
||||||
|
|
||||||
print_plugins ();
|
print_plugins ();
|
||||||
|
|
||||||
check_cond = g_cond_new ();
|
|
||||||
check_mutex = g_mutex_new ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* message checking */
|
/* message checking */
|
||||||
|
@ -167,9 +164,9 @@ gst_check_chain_func (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
||||||
GST_DEBUG_OBJECT (pad, "chain_func: received buffer %p", buffer);
|
GST_DEBUG_OBJECT (pad, "chain_func: received buffer %p", buffer);
|
||||||
buffers = g_list_append (buffers, buffer);
|
buffers = g_list_append (buffers, buffer);
|
||||||
|
|
||||||
g_mutex_lock (check_mutex);
|
g_mutex_lock (&check_mutex);
|
||||||
g_cond_signal (check_cond);
|
g_cond_signal (&check_cond);
|
||||||
g_mutex_unlock (check_mutex);
|
g_mutex_unlock (&check_mutex);
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,8 +51,8 @@ extern gboolean _gst_check_expecting_log;
|
||||||
/* global variables used in test methods */
|
/* global variables used in test methods */
|
||||||
extern GList * buffers;
|
extern GList * buffers;
|
||||||
|
|
||||||
extern GMutex *check_mutex;
|
extern GMutex check_mutex;
|
||||||
extern GCond *check_cond;
|
extern GCond check_cond;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -267,9 +267,9 @@ G_STMT_START { \
|
||||||
* thread test macros and variables
|
* thread test macros and variables
|
||||||
*/
|
*/
|
||||||
extern GList *thread_list;
|
extern GList *thread_list;
|
||||||
extern GMutex *mutex;
|
extern GMutex mutex;
|
||||||
extern GCond *start_cond; /* used to notify main thread of thread startups */
|
extern GCond start_cond; /* used to notify main thread of thread startups */
|
||||||
extern GCond *sync_cond; /* used to synchronize all threads and main thread */
|
extern GCond sync_cond; /* used to synchronize all threads and main thread */
|
||||||
|
|
||||||
#define MAIN_START_THREADS(count, function, data) \
|
#define MAIN_START_THREADS(count, function, data) \
|
||||||
MAIN_INIT(); \
|
MAIN_INIT(); \
|
||||||
|
@ -354,12 +354,6 @@ gst_g_cond_timed_wait (GCond *cond, GMutex *mutex, GTimeVal *abs_time)
|
||||||
#define MAIN_INIT() \
|
#define MAIN_INIT() \
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
_gst_check_threads_running = TRUE; \
|
_gst_check_threads_running = TRUE; \
|
||||||
\
|
|
||||||
if (mutex == NULL) { \
|
|
||||||
mutex = g_mutex_new (); \
|
|
||||||
start_cond = g_cond_new (); \
|
|
||||||
sync_cond = g_cond_new (); \
|
|
||||||
} \
|
|
||||||
} G_STMT_END;
|
} G_STMT_END;
|
||||||
|
|
||||||
#define MAIN_START_THREAD_FUNCTIONS(count, function, data) \
|
#define MAIN_START_THREAD_FUNCTIONS(count, function, data) \
|
||||||
|
@ -374,13 +368,13 @@ G_STMT_START { \
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
GThread *thread = NULL; \
|
GThread *thread = NULL; \
|
||||||
GST_DEBUG ("MAIN: creating thread %d", i); \
|
GST_DEBUG ("MAIN: creating thread %d", i); \
|
||||||
g_mutex_lock (mutex); \
|
g_mutex_lock (&mutex); \
|
||||||
thread = g_thread_create ((GThreadFunc) function, data, \
|
thread = g_thread_try_new ("gst-check", \
|
||||||
TRUE, NULL); \
|
(GThreadFunc) function, data, NULL); \
|
||||||
/* wait for thread to signal us that it's ready */ \
|
/* wait for thread to signal us that it's ready */ \
|
||||||
GST_DEBUG ("MAIN: waiting for thread %d", i); \
|
GST_DEBUG ("MAIN: waiting for thread %d", i); \
|
||||||
g_cond_wait (start_cond, mutex); \
|
g_cond_wait (&start_cond, &mutex); \
|
||||||
g_mutex_unlock (mutex); \
|
g_mutex_unlock (&mutex); \
|
||||||
\
|
\
|
||||||
thread_list = g_list_append (thread_list, thread); \
|
thread_list = g_list_append (thread_list, thread); \
|
||||||
} G_STMT_END;
|
} G_STMT_END;
|
||||||
|
@ -389,7 +383,7 @@ G_STMT_START { \
|
||||||
#define MAIN_SYNCHRONIZE() \
|
#define MAIN_SYNCHRONIZE() \
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
GST_DEBUG ("MAIN: synchronizing"); \
|
GST_DEBUG ("MAIN: synchronizing"); \
|
||||||
g_cond_broadcast (sync_cond); \
|
g_cond_broadcast (&sync_cond); \
|
||||||
GST_DEBUG ("MAIN: synchronized"); \
|
GST_DEBUG ("MAIN: synchronized"); \
|
||||||
} G_STMT_END;
|
} G_STMT_END;
|
||||||
|
|
||||||
|
@ -413,17 +407,17 @@ THREAD_SYNCHRONIZE();
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
/* signal main thread that we started */ \
|
/* signal main thread that we started */ \
|
||||||
GST_DEBUG ("THREAD %p: started", g_thread_self ()); \
|
GST_DEBUG ("THREAD %p: started", g_thread_self ()); \
|
||||||
g_mutex_lock (mutex); \
|
g_mutex_lock (&mutex); \
|
||||||
g_cond_signal (start_cond); \
|
g_cond_signal (&start_cond); \
|
||||||
} G_STMT_END;
|
} G_STMT_END;
|
||||||
|
|
||||||
#define THREAD_SYNCHRONIZE() \
|
#define THREAD_SYNCHRONIZE() \
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
/* synchronize everyone */ \
|
/* synchronize everyone */ \
|
||||||
GST_DEBUG ("THREAD %p: syncing", g_thread_self ()); \
|
GST_DEBUG ("THREAD %p: syncing", g_thread_self ()); \
|
||||||
g_cond_wait (sync_cond, mutex); \
|
g_cond_wait (&sync_cond, &mutex); \
|
||||||
GST_DEBUG ("THREAD %p: synced", g_thread_self ()); \
|
GST_DEBUG ("THREAD %p: synced", g_thread_self ()); \
|
||||||
g_mutex_unlock (mutex); \
|
g_mutex_unlock (&mutex); \
|
||||||
} G_STMT_END;
|
} G_STMT_END;
|
||||||
|
|
||||||
#define THREAD_SWITCH() \
|
#define THREAD_SWITCH() \
|
||||||
|
|
|
@ -270,12 +270,12 @@ GST_START_TEST (test_non_leaky_overrun)
|
||||||
fail_unless (overrun_count == 1);
|
fail_unless (overrun_count == 1);
|
||||||
|
|
||||||
/* lock the check_mutex to block the first buffer pushed to mysinkpad */
|
/* lock the check_mutex to block the first buffer pushed to mysinkpad */
|
||||||
g_mutex_lock (check_mutex);
|
g_mutex_lock (&check_mutex);
|
||||||
/* now let the queue push all buffers */
|
/* now let the queue push all buffers */
|
||||||
while (g_list_length (buffers) < 3) {
|
while (g_list_length (buffers) < 3) {
|
||||||
g_cond_wait (check_cond, check_mutex);
|
g_cond_wait (&check_cond, &check_mutex);
|
||||||
}
|
}
|
||||||
g_mutex_unlock (check_mutex);
|
g_mutex_unlock (&check_mutex);
|
||||||
|
|
||||||
fail_unless (overrun_count == 1);
|
fail_unless (overrun_count == 1);
|
||||||
/* make sure we get the underrun signal before we check underrun_count */
|
/* make sure we get the underrun signal before we check underrun_count */
|
||||||
|
|
|
@ -242,20 +242,20 @@ app_thread_func (gpointer data)
|
||||||
BufferAllocHarness *h = data;
|
BufferAllocHarness *h = data;
|
||||||
|
|
||||||
/* Signal that we are about to call release_request_pad(). */
|
/* Signal that we are about to call release_request_pad(). */
|
||||||
g_mutex_lock (check_mutex);
|
g_mutex_lock (&check_mutex);
|
||||||
h->app_thread_prepped = TRUE;
|
h->app_thread_prepped = TRUE;
|
||||||
g_cond_signal (check_cond);
|
g_cond_signal (&check_cond);
|
||||||
g_mutex_unlock (check_mutex);
|
g_mutex_unlock (&check_mutex);
|
||||||
|
|
||||||
/* Simulate that the app releases the pad while the streaming thread is in
|
/* Simulate that the app releases the pad while the streaming thread is in
|
||||||
* buffer_alloc below. */
|
* buffer_alloc below. */
|
||||||
gst_element_release_request_pad (h->tee, h->tee_srcpad);
|
gst_element_release_request_pad (h->tee, h->tee_srcpad);
|
||||||
|
|
||||||
/* Signal the bufferalloc function below if it's still waiting. */
|
/* Signal the bufferalloc function below if it's still waiting. */
|
||||||
g_mutex_lock (check_mutex);
|
g_mutex_lock (&check_mutex);
|
||||||
h->bufferalloc_blocked = FALSE;
|
h->bufferalloc_blocked = FALSE;
|
||||||
g_cond_signal (check_cond);
|
g_cond_signal (&check_cond);
|
||||||
g_mutex_unlock (check_mutex);
|
g_mutex_unlock (&check_mutex);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -282,21 +282,21 @@ final_sinkpad_bufferalloc (GstPad * pad, guint64 offset, guint size,
|
||||||
fail_if (h->app_thread == NULL);
|
fail_if (h->app_thread == NULL);
|
||||||
|
|
||||||
/* Wait for the app thread to get ready to call release_request_pad(). */
|
/* Wait for the app thread to get ready to call release_request_pad(). */
|
||||||
g_mutex_lock (check_mutex);
|
g_mutex_lock (&check_mutex);
|
||||||
while (!h->app_thread_prepped)
|
while (!h->app_thread_prepped)
|
||||||
g_cond_wait (check_cond, check_mutex);
|
g_cond_wait (&check_cond, &check_mutex);
|
||||||
g_mutex_unlock (check_mutex);
|
g_mutex_unlock (&check_mutex);
|
||||||
|
|
||||||
/* Now wait for it to do that within a second, to avoid deadlocking
|
/* Now wait for it to do that within a second, to avoid deadlocking
|
||||||
* in the event of future changes to the locking semantics. */
|
* in the event of future changes to the locking semantics. */
|
||||||
g_mutex_lock (check_mutex);
|
g_mutex_lock (&check_mutex);
|
||||||
g_get_current_time (&deadline);
|
g_get_current_time (&deadline);
|
||||||
deadline.tv_sec += 1;
|
deadline.tv_sec += 1;
|
||||||
while (h->bufferalloc_blocked) {
|
while (h->bufferalloc_blocked) {
|
||||||
if (!g_cond_timed_wait (check_cond, check_mutex, &deadline))
|
if (!g_cond_timed_wait (&check_cond, &check_mutex, &deadline))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
g_mutex_unlock (check_mutex);
|
g_mutex_unlock (&check_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
*buf = gst_buffer_new_and_alloc (size);
|
*buf = gst_buffer_new_and_alloc (size);
|
||||||
|
|
Loading…
Reference in a new issue