parse: Don't hold element's object lock while querying element pads' caps
[platform/upstream/gstreamer.git] / gst / gstcontext.h
1 /* GStreamer
2  * Copyright (C) 2013 Collabora Ltd.
3  *   Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
4  * Copyright (C) 2013 Sebastian Dröge <slomo@circular-chaos.org>
5  *
6  * gstcontext.h: Header for GstContext subsystem
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23
24 #ifndef __GST_CONTEXT_H__
25 #define __GST_CONTEXT_H__
26
27 #include <glib.h>
28
29 G_BEGIN_DECLS
30
31 typedef struct _GstContext GstContext;
32
33 #include <gst/gstminiobject.h>
34 #include <gst/gststructure.h>
35
36 GST_EXPORT GType _gst_context_type;
37
38 #define GST_TYPE_CONTEXT                         (_gst_context_type)
39 #define GST_IS_CONTEXT(obj)                      (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_CONTEXT))
40 #define GST_CONTEXT_CAST(obj)                    ((GstContext*)(obj))
41 #define GST_CONTEXT(obj)                         (GST_CONTEXT_CAST(obj))
42
43
44
45 GType           gst_context_get_type            (void);
46
47
48 /* refcounting */
49 /**
50  * gst_context_ref:
51  * @context: the context to ref
52  *
53  * Convenience macro to increase the reference count of the context.
54  *
55  * Returns: @context (for convenience when doing assignments)
56  */
57 static inline GstContext *
58 gst_context_ref (GstContext * context)
59 {
60   return (GstContext *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (context));
61 }
62
63 /**
64  * gst_context_unref:
65  * @context: the context to unref
66  *
67  * Convenience macro to decrease the reference count of the context, possibly
68  * freeing it.
69  */
70 static inline void
71 gst_context_unref (GstContext * context)
72 {
73   gst_mini_object_unref (GST_MINI_OBJECT_CAST (context));
74 }
75
76 /* copy context */
77 /**
78  * gst_context_copy:
79  * @context: the context to copy
80  *
81  * Creates a copy of the context. Returns a copy of the context.
82  *
83  * Returns: (transfer full): a new copy of @context.
84  *
85  * MT safe
86  */
87 static inline GstContext *
88 gst_context_copy (const GstContext * context)
89 {
90   return GST_CONTEXT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (context)));
91 }
92
93 /**
94  * gst_context_is_writable:
95  * @context: a #GstContext
96  *
97  * Tests if you can safely write into a context's structure or validly
98  * modify the seqnum and timestamp fields.
99  */
100 #define         gst_context_is_writable(context)     gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (context))
101 /**
102  * gst_context_make_writable:
103  * @context: (transfer full): the context to make writable
104  *
105  * Checks if a context is writable. If not, a writable copy is made and
106  * returned.
107  *
108  * Returns: (transfer full): a context (possibly a duplicate) that is writable.
109  *
110  * MT safe
111  */
112 #define         gst_context_make_writable(context)  GST_CONTEXT_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (context)))
113 /**
114  * gst_context_replace:
115  * @old_context: (inout) (transfer full): pointer to a pointer to a #GstContext
116  *     to be replaced.
117  * @new_context: (allow-none) (transfer none): pointer to a #GstContext that will
118  *     replace the context pointed to by @old_context.
119  *
120  * Modifies a pointer to a #GstContext to point to a different #GstContext. The
121  * modification is done atomically (so this is useful for ensuring thread safety
122  * in some cases), and the reference counts are updated appropriately (the old
123  * context is unreffed, the new one is reffed).
124  *
125  * Either @new_context or the #GstContext pointed to by @old_context may be %NULL.
126  *
127  * Returns: %TRUE if @new_context was different from @old_context
128  */
129 static inline gboolean
130 gst_context_replace (GstContext **old_context, GstContext *new_context)
131 {
132   return gst_mini_object_replace ((GstMiniObject **) old_context, (GstMiniObject *) new_context);
133 }
134
135 GstContext *          gst_context_new                      (const gchar * context_type,
136                                                             gboolean persistent) G_GNUC_MALLOC;
137
138 const gchar *         gst_context_get_context_type         (const GstContext * context);
139 gboolean              gst_context_has_context_type         (const GstContext * context, const gchar * context_type);
140 const GstStructure *  gst_context_get_structure            (const GstContext * context);
141 GstStructure *        gst_context_writable_structure       (GstContext * context);
142
143 gboolean              gst_context_is_persistent            (const GstContext * context);
144
145 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
146 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstContext, gst_context_unref)
147 #endif
148
149 G_END_DECLS
150
151 #endif /* __GST_CONTEXT_H__ */