Debian Codegraph @

gstreamer/gstreamermm/miniobject.cc

raw symbols SCIP
1 // Generated by gmmproc 2.50.1 -- DO NOT MODIFY!
2
3
4 #include <glibmm.h>
5
6 #include <gstreamermm/miniobject.h>
7 #include <gstreamermm/private/miniobject_p.h>
8
9
10 /* gstreamermm - a C++ wrapper for gstreamer
11 *
12 * Copyright 2008 The gstreamermm Development Team
13 *
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free
26 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29 #include <gstreamermm/miniobject.h>
30 #include <gstreamermm/private/miniobject_p.h>
31
32 namespace Gst
33 {
34
35 std::map<GstMiniObject*, MiniObject::SlotFinalizer*> MiniObject::finalizers;
36
37 MiniObject::~MiniObject()
38 {
39 GstMiniObject *const gobject_ = reinterpret_cast<GstMiniObject*>(const_cast<MiniObject*>(this));
40 // The value of the reference count is checked so that if this mini object is
41 // being destroyed as a result of weak reference notification no
42 // unreferencing is done and thus no error is issued on unreferencing a mini
43 // object with a reference of 0.
44 if (gobject_ && GST_MINI_OBJECT_REFCOUNT_VALUE(gobject_) > 0)
45 {
46 gst_mini_object_unref(gobject_);
47 }
48
49 if (finalizers.find(gobject_) != finalizers.end())
50 {
51 delete finalizers[gobject_];
52 finalizers[gobject_] = nullptr;
53 }
54 }
55
56 Glib::RefPtr<Gst::MiniObject> MiniObject::create_writable()
57 {
58 /*
59 * This function is generally used in the following pattern:
60 * RefPtr<Buffer> p = (...);
61 * p = p->create_writable();
62 *
63 * There are two cases:
64 * 1. object is not writable, therefore:
65 * - somebody else may have another reference to the object (but it this might change in the meantime)
66 * - gst_mini_object_make_writable may return a new copy of object
67 * - we have to make additional ref, that will be unreffed in gst_mini_object_make_writable
68 * 2. object is_writable, then:
69 * - our caller has the only one reference to object (therefore nobody can increase refcount in the meantime)
70 * - gst_mini_object_make_writable will return the same object and will not do any reffing/unreffing
71 * - we cannot make any additional refs before calling gst_mini_object_make_writable, since it would enforce unnecessary
72 * copying of the object
73 * - we are supposed to create a new RefPtr with is own reference to the object, therefore we need to "take copy"
74 * - however when caller release the pointer (implicitly, during assignment) the refcount will be 1 again
75 */
76 if(is_writable())
77 {
78 return Glib::wrap(gst_mini_object_make_writable(gobj()), true); // take copy so original object is left to the current owner (and hopefully will be released soon)
79 }
80 else
81 {
82 reference(); // gst_mini_object_make_writable(buf) will unref the old buffer, but our caller is still holding RefPtr to it
83 return Glib::wrap(gst_mini_object_make_writable(gobj()));
84 }
85 }
86
87 void MiniObject::set_qdata(GQuark quark, QuarkData *data)
88 {
89 gst_mini_object_set_qdata(gobj(), quark, static_cast<gpointer>(data), &MiniObject::destroy_qdata);
90 }
91
92 void MiniObject::destroy_qdata(gpointer qdata)
93 {
94 QuarkData *data = static_cast<QuarkData*>(qdata);
95 delete data;
96 }
97
98 QuarkData* MiniObject::get_qdata(GQuark quark) const
99 {
100 gpointer qdata = gst_mini_object_get_qdata(const_cast<GstMiniObject*>(gobj()), quark);
101 return static_cast<QuarkData*>(qdata);
102 }
103
104 void MiniObject::add_finalize_notifier(const SlotFinalizer& slot)
105 {
106 SlotFinalizer *finalizer = new SlotFinalizer(slot);
107 if (finalizers.find(gobj()) != finalizers.end())
108 {
109 delete finalizers[gobj()];
110 finalizers[gobj()] = finalizer;
111 }
112 else
113 {
114 finalizers.insert(std::make_pair(gobj(), finalizer));
115 }
116 gst_mini_object_weak_ref(gobj(), &MiniObject::MiniObject_Finalizer_gstreamermm_callback, static_cast<gpointer>(finalizer));
117 }
118
119 void MiniObject::MiniObject_Finalizer_gstreamermm_callback(gpointer userdata, GstMiniObject*)
120 {
121 (*static_cast<SlotFinalizer*>(userdata))();
122 }
123
124 void MiniObject::remove_finalize_notifier()
125 {
126 if (finalizers.find(gobj()) != finalizers.end())
127 {
128 gst_mini_object_weak_unref(gobj(), &MiniObject::MiniObject_Finalizer_gstreamermm_callback, finalizers[gobj()]);
129 delete finalizers[gobj()];
130 finalizers[gobj()] = nullptr;
131 }
132 }
133
134 } //namespace Gst
135
136 namespace
137 {
138 } // anonymous namespace
139
140 // static
141 GType Glib::Value<Gst::MiniObjectFlags>::value_type()
142 {
143 return gst_mini_object_flags_get_type();
144 }
145
146 // static
147 GType Glib::Value<Gst::LockFlags>::value_type()
148 {
149 return gst_lock_flags_get_type();
150 }
151
152
153 /* Why reinterpret_cast<MiniObject*>(gobject) is needed:
154 *
155 * A MiniObject instance is in fact always a GstMiniObject instance.
156 * Unfortunately, GstMiniObject cannot be a member of MiniObject,
157 * because it is an opaque struct. Also, the C interface does not provide
158 * any hooks to install a destroy notification handler, thus we cannot
159 * wrap it dynamically either.
160 *
161 * The cast works because MiniObject does not have any member data, and
162 * it is impossible to derive from it. This is ensured by using final on the
163 * class and by using = delete on the default constructor.
164 */
165
166 namespace Glib
167 {
168
169 Glib::RefPtr<Gst::MiniObject> wrap(GstMiniObject* object, bool take_copy)
170 {
171 if(take_copy && object)
172 gst_mini_object_ref(object);
173
174 // See the comment at the top of this file, if you want to know why the cast works.
175 return Glib::RefPtr<Gst::MiniObject>(reinterpret_cast<Gst::MiniObject*>(object));
176 }
177
178 } // namespace Glib
179
180
181 namespace Gst
182 {
183
184
185 void MiniObject::reference() const
186 {
187 // See the comment at the top of this file, if you want to know why the cast works.
188 gst_mini_object_ref(reinterpret_cast<GstMiniObject*>(const_cast<MiniObject*>(this)));
189 }
190
191 void MiniObject::unreference() const
192 {
193 // See the comment at the top of this file, if you want to know why the cast works.
194 gst_mini_object_unref(reinterpret_cast<GstMiniObject*>(const_cast<MiniObject*>(this)));
195 }
196
197 GstMiniObject* MiniObject::gobj()
198 {
199 // See the comment at the top of this file, if you want to know why the cast works.
200 return reinterpret_cast<GstMiniObject*>(this);
201 }
202
203 const GstMiniObject* MiniObject::gobj() const
204 {
205 // See the comment at the top of this file, if you want to know why the cast works.
206 return reinterpret_cast<const GstMiniObject*>(this);
207 }
208
209 GstMiniObject* MiniObject::gobj_copy() const
210 {
211 // See the comment at the top of this file, if you want to know why the cast works.
212 const auto gobject = reinterpret_cast<GstMiniObject*>(const_cast<MiniObject*>(this));
213 gst_mini_object_ref(gobject);
214 return gobject;
215 }
216
217
218 guint MiniObject::get_flags() const
219 {
220 return gobj()->flags;
221 }
222
223 void MiniObject::set_flags(const guint& value)
224 {
225 gobj()->flags = value;
226 }
227
228 gint MiniObject::get_refcount() const
229 {
230 return gobj()->refcount;
231 }
232
233 gint MiniObject::get_lockstate() const
234 {
235 return gobj()->lockstate;
236 }
237
238 bool MiniObject::lock(LockFlags flags)
239 {
240 return gst_mini_object_lock(gobj(), ((GstLockFlags)(flags)));
241 }
242
243 void MiniObject::unlock(LockFlags flags)
244 {
245 gst_mini_object_unlock(gobj(), ((GstLockFlags)(flags)));
246 }
247
248 bool MiniObject::is_writable() const
249 {
250 return gst_mini_object_is_writable(const_cast<GstMiniObject*>(gobj()));
251 }
252
253 QuarkData* MiniObject::steal_qdata(GQuark quark)
254 {
255 return static_cast<QuarkData*>(gst_mini_object_steal_qdata(gobj(), quark));
256 }
257
258
259 } // namespace Gst
260
261