2 * Copyright (C) 2011 Wim Taymans <wim.taymans@gmail.com>
4 * gstcontext.c: GstContext subsystem
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 * @short_description: Structure containing events describing the context
25 * for buffers in a pipeline
26 * @see_also: #GstPad, #GstBuffer
28 * Last reviewed on 2011-05-4 (0.11.0)
32 #include "gst_private.h"
35 #include "gstcontext.h"
41 GstMiniObject mini_object;
44 GstEvent *events[GST_EVENT_MAX_STICKY];
46 gpointer _gst_reserved[GST_PADDING];
49 static GType _gst_context_type = 0;
52 gst_context_get_type (void)
54 if (G_UNLIKELY (_gst_context_type == 0)) {
55 _gst_context_type = gst_mini_object_register ("GstContext");
57 return _gst_context_type;
61 _gst_context_free (GstContext * context)
63 g_return_if_fail (context != NULL);
64 g_return_if_fail (GST_IS_CONTEXT (context));
66 GST_LOG ("freeing context %p", context);
68 gst_context_clear (context);
70 g_slice_free1 (GST_MINI_OBJECT_SIZE (context), context);
73 static void gst_context_init (GstContext * context, gsize size);
76 _gst_context_copy (GstContext * context)
81 copy = g_slice_new0 (GstContext);
83 gst_context_init (copy, sizeof (GstContext));
85 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
86 gst_event_replace (©->events[i], context->events[i]);
92 gst_context_init (GstContext * context, gsize size)
94 gst_mini_object_init (GST_MINI_OBJECT_CAST (context), _gst_context_type,
97 context->mini_object.copy = (GstMiniObjectCopyFunction) _gst_context_copy;
98 context->mini_object.free = (GstMiniObjectFreeFunction) _gst_context_free;
104 * Create a new #GstContext object that can be used to manage events.
106 * Returns: (transfer full): a new #GstContext
109 gst_context_new (void)
113 context = g_slice_new0 (GstContext);
115 GST_DEBUG ("creating new context %p", context);
117 gst_context_init (context, sizeof (GstContext));
123 * gst_context_update:
124 * @context: a #GstContext
125 * @event: a #GstEvent
127 * Update @context with @event. The context must be writable.
130 gst_context_update (GstContext * context, GstEvent * event)
134 g_return_if_fail (context != NULL);
135 g_return_if_fail (gst_context_is_writable (context));
137 idx = GST_EVENT_STICKY_IDX (event);
139 GST_LOG ("storing event %s at index %u", GST_EVENT_TYPE_NAME (event), idx);
141 gst_event_replace (&context->events[idx], event);
146 * @context: a #GstContext
147 * @type: a #GstEventType
149 * Get the event of @type from @context.
151 * Returns: the last #GstEvent of @type that was updated on @context. This
152 * function returns NULL when there is no event with the given type.
155 gst_context_get (GstContext * context, GstEventType type)
158 GstEvent *event = NULL;
160 g_return_val_if_fail (context != NULL, NULL);
162 idx = GST_EVENT_STICKY_IDX_TYPE (type);
164 if ((event = context->events[idx]))
165 gst_event_ref (event);
172 * @context: a #GstContext
174 * Clear all stored events in @context
177 gst_context_clear (GstContext * context)
181 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
182 gst_event_replace (&context->events[i], NULL);