1/* GStreamer
2 * Copyright (C) 2013 Collabora Ltd.
3 * Author: Sebastian Dröge <[email protected]>
4 * Copyright (C) 2013 Sebastian Dröge <[email protected]>
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
29G_BEGIN_DECLS
30
31typedef struct _GstContext GstContext;
32
33#include <gst/gstminiobject.h>
34#include <gst/gststructure.h>
35
36GST_API 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
45GST_API
46GType gst_context_get_type (void);
47
48
49/* refcounting */
50/**
51 * gst_context_ref:
52 * @context: the context to ref
53 *
54 * Convenience macro to increase the reference count of the context.
55 *
56 * Returns: @context (for convenience when doing assignments)
57 */
58static inline GstContext *
59gst_context_ref (GstContext * context)
60{
61 return (GstContext *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (context));
62}
63
64/**
65 * gst_context_unref:
66 * @context: the context to unref
67 *
68 * Convenience macro to decrease the reference count of the context, possibly
69 * freeing it.
70 */
71static inline void
72gst_context_unref (GstContext * context)
73{
74 gst_mini_object_unref (GST_MINI_OBJECT_CAST (context));
75}
76
77/* copy context */
78/**
79 * gst_context_copy:
80 * @context: the context to copy
81 *
82 * Creates a copy of the context. Returns a copy of the context.
83 *
84 * Returns: (transfer full): a new copy of @context.
85 *
86 * MT safe
87 */
88static inline GstContext *
89gst_context_copy (const GstContext * context)
90{
91 return GST_CONTEXT_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (context)));
92}
93
94/**
95 * gst_context_is_writable:
96 * @context: a #GstContext
97 *
98 * Tests if you can safely write into a context's structure or validly
99 * modify the seqnum and timestamp fields.
100 */
101#define gst_context_is_writable(context) gst_mini_object_is_writable (GST_MINI_OBJECT_CAST (context))
102/**
103 * gst_context_make_writable:
104 * @context: (transfer full): the context to make writable
105 *
106 * Checks if a context is writable. If not, a writable copy is made and
107 * returned.
108 *
109 * Returns: (transfer full): a context (possibly a duplicate) that is writable.
110 *
111 * MT safe
112 */
113#define gst_context_make_writable(context) GST_CONTEXT_CAST (gst_mini_object_make_writable (GST_MINI_OBJECT_CAST (context)))
114/**
115 * gst_context_replace:
116 * @old_context: (inout) (transfer full): pointer to a pointer to a #GstContext
117 * to be replaced.
118 * @new_context: (allow-none) (transfer none): pointer to a #GstContext that will
119 * replace the context pointed to by @old_context.
120 *
121 * Modifies a pointer to a #GstContext to point to a different #GstContext. The
122 * modification is done atomically (so this is useful for ensuring thread safety
123 * in some cases), and the reference counts are updated appropriately (the old
124 * context is unreffed, the new one is reffed).
125 *
126 * Either @new_context or the #GstContext pointed to by @old_context may be %NULL.
127 *
128 * Returns: %TRUE if @new_context was different from @old_context
129 */
130static inline gboolean
131gst_context_replace (GstContext **old_context, GstContext *new_context)
132{
133 return gst_mini_object_replace ((GstMiniObject **) old_context, (GstMiniObject *) new_context);
134}
135
136GST_API
137GstContext * gst_context_new (const gchar * context_type,
138 gboolean persistent) G_GNUC_MALLOC;
139GST_API
140const gchar * gst_context_get_context_type (const GstContext * context);
141
142GST_API
143gboolean gst_context_has_context_type (const GstContext * context, const gchar * context_type);
144
145GST_API
146const GstStructure * gst_context_get_structure (const GstContext * context);
147
148GST_API
149GstStructure * gst_context_writable_structure (GstContext * context);
150
151GST_API
152gboolean gst_context_is_persistent (const GstContext * context);
153
154#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
155G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstContext, gst_context_unref)
156#endif
157
158G_END_DECLS
159
160#endif /* __GST_CONTEXT_H__ */
161