context: Change GstContext to contain only a single context

It was unintuitive that GstContext was actually a list of different
contexts. GstContext now is only a type string and a structure to
contain the actual context.
This commit is contained in:
Sebastian Dröge 2013-09-17 13:28:42 +02:00
parent 014690326f
commit 4d367dc1b0
3 changed files with 34 additions and 10 deletions

View file

@ -63,6 +63,7 @@ struct _GstContext
{
GstMiniObject mini_object;
gchar *context_type;
GstStructure *structure;
gboolean persistent;
};
@ -119,6 +120,8 @@ _gst_context_copy (GstContext * context)
gst_context_init (copy);
copy->context_type = g_strdup (context->context_type);
structure = GST_CONTEXT_STRUCTURE (context);
GST_CONTEXT_STRUCTURE (copy) = gst_structure_copy (structure);
gst_structure_set_parent_refcount (GST_CONTEXT_STRUCTURE (copy),
@ -148,11 +151,13 @@ gst_context_init (GstContext * context)
* Since: 1.2
*/
GstContext *
gst_context_new (gboolean persistent)
gst_context_new (const gchar * context_type, gboolean persistent)
{
GstContext *context;
GstStructure *structure;
g_return_val_if_fail (context_type != NULL, NULL);
context = g_slice_new0 (GstContext);
GST_CAT_LOG (GST_CAT_CONTEXT, "creating new context %p", context);
@ -161,12 +166,31 @@ gst_context_new (gboolean persistent)
gst_structure_set_parent_refcount (structure, &context->mini_object.refcount);
gst_context_init (context);
context->context_type = g_strdup (context_type);
GST_CONTEXT_STRUCTURE (context) = structure;
context->persistent = persistent;
return context;
}
/**
* gst_context_get_context_type:
* @context: The #GstContext.
*
* Get the type of @context.
*
* Returns: The type of the context.
*
* Since: 1.2
*/
const gchar *
gst_context_get_context_type (const GstContext * context)
{
g_return_val_if_fail (GST_IS_CONTEXT (context), NULL);
return context->context_type;
}
/**
* gst_context_get_structure:
* @context: The #GstContext.

View file

@ -144,10 +144,12 @@ gst_context_replace (GstContext **old_context, GstContext *new_context)
return gst_mini_object_replace ((GstMiniObject **) old_context, (GstMiniObject *) new_context);
}
GstContext * gst_context_new (gboolean persistent) G_GNUC_MALLOC;
GstContext * gst_context_new (const gchar * context_type,
gboolean persistent) G_GNUC_MALLOC;
const GstStructure * gst_context_get_structure (const GstContext *context);
GstStructure * gst_context_writable_structure (GstContext *context);
const gchar * gst_context_get_context_type (const GstContext * context);
const GstStructure * gst_context_get_structure (const GstContext * context);
GstStructure * gst_context_writable_structure (GstContext * context);
gboolean gst_context_is_persistent (const GstContext * context);

View file

@ -709,17 +709,15 @@ gst_debug_print_object (gpointer ptr)
if (GST_IS_CONTEXT (object)) {
GstContext *context = GST_CONTEXT_CAST (object);
gchar *s, *ret;
const gchar *type;
const GstStructure *structure;
type = gst_context_get_context_type (context);
structure = gst_context_get_structure (context);
if (structure) {
s = gst_info_structure_to_string (structure);
} else {
s = g_strdup ("(NULL)");
}
ret = g_strdup_printf ("context '%s'", s);
ret = g_strdup_printf ("context '%s'='%s'", type, s);
g_free (s);
return ret;
}