Debian Codegraph @

gstreamer/src/basetransform.ccg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008-2016 The gstreamermm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <gstreamermm/pad.h>
21 #include <gstreamermm/caps.h>
22 #include <gstreamermm/buffer.h>
23
24 _PINCLUDE(gstreamermm/private/element_p.h)
25
26 #define IGNORE_RESULT(x) { auto release_value = x; (void)release_value; }
27
28 namespace Gst
29 {
30
31 const Glib::ustring BaseTransform::SINK_NAME = GST_BASE_TRANSFORM_SINK_NAME;
32 const Glib::ustring BaseTransform::SRC_NAME = GST_BASE_TRANSFORM_SRC_NAME;
33
34 GstFlowReturn BaseTransform_Class::prepare_output_buffer_vfunc_callback(GstBaseTransform* self, GstBuffer* input, GstBuffer** buffer)
35 {
36 Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
37 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
38
39 // Non-gtkmmproc-generated custom classes implicitly call the default
40 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
41 // generated classes can use this optimisation, which avoids the unnecessary
42 // parameter conversions if there is no possibility of the virtual function
43 // being overridden:
44 if(obj_base && obj_base->is_derived_())
45 {
46 CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
47 if(obj) // This can be NULL during destruction.
48 {
49 try // Trap C++ exceptions which would normally be lost because this is a C callback.
50 {
51 Glib::RefPtr<Gst::Buffer> cpp_buffer;
52 // Call the virtual member method, which derived classes might override.
53 const GstFlowReturn result =
54 static_cast<GstFlowReturn>(obj->prepare_output_buffer_vfunc(
55 Glib::wrap(input, true), cpp_buffer));
56 *buffer = cpp_buffer ? cpp_buffer->gobj_copy() : 0;
57 return result;
58 }
59 catch(...)
60 {
61 Glib::exception_handlers_invoke();
62 }
63 }
64 }
65
66 BaseClassType *const base = static_cast<BaseClassType*>(
67 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
68 );
69
70 // Call the original underlying C function:
71 if(base && base->prepare_output_buffer)
72 return (*base->prepare_output_buffer)(self, input, buffer);
73
74
75 typedef GstFlowReturn RType;
76 return RType();
77 }
78 FlowReturn Gst::BaseTransform::prepare_output_buffer_vfunc(const Glib::RefPtr<Gst::Buffer>& input, Glib::RefPtr<Gst::Buffer>& buffer)
79 {
80 BaseClassType *const base = static_cast<BaseClassType*>(
81 g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
82 );
83
84 if(base && base->prepare_output_buffer)
85 {
86 GstBuffer* gst_buffer;
87 const Gst::FlowReturn result =
88 static_cast<Gst::FlowReturn>((*base->prepare_output_buffer)(gobj(),
89 Glib::unwrap(input), &gst_buffer));
90 buffer = Glib::wrap(gst_buffer, false); // Don't take copy because callback returns a newly created copy.
91 return result;
92 }
93
94 typedef FlowReturn RType;
95 return RType();
96 }
97
98 Glib::RefPtr<Allocator> BaseTransform::get_allocator(AllocationParams& params)
99 {
100 GstAllocator* alloc;
101 gst_base_transform_get_allocator(gobj(), &alloc, params.gobj());
102 return Glib::wrap(alloc, false);
103 }
104
105 GstFlowReturn BaseTransform_Class::transform_vfunc_callback(GstBaseTransform* self, GstBuffer* inbuf, GstBuffer* outbuf)
106 {
107 Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
108 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
109
110 if(obj_base && obj_base->is_derived_())
111 {
112 CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
113 if(obj) // This can be NULL during destruction.
114 {
115 #ifdef GLIBMM_EXCEPTIONS_ENABLED
116 try // Trap C++ exceptions which would normally be lost because this is a C callback.
117 {
118 #endif //GLIBMM_EXCEPTIONS_ENABLED
119 Glib::RefPtr<Gst::Buffer> w_inbuf = Glib::wrap(inbuf, false),
120 w_outbuf = Glib::wrap(outbuf, false);
121 // Call the virtual member method, which derived classes might override.
122 GstFlowReturn ret = ((GstFlowReturn)(obj->transform_vfunc(w_inbuf, w_outbuf)));
123 w_inbuf->reference(); w_outbuf->reference();
124 return ret;
125 #ifdef GLIBMM_EXCEPTIONS_ENABLED
126 }
127 catch(...)
128 {
129 Glib::exception_handlers_invoke();
130 }
131 #endif //GLIBMM_EXCEPTIONS_ENABLED
132 }
133 }
134
135 BaseClassType *const base = static_cast<BaseClassType*>(
136 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
137 );
138
139 // Call the original underlying C function:
140 if(base && base->transform)
141 {
142 GstFlowReturn retval = (*base->transform)(self, inbuf, outbuf);
143 return retval;
144 }
145
146 typedef GstFlowReturn RType;
147 return RType();
148 }
149
150 FlowReturn Gst::BaseTransform::transform_vfunc(const Glib::RefPtr<Gst::Buffer>& inbuf, const Glib::RefPtr<Gst::Buffer>& outbuf)
151 {
152 BaseClassType *const base = static_cast<BaseClassType*>(
153 g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
154 );
155
156 if(base && base->transform)
157 {
158 FlowReturn retval(((FlowReturn)((*base->transform)(gobj(),Glib::unwrap(inbuf),Glib::unwrap(outbuf)))));
159 return retval;
160 }
161
162 typedef FlowReturn RType;
163 return RType();
164 }
165
166 GstFlowReturn BaseTransform_Class::generate_output_vfunc_callback(GstBaseTransform* self, GstBuffer** outbuf)
167 {
168 Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
169 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
170
171 // Non-gtkmmproc-generated custom classes implicitly call the default
172 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
173 // generated classes can use this optimisation, which avoids the unnecessary
174 // parameter conversions if there is no possibility of the virtual function
175 // being overridden:
176 if(obj_base && obj_base->is_derived_())
177 {
178 CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
179 if(obj) // This can be NULL during destruction.
180 {
181 try // Trap C++ exceptions which would normally be lost because this is a C callback.
182 {
183 Glib::RefPtr<Gst::Buffer> cpp_buffer;
184 // Call the virtual member method, which derived classes might override.
185 const GstFlowReturn result =
186 static_cast<GstFlowReturn>(obj->generate_output_vfunc(
187 cpp_buffer));
188 *outbuf = cpp_buffer ? cpp_buffer->gobj_copy() : 0;
189 return result;
190 }
191 catch(...)
192 {
193 Glib::exception_handlers_invoke();
194 }
195 }
196 }
197
198 BaseClassType *const base = static_cast<BaseClassType*>(
199 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
200 );
201
202 // Call the original underlying C function:
203 if(base && base->generate_output)
204 return (*base->generate_output)(self, outbuf);
205
206
207 typedef GstFlowReturn RType;
208 return RType();
209 }
210
211 FlowReturn Gst::BaseTransform::generate_output_vfunc(Glib::RefPtr<Gst::Buffer>& outbuf)
212 {
213 BaseClassType *const base = static_cast<BaseClassType*>(
214 g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
215 );
216
217 if(base && base->generate_output)
218 {
219 GstBuffer* gst_buffer = nullptr;
220 const Gst::FlowReturn result =
221 static_cast<Gst::FlowReturn>((*base->generate_output)(gobj(), &gst_buffer));
222 outbuf = Glib::wrap(gst_buffer, false); // Don't take copy because callback returns a newly created copy.
223 return result;
224 }
225
226 typedef FlowReturn RType;
227 return RType();
228 }
229
230 gboolean BaseTransform_Class::query_vfunc_callback(GstBaseTransform* self, GstPadDirection direction, GstQuery* query)
231 {
232 const auto obj_base = static_cast<Glib::ObjectBase*>(
233 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
234
235 // Non-gtkmmproc-generated custom classes implicitly call the default
236 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
237 // generated classes can use this optimisation, which avoids the unnecessary
238 // parameter conversions if there is no possibility of the virtual function
239 // being overridden:
240 if(obj_base && obj_base->is_derived_())
241 {
242 const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
243 if(obj) // This can be NULL during destruction.
244 {
245 try // Trap C++ exceptions which would normally be lost because this is a C callback.
246 {
247 // Call the virtual member method, which derived classes might override.
248 auto query_cpp = Glib::wrap(query, false);
249 int ret = static_cast<int>(obj->base_transform_query_vfunc(static_cast<Gst::PadDirection>(direction), query_cpp));
250 IGNORE_RESULT(query_cpp.release());
251 return ret;
252 }
253 catch(...)
254 {
255 Glib::exception_handlers_invoke();
256 }
257 }
258 }
259
260 BaseClassType *const base = static_cast<BaseClassType*>(
261 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
262 );
263
264 // Call the original underlying C function:
265 if(base && base->query)
266 {
267 gboolean retval = (*base->query)(self, direction, query);
268 return retval;
269 }
270
271 typedef gboolean RType;
272 return RType();
273 }
274
275
276 bool Gst::BaseTransform::base_transform_query_vfunc(Gst::PadDirection direction, const Glib::RefPtr<Gst::Query>& query)
277 {
278 const auto base = static_cast<BaseClassType*>(
279 g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
280 );
281
282 if(base && base->query)
283 {
284 bool retval((*base->query)(gobj(), static_cast<GstPadDirection>(direction), Glib::unwrap(query)));
285 return retval;
286 }
287
288 typedef bool RType;
289 return RType();
290 }
291
292 bool BaseTransform::propose_allocation_vfunc(const Glib::RefPtr<Gst::Query>& decide_query, const Glib::RefPtr<Gst::Query>& query)
293 {
294 const auto base = static_cast<BaseClassType*>(
295 g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
296 );
297
298 if(base && base->propose_allocation)
299 {
300 bool retval((*base->propose_allocation)(gobj(),Glib::unwrap(decide_query),Glib::unwrap(query)));
301 return retval;
302 }
303
304 typedef bool RType;
305 return RType();
306 }
307
308 gboolean BaseTransform_Class::propose_allocation_vfunc_callback(GstBaseTransform* self, GstQuery* decide_query, GstQuery* query)
309 {
310 const auto obj_base = static_cast<Glib::ObjectBase*>(
311 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
312
313 // Non-gtkmmproc-generated custom classes implicitly call the default
314 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
315 // generated classes can use this optimisation, which avoids the unnecessary
316 // parameter conversions if there is no possibility of the virtual function
317 // being overridden:
318 if(obj_base && obj_base->is_derived_())
319 {
320 const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
321 if(obj) // This can be NULL during destruction.
322 {
323 try // Trap C++ exceptions which would normally be lost because this is a C callback.
324 {
325 // Call the virtual member method, which derived classes might override.
326 auto query_cpp = Glib::wrap(query, false);
327 auto decide_query_cpp = Glib::wrap(decide_query, false);
328 auto ret = static_cast<int>(obj->propose_allocation_vfunc(decide_query_cpp, query_cpp));
329 IGNORE_RESULT(query_cpp.release());
330 IGNORE_RESULT(decide_query_cpp.release());
331 return ret;
332 }
333 catch(...)
334 {
335 Glib::exception_handlers_invoke();
336 }
337 }
338 }
339
340 BaseClassType *const base = static_cast<BaseClassType*>(
341 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
342 );
343
344 // Call the original underlying C function:
345 if(base && base->propose_allocation)
346 return (*base->propose_allocation)(self, decide_query, query);
347
348 typedef gboolean RType;
349 return RType();
350 }
351
352 bool Gst::BaseTransform::decide_allocation_vfunc(const Glib::RefPtr<Gst::Query>& query)
353 {
354 const auto base = static_cast<BaseClassType*>(
355 g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
356 );
357
358 if(base && base->decide_allocation)
359 {
360 bool retval((*base->decide_allocation)(gobj(),Glib::unwrap(query)));
361 return retval;
362 }
363
364 typedef bool RType;
365 return RType();
366 }
367
368 gboolean BaseTransform_Class::decide_allocation_vfunc_callback(GstBaseTransform* self, GstQuery* query)
369 {
370 const auto obj_base = static_cast<Glib::ObjectBase*>(
371 Glib::ObjectBase::_get_current_wrapper((GObject*)self));
372
373 // Non-gtkmmproc-generated custom classes implicitly call the default
374 // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
375 // generated classes can use this optimisation, which avoids the unnecessary
376 // parameter conversions if there is no possibility of the virtual function
377 // being overridden:
378 if(obj_base && obj_base->is_derived_())
379 {
380 const auto obj = dynamic_cast<CppObjectType* const>(obj_base);
381 if(obj) // This can be NULL during destruction.
382 {
383 try // Trap C++ exceptions which would normally be lost because this is a C callback.
384 {
385 // Call the virtual member method, which derived classes might override.
386 auto query_cpp = Glib::wrap(query, false);
387 auto ret = static_cast<int>(obj->decide_allocation_vfunc(query_cpp));
388 IGNORE_RESULT(query_cpp.release());
389 return ret;
390 }
391 catch(...)
392 {
393 Glib::exception_handlers_invoke();
394 }
395 }
396 }
397
398 BaseClassType *const base = static_cast<BaseClassType*>(
399 g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
400 );
401
402 // Call the original underlying C function:
403 if(base && base->decide_allocation)
404 return (*base->decide_allocation)(self, query);
405
406 typedef gboolean RType;
407 return RType();
408 }
409
410
411 } //namespace Gst