From 03c3738b6722983f077c4d06711e3d156de97a6d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 18 Apr 2013 10:17:44 +0200 Subject: [PATCH] context: Add gst_context_writable_structure() and let get_structure() return const again --- docs/gst/gstreamer-sections.txt | 1 + gst/gstcontext.c | 29 +++++++++++++++++++++++++---- gst/gstcontext.h | 3 ++- tests/check/gst/gstcontext.c | 25 ++++++++++++++----------- win32/common/libgstreamer.def | 1 + 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index 87eaa6b..b0ae703 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -678,6 +678,7 @@ gst_context_ref gst_context_unref gst_context_copy gst_context_get_structure +gst_context_writable_structure gst_context_make_writable gst_context_is_writable gst_context_replace diff --git a/gst/gstcontext.c b/gst/gstcontext.c index 8f45590..5cf8259 100644 --- a/gst/gstcontext.c +++ b/gst/gstcontext.c @@ -168,16 +168,37 @@ gst_context_new (void) * Access the structure of the context. * * Returns: (transfer none): The structure of the context. The structure is - * still owned by the context, which means that you should not modify it unless - * the context is writable, and should not free it and that the pointer becomes - * invalid when you free the context. + * still owned by the context, which means that you should not modify it, + * free it and that the pointer becomes invalid when you free the context. * * Since: 1.2 */ -GstStructure * +const GstStructure * gst_context_get_structure (GstContext * context) { g_return_val_if_fail (GST_IS_CONTEXT (context), NULL); return GST_CONTEXT_STRUCTURE (context); } + +/** + * gst_context_writable_structure: + * @context: The #GstContext. + * + * Get a writable version of the structure. + * + * Returns: The structure of the context. The structure is still + * owned by the event, which means that you should not free it and + * that the pointer becomes invalid when you free the event. + * This function checks if @context is writable. + * + * Since: 1.2 + */ +GstStructure * +gst_context_writable_structure (GstContext * context) +{ + g_return_val_if_fail (GST_IS_CONTEXT (context), NULL); + g_return_val_if_fail (gst_context_is_writable (context), NULL); + + return GST_CONTEXT_STRUCTURE (context); +} diff --git a/gst/gstcontext.h b/gst/gstcontext.h index 4c3699c..7f4a565 100644 --- a/gst/gstcontext.h +++ b/gst/gstcontext.h @@ -145,7 +145,8 @@ gst_context_replace (GstContext **old_context, GstContext *new_context) GstContext * gst_context_new (void) G_GNUC_MALLOC; -GstStructure * gst_context_get_structure (GstContext *context); +const GstStructure * gst_context_get_structure (GstContext *context); +GstStructure * gst_context_writable_structure (GstContext *context); G_END_DECLS diff --git a/tests/check/gst/gstcontext.c b/tests/check/gst/gstcontext.c index 0c7a01e..702cd03 100644 --- a/tests/check/gst/gstcontext.c +++ b/tests/check/gst/gstcontext.c @@ -25,19 +25,20 @@ GST_START_TEST (test_basic) { GstContext *c1, *c2; - GstStructure *s1, *s2; + GstStructure *s1; + const GstStructure *s2; c1 = gst_context_new (); fail_unless (c1 != NULL); fail_unless (GST_IS_CONTEXT (c1)); - s1 = (GstStructure *) gst_context_get_structure (c1); + s1 = gst_context_writable_structure (c1); fail_unless (s1 != NULL); gst_structure_set (s1, "foobar", G_TYPE_INT, 1, NULL); c2 = gst_context_copy (c1); fail_unless (c2 != NULL); fail_unless (GST_IS_CONTEXT (c2)); - s2 = (GstStructure *) gst_context_get_structure (c2); + s2 = gst_context_get_structure (c2); fail_unless (s2 != NULL); fail_unless (gst_structure_is_equal (s1, s2)); @@ -79,7 +80,7 @@ gst_context_element_change_state (GstElement * element, if (transition == GST_STATE_CHANGE_NULL_TO_READY) { GstContext *context; - GstStructure *s; + const GstStructure *s; GstMessage *msg; gboolean have_foobar = FALSE; @@ -127,13 +128,14 @@ gst_context_element_change_state (GstElement * element, 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 (); - s = gst_context_get_structure (context); - gst_structure_set (s, "foobar", G_TYPE_INT, 123, NULL); + s2 = gst_context_writable_structure (context); + gst_structure_set (s2, "foobar", G_TYPE_INT, 123, NULL); gst_element_set_context (element, context); msg = gst_message_new_have_context (GST_OBJECT (element), @@ -171,7 +173,8 @@ GST_START_TEST (test_element_set_before_ready) GstBus *bus; GstElement *element; GstContext *context, *context2; - GstStructure *s, *s2; + GstStructure *s; + const GstStructure *s2; GstMessage *msg; element = g_object_new (gst_context_element_get_type (), NULL); @@ -185,7 +188,7 @@ GST_START_TEST (test_element_set_before_ready) fail_if (gst_bus_pop (bus) != NULL); context = gst_context_new (); - s = gst_context_get_structure (context); + s = gst_context_writable_structure (context); gst_structure_set (s, "foobar", G_TYPE_INT, 123, NULL); gst_element_set_context (element, context); fail_unless (gst_element_set_state (element, @@ -232,7 +235,7 @@ sync_handler (GstBus * bus, GstMessage * message, gpointer user_data) context = gst_context_make_writable (context); else context = gst_context_new (); - s = gst_context_get_structure (context); + s = gst_context_writable_structure (context); gst_structure_set (s, "foobar", G_TYPE_INT, 123, NULL); gst_element_set_context (element, context); gst_context_unref (context); @@ -246,7 +249,7 @@ GST_START_TEST (test_element_set_from_need_context) GstBus *bus; GstElement *element; GstContext *context; - GstStructure *s; + const GstStructure *s; GstMessage *msg; element = g_object_new (gst_context_element_get_type (), NULL); @@ -288,7 +291,7 @@ GST_START_TEST (test_element_create_self) GstBus *bus; GstElement *element; GstContext *context; - GstStructure *s; + const GstStructure *s; GstMessage *msg; element = g_object_new (gst_context_element_get_type (), NULL); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index 9f292b2..47ac5c1 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -305,6 +305,7 @@ EXPORTS gst_context_get_structure gst_context_get_type gst_context_new + gst_context_writable_structure gst_control_binding_get_g_value_array gst_control_binding_get_type gst_control_binding_get_value -- 2.7.4