From ed9d0381b2aef7270d1bc41a70db5d06e99f6a90 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Sat, 12 Apr 2014 15:22:35 +0100 Subject: [PATCH] testclock: replace newly-added GstTestClockIDList structure with a simple GList Keep it simple. Likely also makes things easier for bindings, and efficiency clearly has not been a consideration given how the existing code handled these lists. --- libs/gst/check/Makefile.am | 3 +- libs/gst/check/gsttestclock.c | 70 ++++++++++++++--------------------------- libs/gst/check/gsttestclock.h | 31 ++++-------------- tests/check/libs/gsttestclock.c | 12 ++++--- 4 files changed, 37 insertions(+), 79 deletions(-) diff --git a/libs/gst/check/Makefile.am b/libs/gst/check/Makefile.am index cf1328b..120a3b0 100644 --- a/libs/gst/check/Makefile.am +++ b/libs/gst/check/Makefile.am @@ -107,8 +107,7 @@ LIBGSTCHECK_EXPORTED_FUNCS = \ gst_test_clock_get_next_entry_time \ gst_test_clock_wait_for_multiple_pending_ids \ gst_test_clock_process_id_list \ - gst_test_clock_id_list_get_latest_time \ - gst_test_clock_id_list_free + gst_test_clock_id_list_get_latest_time LIBGSTCHECK_EXPORTED_SYMBOLS = \ diff --git a/libs/gst/check/gsttestclock.c b/libs/gst/check/gsttestclock.c index 6bdde06..a609766 100644 --- a/libs/gst/check/gsttestclock.c +++ b/libs/gst/check/gsttestclock.c @@ -624,24 +624,20 @@ process_entry_context_unlocked (GstTestClock * test_clock, } } -static GstTestClockIDList * +static GList * gst_test_clock_get_pending_id_list_unlocked (GstTestClock * test_clock) { GstTestClockPrivate *priv = GST_TEST_CLOCK_GET_PRIVATE (test_clock); - GstTestClockIDList *result = g_new0 (GstTestClockIDList, 1); + GQueue queue = G_QUEUE_INIT; + GList *cur; - if (priv->entry_contexts != NULL) { - GList *cur; - for (cur = priv->entry_contexts; cur != NULL; cur = cur->next) { - GstClockEntryContext *ctx = cur->data; + for (cur = priv->entry_contexts; cur != NULL; cur = cur->next) { + GstClockEntryContext *ctx = cur->data; - result->cur = - g_list_append (result->cur, gst_clock_id_ref (ctx->clock_entry)); - } + g_queue_push_tail (&queue, gst_clock_id_ref (ctx->clock_entry)); } - result->length = g_list_length (result->cur); - return result; + return queue.head; } /** @@ -987,7 +983,9 @@ gst_test_clock_get_next_entry_time (GstTestClock * test_clock) * gst_test_clock_wait_for_multiple_pending_ids: * @test_clock: #GstTestClock for which to await having enough pending clock * @count: the number of pending clock notifications to wait for - * @pending_list: A #GstTestClockIDList with pending #GstClockIDs + * @pending_list: (out) (element-type Gst.ClockID) (transfer full) (allow-none): Address + * of a #GList pointer variable to store the list of pending #GstClockIDs + * that expired, or NULL * * Blocks until at least @count clock notifications have been requested from * @test_clock. There is no timeout for this wait, see the main description of @@ -999,7 +997,7 @@ gst_test_clock_get_next_entry_time (GstTestClock * test_clock) */ void gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock, - guint count, GstTestClockIDList ** pending_list) + guint count, GList ** pending_list) { GstTestClockPrivate *priv; @@ -1020,9 +1018,10 @@ gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock, /** * gst_test_clock_process_id_list: * @test_clock: #GstTestClock for which to process the pending IDs - * @pending_list: A #GstTestClockIDList with pending #GstClockIDs + * @pending_list: (element-type Gst.ClockID) (transfer none) (allow-none): List + * of pending #GstClockIDs * - * Processes and releases the pending IDs in #GstTestClockIDList + * Processes and releases the pending IDs in the list. * * MT safe. * @@ -1030,16 +1029,16 @@ gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock, */ guint gst_test_clock_process_id_list (GstTestClock * test_clock, - GstTestClockIDList * pending_list) + const GList * pending_list) { - GList *cur; + const GList *cur; guint result = 0; g_return_val_if_fail (GST_IS_TEST_CLOCK (test_clock), 0); GST_OBJECT_LOCK (test_clock); - for (cur = pending_list->cur; cur != NULL; cur = cur->next) { + for (cur = pending_list; cur != NULL; cur = cur->next) { GstClockID pending_id = cur->data; GstClockEntryContext *ctx = gst_test_clock_lookup_entry_context (test_clock, pending_id); @@ -1055,21 +1054,22 @@ gst_test_clock_process_id_list (GstTestClock * test_clock, /** * gst_test_clock_id_list_get_latest_time: - * @pending_list: A #GstTestClockIDList with pending #GstClockIDs + * @pending_list: (element-type Gst.ClockID) (transfer none) (allow-none): List + * of of pending #GstClockIDs * - * Finds the latest time inside the #GstTestClockIDList + * Finds the latest time inside the list. * * MT safe. * * Since: 1.4 */ GstClockTime -gst_test_clock_id_list_get_latest_time (GstTestClockIDList * pending_list) +gst_test_clock_id_list_get_latest_time (const GList * pending_list) { - GList *cur; + const GList *cur; GstClockTime result = 0; - for (cur = pending_list->cur; cur != NULL; cur = cur->next) { + for (cur = pending_list; cur != NULL; cur = cur->next) { GstClockID *pending_id = cur->data; GstClockTime time = gst_clock_id_get_time (pending_id); if (time > result) @@ -1078,27 +1078,3 @@ gst_test_clock_id_list_get_latest_time (GstTestClockIDList * pending_list) return result; } - -/** - * gst_test_clock_id_list_free: - * @pending_list: A #GstTestClockIDList with pending #GstClockIDs - * - * Free the supplied #GstTestClockIDList - * - * MT safe. - * - * Since: 1.4 - */ -void -gst_test_clock_id_list_free (GstTestClockIDList * pending_list) -{ - GList *cur; - - for (cur = pending_list->cur; cur != NULL; cur = cur->next) { - GstClockID *pending_id = cur->data; - gst_clock_id_unref (pending_id); - } - - g_list_free (pending_list->cur); - g_free (pending_list); -} diff --git a/libs/gst/check/gsttestclock.h b/libs/gst/check/gsttestclock.h index 7610335..af7a5f1 100644 --- a/libs/gst/check/gsttestclock.h +++ b/libs/gst/check/gsttestclock.h @@ -45,8 +45,6 @@ typedef struct _GstTestClock GstTestClock; typedef struct _GstTestClockClass GstTestClockClass; typedef struct _GstTestClockPrivate GstTestClockPrivate; -typedef struct _GstTestClockIDList GstTestClockIDList; - /** * GstTestClock: * @@ -76,21 +74,6 @@ struct _GstTestClockClass GstClockClass parent_class; }; -/** - * GstTestClockIDList: - * @cur: A #GList with all pending #GstClockID - * @length: A #guint with the length of the list - * - * A #GstTestClockIDList structure, which is returned when waiting for multiple IDs - * - * Since: 1.4 - */ - struct _GstTestClockIDList -{ - GList * cur; - guint length; -}; - GType gst_test_clock_get_type (void); GstClock * gst_test_clock_new (void); @@ -122,16 +105,14 @@ GstClockID gst_test_clock_process_next_clock_id (GstTestClock * test_clock); GstClockTime gst_test_clock_get_next_entry_time (GstTestClock * test_clock); -void gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock, - guint count, - GstTestClockIDList ** pending_list); - -guint gst_test_clock_process_id_list (GstTestClock * test_clock, - GstTestClockIDList * pending_list); +void gst_test_clock_wait_for_multiple_pending_ids (GstTestClock * test_clock, + guint count, + GList ** pending_list); -GstClockTime gst_test_clock_id_list_get_latest_time (GstTestClockIDList * list); +guint gst_test_clock_process_id_list (GstTestClock * test_clock, + const GList * pending_list); -void gst_test_clock_id_list_free (GstTestClockIDList * list); +GstClockTime gst_test_clock_id_list_get_latest_time (const GList * pending_list); G_END_DECLS diff --git a/tests/check/libs/gsttestclock.c b/tests/check/libs/gsttestclock.c index 97a04c2..b9d36b2 100644 --- a/tests/check/libs/gsttestclock.c +++ b/tests/check/libs/gsttestclock.c @@ -690,6 +690,7 @@ GST_START_TEST (test_single_shot_sync_simultaneous_no_timeout) gst_object_unref (clock); } + GST_END_TEST; GST_START_TEST (test_processing_multiple_ids) @@ -702,7 +703,7 @@ GST_START_TEST (test_processing_multiple_ids) SyncClockWaitContext context_b; GThread *worker_thread_a; GThread *worker_thread_b; - GstTestClockIDList * pending_list; + GList *pending_list = NULL; clock = gst_test_clock_new_with_start_time (GST_SECOND); test_clock = GST_TEST_CLOCK (clock); @@ -727,10 +728,10 @@ GST_START_TEST (test_processing_multiple_ids) gst_test_clock_wait_for_multiple_pending_ids (test_clock, 2, &pending_list); /* assert they are correct */ - assert_pending_id (pending_list->cur->data, clock_id_a, GST_CLOCK_ENTRY_SINGLE, + assert_pending_id (pending_list->data, clock_id_a, GST_CLOCK_ENTRY_SINGLE, 5 * GST_SECOND); - assert_pending_id (pending_list->cur->next->data, clock_id_b, GST_CLOCK_ENTRY_SINGLE, - 6 * GST_SECOND); + assert_pending_id (pending_list->next->data, clock_id_b, + GST_CLOCK_ENTRY_SINGLE, 6 * GST_SECOND); /* verify we are waiting for 6 seconds as the latest time */ fail_unless_equals_int64 (6 * GST_SECOND, @@ -738,7 +739,7 @@ GST_START_TEST (test_processing_multiple_ids) /* process both ID's at the same time */ gst_test_clock_process_id_list (test_clock, pending_list); - gst_test_clock_id_list_free (pending_list); + g_list_free_full (pending_list, (GDestroyNotify) gst_clock_id_unref); g_thread_join (worker_thread_a); g_thread_join (worker_thread_b); @@ -754,6 +755,7 @@ GST_START_TEST (test_processing_multiple_ids) gst_object_unref (clock); } + GST_END_TEST; GST_START_TEST (test_single_shot_async_past) -- 2.7.4