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