summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2016-03-08 00:35:22 +1100
committerMatthew Waters <matthew@centricular.com>2016-03-08 02:06:13 +1100
commitaa6062945c9e4e293332cfc6ab1832647c09008e (patch)
tree0062b6dad3aac5d50090be285d99d0fa38368372
parent5f925a15805dd2384436c36ec1cc4248f8bb370b (diff)
downloadgstreamer-plugins-bad-aa6062945c9e4e293332cfc6ab1832647c09008e.tar.gz
gldisplay: make readding the same context a no-op
With e38af2304427db908a16bbae0e60aa68be1ba5b5 returning the correct contexts, gst_gl_display_add_context() was susceptible to causing infinte loops when adding the same GstGLContext more than once. Fix and add a test for gst_gl_display_add_context(). Fixes glvideomixer gst-validate tests.
-rw-r--r--gst-libs/gst/gl/gstgldisplay.c9
-rw-r--r--tests/check/libs/gstglcontext.c92
2 files changed, 100 insertions, 1 deletions
diff --git a/gst-libs/gst/gl/gstgldisplay.c b/gst-libs/gst/gl/gstgldisplay.c
index 65ce1a301..5cae2f4b9 100644
--- a/gst-libs/gst/gl/gstgldisplay.c
+++ b/gst-libs/gst/gl/gstgldisplay.c
@@ -500,7 +500,7 @@ _check_collision (GstGLContext * context, GstGLContext * collision)
goto out;
}
- if (collision == context) {
+ if (thread == collision_thread) {
ret = TRUE;
goto out;
}
@@ -546,6 +546,13 @@ gst_gl_display_add_context (GstGLDisplay * display, GstGLContext * context)
if (thread) {
collision = _get_gl_context_for_thread_unlocked (display, thread);
g_thread_unref (thread);
+
+ /* adding the same context is a no-op */
+ if (context == collision) {
+ ret = TRUE;
+ goto out;
+ }
+
if (_check_collision (context, collision)) {
ret = FALSE;
goto out;
diff --git a/tests/check/libs/gstglcontext.c b/tests/check/libs/gstglcontext.c
index e626f2a7d..f2f27f8e0 100644
--- a/tests/check/libs/gstglcontext.c
+++ b/tests/check/libs/gstglcontext.c
@@ -517,6 +517,97 @@ GST_START_TEST (test_is_shared)
GST_END_TEST;
+GST_START_TEST (test_display_list)
+{
+ GstGLContext *c1, *c2;
+ GError *error = NULL;
+
+ c1 = gst_gl_context_new (display);
+ gst_gl_context_create (c1, NULL, &error);
+ fail_if (error != NULL, "Error creating context %s\n",
+ error ? error->message : "Unknown Error");
+
+ GST_OBJECT_LOCK (display);
+ {
+ /* no context added so get should return NULL */
+ GstGLContext *tmp =
+ gst_gl_display_get_gl_context_for_thread (display, NULL);
+ fail_unless (tmp == NULL);
+ }
+
+ fail_unless (gst_gl_display_add_context (display, c1));
+ /* re-adding the same context is a no-op */
+ fail_unless (gst_gl_display_add_context (display, c1));
+
+ {
+ GThread *thread;
+ GstGLContext *tmp;
+
+ thread = gst_gl_context_get_thread (c1);
+ fail_unless (thread != NULL);
+
+ tmp = gst_gl_display_get_gl_context_for_thread (display, thread);
+ fail_unless (tmp == c1);
+ g_thread_unref (thread);
+ gst_object_unref (tmp);
+
+ tmp = gst_gl_display_get_gl_context_for_thread (display, NULL);
+ fail_unless (tmp == c1);
+ gst_object_unref (tmp);
+ }
+
+ c2 = gst_gl_context_new (display);
+ gst_gl_context_create (c2, c1, &error);
+ fail_if (error != NULL, "Error creating context %s\n",
+ error ? error->message : "Unknown Error");
+
+ fail_unless (gst_gl_display_add_context (display, c2));
+ /* re-adding the same context is a no-op */
+ fail_unless (gst_gl_display_add_context (display, c2));
+
+ {
+ GThread *thread;
+ GstGLContext *tmp;
+
+ thread = gst_gl_context_get_thread (c2);
+ fail_unless (thread != NULL);
+
+ tmp = gst_gl_display_get_gl_context_for_thread (display, thread);
+ fail_unless (tmp == c2);
+ g_thread_unref (thread);
+ gst_object_unref (tmp);
+
+ /* undefined which context will be returned for the NULL thread */
+ tmp = gst_gl_display_get_gl_context_for_thread (display, NULL);
+ fail_unless (tmp != NULL);
+ gst_object_unref (tmp);
+ }
+
+ gst_object_unref (c1);
+ /* c1 is now dead */
+
+ {
+ GstGLContext *tmp;
+
+ tmp = gst_gl_display_get_gl_context_for_thread (display, NULL);
+ fail_unless (tmp == c2);
+ gst_object_unref (tmp);
+ }
+ GST_OBJECT_UNLOCK (display);
+
+ gst_object_unref (c2);
+ /* c2 is now dead */
+
+ {
+ /* no more contexts alive */
+ GstGLContext *tmp =
+ gst_gl_display_get_gl_context_for_thread (display, NULL);
+ fail_unless (tmp == NULL);
+ }
+}
+
+GST_END_TEST;
+
static Suite *
gst_gl_context_suite (void)
{
@@ -530,6 +621,7 @@ gst_gl_context_suite (void)
tcase_add_test (tc_chain, test_current_context);
tcase_add_test (tc_chain, test_context_can_share);
tcase_add_test (tc_chain, test_is_shared);
+ tcase_add_test (tc_chain, test_display_list);
return s;
}