/* GStreamer
* Copyright (C) 2013 Collabora Ltd.
* Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ * Copyright (C) 2013 Sebastian Dröge <slomo@circular-chaos.org>
*
* gstcontext.c: Unit test for GstContext
*
GstStructure *s1;
const GstStructure *s2;
- c1 = gst_context_new ();
+ c1 = gst_context_new ("test", FALSE);
fail_unless (c1 != NULL);
fail_unless (GST_IS_CONTEXT (c1));
s1 = gst_context_writable_structure (c1);
c2 = gst_context_copy (c1);
fail_unless (c2 != NULL);
fail_unless (GST_IS_CONTEXT (c2));
+ fail_unless (strcmp (gst_context_get_context_type (c1),
+ gst_context_get_context_type (c2)) == 0);
s2 = gst_context_get_structure (c2);
fail_unless (s2 != NULL);
fail_unless (gst_structure_is_equal (s1, s2));
gboolean set_before_ready;
gboolean set_from_need_context;
gboolean create_self;
+
+ gboolean have_foobar;
} GstContextElement;
typedef struct
static void
gst_context_element_set_context (GstElement * element, GstContext * context)
{
- GST_ELEMENT_CLASS (gst_context_element_parent_class)->set_context (element,
- context);
+ if (strcmp (gst_context_get_context_type (context), "foobar") == 0)
+ ((GstContextElement *) element)->have_foobar = TRUE;
}
static GstStateChangeReturn
if (transition == GST_STATE_CHANGE_NULL_TO_READY) {
GstContext *context;
- const GstStructure *s;
GstMessage *msg;
- gboolean have_foobar = FALSE;
-
- context = gst_element_get_context (element);
- if (context) {
- s = gst_context_get_structure (context);
- if (gst_structure_has_field (s, "foobar"))
- have_foobar = TRUE;
- gst_context_unref (context);
- }
+ gboolean have_foobar = celement->have_foobar;
if (celement->set_before_ready && !have_foobar)
return GST_STATE_CHANGE_FAILURE;
if (!have_foobar) {
/* Here we would first query downstream for a context but we have no pads */
- msg = gst_message_new_need_context (GST_OBJECT (element));
- gst_message_add_context_type (msg, "foobar");
+ msg = gst_message_new_need_context (GST_OBJECT (element), "foobar");
gst_element_post_message (element, msg);
- context = gst_element_get_context (element);
- if (context) {
- s = gst_context_get_structure (context);
- if (gst_structure_has_field (s, "foobar"))
- have_foobar = TRUE;
- gst_context_unref (context);
- }
+ have_foobar = celement->have_foobar;
}
if (celement->set_from_need_context && !have_foobar)
return GST_STATE_CHANGE_FAILURE;
if (!have_foobar) {
- GstStructure *s2;
- context = gst_element_get_context (element);
- if (context)
- context = gst_context_make_writable (context);
- else
- context = gst_context_new ();
- s2 = gst_context_writable_structure (context);
- gst_structure_set (s2, "foobar", G_TYPE_INT, 123, NULL);
+ context = gst_context_new ("foobar", FALSE);
gst_element_set_context (element, context);
msg =
gst_message_new_have_context (GST_OBJECT (element),
{
GstBus *bus;
GstElement *element;
- GstContext *context, *context2;
- GstStructure *s;
- const GstStructure *s2;
+ GstContext *context;
GstMessage *msg;
element = g_object_new (gst_context_element_get_type (), NULL);
GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS);
fail_if (gst_bus_pop (bus) != NULL);
- context = gst_context_new ();
- s = gst_context_writable_structure (context);
- gst_structure_set (s, "foobar", G_TYPE_INT, 123, NULL);
+ context = gst_context_new ("foobar", FALSE);
gst_element_set_context (element, context);
fail_unless (gst_element_set_state (element,
GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS);
gst_message_unref (msg);
fail_if (gst_bus_pop (bus) != NULL);
- context2 = gst_element_get_context (element);
- fail_unless (GST_IS_CONTEXT (context2));
- s2 = gst_context_get_structure (context2);
- fail_unless (gst_structure_is_equal (s, s2));
+ fail_unless (((GstContextElement *) element)->have_foobar);
gst_context_unref (context);
- gst_context_unref (context2);
gst_element_set_bus (element, NULL);
fail_unless (gst_element_set_state (element,
sync_handler (GstBus * bus, GstMessage * message, gpointer user_data)
{
if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_NEED_CONTEXT) {
- guint n;
const gchar *type;
GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message));
GstContext *context;
- GstStructure *s;
- n = gst_message_get_n_context_types (message);
- fail_unless (n == 1);
- fail_unless (gst_message_parse_nth_context_type (message, 0, &type));
+ fail_unless (gst_message_parse_context_type (message, &type));
fail_unless_equals_string (type, "foobar");
- context = gst_element_get_context (element);
- if (context)
- context = gst_context_make_writable (context);
- else
- context = gst_context_new ();
- s = gst_context_writable_structure (context);
- gst_structure_set (s, "foobar", G_TYPE_INT, 123, NULL);
+ context = gst_context_new ("foobar", FALSE);
gst_element_set_context (element, context);
gst_context_unref (context);
}
{
GstBus *bus;
GstElement *element;
- GstContext *context;
- const GstStructure *s;
GstMessage *msg;
element = g_object_new (gst_context_element_get_type (), NULL);
gst_message_unref (msg);
fail_if (gst_bus_pop (bus) != NULL);
- context = gst_element_get_context (element);
- fail_unless (GST_IS_CONTEXT (context));
- s = gst_context_get_structure (context);
- fail_unless (gst_structure_has_field (s, "foobar"));
-
- gst_context_unref (context);
+ fail_unless (((GstContextElement *) element)->have_foobar);
gst_element_set_bus (element, NULL);
fail_unless (gst_element_set_state (element,
GstBus *bus;
GstElement *element;
GstContext *context;
- const GstStructure *s;
GstMessage *msg;
element = g_object_new (gst_context_element_get_type (), NULL);
gst_bus_pop_filtered (bus, GST_MESSAGE_HAVE_CONTEXT)) != NULL);
gst_message_parse_have_context (msg, &context);
fail_unless (GST_IS_CONTEXT (context));
- s = gst_context_get_structure (context);
- fail_unless (gst_structure_has_field (s, "foobar"));
+ fail_unless_equals_string (gst_context_get_context_type (context), "foobar");
gst_context_unref (context);
gst_message_unref (msg);
fail_unless ((msg =
gst_message_unref (msg);
fail_if (gst_bus_pop (bus) != NULL);
- context = gst_element_get_context (element);
- fail_unless (GST_IS_CONTEXT (context));
- s = gst_context_get_structure (context);
- fail_unless (gst_structure_has_field (s, "foobar"));
-
- gst_context_unref (context);
+ fail_unless (((GstContextElement *) element)->have_foobar);
gst_element_set_bus (element, NULL);
fail_unless (gst_element_set_state (element,